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 package mod._forms; 28 29 import java.io.PrintWriter; 30 31 import lib.StatusException; 32 import lib.TestCase; 33 import lib.TestEnvironment; 34 import lib.TestParameters; 35 import util.FormTools; 36 import util.SOfficeFactory; 37 import util.WriterTools; 38 39 import com.sun.star.awt.XControl; 40 import com.sun.star.awt.XControlModel; 41 import com.sun.star.awt.XDevice; 42 import com.sun.star.awt.XGraphics; 43 import com.sun.star.awt.XTextComponent; 44 import com.sun.star.awt.XToolkit; 45 import com.sun.star.awt.XWindow; 46 import com.sun.star.awt.XWindowPeer; 47 import com.sun.star.drawing.XControlShape; 48 import com.sun.star.drawing.XShape; 49 import com.sun.star.lang.XMultiServiceFactory; 50 import com.sun.star.text.XTextDocument; 51 import com.sun.star.uno.UnoRuntime; 52 import com.sun.star.uno.XInterface; 53 import com.sun.star.util.XCloseable; 54 import com.sun.star.view.XControlAccess; 55 56 57 /** 58 * Test for object which is represented by default controller 59 * of the <code>com.sun.star.form.component.CurrencyField</code> 60 * component. <p> 61 * 62 * Object implements the following interfaces : 63 * <ul> 64 * <li> <code>com::sun::star::awt::XView</code></li> 65 * <li> <code>com::sun::star::form::XBoundControl</code></li> 66 * <li> <code>com::sun::star::awt::XControl</code></li> 67 * <li> <code>com::sun::star::awt::XTextComponent</code></li> 68 * <li> <code>com::sun::star::awt::XLayoutConstrains</code></li> 69 * <li> <code>com::sun::star::awt::XTextListener</code></li> 70 * <li> <code>com::sun::star::awt::XWindow</code></li> 71 * <li> <code>com::sun::star::awt::XCurrencyField</code></li> 72 * <li> <code>com::sun::star::lang::XComponent</code></li> 73 * <li> <code>com::sun::star::awt::XTextLayoutConstrains</code></li> 74 * <li> <code>com::sun::star::lang::XEventListener</code></li> 75 * </ul> <p> 76 * This object test <b> is NOT </b> designed to be run in several 77 * threads concurently. 78 * 79 * @see com.sun.star.awt.XView 80 * @see com.sun.star.form.XBoundControl 81 * @see com.sun.star.awt.XControl 82 * @see com.sun.star.awt.XTextComponent 83 * @see com.sun.star.awt.XLayoutConstrains 84 * @see com.sun.star.awt.XTextListener 85 * @see com.sun.star.awt.XWindow 86 * @see com.sun.star.awt.XCurrencyField 87 * @see com.sun.star.lang.XComponent 88 * @see com.sun.star.awt.XTextLayoutConstrains 89 * @see com.sun.star.lang.XEventListener 90 * @see ifc.awt._XView 91 * @see ifc.form._XBoundControl 92 * @see ifc.awt._XControl 93 * @see ifc.awt._XTextComponent 94 * @see ifc.awt._XLayoutConstrains 95 * @see ifc.awt._XTextListener 96 * @see ifc.awt._XWindow 97 * @see ifc.awt._XCurrencyField 98 * @see ifc.lang._XComponent 99 * @see ifc.awt._XTextLayoutConstrains 100 * @see ifc.lang._XEventListener 101 */ 102 public class OCurrencyControl extends TestCase { 103 XTextDocument xTextDoc; 104 105 /** 106 * Creates a new text document. 107 */ 108 protected void initialize(TestParameters Param, PrintWriter log) { 109 SOfficeFactory SOF = SOfficeFactory.getFactory((XMultiServiceFactory) Param.getMSF()); 110 111 try { 112 log.println("creating a textdocument"); 113 xTextDoc = SOF.createTextDoc(null); 114 } catch (com.sun.star.uno.Exception e) { 115 // Some exception occures.FAILED 116 e.printStackTrace(log); 117 throw new StatusException("Couldn't create document", e); 118 } 119 } 120 121 /** 122 * Disposes the text document created before 123 */ 124 protected void cleanup(TestParameters tParam, PrintWriter log) { 125 log.println(" disposing xTextDoc "); 126 127 try { 128 XCloseable closer = (XCloseable) UnoRuntime.queryInterface( 129 XCloseable.class, xTextDoc); 130 closer.close(true); 131 } catch (com.sun.star.util.CloseVetoException e) { 132 log.println("couldn't close document"); 133 } catch (com.sun.star.lang.DisposedException e) { 134 log.println("couldn't close document"); 135 } 136 } 137 138 /** 139 * Creates two components and inserts them to the form of 140 * text document. One component 141 * (<code>com.sun.star.form.component.CurrencyField</code>) is created 142 * for testing, another to be passed as relation. Using a controller 143 * of the text document the controller of the first component is 144 * obtained and returned in environment as a test object. <p> 145 * 146 * Object relations created : 147 * <ul> 148 * <li> <code>'GRAPHICS'</code> for 149 * {@link ifc.awt._XView} : a graphics component 150 * created using screen device of the window peer of 151 * the controller tested. </li> 152 * <li> <code>'CONTEXT'</code> for 153 * {@link ifc.awt._XControl} : the text document 154 * where the component is inserted. </li> 155 * <li> <code>'WINPEER'</code> for 156 * {@link ifc.awt._XControl} : Window peer of the 157 * controller tested. </li> 158 * <li> <code>'TOOLKIT'</code> for 159 * {@link ifc.awt._XControl} : toolkit of the component.</li> 160 * <li> <code>'MODEL'</code> for 161 * {@link ifc.awt._XControl} : the model of the controller.</li> 162 * <li> <code>'XWindow.AnotherWindow'</code> for 163 * {@link ifc.awt._XWindow} : the controller of another 164 * component. </li> 165 * <li> <code>'XTextComponent.onlyNumbers'</code> for 166 * {@link ifc.awt._XTextComponent} : as the currency field 167 * can have only numeric values the relation must be specified. </li> 168 * </ul> 169 */ 170 protected TestEnvironment createTestEnvironment(TestParameters Param, 171 PrintWriter log) { 172 XInterface oObj = null; 173 XWindowPeer the_win = null; 174 XToolkit the_kit = null; 175 XDevice aDevice = null; 176 XGraphics aGraphic = null; 177 XControl aControl = null; 178 179 //Insert a ControlShape and get the ControlModel 180 XControlShape aShape = FormTools.createControlShape(xTextDoc, 3000, 181 4500, 15000, 10000, 182 "CurrencyField"); 183 184 WriterTools.getDrawPage(xTextDoc).add((XShape) aShape); 185 186 XControlModel the_Model = aShape.getControl(); 187 188 XControlShape aShape2 = FormTools.createControlShape(xTextDoc, 3000, 189 4500, 5000, 10000, 190 "TextField"); 191 192 WriterTools.getDrawPage(xTextDoc).add((XShape) aShape2); 193 194 XControlModel the_Model2 = aShape2.getControl(); 195 196 //Try to query XControlAccess 197 XControlAccess the_access = (XControlAccess) UnoRuntime.queryInterface( 198 XControlAccess.class, 199 xTextDoc.getCurrentController()); 200 201 //now get the OCurrencyControl 202 try { 203 oObj = the_access.getControl(the_Model); 204 aControl = the_access.getControl(the_Model2); 205 the_win = the_access.getControl(the_Model).getPeer(); 206 the_kit = the_win.getToolkit(); 207 aDevice = the_kit.createScreenCompatibleDevice(200, 200); 208 aGraphic = aDevice.createGraphics(); 209 } catch (com.sun.star.container.NoSuchElementException e) { 210 log.println("Couldn't get OCurrencyControl"); 211 e.printStackTrace(log); 212 throw new StatusException("Couldn't get OCurrencyControl", e); 213 } 214 215 log.println("creating a new environment for OCurrencyControl object"); 216 217 TestEnvironment tEnv = new TestEnvironment(oObj); 218 219 220 //Adding ObjRelation for XView 221 tEnv.addObjRelation("GRAPHICS", aGraphic); 222 223 224 //Adding ObjRelation for XControl 225 tEnv.addObjRelation("CONTEXT", xTextDoc); 226 tEnv.addObjRelation("WINPEER", the_win); 227 tEnv.addObjRelation("TOOLKIT", the_kit); 228 tEnv.addObjRelation("MODEL", the_Model); 229 230 231 // Adding relation for XTextComponent 232 tEnv.addObjRelation("XTextComponent.onlyNumbers", new Object()); 233 234 // Adding relation for XWindow 235 XWindow forObjRel = (XWindow) UnoRuntime.queryInterface(XWindow.class, 236 aControl); 237 238 tEnv.addObjRelation("XWindow.AnotherWindow", forObjRel); 239 tEnv.addObjRelation("XWindow.ControlShape", aShape); 240 241 // Adding relation for XTextListener 242 ifc.awt._XTextListener.TestTextListener listener = 243 new ifc.awt._XTextListener.TestTextListener(); 244 XTextComponent textComp = (XTextComponent) UnoRuntime.queryInterface( 245 XTextComponent.class, oObj); 246 textComp.addTextListener(listener); 247 tEnv.addObjRelation("TestTextListener", listener); 248 249 return tEnv; 250 } // finish method getTestEnvironment 251 } // finish class OCurrencyControl 252