calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / sc / qa / extras / sctableconditionalformat.cxx
blob7d752c3acb71dfcc3d45654907aaa424baf6b44b
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/container/xindexaccess.hxx>
14 #include <test/container/xnameaccess.hxx>
15 #include <test/lang/xserviceinfo.hxx>
16 #include <test/sheet/xsheetconditionalentries.hxx>
18 #include <com/sun/star/beans/PropertyValue.hpp>
19 #include <com/sun/star/beans/XPropertySet.hpp>
20 #include <com/sun/star/container/XIndexAccess.hpp>
21 #include <com/sun/star/lang/XComponent.hpp>
22 #include <com/sun/star/sheet/ConditionOperator.hpp>
23 #include <com/sun/star/sheet/XSheetConditionalEntry.hpp>
24 #include <com/sun/star/sheet/XSheetConditionalEntries.hpp>
25 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
26 #include <com/sun/star/sheet/XSpreadsheet.hpp>
27 #include <com/sun/star/table/CellAddress.hpp>
28 #include <com/sun/star/uno/XInterface.hpp>
30 #include <unonames.hxx>
32 #include <com/sun/star/uno/Reference.hxx>
33 #include <com/sun/star/uno/Sequence.hxx>
35 #include <comphelper/propertyvalue.hxx>
36 #include <cppu/unotype.hxx>
38 using namespace css;
39 using namespace css::uno;
40 using namespace com::sun::star;
42 namespace sc_apitest
44 class ScTableConditionalFormat : public UnoApiTest,
45 public apitest::XElementAccess,
46 public apitest::XEnumerationAccess,
47 public apitest::XIndexAccess,
48 public apitest::XNameAccess,
49 public apitest::XServiceInfo,
50 public apitest::XSheetConditionalEntries
52 public:
53 ScTableConditionalFormat();
55 virtual uno::Reference<uno::XInterface> init() override;
56 virtual uno::Sequence<beans::PropertyValue> createCondition(const sal_Int32 nr) override;
57 virtual void setUp() override;
59 CPPUNIT_TEST_SUITE(ScTableConditionalFormat);
61 // XElementAccess
62 CPPUNIT_TEST(testGetElementType);
63 CPPUNIT_TEST(testHasElements);
65 // XEnumerationAccess
66 CPPUNIT_TEST(testCreateEnumeration);
68 // XIndexAccess
69 CPPUNIT_TEST(testGetByIndex);
70 CPPUNIT_TEST(testGetCount);
72 // XNameAccess
73 CPPUNIT_TEST(testGetByName);
74 CPPUNIT_TEST(testGetElementNames);
75 CPPUNIT_TEST(testHasByName);
77 // XServiceInfo
78 CPPUNIT_TEST(testGetImplementationName);
79 CPPUNIT_TEST(testGetSupportedServiceNames);
80 CPPUNIT_TEST(testSupportsService);
82 // XSheetConditionalEntries
83 CPPUNIT_TEST(testAddNew);
84 CPPUNIT_TEST(testClear);
85 CPPUNIT_TEST(testRemoveByIndex);
87 CPPUNIT_TEST_SUITE_END();
90 ScTableConditionalFormat::ScTableConditionalFormat()
91 : UnoApiTest("/sc/qa/extras/testdocuments")
92 , XElementAccess(cppu::UnoType<sheet::XSheetConditionalEntry>::get())
93 , XIndexAccess(2)
94 , XNameAccess("Entry1")
95 , XServiceInfo("ScTableConditionalFormat", "com.sun.star.sheet.TableConditionalFormat")
99 uno::Reference<uno::XInterface> ScTableConditionalFormat::init()
101 uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW);
103 uno::Reference<container::XIndexAccess> xIndex(xDoc->getSheets(), uno::UNO_QUERY_THROW);
104 uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(0), uno::UNO_QUERY_THROW);
106 xSheet->getCellByPosition(5, 5)->setValue(15);
107 xSheet->getCellByPosition(1, 4)->setValue(10);
108 xSheet->getCellByPosition(2, 0)->setValue(-5.15);
110 uno::Reference<beans::XPropertySet> xPropSet(xSheet, uno::UNO_QUERY_THROW);
111 uno::Reference<sheet::XSheetConditionalEntries> xSheetConditionalEntries;
112 xSheetConditionalEntries.set(xPropSet->getPropertyValue(SC_UNONAME_CONDFMT),
113 uno::UNO_QUERY_THROW);
115 xSheetConditionalEntries->addNew(createCondition(5));
116 xSheetConditionalEntries->addNew(createCondition(2));
118 return xSheetConditionalEntries;
121 uno::Sequence<beans::PropertyValue> ScTableConditionalFormat::createCondition(const sal_Int32 nr)
123 uno::Sequence<beans::PropertyValue> aPropValue{
124 comphelper::makePropertyValue(SC_UNONAME_STYLENAME, OUString("Result2")),
125 comphelper::makePropertyValue(SC_UNONAME_FORMULA1, "$Sheet1.$B$" + OUString::number(nr)),
126 comphelper::makePropertyValue(SC_UNONAME_FORMULA2, OUString("")),
127 comphelper::makePropertyValue(SC_UNONAME_OPERATOR, sheet::ConditionOperator_EQUAL),
128 comphelper::makePropertyValue(SC_UNONAME_SOURCEPOS, table::CellAddress(0, 1, 5))
131 return aPropValue;
134 void ScTableConditionalFormat::setUp()
136 UnoApiTest::setUp();
137 // create a calc document
138 mxComponent = loadFromDesktop("private:factory/scalc");
141 CPPUNIT_TEST_SUITE_REGISTRATION(ScTableConditionalFormat);
143 } // namespace sc_apitest
145 CPPUNIT_PLUGIN_IMPLEMENT();
147 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */