bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _forms / OCheckBoxControl.java
blobf698c2a4433dae496165fdd5756a922bfb36635c
1 /*
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 .
19 package mod._forms;
21 import java.io.PrintWriter;
23 import lib.StatusException;
24 import lib.TestCase;
25 import lib.TestEnvironment;
26 import lib.TestParameters;
27 import util.FormTools;
28 import util.SOfficeFactory;
29 import util.WriterTools;
31 import com.sun.star.awt.XCheckBox;
32 import com.sun.star.awt.XControl;
33 import com.sun.star.awt.XControlModel;
34 import com.sun.star.awt.XDevice;
35 import com.sun.star.awt.XGraphics;
36 import com.sun.star.awt.XToolkit;
37 import com.sun.star.awt.XWindow;
38 import com.sun.star.awt.XWindowPeer;
39 import com.sun.star.drawing.XControlShape;
40 import com.sun.star.lang.XMultiServiceFactory;
41 import com.sun.star.text.XTextDocument;
42 import com.sun.star.uno.UnoRuntime;
43 import com.sun.star.uno.XInterface;
44 import com.sun.star.util.XCloseable;
45 import com.sun.star.view.XControlAccess;
48 /**
49 * Test for object which is represented by default controller
50 * of the <code>com.sun.star.form.component.CheckBox</code>
51 * component. <p>
53 * Object implements the following interfaces :
54 * <ul>
55 * <li> <code>com::sun::star::awt::XView</code></li>
56 * <li> <code>com::sun::star::form::XBoundControl</code></li>
57 * <li> <code>com::sun::star::awt::XControl</code></li>
58 * <li> <code>com::sun::star::awt::XLayoutConstrains</code></li>
59 * <li> <code>com::sun::star::awt::XItemListener</code></li>
60 * <li> <code>com::sun::star::awt::XWindow</code></li>
61 * <li> <code>com::sun::star::awt::XCheckBox</code></li>
62 * <li> <code>com::sun::star::lang::XComponent</code></li>
63 * <li> <code>com::sun::star::lang::XEventListener</code></li>
64 * </ul> <p>
65 * This object test <b> is NOT </b> designed to be run in several
66 * threads concurently.
68 * @see com.sun.star.awt.XView
69 * @see com.sun.star.form.XBoundControl
70 * @see com.sun.star.awt.XControl
71 * @see com.sun.star.awt.XLayoutConstrains
72 * @see com.sun.star.awt.XItemListener
73 * @see com.sun.star.awt.XWindow
74 * @see com.sun.star.awt.XCheckBox
75 * @see com.sun.star.lang.XComponent
76 * @see com.sun.star.lang.XEventListener
77 * @see ifc.awt._XView
78 * @see ifc.form._XBoundControl
79 * @see ifc.awt._XControl
80 * @see ifc.awt._XLayoutConstrains
81 * @see ifc.awt._XItemListener
82 * @see ifc.awt._XWindow
83 * @see ifc.awt._XCheckBox
84 * @see ifc.lang._XComponent
85 * @see ifc.lang._XEventListener
87 public class OCheckBoxControl extends TestCase {
89 XTextDocument xTextDoc;
91 /**
92 * Creates a new text document.
94 protected void initialize ( TestParameters Param, PrintWriter log) {
95 SOfficeFactory SOF = SOfficeFactory.getFactory( ((XMultiServiceFactory)Param.getMSF()) );
97 try {
98 log.println( "creating a textdocument" );
99 xTextDoc = SOF.createTextDoc( null );
100 } catch ( com.sun.star.uno.Exception e ) {
101 // Some exception occurs.FAILED
102 e.printStackTrace( log );
103 throw new StatusException( "Couldn't create document", e );
108 * Disposes the text document created before
110 protected void cleanup(TestParameters tParam, PrintWriter log) {
111 log.println(" disposing xTextDoc ");
113 try {
114 XCloseable closer = UnoRuntime.queryInterface(
115 XCloseable.class, xTextDoc);
116 closer.close(true);
117 } catch (com.sun.star.util.CloseVetoException e) {
118 log.println("couldn't close document");
119 } catch (com.sun.star.lang.DisposedException e) {
120 log.println("couldn't close document");
125 * Creates two components and inserts them to the form of
126 * text document. One component
127 * (<code>com.sun.star.form.component.CheckBox</code>) is created
128 * for testing, another to be passed as relation. Using a controller
129 * of the text document the controller of the first component is
130 * obtained and returned in environment as a test object. <p>
132 * Object relations created :
133 * <ul>
134 * <li> <code>'GRAPHICS'</code> for
135 * {@link ifc.awt._XView} : a graphics component
136 * created using screen device of the window peer of
137 * the controller tested. </li>
138 * <li> <code>'CONTEXT'</code> for
139 * {@link ifc.awt._XControl} : the text document
140 * where the component is inserted. </li>
141 * <li> <code>'WINPEER'</code> for
142 * {@link ifc.awt._XControl} : Window peer of the
143 * controller tested. </li>
144 * <li> <code>'TOOLKIT'</code> for
145 * {@link ifc.awt._XControl} : toolkit of the component.</li>
146 * <li> <code>'MODEL'</code> for
147 * {@link ifc.awt._XControl} : the model of the controller.</li>
148 * <li> <code>'XWindow.AnotherWindow'</code> for
149 * {@link ifc.awt._XWindow} : the controller of another
150 * component. </li>
151 * <li> <code>'TestItemListener'</code> for
152 * {@link ifc.awt._XItemListener} : listener implementation is
153 * registered here and passed as relation. </li>
154 * </ul>
156 protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
157 XInterface oObj = null;
158 XWindowPeer the_win = null;
159 XToolkit the_kit = null;
160 XDevice aDevice = null;
161 XGraphics aGraphic = null;
162 XControl aControl = null;
163 //Insert a ControlShape and get the ControlModel
164 XControlShape aShape = FormTools.createControlShape(
165 xTextDoc,3000,4500,15000,10000,"CheckBox");
167 WriterTools.getDrawPage(xTextDoc).add(aShape);
169 XControlModel the_Model = aShape.getControl();
171 XControlShape aShape2 = FormTools.createControlShape(
172 xTextDoc,3000,4500,5000,10000,"TextField");
174 WriterTools.getDrawPage(xTextDoc).add(aShape2);
176 XControlModel the_Model2 = aShape2.getControl();
178 //Try to query XControlAccess
179 XControlAccess the_access = UnoRuntime.queryInterface(
180 XControlAccess.class,xTextDoc.getCurrentController());
182 //now get the OButtonControl
183 try {
184 oObj = the_access.getControl(the_Model);
185 aControl = the_access.getControl(the_Model2);
186 the_win = the_access.getControl(the_Model).getPeer();
187 the_kit = the_win.getToolkit();
188 aDevice = the_kit.createScreenCompatibleDevice(200,200);
189 aGraphic = aDevice.createGraphics();
190 } catch (com.sun.star.container.NoSuchElementException e) {
191 log.println("Couldn't get OCheckBoxControl");
192 e.printStackTrace(log);
193 throw new StatusException("Couldn't get OCheckBoxControl", e );
196 log.println( "creating a new environment for OCheckBoxControl object" );
197 TestEnvironment tEnv = new TestEnvironment( oObj );
199 //Adding ObjRelation for XView
200 tEnv.addObjRelation("GRAPHICS",aGraphic);
202 //Adding ObjRelation for XControl
203 tEnv.addObjRelation("CONTEXT",xTextDoc);
204 tEnv.addObjRelation("WINPEER",the_win);
205 tEnv.addObjRelation("TOOLKIT",the_kit);
206 tEnv.addObjRelation("MODEL",the_Model);
208 // Adding relation for XItemListener
209 ifc.awt._XItemListener.TestItemListener listener =
210 new ifc.awt._XItemListener.TestItemListener() ;
211 XCheckBox box = UnoRuntime.queryInterface
212 (XCheckBox.class, oObj) ;
213 box.addItemListener(listener) ;
214 tEnv.addObjRelation("TestItemListener", listener) ;
216 // Adding relation for XWindow
217 XWindow forObjRel = UnoRuntime.queryInterface(XWindow.class,aControl);
219 tEnv.addObjRelation("XWindow.AnotherWindow",forObjRel);
221 return tEnv;
222 } // finish method getTestEnvironment
224 } // finish class OButtonControl