cURL: follow redirects
[LibreOffice.git] / svtools / qa / unit / testHtmlWriter.cxx
blob5dd9491f9f9c860b4ec2ef4208dec4073e80a0d0
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 <tools/stream.hxx>
18 #include <svtools/HtmlWriter.hxx>
20 namespace
23 OString extractFromStream(SvMemoryStream& rStream)
25 rStream.WriteChar('\0');
26 rStream.Flush();
27 rStream.Seek(STREAM_SEEK_TO_BEGIN);
28 return OString(static_cast<const sal_Char*>(rStream.GetBuffer()));
33 class Test: public CppUnit::TestFixture
36 public:
37 void testSingleElement();
38 void testSingleElementWithAttributes();
39 void testSingleElementWithContent();
40 void testSingleElementWithContentAndAttributes();
41 void testNested();
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);
62 aHtml.start("abc");
63 aHtml.end();
65 OString aString = extractFromStream(aStream);
66 CPPUNIT_ASSERT_EQUAL(aString, OString("<abc/>"));
70 SvMemoryStream aStream;
72 HtmlWriter aHtml(aStream);
73 aHtml.prettyPrint(false);
74 aHtml.single("abc");
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);
89 aHtml.start("abc");
90 aHtml.attribute("x", "y");
91 aHtml.end();
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);
103 aHtml.start("abc");
104 aHtml.attribute("x", "y");
105 aHtml.attribute("q", "w");
106 aHtml.end();
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);
120 aHtml.start("abc");
121 aHtml.end();
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);
134 aHtml.start("abc");
135 aHtml.attribute("x", "y");
136 aHtml.attribute("q", "w");
137 aHtml.end();
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);
150 aHtml.start("abc");
151 aHtml.start("xyz");
152 aHtml.end();
153 aHtml.end();
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);
166 aHtml.start("abc");
167 aHtml.attribute("one", OString("one"));
168 aHtml.attribute("two", OUString("two"));
169 aHtml.attribute("three", sal_Int32(12));
170 aHtml.end();
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: */