1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir package ifc.container; 28*cdf0e10cSrcweir 29*cdf0e10cSrcweir import com.sun.star.container.XNamed; 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir import lib.MultiMethodTest; 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir import util.utils; 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir /** 37*cdf0e10cSrcweir * Testing <code>com.sun.star.container.XNamed</code> 38*cdf0e10cSrcweir * interface methods : 39*cdf0e10cSrcweir * <ul> 40*cdf0e10cSrcweir * <li><code> getName()</code></li> 41*cdf0e10cSrcweir * <li><code> setName()</code></li> 42*cdf0e10cSrcweir * </ul> 43*cdf0e10cSrcweir * This test need the following object relations : 44*cdf0e10cSrcweir * <ul> 45*cdf0e10cSrcweir * <li> <code>'setName'</code> : of <code>Boolean</code> 46*cdf0e10cSrcweir * type. If it exists then <code>setName</code> method 47*cdf0e10cSrcweir * isn't to be tested and result of this test will be 48*cdf0e10cSrcweir * equal to relation value.</li> 49*cdf0e10cSrcweir * <ul> <p> 50*cdf0e10cSrcweir * Test is <b> NOT </b> multithread compilant. <p> 51*cdf0e10cSrcweir * @see com.sun.star.container.XNamed 52*cdf0e10cSrcweir */ 53*cdf0e10cSrcweir public class _XNamed extends MultiMethodTest { 54*cdf0e10cSrcweir public XNamed oObj = null; // oObj filled by MultiMethodTest 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir /** 57*cdf0e10cSrcweir * Test calls the method and checks return value and that 58*cdf0e10cSrcweir * no exceptions were thrown. <p> 59*cdf0e10cSrcweir * Has <b> OK </b> status if the method returns non null value 60*cdf0e10cSrcweir * and no exceptions were thrown. <p> 61*cdf0e10cSrcweir */ 62*cdf0e10cSrcweir public void _getName() { 63*cdf0e10cSrcweir // write to log what we try next 64*cdf0e10cSrcweir log.println("test for getName()"); 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir boolean result = true; 67*cdf0e10cSrcweir boolean loc_result = true; 68*cdf0e10cSrcweir String name = null; 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir loc_result = ((name = oObj.getName()) != null); 71*cdf0e10cSrcweir log.println("getting the name \"" + name + "\""); 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir if (loc_result) { 74*cdf0e10cSrcweir log.println("... getName() - OK"); 75*cdf0e10cSrcweir } else { 76*cdf0e10cSrcweir log.println("... getName() - FAILED"); 77*cdf0e10cSrcweir } 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir result &= loc_result; 80*cdf0e10cSrcweir tRes.tested("getName()", result); 81*cdf0e10cSrcweir } 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir /** 84*cdf0e10cSrcweir * Sets a new name for object and checks if it was properly 85*cdf0e10cSrcweir * set. Special cases for the following objects : 86*cdf0e10cSrcweir * <ul> 87*cdf0e10cSrcweir * <li><code>ScSheetLinkObj</code> : name must be in form of URL.</li> 88*cdf0e10cSrcweir * <li><code>ScDDELinkObj</code> : name must contain link to cell in 89*cdf0e10cSrcweir * some external Sheet.</li> 90*cdf0e10cSrcweir * </ul> 91*cdf0e10cSrcweir * Has <b> OK </b> status if new name was successfully set, or if 92*cdf0e10cSrcweir * object environment contains relation <code>'setName'</code> with 93*cdf0e10cSrcweir * value <code>true</code>. <p> 94*cdf0e10cSrcweir * The following method tests are to be completed successfully before : 95*cdf0e10cSrcweir * <ul> 96*cdf0e10cSrcweir * <li> <code> getName() </code> : to be sure the method works</li> 97*cdf0e10cSrcweir * </ul> 98*cdf0e10cSrcweir */ 99*cdf0e10cSrcweir public void _setName() { 100*cdf0e10cSrcweir String Oname = tEnv.getTestCase().getObjectName(); 101*cdf0e10cSrcweir String nsn = (String) tEnv.getObjRelation("NoSetName"); 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir if (nsn != null) { 104*cdf0e10cSrcweir Oname = nsn; 105*cdf0e10cSrcweir } 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir if ((Oname.indexOf("Exporter") > 0) || (nsn != null)) { 108*cdf0e10cSrcweir log.println("With " + Oname + " setName() doesn't work"); 109*cdf0e10cSrcweir log.println("see idl-file for further information"); 110*cdf0e10cSrcweir tRes.tested("setName()", true); 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir return; 113*cdf0e10cSrcweir } 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir requiredMethod("getName()"); 116*cdf0e10cSrcweir log.println("testing setName() ... "); 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir String oldName = oObj.getName(); 119*cdf0e10cSrcweir String NewName = (oldName == null) ? "XNamed" : oldName + "X"; 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir String testobjname = tEnv.getTestCase().getObjectName(); 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir if (testobjname.equals("ScSheetLinkObj")) { 124*cdf0e10cSrcweir // special case, here name is equals to links URL. 125*cdf0e10cSrcweir NewName = "file:///c:/somename/from/XNamed"; 126*cdf0e10cSrcweir } else if (testobjname.equals("ScDDELinkObj")) { 127*cdf0e10cSrcweir String fileName = utils.getFullTestDocName("ScDDELinksObj.sdc"); 128*cdf0e10cSrcweir NewName = "soffice|" + fileName + "!Sheet1.A2"; 129*cdf0e10cSrcweir } else if (testobjname.equals("SwXAutoTextGroup")) { 130*cdf0e10cSrcweir //This avoids a GPF 131*cdf0e10cSrcweir NewName = "XNamed*1"; 132*cdf0e10cSrcweir } 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir boolean result = true; 135*cdf0e10cSrcweir boolean loc_result = true; 136*cdf0e10cSrcweir Boolean sName = (Boolean) tEnv.getObjRelation("setName"); 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir if (sName == null) { 139*cdf0e10cSrcweir log.println("set the name of object to \"" + NewName + "\""); 140*cdf0e10cSrcweir oObj.setName(NewName); 141*cdf0e10cSrcweir log.println("check that container has element with this name"); 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir String name = oObj.getName(); 144*cdf0e10cSrcweir log.println("getting the name \"" + name + "\""); 145*cdf0e10cSrcweir loc_result = name.equals(NewName); 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir if (loc_result) { 148*cdf0e10cSrcweir log.println("... setName() - OK"); 149*cdf0e10cSrcweir } else { 150*cdf0e10cSrcweir log.println("... setName() - FAILED"); 151*cdf0e10cSrcweir } 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir result &= loc_result; 154*cdf0e10cSrcweir oObj.setName(oldName); 155*cdf0e10cSrcweir } else { 156*cdf0e10cSrcweir log.println("The names for the object '" + testobjname + 157*cdf0e10cSrcweir "' are fixed."); 158*cdf0e10cSrcweir log.println("It is not possible to rename."); 159*cdf0e10cSrcweir log.println("So 'setName()' is always OK"); 160*cdf0e10cSrcweir result = sName.booleanValue(); 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir tRes.tested("setName()", result); 164*cdf0e10cSrcweir } 165*cdf0e10cSrcweir }