bump product version to 6.3.0.0.beta1
[LibreOffice.git] / svtools / qa / unit / testHtmlWriter.cxx
blob86da936b8ce8d690b5e8224101fa989f8cdb6ac6
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/.
9 */
11 #include <cppunit/TestCase.h>
12 #include <cppunit/TestFixture.h>
13 #include <cppunit/TestSuite.h>
14 #include <cppunit/extensions/HelperMacros.h>
15 #include <cppunit/plugin/TestPlugIn.h>
17 #include <unotest/bootstrapfixturebase.hxx>
18 #include <tools/stream.hxx>
19 #include <svtools/HtmlWriter.hxx>
21 namespace
24 OString extractFromStream(SvMemoryStream& rStream)
26 rStream.WriteChar('\0');
27 rStream.Flush();
28 rStream.Seek(STREAM_SEEK_TO_BEGIN);
29 return OString(static_cast<const sal_Char*>(rStream.GetData()));
34 class Test: public CppUnit::TestFixture
38 CPPUNIT_TEST_FIXTURE(Test, testSingleElement)
41 SvMemoryStream aStream;
43 HtmlWriter aHtml(aStream);
44 aHtml.prettyPrint(false);
45 aHtml.start("abc");
46 aHtml.end();
48 OString aString = extractFromStream(aStream);
49 CPPUNIT_ASSERT_EQUAL(OString("<abc/>"), aString);
53 SvMemoryStream aStream;
55 HtmlWriter aHtml(aStream);
56 aHtml.prettyPrint(false);
57 aHtml.single("abc");
59 OString aString = extractFromStream(aStream);
61 CPPUNIT_ASSERT_EQUAL(OString("<abc/>"), aString);
65 CPPUNIT_TEST_FIXTURE(Test, testSingleElementWithAttributes)
68 SvMemoryStream aStream;
70 HtmlWriter aHtml(aStream);
71 aHtml.prettyPrint(false);
72 aHtml.start("abc");
73 aHtml.attribute("x", "y");
74 aHtml.end();
76 OString aString = extractFromStream(aStream);
78 CPPUNIT_ASSERT_EQUAL(OString("<abc x=\"y\"/>"), aString);
82 SvMemoryStream aStream;
84 HtmlWriter aHtml(aStream);
85 aHtml.prettyPrint(false);
86 aHtml.start("abc");
87 aHtml.attribute("x", "y");
88 aHtml.attribute("q", "w");
89 aHtml.end();
91 OString aString = extractFromStream(aStream);
93 CPPUNIT_ASSERT_EQUAL(OString("<abc x=\"y\" q=\"w\"/>"), aString);
97 CPPUNIT_TEST_FIXTURE(Test, testSingleElementWithContent)
99 SvMemoryStream aStream;
101 HtmlWriter aHtml(aStream);
102 aHtml.prettyPrint(false);
103 aHtml.start("abc");
104 aHtml.end();
106 OString aString = extractFromStream(aStream);
108 CPPUNIT_ASSERT_EQUAL(OString("<abc/>"), aString);
111 CPPUNIT_TEST_FIXTURE(Test, testSingleElementWithContentAndAttributes)
113 SvMemoryStream aStream;
115 HtmlWriter aHtml(aStream);
116 aHtml.prettyPrint(false);
117 aHtml.start("abc");
118 aHtml.attribute("x", "y");
119 aHtml.attribute("q", "w");
120 aHtml.end();
122 OString aString = extractFromStream(aStream);
124 CPPUNIT_ASSERT_EQUAL(OString("<abc x=\"y\" q=\"w\"/>"), aString);
127 CPPUNIT_TEST_FIXTURE(Test, testNested)
129 SvMemoryStream aStream;
131 HtmlWriter aHtml(aStream);
132 aHtml.prettyPrint(false);
133 aHtml.start("abc");
134 aHtml.start("xyz");
135 aHtml.end();
136 aHtml.end();
138 OString aString = extractFromStream(aStream);
140 CPPUNIT_ASSERT_EQUAL(OString("<abc><xyz/></abc>"), aString);
143 CPPUNIT_TEST_FIXTURE(Test, testNamespace)
145 SvMemoryStream aStream;
147 HtmlWriter aHtml(aStream, "reqif-xhtml");
148 aHtml.prettyPrint(false);
149 aHtml.single("br");
151 OString aString = extractFromStream(aStream);
153 // This was <br/>, namespace request was ignored.
154 CPPUNIT_ASSERT_EQUAL(OString("<reqif-xhtml:br/>"), aString);
157 CPPUNIT_TEST_FIXTURE(Test, testAttributeValues)
159 SvMemoryStream aStream;
161 HtmlWriter aHtml(aStream);
162 aHtml.prettyPrint(false);
163 aHtml.start("abc");
164 aHtml.attribute("one", OString("one"));
165 aHtml.attribute("two", OUString("two"));
166 aHtml.attribute("three", sal_Int32(12));
167 aHtml.end();
169 OString aString = extractFromStream(aStream);
171 CPPUNIT_ASSERT_EQUAL(OString("<abc one=\"one\" two=\"two\" three=\"12\"/>"), aString);
174 CPPUNIT_TEST_FIXTURE(Test, testCharacters)
176 SvMemoryStream aStream;
178 HtmlWriter aHtml(aStream);
179 aHtml.prettyPrint(false);
180 aHtml.start("abc");
181 aHtml.characters("hello");
182 aHtml.end();
184 OString aString = extractFromStream(aStream);
186 CPPUNIT_ASSERT_EQUAL(OString("<abc>hello</abc>"), aString);
189 CPPUNIT_PLUGIN_IMPLEMENT();
191 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */