1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
29 import com
.sun
.star
.sheet
.XCellRangesQuery
;
30 import com
.sun
.star
.sheet
.XSheetCellRanges
;
31 import lib
.MultiMethodTest
;
33 import com
.sun
.star
.sheet
.XSheetOutline
;
34 import com
.sun
.star
.table
.CellRangeAddress
;
35 import com
.sun
.star
.table
.TableOrientation
;
36 import com
.sun
.star
.uno
.UnoRuntime
;
38 import lib
.StatusException
;
43 public class _XSheetOutline
extends MultiMethodTest
{
44 public XSheetOutline oObj
= null;
45 CellRangeAddress address
= null;
46 CellRangeAddress subaddress
= null;
48 public void before() {
49 address
= (CellRangeAddress
)tEnv
.getObjRelation("CellRangeAddress");
50 subaddress
= (CellRangeAddress
)tEnv
.getObjRelation("CellRangeSubAddress");
52 throw new StatusException(Status
.failed("Object relation CellRangeAddress not found"));
53 if (subaddress
== null)
54 throw new StatusException(Status
.failed("Object relation CellRangeSubAddress not found"));
57 public void _autoOutline() {
58 executeMethod("ungroup()");
59 boolean result
= false;
60 oObj
.autoOutline(address
);
61 // initially the range is grouped and shown
62 result
= isCellShown(subaddress
);
63 oObj
.hideDetail(address
);
64 // here only a part of the address is hidden: subaddress must be that part
65 result
&= !isCellShown(subaddress
);
66 tRes
.tested("autoOutline()", result
);
69 public void _clearOutline() {
70 executeMethod("autoOutline()");
71 boolean result
= false;
73 result
= isCellShown(subaddress
);
74 oObj
.hideDetail(address
);
75 result
&= isCellShown(subaddress
);
76 tRes
.tested("clearOutline()", result
);
79 public void _group() {
80 oObj
.group(address
, TableOrientation
.COLUMNS
);
81 oObj
.group(address
, TableOrientation
.ROWS
);
82 tRes
.tested("group()", true);
85 public void _ungroup() {
86 executeMethod("showDetail()");
87 oObj
.ungroup(address
, TableOrientation
.COLUMNS
);
88 oObj
.ungroup(address
, TableOrientation
.ROWS
);
89 oObj
.hideDetail(address
);
90 tRes
.tested("ungroup()", isCellShown(address
));
93 public void _hideDetail() {
94 requiredMethod("group()");
95 oObj
.hideDetail(address
);
96 tRes
.tested("hideDetail()", !isCellShown(address
));
99 public void _showDetail() {
100 executeMethod("showLevel()");
101 oObj
.showDetail(address
);
102 tRes
.tested("showDetail()", isCellShown(address
));
105 public void _showLevel() {
106 executeMethod("hideDetail()");
107 boolean result
= false;
108 oObj
.showLevel((short)2, TableOrientation
.COLUMNS
);
109 oObj
.showLevel((short)2, TableOrientation
.ROWS
);
110 result
= isCellShown(address
);
111 oObj
.showLevel((short)0, TableOrientation
.COLUMNS
);
112 oObj
.showLevel((short)0, TableOrientation
.ROWS
);
114 result
&= !isCellShown(address
);
115 tRes
.tested("showLevel()", result
);
118 private boolean isCellShown(CellRangeAddress range
) {
119 boolean isNotShown
= true;
120 XCellRangesQuery xCellRangesQuery
= (XCellRangesQuery
)UnoRuntime
.queryInterface(XCellRangesQuery
.class, oObj
);
121 if (xCellRangesQuery
!= null) {
122 XSheetCellRanges xRanges
= xCellRangesQuery
.queryVisibleCells();
123 CellRangeAddress
[] visibleRanges
= xRanges
.getRangeAddresses();
124 for (int i
=0; i
<visibleRanges
.length
; i
++) {
125 isNotShown
&= dotIsOutsideRange(range
.StartRow
, range
.StartColumn
, visibleRanges
[i
]);
126 isNotShown
&= dotIsOutsideRange(range
.StartRow
, range
.EndColumn
, visibleRanges
[i
]);
127 isNotShown
&= dotIsOutsideRange(range
.EndRow
, range
.StartColumn
, visibleRanges
[i
]);
128 isNotShown
&= dotIsOutsideRange(range
.EndRow
, range
.EndColumn
, visibleRanges
[i
]);
129 log
.println(isNotShown?
"\tisOutSide":"\tisInside");
135 private boolean dotIsOutsideRange(int dotRow
, int dotColumn
, CellRangeAddress range
) {
136 log
.println("Checking dot(" + dotRow
+ "," + dotColumn
+ ") against row["
137 + range
.StartRow
+ ":" + range
.EndRow
+ "] column["
138 + range
.StartColumn
+ ":" + range
.EndColumn
+ "]");
139 boolean isInside
= true;
140 if (dotRow
>= range
.StartRow
&& dotRow
<= range
.EndRow
)
141 if (dotColumn
>= range
.StartColumn
&& dotColumn
<= range
.EndColumn
)