summaryrefslogtreecommitdiffstats
path: root/test/qa
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 05:54:39 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 05:54:39 +0000
commit267c6f2ac71f92999e969232431ba04678e7437e (patch)
tree358c9467650e1d0a1d7227a21dac2e3d08b622b2 /test/qa
parentInitial commit. (diff)
downloadlibreoffice-267c6f2ac71f92999e969232431ba04678e7437e.tar.xz
libreoffice-267c6f2ac71f92999e969232431ba04678e7437e.zip
Adding upstream version 4:24.2.0.upstream/4%24.2.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/qa')
-rw-r--r--test/qa/cppunit/dialog.cxx65
-rw-r--r--test/qa/cppunit/test_xpath.cxx46
2 files changed, 111 insertions, 0 deletions
diff --git a/test/qa/cppunit/dialog.cxx b/test/qa/cppunit/dialog.cxx
new file mode 100644
index 0000000000..eb6996fa68
--- /dev/null
+++ b/test/qa/cppunit/dialog.cxx
@@ -0,0 +1,65 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * 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 <test/a11y/accessibletestbase.hxx>
+
+// FIXME: dialog API doesn't work on macos yet
+#if !defined(MACOSX)
+
+/* Checks an unexpected dialog opening (instead of the expected one) is properly caught, as it would
+ * otherwise block the test potentially indefinitely */
+CPPUNIT_TEST_FIXTURE(test::AccessibleTestBase, SelfTestIncorrectDialog)
+{
+ load(u"private:factory/swriter"_ustr);
+
+ auto dialogWaiter = awaitDialog(u"This Dialog Does Not Exist", [](Dialog&) {
+ CPPUNIT_ASSERT_MESSAGE("This code should not be reached", false);
+ });
+
+ CPPUNIT_ASSERT(activateMenuItem(u"Insert", u"Section..."));
+ /* Make sure an incorrect dialog popping up is caught and raises. The exception is thrown in
+ * waitEndDialog() for consistency even though the error itself is likely to have been triggered
+ * by the activateMenuItem() call above */
+ CPPUNIT_ASSERT_THROW(dialogWaiter->waitEndDialog(), css::uno::RuntimeException);
+}
+
+/* Checks that an exception in the dialog callback code is properly handled and won't disturb
+ * subsequent tests if caught -- especially that DialogWaiter::waitEndDialog() won't timeout. */
+CPPUNIT_TEST_FIXTURE(test::AccessibleTestBase, SelfTestThrowInDialogCallback)
+{
+ load(u"private:factory/swriter"_ustr);
+
+ class DummyException : public std::exception
+ {
+ };
+
+ auto dialogWaiter = awaitDialog(u"Hyperlink", [](Dialog&) { throw DummyException(); });
+
+ CPPUNIT_ASSERT(activateMenuItem(u"Insert", u"Hyperlink..."));
+ CPPUNIT_ASSERT_THROW(dialogWaiter->waitEndDialog(), DummyException);
+}
+
+// Checks timeout if dialog does not show up as expected
+CPPUNIT_TEST_FIXTURE(test::AccessibleTestBase, SelfTestNoDialog)
+{
+ load(u"private:factory/swriter"_ustr);
+
+ auto dialogWaiter = awaitDialog(u"This Dialog Did Not Show Up", [](Dialog&) {
+ CPPUNIT_ASSERT_MESSAGE("This code should not be reached", false);
+ });
+
+ // as we don't actually call any dialog up, this should fail after a timeout
+ CPPUNIT_ASSERT(!dialogWaiter->waitEndDialog());
+}
+
+#endif //defined(MACOSX)
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/test/qa/cppunit/test_xpath.cxx b/test/qa/cppunit/test_xpath.cxx
new file mode 100644
index 0000000000..8d105dd4ea
--- /dev/null
+++ b/test/qa/cppunit/test_xpath.cxx
@@ -0,0 +1,46 @@
+/* -*- 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/types.h>
+#include <test/xmltesttools.hxx>
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/plugin/TestPlugIn.h>
+
+class TestXPath : public CppUnit::TestFixture, public XmlTestTools
+{
+};
+
+CPPUNIT_TEST_FIXTURE(TestXPath, test_getXPath)
+{
+ const xmlChar s_xml[] = "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>"
+ "<xml><item attrib='val'>text</item></xml>";
+ xmlDocUniquePtr pTable(xmlParseDoc(s_xml));
+ CPPUNIT_ASSERT(pTable);
+ // Must get existing element content without errors
+ CPPUNIT_ASSERT_ASSERTION_PASS(assertXPath(pTable, "/xml/item"_ostr));
+ // Must error out when getting non-existing element
+ CPPUNIT_ASSERT_ASSERTION_FAIL(assertXPath(pTable, "/xml/no_item"_ostr));
+ // Must get existing attribute value correctly
+ CPPUNIT_ASSERT_ASSERTION_PASS(getXPath(pTable, "/xml/item"_ostr, "attrib"_ostr));
+ // Must fail when requested non-empty attribute doesn't exist
+ CPPUNIT_ASSERT_ASSERTION_FAIL(getXPath(pTable, "/xml/item"_ostr, "no_attrib"_ostr));
+ // Must properly return attribute content
+ CPPUNIT_ASSERT_EQUAL(OUString("val"), getXPath(pTable, "/xml/item"_ostr, "attrib"_ostr));
+ // Trying to get position of missing child of a node must fail assertion
+ CPPUNIT_ASSERT_ASSERTION_FAIL(getXPathPosition(pTable, "/xml/item"_ostr, "absent"));
+ // Asserting that an attribute is absent
+ CPPUNIT_ASSERT_ASSERTION_FAIL(assertXPathNoAttribute(pTable, "/xml/item"_ostr, "attrib"_ostr));
+ CPPUNIT_ASSERT_ASSERTION_PASS(assertXPathNoAttribute(pTable, "/xml/item"_ostr, "foo"_ostr));
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */