diff --git a/officecfg/CppunitTest_officecfg_accelerator_key_checker_test.mk b/officecfg/CppunitTest_officecfg_accelerator_key_checker_test.mk new file mode 100644 index 000000000000..84f3f125a8d2 --- /dev/null +++ b/officecfg/CppunitTest_officecfg_accelerator_key_checker_test.mk @@ -0,0 +1,44 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t; 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/. +# + +$(eval $(call gb_CppunitTest_CppunitTest,officecfg_accelerator_key_checker_test)) + +$(eval $(call gb_CppunitTest_add_exception_objects,officecfg_accelerator_key_checker_test, \ + officecfg/qa/acceleratorkeychecker \ +)) + +$(eval $(call gb_CppunitTest_use_libraries,officecfg_accelerator_key_checker_test, \ + cppu \ + cppuhelper \ + sal \ + subsequenttest \ + test \ + unotest \ + utl \ + vcl \ + tl \ +)) + +$(eval $(call gb_CppunitTest_use_api,officecfg_accelerator_key_checker_test, \ + udkapi \ + offapi \ + oovbaapi \ +)) + +$(eval $(call gb_CppunitTest_use_externals,officecfg_accelerator_key_checker_test, \ + boost_headers \ + libxml2 \ +)) + +$(eval $(call gb_CppunitTest_use_ure,officecfg_accelerator_key_checker_test)) +$(eval $(call gb_CppunitTest_use_vcl,officecfg_accelerator_key_checker_test,services)) +$(eval $(call gb_CppunitTest_use_rdb,officecfg_accelerator_key_checker_test,services)) +$(eval $(call gb_CppunitTest_use_configuration,officecfg_accelerator_key_checker_test)) + +# vim: set noet sw=4 ts=4: diff --git a/officecfg/Module_officecfg.mk b/officecfg/Module_officecfg.mk index 326ae1580714..1d0e0fff857c 100644 --- a/officecfg/Module_officecfg.mk +++ b/officecfg/Module_officecfg.mk @@ -28,6 +28,7 @@ $(eval $(call gb_Module_add_targets,officecfg,\ $(eval $(call gb_Module_add_check_targets,officecfg,\ CppunitTest_officecfg_cppheader_test \ + CppunitTest_officecfg_accelerator_key_checker_test \ )) # vim: set noet sw=4 ts=4: diff --git a/officecfg/qa/acceleratorkeychecker.cxx b/officecfg/qa/acceleratorkeychecker.cxx new file mode 100644 index 000000000000..8a988141e2f0 --- /dev/null +++ b/officecfg/qa/acceleratorkeychecker.cxx @@ -0,0 +1,104 @@ +/* -*- 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 + +#include +#include +#include + +#include +#include +#include +#include + +namespace +{ +class AcceleratorKeyCheckerTest : public UnoApiTest +{ +public: + AcceleratorKeyCheckerTest() + : UnoApiTest(u"/officecfg/util"_ustr) + { + } + +private: + void testAcceleratorKeyChecker(); + + CPPUNIT_TEST_SUITE(AcceleratorKeyCheckerTest); + CPPUNIT_TEST(testAcceleratorKeyChecker); + CPPUNIT_TEST_SUITE_END(); +}; + +css::uno::Reference +findChildNode(const css::uno::Reference& xNode, + const std::u16string_view sName) +{ + for (const auto& xChildNode : xNode->getChildNodes()) + { + if (xChildNode->getName() == sName) + return xChildNode; + } + + CPPUNIT_FAIL(OUString(u"Couldn’t find child node "_ustr + sName).toUtf8().getStr()); +} + +// Tries running the script contained in the AcceleratorKeyChecker utility document +void AcceleratorKeyCheckerTest::testAcceleratorKeyChecker() +{ + // Make sure that dialogs are fatal so that if the script reports + // an error then the test will fail + DialogCancelMode nOldDialogCancelMode = Application::GetDialogCancelMode(); + comphelper::ScopeGuard g( + [nOldDialogCancelMode]() { Application::SetDialogCancelMode(nOldDialogCancelMode); }); + Application::SetDialogCancelMode(DialogCancelMode::Fatal); + + loadFromFile(u"AcceleratorKeyChecker.fodt"); + + // Get the script provider for BASIC macros in the document + css::uno::Sequence aArgs(1); + aArgs.getArray()[0] <<= u"vnd.sun.star.tdoc:/1"_ustr; + + css::uno::Reference xRootNode( + m_xFactory->createInstanceWithArgumentsAndContext( + "com.sun.star.script.provider.ScriptProviderForBasic", aArgs, m_xContext), + css::uno::UNO_QUERY_THROW); + + // Get the browse node for the testmenus macro + css::uno::Reference xBrowseNode + = findChildNode(xRootNode, u"AcceleratorKeyCheck"); + xBrowseNode = findChildNode(xBrowseNode, u"__testMenu"); + xBrowseNode = findChildNode(xBrowseNode, u"testmenus"); + + // Get the URI for the macro + css::uno::Reference xNodeProperties(xBrowseNode, + css::uno::UNO_QUERY_THROW); + css::uno::Any value = xNodeProperties->getPropertyValue(u"URI"_ustr); + OUString sURI; + CPPUNIT_ASSERT(value >>= sURI); + + // Get the XScript for the macro from the script provider + css::uno::Reference xScriptProvider( + xRootNode, css::uno::UNO_QUERY_THROW); + css::uno::Reference xScript = xScriptProvider->getScript(sURI); + + // Run the macro + css::uno::Sequence aParams; + css::uno::Sequence aOutParamIndex; + css::uno::Sequence aOutParam; + xScript->invoke(aParams, aOutParamIndex, aOutParam); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(AcceleratorKeyCheckerTest); + +} // namespace + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */