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 .
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
;
38 import lib
.TestEnvironment
;
39 import lib
.TestParameters
;
41 import util
.SOfficeFactory
;
45 * Test for object which is represented by service
46 * <code>com.sun.star.awt.UnoControlDialog</code>. <p>
47 * Object implements the following interfaces :
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>
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
74 public class UnoControlDialog
extends TestCase
{
75 private static XWindow xWinDlg
= null;
76 private static XTextDocument xTextDoc
;
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>
85 public TestEnvironment
createTestEnvironment(TestParameters Param
,
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) {
109 dlgModel
= UnoRuntime
.queryInterface(
112 "com.sun.star.awt.UnoControlDialogModel"));
114 XControl dlgControl
= UnoRuntime
.queryInterface(
117 "com.sun.star.awt.UnoControlDialog"));
119 dlgControl
.setModel(dlgModel
);
121 XControlModel butModel
= UnoRuntime
.queryInterface(
124 "com.sun.star.awt.UnoControlButtonModel"));
126 butControl
= UnoRuntime
.queryInterface(XControl
.class,
128 "com.sun.star.awt.UnoControlButton"));
130 butControl
.setModel(butModel
);
133 // creating additional controls for XUnoControlContainer
134 tabControl1
= UnoRuntime
.queryInterface(
135 XTabController
.class,
137 "com.sun.star.awt.TabController"));
139 tabControl2
= UnoRuntime
.queryInterface(
140 XTabController
.class,
142 "com.sun.star.awt.TabController"));
145 // creating additional controls for XControlContainer
146 butModel
= UnoRuntime
.queryInterface(
149 "com.sun.star.awt.UnoControlButtonModel"));
151 butControl1
= UnoRuntime
.queryInterface(XControl
.class,
153 "com.sun.star.awt.UnoControlButton"));
155 butControl1
.setModel(butModel
);
157 butModel
= UnoRuntime
.queryInterface(
160 "com.sun.star.awt.UnoControlButtonModel"));
162 butControl2
= UnoRuntime
.queryInterface(XControl
.class,
164 "com.sun.star.awt.UnoControlButton"));
166 butControl2
.setModel(butModel
);
168 ctrlCont
= UnoRuntime
.queryInterface(
169 XControlContainer
.class, dlgControl
);
171 xWinDlg
= UnoRuntime
.queryInterface(XWindow
.class,
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();
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
);
222 } // finish method getTestEnvironment
225 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
226 log
.println("Disposing dialog ...");
228 log
.println(" disposing xTextDoc ");
230 util
.DesktopTools
.closeDoc(xTextDoc
);
234 protected void initialize(TestParameters tParam
, PrintWriter log
) throws Exception
{
235 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
238 log
.println("creating a textdocument");
239 xTextDoc
= SOF
.createTextDoc(null);