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 <sal/config.h>
12 #include <com/sun/star/beans/XPropertySet.hpp>
13 #include <com/sun/star/sheet/XConditionalFormats.hpp>
14 #include <com/sun/star/sheet/XSpreadsheet.hpp>
15 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
16 #include <test/calc_unoapi_test.hxx>
18 namespace com::sun::star::lang
25 class ScCondFormatMergeTest
: public CalcUnoApiTest
28 ScCondFormatMergeTest();
30 void testCondFormatMerge();
32 CPPUNIT_TEST_SUITE(ScCondFormatMergeTest
);
33 CPPUNIT_TEST(testCondFormatMerge
);
34 CPPUNIT_TEST_SUITE_END();
37 ScCondFormatMergeTest::ScCondFormatMergeTest()
38 : CalcUnoApiTest("sc/qa/extras/testdocuments/")
42 void ScCondFormatMergeTest::testCondFormatMerge()
45 createFileURL(u
"cond_format_merge.ods", aFileURL
);
46 uno::Reference
<lang::XComponent
> mxComponent
= loadFromDesktop(aFileURL
);
48 CPPUNIT_ASSERT_MESSAGE("Component not loaded", mxComponent
.is());
50 // get the first sheet
51 uno::Reference
<sheet::XSpreadsheetDocument
> xDoc(mxComponent
, uno::UNO_QUERY_THROW
);
52 uno::Reference
<container::XIndexAccess
> xIndex(xDoc
->getSheets(), uno::UNO_QUERY_THROW
);
53 uno::Reference
<sheet::XSpreadsheet
> xSheet(xIndex
->getByIndex(0), uno::UNO_QUERY_THROW
);
55 uno::Reference
<beans::XPropertySet
> xProps(xSheet
, uno::UNO_QUERY_THROW
);
56 uno::Any aAny
= xProps
->getPropertyValue("ConditionalFormats");
57 uno::Reference
<sheet::XConditionalFormats
> xCondFormats
;
59 CPPUNIT_ASSERT(aAny
>>= xCondFormats
);
60 CPPUNIT_ASSERT(xCondFormats
.is());
62 CPPUNIT_ASSERT_EQUAL(sal_Int32(5), xCondFormats
->getLength());
64 uno::Sequence
<uno::Reference
<sheet::XConditionalFormat
>> xCondFormatSeq
65 = xCondFormats
->getConditionalFormats();
66 CPPUNIT_ASSERT_EQUAL(sal_Int32(5), xCondFormatSeq
.getLength());
69 for (sal_Int32 i
= 0, n
= xCondFormatSeq
.getLength(); i
< n
; ++i
)
71 CPPUNIT_ASSERT(xCondFormatSeq
[i
].is());
73 uno::Reference
<sheet::XConditionalFormat
> xCondFormat
= xCondFormatSeq
[i
];
74 CPPUNIT_ASSERT(xCondFormat
.is());
76 uno::Reference
<beans::XPropertySet
> xPropSet(xCondFormat
, uno::UNO_QUERY_THROW
);
78 aAny
= xPropSet
->getPropertyValue("Range");
79 uno::Reference
<sheet::XSheetCellRanges
> xCellRanges
;
80 CPPUNIT_ASSERT(aAny
>>= xCellRanges
);
81 CPPUNIT_ASSERT(xCellRanges
.is());
83 uno::Sequence
<table::CellRangeAddress
> aRanges
= xCellRanges
->getRangeAddresses();
84 CPPUNIT_ASSERT_GREATEREQUAL(sal_Int32(1), aRanges
.getLength());
86 table::CellRangeAddress aRange0
= aRanges
[0];
87 CPPUNIT_ASSERT_EQUAL(sal_Int16(0), aRange0
.Sheet
);
88 CPPUNIT_ASSERT_EQUAL(aRange0
.StartColumn
, aRange0
.EndColumn
);
90 table::CellRangeAddress aRange1
;
92 switch (aRange0
.StartColumn
)
95 switch (aRange0
.StartRow
)
97 case 0: // D1:D2,D5::D8
99 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aRange0
.EndRow
);
100 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aRanges
.getLength());
101 aRange1
= aRanges
[1];
102 CPPUNIT_ASSERT_EQUAL(sal_Int16(0), aRange1
.Sheet
);
103 CPPUNIT_ASSERT_EQUAL(aRange1
.StartColumn
, aRange1
.EndColumn
);
104 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), aRange1
.StartColumn
);
105 CPPUNIT_ASSERT_EQUAL(sal_Int32(4), aRange1
.StartRow
);
106 CPPUNIT_ASSERT_EQUAL(sal_Int32(7), aRange1
.EndRow
);
109 CPPUNIT_FAIL("Unexpected range in column D");
113 switch (aRange0
.StartRow
)
117 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aRange0
.EndRow
);
118 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aRanges
.getLength());
122 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aRange0
.EndRow
);
123 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aRanges
.getLength());
127 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), aRange0
.EndRow
);
128 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aRanges
.getLength());
132 CPPUNIT_ASSERT_EQUAL(sal_Int32(4), aRange0
.EndRow
);
133 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aRanges
.getLength());
136 CPPUNIT_FAIL("Unexpected range in column F");
140 CPPUNIT_FAIL("Unexpected range");
144 CPPUNIT_ASSERT_EQUAL(5, nRanges
);
146 closeDocument(mxComponent
);
150 CPPUNIT_TEST_SUITE_REGISTRATION(ScCondFormatMergeTest
);
152 CPPUNIT_PLUGIN_IMPLEMENT();
154 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */