bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _toolkit / UnoControlContainer.java
blob8701e6a801100af212d3469a5769dcea372d4b49
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._toolkit;
20 import com.sun.star.awt.PosSize;
21 import com.sun.star.awt.Rectangle;
22 import com.sun.star.awt.XControl;
23 import com.sun.star.awt.XControlContainer;
24 import com.sun.star.awt.XControlModel;
25 import com.sun.star.awt.XDevice;
26 import com.sun.star.awt.XGraphics;
27 import com.sun.star.awt.XToolkit;
28 import com.sun.star.awt.XWindow;
29 import com.sun.star.awt.XWindowPeer;
30 import com.sun.star.drawing.XControlShape;
31 import com.sun.star.frame.XController;
32 import com.sun.star.frame.XFrame;
33 import com.sun.star.text.XTextDocument;
34 import com.sun.star.uno.UnoRuntime;
35 import com.sun.star.uno.XInterface;
36 import com.sun.star.view.XControlAccess;
38 import java.io.PrintWriter;
40 import lib.StatusException;
41 import lib.TestCase;
42 import lib.TestEnvironment;
43 import lib.TestParameters;
45 import util.FormTools;
46 import util.WriterTools;
47 import util.utils;
50 public class UnoControlContainer extends TestCase {
51 private static XTextDocument xTextDoc;
52 private static XTextDocument xTD2;
53 private static XControl xCtrl;
54 private static XControl xCtrl1;
55 private static XControl xCtrl2;
57 @Override
58 protected void initialize(TestParameters param, PrintWriter log) {
59 try {
60 log.println("creating a textdocument");
61 xTD2 = WriterTools.createTextDoc(
62 param.getMSF());
63 xTextDoc = WriterTools.createTextDoc(
64 param.getMSF());
65 } catch (Exception e) {
66 // Some exception occurs.FAILED
67 e.printStackTrace(log);
68 throw new StatusException("Couldn't create document", e);
72 @Override
73 protected void cleanup(TestParameters tParam, PrintWriter log) {
74 log.println(" disposing xTextDoc ");
76 util.DesktopTools.closeDoc(xTextDoc);
77 util.DesktopTools.closeDoc(xTD2);
80 @Override
81 public TestEnvironment createTestEnvironment(TestParameters param,
82 PrintWriter log) {
83 // create Object Relations -------------------------------------------
84 XInterface oObj = null;
85 XControlShape shape = null;
86 XControlModel model = null;
87 XControlAccess access = null;
88 XWindow anotherWindow = null;
90 // for XControl
91 XWindowPeer the_win = null;
92 XToolkit the_kit = null;
94 XControlContainer ctrlCont = null;
96 XGraphics aGraphic = null;
99 // create 3 XControls
100 // create first XControl
101 shape = FormTools.createControlShape(xTextDoc, 3000, 4500, 15000,
102 10000, "TextField");
103 WriterTools.getDrawPage(xTextDoc).add(shape);
104 model = shape.getControl();
105 access = UnoRuntime.queryInterface(
106 XControlAccess.class, xTextDoc.getCurrentController());
108 try {
109 xCtrl = access.getControl(model);
110 } catch (Exception e) {
111 e.printStackTrace(log);
112 throw new StatusException("Couldn't create XControl", e);
116 // create second XControl
117 shape = FormTools.createControlShape(xTextDoc, 3000, 4500, 15000,
118 10000, "TextField");
119 WriterTools.getDrawPage(xTextDoc).add(shape);
120 model = shape.getControl();
121 access = UnoRuntime.queryInterface(
122 XControlAccess.class, xTextDoc.getCurrentController());
124 try {
125 xCtrl1 = access.getControl(model);
126 } catch (Exception e) {
127 e.printStackTrace(log);
128 throw new StatusException("Couldn't create XControl", e);
132 // create third XControl
133 shape = FormTools.createControlShape(xTextDoc, 3000, 4500, 15000,
134 10000, "CommandButton");
135 WriterTools.getDrawPage(xTextDoc).add(shape);
136 model = shape.getControl();
137 access = UnoRuntime.queryInterface(
138 XControlAccess.class, xTextDoc.getCurrentController());
140 try {
141 xCtrl2 = access.getControl(model);
142 } catch (Exception e) {
143 e.printStackTrace(log);
144 throw new StatusException("Couldn't create XControl", e);
147 // create XToolkit, XWindowPeer, XDevice
148 //Insert a ControlShape and get the ControlModel
149 XControlShape aShape = FormTools.createUnoControlShape(xTextDoc, 3000,
150 4500, 15000,
151 10000,
152 "CommandButton",
153 "UnoControlButton");
155 WriterTools.getDrawPage(xTD2).add(aShape);
157 XControlModel the_Model = aShape.getControl();
159 //Try to query XControlAccess
160 XControlAccess the_access = UnoRuntime.queryInterface(
161 XControlAccess.class,
162 xTD2.getCurrentController());
164 //get the ButtonControl for the needed Object relations
165 try {
166 the_win = the_access.getControl(the_Model).getPeer();
167 the_kit = the_win.getToolkit();
169 XDevice aDevice = the_kit.createScreenCompatibleDevice(200, 200);
170 aGraphic = aDevice.createGraphics();
171 } catch (Exception e) {
172 log.println("Couldn't get ButtonControl");
173 e.printStackTrace(log);
174 throw new StatusException("Couldn't get ButtonControl", e);
177 try {
178 XController aController = xTD2.getCurrentController();
179 XFrame aFrame = aController.getFrame();
180 anotherWindow = aFrame.getComponentWindow();
181 } catch (Exception e) {
182 e.printStackTrace(log);
183 throw new StatusException("Couldn't create XWindow", e);
186 // finished create Object Relations -----------------------------------
187 // create the UnoControlContainer
188 try {
189 oObj = (XInterface) param.getMSF().createInstance(
190 "com.sun.star.awt.UnoControlContainer");
192 XControl xCtrl = UnoRuntime.queryInterface(
193 XControl.class, oObj);
194 xCtrl.setModel(the_Model);
196 ctrlCont = UnoRuntime.queryInterface(
197 XControlContainer.class, oObj);
198 ctrlCont.addControl("jupp", access.getControl(aShape.getControl()));
199 } catch (Exception e) {
200 e.printStackTrace(log);
201 throw new StatusException("Couldn't create UnoControlContainer", e);
204 log.println(
205 "creating a new environment for UnoControlContainer object");
207 TestEnvironment tEnv = new TestEnvironment(oObj);
209 XWindow xWindow = UnoRuntime.queryInterface(XWindow.class, oObj);
210 Rectangle ps = xWindow.getPosSize();
211 xWindow.setPosSize(ps.X+10, ps.Y+10, ps.Width+10, ps.Height+10, PosSize.POSSIZE);
213 String objName = "UnoControlContainer";
214 tEnv.addObjRelation("OBJNAME", "toolkit." + objName);
217 // Object relation for XContainer
218 tEnv.addObjRelation("XContainer.Container", ctrlCont);
219 tEnv.addObjRelation("INSTANCE", xCtrl);
222 //Adding ObjRelation for XView
223 tEnv.addObjRelation("GRAPHICS", aGraphic);
226 // Object Relation for XControlContainer
227 tEnv.addObjRelation("CONTROL1", xCtrl1);
228 tEnv.addObjRelation("CONTROL2", xCtrl2);
231 // Object Relation for XControl
232 tEnv.addObjRelation("CONTEXT", xTD2);
233 tEnv.addObjRelation("WINPEER", the_win);
234 tEnv.addObjRelation("TOOLKIT", the_kit);
235 tEnv.addObjRelation("MODEL", the_Model);
238 // Object Relation for XWindow
239 tEnv.addObjRelation("XWindow.AnotherWindow", anotherWindow);
240 System.out.println("ImplementationName: " + utils.getImplName(oObj));
242 return tEnv;