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