bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _forms / OImageButtonControl.java
blob751bb12bc6de7527b005a5eedc34cc483301f063
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 .
18 package mod._forms;
20 import java.io.PrintWriter;
22 import lib.StatusException;
23 import lib.TestCase;
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.XControlModel;
31 import com.sun.star.awt.XDevice;
32 import com.sun.star.awt.XGraphics;
33 import com.sun.star.awt.XToolkit;
34 import com.sun.star.awt.XWindow;
35 import com.sun.star.awt.XWindowPeer;
36 import com.sun.star.drawing.XControlShape;
37 import com.sun.star.lang.XMultiServiceFactory;
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;
45 /**
46 * Test for object which is represented by default controller
47 * of the <code>com.sun.star.form.component.ImageButton</code>
48 * component. <p>
50 * Object implements the following interfaces :
51 * <ul>
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::XView</code></li>
58 * </ul> <p>
59 * This object test <b> is NOT </b> designed to be run in several
60 * threads concurently.
62 * @see com.sun.star.lang.XComponent
63 * @see com.sun.star.awt.XWindow
64 * @see com.sun.star.form.XApproveActionBroadcaster
65 * @see com.sun.star.awt.XControl
66 * @see com.sun.star.awt.XLayoutConstrains
67 * @see com.sun.star.awt.XView
68 * @see ifc.lang._XComponent
69 * @see ifc.awt._XWindow
70 * @see ifc.form._XApproveActionBroadcaster
71 * @see ifc.awt._XControl
72 * @see ifc.awt._XLayoutConstrains
73 * @see ifc.awt._XView
75 public class OImageButtonControl extends TestCase {
76 XTextDocument xTextDoc;
78 /**
79 * Creates a new text document.
81 protected void initialize(TestParameters Param, PrintWriter log) {
82 SOfficeFactory SOF = SOfficeFactory.getFactory(((XMultiServiceFactory) Param.getMSF()));
84 try {
85 log.println("creating a textdocument");
86 xTextDoc = SOF.createTextDoc(null);
87 } catch (com.sun.star.uno.Exception e) {
88 // Some exception occurs.FAILED
89 e.printStackTrace(log);
90 throw new StatusException("Couldn't create document", e);
94 /**
95 * Disposes the text document created before
97 protected void cleanup(TestParameters tParam, PrintWriter log) {
98 log.println(" disposing xTextDoc ");
100 try {
101 XCloseable closer = UnoRuntime.queryInterface(
102 XCloseable.class, xTextDoc);
103 closer.close(true);
104 } catch (com.sun.star.util.CloseVetoException e) {
105 log.println("couldn't close document");
106 } catch (com.sun.star.lang.DisposedException e) {
107 log.println("couldn't close document");
112 * Creates two components and inserts them to the form of
113 * text document. One component
114 * (<code>com.sun.star.form.component.ImageButton</code>) is created
115 * for testing, another to be passed as relation. Using a controller
116 * of the text document the controller of the first component is
117 * obtained and returned in environment as a test object. <p>
119 * Object relations created :
120 * <ul>
121 * <li> <code>'GRAPHICS'</code> for
122 * {@link ifc.awt._XView} : a graphics component
123 * created using screen device of the window peer of
124 * the controller tested. </li>
125 * <li> <code>'CONTEXT'</code> for
126 * {@link ifc.awt._XControl} : the text document
127 * where the component is inserted. </li>
128 * <li> <code>'WINPEER'</code> for
129 * {@link ifc.awt._XControl} : Window peer of the
130 * controller tested. </li>
131 * <li> <code>'TOOLKIT'</code> for
132 * {@link ifc.awt._XControl} : toolkit of the component.</li>
133 * <li> <code>'MODEL'</code> for
134 * {@link ifc.awt._XControl} : the model of the controller.</li>
135 * <li> <code>'XWindow.AnotherWindow'</code> for
136 * {@link ifc.awt._XWindow} : the controller of another
137 * component. </li>
138 * </ul>
140 protected TestEnvironment createTestEnvironment(TestParameters Param,
141 PrintWriter log) {
142 XInterface oObj = null;
143 Object anotherCtrl = null;
144 XWindowPeer the_win = null;
145 XToolkit the_kit = null;
146 XDevice aDevice = null;
147 XGraphics aGraphic = null;
149 //Insert a ControlShape and get the ControlModel
150 XControlShape aShape = FormTools.createControlShape(xTextDoc, 3000,
151 4500, 15000, 10000,
152 "ImageButton");
154 WriterTools.getDrawPage(xTextDoc).add(aShape);
156 XControlModel the_Model = aShape.getControl();
158 XControlShape aShape2 = FormTools.createControlShape(xTextDoc, 3000,
159 4500, 5000, 10000,
160 "TextField");
162 WriterTools.getDrawPage(xTextDoc).add(aShape2);
164 XControlModel the_Model2 = aShape2.getControl();
166 //Try to query XControlAccess
167 XControlAccess the_access = UnoRuntime.queryInterface(
168 XControlAccess.class,
169 xTextDoc.getCurrentController());
171 //now get the OImageButtonControl
172 try {
173 oObj = the_access.getControl(the_Model);
174 anotherCtrl = the_access.getControl(the_Model2);
175 the_win = the_access.getControl(the_Model).getPeer();
176 the_kit = the_win.getToolkit();
177 aDevice = the_kit.createScreenCompatibleDevice(200, 200);
178 aGraphic = aDevice.createGraphics();
179 } catch (com.sun.star.container.NoSuchElementException e) {
180 log.println("Couldn't get OImageButtonControl");
181 e.printStackTrace(log);
182 throw new StatusException("Couldn't get OImageButtonControl", e);
185 log.println(
186 "creating a new environment for OImageButtonControl object");
188 TestEnvironment tEnv = new TestEnvironment(oObj);
191 //Adding ObjRelation for XView
192 tEnv.addObjRelation("GRAPHICS", aGraphic);
195 //Adding ObjRelation for XControl
196 tEnv.addObjRelation("CONTEXT", xTextDoc);
197 tEnv.addObjRelation("WINPEER", the_win);
198 tEnv.addObjRelation("TOOLKIT", the_kit);
199 tEnv.addObjRelation("MODEL", the_Model);
201 // Adding relation for XWindow
202 XWindow forObjRel = UnoRuntime.queryInterface(XWindow.class,
203 anotherCtrl);
205 tEnv.addObjRelation("XWindow.AnotherWindow", forObjRel);
207 return tEnv;
208 } // finish method getTestEnvironment
209 } // finish class OImageButtonControl