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
.container
;
21 import lib
.MultiMethodTest
;
23 import com
.sun
.star
.container
.XIndexAccess
;
24 import com
.sun
.star
.lang
.IndexOutOfBoundsException
;
25 import com
.sun
.star
.lang
.WrappedTargetException
;
28 * Testing <code>com.sun.star.container.XIndexAccess</code>
31 * <li><code> getCount()</code></li>
32 * <li><code> getByIndex()</code></li>
34 * Test seems to work properly in multithreaded environment.
35 * @see com.sun.star.container.XIndexAccess
37 public class _XIndexAccess
extends MultiMethodTest
{
39 public XIndexAccess oObj
= null;
42 * Number of elements in the container.
47 * Get number of element in the container. <p>
48 * Has <b> OK </b> status if method returns number lager than -1.
50 public void _getCount() {
51 boolean result
= true;
52 log
.println("getting the number of the elements");
53 // hope we haven't a count lower than zerro ;-)
55 count
= oObj
.getCount();
56 result
= (count
!= -1);
57 tRes
.tested("getCount()", result
);
61 * This method tests the IndexAccess from the first element,
62 * the middle element and the last element. Finaly it test
63 * Exceptions which throws by a not available index. <p>
64 * Has <b> OK </b> status if first, middle and last elements
65 * successfully returned and has non null value; and if on
66 * invalid index parameter <code>IndexOutOfBoundException</code>
68 * The following method tests are to be completed successfully before :
70 * <li> <code> getCount() </code> : to have number of elements
74 public void _getByIndex() {
75 requiredMethod("getCount()");
76 // get count from holder
81 catch(java
.lang
.InterruptedException e
) {}
83 boolean result
= true;
84 log
.println("Testing getByIndex()");
87 // Check the first element
88 log
.println("Check the first element");
89 result
&= checkGetByIndex(0);
91 // Check the middle element
92 log
.println("Check the middle element");
93 result
&= checkGetByIndex(count
/2);
95 // Check the last element
96 log
.println("Check the last element");
97 result
&= checkGetByIndex(count
-1);
99 // Testing getByIndex with wrong params.
100 log
.println("Testing getByIndex with wrong params.");
102 log
.println("getByIndex(" + count
+ ")");
103 oObj
.getByIndex(count
);
104 log
.println("no exception thrown - FAILED");
106 } catch (IndexOutOfBoundsException e
) {
107 log
.println("Expected exception cought! " + e
+ " OK");
108 } catch (WrappedTargetException e
) {
109 log
.println("Wrong exception! " + e
+ " FAILED");
114 tRes
.tested("getByIndex()", result
);
118 private boolean checkGetByIndex(int index
){
120 boolean result
= true;
122 log
.println("getByIndex(" + index
+ ")");
123 o
= oObj
.getByIndex(index
);
125 if ( tEnv
.getObjRelation("XIndexAccess.getByIndex.mustBeNull") != null){
126 result
= (o
== null);
127 if (result
) log
.println("OK"); else log
.println("FAILED -> not null");
129 result
= (o
!= null);
130 if (result
) log
.println("OK"); else log
.println("FAILED -> null");
133 } catch (WrappedTargetException e
) {
134 log
.println("Exception! " + e
);
136 } catch (IndexOutOfBoundsException e
) {
137 log
.println("Exception! " + e
);
144 } // end XIndexAccess