2 * This file is part of the LibreOffice project.
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/.
8 * This file incorporates work covered by the following license notice:
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 .
21 import lib
.MultiMethodTest
;
23 import com
.sun
.star
.awt
.Point
;
24 import com
.sun
.star
.awt
.Size
;
25 import com
.sun
.star
.drawing
.XShape
;
28 * Testing <code>com.sun.star.drawing.XShape</code>
31 * <li><code> getPosition()</code></li>
32 * <li><code> setPosition()</code></li>
33 * <li><code> getSize()</code></li>
34 * <li><code> setSize()</code></li>
36 * This test needs the following object relations :
38 * <li> <code>'NoPos'</code> <b>optional</b>
39 * (of type <code>Object</code>):
40 * if this relation exists then position setting is
41 * not supported by the object.</li>
43 * Test is <b> NOT </b> multithread compliant. <p>
44 * @see com.sun.star.drawing.XShape
46 public class _XShape
extends MultiMethodTest
{
48 public XShape oObj
= null; //oObj filled by MultiMethodTest
50 Size sOld
= new Size();
51 Point pOld
= new Point();
52 Size sNew
= new Size();
53 Point pNew
= new Point();
56 * Gets the size and stores it. <p>
57 * Has <b> OK </b> status if the method successfully returns
58 * and no exceptions were thrown. <p>
60 public void _getSize(){
62 boolean result
= false;
64 log
.println("get the size");
66 sOld
= oObj
.getSize();
69 tRes
.tested("getSize()", result
);
73 * Gets the current position and stores it if the object
74 * supports position setting. <p>
75 * Has <b> OK </b> status if the method successfully returns
76 * and no exceptions were thrown or object doesn't
77 * support position setting. <p>
79 public void _getPosition(){
80 boolean result
= false;
82 String obj
= (String
) tEnv
.getObjRelation("NoPos");
84 log
.println("Can't be used with "+obj
);
86 tRes
.tested("getPosition()", result
);
90 log
.println("get the position");
91 pOld
= oObj
.getPosition();
94 tRes
.tested("getPosition()", result
);
98 * Sets a new size different from the size get before. <p>
99 * Has <b> OK </b> status if the size returned by <code>getSize()</code>
100 * is equal to the size which was set. <p>
101 * The following method tests are to be completed successfully before :
103 * <li> <code> getSize() </code> : to set the original size changed.</li>
106 public void _setSize(){
107 requiredMethod("getSize()");
109 boolean result
= true;
111 String obj
= (String
) tEnv
.getObjRelation("NoSetSize");
113 log
.println("Can't be used with " + obj
);
114 tRes
.tested("setSize()", true);
117 // get the current thread's holder
118 sNew
= new Size(sOld
.Width
+ 10,sOld
.Height
+ 10) ;
121 log
.println("change the size");
124 } catch (com
.sun
.star
.beans
.PropertyVetoException e
) {
125 log
.println("Exception while calling the method :" + e
);
129 Size gSize
= oObj
.getSize() ;
131 log
.println("Previously: "+sOld
.Height
+";"+sOld
.Width
);
132 log
.println("Expected: "+sNew
.Height
+";"+sNew
.Width
);
133 log
.println("Getting: "+gSize
.Height
+";"+gSize
.Width
);
135 //errors in calculation from points/twips less than 1 are acceptable
136 result
&= (sNew
.Height
-gSize
.Height
<= 2) && (sNew
.Width
-gSize
.Width
<= 2);
138 if (result
&& ((sNew
.Height
-gSize
.Height
!= 0) || (sNew
.Width
-gSize
.Width
!= 0))){
139 log
.println("NOTE: there is a difference between the expected and the gotten value. " +
140 "This might be ok because of problems in calculation from points <-> twips");
142 tRes
.tested("setSize()", result
);
146 * If object doesn't support position setting the test does nothing.
147 * Else a new position is created and set.<p>
148 * Has <b> OK </b> status if get position is equal to set position or
149 * if the position setting isn't supported. <p>
150 * The following method tests are to be completed successfully before :
152 * <li> <code> getPosition() </code> : to change old position. </li>
155 public void _setPosition(){
156 requiredMethod("getPosition()");
158 boolean result
= true;
160 String obj
= (String
) tEnv
.getObjRelation("NoPos");
162 log
.println("Can't be used with " + obj
);
163 tRes
.tested("setPosition()", true);
167 // get the current thread's holder
168 pNew
= new Point(pOld
.X
+ 100, pOld
.Y
+ 100) ;
169 oObj
.setPosition(pNew
);
171 Point gPos
= oObj
.getPosition() ;
173 log
.println("Previously: "+pOld
.X
+";"+pOld
.Y
);
174 log
.println("Expected: "+pNew
.X
+";"+pNew
.Y
);
175 log
.println("Getting: "+gPos
.X
+";"+gPos
.Y
);
177 result
= !util
.ValueComparer
.equalValue(pOld
, gPos
) ;
179 tRes
.tested("setPosition()", result
);
183 } // finish class _XShape