1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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/.
10 #include <test/calc_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>
32 using namespace css::uno
;
33 using namespace com::sun::star
;
37 class ScTableConditionalEntryObj
: public CalcUnoApiTest
,
38 public apitest::XSheetConditionalEntry
,
39 public apitest::XSheetCondition
42 ScTableConditionalEntryObj();
44 virtual uno::Reference
<uno::XInterface
> init() override
;
45 virtual void setUp() override
;
46 virtual void tearDown() override
;
48 CPPUNIT_TEST_SUITE(ScTableConditionalEntryObj
);
50 // XSheetConditionalEntry
51 CPPUNIT_TEST(testGetSetStyleName
);
54 CPPUNIT_TEST(testGetSetFormula1
);
55 CPPUNIT_TEST(testGetSetFormula2
);
56 CPPUNIT_TEST(testGetSetOperator
);
57 CPPUNIT_TEST(testGetSetSourcePosition
);
59 CPPUNIT_TEST_SUITE_END();
62 uno::Reference
<lang::XComponent
> mxComponent
;
65 ScTableConditionalEntryObj::ScTableConditionalEntryObj()
66 : CalcUnoApiTest("/sc/qa/extras/testdocuments")
70 uno::Reference
<uno::XInterface
> ScTableConditionalEntryObj::init()
72 uno::Reference
<sheet::XSpreadsheetDocument
> xDoc(mxComponent
, uno::UNO_QUERY_THROW
);
74 uno::Reference
<container::XIndexAccess
> xIndex(xDoc
->getSheets(), uno::UNO_QUERY_THROW
);
75 uno::Reference
<sheet::XSpreadsheet
> xSheet(xIndex
->getByIndex(0), uno::UNO_QUERY_THROW
);
77 xSheet
->getCellByPosition(5, 5)->setValue(15);
78 xSheet
->getCellByPosition(1, 4)->setValue(10);
79 xSheet
->getCellByPosition(2, 0)->setValue(-5.15);
81 uno::Reference
<beans::XPropertySet
> xPropSet(xSheet
, uno::UNO_QUERY_THROW
);
82 uno::Reference
<sheet::XSheetConditionalEntries
> xSheetConditionalEntries
;
83 xSheetConditionalEntries
.set(xPropSet
->getPropertyValue(SC_UNONAME_CONDFMT
),
84 uno::UNO_QUERY_THROW
);
86 uno::Sequence
<beans::PropertyValue
> aPropValue(5);
87 aPropValue
[0].Name
= SC_UNONAME_STYLENAME
;
88 aPropValue
[0].Value
<<= OUString("Result2");
89 aPropValue
[1].Name
= SC_UNONAME_FORMULA1
;
90 aPropValue
[1].Value
<<= OUString("$Sheet1.$B$5");
91 aPropValue
[2].Name
= SC_UNONAME_FORMULA2
;
92 aPropValue
[2].Value
<<= OUString("");
93 aPropValue
[3].Name
= SC_UNONAME_OPERATOR
;
94 aPropValue
[3].Value
<<= sheet::ConditionOperator_EQUAL
;
95 aPropValue
[4].Name
= SC_UNONAME_SOURCEPOS
;
96 aPropValue
[4].Value
<<= table::CellAddress(0, 1, 5);
97 xSheetConditionalEntries
->addNew(aPropValue
);
99 uno::Reference
<sheet::XSheetConditionalEntry
> xSheetConditionalEntry(
100 xSheetConditionalEntries
->getByIndex(0), uno::UNO_QUERY_THROW
);
101 return xSheetConditionalEntry
;
104 void ScTableConditionalEntryObj::setUp()
106 CalcUnoApiTest::setUp();
107 // create a calc document
108 mxComponent
= loadFromDesktop("private:factory/scalc");
111 void ScTableConditionalEntryObj::tearDown()
113 closeDocument(mxComponent
);
114 CalcUnoApiTest::tearDown();
117 CPPUNIT_TEST_SUITE_REGISTRATION(ScTableConditionalEntryObj
);
121 CPPUNIT_PLUGIN_IMPLEMENT();
123 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */