LibreOffice Module test (master) 1
xsheetoutline.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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 */
9
11
12#include <com/sun/star/sheet/XSpreadsheet.hpp>
13#include <com/sun/star/table/CellRangeAddress.hpp>
14#include <com/sun/star/table/XCellRange.hpp>
15
16#include <com/sun/star/sheet/XCellRangeAddressable.hpp>
17#include <com/sun/star/table/TableOrientation.hpp>
18
19#include <com/sun/star/sheet/XSheetCellRanges.hpp>
20#include <com/sun/star/sheet/XSheetOutline.hpp>
21#include <com/sun/star/sheet/XCellRangesQuery.hpp>
22
23#include <cppunit/TestAssert.h>
24#include <rtl/ustring.hxx>
25
26using namespace css;
27using namespace css::uno;
28
29namespace apitest {
30
31constexpr OUStringLiteral colLevel1 = u"OutlineSheet.A1:Z1";
32constexpr OUStringLiteral colLevel2 = u"OutlineSheet.C1:W1";
33constexpr OUStringLiteral colLevel3 = u"OutlineSheet.E1:U1";
34constexpr OUStringLiteral colLevel4 = u"OutlineSheet.G1:S1";
35
36constexpr OUStringLiteral rowLevel1 = u"OutlineSheet.A1:A30";
37constexpr OUStringLiteral rowLevel2 = u"OutlineSheet.A3:A27";
38
39static OUString getVisibleAddress(
40 uno::Reference<sheet::XSpreadsheet> const& xSheet,
41 const OUString& aLevelRangeString)
42{
43
44 uno::Reference<table::XCellRange> aSheetRangeAccess(xSheet, UNO_QUERY_THROW);
45 uno::Reference<table::XCellRange> aLevelRange = aSheetRangeAccess->getCellRangeByName(aLevelRangeString);
46
47 uno::Reference<sheet::XCellRangesQuery> xCellRangesQuery(aLevelRange,UNO_QUERY_THROW);
48 uno::Reference<sheet::XSheetCellRanges> xRanges = xCellRangesQuery->queryVisibleCells();
49 OUString aResult = xRanges->getRangeAddressesAsString();
50
51 return aResult;
52
53}
54
55static table::CellRangeAddress getAddressFromRangeString(
56 uno::Reference<sheet::XSpreadsheet> const& xSheet,
57 const OUString& aStringAddress)
58{
59
60 uno::Reference< table::XCellRange > aSheetRangeAccess(xSheet, UNO_QUERY_THROW);
61 uno::Reference<table::XCellRange> aRange = aSheetRangeAccess->getCellRangeByName(aStringAddress);
62
63 uno::Reference<sheet::XCellRangeAddressable> xCellRangeAddressable(aRange, UNO_QUERY_THROW);
64 table::CellRangeAddress aLevelRangeAddress = xCellRangeAddressable->getRangeAddress();
65
66 return aLevelRangeAddress;
67
68}
69
71{
72
73 uno::Reference< sheet::XSpreadsheet > aSheet(init(), UNO_QUERY_THROW);
74 uno::Reference< sheet::XSheetOutline > aSheetOutline(aSheet, UNO_QUERY_THROW);
75
76 // Column level 2
77 table::CellRangeAddress aLevelRangeAddress = getAddressFromRangeString(aSheet, colLevel2);
78 aSheetOutline->hideDetail(aLevelRangeAddress);
79
80 CPPUNIT_ASSERT_EQUAL_MESSAGE("Column level 2 not hidden",
81 getVisibleAddress(aSheet, colLevel2), OUString());
82
83 // Row Level 2
84 aLevelRangeAddress = getAddressFromRangeString(aSheet, rowLevel2);
85 aSheetOutline->hideDetail(aLevelRangeAddress);
86
87 CPPUNIT_ASSERT_EQUAL_MESSAGE("Row level 2 not hidden",
88 getVisibleAddress(aSheet, rowLevel2), OUString());
89
90}
91
93{
94 uno::Reference< sheet::XSpreadsheet > aSheet(init(), UNO_QUERY_THROW);
95 uno::Reference< sheet::XSheetOutline > aSheetOutline(aSheet, UNO_QUERY_THROW);
96
97 aSheetOutline->showDetail(getAddressFromRangeString(aSheet, colLevel1));
98 aSheetOutline->showDetail(getAddressFromRangeString(aSheet, rowLevel1));
99
100 // Row Level 2
101 table::CellRangeAddress aLevelRangeAddress = getAddressFromRangeString(aSheet, rowLevel2);
102 aSheetOutline->showDetail(aLevelRangeAddress);
103
104 CPPUNIT_ASSERT_EQUAL_MESSAGE("Row level 2 still hidden",
105 getVisibleAddress(aSheet, rowLevel2), OUString(rowLevel2));
106
107 // Column Level 2
108 aLevelRangeAddress = getAddressFromRangeString(aSheet, colLevel2);
109 aSheetOutline->showDetail(aLevelRangeAddress);
110
111 CPPUNIT_ASSERT_EQUAL_MESSAGE("Column level 2 still hidden",
112 getVisibleAddress(aSheet, colLevel2), OUString(colLevel2));
113
114}
115
117{
118
119 uno::Reference< sheet::XSpreadsheet > aSheet(init(), UNO_QUERY_THROW);
120 uno::Reference< sheet::XSheetOutline > aSheetOutline(aSheet, UNO_QUERY_THROW);
121
122 // test columns
123
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);
128
129 aSheetOutline->showDetail(getAddressFromRangeString(aSheet, colLevel1));
130 aSheetOutline->showDetail(getAddressFromRangeString(aSheet, colLevel2));
131 aSheetOutline->showDetail(getAddressFromRangeString(aSheet, rowLevel1));
132
133 aSheetOutline->hideDetail(aLevel1);
134 aSheetOutline->hideDetail(aLevel2);
135 aSheetOutline->hideDetail(aLevel3);
136 aSheetOutline->hideDetail(aLevel4);
137
138 aSheetOutline->showLevel(2, table::TableOrientation_COLUMNS);
139
140 std::cout << " verify showLevel col apres" << getVisibleAddress(aSheet, "OutlineSheet.A1:Z30") << std::endl;
141
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
144
145 CPPUNIT_ASSERT_EQUAL_MESSAGE("testShowLevel Column", OUString("OutlineSheet.A1:D1"), getVisibleAddress(aSheet, "OutlineSheet.A1:D1"));
146 CPPUNIT_ASSERT_EQUAL_MESSAGE("testShowLevel Column", OUString("OutlineSheet.V1:Z1"), getVisibleAddress(aSheet, "OutlineSheet.V1:Z1"));
147 CPPUNIT_ASSERT_EQUAL_MESSAGE("testShowLevel Column", OUString(), getVisibleAddress(aSheet, colLevel3));
148
149/* FIXME !!
150
151 // test Rows
152
153 aLevel1 = getAddressFromRangeString(rowLevel1);
154 aLevel2 = getAddressFromRangeString(rowLevel2);
155 aLevel3 = getAddressFromRangeString(rowLevel3);
156 aLevel4 = getAddressFromRangeString(rowLevel4);
157
158 aSheetOutline->showDetail(getAddressFromRangeString(colLevel1));
159 aSheetOutline->showDetail(getAddressFromRangeString(rowLevel1));
160 aSheetOutline->showDetail(getAddressFromRangeString(rowLevel2));
161
162 std::cout << " verify showLevel row before" << OUStringToOString(getVisibleAddress("OutlineSheet.A1:Z30"), RTL_TEXTENCODING_UTF8).getStr() << std::endl;
163
164 aSheetOutline->hideDetail(aLevel1);
165 aSheetOutline->hideDetail(aLevel2);
166 aSheetOutline->hideDetail(aLevel3);
167 aSheetOutline->hideDetail(aLevel4);
168
169 std::cout << " verify showLevel row just before" << OUStringToOString(getVisibleAddress("OutlineSheet.A1:Z30"), RTL_TEXTENCODING_UTF8).getStr() << std::endl;
170
171 aSheetOutline->showLevel(2, table::TableOrientation_ROWS);
172
173 std::cout << " verify showLevel row after" << OUStringToOString(getVisibleAddress("OutlineSheet.A1:Z30"), RTL_TEXTENCODING_UTF8).getStr() << std::endl;
174
175 // verify rows visible 0..3 & 24..29
176 // verify rows hidden 4..23
177
178 CPPUNIT_ASSERT_EQUAL_MESSAGE("testShowLevel Row", OUString("OutlineSheet.A1:A4"), getVisibleAddress("OutlineSheet.A1:A4"));
179 CPPUNIT_ASSERT_EQUAL_MESSAGE("testShowLevel Row", OUString("OutlineSheet.A25:A30"), getVisibleAddress("OutlineSheet.A25:A30"));
180 CPPUNIT_ASSERT_EQUAL_MESSAGE("testShowLevel Row", OUString(), getVisibleAddress(rowLevel3));
181
182*/
183
184}
185
187{
188
189 uno::Reference< sheet::XSpreadsheet > aSheet(init(), UNO_QUERY_THROW);
190 uno::Reference< sheet::XSheetOutline > aSheetOutline(aSheet, UNO_QUERY_THROW);
191
192 // Column level 2
193 OUString aNewString = "OutlineSheet.AB1:AG1";
194 table::CellRangeAddress aLevelRangeAddress = getAddressFromRangeString(aSheet, aNewString);
195 aSheetOutline->group(aLevelRangeAddress, table::TableOrientation_COLUMNS);
196
197 aSheetOutline->hideDetail(aLevelRangeAddress);
198
199 CPPUNIT_ASSERT_EQUAL_MESSAGE("testGroup Column still visible", getVisibleAddress(aSheet, aNewString), OUString());
200
201 // Row Level 2
202 aNewString = "OutlineSheet.A50:A60";
203 aLevelRangeAddress = getAddressFromRangeString(aSheet, aNewString);
204 aSheetOutline->group(aLevelRangeAddress, table::TableOrientation_ROWS);
205
206 aSheetOutline->hideDetail(aLevelRangeAddress);
207
208 CPPUNIT_ASSERT_EQUAL_MESSAGE("testGroup Row still visible", getVisibleAddress(aSheet, aNewString), OUString());
209
210}
211
213{
214 uno::Reference< sheet::XSpreadsheet > aSheet(init(), UNO_QUERY_THROW);
215 uno::Reference< sheet::XSheetOutline > aSheetOutline(aSheet, UNO_QUERY_THROW);
216
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);
222
223 aSheetOutline->ungroup(aLevelRangeAddress, table::TableOrientation_COLUMNS);
224
225 aSheetOutline->showDetail(aLevelRangeAddress);
226 // should remain hidden ?
227
228 CPPUNIT_ASSERT_EQUAL_MESSAGE("testUnGroup Column becomes visible after ungroup", getVisibleAddress(aSheet, aNewString), OUString());
229
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);
235
236 aSheetOutline->ungroup(aLevelRangeAddress, table::TableOrientation_ROWS);
237
238 aSheetOutline->showDetail(aLevelRangeAddress);
239 // should remain hidden ?
240
241 CPPUNIT_ASSERT_EQUAL_MESSAGE("testUnGroup Row becomes visible after ungroup", getVisibleAddress(aSheet, aNewString), OUString());
242
243}
244
246{
247 uno::Reference< sheet::XSpreadsheet > aSheet(init(), UNO_QUERY_THROW);
248 uno::Reference< sheet::XSheetOutline > aSheetOutline(aSheet, UNO_QUERY_THROW);
249
250 aSheetOutline->clearOutline();
251
252 table::CellRangeAddress aLevelRangeAddress = getAddressFromRangeString(aSheet, colLevel1);
253 aSheetOutline->hideDetail(aLevelRangeAddress);
254 aLevelRangeAddress = getAddressFromRangeString(aSheet, rowLevel1);
255 aSheetOutline->hideDetail(aLevelRangeAddress);
256
257 CPPUNIT_ASSERT_EQUAL_MESSAGE("testClearOutline Columns are hidden after clear", getVisibleAddress(aSheet, colLevel1), OUString(colLevel1));
258 CPPUNIT_ASSERT_EQUAL_MESSAGE("testClearOutline Rows are hidden after clear", getVisibleAddress(aSheet, rowLevel1), OUString(rowLevel1));
259
260}
261
262}
263
264/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual css::uno::Reference< css::uno::XInterface > init()=0
float u
static table::CellRangeAddress getAddressFromRangeString(uno::Reference< sheet::XSpreadsheet > const &xSheet, const OUString &aStringAddress)
static OUString getVisibleAddress(uno::Reference< sheet::XSpreadsheet > const &xSheet, const OUString &aLevelRangeString)
constexpr OUStringLiteral colLevel3
constexpr OUStringLiteral rowLevel1
constexpr OUStringLiteral colLevel4
constexpr OUStringLiteral colLevel2
constexpr OUStringLiteral rowLevel2
constexpr OUStringLiteral colLevel1