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.XSet;
29 import com.sun.star.lang.XMultiServiceFactory;
30 
31 /**
32 * Testing <code>com.sun.star.container.XSet</code>
33 * interface methods :
34 * <ul>
35 *  <li><code> has()</code></li>
36 *  <li><code> insert()</code></li>
37 *  <li><code> remove()</code></li>
38 * </ul> <p>
39 * Test is <b> NOT </b> multithread compilant. <p>
40 * @see com.sun.star.container.XSet
41 */
42 public class _XSet extends MultiMethodTest {
43 
44     public static XSet oObj = null;
45 
46     private Object element = null ;
47     private boolean hasResult = true ;
48 
49     /**
50     * Inserts the element stored and removed before. <p>
51     * Has <b> OK </b> status if <code>has()</code> method returns
52     * <code>true</code>.
53     * The following method tests are to be completed successfully before :
54     * <ul>
55     *  <li> <code> remove() </code> : element from set is stored and
56     *    removed </li>
57     * </ul>
58     */
_insert()59     public void _insert() {
60         boolean res = true ;
61         try {
62             XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF();
63             element = xMSF.createInstance(
64                             "com.sun.star.reflection.TypeDescriptionProvider");
65 
66 
67             oObj.insert(element) ;
68 
69             if (!oObj.has(element)) {
70                 res = false ;
71                 log.println("After adding element method has()" +
72                     " returned false") ;
73                 hasResult = false ;
74             }
75         } catch (com.sun.star.container.ElementExistException e) {
76             e.printStackTrace(log) ;
77             res = false ;
78         } catch (com.sun.star.lang.IllegalArgumentException e) {
79             e.printStackTrace(log) ;
80             res = false ;
81         }
82         catch(com.sun.star.uno.Exception e) {
83             e.printStackTrace(log);
84             res = false;
85         }
86 
87         tRes.tested("insert()", res) ;
88     }
89 
90     /**
91     * Through <code>XEnumeration</code> interface an element from the set
92     * is retrieved. Then this element removed.<p>
93     * Has <b> OK </b> status if after removing <code>has()</code> method
94     * returns false.
95     */
_remove()96     public void _remove() {
97         requiredMethod("insert()");
98         boolean res = true ;
99 
100         try {
101 
102             // get an element to be removed/inserted
103 
104             oObj.remove(element) ;
105 
106             if (oObj.has(element)) {
107                 res = false ;
108                 log.println("After removing element method has()" +
109                     " returned true") ;
110                 hasResult = false ;
111             }
112 
113 
114 
115         } catch (com.sun.star.container.NoSuchElementException e) {
116             e.printStackTrace(log) ;
117             res = false ;
118         } catch (com.sun.star.lang.IllegalArgumentException e) {
119             e.printStackTrace(log) ;
120             res = false ;
121         }
122 
123         tRes.tested("remove()", res) ;
124     }
125 
126     /**
127     * Does nothing. Testing performed in previous methods.<p>
128     * Has <b> OK </b> status if after <code>remove()</code> call
129     * methods returned <code>false</code>, and after <code>remove()</code>
130     * call methods returned <code>true</code>.
131     * The following method tests are to be completed successfully before :
132     * <ul>
133     *  <li> <code> insert() </code> : here the method is checked </li>
134     *  <li> <code> remove() </code> : here the method is checked </li>
135     * </ul>
136     */
_has()137     public void _has() {
138 
139         requiredMethod("insert()") ;
140         requiredMethod("remove()") ;
141 
142         tRes.tested("has()", hasResult) ;
143     }
144 
145 } // finished class _XSet
146 
147