summaryrefslogtreecommitdiff
path: root/tools/qa
diff options
context:
space:
mode:
authorNoel Grandin <noelgrandin@gmail.com>2020-06-15 20:32:25 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2020-06-18 10:54:10 +0200
commitc8bed6445b244a5d9021dbd9a2ff19d80c03917b (patch)
treecdfdf457f2617b4480961009e6b50a645d48c592 /tools/qa
parent41d75ee814d71513922a12fae82f2e7eecbcd5f5 (diff)
new json writer for LOK
we shave about 3 memory copies off in the process, and make the class play nicely with our string types. Change-Id: I1f614fb35b1de499ac99e3b33ac638ad81054bed Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96393 Tested-by: Noel Grandin <noel.grandin@collabora.co.uk> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'tools/qa')
-rw-r--r--tools/qa/cppunit/test_json_writer.cxx57
1 files changed, 57 insertions, 0 deletions
diff --git a/tools/qa/cppunit/test_json_writer.cxx b/tools/qa/cppunit/test_json_writer.cxx
new file mode 100644
index 000000000000..c4e9331c8d17
--- /dev/null
+++ b/tools/qa/cppunit/test_json_writer.cxx
@@ -0,0 +1,57 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <cppunit/extensions/HelperMacros.h>
+#include <test/bootstrapfixture.hxx>
+#include <rtl/ustring.hxx>
+#include <tools/stream.hxx>
+#include <tools/json_writer.hxx>
+
+namespace
+{
+class JsonWriterTest : public test::BootstrapFixture
+{
+public:
+ JsonWriterTest()
+ : BootstrapFixture(true, false)
+ {
+ }
+
+ virtual void setUp() override {}
+
+ void test1();
+
+ CPPUNIT_TEST_SUITE(JsonWriterTest);
+ CPPUNIT_TEST(test1);
+ CPPUNIT_TEST_SUITE_END();
+};
+
+void JsonWriterTest::test1()
+{
+ tools::JsonWriter aJson;
+
+ {
+ auto testNode = aJson.startNode("node");
+ aJson.put("oustring", OUString("val1"));
+ aJson.put("ostring", OString("val2"));
+ aJson.put("charptr", "val3");
+ aJson.put("int", 12);
+ }
+
+ std::unique_ptr<char[]> result(aJson.extractData());
+
+ CPPUNIT_ASSERT_EQUAL(std::string("{ \"node\": { \"oustring\": \"val1\", \"ostring\": \"val2\", "
+ "\"charptr\": \"val3\", \"int\": 12}}"),
+ std::string(result.get()));
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(JsonWriterTest);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */