Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / qadevOOo / tests / java / ifc / sheet / _XSheetCellRangeContainer.java
blob230306b300cd6ab544827cef4fbcf67855660055
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 ************************************************************************/
28 package ifc.sheet;
30 import lib.MultiMethodTest;
31 import lib.StatusException;
33 import com.sun.star.sheet.XSheetCellRangeContainer;
34 import com.sun.star.table.CellRangeAddress;
36 /**
37 * Testing <code>com.sun.star.sheet.XSheetCellRangeContainer</code>
38 * interface methods :
39 * <ul>
40 * <li><code> addRangeAddress() </code></li>
41 * <li><code> removeRangeAddress() </code></li>
42 * <li><code> addRangeAddresses() </code></li>
43 * <li><code> removeRangeAddresses() </code></li>
44 * </ul> <p>
45 * Test is <b> NOT </b> multithread compilant. <p>
46 * @see com.sun.star.sheet.XSheetCellRangeContainer
48 public class _XSheetCellRangeContainer extends MultiMethodTest {
49 public XSheetCellRangeContainer oObj = null;
50 public CellRangeAddress[] rAddr = new CellRangeAddress[3];
52 /**
53 * After method called, the new array of structures 'CellRangeAddress'
54 * is created. Then container is cleared.
56 public void before() {
57 for ( short i=0; i<=2; i++ ) {
58 rAddr[i] = new CellRangeAddress();
59 rAddr[i].Sheet = i;
60 rAddr[i].StartColumn = i;
61 rAddr[i].StartRow = i;
62 rAddr[i].EndColumn = i + 3;
63 rAddr[i].EndRow = i + 3;
64 try {
65 oObj.removeRangeAddresses(oObj.getRangeAddresses());
66 } catch (com.sun.star.uno.Exception e) {
67 e.printStackTrace(log);
68 throw new StatusException("Error: Cannot remove "+
69 "range addresses." ,e);
74 /**
75 * The method called. Then new value is added to Container.
76 * Next we try to obtain back added value and check it. <p>
78 * Has <b> OK </b> status if the range just added presents among
79 * all ranges in the container.
81 public void _addRangeAddress() {
82 boolean result = true;
84 log.println("Elements before adding: " + oObj.getCount());
85 oObj.addRangeAddress(rAddr[0], false);
86 log.println("Elements after adding: " + oObj.getCount());
87 CellRangeAddress[] addr = oObj.getRangeAddresses();
88 boolean exist = false ;
89 for (int i=0; i<=oObj.getCount()-1; i++) {
90 if ( addr[i].Sheet == rAddr[0].Sheet &&
91 addr[i].StartColumn == rAddr[0].StartColumn &&
92 addr[i].StartRow == rAddr[0].StartRow &&
93 addr[i].EndColumn == rAddr[0].EndColumn &&
94 addr[i].EndRow == rAddr[0].EndRow) {
96 exist = true;
100 result &= exist ;
102 tRes.tested("addRangeAddress()" ,result);
106 * The method called. Then a value added before is removed.
107 * Next we check Container for existence of removed value. <p>
108 * Has <b> OK </b> status if the range just removed doesn't presents among
109 * all ranges in the container.
111 public void _removeRangeAddress() {
112 boolean result = true;
114 log.println("Elements before removing: " + oObj.getCount());
115 try {
116 oObj.removeRangeAddress(rAddr[0]);
117 } catch (com.sun.star.container.NoSuchElementException e) {
118 e.printStackTrace(log);
119 result = false;
121 log.println("Elements after removing: " + oObj.getCount());
122 CellRangeAddress[] addr = oObj.getRangeAddresses();
123 for (int i=0; i<=oObj.getCount()-1; i++) {
124 if ( (addr[i].Sheet == rAddr[0].Sheet) &&
125 (addr[i].StartColumn == rAddr[0].StartColumn) &&
126 (addr[i].StartRow == rAddr[0].StartRow) &&
127 (addr[i].EndColumn == rAddr[0].EndColumn) &&
128 (addr[i].EndRow == rAddr[0].EndRow) ) {
129 result = false;
132 tRes.tested("removeRangeAddress()" ,result);
136 * The method called. Then new values are added to Container.
137 * Next we try to obtain back all added values and check it. <p>
139 * Has <b> OK </b> status if the count of ranges increases by
140 * number of added ranges - 1 (one of ranges already exists in the
141 * container). And if all of ranges added exist in the container.
143 public void _addRangeAddresses() {
144 executeMethod("addRangeAddress()");
146 boolean result = true;
148 int cntBefore = oObj.getCount();
149 log.println("Elements before adding: " + cntBefore);
150 oObj.addRangeAddresses(rAddr, false);
151 log.println("Elements after adding: " + oObj.getCount());
152 CellRangeAddress[] addr = oObj.getRangeAddresses();
154 result &= cntBefore + rAddr.length == oObj.getCount();
156 for (int j = 0; j < rAddr.length; j++) {
157 boolean exist = false ;
158 for (int i=0; i < oObj.getCount(); i++) {
159 if ( addr[i].Sheet == rAddr[j].Sheet &&
160 addr[i].StartColumn == rAddr[j].StartColumn &&
161 addr[i].StartRow == rAddr[j].StartRow &&
162 addr[i].EndColumn == rAddr[j].EndColumn &&
163 addr[i].EndRow == rAddr[j].EndRow ) {
165 exist = true;
166 break;
169 result &= exist;
172 tRes.tested("addRangeAddresses()" ,result);
176 * All ranges are remover from contaier.
178 * Has <b> OK </b> status if there are no more ranges in the container.
180 public void _removeRangeAddresses() {
181 boolean result = false;
182 int cnt;
184 log.println("Elements before removing: " + oObj.getCount());
185 try {
186 oObj.removeRangeAddresses(oObj.getRangeAddresses());
187 } catch (com.sun.star.container.NoSuchElementException e) {
188 e.printStackTrace(log);
189 result = false;
191 if ( (cnt = oObj.getCount()) == 0) {
192 result = true;
194 log.println("Elements after removing: " + cnt);
195 tRes.tested("removeRangeAddresses()" ,result);
199 * Forces environment recreation.
201 protected void after() {
202 disposeEnvironment();