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.Status; 28 import lib.StatusException; 29 import lib.TestCase; 30 import lib.TestEnvironment; 31 import lib.TestParameters; 32 import util.DrawTools; 33 import util.SOfficeFactory; 34 35 import com.sun.star.awt.Point; 36 import com.sun.star.awt.Size; 37 import com.sun.star.awt.XControlModel; 38 import com.sun.star.beans.PropertyValue; 39 import com.sun.star.drawing.XControlShape; 40 import com.sun.star.drawing.XShape; 41 import com.sun.star.lang.XComponent; 42 import com.sun.star.lang.XMultiServiceFactory; 43 import com.sun.star.uno.UnoRuntime; 44 import com.sun.star.uno.XInterface; 45 import com.sun.star.util.XCloseable; 46 47 48 /** 49 * Test for object which is represented by service 50 * <code>com.sun.star.form.component.FileControl</code>. <p> 51 * Object implements the following interfaces : 52 * <ul> 53 * <li> <code>com::sun::star::io::XPersistObject</code></li> 54 * <li> <code>com::sun::star::container::XChild</code></li> 55 * <li> <code>com::sun::star::form::FormControlModel</code></li> 56 * <li> <code>com::sun::star::awt::UnoControlFileControlModel</code></li> 57 * <li> <code>com::sun::star::form::FormComponent</code></li> 58 * <li> <code>com::sun::star::beans::XPropertyAccess</code></li> 59 * <li> <code>com::sun::star::beans::XPropertyContainer</code></li> 60 * <li> <code>com::sun::star::beans::XPropertySet</code></li> 61 * <li> <code>com::sun::star::beans::XFastPropertySet</code></li> 62 * <li> <code>com::sun::star::beans::XPropertyState</code></li> 63 * <li> <code>com::sun::star::container::XNamed</code></li> 64 * <li> <code>com::sun::star::beans::XMultiPropertySet</code></li> 65 * <li> <code>com::sun::star::lang::XComponent</code></li> 66 * <li> <code>com::sun::star::form::component::FileControl</code></li> 67 * </ul> 68 * This object test <b> is NOT </b> designed to be run in several 69 * threads concurently. 70 * @see com.sun.star.io.XPersistObject 71 * @see com.sun.star.container.XChild 72 * @see com.sun.star.form 73 * @see com.sun.star.awt.UnoControlFileControlModel 74 * @see com.sun.star.form.FormComponent 75 * @see com.sun.star.beans.XPropertyAccess 76 * @see com.sun.star.beans.XPropertyContainer 77 * @see com.sun.star.beans.XPropertySet 78 * @see com.sun.star.beans.XFastPropertySet 79 * @see com.sun.star.beans.XPropertyState 80 * @see com.sun.star.container.XNamed 81 * @see com.sun.star.beans.XMultiPropertySet 82 * @see com.sun.star.lang.XComponent 83 * @see com.sun.star.form.component.FileControl 84 * @see ifc.io._XPersistObject 85 * @see ifc.container._XChild 86 * @see ifc.form._FormControlModel 87 * @see ifc.awt._UnoControlFileControlModel 88 * @see ifc.form._FormComponent 89 * @see ifc.beans._XPropertySet 90 * @see ifc.beans._XFastPropertySet 91 * @see ifc.beans._XPropertyState 92 * @see ifc.container._XNamed 93 * @see ifc.beans._XMultiPropertySet 94 * @see ifc.lang._XComponent 95 * @see ifc.form.component._FileControl 96 */ 97 public class OFileControlModel extends TestCase { 98 XComponent xDrawDoc; 99 100 /** 101 * Creates Draw document where controls are placed. 102 */ initialize(TestParameters tParam, PrintWriter log)103 protected void initialize(TestParameters tParam, PrintWriter log) { 104 SOfficeFactory SOF = SOfficeFactory.getFactory(((XMultiServiceFactory) tParam.getMSF())); 105 106 try { 107 log.println("creating a draw document"); 108 xDrawDoc = SOF.createDrawDoc(null); 109 } catch (com.sun.star.uno.Exception e) { 110 log.println("Can't create a document :"); 111 e.printStackTrace(log); 112 throw new StatusException(Status.failed("Can't create a document")); 113 } 114 } 115 116 /** 117 * Disposes Draw document. 118 */ cleanup(TestParameters tParam, PrintWriter log)119 protected void cleanup(TestParameters tParam, PrintWriter log) { 120 log.println(" disposing xDrawDoc "); 121 122 try { 123 XCloseable closer = (XCloseable) UnoRuntime.queryInterface( 124 XCloseable.class, xDrawDoc); 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 * Creating a Testenvironment for the interfaces to be tested. 135 * Creates FileControl in the Form. <p> 136 * Object relations created : 137 * <ul> 138 * <li> <code>'OBJNAME'</code> for 139 * {@link ifc.io._XPersistObject} : name of service which is 140 * represented by this object. </li> 141 * </ul> 142 */ createTestEnvironment(TestParameters Param, PrintWriter log)143 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, 144 PrintWriter log) { 145 XInterface oObj = null; 146 147 148 // creation of testobject here 149 // first we write what we are intend to do to log file 150 log.println("creating a test environment"); 151 152 //get FileControlModel 153 String objName = "FileControl"; 154 155 XControlShape aShape = null; 156 157 Size size = new Size(); 158 Point position = new Point(); 159 XControlModel aControl = null; 160 161 //get MSF 162 XMultiServiceFactory oDocMSF = (XMultiServiceFactory) UnoRuntime.queryInterface( 163 XMultiServiceFactory.class, 164 xDrawDoc); 165 166 try { 167 Object oInt = oDocMSF.createInstance( 168 "com.sun.star.drawing.ControlShape"); 169 Object aCon = oDocMSF.createInstance( 170 "com.sun.star.form.component." + objName); 171 aControl = (XControlModel) UnoRuntime.queryInterface( 172 XControlModel.class, aCon); 173 aShape = (XControlShape) UnoRuntime.queryInterface( 174 XControlShape.class, oInt); 175 size.Height = 1500; 176 size.Width = 3000; 177 position.X = 1000; 178 position.Y = 1000; 179 aShape.setSize(size); 180 aShape.setPosition(position); 181 } catch (com.sun.star.uno.Exception e) { 182 // Some exception occured.FAILED 183 log.println("Couldn't create a component " + e); 184 throw new StatusException(Status.failed("Can't create component")); 185 } 186 187 aShape.setControl(aControl); 188 189 DrawTools.getDrawPage(xDrawDoc, 0).add((XShape) aShape); 190 oObj = aShape.getControl(); 191 192 log.println("creating a new environment for drawpage object"); 193 194 TestEnvironment tEnv = new TestEnvironment(oObj); 195 196 tEnv.addObjRelation("OBJNAME", "stardiv.one.form.component." + 197 objName); 198 PropertyValue prop = new PropertyValue(); 199 prop.Name = "HelpText"; 200 prop.Value = "new Help Text since XPropertyAccess"; 201 tEnv.addObjRelation("XPropertyAccess.propertyToChange", prop); 202 tEnv.addObjRelation("XPropertyContainer.propertyNotRemovable", "HelpText"); 203 204 return tEnv; 205 } // finish method getTestEnvironment 206 } // finish class OFileControlModel 207