Commit 3bc95ecd authored by Milo Yip's avatar Milo Yip

Add coverage for Document::ParseXXX()

parent 65bffef4
......@@ -28,13 +28,9 @@
using namespace rapidjson;
template <typename Allocator, typename StackAllocator>
void ParseTest() {
typedef GenericDocument<UTF8<>, Allocator, StackAllocator> DocumentType;
template <typename DocumentType>
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 <typename Allocator, typename StackAllocator>
void ParseTest() {
typedef GenericDocument<UTF8<>, 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<MemoryPoolAllocator<>, CrtAllocator>();
ParseTest<MemoryPoolAllocator<>, MemoryPoolAllocator<> >();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment