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.XNameAccess;
30 
31 /**
32 * Testing <code>com.sun.star.container.XNameAccess</code> interface methods. <p>
33 * Test is <b> NOT </b> multithread compilant. <p>
34 */
35 public class _XNameAccess extends MultiMethodTest {
36     public XNameAccess oObj = null;
37     public String[] Names = null;
38 
39     /**
40     * Test calls the method and checks return value and that
41     * no exceptions were thrown. <p>
42     * Has <b> OK </b> status if the method successfully returns
43     * not null value and no exceptions were thrown. <p>
44     */
_getElementNames()45     public void _getElementNames() {
46         boolean result = true;
47         log.println("getting elements names");
48         Names = oObj.getElementNames();
49 
50         result = (Names != null);
51         tRes.tested("getElementNames()", result);
52         return;
53     } // end getElementNames()
54 
55     /**
56     * First test calls the method with existing element name,
57     * then with non existing. <p>
58     * Has <b> OK </b> status if in the first case the method returns
59     * true and in the second - false. <p>
60     * The following method tests are to be completed successfully before :
61     * <ul>
62     *  <li> <code> getElementNames </code> : to retrieve at least one
63     *    element name. </li>
64     * </ul>
65     */
_hasByName()66     public void _hasByName() {
67         requiredMethod("getElementNames()");
68         log.println("testing hasByName() ...");
69 
70         boolean result = true;
71         boolean loc_result = true;
72 
73         String name = null;
74 
75     if (Names.length != 0) {
76             name = Names[0];
77             log.println("testing hasByName() with valid name '" + name + "'");
78             loc_result = oObj.hasByName(name);
79             log.println("hasByName with valid names: " + loc_result);
80             result &= loc_result;
81     }
82 
83     name = "non_existant_name__1234";
84     log.println("testing hasByName() with invalid name");
85         try {
86             loc_result = !oObj.hasByName(name);
87         } catch ( Exception nsee) {
88             log.println("Expected exception was thrown");
89         }
90         log.println("hasByName with invalid names: " + loc_result);
91     result &= loc_result;
92 
93     tRes.tested("hasByName()", result);
94 
95         return;
96     } // end hasByName()
97 
98 
99     /**
100     * First test calls the method with existing element name,
101     * then with non existing. <p>
102     * Has <b> OK </b> status if in the first case the method returns
103     * not null value and no exceptions were thrown,
104     * and in the second case <code>NoSuchElementException</code> was
105     * thrown. <p>
106     * The following method tests are to be completed successfully before :
107     * <ul>
108     *  <li> <code> getElementNames </code> : to retrieve at least one
109     *    element name. </li>
110     * </ul>
111     */
_getByName()112     public void _getByName() {
113         log.println("reqiure getElementNames() ...");
114         requiredMethod("getElementNames()");
115         log.println("require getElementNames() ...OK");
116         log.println("testing getByName() ...");
117 
118         boolean result = true;
119         boolean loc_result = true;
120 
121         String name = null;
122 
123         if (Names.length != 0) {
124             name = Names[0];
125             log.println("testing with valid name '" + name + "'");
126             try {
127                 loc_result = (null != oObj.getByName(name));
128             } catch (Exception e) {
129                 log.println("Exception! - FAILED");
130                 log.println(e.toString());
131                 loc_result = false;
132             }
133             log.println("getByName with valid name: " + loc_result);
134             result &= loc_result;
135         }
136 
137         log.println("testing with non-existant name");
138         name = "non_existant_name__1234";
139         try {
140             loc_result = (null != oObj.getByName(name));
141             loc_result = false;
142             log.println("getByName: Exception expected - FAILED");
143         } catch (NoSuchElementException e) {
144             log.println("getByName: Expected exception - OK");
145             loc_result = true;
146         } catch (com.sun.star.lang.WrappedTargetException e) {
147             log.println("getByName: Wrong exception - " + e + " - FAILED");
148             loc_result = false;
149         }
150 
151         result &= loc_result;
152         tRes.tested("getByName()", result);
153 
154         return;
155 
156     } // end getByName()
157 } /// finished class _XNameAccess
158 
159 
160 
161