summaryrefslogtreecommitdiff
path: root/test/qa/cppunit
diff options
context:
space:
mode:
authorColomban Wendling <cwendling@hypra.fr>2022-10-27 19:07:44 +0200
committerMichael Weghorn <m.weghorn@posteo.de>2023-02-24 15:13:39 +0000
commit0ccea0dd6e50199af4a7aae75d691b32c853b177 (patch)
tree6d8de9d8ee55401732645a06fb492a2f34f17d0f /test/qa/cppunit
parentc15412eb96bda1037c12811f5818ed8ce1e603bd (diff)
test: Add accessibility test dialog infrastructure
Interacting with dialogues in tests is non-trivial, so introduce helpers to make it simpler and less error-prone. Add tests for the infrastructure itself as well. Change-Id: I8ea6087a61380194eb2b5ec9f25091db00f5a550 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142258 Reviewed-by: Michael Weghorn <m.weghorn@posteo.de> Tested-by: Jenkins
Diffstat (limited to 'test/qa/cppunit')
-rw-r--r--test/qa/cppunit/dialog.cxx66
1 files changed, 66 insertions, 0 deletions
diff --git a/test/qa/cppunit/dialog.cxx b/test/qa/cppunit/dialog.cxx
new file mode 100644
index 000000000000..f64e7d13a68c
--- /dev/null
+++ b/test/qa/cppunit/dialog.cxx
@@ -0,0 +1,66 @@
+/* -*- 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 doesn't pop up on macos and doesn't close on win32...
+#if !defined(MACOSX) && !defined(_WIN32)
+/* 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");
+
+ 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 poping 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);
+}
+#endif
+
+// FIXME: dialog doesn't pop up on macos and doesn't close on win32...
+#if !defined(MACOSX) && !defined(_WIN32)
+/* 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");
+
+ 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);
+}
+#endif
+
+// Checks timeout if dialog does not show up as expected
+CPPUNIT_TEST_FIXTURE(test::AccessibleTestBase, SelfTestNoDialog)
+{
+ load(u"private:factory/swriter");
+
+ 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());
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */