Update ooo320-m1
[ooovba.git] / qadevOOo / tests / java / ifc / container / _XNameAccess.java
bloba2a1df8264598d79be954f6d2e38086bc1bd1529
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XNameAccess.java,v $
10 * $Revision: 1.5 $
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;
38 /**
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;
46 /**
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);
59 return;
60 } // end getElementNames()
62 /**
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 :
68 * <ul>
69 * <li> <code> getElementNames </code> : to retrieve at least one
70 * element name. </li>
71 * </ul>
73 public void _hasByName() {
74 requiredMethod("getElementNames()");
75 log.println("testing hasByName() ...");
77 boolean result = true;
78 boolean loc_result = true;
80 String name = null;
82 if (Names.length != 0) {
83 name = Names[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);
87 result &= loc_result;
90 name = "non_existant_name__1234";
91 log.println("testing hasByName() with invalid name");
92 try {
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);
98 result &= loc_result;
100 tRes.tested("hasByName()", result);
102 return;
103 } // end hasByName()
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
112 * thrown. <p>
113 * The following method tests are to be completed successfully before :
114 * <ul>
115 * <li> <code> getElementNames </code> : to retrieve at least one
116 * element name. </li>
117 * </ul>
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;
128 String name = null;
130 if (Names.length != 0) {
131 name = Names[0];
132 log.println("testing with valid name '" + name + "'");
133 try {
134 loc_result = (null != oObj.getByName(name));
135 } catch (Exception e) {
136 log.println("Exception! - FAILED");
137 log.println(e.toString());
138 loc_result = false;
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";
146 try {
147 loc_result = (null != oObj.getByName(name));
148 loc_result = false;
149 log.println("getByName: Exception expected - FAILED");
150 } catch (NoSuchElementException e) {
151 log.println("getByName: Expected exception - OK");
152 loc_result = true;
153 } catch (com.sun.star.lang.WrappedTargetException e) {
154 log.println("getByName: Wrong exception - " + e + " - FAILED");
155 loc_result = false;
158 result &= loc_result;
159 tRes.tested("getByName()", result);
161 return;
163 } // end getByName()
164 } /// finished class _XNameAccess