Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / ifc / container / _XNameAccess.java
blob52f2024850f12c4cbfa1e133e25bf1141790272f
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 compliant. <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 } // end getElementNames()
49 /**
50 * First test calls the method with existing element name,
51 * then with non existing. <p>
52 * Has <b> OK </b> status if in the first case the method returns
53 * true and in the second - false. <p>
54 * The following method tests are to be completed successfully before :
55 * <ul>
56 * <li> <code> getElementNames </code> : to retrieve at least one
57 * element name. </li>
58 * </ul>
60 public void _hasByName() {
61 requiredMethod("getElementNames()");
62 log.println("testing hasByName() ...");
64 boolean result = true;
65 boolean loc_result = true;
67 String name = null;
69 if (Names.length != 0) {
70 name = Names[0];
71 log.println("testing hasByName() with valid name '" + name + "'");
72 loc_result = oObj.hasByName(name);
73 log.println("hasByName with valid names: " + loc_result);
74 result &= loc_result;
77 name = "non_existent_name__1234";
78 log.println("testing hasByName() with invalid name");
79 try {
80 loc_result = !oObj.hasByName(name);
81 } catch ( Exception nsee) {
82 log.println("Expected exception was thrown");
84 log.println("hasByName with invalid names: " + loc_result);
85 result &= loc_result;
87 tRes.tested("hasByName()", result);
88 } // end hasByName()
91 /**
92 * First test calls the method with existing element name,
93 * then with non existing. <p>
94 * Has <b> OK </b> status if in the first case the method returns
95 * not null value and no exceptions were thrown,
96 * and in the second case <code>NoSuchElementException</code> was
97 * thrown. <p>
98 * The following method tests are to be completed successfully before :
99 * <ul>
100 * <li> <code> getElementNames </code> : to retrieve at least one
101 * element name. </li>
102 * </ul>
104 public void _getByName() {
105 log.println("reqiure getElementNames() ...");
106 requiredMethod("getElementNames()");
107 log.println("require getElementNames() ...OK");
108 log.println("testing getByName() ...");
110 boolean result = true;
111 boolean loc_result = true;
113 String name = null;
115 if (Names.length != 0) {
116 name = Names[0];
117 log.println("testing with valid name '" + name + "'");
118 try {
119 loc_result = (null != oObj.getByName(name));
120 } catch (Exception e) {
121 log.println("Exception! - FAILED");
122 log.println(e.toString());
123 loc_result = false;
125 log.println("getByName with valid name: " + loc_result);
126 result &= loc_result;
129 log.println("testing with non-existent name");
130 name = "non_existent_name__1234";
131 try {
132 loc_result = (null != oObj.getByName(name));
133 loc_result = false;
134 log.println("getByName: Exception expected - FAILED");
135 } catch (NoSuchElementException e) {
136 log.println("getByName: Expected exception - OK");
137 loc_result = true;
138 } catch (com.sun.star.lang.WrappedTargetException e) {
139 log.println("getByName: Wrong exception - " + e + " - FAILED");
140 loc_result = false;
143 result &= loc_result;
144 tRes.tested("getByName()", result);
145 } // end getByName()
146 } /// finished class _XNameAccess