1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 package mod._forms; 29 30 import java.io.PrintWriter; 31 32 import lib.StatusException; 33 import lib.TestCase; 34 import lib.TestEnvironment; 35 import lib.TestParameters; 36 import util.FormTools; 37 import util.SOfficeFactory; 38 import util.WriterTools; 39 40 import com.sun.star.awt.XCheckBox; 41 import com.sun.star.awt.XControl; 42 import com.sun.star.awt.XControlModel; 43 import com.sun.star.awt.XDevice; 44 import com.sun.star.awt.XGraphics; 45 import com.sun.star.awt.XToolkit; 46 import com.sun.star.awt.XWindow; 47 import com.sun.star.awt.XWindowPeer; 48 import com.sun.star.drawing.XControlShape; 49 import com.sun.star.drawing.XShape; 50 import com.sun.star.lang.XMultiServiceFactory; 51 import com.sun.star.text.XTextDocument; 52 import com.sun.star.uno.UnoRuntime; 53 import com.sun.star.uno.XInterface; 54 import com.sun.star.util.XCloseable; 55 import com.sun.star.view.XControlAccess; 56 57 58 /** 59 * Test for object which is represented by default controller 60 * of the <code>com.sun.star.form.component.CheckBox</code> 61 * component. <p> 62 * 63 * Object implements the following interfaces : 64 * <ul> 65 * <li> <code>com::sun::star::awt::XView</code></li> 66 * <li> <code>com::sun::star::form::XBoundControl</code></li> 67 * <li> <code>com::sun::star::awt::XControl</code></li> 68 * <li> <code>com::sun::star::awt::XLayoutConstrains</code></li> 69 * <li> <code>com::sun::star::awt::XItemListener</code></li> 70 * <li> <code>com::sun::star::awt::XWindow</code></li> 71 * <li> <code>com::sun::star::awt::XCheckBox</code></li> 72 * <li> <code>com::sun::star::lang::XComponent</code></li> 73 * <li> <code>com::sun::star::lang::XEventListener</code></li> 74 * </ul> <p> 75 * This object test <b> is NOT </b> designed to be run in several 76 * threads concurently. 77 * 78 * @see com.sun.star.awt.XView 79 * @see com.sun.star.form.XBoundControl 80 * @see com.sun.star.awt.XControl 81 * @see com.sun.star.awt.XLayoutConstrains 82 * @see com.sun.star.awt.XItemListener 83 * @see com.sun.star.awt.XWindow 84 * @see com.sun.star.awt.XCheckBox 85 * @see com.sun.star.lang.XComponent 86 * @see com.sun.star.lang.XEventListener 87 * @see ifc.awt._XView 88 * @see ifc.form._XBoundControl 89 * @see ifc.awt._XControl 90 * @see ifc.awt._XLayoutConstrains 91 * @see ifc.awt._XItemListener 92 * @see ifc.awt._XWindow 93 * @see ifc.awt._XCheckBox 94 * @see ifc.lang._XComponent 95 * @see ifc.lang._XEventListener 96 */ 97 public class OCheckBoxControl extends TestCase { 98 99 XTextDocument xTextDoc; 100 101 /** 102 * Creates a new text document. 103 */ 104 protected void initialize ( TestParameters Param, PrintWriter log) { 105 SOfficeFactory SOF = SOfficeFactory.getFactory( ((XMultiServiceFactory)Param.getMSF()) ); 106 107 try { 108 log.println( "creating a textdocument" ); 109 xTextDoc = SOF.createTextDoc( null ); 110 } catch ( com.sun.star.uno.Exception e ) { 111 // Some exception occures.FAILED 112 e.printStackTrace( log ); 113 throw new StatusException( "Couldn't create document", e ); 114 } 115 } 116 117 /** 118 * Disposes the text document created before 119 */ 120 protected void cleanup(TestParameters tParam, PrintWriter log) { 121 log.println(" disposing xTextDoc "); 122 123 try { 124 XCloseable closer = (XCloseable) UnoRuntime.queryInterface( 125 XCloseable.class, xTextDoc); 126 closer.close(true); 127 } catch (com.sun.star.util.CloseVetoException e) { 128 log.println("couldn't close document"); 129 } catch (com.sun.star.lang.DisposedException e) { 130 log.println("couldn't close document"); 131 } 132 } 133 134 /** 135 * Creates two components and inserts them to the form of 136 * text document. One component 137 * (<code>com.sun.star.form.component.CheckBox</code>) is created 138 * for testing, another to be passed as relation. Using a controller 139 * of the text document the controller of the first component is 140 * obtained and returned in environment as a test object. <p> 141 * 142 * Object relations created : 143 * <ul> 144 * <li> <code>'GRAPHICS'</code> for 145 * {@link ifc.awt._XView} : a graphics component 146 * created using screen device of the window peer of 147 * the controller tested. </li> 148 * <li> <code>'CONTEXT'</code> for 149 * {@link ifc.awt._XControl} : the text document 150 * where the component is inserted. </li> 151 * <li> <code>'WINPEER'</code> for 152 * {@link ifc.awt._XControl} : Window peer of the 153 * controller tested. </li> 154 * <li> <code>'TOOLKIT'</code> for 155 * {@link ifc.awt._XControl} : toolkit of the component.</li> 156 * <li> <code>'MODEL'</code> for 157 * {@link ifc.awt._XControl} : the model of the controller.</li> 158 * <li> <code>'XWindow.AnotherWindow'</code> for 159 * {@link ifc.awt._XWindow} : the controller of another 160 * component. </li> 161 * <li> <code>'TestItemListener'</code> for 162 * {@link ifc.awt._XItemListener} : listener implementation is 163 * registered here and passed as relation. </li> 164 * </ul> 165 */ 166 protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) { 167 XInterface oObj = null; 168 XWindowPeer the_win = null; 169 XToolkit the_kit = null; 170 XDevice aDevice = null; 171 XGraphics aGraphic = null; 172 XControl aControl = null; 173 //Insert a ControlShape and get the ControlModel 174 XControlShape aShape = FormTools.createControlShape( 175 xTextDoc,3000,4500,15000,10000,"CheckBox"); 176 177 WriterTools.getDrawPage(xTextDoc).add((XShape) aShape); 178 179 XControlModel the_Model = aShape.getControl(); 180 181 XControlShape aShape2 = FormTools.createControlShape( 182 xTextDoc,3000,4500,5000,10000,"TextField"); 183 184 WriterTools.getDrawPage(xTextDoc).add((XShape) aShape2); 185 186 XControlModel the_Model2 = aShape2.getControl(); 187 188 //Try to query XControlAccess 189 XControlAccess the_access = (XControlAccess) UnoRuntime.queryInterface( 190 XControlAccess.class,xTextDoc.getCurrentController()); 191 192 //now get the OButtonControl 193 try { 194 oObj = the_access.getControl(the_Model); 195 aControl = the_access.getControl(the_Model2); 196 the_win = the_access.getControl(the_Model).getPeer(); 197 the_kit = the_win.getToolkit(); 198 aDevice = the_kit.createScreenCompatibleDevice(200,200); 199 aGraphic = aDevice.createGraphics(); 200 } catch (com.sun.star.container.NoSuchElementException e) { 201 log.println("Couldn't get OCheckBoxControl"); 202 e.printStackTrace(log); 203 throw new StatusException("Couldn't get OCheckBoxControl", e ); 204 } 205 206 log.println( "creating a new environment for OCheckBoxControl object" ); 207 TestEnvironment tEnv = new TestEnvironment( oObj ); 208 209 //Adding ObjRelation for XView 210 tEnv.addObjRelation("GRAPHICS",aGraphic); 211 212 //Adding ObjRelation for XControl 213 tEnv.addObjRelation("CONTEXT",xTextDoc); 214 tEnv.addObjRelation("WINPEER",the_win); 215 tEnv.addObjRelation("TOOLKIT",the_kit); 216 tEnv.addObjRelation("MODEL",the_Model); 217 218 // Adding relation for XItemListener 219 ifc.awt._XItemListener.TestItemListener listener = 220 new ifc.awt._XItemListener.TestItemListener() ; 221 XCheckBox box = (XCheckBox) UnoRuntime.queryInterface 222 (XCheckBox.class, oObj) ; 223 box.addItemListener(listener) ; 224 tEnv.addObjRelation("TestItemListener", listener) ; 225 226 // Adding relation for XWindow 227 XWindow forObjRel = (XWindow) 228 UnoRuntime.queryInterface(XWindow.class,aControl); 229 230 tEnv.addObjRelation("XWindow.AnotherWindow",forObjRel); 231 232 return tEnv; 233 } // finish method getTestEnvironment 234 235 } // finish class OButtonControl 236 237 238