1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #include <cppunit/extensions/HelperMacros.h>
11 #include <test/bootstrapfixture.hxx>
12 #include <rtl/ustring.hxx>
13 #include <tools/stream.hxx>
14 #include <tools/XmlWalker.hxx>
18 class XmlWalkerTest
: public test::BootstrapFixture
24 : BootstrapFixture(true, false)
28 virtual void setUp() override
{ maBasePath
= m_directories
.getURLFromSrc("/tools/qa/data/"); }
32 CPPUNIT_TEST_SUITE(XmlWalkerTest
);
33 CPPUNIT_TEST(testReadXML
);
34 CPPUNIT_TEST_SUITE_END();
37 void XmlWalkerTest::testReadXML()
39 OUString aXmlFilePath
= maBasePath
+ "test.xml";
41 tools::XmlWalker aWalker
;
42 SvFileStream
aFileStream(aXmlFilePath
, StreamMode::READ
);
43 CPPUNIT_ASSERT(aWalker
.open(&aFileStream
));
44 CPPUNIT_ASSERT_EQUAL(OString("root"), aWalker
.name());
45 CPPUNIT_ASSERT_EQUAL(OString("Hello World"), aWalker
.attribute("root-attr"));
47 int nNumberOfChildNodes
= 0;
50 while (aWalker
.isValid())
52 if (aWalker
.name() == "child")
54 nNumberOfChildNodes
++;
56 CPPUNIT_ASSERT_EQUAL(OString(OString::number(nNumberOfChildNodes
)),
57 aWalker
.attribute("number"));
59 if (nNumberOfChildNodes
== 1) // only the first node has the attribute
60 CPPUNIT_ASSERT_EQUAL(OString("123"), aWalker
.attribute("attribute"));
62 CPPUNIT_ASSERT_EQUAL(OString(), aWalker
.attribute("attribute"));
65 while (aWalker
.isValid())
67 if (aWalker
.name() == "grandchild")
69 CPPUNIT_ASSERT_EQUAL(OString("ABC"), aWalker
.attribute("attribute1"));
70 CPPUNIT_ASSERT_EQUAL(OString("CDE"), aWalker
.attribute("attribute2"));
71 CPPUNIT_ASSERT_EQUAL(OString("Content"), aWalker
.content());
81 CPPUNIT_ASSERT_EQUAL(3, nNumberOfChildNodes
);
84 CPPUNIT_TEST_SUITE_REGISTRATION(XmlWalkerTest
);
87 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */