cid#1607171 Data race condition
[LibreOffice.git] / qadevOOo / tests / java / ifc / container / _XNamed.java
blob054306f40a1cbbbee9349cc68ccbffc30f504acc
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 .
18 package ifc.container;
20 import com.sun.star.container.XNamed;
22 import lib.MultiMethodTest;
24 import util.utils;
27 /**
28 * Testing <code>com.sun.star.container.XNamed</code>
29 * interface methods :
30 * <ul>
31 * <li><code> getName()</code></li>
32 * <li><code> setName()</code></li>
33 * </ul>
34 * This test need the following object relations :
35 * <ul>
36 * <li> <code>'setName'</code> : of <code>Boolean</code>
37 * type. If it exists then <code>setName</code> method
38 * isn't to be tested and result of this test will be
39 * equal to relation value.</li>
40 * <ul> <p>
41 * Test is <b> NOT </b> multithread compliant. <p>
42 * @see com.sun.star.container.XNamed
44 public class _XNamed extends MultiMethodTest {
45 public XNamed oObj = null; // oObj filled by MultiMethodTest
47 /**
48 * Test calls the method and checks return value and that
49 * no exceptions were thrown. <p>
50 * Has <b> OK </b> status if the method returns non null value
51 * and no exceptions were thrown. <p>
53 public void _getName() {
54 // write to log what we try next
55 log.println("test for getName()");
57 boolean result = true;
58 boolean loc_result = true;
59 String name = null;
61 loc_result = ((name = oObj.getName()) != null);
62 log.println("getting the name \"" + name + "\"");
64 if (loc_result) {
65 log.println("... getName() - OK");
66 } else {
67 log.println("... getName() - FAILED");
70 result &= loc_result;
71 tRes.tested("getName()", result);
74 /**
75 * Sets a new name for object and checks if it was properly
76 * set. Special cases for the following objects :
77 * <ul>
78 * <li><code>ScSheetLinkObj</code> : name must be in form of URL.</li>
79 * <li><code>ScDDELinkObj</code> : name must contain link to cell in
80 * some external Sheet.</li>
81 * </ul>
82 * Has <b> OK </b> status if new name was successfully set, or if
83 * object environment contains relation <code>'setName'</code> with
84 * value <code>true</code>. <p>
85 * The following method tests are to be completed successfully before :
86 * <ul>
87 * <li> <code> getName() </code> : to be sure the method works</li>
88 * </ul>
90 public void _setName() {
91 String Oname = tEnv.getTestCase().getObjectName();
92 String nsn = (String) tEnv.getObjRelation("NoSetName");
94 if (nsn != null) {
95 Oname = nsn;
98 if ((Oname.indexOf("Exporter") > 0) || (nsn != null)) {
99 log.println("With " + Oname + " setName() doesn't work");
100 log.println("see idl-file for further information");
101 tRes.tested("setName()", true);
103 return;
106 requiredMethod("getName()");
107 log.println("testing setName() ... ");
109 String oldName = oObj.getName();
110 String NewName = (oldName == null) ? "XNamed" : oldName + "X";
112 String testobjname = tEnv.getTestCase().getObjectName();
114 if (testobjname.equals("ScSheetLinkObj")) {
115 // special case, here name is equals to links URL.
116 NewName = "file:///c:/somename/from/XNamed";
117 } else if (testobjname.equals("ScDDELinkObj")) {
118 String fileName = utils.getFullTestDocName("ScDDELinksObj.ods");
119 NewName = "soffice|" + fileName + "!Sheet1.A2";
120 } else if (testobjname.equals("SwXAutoTextGroup")) {
121 //This avoids a GPF
122 NewName = "XNamed*1";
125 boolean result = true;
126 boolean loc_result = true;
127 Boolean sName = (Boolean) tEnv.getObjRelation("setName");
129 if (sName == null) {
130 log.println("set the name of object to \"" + NewName + "\"");
131 oObj.setName(NewName);
132 log.println("check that container has element with this name");
134 String name = oObj.getName();
135 log.println("getting the name \"" + name + "\"");
136 loc_result = name.equals(NewName);
138 if (loc_result) {
139 log.println("... setName() - OK");
140 } else {
141 log.println("... setName() - FAILED");
144 result &= loc_result;
145 oObj.setName(oldName);
146 } else {
147 log.println("The names for the object '" + testobjname +
148 "' are fixed.");
149 log.println("It is not possible to rename.");
150 log.println("So 'setName()' is always OK");
151 result = sName.booleanValue();
154 tRes.tested("setName()", result);