merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _forms / ODateControl.java
blob29dc3f7efc42a4a9cf5927d667ad0b250d4104de
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: ODateControl.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 ************************************************************************/
30 package mod._forms;
32 import java.io.PrintWriter;
34 import lib.StatusException;
35 import lib.TestCase;
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.XControlModel;
43 import com.sun.star.awt.XDevice;
44 import com.sun.star.awt.XGraphics;
45 import com.sun.star.awt.XTextComponent;
46 import com.sun.star.awt.XToolkit;
47 import com.sun.star.awt.XWindow;
48 import com.sun.star.awt.XWindowPeer;
49 import com.sun.star.drawing.XControlShape;
50 import com.sun.star.drawing.XShape;
51 import com.sun.star.lang.XMultiServiceFactory;
52 import com.sun.star.text.XTextDocument;
53 import com.sun.star.uno.UnoRuntime;
54 import com.sun.star.uno.XInterface;
55 import com.sun.star.util.XCloseable;
56 import com.sun.star.view.XControlAccess;
59 /**
60 * Test for object which is represented by default controller
61 * of the <code>com.sun.star.form.component.DateField</code>
62 * component. <p>
64 * Object implements the following interfaces :
65 * <ul>
66 * <li> <code>com::sun::star::awt::XView</code></li>
67 * <li> <code>com::sun::star::form::XBoundControl</code></li>
68 * <li> <code>com::sun::star::awt::XControl</code></li>
69 * <li> <code>com::sun::star::awt::XTextComponent</code></li>
70 * <li> <code>com::sun::star::awt::XLayoutConstrains</code></li>
71 * <li> <code>com::sun::star::awt::XDateField</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::lang::XComponent</code></li>
75 * <li> <code>com::sun::star::awt::XTextLayoutConstrains</code></li>
76 * <li> <code>com::sun::star::lang::XEventListener</code></li>
77 * </ul> <p>
78 * This object test <b> is NOT </b> designed to be run in several
79 * threads concurently.
81 * @see com.sun.star.awt.XView
82 * @see com.sun.star.form.XBoundControl
83 * @see com.sun.star.awt.XControl
84 * @see com.sun.star.awt.XTextComponent
85 * @see com.sun.star.awt.XLayoutConstrains
86 * @see com.sun.star.awt.XDateField
87 * @see com.sun.star.awt.XTextListener
88 * @see com.sun.star.awt.XWindow
89 * @see com.sun.star.lang.XComponent
90 * @see com.sun.star.awt.XTextLayoutConstrains
91 * @see com.sun.star.lang.XEventListener
92 * @see ifc.awt._XView
93 * @see ifc.form._XBoundControl
94 * @see ifc.awt._XControl
95 * @see ifc.awt._XTextComponent
96 * @see ifc.awt._XLayoutConstrains
97 * @see ifc.awt._XDateField
98 * @see ifc.awt._XTextListener
99 * @see ifc.awt._XWindow
100 * @see ifc.lang._XComponent
101 * @see ifc.awt._XTextLayoutConstrains
102 * @see ifc.lang._XEventListener
104 public class ODateControl extends TestCase {
105 XTextDocument xTextDoc;
108 * Creates a new text document.
110 protected void initialize(TestParameters Param, PrintWriter log) {
111 SOfficeFactory SOF = SOfficeFactory.getFactory(((XMultiServiceFactory) Param.getMSF()));
113 try {
114 log.println("creating a textdocument");
115 xTextDoc = SOF.createTextDoc(null);
116 } catch (com.sun.star.uno.Exception e) {
117 // Some exception occures.FAILED
118 e.printStackTrace(log);
119 throw new StatusException("Couldn't create document", e);
124 * Disposes the text document created before
126 protected void cleanup(TestParameters tParam, PrintWriter log) {
127 log.println(" disposing xTextDoc ");
129 try {
130 XCloseable closer = (XCloseable) UnoRuntime.queryInterface(
131 XCloseable.class, xTextDoc);
132 closer.close(true);
133 } catch (com.sun.star.util.CloseVetoException e) {
134 log.println("couldn't close document");
135 } catch (com.sun.star.lang.DisposedException e) {
136 log.println("couldn't close document");
141 * Creates two components and inserts them to the form of
142 * text document. One component
143 * (<code>com.sun.star.form.component.DateField</code>) is created
144 * for testing, another to be passed as relation. Using a controller
145 * of the text document the controller of the first component is
146 * obtained and returned in environment as a test object. <p>
148 * Object relations created :
149 * <ul>
150 * <li> <code>'GRAPHICS'</code> for
151 * {@link ifc.awt._XView} : a graphics component
152 * created using screen device of the window peer of
153 * the controller tested. </li>
154 * <li> <code>'CONTEXT'</code> for
155 * {@link ifc.awt._XControl} : the text document
156 * where the component is inserted. </li>
157 * <li> <code>'WINPEER'</code> for
158 * {@link ifc.awt._XControl} : Window peer of the
159 * controller tested. </li>
160 * <li> <code>'TOOLKIT'</code> for
161 * {@link ifc.awt._XControl} : toolkit of the component.</li>
162 * <li> <code>'MODEL'</code> for
163 * {@link ifc.awt._XControl} : the model of the controller.</li>
164 * <li> <code>'XWindow.AnotherWindow'</code> for
165 * {@link ifc.awt._XWindow} : the controller of another
166 * component. </li>
167 * </ul>
169 protected TestEnvironment createTestEnvironment(TestParameters Param,
170 PrintWriter log) {
171 XInterface oObj = null;
172 Object anotherCtrl = null;
173 XWindowPeer the_win = null;
174 XToolkit the_kit = null;
175 XDevice aDevice = null;
176 XGraphics aGraphic = null;
178 //Insert a ControlShape and get the ControlModel
179 XControlShape aShape = FormTools.createControlShape(xTextDoc, 3000,
180 4500, 15000, 10000,
181 "DateField");
183 WriterTools.getDrawPage(xTextDoc).add((XShape) aShape);
185 XControlModel the_Model = aShape.getControl();
187 XControlShape aShape2 = FormTools.createControlShape(xTextDoc, 3000,
188 4500, 5000, 10000,
189 "TextField");
191 WriterTools.getDrawPage(xTextDoc).add((XShape) aShape2);
193 XControlModel the_Model2 = aShape2.getControl();
195 //Try to query XControlAccess
196 XControlAccess the_access = (XControlAccess) UnoRuntime.queryInterface(
197 XControlAccess.class,
198 xTextDoc.getCurrentController());
200 //now get the ODateControl
201 try {
202 oObj = the_access.getControl(the_Model);
203 anotherCtrl = the_access.getControl(the_Model2);
204 the_win = the_access.getControl(the_Model).getPeer();
205 the_kit = the_win.getToolkit();
206 aDevice = the_kit.createScreenCompatibleDevice(200, 200);
207 aGraphic = aDevice.createGraphics();
208 } catch (com.sun.star.container.NoSuchElementException e) {
209 log.println("Couldn't get ODateControl");
210 e.printStackTrace(log);
211 throw new StatusException("Couldn't get ODateControl", e);
214 log.println("creating a new environment for ODateControl object");
216 TestEnvironment tEnv = new TestEnvironment(oObj);
219 //Adding ObjRelation for XView
220 tEnv.addObjRelation("GRAPHICS", aGraphic);
223 //Adding ObjRelation for XControl
224 tEnv.addObjRelation("CONTEXT", xTextDoc);
225 tEnv.addObjRelation("WINPEER", the_win);
226 tEnv.addObjRelation("TOOLKIT", the_kit);
227 tEnv.addObjRelation("MODEL", the_Model);
229 // Adding relation for XWindow
230 XWindow forObjRel = (XWindow) UnoRuntime.queryInterface(XWindow.class,
231 anotherCtrl);
233 tEnv.addObjRelation("XWindow.AnotherWindow", forObjRel);
234 tEnv.addObjRelation("XWindow.ControlShape", aShape);
236 // Adding relation for XTextListener
237 ifc.awt._XTextListener.TestTextListener listener =
238 new ifc.awt._XTextListener.TestTextListener();
239 XTextComponent textComp = (XTextComponent) UnoRuntime.queryInterface(
240 XTextComponent.class, oObj);
241 textComp.addTextListener(listener);
242 tEnv.addObjRelation("TestTextListener", listener);
244 return tEnv;
245 } // finish method getTestEnvironment
246 } // finish class ODateControl