bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _forms / OGroupBoxControl.java
blobd76af3480fa11e870c55ad72c9508bfbc34a6341
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;
29 import util.utils;
31 import com.sun.star.awt.XControlModel;
32 import com.sun.star.awt.XDevice;
33 import com.sun.star.awt.XGraphics;
34 import com.sun.star.awt.XToolkit;
35 import com.sun.star.awt.XWindow;
36 import com.sun.star.awt.XWindowPeer;
37 import com.sun.star.drawing.XControlShape;
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.GroupBox</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::awt::XControl</code></li>
55 * <li> <code>com::sun::star::awt::XView</code></li>
56 * </ul> <p>
57 * This object test <b> is NOT </b> designed to be run in several
58 * threads concurently.
60 * @see com.sun.star.lang.XComponent
61 * @see com.sun.star.awt.XWindow
62 * @see com.sun.star.awt.XControl
63 * @see com.sun.star.awt.XView
64 * @see ifc.lang._XComponent
65 * @see ifc.awt._XWindow
66 * @see ifc.awt._XControl
67 * @see ifc.awt._XView
69 public class OGroupBoxControl extends TestCase {
70 XTextDocument xTextDoc;
72 /**
73 * Creates a new text document.
75 @Override
76 protected void initialize(TestParameters Param, PrintWriter log) {
77 SOfficeFactory SOF = SOfficeFactory.getFactory((Param.getMSF()));
79 try {
80 log.println("creating a textdocument");
81 xTextDoc = SOF.createTextDoc(null);
82 } catch (com.sun.star.uno.Exception e) {
83 // Some exception occurs.FAILED
84 e.printStackTrace(log);
85 throw new StatusException("Couldn't create document", e);
89 /**
90 * Disposes the text document created before
92 @Override
93 protected void cleanup(TestParameters tParam, PrintWriter log) {
94 log.println(" disposing xTextDoc ");
96 try {
97 XCloseable closer = UnoRuntime.queryInterface(
98 XCloseable.class, xTextDoc);
99 closer.close(true);
100 } catch (com.sun.star.util.CloseVetoException e) {
101 log.println("couldn't close document");
102 } catch (com.sun.star.lang.DisposedException e) {
103 log.println("couldn't close document");
108 * Creates two components and inserts them to the form of
109 * text document. One component
110 * (<code>com.sun.star.form.component.GroupBox</code>) is created
111 * for testing, another to be passed as relation. Using a controller
112 * of the text document the controller of the first component is
113 * obtained and returned in environment as a test object. <p>
115 * Object relations created :
116 * <ul>
117 * <li> <code>'GRAPHICS'</code> for
118 * {@link ifc.awt._XView} : a graphics component
119 * created using screen device of the window peer of
120 * the controller tested. </li>
121 * <li> <code>'CONTEXT'</code> for
122 * {@link ifc.awt._XControl} : the text document
123 * where the component is inserted. </li>
124 * <li> <code>'WINPEER'</code> for
125 * {@link ifc.awt._XControl} : Window peer of the
126 * controller tested. </li>
127 * <li> <code>'TOOLKIT'</code> for
128 * {@link ifc.awt._XControl} : toolkit of the component.</li>
129 * <li> <code>'MODEL'</code> for
130 * {@link ifc.awt._XControl} : the model of the controller.</li>
131 * <li> <code>'XWindow.AnotherWindow'</code> for
132 * {@link ifc.awt._XWindow} : the controller of another
133 * component. </li>
134 * </ul>
136 @Override
137 protected TestEnvironment createTestEnvironment(TestParameters Param,
138 PrintWriter log) {
139 XInterface oObj = null;
140 Object anotherCtrl = null;
141 XWindowPeer the_win = null;
142 XToolkit the_kit = null;
143 XDevice aDevice = null;
144 XGraphics aGraphic = null;
146 //Insert a ControlShape and get the ControlModel
147 XControlShape aShape = FormTools.createControlShape(xTextDoc, 5000,
148 7000, 2000, 2000,
149 "GroupBox");
151 WriterTools.getDrawPage(xTextDoc).add(aShape);
153 XControlModel the_Model = aShape.getControl();
155 XControlShape aShape2 = FormTools.createControlShape(xTextDoc, 3000,
156 4500, 5000, 10000,
157 "TextField");
159 WriterTools.getDrawPage(xTextDoc).add(aShape2);
161 XControlModel the_Model2 = aShape2.getControl();
163 //Try to query XControlAccess
164 XControlAccess the_access = UnoRuntime.queryInterface(
165 XControlAccess.class,
166 xTextDoc.getCurrentController());
168 //now get the OGroupBoxControl
169 try {
170 oObj = the_access.getControl(the_Model);
171 anotherCtrl = the_access.getControl(the_Model2);
172 the_win = the_access.getControl(the_Model).getPeer();
173 the_kit = the_win.getToolkit();
174 aDevice = the_kit.createScreenCompatibleDevice(200, 200);
175 aGraphic = aDevice.createGraphics();
176 } catch (com.sun.star.container.NoSuchElementException e) {
177 log.println("Couldn't get OGroupBoxControl");
178 e.printStackTrace(log);
179 throw new StatusException("Couldn't get OGroupBoxControl", e);
182 log.println("creating a new environment for OGroupBoxControl object");
184 TestEnvironment tEnv = new TestEnvironment(oObj);
187 //Adding ObjRelation for XView
188 tEnv.addObjRelation("GRAPHICS", aGraphic);
191 //Adding ObjRelation for XControl
192 tEnv.addObjRelation("CONTEXT", xTextDoc);
193 tEnv.addObjRelation("WINPEER", the_win);
194 tEnv.addObjRelation("TOOLKIT", the_kit);
195 tEnv.addObjRelation("MODEL", the_Model);
196 log.println("ImplementationName: " + utils.getImplName(oObj));
199 // Adding relation for XWindow
200 tEnv.addObjRelation("XWindow.AnotherWindow",
201 UnoRuntime.queryInterface(XWindow.class,
202 anotherCtrl));
204 return tEnv;
205 } // finish method getTestEnvironment
206 } // finish class OGroupBoxControl