framework/CppunitTest_framework_checkDispatchAPI.mk | 43 ++++ framework/Module_framework.mk | 1 framework/qa/cppunit/checkDispatchAPI.cxx | 196 ++++++++++++++++++++ framework/qa/cppunit/data/checkDispatchAPIDB.odb |binary 4 files changed, 240 insertions(+)
New commits: commit 227f5c77278c96f7f1b126aade457422949a095c Author: Adam Seskunas <adamsesku...@gmail.com> AuthorDate: Wed Jun 5 14:54:19 2024 -0700 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Fri Jun 7 10:45:17 2024 +0200 framework/qa/complex/dispatches/checkdispatchapi.java to CppUnit Ports the checkDispatchOfXXX tests including the three database dependent tests. The other tests in the file will be ported in another commit, to be merged with this one. Change-Id: I6bcbcbf91ad4d9cc52c817f4efef9779a17f2198 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168482 Tested-by: Jenkins Tested-by: Xisco Fauli <xiscofa...@libreoffice.org> Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> diff --git a/framework/CppunitTest_framework_checkDispatchAPI.mk b/framework/CppunitTest_framework_checkDispatchAPI.mk new file mode 100644 index 000000000000..94aa88d43d5b --- /dev/null +++ b/framework/CppunitTest_framework_checkDispatchAPI.mk @@ -0,0 +1,43 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# +# 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,framework_checkDispatchAPI)) + +$(eval $(call gb_CppunitTest_add_exception_objects,framework_checkDispatchAPI, \ + framework/qa/cppunit/checkDispatchAPI \ +)) + +$(eval $(call gb_CppunitTest_use_sdk_api,framework_checkDispatchAPI)) + +$(eval $(call gb_CppunitTest_use_libraries,framework_checkDispatchAPI, \ + comphelper \ + cppu \ + cppuhelper \ + sal \ + salhelper \ + subsequenttest \ + test \ + unotest \ + utl \ + tl \ + vcl \ +)) + +$(eval $(call gb_CppunitTest_use_external,framework_checkDispatchAPI,boost_headers)) + +$(eval $(call gb_CppunitTest_use_sdk_api,framework_checkDispatchAPI)) + +$(eval $(call gb_CppunitTest_use_ure,framework_checkDispatchAPI)) +$(eval $(call gb_CppunitTest_use_vcl,framework_checkDispatchAPI)) + +$(eval $(call gb_CppunitTest_use_rdb,framework_checkDispatchAPI,services)) + +$(eval $(call gb_CppunitTest_use_configuration,framework_checkDispatchAPI)) + +# vim: set noet sw=4 ts=4: diff --git a/framework/Module_framework.mk b/framework/Module_framework.mk index 7521418d3861..8f700010444f 100644 --- a/framework/Module_framework.mk +++ b/framework/Module_framework.mk @@ -29,6 +29,7 @@ $(eval $(call gb_Module_add_slowcheck_targets,framework,\ CppunitTest_framework_dispatch \ CppunitTest_framework_loadenv \ CppunitTest_framework_CheckXTitle \ + CppunitTest_framework_checkDispatchAPI \ )) # Not sure why this is not stable on macOS. diff --git a/framework/qa/cppunit/checkDispatchAPI.cxx b/framework/qa/cppunit/checkDispatchAPI.cxx new file mode 100644 index 000000000000..0536690addd0 --- /dev/null +++ b/framework/qa/cppunit/checkDispatchAPI.cxx @@ -0,0 +1,196 @@ +/* -*- 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 <test/unoapi_test.hxx> + +#include <com/sun/star/frame/XDispatchInformationProvider.hpp> +#include <com/sun/star/frame/Desktop.hpp> +#include <com/sun/star/sdb/XOfficeDatabaseDocument.hpp> +#include <com/sun/star/sdbc/XDataSource.hpp> +#include <com/sun/star/sdbc/XConnection.hpp> + +#include <comphelper/propertyvalue.hxx> +#include <comphelper/processfactory.hxx> + +using namespace ::com::sun::star; + +namespace +{ +class DispatchAPITest : public UnoApiTest +{ +public: + DispatchAPITest() + : UnoApiTest(u"/framework/qa/cppunit/data/"_ustr) + { + } + void checkDispatchInfo(uno::Reference<frame::XFrame> xFrame); + uno::Reference<frame::XFrame> loadComponent(OUString url); + uno::Reference<frame::XFrame> loadWithDBComponent(OUString url); +}; + +uno::Reference<frame::XFrame> DispatchAPITest::loadComponent(OUString url) +{ + uno::Reference<css::frame::XDesktop2> xDesktop + = css::frame::Desktop::create(comphelper::getProcessComponentContext()); + uno::Reference<css::frame::XFrame> xFrame = xDesktop->findFrame(u"_blank"_ustr, 0); + uno::Reference<frame::XComponentLoader> xComponentLoader(xFrame, uno::UNO_QUERY); + uno::Sequence<beans::PropertyValue> aLoadArgs{ comphelper::makePropertyValue(u"Hidden"_ustr, + false) }; + uno::Reference<lang::XComponent> xComponent + = xComponentLoader->loadComponentFromURL(url, u"_default"_ustr, 0, aLoadArgs); + CPPUNIT_ASSERT(xComponent.is()); + + return xFrame; +} + +uno::Reference<frame::XFrame> DispatchAPITest::loadWithDBComponent(OUString url) +{ + uno::Reference<css::frame::XDesktop2> xDesktop + = css::frame::Desktop::create(comphelper::getProcessComponentContext()); + uno::Reference<css::frame::XFrame> xFrame = xDesktop->findFrame(u"_blank"_ustr, 0); + + // Get the database connection + createTempCopy(u"checkDispatchAPIDB.odb"); + uno::Reference<lang::XComponent> xDBComponent = loadFromDesktop(maTempFile.GetURL()); + uno::Reference<sdb::XOfficeDatabaseDocument> xDBDocument(xDBComponent, uno::UNO_QUERY_THROW); + + uno::Reference<sdbc::XDataSource> xDataSource = xDBDocument->getDataSource(); + uno::Reference<sdbc::XConnection> xConnection = xDataSource->getConnection(u""_ustr, u""_ustr); + CPPUNIT_ASSERT(xConnection.is()); + + // Get the frame reference + uno::Reference<lang::XMultiServiceFactory> xFactory(comphelper::getProcessServiceFactory()); + uno::Reference<uno::XInterface> xInterface + = xFactory->createInstance(u"com.sun.star.frame.Desktop"_ustr); + uno::Reference<frame::XComponentLoader> xComponentLoader(xFrame, uno::UNO_QUERY); + + uno::Sequence<beans::PropertyValue> aLoadArgs{ comphelper::makePropertyValue( + u"ActiveConnection"_ustr, uno::Any(xConnection)) }; + uno::Reference<lang::XComponent> xComponent + = xComponentLoader->loadComponentFromURL(url, u"_self"_ustr, 0, aLoadArgs); + CPPUNIT_ASSERT(xComponent.is()); + + return xFrame; +} + +void DispatchAPITest::checkDispatchInfo(uno::Reference<frame::XFrame> xFrame) +{ + uno::Reference<frame::XDispatchInformationProvider> xProvider(xFrame, uno::UNO_QUERY); + CPPUNIT_ASSERT_MESSAGE("Can't load XDispatchInformationProvider.", xProvider.is()); + + uno::Sequence<sal_Int16> Groups = xProvider->getSupportedCommandGroups(); + CPPUNIT_ASSERT_MESSAGE("Couldn't get Supported Command Groups", Groups.getLength() > 0); + + for (sal_Int32 i = 0; i < Groups.getLength(); i++) + { + uno::Sequence<frame::DispatchInformation> DispatchInfos + = xProvider->getConfigurableDispatchInformation(Groups[i]); + CPPUNIT_ASSERT_MESSAGE("Couldn't get Dispatch Information for Supported Command Groups", + DispatchInfos.getLength() > 0); + + std::unordered_map<OUString, OUString> rCheckMap; + + for (sal_Int32 j = 0; j < DispatchInfos.getLength(); j++) + { + const frame::DispatchInformation& xDispatchInfo = DispatchInfos[j]; + CPPUNIT_ASSERT_EQUAL(xDispatchInfo.GroupId, Groups[i]); + + // Check the Dispatch Information + // There should be no duplicates in rCheckMap + // i.e. rCheckMap[xDispatchInfo.Command] should be empty + CPPUNIT_ASSERT_EQUAL(rCheckMap[xDispatchInfo.Command], OUString()); + + rCheckMap[xDispatchInfo.Command] = xDispatchInfo.Command; + } + } +} + +CPPUNIT_TEST_FIXTURE(DispatchAPITest, testCheckDispatchInfoOfWriter) +{ + uno::Reference<frame::XFrame> xFrame = loadComponent(u"private:factory/swriter"_ustr); + checkDispatchInfo(xFrame); +} + +CPPUNIT_TEST_FIXTURE(DispatchAPITest, testCheckDispatchInfoOfCalc) +{ + uno::Reference<frame::XFrame> xFrame = loadComponent(u"private:factory/scalc"_ustr); + checkDispatchInfo(xFrame); +} + +CPPUNIT_TEST_FIXTURE(DispatchAPITest, testCheckDispatchInfoOfDraw) +{ + uno::Reference<frame::XFrame> xFrame = loadComponent(u"private:factory/sdraw"_ustr); + checkDispatchInfo(xFrame); +} + +CPPUNIT_TEST_FIXTURE(DispatchAPITest, testCheckDispatchInfoOfImpress) +{ + uno::Reference<frame::XFrame> xFrame = loadComponent(u"private:factory/simpress"_ustr); + checkDispatchInfo(xFrame); +} + +CPPUNIT_TEST_FIXTURE(DispatchAPITest, testCheckDispatchInfoOfChart) +{ + uno::Reference<frame::XFrame> xFrame = loadComponent(u"private:factory/schart"_ustr); + checkDispatchInfo(xFrame); +} + +CPPUNIT_TEST_FIXTURE(DispatchAPITest, testCheckDispatchInfoOfMath) +{ + uno::Reference<frame::XFrame> xFrame = loadComponent(u"private:factory/smath"_ustr); + checkDispatchInfo(xFrame); +} + +CPPUNIT_TEST_FIXTURE(DispatchAPITest, testCheckDispatchInfoOfDatabase) +{ + uno::Reference<frame::XFrame> xFrame = loadComponent(u"private:factory/sdatabase"_ustr); + checkDispatchInfo(xFrame); +} + +CPPUNIT_TEST_FIXTURE(DispatchAPITest, testCheckDispatchInfoOfBibliography) +{ + uno::Reference<frame::XFrame> xFrame = loadComponent(u".component:Bibliography/View1"_ustr); + checkDispatchInfo(xFrame); +} + +CPPUNIT_TEST_FIXTURE(DispatchAPITest, testCheckDispatchInfoOfFormGridView) +{ + uno::Reference<frame::XFrame> xFrame = loadComponent(u".component:DB/FormGridView"_ustr); + checkDispatchInfo(xFrame); +} + +CPPUNIT_TEST_FIXTURE(DispatchAPITest, testCheckDispatchInfoOfDataSourceBrowser) +{ + uno::Reference<frame::XFrame> xFrame = loadComponent(u".component:DB/DataSourceBrowser"_ustr); + checkDispatchInfo(xFrame); +} + +CPPUNIT_TEST_FIXTURE(DispatchAPITest, testCheckDispatchInfoOfRelationDesign) +{ + uno::Reference<frame::XFrame> xFrame + = loadWithDBComponent(u".component:DB/RelationDesign"_ustr); + checkDispatchInfo(xFrame); +} + +CPPUNIT_TEST_FIXTURE(DispatchAPITest, testCheckDispatchInfoOfQueryDesign) +{ + uno::Reference<frame::XFrame> xFrame = loadWithDBComponent(u".component:DB/QueryDesign"_ustr); + checkDispatchInfo(xFrame); +} + +CPPUNIT_TEST_FIXTURE(DispatchAPITest, testCheckDispatchInfoOfTableDesign) +{ + uno::Reference<frame::XFrame> xFrame = loadWithDBComponent(u".component:DB/TableDesign"_ustr); + checkDispatchInfo(xFrame); +} +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/framework/qa/cppunit/data/checkDispatchAPIDB.odb b/framework/qa/cppunit/data/checkDispatchAPIDB.odb new file mode 100644 index 000000000000..29c20c688349 Binary files /dev/null and b/framework/qa/cppunit/data/checkDispatchAPIDB.odb differ