25 RAPIDJSON_DIAG_OFF(4702)
31 template <
typename StringStreamType>
33 typedef typename StringStreamType::char_type Ch;
38 EXPECT_EQ(0, is.
Tell());
39 if (
sizeof(Ch) == 1) {
40 EXPECT_EQ(0, is.
Peek4());
41 EXPECT_EQ(0, is.
Tell());
43 EXPECT_EQ(0, is.
Peek());
44 EXPECT_EQ(0, is.
Take());
45 EXPECT_EQ(0, is.
Tell());
49 Ch
s[] = {
'A',
'B',
'C',
'\0' };
50 StringStreamType iss(s);
52 EXPECT_EQ(0, is.
Tell());
53 if (
sizeof(Ch) == 1) {
54 EXPECT_EQ(0, is.
Peek4());
56 for (
int i = 0; i < 3; i++) {
57 EXPECT_EQ(static_cast<size_t>(i), is.
Tell());
58 EXPECT_EQ(
'A' + i, is.
Peek());
59 EXPECT_EQ(
'A' + i, is.
Peek());
60 EXPECT_EQ(
'A' + i, is.
Take());
62 EXPECT_EQ(3, is.
Tell());
63 EXPECT_EQ(0, is.
Peek());
64 EXPECT_EQ(0, is.
Take());
68 Ch
s[] = {
'A',
'B',
'C',
'D',
'E',
'\0' };
69 StringStreamType iss(s);
71 if (
sizeof(Ch) == 1) {
72 const Ch* c = is.
Peek4();
73 for (
int i = 0; i < 4; i++)
74 EXPECT_EQ(
'A' + i, c[i]);
75 EXPECT_EQ(0, is.
Tell());
77 for (
int i = 0; i < 5; i++) {
78 EXPECT_EQ(static_cast<size_t>(i), is.
Tell());
79 EXPECT_EQ(
'A' + i, is.
Peek());
80 EXPECT_EQ(
'A' + i, is.
Peek());
81 EXPECT_EQ(
'A' + i, is.
Take());
83 EXPECT_EQ(5, is.
Tell());
84 EXPECT_EQ(0, is.
Peek());
85 EXPECT_EQ(0, is.
Take());
90 TestStringStream<istringstream>();
94 TestStringStream<stringstream>();
98 TestStringStream<wistringstream>();
102 TestStringStream<wstringstream>();
105 template <
typename FileStreamType>
106 static bool Open(FileStreamType& fs,
const char* filename) {
107 const char *paths[] = {
111 "../../bin/encodings",
112 "../../../bin/encodings" 115 for (
size_t i = 0; i <
sizeof(paths) /
sizeof(paths[0]); i++) {
116 sprintf(buffer,
"%s/%s", paths[i], filename);
117 fs.open(buffer, ios_base::in | ios_base::binary);
126 ASSERT_TRUE(
Open(ifs,
"utf8bom.json"));
131 EXPECT_TRUE(d.IsObject());
132 EXPECT_EQ(5, d.MemberCount());
137 ASSERT_TRUE(
Open(fs,
"utf8bom.json"));
142 EXPECT_TRUE(d.IsObject());
143 EXPECT_EQ(5, d.MemberCount());
153 ASSERT_TRUE(
Open(ifs,
"utf16bebom.json"));
154 ifs.imbue(std::locale(ifs.getloc(),
155 new std::codecvt_utf16<wchar_t, 0x10ffff, std::consume_header>));
160 EXPECT_TRUE(d.IsObject());
161 EXPECT_EQ(5, d.MemberCount());
166 ASSERT_TRUE(
Open(fs,
"utf16bebom.json"));
167 fs.imbue(std::locale(fs.getloc(),
168 new std::codecvt_utf16<wchar_t, 0x10ffff, std::consume_header>));
173 EXPECT_TRUE(d.IsObject());
174 EXPECT_EQ(5, d.MemberCount());
Default parse flags. Can be customized by defining RAPIDJSON_PARSE_DEFAULT_FLAGS. ...
static bool Open(FileStreamType &fs, const char *filename)
static void TestStringStream()
Wrapper of std::basic_istream into RapidJSON's Stream concept.
TEST(IStreamWrapper, istringstream)
bool HasParseError() const
Whether a parse error has occured in the last parsing.
GenericDocument & ParseStream(InputStream &is)
Parse JSON text from an input stream (with Encoding conversion)