Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / ifc / sheet / _XSheetCellRangeContainer.java
bloba852daf67fbdc9f50281e0d1a77249dd3c22c893
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package ifc.sheet;
21 import lib.MultiMethodTest;
22 import lib.StatusException;
24 import com.sun.star.sheet.XSheetCellRangeContainer;
25 import com.sun.star.table.CellRangeAddress;
27 /**
28 * Testing <code>com.sun.star.sheet.XSheetCellRangeContainer</code>
29 * interface methods :
30 * <ul>
31 * <li><code> addRangeAddress() </code></li>
32 * <li><code> removeRangeAddress() </code></li>
33 * <li><code> addRangeAddresses() </code></li>
34 * <li><code> removeRangeAddresses() </code></li>
35 * </ul> <p>
36 * Test is <b> NOT </b> multithread compliant. <p>
37 * @see com.sun.star.sheet.XSheetCellRangeContainer
39 public class _XSheetCellRangeContainer extends MultiMethodTest {
40 public XSheetCellRangeContainer oObj = null;
41 public CellRangeAddress[] rAddr = new CellRangeAddress[3];
43 /**
44 * After method called, the new array of structures 'CellRangeAddress'
45 * is created. Then container is cleared.
47 @Override
48 public void before() {
49 for ( short i=0; i<=2; i++ ) {
50 rAddr[i] = new CellRangeAddress();
51 rAddr[i].Sheet = i;
52 rAddr[i].StartColumn = i;
53 rAddr[i].StartRow = i;
54 rAddr[i].EndColumn = i + 3;
55 rAddr[i].EndRow = i + 3;
56 try {
57 oObj.removeRangeAddresses(oObj.getRangeAddresses());
58 } catch (com.sun.star.uno.Exception e) {
59 e.printStackTrace(log);
60 throw new StatusException("Error: Cannot remove "+
61 "range addresses." ,e);
66 /**
67 * The method called. Then new value is added to Container.
68 * Next we try to obtain back added value and check it. <p>
70 * Has <b> OK </b> status if the range just added presents among
71 * all ranges in the container.
73 public void _addRangeAddress() {
74 boolean result = true;
76 log.println("Elements before adding: " + oObj.getCount());
77 oObj.addRangeAddress(rAddr[0], false);
78 log.println("Elements after adding: " + oObj.getCount());
79 CellRangeAddress[] addr = oObj.getRangeAddresses();
80 boolean exist = false ;
81 for (int i=0; i<=oObj.getCount()-1; i++) {
82 if ( addr[i].Sheet == rAddr[0].Sheet &&
83 addr[i].StartColumn == rAddr[0].StartColumn &&
84 addr[i].StartRow == rAddr[0].StartRow &&
85 addr[i].EndColumn == rAddr[0].EndColumn &&
86 addr[i].EndRow == rAddr[0].EndRow) {
88 exist = true;
92 result &= exist ;
94 tRes.tested("addRangeAddress()" ,result);
97 /**
98 * The method called. Then a value added before is removed.
99 * Next we check Container for existence of removed value. <p>
100 * Has <b> OK </b> status if the range just removed doesn't presents among
101 * all ranges in the container.
103 public void _removeRangeAddress() {
104 boolean result = true;
106 log.println("Elements before removing: " + oObj.getCount());
107 try {
108 oObj.removeRangeAddress(rAddr[0]);
109 } catch (com.sun.star.container.NoSuchElementException e) {
110 e.printStackTrace(log);
111 result = false;
113 log.println("Elements after removing: " + oObj.getCount());
114 CellRangeAddress[] addr = oObj.getRangeAddresses();
115 for (int i=0; i<=oObj.getCount()-1; i++) {
116 if ( (addr[i].Sheet == rAddr[0].Sheet) &&
117 (addr[i].StartColumn == rAddr[0].StartColumn) &&
118 (addr[i].StartRow == rAddr[0].StartRow) &&
119 (addr[i].EndColumn == rAddr[0].EndColumn) &&
120 (addr[i].EndRow == rAddr[0].EndRow) ) {
121 result = false;
124 tRes.tested("removeRangeAddress()" ,result);
128 * The method called. Then new values are added to Container.
129 * Next we try to obtain back all added values and check it. <p>
131 * Has <b> OK </b> status if the count of ranges increases by
132 * number of added ranges - 1 (one of ranges already exists in the
133 * container). And if all of ranges added exist in the container.
135 public void _addRangeAddresses() {
136 executeMethod("addRangeAddress()");
138 boolean result = true;
140 int cntBefore = oObj.getCount();
141 log.println("Elements before adding: " + cntBefore);
142 oObj.addRangeAddresses(rAddr, false);
143 log.println("Elements after adding: " + oObj.getCount());
144 CellRangeAddress[] addr = oObj.getRangeAddresses();
146 result &= cntBefore + rAddr.length == oObj.getCount();
148 for (int j = 0; j < rAddr.length; j++) {
149 boolean exist = false ;
150 for (int i=0; i < oObj.getCount(); i++) {
151 if ( addr[i].Sheet == rAddr[j].Sheet &&
152 addr[i].StartColumn == rAddr[j].StartColumn &&
153 addr[i].StartRow == rAddr[j].StartRow &&
154 addr[i].EndColumn == rAddr[j].EndColumn &&
155 addr[i].EndRow == rAddr[j].EndRow ) {
157 exist = true;
158 break;
161 result &= exist;
164 tRes.tested("addRangeAddresses()" ,result);
168 * All ranges are remover from contaier.
170 * Has <b> OK </b> status if there are no more ranges in the container.
172 public void _removeRangeAddresses() {
173 boolean result = false;
174 int cnt;
176 log.println("Elements before removing: " + oObj.getCount());
177 try {
178 oObj.removeRangeAddresses(oObj.getRangeAddresses());
179 } catch (com.sun.star.container.NoSuchElementException e) {
180 e.printStackTrace(log);
181 result = false;
183 if ( (cnt = oObj.getCount()) == 0) {
184 result = true;
186 log.println("Elements after removing: " + cnt);
187 tRes.tested("removeRangeAddresses()" ,result);
191 * Forces environment recreation.
193 @Override
194 protected void after() {
195 disposeEnvironment();