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
.text
.XTextDocument
;
39 import com
.sun
.star
.uno
.UnoRuntime
;
40 import com
.sun
.star
.uno
.XInterface
;
41 import com
.sun
.star
.util
.XCloseable
;
42 import com
.sun
.star
.view
.XControlAccess
;
46 * Test for object which is represented by default controller
47 * of the <code>com.sun.star.form.component.CommandButton</code>
50 * Object implements the following interfaces :
52 * <li> <code>com::sun::star::lang::XComponent</code></li>
53 * <li> <code>com::sun::star::awt::XWindow</code></li>
54 * <li> <code>com::sun::star::form::XApproveActionBroadcaster</code></li>
55 * <li> <code>com::sun::star::awt::XControl</code></li>
56 * <li> <code>com::sun::star::awt::XLayoutConstrains</code></li>
57 * <li> <code>com::sun::star::awt::XButton</code></li>
58 * <li> <code>com::sun::star::awt::XView</code></li>
61 * This object test <b> is NOT </b> designed to be run in several
62 * threads concurently.
64 * @see com.sun.star.lang.XComponent
65 * @see com.sun.star.awt.XWindow
66 * @see com.sun.star.form.XApproveActionBroadcaster
67 * @see com.sun.star.awt.XControl
68 * @see com.sun.star.awt.XLayoutConstrains
69 * @see com.sun.star.awt.XButton
70 * @see com.sun.star.awt.XView
71 * @see ifc.lang._XComponent
72 * @see ifc.awt._XWindow
73 * @see ifc.form._XApproveActionBroadcaster
74 * @see ifc.awt._XControl
75 * @see ifc.awt._XLayoutConstrains
76 * @see ifc.awt._XButton
79 public class OButtonControl
extends TestCase
{
80 XTextDocument xTextDoc
;
83 * Creates a text document.
86 protected void initialize(TestParameters Param
, PrintWriter log
) {
87 SOfficeFactory SOF
= SOfficeFactory
.getFactory(Param
.getMSF());
90 log
.println("creating a textdocument");
91 xTextDoc
= SOF
.createTextDoc(null);
92 } catch (com
.sun
.star
.uno
.Exception e
) {
93 // Some exception occurs.FAILED
94 e
.printStackTrace(log
);
95 throw new StatusException("Couldn't create document", e
);
100 * Disposes the text document created before
103 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
104 log
.println(" disposing xTextDoc ");
107 XCloseable closer
= UnoRuntime
.queryInterface(
108 XCloseable
.class, xTextDoc
);
110 } catch (com
.sun
.star
.util
.CloseVetoException e
) {
111 log
.println("couldn't close document");
112 } catch (com
.sun
.star
.lang
.DisposedException e
) {
113 log
.println("couldn't close document");
118 * Creates two components and inserts them to the form of
119 * text document. One component
120 * (<code>com.sun.star.form.component.CommandButton</code>) is created
121 * for testing, another to be passed as relation. Using a controller
122 * of the text document the controller of the first component is
123 * obtained and returned in environment as a test object. <p>
125 * Object relations created :
127 * <li> <code>'GRAPHICS'</code> for
128 * {@link ifc.awt._XView} : a graphics component
129 * created using screen device of the window peer of
130 * the controller tested. </li>
131 * <li> <code>'CONTEXT'</code> for
132 * {@link ifc.awt._XControl} : the text document
133 * where the component is inserted. </li>
134 * <li> <code>'WINPEER'</code> for
135 * {@link ifc.awt._XControl} : Window peer of the
136 * controller tested. </li>
137 * <li> <code>'TOOLKIT'</code> for
138 * {@link ifc.awt._XControl} : toolkit of the component.</li>
139 * <li> <code>'MODEL'</code> for
140 * {@link ifc.awt._XControl} : the model of the controller.</li>
141 * <li> <code>'XWindow.AnotherWindow'</code> for
142 * {@link ifc.awt._XWindow} : the controller of another
147 protected TestEnvironment
createTestEnvironment(TestParameters Param
,
149 XInterface oObj
= null;
150 XWindowPeer the_win
= null;
151 XToolkit the_kit
= null;
152 XDevice aDevice
= null;
153 XGraphics aGraphic
= null;
154 XControl aControl
= null;
156 //Insert a ControlShape and get the ControlModel
157 XControlShape aShape
= FormTools
.createControlShape(xTextDoc
, 3000,
161 WriterTools
.getDrawPage(xTextDoc
).add(aShape
);
163 XControlModel the_Model
= aShape
.getControl();
165 XControlShape aShape2
= FormTools
.createControlShape(xTextDoc
, 3000,
169 WriterTools
.getDrawPage(xTextDoc
).add(aShape2
);
171 XControlModel the_Model2
= aShape2
.getControl();
173 //Try to query XControlAccess
174 XControlAccess the_access
= UnoRuntime
.queryInterface(
175 XControlAccess
.class,
176 xTextDoc
.getCurrentController());
178 //now get the OButtonControl
180 oObj
= the_access
.getControl(the_Model
);
181 aControl
= the_access
.getControl(the_Model2
);
182 the_win
= the_access
.getControl(the_Model
).getPeer();
183 the_kit
= the_win
.getToolkit();
184 aDevice
= the_kit
.createScreenCompatibleDevice(200, 200);
185 aGraphic
= aDevice
.createGraphics();
186 } catch (com
.sun
.star
.container
.NoSuchElementException e
) {
187 log
.println("Couldn't get OButtonControl");
188 e
.printStackTrace(log
);
189 throw new StatusException("Couldn't get OButtonControl", e
);
192 log
.println("creating a new environment for OButtonControl object");
194 TestEnvironment tEnv
= new TestEnvironment(oObj
);
197 //Adding ObjRelation for XView
198 tEnv
.addObjRelation("GRAPHICS", aGraphic
);
201 //Adding ObjRelation for XControl
202 tEnv
.addObjRelation("CONTEXT", xTextDoc
);
203 tEnv
.addObjRelation("WINPEER", the_win
);
204 tEnv
.addObjRelation("TOOLKIT", the_kit
);
205 tEnv
.addObjRelation("MODEL", the_Model
);
207 XWindow forObjRel
= UnoRuntime
.queryInterface(XWindow
.class,
210 tEnv
.addObjRelation("XWindow.AnotherWindow", forObjRel
);
211 tEnv
.addObjRelation("XWindow.ControlShape", aShape
);
214 } // finish method getTestEnvironment
215 } // finish class OButtonControl