Go to the source code of this file.
|
| template<typename DocumentType > |
| void | ParseCheck (DocumentType &doc) |
| |
| template<typename Allocator , typename StackAllocator > |
| void | ParseTest () |
| |
| | TEST (Document, Parse) |
| |
| | TEST (Document, UnchangedOnParseError) |
| |
| | TEST (Document, Parse_Encoding) |
| |
| | TEST (Document, ParseStream_EncodedInputStream) |
| |
| | TEST (Document, ParseStream_AutoUTFInputStream) |
| |
| | TEST (Document, Swap) |
| |
| | TEST (Document, AcceptWriter) |
| |
| | TEST (Document, UserBuffer) |
| |
| | TEST (Document, AssertAcceptInvalidNameType) |
| |
| | TEST (Document, UTF16_Document) |
| |
◆ ParseCheck()
template<typename DocumentType >
| void ParseCheck |
( |
DocumentType & |
doc | ) |
|
Definition at line 33 of file documenttest.cpp.
34 typedef typename DocumentType::ValueType ValueType;
37 if (doc.HasParseError())
38 printf(
"Error: %d at %zu\n", static_cast<int>(doc.GetParseError()), doc.GetErrorOffset());
44 const ValueType& hello = doc[
"hello"];
49 const ValueType& t = doc[
"t"];
53 const ValueType& f = doc[
"f"];
57 const ValueType& n = doc[
"n"];
61 const ValueType& i = doc[
"i"];
66 const ValueType& pi = doc[
"pi"];
71 const ValueType&
a = doc[
"a"];
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
#define EXPECT_TRUE(condition)
#define EXPECT_STREQ(s1, s2)
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
#define EXPECT_DOUBLE_EQ(val1, val2)
#define EXPECT_FALSE(condition)
#define EXPECT_EQ(val1, val2)
◆ ParseTest()
template<typename Allocator , typename StackAllocator >
Definition at line 79 of file documenttest.cpp.
83 const char*
json =
" { \"hello\" : \"world\", \"t\" : true , \"f\" : false, \"n\": null, \"i\":123, \"pi\": 3.1416, \"a\":[1, 2, 3, 4] } ";
90 doc.template ParseStream<0>(s);
94 char *buffer = strdup(
json);
95 doc.ParseInsitu(buffer);
100 size_t length = strlen(
json);
101 buffer =
reinterpret_cast<char*
>(malloc(length * 2));
103 memset(buffer + length,
'X', length);
104 #if RAPIDJSON_HAS_STDSTRING 108 doc.Parse(buffer, length);
112 #if RAPIDJSON_HAS_STDSTRING
void ParseCheck(DocumentType &doc)
void * memcpy(void *a, const void *b, size_t c)
Concept for allocating, resizing and freeing memory block.
A document for parsing JSON text as DOM.
◆ TEST() [1/10]
Definition at line 120 of file documenttest.cpp.
123 ParseTest<CrtAllocator, MemoryPoolAllocator<> >();
124 ParseTest<CrtAllocator, CrtAllocator>();
C-runtime library allocator.
◆ TEST() [2/10]
| TEST |
( |
Document |
, |
|
|
UnchangedOnParseError |
|
|
) |
| |
Definition at line 127 of file documenttest.cpp.
144 err = doc.
Parse(
"{}");
ParseErrorCode GetParseError() const
Get the ParseErrorCode of last parsing.
#define EXPECT_TRUE(condition)
ParseErrorCode Code() const
Get the error code.
size_t GetErrorOffset() const
Get the position of last parsing error in input, 0 otherwise.
Allocator & GetAllocator()
Get the allocator of this document.
bool HasParseError() const
Whether a parse error has occurred in the last parsing.
#define EXPECT_NE(val1, val2)
GenericDocument & Parse(const typename SourceEncoding::Ch *str)
Parse JSON text from a read-only string (with Encoding conversion)
Result of parsing (wraps ParseErrorCode)
#define EXPECT_FALSE(condition)
#define EXPECT_EQ(val1, val2)
size_t Offset() const
Get the error offset, if IsError(), 0 otherwise.
◆ TEST() [3/10]
Definition at line 174 of file documenttest.cpp.
175 const char*
json =
" { \"hello\" : \"world\", \"t\" : true , \"f\" : false, \"n\": null, \"i\":123, \"pi\": 3.1416, \"a\":[1, 2, 3, 4] } ";
186 size_t length = strlen(
json);
187 char* buffer =
reinterpret_cast<char*
>(malloc(length * 2));
189 memset(buffer + length,
'X', length);
190 #if RAPIDJSON_HAS_STDSTRING 197 if (doc.HasParseError())
198 printf(
"Error: %d at %zu\n", static_cast<int>(doc.GetParseError()), doc.GetErrorOffset());
201 #if RAPIDJSON_HAS_STDSTRING 205 #if defined(_MSC_VER) && _MSC_VER < 1800
Default parse flags. Can be customized by defining RAPIDJSON_PARSE_DEFAULT_FLAGS. ...
int StrCmp(const Ch *s1, const Ch *s2)
void * memcpy(void *a, const void *b, size_t c)
#define EXPECT_FALSE(condition)
#define EXPECT_EQ(val1, val2)
A document for parsing JSON text as DOM.
◆ TEST() [4/10]
| TEST |
( |
Document |
, |
|
|
ParseStream_EncodedInputStream |
|
|
) |
| |
Definition at line 215 of file documenttest.cpp.
217 FILE* fp = OpenEncodedFile(
"utf8.json");
228 wchar_t expected[] = L
"I can eat glass and it doesn't hurt me.";
231 EXPECT_EQ(
sizeof(expected) /
sizeof(
wchar_t) - 1, v.GetStringLength());
237 OutputStream eos(bos,
false);
244 fp = OpenEncodedFile(
"utf8.json");
249 reader.
Parse(is, writer2);
#define EXPECT_TRUE(condition)
Output byte stream wrapper with statically bound encoding.
size_t GetSize() const
Get the size of string in bytes in the string buffer.
Represents a JSON value. Use Value for UTF8 encoding and default allocator.
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text.
File byte stream for input using fread().
bool HasParseError() const
Whether a parse error has occurred in the last parsing.
int StrCmp(const Ch *s1, const Ch *s2)
const Ch * GetString() const
#define EXPECT_FALSE(condition)
GenericDocument & ParseStream(InputStream &is)
Parse JSON text from an input stream (with Encoding conversion)
#define EXPECT_EQ(val1, val2)
A document for parsing JSON text as DOM.
◆ TEST() [5/10]
| TEST |
( |
Document |
, |
|
|
ParseStream_AutoUTFInputStream |
|
|
) |
| |
Definition at line 256 of file documenttest.cpp.
258 FILE* fp = OpenEncodedFile(
"utf32be.json");
269 char expected[] =
"I can eat glass and it doesn't hurt me.";
272 EXPECT_EQ(
sizeof(expected) - 1, v.GetStringLength());
281 fp = OpenEncodedFile(
"utf8.json");
286 reader.
Parse(is, writer2);
#define EXPECT_TRUE(condition)
size_t GetSize() const
Get the size of string in bytes in the string buffer.
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text.
File byte stream for input using fread().
bool HasParseError() const
Whether a parse error has occurred in the last parsing.
int StrCmp(const Ch *s1, const Ch *s2)
const Ch * GetString() const
#define EXPECT_FALSE(condition)
GenericDocument & ParseStream(InputStream &is)
Parse JSON text from an input stream (with Encoding conversion)
#define EXPECT_EQ(val1, val2)
◆ TEST() [6/10]
Definition at line 293 of file documenttest.cpp.
297 d1.SetArray().PushBack(1,
a).PushBack(2,
a);
300 o.SetObject().AddMember(
"a", 1,
a);
317 d2.SetArray().PushBack(3,
a);
GenericDocument & Swap(GenericDocument &rhs) RAPIDJSON_NOEXCEPT
Exchange the contents of this document with those of another.
#define EXPECT_TRUE(condition)
Allocator & GetAllocator()
Get the allocator of this document.
GenericValue< UTF8<> > Value
GenericValue with UTF8 encoding.
GenericDocument< UTF8<> > Document
GenericDocument with UTF8 encoding.
#define EXPECT_NE(val1, val2)
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
#define EXPECT_EQ(val1, val2)
◆ TEST() [7/10]
Definition at line 359 of file documenttest.cpp.
361 doc.
Parse(
" { \"hello\" : \"world\", \"t\" : true , \"f\" : false, \"n\": null, \"i\":123, \"pi\": 3.1416, \"a\":[1, 2, 3, 4] } ");
367 EXPECT_EQ(
"{\"hello\":\"world\",\"t\":true,\"f\":false,\"n\":null,\"i\":123,\"pi\":3.1416,\"a\":[1,2,3,4]}", os.str());
GenericDocument & Parse(const typename SourceEncoding::Ch *str)
Parse JSON text from a read-only string (with Encoding conversion)
#define EXPECT_EQ(val1, val2)
◆ TEST() [8/10]
Definition at line 370 of file documenttest.cpp.
372 char valueBuffer[4096];
373 char parseBuffer[1024];
376 DocumentType doc(&valueAllocator,
sizeof(parseBuffer) / 2, &parseAllocator);
377 doc.Parse(
" { \"hello\" : \"world\", \"t\" : true , \"f\" : false, \"n\": null, \"i\":123, \"pi\": 3.1416, \"a\":[1, 2, 3, 4] } ");
379 EXPECT_LE(valueAllocator.Size(),
sizeof(valueBuffer));
380 EXPECT_LE(parseAllocator.Size(),
sizeof(parseBuffer));
383 EXPECT_LE(valueAllocator.Size(), valueAllocator.Capacity());
384 EXPECT_LE(parseAllocator.Size(), parseAllocator.Capacity());
#define EXPECT_LE(val1, val2)
#define EXPECT_FALSE(condition)
A document for parsing JSON text as DOM.
◆ TEST() [9/10]
| TEST |
( |
Document |
, |
|
|
AssertAcceptInvalidNameType |
|
|
) |
| |
Definition at line 388 of file documenttest.cpp.
392 doc.FindMember(
"a")->name.SetNull();
Allocator & GetAllocator()
Get the allocator of this document.
#define ASSERT_THROW(statement, expected_exception)
◆ TEST() [10/10]
Definition at line 400 of file documenttest.cpp.
411 EXPECT_EQ(0, memcmp(L
"Wed Oct 30 17:13:20 +0000 2012", s.GetString(), (s.GetStringLength() + 1) *
sizeof(
wchar_t)));
Represents a JSON value. Use Value for UTF8 encoding and default allocator.
#define ASSERT_TRUE(condition)
Validate encoding of JSON strings.
#define EXPECT_EQ(val1, val2)
A document for parsing JSON text as DOM.