1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #include <test/bootstrapfixture.hxx>
11 #include <test/lang/xcomponent.hxx>
12 #include <unotest/macros_test.hxx>
14 #include <com/sun/star/frame/Desktop.hpp>
16 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
18 #include <com/sun/star/beans/XPropertySet.hpp>
20 #include <com/sun/star/text/XTextDocument.hpp>
21 #include <com/sun/star/text/XTextContent.hpp>
22 #include <com/sun/star/text/XText.hpp>
23 #include <com/sun/star/text/XDependentTextField.hpp>
24 #include <com/sun/star/text/XTextCursor.hpp>
26 #include <comphelper/processfactory.hxx>
29 using namespace css::uno
;
30 using namespace css::beans
;
35 * Initial tests for SwXTextField.
37 struct SwXTextField final
: public test::BootstrapFixture
,
38 public unotest::MacrosTest
,
39 public apitest::XComponent
41 virtual void setUp() override
;
42 void tearDown() override
;
44 Reference
<XInterface
> init() override
;
45 void triggerDesktopTerminate() override
;
47 CPPUNIT_TEST_SUITE(SwXTextField
);
48 CPPUNIT_TEST(testAddEventListener
);
49 CPPUNIT_TEST(testRemoveEventListener
);
50 CPPUNIT_TEST_SUITE_END();
53 css::uno::Reference
<css::lang::XComponent
> component_
;
56 void SwXTextField::setUp()
58 test::BootstrapFixture::setUp();
60 frame::Desktop::create(comphelper::getComponentContext(getMultiServiceFactory())));
63 void SwXTextField::tearDown()
67 component_
->dispose();
71 void SwXTextField::triggerDesktopTerminate() { mxDesktop
->terminate(); }
73 Reference
<XInterface
> SwXTextField::init()
75 component_
= loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument");
76 Reference
<text::XTextDocument
> xTextDocument(component_
, UNO_QUERY_THROW
);
77 Reference
<lang::XMultiServiceFactory
> xMSF(component_
, UNO_QUERY_THROW
);
79 Reference
<XPropertySet
> xFieldMaster(
80 xMSF
->createInstance("com.sun.star.text.FieldMaster.Database"), UNO_QUERY_THROW
);
81 xFieldMaster
->setPropertyValue("DataBaseName", Any(OUString("Address Book File")));
82 xFieldMaster
->setPropertyValue("DataTableName", Any(OUString("address")));
83 xFieldMaster
->setPropertyValue("DataColumnName", Any(OUString("FIRSTNAME")));
85 Reference
<text::XDependentTextField
> xField(
86 xMSF
->createInstance("com.sun.star.text.TextField.Database"), UNO_QUERY_THROW
);
87 xField
->attachTextFieldMaster(xFieldMaster
);
88 Reference
<text::XText
> xText
= xTextDocument
->getText();
89 Reference
<text::XTextCursor
> xCursor
= xText
->createTextCursor();
90 Reference
<text::XTextContent
> xFieldAsContent(xField
, UNO_QUERY_THROW
);
91 xText
->insertTextContent(xCursor
, xFieldAsContent
, false);
92 return Reference
<XInterface
>(xField
, UNO_QUERY_THROW
);
95 CPPUNIT_TEST_SUITE_REGISTRATION(SwXTextField
);
98 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */