calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / sc / qa / extras / scheaderfieldsobj.cxx
blob93b1629587d8b27e1fc3dd203b06125995c668e4
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/XComponent.hpp>
18 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
19 #include <com/sun/star/sheet/XHeaderFooterContent.hpp>
20 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
21 #include <com/sun/star/style/XStyle.hpp>
22 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
23 #include <com/sun/star/text/XText.hpp>
24 #include <com/sun/star/text/XTextContent.hpp>
25 #include <com/sun/star/text/XTextField.hpp>
26 #include <com/sun/star/text/XTextFieldsSupplier.hpp>
27 #include <com/sun/star/uno/XInterface.hpp>
29 #include <com/sun/star/uno/Reference.hxx>
31 using namespace css;
33 namespace sc_apitest
35 class ScHeaderFieldsObj : public UnoApiTest,
36 public apitest::XElementAccess,
37 public apitest::XEnumerationAccess,
38 public apitest::XRefreshable
40 public:
41 ScHeaderFieldsObj();
43 virtual uno::Reference<uno::XInterface> init() override;
44 virtual void setUp() override;
45 virtual void tearDown() override;
47 CPPUNIT_TEST_SUITE(ScHeaderFieldsObj);
49 // XElementAccess
50 CPPUNIT_TEST(testGetElementType);
51 CPPUNIT_TEST(testHasElements);
53 // XEnumerationAccess
54 CPPUNIT_TEST(testCreateEnumeration);
56 // XRefreshable
57 CPPUNIT_TEST(testRefreshListener);
59 CPPUNIT_TEST_SUITE_END();
61 private:
62 // We need a long living reference to css::text::XText to make the
63 // XElementAccess::hasElements() test work as ScHeaderFooterEditSource holds
64 // only (weak) references and they sometimes are gone.
65 static uno::Reference<text::XText> m_xText;
68 uno::Reference<text::XText> ScHeaderFieldsObj::m_xText;
70 ScHeaderFieldsObj::ScHeaderFieldsObj()
71 : UnoApiTest("/sc/qa/extras/testdocuments")
72 , ::apitest::XElementAccess(cppu::UnoType<text::XTextField>::get())
76 uno::Reference<uno::XInterface> ScHeaderFieldsObj::init()
78 uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW);
80 uno::Reference<style::XStyleFamiliesSupplier> xSFS(xDoc, uno::UNO_QUERY_THROW);
81 uno::Reference<container::XNameAccess> xNA(xSFS->getStyleFamilies(), uno::UNO_SET_THROW);
82 uno::Reference<container::XNameAccess> xNA1(xNA->getByName("PageStyles"), uno::UNO_QUERY_THROW);
83 uno::Reference<style::XStyle> xStyle(xNA1->getByName("Default"), uno::UNO_QUERY_THROW);
85 uno::Reference<beans::XPropertySet> xPropertySet(xStyle, uno::UNO_QUERY_THROW);
86 uno::Reference<sheet::XHeaderFooterContent> xHFC(
87 xPropertySet->getPropertyValue("RightPageHeaderContent"), 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(xMSF->createInstance("com.sun.star.text.TextField.Time"),
92 uno::UNO_QUERY_THROW);
93 m_xText->insertTextContent(m_xText->createTextCursor(), xTC, false);
94 xPropertySet->setPropertyValue("RightPageHeaderContent", 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 mxComponent = loadFromDesktop("private:factory/scalc");
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: */