1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XIndexAccess.java,v $
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
;
40 * Testing <code>com.sun.star.container.XIndexAccess</code>
43 * <li><code> getCount()</code></li>
44 * <li><code> getByIndex()</code></li>
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;
54 * Number of elements in the container.
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 ;-)
67 count
= oObj
.getCount();
68 result
= (count
!= -1);
69 tRes
.tested("getCount()", result
);
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>
80 * The following method tests are to be completed successfully before :
82 * <li> <code> getCount() </code> : to have number of elements
86 public void _getByIndex() {
87 requiredMethod("getCount()");
88 // get count from holder
93 catch(java
.lang
.InterruptedException e
) {}
95 boolean result
= true;
96 boolean loc_result
= true;
98 log
.println("Testing getByIndex()");
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.");
116 log
.println("getByIndex(" + count
+ ")");
117 loc_result
= oObj
.getByIndex(count
) == null;
118 log
.println("no exception thrown - FAILED");
120 } catch (IndexOutOfBoundsException e
) {
121 log
.println("Expected exception cought! " + e
+ " OK");
122 } catch (WrappedTargetException e
) {
123 log
.println("Wrong exception! " + e
+ " FAILED");
128 tRes
.tested("getByIndex()", result
);
132 private boolean checkGetByIndex(int index
){
134 boolean result
= true;
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");
143 result
= (o
!= null);
144 if (result
) log
.println("OK"); else log
.println("FAILED -> null");
147 } catch (WrappedTargetException e
) {
148 log
.println("Exception! " + e
);
150 } catch (IndexOutOfBoundsException e
) {
151 log
.println("Exception! " + e
);
158 } // end XIndexAccess