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.XControl; 36 import com.sun.star.awt.XControlModel; 37 import com.sun.star.awt.XDevice; 38 import com.sun.star.awt.XGraphics; 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.DatabaseImageControl</code> 55 * component. <p> 56 * 57 * Object implements the following interfaces : 58 * <ul> 59 * <li> <code>com::sun::star::lang::XComponent</code></li> 60 * <li> <code>com::sun::star::awt::XWindow</code></li> 61 * <li> <code>com::sun::star::form::XBoundControl</code></li> 62 * <li> <code>com::sun::star::awt::XControl</code></li> 63 * <li> <code>com::sun::star::awt::XLayoutConstrains</code></li> 64 * <li> <code>com::sun::star::awt::XView</code></li> 65 * </ul> <p> 66 * This object test <b> is NOT </b> designed to be run in several 67 * threads concurently. 68 * 69 * @see com.sun.star.lang.XComponent 70 * @see com.sun.star.awt.XWindow 71 * @see com.sun.star.form.XBoundControl 72 * @see com.sun.star.awt.XControl 73 * @see com.sun.star.awt.XLayoutConstrains 74 * @see com.sun.star.awt.XView 75 * @see ifc.lang._XComponent 76 * @see ifc.awt._XWindow 77 * @see ifc.form._XBoundControl 78 * @see ifc.awt._XControl 79 * @see ifc.awt._XLayoutConstrains 80 * @see ifc.awt._XView 81 */ 82 public class OImageControlControl extends TestCase { 83 XTextDocument xTextDoc; 84 85 /** 86 * Creates a new text document. 87 */ initialize(TestParameters Param, PrintWriter log)88 protected void initialize(TestParameters Param, PrintWriter log) { 89 SOfficeFactory SOF = SOfficeFactory.getFactory(((XMultiServiceFactory) Param.getMSF())); 90 91 try { 92 log.println("creating a textdocument"); 93 xTextDoc = SOF.createTextDoc(null); 94 } catch (com.sun.star.uno.Exception e) { 95 // Some exception occures.FAILED 96 e.printStackTrace(log); 97 throw new StatusException("Couldn't create document", e); 98 } 99 } 100 101 /** 102 * Disposes the text document created before 103 */ cleanup(TestParameters tParam, PrintWriter log)104 protected void cleanup(TestParameters tParam, PrintWriter log) { 105 log.println(" disposing xTextDoc "); 106 107 try { 108 XCloseable closer = (XCloseable) UnoRuntime.queryInterface( 109 XCloseable.class, xTextDoc); 110 closer.close(true); 111 } catch (com.sun.star.util.CloseVetoException e) { 112 log.println("couldn't close document"); 113 } catch (com.sun.star.lang.DisposedException e) { 114 log.println("couldn't close document"); 115 } 116 } 117 118 /** 119 * Creates two components and inserts them to the form of 120 * text document. One component 121 * (<code>com.sun.star.form.component.DatabaseImageControl</code>) is created 122 * for testing, another to be passed as relation. Using a controller 123 * of the text document the controller of the first component is 124 * obtained and returned in environment as a test object. <p> 125 * 126 * Object relations created : 127 * <ul> 128 * <li> <code>'GRAPHICS'</code> for 129 * {@link ifc.awt._XView} : a graphics component 130 * created using screen device of the window peer of 131 * the controller tested. </li> 132 * <li> <code>'CONTEXT'</code> for 133 * {@link ifc.awt._XControl} : the text document 134 * where the component is inserted. </li> 135 * <li> <code>'WINPEER'</code> for 136 * {@link ifc.awt._XControl} : Window peer of the 137 * controller tested. </li> 138 * <li> <code>'TOOLKIT'</code> for 139 * {@link ifc.awt._XControl} : toolkit of the component.</li> 140 * <li> <code>'MODEL'</code> for 141 * {@link ifc.awt._XControl} : the model of the controller.</li> 142 * <li> <code>'XWindow.AnotherWindow'</code> for 143 * {@link ifc.awt._XWindow} : the controller of another 144 * component. </li> 145 * </ul> 146 */ createTestEnvironment(TestParameters Param, PrintWriter log)147 protected TestEnvironment createTestEnvironment(TestParameters Param, 148 PrintWriter log) { 149 XInterface oObj = null; 150 XWindowPeer the_win = null; 151 XToolkit the_kit = null; 152 XDevice aDevice = null; 153 XGraphics aGraphic = null; 154 XControl aControl = null; 155 156 //Insert a ControlShape and get the ControlModel 157 XControlShape aShape = FormTools.createControlShapeWithDefaultControl( 158 xTextDoc, 3000, 4500, 15000, 10000, 159 "DatabaseImageControl"); 160 161 WriterTools.getDrawPage(xTextDoc).add((XShape) aShape); 162 163 XControlModel the_Model = aShape.getControl(); 164 165 XControlShape aShape2 = FormTools.createControlShape(xTextDoc, 3000, 166 4500, 5000, 10000, 167 "TextField"); 168 169 WriterTools.getDrawPage(xTextDoc).add((XShape) aShape2); 170 171 XControlModel the_Model2 = aShape2.getControl(); 172 173 //Try to query XControlAccess 174 XControlAccess the_access = (XControlAccess) UnoRuntime.queryInterface( 175 XControlAccess.class, 176 xTextDoc.getCurrentController()); 177 178 //now get the OImageControlControl 179 try { 180 oObj = the_access.getControl(the_Model); 181 the_win = the_access.getControl(the_Model).getPeer(); 182 aControl = the_access.getControl(the_Model2); 183 the_kit = the_win.getToolkit(); 184 aDevice = the_kit.createScreenCompatibleDevice(200, 200); 185 aGraphic = aDevice.createGraphics(); 186 } catch (com.sun.star.container.NoSuchElementException e) { 187 log.println("Couldn't get OImageControlControl"); 188 e.printStackTrace(log); 189 throw new StatusException("Couldn't get OImageControlControl", e); 190 } 191 192 log.println( 193 "creating a new environment for OImageControlControl object"); 194 195 TestEnvironment tEnv = new TestEnvironment(oObj); 196 197 198 //Adding ObjRelation for XView 199 tEnv.addObjRelation("GRAPHICS", aGraphic); 200 201 202 //Adding ObjRelation for XControl 203 tEnv.addObjRelation("CONTEXT", xTextDoc); 204 tEnv.addObjRelation("WINPEER", the_win); 205 tEnv.addObjRelation("TOOLKIT", the_kit); 206 tEnv.addObjRelation("MODEL", the_Model); 207 208 // Adding relation for XWindow 209 XWindow forObjRel = (XWindow) UnoRuntime.queryInterface(XWindow.class, 210 aControl); 211 212 tEnv.addObjRelation("XWindow.AnotherWindow", forObjRel); 213 214 return tEnv; 215 } // finish method getTestEnvironment 216 } // finish class OImageControlControl 217