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