1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: OCurrencyControl.java,v $
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 ************************************************************************/
32 import java
.io
.PrintWriter
;
34 import lib
.StatusException
;
36 import lib
.TestEnvironment
;
37 import lib
.TestParameters
;
38 import util
.FormTools
;
39 import util
.SOfficeFactory
;
40 import util
.WriterTools
;
42 import com
.sun
.star
.awt
.XControl
;
43 import com
.sun
.star
.awt
.XControlModel
;
44 import com
.sun
.star
.awt
.XDevice
;
45 import com
.sun
.star
.awt
.XGraphics
;
46 import com
.sun
.star
.awt
.XTextComponent
;
47 import com
.sun
.star
.awt
.XToolkit
;
48 import com
.sun
.star
.awt
.XWindow
;
49 import com
.sun
.star
.awt
.XWindowPeer
;
50 import com
.sun
.star
.drawing
.XControlShape
;
51 import com
.sun
.star
.drawing
.XShape
;
52 import com
.sun
.star
.lang
.XMultiServiceFactory
;
53 import com
.sun
.star
.text
.XTextDocument
;
54 import com
.sun
.star
.uno
.UnoRuntime
;
55 import com
.sun
.star
.uno
.XInterface
;
56 import com
.sun
.star
.util
.XCloseable
;
57 import com
.sun
.star
.view
.XControlAccess
;
61 * Test for object which is represented by default controller
62 * of the <code>com.sun.star.form.component.CurrencyField</code>
65 * Object implements the following interfaces :
67 * <li> <code>com::sun::star::awt::XView</code></li>
68 * <li> <code>com::sun::star::form::XBoundControl</code></li>
69 * <li> <code>com::sun::star::awt::XControl</code></li>
70 * <li> <code>com::sun::star::awt::XTextComponent</code></li>
71 * <li> <code>com::sun::star::awt::XLayoutConstrains</code></li>
72 * <li> <code>com::sun::star::awt::XTextListener</code></li>
73 * <li> <code>com::sun::star::awt::XWindow</code></li>
74 * <li> <code>com::sun::star::awt::XCurrencyField</code></li>
75 * <li> <code>com::sun::star::lang::XComponent</code></li>
76 * <li> <code>com::sun::star::awt::XTextLayoutConstrains</code></li>
77 * <li> <code>com::sun::star::lang::XEventListener</code></li>
79 * This object test <b> is NOT </b> designed to be run in several
80 * threads concurently.
82 * @see com.sun.star.awt.XView
83 * @see com.sun.star.form.XBoundControl
84 * @see com.sun.star.awt.XControl
85 * @see com.sun.star.awt.XTextComponent
86 * @see com.sun.star.awt.XLayoutConstrains
87 * @see com.sun.star.awt.XTextListener
88 * @see com.sun.star.awt.XWindow
89 * @see com.sun.star.awt.XCurrencyField
90 * @see com.sun.star.lang.XComponent
91 * @see com.sun.star.awt.XTextLayoutConstrains
92 * @see com.sun.star.lang.XEventListener
94 * @see ifc.form._XBoundControl
95 * @see ifc.awt._XControl
96 * @see ifc.awt._XTextComponent
97 * @see ifc.awt._XLayoutConstrains
98 * @see ifc.awt._XTextListener
99 * @see ifc.awt._XWindow
100 * @see ifc.awt._XCurrencyField
101 * @see ifc.lang._XComponent
102 * @see ifc.awt._XTextLayoutConstrains
103 * @see ifc.lang._XEventListener
105 public class OCurrencyControl
extends TestCase
{
106 XTextDocument xTextDoc
;
109 * Creates a new text document.
111 protected void initialize(TestParameters Param
, PrintWriter log
) {
112 SOfficeFactory SOF
= SOfficeFactory
.getFactory((XMultiServiceFactory
) Param
.getMSF());
115 log
.println("creating a textdocument");
116 xTextDoc
= SOF
.createTextDoc(null);
117 } catch (com
.sun
.star
.uno
.Exception e
) {
118 // Some exception occures.FAILED
119 e
.printStackTrace(log
);
120 throw new StatusException("Couldn't create document", e
);
125 * Disposes the text document created before
127 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
128 log
.println(" disposing xTextDoc ");
131 XCloseable closer
= (XCloseable
) UnoRuntime
.queryInterface(
132 XCloseable
.class, xTextDoc
);
134 } catch (com
.sun
.star
.util
.CloseVetoException e
) {
135 log
.println("couldn't close document");
136 } catch (com
.sun
.star
.lang
.DisposedException e
) {
137 log
.println("couldn't close document");
142 * Creates two components and inserts them to the form of
143 * text document. One component
144 * (<code>com.sun.star.form.component.CurrencyField</code>) is created
145 * for testing, another to be passed as relation. Using a controller
146 * of the text document the controller of the first component is
147 * obtained and returned in environment as a test object. <p>
149 * Object relations created :
151 * <li> <code>'GRAPHICS'</code> for
152 * {@link ifc.awt._XView} : a graphics component
153 * created using screen device of the window peer of
154 * the controller tested. </li>
155 * <li> <code>'CONTEXT'</code> for
156 * {@link ifc.awt._XControl} : the text document
157 * where the component is inserted. </li>
158 * <li> <code>'WINPEER'</code> for
159 * {@link ifc.awt._XControl} : Window peer of the
160 * controller tested. </li>
161 * <li> <code>'TOOLKIT'</code> for
162 * {@link ifc.awt._XControl} : toolkit of the component.</li>
163 * <li> <code>'MODEL'</code> for
164 * {@link ifc.awt._XControl} : the model of the controller.</li>
165 * <li> <code>'XWindow.AnotherWindow'</code> for
166 * {@link ifc.awt._XWindow} : the controller of another
168 * <li> <code>'XTextComponent.onlyNumbers'</code> for
169 * {@link ifc.awt._XTextComponent} : as the currency field
170 * can have only numeric values the relation must be specified. </li>
173 protected TestEnvironment
createTestEnvironment(TestParameters Param
,
175 XInterface oObj
= null;
176 XWindowPeer the_win
= null;
177 XToolkit the_kit
= null;
178 XDevice aDevice
= null;
179 XGraphics aGraphic
= null;
180 XControl aControl
= null;
182 //Insert a ControlShape and get the ControlModel
183 XControlShape aShape
= FormTools
.createControlShape(xTextDoc
, 3000,
187 WriterTools
.getDrawPage(xTextDoc
).add((XShape
) aShape
);
189 XControlModel the_Model
= aShape
.getControl();
191 XControlShape aShape2
= FormTools
.createControlShape(xTextDoc
, 3000,
195 WriterTools
.getDrawPage(xTextDoc
).add((XShape
) aShape2
);
197 XControlModel the_Model2
= aShape2
.getControl();
199 //Try to query XControlAccess
200 XControlAccess the_access
= (XControlAccess
) UnoRuntime
.queryInterface(
201 XControlAccess
.class,
202 xTextDoc
.getCurrentController());
204 //now get the OCurrencyControl
206 oObj
= the_access
.getControl(the_Model
);
207 aControl
= the_access
.getControl(the_Model2
);
208 the_win
= the_access
.getControl(the_Model
).getPeer();
209 the_kit
= the_win
.getToolkit();
210 aDevice
= the_kit
.createScreenCompatibleDevice(200, 200);
211 aGraphic
= aDevice
.createGraphics();
212 } catch (com
.sun
.star
.container
.NoSuchElementException e
) {
213 log
.println("Couldn't get OCurrencyControl");
214 e
.printStackTrace(log
);
215 throw new StatusException("Couldn't get OCurrencyControl", e
);
218 log
.println("creating a new environment for OCurrencyControl object");
220 TestEnvironment tEnv
= new TestEnvironment(oObj
);
223 //Adding ObjRelation for XView
224 tEnv
.addObjRelation("GRAPHICS", aGraphic
);
227 //Adding ObjRelation for XControl
228 tEnv
.addObjRelation("CONTEXT", xTextDoc
);
229 tEnv
.addObjRelation("WINPEER", the_win
);
230 tEnv
.addObjRelation("TOOLKIT", the_kit
);
231 tEnv
.addObjRelation("MODEL", the_Model
);
234 // Adding relation for XTextComponent
235 tEnv
.addObjRelation("XTextComponent.onlyNumbers", new Object());
237 // Adding relation for XWindow
238 XWindow forObjRel
= (XWindow
) UnoRuntime
.queryInterface(XWindow
.class,
241 tEnv
.addObjRelation("XWindow.AnotherWindow", forObjRel
);
242 tEnv
.addObjRelation("XWindow.ControlShape", aShape
);
244 // Adding relation for XTextListener
245 ifc
.awt
._XTextListener
.TestTextListener listener
=
246 new ifc
.awt
._XTextListener
.TestTextListener();
247 XTextComponent textComp
= (XTextComponent
) UnoRuntime
.queryInterface(
248 XTextComponent
.class, oObj
);
249 textComp
.addTextListener(listener
);
250 tEnv
.addObjRelation("TestTextListener", listener
);
253 } // finish method getTestEnvironment
254 } // finish class OCurrencyControl