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
.container
.XEnumerationAccess
;
26 import com
.sun
.star
.lang
.WrappedTargetException
;
29 * Testing <code>com.sun.star.container.XEnumeration</code>
32 * <li><code> hasMoreElements()</code></li>
33 * <li><code> nextElement()</code></li>
35 * This test needs the following object relations :
37 * <li> <code>'ENUM'</code> (of type <code>XEnumerationAccess</code>):
38 * This test creates its own oObj because the method nextElement()
39 * will be modified this Object directly so other threads may be faild.
42 * Test is multithread compliant. <p>
43 * @see com.sun.star.container.XEnumeration
45 public class _XEnumeration
extends MultiMethodTest
{
47 public XEnumeration oObj
= null;
48 public XEnumerationAccess Enum
= null;
51 * Retrieves relation and sets oObj to a separate enumeration
52 * created. Retrieves all elements from enumeration.<p>
53 * Has <b> OK </b> status if all elements successfully retrieved
54 * and exceptions occurred.
56 public void _hasMoreElements() {
57 boolean result
= true;
59 log
.println("get all elements");
62 while ( oObj
.hasMoreElements() ) {
66 if (counter
- tmpCounter
> 10000) {
67 log
.println(counter
+ " Elements");
70 } catch (WrappedTargetException e
) {
71 log
.println("hasMoreElements() : " + e
);
74 } catch (NoSuchElementException e
) {
75 log
.println("hasMoreElements() : " + e
);
80 Object expCount
= tEnv
.getObjRelation("ExpectedCount");
81 if (expCount
!= null) {
82 int ec
= ((Integer
) expCount
).intValue();
83 boolean locResult
= counter
== ec
;
85 log
.println("Not all Elements are returned: ");
86 log
.println("\tExpected: "+ ec
);
87 log
.println("\tFound: "+counter
);
91 tRes
.tested("hasMoreElements()", result
);
92 } // end hasMoreElements
95 * Calls the method (on starting this method there is no more elements
96 * in the enumeration. <p>
97 * Has <b> OK </b> status if only <code>NoSuchElementException</code>
98 * exception rises. <p>
99 * The following method tests are to be completed successfully before :
101 * <li> <code> hasMoreElements() </code> : it retrieves all elements </li>
104 public void _nextElement(){
105 requiredMethod("hasMoreElements()");
106 boolean result
= true;
107 log
.println("additional call must throw NoSuchElementException");
111 log
.println("nextElement: no exception!");
113 } catch (WrappedTargetException e
) {
114 log
.println("nextElement: wrong exception!");
116 } catch (NoSuchElementException e
) {
117 log
.println("nextElement: correct exception");
120 tRes
.tested("nextElement()", result
);