Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
readertest.cpp File Reference
#include "unittest.h"
#include "rapidjson/reader.h"
#include "rapidjson/internal/dtoa.h"
#include "rapidjson/internal/itoa.h"
#include "rapidjson/memorystream.h"
#include <limits>
#include <sstream>
Include dependency graph for readertest.cpp:

Go to the source code of this file.

Classes

struct  ParseBoolHandler< expect >
 
struct  ParseIntHandler
 
struct  ParseUintHandler
 
struct  ParseInt64Handler
 
struct  ParseUint64Handler
 
struct  ParseDoubleHandler
 
struct  ParseStringHandler< Encoding >
 
struct  ParseArrayHandler< count >
 
struct  ParseObjectHandler
 
struct  ParseEmptyObjectHandler
 
struct  ParseMultipleRootHandler
 
class  CustomStringStream< Encoding >
 
class  IStreamWrapper
 
struct  IterativeParsingReaderHandler< Encoding >
 
struct  HandlerTerminateAtStartObject
 
struct  HandlerTerminateAtStartArray
 
struct  HandlerTerminateAtEndObject
 
struct  HandlerTerminateAtEndArray
 
struct  TerminateHandler< e >
 
struct  NumbersAsStringsHandler
 

Macros

#define TEST_INTEGER(Handler, str, x)
 
#define TEST_DOUBLE(fullPrecision, str, x)
 
#define TEST_NUMBER_ERROR(errorCode, str, errorOffset, streamPos)
 
#define TEST_STRING(Encoding, e, x)
 
#define ARRAY(...)
 
#define TEST_STRINGARRAY(Encoding, utype, array, x)
 
#define TEST_STRINGARRAY2(Encoding, utype, earray, xarray)
 
#define TEST_STRING_ERROR(errorCode, str, errorOffset, streamPos)
 
#define ARRAY(...)
 
#define TEST_STRINGENCODING_ERROR(Encoding, TargetEncoding, utype, array)
 
#define TEST_ARRAY_ERROR(errorCode, str, errorOffset)
 
#define TEST_ERROR(errorCode, str, errorOffset)
 
#define TESTERRORHANDLING(text, errorCode, offset)
 
#define TEST_TERMINATION(e, json)
 
#define TEST_NAN_INF(str, x)
 
#define TEST_NAN_INF_ERROR(errorCode, str, errorOffset)
 

Functions

 TEST (Reader, ParseTrue)
 
 TEST (Reader, ParseFalse)
 
 TEST (Reader, ParseNumber_Integer)
 
 TEST (Reader, ParseNumber_NormalPrecisionDouble)
 
 TEST (Reader, ParseNumber_FullPrecisionDouble)
 
 TEST (Reader, ParseNumber_NormalPrecisionError)
 
 TEST (Reader, ParseNumberError_NormalPrecisionDouble)
 
 TEST (Reader, ParseNumberError_FullPrecisionDouble)
 
 TEST (Reader, ParseString)
 
 TEST (Reader, ParseString_Transcoding)
 
 TEST (Reader, ParseString_TranscodingWithValidation)
 
 TEST (Reader, ParseString_NonDestructive)
 
template<typename Encoding >
ParseErrorCode TestString (const typename Encoding::Ch *str)
 
 TEST (Reader, ParseString_Error)
 
 TEST (Reader, ParseEmptyArray)
 
 TEST (Reader, ParseArray)
 
 TEST (Reader, ParseArray_Error)
 
 TEST (Reader, ParseObject)
 
 TEST (Reader, Parse_EmptyObject)
 
template<unsigned parseFlags>
void TestMultipleRoot ()
 
 TEST (Reader, Parse_MultipleRoot)
 
 TEST (Reader, ParseIterative_MultipleRoot)
 
template<unsigned parseFlags>
void TestInsituMultipleRoot ()
 
 TEST (Reader, ParseInsitu_MultipleRoot)
 
 TEST (Reader, ParseInsituIterative_MultipleRoot)
 
 TEST (Reader, ParseDocument_Error)
 
 TEST (Reader, ParseValue_Error)
 
 TEST (Reader, ParseObject_Error)
 
 TEST (Reader, SkipWhitespace)
 
 TEST (Reader, CustomStringStream)
 
 TEST (Reader, Parse_IStreamWrapper_StringStream)
 
 TEST (Reader, IterativeParsing_ErrorHandling)
 
 TEST (Reader, IterativeParsing_General)
 
 TEST (Reader, IterativeParsing_Count)
 
 TEST (Reader, IterativePullParsing_General)
 
 TEST (Reader, IterativeParsing_ShortCircuit)
 
 TEST (Reader, BaseReaderHandler_Default)
 
 TEST (Reader, ParseTerminationByHandler)
 
 TEST (Reader, ParseComments)
 
 TEST (Reader, ParseEmptyInlineComment)
 
 TEST (Reader, ParseEmptyOnelineComment)
 
 TEST (Reader, ParseMultipleCommentsInARow)
 
 TEST (Reader, InlineCommentsAreDisabledByDefault)
 
 TEST (Reader, OnelineCommentsAreDisabledByDefault)
 
 TEST (Reader, EofAfterOneLineComment)
 
 TEST (Reader, IncompleteMultilineComment)
 
 TEST (Reader, IncompleteMultilineComment2)
 
 TEST (Reader, UnrecognizedComment)
 
 TEST (Reader, NumbersAsStrings)
 
template<unsigned extraFlags>
void TestTrailingCommas ()
 
 TEST (Reader, TrailingCommas)
 
 TEST (Reader, TrailingCommasIterative)
 
template<unsigned extraFlags>
void TestMultipleTrailingCommaErrors ()
 
 TEST (Reader, MultipleTrailingCommaErrors)
 
 TEST (Reader, MultipleTrailingCommaErrorsIterative)
 
template<unsigned extraFlags>
void TestEmptyExceptForCommaErrors ()
 
 TEST (Reader, EmptyExceptForCommaErrors)
 
 TEST (Reader, EmptyExceptForCommaErrorsIterative)
 
template<unsigned extraFlags>
void TestTrailingCommaHandlerTermination ()
 
 TEST (Reader, TrailingCommaHandlerTermination)
 
 TEST (Reader, TrailingCommaHandlerTerminationIterative)
 
 TEST (Reader, ParseNanAndInfinity)
 

Macro Definition Documentation

◆ ARRAY [1/2]

#define ARRAY ( ...)
Value:
{ __VA_ARGS__ }

◆ ARRAY [2/2]

#define ARRAY ( ...)
Value:
{ __VA_ARGS__ }

◆ TEST_ARRAY_ERROR

#define TEST_ARRAY_ERROR ( errorCode,
str,
errorOffset )
Value:
{ \
unsigned streamPos = errorOffset; \
char buffer[1001]; \
strncpy(buffer, str, 1000); \
InsituStringStream s(buffer); \
EXPECT_FALSE(reader.Parse(s, h)); \
EXPECT_EQ(errorCode, reader.GetParseErrorCode());\
EXPECT_EQ(errorOffset, reader.GetErrorOffset());\
EXPECT_EQ(streamPos, s.Tell());\
}
C-runtime library allocator.
Definition allocators.h:75
SAX-style JSON parser. Use Reader for UTF8 encoding and default allocator.
Definition reader.h:537
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text.
Definition reader.h:557
ParseErrorCode GetParseErrorCode() const
Get the ParseErrorCode of last parsing.
Definition reader.h:683
size_t GetErrorOffset() const
Get the position of last parsing error in input, 0 otherwise.
Definition reader.h:686
Default implementation of Handler.
Definition reader.h:196
UTF-8 encoding.
Definition encodings.h:96
char * s

◆ TEST_DOUBLE

#define TEST_DOUBLE ( fullPrecision,
str,
x )
Value:
{ \
StringStream s(str); \
Reader reader; \
ASSERT_EQ(kParseErrorNone, reader.Parse<fullPrecision ? kParseFullPrecisionFlag : 0>(s, h).Code()); \
EXPECT_EQ(1u, h.step_); \
if (fullPrecision) { \
EXPECT_EQ(e.Uint64Value(), a.Uint64Value()); \
if (e.Uint64Value() != a.Uint64Value()) \
printf(" String: %s\n Actual: %.17g\nExpected: %.17g\n", str, h.actual_, x); \
} \
else { \
EXPECT_EQ(e.Sign(), a.Sign()); /* for 0.0 != -0.0 */ \
EXPECT_DOUBLE_EQ(x, h.actual_); \
} \
}
@ kParseErrorNone
No error.
Definition error.h:65
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1181
@ kParseFullPrecisionFlag
Parse number in full precision (but slower).
Definition reader.h:151
Read-only string stream.
Definition stream.h:154
ParseErrorCode Code() const
Get the error code.
Definition error.h:116

◆ TEST_ERROR

#define TEST_ERROR ( errorCode,
str,
errorOffset )
Value:
{ \
unsigned streamPos = errorOffset; \
char buffer[1001]; \
strncpy(buffer, str, 1000); \
InsituStringStream s(buffer); \
Reader reader; \
EXPECT_FALSE(reader.Parse(s, h)); \
EXPECT_EQ(errorCode, reader.GetParseErrorCode());\
EXPECT_EQ(errorOffset, reader.GetErrorOffset());\
EXPECT_EQ(streamPos, s.Tell());\
}

Definition at line 1231 of file readertest.cpp.

1231#define TEST_ERROR(errorCode, str, errorOffset) \
1232 { \
1233 unsigned streamPos = errorOffset; \
1234 char buffer[1001]; \
1235 strncpy(buffer, str, 1000); \
1236 InsituStringStream s(buffer); \
1237 BaseReaderHandler<> h; \
1238 Reader reader; \
1239 EXPECT_FALSE(reader.Parse(s, h)); \
1240 EXPECT_EQ(errorCode, reader.GetParseErrorCode());\
1241 EXPECT_EQ(errorOffset, reader.GetErrorOffset());\
1242 EXPECT_EQ(streamPos, s.Tell());\
1243 }

◆ TEST_INTEGER

#define TEST_INTEGER ( Handler,
str,
x )
Value:
{ \
StringStream s(str); \
Handler h; \
Reader reader; \
reader.Parse(s, h); \
EXPECT_EQ(1u, h.step_); \
EXPECT_EQ(x, h.actual_); \
}
Concept for receiving events from GenericReader upon parsing. The functions return true if no error o...

◆ TEST_NAN_INF

#define TEST_NAN_INF ( str,
x )
Value:
{ \
{ \
StringStream s(str); \
Reader reader; \
ASSERT_EQ(kParseErrorNone, reader.Parse<kParseNanAndInfFlag>(s, h).Code()); \
EXPECT_EQ(1u, h.step_); \
EXPECT_EQ(e.IsNan(), a.IsNan()); \
EXPECT_EQ(e.IsInf(), a.IsInf()); \
if (!e.IsNan()) \
EXPECT_EQ(e.Sign(), a.Sign()); \
} \
{ \
const char* json = "{ \"naninfdouble\": " str " } "; \
StringStream s(json); \
Reader reader; \
} \
{ \
char* json = StrDup("{ \"naninfdouble\": " str " } "); \
Reader reader; \
free(json); \
} \
}
@ kParseInsituFlag
In-situ(destructive) parsing.
Definition reader.h:147
@ kParseNanAndInfFlag
Allow parsing NaN, Inf, Infinity, -Inf and -Infinity as doubles.
Definition reader.h:155
@ kParseNumbersAsStringsFlag
Parse all numbers (ints/doubles) as strings.
Definition reader.h:153
Ch * StrDup(const Ch *str)
Definition unittest.h:73

◆ TEST_NAN_INF_ERROR

#define TEST_NAN_INF_ERROR ( errorCode,
str,
errorOffset )
Value:
{ \
unsigned streamPos = errorOffset; \
char buffer[1001]; \
strncpy(buffer, str, 1000); \
InsituStringStream s(buffer); \
Reader reader; \
EXPECT_FALSE(reader.Parse<kParseNanAndInfFlag>(s, h)); \
EXPECT_EQ(errorCode, reader.GetParseErrorCode());\
EXPECT_EQ(errorOffset, reader.GetErrorOffset());\
EXPECT_EQ(streamPos, s.Tell());\
}

◆ TEST_NUMBER_ERROR

#define TEST_NUMBER_ERROR ( errorCode,
str,
errorOffset,
streamPos )
Value:
{ \
char buffer[2048]; \
ASSERT_LT(std::strlen(str), 2048u); \
sprintf(buffer, "%s", str); \
InsituStringStream s(buffer); \
Reader reader; \
EXPECT_FALSE(reader.Parse<fullPrecision ? kParseFullPrecisionFlag : 0>(s, h)); \
EXPECT_EQ(errorCode, reader.GetParseErrorCode());\
EXPECT_EQ(errorOffset, reader.GetErrorOffset());\
EXPECT_EQ(streamPos, s.Tell());\
}

◆ TEST_STRING

#define TEST_STRING ( Encoding,
e,
x )
Value:
{ \
Encoding::Ch* buffer = StrDup(x); \
EXPECT_EQ(0, StrCmp<Encoding::Ch>(e, h.str_)); \
EXPECT_EQ(StrLen(e), h.length_); \
free(buffer); \
reader2.Parse(s, h2); \
EXPECT_EQ(0, StrCmp<Encoding::Ch>(e, h2.str_)); \
EXPECT_EQ(StrLen(e), h2.length_); \
}
@ kParseValidateEncodingFlag
Validate encoding of JSON strings.
Definition reader.h:148
const Encoding::Ch * str_
unsigned StrLen(const Ch *s)
Definition unittest.h:60
int StrCmp(const Ch *s1, const Ch *s2)
Definition unittest.h:67

◆ TEST_STRING_ERROR

#define TEST_STRING_ERROR ( errorCode,
str,
errorOffset,
streamPos )
Value:
{\
EXPECT_EQ(errorCode, reader.GetParseErrorCode());\
EXPECT_EQ(errorOffset, reader.GetErrorOffset());\
EXPECT_EQ(streamPos, s.Tell());\
}

◆ TEST_STRINGARRAY

#define TEST_STRINGARRAY ( Encoding,
utype,
array,
x )
Value:
{ \
static const utype ue[] = array; \
static const Encoding::Ch* e = reinterpret_cast<const Encoding::Ch *>(&ue[0]); \
TEST_STRING(Encoding, e, x); \
}
Concept for encoding of Unicode characters.

◆ TEST_STRINGARRAY2

#define TEST_STRINGARRAY2 ( Encoding,
utype,
earray,
xarray )
Value:
{ \
static const utype ue[] = earray; \
static const utype xe[] = xarray; \
static const Encoding::Ch* e = reinterpret_cast<const Encoding::Ch *>(&ue[0]); \
static const Encoding::Ch* x = reinterpret_cast<const Encoding::Ch *>(&xe[0]); \
TEST_STRING(Encoding, e, x); \
}

◆ TEST_STRINGENCODING_ERROR

#define TEST_STRINGENCODING_ERROR ( Encoding,
TargetEncoding,
utype,
array )
Value:
{ \
static const utype ue[] = array; \
static const Encoding::Ch* e = reinterpret_cast<const Encoding::Ch *>(&ue[0]); \
/* decode error */\
reader.Parse(s, h);\
}
@ kParseErrorStringInvalidEncoding
Invalid encoding in string.
Definition error.h:82
ParseErrorCode TestString(const typename Encoding::Ch *str)

◆ TEST_TERMINATION

#define TEST_TERMINATION ( e,
json )
Value:
{\
Reader reader;\
StringStream is(json);\
EXPECT_FALSE(reader.Parse(is, h));\
}
@ kParseErrorTermination
Parsing was terminated.
Definition error.h:88

Definition at line 1727 of file readertest.cpp.

1727#define TEST_TERMINATION(e, json)\
1728{\
1729 Reader reader;\
1730 TerminateHandler<e> h;\
1731 StringStream is(json);\
1732 EXPECT_FALSE(reader.Parse(is, h));\
1733 EXPECT_EQ(kParseErrorTermination, reader.GetParseErrorCode());\
1734}

◆ TESTERRORHANDLING

#define TESTERRORHANDLING ( text,
errorCode,
offset )
Value:
{\
unsigned streamPos = offset; \
StringStream json(text); \
Reader reader; \
reader.Parse<kParseIterativeFlag>(json, handler); \
EXPECT_TRUE(reader.HasParseError()); \
EXPECT_EQ(errorCode, reader.GetParseErrorCode()); \
EXPECT_EQ(offset, reader.GetErrorOffset()); \
EXPECT_EQ(streamPos, json.Tell()); \
}
bool HasParseError() const
Whether a parse error has occurred in the last parsing.
Definition reader.h:680
@ kParseIterativeFlag
Iterative(constant complexity in terms of function call stack size) parsing.
Definition reader.h:149

Definition at line 1406 of file readertest.cpp.

1406#define TESTERRORHANDLING(text, errorCode, offset)\
1407{\
1408 unsigned streamPos = offset; \
1409 StringStream json(text); \
1410 BaseReaderHandler<> handler; \
1411 Reader reader; \
1412 reader.Parse<kParseIterativeFlag>(json, handler); \
1413 EXPECT_TRUE(reader.HasParseError()); \
1414 EXPECT_EQ(errorCode, reader.GetParseErrorCode()); \
1415 EXPECT_EQ(offset, reader.GetErrorOffset()); \
1416 EXPECT_EQ(streamPos, json.Tell()); \
1417}

Function Documentation

◆ TEST() [1/55]

TEST ( Reader ,
BaseReaderHandler_Default  )

Definition at line 1702 of file readertest.cpp.

1702 {
1704 Reader reader;
1705 StringStream is("[null, true, -1, 1, -1234567890123456789, 1234567890123456789, 3.14, \"s\", { \"a\" : 1 }]");
1706 EXPECT_TRUE(reader.Parse(is, h));
1707}
#define EXPECT_TRUE(condition)
Definition gtest.h:1895
Here is the call graph for this function:

◆ TEST() [2/55]

TEST ( Reader ,
CustomStringStream  )

Definition at line 1351 of file readertest.cpp.

1351 {
1352 const char* json = "{ \"hello\" : \"world\", \"t\" : true , \"f\" : false, \"n\": null, \"i\":123, \"pi\": 3.1416, \"a\":[1, 2, 3] } ";
1355 Reader reader;
1356 reader.Parse(s, h);
1357 EXPECT_EQ(20u, h.step_);
1358}
#define EXPECT_EQ(val1, val2)
Definition gtest.h:1954
Here is the call graph for this function:

◆ TEST() [3/55]

TEST ( Reader ,
EmptyExceptForCommaErrors  )

Definition at line 2096 of file readertest.cpp.

2096 {
2098}
void TestEmptyExceptForCommaErrors()
Here is the call graph for this function:

◆ TEST() [4/55]

TEST ( Reader ,
EmptyExceptForCommaErrorsIterative  )

Definition at line 2100 of file readertest.cpp.

Here is the call graph for this function:

◆ TEST() [5/55]

TEST ( Reader ,
EofAfterOneLineComment  )

Definition at line 1839 of file readertest.cpp.

1839 {
1840 const char* json = "{\"hello\" : \"world\" // EOF is here -->\0 \n}";
1841
1842 StringStream s(json);
1844 Reader reader;
1847}
@ kParseErrorObjectMissCommaOrCurlyBracket
Missing a comma or '}' after an object member.
Definition error.h:74
#define EXPECT_FALSE(condition)
Definition gtest.h:1898
@ kParseCommentsFlag
Allow one-line (//) and multi-line (/‍**/) comments.
Definition reader.h:152
Here is the call graph for this function:

◆ TEST() [6/55]

TEST ( Reader ,
IncompleteMultilineComment  )

Definition at line 1849 of file readertest.cpp.

1849 {
1850 const char* json = "{\"hello\" : \"world\" /* EOF is here -->\0 */}";
1851
1852 StringStream s(json);
1854 Reader reader;
1857}
@ kParseErrorUnspecificSyntaxError
Unspecific syntax error.
Definition error.h:89
Here is the call graph for this function:

◆ TEST() [7/55]

TEST ( Reader ,
IncompleteMultilineComment2  )

Definition at line 1859 of file readertest.cpp.

1859 {
1860 const char* json = "{\"hello\" : \"world\" /* *\0 */}";
1861
1862 StringStream s(json);
1864 Reader reader;
1867}
Here is the call graph for this function:

◆ TEST() [8/55]

TEST ( Reader ,
InlineCommentsAreDisabledByDefault  )

Definition at line 1807 of file readertest.cpp.

1807 {
1808 {
1809 const char* json = "{/* Inline comment. */\"hello\" : \"world\", \"t\" : true, \"f\" : false, \"n\": null, \"i\":123, \"pi\": 3.1416, \"a\":[1, 2, 3] }";
1810
1811 StringStream s(json);
1813 Reader reader;
1815 }
1816
1817 {
1818 const char* json =
1819 "{\"hello\" : /* Multiline comment starts here\n"
1820 " continues here\n"
1821 " and ends here */\"world\", \"t\" :true , \"f\" : false, \"n\": null, \"i\":123, \"pi\": 3.1416, \"a\":[1, 2, 3] }";
1822
1823 StringStream s(json);
1825 Reader reader;
1827 }
1828}
@ kParseDefaultFlags
Default parse flags. Can be customized by defining RAPIDJSON_PARSE_DEFAULT_FLAGS.
Definition reader.h:156
Here is the call graph for this function:

◆ TEST() [9/55]

TEST ( Reader ,
IterativeParsing_Count  )

Definition at line 1554 of file readertest.cpp.

1554 {
1555 {
1556 StringStream is("[{}, {\"k\": 1}, [1], []]");
1557 Reader reader;
1559
1560 ParseResult r = reader.Parse<kParseIterativeFlag>(is, handler);
1561
1562 EXPECT_FALSE(r.IsError());
1563 EXPECT_FALSE(reader.HasParseError());
1564
1565 uint32_t e[] = {
1566 handler.LOG_STARTARRAY,
1567 handler.LOG_STARTOBJECT,
1568 handler.LOG_ENDOBJECT | 0,
1569 handler.LOG_STARTOBJECT,
1570 handler.LOG_KEY,
1571 handler.LOG_INT,
1572 handler.LOG_ENDOBJECT | 1,
1573 handler.LOG_STARTARRAY,
1574 handler.LOG_INT,
1575 handler.LOG_ENDARRAY | 1,
1576 handler.LOG_STARTARRAY,
1577 handler.LOG_ENDARRAY | 0,
1578 handler.LOG_ENDARRAY | 4
1579 };
1580
1581 EXPECT_EQ(sizeof(e) / sizeof(int), handler.LogCount);
1582
1583 for (size_t i = 0; i < handler.LogCount; ++i) {
1584 EXPECT_EQ(e[i], handler.Logs[i]) << "i = " << i;
1585 }
1586 }
1587}
const mie::Vuint & r
Definition bn.cpp:28
unsigned int uint32_t
Definition stdint.h:126
static const uint32_t LOG_INT
uint32_t Logs[LogCapacity]
static const uint32_t LOG_KEY
static const uint32_t LOG_ENDOBJECT
static const uint32_t LOG_STARTOBJECT
static const uint32_t LOG_STARTARRAY
static const uint32_t LOG_ENDARRAY
Result of parsing (wraps ParseErrorCode)
Definition error.h:106
Here is the call graph for this function:

◆ TEST() [10/55]

TEST ( Reader ,
IterativeParsing_ErrorHandling  )

Definition at line 1419 of file readertest.cpp.

1419 {
1420 TESTERRORHANDLING("{\"a\": a}", kParseErrorValueInvalid, 6u);
1421
1424
1437
1438 // Trailing commas are not allowed without kParseTrailingCommasFlag
1439 TESTERRORHANDLING("{\"a\": 1,}", kParseErrorObjectMissName, 8u);
1441
1442 // Any JSON value can be a valid root element in RFC7159.
1451}
@ kParseErrorDocumentEmpty
The document is empty.
Definition error.h:67
@ kParseErrorValueInvalid
Invalid value.
Definition error.h:70
@ kParseErrorDocumentRootNotSingular
The document root must not follow by other values.
Definition error.h:68
@ kParseErrorObjectMissColon
Missing a colon after a name of object member.
Definition error.h:73
@ kParseErrorStringMissQuotationMark
Missing a closing quotation mark in string.
Definition error.h:81
@ kParseErrorArrayMissCommaOrSquareBracket
Missing a comma or ']' after an array element.
Definition error.h:76
@ kParseErrorObjectMissName
Missing a name for object member.
Definition error.h:72
#define TESTERRORHANDLING(text, errorCode, offset)

◆ TEST() [11/55]

TEST ( Reader ,
IterativeParsing_General  )

Definition at line 1517 of file readertest.cpp.

1517 {
1518 {
1519 StringStream is("[1, {\"k\": [1, 2]}, null, false, true, \"string\", 1.2]");
1520 Reader reader;
1522
1523 ParseResult r = reader.Parse<kParseIterativeFlag>(is, handler);
1524
1525 EXPECT_FALSE(r.IsError());
1526 EXPECT_FALSE(reader.HasParseError());
1527
1528 uint32_t e[] = {
1529 handler.LOG_STARTARRAY,
1530 handler.LOG_INT,
1531 handler.LOG_STARTOBJECT,
1532 handler.LOG_KEY,
1533 handler.LOG_STARTARRAY,
1534 handler.LOG_INT,
1535 handler.LOG_INT,
1536 handler.LOG_ENDARRAY | 2,
1537 handler.LOG_ENDOBJECT | 1,
1538 handler.LOG_NULL,
1539 handler.LOG_BOOL,
1540 handler.LOG_BOOL,
1541 handler.LOG_STRING,
1542 handler.LOG_DOUBLE,
1543 handler.LOG_ENDARRAY | 7
1544 };
1545
1546 EXPECT_EQ(sizeof(e) / sizeof(int), handler.LogCount);
1547
1548 for (size_t i = 0; i < handler.LogCount; ++i) {
1549 EXPECT_EQ(e[i], handler.Logs[i]) << "i = " << i;
1550 }
1551 }
1552}
static const uint32_t LOG_DOUBLE
static const uint32_t LOG_BOOL
static const uint32_t LOG_NULL
static const uint32_t LOG_STRING
Here is the call graph for this function:

◆ TEST() [12/55]

TEST ( Reader ,
IterativeParsing_ShortCircuit  )

Definition at line 1651 of file readertest.cpp.

1651 {
1652 {
1654 Reader reader;
1655 StringStream is("[1, {}]");
1656
1657 ParseResult r = reader.Parse<kParseIterativeFlag>(is, handler);
1658
1659 EXPECT_TRUE(reader.HasParseError());
1661 EXPECT_EQ(4u, r.Offset());
1662 }
1663
1664 {
1666 Reader reader;
1667 StringStream is("{\"a\": []}");
1668
1669 ParseResult r = reader.Parse<kParseIterativeFlag>(is, handler);
1670
1671 EXPECT_TRUE(reader.HasParseError());
1673 EXPECT_EQ(6u, r.Offset());
1674 }
1675
1676 {
1678 Reader reader;
1679 StringStream is("[1, {}]");
1680
1681 ParseResult r = reader.Parse<kParseIterativeFlag>(is, handler);
1682
1683 EXPECT_TRUE(reader.HasParseError());
1685 EXPECT_EQ(5u, r.Offset());
1686 }
1687
1688 {
1690 Reader reader;
1691 StringStream is("{\"a\": []}");
1692
1693 ParseResult r = reader.Parse<kParseIterativeFlag>(is, handler);
1694
1695 EXPECT_TRUE(reader.HasParseError());
1697 EXPECT_EQ(7u, r.Offset());
1698 }
1699}
Here is the call graph for this function:

◆ TEST() [13/55]

TEST ( Reader ,
IterativePullParsing_General  )

Definition at line 1589 of file readertest.cpp.

1589 {
1590 {
1592 uint32_t e[] = {
1593 handler.LOG_STARTARRAY,
1594 handler.LOG_INT,
1595 handler.LOG_STARTOBJECT,
1596 handler.LOG_KEY,
1597 handler.LOG_STARTARRAY,
1598 handler.LOG_INT,
1599 handler.LOG_INT,
1600 handler.LOG_ENDARRAY | 2,
1601 handler.LOG_ENDOBJECT | 1,
1602 handler.LOG_NULL,
1603 handler.LOG_BOOL,
1604 handler.LOG_BOOL,
1605 handler.LOG_STRING,
1606 handler.LOG_DOUBLE,
1607 handler.LOG_ENDARRAY | 7
1608 };
1609
1610 StringStream is("[1, {\"k\": [1, 2]}, null, false, true, \"string\", 1.2]");
1611 Reader reader;
1612
1613 reader.IterativeParseInit();
1614 while (!reader.IterativeParseComplete()) {
1615 size_t oldLogCount = handler.LogCount;
1616 EXPECT_TRUE(oldLogCount < sizeof(e) / sizeof(int)) << "overrun";
1617
1618 EXPECT_TRUE(reader.IterativeParseNext<kParseDefaultFlags>(is, handler)) << "parse fail";
1619 EXPECT_EQ(handler.LogCount, oldLogCount + 1) << "handler should be invoked exactly once each time";
1620 EXPECT_EQ(e[oldLogCount], handler.Logs[oldLogCount]) << "wrong event returned";
1621 }
1622
1623 EXPECT_FALSE(reader.HasParseError());
1624 EXPECT_EQ(sizeof(e) / sizeof(int), handler.LogCount) << "handler invoked wrong number of times";
1625
1626 // The handler should not be invoked when the JSON has been fully read, but it should not fail
1627 size_t oldLogCount = handler.LogCount;
1628 EXPECT_TRUE(reader.IterativeParseNext<kParseDefaultFlags>(is, handler)) << "parse-next past complete is allowed";
1629 EXPECT_EQ(handler.LogCount, oldLogCount) << "parse-next past complete should not invoke handler";
1630 EXPECT_FALSE(reader.HasParseError()) << "parse-next past complete should not generate parse error";
1631 }
1632}
bool IterativeParseNext(InputStream &is, Handler &handler)
Parse one token from JSON text.
Definition reader.h:618
void IterativeParseInit()
Initialize JSON text token-by-token parsing.
Definition reader.h:605
RAPIDJSON_FORCEINLINE bool IterativeParseComplete() const
Check if token-by-token parsing JSON text is complete.
Definition reader.h:675
Here is the call graph for this function:

◆ TEST() [14/55]

TEST ( Reader ,
MultipleTrailingCommaErrors  )

Definition at line 2064 of file readertest.cpp.

2064 {
2066}
void TestMultipleTrailingCommaErrors()
Here is the call graph for this function:

◆ TEST() [15/55]

TEST ( Reader ,
MultipleTrailingCommaErrorsIterative  )

Definition at line 2068 of file readertest.cpp.

Here is the call graph for this function:

◆ TEST() [16/55]

TEST ( Reader ,
NumbersAsStrings  )

Definition at line 1909 of file readertest.cpp.

1909 {
1910 {
1911 const char* json = "{ \"pi\": 3.1416 } ";
1912 StringStream s(json);
1913 NumbersAsStringsHandler h("3.1416");
1914 Reader reader;
1916 }
1917 {
1918 char* json = StrDup("{ \"pi\": 3.1416 } ");
1919 InsituStringStream s(json);
1920 NumbersAsStringsHandler h("3.1416");
1921 Reader reader;
1923 free(json);
1924 }
1925 {
1926 const char* json = "{ \"gigabyte\": 1.0e9 } ";
1927 StringStream s(json);
1928 NumbersAsStringsHandler h("1.0e9");
1929 Reader reader;
1931 }
1932 {
1933 char* json = StrDup("{ \"gigabyte\": 1.0e9 } ");
1934 InsituStringStream s(json);
1935 NumbersAsStringsHandler h("1.0e9");
1936 Reader reader;
1938 free(json);
1939 }
1940 {
1941 const char* json = "{ \"pi\": 314.159e-2 } ";
1942 StringStream s(json);
1943 NumbersAsStringsHandler h("314.159e-2");
1944 Reader reader;
1946 }
1947 {
1948 char* json = StrDup("{ \"gigabyte\": 314.159e-2 } ");
1949 InsituStringStream s(json);
1950 NumbersAsStringsHandler h("314.159e-2");
1951 Reader reader;
1953 free(json);
1954 }
1955 {
1956 const char* json = "{ \"negative\": -1.54321 } ";
1957 StringStream s(json);
1958 NumbersAsStringsHandler h("-1.54321");
1959 Reader reader;
1961 }
1962 {
1963 char* json = StrDup("{ \"negative\": -1.54321 } ");
1964 InsituStringStream s(json);
1965 NumbersAsStringsHandler h("-1.54321");
1966 Reader reader;
1968 free(json);
1969 }
1970 {
1971 const char* json = "{ \"pi\": 314.159e-2 } ";
1972 std::stringstream ss(json);
1973 IStreamWrapper s(ss);
1974 NumbersAsStringsHandler h("314.159e-2");
1975 Reader reader;
1977 }
1978 {
1979 char n1e319[321]; // '1' followed by 319 '0'
1980 n1e319[0] = '1';
1981 for (int i = 1; i < 320; i++)
1982 n1e319[i] = '0';
1983 n1e319[320] = '\0';
1984 StringStream s(n1e319);
1985 NumbersAsStringsHandler h(n1e319);
1986 Reader reader;
1988 }
1989}
static const Segment ss(Segment::ss)
Here is the call graph for this function:

◆ TEST() [17/55]

TEST ( Reader ,
OnelineCommentsAreDisabledByDefault  )

Definition at line 1830 of file readertest.cpp.

1830 {
1831 const char* json = "{// One-line comment\n\"hello\" : \"world\", \"t\" : true , \"f\" : false, \"n\": null, \"i\":123, \"pi\": 3.1416, \"a\":[1, 2, 3] }";
1832
1833 StringStream s(json);
1835 Reader reader;
1837}
Here is the call graph for this function:

◆ TEST() [18/55]

TEST ( Reader ,
Parse_EmptyObject  )

Definition at line 1167 of file readertest.cpp.

1167 {
1168 StringStream s("{ } ");
1170 Reader reader;
1171 reader.Parse(s, h);
1172 EXPECT_EQ(2u, h.step_);
1173}
Here is the call graph for this function:

◆ TEST() [19/55]

TEST ( Reader ,
Parse_IStreamWrapper_StringStream  )

Definition at line 1392 of file readertest.cpp.

1392 {
1393 const char* json = "[1,2,3,4]";
1394
1395 std::stringstream ss(json);
1396 IStreamWrapper is(ss);
1397
1398 Reader reader;
1400 reader.Parse(is, h);
1401 EXPECT_FALSE(reader.HasParseError());
1402}
Here is the call graph for this function:

◆ TEST() [20/55]

TEST ( Reader ,
Parse_MultipleRoot  )

Definition at line 1200 of file readertest.cpp.

1200 {
1202}
void TestMultipleRoot()
Here is the call graph for this function:

◆ TEST() [21/55]

TEST ( Reader ,
ParseArray  )

Definition at line 1052 of file readertest.cpp.

1052 {
1053 char *json = StrDup("[1, 2, 3, 4]");
1054 InsituStringStream s(json);
1056 Reader reader;
1057 reader.Parse(s, h);
1058 EXPECT_EQ(6u, h.step_);
1059 free(json);
1060}
Here is the call graph for this function:

◆ TEST() [22/55]

TEST ( Reader ,
ParseArray_Error  )

Definition at line 1062 of file readertest.cpp.

1062 {
1063#define TEST_ARRAY_ERROR(errorCode, str, errorOffset) \
1064 { \
1065 unsigned streamPos = errorOffset; \
1066 char buffer[1001]; \
1067 strncpy(buffer, str, 1000); \
1068 InsituStringStream s(buffer); \
1069 BaseReaderHandler<> h; \
1070 GenericReader<UTF8<>, UTF8<>, CrtAllocator> reader; \
1071 EXPECT_FALSE(reader.Parse(s, h)); \
1072 EXPECT_EQ(errorCode, reader.GetParseErrorCode());\
1073 EXPECT_EQ(errorOffset, reader.GetErrorOffset());\
1074 EXPECT_EQ(streamPos, s.Tell());\
1075 }
1076
1077 // Missing a comma or ']' after an array element.
1081
1082 // Array cannot have a trailing comma (without kParseTrailingCommasFlag);
1083 // a value must follow a comma
1085
1086#undef TEST_ARRAY_ERROR
1087}
#define TEST_ARRAY_ERROR(errorCode, str, errorOffset)

◆ TEST() [23/55]

TEST ( Reader ,
ParseComments  )

Definition at line 1756 of file readertest.cpp.

1756 {
1757 const char* json =
1758 "// Here is a one-line comment.\n"
1759 "{// And here's another one\n"
1760 " /*And here's an in-line one.*/\"hello\" : \"world\","
1761 " \"t\" :/* And one with '*' symbol*/true ,"
1762 "/* A multiline comment\n"
1763 " goes here*/"
1764 " \"f\" : false, \"n\": null, \"i\":123, \"pi\": 3.1416, \"a\":[1, 2, 3]"
1765 "}/*And the last one to be sure */";
1766
1767 StringStream s(json);
1769 Reader reader;
1771 EXPECT_EQ(20u, h.step_);
1772}
Here is the call graph for this function:

◆ TEST() [24/55]

TEST ( Reader ,
ParseDocument_Error  )

Definition at line 1245 of file readertest.cpp.

1245 {
1246 // The document is empty.
1250
1251 // The document root must not follow by other values.
1256}
#define TEST_ERROR(errorCode, str, errorOffset)

◆ TEST() [25/55]

TEST ( Reader ,
ParseEmptyArray  )

Definition at line 1042 of file readertest.cpp.

1042 {
1043 char *json = StrDup("[ ] ");
1044 InsituStringStream s(json);
1046 Reader reader;
1047 reader.Parse(s, h);
1048 EXPECT_EQ(2u, h.step_);
1049 free(json);
1050}
Here is the call graph for this function:

◆ TEST() [26/55]

TEST ( Reader ,
ParseEmptyInlineComment  )

Definition at line 1774 of file readertest.cpp.

1774 {
1775 const char* json = "{/**/\"hello\" : \"world\", \"t\" : true, \"f\" : false, \"n\": null, \"i\":123, \"pi\": 3.1416, \"a\":[1, 2, 3] }";
1776
1777 StringStream s(json);
1779 Reader reader;
1781 EXPECT_EQ(20u, h.step_);
1782}
Here is the call graph for this function:

◆ TEST() [27/55]

TEST ( Reader ,
ParseEmptyOnelineComment  )

Definition at line 1784 of file readertest.cpp.

1784 {
1785 const char* json = "{//\n\"hello\" : \"world\", \"t\" : true, \"f\" : false, \"n\": null, \"i\":123, \"pi\": 3.1416, \"a\":[1, 2, 3] }";
1786
1787 StringStream s(json);
1789 Reader reader;
1791 EXPECT_EQ(20u, h.step_);
1792}
Here is the call graph for this function:

◆ TEST() [28/55]

TEST ( Reader ,
ParseFalse  )

Definition at line 60 of file readertest.cpp.

60 {
61 StringStream s("false");
63 Reader reader;
64 reader.Parse(s, h);
65 EXPECT_EQ(1u, h.step_);
66}
Here is the call graph for this function:

◆ TEST() [29/55]

TEST ( Reader ,
ParseInsitu_MultipleRoot  )

Definition at line 1223 of file readertest.cpp.

1223 {
1225}
void TestInsituMultipleRoot()
Here is the call graph for this function:

◆ TEST() [30/55]

TEST ( Reader ,
ParseInsituIterative_MultipleRoot  )

Definition at line 1227 of file readertest.cpp.

Here is the call graph for this function:

◆ TEST() [31/55]

TEST ( Reader ,
ParseIterative_MultipleRoot  )

Definition at line 1204 of file readertest.cpp.

Here is the call graph for this function:

◆ TEST() [32/55]

TEST ( Reader ,
ParseMultipleCommentsInARow  )

Definition at line 1794 of file readertest.cpp.

1794 {
1795 const char* json =
1796 "{/* first comment *//* second */\n"
1797 "/* third */ /*fourth*/// last one\n"
1798 "\"hello\" : \"world\", \"t\" : true, \"f\" : false, \"n\": null, \"i\":123, \"pi\": 3.1416, \"a\":[1, 2, 3] }";
1799
1800 StringStream s(json);
1802 Reader reader;
1804 EXPECT_EQ(20u, h.step_);
1805}
Here is the call graph for this function:

◆ TEST() [33/55]

TEST ( Reader ,
ParseNanAndInfinity  )

Definition at line 2134 of file readertest.cpp.

2134 {
2135#define TEST_NAN_INF(str, x) \
2136 { \
2137 { \
2138 StringStream s(str); \
2139 ParseDoubleHandler h; \
2140 Reader reader; \
2141 ASSERT_EQ(kParseErrorNone, reader.Parse<kParseNanAndInfFlag>(s, h).Code()); \
2142 EXPECT_EQ(1u, h.step_); \
2143 internal::Double e(x), a(h.actual_); \
2144 EXPECT_EQ(e.IsNan(), a.IsNan()); \
2145 EXPECT_EQ(e.IsInf(), a.IsInf()); \
2146 if (!e.IsNan()) \
2147 EXPECT_EQ(e.Sign(), a.Sign()); \
2148 } \
2149 { \
2150 const char* json = "{ \"naninfdouble\": " str " } "; \
2151 StringStream s(json); \
2152 NumbersAsStringsHandler h(str); \
2153 Reader reader; \
2154 EXPECT_TRUE(reader.Parse<kParseNumbersAsStringsFlag|kParseNanAndInfFlag>(s, h)); \
2155 } \
2156 { \
2157 char* json = StrDup("{ \"naninfdouble\": " str " } "); \
2158 InsituStringStream s(json); \
2159 NumbersAsStringsHandler h(str); \
2160 Reader reader; \
2161 EXPECT_TRUE(reader.Parse<kParseInsituFlag|kParseNumbersAsStringsFlag|kParseNanAndInfFlag>(s, h)); \
2162 free(json); \
2163 } \
2164 }
2165#define TEST_NAN_INF_ERROR(errorCode, str, errorOffset) \
2166 { \
2167 unsigned streamPos = errorOffset; \
2168 char buffer[1001]; \
2169 strncpy(buffer, str, 1000); \
2170 InsituStringStream s(buffer); \
2171 BaseReaderHandler<> h; \
2172 Reader reader; \
2173 EXPECT_FALSE(reader.Parse<kParseNanAndInfFlag>(s, h)); \
2174 EXPECT_EQ(errorCode, reader.GetParseErrorCode());\
2175 EXPECT_EQ(errorOffset, reader.GetErrorOffset());\
2176 EXPECT_EQ(streamPos, s.Tell());\
2177 }
2178
2179 double nan = std::numeric_limits<double>::quiet_NaN();
2180 double inf = std::numeric_limits<double>::infinity();
2181
2182 TEST_NAN_INF("NaN", nan);
2183 TEST_NAN_INF("-NaN", nan);
2184 TEST_NAN_INF("Inf", inf);
2185 TEST_NAN_INF("Infinity", inf);
2186 TEST_NAN_INF("-Inf", -inf);
2187 TEST_NAN_INF("-Infinity", -inf);
2196
2197#undef TEST_NAN_INF_ERROR
2198#undef TEST_NAN_INF
2199}
#define TEST_NAN_INF(str, x)
#define TEST_NAN_INF_ERROR(errorCode, str, errorOffset)

◆ TEST() [34/55]

TEST ( Reader ,
ParseNumber_FullPrecisionDouble  )

Definition at line 591 of file readertest.cpp.

591 {
592 TestParseDouble<true>();
593}

◆ TEST() [35/55]

TEST ( Reader ,
ParseNumber_Integer  )

Definition at line 113 of file readertest.cpp.

113 {
114#define TEST_INTEGER(Handler, str, x) \
115 { \
116 StringStream s(str); \
117 Handler h; \
118 Reader reader; \
119 reader.Parse(s, h); \
120 EXPECT_EQ(1u, h.step_); \
121 EXPECT_EQ(x, h.actual_); \
122 }
123
125 TEST_INTEGER(ParseUintHandler, "123", 123u);
126 TEST_INTEGER(ParseUintHandler, "2147483648", 2147483648u); // 2^31 - 1 (cannot be stored in int)
127 TEST_INTEGER(ParseUintHandler, "4294967295", 4294967295u);
128
129 TEST_INTEGER(ParseIntHandler, "-123", -123);
130 TEST_INTEGER(ParseIntHandler, "-2147483648", static_cast<int32_t>(0x80000000)); // -2^31 (min of int)
131
132 TEST_INTEGER(ParseUint64Handler, "4294967296", RAPIDJSON_UINT64_C2(1, 0)); // 2^32 (max of unsigned + 1, force to use uint64_t)
133 TEST_INTEGER(ParseUint64Handler, "18446744073709551615", RAPIDJSON_UINT64_C2(0xFFFFFFFF, 0xFFFFFFFF)); // 2^64 - 1 (max of uint64_t)
134
135 TEST_INTEGER(ParseInt64Handler, "-2147483649", static_cast<int64_t>(RAPIDJSON_UINT64_C2(0xFFFFFFFF, 0x7FFFFFFF))); // -2^31 -1 (min of int - 1, force to use int64_t)
136 TEST_INTEGER(ParseInt64Handler, "-9223372036854775808", static_cast<int64_t>(RAPIDJSON_UINT64_C2(0x80000000, 0x00000000))); // -2^63 (min of int64_t)
137
138 // Random test for uint32_t/int32_t
139 {
140 union {
141 uint32_t u;
142 int32_t i;
143 }u;
144 Random r;
145
146 for (unsigned i = 0; i < 100000; i++) {
147 u.u = r();
148
149 char buffer[32];
150 *internal::u32toa(u.u, buffer) = '\0';
151 TEST_INTEGER(ParseUintHandler, buffer, u.u);
152
153 if (u.i < 0) {
154 *internal::i32toa(u.i, buffer) = '\0';
155 TEST_INTEGER(ParseIntHandler, buffer, u.i);
156 }
157 }
158 }
159
160 // Random test for uint64_t/int64_t
161 {
162 union {
163 uint64_t u;
164 int64_t i;
165 }u;
166 Random r;
167
168 for (unsigned i = 0; i < 100000; i++) {
169 u.u = uint64_t(r()) << 32;
170 u.u |= r();
171
172 char buffer[32];
173 if (u.u > uint64_t(4294967295u)) {
174 *internal::u64toa(u.u, buffer) = '\0';
175 TEST_INTEGER(ParseUint64Handler, buffer, u.u);
176 }
177
178 if (u.i < -int64_t(2147483648u)) {
179 *internal::i64toa(u.i, buffer) = '\0';
180 TEST_INTEGER(ParseInt64Handler, buffer, u.i);
181 }
182 }
183 }
184#undef TEST_INTEGER
185}
char * u64toa(uint64_t value, char *buffer)
Definition itoa.h:126
char * i64toa(int64_t value, char *buffer)
Definition itoa.h:294
char * u32toa(uint32_t value, char *buffer)
Definition itoa.h:39
char * i32toa(int32_t value, char *buffer)
Definition itoa.h:115
#define RAPIDJSON_UINT64_C2(high32, low32)
Construct a 64-bit literal by a pair of 32-bit integer.
Definition rapidjson.h:289
#define TEST_INTEGER(Handler, str, x)
signed __int64 int64_t
Definition stdint.h:135
signed int int32_t
Definition stdint.h:123
unsigned __int64 uint64_t
Definition stdint.h:136
Here is the call graph for this function:

◆ TEST() [36/55]

TEST ( Reader ,
ParseNumber_NormalPrecisionDouble  )

Definition at line 587 of file readertest.cpp.

587 {
588 TestParseDouble<false>();
589}

◆ TEST() [37/55]

TEST ( Reader ,
ParseNumber_NormalPrecisionError  )

Definition at line 595 of file readertest.cpp.

595 {
596 static unsigned count = 1000000;
597 Random r;
598
599 double ulpSum = 0.0;
600 double ulpMax = 0.0;
601 for (unsigned i = 0; i < count; i++) {
603 do {
604 // Need to call r() in two statements for cross-platform coherent sequence.
605 uint64_t u = uint64_t(r()) << 32;
606 u |= uint64_t(r());
607 e = u;
608 } while (e.IsNan() || e.IsInf() || !e.IsNormal());
609
610 char buffer[32];
611 *internal::dtoa(e.Value(), buffer) = '\0';
612
613 StringStream s(buffer);
615 Reader reader;
616 ASSERT_EQ(kParseErrorNone, reader.Parse(s, h).Code());
617 EXPECT_EQ(1u, h.step_);
618
619 a = h.actual_;
620 uint64_t bias1 = e.ToBias();
621 uint64_t bias2 = a.ToBias();
622 double ulp = static_cast<double>(bias1 >= bias2 ? bias1 - bias2 : bias2 - bias1);
623 ulpMax = (std::max)(ulpMax, ulp);
624 ulpSum += ulp;
625 }
626 printf("ULP Average = %g, Max = %g \n", ulpSum / count, ulpMax);
627}
bool IsNan() const
Definition ieee754.h:41
double Value() const
Definition ieee754.h:29
bool IsNormal() const
Definition ieee754.h:44
uint64_t ToBias() const
Definition ieee754.h:49
bool IsInf() const
Definition ieee754.h:42
int * count
#define ASSERT_EQ(val1, val2)
Definition gtest.h:1988
LOGGING_API void printf(Category category, const char *format,...)
Definition Logging.cpp:30
char * dtoa(double value, char *buffer, int maxDecimalPlaces=324)
Definition dtoa.h:216
Here is the call graph for this function:

◆ TEST() [38/55]

TEST ( Reader ,
ParseNumberError_FullPrecisionDouble  )

Definition at line 751 of file readertest.cpp.

751 {
752 TestParseNumberError<true>();
753}

◆ TEST() [39/55]

TEST ( Reader ,
ParseNumberError_NormalPrecisionDouble  )

Definition at line 747 of file readertest.cpp.

747 {
748 TestParseNumberError<false>();
749}

◆ TEST() [40/55]

TEST ( Reader ,
ParseObject  )

Definition at line 1133 of file readertest.cpp.

1133 {
1134 const char* json = "{ \"hello\" : \"world\", \"t\" : true , \"f\" : false, \"n\": null, \"i\":123, \"pi\": 3.1416, \"a\":[1, 2, 3] } ";
1135
1136 // Insitu
1137 {
1138 char* json2 = StrDup(json);
1139 InsituStringStream s(json2);
1141 Reader reader;
1142 reader.Parse<kParseInsituFlag>(s, h);
1143 EXPECT_EQ(20u, h.step_);
1144 free(json2);
1145 }
1146
1147 // Normal
1148 {
1149 StringStream s(json);
1151 Reader reader;
1152 reader.Parse(s, h);
1153 EXPECT_EQ(20u, h.step_);
1154 }
1155}
Here is the call graph for this function:

◆ TEST() [41/55]

TEST ( Reader ,
ParseObject_Error  )

Definition at line 1267 of file readertest.cpp.

1267 {
1268 // Missing a name for object member.
1271 TEST_ERROR(kParseErrorObjectMissName, "{null:1}", 1u);
1272 TEST_ERROR(kParseErrorObjectMissName, "{true:1}", 1u);
1273 TEST_ERROR(kParseErrorObjectMissName, "{false:1}", 1u);
1277 TEST_ERROR(kParseErrorObjectMissName, "{xyz:1}", 1u);
1278
1279 // Missing a colon after a name of object member.
1280 TEST_ERROR(kParseErrorObjectMissColon, "{\"a\" 1}", 5u);
1281 TEST_ERROR(kParseErrorObjectMissColon, "{\"a\",1}", 4u);
1282
1283 // Must be a comma or '}' after an object member
1285
1286 // Object cannot have a trailing comma (without kParseTrailingCommasFlag);
1287 // an object member name must follow a comma
1288 TEST_ERROR(kParseErrorObjectMissName, "{\"a\":1,}", 7u);
1289
1290 // This tests that MemoryStream is checking the length in Peek().
1291 {
1292 MemoryStream ms("{\"a\"", 1);
1294 Reader reader;
1297 }
1298}
@ kParseStopWhenDoneFlag
After parsing a complete JSON root from stream, stop further processing the rest of stream....
Definition reader.h:150
Represents an in-memory input byte stream.
Here is the call graph for this function:

◆ TEST() [42/55]

TEST ( Reader ,
ParseString  )

Definition at line 782 of file readertest.cpp.

782 {
783#define TEST_STRING(Encoding, e, x) \
784 { \
785 Encoding::Ch* buffer = StrDup(x); \
786 GenericInsituStringStream<Encoding> is(buffer); \
787 ParseStringHandler<Encoding> h; \
788 GenericReader<Encoding, Encoding> reader; \
789 reader.Parse<kParseInsituFlag | kParseValidateEncodingFlag>(is, h); \
790 EXPECT_EQ(0, StrCmp<Encoding::Ch>(e, h.str_)); \
791 EXPECT_EQ(StrLen(e), h.length_); \
792 free(buffer); \
793 GenericStringStream<Encoding> s(x); \
794 ParseStringHandler<Encoding> h2; \
795 GenericReader<Encoding, Encoding> reader2; \
796 reader2.Parse(s, h2); \
797 EXPECT_EQ(0, StrCmp<Encoding::Ch>(e, h2.str_)); \
798 EXPECT_EQ(StrLen(e), h2.length_); \
799 }
800
801 // String constant L"\xXX" can only specify character code in bytes, which is not endianness-neutral.
802 // And old compiler does not support u"" and U"" string literal. So here specify string literal by array of Ch.
803 // In addition, GCC 4.8 generates -Wnarrowing warnings when character code >= 128 are assigned to signed integer types.
804 // Therefore, utype is added for declaring unsigned array, and then cast it to Encoding::Ch.
805#define ARRAY(...) { __VA_ARGS__ }
806#define TEST_STRINGARRAY(Encoding, utype, array, x) \
807 { \
808 static const utype ue[] = array; \
809 static const Encoding::Ch* e = reinterpret_cast<const Encoding::Ch *>(&ue[0]); \
810 TEST_STRING(Encoding, e, x); \
811 }
812
813#define TEST_STRINGARRAY2(Encoding, utype, earray, xarray) \
814 { \
815 static const utype ue[] = earray; \
816 static const utype xe[] = xarray; \
817 static const Encoding::Ch* e = reinterpret_cast<const Encoding::Ch *>(&ue[0]); \
818 static const Encoding::Ch* x = reinterpret_cast<const Encoding::Ch *>(&xe[0]); \
819 TEST_STRING(Encoding, e, x); \
820 }
821
822 TEST_STRING(UTF8<>, "", "\"\"");
823 TEST_STRING(UTF8<>, "Hello", "\"Hello\"");
824 TEST_STRING(UTF8<>, "Hello\nWorld", "\"Hello\\nWorld\"");
825 TEST_STRING(UTF8<>, "\"\\/\b\f\n\r\t", "\"\\\"\\\\/\\b\\f\\n\\r\\t\"");
826 TEST_STRING(UTF8<>, "\x24", "\"\\u0024\""); // Dollar sign U+0024
827 TEST_STRING(UTF8<>, "\xC2\xA2", "\"\\u00A2\""); // Cents sign U+00A2
828 TEST_STRING(UTF8<>, "\xE2\x82\xAC", "\"\\u20AC\""); // Euro sign U+20AC
829 TEST_STRING(UTF8<>, "\xF0\x9D\x84\x9E", "\"\\uD834\\uDD1E\""); // G clef sign U+1D11E
830
831 // UTF16
832 TEST_STRING(UTF16<>, L"", L"\"\"");
833 TEST_STRING(UTF16<>, L"Hello", L"\"Hello\"");
834 TEST_STRING(UTF16<>, L"Hello\nWorld", L"\"Hello\\nWorld\"");
835 TEST_STRING(UTF16<>, L"\"\\/\b\f\n\r\t", L"\"\\\"\\\\/\\b\\f\\n\\r\\t\"");
836 TEST_STRINGARRAY(UTF16<>, wchar_t, ARRAY(0x0024, 0x0000), L"\"\\u0024\"");
837 TEST_STRINGARRAY(UTF16<>, wchar_t, ARRAY(0x00A2, 0x0000), L"\"\\u00A2\""); // Cents sign U+00A2
838 TEST_STRINGARRAY(UTF16<>, wchar_t, ARRAY(0x20AC, 0x0000), L"\"\\u20AC\""); // Euro sign U+20AC
839 TEST_STRINGARRAY(UTF16<>, wchar_t, ARRAY(0xD834, 0xDD1E, 0x0000), L"\"\\uD834\\uDD1E\""); // G clef sign U+1D11E
840
841 // UTF32
842 TEST_STRINGARRAY2(UTF32<>, unsigned, ARRAY('\0'), ARRAY('\"', '\"', '\0'));
843 TEST_STRINGARRAY2(UTF32<>, unsigned, ARRAY('H', 'e', 'l', 'l', 'o', '\0'), ARRAY('\"', 'H', 'e', 'l', 'l', 'o', '\"', '\0'));
844 TEST_STRINGARRAY2(UTF32<>, unsigned, ARRAY('H', 'e', 'l', 'l', 'o', '\n', 'W', 'o', 'r', 'l', 'd', '\0'), ARRAY('\"', 'H', 'e', 'l', 'l', 'o', '\\', 'n', 'W', 'o', 'r', 'l', 'd', '\"', '\0'));
845 TEST_STRINGARRAY2(UTF32<>, unsigned, ARRAY('\"', '\\', '/', '\b', '\f', '\n', '\r', '\t', '\0'), ARRAY('\"', '\\', '\"', '\\', '\\', '/', '\\', 'b', '\\', 'f', '\\', 'n', '\\', 'r', '\\', 't', '\"', '\0'));
846 TEST_STRINGARRAY2(UTF32<>, unsigned, ARRAY(0x00024, 0x0000), ARRAY('\"', '\\', 'u', '0', '0', '2', '4', '\"', '\0'));
847 TEST_STRINGARRAY2(UTF32<>, unsigned, ARRAY(0x000A2, 0x0000), ARRAY('\"', '\\', 'u', '0', '0', 'A', '2', '\"', '\0')); // Cents sign U+00A2
848 TEST_STRINGARRAY2(UTF32<>, unsigned, ARRAY(0x020AC, 0x0000), ARRAY('\"', '\\', 'u', '2', '0', 'A', 'C', '\"', '\0')); // Euro sign U+20AC
849 TEST_STRINGARRAY2(UTF32<>, unsigned, ARRAY(0x1D11E, 0x0000), ARRAY('\"', '\\', 'u', 'D', '8', '3', '4', '\\', 'u', 'D', 'D', '1', 'E', '\"', '\0')); // G clef sign U+1D11E
850
851#undef TEST_STRINGARRAY
852#undef ARRAY
853#undef TEST_STRING
854
855 // Support of null character in string
856 {
857 StringStream s("\"Hello\\u0000World\"");
858 const char e[] = "Hello\0World";
860 Reader reader;
861 reader.Parse(s, h);
862 EXPECT_EQ(0, memcmp(e, h.str_, h.length_ + 1));
863 EXPECT_EQ(11u, h.length_);
864 }
865}
#define ARRAY(...)
#define TEST_STRING(Encoding, e, x)
#define TEST_STRINGARRAY(Encoding, utype, array, x)
#define TEST_STRINGARRAY2(Encoding, utype, earray, xarray)
UTF-16 encoding.
Definition encodings.h:269
UTF-32 encoding.
Definition encodings.h:418
Here is the call graph for this function:

◆ TEST() [43/55]

TEST ( Reader ,
ParseString_Error  )

Definition at line 907 of file readertest.cpp.

907 {
908#define TEST_STRING_ERROR(errorCode, str, errorOffset, streamPos)\
909{\
910 GenericStringStream<UTF8<> > s(str);\
911 BaseReaderHandler<UTF8<> > h;\
912 GenericReader<UTF8<> , UTF8<> > reader;\
913 reader.Parse<kParseValidateEncodingFlag>(s, h);\
914 EXPECT_EQ(errorCode, reader.GetParseErrorCode());\
915 EXPECT_EQ(errorOffset, reader.GetErrorOffset());\
916 EXPECT_EQ(streamPos, s.Tell());\
917}
918
919#define ARRAY(...) { __VA_ARGS__ }
920#define TEST_STRINGENCODING_ERROR(Encoding, TargetEncoding, utype, array) \
921 { \
922 static const utype ue[] = array; \
923 static const Encoding::Ch* e = reinterpret_cast<const Encoding::Ch *>(&ue[0]); \
924 EXPECT_EQ(kParseErrorStringInvalidEncoding, TestString<Encoding>(e));\
925 /* decode error */\
926 GenericStringStream<Encoding> s(e);\
927 BaseReaderHandler<TargetEncoding> h;\
928 GenericReader<Encoding, TargetEncoding> reader;\
929 reader.Parse(s, h);\
930 EXPECT_EQ(kParseErrorStringInvalidEncoding, reader.GetParseErrorCode());\
931 }
932
933 // Invalid escape character in string.
935
936 // Incorrect hex digit after \\u escape in string.
938
939 // Quotation in \\u escape in string (Issue #288)
941 TEST_STRING_ERROR(kParseErrorStringUnicodeEscapeInvalidHex, "[\"\\uD800\\uFFF\"]", 2u, 13u);
942
943 // The surrogate pair in string is invalid.
945 TEST_STRING_ERROR(kParseErrorStringUnicodeSurrogateInvalid, "[\"\\uD800\\uFFFF\"]", 2u, 14u);
946
947 // Missing a closing quotation mark in string.
949
950 // http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt
951
952 // 3 Malformed sequences
953
954 // 3.1 Unexpected continuation bytes
955 {
956 char e[] = { '[', '\"', 0, '\"', ']', '\0' };
957 for (unsigned char c = 0x80u; c <= 0xBFu; c++) {
958 e[2] = static_cast<char>(c);
962 std::cout << static_cast<unsigned>(c) << std::endl;
963 }
964 }
965
966 // 3.2 Lonely start characters, 3.5 Impossible bytes
967 {
968 char e[] = { '[', '\"', 0, ' ', '\"', ']', '\0' };
969 for (unsigned c = 0xC0u; c <= 0xFFu; c++) {
970 e[2] = static_cast<char>(c);
971 unsigned streamPos;
972 if (c <= 0xC1u)
973 streamPos = 3; // 0xC0 - 0xC1
974 else if (c <= 0xDFu)
975 streamPos = 4; // 0xC2 - 0xDF
976 else if (c <= 0xEFu)
977 streamPos = 5; // 0xE0 - 0xEF
978 else if (c <= 0xF4u)
979 streamPos = 6; // 0xF0 - 0xF4
980 else
981 streamPos = 3; // 0xF5 - 0xFF
983 }
984 }
985
986 // 4 Overlong sequences
987
988 // 4.1 Examples of an overlong ASCII character
989 TEST_STRINGENCODING_ERROR(UTF8<>, UTF16<>, unsigned char, ARRAY('[', '\"', 0xC0u, 0xAFu, '\"', ']', '\0'));
990 TEST_STRINGENCODING_ERROR(UTF8<>, UTF16<>, unsigned char, ARRAY('[', '\"', 0xE0u, 0x80u, 0xAFu, '\"', ']', '\0'));
991 TEST_STRINGENCODING_ERROR(UTF8<>, UTF16<>, unsigned char, ARRAY('[', '\"', 0xF0u, 0x80u, 0x80u, 0xAFu, '\"', ']', '\0'));
992
993 // 4.2 Maximum overlong sequences
994 TEST_STRINGENCODING_ERROR(UTF8<>, UTF16<>, unsigned char, ARRAY('[', '\"', 0xC1u, 0xBFu, '\"', ']', '\0'));
995 TEST_STRINGENCODING_ERROR(UTF8<>, UTF16<>, unsigned char, ARRAY('[', '\"', 0xE0u, 0x9Fu, 0xBFu, '\"', ']', '\0'));
996 TEST_STRINGENCODING_ERROR(UTF8<>, UTF16<>, unsigned char, ARRAY('[', '\"', 0xF0u, 0x8Fu, 0xBFu, 0xBFu, '\"', ']', '\0'));
997
998 // 4.3 Overlong representation of the NUL character
999 TEST_STRINGENCODING_ERROR(UTF8<>, UTF16<>, unsigned char, ARRAY('[', '\"', 0xC0u, 0x80u, '\"', ']', '\0'));
1000 TEST_STRINGENCODING_ERROR(UTF8<>, UTF16<>, unsigned char, ARRAY('[', '\"', 0xE0u, 0x80u, 0x80u, '\"', ']', '\0'));
1001 TEST_STRINGENCODING_ERROR(UTF8<>, UTF16<>, unsigned char, ARRAY('[', '\"', 0xF0u, 0x80u, 0x80u, 0x80u, '\"', ']', '\0'));
1002
1003 // 5 Illegal code positions
1004
1005 // 5.1 Single UTF-16 surrogates
1006 TEST_STRINGENCODING_ERROR(UTF8<>, UTF16<>, unsigned char, ARRAY('[', '\"', 0xEDu, 0xA0u, 0x80u, '\"', ']', '\0'));
1007 TEST_STRINGENCODING_ERROR(UTF8<>, UTF16<>, unsigned char, ARRAY('[', '\"', 0xEDu, 0xADu, 0xBFu, '\"', ']', '\0'));
1008 TEST_STRINGENCODING_ERROR(UTF8<>, UTF16<>, unsigned char, ARRAY('[', '\"', 0xEDu, 0xAEu, 0x80u, '\"', ']', '\0'));
1009 TEST_STRINGENCODING_ERROR(UTF8<>, UTF16<>, unsigned char, ARRAY('[', '\"', 0xEDu, 0xAFu, 0xBFu, '\"', ']', '\0'));
1010 TEST_STRINGENCODING_ERROR(UTF8<>, UTF16<>, unsigned char, ARRAY('[', '\"', 0xEDu, 0xB0u, 0x80u, '\"', ']', '\0'));
1011 TEST_STRINGENCODING_ERROR(UTF8<>, UTF16<>, unsigned char, ARRAY('[', '\"', 0xEDu, 0xBEu, 0x80u, '\"', ']', '\0'));
1012 TEST_STRINGENCODING_ERROR(UTF8<>, UTF16<>, unsigned char, ARRAY('[', '\"', 0xEDu, 0xBFu, 0xBFu, '\"', ']', '\0'));
1013
1014 // Malform UTF-16 sequences
1015 TEST_STRINGENCODING_ERROR(UTF16<>, UTF8<>, wchar_t, ARRAY('[', '\"', 0xDC00, 0xDC00, '\"', ']', '\0'));
1016 TEST_STRINGENCODING_ERROR(UTF16<>, UTF8<>, wchar_t, ARRAY('[', '\"', 0xD800, 0xD800, '\"', ']', '\0'));
1017
1018 // Malform UTF-32 sequence
1019 TEST_STRINGENCODING_ERROR(UTF32<>, UTF8<>, unsigned, ARRAY('[', '\"', 0x110000, '\"', ']', '\0'));
1020
1021 // Malform ASCII sequence
1022 TEST_STRINGENCODING_ERROR(ASCII<>, UTF8<>, char, ARRAY('[', '\"', char(0x80u), '\"', ']', '\0'));
1023 TEST_STRINGENCODING_ERROR(ASCII<>, UTF8<>, char, ARRAY('[', '\"', char(0x01u), '\"', ']', '\0'));
1024 TEST_STRINGENCODING_ERROR(ASCII<>, UTF8<>, char, ARRAY('[', '\"', char(0x1Cu), '\"', ']', '\0'));
1025
1026#undef ARRAY
1027#undef TEST_STRINGARRAY_ERROR
1028}
ParseErrorCode
Error code of parsing.
Definition error.h:64
@ kParseErrorStringEscapeInvalid
Invalid escape character in string.
Definition error.h:80
@ kParseErrorStringUnicodeSurrogateInvalid
The surrogate pair in string is invalid.
Definition error.h:79
@ kParseErrorStringUnicodeEscapeInvalidHex
Incorrect hex digit after \u escape in string.
Definition error.h:78
#define TEST_STRING_ERROR(errorCode, str, errorOffset, streamPos)
#define TEST_STRINGENCODING_ERROR(Encoding, TargetEncoding, utype, array)
ASCII encoding.
Definition encodings.h:542
Here is the call graph for this function:

◆ TEST() [44/55]

TEST ( Reader ,
ParseString_NonDestructive  )

Definition at line 889 of file readertest.cpp.

889 {
890 StringStream s("\"Hello\\nWorld\"");
892 Reader reader;
893 reader.Parse(s, h);
894 EXPECT_EQ(0, StrCmp("Hello\nWorld", h.str_));
895 EXPECT_EQ(11u, h.length_);
896}
Here is the call graph for this function:

◆ TEST() [45/55]

TEST ( Reader ,
ParseString_Transcoding  )

Definition at line 867 of file readertest.cpp.

867 {
868 const char* x = "\"Hello\"";
869 const wchar_t* e = L"Hello";
873 reader.Parse(is, h);
874 EXPECT_EQ(0, StrCmp<UTF16<>::Ch>(e, h.str_));
875 EXPECT_EQ(StrLen(e), h.length_);
876}
CharType Ch
Definition encodings.h:270
Here is the call graph for this function:

◆ TEST() [46/55]

TEST ( Reader ,
ParseString_TranscodingWithValidation  )

Definition at line 878 of file readertest.cpp.

878 {
879 const char* x = "\"Hello\"";
880 const wchar_t* e = L"Hello";
884 reader.Parse<kParseValidateEncodingFlag>(is, h);
885 EXPECT_EQ(0, StrCmp<UTF16<>::Ch>(e, h.str_));
886 EXPECT_EQ(StrLen(e), h.length_);
887}
Here is the call graph for this function:

◆ TEST() [47/55]

TEST ( Reader ,
ParseTerminationByHandler  )

Definition at line 1736 of file readertest.cpp.

1736 {
1737 TEST_TERMINATION(0, "[null");
1738 TEST_TERMINATION(1, "[true");
1739 TEST_TERMINATION(1, "[false");
1740 TEST_TERMINATION(2, "[-1");
1741 TEST_TERMINATION(3, "[1");
1742 TEST_TERMINATION(4, "[-1234567890123456789");
1743 TEST_TERMINATION(5, "[1234567890123456789");
1744 TEST_TERMINATION(6, "[0.5]");
1745 // RawNumber() is never called
1746 TEST_TERMINATION(8, "[\"a\"");
1747 TEST_TERMINATION(9, "[{");
1748 TEST_TERMINATION(10, "[{\"a\"");
1749 TEST_TERMINATION(11, "[{}");
1750 TEST_TERMINATION(11, "[{\"a\":1}"); // non-empty object
1751 TEST_TERMINATION(12, "{\"a\":[");
1752 TEST_TERMINATION(13, "{\"a\":[]");
1753 TEST_TERMINATION(13, "{\"a\":[1]"); // non-empty array
1754}
#define TEST_TERMINATION(e, json)

◆ TEST() [48/55]

TEST ( Reader ,
ParseTrue  )

Definition at line 52 of file readertest.cpp.

52 {
53 StringStream s("true");
55 Reader reader;
56 reader.Parse(s, h);
57 EXPECT_EQ(1u, h.step_);
58}
Here is the call graph for this function:

◆ TEST() [49/55]

TEST ( Reader ,
ParseValue_Error  )

Definition at line 1258 of file readertest.cpp.

1258 {
1259 // Invalid value.
1262 TEST_ERROR(kParseErrorValueInvalid, "falsE", 4u);
1265}

◆ TEST() [50/55]

TEST ( Reader ,
SkipWhitespace  )

Definition at line 1302 of file readertest.cpp.

1302 {
1303 StringStream ss(" A \t\tB\n \n\nC\r\r \rD \t\n\r E");
1304 const char* expected = "ABCDE";
1305 for (size_t i = 0; i < 5; i++) {
1306 SkipWhitespace(ss);
1307 EXPECT_EQ(expected[i], ss.Take());
1308 }
1309}
void SkipWhitespace(InputStream &is)
Skip the JSON white spaces in a stream.
Definition reader.h:264
Here is the call graph for this function:

◆ TEST() [51/55]

TEST ( Reader ,
TrailingCommaHandlerTermination  )

Definition at line 2126 of file readertest.cpp.

2126 {
2128}
void TestTrailingCommaHandlerTermination()
Here is the call graph for this function:

◆ TEST() [52/55]

TEST ( Reader ,
TrailingCommaHandlerTerminationIterative  )

Definition at line 2130 of file readertest.cpp.

Here is the call graph for this function:

◆ TEST() [53/55]

TEST ( Reader ,
TrailingCommas  )

Definition at line 2031 of file readertest.cpp.

2031 {
2033}
void TestTrailingCommas()
Here is the call graph for this function:

◆ TEST() [54/55]

TEST ( Reader ,
TrailingCommasIterative  )

Definition at line 2035 of file readertest.cpp.

Here is the call graph for this function:

◆ TEST() [55/55]

TEST ( Reader ,
UnrecognizedComment  )

Definition at line 1869 of file readertest.cpp.

1869 {
1870 const char* json = "{\"hello\" : \"world\" /! }";
1871
1872 StringStream s(json);
1874 Reader reader;
1877}
Here is the call graph for this function:

◆ TestEmptyExceptForCommaErrors()

template<unsigned extraFlags>
void TestEmptyExceptForCommaErrors ( )

Definition at line 2073 of file readertest.cpp.

2073 {
2074 // not allowed even with trailing commas enabled; the
2075 // trailing comma must follow a value.
2076 {
2077 StringStream s("[,]");
2079 Reader reader;
2080 ParseResult r = reader.Parse<extraFlags|kParseTrailingCommasFlag>(s, h);
2081 EXPECT_TRUE(reader.HasParseError());
2083 EXPECT_EQ(1u, r.Offset());
2084 }
2085 {
2086 StringStream s("{,}");
2088 Reader reader;
2089 ParseResult r = reader.Parse<extraFlags|kParseTrailingCommasFlag>(s, h);
2090 EXPECT_TRUE(reader.HasParseError());
2092 EXPECT_EQ(1u, r.Offset());
2093 }
2094}
@ kParseTrailingCommasFlag
Allow trailing commas at the end of objects and arrays.
Definition reader.h:154
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestInsituMultipleRoot()

template<unsigned parseFlags>
void TestInsituMultipleRoot ( )

Definition at line 1209 of file readertest.cpp.

1209 {
1210 char* buffer = strdup("{}[] a");
1211 InsituStringStream s(buffer);
1213 Reader reader;
1214 EXPECT_TRUE(reader.Parse<kParseInsituFlag | parseFlags>(s, h));
1215 EXPECT_EQ(2u, h.step_);
1216 EXPECT_TRUE(reader.Parse<kParseInsituFlag | parseFlags>(s, h));
1217 EXPECT_EQ(4u, h.step_);
1218 EXPECT_EQ(' ', s.Take());
1219 EXPECT_EQ('a', s.Take());
1220 free(buffer);
1221}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestMultipleRoot()

template<unsigned parseFlags>
void TestMultipleRoot ( )

Definition at line 1188 of file readertest.cpp.

1188 {
1189 StringStream s("{}[] a");
1191 Reader reader;
1192 EXPECT_TRUE(reader.Parse<parseFlags>(s, h));
1193 EXPECT_EQ(2u, h.step_);
1194 EXPECT_TRUE(reader.Parse<parseFlags>(s, h));
1195 EXPECT_EQ(4u, h.step_);
1196 EXPECT_EQ(' ', s.Take());
1197 EXPECT_EQ('a', s.Take());
1198}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestMultipleTrailingCommaErrors()

template<unsigned extraFlags>
void TestMultipleTrailingCommaErrors ( )

Definition at line 2040 of file readertest.cpp.

2040 {
2041 // only a single trailing comma is allowed.
2042 {
2043 StringStream s("[1,2,3,,]");
2045 Reader reader;
2046 ParseResult r = reader.Parse<extraFlags|kParseTrailingCommasFlag>(s, h);
2047 EXPECT_TRUE(reader.HasParseError());
2049 EXPECT_EQ(7u, r.Offset());
2050 }
2051 {
2052 const char* json = "{ \"hello\" : \"world\", \"t\" : true , \"f\" : false,"
2053 "\"n\": null, \"i\":123, \"pi\": 3.1416, \"a\":[1, 2, 3,],,}";
2054 StringStream s(json);
2056 Reader reader;
2057 ParseResult r = reader.Parse<extraFlags|kParseTrailingCommasFlag>(s, h);
2058 EXPECT_TRUE(reader.HasParseError());
2060 EXPECT_EQ(95u, r.Offset());
2061 }
2062}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestString()

template<typename Encoding >
ParseErrorCode TestString ( const typename Encoding::Ch * str)

Definition at line 899 of file readertest.cpp.

899 {
903 reader.template Parse<kParseValidateEncodingFlag>(s, h);
904 return reader.GetParseErrorCode();
905}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestTrailingCommaHandlerTermination()

template<unsigned extraFlags>
void TestTrailingCommaHandlerTermination ( )

Definition at line 2105 of file readertest.cpp.

2105 {
2106 {
2108 Reader reader;
2109 StringStream s("[1,2,3,]");
2110 ParseResult r = reader.Parse<extraFlags|kParseTrailingCommasFlag>(s, h);
2111 EXPECT_TRUE(reader.HasParseError());
2113 EXPECT_EQ(7u, r.Offset());
2114 }
2115 {
2117 Reader reader;
2118 StringStream s("{\"t\": true, \"f\": false,}");
2119 ParseResult r = reader.Parse<extraFlags|kParseTrailingCommasFlag>(s, h);
2120 EXPECT_TRUE(reader.HasParseError());
2122 EXPECT_EQ(23u, r.Offset());
2123 }
2124}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestTrailingCommas()

template<unsigned extraFlags>
void TestTrailingCommas ( )

Definition at line 1992 of file readertest.cpp.

1992 {
1993 {
1994 StringStream s("[1,2,3,]");
1996 Reader reader;
1997 EXPECT_TRUE(reader.Parse<extraFlags|kParseTrailingCommasFlag>(s, h));
1998 EXPECT_EQ(5u, h.step_);
1999 }
2000 {
2001 const char* json = "{ \"hello\" : \"world\", \"t\" : true , \"f\" : false,"
2002 "\"n\": null, \"i\":123, \"pi\": 3.1416, \"a\":[1, 2, 3],}";
2003 StringStream s(json);
2005 Reader reader;
2006 EXPECT_TRUE(reader.Parse<extraFlags|kParseTrailingCommasFlag>(s, h));
2007 EXPECT_EQ(20u, h.step_);
2008 }
2009 {
2010 // whitespace around trailing commas
2011 const char* json = "{ \"hello\" : \"world\", \"t\" : true , \"f\" : false,"
2012 "\"n\": null, \"i\":123, \"pi\": 3.1416, \"a\":[1, 2, 3\n,\n]\n,\n} ";
2013 StringStream s(json);
2015 Reader reader;
2016 EXPECT_TRUE(reader.Parse<extraFlags|kParseTrailingCommasFlag>(s, h));
2017 EXPECT_EQ(20u, h.step_);
2018 }
2019 {
2020 // comments around trailing commas
2021 const char* json = "{ \"hello\" : \"world\", \"t\" : true , \"f\" : false, \"n\": null,"
2022 "\"i\":123, \"pi\": 3.1416, \"a\":[1, 2, 3/*test*/,/*test*/]/*test*/,/*test*/}";
2023 StringStream s(json);
2025 Reader reader;
2027 EXPECT_EQ(20u, h.step_);
2028 }
2029}
Here is the call graph for this function:
Here is the caller graph for this function: