1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XNamed.java,v $
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 ************************************************************************/
30 package ifc
.container
;
32 import com
.sun
.star
.container
.XNamed
;
34 import lib
.MultiMethodTest
;
40 * Testing <code>com.sun.star.container.XNamed</code>
43 * <li><code> getName()</code></li>
44 * <li><code> setName()</code></li>
46 * This test need the following object relations :
48 * <li> <code>'setName'</code> : of <code>Boolean</code>
49 * type. If it exists then <code>setName</code> method
50 * isn't to be tested and result of this test will be
51 * equal to relation value.</li>
53 * Test is <b> NOT </b> multithread compilant. <p>
54 * @see com.sun.star.container.XNamed
56 public class _XNamed
extends MultiMethodTest
{
57 public XNamed oObj
= null; // oObj filled by MultiMethodTest
60 * Test calls the method and checks return value and that
61 * no exceptions were thrown. <p>
62 * Has <b> OK </b> status if the method returns non null value
63 * and no exceptions were thrown. <p>
65 public void _getName() {
66 // write to log what we try next
67 log
.println("test for getName()");
69 boolean result
= true;
70 boolean loc_result
= true;
73 loc_result
= ((name
= oObj
.getName()) != null);
74 log
.println("getting the name \"" + name
+ "\"");
77 log
.println("... getName() - OK");
79 log
.println("... getName() - FAILED");
83 tRes
.tested("getName()", result
);
87 * Sets a new name for object and checks if it was properly
88 * set. Special cases for the following objects :
90 * <li><code>ScSheetLinkObj</code> : name must be in form of URL.</li>
91 * <li><code>ScDDELinkObj</code> : name must contain link to cell in
92 * some external Sheet.</li>
94 * Has <b> OK </b> status if new name was successfully set, or if
95 * object environment contains relation <code>'setName'</code> with
96 * value <code>true</code>. <p>
97 * The following method tests are to be completed successfully before :
99 * <li> <code> getName() </code> : to be sure the method works</li>
102 public void _setName() {
103 String Oname
= tEnv
.getTestCase().getObjectName();
104 String nsn
= (String
) tEnv
.getObjRelation("NoSetName");
110 if ((Oname
.indexOf("Exporter") > 0) || (nsn
!= null)) {
111 log
.println("With " + Oname
+ " setName() doesn't work");
112 log
.println("see idl-file for further information");
113 tRes
.tested("setName()", true);
118 requiredMethod("getName()");
119 log
.println("testing setName() ... ");
121 String oldName
= oObj
.getName();
122 String NewName
= (oldName
== null) ?
"XNamed" : oldName
+ "X";
124 String testobjname
= tEnv
.getTestCase().getObjectName();
126 if (testobjname
.equals("ScSheetLinkObj")) {
127 // special case, here name is equals to links URL.
128 NewName
= "file:///c:/somename/from/XNamed";
129 } else if (testobjname
.equals("ScDDELinkObj")) {
130 String fileName
= utils
.getFullTestDocName("ScDDELinksObj.sdc");
131 NewName
= "soffice|" + fileName
+ "!Sheet1.A2";
132 } else if (testobjname
.equals("SwXAutoTextGroup")) {
134 NewName
= "XNamed*1";
137 boolean result
= true;
138 boolean loc_result
= true;
139 Boolean sName
= (Boolean
) tEnv
.getObjRelation("setName");
142 log
.println("set the name of object to \"" + NewName
+ "\"");
143 oObj
.setName(NewName
);
144 log
.println("check that container has element with this name");
146 String name
= oObj
.getName();
147 log
.println("getting the name \"" + name
+ "\"");
148 loc_result
= name
.equals(NewName
);
151 log
.println("... setName() - OK");
153 log
.println("... setName() - FAILED");
156 result
&= loc_result
;
157 oObj
.setName(oldName
);
159 log
.println("The names for the object '" + testobjname
+
161 log
.println("It is not possible to rename.");
162 log
.println("So 'setName()' is always OK");
163 result
= sName
.booleanValue();
166 tRes
.tested("setName()", result
);