1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir package mod._toolkit;
28*cdf0e10cSrcweir 
29*cdf0e10cSrcweir import com.sun.star.awt.PosSize;
30*cdf0e10cSrcweir import com.sun.star.awt.XControl;
31*cdf0e10cSrcweir import com.sun.star.awt.XControlContainer;
32*cdf0e10cSrcweir import com.sun.star.awt.XControlModel;
33*cdf0e10cSrcweir import com.sun.star.awt.XDevice;
34*cdf0e10cSrcweir import com.sun.star.awt.XGraphics;
35*cdf0e10cSrcweir import com.sun.star.awt.XTabController;
36*cdf0e10cSrcweir import com.sun.star.awt.XToolkit;
37*cdf0e10cSrcweir import com.sun.star.awt.XWindow;
38*cdf0e10cSrcweir import com.sun.star.awt.XWindowPeer;
39*cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
40*cdf0e10cSrcweir import com.sun.star.text.XTextDocument;
41*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
42*cdf0e10cSrcweir import com.sun.star.uno.XInterface;
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir import java.io.PrintWriter;
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir import lib.StatusException;
47*cdf0e10cSrcweir import lib.TestCase;
48*cdf0e10cSrcweir import lib.TestEnvironment;
49*cdf0e10cSrcweir import lib.TestParameters;
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir import util.SOfficeFactory;
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir /**
55*cdf0e10cSrcweir * Test for object which is represented by service
56*cdf0e10cSrcweir * <code>com.sun.star.awt.UnoControlDialog</code>. <p>
57*cdf0e10cSrcweir * Object implements the following interfaces :
58*cdf0e10cSrcweir * <ul>
59*cdf0e10cSrcweir *  <li> <code>com::sun::star::lang::XComponent</code></li>
60*cdf0e10cSrcweir *  <li> <code>com::sun::star::awt::XWindow</code></li>
61*cdf0e10cSrcweir *  <li> <code>com::sun::star::awt::XDialog</code></li>
62*cdf0e10cSrcweir *  <li> <code>com::sun::star::awt::XControl</code></li>
63*cdf0e10cSrcweir *  <li> <code>com::sun::star::awt::XTopWindow</code></li>
64*cdf0e10cSrcweir *  <li> <code>com::sun::star::awt::XControlContainer</code></li>
65*cdf0e10cSrcweir *  <li> <code>com::sun::star::awt::XView</code></li>
66*cdf0e10cSrcweir * </ul>
67*cdf0e10cSrcweir * This object test <b> is NOT </b> designed to be run in several
68*cdf0e10cSrcweir * threads concurently.
69*cdf0e10cSrcweir * @see com.sun.star.lang.XComponent
70*cdf0e10cSrcweir * @see com.sun.star.awt.XWindow
71*cdf0e10cSrcweir * @see com.sun.star.awt.XDialog
72*cdf0e10cSrcweir * @see com.sun.star.awt.XControl
73*cdf0e10cSrcweir * @see com.sun.star.awt.XTopWindow
74*cdf0e10cSrcweir * @see com.sun.star.awt.XControlContainer
75*cdf0e10cSrcweir * @see com.sun.star.awt.XView
76*cdf0e10cSrcweir * @see ifc.lang._XComponent
77*cdf0e10cSrcweir * @see ifc.awt._XWindow
78*cdf0e10cSrcweir * @see ifc.awt._XDialog
79*cdf0e10cSrcweir * @see ifc.awt._XControl
80*cdf0e10cSrcweir * @see ifc.awt._XTopWindow
81*cdf0e10cSrcweir * @see ifc.awt._XControlContainer
82*cdf0e10cSrcweir * @see ifc.awt._XView
83*cdf0e10cSrcweir */
84*cdf0e10cSrcweir public class UnoControlDialog extends TestCase {
85*cdf0e10cSrcweir     private static XWindow xWinDlg = null;
86*cdf0e10cSrcweir     private static XTextDocument xTextDoc;
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir     /**
89*cdf0e10cSrcweir     * Creating a Testenvironment for the interfaces to be tested.
90*cdf0e10cSrcweir     * Creates a Dialog Control and Model instance defines Model
91*cdf0e10cSrcweir     * for Control, adds to Dialog a button, sets its size and
92*cdf0e10cSrcweir     * sets the dialog visible. <p>
93*cdf0e10cSrcweir     */
94*cdf0e10cSrcweir     public synchronized TestEnvironment createTestEnvironment(TestParameters Param,
95*cdf0e10cSrcweir                                                               PrintWriter log) {
96*cdf0e10cSrcweir         XInterface oObj = null;
97*cdf0e10cSrcweir         XMultiServiceFactory xMSF = (XMultiServiceFactory) Param.getMSF();
98*cdf0e10cSrcweir         XControlModel dlgModel = null;
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir         XWindowPeer the_win = null;
101*cdf0e10cSrcweir         XToolkit the_kit = null;
102*cdf0e10cSrcweir         XDevice aDevice = null;
103*cdf0e10cSrcweir         XGraphics aGraphic = null;
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir         XControl butControl = null;
106*cdf0e10cSrcweir         XControl butControl1 = null;
107*cdf0e10cSrcweir         XControl butControl2 = null;
108*cdf0e10cSrcweir         XTabController tabControl1 = null;
109*cdf0e10cSrcweir         XTabController tabControl2 = null;
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir         XControlContainer ctrlCont = null;
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir         if (xWinDlg != null) {
114*cdf0e10cSrcweir             xWinDlg.dispose();
115*cdf0e10cSrcweir         }
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir         try {
118*cdf0e10cSrcweir             dlgModel = (XControlModel) UnoRuntime.queryInterface(
119*cdf0e10cSrcweir                                XControlModel.class,
120*cdf0e10cSrcweir                                xMSF.createInstance(
121*cdf0e10cSrcweir                                        "com.sun.star.awt.UnoControlDialogModel"));
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir             XControl dlgControl = (XControl) UnoRuntime.queryInterface(
124*cdf0e10cSrcweir                                           XControl.class,
125*cdf0e10cSrcweir                                           xMSF.createInstance(
126*cdf0e10cSrcweir                                                   "com.sun.star.awt.UnoControlDialog"));
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir             dlgControl.setModel(dlgModel);
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir             XControlModel butModel = (XControlModel) UnoRuntime.queryInterface(
131*cdf0e10cSrcweir                                              XControlModel.class,
132*cdf0e10cSrcweir                                              xMSF.createInstance(
133*cdf0e10cSrcweir                                                      "com.sun.star.awt.UnoControlButtonModel"));
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir             butControl = (XControl) UnoRuntime.queryInterface(XControl.class,
136*cdf0e10cSrcweir                                                               xMSF.createInstance(
137*cdf0e10cSrcweir                                                                       "com.sun.star.awt.UnoControlButton"));
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir             butControl.setModel(butModel);
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir             // creating additional controls for XUnoControlContainer
143*cdf0e10cSrcweir             tabControl1 = (XTabController) UnoRuntime.queryInterface(
144*cdf0e10cSrcweir                                   XTabController.class,
145*cdf0e10cSrcweir                                   xMSF.createInstance(
146*cdf0e10cSrcweir                                           "com.sun.star.awt.TabController"));
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir             tabControl2 = (XTabController) UnoRuntime.queryInterface(
149*cdf0e10cSrcweir                                   XTabController.class,
150*cdf0e10cSrcweir                                   xMSF.createInstance(
151*cdf0e10cSrcweir                                           "com.sun.star.awt.TabController"));
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir             // creating additional controls for XControlContainer
155*cdf0e10cSrcweir             butModel = (XControlModel) UnoRuntime.queryInterface(
156*cdf0e10cSrcweir                                XControlModel.class,
157*cdf0e10cSrcweir                                xMSF.createInstance(
158*cdf0e10cSrcweir                                        "com.sun.star.awt.UnoControlButtonModel"));
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir             butControl1 = (XControl) UnoRuntime.queryInterface(XControl.class,
161*cdf0e10cSrcweir                                                                xMSF.createInstance(
162*cdf0e10cSrcweir                                                                        "com.sun.star.awt.UnoControlButton"));
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir             butControl1.setModel(butModel);
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir             butModel = (XControlModel) UnoRuntime.queryInterface(
167*cdf0e10cSrcweir                                XControlModel.class,
168*cdf0e10cSrcweir                                xMSF.createInstance(
169*cdf0e10cSrcweir                                        "com.sun.star.awt.UnoControlButtonModel"));
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir             butControl2 = (XControl) UnoRuntime.queryInterface(XControl.class,
172*cdf0e10cSrcweir                                                                xMSF.createInstance(
173*cdf0e10cSrcweir                                                                        "com.sun.star.awt.UnoControlButton"));
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir             butControl2.setModel(butModel);
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir             ctrlCont = (XControlContainer) UnoRuntime.queryInterface(
178*cdf0e10cSrcweir                                XControlContainer.class, dlgControl);
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir             xWinDlg = (XWindow) UnoRuntime.queryInterface(XWindow.class,
181*cdf0e10cSrcweir                                                           dlgControl);
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir             xWinDlg.setVisible(true);
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir             xWinDlg.setPosSize(10, 10, 220, 110, PosSize.SIZE);
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir             the_win = dlgControl.getPeer();
188*cdf0e10cSrcweir             the_kit = the_win.getToolkit();
189*cdf0e10cSrcweir             aDevice = the_kit.createScreenCompatibleDevice(220, 220);
190*cdf0e10cSrcweir             aGraphic = aDevice.createGraphics();
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir             oObj = dlgControl;
193*cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception e) {
194*cdf0e10cSrcweir             log.println("Error creating dialog :");
195*cdf0e10cSrcweir             e.printStackTrace(log);
196*cdf0e10cSrcweir         }
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir         log.println("creating a new environment for object");
199*cdf0e10cSrcweir 
200*cdf0e10cSrcweir         TestEnvironment tEnv = new TestEnvironment(oObj);
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir         //Adding ObjRelation for XView
204*cdf0e10cSrcweir         tEnv.addObjRelation("GRAPHICS", aGraphic);
205*cdf0e10cSrcweir 
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir         //Adding ObjRelation for XControl
208*cdf0e10cSrcweir         tEnv.addObjRelation("CONTEXT", dlgModel);
209*cdf0e10cSrcweir         tEnv.addObjRelation("WINPEER", the_win);
210*cdf0e10cSrcweir         tEnv.addObjRelation("TOOLKIT", the_kit);
211*cdf0e10cSrcweir         tEnv.addObjRelation("MODEL", dlgModel);
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir         tEnv.addObjRelation("INSTANCE", butControl);
214*cdf0e10cSrcweir         tEnv.addObjRelation("XContainer.Container", ctrlCont);
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir 
217*cdf0e10cSrcweir         // adding relations for XUnoControlContainer
218*cdf0e10cSrcweir         tEnv.addObjRelation("TABCONTROL1", tabControl1);
219*cdf0e10cSrcweir         tEnv.addObjRelation("TABCONTROL2", tabControl2);
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir 
222*cdf0e10cSrcweir         // adding relations for XControlContainer
223*cdf0e10cSrcweir         tEnv.addObjRelation("CONTROL1", butControl1);
224*cdf0e10cSrcweir         tEnv.addObjRelation("CONTROL2", butControl2);
225*cdf0e10cSrcweir 
226*cdf0e10cSrcweir         XWindow forObjRel = xTextDoc.getCurrentController().getFrame()
227*cdf0e10cSrcweir                                     .getComponentWindow();
228*cdf0e10cSrcweir         tEnv.addObjRelation("XWindow.AnotherWindow", forObjRel);
229*cdf0e10cSrcweir 
230*cdf0e10cSrcweir         return tEnv;
231*cdf0e10cSrcweir     } // finish method getTestEnvironment
232*cdf0e10cSrcweir 
233*cdf0e10cSrcweir     protected void cleanup(TestParameters tParam, PrintWriter log) {
234*cdf0e10cSrcweir         log.println("Disposing dialog ...");
235*cdf0e10cSrcweir         xWinDlg.dispose();
236*cdf0e10cSrcweir         log.println("    disposing xTextDoc ");
237*cdf0e10cSrcweir 
238*cdf0e10cSrcweir         util.DesktopTools.closeDoc(xTextDoc);
239*cdf0e10cSrcweir     }
240*cdf0e10cSrcweir 
241*cdf0e10cSrcweir     protected void initialize(TestParameters tParam, PrintWriter log) {
242*cdf0e10cSrcweir         SOfficeFactory SOF = SOfficeFactory.getFactory(
243*cdf0e10cSrcweir                                      (XMultiServiceFactory) tParam.getMSF());
244*cdf0e10cSrcweir 
245*cdf0e10cSrcweir         try {
246*cdf0e10cSrcweir             log.println("creating a textdocument");
247*cdf0e10cSrcweir             xTextDoc = SOF.createTextDoc(null);
248*cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception e) {
249*cdf0e10cSrcweir             // Some exception occures.FAILED
250*cdf0e10cSrcweir             e.printStackTrace(log);
251*cdf0e10cSrcweir             throw new StatusException("Couldn't create document", e);
252*cdf0e10cSrcweir         }
253*cdf0e10cSrcweir     }
254*cdf0e10cSrcweir }
255