Avoid potential negative array index access to cached text.
[LibreOffice.git] / qadevOOo / tests / java / ifc / container / _XEnumeration.java
blob4cddb309e14dbc4428168cc8c0cc5f1218e76517
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.NoSuchElementException;
24 import com.sun.star.container.XEnumeration;
25 import com.sun.star.lang.WrappedTargetException;
27 /**
28 * Testing <code>com.sun.star.container.XEnumeration</code>
29 * interface methods :
30 * <ul>
31 * <li><code> hasMoreElements()</code></li>
32 * <li><code> nextElement()</code></li>
33 * </ul>
34 * Test is multithread compliant. <p>
35 * @see com.sun.star.container.XEnumeration
37 public class _XEnumeration extends MultiMethodTest {
39 public XEnumeration oObj = null;
41 /**
42 * Retrieves relation and sets oObj to a separate enumeration
43 * created. Retrieves all elements from enumeration.<p>
44 * Has <b> OK </b> status if all elements successfully retrieved
45 * and exceptions occurred.
47 public void _hasMoreElements() {
48 boolean result = true;
50 log.println("get all elements");
51 int counter = 0;
52 int tmpCounter = 0;
53 while ( oObj.hasMoreElements() ) {
54 try {
55 oObj.nextElement();
56 counter ++;
57 if (counter - tmpCounter > 10000) {
58 log.println(counter+ " Elements");
59 tmpCounter = counter;
61 } catch (WrappedTargetException e) {
62 log.println("hasMoreElements() : " + e);
63 result = false;
64 break;
65 } catch (NoSuchElementException e) {
66 log.println("hasMoreElements() : " + e);
67 result = false;
68 break;
71 Object expCount = tEnv.getObjRelation("ExpectedCount");
72 if (expCount != null) {
73 int ec = ((Integer) expCount).intValue();
74 boolean locResult = counter == ec;
75 if (!locResult) {
76 log.println("Not all Elements are returned: ");
77 log.println("\tExpected: "+ ec);
78 log.println("\tFound: "+counter);
80 result &= locResult;
82 tRes.tested("hasMoreElements()", result);
83 } // end hasMoreElements
85 /**
86 * Calls the method (on starting this method there is no more elements
87 * in the enumeration. <p>
88 * Has <b> OK </b> status if only <code>NoSuchElementException</code>
89 * exception rises. <p>
90 * The following method tests are to be completed successfully before :
91 * <ul>
92 * <li> <code> hasMoreElements() </code> : it retrieves all elements </li>
93 * </ul>
95 public void _nextElement(){
96 requiredMethod("hasMoreElements()");
97 boolean result = true;
98 log.println("additional call must throw NoSuchElementException");
100 try {
101 oObj.nextElement();
102 log.println("nextElement: no exception!");
103 result = false;
104 } catch (WrappedTargetException e) {
105 log.println("nextElement: wrong exception!");
106 result = false;
107 } catch (NoSuchElementException e) {
108 log.println("nextElement: correct exception");
111 tRes.tested("nextElement()", result);
112 } // end NextElement
114 } //end XEnumeration