mirror of
https://github.com/Tencent/rapidjson.git
synced 2025-03-10 03:29:59 +01:00
readertest.cpp: use top-level Parse functions, instead of internal ones
With the allowance of arbitrary root value types, the individual tests can use the top-level Parse functions, instead of ParseFoo() variants. Secondly, some unneeded array wrappers have been dropped and non-singular tests starting with other values than objects or arrays have been added.
This commit is contained in:
parent
24b7976145
commit
e29a4521b1
@ -45,7 +45,7 @@ TEST(Reader, ParseTrue) {
|
|||||||
StringStream s("true");
|
StringStream s("true");
|
||||||
ParseBoolHandler<true> h;
|
ParseBoolHandler<true> h;
|
||||||
Reader reader;
|
Reader reader;
|
||||||
reader.ParseTrue<0>(s, h);
|
reader.Parse(s, h);
|
||||||
EXPECT_EQ(1u, h.step_);
|
EXPECT_EQ(1u, h.step_);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,11 +53,11 @@ TEST(Reader, ParseFalse) {
|
|||||||
StringStream s("false");
|
StringStream s("false");
|
||||||
ParseBoolHandler<false> h;
|
ParseBoolHandler<false> h;
|
||||||
Reader reader;
|
Reader reader;
|
||||||
reader.ParseFalse<0>(s, h);
|
reader.Parse(s, h);
|
||||||
EXPECT_EQ(1u, h.step_);
|
EXPECT_EQ(1u, h.step_);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ParseIntHandler : BaseReaderHandler<> {
|
struct ParseIntHandler : BaseReaderHandler<UTF8<>, ParseIntHandler> {
|
||||||
ParseIntHandler() : step_(0), actual_() {}
|
ParseIntHandler() : step_(0), actual_() {}
|
||||||
bool Default() { ADD_FAILURE(); return false; }
|
bool Default() { ADD_FAILURE(); return false; }
|
||||||
bool Int(int i) { actual_ = i; step_++; return true; }
|
bool Int(int i) { actual_ = i; step_++; return true; }
|
||||||
@ -108,7 +108,7 @@ TEST(Reader, ParseNumberHandler) {
|
|||||||
StringStream s(str); \
|
StringStream s(str); \
|
||||||
Handler h; \
|
Handler h; \
|
||||||
Reader reader; \
|
Reader reader; \
|
||||||
reader.ParseNumber<0>(s, h); \
|
reader.Parse(s, h); \
|
||||||
EXPECT_EQ(1u, h.step_); \
|
EXPECT_EQ(1u, h.step_); \
|
||||||
EXPECT_EQ(double(x), h.actual_); \
|
EXPECT_EQ(double(x), h.actual_); \
|
||||||
}
|
}
|
||||||
@ -118,7 +118,7 @@ TEST(Reader, ParseNumberHandler) {
|
|||||||
StringStream s(str); \
|
StringStream s(str); \
|
||||||
ParseDoubleHandler h; \
|
ParseDoubleHandler h; \
|
||||||
Reader reader; \
|
Reader reader; \
|
||||||
reader.ParseNumber<0>(s, h); \
|
reader.Parse(s, h); \
|
||||||
EXPECT_EQ(1u, h.step_); \
|
EXPECT_EQ(1u, h.step_); \
|
||||||
EXPECT_DOUBLE_EQ(x, h.actual_); \
|
EXPECT_DOUBLE_EQ(x, h.actual_); \
|
||||||
}
|
}
|
||||||
@ -178,11 +178,11 @@ TEST(Reader, ParseNumber_Error) {
|
|||||||
#define TEST_NUMBER_ERROR(errorCode, str) \
|
#define TEST_NUMBER_ERROR(errorCode, str) \
|
||||||
{ \
|
{ \
|
||||||
char buffer[1001]; \
|
char buffer[1001]; \
|
||||||
sprintf(buffer, "[%s]", str); \
|
sprintf(buffer, "%s", str); \
|
||||||
InsituStringStream s(buffer); \
|
InsituStringStream s(buffer); \
|
||||||
BaseReaderHandler<> h; \
|
BaseReaderHandler<> h; \
|
||||||
Reader reader; \
|
Reader reader; \
|
||||||
EXPECT_FALSE(reader.Parse<0>(s, h)); \
|
EXPECT_FALSE(reader.Parse(s, h)); \
|
||||||
EXPECT_EQ(errorCode, reader.GetParseErrorCode());\
|
EXPECT_EQ(errorCode, reader.GetParseErrorCode());\
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -242,14 +242,14 @@ TEST(Reader, ParseString) {
|
|||||||
GenericInsituStringStream<Encoding> is(buffer); \
|
GenericInsituStringStream<Encoding> is(buffer); \
|
||||||
ParseStringHandler<Encoding> h; \
|
ParseStringHandler<Encoding> h; \
|
||||||
GenericReader<Encoding, Encoding> reader; \
|
GenericReader<Encoding, Encoding> reader; \
|
||||||
reader.ParseString<kParseInsituFlag | kParseValidateEncodingFlag>(is, h); \
|
reader.Parse<kParseInsituFlag | kParseValidateEncodingFlag>(is, h); \
|
||||||
EXPECT_EQ(0, StrCmp<Encoding::Ch>(e, h.str_)); \
|
EXPECT_EQ(0, StrCmp<Encoding::Ch>(e, h.str_)); \
|
||||||
EXPECT_EQ(StrLen(e), h.length_); \
|
EXPECT_EQ(StrLen(e), h.length_); \
|
||||||
free(buffer); \
|
free(buffer); \
|
||||||
GenericStringStream<Encoding> s(x); \
|
GenericStringStream<Encoding> s(x); \
|
||||||
ParseStringHandler<Encoding> h2; \
|
ParseStringHandler<Encoding> h2; \
|
||||||
GenericReader<Encoding, Encoding> reader2; \
|
GenericReader<Encoding, Encoding> reader2; \
|
||||||
reader2.ParseString<0>(s, h2); \
|
reader2.Parse(s, h2); \
|
||||||
EXPECT_EQ(0, StrCmp<Encoding::Ch>(e, h2.str_)); \
|
EXPECT_EQ(0, StrCmp<Encoding::Ch>(e, h2.str_)); \
|
||||||
EXPECT_EQ(StrLen(e), h2.length_); \
|
EXPECT_EQ(StrLen(e), h2.length_); \
|
||||||
}
|
}
|
||||||
@ -314,7 +314,7 @@ TEST(Reader, ParseString) {
|
|||||||
const char e[] = "Hello\0World";
|
const char e[] = "Hello\0World";
|
||||||
ParseStringHandler<UTF8<> > h;
|
ParseStringHandler<UTF8<> > h;
|
||||||
Reader reader;
|
Reader reader;
|
||||||
reader.ParseString<0>(s, h);
|
reader.Parse(s, h);
|
||||||
EXPECT_EQ(0, memcmp(e, h.str_, h.length_ + 1));
|
EXPECT_EQ(0, memcmp(e, h.str_, h.length_ + 1));
|
||||||
EXPECT_EQ(11u, h.length_);
|
EXPECT_EQ(11u, h.length_);
|
||||||
}
|
}
|
||||||
@ -326,7 +326,7 @@ TEST(Reader, ParseString_Transcoding) {
|
|||||||
GenericStringStream<UTF8<> > is(x);
|
GenericStringStream<UTF8<> > is(x);
|
||||||
GenericReader<UTF8<>, UTF16<> > reader;
|
GenericReader<UTF8<>, UTF16<> > reader;
|
||||||
ParseStringHandler<UTF16<> > h;
|
ParseStringHandler<UTF16<> > h;
|
||||||
reader.ParseString<0>(is, h);
|
reader.Parse(is, h);
|
||||||
EXPECT_EQ(0, StrCmp<UTF16<>::Ch>(e, h.str_));
|
EXPECT_EQ(0, StrCmp<UTF16<>::Ch>(e, h.str_));
|
||||||
EXPECT_EQ(StrLen(e), h.length_);
|
EXPECT_EQ(StrLen(e), h.length_);
|
||||||
}
|
}
|
||||||
@ -335,7 +335,7 @@ TEST(Reader, ParseString_NonDestructive) {
|
|||||||
StringStream s("\"Hello\\nWorld\"");
|
StringStream s("\"Hello\\nWorld\"");
|
||||||
ParseStringHandler<UTF8<> > h;
|
ParseStringHandler<UTF8<> > h;
|
||||||
Reader reader;
|
Reader reader;
|
||||||
reader.ParseString<0>(s, h);
|
reader.Parse(s, h);
|
||||||
EXPECT_EQ(0, StrCmp("Hello\nWorld", h.str_));
|
EXPECT_EQ(0, StrCmp("Hello\nWorld", h.str_));
|
||||||
EXPECT_EQ(11u, h.length_);
|
EXPECT_EQ(11u, h.length_);
|
||||||
}
|
}
|
||||||
@ -447,7 +447,7 @@ TEST(Reader, ParseEmptyArray) {
|
|||||||
InsituStringStream s(json);
|
InsituStringStream s(json);
|
||||||
ParseArrayHandler<0> h;
|
ParseArrayHandler<0> h;
|
||||||
Reader reader;
|
Reader reader;
|
||||||
reader.ParseArray<0>(s, h);
|
reader.Parse(s, h);
|
||||||
EXPECT_EQ(2u, h.step_);
|
EXPECT_EQ(2u, h.step_);
|
||||||
free(json);
|
free(json);
|
||||||
}
|
}
|
||||||
@ -457,7 +457,7 @@ TEST(Reader, ParseArray) {
|
|||||||
InsituStringStream s(json);
|
InsituStringStream s(json);
|
||||||
ParseArrayHandler<4> h;
|
ParseArrayHandler<4> h;
|
||||||
Reader reader;
|
Reader reader;
|
||||||
reader.ParseArray<0>(s, h);
|
reader.Parse(s, h);
|
||||||
EXPECT_EQ(6u, h.step_);
|
EXPECT_EQ(6u, h.step_);
|
||||||
free(json);
|
free(json);
|
||||||
}
|
}
|
||||||
@ -470,7 +470,7 @@ TEST(Reader, ParseArray_Error) {
|
|||||||
InsituStringStream s(buffer); \
|
InsituStringStream s(buffer); \
|
||||||
BaseReaderHandler<> h; \
|
BaseReaderHandler<> h; \
|
||||||
GenericReader<UTF8<>, UTF8<>, CrtAllocator> reader; \
|
GenericReader<UTF8<>, UTF8<>, CrtAllocator> reader; \
|
||||||
EXPECT_FALSE(reader.Parse<0>(s, h)); \
|
EXPECT_FALSE(reader.Parse(s, h)); \
|
||||||
EXPECT_EQ(errorCode, reader.GetParseErrorCode());\
|
EXPECT_EQ(errorCode, reader.GetParseErrorCode());\
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -534,7 +534,7 @@ TEST(Reader, ParseObject) {
|
|||||||
InsituStringStream s(json2);
|
InsituStringStream s(json2);
|
||||||
ParseObjectHandler h;
|
ParseObjectHandler h;
|
||||||
Reader reader;
|
Reader reader;
|
||||||
reader.ParseObject<kParseInsituFlag>(s, h);
|
reader.Parse<kParseInsituFlag>(s, h);
|
||||||
EXPECT_EQ(20u, h.step_);
|
EXPECT_EQ(20u, h.step_);
|
||||||
free(json2);
|
free(json2);
|
||||||
}
|
}
|
||||||
@ -544,7 +544,7 @@ TEST(Reader, ParseObject) {
|
|||||||
StringStream s(json);
|
StringStream s(json);
|
||||||
ParseObjectHandler h;
|
ParseObjectHandler h;
|
||||||
Reader reader;
|
Reader reader;
|
||||||
reader.ParseObject<0>(s, h);
|
reader.Parse(s, h);
|
||||||
EXPECT_EQ(20u, h.step_);
|
EXPECT_EQ(20u, h.step_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -563,7 +563,7 @@ TEST(Reader, Parse_EmptyObject) {
|
|||||||
StringStream s("{ } ");
|
StringStream s("{ } ");
|
||||||
ParseEmptyObjectHandler h;
|
ParseEmptyObjectHandler h;
|
||||||
Reader reader;
|
Reader reader;
|
||||||
reader.ParseObject<0>(s, h);
|
reader.Parse(s, h);
|
||||||
EXPECT_EQ(2u, h.step_);
|
EXPECT_EQ(2u, h.step_);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -630,7 +630,7 @@ TEST(Reader, ParseInsituIterative_MultipleRoot) {
|
|||||||
InsituStringStream s(buffer); \
|
InsituStringStream s(buffer); \
|
||||||
BaseReaderHandler<> h; \
|
BaseReaderHandler<> h; \
|
||||||
Reader reader; \
|
Reader reader; \
|
||||||
EXPECT_FALSE(reader.Parse<0>(s, h)); \
|
EXPECT_FALSE(reader.Parse(s, h)); \
|
||||||
EXPECT_EQ(errorCode, reader.GetParseErrorCode());\
|
EXPECT_EQ(errorCode, reader.GetParseErrorCode());\
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -643,15 +643,17 @@ TEST(Reader, ParseDocument_Error) {
|
|||||||
// The document root must not follow by other values.
|
// The document root must not follow by other values.
|
||||||
TEST_ERROR(kParseErrorDocumentRootNotSingular, "[] 0");
|
TEST_ERROR(kParseErrorDocumentRootNotSingular, "[] 0");
|
||||||
TEST_ERROR(kParseErrorDocumentRootNotSingular, "{} 0");
|
TEST_ERROR(kParseErrorDocumentRootNotSingular, "{} 0");
|
||||||
|
TEST_ERROR(kParseErrorDocumentRootNotSingular, "null []");
|
||||||
|
TEST_ERROR(kParseErrorDocumentRootNotSingular, "0 {}");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Reader, ParseValue_Error) {
|
TEST(Reader, ParseValue_Error) {
|
||||||
// Invalid value.
|
// Invalid value.
|
||||||
TEST_ERROR(kParseErrorValueInvalid, "[nulL]");
|
TEST_ERROR(kParseErrorValueInvalid, "nulL");
|
||||||
TEST_ERROR(kParseErrorValueInvalid, "[truE]");
|
TEST_ERROR(kParseErrorValueInvalid, "truE");
|
||||||
TEST_ERROR(kParseErrorValueInvalid, "[falsE]");
|
TEST_ERROR(kParseErrorValueInvalid, "falsE");
|
||||||
TEST_ERROR(kParseErrorValueInvalid, "[a]");
|
TEST_ERROR(kParseErrorValueInvalid, "a]");
|
||||||
TEST_ERROR(kParseErrorValueInvalid, "[.1]");
|
TEST_ERROR(kParseErrorValueInvalid, ".1");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Reader, ParseObject_Error) {
|
TEST(Reader, ParseObject_Error) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user