xref: /AOO41X/main/qadevOOo/tests/java/ifc/sheet/_XSheetCellRangeContainer.java (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir package ifc.sheet;
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir import lib.MultiMethodTest;
31*cdf0e10cSrcweir import lib.StatusException;
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir import com.sun.star.sheet.XSheetCellRangeContainer;
34*cdf0e10cSrcweir import com.sun.star.table.CellRangeAddress;
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir /**
37*cdf0e10cSrcweir * Testing <code>com.sun.star.sheet.XSheetCellRangeContainer</code>
38*cdf0e10cSrcweir * interface methods :
39*cdf0e10cSrcweir * <ul>
40*cdf0e10cSrcweir *  <li><code> addRangeAddress() </code></li>
41*cdf0e10cSrcweir *  <li><code> removeRangeAddress() </code></li>
42*cdf0e10cSrcweir *  <li><code> addRangeAddresses() </code></li>
43*cdf0e10cSrcweir *  <li><code> removeRangeAddresses() </code></li>
44*cdf0e10cSrcweir * </ul> <p>
45*cdf0e10cSrcweir * Test is <b> NOT </b> multithread compilant. <p>
46*cdf0e10cSrcweir * @see com.sun.star.sheet.XSheetCellRangeContainer
47*cdf0e10cSrcweir */
48*cdf0e10cSrcweir public class _XSheetCellRangeContainer extends MultiMethodTest {
49*cdf0e10cSrcweir     public XSheetCellRangeContainer oObj = null;
50*cdf0e10cSrcweir     public CellRangeAddress[] rAddr = new CellRangeAddress[3];
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir     /**
53*cdf0e10cSrcweir     * After method called, the new array of structures 'CellRangeAddress'
54*cdf0e10cSrcweir     *  is created. Then container is cleared.
55*cdf0e10cSrcweir     */
56*cdf0e10cSrcweir     public void before() {
57*cdf0e10cSrcweir         for ( short i=0; i<=2; i++ ) {
58*cdf0e10cSrcweir             rAddr[i] = new CellRangeAddress();
59*cdf0e10cSrcweir             rAddr[i].Sheet = i;
60*cdf0e10cSrcweir             rAddr[i].StartColumn = i;
61*cdf0e10cSrcweir             rAddr[i].StartRow = i;
62*cdf0e10cSrcweir             rAddr[i].EndColumn = i + 3;
63*cdf0e10cSrcweir             rAddr[i].EndRow = i + 3;
64*cdf0e10cSrcweir             try {
65*cdf0e10cSrcweir                 oObj.removeRangeAddresses(oObj.getRangeAddresses());
66*cdf0e10cSrcweir             } catch (com.sun.star.uno.Exception e) {
67*cdf0e10cSrcweir                 e.printStackTrace(log);
68*cdf0e10cSrcweir                 throw new StatusException("Error: Cannot remove "+
69*cdf0e10cSrcweir                     "range addresses." ,e);
70*cdf0e10cSrcweir             }
71*cdf0e10cSrcweir         }
72*cdf0e10cSrcweir     }
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir     /**
75*cdf0e10cSrcweir     * The method called. Then new value is added to Container.
76*cdf0e10cSrcweir     * Next we try to obtain back added value and check it. <p>
77*cdf0e10cSrcweir     *
78*cdf0e10cSrcweir     * Has <b> OK </b> status if the range just added presents among
79*cdf0e10cSrcweir     * all ranges in the container.
80*cdf0e10cSrcweir     */
81*cdf0e10cSrcweir     public void _addRangeAddress() {
82*cdf0e10cSrcweir         boolean result = true;
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir         log.println("Elements before adding: " + oObj.getCount());
85*cdf0e10cSrcweir         oObj.addRangeAddress(rAddr[0], false);
86*cdf0e10cSrcweir         log.println("Elements after adding: " + oObj.getCount());
87*cdf0e10cSrcweir         CellRangeAddress[] addr = oObj.getRangeAddresses();
88*cdf0e10cSrcweir         boolean exist = false ;
89*cdf0e10cSrcweir         for (int i=0; i<=oObj.getCount()-1; i++) {
90*cdf0e10cSrcweir             if ( addr[i].Sheet == rAddr[0].Sheet &&
91*cdf0e10cSrcweir                  addr[i].StartColumn == rAddr[0].StartColumn &&
92*cdf0e10cSrcweir                  addr[i].StartRow == rAddr[0].StartRow &&
93*cdf0e10cSrcweir                  addr[i].EndColumn == rAddr[0].EndColumn &&
94*cdf0e10cSrcweir                  addr[i].EndRow == rAddr[0].EndRow) {
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir                 exist = true;
97*cdf0e10cSrcweir             }
98*cdf0e10cSrcweir         }
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir         result &= exist ;
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir         tRes.tested("addRangeAddress()" ,result);
103*cdf0e10cSrcweir     }
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir     /**
106*cdf0e10cSrcweir     * The method called. Then a value added before is removed.
107*cdf0e10cSrcweir     * Next we check Container for existence of removed value. <p>
108*cdf0e10cSrcweir     * Has <b> OK </b> status if the range just removed doesn't presents among
109*cdf0e10cSrcweir     * all ranges in the container.
110*cdf0e10cSrcweir     */
111*cdf0e10cSrcweir     public void _removeRangeAddress() {
112*cdf0e10cSrcweir         boolean result = true;
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir         log.println("Elements before removing: " + oObj.getCount());
115*cdf0e10cSrcweir         try {
116*cdf0e10cSrcweir             oObj.removeRangeAddress(rAddr[0]);
117*cdf0e10cSrcweir         } catch (com.sun.star.container.NoSuchElementException e) {
118*cdf0e10cSrcweir             e.printStackTrace(log);
119*cdf0e10cSrcweir             result = false;
120*cdf0e10cSrcweir         }
121*cdf0e10cSrcweir         log.println("Elements after removing: " + oObj.getCount());
122*cdf0e10cSrcweir         CellRangeAddress[] addr = oObj.getRangeAddresses();
123*cdf0e10cSrcweir         for (int i=0; i<=oObj.getCount()-1; i++) {
124*cdf0e10cSrcweir             if ( (addr[i].Sheet == rAddr[0].Sheet) &&
125*cdf0e10cSrcweir                     (addr[i].StartColumn == rAddr[0].StartColumn) &&
126*cdf0e10cSrcweir                     (addr[i].StartRow == rAddr[0].StartRow) &&
127*cdf0e10cSrcweir                     (addr[i].EndColumn == rAddr[0].EndColumn) &&
128*cdf0e10cSrcweir                     (addr[i].EndRow == rAddr[0].EndRow) ) {
129*cdf0e10cSrcweir                 result = false;
130*cdf0e10cSrcweir             }
131*cdf0e10cSrcweir         }
132*cdf0e10cSrcweir         tRes.tested("removeRangeAddress()" ,result);
133*cdf0e10cSrcweir     }
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir     /**
136*cdf0e10cSrcweir      * The method called. Then new values are added to Container.
137*cdf0e10cSrcweir      * Next we try to obtain back all added values and check it. <p>
138*cdf0e10cSrcweir      *
139*cdf0e10cSrcweir      * Has <b> OK </b> status if the count of ranges increases by
140*cdf0e10cSrcweir      * number of added ranges - 1 (one of ranges already exists in the
141*cdf0e10cSrcweir      * container). And if all of ranges added exist in the container.
142*cdf0e10cSrcweir      */
143*cdf0e10cSrcweir     public void _addRangeAddresses() {
144*cdf0e10cSrcweir         executeMethod("addRangeAddress()");
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir         boolean result = true;
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir         int cntBefore = oObj.getCount();
149*cdf0e10cSrcweir         log.println("Elements before adding: " + cntBefore);
150*cdf0e10cSrcweir         oObj.addRangeAddresses(rAddr, false);
151*cdf0e10cSrcweir         log.println("Elements after adding: " + oObj.getCount());
152*cdf0e10cSrcweir         CellRangeAddress[] addr = oObj.getRangeAddresses();
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir         result &= cntBefore + rAddr.length == oObj.getCount();
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir         for (int j = 0; j < rAddr.length; j++) {
157*cdf0e10cSrcweir             boolean exist = false ;
158*cdf0e10cSrcweir             for (int i=0; i < oObj.getCount(); i++) {
159*cdf0e10cSrcweir                 if ( addr[i].Sheet == rAddr[j].Sheet &&
160*cdf0e10cSrcweir                      addr[i].StartColumn == rAddr[j].StartColumn &&
161*cdf0e10cSrcweir                      addr[i].StartRow == rAddr[j].StartRow &&
162*cdf0e10cSrcweir                      addr[i].EndColumn == rAddr[j].EndColumn &&
163*cdf0e10cSrcweir                      addr[i].EndRow == rAddr[j].EndRow ) {
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir                     exist = true;
166*cdf0e10cSrcweir                     break;
167*cdf0e10cSrcweir                 }
168*cdf0e10cSrcweir             }
169*cdf0e10cSrcweir             result &= exist;
170*cdf0e10cSrcweir         }
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir         tRes.tested("addRangeAddresses()" ,result);
173*cdf0e10cSrcweir     }
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir     /**
176*cdf0e10cSrcweir      * All ranges are remover from contaier.
177*cdf0e10cSrcweir      *
178*cdf0e10cSrcweir      * Has <b> OK </b> status if there are no more ranges in the container.
179*cdf0e10cSrcweir      */
180*cdf0e10cSrcweir     public void _removeRangeAddresses() {
181*cdf0e10cSrcweir         boolean result = false;
182*cdf0e10cSrcweir         int cnt;
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir         log.println("Elements before removing: " + oObj.getCount());
185*cdf0e10cSrcweir         try {
186*cdf0e10cSrcweir             oObj.removeRangeAddresses(oObj.getRangeAddresses());
187*cdf0e10cSrcweir         } catch (com.sun.star.container.NoSuchElementException e) {
188*cdf0e10cSrcweir             e.printStackTrace(log);
189*cdf0e10cSrcweir             result = false;
190*cdf0e10cSrcweir         }
191*cdf0e10cSrcweir         if ( (cnt = oObj.getCount()) == 0) {
192*cdf0e10cSrcweir             result = true;
193*cdf0e10cSrcweir         }
194*cdf0e10cSrcweir         log.println("Elements after removing: " + cnt);
195*cdf0e10cSrcweir         tRes.tested("removeRangeAddresses()" ,result);
196*cdf0e10cSrcweir     }
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir     /**
199*cdf0e10cSrcweir     * Forces environment recreation.
200*cdf0e10cSrcweir     */
201*cdf0e10cSrcweir     protected void after() {
202*cdf0e10cSrcweir         disposeEnvironment();
203*cdf0e10cSrcweir     }
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir }
206