1*ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ef39d40dSAndrew Rist  * distributed with this work for additional information
6*ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9*ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*ef39d40dSAndrew Rist  *
11*ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ef39d40dSAndrew Rist  *
13*ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15*ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18*ef39d40dSAndrew Rist  * under the License.
19*ef39d40dSAndrew Rist  *
20*ef39d40dSAndrew Rist  *************************************************************/
21*ef39d40dSAndrew Rist 
22*ef39d40dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package ifc.container;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import lib.MultiMethodTest;
27cdf0e10cSrcweir 
28cdf0e10cSrcweir import com.sun.star.container.XSet;
29cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
30cdf0e10cSrcweir 
31cdf0e10cSrcweir /**
32cdf0e10cSrcweir * Testing <code>com.sun.star.container.XSet</code>
33cdf0e10cSrcweir * interface methods :
34cdf0e10cSrcweir * <ul>
35cdf0e10cSrcweir *  <li><code> has()</code></li>
36cdf0e10cSrcweir *  <li><code> insert()</code></li>
37cdf0e10cSrcweir *  <li><code> remove()</code></li>
38cdf0e10cSrcweir * </ul> <p>
39cdf0e10cSrcweir * Test is <b> NOT </b> multithread compilant. <p>
40cdf0e10cSrcweir * @see com.sun.star.container.XSet
41cdf0e10cSrcweir */
42cdf0e10cSrcweir public class _XSet extends MultiMethodTest {
43cdf0e10cSrcweir 
44cdf0e10cSrcweir     public static XSet oObj = null;
45cdf0e10cSrcweir 
46cdf0e10cSrcweir     private Object element = null ;
47cdf0e10cSrcweir     private boolean hasResult = true ;
48cdf0e10cSrcweir 
49cdf0e10cSrcweir     /**
50cdf0e10cSrcweir     * Inserts the element stored and removed before. <p>
51cdf0e10cSrcweir     * Has <b> OK </b> status if <code>has()</code> method returns
52cdf0e10cSrcweir     * <code>true</code>.
53cdf0e10cSrcweir     * The following method tests are to be completed successfully before :
54cdf0e10cSrcweir     * <ul>
55cdf0e10cSrcweir     *  <li> <code> remove() </code> : element from set is stored and
56cdf0e10cSrcweir     *    removed </li>
57cdf0e10cSrcweir     * </ul>
58cdf0e10cSrcweir     */
_insert()59cdf0e10cSrcweir     public void _insert() {
60cdf0e10cSrcweir         boolean res = true ;
61cdf0e10cSrcweir         try {
62cdf0e10cSrcweir             XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF();
63cdf0e10cSrcweir             element = xMSF.createInstance(
64cdf0e10cSrcweir                             "com.sun.star.reflection.TypeDescriptionProvider");
65cdf0e10cSrcweir 
66cdf0e10cSrcweir 
67cdf0e10cSrcweir             oObj.insert(element) ;
68cdf0e10cSrcweir 
69cdf0e10cSrcweir             if (!oObj.has(element)) {
70cdf0e10cSrcweir                 res = false ;
71cdf0e10cSrcweir                 log.println("After adding element method has()" +
72cdf0e10cSrcweir                     " returned false") ;
73cdf0e10cSrcweir                 hasResult = false ;
74cdf0e10cSrcweir             }
75cdf0e10cSrcweir         } catch (com.sun.star.container.ElementExistException e) {
76cdf0e10cSrcweir             e.printStackTrace(log) ;
77cdf0e10cSrcweir             res = false ;
78cdf0e10cSrcweir         } catch (com.sun.star.lang.IllegalArgumentException e) {
79cdf0e10cSrcweir             e.printStackTrace(log) ;
80cdf0e10cSrcweir             res = false ;
81cdf0e10cSrcweir         }
82cdf0e10cSrcweir         catch(com.sun.star.uno.Exception e) {
83cdf0e10cSrcweir             e.printStackTrace(log);
84cdf0e10cSrcweir             res = false;
85cdf0e10cSrcweir         }
86cdf0e10cSrcweir 
87cdf0e10cSrcweir         tRes.tested("insert()", res) ;
88cdf0e10cSrcweir     }
89cdf0e10cSrcweir 
90cdf0e10cSrcweir     /**
91cdf0e10cSrcweir     * Through <code>XEnumeration</code> interface an element from the set
92cdf0e10cSrcweir     * is retrieved. Then this element removed.<p>
93cdf0e10cSrcweir     * Has <b> OK </b> status if after removing <code>has()</code> method
94cdf0e10cSrcweir     * returns false.
95cdf0e10cSrcweir     */
_remove()96cdf0e10cSrcweir     public void _remove() {
97cdf0e10cSrcweir         requiredMethod("insert()");
98cdf0e10cSrcweir         boolean res = true ;
99cdf0e10cSrcweir 
100cdf0e10cSrcweir         try {
101cdf0e10cSrcweir 
102cdf0e10cSrcweir             // get an element to be removed/inserted
103cdf0e10cSrcweir 
104cdf0e10cSrcweir             oObj.remove(element) ;
105cdf0e10cSrcweir 
106cdf0e10cSrcweir             if (oObj.has(element)) {
107cdf0e10cSrcweir                 res = false ;
108cdf0e10cSrcweir                 log.println("After removing element method has()" +
109cdf0e10cSrcweir                     " returned true") ;
110cdf0e10cSrcweir                 hasResult = false ;
111cdf0e10cSrcweir             }
112cdf0e10cSrcweir 
113cdf0e10cSrcweir 
114cdf0e10cSrcweir 
115cdf0e10cSrcweir         } catch (com.sun.star.container.NoSuchElementException e) {
116cdf0e10cSrcweir             e.printStackTrace(log) ;
117cdf0e10cSrcweir             res = false ;
118cdf0e10cSrcweir         } catch (com.sun.star.lang.IllegalArgumentException e) {
119cdf0e10cSrcweir             e.printStackTrace(log) ;
120cdf0e10cSrcweir             res = false ;
121cdf0e10cSrcweir         }
122cdf0e10cSrcweir 
123cdf0e10cSrcweir         tRes.tested("remove()", res) ;
124cdf0e10cSrcweir     }
125cdf0e10cSrcweir 
126cdf0e10cSrcweir     /**
127cdf0e10cSrcweir     * Does nothing. Testing performed in previous methods.<p>
128cdf0e10cSrcweir     * Has <b> OK </b> status if after <code>remove()</code> call
129cdf0e10cSrcweir     * methods returned <code>false</code>, and after <code>remove()</code>
130cdf0e10cSrcweir     * call methods returned <code>true</code>.
131cdf0e10cSrcweir     * The following method tests are to be completed successfully before :
132cdf0e10cSrcweir     * <ul>
133cdf0e10cSrcweir     *  <li> <code> insert() </code> : here the method is checked </li>
134cdf0e10cSrcweir     *  <li> <code> remove() </code> : here the method is checked </li>
135cdf0e10cSrcweir     * </ul>
136cdf0e10cSrcweir     */
_has()137cdf0e10cSrcweir     public void _has() {
138cdf0e10cSrcweir 
139cdf0e10cSrcweir         requiredMethod("insert()") ;
140cdf0e10cSrcweir         requiredMethod("remove()") ;
141cdf0e10cSrcweir 
142cdf0e10cSrcweir         tRes.tested("has()", hasResult) ;
143cdf0e10cSrcweir     }
144cdf0e10cSrcweir 
145cdf0e10cSrcweir } // finished class _XSet
146cdf0e10cSrcweir 
147