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>
34 class ScCondFormatMergeTest
: public CalcUnoApiTest
37 ScCondFormatMergeTest();
39 void testCondFormatMerge();
41 CPPUNIT_TEST_SUITE(ScCondFormatMergeTest
);
42 CPPUNIT_TEST(testCondFormatMerge
);
43 CPPUNIT_TEST_SUITE_END();
46 ScCondFormatMergeTest::ScCondFormatMergeTest()
47 : CalcUnoApiTest("sc/qa/extras/testdocuments/")
51 void ScCondFormatMergeTest::testCondFormatMerge()
54 createFileURL("cond_format_merge.ods", aFileURL
);
55 uno::Reference
<lang::XComponent
> mxComponent
= loadFromDesktop(aFileURL
);
57 CPPUNIT_ASSERT_MESSAGE("Component not loaded", mxComponent
.is());
59 // get the first sheet
60 uno::Reference
<sheet::XSpreadsheetDocument
> xDoc(mxComponent
, uno::UNO_QUERY_THROW
);
61 uno::Reference
<container::XIndexAccess
> xIndex(xDoc
->getSheets(), uno::UNO_QUERY_THROW
);
62 uno::Reference
<sheet::XSpreadsheet
> xSheet(xIndex
->getByIndex(0), uno::UNO_QUERY_THROW
);
64 uno::Reference
<beans::XPropertySet
> xProps(xSheet
, uno::UNO_QUERY_THROW
);
65 uno::Any aAny
= xProps
->getPropertyValue("ConditionalFormats");
66 uno::Reference
<sheet::XConditionalFormats
> xCondFormats
;
68 CPPUNIT_ASSERT(aAny
>>= xCondFormats
);
69 CPPUNIT_ASSERT(xCondFormats
.is());
71 CPPUNIT_ASSERT_EQUAL(sal_Int32(5), xCondFormats
->getLength());
73 uno::Sequence
<uno::Reference
<sheet::XConditionalFormat
>> xCondFormatSeq
74 = xCondFormats
->getConditionalFormats();
75 CPPUNIT_ASSERT_EQUAL(sal_Int32(5), xCondFormatSeq
.getLength());
78 for (sal_Int32 i
= 0, n
= xCondFormatSeq
.getLength(); i
< n
; ++i
)
80 CPPUNIT_ASSERT(xCondFormatSeq
[i
].is());
82 uno::Reference
<sheet::XConditionalFormat
> xCondFormat
= xCondFormatSeq
[i
];
83 CPPUNIT_ASSERT(xCondFormat
.is());
85 uno::Reference
<beans::XPropertySet
> xPropSet(xCondFormat
, uno::UNO_QUERY_THROW
);
87 aAny
= xPropSet
->getPropertyValue("Range");
88 uno::Reference
<sheet::XSheetCellRanges
> xCellRanges
;
89 CPPUNIT_ASSERT(aAny
>>= xCellRanges
);
90 CPPUNIT_ASSERT(xCellRanges
.is());
92 uno::Sequence
<table::CellRangeAddress
> aRanges
= xCellRanges
->getRangeAddresses();
93 CPPUNIT_ASSERT_GREATEREQUAL(sal_Int32(1), aRanges
.getLength());
95 table::CellRangeAddress aRange0
= aRanges
[0];
96 CPPUNIT_ASSERT_EQUAL(sal_Int16(0), aRange0
.Sheet
);
97 CPPUNIT_ASSERT_EQUAL(aRange0
.StartColumn
, aRange0
.EndColumn
);
99 table::CellRangeAddress aRange1
;
101 switch (aRange0
.StartColumn
)
104 switch (aRange0
.StartRow
)
106 case 0: // D1:D2,D5::D8
108 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aRange0
.EndRow
);
109 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aRanges
.getLength());
110 aRange1
= aRanges
[1];
111 CPPUNIT_ASSERT_EQUAL(sal_Int16(0), aRange1
.Sheet
);
112 CPPUNIT_ASSERT_EQUAL(aRange1
.StartColumn
, aRange1
.EndColumn
);
113 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), aRange1
.StartColumn
);
114 CPPUNIT_ASSERT_EQUAL(sal_Int32(4), aRange1
.StartRow
);
115 CPPUNIT_ASSERT_EQUAL(sal_Int32(7), aRange1
.EndRow
);
118 CPPUNIT_FAIL("Unexpected range in column D");
122 switch (aRange0
.StartRow
)
126 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aRange0
.EndRow
);
127 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aRanges
.getLength());
131 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aRange0
.EndRow
);
132 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aRanges
.getLength());
136 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), aRange0
.EndRow
);
137 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aRanges
.getLength());
141 CPPUNIT_ASSERT_EQUAL(sal_Int32(4), aRange0
.EndRow
);
142 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aRanges
.getLength());
145 CPPUNIT_FAIL("Unexpected range in column F");
149 CPPUNIT_FAIL("Unexpected range");
153 CPPUNIT_ASSERT_EQUAL(5, nRanges
);
155 closeDocument(mxComponent
);
159 CPPUNIT_TEST_SUITE_REGISTRATION(ScCondFormatMergeTest
);
161 CPPUNIT_PLUGIN_IMPLEMENT();
163 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */