Avoid potential negative array index access to cached text.
[LibreOffice.git] / tools / qa / cppunit / test_xmlwriter.cxx
blobeeb475030f89573714509f03f6b66df33f605ba8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 #include <cppunit/extensions/HelperMacros.h>
11 #include <test/bootstrapfixture.hxx>
12 #include <tools/stream.hxx>
13 #include <tools/XmlWriter.hxx>
15 namespace
17 class XmlWriterTest : public test::BootstrapFixture
19 public:
20 XmlWriterTest()
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");
43 aWriter.endElement();
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);
59 aWriter.endElement();
60 aWriter.endDocument();
62 aMemoryStream.Seek(0);
63 OString aString(static_cast<const char*>(aMemoryStream.GetData()), aMemoryStream.GetSize());
64 CPPUNIT_ASSERT_EQUAL("<test>&lt;&gt;</test>"_ostr, aString);
67 CPPUNIT_TEST_SUITE_REGISTRATION(XmlWriterTest);
70 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */