merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / ifc / sheet / _XSheetCellRangeContainer.java
blobc2327c3eb90be70720ace1f846948950b6f3e4d3
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XSheetCellRangeContainer.java,v $
10 * $Revision: 1.4 $
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 ************************************************************************/
31 package ifc.sheet;
33 import lib.MultiMethodTest;
34 import lib.StatusException;
36 import com.sun.star.sheet.XSheetCellRangeContainer;
37 import com.sun.star.table.CellRangeAddress;
39 /**
40 * Testing <code>com.sun.star.sheet.XSheetCellRangeContainer</code>
41 * interface methods :
42 * <ul>
43 * <li><code> addRangeAddress() </code></li>
44 * <li><code> removeRangeAddress() </code></li>
45 * <li><code> addRangeAddresses() </code></li>
46 * <li><code> removeRangeAddresses() </code></li>
47 * </ul> <p>
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];
55 /**
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();
62 rAddr[i].Sheet = i;
63 rAddr[i].StartColumn = i;
64 rAddr[i].StartRow = i;
65 rAddr[i].EndColumn = i + 3;
66 rAddr[i].EndRow = i + 3;
67 try {
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);
77 /**
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) {
99 exist = true;
103 result &= exist ;
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());
118 try {
119 oObj.removeRangeAddress(rAddr[0]);
120 } catch (com.sun.star.container.NoSuchElementException e) {
121 e.printStackTrace(log);
122 result = false;
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) ) {
132 result = false;
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 ) {
168 exist = true;
169 break;
172 result &= exist;
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;
185 int cnt;
187 log.println("Elements before removing: " + oObj.getCount());
188 try {
189 oObj.removeRangeAddresses(oObj.getRangeAddresses());
190 } catch (com.sun.star.container.NoSuchElementException e) {
191 e.printStackTrace(log);
192 result = false;
194 if ( (cnt = oObj.getCount()) == 0) {
195 result = true;
197 log.println("Elements after removing: " + cnt);
198 tRes.tested("removeRangeAddresses()" ,result);
202 * Forces environment recreation.
204 protected void after() {
205 disposeEnvironment();