Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / ifc / container / _XEnumeration.java
blobdfa2d52a84be205c6d243822b2260132e34adff2
1 /*
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;
28 /**
29 * Testing <code>com.sun.star.container.XEnumeration</code>
30 * interface methods :
31 * <ul>
32 * <li><code> hasMoreElements()</code></li>
33 * <li><code> nextElement()</code></li>
34 * </ul> <p>
35 * This test needs the following object relations :
36 * <ul>
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.
40 * </li>
41 * <ul> <p>
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;
50 /**
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");
60 int counter = 0;
61 int tmpCounter = 0;
62 while ( oObj.hasMoreElements() ) {
63 try {
64 oObj.nextElement();
65 counter ++;
66 if (counter - tmpCounter > 10000) {
67 log.println(counter+ " Elements");
68 tmpCounter = counter;
70 } catch (WrappedTargetException e) {
71 log.println("hasMoreElements() : " + e);
72 result = false;
73 break;
74 } catch (NoSuchElementException e) {
75 log.println("hasMoreElements() : " + e);
76 result = false;
77 break;
80 Object expCount = tEnv.getObjRelation("ExpectedCount");
81 if (expCount != null) {
82 int ec = ((Integer) expCount).intValue();
83 boolean locResult = counter == ec;
84 if (!locResult) {
85 log.println("Not all Elements are returned: ");
86 log.println("\tExpected: "+ ec);
87 log.println("\tFound: "+counter);
89 result &= locResult;
91 tRes.tested("hasMoreElements()", result);
92 } // end hasMoreElements
94 /**
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 :
100 * <ul>
101 * <li> <code> hasMoreElements() </code> : it retrieves all elements </li>
102 * </ul>
104 public void _nextElement(){
105 requiredMethod("hasMoreElements()");
106 boolean result = true;
107 log.println("additional call must throw NoSuchElementException");
109 try {
110 oObj.nextElement();
111 log.println("nextElement: no exception!");
112 result = false;
113 } catch (WrappedTargetException e) {
114 log.println("nextElement: wrong exception!");
115 result = false;
116 } catch (NoSuchElementException e) {
117 log.println("nextElement: correct exception");
120 tRes.tested("nextElement()", result);
121 } // end NextElement
123 } //end XEnumeration