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
;
37 * Testing <code>com.sun.star.container.XIndexAccess</code>
40 * <li><code> getCount()</code></li>
41 * <li><code> getByIndex()</code></li>
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;
51 * Number of elements in the container.
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 ;-)
64 count
= oObj
.getCount();
65 result
= (count
!= -1);
66 tRes
.tested("getCount()", result
);
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>
77 * The following method tests are to be completed successfully before :
79 * <li> <code> getCount() </code> : to have number of elements
83 public void _getByIndex() {
84 requiredMethod("getCount()");
85 // get count from holder
90 catch(java
.lang
.InterruptedException e
) {}
92 boolean result
= true;
93 boolean loc_result
= true;
95 log
.println("Testing getByIndex()");
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.");
113 log
.println("getByIndex(" + count
+ ")");
114 loc_result
= oObj
.getByIndex(count
) == null;
115 log
.println("no exception thrown - FAILED");
117 } catch (IndexOutOfBoundsException e
) {
118 log
.println("Expected exception cought! " + e
+ " OK");
119 } catch (WrappedTargetException e
) {
120 log
.println("Wrong exception! " + e
+ " FAILED");
125 tRes
.tested("getByIndex()", result
);
129 private boolean checkGetByIndex(int index
){
131 boolean result
= true;
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");
140 result
= (o
!= null);
141 if (result
) log
.println("OK"); else log
.println("FAILED -> null");
144 } catch (WrappedTargetException e
) {
145 log
.println("Exception! " + e
);
147 } catch (IndexOutOfBoundsException e
) {
148 log
.println("Exception! " + e
);
155 } // end XIndexAccess