Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / ifc / container / _XIndexAccess.java
blob99e3d609a74e7087df9709ef8501e77c016f2081
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. 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>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 util.utils.pause(200);
80 boolean result = true;
81 log.println("Testing getByIndex()");
83 if (count > 0) {
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.");
98 try {
99 log.println("getByIndex(" + count + ")");
100 oObj.getByIndex(count);
101 log.println("no exception thrown - FAILED");
102 result = false;
103 } catch (IndexOutOfBoundsException e) {
104 log.println("Expected exception caught! " + e + " OK");
105 } catch (WrappedTargetException e) {
106 log.println("Wrong exception! " + e + " FAILED");
107 result = false;
111 tRes.tested("getByIndex()", result);
113 } // end getByIndex
115 private boolean checkGetByIndex(int index){
116 Object o = null;
117 boolean result = true;
118 try {
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");
125 } else {
126 result = (o != null);
127 if (result) log.println("OK"); else log.println("FAILED -> null");
130 } catch (WrappedTargetException e) {
131 log.println("Exception! " + e);
132 result = false;
133 } catch (IndexOutOfBoundsException e) {
134 log.println("Exception! " + e);
135 result = false;
138 return result;
141 } // end XIndexAccess