update emoji autocorrect entries from po-files
[LibreOffice.git] / sc / qa / extras / sceditfieldobj-header.cxx
blobc72befda1dfd35e9a1e95fc7ee6023a85123c1ee
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/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
28 using namespace css;
29 using namespace css::uno;
31 namespace sc_apitest {
33 class ScEditFieldObj_Header : public CalcUnoApiTest, apitest::XTextContent, apitest::XPropertySet
35 public:
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);
47 // XPropertySet
48 CPPUNIT_TEST(testGetPropertySetInfo);
49 CPPUNIT_TEST(testGetPropertyValue);
50 CPPUNIT_TEST(testSetPropertyValue);
52 // XTextContent
53 CPPUNIT_TEST(testGetAnchor);
54 CPPUNIT_TEST(testAttach);
55 CPPUNIT_TEST_SUITE_END();
57 private:
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()
76 ++nTest;
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!
85 mxField.clear();
86 mxRightText.clear();
87 closeDocument(mxComponent);
88 mxComponent.clear();
91 CalcUnoApiTest::tearDown();
94 uno::Reference<uno::XInterface> ScEditFieldObj_Header::init()
96 // Return a field that's already in the header.
97 if (!mxField.is())
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();
128 return mxField;
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);
137 return xField;
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);
144 return xRange;
147 CPPUNIT_TEST_SUITE_REGISTRATION(ScEditFieldObj_Header);
151 CPPUNIT_PLUGIN_IMPLEMENT();
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */