Update ooo320-m1
[ooovba.git] / qadevOOo / tests / java / ifc / drawing / _XShape.java
blob3d0b0c23429bd50159b0b8debdcde516fccdb2bc
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XShape.java,v $
10 * $Revision: 1.5 $
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 ************************************************************************/
31 package ifc.drawing;
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;
39 /**
40 * Testing <code>com.sun.star.drawing.XShape</code>
41 * interface methods :
42 * <ul>
43 * <li><code> getPosition()</code></li>
44 * <li><code> setPosition()</code></li>
45 * <li><code> getSize()</code></li>
46 * <li><code> setSize()</code></li>
47 * </ul> <p>
48 * This test needs the following object relations :
49 * <ul>
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>
54 * <ul> <p>
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();
67 /**
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();
79 result = true;
81 tRes.tested("getSize()", result);
84 /**
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");
95 if (obj != null) {
96 log.println("Can't be used with "+obj);
97 result = true;
98 tRes.tested("getPosition()", result);
99 return;
102 log.println("get the position");
103 pOld = (Point) oObj.getPosition();
104 result = true;
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 :
114 * <ul>
115 * <li> <code> getSize() </code> : to set the original size changed.</li>
116 * </ul>
118 public void _setSize(){
119 requiredMethod("getSize()");
121 boolean result = true;
123 String obj = (String) tEnv.getObjRelation("NoSetSize");
124 if (obj != null) {
125 log.println("Can't be used with " + obj);
126 tRes.tested("setSize()", true);
127 return;
129 // get the current thread's holder
130 sNew = new Size(sOld.Width + 10,sOld.Height + 10) ;
132 //set new size
133 log.println("change the size");
134 try {
135 oObj.setSize(sNew);
136 } catch (com.sun.star.beans.PropertyVetoException e) {
137 log.println("Exception while calling the method :" + e);
138 result = true ;
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 :
164 * <ul>
165 * <li> <code> getPosition() </code> : to change old position. </li>
166 * </ul>
168 public void _setPosition(){
169 requiredMethod("getPosition()");
171 boolean result = true;
173 String obj = (String) tEnv.getObjRelation("NoPos");
174 if (obj != null) {
175 log.println("Can't be used with " + obj);
176 tRes.tested("setPosition()", true);
177 return;
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