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
;
37 import lib
.StatusException
;
39 import lib
.TestEnvironment
;
40 import lib
.TestParameters
;
42 import util
.SOfficeFactory
;
46 * Test for object which is represented by service
47 * <code>com.sun.star.awt.UnoControlDialog</code>. <p>
48 * Object implements the following interfaces :
50 * <li> <code>com::sun::star::lang::XComponent</code></li>
51 * <li> <code>com::sun::star::awt::XWindow</code></li>
52 * <li> <code>com::sun::star::awt::XDialog</code></li>
53 * <li> <code>com::sun::star::awt::XControl</code></li>
54 * <li> <code>com::sun::star::awt::XTopWindow</code></li>
55 * <li> <code>com::sun::star::awt::XControlContainer</code></li>
56 * <li> <code>com::sun::star::awt::XView</code></li>
58 * This object test <b> is NOT </b> designed to be run in several
59 * threads concurently.
60 * @see com.sun.star.lang.XComponent
61 * @see com.sun.star.awt.XWindow
62 * @see com.sun.star.awt.XDialog
63 * @see com.sun.star.awt.XControl
64 * @see com.sun.star.awt.XTopWindow
65 * @see com.sun.star.awt.XControlContainer
66 * @see com.sun.star.awt.XView
67 * @see ifc.lang._XComponent
68 * @see ifc.awt._XWindow
69 * @see ifc.awt._XDialog
70 * @see ifc.awt._XControl
71 * @see ifc.awt._XTopWindow
72 * @see ifc.awt._XControlContainer
75 public class UnoControlDialog
extends TestCase
{
76 private static XWindow xWinDlg
= null;
77 private static XTextDocument xTextDoc
;
80 * Creating a Testenvironment for the interfaces to be tested.
81 * Creates a Dialog Control and Model instance defines Model
82 * for Control, adds to Dialog a button, sets its size and
83 * sets the dialog visible. <p>
86 public synchronized TestEnvironment
createTestEnvironment(TestParameters Param
,
88 XInterface oObj
= null;
89 XMultiServiceFactory xMSF
= Param
.getMSF();
90 XControlModel dlgModel
= null;
92 XWindowPeer the_win
= null;
93 XToolkit the_kit
= null;
94 XDevice aDevice
= null;
95 XGraphics aGraphic
= null;
97 XControl butControl
= null;
98 XControl butControl1
= null;
99 XControl butControl2
= null;
100 XTabController tabControl1
= null;
101 XTabController tabControl2
= null;
103 XControlContainer ctrlCont
= null;
105 if (xWinDlg
!= null) {
110 dlgModel
= UnoRuntime
.queryInterface(
113 "com.sun.star.awt.UnoControlDialogModel"));
115 XControl dlgControl
= UnoRuntime
.queryInterface(
118 "com.sun.star.awt.UnoControlDialog"));
120 dlgControl
.setModel(dlgModel
);
122 XControlModel butModel
= UnoRuntime
.queryInterface(
125 "com.sun.star.awt.UnoControlButtonModel"));
127 butControl
= UnoRuntime
.queryInterface(XControl
.class,
129 "com.sun.star.awt.UnoControlButton"));
131 butControl
.setModel(butModel
);
134 // creating additional controls for XUnoControlContainer
135 tabControl1
= UnoRuntime
.queryInterface(
136 XTabController
.class,
138 "com.sun.star.awt.TabController"));
140 tabControl2
= UnoRuntime
.queryInterface(
141 XTabController
.class,
143 "com.sun.star.awt.TabController"));
146 // creating additional controls for XControlContainer
147 butModel
= UnoRuntime
.queryInterface(
150 "com.sun.star.awt.UnoControlButtonModel"));
152 butControl1
= UnoRuntime
.queryInterface(XControl
.class,
154 "com.sun.star.awt.UnoControlButton"));
156 butControl1
.setModel(butModel
);
158 butModel
= UnoRuntime
.queryInterface(
161 "com.sun.star.awt.UnoControlButtonModel"));
163 butControl2
= UnoRuntime
.queryInterface(XControl
.class,
165 "com.sun.star.awt.UnoControlButton"));
167 butControl2
.setModel(butModel
);
169 ctrlCont
= UnoRuntime
.queryInterface(
170 XControlContainer
.class, dlgControl
);
172 xWinDlg
= UnoRuntime
.queryInterface(XWindow
.class,
175 xWinDlg
.setVisible(true);
177 xWinDlg
.setPosSize(10, 10, 220, 110, PosSize
.SIZE
);
179 the_win
= dlgControl
.getPeer();
180 the_kit
= the_win
.getToolkit();
181 aDevice
= the_kit
.createScreenCompatibleDevice(220, 220);
182 aGraphic
= aDevice
.createGraphics();
185 } catch (com
.sun
.star
.uno
.Exception e
) {
186 log
.println("Error creating dialog :");
187 e
.printStackTrace(log
);
190 log
.println("creating a new environment for object");
192 TestEnvironment tEnv
= new TestEnvironment(oObj
);
195 //Adding ObjRelation for XView
196 tEnv
.addObjRelation("GRAPHICS", aGraphic
);
199 //Adding ObjRelation for XControl
200 tEnv
.addObjRelation("CONTEXT", dlgModel
);
201 tEnv
.addObjRelation("WINPEER", the_win
);
202 tEnv
.addObjRelation("TOOLKIT", the_kit
);
203 tEnv
.addObjRelation("MODEL", dlgModel
);
205 tEnv
.addObjRelation("INSTANCE", butControl
);
206 tEnv
.addObjRelation("XContainer.Container", ctrlCont
);
209 // adding relations for XUnoControlContainer
210 tEnv
.addObjRelation("TABCONTROL1", tabControl1
);
211 tEnv
.addObjRelation("TABCONTROL2", tabControl2
);
214 // adding relations for XControlContainer
215 tEnv
.addObjRelation("CONTROL1", butControl1
);
216 tEnv
.addObjRelation("CONTROL2", butControl2
);
218 XWindow forObjRel
= xTextDoc
.getCurrentController().getFrame()
219 .getComponentWindow();
220 tEnv
.addObjRelation("XWindow.AnotherWindow", forObjRel
);
223 } // finish method getTestEnvironment
226 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
227 log
.println("Disposing dialog ...");
229 log
.println(" disposing xTextDoc ");
231 util
.DesktopTools
.closeDoc(xTextDoc
);
235 protected void initialize(TestParameters tParam
, PrintWriter log
) {
236 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
240 log
.println("creating a textdocument");
241 xTextDoc
= SOF
.createTextDoc(null);
242 } catch (com
.sun
.star
.uno
.Exception e
) {
243 // Some exception occurs.FAILED
244 e
.printStackTrace(log
);
245 throw new StatusException("Couldn't create document", e
);