1 /* 2 * This file is part of the LibreOffice project. 3 * 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/. 7 * 8 * This file incorporates work covered by the following license notice: 9 * 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 . 17 */ 18 19 package complex.dataPilot; 20 21 import com.sun.star.container.XNamed; 22 import lib.TestParameters; 23 24 /** 25 * Testing <code>com.sun.star.container.XNamed</code> 26 * interface methods : 27 * <ul> 28 * <li><code> getName()</code></li> 29 * <li><code> setName()</code></li> 30 * </ul> 31 * This test need the following object relations : 32 * <ul> 33 * <li> <code>'setName'</code> : of <code>Boolean</code> 34 * type. If it exists then <code>setName</code> method 35 * isn't to be tested and result of this test will be 36 * equal to relation value.</li> 37 * <ul> <p> 38 * Test is <b> NOT </b> multithread compliant. <p> 39 * @see com.sun.star.container.XNamed 40 */ 41 public class _XNamed { 42 43 /** 44 * The object that is testsed. 45 */ 46 private final XNamed oObj; 47 48 /** 49 * Constructor: gets the object to test, a logger and the test parameters 50 * @param xObj The test object 51 * @param param The test parameters 52 */ _XNamed(XNamed xObj , TestParameters param)53 public _XNamed(XNamed xObj/*, LogWriter log*/, TestParameters param) { 54 oObj = xObj; 55 } 56 57 /** 58 * Test calls the method and checks return value and that 59 * no exceptions were thrown. <p> 60 * Has <b> OK </b> status if the method returns non null value 61 * and no exceptions were thrown. <p> 62 */ _getName()63 public boolean _getName() { 64 65 // write to log what we try next 66 System.out.println( "test for getName()" ); 67 68 boolean result = true; 69 boolean loc_result = true; 70 String name = null; 71 72 loc_result = ((name = oObj.getName()) != null); 73 System.out.println("getting the name \"" + name + "\""); 74 75 if (loc_result) 76 { 77 System.out.println("... getName() - OK"); 78 } 79 else 80 { 81 System.out.println("... getName() - FAILED"); 82 } 83 result &= loc_result; 84 return result; 85 } 86 87 /** 88 * Sets a new name for object and checks if it was properly 89 * set. Special cases for the following objects : 90 * <ul> 91 * <li><code>ScSheetLinkObj</code> : name must be in form of URL.</li> 92 * <li><code>ScDDELinkObj</code> : name must contain link to cell in 93 * some external Sheet.</li> 94 * </ul> 95 * Has <b> OK </b> status if new name was successfully set, or if 96 * object environment contains relation <code>'setName'</code> with 97 * value <code>true</code>. <p> 98 * The following method tests are to be completed successfully before : 99 * <ul> 100 * <li> <code> getName() </code> : to be sure the method works</li> 101 * </ul> 102 */ _setName()103 public boolean _setName(){ 104 System.out.println("testing setName() ... "); 105 106 String oldName = oObj.getName(); 107 String NewName = oldName == null ? "XNamed" : oldName + "X" ; 108 109 boolean result = true; 110 boolean loc_result = true; 111 System.out.println("set the name of object to \"" + NewName + "\""); 112 oObj.setName(NewName); 113 System.out.println("check that container has element with this name"); 114 115 String name = oObj.getName(); 116 System.out.println("getting the name \"" + name + "\""); 117 loc_result = name.equals(NewName); 118 119 if (loc_result) 120 { 121 System.out.println("... setName() - OK"); 122 } 123 else 124 { 125 System.out.println("... setName() - FAILED"); 126 } 127 result &= loc_result; 128 oObj.setName(oldName); 129 return result; 130 } 131 } 132 133 134