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