From 2d920e7e0f083c1719d6fa472dad1d1a03e500e9 Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Wed, 25 Feb 2015 21:48:58 +0800 Subject: [PATCH] Add user buffer unit test --- test/unittest/documenttest.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/unittest/documenttest.cpp b/test/unittest/documenttest.cpp index 93f7a3d..3222351 100644 --- a/test/unittest/documenttest.cpp +++ b/test/unittest/documenttest.cpp @@ -212,6 +212,19 @@ TEST(Document, AcceptWriter) { EXPECT_EQ("{\"hello\":\"world\",\"t\":true,\"f\":false,\"n\":null,\"i\":123,\"pi\":3.1416,\"a\":[1,2,3,4]}", os.str()); } +TEST(Document, UserBuffer) { + typedef GenericDocument, MemoryPoolAllocator<>, MemoryPoolAllocator<>> DocumentType; + char valueBuffer[4096]; + char parseBuffer[1024]; + MemoryPoolAllocator<> valueAllocator(valueBuffer, sizeof(valueBuffer)); + MemoryPoolAllocator<> parseAllocator(parseBuffer, sizeof(parseBuffer)); + DocumentType doc(&valueAllocator, sizeof(parseBuffer), &parseAllocator); + doc.Parse(" { \"hello\" : \"world\", \"t\" : true , \"f\" : false, \"n\": null, \"i\":123, \"pi\": 3.1416, \"a\":[1, 2, 3, 4] } "); + EXPECT_FALSE(doc.HasParseError()); + EXPECT_LE(valueAllocator.Size(), sizeof(valueBuffer)); + EXPECT_LE(parseAllocator.Size(), sizeof(parseBuffer)); +} + // Issue 226: Value of string type should not point to NULL TEST(Document, AssertAcceptInvalidNameType) { Document doc;