Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / qadevOOo / tests / java / ifc / container / _XEnumeration.java
blob4e4d8c3821d5b521e78ff092ab03329a88703395
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 package ifc.container;
30 import lib.MultiMethodTest;
32 import com.sun.star.container.NoSuchElementException;
33 import com.sun.star.container.XEnumeration;
34 import com.sun.star.container.XEnumerationAccess;
35 import com.sun.star.lang.WrappedTargetException;
37 /**
38 * Testing <code>com.sun.star.container.XEnumeration</code>
39 * interface methods :
40 * <ul>
41 * <li><code> hasMoreElements()</code></li>
42 * <li><code> nextElement()</code></li>
43 * </ul> <p>
44 * This test needs the following object relations :
45 * <ul>
46 * <li> <code>'ENUM'</code> (of type <code>XEnumerationAccess</code>):
47 * This test creates its own oObj because the method nextElement()
48 * will be modified this Object directly so other threads may be faild.
49 * </li>
50 * <ul> <p>
51 * Test is multithread compilant. <p>
52 * @see com.sun.star.container.XEnumeration
54 public class _XEnumeration extends MultiMethodTest {
56 public XEnumeration oObj = null;
57 public XEnumerationAccess Enum = null;
59 /**
60 * Retrieves relation and sets oObj to a separate enumeration
61 * created. Retrieves all elements from enumeration.<p>
62 * Has <b> OK </b> status if all elements successfully retrieved
63 * and exceptions occurred.
65 public void _hasMoreElements() {
66 boolean result = true;
68 log.println("get all elements");
69 int counter = 0;
70 int tmpCounter = 0;
71 while ( oObj.hasMoreElements() ) {
72 try {
73 Object oAny = oObj.nextElement();
74 counter ++;
75 if (counter - tmpCounter > 10000) {
76 log.println(counter+ " Elements");
77 tmpCounter = counter;
79 } catch (WrappedTargetException e) {
80 log.println("hasMoreElements() : " + e);
81 result = false;
82 break;
83 } catch (NoSuchElementException e) {
84 log.println("hasMoreElements() : " + e);
85 result = false;
86 break;
89 Object expCount = tEnv.getObjRelation("ExpectedCount");
90 if (expCount != null) {
91 int ec = ((Integer) expCount).intValue();
92 boolean locResult = counter == ec;
93 if (!locResult) {
94 log.println("Not all Elements are returned: ");
95 log.println("\tExpected: "+ ec);
96 log.println("\tFound: "+counter);
98 result &= locResult;
100 tRes.tested("hasMoreElements()", result);
101 return;
102 } // end hasMoreElements
105 * Calls the method (on starting this method there is no more elements
106 * in the enumeration. <p>
107 * Has <b> OK </b> status if only <code>NoSuchElementException</code>
108 * exception rises. <p>
109 * The following method tests are to be completed successfully before :
110 * <ul>
111 * <li> <code> hasMoreElements() </code> : it retrieves all elements </li>
112 * </ul>
114 public void _nextElement(){
115 requiredMethod("hasMoreElements()");
116 boolean result = true;
117 log.println("additional call must throw NoSuchElementException");
119 try {
120 Object oAny = oObj.nextElement();
121 log.println("nextElement: no exception!");
122 result = false;
123 } catch (WrappedTargetException e) {
124 log.println("nextElement: wrong exception!");
125 result = false;
126 } catch (NoSuchElementException e) {
127 log.println("nextElement: correct exception");
130 tRes.tested("nextElement()", result);
132 return;
134 } // end NextElement
136 } //end XEnumeration