Kaydet (Commit) c7b69624 authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl

Introduce HtmlWriter unit tests.

Change-Id: Icb39dde433124d444c48761e074f6b839a043d4e
üst 2480ded8
# -*- 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:
......@@ -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)
......
/* -*- 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: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment