Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / sc / qa / unit / cond_format_merge.cxx
blob28da3a88fbb21dc281d618c30d1ea28efc21c842
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 <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
20 namespace sun
22 namespace star
24 namespace lang
26 class XComponent;
32 using namespace css;
34 class ScCondFormatMergeTest : public CalcUnoApiTest
36 public:
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()
53 OUString aFileURL;
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());
77 int nRanges = 0;
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)
103 case 3:
104 switch (aRange0.StartRow)
106 case 0: // D1:D2,D5::D8
107 nRanges++;
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);
116 break;
117 default:
118 CPPUNIT_FAIL("Unexpected range in column D");
120 break;
121 case 5:
122 switch (aRange0.StartRow)
124 case 0: // F1:F2
125 nRanges++;
126 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aRange0.EndRow);
127 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aRanges.getLength());
128 break;
129 case 2: // F3
130 nRanges++;
131 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aRange0.EndRow);
132 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aRanges.getLength());
133 break;
134 case 3: // F4
135 nRanges++;
136 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), aRange0.EndRow);
137 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aRanges.getLength());
138 break;
139 case 4: // F5
140 nRanges++;
141 CPPUNIT_ASSERT_EQUAL(sal_Int32(4), aRange0.EndRow);
142 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aRanges.getLength());
143 break;
144 default:
145 CPPUNIT_FAIL("Unexpected range in column F");
147 break;
148 default:
149 CPPUNIT_FAIL("Unexpected range");
153 CPPUNIT_ASSERT_EQUAL(5, nRanges);
155 closeDocument(mxComponent);
156 mxComponent.clear();
159 CPPUNIT_TEST_SUITE_REGISTRATION(ScCondFormatMergeTest);
161 CPPUNIT_PLUGIN_IMPLEMENT();
163 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */