[Libreoffice-commits] core.git: tools/CppunitTest_tools_test.mk tools/qa
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Wed Jan 23 09:56:41 UTC 2019
tools/CppunitTest_tools_test.mk | 7 ++
tools/qa/cppunit/test_xmlwalker.cxx | 91 ++++++++++++++++++++++++++++++++++++
tools/qa/data/test.xml | 11 ++++
3 files changed, 109 insertions(+)
New commits:
commit bb30e9e591d5f9f913b3cd8fbaa3c5e412b509bd
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Wed Jan 23 09:53:59 2019 +0100
Commit: Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Wed Jan 23 10:56:14 2019 +0100
Test for XmlWalker to check it parses the xml as expected
Change-Id: Icf6bc7eee09b469f460080b6937fad93de6dbd39
Reviewed-on: https://gerrit.libreoffice.org/66772
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
diff --git a/tools/CppunitTest_tools_test.mk b/tools/CppunitTest_tools_test.mk
index 7cf5657e68ec..3971606c9a9d 100644
--- a/tools/CppunitTest_tools_test.mk
+++ b/tools/CppunitTest_tools_test.mk
@@ -28,6 +28,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,tools_test, \
tools/qa/cppunit/test_minmax \
tools/qa/cppunit/test_100mm2twips \
tools/qa/cppunit/test_fround \
+ tools/qa/cppunit/test_xmlwalker \
))
$(eval $(call gb_CppunitTest_use_sdk_api,tools_test))
@@ -35,6 +36,8 @@ $(eval $(call gb_CppunitTest_use_sdk_api,tools_test))
$(eval $(call gb_CppunitTest_use_libraries,tools_test, \
sal \
tl \
+ test \
+ unotest \
))
$(eval $(call gb_CppunitTest_use_static_libraries,tools_test, \
@@ -46,4 +49,8 @@ $(eval $(call gb_CppunitTest_set_include,tools_test,\
-I$(SRCDIR)/tools/inc \
))
+$(eval $(call gb_Library_use_externals,tools_test,\
+ libxml2 \
+))
+
# vim: set noet sw=4 ts=4:
diff --git a/tools/qa/cppunit/test_xmlwalker.cxx b/tools/qa/cppunit/test_xmlwalker.cxx
new file mode 100644
index 000000000000..d10221937145
--- /dev/null
+++ b/tools/qa/cppunit/test_xmlwalker.cxx
@@ -0,0 +1,91 @@
+/* -*- 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 <memory>
+#include <string>
+
+#include <sal/types.h>
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+#include <test/bootstrapfixture.hxx>
+#include <rtl/ustring.hxx>
+#include <tools/stream.hxx>
+#include <tools/XmlWalker.hxx>
+
+namespace
+{
+class XmlWalkerTest : public test::BootstrapFixture
+{
+ OUString maBasePath;
+
+public:
+ XmlWalkerTest()
+ : BootstrapFixture(true, false)
+ {
+ }
+
+ virtual void setUp() override { maBasePath = m_directories.getURLFromSrc("/tools/qa/data/"); }
+
+ void testReadXML();
+
+ CPPUNIT_TEST_SUITE(XmlWalkerTest);
+ CPPUNIT_TEST(testReadXML);
+ CPPUNIT_TEST_SUITE_END();
+};
+
+void XmlWalkerTest::testReadXML()
+{
+ OUString aXmlFilePath = maBasePath + "test.xml";
+
+ tools::XmlWalker aWalker;
+ SvFileStream aFileStream(aXmlFilePath, StreamMode::READ);
+ CPPUNIT_ASSERT(aWalker.open(&aFileStream));
+ CPPUNIT_ASSERT_EQUAL(OString("root"), aWalker.name());
+ CPPUNIT_ASSERT_EQUAL(OString("Hello World"), aWalker.attribute("root-attr"));
+
+ int nNumberOfChildNodes = 0;
+
+ aWalker.children();
+ while (aWalker.isValid())
+ {
+ if (aWalker.name() == "child")
+ {
+ nNumberOfChildNodes++;
+
+ CPPUNIT_ASSERT_EQUAL(OString::number(nNumberOfChildNodes), aWalker.attribute("number"));
+
+ if (nNumberOfChildNodes == 1) // only the first node has the attribute
+ CPPUNIT_ASSERT_EQUAL(OString("123"), aWalker.attribute("attribute"));
+ else
+ CPPUNIT_ASSERT_EQUAL(OString(), aWalker.attribute("attribute"));
+
+ aWalker.children();
+ while (aWalker.isValid())
+ {
+ if (aWalker.name() == "grandchild")
+ {
+ CPPUNIT_ASSERT_EQUAL(OString("ABC"), aWalker.attribute("attribute1"));
+ CPPUNIT_ASSERT_EQUAL(OString("CDE"), aWalker.attribute("attribute2"));
+ CPPUNIT_ASSERT_EQUAL(OString("Content"), aWalker.content());
+ }
+ aWalker.next();
+ }
+ aWalker.parent();
+ }
+ aWalker.next();
+ }
+ aWalker.parent();
+
+ CPPUNIT_ASSERT_EQUAL(3, nNumberOfChildNodes);
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(XmlWalkerTest);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/tools/qa/data/test.xml b/tools/qa/data/test.xml
new file mode 100644
index 000000000000..7a0473d7f8f9
--- /dev/null
+++ b/tools/qa/data/test.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<root root-attr="Hello World">
+ <child number="1" attribute="123">
+ <grandchild attribute1="ABC" attribute2="CDE">Content</grandchild>
+ </child>
+ <child number="2">
+ </child>
+ <child number="3">
+ </child>
+</root>
More information about the Libreoffice-commits
mailing list