1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 package mod._forms; 24 25 import java.io.PrintWriter; 26 27 import lib.StatusException; 28 import lib.TestCase; 29 import lib.TestEnvironment; 30 import lib.TestParameters; 31 import util.FormTools; 32 import util.SOfficeFactory; 33 import util.WriterTools; 34 35 import com.sun.star.awt.XControlModel; 36 import com.sun.star.awt.XDevice; 37 import com.sun.star.awt.XGraphics; 38 import com.sun.star.awt.XTextComponent; 39 import com.sun.star.awt.XToolkit; 40 import com.sun.star.awt.XWindow; 41 import com.sun.star.awt.XWindowPeer; 42 import com.sun.star.drawing.XControlShape; 43 import com.sun.star.drawing.XShape; 44 import com.sun.star.lang.XMultiServiceFactory; 45 import com.sun.star.text.XTextDocument; 46 import com.sun.star.uno.UnoRuntime; 47 import com.sun.star.uno.XInterface; 48 import com.sun.star.util.XCloseable; 49 import com.sun.star.view.XControlAccess; 50 51 52 /** 53 * Test for object which is represented by default controller 54 * of the <code>com.sun.star.form.component.DateField</code> 55 * component. <p> 56 * 57 * Object implements the following interfaces : 58 * <ul> 59 * <li> <code>com::sun::star::awt::XView</code></li> 60 * <li> <code>com::sun::star::form::XBoundControl</code></li> 61 * <li> <code>com::sun::star::awt::XControl</code></li> 62 * <li> <code>com::sun::star::awt::XTextComponent</code></li> 63 * <li> <code>com::sun::star::awt::XLayoutConstrains</code></li> 64 * <li> <code>com::sun::star::awt::XDateField</code></li> 65 * <li> <code>com::sun::star::awt::XTextListener</code></li> 66 * <li> <code>com::sun::star::awt::XWindow</code></li> 67 * <li> <code>com::sun::star::lang::XComponent</code></li> 68 * <li> <code>com::sun::star::awt::XTextLayoutConstrains</code></li> 69 * <li> <code>com::sun::star::lang::XEventListener</code></li> 70 * </ul> <p> 71 * This object test <b> is NOT </b> designed to be run in several 72 * threads concurently. 73 * 74 * @see com.sun.star.awt.XView 75 * @see com.sun.star.form.XBoundControl 76 * @see com.sun.star.awt.XControl 77 * @see com.sun.star.awt.XTextComponent 78 * @see com.sun.star.awt.XLayoutConstrains 79 * @see com.sun.star.awt.XDateField 80 * @see com.sun.star.awt.XTextListener 81 * @see com.sun.star.awt.XWindow 82 * @see com.sun.star.lang.XComponent 83 * @see com.sun.star.awt.XTextLayoutConstrains 84 * @see com.sun.star.lang.XEventListener 85 * @see ifc.awt._XView 86 * @see ifc.form._XBoundControl 87 * @see ifc.awt._XControl 88 * @see ifc.awt._XTextComponent 89 * @see ifc.awt._XLayoutConstrains 90 * @see ifc.awt._XDateField 91 * @see ifc.awt._XTextListener 92 * @see ifc.awt._XWindow 93 * @see ifc.lang._XComponent 94 * @see ifc.awt._XTextLayoutConstrains 95 * @see ifc.lang._XEventListener 96 */ 97 public class ODateControl extends TestCase { 98 XTextDocument xTextDoc; 99 100 /** 101 * Creates a new text document. 102 */ 103 protected void initialize(TestParameters Param, PrintWriter log) { 104 SOfficeFactory SOF = SOfficeFactory.getFactory(((XMultiServiceFactory) Param.getMSF())); 105 106 try { 107 log.println("creating a textdocument"); 108 xTextDoc = SOF.createTextDoc(null); 109 } catch (com.sun.star.uno.Exception e) { 110 // Some exception occures.FAILED 111 e.printStackTrace(log); 112 throw new StatusException("Couldn't create document", e); 113 } 114 } 115 116 /** 117 * Disposes the text document created before 118 */ 119 protected void cleanup(TestParameters tParam, PrintWriter log) { 120 log.println(" disposing xTextDoc "); 121 122 try { 123 XCloseable closer = (XCloseable) UnoRuntime.queryInterface( 124 XCloseable.class, xTextDoc); 125 closer.close(true); 126 } catch (com.sun.star.util.CloseVetoException e) { 127 log.println("couldn't close document"); 128 } catch (com.sun.star.lang.DisposedException e) { 129 log.println("couldn't close document"); 130 } 131 } 132 133 /** 134 * Creates two components and inserts them to the form of 135 * text document. One component 136 * (<code>com.sun.star.form.component.DateField</code>) is created 137 * for testing, another to be passed as relation. Using a controller 138 * of the text document the controller of the first component is 139 * obtained and returned in environment as a test object. <p> 140 * 141 * Object relations created : 142 * <ul> 143 * <li> <code>'GRAPHICS'</code> for 144 * {@link ifc.awt._XView} : a graphics component 145 * created using screen device of the window peer of 146 * the controller tested. </li> 147 * <li> <code>'CONTEXT'</code> for 148 * {@link ifc.awt._XControl} : the text document 149 * where the component is inserted. </li> 150 * <li> <code>'WINPEER'</code> for 151 * {@link ifc.awt._XControl} : Window peer of the 152 * controller tested. </li> 153 * <li> <code>'TOOLKIT'</code> for 154 * {@link ifc.awt._XControl} : toolkit of the component.</li> 155 * <li> <code>'MODEL'</code> for 156 * {@link ifc.awt._XControl} : the model of the controller.</li> 157 * <li> <code>'XWindow.AnotherWindow'</code> for 158 * {@link ifc.awt._XWindow} : the controller of another 159 * component. </li> 160 * </ul> 161 */ 162 protected TestEnvironment createTestEnvironment(TestParameters Param, 163 PrintWriter log) { 164 XInterface oObj = null; 165 Object anotherCtrl = null; 166 XWindowPeer the_win = null; 167 XToolkit the_kit = null; 168 XDevice aDevice = null; 169 XGraphics aGraphic = null; 170 171 //Insert a ControlShape and get the ControlModel 172 XControlShape aShape = FormTools.createControlShape(xTextDoc, 3000, 173 4500, 15000, 10000, 174 "DateField"); 175 176 WriterTools.getDrawPage(xTextDoc).add((XShape) aShape); 177 178 XControlModel the_Model = aShape.getControl(); 179 180 XControlShape aShape2 = FormTools.createControlShape(xTextDoc, 3000, 181 4500, 5000, 10000, 182 "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, 191 xTextDoc.getCurrentController()); 192 193 //now get the ODateControl 194 try { 195 oObj = the_access.getControl(the_Model); 196 anotherCtrl = the_access.getControl(the_Model2); 197 the_win = the_access.getControl(the_Model).getPeer(); 198 the_kit = the_win.getToolkit(); 199 aDevice = the_kit.createScreenCompatibleDevice(200, 200); 200 aGraphic = aDevice.createGraphics(); 201 } catch (com.sun.star.container.NoSuchElementException e) { 202 log.println("Couldn't get ODateControl"); 203 e.printStackTrace(log); 204 throw new StatusException("Couldn't get ODateControl", e); 205 } 206 207 log.println("creating a new environment for ODateControl object"); 208 209 TestEnvironment tEnv = new TestEnvironment(oObj); 210 211 212 //Adding ObjRelation for XView 213 tEnv.addObjRelation("GRAPHICS", aGraphic); 214 215 216 //Adding ObjRelation for XControl 217 tEnv.addObjRelation("CONTEXT", xTextDoc); 218 tEnv.addObjRelation("WINPEER", the_win); 219 tEnv.addObjRelation("TOOLKIT", the_kit); 220 tEnv.addObjRelation("MODEL", the_Model); 221 222 // Adding relation for XWindow 223 XWindow forObjRel = (XWindow) UnoRuntime.queryInterface(XWindow.class, 224 anotherCtrl); 225 226 tEnv.addObjRelation("XWindow.AnotherWindow", forObjRel); 227 tEnv.addObjRelation("XWindow.ControlShape", aShape); 228 229 // Adding relation for XTextListener 230 ifc.awt._XTextListener.TestTextListener listener = 231 new ifc.awt._XTextListener.TestTextListener(); 232 XTextComponent textComp = (XTextComponent) UnoRuntime.queryInterface( 233 XTextComponent.class, oObj); 234 textComp.addTextListener(listener); 235 tEnv.addObjRelation("TestTextListener", listener); 236 237 return tEnv; 238 } // finish method getTestEnvironment 239 } // finish class ODateControl 240