Version 7.5.1.1, tag libreoffice-7.5.1.1
[LibreOffice.git] / sc / qa / extras / scindexenumeration_tableconditionalentryenumeration.cxx
blobe310b1a4f8b29af52e97ccccdee732db0c7510c9
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/xenumeration.hxx>
13 #include <com/sun/star/beans/PropertyValue.hpp>
14 #include <com/sun/star/beans/XPropertySet.hpp>
15 #include <com/sun/star/container/XEnumerationAccess.hpp>
16 #include <com/sun/star/container/XIndexAccess.hpp>
17 #include <com/sun/star/lang/XComponent.hpp>
18 #include <com/sun/star/sheet/ConditionOperator.hpp>
19 #include <com/sun/star/sheet/XSheetConditionalEntries.hpp>
20 #include <com/sun/star/sheet/XSpreadsheet.hpp>
21 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
22 #include <com/sun/star/sheet/XSpreadsheets.hpp>
23 #include <com/sun/star/table/CellAddress.hpp>
24 #include <com/sun/star/uno/XInterface.hpp>
26 #include <com/sun/star/uno/Any.hxx>
27 #include <com/sun/star/uno/Sequence.hxx>
28 #include <com/sun/star/uno/Reference.hxx>
30 #include <comphelper/propertyvalue.hxx>
32 using namespace css;
33 using namespace css::uno;
35 namespace sc_apitest
37 class ScIndexEnumeration_TableConditionalEntryEnumeration : public UnoApiTest,
38 public apitest::XEnumeration
40 public:
41 ScIndexEnumeration_TableConditionalEntryEnumeration();
43 virtual uno::Reference<uno::XInterface> init() override;
44 virtual void setUp() override;
46 CPPUNIT_TEST_SUITE(ScIndexEnumeration_TableConditionalEntryEnumeration);
48 // XEnumeration
49 CPPUNIT_TEST(testHasMoreElements);
50 CPPUNIT_TEST(testNextElement);
52 CPPUNIT_TEST_SUITE_END();
55 ScIndexEnumeration_TableConditionalEntryEnumeration::
56 ScIndexEnumeration_TableConditionalEntryEnumeration()
57 : UnoApiTest("/sc/qa/extras/testdocuments")
61 uno::Reference<uno::XInterface> ScIndexEnumeration_TableConditionalEntryEnumeration::init()
63 uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW);
64 CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is());
66 uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW);
67 uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW);
68 uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW);
70 xSheet0->getCellByPosition(5, 5)->setValue(15);
71 xSheet0->getCellByPosition(1, 4)->setValue(10);
72 xSheet0->getCellByPosition(2, 0)->setValue(-5.15);
74 uno::Sequence<beans::PropertyValue> aConditions{
75 comphelper::makePropertyValue("StyleName", OUString("Result2")),
76 comphelper::makePropertyValue("Formula1", OUString("$Sheet1.$B$5")),
77 comphelper::makePropertyValue("Formula2", OUString("")),
78 comphelper::makePropertyValue("Operator", sheet::ConditionOperator_EQUAL),
79 comphelper::makePropertyValue("SourcePosition", table::CellAddress(0, 1, 5))
82 uno::Reference<beans::XPropertySet> xPropertySet(xSheet0, uno::UNO_QUERY_THROW);
83 uno::Reference<sheet::XSheetConditionalEntries> xSCE(
84 xPropertySet->getPropertyValue("ConditionalFormat"), uno::UNO_QUERY_THROW);
85 xSCE->addNew(aConditions);
87 uno::Any aProperty;
88 aProperty <<= xSCE;
89 xPropertySet->setPropertyValue("ConditionalFormat", aProperty);
91 uno::Reference<container::XEnumerationAccess> xEA(xSCE, uno::UNO_QUERY_THROW);
93 return xEA->createEnumeration();
96 void ScIndexEnumeration_TableConditionalEntryEnumeration::setUp()
98 UnoApiTest::setUp();
99 mxComponent = loadFromDesktop("private:factory/scalc");
102 CPPUNIT_TEST_SUITE_REGISTRATION(ScIndexEnumeration_TableConditionalEntryEnumeration);
104 } // namespace sc_apitest
106 CPPUNIT_PLUGIN_IMPLEMENT();
108 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */