Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / qadevOOo / tests / java / ifc / container / _XIndexAccess.java
blobc87a62baaf2368c5bca50d408af5a0312a3aee41
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.container;
30 import lib.MultiMethodTest;
32 import com.sun.star.container.XIndexAccess;
33 import com.sun.star.lang.IndexOutOfBoundsException;
34 import com.sun.star.lang.WrappedTargetException;
36 /**
37 * Testing <code>com.sun.star.container.XIndexAccess</code>
38 * interface methods :
39 * <ul>
40 * <li><code> getCount()</code></li>
41 * <li><code> getByIndex()</code></li>
42 * </ul> <p>
43 * Test seems to work properly in multithreaded environment.
44 * @see com.sun.star.container.XIndexAccess
46 public class _XIndexAccess extends MultiMethodTest {
48 public XIndexAccess oObj = null;
50 /**
51 * Number of elements in the container.
53 public int count = 0;
55 /**
56 * Get number of element in the container. <p>
57 * Has <b> OK </b> status if method returns number lager than -1.
59 public void _getCount() {
60 boolean result = true;
61 log.println("getting the number of the elements");
62 // hope we haven't a count lower than zerro ;-)
63 count = -1;
64 count = oObj.getCount();
65 result = (count != -1);
66 tRes.tested("getCount()", result);
67 } //end getCount()
69 /**
70 * This method tests the IndexAccess from the first element,
71 * the middle element and the last element. Finaly it test
72 * Exceptions which throws by a not available index. <p>
73 * Has <b> OK </b> status if first, middle and last elements
74 * successfully returned and has non null value; and if on
75 * invalid index parameter <code>IndexOutOfBoundException</code>
76 * is thrown.<p>
77 * The following method tests are to be completed successfully before :
78 * <ul>
79 * <li> <code> getCount() </code> : to have number of elements
80 * in container. </li>
81 * </ul>
83 public void _getByIndex() {
84 requiredMethod("getCount()");
85 // get count from holder
87 try {
88 Thread.sleep(200);
90 catch(java.lang.InterruptedException e) {}
92 boolean result = true;
93 boolean loc_result = true;
94 Object o = null;
95 log.println("Testing getByIndex()");
97 if (count > 0) {
98 // Check the first element
99 log.println("Check the first element");
100 result &= checkGetByIndex(0);
102 // Check the middle element
103 log.println("Check the middle element");
104 result &= checkGetByIndex(count /2);
106 // Check the last element
107 log.println("Check the last element");
108 result &= checkGetByIndex(count -1);
110 // Testing getByIndex with wrong params.
111 log.println("Testing getByIndex with wrong params.");
112 try {
113 log.println("getByIndex(" + count + ")");
114 loc_result = oObj.getByIndex(count) == null;
115 log.println("no exception thrown - FAILED");
116 result = false;
117 } catch (IndexOutOfBoundsException e) {
118 log.println("Expected exception cought! " + e + " OK");
119 } catch (WrappedTargetException e) {
120 log.println("Wrong exception! " + e + " FAILED");
121 result = false;
125 tRes.tested("getByIndex()", result);
127 } // end getByIndex
129 private boolean checkGetByIndex(int index){
130 Object o = null;
131 boolean result = true;
132 try {
133 log.println("getByIndex(" + index + ")");
134 o = oObj.getByIndex(index);
136 if ( tEnv.getObjRelation("XIndexAccess.getByIndex.mustBeNull") != null){
137 result = (o == null);
138 if (result) log.println("OK"); else log.println("FAILED -> not null");
139 } else {
140 result = (o != null);
141 if (result) log.println("OK"); else log.println("FAILED -> null");
144 } catch (WrappedTargetException e) {
145 log.println("Exception! " + e);
146 result = false;
147 } catch (IndexOutOfBoundsException e) {
148 log.println("Exception! " + e);
149 result = false;
152 return result;
155 } // end XIndexAccess