tdf#130857 qt weld: Support mail merge "Server Auth" dialog
[LibreOffice.git] / sw / qa / api / SwXTextField.cxx
blobfc3882ef7c00a3501372ab0cefd7e2da5e192cb2
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/unoapi_test.hxx>
11 #include <test/beans/xpropertyset.hxx>
12 #include <test/lang/xcomponent.hxx>
13 #include <test/text/textcontent.hxx>
14 #include <test/text/xtextcontent.hxx>
15 #include <test/text/xtextfield.hxx>
17 #include <com/sun/star/frame/Desktop.hpp>
19 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
21 #include <com/sun/star/beans/XPropertySet.hpp>
23 #include <com/sun/star/text/XTextDocument.hpp>
24 #include <com/sun/star/text/XTextContent.hpp>
25 #include <com/sun/star/text/XText.hpp>
26 #include <com/sun/star/text/XDependentTextField.hpp>
27 #include <com/sun/star/text/XTextCursor.hpp>
29 #include <comphelper/processfactory.hxx>
31 using namespace css;
32 using namespace css::uno;
34 namespace
36 /**
37 * Initial tests for SwXTextField.
39 struct SwXTextField final : public UnoApiTest,
40 public apitest::XPropertySet,
41 public apitest::XComponent,
42 public apitest::TextContent,
43 public apitest::XTextContent,
44 public apitest::XTextField
46 SwXTextField()
47 : UnoApiTest(u""_ustr)
48 , TextContent(text::TextContentAnchorType_AS_CHARACTER,
49 text::TextContentAnchorType_AS_CHARACTER, text::WrapTextMode_NONE,
50 text::WrapTextMode_NONE)
54 Reference<XInterface> init() override
56 loadFromURL(u"private:factory/swriter"_ustr);
57 Reference<text::XTextDocument> xTextDocument(mxComponent, UNO_QUERY_THROW);
58 Reference<lang::XMultiServiceFactory> xMSF(mxComponent, UNO_QUERY_THROW);
60 Reference<beans::XPropertySet> xFieldMaster(
61 xMSF->createInstance(u"com.sun.star.text.FieldMaster.Database"_ustr), UNO_QUERY_THROW);
63 xFieldMaster->setPropertyValue(u"DataBaseName"_ustr, Any(u"Address Book File"_ustr));
64 xFieldMaster->setPropertyValue(u"DataTableName"_ustr, Any(u"address"_ustr));
65 xFieldMaster->setPropertyValue(u"DataColumnName"_ustr, Any(u"FIRSTNAME"_ustr));
67 Reference<text::XDependentTextField> xField(
68 xMSF->createInstance(u"com.sun.star.text.TextField.Database"_ustr), UNO_QUERY_THROW);
69 xField->attachTextFieldMaster(xFieldMaster);
71 Reference<text::XText> xText = xTextDocument->getText();
72 Reference<text::XTextCursor> xCursor = xText->createTextCursor();
73 Reference<text::XTextContent> xFieldAsContent(xField, UNO_QUERY_THROW);
74 xText->insertTextContent(xCursor, xFieldAsContent, false);
76 mxTextRange = Reference<text::XTextRange>(xCursor, UNO_QUERY_THROW);
77 mxTextContent = Reference<text::XTextContent>(
78 xMSF->createInstance(u"com.sun.star.text.TextField.DateTime"_ustr), UNO_QUERY_THROW);
80 return Reference<XInterface>(xField, UNO_QUERY_THROW);
83 void triggerDesktopTerminate() override { mxDesktop->terminate(); };
84 bool isAttachSupported() override { return true; };
85 Reference<text::XTextRange> getTextRange() override { return mxTextRange; };
86 Reference<text::XTextContent> getTextContent() override { return mxTextContent; };
88 CPPUNIT_TEST_SUITE(SwXTextField);
89 CPPUNIT_TEST(testDispose);
90 CPPUNIT_TEST(testAddEventListener);
91 CPPUNIT_TEST(testRemoveEventListener);
92 CPPUNIT_TEST(testTextContentProperties);
93 CPPUNIT_TEST(testAttach);
94 CPPUNIT_TEST(testGetAnchor);
95 CPPUNIT_TEST_SUITE_END();
97 private:
98 Reference<text::XTextRange> mxTextRange;
99 Reference<text::XTextContent> mxTextContent;
102 CPPUNIT_TEST_SUITE_REGISTRATION(SwXTextField);
105 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */