1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
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/XCellRangesQuery.hpp>
22 #include "cppunit/extensions/HelperMacros.h"
23 #include <rtl/ustring.hxx>
26 using namespace css::uno
;
30 const OUString colLevel1
= "OutlineSheet.A1:Z1";
31 const OUString colLevel2
= "OutlineSheet.C1:W1";
32 const OUString colLevel3
= "OutlineSheet.E1:U1";
33 const OUString colLevel4
= "OutlineSheet.G1:S1";
35 const OUString rowLevel1
= "OutlineSheet.A1:A30";
36 const OUString rowLevel2
= "OutlineSheet.A3:A27";
37 const OUString rowLevel3
= "OutlineSheet.A5:A24";
38 const OUString rowLevel4
= "OutlineSheet.A7:A21";
40 OUString
getVisibleAdress(
41 uno::Reference
<sheet::XSpreadsheet
> const& xSheet
,
42 const OUString
& aLevelRangeString
)
45 uno::Reference
<table::XCellRange
> aSheetRangeAccess(xSheet
, UNO_QUERY_THROW
);
46 uno::Reference
<table::XCellRange
> aLevelRange
= aSheetRangeAccess
->getCellRangeByName(aLevelRangeString
);
48 uno::Reference
<sheet::XCellRangesQuery
> xCellRangesQuery(aLevelRange
,UNO_QUERY_THROW
);
49 uno::Reference
<sheet::XSheetCellRanges
> xRanges
= xCellRangesQuery
->queryVisibleCells();
50 OUString aResult
= xRanges
->getRangeAddressesAsString();
56 table::CellRangeAddress
getAddressFromRangeString(
57 uno::Reference
<sheet::XSpreadsheet
> const& xSheet
,
58 const OUString
& aStringAddress
)
61 uno::Reference
< table::XCellRange
> aSheetRangeAccess(xSheet
, UNO_QUERY_THROW
);
62 uno::Reference
<table::XCellRange
> aRange
= aSheetRangeAccess
->getCellRangeByName(aStringAddress
);
64 uno::Reference
<sheet::XCellRangeAddressable
> xCellRangeAddressable(aRange
, UNO_QUERY_THROW
);
65 table::CellRangeAddress aLevelRangeAddress
= xCellRangeAddressable
->getRangeAddress();
67 return aLevelRangeAddress
;
71 void XSheetOutline::testHideDetail()
74 uno::Reference
< sheet::XSpreadsheet
> aSheet(init(), UNO_QUERY_THROW
);
75 uno::Reference
< sheet::XSheetOutline
> aSheetOutline(aSheet
, UNO_QUERY_THROW
);
78 table::CellRangeAddress aLevelRangeAddress
= getAddressFromRangeString(aSheet
, colLevel2
);
79 aSheetOutline
->hideDetail(aLevelRangeAddress
);
81 CPPUNIT_ASSERT_EQUAL_MESSAGE("Column level 2 not hidden",
82 getVisibleAdress(aSheet
, colLevel2
), OUString(""));
85 aLevelRangeAddress
= getAddressFromRangeString(aSheet
, rowLevel2
);
86 aSheetOutline
->hideDetail(aLevelRangeAddress
);
88 CPPUNIT_ASSERT_EQUAL_MESSAGE("Row level 2 not hidden",
89 getVisibleAdress(aSheet
, rowLevel2
), OUString(""));
93 void XSheetOutline::testShowDetail()
95 uno::Reference
< sheet::XSpreadsheet
> aSheet(init(), UNO_QUERY_THROW
);
96 uno::Reference
< sheet::XSheetOutline
> aSheetOutline(aSheet
, UNO_QUERY_THROW
);
98 aSheetOutline
->showDetail(getAddressFromRangeString(aSheet
, colLevel1
));
99 aSheetOutline
->showDetail(getAddressFromRangeString(aSheet
, rowLevel1
));
102 table::CellRangeAddress aLevelRangeAddress
= getAddressFromRangeString(aSheet
, rowLevel2
);
103 aSheetOutline
->showDetail(aLevelRangeAddress
);
105 CPPUNIT_ASSERT_EQUAL_MESSAGE("Row level 2 still hidden",
106 getVisibleAdress(aSheet
, rowLevel2
), rowLevel2
);
109 aLevelRangeAddress
= getAddressFromRangeString(aSheet
, colLevel2
);
110 aSheetOutline
->showDetail(aLevelRangeAddress
);
112 CPPUNIT_ASSERT_EQUAL_MESSAGE("Column level 2 still hidden",
113 getVisibleAdress(aSheet
, colLevel2
), colLevel2
);
117 void XSheetOutline::testShowLevel()
120 uno::Reference
< sheet::XSpreadsheet
> aSheet(init(), UNO_QUERY_THROW
);
121 uno::Reference
< sheet::XSheetOutline
> aSheetOutline(aSheet
, UNO_QUERY_THROW
);
123 table::CellRangeAddress aLevelRangeAddress
;
127 table::CellRangeAddress aLevel1
= getAddressFromRangeString(aSheet
, colLevel1
);
128 table::CellRangeAddress aLevel2
= getAddressFromRangeString(aSheet
, colLevel2
);
129 table::CellRangeAddress aLevel3
= getAddressFromRangeString(aSheet
, colLevel3
);
130 table::CellRangeAddress aLevel4
= getAddressFromRangeString(aSheet
, colLevel4
);
132 aSheetOutline
->showDetail(getAddressFromRangeString(aSheet
, colLevel1
));
133 aSheetOutline
->showDetail(getAddressFromRangeString(aSheet
, colLevel2
));
134 aSheetOutline
->showDetail(getAddressFromRangeString(aSheet
, rowLevel1
));
136 aSheetOutline
->hideDetail(aLevel1
);
137 aSheetOutline
->hideDetail(aLevel2
);
138 aSheetOutline
->hideDetail(aLevel3
);
139 aSheetOutline
->hideDetail(aLevel4
);
141 aSheetOutline
->showLevel(2, table::TableOrientation_COLUMNS
);
143 std::cout
<< " verifiy showLevel col apres" << OUStringToOString(getVisibleAdress(aSheet
, "OutlineSheet.A1:Z30"), RTL_TEXTENCODING_UTF8
).getStr() << std::endl
;
145 // verify that level 2 and level 1 are shown --> column 0..3 & column 22..26
146 // level 3 & 4 are hidden --> column 4..19
148 CPPUNIT_ASSERT_EQUAL_MESSAGE("testShowLevel Column", OUString("OutlineSheet.A1:D1"), getVisibleAdress(aSheet
, "OutlineSheet.A1:D1"));
149 CPPUNIT_ASSERT_EQUAL_MESSAGE("testShowLevel Column", OUString("OutlineSheet.V1:Z1"), getVisibleAdress(aSheet
, "OutlineSheet.V1:Z1"));
150 CPPUNIT_ASSERT_EQUAL_MESSAGE("testShowLevel Column", OUString(""), getVisibleAdress(aSheet
, colLevel3
));
156 aLevel1 = getAddressFromRangeString(rowLevel1);
157 aLevel2 = getAddressFromRangeString(rowLevel2);
158 aLevel3 = getAddressFromRangeString(rowLevel3);
159 aLevel4 = getAddressFromRangeString(rowLevel4);
161 aSheetOutline->showDetail(getAddressFromRangeString(colLevel1));
162 aSheetOutline->showDetail(getAddressFromRangeString(rowLevel1));
163 aSheetOutline->showDetail(getAddressFromRangeString(rowLevel2));
165 std::cout << " verifiy showLevel row avant" << OUStringToOString(getVisibleAdress("OutlineSheet.A1:Z30"), RTL_TEXTENCODING_UTF8).getStr() << std::endl;
167 aSheetOutline->hideDetail(aLevel1);
168 aSheetOutline->hideDetail(aLevel2);
169 aSheetOutline->hideDetail(aLevel3);
170 aSheetOutline->hideDetail(aLevel4);
172 std::cout << " verifiy showLevel row juste avant" << OUStringToOString(getVisibleAdress("OutlineSheet.A1:Z30"), RTL_TEXTENCODING_UTF8).getStr() << std::endl;
174 aSheetOutline->showLevel(2, table::TableOrientation_ROWS);
176 std::cout << " verifiy showLevel row apres" << OUStringToOString(getVisibleAdress("OutlineSheet.A1:Z30"), RTL_TEXTENCODING_UTF8).getStr() << std::endl;
178 // verify rows visible 0..3 & 24..29
179 // verfiy rows hidden 4..23
181 CPPUNIT_ASSERT_EQUAL_MESSAGE("testShowLevel Row", OUString("OutlineSheet.A1:A4"), getVisibleAdress("OutlineSheet.A1:A4"));
182 CPPUNIT_ASSERT_EQUAL_MESSAGE("testShowLevel Row", OUString("OutlineSheet.A25:A30"), getVisibleAdress("OutlineSheet.A25:A30"));
183 CPPUNIT_ASSERT_EQUAL_MESSAGE("testShowLevel Row", OUString(""), getVisibleAdress(rowLevel3));
189 void XSheetOutline::testGroup()
192 uno::Reference
< sheet::XSpreadsheet
> aSheet(init(), UNO_QUERY_THROW
);
193 uno::Reference
< sheet::XSheetOutline
> aSheetOutline(aSheet
, UNO_QUERY_THROW
);
196 OUString aNewString
= "OutlineSheet.AB1:AG1";
197 table::CellRangeAddress aLevelRangeAddress
= getAddressFromRangeString(aSheet
, aNewString
);
198 aSheetOutline
->group(aLevelRangeAddress
, table::TableOrientation_COLUMNS
);
200 aSheetOutline
->hideDetail(aLevelRangeAddress
);
202 CPPUNIT_ASSERT_EQUAL_MESSAGE("testGroup Column still visible", getVisibleAdress(aSheet
, aNewString
), OUString(""));
205 aNewString
= "OutlineSheet.A50:A60";
206 aLevelRangeAddress
= getAddressFromRangeString(aSheet
, aNewString
);
207 aSheetOutline
->group(aLevelRangeAddress
, table::TableOrientation_ROWS
);
209 aSheetOutline
->hideDetail(aLevelRangeAddress
);
211 CPPUNIT_ASSERT_EQUAL_MESSAGE("testGroup Row still visible", getVisibleAdress(aSheet
, aNewString
), OUString(""));
215 void XSheetOutline::testUngroup()
217 uno::Reference
< sheet::XSpreadsheet
> aSheet(init(), UNO_QUERY_THROW
);
218 uno::Reference
< sheet::XSheetOutline
> aSheetOutline(aSheet
, UNO_QUERY_THROW
);
221 OUString aNewString
= "OutlineSheet.BB1:BG1";
222 table::CellRangeAddress aLevelRangeAddress
= getAddressFromRangeString(aSheet
, aNewString
);
223 aSheetOutline
->group(aLevelRangeAddress
, table::TableOrientation_COLUMNS
);
224 aSheetOutline
->hideDetail(aLevelRangeAddress
);
226 aSheetOutline
->ungroup(aLevelRangeAddress
, table::TableOrientation_COLUMNS
);
228 aSheetOutline
->showDetail(aLevelRangeAddress
);
229 // should remain hidden ?
231 CPPUNIT_ASSERT_EQUAL_MESSAGE("testUnGroup Column becomes visible after ungroup", getVisibleAdress(aSheet
, aNewString
), OUString(""));
234 aNewString
= "OutlineSheet.A70:A80";
235 aLevelRangeAddress
= getAddressFromRangeString(aSheet
, aNewString
);
236 aSheetOutline
->group(aLevelRangeAddress
, table::TableOrientation_ROWS
);
237 aSheetOutline
->hideDetail(aLevelRangeAddress
);
239 aSheetOutline
->ungroup(aLevelRangeAddress
, table::TableOrientation_ROWS
);
241 aSheetOutline
->showDetail(aLevelRangeAddress
);
242 // should remain hidden ?
244 CPPUNIT_ASSERT_EQUAL_MESSAGE("testUnGroup Row becomes visible after ungroup", getVisibleAdress(aSheet
, aNewString
), OUString(""));
248 void XSheetOutline::testClearOutline()
250 uno::Reference
< sheet::XSpreadsheet
> aSheet(init(), UNO_QUERY_THROW
);
251 uno::Reference
< sheet::XSheetOutline
> aSheetOutline(aSheet
, UNO_QUERY_THROW
);
253 aSheetOutline
->clearOutline();
255 table::CellRangeAddress aLevelRangeAddress
= getAddressFromRangeString(aSheet
, colLevel1
);
256 aSheetOutline
->hideDetail(aLevelRangeAddress
);
257 aLevelRangeAddress
= getAddressFromRangeString(aSheet
, rowLevel1
);
258 aSheetOutline
->hideDetail(aLevelRangeAddress
);
260 CPPUNIT_ASSERT_EQUAL_MESSAGE("testClearOutline Columns are hidden after clear", getVisibleAdress(aSheet
, colLevel1
), colLevel1
);
261 CPPUNIT_ASSERT_EQUAL_MESSAGE("testClearOutline Rows are hidden after clear", getVisibleAdress(aSheet
, rowLevel1
), rowLevel1
);
267 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */