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
.XToolkit
;
35 import com
.sun
.star
.awt
.XWindow
;
36 import com
.sun
.star
.awt
.XWindowPeer
;
37 import com
.sun
.star
.drawing
.XControlShape
;
38 import com
.sun
.star
.lang
.XMultiServiceFactory
;
39 import com
.sun
.star
.text
.XTextDocument
;
40 import com
.sun
.star
.uno
.UnoRuntime
;
41 import com
.sun
.star
.uno
.XInterface
;
42 import com
.sun
.star
.util
.XCloseable
;
43 import com
.sun
.star
.view
.XControlAccess
;
47 * Test for object which is represented by default controller
48 * of the <code>com.sun.star.form.component.DatabaseImageControl</code>
51 * Object implements the following interfaces :
53 * <li> <code>com::sun::star::lang::XComponent</code></li>
54 * <li> <code>com::sun::star::awt::XWindow</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::XLayoutConstrains</code></li>
58 * <li> <code>com::sun::star::awt::XView</code></li>
60 * This object test <b> is NOT </b> designed to be run in several
61 * threads concurently.
63 * @see com.sun.star.lang.XComponent
64 * @see com.sun.star.awt.XWindow
65 * @see com.sun.star.form.XBoundControl
66 * @see com.sun.star.awt.XControl
67 * @see com.sun.star.awt.XLayoutConstrains
68 * @see com.sun.star.awt.XView
69 * @see ifc.lang._XComponent
70 * @see ifc.awt._XWindow
71 * @see ifc.form._XBoundControl
72 * @see ifc.awt._XControl
73 * @see ifc.awt._XLayoutConstrains
76 public class OImageControlControl
extends TestCase
{
77 XTextDocument xTextDoc
;
80 * Creates a new text document.
82 protected void initialize(TestParameters Param
, PrintWriter log
) {
83 SOfficeFactory SOF
= SOfficeFactory
.getFactory(((XMultiServiceFactory
) Param
.getMSF()));
86 log
.println("creating a textdocument");
87 xTextDoc
= SOF
.createTextDoc(null);
88 } catch (com
.sun
.star
.uno
.Exception e
) {
89 // Some exception occurs.FAILED
90 e
.printStackTrace(log
);
91 throw new StatusException("Couldn't create document", e
);
96 * Disposes the text document created before
98 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
99 log
.println(" disposing xTextDoc ");
102 XCloseable closer
= UnoRuntime
.queryInterface(
103 XCloseable
.class, xTextDoc
);
105 } catch (com
.sun
.star
.util
.CloseVetoException e
) {
106 log
.println("couldn't close document");
107 } catch (com
.sun
.star
.lang
.DisposedException e
) {
108 log
.println("couldn't close document");
113 * Creates two components and inserts them to the form of
114 * text document. One component
115 * (<code>com.sun.star.form.component.DatabaseImageControl</code>) is created
116 * for testing, another to be passed as relation. Using a controller
117 * of the text document the controller of the first component is
118 * obtained and returned in environment as a test object. <p>
120 * Object relations created :
122 * <li> <code>'GRAPHICS'</code> for
123 * {@link ifc.awt._XView} : a graphics component
124 * created using screen device of the window peer of
125 * the controller tested. </li>
126 * <li> <code>'CONTEXT'</code> for
127 * {@link ifc.awt._XControl} : the text document
128 * where the component is inserted. </li>
129 * <li> <code>'WINPEER'</code> for
130 * {@link ifc.awt._XControl} : Window peer of the
131 * controller tested. </li>
132 * <li> <code>'TOOLKIT'</code> for
133 * {@link ifc.awt._XControl} : toolkit of the component.</li>
134 * <li> <code>'MODEL'</code> for
135 * {@link ifc.awt._XControl} : the model of the controller.</li>
136 * <li> <code>'XWindow.AnotherWindow'</code> for
137 * {@link ifc.awt._XWindow} : the controller of another
141 protected TestEnvironment
createTestEnvironment(TestParameters Param
,
143 XInterface oObj
= null;
144 XWindowPeer the_win
= null;
145 XToolkit the_kit
= null;
146 XDevice aDevice
= null;
147 XGraphics aGraphic
= null;
148 XControl aControl
= null;
150 //Insert a ControlShape and get the ControlModel
151 XControlShape aShape
= FormTools
.createControlShapeWithDefaultControl(
152 xTextDoc
, 3000, 4500, 15000, 10000,
153 "DatabaseImageControl");
155 WriterTools
.getDrawPage(xTextDoc
).add(aShape
);
157 XControlModel the_Model
= aShape
.getControl();
159 XControlShape aShape2
= FormTools
.createControlShape(xTextDoc
, 3000,
163 WriterTools
.getDrawPage(xTextDoc
).add(aShape2
);
165 XControlModel the_Model2
= aShape2
.getControl();
167 //Try to query XControlAccess
168 XControlAccess the_access
= UnoRuntime
.queryInterface(
169 XControlAccess
.class,
170 xTextDoc
.getCurrentController());
172 //now get the OImageControlControl
174 oObj
= the_access
.getControl(the_Model
);
175 the_win
= the_access
.getControl(the_Model
).getPeer();
176 aControl
= the_access
.getControl(the_Model2
);
177 the_kit
= the_win
.getToolkit();
178 aDevice
= the_kit
.createScreenCompatibleDevice(200, 200);
179 aGraphic
= aDevice
.createGraphics();
180 } catch (com
.sun
.star
.container
.NoSuchElementException e
) {
181 log
.println("Couldn't get OImageControlControl");
182 e
.printStackTrace(log
);
183 throw new StatusException("Couldn't get OImageControlControl", e
);
187 "creating a new environment for OImageControlControl object");
189 TestEnvironment tEnv
= new TestEnvironment(oObj
);
192 //Adding ObjRelation for XView
193 tEnv
.addObjRelation("GRAPHICS", aGraphic
);
196 //Adding ObjRelation for XControl
197 tEnv
.addObjRelation("CONTEXT", xTextDoc
);
198 tEnv
.addObjRelation("WINPEER", the_win
);
199 tEnv
.addObjRelation("TOOLKIT", the_kit
);
200 tEnv
.addObjRelation("MODEL", the_Model
);
202 // Adding relation for XWindow
203 XWindow forObjRel
= UnoRuntime
.queryInterface(XWindow
.class,
206 tEnv
.addObjRelation("XWindow.AnotherWindow", forObjRel
);
209 } // finish method getTestEnvironment
210 } // finish class OImageControlControl