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/calc_unoapi_test.hxx>
11 #include <test/beans/xpropertyset.hxx>
12 #include <test/text/textcontent.hxx>
13 #include <test/text/xtextcontent.hxx>
14 #include <test/text/xtextfield.hxx>
16 #include <com/sun/star/beans/XPropertySet.hpp>
17 #include <com/sun/star/container/XNameAccess.hpp>
18 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
19 #include <com/sun/star/sheet/XHeaderFooterContent.hpp>
20 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
21 #include <com/sun/star/text/TextContentAnchorType.hpp>
22 #include <com/sun/star/text/WrapTextMode.hpp>
23 #include <com/sun/star/text/XText.hpp>
24 #include <com/sun/star/text/XTextContent.hpp>
25 #include <com/sun/star/text/XTextCursor.hpp>
26 #include <com/sun/star/text/XTextField.hpp>
27 #include <com/sun/star/text/XTextRange.hpp>
28 #include <com/sun/star/uno/XInterface.hpp>
30 #include <com/sun/star/uno/Reference.hxx>
36 class ScEditFieldObj_Header
: public CalcUnoApiTest
,
37 public apitest::TextContent
,
38 public apitest::XPropertySet
,
39 public apitest::XTextContent
,
40 public apitest::XTextField
43 ScEditFieldObj_Header();
45 virtual void setUp() override
;
46 virtual void tearDown() override
;
47 virtual uno::Reference
<uno::XInterface
> init() override
;
48 virtual uno::Reference
<text::XTextContent
> getTextContent() override
;
49 virtual uno::Reference
<text::XTextRange
> getTextRange() override
;
50 virtual bool isAttachSupported() override
{ return false; }
52 CPPUNIT_TEST_SUITE(ScEditFieldObj_Header
);
55 CPPUNIT_TEST(testTextContentProperties
);
58 CPPUNIT_TEST(testGetPropertySetInfo
);
59 CPPUNIT_TEST(testGetPropertyValue
);
60 CPPUNIT_TEST(testSetPropertyValue
);
61 CPPUNIT_TEST(testPropertyChangeListener
);
62 CPPUNIT_TEST(testVetoableChangeListener
);
65 CPPUNIT_TEST(testGetAnchor
);
66 CPPUNIT_TEST(testAttach
);
69 CPPUNIT_TEST(testGetPresentationEmptyString
);
71 CPPUNIT_TEST_SUITE_END();
74 uno::Reference
<lang::XComponent
> mxComponent
;
75 static uno::Reference
<text::XTextField
> mxField
;
76 static uno::Reference
<text::XText
> mxRightText
;
79 uno::Reference
<text::XTextField
> ScEditFieldObj_Header::mxField
;
80 uno::Reference
<text::XText
> ScEditFieldObj_Header::mxRightText
;
82 ScEditFieldObj_Header::ScEditFieldObj_Header()
83 : CalcUnoApiTest("/sc/qa/extras/testdocuments")
84 , TextContent(text::TextContentAnchorType_AS_CHARACTER
,
85 text::TextContentAnchorType_AS_CHARACTER
, text::WrapTextMode_NONE
,
86 text::WrapTextMode_NONE
)
90 void ScEditFieldObj_Header::setUp()
92 CalcUnoApiTest::setUp();
93 // Load an empty document.
94 mxComponent
= loadFromDesktop("private:factory/scalc");
97 void ScEditFieldObj_Header::tearDown()
99 // Clear these before the component is destroyed. This is important!
102 closeDocument(mxComponent
);
104 CalcUnoApiTest::tearDown();
107 uno::Reference
<uno::XInterface
> ScEditFieldObj_Header::init()
109 // Return a field that's already in the header.
112 uno::Reference
<lang::XMultiServiceFactory
> xSM(mxComponent
, uno::UNO_QUERY_THROW
);
114 // Create a new URL field object, and populate it with name and URL.
115 mxField
.set(xSM
->createInstance("com.sun.star.text.TextField.Time"), uno::UNO_QUERY_THROW
);
117 uno::Reference
<style::XStyleFamiliesSupplier
> xSFS(mxComponent
, uno::UNO_QUERY_THROW
);
118 uno::Reference
<container::XNameAccess
> xStyleFamilies(xSFS
->getStyleFamilies(),
120 uno::Reference
<container::XNameAccess
> xPageStyles(xStyleFamilies
->getByName("PageStyles"),
121 uno::UNO_QUERY_THROW
);
122 uno::Reference
<beans::XPropertySet
> xPropSet(xPageStyles
->getByName("Default"),
123 uno::UNO_QUERY_THROW
);
125 uno::Reference
<sheet::XHeaderFooterContent
> xHeaderContent(
126 xPropSet
->getPropertyValue("RightPageHeaderContent"), uno::UNO_QUERY_THROW
);
128 // Use the left header text.
129 uno::Reference
<text::XText
> xText
= xHeaderContent
->getLeftText();
130 uno::Reference
<text::XTextCursor
> xCursor
= xText
->createTextCursor();
131 uno::Reference
<text::XTextRange
> xRange(xCursor
, uno::UNO_QUERY_THROW
);
132 uno::Reference
<text::XTextContent
> xContent(mxField
, uno::UNO_QUERY_THROW
);
133 xText
->insertTextContent(xRange
, xContent
, false);
135 xPropSet
->setPropertyValue("RightPageHeaderContent", uno::makeAny(xHeaderContent
));
137 mxRightText
= xHeaderContent
->getRightText();
143 uno::Reference
<text::XTextContent
> ScEditFieldObj_Header::getTextContent()
145 // Return a field object that's not yet inserted.
146 uno::Reference
<lang::XMultiServiceFactory
> xSM(mxComponent
, uno::UNO_QUERY_THROW
);
147 uno::Reference
<text::XTextContent
> xField(
148 xSM
->createInstance("com.sun.star.text.TextField.Date"), uno::UNO_QUERY_THROW
);
152 uno::Reference
<text::XTextRange
> ScEditFieldObj_Header::getTextRange()
154 // Use the right header text for this.
155 uno::Reference
<text::XTextRange
> xRange(mxRightText
, uno::UNO_QUERY_THROW
);
159 CPPUNIT_TEST_SUITE_REGISTRATION(ScEditFieldObj_Header
);
161 } // namespace sc_apitest
163 CPPUNIT_PLUGIN_IMPLEMENT();
165 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */