nss: upgrade to release 3.73
[LibreOffice.git] / tools / qa / cppunit / test_json_writer.cxx
blobd5c037801067863fc1e29a5678846d3e0cb6c1cc
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include <sal/config.h>
12 #include <cstdlib>
14 #include <cppunit/extensions/HelperMacros.h>
15 #include <o3tl/deleter.hxx>
16 #include <test/bootstrapfixture.hxx>
17 #include <rtl/ustring.hxx>
18 #include <tools/stream.hxx>
19 #include <tools/json_writer.hxx>
21 namespace
23 class JsonWriterTest : public test::BootstrapFixture
25 public:
26 JsonWriterTest()
27 : BootstrapFixture(true, false)
31 virtual void setUp() override {}
33 void test1();
34 void test2();
36 CPPUNIT_TEST_SUITE(JsonWriterTest);
37 CPPUNIT_TEST(test1);
38 CPPUNIT_TEST(test2);
39 CPPUNIT_TEST_SUITE_END();
42 void JsonWriterTest::test1()
44 tools::JsonWriter aJson;
47 auto testNode = aJson.startNode("node");
48 aJson.put("oustring", OUString("val1"));
49 aJson.put("ostring", OString("val2"));
50 aJson.put("charptr", "val3");
51 aJson.put("int", static_cast<sal_Int32>(12));
54 std::unique_ptr<char, o3tl::free_delete> result(aJson.extractData());
56 CPPUNIT_ASSERT_EQUAL(std::string("{ \"node\": { \"oustring\": \"val1\", \"ostring\": \"val2\", "
57 "\"charptr\": \"val3\", \"int\": 12}}"),
58 std::string(result.get()));
61 void JsonWriterTest::test2()
63 tools::JsonWriter aJson;
66 auto testNode = aJson.startNode("node");
67 aJson.put("field1", OUString("val1"));
68 aJson.put("field2", OUString("val2"));
70 auto testNode2 = aJson.startNode("node");
71 aJson.put("field3", OUString("val3"));
73 auto testNode3 = aJson.startNode("node");
74 aJson.put("field4", OUString("val4"));
75 aJson.put("field5", OUString("val5"));
80 std::unique_ptr<char, o3tl::free_delete> result(aJson.extractData());
82 CPPUNIT_ASSERT_EQUAL(std::string("{ \"node\": { \"field1\": \"val1\", \"field2\": \"val2\", "
83 "\"node\": { \"field3\": \"val3\", \"node\": { \"field4\": "
84 "\"val4\", \"field5\": \"val5\"}}}}"),
85 std::string(result.get()));
88 CPPUNIT_TEST_SUITE_REGISTRATION(JsonWriterTest);
91 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */