diff options
author | Noel Grandin <noelgrandin@gmail.com> | 2020-06-18 21:39:30 +0200 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2020-08-10 23:07:20 +0200 |
commit | 29954dbeb16ef206940a8fe7ed94e487f842d17a (patch) | |
tree | f2f11352b7df4e3cfc68e8afdb86e894cb59d1e2 /tools/qa/cppunit | |
parent | cf6388b6a5f3e3baa54ed8b02020e9a25487b32b (diff) |
improvements to JSON Writer
part of the master commit cb95276e6e6bf12a1c06d5c252551e55c788fcb2
Change-Id: Icf18fb4b3ebced375196a8cdbd2a543acf4e43c5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100444
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'tools/qa/cppunit')
-rw-r--r-- | tools/qa/cppunit/test_json_writer.cxx | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/tools/qa/cppunit/test_json_writer.cxx b/tools/qa/cppunit/test_json_writer.cxx index e27afc95f712..6a2cc7813574 100644 --- a/tools/qa/cppunit/test_json_writer.cxx +++ b/tools/qa/cppunit/test_json_writer.cxx @@ -30,12 +30,19 @@ public: virtual void setUp() override {} void test1(); + void test2(); CPPUNIT_TEST_SUITE(JsonWriterTest); CPPUNIT_TEST(test1); + CPPUNIT_TEST(test2); CPPUNIT_TEST_SUITE_END(); }; +struct Free +{ + void operator()(void* p) const { std::free(p); } +}; + void JsonWriterTest::test1() { tools::JsonWriter aJson; @@ -48,10 +55,6 @@ void JsonWriterTest::test1() aJson.put("int", 12); } - struct Free - { - void operator()(void* p) const { std::free(p); } - }; std::unique_ptr<char, Free> result(aJson.extractData()); CPPUNIT_ASSERT_EQUAL(std::string("{ \"node\": { \"oustring\": \"val1\", \"ostring\": \"val2\", " @@ -59,6 +62,33 @@ void JsonWriterTest::test1() std::string(result.get())); } +void JsonWriterTest::test2() +{ + tools::JsonWriter aJson; + + { + auto testNode = aJson.startNode("node"); + aJson.put("field1", OUString("val1")); + aJson.put("field2", OUString("val2")); + { + auto testNode2 = aJson.startNode("node"); + aJson.put("field3", OUString("val3")); + { + auto testNode3 = aJson.startNode("node"); + aJson.put("field4", OUString("val4")); + aJson.put("field5", OUString("val5")); + } + } + } + + std::unique_ptr<char, Free> result(aJson.extractData()); + + CPPUNIT_ASSERT_EQUAL(std::string("{ \"node\": { \"field1\": \"val1\", \"field2\": \"val2\", " + "\"node\": { \"field3\": \"val3\", \"node\": { \"field4\": " + "\"val4\", \"field5\": \"val5\"}}}}"), + std::string(result.get())); +} + CPPUNIT_TEST_SUITE_REGISTRATION(JsonWriterTest); } |