1ef39d40dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3ef39d40dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4ef39d40dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5ef39d40dSAndrew Rist * distributed with this work for additional information 6ef39d40dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7ef39d40dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8ef39d40dSAndrew Rist * "License"); you may not use this file except in compliance 9ef39d40dSAndrew Rist * with the License. You may obtain a copy of the License at 10ef39d40dSAndrew Rist * 11ef39d40dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12ef39d40dSAndrew Rist * 13ef39d40dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14ef39d40dSAndrew Rist * software distributed under the License is distributed on an 15ef39d40dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16ef39d40dSAndrew Rist * KIND, either express or implied. See the License for the 17ef39d40dSAndrew Rist * specific language governing permissions and limitations 18ef39d40dSAndrew Rist * under the License. 19ef39d40dSAndrew Rist * 20ef39d40dSAndrew Rist *************************************************************/ 21ef39d40dSAndrew Rist 22ef39d40dSAndrew Rist 23cdf0e10cSrcweir package mod._forms; 24cdf0e10cSrcweir 25cdf0e10cSrcweir import java.io.PrintWriter; 26cdf0e10cSrcweir 27cdf0e10cSrcweir import lib.Status; 28cdf0e10cSrcweir import lib.StatusException; 29cdf0e10cSrcweir import lib.TestCase; 30cdf0e10cSrcweir import lib.TestEnvironment; 31cdf0e10cSrcweir import lib.TestParameters; 32cdf0e10cSrcweir import util.DrawTools; 33cdf0e10cSrcweir import util.SOfficeFactory; 34cdf0e10cSrcweir 35cdf0e10cSrcweir import com.sun.star.awt.Point; 36cdf0e10cSrcweir import com.sun.star.awt.Size; 37cdf0e10cSrcweir import com.sun.star.awt.XControlModel; 38cdf0e10cSrcweir import com.sun.star.beans.PropertyValue; 39cdf0e10cSrcweir import com.sun.star.drawing.XControlShape; 40cdf0e10cSrcweir import com.sun.star.drawing.XShape; 41cdf0e10cSrcweir import com.sun.star.lang.XComponent; 42cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 43cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 44cdf0e10cSrcweir import com.sun.star.uno.XInterface; 45cdf0e10cSrcweir import com.sun.star.util.XCloseable; 46cdf0e10cSrcweir 47cdf0e10cSrcweir 48cdf0e10cSrcweir /** 49cdf0e10cSrcweir * Test for object which is represented by service 50cdf0e10cSrcweir * <code>com.sun.star.form.component.FileControl</code>. <p> 51cdf0e10cSrcweir * Object implements the following interfaces : 52cdf0e10cSrcweir * <ul> 53cdf0e10cSrcweir * <li> <code>com::sun::star::io::XPersistObject</code></li> 54cdf0e10cSrcweir * <li> <code>com::sun::star::container::XChild</code></li> 55cdf0e10cSrcweir * <li> <code>com::sun::star::form::FormControlModel</code></li> 56cdf0e10cSrcweir * <li> <code>com::sun::star::awt::UnoControlFileControlModel</code></li> 57cdf0e10cSrcweir * <li> <code>com::sun::star::form::FormComponent</code></li> 58cdf0e10cSrcweir * <li> <code>com::sun::star::beans::XPropertyAccess</code></li> 59cdf0e10cSrcweir * <li> <code>com::sun::star::beans::XPropertyContainer</code></li> 60cdf0e10cSrcweir * <li> <code>com::sun::star::beans::XPropertySet</code></li> 61cdf0e10cSrcweir * <li> <code>com::sun::star::beans::XFastPropertySet</code></li> 62cdf0e10cSrcweir * <li> <code>com::sun::star::beans::XPropertyState</code></li> 63cdf0e10cSrcweir * <li> <code>com::sun::star::container::XNamed</code></li> 64cdf0e10cSrcweir * <li> <code>com::sun::star::beans::XMultiPropertySet</code></li> 65cdf0e10cSrcweir * <li> <code>com::sun::star::lang::XComponent</code></li> 66cdf0e10cSrcweir * <li> <code>com::sun::star::form::component::FileControl</code></li> 67cdf0e10cSrcweir * </ul> 68cdf0e10cSrcweir * This object test <b> is NOT </b> designed to be run in several 69cdf0e10cSrcweir * threads concurently. 70cdf0e10cSrcweir * @see com.sun.star.io.XPersistObject 71cdf0e10cSrcweir * @see com.sun.star.container.XChild 725496b966SPedro Giffuni * @see com.sun.star.form 73cdf0e10cSrcweir * @see com.sun.star.awt.UnoControlFileControlModel 74cdf0e10cSrcweir * @see com.sun.star.form.FormComponent 75cdf0e10cSrcweir * @see com.sun.star.beans.XPropertyAccess 76cdf0e10cSrcweir * @see com.sun.star.beans.XPropertyContainer 77cdf0e10cSrcweir * @see com.sun.star.beans.XPropertySet 78cdf0e10cSrcweir * @see com.sun.star.beans.XFastPropertySet 79cdf0e10cSrcweir * @see com.sun.star.beans.XPropertyState 80cdf0e10cSrcweir * @see com.sun.star.container.XNamed 81cdf0e10cSrcweir * @see com.sun.star.beans.XMultiPropertySet 82cdf0e10cSrcweir * @see com.sun.star.lang.XComponent 83cdf0e10cSrcweir * @see com.sun.star.form.component.FileControl 84cdf0e10cSrcweir * @see ifc.io._XPersistObject 85cdf0e10cSrcweir * @see ifc.container._XChild 86cdf0e10cSrcweir * @see ifc.form._FormControlModel 87cdf0e10cSrcweir * @see ifc.awt._UnoControlFileControlModel 88cdf0e10cSrcweir * @see ifc.form._FormComponent 89cdf0e10cSrcweir * @see ifc.beans._XPropertySet 90cdf0e10cSrcweir * @see ifc.beans._XFastPropertySet 91cdf0e10cSrcweir * @see ifc.beans._XPropertyState 92cdf0e10cSrcweir * @see ifc.container._XNamed 93cdf0e10cSrcweir * @see ifc.beans._XMultiPropertySet 94cdf0e10cSrcweir * @see ifc.lang._XComponent 95cdf0e10cSrcweir * @see ifc.form.component._FileControl 96cdf0e10cSrcweir */ 97cdf0e10cSrcweir public class OFileControlModel extends TestCase { 98cdf0e10cSrcweir XComponent xDrawDoc; 99cdf0e10cSrcweir 100cdf0e10cSrcweir /** 101cdf0e10cSrcweir * Creates Draw document where controls are placed. 102cdf0e10cSrcweir */ initialize(TestParameters tParam, PrintWriter log)103cdf0e10cSrcweir protected void initialize(TestParameters tParam, PrintWriter log) { 104cdf0e10cSrcweir SOfficeFactory SOF = SOfficeFactory.getFactory(((XMultiServiceFactory) tParam.getMSF())); 105cdf0e10cSrcweir 106cdf0e10cSrcweir try { 107cdf0e10cSrcweir log.println("creating a draw document"); 108cdf0e10cSrcweir xDrawDoc = SOF.createDrawDoc(null); 109cdf0e10cSrcweir } catch (com.sun.star.uno.Exception e) { 110cdf0e10cSrcweir log.println("Can't create a document :"); 111cdf0e10cSrcweir e.printStackTrace(log); 112cdf0e10cSrcweir throw new StatusException(Status.failed("Can't create a document")); 113cdf0e10cSrcweir } 114cdf0e10cSrcweir } 115cdf0e10cSrcweir 116cdf0e10cSrcweir /** 117cdf0e10cSrcweir * Disposes Draw document. 118cdf0e10cSrcweir */ cleanup(TestParameters tParam, PrintWriter log)119cdf0e10cSrcweir protected void cleanup(TestParameters tParam, PrintWriter log) { 120cdf0e10cSrcweir log.println(" disposing xDrawDoc "); 121cdf0e10cSrcweir 122cdf0e10cSrcweir try { 123cdf0e10cSrcweir XCloseable closer = (XCloseable) UnoRuntime.queryInterface( 124cdf0e10cSrcweir XCloseable.class, xDrawDoc); 125cdf0e10cSrcweir closer.close(true); 126cdf0e10cSrcweir } catch (com.sun.star.util.CloseVetoException e) { 127cdf0e10cSrcweir log.println("couldn't close document"); 128cdf0e10cSrcweir } catch (com.sun.star.lang.DisposedException e) { 129cdf0e10cSrcweir log.println("couldn't close document"); 130cdf0e10cSrcweir } 131cdf0e10cSrcweir } 132cdf0e10cSrcweir 133cdf0e10cSrcweir /** 134cdf0e10cSrcweir * Creating a Testenvironment for the interfaces to be tested. 135cdf0e10cSrcweir * Creates FileControl in the Form. <p> 136cdf0e10cSrcweir * Object relations created : 137cdf0e10cSrcweir * <ul> 138cdf0e10cSrcweir * <li> <code>'OBJNAME'</code> for 139cdf0e10cSrcweir * {@link ifc.io._XPersistObject} : name of service which is 140cdf0e10cSrcweir * represented by this object. </li> 141cdf0e10cSrcweir * </ul> 142cdf0e10cSrcweir */ createTestEnvironment(TestParameters Param, PrintWriter log)143cdf0e10cSrcweir protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, 144cdf0e10cSrcweir PrintWriter log) { 145cdf0e10cSrcweir XInterface oObj = null; 146cdf0e10cSrcweir 147cdf0e10cSrcweir 148cdf0e10cSrcweir // creation of testobject here 149cdf0e10cSrcweir // first we write what we are intend to do to log file 150cdf0e10cSrcweir log.println("creating a test environment"); 151cdf0e10cSrcweir 152cdf0e10cSrcweir //get FileControlModel 153cdf0e10cSrcweir String objName = "FileControl"; 154cdf0e10cSrcweir 155cdf0e10cSrcweir XControlShape aShape = null; 156cdf0e10cSrcweir 157cdf0e10cSrcweir Size size = new Size(); 158cdf0e10cSrcweir Point position = new Point(); 159cdf0e10cSrcweir XControlModel aControl = null; 160cdf0e10cSrcweir 161cdf0e10cSrcweir //get MSF 162cdf0e10cSrcweir XMultiServiceFactory oDocMSF = (XMultiServiceFactory) UnoRuntime.queryInterface( 163cdf0e10cSrcweir XMultiServiceFactory.class, 164cdf0e10cSrcweir xDrawDoc); 165cdf0e10cSrcweir 166cdf0e10cSrcweir try { 167cdf0e10cSrcweir Object oInt = oDocMSF.createInstance( 168cdf0e10cSrcweir "com.sun.star.drawing.ControlShape"); 169cdf0e10cSrcweir Object aCon = oDocMSF.createInstance( 170cdf0e10cSrcweir "com.sun.star.form.component." + objName); 171cdf0e10cSrcweir aControl = (XControlModel) UnoRuntime.queryInterface( 172cdf0e10cSrcweir XControlModel.class, aCon); 173cdf0e10cSrcweir aShape = (XControlShape) UnoRuntime.queryInterface( 174cdf0e10cSrcweir XControlShape.class, oInt); 175cdf0e10cSrcweir size.Height = 1500; 176cdf0e10cSrcweir size.Width = 3000; 177cdf0e10cSrcweir position.X = 1000; 178cdf0e10cSrcweir position.Y = 1000; 179cdf0e10cSrcweir aShape.setSize(size); 180cdf0e10cSrcweir aShape.setPosition(position); 181cdf0e10cSrcweir } catch (com.sun.star.uno.Exception e) { 182*30acf5e8Spfg // Some exception occured.FAILED 183cdf0e10cSrcweir log.println("Couldn't create a component " + e); 184cdf0e10cSrcweir throw new StatusException(Status.failed("Can't create component")); 185cdf0e10cSrcweir } 186cdf0e10cSrcweir 187cdf0e10cSrcweir aShape.setControl(aControl); 188cdf0e10cSrcweir 189cdf0e10cSrcweir DrawTools.getDrawPage(xDrawDoc, 0).add((XShape) aShape); 190cdf0e10cSrcweir oObj = aShape.getControl(); 191cdf0e10cSrcweir 192cdf0e10cSrcweir log.println("creating a new environment for drawpage object"); 193cdf0e10cSrcweir 194cdf0e10cSrcweir TestEnvironment tEnv = new TestEnvironment(oObj); 195cdf0e10cSrcweir 196cdf0e10cSrcweir tEnv.addObjRelation("OBJNAME", "stardiv.one.form.component." + 197cdf0e10cSrcweir objName); 198cdf0e10cSrcweir PropertyValue prop = new PropertyValue(); 199cdf0e10cSrcweir prop.Name = "HelpText"; 200cdf0e10cSrcweir prop.Value = "new Help Text since XPropertyAccess"; 201cdf0e10cSrcweir tEnv.addObjRelation("XPropertyAccess.propertyToChange", prop); 202cdf0e10cSrcweir tEnv.addObjRelation("XPropertyContainer.propertyNotRemovable", "HelpText"); 203cdf0e10cSrcweir 204cdf0e10cSrcweir return tEnv; 205cdf0e10cSrcweir } // finish method getTestEnvironment 206cdf0e10cSrcweir } // finish class OFileControlModel 207