1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 package ifc
.container
;
30 import lib
.MultiMethodTest
;
32 import com
.sun
.star
.container
.NoSuchElementException
;
33 import com
.sun
.star
.container
.XNameAccess
;
36 * Testing <code>com.sun.star.container.XNameAccess</code> interface methods. <p>
37 * Test is <b> NOT </b> multithread compilant. <p>
39 public class _XNameAccess
extends MultiMethodTest
{
40 public XNameAccess oObj
= null;
41 public String
[] Names
= null;
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>
49 public void _getElementNames() {
50 boolean result
= true;
51 log
.println("getting elements names");
52 Names
= oObj
.getElementNames();
54 result
= (Names
!= null);
55 tRes
.tested("getElementNames()", result
);
57 } // end getElementNames()
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 :
66 * <li> <code> getElementNames </code> : to retrieve at least one
70 public void _hasByName() {
71 requiredMethod("getElementNames()");
72 log
.println("testing hasByName() ...");
74 boolean result
= true;
75 boolean loc_result
= true;
79 if (Names
.length
!= 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
);
87 name
= "non_existant_name__1234";
88 log
.println("testing hasByName() with invalid name");
90 loc_result
= !oObj
.hasByName(name
);
91 } catch ( Exception nsee
) {
92 log
.println("Expected exception was thrown");
94 log
.println("hasByName with invalid names: " + loc_result
);
97 tRes
.tested("hasByName()", result
);
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
110 * The following method tests are to be completed successfully before :
112 * <li> <code> getElementNames </code> : to retrieve at least one
113 * element name. </li>
116 public void _getByName() {
117 log
.println("reqiure getElementNames() ...");
118 requiredMethod("getElementNames()");
119 log
.println("require getElementNames() ...OK");
120 log
.println("testing getByName() ...");
122 boolean result
= true;
123 boolean loc_result
= true;
127 if (Names
.length
!= 0) {
129 log
.println("testing with valid name '" + name
+ "'");
131 loc_result
= (null != oObj
.getByName(name
));
132 } catch (Exception e
) {
133 log
.println("Exception! - FAILED");
134 log
.println(e
.toString());
137 log
.println("getByName with valid name: " + loc_result
);
138 result
&= loc_result
;
141 log
.println("testing with non-existant name");
142 name
= "non_existant_name__1234";
144 loc_result
= (null != oObj
.getByName(name
));
146 log
.println("getByName: Exception expected - FAILED");
147 } catch (NoSuchElementException e
) {
148 log
.println("getByName: Expected exception - OK");
150 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
151 log
.println("getByName: Wrong exception - " + e
+ " - FAILED");
155 result
&= loc_result
;
156 tRes
.tested("getByName()", result
);
161 } /// finished class _XNameAccess