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 <tools/stream.hxx>
13 #include <tools/XmlWriter.hxx>
17 class XmlWriterTest
: public test::BootstrapFixture
21 : BootstrapFixture(true, false)
25 virtual void setUp() override
{}
27 void testSimpleRoot();
28 void testSpecialChars();
30 CPPUNIT_TEST_SUITE(XmlWriterTest
);
31 CPPUNIT_TEST(testSimpleRoot
);
32 CPPUNIT_TEST(testSpecialChars
);
33 CPPUNIT_TEST_SUITE_END();
36 void XmlWriterTest::testSimpleRoot()
38 SvMemoryStream aMemoryStream
;
40 tools::XmlWriter
aWriter(&aMemoryStream
);
41 aWriter
.startDocument(0, false);
42 aWriter
.startElement("test");
44 aWriter
.endDocument();
46 aMemoryStream
.Seek(0);
47 OString
aString(static_cast<const char*>(aMemoryStream
.GetData()), aMemoryStream
.GetSize());
48 CPPUNIT_ASSERT_EQUAL("<test/>"_ostr
, aString
);
51 void XmlWriterTest::testSpecialChars()
53 SvMemoryStream aMemoryStream
;
55 tools::XmlWriter
aWriter(&aMemoryStream
);
56 aWriter
.startDocument(0, false);
57 aWriter
.startElement("test");
58 aWriter
.content("<>"_ostr
);
60 aWriter
.endDocument();
62 aMemoryStream
.Seek(0);
63 OString
aString(static_cast<const char*>(aMemoryStream
.GetData()), aMemoryStream
.GetSize());
64 CPPUNIT_ASSERT_EQUAL("<test><></test>"_ostr
, aString
);
67 CPPUNIT_TEST_SUITE_REGISTRATION(XmlWriterTest
);
70 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */