1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XSheetCellRangeContainer.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 import lib
.MultiMethodTest
;
34 import lib
.StatusException
;
36 import com
.sun
.star
.sheet
.XSheetCellRangeContainer
;
37 import com
.sun
.star
.table
.CellRangeAddress
;
40 * Testing <code>com.sun.star.sheet.XSheetCellRangeContainer</code>
43 * <li><code> addRangeAddress() </code></li>
44 * <li><code> removeRangeAddress() </code></li>
45 * <li><code> addRangeAddresses() </code></li>
46 * <li><code> removeRangeAddresses() </code></li>
48 * Test is <b> NOT </b> multithread compilant. <p>
49 * @see com.sun.star.sheet.XSheetCellRangeContainer
51 public class _XSheetCellRangeContainer
extends MultiMethodTest
{
52 public XSheetCellRangeContainer oObj
= null;
53 public CellRangeAddress
[] rAddr
= new CellRangeAddress
[3];
56 * After method called, the new array of structures 'CellRangeAddress'
57 * is created. Then container is cleared.
59 public void before() {
60 for ( short i
=0; i
<=2; i
++ ) {
61 rAddr
[i
] = new CellRangeAddress();
63 rAddr
[i
].StartColumn
= i
;
64 rAddr
[i
].StartRow
= i
;
65 rAddr
[i
].EndColumn
= i
+ 3;
66 rAddr
[i
].EndRow
= i
+ 3;
68 oObj
.removeRangeAddresses(oObj
.getRangeAddresses());
69 } catch (com
.sun
.star
.uno
.Exception e
) {
70 e
.printStackTrace(log
);
71 throw new StatusException("Error: Cannot remove "+
72 "range addresses." ,e
);
78 * The method called. Then new value is added to Container.
79 * Next we try to obtain back added value and check it. <p>
81 * Has <b> OK </b> status if the range just added presents among
82 * all ranges in the container.
84 public void _addRangeAddress() {
85 boolean result
= true;
87 log
.println("Elements before adding: " + oObj
.getCount());
88 oObj
.addRangeAddress(rAddr
[0], false);
89 log
.println("Elements after adding: " + oObj
.getCount());
90 CellRangeAddress
[] addr
= oObj
.getRangeAddresses();
91 boolean exist
= false ;
92 for (int i
=0; i
<=oObj
.getCount()-1; i
++) {
93 if ( addr
[i
].Sheet
== rAddr
[0].Sheet
&&
94 addr
[i
].StartColumn
== rAddr
[0].StartColumn
&&
95 addr
[i
].StartRow
== rAddr
[0].StartRow
&&
96 addr
[i
].EndColumn
== rAddr
[0].EndColumn
&&
97 addr
[i
].EndRow
== rAddr
[0].EndRow
) {
105 tRes
.tested("addRangeAddress()" ,result
);
109 * The method called. Then a value added before is removed.
110 * Next we check Container for existence of removed value. <p>
111 * Has <b> OK </b> status if the range just removed doesn't presents among
112 * all ranges in the container.
114 public void _removeRangeAddress() {
115 boolean result
= true;
117 log
.println("Elements before removing: " + oObj
.getCount());
119 oObj
.removeRangeAddress(rAddr
[0]);
120 } catch (com
.sun
.star
.container
.NoSuchElementException e
) {
121 e
.printStackTrace(log
);
124 log
.println("Elements after removing: " + oObj
.getCount());
125 CellRangeAddress
[] addr
= oObj
.getRangeAddresses();
126 for (int i
=0; i
<=oObj
.getCount()-1; i
++) {
127 if ( (addr
[i
].Sheet
== rAddr
[0].Sheet
) &&
128 (addr
[i
].StartColumn
== rAddr
[0].StartColumn
) &&
129 (addr
[i
].StartRow
== rAddr
[0].StartRow
) &&
130 (addr
[i
].EndColumn
== rAddr
[0].EndColumn
) &&
131 (addr
[i
].EndRow
== rAddr
[0].EndRow
) ) {
135 tRes
.tested("removeRangeAddress()" ,result
);
139 * The method called. Then new values are added to Container.
140 * Next we try to obtain back all added values and check it. <p>
142 * Has <b> OK </b> status if the count of ranges increases by
143 * number of added ranges - 1 (one of ranges already exists in the
144 * container). And if all of ranges added exist in the container.
146 public void _addRangeAddresses() {
147 executeMethod("addRangeAddress()");
149 boolean result
= true;
151 int cntBefore
= oObj
.getCount();
152 log
.println("Elements before adding: " + cntBefore
);
153 oObj
.addRangeAddresses(rAddr
, false);
154 log
.println("Elements after adding: " + oObj
.getCount());
155 CellRangeAddress
[] addr
= oObj
.getRangeAddresses();
157 result
&= cntBefore
+ rAddr
.length
== oObj
.getCount();
159 for (int j
= 0; j
< rAddr
.length
; j
++) {
160 boolean exist
= false ;
161 for (int i
=0; i
< oObj
.getCount(); i
++) {
162 if ( addr
[i
].Sheet
== rAddr
[j
].Sheet
&&
163 addr
[i
].StartColumn
== rAddr
[j
].StartColumn
&&
164 addr
[i
].StartRow
== rAddr
[j
].StartRow
&&
165 addr
[i
].EndColumn
== rAddr
[j
].EndColumn
&&
166 addr
[i
].EndRow
== rAddr
[j
].EndRow
) {
175 tRes
.tested("addRangeAddresses()" ,result
);
179 * All ranges are remover from contaier.
181 * Has <b> OK </b> status if there are no more ranges in the container.
183 public void _removeRangeAddresses() {
184 boolean result
= false;
187 log
.println("Elements before removing: " + oObj
.getCount());
189 oObj
.removeRangeAddresses(oObj
.getRangeAddresses());
190 } catch (com
.sun
.star
.container
.NoSuchElementException e
) {
191 e
.printStackTrace(log
);
194 if ( (cnt
= oObj
.getCount()) == 0) {
197 log
.println("Elements after removing: " + cnt
);
198 tRes
.tested("removeRangeAddresses()" ,result
);
202 * Forces environment recreation.
204 protected void after() {
205 disposeEnvironment();