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: OImageControlControl.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
.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
;
60 * Test for object which is represented by default controller
61 * of the <code>com.sun.star.form.component.DatabaseImageControl</code>
64 * Object implements the following interfaces :
66 * <li> <code>com::sun::star::lang::XComponent</code></li>
67 * <li> <code>com::sun::star::awt::XWindow</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::XLayoutConstrains</code></li>
71 * <li> <code>com::sun::star::awt::XView</code></li>
73 * This object test <b> is NOT </b> designed to be run in several
74 * threads concurently.
76 * @see com.sun.star.lang.XComponent
77 * @see com.sun.star.awt.XWindow
78 * @see com.sun.star.form.XBoundControl
79 * @see com.sun.star.awt.XControl
80 * @see com.sun.star.awt.XLayoutConstrains
81 * @see com.sun.star.awt.XView
82 * @see ifc.lang._XComponent
83 * @see ifc.awt._XWindow
84 * @see ifc.form._XBoundControl
85 * @see ifc.awt._XControl
86 * @see ifc.awt._XLayoutConstrains
89 public class OImageControlControl
extends TestCase
{
90 XTextDocument xTextDoc
;
93 * Creates a new text document.
95 protected void initialize(TestParameters Param
, PrintWriter log
) {
96 SOfficeFactory SOF
= SOfficeFactory
.getFactory(((XMultiServiceFactory
) Param
.getMSF()));
99 log
.println("creating a textdocument");
100 xTextDoc
= SOF
.createTextDoc(null);
101 } catch (com
.sun
.star
.uno
.Exception e
) {
102 // Some exception occures.FAILED
103 e
.printStackTrace(log
);
104 throw new StatusException("Couldn't create document", e
);
109 * Disposes the text document created before
111 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
112 log
.println(" disposing xTextDoc ");
115 XCloseable closer
= (XCloseable
) UnoRuntime
.queryInterface(
116 XCloseable
.class, xTextDoc
);
118 } catch (com
.sun
.star
.util
.CloseVetoException e
) {
119 log
.println("couldn't close document");
120 } catch (com
.sun
.star
.lang
.DisposedException e
) {
121 log
.println("couldn't close document");
126 * Creates two components and inserts them to the form of
127 * text document. One component
128 * (<code>com.sun.star.form.component.DatabaseImageControl</code>) is created
129 * for testing, another to be passed as relation. Using a controller
130 * of the text document the controller of the first component is
131 * obtained and returned in environment as a test object. <p>
133 * Object relations created :
135 * <li> <code>'GRAPHICS'</code> for
136 * {@link ifc.awt._XView} : a graphics component
137 * created using screen device of the window peer of
138 * the controller tested. </li>
139 * <li> <code>'CONTEXT'</code> for
140 * {@link ifc.awt._XControl} : the text document
141 * where the component is inserted. </li>
142 * <li> <code>'WINPEER'</code> for
143 * {@link ifc.awt._XControl} : Window peer of the
144 * controller tested. </li>
145 * <li> <code>'TOOLKIT'</code> for
146 * {@link ifc.awt._XControl} : toolkit of the component.</li>
147 * <li> <code>'MODEL'</code> for
148 * {@link ifc.awt._XControl} : the model of the controller.</li>
149 * <li> <code>'XWindow.AnotherWindow'</code> for
150 * {@link ifc.awt._XWindow} : the controller of another
154 protected TestEnvironment
createTestEnvironment(TestParameters Param
,
156 XInterface oObj
= null;
157 XWindowPeer the_win
= null;
158 XToolkit the_kit
= null;
159 XDevice aDevice
= null;
160 XGraphics aGraphic
= null;
161 XControl aControl
= null;
163 //Insert a ControlShape and get the ControlModel
164 XControlShape aShape
= FormTools
.createControlShapeWithDefaultControl(
165 xTextDoc
, 3000, 4500, 15000, 10000,
166 "DatabaseImageControl");
168 WriterTools
.getDrawPage(xTextDoc
).add((XShape
) aShape
);
170 XControlModel the_Model
= aShape
.getControl();
172 XControlShape aShape2
= FormTools
.createControlShape(xTextDoc
, 3000,
176 WriterTools
.getDrawPage(xTextDoc
).add((XShape
) aShape2
);
178 XControlModel the_Model2
= aShape2
.getControl();
180 //Try to query XControlAccess
181 XControlAccess the_access
= (XControlAccess
) UnoRuntime
.queryInterface(
182 XControlAccess
.class,
183 xTextDoc
.getCurrentController());
185 //now get the OImageControlControl
187 oObj
= the_access
.getControl(the_Model
);
188 the_win
= the_access
.getControl(the_Model
).getPeer();
189 aControl
= the_access
.getControl(the_Model2
);
190 the_kit
= the_win
.getToolkit();
191 aDevice
= the_kit
.createScreenCompatibleDevice(200, 200);
192 aGraphic
= aDevice
.createGraphics();
193 } catch (com
.sun
.star
.container
.NoSuchElementException e
) {
194 log
.println("Couldn't get OImageControlControl");
195 e
.printStackTrace(log
);
196 throw new StatusException("Couldn't get OImageControlControl", e
);
200 "creating a new environment for OImageControlControl object");
202 TestEnvironment tEnv
= new TestEnvironment(oObj
);
205 //Adding ObjRelation for XView
206 tEnv
.addObjRelation("GRAPHICS", aGraphic
);
209 //Adding ObjRelation for XControl
210 tEnv
.addObjRelation("CONTEXT", xTextDoc
);
211 tEnv
.addObjRelation("WINPEER", the_win
);
212 tEnv
.addObjRelation("TOOLKIT", the_kit
);
213 tEnv
.addObjRelation("MODEL", the_Model
);
215 // Adding relation for XWindow
216 XWindow forObjRel
= (XWindow
) UnoRuntime
.queryInterface(XWindow
.class,
219 tEnv
.addObjRelation("XWindow.AnotherWindow", forObjRel
);
222 } // finish method getTestEnvironment
223 } // finish class OImageControlControl