From de0147fbf09ab2f654d7f7db31261725ef068b6f Mon Sep 17 00:00:00 2001 From: Kontinuation Date: Fri, 23 May 2014 21:56:00 +0800 Subject: [PATCH] added test case for the newly added JSON::Array::set function --- JSON/testsuite/src/JSONTest.cpp | 29 +++++++++++++++++++++++++++++ JSON/testsuite/src/JSONTest.h | 1 + 2 files changed, 30 insertions(+) diff --git a/JSON/testsuite/src/JSONTest.cpp b/JSON/testsuite/src/JSONTest.cpp index e034fc505..b6f5b5696 100644 --- a/JSON/testsuite/src/JSONTest.cpp +++ b/JSON/testsuite/src/JSONTest.cpp @@ -991,6 +991,34 @@ void JSONTest::testDoubleElement() } +void JSONTest::testSetArrayElement() +{ + std::string json = "[]"; + Parser parser; + Var result = parser.parse(json); + Poco::JSON::Array::Ptr array = result.extract(); + + // array[0] = 7 + array->set(0, 7); + assert(array->size() == 1); + assert(array->getElement(0) == 7); + + // array[2] = "foo" + array->set(2, std::string("foo")); + assert(array->size() == 3); + assert(array->getElement(0) == 7); + assert(array->isNull(1)); + assert(array->getElement(2) == "foo"); + + // array[1] = 13 + array->set(1, 13); + assert(array->size() == 3); + assert(array->getElement(0) == 7); + assert(array->getElement(1) == 13); + assert(array->getElement(2) == "foo"); +} + + void JSONTest::testOptValue() { std::string json = "{ }"; @@ -1717,6 +1745,7 @@ CppUnit::Test* JSONTest::suite() CppUnit_addTest(pSuite, JSONTest, testStringElement); CppUnit_addTest(pSuite, JSONTest, testEmptyObjectElement); CppUnit_addTest(pSuite, JSONTest, testDoubleElement); + CppUnit_addTest(pSuite, JSONTest, testSetArrayElement); CppUnit_addTest(pSuite, JSONTest, testOptValue); CppUnit_addTest(pSuite, JSONTest, testQuery); CppUnit_addTest(pSuite, JSONTest, testComment); diff --git a/JSON/testsuite/src/JSONTest.h b/JSON/testsuite/src/JSONTest.h index aec2e1fd2..a3640a537 100644 --- a/JSON/testsuite/src/JSONTest.h +++ b/JSON/testsuite/src/JSONTest.h @@ -53,6 +53,7 @@ public: void testStringElement(); void testEmptyObjectElement(); void testDoubleElement(); + void testSetArrayElement(); void testOptValue(); void testQuery(); void testComment();