sc/qa/extras/testdocuments/KeyShortcut.xlsm |binary sc/qa/extras/vba-macro-test.cxx | 43 ++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+)
New commits: commit 65d2c9ca4d930bd9352e0b51f45e163cf4393241 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Tue Feb 1 12:59:30 2022 +0900 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Wed Feb 2 07:19:05 2022 +0100 vba: test key-binding define by the macro VBA macro can be bound to a key shortcut, so it is executed when the key combination is hit. This checks that the macro gets bound to a specific key combination, when opening a document with such a macro. Change-Id: I1a7739ec9de745a82c130957236576bc694a86cd Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129268 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/sc/qa/extras/testdocuments/KeyShortcut.xlsm b/sc/qa/extras/testdocuments/KeyShortcut.xlsm new file mode 100644 index 000000000000..d684d2a48234 Binary files /dev/null and b/sc/qa/extras/testdocuments/KeyShortcut.xlsm differ diff --git a/sc/qa/extras/vba-macro-test.cxx b/sc/qa/extras/vba-macro-test.cxx index ac93cf181d0b..600951c19615 100644 --- a/sc/qa/extras/vba-macro-test.cxx +++ b/sc/qa/extras/vba-macro-test.cxx @@ -23,6 +23,9 @@ #include <com/sun/star/sheet/XSpreadsheet.hpp> #include <com/sun/star/sheet/XPrintAreas.hpp> #include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp> +#include <com/sun/star/ui/XUIConfigurationManager.hpp> +#include <com/sun/star/awt/KeyModifier.hpp> using namespace css; @@ -55,6 +58,7 @@ public: void testRangeSelect(); void testWindowState(); void testScroll(); + void testMacroKeyBinding(); void testVba(); void testTdf107885(); @@ -71,6 +75,7 @@ public: CPPUNIT_TEST(testRangeSelect); CPPUNIT_TEST(testWindowState); CPPUNIT_TEST(testScroll); + CPPUNIT_TEST(testMacroKeyBinding); CPPUNIT_TEST(testVba); CPPUNIT_TEST(testTdf107885); @@ -420,6 +425,44 @@ void VBAMacroTest::testScroll() CPPUNIT_ASSERT_EQUAL(SCROW(99), rViewData.GetPosY(ScVSplitPos::SC_SPLIT_BOTTOM)); } +void VBAMacroTest::testMacroKeyBinding() +{ + // key_U() -> CTRL+U + // key_T() -> CTRL+T + + OUString aFileName; + createFileURL(u"KeyShortcut.xlsm", aFileName); + mxComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY); + CPPUNIT_ASSERT(xModel.is()); + + uno::Reference<ui::XUIConfigurationManagerSupplier> xConfigSupplier(xModel, uno::UNO_QUERY); + CPPUNIT_ASSERT(xConfigSupplier.is()); + uno::Reference<ui::XUIConfigurationManager> xConfigManager + = xConfigSupplier->getUIConfigurationManager(); + uno::Reference<ui::XAcceleratorConfiguration> xAccelerator + = xConfigManager->getShortCutManager(); + + awt::KeyEvent aCtrlU; + aCtrlU.KeyCode = css::awt::Key::U; + aCtrlU.Modifiers = css::awt::KeyModifier::MOD1; + + CPPUNIT_ASSERT_EQUAL( + OUString( + "vnd.sun.star.script:VBAProject.ThisWorkbook.key_U?language=Basic&location=document"), + xAccelerator->getCommandByKeyEvent(aCtrlU)); + + awt::KeyEvent aCtrlT; + aCtrlT.KeyCode = css::awt::Key::T; + aCtrlT.Modifiers = css::awt::KeyModifier::MOD1; + + CPPUNIT_ASSERT_EQUAL( + OUString( + "vnd.sun.star.script:VBAProject.ThisWorkbook.key_T?language=Basic&location=document"), + xAccelerator->getCommandByKeyEvent(aCtrlT)); +} + void VBAMacroTest::testVba() { TestMacroInfo testInfo[] = {