1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 package ifc.sheet;
24 
25 import com.sun.star.sheet.XCellRangesQuery;
26 import com.sun.star.sheet.XSheetCellRanges;
27 import lib.MultiMethodTest;
28 
29 import com.sun.star.sheet.XSheetOutline;
30 import com.sun.star.table.CellRangeAddress;
31 import com.sun.star.table.TableOrientation;
32 import com.sun.star.uno.UnoRuntime;
33 import lib.Status;
34 import lib.StatusException;
35 
36 /**
37  *
38  */
39 public class _XSheetOutline extends MultiMethodTest {
40     public XSheetOutline oObj = null;
41     CellRangeAddress address = null;
42     CellRangeAddress subaddress = null;
43 
before()44     public void before() {
45         address = (CellRangeAddress)tEnv.getObjRelation("CellRangeAddress");
46         subaddress = (CellRangeAddress)tEnv.getObjRelation("CellRangeSubAddress");
47         if (address == null)
48             throw new StatusException(Status.failed("Object relation CellRangeAddress not found"));
49         if (subaddress == null)
50             throw new StatusException(Status.failed("Object relation CellRangeSubAddress not found"));
51     }
52 
_autoOutline()53     public void _autoOutline() {
54         executeMethod("ungroup()");
55         boolean result = false;
56         oObj.autoOutline(address);
57         // initially the range is grouped and shown
58         result = isCellShown(subaddress);
59         oObj.hideDetail(address);
60         // here only a part of the address is hidden: subaddress must be that part
61         result &= !isCellShown(subaddress);
62         tRes.tested("autoOutline()", result);
63     }
64 
_clearOutline()65     public void _clearOutline() {
66         executeMethod("autoOutline()");
67         boolean result = false;
68         oObj.clearOutline();
69         result = isCellShown(subaddress);
70         oObj.hideDetail(address);
71         result &= isCellShown(subaddress);
72         tRes.tested("clearOutline()", result);
73     }
74 
_group()75     public void _group() {
76         oObj.group(address, TableOrientation.COLUMNS);
77         oObj.group(address, TableOrientation.ROWS);
78         tRes.tested("group()", true);
79     }
80 
_ungroup()81     public void _ungroup() {
82         executeMethod("showDetail()");
83         oObj.ungroup(address, TableOrientation.COLUMNS);
84         oObj.ungroup(address, TableOrientation.ROWS);
85         oObj.hideDetail(address);
86         tRes.tested("ungroup()", isCellShown(address));
87     }
88 
_hideDetail()89     public void _hideDetail() {
90         requiredMethod("group()");
91         oObj.hideDetail(address);
92         tRes.tested("hideDetail()", !isCellShown(address));
93     }
94 
_showDetail()95     public void _showDetail() {
96         executeMethod("showLevel()");
97         oObj.showDetail(address);
98         tRes.tested("showDetail()", isCellShown(address));
99     }
100 
_showLevel()101     public void _showLevel() {
102         executeMethod("hideDetail()");
103         boolean result = false;
104         oObj.showLevel((short)2, TableOrientation.COLUMNS);
105         oObj.showLevel((short)2, TableOrientation.ROWS);
106         result = isCellShown(address);
107         oObj.showLevel((short)0, TableOrientation.COLUMNS);
108         oObj.showLevel((short)0, TableOrientation.ROWS);
109 
110         result &= !isCellShown(address);
111         tRes.tested("showLevel()", result);
112     }
113 
isCellShown(CellRangeAddress range)114     private boolean isCellShown(CellRangeAddress range) {
115         boolean isNotShown = true;
116         XCellRangesQuery xCellRangesQuery = (XCellRangesQuery)UnoRuntime.queryInterface(XCellRangesQuery.class, oObj);
117         if (xCellRangesQuery != null) {
118             XSheetCellRanges xRanges = xCellRangesQuery.queryVisibleCells();
119             CellRangeAddress[] visibleRanges = xRanges.getRangeAddresses();
120             for (int i=0; i<visibleRanges.length; i++) {
121                 isNotShown &= dotIsOutsideRange(range.StartRow, range.StartColumn, visibleRanges[i]);
122                 isNotShown &= dotIsOutsideRange(range.StartRow, range.EndColumn, visibleRanges[i]);
123                 isNotShown &= dotIsOutsideRange(range.EndRow, range.StartColumn, visibleRanges[i]);
124                 isNotShown &= dotIsOutsideRange(range.EndRow, range.EndColumn, visibleRanges[i]);
125                 log.println(isNotShown?"\tisOutSide":"\tisInside");
126             }
127         }
128         return !isNotShown;
129     }
130 
dotIsOutsideRange(int dotRow, int dotColumn, CellRangeAddress range)131     private boolean dotIsOutsideRange(int dotRow, int dotColumn, CellRangeAddress range) {
132         log.println("Checking dot(" + dotRow + "," + dotColumn + ") against row["
133                     + range.StartRow + ":" + range.EndRow + "]  column["
134                     + range.StartColumn + ":" + range.EndColumn + "]");
135         boolean isInside = true;
136         if (dotRow >= range.StartRow && dotRow <= range.EndRow)
137             if (dotColumn >= range.StartColumn && dotColumn <= range.EndColumn)
138                 isInside = false;
139         return isInside;
140     }
141 }
142