MCPcopy Create free account
hub / github.com/Tencent/rapidjson / ParseTest

Function ParseTest

test/unittest/documenttest.cpp:79–118  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

77
78template <typename Allocator, typename StackAllocator>
79void ParseTest() {
80 typedef GenericDocument<UTF8<>, Allocator, StackAllocator> DocumentType;
81 DocumentType doc;
82
83 const char* json = " { \"hello\" : \"world\", \"t\" : true , \"f\" : false, \"n\": null, \"i\":123, \"pi\": 3.1416, \"a\":[1, 2, 3, 4] } ";
84
85 doc.Parse(json);
86 ParseCheck(doc);
87
88 doc.SetNull();
89 StringStream s(json);
90 doc.template ParseStream<0>(s);
91 ParseCheck(doc);
92
93 doc.SetNull();
94 char *buffer = strdup(json);
95 doc.ParseInsitu(buffer);
96 ParseCheck(doc);
97 free(buffer);
98
99 // Parse(const Ch*, size_t)
100 size_t length = strlen(json);
101 buffer = reinterpret_cast<char*>(malloc(length * 2));
102 memcpy(buffer, json, length);
103 memset(buffer + length, 'X', length);
104#if RAPIDJSON_HAS_STDSTRING
105 std::string s2(buffer, length); // backup buffer
106#endif
107 doc.SetNull();
108 doc.Parse(buffer, length);
109 free(buffer);
110 ParseCheck(doc);
111
112#if RAPIDJSON_HAS_STDSTRING
113 // Parse(std::string)
114 doc.SetNull();
115 doc.Parse(s2);
116 ParseCheck(doc);
117#endif
118}
119
120TEST(Document, Parse) {
121 ParseTest<MemoryPoolAllocator<>, CrtAllocator>();

Callers

nothing calls this directly

Calls 2

ParseCheckFunction · 0.85
ParseMethod · 0.45

Tested by

no test coverage detected