Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / qadevOOo / tests / java / ifc / container / _XNameAccess.java
blobbe3909179f3d3250556a55dbca004b32d7e7feb9
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;
35 /**
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;
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>
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);
56 return;
57 } // end getElementNames()
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>
70 public void _hasByName() {
71 requiredMethod("getElementNames()");
72 log.println("testing hasByName() ...");
74 boolean result = true;
75 boolean loc_result = true;
77 String name = null;
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;
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");
94 log.println("hasByName with invalid names: " + loc_result);
95 result &= loc_result;
97 tRes.tested("hasByName()", result);
99 return;
100 } // end hasByName()
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>
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;
125 String name = null;
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;
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";
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;
155 result &= loc_result;
156 tRes.tested("getByName()", result);
158 return;
160 } // end getByName()
161 } /// finished class _XNameAccess