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/.
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 <tools/stream.hxx>
18 #include <svtools/HtmlWriter.hxx>
23 OString
extractFromStream(SvMemoryStream
& rStream
)
25 rStream
.WriteChar('\0');
27 rStream
.Seek(STREAM_SEEK_TO_BEGIN
);
28 return OString(static_cast<const sal_Char
*>(rStream
.GetBuffer()));
33 class Test
: public CppUnit::TestFixture
37 void testSingleElement();
38 void testSingleElementWithAttributes();
39 void testSingleElementWithContent();
40 void testSingleElementWithContentAndAttributes();
42 void testAttributeValues();
44 CPPUNIT_TEST_SUITE(Test
);
45 CPPUNIT_TEST(testSingleElement
);
46 CPPUNIT_TEST(testSingleElementWithAttributes
);
47 CPPUNIT_TEST(testSingleElementWithContent
);
48 CPPUNIT_TEST(testSingleElementWithContentAndAttributes
);
49 CPPUNIT_TEST(testNested
);
50 CPPUNIT_TEST(testAttributeValues
);
52 CPPUNIT_TEST_SUITE_END();
55 void Test::testSingleElement()
58 SvMemoryStream aStream
;
60 HtmlWriter
aHtml(aStream
);
61 aHtml
.prettyPrint(false);
65 OString aString
= extractFromStream(aStream
);
66 CPPUNIT_ASSERT_EQUAL(aString
, OString("<abc/>"));
70 SvMemoryStream aStream
;
72 HtmlWriter
aHtml(aStream
);
73 aHtml
.prettyPrint(false);
76 OString aString
= extractFromStream(aStream
);
78 CPPUNIT_ASSERT_EQUAL(aString
, OString("<abc/>"));
82 void Test::testSingleElementWithAttributes()
85 SvMemoryStream aStream
;
87 HtmlWriter
aHtml(aStream
);
88 aHtml
.prettyPrint(false);
90 aHtml
.attribute("x", "y");
93 OString aString
= extractFromStream(aStream
);
95 CPPUNIT_ASSERT_EQUAL(aString
, OString("<abc x=\"y\"/>"));
99 SvMemoryStream aStream
;
101 HtmlWriter
aHtml(aStream
);
102 aHtml
.prettyPrint(false);
104 aHtml
.attribute("x", "y");
105 aHtml
.attribute("q", "w");
108 OString aString
= extractFromStream(aStream
);
110 CPPUNIT_ASSERT_EQUAL(aString
, OString("<abc x=\"y\" q=\"w\"/>"));
114 void Test::testSingleElementWithContent()
116 SvMemoryStream aStream
;
118 HtmlWriter
aHtml(aStream
);
119 aHtml
.prettyPrint(false);
123 OString aString
= extractFromStream(aStream
);
125 CPPUNIT_ASSERT_EQUAL(aString
, OString("<abc/>"));
128 void Test::testSingleElementWithContentAndAttributes()
130 SvMemoryStream aStream
;
132 HtmlWriter
aHtml(aStream
);
133 aHtml
.prettyPrint(false);
135 aHtml
.attribute("x", "y");
136 aHtml
.attribute("q", "w");
139 OString aString
= extractFromStream(aStream
);
141 CPPUNIT_ASSERT_EQUAL(aString
, OString("<abc x=\"y\" q=\"w\"/>"));
144 void Test::testNested()
146 SvMemoryStream aStream
;
148 HtmlWriter
aHtml(aStream
);
149 aHtml
.prettyPrint(false);
155 OString aString
= extractFromStream(aStream
);
157 CPPUNIT_ASSERT_EQUAL(OString("<abc><xyz/></abc>"), aString
);
160 void Test::testAttributeValues()
162 SvMemoryStream aStream
;
164 HtmlWriter
aHtml(aStream
);
165 aHtml
.prettyPrint(false);
167 aHtml
.attribute("one", OString("one"));
168 aHtml
.attribute("two", OUString("two"));
169 aHtml
.attribute("three", sal_Int32(12));
172 OString aString
= extractFromStream(aStream
);
174 CPPUNIT_ASSERT_EQUAL(OString("<abc one=\"one\" two=\"two\" three=\"12\"/>"), aString
);
177 CPPUNIT_TEST_SUITE_REGISTRATION(Test
);
178 CPPUNIT_PLUGIN_IMPLEMENT();
180 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */