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 .
21 import java
.io
.PrintWriter
;
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
.XCheckBox
;
31 import com
.sun
.star
.awt
.XControl
;
32 import com
.sun
.star
.awt
.XControlModel
;
33 import com
.sun
.star
.awt
.XDevice
;
34 import com
.sun
.star
.awt
.XGraphics
;
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
.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.CheckBox</code>
51 * Object implements the following interfaces :
53 * <li> <code>com::sun::star::awt::XView</code></li>
54 * <li> <code>com::sun::star::form::XBoundControl</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::XItemListener</code></li>
58 * <li> <code>com::sun::star::awt::XWindow</code></li>
59 * <li> <code>com::sun::star::awt::XCheckBox</code></li>
60 * <li> <code>com::sun::star::lang::XComponent</code></li>
61 * <li> <code>com::sun::star::lang::XEventListener</code></li>
63 * This object test <b> is NOT </b> designed to be run in several
64 * threads concurrently.
66 * @see com.sun.star.awt.XView
67 * @see com.sun.star.form.XBoundControl
68 * @see com.sun.star.awt.XControl
69 * @see com.sun.star.awt.XLayoutConstrains
70 * @see com.sun.star.awt.XItemListener
71 * @see com.sun.star.awt.XWindow
72 * @see com.sun.star.awt.XCheckBox
73 * @see com.sun.star.lang.XComponent
74 * @see com.sun.star.lang.XEventListener
76 * @see ifc.form._XBoundControl
77 * @see ifc.awt._XControl
78 * @see ifc.awt._XLayoutConstrains
79 * @see ifc.awt._XItemListener
80 * @see ifc.awt._XWindow
81 * @see ifc.awt._XCheckBox
82 * @see ifc.lang._XComponent
83 * @see ifc.lang._XEventListener
85 public class OCheckBoxControl
extends TestCase
{
87 XTextDocument xTextDoc
;
90 * Creates a new text document.
93 protected void initialize ( TestParameters Param
, PrintWriter log
) throws Exception
{
94 SOfficeFactory SOF
= SOfficeFactory
.getFactory( Param
.getMSF() );
95 log
.println( "creating a textdocument" );
96 xTextDoc
= SOF
.createTextDoc( null );
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.CheckBox</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
144 * <li> <code>'TestItemListener'</code> for
145 * {@link ifc.awt._XItemListener} : listener implementation is
146 * registered here and passed as relation. </li>
150 protected TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) throws Exception
{
151 XInterface oObj
= null;
152 XWindowPeer the_win
= null;
153 XToolkit the_kit
= null;
154 XDevice aDevice
= null;
155 XGraphics aGraphic
= null;
156 XControl aControl
= null;
157 //Insert a ControlShape and get the ControlModel
158 XControlShape aShape
= FormTools
.createControlShape(
159 xTextDoc
,3000,4500,15000,10000,"CheckBox");
161 WriterTools
.getDrawPage(xTextDoc
).add(aShape
);
163 XControlModel the_Model
= aShape
.getControl();
165 XControlShape aShape2
= FormTools
.createControlShape(
166 xTextDoc
,3000,4500,5000,10000,"TextField");
168 WriterTools
.getDrawPage(xTextDoc
).add(aShape2
);
170 XControlModel the_Model2
= aShape2
.getControl();
172 //Try to query XControlAccess
173 XControlAccess the_access
= UnoRuntime
.queryInterface(
174 XControlAccess
.class,xTextDoc
.getCurrentController());
176 //now get the OButtonControl
177 oObj
= the_access
.getControl(the_Model
);
178 aControl
= the_access
.getControl(the_Model2
);
179 the_win
= the_access
.getControl(the_Model
).getPeer();
180 the_kit
= the_win
.getToolkit();
181 aDevice
= the_kit
.createScreenCompatibleDevice(200,200);
182 aGraphic
= aDevice
.createGraphics();
184 log
.println( "creating a new environment for OCheckBoxControl object" );
185 TestEnvironment tEnv
= new TestEnvironment( oObj
);
187 //Adding ObjRelation for XView
188 tEnv
.addObjRelation("GRAPHICS",aGraphic
);
190 //Adding ObjRelation for XControl
191 tEnv
.addObjRelation("CONTEXT",xTextDoc
);
192 tEnv
.addObjRelation("WINPEER",the_win
);
193 tEnv
.addObjRelation("TOOLKIT",the_kit
);
194 tEnv
.addObjRelation("MODEL",the_Model
);
196 // Adding relation for XItemListener
197 ifc
.awt
._XItemListener
.TestItemListener listener
=
198 new ifc
.awt
._XItemListener
.TestItemListener() ;
199 XCheckBox box
= UnoRuntime
.queryInterface
200 (XCheckBox
.class, oObj
) ;
201 box
.addItemListener(listener
) ;
202 tEnv
.addObjRelation("TestItemListener", listener
) ;
204 // Adding relation for XWindow
205 XWindow forObjRel
= UnoRuntime
.queryInterface(XWindow
.class,aControl
);
207 tEnv
.addObjRelation("XWindow.AnotherWindow",forObjRel
);
210 } // finish method getTestEnvironment
212 } // finish class OButtonControl