1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XNameAccess.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package ifc
.container
;
33 import lib
.MultiMethodTest
;
35 import com
.sun
.star
.container
.NoSuchElementException
;
36 import com
.sun
.star
.container
.XNameAccess
;
39 * Testing <code>com.sun.star.container.XNameAccess</code> interface methods. <p>
40 * Test is <b> NOT </b> multithread compilant. <p>
42 public class _XNameAccess
extends MultiMethodTest
{
43 public XNameAccess oObj
= null;
44 public String
[] Names
= null;
47 * Test calls the method and checks return value and that
48 * no exceptions were thrown. <p>
49 * Has <b> OK </b> status if the method successfully returns
50 * not null value and no exceptions were thrown. <p>
52 public void _getElementNames() {
53 boolean result
= true;
54 log
.println("getting elements names");
55 Names
= oObj
.getElementNames();
57 result
= (Names
!= null);
58 tRes
.tested("getElementNames()", result
);
60 } // end getElementNames()
63 * First test calls the method with existing element name,
64 * then with non existing. <p>
65 * Has <b> OK </b> status if in the first case the method returns
66 * true and in the second - false. <p>
67 * The following method tests are to be completed successfully before :
69 * <li> <code> getElementNames </code> : to retrieve at least one
73 public void _hasByName() {
74 requiredMethod("getElementNames()");
75 log
.println("testing hasByName() ...");
77 boolean result
= true;
78 boolean loc_result
= true;
82 if (Names
.length
!= 0) {
84 log
.println("testing hasByName() with valid name '" + name
+ "'");
85 loc_result
= oObj
.hasByName(name
);
86 log
.println("hasByName with valid names: " + loc_result
);
90 name
= "non_existant_name__1234";
91 log
.println("testing hasByName() with invalid name");
93 loc_result
= !oObj
.hasByName(name
);
94 } catch ( Exception nsee
) {
95 log
.println("Expected exception was thrown");
97 log
.println("hasByName with invalid names: " + loc_result
);
100 tRes
.tested("hasByName()", result
);
107 * First test calls the method with existing element name,
108 * then with non existing. <p>
109 * Has <b> OK </b> status if in the first case the method returns
110 * not null value and no exceptions were thrown,
111 * and in the second case <code>NoSuchElementException</code> was
113 * The following method tests are to be completed successfully before :
115 * <li> <code> getElementNames </code> : to retrieve at least one
116 * element name. </li>
119 public void _getByName() {
120 log
.println("reqiure getElementNames() ...");
121 requiredMethod("getElementNames()");
122 log
.println("require getElementNames() ...OK");
123 log
.println("testing getByName() ...");
125 boolean result
= true;
126 boolean loc_result
= true;
130 if (Names
.length
!= 0) {
132 log
.println("testing with valid name '" + name
+ "'");
134 loc_result
= (null != oObj
.getByName(name
));
135 } catch (Exception e
) {
136 log
.println("Exception! - FAILED");
137 log
.println(e
.toString());
140 log
.println("getByName with valid name: " + loc_result
);
141 result
&= loc_result
;
144 log
.println("testing with non-existant name");
145 name
= "non_existant_name__1234";
147 loc_result
= (null != oObj
.getByName(name
));
149 log
.println("getByName: Exception expected - FAILED");
150 } catch (NoSuchElementException e
) {
151 log
.println("getByName: Expected exception - OK");
153 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
154 log
.println("getByName: Wrong exception - " + e
+ " - FAILED");
158 result
&= loc_result
;
159 tRes
.tested("getByName()", result
);
164 } /// finished class _XNameAccess