1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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/sheet/xheaderfootercontent.hxx>
13 #include <com/sun/star/beans/XPropertySet.hpp>
14 #include <com/sun/star/container/XNameAccess.hpp>
15 #include <com/sun/star/lang/XComponent.hpp>
16 #include <com/sun/star/sheet/XHeaderFooterContent.hpp>
17 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
18 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
19 #include <com/sun/star/text/XText.hpp>
20 #include <com/sun/star/uno/Any.hxx>
21 #include <com/sun/star/uno/Reference.hxx>
22 #include <com/sun/star/uno/XInterface.hpp>
25 using namespace css::uno
;
26 using namespace com::sun::star
;
30 class ScHeaderFooterContentObj
: public CalcUnoApiTest
, public apitest::XHeaderFooterContent
33 ScHeaderFooterContentObj();
35 virtual uno::Reference
<uno::XInterface
> init() override
;
36 virtual void setUp() override
;
37 virtual void tearDown() override
;
39 CPPUNIT_TEST_SUITE(ScHeaderFooterContentObj
);
41 // XHeaderFooterContent
42 CPPUNIT_TEST(testGetCenterText
);
43 CPPUNIT_TEST(testGetLeftText
);
44 CPPUNIT_TEST(testGetRightText
);
46 CPPUNIT_TEST_SUITE_END();
49 uno::Reference
<lang::XComponent
> mxComponent
;
52 ScHeaderFooterContentObj::ScHeaderFooterContentObj()
53 : CalcUnoApiTest("/sc/qa/extras/testdocuments")
57 uno::Reference
<uno::XInterface
> ScHeaderFooterContentObj::init()
59 uno::Reference
<sheet::XSpreadsheetDocument
> xDoc(mxComponent
, UNO_QUERY_THROW
);
61 uno::Reference
<style::XStyleFamiliesSupplier
> xStyleFamSupp(xDoc
, UNO_QUERY_THROW
);
62 uno::Reference
<container::XNameAccess
> xStyleFamiliesNames(xStyleFamSupp
->getStyleFamilies(),
64 uno::Reference
<container::XNameAccess
> xPageStyles(xStyleFamiliesNames
->getByName("PageStyles"),
66 uno::Any aDefaultStyle
= xPageStyles
->getByName("Default");
67 uno::Reference
<beans::XPropertySet
> xProp(aDefaultStyle
, UNO_QUERY_THROW
);
69 uno::Any aHFC
= xProp
->getPropertyValue("RightPageHeaderContent");
70 uno::Reference
<sheet::XHeaderFooterContent
> xHFC(aHFC
, UNO_QUERY_THROW
);
72 uno::Reference
<text::XText
> xTxtCenter
= xHFC
->getCenterText();
73 uno::Reference
<text::XText
> xTxtLeft
= xHFC
->getLeftText();
74 uno::Reference
<text::XText
> xTxtRight
= xHFC
->getRightText();
76 xTxtCenter
->setString("CENTER");
77 xTxtLeft
->setString("LEFT");
78 xTxtRight
->setString("RIGHT");
80 xProp
->setPropertyValue("RightPageHeaderContent", aHFC
);
85 void ScHeaderFooterContentObj::setUp()
87 CalcUnoApiTest::setUp();
88 // create a calc document
89 mxComponent
= loadFromDesktop("private:factory/scalc");
92 void ScHeaderFooterContentObj::tearDown()
94 closeDocument(mxComponent
);
95 CalcUnoApiTest::tearDown();
98 CPPUNIT_TEST_SUITE_REGISTRATION(ScHeaderFooterContentObj
);
102 CPPUNIT_PLUGIN_IMPLEMENT();
104 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */