Add coverage for Document::ParseXXX()

This commit is contained in:
Milo Yip 2015-04-13 22:04:00 +08:00
parent 65bffef4b1
commit 3bc95ecd7c

View File

@ -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<> >();