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