From 3bc95ecd7c8e2cc8aa1c053dc97294fa5e807587 Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Mon, 13 Apr 2015 22:04:00 +0800 Subject: [PATCH] Add coverage for Document::ParseXXX() --- test/unittest/documenttest.cpp | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/test/unittest/documenttest.cpp b/test/unittest/documenttest.cpp index 12ea751..e185efb 100644 --- a/test/unittest/documenttest.cpp +++ b/test/unittest/documenttest.cpp @@ -28,13 +28,9 @@ using namespace rapidjson; -template -void ParseTest() { - typedef GenericDocument, Allocator, StackAllocator> DocumentType; +template +void ParseCheck(DocumentType& doc) { typedef typename DocumentType::ValueType ValueType; - DocumentType doc; - - doc.Parse(" { \"hello\" : \"world\", \"t\" : true , \"f\" : false, \"n\": null, \"i\":123, \"pi\": 3.1416, \"a\":[1, 2, 3, 4] } "); EXPECT_TRUE(doc.IsObject()); @@ -73,6 +69,28 @@ void ParseTest() { EXPECT_EQ(i + 1, a[i].GetUint()); } +template +void ParseTest() { + typedef GenericDocument, Allocator, StackAllocator> DocumentType; + DocumentType doc; + + const char* json = " { \"hello\" : \"world\", \"t\" : true , \"f\" : false, \"n\": null, \"i\":123, \"pi\": 3.1416, \"a\":[1, 2, 3, 4] } "; + + EXPECT_FALSE(doc.Parse(json).HasParseError()); + ParseCheck(doc); + + doc.SetNull(); + StringStream s(json); + EXPECT_FALSE(doc.ParseStream<0>( s).HasParseError()); + ParseCheck(doc); + + doc.SetNull(); + char *buffer = strdup(json); + EXPECT_FALSE(doc.ParseInsitu(buffer).HasParseError()); + ParseCheck(doc); + free(buffer); +} + TEST(Document, Parse) { ParseTest, CrtAllocator>(); ParseTest, MemoryPoolAllocator<> >();