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 static 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 static 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
);
125 table::CellRangeAddress aLevel1
= getAddressFromRangeString(aSheet
, colLevel1
);
126 table::CellRangeAddress aLevel2
= getAddressFromRangeString(aSheet
, colLevel2
);
127 table::CellRangeAddress aLevel3
= getAddressFromRangeString(aSheet
, colLevel3
);
128 table::CellRangeAddress aLevel4
= getAddressFromRangeString(aSheet
, colLevel4
);
130 aSheetOutline
->showDetail(getAddressFromRangeString(aSheet
, colLevel1
));
131 aSheetOutline
->showDetail(getAddressFromRangeString(aSheet
, colLevel2
));
132 aSheetOutline
->showDetail(getAddressFromRangeString(aSheet
, rowLevel1
));
134 aSheetOutline
->hideDetail(aLevel1
);
135 aSheetOutline
->hideDetail(aLevel2
);
136 aSheetOutline
->hideDetail(aLevel3
);
137 aSheetOutline
->hideDetail(aLevel4
);
139 aSheetOutline
->showLevel(2, table::TableOrientation_COLUMNS
);
141 std::cout
<< " verifiy showLevel col apres" << getVisibleAdress(aSheet
, "OutlineSheet.A1:Z30") << std::endl
;
143 // verify that level 2 and level 1 are shown --> column 0..3 & column 22..26
144 // level 3 & 4 are hidden --> column 4..19
146 CPPUNIT_ASSERT_EQUAL_MESSAGE("testShowLevel Column", OUString("OutlineSheet.A1:D1"), getVisibleAdress(aSheet
, "OutlineSheet.A1:D1"));
147 CPPUNIT_ASSERT_EQUAL_MESSAGE("testShowLevel Column", OUString("OutlineSheet.V1:Z1"), getVisibleAdress(aSheet
, "OutlineSheet.V1:Z1"));
148 CPPUNIT_ASSERT_EQUAL_MESSAGE("testShowLevel Column", OUString(), getVisibleAdress(aSheet
, colLevel3
));
154 aLevel1 = getAddressFromRangeString(rowLevel1);
155 aLevel2 = getAddressFromRangeString(rowLevel2);
156 aLevel3 = getAddressFromRangeString(rowLevel3);
157 aLevel4 = getAddressFromRangeString(rowLevel4);
159 aSheetOutline->showDetail(getAddressFromRangeString(colLevel1));
160 aSheetOutline->showDetail(getAddressFromRangeString(rowLevel1));
161 aSheetOutline->showDetail(getAddressFromRangeString(rowLevel2));
163 std::cout << " verifiy showLevel row avant" << OUStringToOString(getVisibleAdress("OutlineSheet.A1:Z30"), RTL_TEXTENCODING_UTF8).getStr() << std::endl;
165 aSheetOutline->hideDetail(aLevel1);
166 aSheetOutline->hideDetail(aLevel2);
167 aSheetOutline->hideDetail(aLevel3);
168 aSheetOutline->hideDetail(aLevel4);
170 std::cout << " verifiy showLevel row juste avant" << OUStringToOString(getVisibleAdress("OutlineSheet.A1:Z30"), RTL_TEXTENCODING_UTF8).getStr() << std::endl;
172 aSheetOutline->showLevel(2, table::TableOrientation_ROWS);
174 std::cout << " verifiy showLevel row apres" << OUStringToOString(getVisibleAdress("OutlineSheet.A1:Z30"), RTL_TEXTENCODING_UTF8).getStr() << std::endl;
176 // verify rows visible 0..3 & 24..29
177 // verfiy rows hidden 4..23
179 CPPUNIT_ASSERT_EQUAL_MESSAGE("testShowLevel Row", OUString("OutlineSheet.A1:A4"), getVisibleAdress("OutlineSheet.A1:A4"));
180 CPPUNIT_ASSERT_EQUAL_MESSAGE("testShowLevel Row", OUString("OutlineSheet.A25:A30"), getVisibleAdress("OutlineSheet.A25:A30"));
181 CPPUNIT_ASSERT_EQUAL_MESSAGE("testShowLevel Row", OUString(), getVisibleAdress(rowLevel3));
187 void XSheetOutline::testGroup()
190 uno::Reference
< sheet::XSpreadsheet
> aSheet(init(), UNO_QUERY_THROW
);
191 uno::Reference
< sheet::XSheetOutline
> aSheetOutline(aSheet
, UNO_QUERY_THROW
);
194 OUString aNewString
= "OutlineSheet.AB1:AG1";
195 table::CellRangeAddress aLevelRangeAddress
= getAddressFromRangeString(aSheet
, aNewString
);
196 aSheetOutline
->group(aLevelRangeAddress
, table::TableOrientation_COLUMNS
);
198 aSheetOutline
->hideDetail(aLevelRangeAddress
);
200 CPPUNIT_ASSERT_EQUAL_MESSAGE("testGroup Column still visible", getVisibleAdress(aSheet
, aNewString
), OUString());
203 aNewString
= "OutlineSheet.A50:A60";
204 aLevelRangeAddress
= getAddressFromRangeString(aSheet
, aNewString
);
205 aSheetOutline
->group(aLevelRangeAddress
, table::TableOrientation_ROWS
);
207 aSheetOutline
->hideDetail(aLevelRangeAddress
);
209 CPPUNIT_ASSERT_EQUAL_MESSAGE("testGroup Row still visible", getVisibleAdress(aSheet
, aNewString
), OUString());
213 void XSheetOutline::testUngroup()
215 uno::Reference
< sheet::XSpreadsheet
> aSheet(init(), UNO_QUERY_THROW
);
216 uno::Reference
< sheet::XSheetOutline
> aSheetOutline(aSheet
, UNO_QUERY_THROW
);
219 OUString aNewString
= "OutlineSheet.BB1:BG1";
220 table::CellRangeAddress aLevelRangeAddress
= getAddressFromRangeString(aSheet
, aNewString
);
221 aSheetOutline
->group(aLevelRangeAddress
, table::TableOrientation_COLUMNS
);
222 aSheetOutline
->hideDetail(aLevelRangeAddress
);
224 aSheetOutline
->ungroup(aLevelRangeAddress
, table::TableOrientation_COLUMNS
);
226 aSheetOutline
->showDetail(aLevelRangeAddress
);
227 // should remain hidden ?
229 CPPUNIT_ASSERT_EQUAL_MESSAGE("testUnGroup Column becomes visible after ungroup", getVisibleAdress(aSheet
, aNewString
), OUString());
232 aNewString
= "OutlineSheet.A70:A80";
233 aLevelRangeAddress
= getAddressFromRangeString(aSheet
, aNewString
);
234 aSheetOutline
->group(aLevelRangeAddress
, table::TableOrientation_ROWS
);
235 aSheetOutline
->hideDetail(aLevelRangeAddress
);
237 aSheetOutline
->ungroup(aLevelRangeAddress
, table::TableOrientation_ROWS
);
239 aSheetOutline
->showDetail(aLevelRangeAddress
);
240 // should remain hidden ?
242 CPPUNIT_ASSERT_EQUAL_MESSAGE("testUnGroup Row becomes visible after ungroup", getVisibleAdress(aSheet
, aNewString
), OUString());
246 void XSheetOutline::testClearOutline()
248 uno::Reference
< sheet::XSpreadsheet
> aSheet(init(), UNO_QUERY_THROW
);
249 uno::Reference
< sheet::XSheetOutline
> aSheetOutline(aSheet
, UNO_QUERY_THROW
);
251 aSheetOutline
->clearOutline();
253 table::CellRangeAddress aLevelRangeAddress
= getAddressFromRangeString(aSheet
, colLevel1
);
254 aSheetOutline
->hideDetail(aLevelRangeAddress
);
255 aLevelRangeAddress
= getAddressFromRangeString(aSheet
, rowLevel1
);
256 aSheetOutline
->hideDetail(aLevelRangeAddress
);
258 CPPUNIT_ASSERT_EQUAL_MESSAGE("testClearOutline Columns are hidden after clear", getVisibleAdress(aSheet
, colLevel1
), colLevel1
);
259 CPPUNIT_ASSERT_EQUAL_MESSAGE("testClearOutline Rows are hidden after clear", getVisibleAdress(aSheet
, rowLevel1
), rowLevel1
);
265 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */