diff options
-rw-r--r-- | include/svtools/valueset.hxx | 1 | ||||
-rw-r--r-- | svtools/CppunitTest_svtools_dialogs_test.mk | 2 | ||||
-rw-r--r-- | svtools/Library_svt.mk | 1 | ||||
-rw-r--r-- | svtools/inc/uitest/uiobject.hxx | 36 | ||||
-rw-r--r-- | svtools/qa/unit/svtools-dialogs-test.cxx | 35 | ||||
-rw-r--r-- | svtools/source/control/valueset.cxx | 6 | ||||
-rw-r--r-- | svtools/source/uitest/uiobject.cxx | 66 |
7 files changed, 146 insertions, 1 deletions
diff --git a/include/svtools/valueset.hxx b/include/svtools/valueset.hxx index 3855795d0627..eb3ad8d80cf8 100644 --- a/include/svtools/valueset.hxx +++ b/include/svtools/valueset.hxx @@ -296,6 +296,7 @@ public: virtual void StateChanged( StateChangedType nStateChange ) override; virtual void DataChanged( const DataChangedEvent& rDCEvt ) override; virtual boost::property_tree::ptree DumpAsPropertyTree() override; + virtual FactoryFunction GetUITestFactory() const override; virtual void Select(); virtual void UserDraw( const UserDrawEvent& rUDEvt ); diff --git a/svtools/CppunitTest_svtools_dialogs_test.mk b/svtools/CppunitTest_svtools_dialogs_test.mk index 28c4db4742ea..70f8a00e4bf7 100644 --- a/svtools/CppunitTest_svtools_dialogs_test.mk +++ b/svtools/CppunitTest_svtools_dialogs_test.mk @@ -17,7 +17,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,svtools_dialogs_test, \ $(eval $(call gb_CppunitTest_use_sdk_api,svtools_dialogs_test)) -$(eval $(call gb_CppunitTest_set_include,desktop_dialogs_test,\ +$(eval $(call gb_CppunitTest_set_include,svtools_dialogs_test,\ -I$(SRCDIR)/svtools/source/inc \ -I$(SRCDIR)/svtools/inc \ $$(INCLUDE) \ diff --git a/svtools/Library_svt.mk b/svtools/Library_svt.mk index 95486e42b328..c631190904b2 100644 --- a/svtools/Library_svt.mk +++ b/svtools/Library_svt.mk @@ -166,6 +166,7 @@ $(eval $(call gb_Library_add_exception_objects,svt,\ svtools/source/table/mousefunction \ svtools/source/table/cellvalueconversion \ svtools/source/table/tablegeometry \ + svtools/source/uitest/uiobject \ svtools/source/uno/addrtempuno \ svtools/source/uno/fpicker \ svtools/source/uno/framestatuslistener \ diff --git a/svtools/inc/uitest/uiobject.hxx b/svtools/inc/uitest/uiobject.hxx new file mode 100644 index 000000000000..c1a2ecf1f9f5 --- /dev/null +++ b/svtools/inc/uitest/uiobject.hxx @@ -0,0 +1,36 @@ +/* -*- 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 <memory> +#include <vcl/uitest/uiobject.hxx> + +class ValueSet; + +class ValueSetUIObject : public WindowUIObject +{ +private: + VclPtr<ValueSet> mxValueSet; + +public: + ValueSetUIObject(const VclPtr<ValueSet>& xValueSet); + virtual ~ValueSetUIObject() override; + + virtual void execute(const OUString& rAction, const StringMap& rParameters) override; + + virtual StringMap get_state() override; + + static std::unique_ptr<UIObject> create(vcl::Window* pWindow); + + virtual OUString get_action(VclEventId nEvent) const override; + +protected: + virtual OUString get_name() const override; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svtools/qa/unit/svtools-dialogs-test.cxx b/svtools/qa/unit/svtools-dialogs-test.cxx index 3c4efa419426..897455b2ff23 100644 --- a/svtools/qa/unit/svtools-dialogs-test.cxx +++ b/svtools/qa/unit/svtools-dialogs-test.cxx @@ -10,6 +10,10 @@ #include <sal/config.h> #include <test/screenshot_test.hxx> #include <vcl/abstdlg.hxx> +#include <vcl/scheduler.hxx> +#include <vcl/wrkwin.hxx> +#include <uitest/uiobject.hxx> +#include <svtools/valueset.hxx> using namespace ::com::sun::star; @@ -30,9 +34,11 @@ public: // try to open a dialog void openAnyDialog(); + void testValueSetControl(); CPPUNIT_TEST_SUITE(SvtoolsDialogsTest); CPPUNIT_TEST(openAnyDialog); + CPPUNIT_TEST(testValueSetControl); CPPUNIT_TEST_SUITE_END(); }; @@ -56,6 +62,35 @@ void SvtoolsDialogsTest::openAnyDialog() processDialogBatchFile("svtools/qa/unit/data/svtools-dialogs-test.txt"); } +void SvtoolsDialogsTest::testValueSetControl() +{ + VclPtr<WorkWindow> pWorkWindow = VclPtr<WorkWindow>::Create(nullptr, WB_APP | WB_STDWORK); + VclPtr<ValueSet> pValueSet = VclPtr<ValueSet>::Create(pWorkWindow, WB_ITEMBORDER); + pValueSet->InsertItem(100, 0); + pValueSet->InsertItem(200, 1); + pValueSet->InsertItem(300, 2); + pValueSet->Show(); + pWorkWindow->Show(); + Scheduler::ProcessEventsToIdle(); + + CPPUNIT_ASSERT(pValueSet->IsEnabled()); + CPPUNIT_ASSERT(pValueSet->IsReallyVisible()); + CPPUNIT_ASSERT_EQUAL(false, pValueSet->IsItemSelected(300)); + { + std::unique_ptr<UIObject> pUIObject = pValueSet->GetUITestFactory()(pValueSet.get()); + CPPUNIT_ASSERT(pUIObject); + + StringMap aMap; + aMap["ID"] = "300"; + + pUIObject->execute("SELECT", aMap); + } + CPPUNIT_ASSERT_EQUAL(true, pValueSet->IsItemSelected(300)); + + pValueSet->disposeOnce(); + pWorkWindow->disposeOnce(); +} + CPPUNIT_TEST_SUITE_REGISTRATION(SvtoolsDialogsTest); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/svtools/source/control/valueset.cxx b/svtools/source/control/valueset.cxx index 494583799287..462cd55e99d1 100644 --- a/svtools/source/control/valueset.cxx +++ b/svtools/source/control/valueset.cxx @@ -27,6 +27,7 @@ #include <vcl/settings.hxx> #include <vcl/commandevent.hxx> #include <vcl/virdev.hxx> +#include <uitest/uiobject.hxx> #include <com/sun/star/accessibility/AccessibleEventId.hpp> #include <com/sun/star/lang/XComponent.hpp> @@ -1455,6 +1456,11 @@ boost::property_tree::ptree ValueSet::DumpAsPropertyTree() return aTree; } +FactoryFunction ValueSet::GetUITestFactory() const +{ + return ValueSetUIObject::create; +} + void ValueSet::Select() { maSelectHdl.Call( this ); diff --git a/svtools/source/uitest/uiobject.cxx b/svtools/source/uitest/uiobject.cxx new file mode 100644 index 000000000000..2b1933a19e21 --- /dev/null +++ b/svtools/source/uitest/uiobject.cxx @@ -0,0 +1,66 @@ +/* -*- 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 <memory> +#include <uitest/uiobject.hxx> + +#include <svtools/valueset.hxx> + +ValueSetUIObject::ValueSetUIObject(const VclPtr<ValueSet>& xValueSet) + : WindowUIObject(xValueSet) + , mxValueSet(xValueSet) +{ +} + +ValueSetUIObject::~ValueSetUIObject() {} + +void ValueSetUIObject::execute(const OUString& rAction, const StringMap& rParameters) +{ + if (!mxValueSet->IsEnabled() || !mxValueSet->IsReallyVisible()) + return; + + if (rAction == "SELECT") + { + if (rParameters.find("ID") != rParameters.end()) + { + auto aPos = rParameters.find("ID"); + OUString aVal = aPos->second; + sal_Int32 nPos = aVal.toInt32(); + mxValueSet->SelectItem(nPos); + mxValueSet->Select(); + } + } + else + WindowUIObject::execute(rAction, rParameters); +} + +StringMap ValueSetUIObject::get_state() +{ + StringMap aMap = WindowUIObject::get_state(); + aMap["EntryCount"] = OUString::number(mxValueSet->GetItemCount()); + + return aMap; +} + +OUString ValueSetUIObject::get_name() const { return "ValueSetUIObject"; } + +OUString ValueSetUIObject::get_action(VclEventId /*nEvent*/) const +{ + // No action for this control that trigger item selection after mouse tracking end + return OUString(); +} + +std::unique_ptr<UIObject> ValueSetUIObject::create(vcl::Window* pWindow) +{ + ValueSet* pValueSet = dynamic_cast<ValueSet*>(pWindow); + assert(pValueSet); + return std::unique_ptr<UIObject>(new ValueSetUIObject(pValueSet)); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |