rtl::Static->thread-safe static in unotools
[LibreOffice.git] / sc / qa / unit / cond_format_merge.cxx
blob56b47ac7c1a4f1307c8a874fe2ed78699884b217
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::sun::star::lang
20 class XComponent;
23 using namespace css;
25 class ScCondFormatMergeTest : public CalcUnoApiTest
27 public:
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()
44 OUString aFileURL;
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());
68 int nRanges = 0;
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)
94 case 3:
95 switch (aRange0.StartRow)
97 case 0: // D1:D2,D5::D8
98 nRanges++;
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);
107 break;
108 default:
109 CPPUNIT_FAIL("Unexpected range in column D");
111 break;
112 case 5:
113 switch (aRange0.StartRow)
115 case 0: // F1:F2
116 nRanges++;
117 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aRange0.EndRow);
118 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aRanges.getLength());
119 break;
120 case 2: // F3
121 nRanges++;
122 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aRange0.EndRow);
123 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aRanges.getLength());
124 break;
125 case 3: // F4
126 nRanges++;
127 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), aRange0.EndRow);
128 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aRanges.getLength());
129 break;
130 case 4: // F5
131 nRanges++;
132 CPPUNIT_ASSERT_EQUAL(sal_Int32(4), aRange0.EndRow);
133 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aRanges.getLength());
134 break;
135 default:
136 CPPUNIT_FAIL("Unexpected range in column F");
138 break;
139 default:
140 CPPUNIT_FAIL("Unexpected range");
144 CPPUNIT_ASSERT_EQUAL(5, nRanges);
146 closeDocument(mxComponent);
147 mxComponent.clear();
150 CPPUNIT_TEST_SUITE_REGISTRATION(ScCondFormatMergeTest);
152 CPPUNIT_PLUGIN_IMPLEMENT();
154 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */