1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 package ifc.container;
29 
30 import lib.MultiMethodTest;
31 
32 import com.sun.star.container.NoSuchElementException;
33 import com.sun.star.container.XNameAccess;
34 
35 /**
36 * Testing <code>com.sun.star.container.XNameAccess</code> interface methods. <p>
37 * Test is <b> NOT </b> multithread compilant. <p>
38 */
39 public class _XNameAccess extends MultiMethodTest {
40     public XNameAccess oObj = null;
41     public String[] Names = null;
42 
43     /**
44     * Test calls the method and checks return value and that
45     * no exceptions were thrown. <p>
46     * Has <b> OK </b> status if the method successfully returns
47     * not null value and no exceptions were thrown. <p>
48     */
49     public void _getElementNames() {
50         boolean result = true;
51         log.println("getting elements names");
52         Names = oObj.getElementNames();
53 
54         result = (Names != null);
55         tRes.tested("getElementNames()", result);
56         return;
57     } // end getElementNames()
58 
59     /**
60     * First test calls the method with existing element name,
61     * then with non existing. <p>
62     * Has <b> OK </b> status if in the first case the method returns
63     * true and in the second - false. <p>
64     * The following method tests are to be completed successfully before :
65     * <ul>
66     *  <li> <code> getElementNames </code> : to retrieve at least one
67     *    element name. </li>
68     * </ul>
69     */
70     public void _hasByName() {
71         requiredMethod("getElementNames()");
72         log.println("testing hasByName() ...");
73 
74         boolean result = true;
75         boolean loc_result = true;
76 
77         String name = null;
78 
79     if (Names.length != 0) {
80             name = Names[0];
81             log.println("testing hasByName() with valid name '" + name + "'");
82             loc_result = oObj.hasByName(name);
83             log.println("hasByName with valid names: " + loc_result);
84             result &= loc_result;
85     }
86 
87     name = "non_existant_name__1234";
88     log.println("testing hasByName() with invalid name");
89         try {
90             loc_result = !oObj.hasByName(name);
91         } catch ( Exception nsee) {
92             log.println("Expected exception was thrown");
93         }
94         log.println("hasByName with invalid names: " + loc_result);
95     result &= loc_result;
96 
97     tRes.tested("hasByName()", result);
98 
99         return;
100     } // end hasByName()
101 
102 
103     /**
104     * First test calls the method with existing element name,
105     * then with non existing. <p>
106     * Has <b> OK </b> status if in the first case the method returns
107     * not null value and no exceptions were thrown,
108     * and in the second case <code>NoSuchElementException</code> was
109     * thrown. <p>
110     * The following method tests are to be completed successfully before :
111     * <ul>
112     *  <li> <code> getElementNames </code> : to retrieve at least one
113     *    element name. </li>
114     * </ul>
115     */
116     public void _getByName() {
117         log.println("reqiure getElementNames() ...");
118         requiredMethod("getElementNames()");
119         log.println("require getElementNames() ...OK");
120         log.println("testing getByName() ...");
121 
122         boolean result = true;
123         boolean loc_result = true;
124 
125         String name = null;
126 
127         if (Names.length != 0) {
128             name = Names[0];
129             log.println("testing with valid name '" + name + "'");
130             try {
131                 loc_result = (null != oObj.getByName(name));
132             } catch (Exception e) {
133                 log.println("Exception! - FAILED");
134                 log.println(e.toString());
135                 loc_result = false;
136             }
137             log.println("getByName with valid name: " + loc_result);
138             result &= loc_result;
139         }
140 
141         log.println("testing with non-existant name");
142         name = "non_existant_name__1234";
143         try {
144             loc_result = (null != oObj.getByName(name));
145             loc_result = false;
146             log.println("getByName: Exception expected - FAILED");
147         } catch (NoSuchElementException e) {
148             log.println("getByName: Expected exception - OK");
149             loc_result = true;
150         } catch (com.sun.star.lang.WrappedTargetException e) {
151             log.println("getByName: Wrong exception - " + e + " - FAILED");
152             loc_result = false;
153         }
154 
155         result &= loc_result;
156         tRes.tested("getByName()", result);
157 
158         return;
159 
160     } // end getByName()
161 } /// finished class _XNameAccess
162 
163 
164 
165