1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir package ifc.drawing;
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir import lib.MultiMethodTest;
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir import com.sun.star.awt.Point;
33*cdf0e10cSrcweir import com.sun.star.awt.Size;
34*cdf0e10cSrcweir import com.sun.star.drawing.XShape;
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir /**
37*cdf0e10cSrcweir * Testing <code>com.sun.star.drawing.XShape</code>
38*cdf0e10cSrcweir * interface methods :
39*cdf0e10cSrcweir * <ul>
40*cdf0e10cSrcweir *  <li><code> getPosition()</code></li>
41*cdf0e10cSrcweir *  <li><code> setPosition()</code></li>
42*cdf0e10cSrcweir *  <li><code> getSize()</code></li>
43*cdf0e10cSrcweir *  <li><code> setSize()</code></li>
44*cdf0e10cSrcweir * </ul> <p>
45*cdf0e10cSrcweir * This test needs the following object relations :
46*cdf0e10cSrcweir * <ul>
47*cdf0e10cSrcweir *  <li> <code>'NoPos'</code> <b>optional</b>
48*cdf0e10cSrcweir *  (of type <code>Object</code>):
49*cdf0e10cSrcweir *   if this relation exists then position setting is
50*cdf0e10cSrcweir *   not supported by the object.</li>
51*cdf0e10cSrcweir * <ul> <p>
52*cdf0e10cSrcweir * Test is <b> NOT </b> multithread compilant. <p>
53*cdf0e10cSrcweir * @see com.sun.star.drawing.XShape
54*cdf0e10cSrcweir */
55*cdf0e10cSrcweir public class _XShape extends MultiMethodTest {
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir     public XShape oObj = null;        //oObj filled by MultiMethodTest
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir     Size sOld = new Size();
60*cdf0e10cSrcweir     Point pOld = new Point();
61*cdf0e10cSrcweir     Size sNew = new Size();
62*cdf0e10cSrcweir     Point pNew = new Point();
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir     /**
65*cdf0e10cSrcweir     * Gets the size and stores it. <p>
66*cdf0e10cSrcweir     * Has <b> OK </b> status if the method successfully returns
67*cdf0e10cSrcweir     * and no exceptions were thrown. <p>
68*cdf0e10cSrcweir     */
69*cdf0e10cSrcweir     public void _getSize(){
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir         boolean result = false;
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir         log.println("get the size");
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir         sOld = (Size) oObj.getSize();
76*cdf0e10cSrcweir         result = true;
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir         tRes.tested("getSize()", result);
79*cdf0e10cSrcweir     }
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir     /**
82*cdf0e10cSrcweir     * Gets the current position and stores it if the object
83*cdf0e10cSrcweir     * supports position setting. <p>
84*cdf0e10cSrcweir     * Has <b> OK </b> status if the method successfully returns
85*cdf0e10cSrcweir     * and no exceptions were thrown or object doesn't
86*cdf0e10cSrcweir     * support position setting. <p>
87*cdf0e10cSrcweir     */
88*cdf0e10cSrcweir     public void _getPosition(){
89*cdf0e10cSrcweir         boolean result = false;
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir         String obj = (String) tEnv.getObjRelation("NoPos");
92*cdf0e10cSrcweir         if (obj != null) {
93*cdf0e10cSrcweir             log.println("Can't be used with "+obj);
94*cdf0e10cSrcweir             result = true;
95*cdf0e10cSrcweir             tRes.tested("getPosition()", result);
96*cdf0e10cSrcweir             return;
97*cdf0e10cSrcweir         }
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir         log.println("get the position");
100*cdf0e10cSrcweir         pOld = (Point) oObj.getPosition();
101*cdf0e10cSrcweir         result = true;
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir         tRes.tested("getPosition()", result);
104*cdf0e10cSrcweir     }
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir     /**
107*cdf0e10cSrcweir     * Sets a new size different from the size get before. <p>
108*cdf0e10cSrcweir     * Has <b> OK </b> status if the size returned by <code>getSize()</code>
109*cdf0e10cSrcweir     * is equal to the size which was set. <p>
110*cdf0e10cSrcweir     * The following method tests are to be completed successfully before :
111*cdf0e10cSrcweir     * <ul>
112*cdf0e10cSrcweir     *  <li> <code> getSize() </code> : to set the original size changed.</li>
113*cdf0e10cSrcweir     * </ul>
114*cdf0e10cSrcweir     */
115*cdf0e10cSrcweir     public void _setSize(){
116*cdf0e10cSrcweir         requiredMethod("getSize()");
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir         boolean result = true;
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir         String obj = (String) tEnv.getObjRelation("NoSetSize");
121*cdf0e10cSrcweir         if (obj != null) {
122*cdf0e10cSrcweir             log.println("Can't be used with " + obj);
123*cdf0e10cSrcweir             tRes.tested("setSize()", true);
124*cdf0e10cSrcweir             return;
125*cdf0e10cSrcweir         }
126*cdf0e10cSrcweir         // get the current thread's holder
127*cdf0e10cSrcweir         sNew = new Size(sOld.Width + 10,sOld.Height + 10) ;
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir         //set new size
130*cdf0e10cSrcweir         log.println("change the size");
131*cdf0e10cSrcweir         try {
132*cdf0e10cSrcweir             oObj.setSize(sNew);
133*cdf0e10cSrcweir         } catch (com.sun.star.beans.PropertyVetoException e) {
134*cdf0e10cSrcweir             log.println("Exception while calling the method :" + e);
135*cdf0e10cSrcweir             result = true ;
136*cdf0e10cSrcweir         }
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir         Size gSize = oObj.getSize() ;
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir         log.println("Previously: "+sOld.Height+";"+sOld.Width);
141*cdf0e10cSrcweir         log.println("Expected: "+sNew.Height+";"+sNew.Width);
142*cdf0e10cSrcweir         log.println("Getting: "+gSize.Height+";"+gSize.Width);
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir         //result &= util.ValueComparer.equalValue(sNew, gSize) ;
145*cdf0e10cSrcweir         //errors in calculation from points/twips less then 1 are acceptable
146*cdf0e10cSrcweir         result &= (sNew.Height-gSize.Height <= 2) && (sNew.Width-gSize.Width <= 2);
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir         if (result && ((sNew.Height-gSize.Height != 0) || (sNew.Width-gSize.Width != 0))){
149*cdf0e10cSrcweir             log.println("NOTE: there is a difference between the expected and the getted value. " +
150*cdf0e10cSrcweir                     "This might be ok because of problems in calculation from points <-> twips");
151*cdf0e10cSrcweir         }
152*cdf0e10cSrcweir         tRes.tested("setSize()", result);
153*cdf0e10cSrcweir     }
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir     /**
156*cdf0e10cSrcweir     * If object doesn't support position setting the test does nothing.
157*cdf0e10cSrcweir     * Else a new position is created and set.<p>
158*cdf0e10cSrcweir     * Has <b> OK </b> status if get position is equal to set position or
159*cdf0e10cSrcweir     * if the position setting isn't supported. <p>
160*cdf0e10cSrcweir     * The following method tests are to be completed successfully before :
161*cdf0e10cSrcweir     * <ul>
162*cdf0e10cSrcweir     *  <li> <code> getPosition() </code> : to change old position. </li>
163*cdf0e10cSrcweir     * </ul>
164*cdf0e10cSrcweir     */
165*cdf0e10cSrcweir     public void _setPosition(){
166*cdf0e10cSrcweir         requiredMethod("getPosition()");
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir         boolean result = true;
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir         String obj = (String) tEnv.getObjRelation("NoPos");
171*cdf0e10cSrcweir         if (obj != null) {
172*cdf0e10cSrcweir             log.println("Can't be used with " + obj);
173*cdf0e10cSrcweir             tRes.tested("setPosition()", true);
174*cdf0e10cSrcweir             return;
175*cdf0e10cSrcweir         }
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir         // get the current thread's holder
178*cdf0e10cSrcweir         pNew = new Point(pOld.X + 100, pOld.Y + 100) ;
179*cdf0e10cSrcweir         oObj.setPosition(pNew);
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir         Point gPos = oObj.getPosition() ;
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir         log.println("Previously: "+pOld.X+";"+pOld.Y);
184*cdf0e10cSrcweir         log.println("Expected: "+pNew.X+";"+pNew.Y);
185*cdf0e10cSrcweir         log.println("Getting: "+gPos.X+";"+gPos.Y);
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir         result = !util.ValueComparer.equalValue(pOld, gPos) ;
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir         tRes.tested("setPosition()", result);
190*cdf0e10cSrcweir     }
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir }  // finish class _XShape
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir 
197