summaryrefslogtreecommitdiffstats
path: root/svtools/qa/unit
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:06:44 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:06:44 +0000
commited5640d8b587fbcfed7dd7967f3de04b37a76f26 (patch)
tree7a5f7c6c9d02226d7471cb3cc8fbbf631b415303 /svtools/qa/unit
parentInitial commit. (diff)
downloadlibreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.tar.xz
libreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.zip
Adding upstream version 4:7.4.7.upstream/4%7.4.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'svtools/qa/unit')
-rw-r--r--svtools/qa/unit/GraphicObjectTest.cxx57
-rw-r--r--svtools/qa/unit/data/svtools-dialogs-test.txt43
-rw-r--r--svtools/qa/unit/svtools-dialogs-test.cxx61
-rw-r--r--svtools/qa/unit/testHtmlReader.cxx104
-rw-r--r--svtools/qa/unit/testHtmlWriter.cxx224
5 files changed, 489 insertions, 0 deletions
diff --git a/svtools/qa/unit/GraphicObjectTest.cxx b/svtools/qa/unit/GraphicObjectTest.cxx
new file mode 100644
index 000000000..766baea6b
--- /dev/null
+++ b/svtools/qa/unit/GraphicObjectTest.cxx
@@ -0,0 +1,57 @@
+/* -*- 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 = BitmapEx(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..a072220f2
--- /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 weld::Builder
+#
+
+# 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..974cf5347
--- /dev/null
+++ b/svtools/qa/unit/svtools-dialogs-test.cxx
@@ -0,0 +1,61 @@
+/* -*- 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>
+
+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(u"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..37f74e903
--- /dev/null
+++ b/svtools/qa/unit/testHtmlReader.cxx
@@ -0,0 +1,104 @@
+/* -*- 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;
+ OUString m_aCdata;
+};
+
+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;
+ else if (nToken == HtmlTokenId::CDATA)
+ m_aCdata = aToken;
+}
+
+/// 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(u"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);
+}
+
+CPPUNIT_TEST_FIXTURE(Test, testCdata)
+{
+ // Given a document with CDATA:
+ SvMemoryStream aStream;
+ OString aDocument("A<![CDATA[B &uuml; &lt;]]>C");
+ aStream.WriteBytes(aDocument.getStr(), aDocument.getLength());
+ aStream.Seek(0);
+
+ // When parsing that HTML:
+ tools::SvRef<TestHTMLParser> xParser = new TestHTMLParser(aStream);
+ xParser->CallParser();
+
+ // Then make sure that we get a cdata token with the correct content:
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected: B &uuml; &lt;
+ // - Actual :
+ // i.e. the content inside CDATA was lost.
+ CPPUNIT_ASSERT_EQUAL(OUString("B &uuml; &lt;"), xParser->m_aCdata);
+}
+}
+
+/* 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..702bf6446
--- /dev/null
+++ b/svtools/qa/unit/testHtmlWriter.cxx
@@ -0,0 +1,224 @@
+/* -*- 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.FlushBuffer();
+ 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", "one");
+ aHtml.attribute("two", u"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_TEST_FIXTURE(Test, testExactElementEnd)
+{
+ SvMemoryStream aStream;
+
+ HtmlWriter aHtml(aStream);
+ aHtml.prettyPrint(false);
+ aHtml.start("start");
+ aHtml.start("a");
+ CPPUNIT_ASSERT(aHtml.end("a"));
+ aHtml.start("b");
+ CPPUNIT_ASSERT(!aHtml.end("c"));
+ CPPUNIT_ASSERT(aHtml.end("start"));
+
+ OString aString = extractFromStream(aStream);
+ CPPUNIT_ASSERT_EQUAL(OString("<start><a/><b/></start>"), aString);
+}
+
+CPPUNIT_TEST_FIXTURE(Test, testAttributeValueEncode)
+{
+ // Given a HTML writer:
+ SvMemoryStream aStream;
+ HtmlWriter aHtml(aStream);
+ aHtml.prettyPrint(false);
+
+ // When writing an attribute with a value that needs encoding:
+ aHtml.start("element");
+ aHtml.attribute("attribute", "a&b");
+ aHtml.end();
+
+ // Then make sure that the encoding is performed:
+ OString aString = extractFromStream(aStream);
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected: <element attribute="a&amp;b"/>
+ // - Actual : <element attribute="a&b"/>
+ // i.e. attribute value was not encoded in HTML, but it was in e.g. XML.
+ CPPUNIT_ASSERT_EQUAL(OString("<element attribute=\"a&amp;b\"/>"), aString);
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */