Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _forms / OCheckBoxControl.java
blob379a6b9d379fe37a88e40b030cdd79a16e12545a
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.text.XTextDocument;
41 import com.sun.star.uno.UnoRuntime;
42 import com.sun.star.uno.XInterface;
43 import com.sun.star.util.XCloseable;
44 import com.sun.star.view.XControlAccess;
47 /**
48 * Test for object which is represented by default controller
49 * of the <code>com.sun.star.form.component.CheckBox</code>
50 * component. <p>
52 * Object implements the following interfaces :
53 * <ul>
54 * <li> <code>com::sun::star::awt::XView</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::XItemListener</code></li>
59 * <li> <code>com::sun::star::awt::XWindow</code></li>
60 * <li> <code>com::sun::star::awt::XCheckBox</code></li>
61 * <li> <code>com::sun::star::lang::XComponent</code></li>
62 * <li> <code>com::sun::star::lang::XEventListener</code></li>
63 * </ul> <p>
64 * This object test <b> is NOT </b> designed to be run in several
65 * threads concurently.
67 * @see com.sun.star.awt.XView
68 * @see com.sun.star.form.XBoundControl
69 * @see com.sun.star.awt.XControl
70 * @see com.sun.star.awt.XLayoutConstrains
71 * @see com.sun.star.awt.XItemListener
72 * @see com.sun.star.awt.XWindow
73 * @see com.sun.star.awt.XCheckBox
74 * @see com.sun.star.lang.XComponent
75 * @see com.sun.star.lang.XEventListener
76 * @see ifc.awt._XView
77 * @see ifc.form._XBoundControl
78 * @see ifc.awt._XControl
79 * @see ifc.awt._XLayoutConstrains
80 * @see ifc.awt._XItemListener
81 * @see ifc.awt._XWindow
82 * @see ifc.awt._XCheckBox
83 * @see ifc.lang._XComponent
84 * @see ifc.lang._XEventListener
86 public class OCheckBoxControl extends TestCase {
88 XTextDocument xTextDoc;
90 /**
91 * Creates a new text document.
93 @Override
94 protected void initialize ( TestParameters Param, PrintWriter log) {
95 SOfficeFactory SOF = SOfficeFactory.getFactory( (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 @Override
111 protected void cleanup(TestParameters tParam, PrintWriter log) {
112 log.println(" disposing xTextDoc ");
114 try {
115 XCloseable closer = UnoRuntime.queryInterface(
116 XCloseable.class, xTextDoc);
117 closer.close(true);
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.CheckBox</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 :
134 * <ul>
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
151 * component. </li>
152 * <li> <code>'TestItemListener'</code> for
153 * {@link ifc.awt._XItemListener} : listener implementation is
154 * registered here and passed as relation. </li>
155 * </ul>
157 @Override
158 protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
159 XInterface oObj = null;
160 XWindowPeer the_win = null;
161 XToolkit the_kit = null;
162 XDevice aDevice = null;
163 XGraphics aGraphic = null;
164 XControl aControl = null;
165 //Insert a ControlShape and get the ControlModel
166 XControlShape aShape = FormTools.createControlShape(
167 xTextDoc,3000,4500,15000,10000,"CheckBox");
169 WriterTools.getDrawPage(xTextDoc).add(aShape);
171 XControlModel the_Model = aShape.getControl();
173 XControlShape aShape2 = FormTools.createControlShape(
174 xTextDoc,3000,4500,5000,10000,"TextField");
176 WriterTools.getDrawPage(xTextDoc).add(aShape2);
178 XControlModel the_Model2 = aShape2.getControl();
180 //Try to query XControlAccess
181 XControlAccess the_access = UnoRuntime.queryInterface(
182 XControlAccess.class,xTextDoc.getCurrentController());
184 //now get the OButtonControl
185 try {
186 oObj = the_access.getControl(the_Model);
187 aControl = the_access.getControl(the_Model2);
188 the_win = the_access.getControl(the_Model).getPeer();
189 the_kit = the_win.getToolkit();
190 aDevice = the_kit.createScreenCompatibleDevice(200,200);
191 aGraphic = aDevice.createGraphics();
192 } catch (com.sun.star.container.NoSuchElementException e) {
193 log.println("Couldn't get OCheckBoxControl");
194 e.printStackTrace(log);
195 throw new StatusException("Couldn't get OCheckBoxControl", e );
198 log.println( "creating a new environment for OCheckBoxControl object" );
199 TestEnvironment tEnv = new TestEnvironment( oObj );
201 //Adding ObjRelation for XView
202 tEnv.addObjRelation("GRAPHICS",aGraphic);
204 //Adding ObjRelation for XControl
205 tEnv.addObjRelation("CONTEXT",xTextDoc);
206 tEnv.addObjRelation("WINPEER",the_win);
207 tEnv.addObjRelation("TOOLKIT",the_kit);
208 tEnv.addObjRelation("MODEL",the_Model);
210 // Adding relation for XItemListener
211 ifc.awt._XItemListener.TestItemListener listener =
212 new ifc.awt._XItemListener.TestItemListener() ;
213 XCheckBox box = UnoRuntime.queryInterface
214 (XCheckBox.class, oObj) ;
215 box.addItemListener(listener) ;
216 tEnv.addObjRelation("TestItemListener", listener) ;
218 // Adding relation for XWindow
219 XWindow forObjRel = UnoRuntime.queryInterface(XWindow.class,aControl);
221 tEnv.addObjRelation("XWindow.AnotherWindow",forObjRel);
223 return tEnv;
224 } // finish method getTestEnvironment
226 } // finish class OButtonControl