tdf#160621 Variable field dialog size of value field
[LibreOffice.git] / sc / qa / extras / scheaderfieldsobj.cxx
blobafbaf826136ab55aaecd47869427299782eae145
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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/unoapi_test.hxx>
11 #include <test/container/xelementaccess.hxx>
12 #include <test/container/xenumerationaccess.hxx>
13 #include <test/util/xrefreshable.hxx>
15 #include <com/sun/star/beans/XPropertySet.hpp>
16 #include <com/sun/star/container/XNameAccess.hpp>
17 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
18 #include <com/sun/star/sheet/XHeaderFooterContent.hpp>
19 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
20 #include <com/sun/star/style/XStyle.hpp>
21 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
22 #include <com/sun/star/text/XText.hpp>
23 #include <com/sun/star/text/XTextContent.hpp>
24 #include <com/sun/star/text/XTextField.hpp>
25 #include <com/sun/star/text/XTextFieldsSupplier.hpp>
26 #include <com/sun/star/uno/XInterface.hpp>
28 #include <com/sun/star/uno/Reference.hxx>
30 using namespace css;
32 namespace sc_apitest
34 class ScHeaderFieldsObj : public UnoApiTest,
35 public apitest::XElementAccess,
36 public apitest::XEnumerationAccess,
37 public apitest::XRefreshable
39 public:
40 ScHeaderFieldsObj();
42 virtual uno::Reference<uno::XInterface> init() override;
43 virtual void setUp() override;
44 virtual void tearDown() override;
46 CPPUNIT_TEST_SUITE(ScHeaderFieldsObj);
48 // XElementAccess
49 CPPUNIT_TEST(testGetElementType);
50 CPPUNIT_TEST(testHasElements);
52 // XEnumerationAccess
53 CPPUNIT_TEST(testCreateEnumeration);
55 // XRefreshable
56 CPPUNIT_TEST(testRefreshListener);
58 CPPUNIT_TEST_SUITE_END();
60 private:
61 // We need a long living reference to css::text::XText to make the
62 // XElementAccess::hasElements() test work as ScHeaderFooterEditSource holds
63 // only (weak) references and they sometimes are gone.
64 static uno::Reference<text::XText> m_xText;
67 uno::Reference<text::XText> ScHeaderFieldsObj::m_xText;
69 ScHeaderFieldsObj::ScHeaderFieldsObj()
70 : UnoApiTest(u"/sc/qa/extras/testdocuments"_ustr)
71 , ::apitest::XElementAccess(cppu::UnoType<text::XTextField>::get())
75 uno::Reference<uno::XInterface> ScHeaderFieldsObj::init()
77 uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW);
79 uno::Reference<style::XStyleFamiliesSupplier> xSFS(xDoc, uno::UNO_QUERY_THROW);
80 uno::Reference<container::XNameAccess> xNA(xSFS->getStyleFamilies(), uno::UNO_SET_THROW);
81 uno::Reference<container::XNameAccess> xNA1(xNA->getByName(u"PageStyles"_ustr),
82 uno::UNO_QUERY_THROW);
83 uno::Reference<style::XStyle> xStyle(xNA1->getByName(u"Default"_ustr), uno::UNO_QUERY_THROW);
85 uno::Reference<beans::XPropertySet> xPropertySet(xStyle, uno::UNO_QUERY_THROW);
86 uno::Reference<sheet::XHeaderFooterContent> xHFC(
87 xPropertySet->getPropertyValue(u"RightPageHeaderContent"_ustr), uno::UNO_QUERY_THROW);
88 m_xText = xHFC->getLeftText();
90 uno::Reference<lang::XMultiServiceFactory> xMSF(xDoc, uno::UNO_QUERY_THROW);
91 uno::Reference<text::XTextContent> xTC(
92 xMSF->createInstance(u"com.sun.star.text.TextField.Time"_ustr), uno::UNO_QUERY_THROW);
93 m_xText->insertTextContent(m_xText->createTextCursor(), xTC, false);
94 xPropertySet->setPropertyValue(u"RightPageHeaderContent"_ustr, uno::Any(xHFC));
96 uno::Reference<text::XTextFieldsSupplier> xTFS(m_xText, uno::UNO_QUERY_THROW);
97 return xTFS->getTextFields();
100 void ScHeaderFieldsObj::setUp()
102 UnoApiTest::setUp();
103 // create calc document
104 loadFromURL(u"private:factory/scalc"_ustr);
107 void ScHeaderFieldsObj::tearDown()
109 m_xText.clear();
111 UnoApiTest::tearDown();
114 CPPUNIT_TEST_SUITE_REGISTRATION(ScHeaderFieldsObj);
116 } // namespace sc_apitest
118 CPPUNIT_PLUGIN_IMPLEMENT();
120 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */