1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XShape.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 import lib
.MultiMethodTest
;
35 import com
.sun
.star
.awt
.Point
;
36 import com
.sun
.star
.awt
.Size
;
37 import com
.sun
.star
.drawing
.XShape
;
40 * Testing <code>com.sun.star.drawing.XShape</code>
43 * <li><code> getPosition()</code></li>
44 * <li><code> setPosition()</code></li>
45 * <li><code> getSize()</code></li>
46 * <li><code> setSize()</code></li>
48 * This test needs the following object relations :
50 * <li> <code>'NoPos'</code> <b>optional</b>
51 * (of type <code>Object</code>):
52 * if this relation exists then position setting is
53 * not supported by the object.</li>
55 * Test is <b> NOT </b> multithread compilant. <p>
56 * @see com.sun.star.drawing.XShape
58 public class _XShape
extends MultiMethodTest
{
60 public XShape oObj
= null; //oObj filled by MultiMethodTest
62 Size sOld
= new Size();
63 Point pOld
= new Point();
64 Size sNew
= new Size();
65 Point pNew
= new Point();
68 * Gets the size and stores it. <p>
69 * Has <b> OK </b> status if the method successfully returns
70 * and no exceptions were thrown. <p>
72 public void _getSize(){
74 boolean result
= false;
76 log
.println("get the size");
78 sOld
= (Size
) oObj
.getSize();
81 tRes
.tested("getSize()", result
);
85 * Gets the current position and stores it if the object
86 * supports position setting. <p>
87 * Has <b> OK </b> status if the method successfully returns
88 * and no exceptions were thrown or object doesn't
89 * support position setting. <p>
91 public void _getPosition(){
92 boolean result
= false;
94 String obj
= (String
) tEnv
.getObjRelation("NoPos");
96 log
.println("Can't be used with "+obj
);
98 tRes
.tested("getPosition()", result
);
102 log
.println("get the position");
103 pOld
= (Point
) oObj
.getPosition();
106 tRes
.tested("getPosition()", result
);
110 * Sets a new size different from the size get before. <p>
111 * Has <b> OK </b> status if the size returned by <code>getSize()</code>
112 * is equal to the size which was set. <p>
113 * The following method tests are to be completed successfully before :
115 * <li> <code> getSize() </code> : to set the original size changed.</li>
118 public void _setSize(){
119 requiredMethod("getSize()");
121 boolean result
= true;
123 String obj
= (String
) tEnv
.getObjRelation("NoSetSize");
125 log
.println("Can't be used with " + obj
);
126 tRes
.tested("setSize()", true);
129 // get the current thread's holder
130 sNew
= new Size(sOld
.Width
+ 10,sOld
.Height
+ 10) ;
133 log
.println("change the size");
136 } catch (com
.sun
.star
.beans
.PropertyVetoException e
) {
137 log
.println("Exception while calling the method :" + e
);
141 Size gSize
= oObj
.getSize() ;
143 log
.println("Previously: "+sOld
.Height
+";"+sOld
.Width
);
144 log
.println("Expected: "+sNew
.Height
+";"+sNew
.Width
);
145 log
.println("Getting: "+gSize
.Height
+";"+gSize
.Width
);
147 //result &= util.ValueComparer.equalValue(sNew, gSize) ;
148 //errors in calculation from points/twips less then 1 are acceptable
149 result
&= (sNew
.Height
-gSize
.Height
<= 2) && (sNew
.Width
-gSize
.Width
<= 2);
151 if (result
&& ((sNew
.Height
-gSize
.Height
!= 0) || (sNew
.Width
-gSize
.Width
!= 0))){
152 log
.println("NOTE: there is a difference between the expected and the getted value. " +
153 "This might be ok because of problems in calculation from points <-> twips");
155 tRes
.tested("setSize()", result
);
159 * If object doesn't support position setting the test does nothing.
160 * Else a new position is created and set.<p>
161 * Has <b> OK </b> status if get position is equal to set position or
162 * if the position setting isn't supported. <p>
163 * The following method tests are to be completed successfully before :
165 * <li> <code> getPosition() </code> : to change old position. </li>
168 public void _setPosition(){
169 requiredMethod("getPosition()");
171 boolean result
= true;
173 String obj
= (String
) tEnv
.getObjRelation("NoPos");
175 log
.println("Can't be used with " + obj
);
176 tRes
.tested("setPosition()", true);
180 // get the current thread's holder
181 pNew
= new Point(pOld
.X
+ 100, pOld
.Y
+ 100) ;
182 oObj
.setPosition(pNew
);
184 Point gPos
= oObj
.getPosition() ;
186 log
.println("Previously: "+pOld
.X
+";"+pOld
.Y
);
187 log
.println("Expected: "+pNew
.X
+";"+pNew
.Y
);
188 log
.println("Getting: "+gPos
.X
+";"+gPos
.Y
);
190 result
= !util
.ValueComparer
.equalValue(pOld
, gPos
) ;
192 tRes
.tested("setPosition()", result
);
196 } // finish class _XShape