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 24 package ifc.drawing; 25 26 import lib.MultiMethodTest; 27 28 import com.sun.star.awt.Point; 29 import com.sun.star.awt.Size; 30 import com.sun.star.drawing.XShape; 31 32 /** 33 * Testing <code>com.sun.star.drawing.XShape</code> 34 * interface methods : 35 * <ul> 36 * <li><code> getPosition()</code></li> 37 * <li><code> setPosition()</code></li> 38 * <li><code> getSize()</code></li> 39 * <li><code> setSize()</code></li> 40 * </ul> <p> 41 * This test needs the following object relations : 42 * <ul> 43 * <li> <code>'NoPos'</code> <b>optional</b> 44 * (of type <code>Object</code>): 45 * if this relation exists then position setting is 46 * not supported by the object.</li> 47 * <ul> <p> 48 * Test is <b> NOT </b> multithread compilant. <p> 49 * @see com.sun.star.drawing.XShape 50 */ 51 public class _XShape extends MultiMethodTest { 52 53 public XShape oObj = null; //oObj filled by MultiMethodTest 54 55 Size sOld = new Size(); 56 Point pOld = new Point(); 57 Size sNew = new Size(); 58 Point pNew = new Point(); 59 60 /** 61 * Gets the size and stores it. <p> 62 * Has <b> OK </b> status if the method successfully returns 63 * and no exceptions were thrown. <p> 64 */ _getSize()65 public void _getSize(){ 66 67 boolean result = false; 68 69 log.println("get the size"); 70 71 sOld = (Size) oObj.getSize(); 72 result = true; 73 74 tRes.tested("getSize()", result); 75 } 76 77 /** 78 * Gets the current position and stores it if the object 79 * supports position setting. <p> 80 * Has <b> OK </b> status if the method successfully returns 81 * and no exceptions were thrown or object doesn't 82 * support position setting. <p> 83 */ _getPosition()84 public void _getPosition(){ 85 boolean result = false; 86 87 String obj = (String) tEnv.getObjRelation("NoPos"); 88 if (obj != null) { 89 log.println("Can't be used with "+obj); 90 result = true; 91 tRes.tested("getPosition()", result); 92 return; 93 } 94 95 log.println("get the position"); 96 pOld = (Point) oObj.getPosition(); 97 result = true; 98 99 tRes.tested("getPosition()", result); 100 } 101 102 /** 103 * Sets a new size different from the size get before. <p> 104 * Has <b> OK </b> status if the size returned by <code>getSize()</code> 105 * is equal to the size which was set. <p> 106 * The following method tests are to be completed successfully before : 107 * <ul> 108 * <li> <code> getSize() </code> : to set the original size changed.</li> 109 * </ul> 110 */ _setSize()111 public void _setSize(){ 112 requiredMethod("getSize()"); 113 114 boolean result = true; 115 116 String obj = (String) tEnv.getObjRelation("NoSetSize"); 117 if (obj != null) { 118 log.println("Can't be used with " + obj); 119 tRes.tested("setSize()", true); 120 return; 121 } 122 // get the current thread's holder 123 sNew = new Size(sOld.Width + 10,sOld.Height + 10) ; 124 125 //set new size 126 log.println("change the size"); 127 try { 128 oObj.setSize(sNew); 129 } catch (com.sun.star.beans.PropertyVetoException e) { 130 log.println("Exception while calling the method :" + e); 131 result = true ; 132 } 133 134 Size gSize = oObj.getSize() ; 135 136 log.println("Previously: "+sOld.Height+";"+sOld.Width); 137 log.println("Expected: "+sNew.Height+";"+sNew.Width); 138 log.println("Getting: "+gSize.Height+";"+gSize.Width); 139 140 //result &= util.ValueComparer.equalValue(sNew, gSize) ; 141 //errors in calculation from points/twips less then 1 are acceptable 142 result &= (sNew.Height-gSize.Height <= 2) && (sNew.Width-gSize.Width <= 2); 143 144 if (result && ((sNew.Height-gSize.Height != 0) || (sNew.Width-gSize.Width != 0))){ 145 log.println("NOTE: there is a difference between the expected and the getted value. " + 146 "This might be ok because of problems in calculation from points <-> twips"); 147 } 148 tRes.tested("setSize()", result); 149 } 150 151 /** 152 * If object doesn't support position setting the test does nothing. 153 * Else a new position is created and set.<p> 154 * Has <b> OK </b> status if get position is equal to set position or 155 * if the position setting isn't supported. <p> 156 * The following method tests are to be completed successfully before : 157 * <ul> 158 * <li> <code> getPosition() </code> : to change old position. </li> 159 * </ul> 160 */ _setPosition()161 public void _setPosition(){ 162 requiredMethod("getPosition()"); 163 164 boolean result = true; 165 166 String obj = (String) tEnv.getObjRelation("NoPos"); 167 if (obj != null) { 168 log.println("Can't be used with " + obj); 169 tRes.tested("setPosition()", true); 170 return; 171 } 172 173 // get the current thread's holder 174 pNew = new Point(pOld.X + 100, pOld.Y + 100) ; 175 oObj.setPosition(pNew); 176 177 Point gPos = oObj.getPosition() ; 178 179 log.println("Previously: "+pOld.X+";"+pOld.Y); 180 log.println("Expected: "+pNew.X+";"+pNew.Y); 181 log.println("Getting: "+gPos.X+";"+gPos.Y); 182 183 result = !util.ValueComparer.equalValue(pOld, gPos) ; 184 185 tRes.tested("setPosition()", result); 186 } 187 188 189 } // finish class _XShape 190 191 192 193