1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 package ifc.container; 24 25 import com.sun.star.container.XNamed; 26 27 import lib.MultiMethodTest; 28 29 import util.utils; 30 31 32 /** 33 * Testing <code>com.sun.star.container.XNamed</code> 34 * interface methods : 35 * <ul> 36 * <li><code> getName()</code></li> 37 * <li><code> setName()</code></li> 38 * </ul> 39 * This test need the following object relations : 40 * <ul> 41 * <li> <code>'setName'</code> : of <code>Boolean</code> 42 * type. If it exists then <code>setName</code> method 43 * isn't to be tested and result of this test will be 44 * equal to relation value.</li> 45 * <ul> <p> 46 * Test is <b> NOT </b> multithread compilant. <p> 47 * @see com.sun.star.container.XNamed 48 */ 49 public class _XNamed extends MultiMethodTest { 50 public XNamed oObj = null; // oObj filled by MultiMethodTest 51 52 /** 53 * Test calls the method and checks return value and that 54 * no exceptions were thrown. <p> 55 * Has <b> OK </b> status if the method returns non null value 56 * and no exceptions were thrown. <p> 57 */ _getName()58 public void _getName() { 59 // write to log what we try next 60 log.println("test for getName()"); 61 62 boolean result = true; 63 boolean loc_result = true; 64 String name = null; 65 66 loc_result = ((name = oObj.getName()) != null); 67 log.println("getting the name \"" + name + "\""); 68 69 if (loc_result) { 70 log.println("... getName() - OK"); 71 } else { 72 log.println("... getName() - FAILED"); 73 } 74 75 result &= loc_result; 76 tRes.tested("getName()", result); 77 } 78 79 /** 80 * Sets a new name for object and checks if it was properly 81 * set. Special cases for the following objects : 82 * <ul> 83 * <li><code>ScSheetLinkObj</code> : name must be in form of URL.</li> 84 * <li><code>ScDDELinkObj</code> : name must contain link to cell in 85 * some external Sheet.</li> 86 * </ul> 87 * Has <b> OK </b> status if new name was successfully set, or if 88 * object environment contains relation <code>'setName'</code> with 89 * value <code>true</code>. <p> 90 * The following method tests are to be completed successfully before : 91 * <ul> 92 * <li> <code> getName() </code> : to be sure the method works</li> 93 * </ul> 94 */ _setName()95 public void _setName() { 96 String Oname = tEnv.getTestCase().getObjectName(); 97 String nsn = (String) tEnv.getObjRelation("NoSetName"); 98 99 if (nsn != null) { 100 Oname = nsn; 101 } 102 103 if ((Oname.indexOf("Exporter") > 0) || (nsn != null)) { 104 log.println("With " + Oname + " setName() doesn't work"); 105 log.println("see idl-file for further information"); 106 tRes.tested("setName()", true); 107 108 return; 109 } 110 111 requiredMethod("getName()"); 112 log.println("testing setName() ... "); 113 114 String oldName = oObj.getName(); 115 String NewName = (oldName == null) ? "XNamed" : oldName + "X"; 116 117 String testobjname = tEnv.getTestCase().getObjectName(); 118 119 if (testobjname.equals("ScSheetLinkObj")) { 120 // special case, here name is equals to links URL. 121 NewName = "file:///c:/somename/from/XNamed"; 122 } else if (testobjname.equals("ScDDELinkObj")) { 123 String fileName = utils.getFullTestDocName("ScDDELinksObj.sdc"); 124 NewName = "soffice|" + fileName + "!Sheet1.A2"; 125 } else if (testobjname.equals("SwXAutoTextGroup")) { 126 //This avoids a GPF 127 NewName = "XNamed*1"; 128 } 129 130 boolean result = true; 131 boolean loc_result = true; 132 Boolean sName = (Boolean) tEnv.getObjRelation("setName"); 133 134 if (sName == null) { 135 log.println("set the name of object to \"" + NewName + "\""); 136 oObj.setName(NewName); 137 log.println("check that container has element with this name"); 138 139 String name = oObj.getName(); 140 log.println("getting the name \"" + name + "\""); 141 loc_result = name.equals(NewName); 142 143 if (loc_result) { 144 log.println("... setName() - OK"); 145 } else { 146 log.println("... setName() - FAILED"); 147 } 148 149 result &= loc_result; 150 oObj.setName(oldName); 151 } else { 152 log.println("The names for the object '" + testobjname + 153 "' are fixed."); 154 log.println("It is not possible to rename."); 155 log.println("So 'setName()' is always OK"); 156 result = sName.booleanValue(); 157 } 158 159 tRes.tested("setName()", result); 160 } 161 }