merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / ifc / container / _XIndexAccess.java
blobb8b3e3e401abbd83576c6d5608851e65a1acc5b9
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: _XIndexAccess.java,v $
10 * $Revision: 1.5 $
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.container;
33 import lib.MultiMethodTest;
35 import com.sun.star.container.XIndexAccess;
36 import com.sun.star.lang.IndexOutOfBoundsException;
37 import com.sun.star.lang.WrappedTargetException;
39 /**
40 * Testing <code>com.sun.star.container.XIndexAccess</code>
41 * interface methods :
42 * <ul>
43 * <li><code> getCount()</code></li>
44 * <li><code> getByIndex()</code></li>
45 * </ul> <p>
46 * Test seems to work properly in multithreaded environment.
47 * @see com.sun.star.container.XIndexAccess
49 public class _XIndexAccess extends MultiMethodTest {
51 public XIndexAccess oObj = null;
53 /**
54 * Number of elements in the container.
56 public int count = 0;
58 /**
59 * Get number of element in the container. <p>
60 * Has <b> OK </b> status if method returns number lager than -1.
62 public void _getCount() {
63 boolean result = true;
64 log.println("getting the number of the elements");
65 // hope we haven't a count lower than zerro ;-)
66 count = -1;
67 count = oObj.getCount();
68 result = (count != -1);
69 tRes.tested("getCount()", result);
70 } //end getCount()
72 /**
73 * This method tests the IndexAccess from the first element,
74 * the middle element and the last element. Finaly it test
75 * Exceptions which throws by a not available index. <p>
76 * Has <b> OK </b> status if first, middle and last elements
77 * successfully returned and has non null value; and if on
78 * invalid index parameter <code>IndexOutOfBoundException</code>
79 * is thrown.<p>
80 * The following method tests are to be completed successfully before :
81 * <ul>
82 * <li> <code> getCount() </code> : to have number of elements
83 * in container. </li>
84 * </ul>
86 public void _getByIndex() {
87 requiredMethod("getCount()");
88 // get count from holder
90 try {
91 Thread.sleep(200);
93 catch(java.lang.InterruptedException e) {}
95 boolean result = true;
96 boolean loc_result = true;
97 Object o = null;
98 log.println("Testing getByIndex()");
100 if (count > 0) {
101 // Check the first element
102 log.println("Check the first element");
103 result &= checkGetByIndex(0);
105 // Check the middle element
106 log.println("Check the middle element");
107 result &= checkGetByIndex(count /2);
109 // Check the last element
110 log.println("Check the last element");
111 result &= checkGetByIndex(count -1);
113 // Testing getByIndex with wrong params.
114 log.println("Testing getByIndex with wrong params.");
115 try {
116 log.println("getByIndex(" + count + ")");
117 loc_result = oObj.getByIndex(count) == null;
118 log.println("no exception thrown - FAILED");
119 result = false;
120 } catch (IndexOutOfBoundsException e) {
121 log.println("Expected exception cought! " + e + " OK");
122 } catch (WrappedTargetException e) {
123 log.println("Wrong exception! " + e + " FAILED");
124 result = false;
128 tRes.tested("getByIndex()", result);
130 } // end getByIndex
132 private boolean checkGetByIndex(int index){
133 Object o = null;
134 boolean result = true;
135 try {
136 log.println("getByIndex(" + index + ")");
137 o = oObj.getByIndex(index);
139 if ( tEnv.getObjRelation("XIndexAccess.getByIndex.mustBeNull") != null){
140 result = (o == null);
141 if (result) log.println("OK"); else log.println("FAILED -> not null");
142 } else {
143 result = (o != null);
144 if (result) log.println("OK"); else log.println("FAILED -> null");
147 } catch (WrappedTargetException e) {
148 log.println("Exception! " + e);
149 result = false;
150 } catch (IndexOutOfBoundsException e) {
151 log.println("Exception! " + e);
152 result = false;
155 return result;
158 } // end XIndexAccess