1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XEnumeration.java,v $
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
;
41 * Testing <code>com.sun.star.container.XEnumeration</code>
44 * <li><code> hasMoreElements()</code></li>
45 * <li><code> nextElement()</code></li>
47 * This test needs the following object relations :
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.
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;
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");
74 while ( oObj
.hasMoreElements() ) {
76 Object oAny
= oObj
.nextElement();
78 if (counter
- tmpCounter
> 10000) {
79 log
.println(counter
+ " Elements");
82 } catch (WrappedTargetException e
) {
83 log
.println("hasMoreElements() : " + e
);
86 } catch (NoSuchElementException e
) {
87 log
.println("hasMoreElements() : " + e
);
92 Object expCount
= tEnv
.getObjRelation("ExpectedCount");
93 if (expCount
!= null) {
94 int ec
= ((Integer
) expCount
).intValue();
95 boolean locResult
= counter
== ec
;
97 log
.println("Not all Elements are returned: ");
98 log
.println("\tExpected: "+ ec
);
99 log
.println("\tFound: "+counter
);
103 tRes
.tested("hasMoreElements()", result
);
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 :
114 * <li> <code> hasMoreElements() </code> : it retrieves all elements </li>
117 public void _nextElement(){
118 requiredMethod("hasMoreElements()");
119 boolean result
= true;
120 log
.println("additional call must throw NoSuchElementException");
123 Object oAny
= oObj
.nextElement();
124 log
.println("nextElement: no exception!");
126 } catch (WrappedTargetException e
) {
127 log
.println("nextElement: wrong exception!");
129 } catch (NoSuchElementException e
) {
130 log
.println("nextElement: correct exception");
133 tRes
.tested("nextElement()", result
);