Avoid potential negative array index access to cached text.
[LibreOffice.git] / toolkit / qa / cppunit / EventContainer.cxx
blobad62f93105e8bc6cd83d935f134183acbb910138
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include <test/bootstrapfixture.hxx>
12 #include <com/sun/star/awt/XControlModel.hpp>
13 #include <com/sun/star/beans/XPropertySet.hpp>
14 #include <com/sun/star/container/XNameContainer.hpp>
15 #include <com/sun/star/lang/XComponent.hpp>
16 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
17 #include <com/sun/star/script/ScriptEventDescriptor.hpp>
18 #include <com/sun/star/script/XScriptEventsSupplier.hpp>
19 #include <com/sun/star/uno/Reference.hxx>
21 #include <comphelper/processfactory.hxx>
23 using namespace css;
24 using namespace css::awt;
25 using namespace css::container;
26 using namespace css::lang;
27 using namespace css::script;
28 using namespace css::uno;
30 namespace
32 /// Test EventContainer class
33 class EventContainerTest : public test::BootstrapFixture
35 protected:
36 Reference<XComponentContext> mxContext;
38 public:
39 virtual void setUp() override;
42 void EventContainerTest::setUp()
44 test::BootstrapFixture::setUp();
46 mxContext.set(comphelper::getComponentContext(getMultiServiceFactory()));
49 // Make sure that EventContainer keeps insertion order, and does not reorder its elements.
50 // Otherwise this would break macro signatures.
51 CPPUNIT_TEST_FIXTURE(EventContainerTest, testInsertOrder)
53 Reference<XMultiComponentFactory> xFactory(mxContext->getServiceManager(), UNO_SET_THROW);
54 Reference<XControlModel> xControlModel(
55 xFactory->createInstanceWithContext("com.sun.star.awt.UnoControlDialogModel", mxContext),
56 UNO_QUERY_THROW);
58 Reference<beans::XPropertySet> xPropSet(xControlModel, UNO_QUERY_THROW);
60 Reference<XScriptEventsSupplier> xEventsSupplier(xPropSet, UNO_QUERY_THROW);
61 Reference<XNameContainer> xEvents(xEventsSupplier->getEvents(), UNO_SET_THROW);
62 script::ScriptEventDescriptor descr1;
63 script::ScriptEventDescriptor descr2;
64 script::ScriptEventDescriptor descr3;
65 script::ScriptEventDescriptor descr4;
66 xEvents->insertByName("b", Any(descr1));
67 xEvents->insertByName("a", Any(descr2));
68 xEvents->insertByName("1", Any(descr3));
69 xEvents->insertByName("A", Any(descr4));
71 Sequence<OUString> aEventNames(xEvents->getElementNames());
72 sal_Int32 nEventCount = aEventNames.getLength();
73 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(4), nEventCount);
75 CPPUNIT_ASSERT_EQUAL(OUString("b"), aEventNames[0]);
76 CPPUNIT_ASSERT_EQUAL(OUString("a"), aEventNames[1]);
77 CPPUNIT_ASSERT_EQUAL(OUString("1"), aEventNames[2]);
78 CPPUNIT_ASSERT_EQUAL(OUString("A"), aEventNames[3]);
80 css::uno::Reference<css::lang::XComponent>(xControlModel, css::uno::UNO_QUERY_THROW)->dispose();
84 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */