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/xtextfield.hxx>
13 #include <test/text/xtextcontent.hxx>
15 #include <com/sun/star/beans/XPropertySet.hpp>
16 #include <com/sun/star/container/XEnumerationAccess.hpp>
17 #include <com/sun/star/container/XNameAccess.hpp>
18 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
19 #include <com/sun/star/text/XText.hpp>
20 #include <com/sun/star/text/XTextField.hpp>
21 #include <com/sun/star/text/XTextFieldsSupplier.hpp>
22 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
23 #include <com/sun/star/sheet/XSpreadsheet.hpp>
24 #include <com/sun/star/sheet/XHeaderFooterContent.hpp>
26 #define NUMBER_OF_TESTS 5
29 using namespace css::uno
;
31 namespace sc_apitest
{
33 class ScEditFieldObj_Header
: public CalcUnoApiTest
, apitest::XTextContent
, apitest::XPropertySet
36 ScEditFieldObj_Header();
38 virtual void setUp() SAL_OVERRIDE
;
39 virtual void tearDown() SAL_OVERRIDE
;
40 virtual uno::Reference
<uno::XInterface
> init() SAL_OVERRIDE
;
41 virtual uno::Reference
<text::XTextContent
> getTextContent() SAL_OVERRIDE
;
42 virtual uno::Reference
<text::XTextRange
> getTextRange() SAL_OVERRIDE
;
43 virtual bool isAttachSupported() SAL_OVERRIDE
{ return false; }
45 CPPUNIT_TEST_SUITE(ScEditFieldObj_Header
);
48 CPPUNIT_TEST(testGetPropertySetInfo
);
49 CPPUNIT_TEST(testGetPropertyValue
);
50 CPPUNIT_TEST(testSetPropertyValue
);
53 CPPUNIT_TEST(testGetAnchor
);
54 CPPUNIT_TEST(testAttach
);
55 CPPUNIT_TEST_SUITE_END();
58 static sal_Int32 nTest
;
59 static uno::Reference
<lang::XComponent
> mxComponent
;
60 static uno::Reference
<text::XTextField
> mxField
;
61 static uno::Reference
<text::XText
> mxRightText
;
64 sal_Int32
ScEditFieldObj_Header::nTest
= 0;
65 uno::Reference
<lang::XComponent
> ScEditFieldObj_Header::mxComponent
;
66 uno::Reference
<text::XTextField
> ScEditFieldObj_Header::mxField
;
67 uno::Reference
<text::XText
> ScEditFieldObj_Header::mxRightText
;
69 ScEditFieldObj_Header::ScEditFieldObj_Header()
70 : CalcUnoApiTest("/sc/qa/extras/testdocuments")
74 void ScEditFieldObj_Header::setUp()
77 CalcUnoApiTest::setUp();
80 void ScEditFieldObj_Header::tearDown()
82 if (nTest
== NUMBER_OF_TESTS
)
84 // Clear these before the component is destroyed. This is important!
87 closeDocument(mxComponent
);
91 CalcUnoApiTest::tearDown();
94 uno::Reference
<uno::XInterface
> ScEditFieldObj_Header::init()
96 // Return a field that's already in the header.
99 if (!mxComponent
.is())
100 // Load an empty document.
101 mxComponent
= loadFromDesktop("private:factory/scalc");
103 uno::Reference
<lang::XMultiServiceFactory
> xSM(mxComponent
, UNO_QUERY_THROW
);
105 // Create a new URL field object, and populate it with name and URL.
106 mxField
.set(xSM
->createInstance("com.sun.star.text.TextField.Time"), UNO_QUERY_THROW
);
108 uno::Reference
<style::XStyleFamiliesSupplier
> xSFS(mxComponent
, UNO_QUERY_THROW
);
109 uno::Reference
<container::XNameAccess
> xStyleFamilies(xSFS
->getStyleFamilies(), UNO_QUERY_THROW
);
110 uno::Reference
<container::XNameAccess
> xPageStyles(xStyleFamilies
->getByName("PageStyles"), UNO_QUERY_THROW
);
111 uno::Reference
<beans::XPropertySet
> xPropSet(xPageStyles
->getByName("Default"), UNO_QUERY_THROW
);
113 uno::Reference
<sheet::XHeaderFooterContent
> xHeaderContent(
114 xPropSet
->getPropertyValue("RightPageHeaderContent"), UNO_QUERY_THROW
);
116 // Use the left header text.
117 uno::Reference
<text::XText
> xText
= xHeaderContent
->getLeftText();
118 uno::Reference
<text::XTextCursor
> xCursor
= xText
->createTextCursor();
119 uno::Reference
<text::XTextRange
> xRange(xCursor
, UNO_QUERY_THROW
);
120 uno::Reference
<text::XTextContent
> xContent(mxField
, UNO_QUERY_THROW
);
121 xText
->insertTextContent(xRange
, xContent
, sal_False
);
123 xPropSet
->setPropertyValue("RightPageHeaderContent", uno::makeAny(xHeaderContent
));
125 mxRightText
= xHeaderContent
->getRightText();
131 uno::Reference
<text::XTextContent
> ScEditFieldObj_Header::getTextContent()
133 // Return a field object that's not yet inserted.
134 uno::Reference
<lang::XMultiServiceFactory
> xSM(mxComponent
, UNO_QUERY_THROW
);
135 uno::Reference
<text::XTextContent
> xField(
136 xSM
->createInstance("com.sun.star.text.TextField.Date"), UNO_QUERY_THROW
);
140 uno::Reference
<text::XTextRange
> ScEditFieldObj_Header::getTextRange()
142 // Use the right header text for this.
143 uno::Reference
<text::XTextRange
> xRange(mxRightText
, UNO_QUERY_THROW
);
147 CPPUNIT_TEST_SUITE_REGISTRATION(ScEditFieldObj_Header
);
151 CPPUNIT_PLUGIN_IMPLEMENT();
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */