Avoid potential negative array index access to cached text.
[LibreOffice.git] / toolkit / qa / cppunit / Dialog.cxx
blob6ddf3f72584083e31863f045fe0f80246acc9724
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>
11 #include <unotest/macros_test.hxx>
13 #include <com/sun/star/awt/UnoControlDialog.hpp>
14 #include <com/sun/star/awt/XUnoControlDialog.hpp>
15 #include <com/sun/star/awt/XControlModel.hpp>
16 #include <com/sun/star/beans/XPropertySet.hpp>
17 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
19 #include <comphelper/processfactory.hxx>
20 #include <toolkit/helper/vclunohelper.hxx>
21 #include <vcl/vclptr.hxx>
22 #include <vcl/window.hxx>
24 using namespace css;
26 namespace
28 /// Test dialogs constructed via UNO
29 class DialogTest : public test::BootstrapFixture, public unotest::MacrosTest
31 protected:
32 uno::Reference<uno::XComponentContext> mxContext;
34 public:
35 virtual void setUp() override;
38 void DialogTest::setUp()
40 test::BootstrapFixture::setUp();
42 mxContext.set(comphelper::getComponentContext(getMultiServiceFactory()));
45 CPPUNIT_TEST_FIXTURE(DialogTest, testDialogSizeable)
47 uno::Reference<awt::XDialog> xDialog;
48 uno::Reference<lang::XMultiComponentFactory> xFactory(mxContext->getServiceManager(),
49 uno::UNO_SET_THROW);
50 uno::Reference<awt::XControlModel> xControlModel(
51 xFactory->createInstanceWithContext("com.sun.star.awt.UnoControlDialogModel", mxContext),
52 uno::UNO_QUERY_THROW);
54 uno::Reference<beans::XPropertySet> xPropSet(xControlModel, uno::UNO_QUERY_THROW);
55 xPropSet->setPropertyValue("Sizeable", uno::Any(true));
57 uno::Reference<awt::XUnoControlDialog> xControl = awt::UnoControlDialog::create(mxContext);
58 xControl->setModel(xControlModel);
59 xControl->setVisible(true);
60 xDialog.set(xControl, uno::UNO_QUERY_THROW);
61 xDialog->execute();
63 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow(xControl->getPeer());
64 CPPUNIT_ASSERT(pWindow);
65 CPPUNIT_ASSERT(pWindow->GetStyle() & WB_SIZEABLE);
67 xDialog->endExecute();
68 css::uno::Reference<css::lang::XComponent>(xDialog, css::uno::UNO_QUERY_THROW)->dispose();
69 css::uno::Reference<css::lang::XComponent>(xControlModel, css::uno::UNO_QUERY_THROW)->dispose();
73 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */