bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _forms / OImageButtonControl.java
blobe2d56cc22ba37b82fc1f16befc0afc5bd31f50ad
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.text.XTextDocument;
38 import com.sun.star.uno.UnoRuntime;
39 import com.sun.star.uno.XInterface;
40 import com.sun.star.util.XCloseable;
41 import com.sun.star.view.XControlAccess;
44 /**
45 * Test for object which is represented by default controller
46 * of the <code>com.sun.star.form.component.ImageButton</code>
47 * component. <p>
49 * Object implements the following interfaces :
50 * <ul>
51 * <li> <code>com::sun::star::lang::XComponent</code></li>
52 * <li> <code>com::sun::star::awt::XWindow</code></li>
53 * <li> <code>com::sun::star::form::XApproveActionBroadcaster</code></li>
54 * <li> <code>com::sun::star::awt::XControl</code></li>
55 * <li> <code>com::sun::star::awt::XLayoutConstrains</code></li>
56 * <li> <code>com::sun::star::awt::XView</code></li>
57 * </ul> <p>
58 * This object test <b> is NOT </b> designed to be run in several
59 * threads concurently.
61 * @see com.sun.star.lang.XComponent
62 * @see com.sun.star.awt.XWindow
63 * @see com.sun.star.form.XApproveActionBroadcaster
64 * @see com.sun.star.awt.XControl
65 * @see com.sun.star.awt.XLayoutConstrains
66 * @see com.sun.star.awt.XView
67 * @see ifc.lang._XComponent
68 * @see ifc.awt._XWindow
69 * @see ifc.form._XApproveActionBroadcaster
70 * @see ifc.awt._XControl
71 * @see ifc.awt._XLayoutConstrains
72 * @see ifc.awt._XView
74 public class OImageButtonControl extends TestCase {
75 XTextDocument xTextDoc;
77 /**
78 * Creates a new text document.
80 @Override
81 protected void initialize(TestParameters Param, PrintWriter log) {
82 SOfficeFactory SOF = SOfficeFactory.getFactory((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 @Override
98 protected void cleanup(TestParameters tParam, PrintWriter log) {
99 log.println(" disposing xTextDoc ");
101 try {
102 XCloseable closer = UnoRuntime.queryInterface(
103 XCloseable.class, xTextDoc);
104 closer.close(true);
105 } catch (com.sun.star.util.CloseVetoException e) {
106 log.println("couldn't close document");
107 } catch (com.sun.star.lang.DisposedException e) {
108 log.println("couldn't close document");
113 * Creates two components and inserts them to the form of
114 * text document. One component
115 * (<code>com.sun.star.form.component.ImageButton</code>) is created
116 * for testing, another to be passed as relation. Using a controller
117 * of the text document the controller of the first component is
118 * obtained and returned in environment as a test object. <p>
120 * Object relations created :
121 * <ul>
122 * <li> <code>'GRAPHICS'</code> for
123 * {@link ifc.awt._XView} : a graphics component
124 * created using screen device of the window peer of
125 * the controller tested. </li>
126 * <li> <code>'CONTEXT'</code> for
127 * {@link ifc.awt._XControl} : the text document
128 * where the component is inserted. </li>
129 * <li> <code>'WINPEER'</code> for
130 * {@link ifc.awt._XControl} : Window peer of the
131 * controller tested. </li>
132 * <li> <code>'TOOLKIT'</code> for
133 * {@link ifc.awt._XControl} : toolkit of the component.</li>
134 * <li> <code>'MODEL'</code> for
135 * {@link ifc.awt._XControl} : the model of the controller.</li>
136 * <li> <code>'XWindow.AnotherWindow'</code> for
137 * {@link ifc.awt._XWindow} : the controller of another
138 * component. </li>
139 * </ul>
141 @Override
142 protected TestEnvironment createTestEnvironment(TestParameters Param,
143 PrintWriter log) {
144 XInterface oObj = null;
145 Object anotherCtrl = null;
146 XWindowPeer the_win = null;
147 XToolkit the_kit = null;
148 XDevice aDevice = null;
149 XGraphics aGraphic = null;
151 //Insert a ControlShape and get the ControlModel
152 XControlShape aShape = FormTools.createControlShape(xTextDoc, 3000,
153 4500, 15000, 10000,
154 "ImageButton");
156 WriterTools.getDrawPage(xTextDoc).add(aShape);
158 XControlModel the_Model = aShape.getControl();
160 XControlShape aShape2 = FormTools.createControlShape(xTextDoc, 3000,
161 4500, 5000, 10000,
162 "TextField");
164 WriterTools.getDrawPage(xTextDoc).add(aShape2);
166 XControlModel the_Model2 = aShape2.getControl();
168 //Try to query XControlAccess
169 XControlAccess the_access = UnoRuntime.queryInterface(
170 XControlAccess.class,
171 xTextDoc.getCurrentController());
173 //now get the OImageButtonControl
174 try {
175 oObj = the_access.getControl(the_Model);
176 anotherCtrl = the_access.getControl(the_Model2);
177 the_win = the_access.getControl(the_Model).getPeer();
178 the_kit = the_win.getToolkit();
179 aDevice = the_kit.createScreenCompatibleDevice(200, 200);
180 aGraphic = aDevice.createGraphics();
181 } catch (com.sun.star.container.NoSuchElementException e) {
182 log.println("Couldn't get OImageButtonControl");
183 e.printStackTrace(log);
184 throw new StatusException("Couldn't get OImageButtonControl", e);
187 log.println(
188 "creating a new environment for OImageButtonControl object");
190 TestEnvironment tEnv = new TestEnvironment(oObj);
193 //Adding ObjRelation for XView
194 tEnv.addObjRelation("GRAPHICS", aGraphic);
197 //Adding ObjRelation for XControl
198 tEnv.addObjRelation("CONTEXT", xTextDoc);
199 tEnv.addObjRelation("WINPEER", the_win);
200 tEnv.addObjRelation("TOOLKIT", the_kit);
201 tEnv.addObjRelation("MODEL", the_Model);
203 // Adding relation for XWindow
204 XWindow forObjRel = UnoRuntime.queryInterface(XWindow.class,
205 anotherCtrl);
207 tEnv.addObjRelation("XWindow.AnotherWindow", forObjRel);
209 return tEnv;
210 } // finish method getTestEnvironment
211 } // finish class OImageButtonControl