tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _toolkit / UnoControlDialog.java
blob2f0e6ddc7055b2410345f7dcb976eb82a588f54d
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.XControl;
22 import com.sun.star.awt.XControlContainer;
23 import com.sun.star.awt.XControlModel;
24 import com.sun.star.awt.XDevice;
25 import com.sun.star.awt.XGraphics;
26 import com.sun.star.awt.XTabController;
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.lang.XMultiServiceFactory;
31 import com.sun.star.text.XTextDocument;
32 import com.sun.star.uno.UnoRuntime;
33 import com.sun.star.uno.XInterface;
35 import java.io.PrintWriter;
37 import lib.TestCase;
38 import lib.TestEnvironment;
39 import lib.TestParameters;
41 import util.SOfficeFactory;
44 /**
45 * Test for object which is represented by service
46 * <code>com.sun.star.awt.UnoControlDialog</code>. <p>
47 * Object implements the following interfaces :
48 * <ul>
49 * <li> <code>com::sun::star::lang::XComponent</code></li>
50 * <li> <code>com::sun::star::awt::XWindow</code></li>
51 * <li> <code>com::sun::star::awt::XDialog</code></li>
52 * <li> <code>com::sun::star::awt::XControl</code></li>
53 * <li> <code>com::sun::star::awt::XTopWindow</code></li>
54 * <li> <code>com::sun::star::awt::XControlContainer</code></li>
55 * <li> <code>com::sun::star::awt::XView</code></li>
56 * </ul>
57 * This object test <b> is NOT </b> designed to be run in several
58 * threads concurrently.
59 * @see com.sun.star.lang.XComponent
60 * @see com.sun.star.awt.XWindow
61 * @see com.sun.star.awt.XDialog
62 * @see com.sun.star.awt.XControl
63 * @see com.sun.star.awt.XTopWindow
64 * @see com.sun.star.awt.XControlContainer
65 * @see com.sun.star.awt.XView
66 * @see ifc.lang._XComponent
67 * @see ifc.awt._XWindow
68 * @see ifc.awt._XDialog
69 * @see ifc.awt._XControl
70 * @see ifc.awt._XTopWindow
71 * @see ifc.awt._XControlContainer
72 * @see ifc.awt._XView
74 public class UnoControlDialog extends TestCase {
75 private static XWindow xWinDlg = null;
76 private static XTextDocument xTextDoc;
78 /**
79 * Creating a TestEnvironment for the interfaces to be tested.
80 * Creates a Dialog Control and Model instance defines Model
81 * for Control, adds to Dialog a button, sets its size and
82 * sets the dialog visible. <p>
84 @Override
85 public TestEnvironment createTestEnvironment(TestParameters Param,
86 PrintWriter log) {
87 XInterface oObj = null;
88 XMultiServiceFactory xMSF = Param.getMSF();
89 XControlModel dlgModel = null;
91 XWindowPeer the_win = null;
92 XToolkit the_kit = null;
93 XDevice aDevice = null;
94 XGraphics aGraphic = null;
96 XControl butControl = null;
97 XControl butControl1 = null;
98 XControl butControl2 = null;
99 XTabController tabControl1 = null;
100 XTabController tabControl2 = null;
102 XControlContainer ctrlCont = null;
104 if (xWinDlg != null) {
105 xWinDlg.dispose();
108 try {
109 dlgModel = UnoRuntime.queryInterface(
110 XControlModel.class,
111 xMSF.createInstance(
112 "com.sun.star.awt.UnoControlDialogModel"));
114 XControl dlgControl = UnoRuntime.queryInterface(
115 XControl.class,
116 xMSF.createInstance(
117 "com.sun.star.awt.UnoControlDialog"));
119 dlgControl.setModel(dlgModel);
121 XControlModel butModel = UnoRuntime.queryInterface(
122 XControlModel.class,
123 xMSF.createInstance(
124 "com.sun.star.awt.UnoControlButtonModel"));
126 butControl = UnoRuntime.queryInterface(XControl.class,
127 xMSF.createInstance(
128 "com.sun.star.awt.UnoControlButton"));
130 butControl.setModel(butModel);
133 // creating additional controls for XUnoControlContainer
134 tabControl1 = UnoRuntime.queryInterface(
135 XTabController.class,
136 xMSF.createInstance(
137 "com.sun.star.awt.TabController"));
139 tabControl2 = UnoRuntime.queryInterface(
140 XTabController.class,
141 xMSF.createInstance(
142 "com.sun.star.awt.TabController"));
145 // creating additional controls for XControlContainer
146 butModel = UnoRuntime.queryInterface(
147 XControlModel.class,
148 xMSF.createInstance(
149 "com.sun.star.awt.UnoControlButtonModel"));
151 butControl1 = UnoRuntime.queryInterface(XControl.class,
152 xMSF.createInstance(
153 "com.sun.star.awt.UnoControlButton"));
155 butControl1.setModel(butModel);
157 butModel = UnoRuntime.queryInterface(
158 XControlModel.class,
159 xMSF.createInstance(
160 "com.sun.star.awt.UnoControlButtonModel"));
162 butControl2 = UnoRuntime.queryInterface(XControl.class,
163 xMSF.createInstance(
164 "com.sun.star.awt.UnoControlButton"));
166 butControl2.setModel(butModel);
168 ctrlCont = UnoRuntime.queryInterface(
169 XControlContainer.class, dlgControl);
171 xWinDlg = UnoRuntime.queryInterface(XWindow.class,
172 dlgControl);
174 xWinDlg.setVisible(true);
176 xWinDlg.setPosSize(10, 10, 220, 110, PosSize.SIZE);
178 the_win = dlgControl.getPeer();
179 the_kit = the_win.getToolkit();
180 aDevice = the_kit.createScreenCompatibleDevice(220, 220);
181 aGraphic = aDevice.createGraphics();
183 oObj = dlgControl;
184 } catch (com.sun.star.uno.Exception e) {
185 log.println("Error creating dialog :");
186 e.printStackTrace(log);
189 log.println("creating a new environment for object");
191 TestEnvironment tEnv = new TestEnvironment(oObj);
194 //Adding ObjRelation for XView
195 tEnv.addObjRelation("GRAPHICS", aGraphic);
198 //Adding ObjRelation for XControl
199 tEnv.addObjRelation("CONTEXT", dlgModel);
200 tEnv.addObjRelation("WINPEER", the_win);
201 tEnv.addObjRelation("TOOLKIT", the_kit);
202 tEnv.addObjRelation("MODEL", dlgModel);
204 tEnv.addObjRelation("INSTANCE", butControl);
205 tEnv.addObjRelation("XContainer.Container", ctrlCont);
208 // adding relations for XUnoControlContainer
209 tEnv.addObjRelation("TABCONTROL1", tabControl1);
210 tEnv.addObjRelation("TABCONTROL2", tabControl2);
213 // adding relations for XControlContainer
214 tEnv.addObjRelation("CONTROL1", butControl1);
215 tEnv.addObjRelation("CONTROL2", butControl2);
217 XWindow forObjRel = xTextDoc.getCurrentController().getFrame()
218 .getComponentWindow();
219 tEnv.addObjRelation("XWindow.AnotherWindow", forObjRel);
221 return tEnv;
222 } // finish method getTestEnvironment
224 @Override
225 protected void cleanup(TestParameters tParam, PrintWriter log) {
226 log.println("Disposing dialog ...");
227 xWinDlg.dispose();
228 log.println(" disposing xTextDoc ");
230 util.DesktopTools.closeDoc(xTextDoc);
233 @Override
234 protected void initialize(TestParameters tParam, PrintWriter log) throws Exception {
235 SOfficeFactory SOF = SOfficeFactory.getFactory(
236 tParam.getMSF());
238 log.println("creating a textdocument");
239 xTextDoc = SOF.createTextDoc(null);