2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 import java
.io
.PrintWriter
;
22 import lib
.StatusException
;
24 import lib
.TestEnvironment
;
25 import lib
.TestParameters
;
26 import util
.FormTools
;
27 import util
.SOfficeFactory
;
28 import util
.WriterTools
;
30 import com
.sun
.star
.awt
.XControl
;
31 import com
.sun
.star
.awt
.XControlModel
;
32 import com
.sun
.star
.awt
.XDevice
;
33 import com
.sun
.star
.awt
.XGraphics
;
34 import com
.sun
.star
.awt
.XTextComponent
;
35 import com
.sun
.star
.awt
.XToolkit
;
36 import com
.sun
.star
.awt
.XWindow
;
37 import com
.sun
.star
.awt
.XWindowPeer
;
38 import com
.sun
.star
.drawing
.XControlShape
;
39 import com
.sun
.star
.lang
.XMultiServiceFactory
;
40 import com
.sun
.star
.text
.XTextDocument
;
41 import com
.sun
.star
.uno
.UnoRuntime
;
42 import com
.sun
.star
.uno
.XInterface
;
43 import com
.sun
.star
.util
.XCloseable
;
44 import com
.sun
.star
.view
.XControlAccess
;
48 * Test for object which is represented by default controller
49 * of the <code>com.sun.star.form.component.CurrencyField</code>
52 * Object implements the following interfaces :
54 * <li> <code>com::sun::star::awt::XView</code></li>
55 * <li> <code>com::sun::star::form::XBoundControl</code></li>
56 * <li> <code>com::sun::star::awt::XControl</code></li>
57 * <li> <code>com::sun::star::awt::XTextComponent</code></li>
58 * <li> <code>com::sun::star::awt::XLayoutConstrains</code></li>
59 * <li> <code>com::sun::star::awt::XTextListener</code></li>
60 * <li> <code>com::sun::star::awt::XWindow</code></li>
61 * <li> <code>com::sun::star::awt::XCurrencyField</code></li>
62 * <li> <code>com::sun::star::lang::XComponent</code></li>
63 * <li> <code>com::sun::star::awt::XTextLayoutConstrains</code></li>
64 * <li> <code>com::sun::star::lang::XEventListener</code></li>
66 * This object test <b> is NOT </b> designed to be run in several
67 * threads concurently.
69 * @see com.sun.star.awt.XView
70 * @see com.sun.star.form.XBoundControl
71 * @see com.sun.star.awt.XControl
72 * @see com.sun.star.awt.XTextComponent
73 * @see com.sun.star.awt.XLayoutConstrains
74 * @see com.sun.star.awt.XTextListener
75 * @see com.sun.star.awt.XWindow
76 * @see com.sun.star.awt.XCurrencyField
77 * @see com.sun.star.lang.XComponent
78 * @see com.sun.star.awt.XTextLayoutConstrains
79 * @see com.sun.star.lang.XEventListener
81 * @see ifc.form._XBoundControl
82 * @see ifc.awt._XControl
83 * @see ifc.awt._XTextComponent
84 * @see ifc.awt._XLayoutConstrains
85 * @see ifc.awt._XTextListener
86 * @see ifc.awt._XWindow
87 * @see ifc.awt._XCurrencyField
88 * @see ifc.lang._XComponent
89 * @see ifc.awt._XTextLayoutConstrains
90 * @see ifc.lang._XEventListener
92 public class OCurrencyControl
extends TestCase
{
93 XTextDocument xTextDoc
;
96 * Creates a new text document.
98 protected void initialize(TestParameters Param
, PrintWriter log
) {
99 SOfficeFactory SOF
= SOfficeFactory
.getFactory((XMultiServiceFactory
) Param
.getMSF());
102 log
.println("creating a textdocument");
103 xTextDoc
= SOF
.createTextDoc(null);
104 } catch (com
.sun
.star
.uno
.Exception e
) {
105 // Some exception occurs.FAILED
106 e
.printStackTrace(log
);
107 throw new StatusException("Couldn't create document", e
);
112 * Disposes the text document created before
114 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
115 log
.println(" disposing xTextDoc ");
118 XCloseable closer
= UnoRuntime
.queryInterface(
119 XCloseable
.class, xTextDoc
);
121 } catch (com
.sun
.star
.util
.CloseVetoException e
) {
122 log
.println("couldn't close document");
123 } catch (com
.sun
.star
.lang
.DisposedException e
) {
124 log
.println("couldn't close document");
129 * Creates two components and inserts them to the form of
130 * text document. One component
131 * (<code>com.sun.star.form.component.CurrencyField</code>) is created
132 * for testing, another to be passed as relation. Using a controller
133 * of the text document the controller of the first component is
134 * obtained and returned in environment as a test object. <p>
136 * Object relations created :
138 * <li> <code>'GRAPHICS'</code> for
139 * {@link ifc.awt._XView} : a graphics component
140 * created using screen device of the window peer of
141 * the controller tested. </li>
142 * <li> <code>'CONTEXT'</code> for
143 * {@link ifc.awt._XControl} : the text document
144 * where the component is inserted. </li>
145 * <li> <code>'WINPEER'</code> for
146 * {@link ifc.awt._XControl} : Window peer of the
147 * controller tested. </li>
148 * <li> <code>'TOOLKIT'</code> for
149 * {@link ifc.awt._XControl} : toolkit of the component.</li>
150 * <li> <code>'MODEL'</code> for
151 * {@link ifc.awt._XControl} : the model of the controller.</li>
152 * <li> <code>'XWindow.AnotherWindow'</code> for
153 * {@link ifc.awt._XWindow} : the controller of another
155 * <li> <code>'XTextComponent.onlyNumbers'</code> for
156 * {@link ifc.awt._XTextComponent} : as the currency field
157 * can have only numeric values the relation must be specified. </li>
160 protected TestEnvironment
createTestEnvironment(TestParameters Param
,
162 XInterface oObj
= null;
163 XWindowPeer the_win
= null;
164 XToolkit the_kit
= null;
165 XDevice aDevice
= null;
166 XGraphics aGraphic
= null;
167 XControl aControl
= null;
169 //Insert a ControlShape and get the ControlModel
170 XControlShape aShape
= FormTools
.createControlShape(xTextDoc
, 3000,
174 WriterTools
.getDrawPage(xTextDoc
).add(aShape
);
176 XControlModel the_Model
= aShape
.getControl();
178 XControlShape aShape2
= FormTools
.createControlShape(xTextDoc
, 3000,
182 WriterTools
.getDrawPage(xTextDoc
).add(aShape2
);
184 XControlModel the_Model2
= aShape2
.getControl();
186 //Try to query XControlAccess
187 XControlAccess the_access
= UnoRuntime
.queryInterface(
188 XControlAccess
.class,
189 xTextDoc
.getCurrentController());
191 //now get the OCurrencyControl
193 oObj
= the_access
.getControl(the_Model
);
194 aControl
= the_access
.getControl(the_Model2
);
195 the_win
= the_access
.getControl(the_Model
).getPeer();
196 the_kit
= the_win
.getToolkit();
197 aDevice
= the_kit
.createScreenCompatibleDevice(200, 200);
198 aGraphic
= aDevice
.createGraphics();
199 } catch (com
.sun
.star
.container
.NoSuchElementException e
) {
200 log
.println("Couldn't get OCurrencyControl");
201 e
.printStackTrace(log
);
202 throw new StatusException("Couldn't get OCurrencyControl", e
);
205 log
.println("creating a new environment for OCurrencyControl object");
207 TestEnvironment tEnv
= new TestEnvironment(oObj
);
210 //Adding ObjRelation for XView
211 tEnv
.addObjRelation("GRAPHICS", aGraphic
);
214 //Adding ObjRelation for XControl
215 tEnv
.addObjRelation("CONTEXT", xTextDoc
);
216 tEnv
.addObjRelation("WINPEER", the_win
);
217 tEnv
.addObjRelation("TOOLKIT", the_kit
);
218 tEnv
.addObjRelation("MODEL", the_Model
);
221 // Adding relation for XTextComponent
222 tEnv
.addObjRelation("XTextComponent.onlyNumbers", new Object());
224 // Adding relation for XWindow
225 XWindow forObjRel
= UnoRuntime
.queryInterface(XWindow
.class,
228 tEnv
.addObjRelation("XWindow.AnotherWindow", forObjRel
);
229 tEnv
.addObjRelation("XWindow.ControlShape", aShape
);
231 // Adding relation for XTextListener
232 ifc
.awt
._XTextListener
.TestTextListener listener
=
233 new ifc
.awt
._XTextListener
.TestTextListener();
234 XTextComponent textComp
= UnoRuntime
.queryInterface(
235 XTextComponent
.class, oObj
);
236 textComp
.addTextListener(listener
);
237 tEnv
.addObjRelation("TestTextListener", listener
);
240 } // finish method getTestEnvironment
241 } // finish class OCurrencyControl