When I did the fast string concatenation, I didn't add any support for number(), which simply returned a O(U)String, and so it did the extra allocation/deallocation, although that could be avoided. In order to support this, number() now returns a special temporary return type, similarly to O(U)StringConcat, which allows delaying the concatenation the same way. Also similarly, the change of the return type in some cases requires explicit cast to the actual string type. Usage of OString::getStr() is so extensive in the codebase that I actually added it to the helper class, after that it's only relatively few cases. Change-Id: Iba6e158010e1e458089698c426803052b6f46031 Reviewed-on: https://gerrit.libreoffice.org/78873 Tested-by: Jenkins Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
88 lines
2.5 KiB
C++
88 lines
2.5 KiB
C++
/* -*- 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/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(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: */
|