25 RAPIDJSON_DIAG_OFF(c++98-compat)
31 StringStream s(
"{ \"hello\" : \"world\", \"t\" : true , \"f\" : false, \"n\": null, \"i\":123, \"pi\": 3.1416, \"a\":[1, 2, 3] } ");
36 reader.
Parse<0>(s, writer);
37 EXPECT_STREQ(
"{\"hello\":\"world\",\"t\":true,\"f\":false,\"n\":null,\"i\":123,\"pi\":3.1416,\"a\":[1,2,3]}", buffer.
GetString());
38 EXPECT_EQ(77u, buffer.
GetSize());
43 #define TEST_ROUNDTRIP(json) \ 45 StringStream s(json); \ 46 StringBuffer buffer; \ 47 Writer<StringBuffer> writer(buffer); \ 49 reader.Parse<kParseFullPrecisionFlag>(s, writer); \ 50 EXPECT_STREQ(json, buffer.GetString()); \ 51 EXPECT_TRUE(writer.IsComplete()); \ 93 #if RAPIDJSON_HAS_STDSTRING 97 writer.
String(std::string(
"Hello\n"));
98 EXPECT_STREQ(
"\"Hello\\n\"", buffer.
GetString());
104 char buf[100] =
"Hello";
112 EXPECT_STREQ(
"[\"Hello\"]", buffer.
GetString());
117 const char json[] =
"[\" \\\"0123456789ABCDEF\"]";
119 char buffer2[
sizeof(
json) + 32];
122 for (
int i = 0; i < 32; i++) {
123 char* p = buffer2 + i;
124 memcpy(p, json,
sizeof(json));
143 template <
typename TargetEncoding>
149 reader.
Parse(s, writer);
155 reader2.
Parse(s2, writer2);
161 const char json[] =
"{\"hello\":\"world\",\"t\":true,\"f\":false,\"n\":null,\"i\":123,\"pi\":3.1416,\"a\":[1,2,3],\"dollar\":\"\x24\",\"cents\":\"\xC2\xA2\",\"euro\":\"\xE2\x82\xAC\",\"gclef\":\"\xF0\x9D\x84\x9E\"}";
164 TestTranscode<UTF8<> >(
json);
167 TestTranscode<ASCII<> >(
json);
170 TestTranscode<UTF16<> >(
json);
173 TestTranscode<UTF32<> >(
json);
177 for (
size_t i = 0; i < 5; i++) {
183 reader.
Parse(s, writer);
190 reader2.
Parse(is, writer2);
205 Ch
Peek()
const { assert(
false);
return '\0'; }
206 Ch
Take() { assert(
false);
return '\0'; }
207 size_t Tell()
const {
return 0; }
210 void Put(Ch c) { os_.put(c); }
212 size_t PutEnd(Ch*) { assert(
false);
return 0; }
222 StringStream s(
"{ \"hello\" : \"world\", \"t\" : true , \"f\" : false, \"n\": null, \"i\":123, \"pi\": 3.1416, \"a\":[1, 2, 3], \"u64\": 1234567890123456789, \"i64\":-1234567890123456789 } ");
224 std::stringstream ss;
230 reader.
Parse<0>(s, writer);
232 std::string actual = ss.str();
233 EXPECT_STREQ(
"{\"hello\":\"world\",\"t\":true,\"f\":false,\"n\":null,\"i\":123,\"pi\":3.1416,\"a\":[1,2,3],\"u64\":1234567890123456789,\"i64\":-1234567890123456789}", actual.c_str());
239 StringBuffer buffer;\ 240 Writer<StringBuffer> writer(buffer);\ 243 T(writer.Bool(
false));
244 T(writer.Bool(
true));
251 T(writer.String(
"foo"));
288 StringBuffer buffer;\ 289 Writer<StringBuffer> writer(buffer);\ 290 writer.StartObject();\ 291 ASSERT_THROW(x, AssertException); \ 293 T(writer.Bool(
false));
294 T(writer.Bool(
true));
301 T(writer.StartObject());
302 T(writer.StartArray());
314 writer.
Reset(buffer);
318 writer.
Reset(buffer);
322 writer.
Reset(buffer);
359 StringBuffer buffer;\ 360 Writer<StringBuffer> writer(buffer);\ 361 EXPECT_FALSE(writer.IsComplete()); \ 363 EXPECT_TRUE(writer.IsComplete()); \ 366 T(writer.Bool(
true));
367 T(writer.Bool(
false));
373 T(writer.String(
""));
383 EXPECT_FALSE(writer.
String(
"\xfe"));
384 EXPECT_FALSE(writer.
String(
"\xff"));
385 EXPECT_FALSE(writer.
String(
"\xfe\xfe\xff\xff"));
394 EXPECT_FALSE(writer.
String(s));
402 EXPECT_FALSE(writer.
String(s));
411 EXPECT_TRUE(writer.
String(
"\x24"));
412 EXPECT_TRUE(writer.
String(
"\xC2\xA2"));
413 EXPECT_TRUE(writer.
String(
"\xE2\x82\xAC"));
414 EXPECT_TRUE(writer.
String(
"\xF0\x9D\x84\x9E"));
415 EXPECT_TRUE(writer.
String(
"\x01"));
416 EXPECT_TRUE(writer.
String(
"\x1B"));
418 EXPECT_STREQ(
"[\"\x24\",\"\xC2\xA2\",\"\xE2\x82\xAC\",\"\xF0\x9D\x84\x9E\",\"\\u0001\",\"\\u001B\"]", buffer.
GetString());
426 EXPECT_FALSE(writer.
String(
"\xfe"));
427 EXPECT_FALSE(writer.
String(
"\xff"));
428 EXPECT_FALSE(writer.
String(
"\xfe\xfe\xff\xff"));
485 double nan = std::numeric_limits<double>::quiet_NaN();
491 EXPECT_FALSE(writer.
Double(nan));
495 EXPECT_TRUE(writer.
Double(nan));
500 EXPECT_FALSE(writer2.
Double(nan));
504 double inf = std::numeric_limits<double>::infinity();
510 EXPECT_FALSE(writer.
Double(inf));
514 EXPECT_FALSE(writer.
Double(-inf));
518 EXPECT_TRUE(writer.
Double(inf));
522 EXPECT_TRUE(writer.
Double(-inf));
524 EXPECT_STREQ(
"Infinity-Infinity", buffer.
GetString());
534 const char json[] =
"[\"Hello\\nWorld\", 123.456]";
538 EXPECT_STREQ(
"{\"a\":1,\"raw\":[\"Hello\\nWorld\", 123.456]}", buffer.
GetString());
541 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS 555 EXPECT_STREQ(
"{\"a\":1}", buffer.
GetString());
void TestTranscode(const char *json)
size_t GetSize() const
Get the size of string in bytes in the string buffer.
bool EndArray(SizeType elementCount=0)
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text.
bool EndObject(SizeType memberCount=0)
UTFType
Runtime-specified UTF encoding type of a stream.
Represents an in-memory input byte stream.
const Ch * GetString() const
Represents an in-memory output byte stream.
bool RawValue(const Ch *json, size_t length, Type type)
Write a raw JSON value.
bool Double(double d)
Writes the given double value to the stream.
Validate encoding of JSON strings.
OStreamWrapper(std::ostream &os)
Output stream wrapper with dynamically bound encoding and automatic encoding detection.
bool String(const Ch *str, SizeType length, bool copy=false)
BasicOStreamWrapper< std::ostream > OStreamWrapper
const Ch * GetBuffer() const
bool Key(const Ch *str, SizeType length, bool copy=false)
#define TEST_ROUNDTRIP(json)
C-runtime library allocator.
bool IsComplete() const
Checks whether the output is a complete JSON.
void Reset(OutputStream &os)
Reset the writer with a new stream.
Allow writing of Infinity, -Infinity and NaN.