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