Version 7.5.1.1, tag libreoffice-7.5.1.1
[LibreOffice.git] / sc / qa / extras / sctableconditionalentryobj.cxx
blob8954937934155adc98b7af2c29d4ca94d5f3c4f6
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/sheet/xsheetconditionalentry.hxx>
12 #include <test/sheet/xsheetcondition.hxx>
14 #include <com/sun/star/beans/PropertyValue.hpp>
15 #include <com/sun/star/beans/XPropertySet.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/XSheetConditionalEntry.hpp>
20 #include <com/sun/star/sheet/XSheetConditionalEntries.hpp>
21 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
22 #include <com/sun/star/sheet/XSpreadsheet.hpp>
23 #include <com/sun/star/table/CellAddress.hpp>
25 #include <unonames.hxx>
27 #include <com/sun/star/uno/Reference.hxx>
28 #include <com/sun/star/uno/Sequence.hxx>
29 #include <com/sun/star/uno/XInterface.hpp>
31 #include <comphelper/propertyvalue.hxx>
33 using namespace css;
34 using namespace css::uno;
35 using namespace com::sun::star;
37 namespace sc_apitest
39 class ScTableConditionalEntryObj : public UnoApiTest,
40 public apitest::XSheetConditionalEntry,
41 public apitest::XSheetCondition
43 public:
44 ScTableConditionalEntryObj();
46 virtual uno::Reference<uno::XInterface> init() override;
47 virtual void setUp() override;
49 CPPUNIT_TEST_SUITE(ScTableConditionalEntryObj);
51 // XSheetConditionalEntry
52 CPPUNIT_TEST(testGetSetStyleName);
54 // XSheetCondition
55 CPPUNIT_TEST(testGetSetFormula1);
56 CPPUNIT_TEST(testGetSetFormula2);
57 CPPUNIT_TEST(testGetSetOperator);
58 CPPUNIT_TEST(testGetSetSourcePosition);
60 CPPUNIT_TEST_SUITE_END();
63 ScTableConditionalEntryObj::ScTableConditionalEntryObj()
64 : UnoApiTest("/sc/qa/extras/testdocuments")
68 uno::Reference<uno::XInterface> ScTableConditionalEntryObj::init()
70 uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW);
72 uno::Reference<container::XIndexAccess> xIndex(xDoc->getSheets(), uno::UNO_QUERY_THROW);
73 uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(0), uno::UNO_QUERY_THROW);
75 xSheet->getCellByPosition(5, 5)->setValue(15);
76 xSheet->getCellByPosition(1, 4)->setValue(10);
77 xSheet->getCellByPosition(2, 0)->setValue(-5.15);
79 uno::Reference<beans::XPropertySet> xPropSet(xSheet, uno::UNO_QUERY_THROW);
80 uno::Reference<sheet::XSheetConditionalEntries> xSheetConditionalEntries;
81 xSheetConditionalEntries.set(xPropSet->getPropertyValue(SC_UNONAME_CONDFMT),
82 uno::UNO_QUERY_THROW);
84 uno::Sequence<beans::PropertyValue> aPropValue{
85 comphelper::makePropertyValue(SC_UNONAME_STYLENAME, OUString("Result2")),
86 comphelper::makePropertyValue(SC_UNONAME_FORMULA1, OUString("$Sheet1.$B$5")),
87 comphelper::makePropertyValue(SC_UNONAME_FORMULA2, OUString("")),
88 comphelper::makePropertyValue(SC_UNONAME_OPERATOR, sheet::ConditionOperator_EQUAL),
89 comphelper::makePropertyValue(SC_UNONAME_SOURCEPOS, table::CellAddress(0, 1, 5))
91 xSheetConditionalEntries->addNew(aPropValue);
93 uno::Reference<sheet::XSheetConditionalEntry> xSheetConditionalEntry(
94 xSheetConditionalEntries->getByIndex(0), uno::UNO_QUERY_THROW);
95 return xSheetConditionalEntry;
98 void ScTableConditionalEntryObj::setUp()
100 UnoApiTest::setUp();
101 // create a calc document
102 mxComponent = loadFromDesktop("private:factory/scalc");
105 CPPUNIT_TEST_SUITE_REGISTRATION(ScTableConditionalEntryObj);
107 } // end namespace
109 CPPUNIT_PLUGIN_IMPLEMENT();
111 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */