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 com.sun.star.beans.PropertyValue; 26 import java.io.PrintWriter; 27 28 import lib.StatusException; 29 import lib.TestCase; 30 import lib.TestEnvironment; 31 import lib.TestParameters; 32 import util.DrawTools; 33 import util.FormTools; 34 import util.SOfficeFactory; 35 36 import com.sun.star.container.XNameContainer; 37 import com.sun.star.drawing.XDrawPage; 38 import com.sun.star.lang.XComponent; 39 import com.sun.star.lang.XMultiServiceFactory; 40 import com.sun.star.uno.AnyConverter; 41 import com.sun.star.uno.Type; 42 import com.sun.star.uno.UnoRuntime; 43 import com.sun.star.uno.XInterface; 44 import com.sun.star.util.XCloseable; 45 46 47 /** 48 * Test for object which is represented by service 49 * <code>com.sun.star.form.component.HiddenControl</code>. <p> 50 * Object implements the following interfaces : 51 * <ul> 52 * <li> <code>com::sun::star::io::XPersistObject</code></li> 53 * <li> <code>com::sun::star::container::XChild</code></li> 54 * <li> <code>com::sun::star::form::FormControlModel</code></li> 55 * <li> <code>com::sun::star::form::component::HiddenControl</code></li> 56 * <li> <code>com::sun::star::form::FormComponent</code></li> 57 * <li> <code>com::sun::star::beans::XPropertyAccess</code></li> 58 * <li> <code>com::sun::star::beans::XPropertyContainer</code></li> 59 * <li> <code>com::sun::star::beans::XPropertySet</code></li> 60 * <li> <code>com::sun::star::beans::XFastPropertySet</code></li> 61 * <li> <code>com::sun::star::beans::XPropertyState</code></li> 62 * <li> <code>com::sun::star::container::XNamed</code></li> 63 * <li> <code>com::sun::star::beans::XMultiPropertySet</code></li> 64 * <li> <code>com::sun::star::lang::XComponent</code></li> 65 * </ul> <p> 66 * This object test <b> is NOT </b> designed to be run in several 67 * threads concurently. 68 * @see com.sun.star.io.XPersistObject 69 * @see com.sun.star.container.XChild 70 * @see com.sun.star.form 71 * @see com.sun.star.form.component.HiddenControl 72 * @see com.sun.star.form.FormComponent 73 * @see com.sun.star.beans.XPropertyAccess 74 * @see com.sun.star.beans.XPropertyContainer 75 * @see com.sun.star.beans.XPropertySet 76 * @see com.sun.star.beans.XFastPropertySet 77 * @see com.sun.star.beans.XPropertyState 78 * @see com.sun.star.container.XNamed 79 * @see com.sun.star.beans.XMultiPropertySet 80 * @see com.sun.star.lang.XComponent 81 * @see ifc.io._XPersistObject 82 * @see ifc.container._XChild 83 * @see ifc.form._FormControlModel 84 * @see ifc.form.component._HiddenControl 85 * @see ifc.form._FormComponent 86 * @see ifc.beans._XPropertySet 87 * @see ifc.beans._XFastPropertySet 88 * @see ifc.beans._XPropertyState 89 * @see ifc.container._XNamed 90 * @see ifc.beans._XMultiPropertySet 91 * @see ifc.lang._XComponent 92 */ 93 public class OHiddenModel extends TestCase { 94 XComponent xDrawDoc; 95 96 /** 97 * Creates Drawing document. 98 */ initialize(TestParameters tParam, PrintWriter log)99 protected void initialize(TestParameters tParam, PrintWriter log) { 100 SOfficeFactory SOF = SOfficeFactory.getFactory(((XMultiServiceFactory) tParam.getMSF())); 101 102 try { 103 log.println("creating a draw document"); 104 xDrawDoc = SOF.createDrawDoc(null); 105 } catch (com.sun.star.uno.Exception e) { 106 // Some exception occures.FAILED 107 e.printStackTrace(log); 108 throw new StatusException("Couldn't create document", e); 109 } 110 } 111 112 /** 113 * Disposes drawing document. 114 */ cleanup(TestParameters tParam, PrintWriter log)115 protected void cleanup(TestParameters tParam, PrintWriter log) { 116 log.println(" disposing xDrawDoc "); 117 118 try { 119 XCloseable closer = (XCloseable) UnoRuntime.queryInterface( 120 XCloseable.class, xDrawDoc); 121 closer.close(true); 122 } catch (com.sun.star.util.CloseVetoException e) { 123 log.println("couldn't close document"); 124 } catch (com.sun.star.lang.DisposedException e) { 125 log.println("couldn't close document"); 126 } 127 } 128 129 /** 130 * Creates hidden component, then adds Form into draw page, 131 * and inserts the component into Form components' collection. 132 * Object relations created : 133 * <ul> 134 * <li> <code>'OBJNAME'</code> for 135 * {@link ifc.io._XPersistObject} : name of service which is 136 * represented by this object. </li> 137 * </ul> 138 */ createTestEnvironment(TestParameters Param, PrintWriter log)139 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, 140 PrintWriter log) { 141 XInterface oObj = null; 142 143 144 // creation of testobject here 145 // first we write what we are intend to do to log file 146 log.println("creating a test environment"); 147 148 // get a soffice factory object 149 SOfficeFactory SOF = SOfficeFactory.getFactory(((XMultiServiceFactory) Param.getMSF())); 150 String objName = "HiddenControl"; 151 XInterface ctrl = SOF.createControl(xDrawDoc, objName); 152 153 try { 154 XDrawPage oDP = DrawTools.getDrawPage(xDrawDoc, 0); 155 156 XNameContainer nc = FormTools.getForms(oDP); 157 FormTools.insertForm(xDrawDoc, nc, "OHiddenModelForm"); 158 159 Object frm = nc.getByName("OHiddenModelForm"); 160 161 XNameContainer frmNC = (XNameContainer) UnoRuntime.queryInterface( 162 XNameContainer.class, frm); 163 164 frmNC.insertByName("OHiddenModel", ctrl); 165 oObj = (XInterface) AnyConverter.toObject( 166 new Type(XInterface.class), 167 frmNC.getByName("OHiddenModel")); 168 } catch (com.sun.star.lang.WrappedTargetException e) { 169 e.printStackTrace(log); 170 throw new StatusException("Can't create and add control", e); 171 } catch (com.sun.star.lang.IllegalArgumentException e) { 172 e.printStackTrace(log); 173 throw new StatusException("Can't create and add control", e); 174 } catch (com.sun.star.container.NoSuchElementException e) { 175 e.printStackTrace(log); 176 throw new StatusException("Can't create and add control", e); 177 } catch (com.sun.star.container.ElementExistException e) { 178 e.printStackTrace(log); 179 throw new StatusException("Can't create and add control", e); 180 } 181 182 log.println("creating a new environment for drawpage object"); 183 184 TestEnvironment tEnv = new TestEnvironment(oObj); 185 186 util.dbg.getSuppServices(oObj); 187 188 log.println("adding DrawDocument as obj relation to environment"); 189 tEnv.addObjRelation("OBJNAME", "stardiv.one.form.component.Hidden"); 190 191 PropertyValue prop = new PropertyValue(); 192 prop.Name = "Name"; 193 prop.Value = "new Text since XPropertyAccess"; 194 tEnv.addObjRelation("XPropertyAccess.propertyToChange", prop); 195 tEnv.addObjRelation("XPropertyContainer.propertyNotRemovable", "Name"); 196 197 return tEnv; 198 } // finish method getTestEnvironment 199 } // finish class OHiddenModel 200