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/unoapi_test.hxx>
18 namespace com::sun::star::lang
25 class ScCondFormatMergeTest
: public UnoApiTest
28 ScCondFormatMergeTest();
30 void testCondFormatMerge();
32 CPPUNIT_TEST_SUITE(ScCondFormatMergeTest
);
33 CPPUNIT_TEST(testCondFormatMerge
);
34 CPPUNIT_TEST_SUITE_END();
37 ScCondFormatMergeTest::ScCondFormatMergeTest()
38 : UnoApiTest("sc/qa/extras/testdocuments/")
42 void ScCondFormatMergeTest::testCondFormatMerge()
44 loadFromFile(u
"cond_format_merge.ods");
46 // get the first sheet
47 uno::Reference
<sheet::XSpreadsheetDocument
> xDoc(mxComponent
, uno::UNO_QUERY_THROW
);
48 uno::Reference
<container::XIndexAccess
> xIndex(xDoc
->getSheets(), uno::UNO_QUERY_THROW
);
49 uno::Reference
<sheet::XSpreadsheet
> xSheet(xIndex
->getByIndex(0), uno::UNO_QUERY_THROW
);
51 uno::Reference
<beans::XPropertySet
> xProps(xSheet
, uno::UNO_QUERY_THROW
);
52 uno::Any aAny
= xProps
->getPropertyValue("ConditionalFormats");
53 uno::Reference
<sheet::XConditionalFormats
> xCondFormats
;
55 CPPUNIT_ASSERT(aAny
>>= xCondFormats
);
56 CPPUNIT_ASSERT(xCondFormats
.is());
58 CPPUNIT_ASSERT_EQUAL(sal_Int32(5), xCondFormats
->getLength());
60 uno::Sequence
<uno::Reference
<sheet::XConditionalFormat
>> xCondFormatSeq
61 = xCondFormats
->getConditionalFormats();
62 CPPUNIT_ASSERT_EQUAL(sal_Int32(5), xCondFormatSeq
.getLength());
65 for (sal_Int32 i
= 0, n
= xCondFormatSeq
.getLength(); i
< n
; ++i
)
67 CPPUNIT_ASSERT(xCondFormatSeq
[i
].is());
69 uno::Reference
<sheet::XConditionalFormat
> xCondFormat
= xCondFormatSeq
[i
];
70 CPPUNIT_ASSERT(xCondFormat
.is());
72 uno::Reference
<beans::XPropertySet
> xPropSet(xCondFormat
, uno::UNO_QUERY_THROW
);
74 aAny
= xPropSet
->getPropertyValue("Range");
75 uno::Reference
<sheet::XSheetCellRanges
> xCellRanges
;
76 CPPUNIT_ASSERT(aAny
>>= xCellRanges
);
77 CPPUNIT_ASSERT(xCellRanges
.is());
79 uno::Sequence
<table::CellRangeAddress
> aRanges
= xCellRanges
->getRangeAddresses();
80 CPPUNIT_ASSERT_GREATEREQUAL(sal_Int32(1), aRanges
.getLength());
82 table::CellRangeAddress aRange0
= aRanges
[0];
83 CPPUNIT_ASSERT_EQUAL(sal_Int16(0), aRange0
.Sheet
);
84 CPPUNIT_ASSERT_EQUAL(aRange0
.StartColumn
, aRange0
.EndColumn
);
86 table::CellRangeAddress aRange1
;
88 switch (aRange0
.StartColumn
)
91 switch (aRange0
.StartRow
)
93 case 0: // D1:D2,D5::D8
95 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aRange0
.EndRow
);
96 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aRanges
.getLength());
98 CPPUNIT_ASSERT_EQUAL(sal_Int16(0), aRange1
.Sheet
);
99 CPPUNIT_ASSERT_EQUAL(aRange1
.StartColumn
, aRange1
.EndColumn
);
100 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), aRange1
.StartColumn
);
101 CPPUNIT_ASSERT_EQUAL(sal_Int32(4), aRange1
.StartRow
);
102 CPPUNIT_ASSERT_EQUAL(sal_Int32(7), aRange1
.EndRow
);
105 CPPUNIT_FAIL("Unexpected range in column D");
109 switch (aRange0
.StartRow
)
113 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aRange0
.EndRow
);
114 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aRanges
.getLength());
118 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aRange0
.EndRow
);
119 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aRanges
.getLength());
123 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), aRange0
.EndRow
);
124 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aRanges
.getLength());
128 CPPUNIT_ASSERT_EQUAL(sal_Int32(4), aRange0
.EndRow
);
129 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aRanges
.getLength());
132 CPPUNIT_FAIL("Unexpected range in column F");
136 CPPUNIT_FAIL("Unexpected range");
140 CPPUNIT_ASSERT_EQUAL(5, nRanges
);
143 CPPUNIT_TEST_SUITE_REGISTRATION(ScCondFormatMergeTest
);
145 CPPUNIT_PLUGIN_IMPLEMENT();
147 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */