summaryrefslogtreecommitdiffstats
path: root/svtools/qa/unit
diff options
context:
space:
mode:
Diffstat (limited to 'svtools/qa/unit')
-rw-r--r--svtools/qa/unit/GraphicObjectTest.cxx60
-rw-r--r--svtools/qa/unit/data/svtools-dialogs-test.txt43
-rw-r--r--svtools/qa/unit/svtools-dialogs-test.cxx66
-rw-r--r--svtools/qa/unit/testHtmlReader.cxx81
-rw-r--r--svtools/qa/unit/testHtmlWriter.cxx188
5 files changed, 438 insertions, 0 deletions
diff --git a/svtools/qa/unit/GraphicObjectTest.cxx b/svtools/qa/unit/GraphicObjectTest.cxx
new file mode 100644
index 000000000..bb09612f7
--- /dev/null
+++ b/svtools/qa/unit/GraphicObjectTest.cxx
@@ -0,0 +1,60 @@
+/* -*- 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/extensions/HelperMacros.h>
+#include <cppunit/plugin/TestPlugIn.h>
+
+#include <test/bootstrapfixture.hxx>
+
+#include <com/sun/star/frame/Desktop.hpp>
+#include <unotest/macros_test.hxx>
+#include <comphelper/processfactory.hxx>
+
+using namespace css;
+
+namespace
+{
+
+class GraphicObjectTest: public test::BootstrapFixture, public unotest::MacrosTest
+{
+
+public:
+ void testTdf88836();
+
+ virtual void setUp() override
+ {
+ test::BootstrapFixture::setUp();
+
+ mxDesktop.set(css::frame::Desktop::create(comphelper::getComponentContext(getMultiServiceFactory())));
+ }
+
+private:
+ CPPUNIT_TEST_SUITE(GraphicObjectTest);
+ CPPUNIT_TEST(testTdf88836);
+ CPPUNIT_TEST_SUITE_END();
+};
+
+
+void GraphicObjectTest::testTdf88836()
+{
+ // Construction with empty bitmap -> type should be GraphicType::NONE
+ Graphic aGraphic = Bitmap();
+ CPPUNIT_ASSERT_EQUAL(int(GraphicType::NONE), int(aGraphic.GetType()));
+ aGraphic = Graphic(BitmapEx());
+ CPPUNIT_ASSERT_EQUAL(int(GraphicType::NONE), int(aGraphic.GetType()));
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(GraphicObjectTest);
+
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svtools/qa/unit/data/svtools-dialogs-test.txt b/svtools/qa/unit/data/svtools-dialogs-test.txt
new file mode 100644
index 000000000..2ed259ee5
--- /dev/null
+++ b/svtools/qa/unit/data/svtools-dialogs-test.txt
@@ -0,0 +1,43 @@
+# -*- 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/.
+#
+
+# This file contains all dialogs that the unit tests in the module
+# will work on if it is in script mode. It will read one-by-one,
+# try to open it and create a screenshot that will be saved in
+# workdir/screenshots using the pattern of the ui-file name.
+#
+# Syntax:
+# - empty lines are allowed
+# - lines starting with '#' are treated as comment
+# - all other lines should contain a *.ui filename in the same
+# notation as in the dialog constructors (see code)
+
+#
+# The 'known' dialogs which have a hard-coded representation
+# in registerKnownDialogsByID/createDialogByID
+#
+
+# No known dialogs in svtools for now
+
+#
+# Dialogs without a hard-coded representation. These will
+# be visualized using a fallback based on VclBuilder
+#
+
+# currently deactivated, leads to problems and the test to not work
+# This is typically a hint that these should be hard-coded in the
+# test case since they need some document and model data to work
+
+svt/ui/addresstemplatedialog.ui
+svt/ui/placeedit.ui
+svt/ui/printersetupdialog.ui
+svt/ui/restartdialog.ui
+svt/ui/graphicexport.ui
+svt/ui/querydeletedialog.ui
+svt/ui/javadisableddialog.ui
diff --git a/svtools/qa/unit/svtools-dialogs-test.cxx b/svtools/qa/unit/svtools-dialogs-test.cxx
new file mode 100644
index 000000000..be79168bb
--- /dev/null
+++ b/svtools/qa/unit/svtools-dialogs-test.cxx
@@ -0,0 +1,66 @@
+/* -*- 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 <sal/config.h>
+#include <test/screenshot_test.hxx>
+#include <vcl/abstdlg.hxx>
+#include <vcl/scheduler.hxx>
+#include <vcl/wrkwin.hxx>
+#include <svtools/valueset.hxx>
+
+using namespace ::com::sun::star;
+
+/// Test opening a dialog in svtools
+class SvtoolsDialogsTest : public ScreenshotTest
+{
+private:
+ /// helper method to populate KnownDialogs, called in setUp(). Needs to be
+ /// written and has to add entries to KnownDialogs
+ virtual void registerKnownDialogsByID(mapType& rKnownDialogs) override;
+
+ /// dialog creation for known dialogs by ID. Has to be implemented for
+ /// each registered known dialog
+ virtual VclPtr<VclAbstractDialog> createDialogByID(sal_uInt32 nID) override;
+
+public:
+ SvtoolsDialogsTest();
+
+ // try to open a dialog
+ void openAnyDialog();
+
+ CPPUNIT_TEST_SUITE(SvtoolsDialogsTest);
+ CPPUNIT_TEST(openAnyDialog);
+ CPPUNIT_TEST_SUITE_END();
+};
+
+SvtoolsDialogsTest::SvtoolsDialogsTest()
+{
+}
+
+void SvtoolsDialogsTest::registerKnownDialogsByID(mapType& /*rKnownDialogs*/)
+{
+ // fill map of known dialogs
+}
+
+VclPtr<VclAbstractDialog> SvtoolsDialogsTest::createDialogByID(sal_uInt32 /*nID*/)
+{
+ return nullptr;
+}
+
+void SvtoolsDialogsTest::openAnyDialog()
+{
+ /// process input file containing the UXMLDescriptions of the dialogs to dump
+ processDialogBatchFile("svtools/qa/unit/data/svtools-dialogs-test.txt");
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(SvtoolsDialogsTest);
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svtools/qa/unit/testHtmlReader.cxx b/svtools/qa/unit/testHtmlReader.cxx
new file mode 100644
index 000000000..4e5638cc5
--- /dev/null
+++ b/svtools/qa/unit/testHtmlReader.cxx
@@ -0,0 +1,81 @@
+/* -*- 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/TestFixture.h>
+#include <unotest/bootstrapfixturebase.hxx>
+#include <svtools/parhtml.hxx>
+#include <tools/ref.hxx>
+#include <tools/stream.hxx>
+
+namespace
+{
+/// Subclass of HTMLParser that can sense the import result.
+class TestHTMLParser : public HTMLParser
+{
+public:
+ TestHTMLParser(SvStream& rStream);
+ virtual void NextToken(HtmlTokenId nToken) override;
+ /// Make this public for test purposes.
+ using HTMLParser::SetNamespace;
+
+ OUString m_aDocument;
+ int m_nLineBreakCount = 0;
+};
+
+TestHTMLParser::TestHTMLParser(SvStream& rStream)
+ : HTMLParser(rStream)
+{
+}
+
+void TestHTMLParser::NextToken(HtmlTokenId nToken)
+{
+ if (nToken == HtmlTokenId::TEXTTOKEN)
+ m_aDocument += aToken;
+ else if (nToken == HtmlTokenId::LINEBREAK)
+ ++m_nLineBreakCount;
+}
+
+/// Tests HTMLParser.
+class Test : public CppUnit::TestFixture
+{
+};
+
+CPPUNIT_TEST_FIXTURE(Test, testTdf114428)
+{
+ SvMemoryStream aStream;
+ OString aDocument("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<html>hello</html>");
+ aStream.WriteBytes(aDocument.getStr(), aDocument.getLength());
+ aStream.Seek(0);
+
+ tools::SvRef<TestHTMLParser> xParser = new TestHTMLParser(aStream);
+ xParser->CallParser();
+
+ // This was '<?xml version="1.0" encoding="utf-8"?> hello', XML declaration
+ // was not ignored.
+ CPPUNIT_ASSERT_EQUAL(OUString("hello"), xParser->m_aDocument.trim());
+}
+
+CPPUNIT_TEST_FIXTURE(Test, testLineBreak)
+{
+ SvMemoryStream aStream;
+ OString aDocument("aaa<br></br>bbb");
+ aStream.WriteBytes(aDocument.getStr(), aDocument.getLength());
+ aStream.Seek(0);
+
+ tools::SvRef<TestHTMLParser> xParser = new TestHTMLParser(aStream);
+ xParser->SetNamespace("reqif-xhtml");
+ xParser->CallParser();
+
+ // This was 2, <br></br> was interpreted as 2 line breaks in XHTML mode.
+ CPPUNIT_ASSERT_EQUAL(1, xParser->m_nLineBreakCount);
+}
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svtools/qa/unit/testHtmlWriter.cxx b/svtools/qa/unit/testHtmlWriter.cxx
new file mode 100644
index 000000000..773da64c4
--- /dev/null
+++ b/svtools/qa/unit/testHtmlWriter.cxx
@@ -0,0 +1,188 @@
+/* -*- 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/TestFixture.h>
+#include <cppunit/plugin/TestPlugIn.h>
+
+#include <unotest/bootstrapfixturebase.hxx>
+#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 static_cast<const char*>(rStream.GetData());
+}
+
+}
+
+class Test: public CppUnit::TestFixture
+{
+};
+
+CPPUNIT_TEST_FIXTURE(Test, testSingleElement)
+{
+ {
+ SvMemoryStream aStream;
+
+ HtmlWriter aHtml(aStream);
+ aHtml.prettyPrint(false);
+ aHtml.start("abc");
+ aHtml.end();
+
+ OString aString = extractFromStream(aStream);
+ CPPUNIT_ASSERT_EQUAL(OString("<abc/>"), aString);
+ }
+
+ {
+ SvMemoryStream aStream;
+
+ HtmlWriter aHtml(aStream);
+ aHtml.prettyPrint(false);
+ aHtml.single("abc");
+
+ OString aString = extractFromStream(aStream);
+
+ CPPUNIT_ASSERT_EQUAL(OString("<abc/>"), aString);
+ }
+}
+
+CPPUNIT_TEST_FIXTURE(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(OString("<abc x=\"y\"/>"), aString);
+ }
+
+ {
+ 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(OString("<abc x=\"y\" q=\"w\"/>"), aString);
+ }
+}
+
+CPPUNIT_TEST_FIXTURE(Test, testSingleElementWithContent)
+{
+ SvMemoryStream aStream;
+
+ HtmlWriter aHtml(aStream);
+ aHtml.prettyPrint(false);
+ aHtml.start("abc");
+ aHtml.end();
+
+ OString aString = extractFromStream(aStream);
+
+ CPPUNIT_ASSERT_EQUAL(OString("<abc/>"), aString);
+}
+
+CPPUNIT_TEST_FIXTURE(Test, testSingleElementWithContentAndAttributes)
+{
+ 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(OString("<abc x=\"y\" q=\"w\"/>"), aString);
+}
+
+CPPUNIT_TEST_FIXTURE(Test, testNested)
+{
+ SvMemoryStream aStream;
+
+ HtmlWriter aHtml(aStream);
+ aHtml.prettyPrint(false);
+ aHtml.start("abc");
+ aHtml.start("xyz");
+ aHtml.end();
+ aHtml.end();
+
+ OString aString = extractFromStream(aStream);
+
+ CPPUNIT_ASSERT_EQUAL(OString("<abc><xyz/></abc>"), aString);
+}
+
+CPPUNIT_TEST_FIXTURE(Test, testNamespace)
+{
+ SvMemoryStream aStream;
+
+ HtmlWriter aHtml(aStream, "reqif-xhtml");
+ aHtml.prettyPrint(false);
+ aHtml.single("br");
+
+ OString aString = extractFromStream(aStream);
+
+ // This was <br/>, namespace request was ignored.
+ CPPUNIT_ASSERT_EQUAL(OString("<reqif-xhtml:br/>"), aString);
+}
+
+CPPUNIT_TEST_FIXTURE(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);
+}
+
+CPPUNIT_TEST_FIXTURE(Test, testCharacters)
+{
+ SvMemoryStream aStream;
+
+ HtmlWriter aHtml(aStream);
+ aHtml.prettyPrint(false);
+ aHtml.start("abc");
+ aHtml.characters("hello");
+ aHtml.end();
+
+ OString aString = extractFromStream(aStream);
+
+ CPPUNIT_ASSERT_EQUAL(OString("<abc>hello</abc>"), aString);
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */