diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2014-03-16 20:53:44 +0100 |
---|---|---|
committer | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2014-04-06 22:02:11 +0200 |
commit | c7b69624eec1329113630e308170346fce2be823 (patch) | |
tree | 19ca6395b11aee06931a130e049f3ea0777b3932 /svtools | |
parent | 2480ded80ed3b6e75d4cfb92dbe003000a685820 (diff) |
Introduce HtmlWriter unit tests.
Change-Id: Icb39dde433124d444c48761e074f6b839a043d4e
Diffstat (limited to 'svtools')
-rw-r--r-- | svtools/CppunitTest_svtools_html.mk | 33 | ||||
-rw-r--r-- | svtools/Module_svtools.mk | 4 | ||||
-rw-r--r-- | svtools/qa/unit/testHtmlWriter.cxx | 169 |
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: */ |