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