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
;
38 * Testing <code>com.sun.star.container.XEnumeration</code>
41 * <li><code> hasMoreElements()</code></li>
42 * <li><code> nextElement()</code></li>
44 * This test needs the following object relations :
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.
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;
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");
71 while ( oObj
.hasMoreElements() ) {
73 Object oAny
= oObj
.nextElement();
75 if (counter
- tmpCounter
> 10000) {
76 log
.println(counter
+ " Elements");
79 } catch (WrappedTargetException e
) {
80 log
.println("hasMoreElements() : " + e
);
83 } catch (NoSuchElementException e
) {
84 log
.println("hasMoreElements() : " + e
);
89 Object expCount
= tEnv
.getObjRelation("ExpectedCount");
90 if (expCount
!= null) {
91 int ec
= ((Integer
) expCount
).intValue();
92 boolean locResult
= counter
== ec
;
94 log
.println("Not all Elements are returned: ");
95 log
.println("\tExpected: "+ ec
);
96 log
.println("\tFound: "+counter
);
100 tRes
.tested("hasMoreElements()", result
);
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 :
111 * <li> <code> hasMoreElements() </code> : it retrieves all elements </li>
114 public void _nextElement(){
115 requiredMethod("hasMoreElements()");
116 boolean result
= true;
117 log
.println("additional call must throw NoSuchElementException");
120 Object oAny
= oObj
.nextElement();
121 log
.println("nextElement: no exception!");
123 } catch (WrappedTargetException e
) {
124 log
.println("nextElement: wrong exception!");
126 } catch (NoSuchElementException e
) {
127 log
.println("nextElement: correct exception");
130 tRes
.tested("nextElement()", result
);