Line data Source code
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 :
10 : #include <test/sheet/xsheetoutline.hxx>
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/XCellRangesQuery.hpp>
21 :
22 : #include "cppunit/extensions/HelperMacros.h"
23 : #include <rtl/ustring.hxx>
24 :
25 : using namespace css;
26 : using namespace css::uno;
27 :
28 : namespace apitest {
29 :
30 0 : const OUString colLevel1 = "OutlineSheet.A1:Z1";
31 0 : const OUString colLevel2 = "OutlineSheet.C1:W1";
32 0 : const OUString colLevel3 = "OutlineSheet.E1:U1";
33 0 : const OUString colLevel4 = "OutlineSheet.G1:S1";
34 :
35 0 : const OUString rowLevel1 = "OutlineSheet.A1:A30";
36 0 : const OUString rowLevel2 = "OutlineSheet.A3:A27";
37 0 : const OUString rowLevel3 = "OutlineSheet.A5:A24";
38 0 : const OUString rowLevel4 = "OutlineSheet.A7:A21";
39 :
40 0 : uno::Reference< sheet::XSpreadsheet > aSheetGlobal;
41 :
42 0 : OUString getVisibleAdress(const OUString& aLevelRangeString)
43 : {
44 :
45 0 : uno::Reference<table::XCellRange> aSheetRangeAccess(aSheetGlobal, UNO_QUERY_THROW);
46 0 : uno::Reference<table::XCellRange> aLevelRange = aSheetRangeAccess->getCellRangeByName(aLevelRangeString);
47 :
48 0 : uno::Reference<sheet::XCellRangesQuery> xCellRangesQuery(aLevelRange,UNO_QUERY_THROW);
49 0 : uno::Reference<sheet::XSheetCellRanges> xRanges = xCellRangesQuery->queryVisibleCells();
50 0 : OUString aResult = xRanges->getRangeAddressesAsString();
51 :
52 0 : return aResult;
53 :
54 : }
55 :
56 0 : table::CellRangeAddress getAddressFromRangeString(const OUString& aStringAddress)
57 : {
58 :
59 0 : uno::Reference< table::XCellRange > aSheetRangeAccess(aSheetGlobal, UNO_QUERY_THROW);
60 0 : uno::Reference<table::XCellRange> aRange = aSheetRangeAccess->getCellRangeByName(aStringAddress);
61 :
62 0 : uno::Reference<sheet::XCellRangeAddressable> xCellRangeAddressable(aRange, UNO_QUERY_THROW);
63 0 : table::CellRangeAddress aLevelRangeAddress = xCellRangeAddressable->getRangeAddress();
64 :
65 0 : return aLevelRangeAddress;
66 :
67 : }
68 :
69 0 : void XSheetOutline::testHideDetail()
70 : {
71 :
72 0 : uno::Reference< sheet::XSpreadsheet > aSheet(init(), UNO_QUERY_THROW);
73 0 : uno::Reference< sheet::XSheetOutline > aSheetOutline(aSheet, UNO_QUERY_THROW);
74 :
75 0 : aSheetGlobal = aSheet;
76 :
77 : // Column level 2
78 0 : table::CellRangeAddress aLevelRangeAddress = getAddressFromRangeString(colLevel2);
79 0 : aSheetOutline->hideDetail(aLevelRangeAddress);
80 :
81 0 : CPPUNIT_ASSERT_EQUAL_MESSAGE("Column level 2 not hidden", getVisibleAdress(colLevel2), OUString(""));
82 :
83 : // Row Level 2
84 0 : aLevelRangeAddress = getAddressFromRangeString(rowLevel2);
85 0 : aSheetOutline->hideDetail(aLevelRangeAddress);
86 :
87 0 : CPPUNIT_ASSERT_EQUAL_MESSAGE("Row level 2 not hidden", getVisibleAdress(rowLevel2), OUString(""));
88 :
89 0 : }
90 :
91 0 : void XSheetOutline::testShowDetail()
92 : {
93 0 : uno::Reference< sheet::XSpreadsheet > aSheet(init(), UNO_QUERY_THROW);
94 0 : uno::Reference< sheet::XSheetOutline > aSheetOutline(aSheet, UNO_QUERY_THROW);
95 :
96 0 : aSheetGlobal = aSheet;
97 0 : aSheetOutline->showDetail(getAddressFromRangeString(colLevel1));
98 0 : aSheetOutline->showDetail(getAddressFromRangeString(rowLevel1));
99 :
100 : // Row Level 2
101 0 : table::CellRangeAddress aLevelRangeAddress = getAddressFromRangeString(rowLevel2);
102 0 : aSheetOutline->showDetail(aLevelRangeAddress);
103 :
104 0 : CPPUNIT_ASSERT_EQUAL_MESSAGE("Row level 2 still hidden", getVisibleAdress(rowLevel2), rowLevel2);
105 :
106 : // Column Level 2
107 0 : aLevelRangeAddress = getAddressFromRangeString(colLevel2);
108 0 : aSheetOutline->showDetail(aLevelRangeAddress);
109 :
110 0 : CPPUNIT_ASSERT_EQUAL_MESSAGE("Column level 2 still hidden", getVisibleAdress(colLevel2), colLevel2);
111 :
112 0 : }
113 :
114 0 : void XSheetOutline::testShowLevel()
115 : {
116 :
117 0 : uno::Reference< sheet::XSpreadsheet > aSheet(init(), UNO_QUERY_THROW);
118 0 : uno::Reference< sheet::XSheetOutline > aSheetOutline(aSheet, UNO_QUERY_THROW);
119 :
120 0 : aSheetGlobal = aSheet;
121 :
122 0 : table::CellRangeAddress aLevelRangeAddress;
123 :
124 : // test columns
125 :
126 0 : table::CellRangeAddress aLevel1 = getAddressFromRangeString(colLevel1);
127 0 : table::CellRangeAddress aLevel2 = getAddressFromRangeString(colLevel2);
128 0 : table::CellRangeAddress aLevel3 = getAddressFromRangeString(colLevel3);
129 0 : table::CellRangeAddress aLevel4 = getAddressFromRangeString(colLevel4);
130 :
131 0 : aSheetOutline->showDetail(getAddressFromRangeString(colLevel1));
132 0 : aSheetOutline->showDetail(getAddressFromRangeString(colLevel2));
133 0 : aSheetOutline->showDetail(getAddressFromRangeString(rowLevel1));
134 :
135 0 : aSheetOutline->hideDetail(aLevel1);
136 0 : aSheetOutline->hideDetail(aLevel2);
137 0 : aSheetOutline->hideDetail(aLevel3);
138 0 : aSheetOutline->hideDetail(aLevel4);
139 :
140 0 : aSheetOutline->showLevel(2, table::TableOrientation_COLUMNS);
141 :
142 0 : std::cout << " verifiy showLevel col apres" << OUStringToOString(getVisibleAdress("OutlineSheet.A1:Z30"), RTL_TEXTENCODING_UTF8).getStr() << std::endl;
143 :
144 : // verify that level 2 and level 1 are shown --> column 0..3 & column 22..26
145 : // level 3 & 4 are hidden --> column 4..19
146 :
147 0 : CPPUNIT_ASSERT_EQUAL_MESSAGE("testShowLevel Column", OUString("OutlineSheet.A1:D1"), getVisibleAdress("OutlineSheet.A1:D1"));
148 0 : CPPUNIT_ASSERT_EQUAL_MESSAGE("testShowLevel Column", OUString("OutlineSheet.V1:Z1"), getVisibleAdress("OutlineSheet.V1:Z1"));
149 0 : CPPUNIT_ASSERT_EQUAL_MESSAGE("testShowLevel Column", OUString(""), getVisibleAdress(colLevel3));
150 :
151 : /* FIXME !!
152 :
153 : // test Rows
154 :
155 : aLevel1 = getAddressFromRangeString(rowLevel1);
156 : aLevel2 = getAddressFromRangeString(rowLevel2);
157 : aLevel3 = getAddressFromRangeString(rowLevel3);
158 : aLevel4 = getAddressFromRangeString(rowLevel4);
159 :
160 : aSheetOutline->showDetail(getAddressFromRangeString(colLevel1));
161 : aSheetOutline->showDetail(getAddressFromRangeString(rowLevel1));
162 : aSheetOutline->showDetail(getAddressFromRangeString(rowLevel2));
163 :
164 : std::cout << " verifiy showLevel row avant" << OUStringToOString(getVisibleAdress("OutlineSheet.A1:Z30"), RTL_TEXTENCODING_UTF8).getStr() << std::endl;
165 :
166 : aSheetOutline->hideDetail(aLevel1);
167 : aSheetOutline->hideDetail(aLevel2);
168 : aSheetOutline->hideDetail(aLevel3);
169 : aSheetOutline->hideDetail(aLevel4);
170 :
171 : std::cout << " verifiy showLevel row juste avant" << OUStringToOString(getVisibleAdress("OutlineSheet.A1:Z30"), RTL_TEXTENCODING_UTF8).getStr() << std::endl;
172 :
173 : aSheetOutline->showLevel(2, table::TableOrientation_ROWS);
174 :
175 : std::cout << " verifiy showLevel row apres" << OUStringToOString(getVisibleAdress("OutlineSheet.A1:Z30"), RTL_TEXTENCODING_UTF8).getStr() << std::endl;
176 :
177 : // verify rows visible 0..3 & 24..29
178 : // verfiy rows hidden 4..23
179 :
180 : CPPUNIT_ASSERT_EQUAL_MESSAGE("testShowLevel Row", OUString("OutlineSheet.A1:A4"), getVisibleAdress("OutlineSheet.A1:A4"));
181 : CPPUNIT_ASSERT_EQUAL_MESSAGE("testShowLevel Row", OUString("OutlineSheet.A25:A30"), getVisibleAdress("OutlineSheet.A25:A30"));
182 : CPPUNIT_ASSERT_EQUAL_MESSAGE("testShowLevel Row", OUString(""), getVisibleAdress(rowLevel3));
183 :
184 : */
185 :
186 0 : }
187 :
188 0 : void XSheetOutline::testGroup()
189 : {
190 :
191 0 : uno::Reference< sheet::XSpreadsheet > aSheet(init(), UNO_QUERY_THROW);
192 0 : uno::Reference< sheet::XSheetOutline > aSheetOutline(aSheet, UNO_QUERY_THROW);
193 :
194 0 : aSheetGlobal = aSheet;
195 :
196 : // Column level 2
197 0 : OUString aNewString = "OutlineSheet.AB1:AG1";
198 0 : table::CellRangeAddress aLevelRangeAddress = getAddressFromRangeString(aNewString);
199 0 : aSheetOutline->group(aLevelRangeAddress, table::TableOrientation_COLUMNS);
200 :
201 0 : aSheetOutline->hideDetail(aLevelRangeAddress);
202 :
203 0 : CPPUNIT_ASSERT_EQUAL_MESSAGE("testGroup Column still visible", getVisibleAdress(aNewString), OUString(""));
204 :
205 : // Row Level 2
206 0 : aNewString = "OutlineSheet.A50:A60";
207 0 : aLevelRangeAddress = getAddressFromRangeString(aNewString);
208 0 : aSheetOutline->group(aLevelRangeAddress, table::TableOrientation_ROWS);
209 :
210 0 : aSheetOutline->hideDetail(aLevelRangeAddress);
211 :
212 0 : CPPUNIT_ASSERT_EQUAL_MESSAGE("testGroup Row still visible", getVisibleAdress(aNewString), OUString(""));
213 :
214 0 : }
215 :
216 0 : void XSheetOutline::testUngroup()
217 : {
218 0 : uno::Reference< sheet::XSpreadsheet > aSheet(init(), UNO_QUERY_THROW);
219 0 : uno::Reference< sheet::XSheetOutline > aSheetOutline(aSheet, UNO_QUERY_THROW);
220 :
221 0 : aSheetGlobal = aSheet;
222 :
223 : // New Column level
224 0 : OUString aNewString = "OutlineSheet.BB1:BG1";
225 0 : table::CellRangeAddress aLevelRangeAddress = getAddressFromRangeString(aNewString);
226 0 : aSheetOutline->group(aLevelRangeAddress, table::TableOrientation_COLUMNS);
227 0 : aSheetOutline->hideDetail(aLevelRangeAddress);
228 :
229 0 : aSheetOutline->ungroup(aLevelRangeAddress, table::TableOrientation_COLUMNS);
230 :
231 0 : aSheetOutline->showDetail(aLevelRangeAddress);
232 : // should remain hidden ?
233 :
234 0 : CPPUNIT_ASSERT_EQUAL_MESSAGE("testUnGroup Column becomes visible after ungroup", getVisibleAdress(aNewString), OUString(""));
235 :
236 : // New Row level
237 0 : aNewString = "OutlineSheet.A70:A80";
238 0 : aLevelRangeAddress = getAddressFromRangeString(aNewString);
239 0 : aSheetOutline->group(aLevelRangeAddress, table::TableOrientation_ROWS);
240 0 : aSheetOutline->hideDetail(aLevelRangeAddress);
241 :
242 0 : aSheetOutline->ungroup(aLevelRangeAddress, table::TableOrientation_ROWS);
243 :
244 0 : aSheetOutline->showDetail(aLevelRangeAddress);
245 : // should remain hidden ?
246 :
247 0 : CPPUNIT_ASSERT_EQUAL_MESSAGE("testUnGroup Row becomes visible after ungroup", getVisibleAdress(aNewString), OUString(""));
248 :
249 0 : }
250 :
251 0 : void XSheetOutline::testAutoOutline()
252 : {
253 0 : }
254 :
255 0 : void XSheetOutline::testClearOutline()
256 : {
257 0 : uno::Reference< sheet::XSpreadsheet > aSheet(init(), UNO_QUERY_THROW);
258 0 : uno::Reference< sheet::XSheetOutline > aSheetOutline(aSheet, UNO_QUERY_THROW);
259 :
260 0 : aSheetGlobal = aSheet;
261 :
262 0 : aSheetOutline->clearOutline();
263 :
264 0 : table::CellRangeAddress aLevelRangeAddress = getAddressFromRangeString(colLevel1);
265 0 : aSheetOutline->hideDetail(aLevelRangeAddress);
266 0 : aLevelRangeAddress = getAddressFromRangeString(rowLevel1);
267 0 : aSheetOutline->hideDetail(aLevelRangeAddress);
268 :
269 0 : CPPUNIT_ASSERT_EQUAL_MESSAGE("testClearOutline Columns are hidden after clear", getVisibleAdress(colLevel1), colLevel1);
270 0 : CPPUNIT_ASSERT_EQUAL_MESSAGE("testClearOutline Rows are hidden after clear", getVisibleAdress(rowLevel1), rowLevel1);
271 :
272 0 : }
273 :
274 0 : }
275 :
276 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|