Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / qadevOOo / tests / java / ifc / drawing / _XShape.java
blobe774721c9fdc23771763d3f134e198248ae8ff6e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 package ifc.drawing;
30 import lib.MultiMethodTest;
32 import com.sun.star.awt.Point;
33 import com.sun.star.awt.Size;
34 import com.sun.star.drawing.XShape;
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
55 public class _XShape extends MultiMethodTest {
57 public XShape oObj = null; //oObj filled by MultiMethodTest
59 Size sOld = new Size();
60 Point pOld = new Point();
61 Size sNew = new Size();
62 Point pNew = new Point();
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>
69 public void _getSize(){
71 boolean result = false;
73 log.println("get the size");
75 sOld = (Size) oObj.getSize();
76 result = true;
78 tRes.tested("getSize()", result);
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>
88 public void _getPosition(){
89 boolean result = false;
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;
99 log.println("get the position");
100 pOld = (Point) oObj.getPosition();
101 result = true;
103 tRes.tested("getPosition()", result);
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>
115 public void _setSize(){
116 requiredMethod("getSize()");
118 boolean result = true;
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;
126 // get the current thread's holder
127 sNew = new Size(sOld.Width + 10,sOld.Height + 10) ;
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 ;
138 Size gSize = oObj.getSize() ;
140 log.println("Previously: "+sOld.Height+";"+sOld.Width);
141 log.println("Expected: "+sNew.Height+";"+sNew.Width);
142 log.println("Getting: "+gSize.Height+";"+gSize.Width);
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);
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");
152 tRes.tested("setSize()", result);
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>
165 public void _setPosition(){
166 requiredMethod("getPosition()");
168 boolean result = true;
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;
177 // get the current thread's holder
178 pNew = new Point(pOld.X + 100, pOld.Y + 100) ;
179 oObj.setPosition(pNew);
181 Point gPos = oObj.getPosition() ;
183 log.println("Previously: "+pOld.X+";"+pOld.Y);
184 log.println("Expected: "+pNew.X+";"+pNew.Y);
185 log.println("Getting: "+gPos.X+";"+gPos.Y);
187 result = !util.ValueComparer.equalValue(pOld, gPos) ;
189 tRes.tested("setPosition()", result);
193 } // finish class _XShape