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