merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _forms / OGroupBoxControl.java
blob4dbc6fc759e2e48247a5718a5523495688eebecc
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: OGroupBoxControl.java,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 package mod._forms;
32 import java.io.PrintWriter;
34 import lib.StatusException;
35 import lib.TestCase;
36 import lib.TestEnvironment;
37 import lib.TestParameters;
38 import util.FormTools;
39 import util.SOfficeFactory;
40 import util.WriterTools;
41 import util.utils;
43 import com.sun.star.awt.XControlModel;
44 import com.sun.star.awt.XDevice;
45 import com.sun.star.awt.XGraphics;
46 import com.sun.star.awt.XToolkit;
47 import com.sun.star.awt.XWindow;
48 import com.sun.star.awt.XWindowPeer;
49 import com.sun.star.drawing.XControlShape;
50 import com.sun.star.drawing.XShape;
51 import com.sun.star.lang.XMultiServiceFactory;
52 import com.sun.star.text.XTextDocument;
53 import com.sun.star.uno.UnoRuntime;
54 import com.sun.star.uno.XInterface;
55 import com.sun.star.util.XCloseable;
56 import com.sun.star.view.XControlAccess;
59 /**
60 * Test for object which is represented by default controller
61 * of the <code>com.sun.star.form.component.GroupBox</code>
62 * component. <p>
64 * Object implements the following interfaces :
65 * <ul>
66 * <li> <code>com::sun::star::lang::XComponent</code></li>
67 * <li> <code>com::sun::star::awt::XWindow</code></li>
68 * <li> <code>com::sun::star::awt::XControl</code></li>
69 * <li> <code>com::sun::star::awt::XView</code></li>
70 * </ul> <p>
71 * This object test <b> is NOT </b> designed to be run in several
72 * threads concurently.
74 * @see com.sun.star.lang.XComponent
75 * @see com.sun.star.awt.XWindow
76 * @see com.sun.star.awt.XControl
77 * @see com.sun.star.awt.XView
78 * @see ifc.lang._XComponent
79 * @see ifc.awt._XWindow
80 * @see ifc.awt._XControl
81 * @see ifc.awt._XView
83 public class OGroupBoxControl extends TestCase {
84 XTextDocument xTextDoc;
86 /**
87 * Creates a new text document.
89 protected void initialize(TestParameters Param, PrintWriter log) {
90 SOfficeFactory SOF = SOfficeFactory.getFactory(((XMultiServiceFactory) Param.getMSF()));
92 try {
93 log.println("creating a textdocument");
94 xTextDoc = SOF.createTextDoc(null);
95 } catch (com.sun.star.uno.Exception e) {
96 // Some exception occures.FAILED
97 e.printStackTrace(log);
98 throw new StatusException("Couldn't create document", e);
103 * Disposes the text document created before
105 protected void cleanup(TestParameters tParam, PrintWriter log) {
106 log.println(" disposing xTextDoc ");
108 try {
109 XCloseable closer = (XCloseable) UnoRuntime.queryInterface(
110 XCloseable.class, xTextDoc);
111 closer.close(true);
112 } catch (com.sun.star.util.CloseVetoException e) {
113 log.println("couldn't close document");
114 } catch (com.sun.star.lang.DisposedException e) {
115 log.println("couldn't close document");
120 * Creates two components and inserts them to the form of
121 * text document. One component
122 * (<code>com.sun.star.form.component.GroupBox</code>) is created
123 * for testing, another to be passed as relation. Using a controller
124 * of the text document the controller of the first component is
125 * obtained and returned in environment as a test object. <p>
127 * Object relations created :
128 * <ul>
129 * <li> <code>'GRAPHICS'</code> for
130 * {@link ifc.awt._XView} : a graphics component
131 * created using screen device of the window peer of
132 * the controller tested. </li>
133 * <li> <code>'CONTEXT'</code> for
134 * {@link ifc.awt._XControl} : the text document
135 * where the component is inserted. </li>
136 * <li> <code>'WINPEER'</code> for
137 * {@link ifc.awt._XControl} : Window peer of the
138 * controller tested. </li>
139 * <li> <code>'TOOLKIT'</code> for
140 * {@link ifc.awt._XControl} : toolkit of the component.</li>
141 * <li> <code>'MODEL'</code> for
142 * {@link ifc.awt._XControl} : the model of the controller.</li>
143 * <li> <code>'XWindow.AnotherWindow'</code> for
144 * {@link ifc.awt._XWindow} : the controller of another
145 * component. </li>
146 * </ul>
148 protected TestEnvironment createTestEnvironment(TestParameters Param,
149 PrintWriter log) {
150 XInterface oObj = null;
151 Object anotherCtrl = null;
152 XWindowPeer the_win = null;
153 XToolkit the_kit = null;
154 XDevice aDevice = null;
155 XGraphics aGraphic = null;
157 //Insert a ControlShape and get the ControlModel
158 XControlShape aShape = FormTools.createControlShape(xTextDoc, 5000,
159 7000, 2000, 2000,
160 "GroupBox");
162 WriterTools.getDrawPage(xTextDoc).add((XShape) aShape);
164 XControlModel the_Model = aShape.getControl();
166 XControlShape aShape2 = FormTools.createControlShape(xTextDoc, 3000,
167 4500, 5000, 10000,
168 "TextField");
170 WriterTools.getDrawPage(xTextDoc).add((XShape) aShape2);
172 XControlModel the_Model2 = aShape2.getControl();
174 //Try to query XControlAccess
175 XControlAccess the_access = (XControlAccess) UnoRuntime.queryInterface(
176 XControlAccess.class,
177 xTextDoc.getCurrentController());
179 //now get the OGroupBoxControl
180 try {
181 oObj = the_access.getControl(the_Model);
182 anotherCtrl = the_access.getControl(the_Model2);
183 the_win = the_access.getControl(the_Model).getPeer();
184 the_kit = the_win.getToolkit();
185 aDevice = the_kit.createScreenCompatibleDevice(200, 200);
186 aGraphic = aDevice.createGraphics();
187 } catch (com.sun.star.container.NoSuchElementException e) {
188 log.println("Couldn't get OGroupBoxControl");
189 e.printStackTrace(log);
190 throw new StatusException("Couldn't get OGroupBoxControl", e);
193 log.println("creating a new environment for OGroupBoxControl object");
195 TestEnvironment tEnv = new TestEnvironment(oObj);
198 //Adding ObjRelation for XView
199 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);
207 log.println("ImplementationName: " + utils.getImplName(oObj));
210 // Adding relation for XWindow
211 tEnv.addObjRelation("XWindow.AnotherWindow",
212 UnoRuntime.queryInterface(XWindow.class,
213 anotherCtrl));
215 return tEnv;
216 } // finish method getTestEnvironment
217 } // finish class OGroupBoxControl