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 zero ;-)
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. Finally 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>IndexOutOfBoundsException</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
80 boolean result
= true;
81 log
.println("Testing getByIndex()");
84 // Check the first element
85 log
.println("Check the first element");
86 result
&= checkGetByIndex(0);
88 // Check the middle element
89 log
.println("Check the middle element");
90 result
&= checkGetByIndex(count
/2);
92 // Check the last element
93 log
.println("Check the last element");
94 result
&= checkGetByIndex(count
-1);
96 // Testing getByIndex with wrong params.
97 log
.println("Testing getByIndex with wrong params.");
99 log
.println("getByIndex(" + count
+ ")");
100 oObj
.getByIndex(count
);
101 log
.println("no exception thrown - FAILED");
103 } catch (IndexOutOfBoundsException e
) {
104 log
.println("Expected exception caught! " + e
+ " OK");
105 } catch (WrappedTargetException e
) {
106 log
.println("Wrong exception! " + e
+ " FAILED");
111 tRes
.tested("getByIndex()", result
);
115 private boolean checkGetByIndex(int index
){
117 boolean result
= true;
119 log
.println("getByIndex(" + index
+ ")");
120 o
= oObj
.getByIndex(index
);
122 if ( tEnv
.getObjRelation("XIndexAccess.getByIndex.mustBeNull") != null){
123 result
= (o
== null);
124 if (result
) log
.println("OK"); else log
.println("FAILED -> not null");
126 result
= (o
!= null);
127 if (result
) log
.println("OK"); else log
.println("FAILED -> null");
130 } catch (WrappedTargetException e
) {
131 log
.println("Exception! " + e
);
133 } catch (IndexOutOfBoundsException e
) {
134 log
.println("Exception! " + e
);
141 } // end XIndexAccess