summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--svtools/CppunitTest_svtools_html.mk33
-rw-r--r--svtools/Module_svtools.mk4
-rw-r--r--svtools/qa/unit/testHtmlWriter.cxx169
3 files changed, 206 insertions, 0 deletions
diff --git a/svtools/CppunitTest_svtools_html.mk b/svtools/CppunitTest_svtools_html.mk
new file mode 100644
index 000000000000..e436b6d0895f
--- /dev/null
+++ b/svtools/CppunitTest_svtools_html.mk
@@ -0,0 +1,33 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+$(eval $(call gb_CppunitTest_CppunitTest,svtools_html))
+
+$(eval $(call gb_CppunitTest_use_external,svtools_html,boost_headers))
+
+$(eval $(call gb_CppunitTest_use_api,svtools_html, \
+ offapi \
+ udkapi \
+))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,svtools_html, \
+ svtools/qa/unit/testHtmlWriter \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,svtools_html, \
+ comphelper \
+ cppu \
+ cppuhelper \
+ tl \
+ sal \
+ svt \
+ $(gb_UWINAPI) \
+))
+
+# vim: set noet sw=4 ts=4:
diff --git a/svtools/Module_svtools.mk b/svtools/Module_svtools.mk
index 1e0f72ccead8..3a2784c89ae7 100644
--- a/svtools/Module_svtools.mk
+++ b/svtools/Module_svtools.mk
@@ -28,6 +28,10 @@ $(eval $(call gb_Module_add_l10n_targets,svtools,\
UIConfig_svt \
))
+$(eval $(call gb_Module_add_check_targets,svtools,\
+ CppunitTest_svtools_html \
+))
+
ifeq ($(CROSS_COMPILING),)
ifneq ($(OS),WNT)
diff --git a/svtools/qa/unit/testHtmlWriter.cxx b/svtools/qa/unit/testHtmlWriter.cxx
new file mode 100644
index 000000000000..78548b37bf1f
--- /dev/null
+++ b/svtools/qa/unit/testHtmlWriter.cxx
@@ -0,0 +1,169 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#include "cppunit/TestCase.h"
+#include "cppunit/TestFixture.h"
+#include "cppunit/TestSuite.h"
+#include "cppunit/extensions/HelperMacros.h"
+#include "cppunit/plugin/TestPlugIn.h"
+
+#include <tools/stream.hxx>
+#include <svtools/HtmlWriter.hxx>
+
+namespace
+{
+
+OString extractFromStream(SvMemoryStream& rStream)
+{
+ rStream.WriteChar('\0');
+ rStream.Flush();
+ rStream.Seek(STREAM_SEEK_TO_BEGIN);
+ return OString((const sal_Char*)rStream.GetBuffer());
+}
+
+}
+
+class Test: public CppUnit::TestFixture
+{
+
+public:
+ virtual void setUp();
+ void testSingleElement();
+ void testSingleElementWithAttributes();
+ void testSingleElementWithContent();
+ void testSingleElementWithContentAndAttributes();
+ void testNested();
+
+ CPPUNIT_TEST_SUITE(Test);
+ CPPUNIT_TEST(testSingleElement);
+ CPPUNIT_TEST(testSingleElementWithAttributes);
+ CPPUNIT_TEST(testSingleElementWithContent);
+ CPPUNIT_TEST(testSingleElementWithContentAndAttributes);
+ CPPUNIT_TEST(testNested);
+
+ CPPUNIT_TEST_SUITE_END();
+};
+
+void Test::setUp()
+{}
+
+void Test::testSingleElement()
+{
+ {
+ SvMemoryStream aStream;
+
+ HtmlWriter aHtml(aStream);
+ aHtml.prettyPrint(false);
+ aHtml.start("abc");
+ aHtml.end();
+
+ OString aString = extractFromStream(aStream);
+ CPPUNIT_ASSERT_EQUAL(aString, OString("<abc/>"));
+ }
+
+ {
+ SvMemoryStream aStream;
+
+ HtmlWriter aHtml(aStream);
+ aHtml.prettyPrint(false);
+ aHtml.single("abc");
+
+ OString aString = extractFromStream(aStream);
+
+ CPPUNIT_ASSERT_EQUAL(aString, OString("<abc/>"));
+ }
+}
+
+void Test::testSingleElementWithAttributes()
+{
+ {
+ SvMemoryStream aStream;
+
+ HtmlWriter aHtml(aStream);
+ aHtml.prettyPrint(false);
+ aHtml.start("abc");
+ aHtml.attribute("x", "y");
+ aHtml.end();
+
+ OString aString = extractFromStream(aStream);
+
+ CPPUNIT_ASSERT_EQUAL(aString, OString("<abc x=\"y\"/>"));
+ }
+
+ {
+ SvMemoryStream aStream;
+
+ HtmlWriter aHtml(aStream);
+ aHtml.prettyPrint(false);
+ aHtml.start("abc");
+ aHtml.attribute("x", "y");
+ aHtml.attribute("q", "w");
+ aHtml.end();
+
+ OString aString = extractFromStream(aStream);
+
+ CPPUNIT_ASSERT_EQUAL(aString, OString("<abc x=\"y\" q=\"w\"/>"));
+ }
+}
+
+void Test::testSingleElementWithContent()
+{
+ SvMemoryStream aStream;
+
+ HtmlWriter aHtml(aStream);
+ aHtml.prettyPrint(false);
+ aHtml.start("abc");
+ aHtml.write("xxxx");
+ aHtml.end();
+
+ OString aString = extractFromStream(aStream);
+
+ CPPUNIT_ASSERT_EQUAL(aString, OString("<abc>xxxx</abc>"));
+}
+
+void Test::testSingleElementWithContentAndAttributes()
+{
+ SvMemoryStream aStream;
+
+ HtmlWriter aHtml(aStream);
+ aHtml.prettyPrint(false);
+ aHtml.start("abc");
+ aHtml.attribute("x", "y");
+ aHtml.attribute("q", "w");
+ aHtml.write("xxxx");
+ aHtml.end();
+
+ OString aString = extractFromStream(aStream);
+
+ CPPUNIT_ASSERT_EQUAL(aString, OString("<abc x=\"y\" q=\"w\">xxxx</abc>"));
+}
+
+void Test::testNested()
+{
+ SvMemoryStream aStream;
+
+ HtmlWriter aHtml(aStream);
+ aHtml.prettyPrint(false);
+ aHtml.start("abc");
+ aHtml.start("xyz");
+ aHtml.write("xxx");
+ aHtml.end();
+ aHtml.end();
+
+ OString aString = extractFromStream(aStream);
+
+ CPPUNIT_ASSERT_EQUAL(OString("<abc><xyz>xxx</xyz></abc>"), aString);
+}
+
+
+CPPUNIT_TEST_SUITE_REGISTRATION(Test);
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */