xref: /AOO41X/main/qadevOOo/tests/java/ifc/container/_XEnumeration.java (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
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.
14  *
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).
20  *
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.
25  *
26  ************************************************************************/
27 
28 package ifc.container;
29 
30 import lib.MultiMethodTest;
31 
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;
36 
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
53 */
54 public class _XEnumeration extends MultiMethodTest {
55 
56     public XEnumeration oObj = null;
57     public XEnumerationAccess Enum = null;
58 
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 occured.
64     */
65     public void _hasMoreElements() {
66         boolean result = true;
67 
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;
78                 }
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;
87             }
88         }
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);
97             }
98             result &= locResult;
99         }
100         tRes.tested("hasMoreElements()", result);
101         return;
102     } // end hasMoreElements
103 
104     /**
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>
113     */
114     public void _nextElement(){
115         requiredMethod("hasMoreElements()");
116         boolean result = true;
117         log.println("additional call must throw NoSuchElementException");
118 
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");
128         }
129 
130         tRes.tested("nextElement()", result);
131 
132         return;
133 
134     } // end NextElement
135 
136 } //end XEnumeration
137 
138