nss: upgrade to release 3.73
[LibreOffice.git] / test / source / sheet / xsheetoutline.cxx
blob9e6844c3234c062b4535020b3d0f1761ee8ecb1e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <test/sheet/xsheetoutline.hxx>
12 #include <com/sun/star/sheet/XSpreadsheet.hpp>
13 #include <com/sun/star/table/CellRangeAddress.hpp>
14 #include <com/sun/star/table/XCellRange.hpp>
16 #include <com/sun/star/sheet/XCellRangeAddressable.hpp>
17 #include <com/sun/star/table/TableOrientation.hpp>
19 #include <com/sun/star/sheet/XSheetCellRanges.hpp>
20 #include <com/sun/star/sheet/XSheetOutline.hpp>
21 #include <com/sun/star/sheet/XCellRangesQuery.hpp>
23 #include <cppunit/TestAssert.h>
24 #include <rtl/ustring.hxx>
26 using namespace css;
27 using namespace css::uno;
29 namespace apitest {
31 constexpr OUStringLiteral colLevel1 = u"OutlineSheet.A1:Z1";
32 constexpr OUStringLiteral colLevel2 = u"OutlineSheet.C1:W1";
33 constexpr OUStringLiteral colLevel3 = u"OutlineSheet.E1:U1";
34 constexpr OUStringLiteral colLevel4 = u"OutlineSheet.G1:S1";
36 constexpr OUStringLiteral rowLevel1 = u"OutlineSheet.A1:A30";
37 constexpr OUStringLiteral rowLevel2 = u"OutlineSheet.A3:A27";
39 static OUString getVisibleAdress(
40 uno::Reference<sheet::XSpreadsheet> const& xSheet,
41 const OUString& aLevelRangeString)
44 uno::Reference<table::XCellRange> aSheetRangeAccess(xSheet, UNO_QUERY_THROW);
45 uno::Reference<table::XCellRange> aLevelRange = aSheetRangeAccess->getCellRangeByName(aLevelRangeString);
47 uno::Reference<sheet::XCellRangesQuery> xCellRangesQuery(aLevelRange,UNO_QUERY_THROW);
48 uno::Reference<sheet::XSheetCellRanges> xRanges = xCellRangesQuery->queryVisibleCells();
49 OUString aResult = xRanges->getRangeAddressesAsString();
51 return aResult;
55 static table::CellRangeAddress getAddressFromRangeString(
56 uno::Reference<sheet::XSpreadsheet> const& xSheet,
57 const OUString& aStringAddress)
60 uno::Reference< table::XCellRange > aSheetRangeAccess(xSheet, UNO_QUERY_THROW);
61 uno::Reference<table::XCellRange> aRange = aSheetRangeAccess->getCellRangeByName(aStringAddress);
63 uno::Reference<sheet::XCellRangeAddressable> xCellRangeAddressable(aRange, UNO_QUERY_THROW);
64 table::CellRangeAddress aLevelRangeAddress = xCellRangeAddressable->getRangeAddress();
66 return aLevelRangeAddress;
70 void XSheetOutline::testHideDetail()
73 uno::Reference< sheet::XSpreadsheet > aSheet(init(), UNO_QUERY_THROW);
74 uno::Reference< sheet::XSheetOutline > aSheetOutline(aSheet, UNO_QUERY_THROW);
76 // Column level 2
77 table::CellRangeAddress aLevelRangeAddress = getAddressFromRangeString(aSheet, colLevel2);
78 aSheetOutline->hideDetail(aLevelRangeAddress);
80 CPPUNIT_ASSERT_EQUAL_MESSAGE("Column level 2 not hidden",
81 getVisibleAdress(aSheet, colLevel2), OUString());
83 // Row Level 2
84 aLevelRangeAddress = getAddressFromRangeString(aSheet, rowLevel2);
85 aSheetOutline->hideDetail(aLevelRangeAddress);
87 CPPUNIT_ASSERT_EQUAL_MESSAGE("Row level 2 not hidden",
88 getVisibleAdress(aSheet, rowLevel2), OUString());
92 void XSheetOutline::testShowDetail()
94 uno::Reference< sheet::XSpreadsheet > aSheet(init(), UNO_QUERY_THROW);
95 uno::Reference< sheet::XSheetOutline > aSheetOutline(aSheet, UNO_QUERY_THROW);
97 aSheetOutline->showDetail(getAddressFromRangeString(aSheet, colLevel1));
98 aSheetOutline->showDetail(getAddressFromRangeString(aSheet, rowLevel1));
100 // Row Level 2
101 table::CellRangeAddress aLevelRangeAddress = getAddressFromRangeString(aSheet, rowLevel2);
102 aSheetOutline->showDetail(aLevelRangeAddress);
104 CPPUNIT_ASSERT_EQUAL_MESSAGE("Row level 2 still hidden",
105 getVisibleAdress(aSheet, rowLevel2), OUString(rowLevel2));
107 // Column Level 2
108 aLevelRangeAddress = getAddressFromRangeString(aSheet, colLevel2);
109 aSheetOutline->showDetail(aLevelRangeAddress);
111 CPPUNIT_ASSERT_EQUAL_MESSAGE("Column level 2 still hidden",
112 getVisibleAdress(aSheet, colLevel2), OUString(colLevel2));
116 void XSheetOutline::testShowLevel()
119 uno::Reference< sheet::XSpreadsheet > aSheet(init(), UNO_QUERY_THROW);
120 uno::Reference< sheet::XSheetOutline > aSheetOutline(aSheet, UNO_QUERY_THROW);
122 // test columns
124 table::CellRangeAddress aLevel1 = getAddressFromRangeString(aSheet, colLevel1);
125 table::CellRangeAddress aLevel2 = getAddressFromRangeString(aSheet, colLevel2);
126 table::CellRangeAddress aLevel3 = getAddressFromRangeString(aSheet, colLevel3);
127 table::CellRangeAddress aLevel4 = getAddressFromRangeString(aSheet, colLevel4);
129 aSheetOutline->showDetail(getAddressFromRangeString(aSheet, colLevel1));
130 aSheetOutline->showDetail(getAddressFromRangeString(aSheet, colLevel2));
131 aSheetOutline->showDetail(getAddressFromRangeString(aSheet, rowLevel1));
133 aSheetOutline->hideDetail(aLevel1);
134 aSheetOutline->hideDetail(aLevel2);
135 aSheetOutline->hideDetail(aLevel3);
136 aSheetOutline->hideDetail(aLevel4);
138 aSheetOutline->showLevel(2, table::TableOrientation_COLUMNS);
140 std::cout << " verify showLevel col apres" << getVisibleAdress(aSheet, "OutlineSheet.A1:Z30") << std::endl;
142 // verify that level 2 and level 1 are shown --> column 0..3 & column 22..26
143 // level 3 & 4 are hidden --> column 4..19
145 CPPUNIT_ASSERT_EQUAL_MESSAGE("testShowLevel Column", OUString("OutlineSheet.A1:D1"), getVisibleAdress(aSheet, "OutlineSheet.A1:D1"));
146 CPPUNIT_ASSERT_EQUAL_MESSAGE("testShowLevel Column", OUString("OutlineSheet.V1:Z1"), getVisibleAdress(aSheet, "OutlineSheet.V1:Z1"));
147 CPPUNIT_ASSERT_EQUAL_MESSAGE("testShowLevel Column", OUString(), getVisibleAdress(aSheet, colLevel3));
149 /* FIXME !!
151 // test Rows
153 aLevel1 = getAddressFromRangeString(rowLevel1);
154 aLevel2 = getAddressFromRangeString(rowLevel2);
155 aLevel3 = getAddressFromRangeString(rowLevel3);
156 aLevel4 = getAddressFromRangeString(rowLevel4);
158 aSheetOutline->showDetail(getAddressFromRangeString(colLevel1));
159 aSheetOutline->showDetail(getAddressFromRangeString(rowLevel1));
160 aSheetOutline->showDetail(getAddressFromRangeString(rowLevel2));
162 std::cout << " verify showLevel row before" << OUStringToOString(getVisibleAdress("OutlineSheet.A1:Z30"), RTL_TEXTENCODING_UTF8).getStr() << std::endl;
164 aSheetOutline->hideDetail(aLevel1);
165 aSheetOutline->hideDetail(aLevel2);
166 aSheetOutline->hideDetail(aLevel3);
167 aSheetOutline->hideDetail(aLevel4);
169 std::cout << " verify showLevel row just before" << OUStringToOString(getVisibleAdress("OutlineSheet.A1:Z30"), RTL_TEXTENCODING_UTF8).getStr() << std::endl;
171 aSheetOutline->showLevel(2, table::TableOrientation_ROWS);
173 std::cout << " verify showLevel row after" << OUStringToOString(getVisibleAdress("OutlineSheet.A1:Z30"), RTL_TEXTENCODING_UTF8).getStr() << std::endl;
175 // verify rows visible 0..3 & 24..29
176 // verify rows hidden 4..23
178 CPPUNIT_ASSERT_EQUAL_MESSAGE("testShowLevel Row", OUString("OutlineSheet.A1:A4"), getVisibleAdress("OutlineSheet.A1:A4"));
179 CPPUNIT_ASSERT_EQUAL_MESSAGE("testShowLevel Row", OUString("OutlineSheet.A25:A30"), getVisibleAdress("OutlineSheet.A25:A30"));
180 CPPUNIT_ASSERT_EQUAL_MESSAGE("testShowLevel Row", OUString(), getVisibleAdress(rowLevel3));
186 void XSheetOutline::testGroup()
189 uno::Reference< sheet::XSpreadsheet > aSheet(init(), UNO_QUERY_THROW);
190 uno::Reference< sheet::XSheetOutline > aSheetOutline(aSheet, UNO_QUERY_THROW);
192 // Column level 2
193 OUString aNewString = "OutlineSheet.AB1:AG1";
194 table::CellRangeAddress aLevelRangeAddress = getAddressFromRangeString(aSheet, aNewString);
195 aSheetOutline->group(aLevelRangeAddress, table::TableOrientation_COLUMNS);
197 aSheetOutline->hideDetail(aLevelRangeAddress);
199 CPPUNIT_ASSERT_EQUAL_MESSAGE("testGroup Column still visible", getVisibleAdress(aSheet, aNewString), OUString());
201 // Row Level 2
202 aNewString = "OutlineSheet.A50:A60";
203 aLevelRangeAddress = getAddressFromRangeString(aSheet, aNewString);
204 aSheetOutline->group(aLevelRangeAddress, table::TableOrientation_ROWS);
206 aSheetOutline->hideDetail(aLevelRangeAddress);
208 CPPUNIT_ASSERT_EQUAL_MESSAGE("testGroup Row still visible", getVisibleAdress(aSheet, aNewString), OUString());
212 void XSheetOutline::testUngroup()
214 uno::Reference< sheet::XSpreadsheet > aSheet(init(), UNO_QUERY_THROW);
215 uno::Reference< sheet::XSheetOutline > aSheetOutline(aSheet, UNO_QUERY_THROW);
217 // New Column level
218 OUString aNewString = "OutlineSheet.BB1:BG1";
219 table::CellRangeAddress aLevelRangeAddress = getAddressFromRangeString(aSheet, aNewString);
220 aSheetOutline->group(aLevelRangeAddress, table::TableOrientation_COLUMNS);
221 aSheetOutline->hideDetail(aLevelRangeAddress);
223 aSheetOutline->ungroup(aLevelRangeAddress, table::TableOrientation_COLUMNS);
225 aSheetOutline->showDetail(aLevelRangeAddress);
226 // should remain hidden ?
228 CPPUNIT_ASSERT_EQUAL_MESSAGE("testUnGroup Column becomes visible after ungroup", getVisibleAdress(aSheet, aNewString), OUString());
230 // New Row level
231 aNewString = "OutlineSheet.A70:A80";
232 aLevelRangeAddress = getAddressFromRangeString(aSheet, aNewString);
233 aSheetOutline->group(aLevelRangeAddress, table::TableOrientation_ROWS);
234 aSheetOutline->hideDetail(aLevelRangeAddress);
236 aSheetOutline->ungroup(aLevelRangeAddress, table::TableOrientation_ROWS);
238 aSheetOutline->showDetail(aLevelRangeAddress);
239 // should remain hidden ?
241 CPPUNIT_ASSERT_EQUAL_MESSAGE("testUnGroup Row becomes visible after ungroup", getVisibleAdress(aSheet, aNewString), OUString());
245 void XSheetOutline::testClearOutline()
247 uno::Reference< sheet::XSpreadsheet > aSheet(init(), UNO_QUERY_THROW);
248 uno::Reference< sheet::XSheetOutline > aSheetOutline(aSheet, UNO_QUERY_THROW);
250 aSheetOutline->clearOutline();
252 table::CellRangeAddress aLevelRangeAddress = getAddressFromRangeString(aSheet, colLevel1);
253 aSheetOutline->hideDetail(aLevelRangeAddress);
254 aLevelRangeAddress = getAddressFromRangeString(aSheet, rowLevel1);
255 aSheetOutline->hideDetail(aLevelRangeAddress);
257 CPPUNIT_ASSERT_EQUAL_MESSAGE("testClearOutline Columns are hidden after clear", getVisibleAdress(aSheet, colLevel1), OUString(colLevel1));
258 CPPUNIT_ASSERT_EQUAL_MESSAGE("testClearOutline Rows are hidden after clear", getVisibleAdress(aSheet, rowLevel1), OUString(rowLevel1));
264 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */