From 4021fedf758b8c4c439387c61223acd78630cedc Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Wed, 6 May 2020 16:32:12 +0200 Subject: [PATCH] Test keeping element order in EventContainer Change-Id: Ic33d8a83305f70bb3eb60f44da0d9ac0d2b47e16 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93570 Tested-by: Jenkins Reviewed-by: Samuel Mehrbrodt --- toolkit/CppunitTest_toolkit.mk | 1 + toolkit/qa/cppunit/EventContainer.cxx | 82 +++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 toolkit/qa/cppunit/EventContainer.cxx diff --git a/toolkit/CppunitTest_toolkit.mk b/toolkit/CppunitTest_toolkit.mk index 5afa7a616188..496ed0d7bac0 100644 --- a/toolkit/CppunitTest_toolkit.mk +++ b/toolkit/CppunitTest_toolkit.mk @@ -11,6 +11,7 @@ $(eval $(call gb_CppunitTest_CppunitTest,toolkit)) $(eval $(call gb_CppunitTest_add_exception_objects,toolkit, \ toolkit/qa/cppunit/Dialog \ + toolkit/qa/cppunit/EventContainer \ toolkit/qa/cppunit/UnitConversion \ )) diff --git a/toolkit/qa/cppunit/EventContainer.cxx b/toolkit/qa/cppunit/EventContainer.cxx new file mode 100644 index 000000000000..300c8e5adb74 --- /dev/null +++ b/toolkit/qa/cppunit/EventContainer.cxx @@ -0,0 +1,82 @@ +/* -*- 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 + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace css; +using namespace css::awt; +using namespace css::container; +using namespace css::lang; +using namespace css::script; +using namespace css::uno; + +namespace +{ +/// Test EventContainer class +class EventContainerTest : public test::BootstrapFixture +{ +protected: + Reference mxContext; + +public: + virtual void setUp() override; +}; + +void EventContainerTest::setUp() +{ + test::BootstrapFixture::setUp(); + + mxContext.set(comphelper::getComponentContext(getMultiServiceFactory())); +} + +// Make sure that EventContainer keeps insertion order, and does not reorder its elements. +// Otherwise this would break macro signatures. +CPPUNIT_TEST_FIXTURE(EventContainerTest, testInsertOrder) +{ + Reference xFactory(mxContext->getServiceManager(), UNO_SET_THROW); + Reference xControlModel( + xFactory->createInstanceWithContext("com.sun.star.awt.UnoControlDialogModel", mxContext), + UNO_QUERY_THROW); + + Reference xPropSet(xControlModel, UNO_QUERY_THROW); + + Reference xEventsSupplier(xPropSet, UNO_QUERY_THROW); + Reference xEvents(xEventsSupplier->getEvents(), UNO_SET_THROW); + script::ScriptEventDescriptor descr1; + script::ScriptEventDescriptor descr2; + script::ScriptEventDescriptor descr3; + script::ScriptEventDescriptor descr4; + xEvents->insertByName("b", makeAny(descr1)); + xEvents->insertByName("a", makeAny(descr2)); + xEvents->insertByName("1", makeAny(descr3)); + xEvents->insertByName("A", makeAny(descr4)); + + Sequence aEventNames(xEvents->getElementNames()); + sal_Int32 nEventCount = aEventNames.getLength(); + CPPUNIT_ASSERT_EQUAL(4, nEventCount); + + CPPUNIT_ASSERT_EQUAL(OUString("b"), aEventNames[0]); + CPPUNIT_ASSERT_EQUAL(OUString("a"), aEventNames[1]); + CPPUNIT_ASSERT_EQUAL(OUString("1"), aEventNames[2]); + CPPUNIT_ASSERT_EQUAL(OUString("A"), aEventNames[3]); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */