1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * Version: MPL 1.1 / GPLv3+ / LGPLv3+
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License or as specified alternatively below. You may obtain a copy of
8 * the License at http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * Major Contributor(s):
16 * Copyright (C) 2012 Kohei Yoshida <kohei.yoshida@suse.com>
18 * All Rights Reserved.
20 * For minor contributions see the git repository.
22 * Alternatively, the contents of this file may be used under the terms of
23 * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
24 * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
25 * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
26 * instead of those above.
29 #include <test/unoapi_test.hxx>
30 #include <test/beans/xpropertyset.hxx>
31 #include <test/text/xtextfield.hxx>
32 #include <test/text/xtextcontent.hxx>
34 #include <com/sun/star/beans/XPropertySet.hpp>
35 #include <com/sun/star/container/XEnumerationAccess.hpp>
36 #include <com/sun/star/container/XNameAccess.hpp>
37 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
38 #include <com/sun/star/text/XText.hpp>
39 #include <com/sun/star/text/XTextField.hpp>
40 #include <com/sun/star/text/XTextFieldsSupplier.hpp>
41 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
42 #include <com/sun/star/sheet/XSpreadsheet.hpp>
43 #include <com/sun/star/sheet/XHeaderFooterContent.hpp>
45 #define NUMBER_OF_TESTS 5
47 namespace sc_apitest
{
49 class ScEditFieldObj_Header
: public UnoApiTest
, apitest::XTextContent
, apitest::XPropertySet
52 ScEditFieldObj_Header();
55 virtual void tearDown();
56 virtual uno::Reference
<uno::XInterface
> init();
57 virtual uno::Reference
<text::XTextContent
> getTextContent();
58 virtual uno::Reference
<text::XTextRange
> getTextRange();
59 virtual bool isAttachSupported() { return false; }
61 CPPUNIT_TEST_SUITE(ScEditFieldObj_Header
);
64 CPPUNIT_TEST(testGetPropertySetInfo
);
65 CPPUNIT_TEST(testGetPropertyValue
);
66 CPPUNIT_TEST(testSetPropertyValue
);
69 CPPUNIT_TEST(testGetAnchor
);
70 CPPUNIT_TEST(testAttach
);
71 CPPUNIT_TEST_SUITE_END();
74 static sal_Int32 nTest
;
75 static uno::Reference
<lang::XComponent
> mxComponent
;
76 static uno::Reference
<text::XTextField
> mxField
;
77 static uno::Reference
<text::XText
> mxRightText
;
80 sal_Int32
ScEditFieldObj_Header::nTest
= 0;
81 uno::Reference
<lang::XComponent
> ScEditFieldObj_Header::mxComponent
;
82 uno::Reference
<text::XTextField
> ScEditFieldObj_Header::mxField
;
83 uno::Reference
<text::XText
> ScEditFieldObj_Header::mxRightText
;
85 ScEditFieldObj_Header::ScEditFieldObj_Header() {}
87 void ScEditFieldObj_Header::setUp()
93 void ScEditFieldObj_Header::tearDown()
95 if (nTest
== NUMBER_OF_TESTS
)
97 // Clear these before the component is destroyed. This is important!
100 closeDocument(mxComponent
);
103 UnoApiTest::tearDown();
106 uno::Reference
<uno::XInterface
> ScEditFieldObj_Header::init()
108 // Return a field that's already in the header.
111 if (!mxComponent
.is())
112 // Load an empty document.
113 mxComponent
= loadFromDesktop("private:factory/scalc");
115 uno::Reference
<lang::XMultiServiceFactory
> xSM(mxComponent
, UNO_QUERY_THROW
);
117 // Create a new URL field object, and populate it with name and URL.
118 mxField
.set(xSM
->createInstance("com.sun.star.text.TextField.Time"), UNO_QUERY_THROW
);
120 uno::Reference
<style::XStyleFamiliesSupplier
> xSFS(mxComponent
, UNO_QUERY_THROW
);
121 uno::Reference
<container::XNameAccess
> xStyleFamilies(xSFS
->getStyleFamilies(), UNO_QUERY_THROW
);
122 uno::Reference
<container::XNameAccess
> xPageStyles(xStyleFamilies
->getByName("PageStyles"), UNO_QUERY_THROW
);
123 uno::Reference
<beans::XPropertySet
> xPropSet(xPageStyles
->getByName("Default"), UNO_QUERY_THROW
);
125 uno::Reference
<sheet::XHeaderFooterContent
> xHeaderContent(
126 xPropSet
->getPropertyValue("RightPageHeaderContent"), 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_QUERY_THROW
);
132 uno::Reference
<text::XTextContent
> xContent(mxField
, UNO_QUERY_THROW
);
133 xText
->insertTextContent(xRange
, xContent
, sal_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_QUERY_THROW
);
147 uno::Reference
<text::XTextContent
> xField(
148 xSM
->createInstance("com.sun.star.text.TextField.Date"), 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_QUERY_THROW
);
159 CPPUNIT_TEST_SUITE_REGISTRATION(ScEditFieldObj_Header
);
161 CPPUNIT_PLUGIN_IMPLEMENT();
165 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */