Version 7.5.1.1, tag libreoffice-7.5.1.1
[LibreOffice.git] / sc / qa / extras / sceditfieldobj_header.cxx
blob3c577836b692b740d8411ed9636d3b26baed8a6f
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/beans/XPropertySet.hpp>
18 #include <com/sun/star/container/XNameAccess.hpp>
19 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
20 #include <com/sun/star/sheet/XHeaderFooterContent.hpp>
21 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
22 #include <com/sun/star/text/TextContentAnchorType.hpp>
23 #include <com/sun/star/text/WrapTextMode.hpp>
24 #include <com/sun/star/text/XText.hpp>
25 #include <com/sun/star/text/XTextContent.hpp>
26 #include <com/sun/star/text/XTextCursor.hpp>
27 #include <com/sun/star/text/XTextField.hpp>
28 #include <com/sun/star/text/XTextRange.hpp>
29 #include <com/sun/star/uno/XInterface.hpp>
31 #include <com/sun/star/uno/Reference.hxx>
33 using namespace css;
35 namespace sc_apitest
37 class ScEditFieldObj_Header : public UnoApiTest,
38 public apitest::TextContent,
39 public apitest::XComponent,
40 public apitest::XPropertySet,
41 public apitest::XTextContent,
42 public apitest::XTextField
44 public:
45 ScEditFieldObj_Header();
47 virtual void setUp() override;
48 virtual void tearDown() override;
49 virtual uno::Reference<uno::XInterface> init() override;
50 virtual uno::Reference<text::XTextContent> getTextContent() override;
51 virtual uno::Reference<text::XTextRange> getTextRange() override;
52 virtual bool isAttachSupported() override { return false; }
53 virtual void triggerDesktopTerminate() override{};
55 CPPUNIT_TEST_SUITE(ScEditFieldObj_Header);
57 // TextContent
58 CPPUNIT_TEST(testTextContentProperties);
60 // XComponent
61 CPPUNIT_TEST(testAddEventListener);
62 CPPUNIT_TEST(testRemoveEventListener);
63 CPPUNIT_TEST(testDispose);
65 // XPropertySet
66 CPPUNIT_TEST(testGetPropertySetInfo);
67 CPPUNIT_TEST(testGetPropertyValue);
68 CPPUNIT_TEST(testSetPropertyValue);
69 CPPUNIT_TEST(testPropertyChangeListener);
70 CPPUNIT_TEST(testVetoableChangeListener);
72 // XTextContent
73 CPPUNIT_TEST(testGetAnchor);
74 CPPUNIT_TEST(testAttach);
76 // XTextField
77 CPPUNIT_TEST(testGetPresentationEmptyString);
79 CPPUNIT_TEST_SUITE_END();
81 private:
82 static uno::Reference<text::XTextField> mxField;
83 static uno::Reference<text::XText> mxRightText;
86 uno::Reference<text::XTextField> ScEditFieldObj_Header::mxField;
87 uno::Reference<text::XText> ScEditFieldObj_Header::mxRightText;
89 ScEditFieldObj_Header::ScEditFieldObj_Header()
90 : UnoApiTest("/sc/qa/extras/testdocuments")
91 , TextContent(text::TextContentAnchorType_AS_CHARACTER,
92 text::TextContentAnchorType_AS_CHARACTER, text::WrapTextMode_NONE,
93 text::WrapTextMode_NONE)
97 void ScEditFieldObj_Header::setUp()
99 UnoApiTest::setUp();
100 // Load an empty document.
101 mxComponent = loadFromDesktop("private:factory/scalc");
104 void ScEditFieldObj_Header::tearDown()
106 // Clear these before the component is destroyed. This is important!
107 mxField.clear();
108 mxRightText.clear();
110 UnoApiTest::tearDown();
113 uno::Reference<uno::XInterface> ScEditFieldObj_Header::init()
115 // Return a field that's already in the header.
116 if (!mxField.is())
118 uno::Reference<lang::XMultiServiceFactory> xSM(mxComponent, uno::UNO_QUERY_THROW);
120 // Create a new URL field object, and populate it with name and URL.
121 mxField.set(xSM->createInstance("com.sun.star.text.TextField.Time"), uno::UNO_QUERY_THROW);
123 uno::Reference<style::XStyleFamiliesSupplier> xSFS(mxComponent, uno::UNO_QUERY_THROW);
124 uno::Reference<container::XNameAccess> xStyleFamilies(xSFS->getStyleFamilies(),
125 uno::UNO_SET_THROW);
126 uno::Reference<container::XNameAccess> xPageStyles(xStyleFamilies->getByName("PageStyles"),
127 uno::UNO_QUERY_THROW);
128 uno::Reference<beans::XPropertySet> xPropSet(xPageStyles->getByName("Default"),
129 uno::UNO_QUERY_THROW);
131 uno::Reference<sheet::XHeaderFooterContent> xHeaderContent(
132 xPropSet->getPropertyValue("RightPageHeaderContent"), uno::UNO_QUERY_THROW);
134 // Use the left header text.
135 uno::Reference<text::XText> xText = xHeaderContent->getLeftText();
136 uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor();
137 uno::Reference<text::XTextRange> xRange(xCursor, uno::UNO_QUERY_THROW);
138 uno::Reference<text::XTextContent> xContent(mxField, uno::UNO_QUERY_THROW);
139 xText->insertTextContent(xRange, xContent, false);
141 xPropSet->setPropertyValue("RightPageHeaderContent", uno::Any(xHeaderContent));
143 mxRightText = xHeaderContent->getRightText();
146 return mxField;
149 uno::Reference<text::XTextContent> ScEditFieldObj_Header::getTextContent()
151 // Return a field object that's not yet inserted.
152 uno::Reference<lang::XMultiServiceFactory> xSM(mxComponent, uno::UNO_QUERY_THROW);
153 uno::Reference<text::XTextContent> xField(
154 xSM->createInstance("com.sun.star.text.TextField.Date"), uno::UNO_QUERY_THROW);
155 return xField;
158 uno::Reference<text::XTextRange> ScEditFieldObj_Header::getTextRange()
160 // Use the right header text for this.
161 uno::Reference<text::XTextRange> xRange(mxRightText, uno::UNO_QUERY_THROW);
162 return xRange;
165 CPPUNIT_TEST_SUITE_REGISTRATION(ScEditFieldObj_Header);
167 } // namespace sc_apitest
169 CPPUNIT_PLUGIN_IMPLEMENT();
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */