bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / ifc / container / _XNameAccess.java
blobf5d315a5d5d3989b8f848f0ae5783389dc15fb32
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package ifc.container;
21 import lib.MultiMethodTest;
23 import com.sun.star.container.NoSuchElementException;
24 import com.sun.star.container.XNameAccess;
26 /**
27 * Testing <code>com.sun.star.container.XNameAccess</code> interface methods. <p>
28 * Test is <b> NOT </b> multithread compilant. <p>
30 public class _XNameAccess extends MultiMethodTest {
31 public XNameAccess oObj = null;
32 public String[] Names = null;
34 /**
35 * Test calls the method and checks return value and that
36 * no exceptions were thrown. <p>
37 * Has <b> OK </b> status if the method successfully returns
38 * not null value and no exceptions were thrown. <p>
40 public void _getElementNames() {
41 boolean result = true;
42 log.println("getting elements names");
43 Names = oObj.getElementNames();
45 result = (Names != null);
46 tRes.tested("getElementNames()", result);
47 return;
48 } // end getElementNames()
50 /**
51 * First test calls the method with existing element name,
52 * then with non existing. <p>
53 * Has <b> OK </b> status if in the first case the method returns
54 * true and in the second - false. <p>
55 * The following method tests are to be completed successfully before :
56 * <ul>
57 * <li> <code> getElementNames </code> : to retrieve at least one
58 * element name. </li>
59 * </ul>
61 public void _hasByName() {
62 requiredMethod("getElementNames()");
63 log.println("testing hasByName() ...");
65 boolean result = true;
66 boolean loc_result = true;
68 String name = null;
70 if (Names.length != 0) {
71 name = Names[0];
72 log.println("testing hasByName() with valid name '" + name + "'");
73 loc_result = oObj.hasByName(name);
74 log.println("hasByName with valid names: " + loc_result);
75 result &= loc_result;
78 name = "non_existant_name__1234";
79 log.println("testing hasByName() with invalid name");
80 try {
81 loc_result = !oObj.hasByName(name);
82 } catch ( Exception nsee) {
83 log.println("Expected exception was thrown");
85 log.println("hasByName with invalid names: " + loc_result);
86 result &= loc_result;
88 tRes.tested("hasByName()", result);
90 return;
91 } // end hasByName()
94 /**
95 * First test calls the method with existing element name,
96 * then with non existing. <p>
97 * Has <b> OK </b> status if in the first case the method returns
98 * not null value and no exceptions were thrown,
99 * and in the second case <code>NoSuchElementException</code> was
100 * thrown. <p>
101 * The following method tests are to be completed successfully before :
102 * <ul>
103 * <li> <code> getElementNames </code> : to retrieve at least one
104 * element name. </li>
105 * </ul>
107 public void _getByName() {
108 log.println("reqiure getElementNames() ...");
109 requiredMethod("getElementNames()");
110 log.println("require getElementNames() ...OK");
111 log.println("testing getByName() ...");
113 boolean result = true;
114 boolean loc_result = true;
116 String name = null;
118 if (Names.length != 0) {
119 name = Names[0];
120 log.println("testing with valid name '" + name + "'");
121 try {
122 loc_result = (null != oObj.getByName(name));
123 } catch (Exception e) {
124 log.println("Exception! - FAILED");
125 log.println(e.toString());
126 loc_result = false;
128 log.println("getByName with valid name: " + loc_result);
129 result &= loc_result;
132 log.println("testing with non-existant name");
133 name = "non_existant_name__1234";
134 try {
135 loc_result = (null != oObj.getByName(name));
136 loc_result = false;
137 log.println("getByName: Exception expected - FAILED");
138 } catch (NoSuchElementException e) {
139 log.println("getByName: Expected exception - OK");
140 loc_result = true;
141 } catch (com.sun.star.lang.WrappedTargetException e) {
142 log.println("getByName: Wrong exception - " + e + " - FAILED");
143 loc_result = false;
146 result &= loc_result;
147 tRes.tested("getByName()", result);
149 return;
151 } // end getByName()
152 } /// finished class _XNameAccess