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
;
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;
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
);
48 } // end getElementNames()
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 :
57 * <li> <code> getElementNames </code> : to retrieve at least one
61 public void _hasByName() {
62 requiredMethod("getElementNames()");
63 log
.println("testing hasByName() ...");
65 boolean result
= true;
66 boolean loc_result
= true;
70 if (Names
.length
!= 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
);
78 name
= "non_existant_name__1234";
79 log
.println("testing hasByName() with invalid name");
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
);
88 tRes
.tested("hasByName()", result
);
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
101 * The following method tests are to be completed successfully before :
103 * <li> <code> getElementNames </code> : to retrieve at least one
104 * element name. </li>
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;
118 if (Names
.length
!= 0) {
120 log
.println("testing with valid name '" + name
+ "'");
122 loc_result
= (null != oObj
.getByName(name
));
123 } catch (Exception e
) {
124 log
.println("Exception! - FAILED");
125 log
.println(e
.toString());
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";
135 loc_result
= (null != oObj
.getByName(name
));
137 log
.println("getByName: Exception expected - FAILED");
138 } catch (NoSuchElementException e
) {
139 log
.println("getByName: Expected exception - OK");
141 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
142 log
.println("getByName: Wrong exception - " + e
+ " - FAILED");
146 result
&= loc_result
;
147 tRes
.tested("getByName()", result
);
152 } /// finished class _XNameAccess