summaryrefslogtreecommitdiff
path: root/svtools/qa/unit
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.com>2014-09-20 14:50:46 +0200
committerTomaž Vajngerl <tomaz.vajngerl@collabora.com>2014-09-22 00:31:47 +0200
commitd42813db533b0a4930528ba1ccd34f33498ffe36 (patch)
tree519cf354a36b3885671a3aecd947062b282e24a0 /svtools/qa/unit
parent0ce8533ee2b3202922e0ff7ba9f9212080965167 (diff)
Extend HTMLWriter: flush the stack, more values for attribute(..)
Change-Id: I733426ba5f82ee25751387f88942dbc66689821d
Diffstat (limited to 'svtools/qa/unit')
-rw-r--r--svtools/qa/unit/testHtmlWriter.cxx124
1 files changed, 124 insertions, 0 deletions
diff --git a/svtools/qa/unit/testHtmlWriter.cxx b/svtools/qa/unit/testHtmlWriter.cxx
index 59cdb241dfed..7c9d38f45a6b 100644
--- a/svtools/qa/unit/testHtmlWriter.cxx
+++ b/svtools/qa/unit/testHtmlWriter.cxx
@@ -40,6 +40,8 @@ public:
void testSingleElementWithContent();
void testSingleElementWithContentAndAttributes();
void testNested();
+ void testAttributeValues();
+ void testFlushStack();
CPPUNIT_TEST_SUITE(Test);
CPPUNIT_TEST(testSingleElement);
@@ -47,6 +49,8 @@ public:
CPPUNIT_TEST(testSingleElementWithContent);
CPPUNIT_TEST(testSingleElementWithContentAndAttributes);
CPPUNIT_TEST(testNested);
+ CPPUNIT_TEST(testAttributeValues);
+ CPPUNIT_TEST(testFlushStack);
CPPUNIT_TEST_SUITE_END();
};
@@ -162,6 +166,126 @@ void Test::testNested()
CPPUNIT_ASSERT_EQUAL(OString("<abc><xyz>xxx</xyz></abc>"), aString);
}
+void Test::testAttributeValues()
+{
+ SvMemoryStream aStream;
+
+ HtmlWriter aHtml(aStream);
+ aHtml.prettyPrint(false);
+ aHtml.start("abc");
+ aHtml.attribute("one", OString("one"));
+ aHtml.attribute("two", OUString("two"));
+ aHtml.attribute("three", sal_Int32(12));
+ aHtml.end();
+
+ OString aString = extractFromStream(aStream);
+
+ CPPUNIT_ASSERT_EQUAL(OString("<abc one=\"one\" two=\"two\" three=\"12\"/>"), aString);
+}
+
+void Test::testFlushStack()
+{
+ {
+ SvMemoryStream aStream;
+
+ HtmlWriter aHtml(aStream);
+ aHtml.prettyPrint(false);
+ aHtml.start("a");
+ aHtml.flushStack("a"); // simple ,end element "a" = like end()
+
+ OString aString = extractFromStream(aStream);
+
+ CPPUNIT_ASSERT_EQUAL(OString("<a/>"), aString);
+ }
+
+ {
+ SvMemoryStream aStream;
+
+ HtmlWriter aHtml(aStream);
+ aHtml.prettyPrint(false);
+ aHtml.start("a");
+ aHtml.start("b");
+ aHtml.flushStack("b"); // end at first element "b", don't output "a" yet
+
+ OString aString = extractFromStream(aStream);
+
+ CPPUNIT_ASSERT_EQUAL(OString("<a><b/>"), aString);
+ }
+
+ {
+ SvMemoryStream aStream;
+
+ HtmlWriter aHtml(aStream);
+ aHtml.prettyPrint(false);
+ aHtml.start("a");
+ aHtml.start("b");
+ aHtml.flushStack("a"); // end at first element "a"
+
+ OString aString = extractFromStream(aStream);
+
+ CPPUNIT_ASSERT_EQUAL(OString("<a><b/></a>"), aString);
+ }
+
+ {
+ SvMemoryStream aStream;
+
+ HtmlWriter aHtml(aStream);
+ aHtml.prettyPrint(false);
+ aHtml.start("a");
+ aHtml.start("b");
+ aHtml.start("c");
+ aHtml.flushStack("a"); // end at first element "a"
+
+ OString aString = extractFromStream(aStream);
+
+ CPPUNIT_ASSERT_EQUAL(OString("<a><b><c/></b></a>"), aString);
+ }
+
+ {
+ SvMemoryStream aStream;
+
+ HtmlWriter aHtml(aStream);
+ aHtml.prettyPrint(false);
+ aHtml.start("a");
+ aHtml.start("b");
+ aHtml.start("c");
+ aHtml.flushStack("b"); // end at first element "b"
+
+ OString aString = extractFromStream(aStream);
+
+ CPPUNIT_ASSERT_EQUAL(OString("<a><b><c/></b>"), aString);
+ }
+
+ {
+ SvMemoryStream aStream;
+
+ HtmlWriter aHtml(aStream);
+ aHtml.prettyPrint(false);
+ aHtml.start("a");
+ aHtml.start("b");
+ aHtml.start("c");
+ aHtml.flushStack("x"); // no known element - ends when stack is empty
+
+ OString aString = extractFromStream(aStream);
+
+ CPPUNIT_ASSERT_EQUAL(OString("<a><b><c/></b></a>"), aString);
+ }
+
+ {
+ SvMemoryStream aStream;
+
+ HtmlWriter aHtml(aStream);
+ aHtml.prettyPrint(false);
+ aHtml.start("a");
+ aHtml.start("b");
+ aHtml.start("c");
+ aHtml.flushStack(); // flush the whole stack
+
+ OString aString = extractFromStream(aStream);
+
+ CPPUNIT_ASSERT_EQUAL(OString("<a><b><c/></b></a>"), aString);
+ }
+}
CPPUNIT_TEST_SUITE_REGISTRATION(Test);
CPPUNIT_PLUGIN_IMPLEMENT();