Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/miloyip/rapidjson.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMilo Yip <miloyip@gmail.com>2014-07-27 13:10:32 +0400
committerMilo Yip <miloyip@gmail.com>2014-07-27 13:10:32 +0400
commitc81386413b490536ca7d660e563a3cdf43bda28c (patch)
tree1547ea6daa60e1230edbc3d843329497df76c65c /test
parentc4ce48cde9eb5545aad6fec3bcde598ae90e3cb3 (diff)
Add kParseStopWhenDoneFlag, its implementation and related unit tests
Diffstat (limited to 'test')
-rw-r--r--test/unittest/readertest.cpp44
1 files changed, 32 insertions, 12 deletions
diff --git a/test/unittest/readertest.cpp b/test/unittest/readertest.cpp
index 1919e94a..78079e54 100644
--- a/test/unittest/readertest.cpp
+++ b/test/unittest/readertest.cpp
@@ -545,6 +545,38 @@ TEST(Reader, Parse_EmptyObject) {
EXPECT_EQ(2u, h.step_);
}
+struct ParseMultipleRootHandler : BaseReaderHandler<> {
+ ParseMultipleRootHandler() : step_(0) {}
+
+ bool Default() { ADD_FAILURE(); return false; }
+ bool StartObject() { EXPECT_EQ(0u, step_); step_++; return true; }
+ bool EndObject(SizeType) { EXPECT_EQ(1u, step_); step_++; return true; }
+ bool StartArray() { EXPECT_EQ(2u, step_); step_++; return true; }
+ bool EndArray(SizeType) { EXPECT_EQ(3u, step_); step_++; return true; }
+
+ unsigned step_;
+};
+
+template <unsigned parseFlags>
+void TestMultipleRoot() {
+ StringStream s("{}[]a");
+ ParseMultipleRootHandler h;
+ Reader reader;
+ EXPECT_TRUE(reader.Parse<parseFlags>(s, h));
+ EXPECT_EQ(2u, h.step_);
+ EXPECT_TRUE(reader.Parse<parseFlags>(s, h));
+ EXPECT_EQ(4u, h.step_);
+ EXPECT_EQ('a', s.Peek());
+}
+
+TEST(Reader, Parse_MultipleRoot) {
+ TestMultipleRoot<kParseStopWhenDoneFlag>();
+}
+
+TEST(Reader, ParseIterative_MultipleRoot) {
+ TestMultipleRoot<kParseIterativeFlag | kParseStopWhenDoneFlag>();
+}
+
#define TEST_ERROR(errorCode, str) \
{ \
char buffer[1001]; \
@@ -932,18 +964,6 @@ TEST(Reader, IterativeParsing_ShortCircuit) {
}
}
-TEST(Reader, IterativeParsing_LimitStackSize) {
- BaseReaderHandler<> handler;
- Reader reader(20);
- StringStream is("[[[]]]");
-
- ParseResult r = reader.Parse<kParseIterativeFlag>(is, handler);
-
- EXPECT_TRUE(reader.HasParseError());
- EXPECT_EQ(kParseErrorStackSizeLimitExceeded, r.Code());
- EXPECT_EQ(2u, r.Offset());
-}
-
#ifdef __GNUC__
RAPIDJSON_DIAG_POP
#endif