1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package ifc.container;
25 
26 import lib.MultiMethodTest;
27 
28 import com.sun.star.container.NoSuchElementException;
29 import com.sun.star.container.XEnumeration;
30 import com.sun.star.container.XEnumerationAccess;
31 import com.sun.star.lang.WrappedTargetException;
32 
33 /**
34 * Testing <code>com.sun.star.container.XEnumeration</code>
35 * interface methods :
36 * <ul>
37 *  <li><code> hasMoreElements()</code></li>
38 *  <li><code> nextElement()</code></li>
39 * </ul> <p>
40 * This test needs the following object relations :
41 * <ul>
42 *  <li> <code>'ENUM'</code> (of type <code>XEnumerationAccess</code>):
43 *   This test creates its own oObj because the method nextElement()
44 *   will be modified this Object directly so other threads may be faild.
45 *  </li>
46 * <ul> <p>
47 * Test is multithread compilant. <p>
48 * @see com.sun.star.container.XEnumeration
49 */
50 public class _XEnumeration extends MultiMethodTest {
51 
52     public XEnumeration oObj = null;
53     public XEnumerationAccess Enum = null;
54 
55     /**
56     * Retrieves relation and sets oObj to a separate enumeration
57     * created. Retrieves all elements from enumeration.<p>
58     * Has <b> OK </b> status if all elements successfully retrieved
59     * and exceptions occured.
60     */
_hasMoreElements()61     public void _hasMoreElements() {
62         boolean result = true;
63 
64         log.println("get all elements");
65         int counter = 0;
66         int tmpCounter = 0;
67         while ( oObj.hasMoreElements() ) {
68             try {
69                 Object oAny = oObj.nextElement();
70                 counter ++;
71                 if (counter - tmpCounter > 10000) {
72                     log.println(counter+ " Elements");
73                     tmpCounter = counter;
74                 }
75             } catch (WrappedTargetException e) {
76                 log.println("hasMoreElements() : " + e);
77                 result = false;
78                 break;
79             } catch (NoSuchElementException e) {
80                 log.println("hasMoreElements() : " + e);
81                 result = false;
82                 break;
83             }
84         }
85         Object expCount = tEnv.getObjRelation("ExpectedCount");
86         if (expCount != null) {
87             int ec = ((Integer) expCount).intValue();
88             boolean locResult = counter == ec;
89             if (!locResult) {
90                 log.println("Not all Elements are returned: ");
91                 log.println("\tExpected: "+ ec);
92                 log.println("\tFound: "+counter);
93             }
94             result &= locResult;
95         }
96         tRes.tested("hasMoreElements()", result);
97         return;
98     } // end hasMoreElements
99 
100     /**
101     * Calls the method (on starting this method there is no more elements
102     * in the enumeration. <p>
103     * Has <b> OK </b> status if only <code>NoSuchElementException</code>
104     * exception rises. <p>
105     * The following method tests are to be completed successfully before :
106     * <ul>
107     *  <li> <code> hasMoreElements() </code> : it retrieves all elements </li>
108     * </ul>
109     */
_nextElement()110     public void _nextElement(){
111         requiredMethod("hasMoreElements()");
112         boolean result = true;
113         log.println("additional call must throw NoSuchElementException");
114 
115         try {
116             Object oAny = oObj.nextElement();
117             log.println("nextElement: no exception!");
118             result = false;
119         } catch (WrappedTargetException e) {
120             log.println("nextElement: wrong exception!");
121             result = false;
122         } catch (NoSuchElementException e) {
123             log.println("nextElement: correct exception");
124         }
125 
126         tRes.tested("nextElement()", result);
127 
128         return;
129 
130     } // end NextElement
131 
132 } //end XEnumeration
133 
134