nss: upgrade to release 3.73
[LibreOffice.git] / sc / qa / extras / sctableconditionalformat.cxx
blobe26664bf5c147a845fc68559be595c41db0ce1d5
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/calc_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 <cppu/unotype.hxx>
37 using namespace css;
38 using namespace css::uno;
39 using namespace com::sun::star;
41 namespace sc_apitest
43 class ScTableConditionalFormat : public CalcUnoApiTest,
44 public apitest::XElementAccess,
45 public apitest::XEnumerationAccess,
46 public apitest::XIndexAccess,
47 public apitest::XNameAccess,
48 public apitest::XServiceInfo,
49 public apitest::XSheetConditionalEntries
51 public:
52 ScTableConditionalFormat();
54 virtual uno::Reference<uno::XInterface> init() override;
55 virtual uno::Sequence<beans::PropertyValue> createCondition(const sal_Int32 nr) override;
56 virtual void setUp() override;
57 virtual void tearDown() 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();
89 private:
90 uno::Reference<lang::XComponent> mxComponent;
93 ScTableConditionalFormat::ScTableConditionalFormat()
94 : CalcUnoApiTest("/sc/qa/extras/testdocuments")
95 , XElementAccess(cppu::UnoType<sheet::XSheetConditionalEntry>::get())
96 , XIndexAccess(2)
97 , XNameAccess("Entry1")
98 , XServiceInfo("ScTableConditionalFormat", "com.sun.star.sheet.TableConditionalFormat")
102 uno::Reference<uno::XInterface> ScTableConditionalFormat::init()
104 uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW);
106 uno::Reference<container::XIndexAccess> xIndex(xDoc->getSheets(), uno::UNO_QUERY_THROW);
107 uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(0), uno::UNO_QUERY_THROW);
109 xSheet->getCellByPosition(5, 5)->setValue(15);
110 xSheet->getCellByPosition(1, 4)->setValue(10);
111 xSheet->getCellByPosition(2, 0)->setValue(-5.15);
113 uno::Reference<beans::XPropertySet> xPropSet(xSheet, uno::UNO_QUERY_THROW);
114 uno::Reference<sheet::XSheetConditionalEntries> xSheetConditionalEntries;
115 xSheetConditionalEntries.set(xPropSet->getPropertyValue(SC_UNONAME_CONDFMT),
116 uno::UNO_QUERY_THROW);
118 xSheetConditionalEntries->addNew(createCondition(5));
119 xSheetConditionalEntries->addNew(createCondition(2));
121 return xSheetConditionalEntries;
124 uno::Sequence<beans::PropertyValue> ScTableConditionalFormat::createCondition(const sal_Int32 nr)
126 uno::Sequence<beans::PropertyValue> aPropValue(5);
127 aPropValue[0].Name = SC_UNONAME_STYLENAME;
128 aPropValue[0].Value <<= OUString("Result2");
129 aPropValue[1].Name = SC_UNONAME_FORMULA1;
130 aPropValue[1].Value <<= "$Sheet1.$B$" + OUString::number(nr);
131 aPropValue[2].Name = SC_UNONAME_FORMULA2;
132 aPropValue[2].Value <<= OUString("");
133 aPropValue[3].Name = SC_UNONAME_OPERATOR;
134 aPropValue[3].Value <<= sheet::ConditionOperator_EQUAL;
135 aPropValue[4].Name = SC_UNONAME_SOURCEPOS;
136 aPropValue[4].Value <<= table::CellAddress(0, 1, 5);
138 return aPropValue;
141 void ScTableConditionalFormat::setUp()
143 CalcUnoApiTest::setUp();
144 // create a calc document
145 mxComponent = loadFromDesktop("private:factory/scalc");
148 void ScTableConditionalFormat::tearDown()
150 closeDocument(mxComponent);
151 CalcUnoApiTest::tearDown();
154 CPPUNIT_TEST_SUITE_REGISTRATION(ScTableConditionalFormat);
156 } // namespace sc_apitest
158 CPPUNIT_PLUGIN_IMPLEMENT();
160 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */