Electroneum
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(...)   { __VA_ARGS__ }
 
#define TEST_STRINGARRAY(Encoding, utype, array, x)
 
#define TEST_STRINGARRAY2(Encoding, utype, earray, xarray)
 
#define TEST_STRING_ERROR(errorCode, str, errorOffset, streamPos)
 
#define ARRAY(...)   { __VA_ARGS__ }
 
#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 (   ...)    { __VA_ARGS__ }

◆ ARRAY [2/2]

#define ARRAY (   ...)    { __VA_ARGS__ }

◆ TEST_ARRAY_ERROR

#define TEST_ARRAY_ERROR (   errorCode,
  str,
  errorOffset 
)
Value:
{ \
int streamPos = errorOffset; \
char buffer[1001]; \
strncpy(buffer, str, 1000); \
InsituStringStream s(buffer); \
BaseReaderHandler<> h; \
GenericReader<UTF8<>, UTF8<>, CrtAllocator> reader; \
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
UTF-8 encoding.
Definition: encodings.h:96

◆ TEST_DOUBLE

#define TEST_DOUBLE (   fullPrecision,
  str,
 
)
Value:
{ \
StringStream s(str); \
ParseDoubleHandler h; \
Reader reader; \
ASSERT_EQ(kParseErrorNone, reader.Parse<fullPrecision ? kParseFullPrecisionFlag : 0>(s, h).Code()); \
EXPECT_EQ(1u, h.step_); \
internal::Double e(x), a(h.actual_); \
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_); \
} \
}
No error.
Definition: error.h:65
Parse number in full precision (but slower).
Definition: reader.h:151
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1124
FloatingPoint< double > Double

◆ TEST_ERROR

#define TEST_ERROR (   errorCode,
  str,
  errorOffset 
)
Value:
{ \
int streamPos = errorOffset; \
char buffer[1001]; \
strncpy(buffer, str, 1000); \
InsituStringStream s(buffer); \
BaseReaderHandler<> h; \
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.

◆ TEST_INTEGER

#define TEST_INTEGER (   Handler,
  str,
 
)
Value:
{ \
StringStream s(str); \
Handler h; \
Reader reader; \
reader.Parse(s, h); \
EXPECT_EQ(1u, h.step_); \
EXPECT_EQ(x, h.actual_); \
}

◆ TEST_NAN_INF

#define TEST_NAN_INF (   str,
 
)
Value:
{ \
{ \
StringStream s(str); \
ParseDoubleHandler h; \
Reader reader; \
ASSERT_EQ(kParseErrorNone, reader.Parse<kParseNanAndInfFlag>(s, h).Code()); \
EXPECT_EQ(1u, h.step_); \
internal::Double e(x), a(h.actual_); \
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); \
NumbersAsStringsHandler h(str); \
Reader reader; \
EXPECT_TRUE(reader.Parse<kParseNumbersAsStringsFlag|kParseNanAndInfFlag>(s, h)); \
} \
{ \
char* json = StrDup("{ \"naninfdouble\": " str " } "); \
InsituStringStream s(json); \
NumbersAsStringsHandler h(str); \
Reader reader; \
free(json); \
} \
}
No error.
Definition: error.h:65
Allow parsing NaN, Inf, Infinity, -Inf and -Infinity as doubles.
Definition: reader.h:155
Parse all numbers (ints/doubles) as strings.
Definition: reader.h:153
Ch * StrDup(const Ch *str)
Definition: unittest.h:73
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1124
FloatingPoint< double > Double
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
In-situ(destructive) parsing.
Definition: reader.h:147
rapidjson::Document json
Definition: transport.cpp:49

◆ TEST_NAN_INF_ERROR

#define TEST_NAN_INF_ERROR (   errorCode,
  str,
  errorOffset 
)
Value:
{ \
int streamPos = errorOffset; \
char buffer[1001]; \
strncpy(buffer, str, 1000); \
InsituStringStream s(buffer); \
BaseReaderHandler<> h; \
Reader reader; \
EXPECT_FALSE(reader.Parse<kParseNanAndInfFlag>(s, h)); \
EXPECT_EQ(errorCode, reader.GetParseErrorCode());\
EXPECT_EQ(errorOffset, reader.GetErrorOffset());\
EXPECT_EQ(streamPos, s.Tell());\
}
Allow parsing NaN, Inf, Infinity, -Inf and -Infinity as doubles.
Definition: reader.h:155

◆ 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); \
BaseReaderHandler<> h; \
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());\
}
Parse number in full precision (but slower).
Definition: reader.h:151

◆ TEST_STRING

#define TEST_STRING (   Encoding,
  e,
 
)
Value:
{ \
Encoding::Ch* buffer = StrDup(x); \
GenericInsituStringStream<Encoding> is(buffer); \
ParseStringHandler<Encoding> h; \
GenericReader<Encoding, Encoding> reader; \
reader.Parse<kParseInsituFlag | kParseValidateEncodingFlag>(is, h); \
EXPECT_EQ(0, StrCmp<Encoding::Ch>(e, h.str_)); \
EXPECT_EQ(StrLen(e), h.length_); \
free(buffer); \
GenericStringStream<Encoding> s(x); \
ParseStringHandler<Encoding> h2; \
GenericReader<Encoding, Encoding> reader2; \
reader2.Parse(s, h2); \
EXPECT_EQ(0, StrCmp<Encoding::Ch>(e, h2.str_)); \
EXPECT_EQ(StrLen(e), h2.length_); \
}
Ch * StrDup(const Ch *str)
Definition: unittest.h:73
#define Ch(x, y, z)
Definition: hash_impl.h:17
unsigned StrLen(const Ch *s)
Definition: unittest.h:60
Validate encoding of JSON strings.
Definition: reader.h:148
In-situ(destructive) parsing.
Definition: reader.h:147

◆ TEST_STRING_ERROR

#define TEST_STRING_ERROR (   errorCode,
  str,
  errorOffset,
  streamPos 
)
Value:
{\
GenericStringStream<UTF8<> > s(str);\
BaseReaderHandler<UTF8<> > h;\
GenericReader<UTF8<> , UTF8<> > reader;\
reader.Parse<kParseValidateEncodingFlag>(s, h);\
EXPECT_EQ(errorCode, reader.GetParseErrorCode());\
EXPECT_EQ(errorOffset, reader.GetErrorOffset());\
EXPECT_EQ(streamPos, s.Tell());\
}
Validate encoding of JSON strings.
Definition: reader.h:148
UTF-8 encoding.
Definition: encodings.h:96

◆ TEST_STRINGARRAY

#define TEST_STRINGARRAY (   Encoding,
  utype,
  array,
 
)
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.
#define Ch(x, y, z)
Definition: hash_impl.h:17

◆ 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); \
}
Concept for encoding of Unicode characters.
#define Ch(x, y, z)
Definition: hash_impl.h:17

◆ 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]); \
EXPECT_EQ(kParseErrorStringInvalidEncoding, TestString<Encoding>(e));\
/* decode error */\
GenericStringStream<Encoding> s(e);\
BaseReaderHandler<TargetEncoding> h;\
GenericReader<Encoding, TargetEncoding> reader;\
reader.Parse(s, h);\
EXPECT_EQ(kParseErrorStringInvalidEncoding, reader.GetParseErrorCode());\
}
Invalid encoding in string.
Definition: error.h:82
#define Ch(x, y, z)
Definition: hash_impl.h:17

◆ TEST_TERMINATION

#define TEST_TERMINATION (   e,
  json 
)
Value:
{\
Reader reader;\
TerminateHandler<e> h;\
StringStream is(json);\
EXPECT_FALSE(reader.Parse(is, h));\
EXPECT_EQ(kParseErrorTermination, reader.GetParseErrorCode());\
}
Parsing was terminated.
Definition: error.h:88
rapidjson::Document json
Definition: transport.cpp:49

Definition at line 1727 of file readertest.cpp.

◆ TESTERRORHANDLING

#define TESTERRORHANDLING (   text,
  errorCode,
  offset 
)
Value:
{\
int streamPos = offset; \
StringStream json(text); \
BaseReaderHandler<> handler; \
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()); \
}
Iterative(constant complexity in terms of function call stack size) parsing.
Definition: reader.h:149
rapidjson::Document json
Definition: transport.cpp:49

Definition at line 1406 of file readertest.cpp.

Function Documentation

◆ TEST() [1/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 }
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text.
Definition: reader.h:557
Read-only string stream.
Definition: fwd.h:47
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Here is the call graph for this function:

◆ TEST() [2/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 }
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text.
Definition: reader.h:557
Read-only string stream.
Definition: fwd.h:47
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Here is the call graph for this function:

◆ TEST() [3/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 
124  TEST_INTEGER(ParseUintHandler, "0", 0u);
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 }
#define TEST_INTEGER(Handler, str, x)
char * u64toa(uint64_t value, char *buffer)
Definition: itoa.h:126
#define RAPIDJSON_UINT64_C2(high32, low32)
Construct a 64-bit literal by a pair of 32-bit integer.
Definition: rapidjson.h:294
unsigned int uint32_t
Definition: stdint.h:126
unsigned __int64 uint64_t
Definition: stdint.h:136
char * u32toa(uint32_t value, char *buffer)
Definition: itoa.h:39
signed __int64 int64_t
Definition: stdint.h:135
signed int int32_t
Definition: stdint.h:123
char * i64toa(int64_t value, char *buffer)
Definition: itoa.h:295
char * i32toa(int32_t value, char *buffer)
Definition: itoa.h:115
Here is the call graph for this function:

◆ TEST() [4/55]

TEST ( Reader  ,
ParseNumber_NormalPrecisionDouble   
)

Definition at line 587 of file readertest.cpp.

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

◆ TEST() [5/55]

TEST ( Reader  ,
ParseNumber_FullPrecisionDouble   
)

Definition at line 591 of file readertest.cpp.

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

◆ TEST() [6/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++) {
602  internal::Double e, a;
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 }
double Value() const
Definition: ieee754.h:29
uint64_t ToBias() const
Definition: ieee754.h:49
bool IsNormal() const
Definition: ieee754.h:44
No error.
Definition: error.h:65
ParseErrorCode Code() const
Get the error code.
Definition: error.h:116
bool IsNan() const
Definition: ieee754.h:41
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text.
Definition: reader.h:557
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:1956
bool IsInf() const
Definition: ieee754.h:42
mdb_size_t count(MDB_cursor *cur)
Read-only string stream.
Definition: fwd.h:47
unsigned __int64 uint64_t
Definition: stdint.h:136
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1124
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
char * dtoa(double value, char *buffer, int maxDecimalPlaces=324)
Definition: dtoa.h:216
Here is the call graph for this function:

◆ TEST() [7/55]

TEST ( Reader  ,
ParseNumberError_NormalPrecisionDouble   
)

Definition at line 747 of file readertest.cpp.

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

◆ TEST() [8/55]

TEST ( Reader  ,
ParseNumberError_FullPrecisionDouble   
)

Definition at line 751 of file readertest.cpp.

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

◆ TEST() [9/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 }
const Encoding::Ch * str_
Definition: readertest.cpp:777
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text.
Definition: reader.h:557
#define TEST_STRINGARRAY(Encoding, utype, array, x)
Read-only string stream.
Definition: fwd.h:47
#define TEST_STRINGARRAY2(Encoding, utype, earray, xarray)
UTF-32 encoding.
Definition: encodings.h:418
UTF-16 encoding.
Definition: encodings.h:269
#define ARRAY(...)
#define TEST_STRING(Encoding, e, x)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
UTF-8 encoding.
Definition: encodings.h:96

◆ TEST() [10/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";
871  GenericReader<UTF8<>, UTF16<> > reader;
873  reader.Parse(is, h);
874  EXPECT_EQ(0, StrCmp<UTF16<>::Ch>(e, h.str_));
875  EXPECT_EQ(StrLen(e), h.length_);
876 }
const Encoding::Ch * str_
Definition: readertest.cpp:777
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text.
Definition: reader.h:557
Read-only string stream.
Definition: fwd.h:47
int StrCmp(const Ch *s1, const Ch *s2)
Definition: unittest.h:67
SAX-style JSON parser. Use Reader for UTF8 encoding and default allocator.
Definition: fwd.h:88
unsigned StrLen(const Ch *s)
Definition: unittest.h:60
CharType Ch
Definition: encodings.h:270
UTF-16 encoding.
Definition: encodings.h:269
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922

◆ TEST() [11/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";
882  GenericReader<UTF8<>, UTF16<> > reader;
884  reader.Parse<kParseValidateEncodingFlag>(is, h);
885  EXPECT_EQ(0, StrCmp<UTF16<>::Ch>(e, h.str_));
886  EXPECT_EQ(StrLen(e), h.length_);
887 }
const Encoding::Ch * str_
Definition: readertest.cpp:777
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text.
Definition: reader.h:557
Read-only string stream.
Definition: fwd.h:47
int StrCmp(const Ch *s1, const Ch *s2)
Definition: unittest.h:67
SAX-style JSON parser. Use Reader for UTF8 encoding and default allocator.
Definition: fwd.h:88
unsigned StrLen(const Ch *s)
Definition: unittest.h:60
Validate encoding of JSON strings.
Definition: reader.h:148
CharType Ch
Definition: encodings.h:270
UTF-16 encoding.
Definition: encodings.h:269
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922

◆ TEST() [12/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 }
const Encoding::Ch * str_
Definition: readertest.cpp:777
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text.
Definition: reader.h:557
Read-only string stream.
Definition: fwd.h:47
int StrCmp(const Ch *s1, const Ch *s2)
Definition: unittest.h:67
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Here is the call graph for this function:

◆ TEST() [13/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\"]", 2, 13);
942 
943  // The surrogate pair in string is invalid.
945  TEST_STRING_ERROR(kParseErrorStringUnicodeSurrogateInvalid, "[\"\\uD800\\uFFFF\"]", 2, 14);
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);
959  ParseErrorCode error = TestString<UTF8<> >(e);
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  int 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 }
Missing a closing quotation mark in string.
Definition: error.h:81
ParseErrorCode
Error code of parsing.
Definition: error.h:64
Incorrect hex digit after \u escape in string.
Definition: error.h:78
ASCII encoding.
Definition: encodings.h:542
Invalid encoding in string.
Definition: error.h:82
#define TEST_STRINGENCODING_ERROR(Encoding, TargetEncoding, utype, array)
#define TEST_STRING_ERROR(errorCode, str, errorOffset, streamPos)
Invalid escape character in string.
Definition: error.h:80
UTF-32 encoding.
Definition: encodings.h:418
UTF-16 encoding.
Definition: encodings.h:269
#define ARRAY(...)
error
Tracks LMDB error codes.
Definition: error.h:44
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
The surrogate pair in string is invalid.
Definition: error.h:79
UTF-8 encoding.
Definition: encodings.h:96

◆ TEST() [14/55]

TEST ( Reader  ,
ParseEmptyArray   
)

Definition at line 1042 of file readertest.cpp.

1042  {
1043  char *json = StrDup("[ ] ");
1046  Reader reader;
1047  reader.Parse(s, h);
1048  EXPECT_EQ(2u, h.step_);
1049  free(json);
1050 }
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text.
Definition: reader.h:557
Ch * StrDup(const Ch *str)
Definition: unittest.h:73
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
rapidjson::Document json
Definition: transport.cpp:49
Here is the call graph for this function:

◆ TEST() [15/55]

TEST ( Reader  ,
ParseArray   
)

Definition at line 1052 of file readertest.cpp.

1052  {
1053  char *json = StrDup("[1, 2, 3, 4]");
1056  Reader reader;
1057  reader.Parse(s, h);
1058  EXPECT_EQ(6u, h.step_);
1059  free(json);
1060 }
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text.
Definition: reader.h:557
Ch * StrDup(const Ch *str)
Definition: unittest.h:73
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
rapidjson::Document json
Definition: transport.cpp:49
Here is the call graph for this function:

◆ TEST() [16/55]

TEST ( Reader  ,
ParseArray_Error   
)

Definition at line 1062 of file readertest.cpp.

1062  {
1063 #define TEST_ARRAY_ERROR(errorCode, str, errorOffset) \
1064  { \
1065  int 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 }
Missing a comma or &#39;]&#39; after an array element.
Definition: error.h:76
#define TEST_ARRAY_ERROR(errorCode, str, errorOffset)
Invalid value.
Definition: error.h:70

◆ TEST() [17/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 }
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text.
Definition: reader.h:557
Read-only string stream.
Definition: fwd.h:47
Ch * StrDup(const Ch *str)
Definition: unittest.h:73
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
In-situ(destructive) parsing.
Definition: reader.h:147
rapidjson::Document json
Definition: transport.cpp:49
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 }
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text.
Definition: reader.h:557
Read-only string stream.
Definition: fwd.h:47
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Here is the call graph for this function:

◆ TEST() [19/55]

TEST ( Reader  ,
Parse_MultipleRoot   
)

Definition at line 1200 of file readertest.cpp.

1200  {
1201  TestMultipleRoot<kParseStopWhenDoneFlag>();
1202 }

◆ TEST() [20/55]

TEST ( Reader  ,
ParseIterative_MultipleRoot   
)

Definition at line 1204 of file readertest.cpp.

1204  {
1205  TestMultipleRoot<kParseIterativeFlag | kParseStopWhenDoneFlag>();
1206 }

◆ TEST() [21/55]

TEST ( Reader  ,
ParseInsitu_MultipleRoot   
)

Definition at line 1223 of file readertest.cpp.

1223  {
1224  TestInsituMultipleRoot<kParseStopWhenDoneFlag>();
1225 }

◆ TEST() [22/55]

TEST ( Reader  ,
ParseInsituIterative_MultipleRoot   
)

Definition at line 1227 of file readertest.cpp.

1227  {
1228  TestInsituMultipleRoot<kParseIterativeFlag | kParseStopWhenDoneFlag>();
1229 }

◆ TEST() [23/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)
The document is empty.
Definition: error.h:67
The document root must not follow by other values.
Definition: error.h:68

◆ TEST() [24/55]

TEST ( Reader  ,
ParseValue_Error   
)

Definition at line 1258 of file readertest.cpp.

1258  {
1259  // Invalid value.
1260  TEST_ERROR(kParseErrorValueInvalid, "nulL", 3);
1261  TEST_ERROR(kParseErrorValueInvalid, "truE", 3);
1262  TEST_ERROR(kParseErrorValueInvalid, "falsE", 4);
1265 }
#define TEST_ERROR(errorCode, str, errorOffset)
Invalid value.
Definition: error.h:70

◆ TEST() [25/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}", 1);
1272  TEST_ERROR(kParseErrorObjectMissName, "{true:1}", 1);
1273  TEST_ERROR(kParseErrorObjectMissName, "{false:1}", 1);
1275  TEST_ERROR(kParseErrorObjectMissName, "{[]:1}", 1);
1276  TEST_ERROR(kParseErrorObjectMissName, "{{}:1}", 1);
1277  TEST_ERROR(kParseErrorObjectMissName, "{xyz:1}", 1);
1278 
1279  // Missing a colon after a name of object member.
1280  TEST_ERROR(kParseErrorObjectMissColon, "{\"a\" 1}", 5);
1281  TEST_ERROR(kParseErrorObjectMissColon, "{\"a\",1}", 4);
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,}", 7);
1289 
1290  // This tests that MemoryStream is checking the length in Peek().
1291  {
1292  MemoryStream ms("{\"a\"", 1);
1294  Reader reader;
1295  EXPECT_FALSE(reader.Parse<kParseStopWhenDoneFlag>(ms, h));
1297  }
1298 }
#define TEST_ERROR(errorCode, str, errorOffset)
Missing a colon after a name of object member.
Definition: error.h:73
After parsing a complete JSON root from stream, stop further processing the rest of stream...
Definition: reader.h:150
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text.
Definition: reader.h:557
Missing a name for object member.
Definition: error.h:72
Represents an in-memory input byte stream.
Definition: memorystream.h:40
Missing a comma or &#39;}&#39; after an object member.
Definition: error.h:74
ParseErrorCode GetParseErrorCode() const
Get the ParseErrorCode of last parsing.
Definition: reader.h:683
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Here is the call graph for this function:

◆ TEST() [26/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 }
Read-only string stream.
Definition: fwd.h:47
void SkipWhitespace(InputStream &is)
Skip the JSON white spaces in a stream.
Definition: reader.h:264
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Here is the call graph for this function:

◆ TEST() [27/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 }
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text.
Definition: reader.h:557
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
rapidjson::Document json
Definition: transport.cpp:49
Here is the call graph for this function:

◆ TEST() [28/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 }
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text.
Definition: reader.h:557
bool HasParseError() const
Whether a parse error has occurred in the last parsing.
Definition: reader.h:680
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
rapidjson::Document json
Definition: transport.cpp:49
Here is the call graph for this function:

◆ TEST() [29/55]

TEST ( Reader  ,
IterativeParsing_ErrorHandling   
)

Definition at line 1419 of file readertest.cpp.

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

◆ TEST() [30/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 }
Iterative(constant complexity in terms of function call stack size) parsing.
Definition: reader.h:149
static const uint32_t LOG_BOOL
static const uint32_t LOG_NULL
static const uint32_t LOG_STARTOBJECT
static const uint32_t LOG_DOUBLE
static const uint32_t LOG_KEY
static const uint32_t LOG_ENDARRAY
static const uint32_t LOG_STARTARRAY
static const uint32_t LOG_INT
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text.
Definition: reader.h:557
bool HasParseError() const
Whether a parse error has occurred in the last parsing.
Definition: reader.h:680
unsigned int uint32_t
Definition: stdint.h:126
static const uint32_t LOG_ENDOBJECT
Read-only string stream.
Definition: fwd.h:47
uint32_t Logs[LogCapacity]
bool IsError() const
Whether the result is an error.
Definition: error.h:123
Result of parsing (wraps ParseErrorCode)
Definition: error.h:106
static const uint32_t LOG_STRING
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Here is the call graph for this function:

◆ TEST() [31/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 }
Iterative(constant complexity in terms of function call stack size) parsing.
Definition: reader.h:149
static const uint32_t LOG_STARTOBJECT
static const uint32_t LOG_KEY
static const uint32_t LOG_ENDARRAY
static const uint32_t LOG_STARTARRAY
static const uint32_t LOG_INT
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text.
Definition: reader.h:557
bool HasParseError() const
Whether a parse error has occurred in the last parsing.
Definition: reader.h:680
unsigned int uint32_t
Definition: stdint.h:126
static const uint32_t LOG_ENDOBJECT
Read-only string stream.
Definition: fwd.h:47
uint32_t Logs[LogCapacity]
bool IsError() const
Whether the result is an error.
Definition: error.h:123
Result of parsing (wraps ParseErrorCode)
Definition: error.h:106
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Here is the call graph for this function:

◆ TEST() [32/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 }
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
static const uint32_t LOG_BOOL
static const uint32_t LOG_NULL
static const uint32_t LOG_STARTOBJECT
static const uint32_t LOG_DOUBLE
static const uint32_t LOG_KEY
static const uint32_t LOG_ENDARRAY
static const uint32_t LOG_STARTARRAY
static const uint32_t LOG_INT
Default parse flags. Can be customized by defining RAPIDJSON_PARSE_DEFAULT_FLAGS. ...
Definition: reader.h:156
bool HasParseError() const
Whether a parse error has occurred in the last parsing.
Definition: reader.h:680
unsigned int uint32_t
Definition: stdint.h:126
static const uint32_t LOG_ENDOBJECT
Read-only string stream.
Definition: fwd.h:47
bool IterativeParseNext(InputStream &is, Handler &handler)
Parse one token from JSON text.
Definition: reader.h:618
uint32_t Logs[LogCapacity]
void IterativeParseInit()
Initialize JSON text token-by-token parsing.
Definition: reader.h:605
static const uint32_t LOG_STRING
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
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() [33/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 }
Iterative(constant complexity in terms of function call stack size) parsing.
Definition: reader.h:149
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
ParseErrorCode Code() const
Get the error code.
Definition: error.h:116
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text.
Definition: reader.h:557
bool HasParseError() const
Whether a parse error has occurred in the last parsing.
Definition: reader.h:680
Read-only string stream.
Definition: fwd.h:47
Result of parsing (wraps ParseErrorCode)
Definition: error.h:106
Parsing was terminated.
Definition: error.h:88
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
size_t Offset() const
Get the error offset, if IsError(), 0 otherwise.
Definition: error.h:118
Here is the call graph for this function:

◆ TEST() [34/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:1859
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text.
Definition: reader.h:557
Read-only string stream.
Definition: fwd.h:47
Here is the call graph for this function:

◆ TEST() [35/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() [36/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;
1770  EXPECT_TRUE(reader.Parse<kParseCommentsFlag>(s, h));
1771  EXPECT_EQ(20u, h.step_);
1772 }
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text.
Definition: reader.h:557
Read-only string stream.
Definition: fwd.h:47
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
rapidjson::Document json
Definition: transport.cpp:49
Allow one-line (//) and multi-line (/**/) comments.
Definition: reader.h:152
Here is the call graph for this function:

◆ TEST() [37/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;
1780  EXPECT_TRUE(reader.Parse<kParseCommentsFlag>(s, h));
1781  EXPECT_EQ(20u, h.step_);
1782 }
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text.
Definition: reader.h:557
Read-only string stream.
Definition: fwd.h:47
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
rapidjson::Document json
Definition: transport.cpp:49
Allow one-line (//) and multi-line (/**/) comments.
Definition: reader.h:152
Here is the call graph for this function:

◆ TEST() [38/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;
1790  EXPECT_TRUE(reader.Parse<kParseCommentsFlag>(s, h));
1791  EXPECT_EQ(20u, h.step_);
1792 }
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text.
Definition: reader.h:557
Read-only string stream.
Definition: fwd.h:47
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
rapidjson::Document json
Definition: transport.cpp:49
Allow one-line (//) and multi-line (/**/) comments.
Definition: reader.h:152
Here is the call graph for this function:

◆ TEST() [39/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;
1803  EXPECT_TRUE(reader.Parse<kParseCommentsFlag>(s, h));
1804  EXPECT_EQ(20u, h.step_);
1805 }
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text.
Definition: reader.h:557
Read-only string stream.
Definition: fwd.h:47
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
rapidjson::Document json
Definition: transport.cpp:49
Allow one-line (//) and multi-line (/**/) comments.
Definition: reader.h:152
Here is the call graph for this function:

◆ TEST() [40/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;
1814  EXPECT_FALSE(reader.Parse<kParseDefaultFlags>(s, h));
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;
1826  EXPECT_FALSE(reader.Parse<kParseDefaultFlags>(s, h));
1827  }
1828 }
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text.
Definition: reader.h:557
Default parse flags. Can be customized by defining RAPIDJSON_PARSE_DEFAULT_FLAGS. ...
Definition: reader.h:156
Read-only string stream.
Definition: fwd.h:47
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
rapidjson::Document json
Definition: transport.cpp:49
Here is the call graph for this function:

◆ TEST() [41/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;
1836  EXPECT_FALSE(reader.Parse<kParseDefaultFlags>(s, h));
1837 }
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text.
Definition: reader.h:557
Default parse flags. Can be customized by defining RAPIDJSON_PARSE_DEFAULT_FLAGS. ...
Definition: reader.h:156
Read-only string stream.
Definition: fwd.h:47
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
rapidjson::Document json
Definition: transport.cpp:49
Here is the call graph for this function:

◆ TEST() [42/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;
1845  EXPECT_FALSE(reader.Parse<kParseCommentsFlag>(s, h));
1847 }
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text.
Definition: reader.h:557
Read-only string stream.
Definition: fwd.h:47
Missing a comma or &#39;}&#39; after an object member.
Definition: error.h:74
ParseErrorCode GetParseErrorCode() const
Get the ParseErrorCode of last parsing.
Definition: reader.h:683
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
rapidjson::Document json
Definition: transport.cpp:49
Allow one-line (//) and multi-line (/**/) comments.
Definition: reader.h:152
Here is the call graph for this function:

◆ TEST() [43/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;
1855  EXPECT_FALSE(reader.Parse<kParseCommentsFlag>(s, h));
1857 }
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text.
Definition: reader.h:557
Read-only string stream.
Definition: fwd.h:47
Unspecific syntax error.
Definition: error.h:89
ParseErrorCode GetParseErrorCode() const
Get the ParseErrorCode of last parsing.
Definition: reader.h:683
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
rapidjson::Document json
Definition: transport.cpp:49
Allow one-line (//) and multi-line (/**/) comments.
Definition: reader.h:152
Here is the call graph for this function:

◆ TEST() [44/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;
1865  EXPECT_FALSE(reader.Parse<kParseCommentsFlag>(s, h));
1867 }
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text.
Definition: reader.h:557
Read-only string stream.
Definition: fwd.h:47
Unspecific syntax error.
Definition: error.h:89
ParseErrorCode GetParseErrorCode() const
Get the ParseErrorCode of last parsing.
Definition: reader.h:683
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
rapidjson::Document json
Definition: transport.cpp:49
Allow one-line (//) and multi-line (/**/) comments.
Definition: reader.h:152
Here is the call graph for this function:

◆ TEST() [45/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;
1875  EXPECT_FALSE(reader.Parse<kParseCommentsFlag>(s, h));
1877 }
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text.
Definition: reader.h:557
Read-only string stream.
Definition: fwd.h:47
Unspecific syntax error.
Definition: error.h:89
ParseErrorCode GetParseErrorCode() const
Get the ParseErrorCode of last parsing.
Definition: reader.h:683
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
rapidjson::Document json
Definition: transport.cpp:49
Allow one-line (//) and multi-line (/**/) comments.
Definition: reader.h:152
Here is the call graph for this function:

◆ TEST() [46/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 } ");
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 } ");
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 } ");
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 } ");
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 }
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
Parse all numbers (ints/doubles) as strings.
Definition: reader.h:153
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text.
Definition: reader.h:557
Read-only string stream.
Definition: fwd.h:47
Ch * StrDup(const Ch *str)
Definition: unittest.h:73
In-situ(destructive) parsing.
Definition: reader.h:147
rapidjson::Document json
Definition: transport.cpp:49
Here is the call graph for this function:

◆ TEST() [47/55]

TEST ( Reader  ,
TrailingCommas   
)

Definition at line 2020 of file readertest.cpp.

2020  {
2021  TestTrailingCommas<kParseNoFlags>();
2022 }

◆ TEST() [48/55]

TEST ( Reader  ,
TrailingCommasIterative   
)

Definition at line 2024 of file readertest.cpp.

2024  {
2025  TestTrailingCommas<kParseIterativeFlag>();
2026 }

◆ TEST() [49/55]

TEST ( Reader  ,
MultipleTrailingCommaErrors   
)

Definition at line 2053 of file readertest.cpp.

2053  {
2054  TestMultipleTrailingCommaErrors<kParseNoFlags>();
2055 }

◆ TEST() [50/55]

TEST ( Reader  ,
MultipleTrailingCommaErrorsIterative   
)

Definition at line 2057 of file readertest.cpp.

2057  {
2058  TestMultipleTrailingCommaErrors<kParseIterativeFlag>();
2059 }

◆ TEST() [51/55]

TEST ( Reader  ,
EmptyExceptForCommaErrors   
)

Definition at line 2085 of file readertest.cpp.

2085  {
2086  TestEmptyExceptForCommaErrors<kParseNoFlags>();
2087 }

◆ TEST() [52/55]

TEST ( Reader  ,
EmptyExceptForCommaErrorsIterative   
)

Definition at line 2089 of file readertest.cpp.

2089  {
2090  TestEmptyExceptForCommaErrors<kParseIterativeFlag>();
2091 }

◆ TEST() [53/55]

TEST ( Reader  ,
TrailingCommaHandlerTermination   
)

Definition at line 2115 of file readertest.cpp.

2115  {
2116  TestTrailingCommaHandlerTermination<kParseNoFlags>();
2117 }

◆ TEST() [54/55]

TEST ( Reader  ,
TrailingCommaHandlerTerminationIterative   
)

Definition at line 2119 of file readertest.cpp.

2119  {
2120  TestTrailingCommaHandlerTermination<kParseIterativeFlag>();
2121 }

◆ TEST() [55/55]

TEST ( Reader  ,
ParseNanAndInfinity   
)

Definition at line 2123 of file readertest.cpp.

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

◆ TestEmptyExceptForCommaErrors()

template<unsigned extraFlags>
void TestEmptyExceptForCommaErrors ( )

Definition at line 2062 of file readertest.cpp.

2062  {
2063  // not allowed even with trailing commas enabled; the
2064  // trailing comma must follow a value.
2065  {
2066  StringStream s("[,]");
2068  Reader reader;
2069  ParseResult r = reader.Parse<extraFlags|kParseTrailingCommasFlag>(s, h);
2070  EXPECT_TRUE(reader.HasParseError());
2072  EXPECT_EQ(1u, r.Offset());
2073  }
2074  {
2075  StringStream s("{,}");
2077  Reader reader;
2078  ParseResult r = reader.Parse<extraFlags|kParseTrailingCommasFlag>(s, h);
2079  EXPECT_TRUE(reader.HasParseError());
2081  EXPECT_EQ(1u, r.Offset());
2082  }
2083 }
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
ParseErrorCode Code() const
Get the error code.
Definition: error.h:116
Allow trailing commas at the end of objects and arrays.
Definition: reader.h:154
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text.
Definition: reader.h:557
Missing a name for object member.
Definition: error.h:72
bool HasParseError() const
Whether a parse error has occurred in the last parsing.
Definition: reader.h:680
Read-only string stream.
Definition: fwd.h:47
Invalid value.
Definition: error.h:70
Result of parsing (wraps ParseErrorCode)
Definition: error.h:106
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
size_t Offset() const
Get the error offset, if IsError(), 0 otherwise.
Definition: error.h:118
Here is the call 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 }
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text.
Definition: reader.h:557
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
In-situ(destructive) parsing.
Definition: reader.h:147
Here is the call 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 }
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text.
Definition: reader.h:557
Read-only string stream.
Definition: fwd.h:47
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Here is the call graph for this function:

◆ TestMultipleTrailingCommaErrors()

template<unsigned extraFlags>
void TestMultipleTrailingCommaErrors ( )

Definition at line 2029 of file readertest.cpp.

2029  {
2030  // only a single trailing comma is allowed.
2031  {
2032  StringStream s("[1,2,3,,]");
2034  Reader reader;
2035  ParseResult r = reader.Parse<extraFlags|kParseTrailingCommasFlag>(s, h);
2036  EXPECT_TRUE(reader.HasParseError());
2038  EXPECT_EQ(7u, r.Offset());
2039  }
2040  {
2041  const char* json = "{ \"hello\" : \"world\", \"t\" : true , \"f\" : false,"
2042  "\"n\": null, \"i\":123, \"pi\": 3.1416, \"a\":[1, 2, 3,],,}";
2043  StringStream s(json);
2045  Reader reader;
2046  ParseResult r = reader.Parse<extraFlags|kParseTrailingCommasFlag>(s, h);
2047  EXPECT_TRUE(reader.HasParseError());
2049  EXPECT_EQ(95u, r.Offset());
2050  }
2051 }
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
ParseErrorCode Code() const
Get the error code.
Definition: error.h:116
Allow trailing commas at the end of objects and arrays.
Definition: reader.h:154
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text.
Definition: reader.h:557
Missing a name for object member.
Definition: error.h:72
bool HasParseError() const
Whether a parse error has occurred in the last parsing.
Definition: reader.h:680
Read-only string stream.
Definition: fwd.h:47
Invalid value.
Definition: error.h:70
Result of parsing (wraps ParseErrorCode)
Definition: error.h:106
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
rapidjson::Document json
Definition: transport.cpp:49
size_t Offset() const
Get the error offset, if IsError(), 0 otherwise.
Definition: error.h:118
Here is the call 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 }
Default implementation of Handler.
Definition: fwd.h:85
Read-only string stream.
Definition: fwd.h:47
SAX-style JSON parser. Use Reader for UTF8 encoding and default allocator.
Definition: fwd.h:88
ParseErrorCode GetParseErrorCode() const
Get the ParseErrorCode of last parsing.
Definition: reader.h:683
Here is the call graph for this function:

◆ TestTrailingCommaHandlerTermination()

template<unsigned extraFlags>
void TestTrailingCommaHandlerTermination ( )

Definition at line 2094 of file readertest.cpp.

2094  {
2095  {
2097  Reader reader;
2098  StringStream s("[1,2,3,]");
2099  ParseResult r = reader.Parse<extraFlags|kParseTrailingCommasFlag>(s, h);
2100  EXPECT_TRUE(reader.HasParseError());
2102  EXPECT_EQ(7u, r.Offset());
2103  }
2104  {
2106  Reader reader;
2107  StringStream s("{\"t\": true, \"f\": false,}");
2108  ParseResult r = reader.Parse<extraFlags|kParseTrailingCommasFlag>(s, h);
2109  EXPECT_TRUE(reader.HasParseError());
2111  EXPECT_EQ(23u, r.Offset());
2112  }
2113 }
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
ParseErrorCode Code() const
Get the error code.
Definition: error.h:116
Allow trailing commas at the end of objects and arrays.
Definition: reader.h:154
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text.
Definition: reader.h:557
bool HasParseError() const
Whether a parse error has occurred in the last parsing.
Definition: reader.h:680
Read-only string stream.
Definition: fwd.h:47
Result of parsing (wraps ParseErrorCode)
Definition: error.h:106
Parsing was terminated.
Definition: error.h:88
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
size_t Offset() const
Get the error offset, if IsError(), 0 otherwise.
Definition: error.h:118
Here is the call graph for this function:

◆ TestTrailingCommas()

template<unsigned extraFlags>
void TestTrailingCommas ( )

Definition at line 1981 of file readertest.cpp.

1981  {
1982  {
1983  StringStream s("[1,2,3,]");
1985  Reader reader;
1986  EXPECT_TRUE(reader.Parse<extraFlags|kParseTrailingCommasFlag>(s, h));
1987  EXPECT_EQ(5u, h.step_);
1988  }
1989  {
1990  const char* json = "{ \"hello\" : \"world\", \"t\" : true , \"f\" : false,"
1991  "\"n\": null, \"i\":123, \"pi\": 3.1416, \"a\":[1, 2, 3],}";
1992  StringStream s(json);
1994  Reader reader;
1995  EXPECT_TRUE(reader.Parse<extraFlags|kParseTrailingCommasFlag>(s, h));
1996  EXPECT_EQ(20u, h.step_);
1997  }
1998  {
1999  // whitespace around trailing commas
2000  const char* json = "{ \"hello\" : \"world\", \"t\" : true , \"f\" : false,"
2001  "\"n\": null, \"i\":123, \"pi\": 3.1416, \"a\":[1, 2, 3\n,\n]\n,\n} ";
2002  StringStream s(json);
2004  Reader reader;
2005  EXPECT_TRUE(reader.Parse<extraFlags|kParseTrailingCommasFlag>(s, h));
2006  EXPECT_EQ(20u, h.step_);
2007  }
2008  {
2009  // comments around trailing commas
2010  const char* json = "{ \"hello\" : \"world\", \"t\" : true , \"f\" : false, \"n\": null,"
2011  "\"i\":123, \"pi\": 3.1416, \"a\":[1, 2, 3/*test*/,/*test*/]/*test*/,/*test*/}";
2012  StringStream s(json);
2014  Reader reader;
2016  EXPECT_EQ(20u, h.step_);
2017  }
2018 }
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
Allow trailing commas at the end of objects and arrays.
Definition: reader.h:154
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text.
Definition: reader.h:557
Read-only string stream.
Definition: fwd.h:47
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
rapidjson::Document json
Definition: transport.cpp:49
Allow one-line (//) and multi-line (/**/) comments.
Definition: reader.h:152
Here is the call graph for this function: