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