bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / ifc / container / _XIndexAccess.java
blob396635f642b5dd3b02438f8d46dab18b43ca7d43
1 /*
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;
27 /**
28 * Testing <code>com.sun.star.container.XIndexAccess</code>
29 * interface methods :
30 * <ul>
31 * <li><code> getCount()</code></li>
32 * <li><code> getByIndex()</code></li>
33 * </ul> <p>
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;
41 /**
42 * Number of elements in the container.
44 public int count = 0;
46 /**
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 ;-)
54 count = -1;
55 count = oObj.getCount();
56 result = (count != -1);
57 tRes.tested("getCount()", result);
58 } //end getCount()
60 /**
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>
67 * is thrown.<p>
68 * The following method tests are to be completed successfully before :
69 * <ul>
70 * <li> <code> getCount() </code> : to have number of elements
71 * in container. </li>
72 * </ul>
74 public void _getByIndex() {
75 requiredMethod("getCount()");
76 // get count from holder
78 try {
79 Thread.sleep(200);
81 catch(java.lang.InterruptedException e) {}
83 boolean result = true;
84 log.println("Testing getByIndex()");
86 if (count > 0) {
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.");
101 try {
102 log.println("getByIndex(" + count + ")");
103 oObj.getByIndex(count);
104 log.println("no exception thrown - FAILED");
105 result = false;
106 } catch (IndexOutOfBoundsException e) {
107 log.println("Expected exception cought! " + e + " OK");
108 } catch (WrappedTargetException e) {
109 log.println("Wrong exception! " + e + " FAILED");
110 result = false;
114 tRes.tested("getByIndex()", result);
116 } // end getByIndex
118 private boolean checkGetByIndex(int index){
119 Object o = null;
120 boolean result = true;
121 try {
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");
128 } else {
129 result = (o != null);
130 if (result) log.println("OK"); else log.println("FAILED -> null");
133 } catch (WrappedTargetException e) {
134 log.println("Exception! " + e);
135 result = false;
136 } catch (IndexOutOfBoundsException e) {
137 log.println("Exception! " + e);
138 result = false;
141 return result;
144 } // end XIndexAccess