1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 package mod._forms; 28 29 import java.io.PrintWriter; 30 import java.util.Comparator; 31 32 import lib.StatusException; 33 import lib.TestCase; 34 import lib.TestEnvironment; 35 import lib.TestParameters; 36 import util.FormTools; 37 import util.SOfficeFactory; 38 39 import com.sun.star.beans.XPropertySet; 40 import com.sun.star.container.XNameContainer; 41 import com.sun.star.container.XNamed; 42 import com.sun.star.drawing.XControlShape; 43 import com.sun.star.form.XGridColumnFactory; 44 import com.sun.star.lang.XComponent; 45 import com.sun.star.lang.XMultiServiceFactory; 46 import com.sun.star.uno.UnoRuntime; 47 import com.sun.star.uno.XInterface; 48 import com.sun.star.util.XCloseable; 49 50 51 /** 52 * Test for object which is represented by service 53 * <code>com.sun.star.form.component.GridControl</code>. <p> 54 * Object implements the following interfaces : 55 * <ul> 56 * <li> <code>com::sun::star::io::XPersistObject</code></li> 57 * <li> <code>com::sun::star::container::XNameReplace</code></li> 58 * <li> <code>com::sun::star::form::XReset</code></li> 59 * <li> <code>com::sun::star::script::XEventAttacherManager</code></li> 60 * <li> <code>com::sun::star::form::FormComponent</code></li> 61 * <li> <code>com::sun::star::beans::XFastPropertySet</code></li> 62 * <li> <code>com::sun::star::beans::XMultiPropertySet</code></li> 63 * <li> <code>com::sun::star::container::XElementAccess</code></li> 64 * <li> <code>com::sun::star::form::component::GridControl</code></li> 65 * <li> <code>com::sun::star::view::XSelectionSupplier</code></li> 66 * <li> <code>com::sun::star::container::XEnumerationAccess</code></li> 67 * <li> <code>com::sun::star::beans::XPropertyState</code></li> 68 * <li> <code>com::sun::star::form::FormControlModel</code></li> 69 * <li> <code>com::sun::star::container::XIndexReplace</code></li> 70 * <li> <code>com::sun::star::container::XNamed</code></li> 71 * <li> <code>com::sun::star::container::XIndexAccess</code></li> 72 * <li> <code>com::sun::star::container::XNameContainer</code></li> 73 * <li> <code>com::sun::star::form::XGridColumnFactory</code></li> 74 * <li> <code>com::sun::star::lang::XComponent</code></li> 75 * <li> <code>com::sun::star::container::XNameAccess</code></li> 76 * <li> <code>com::sun::star::beans::XPropertyAccess</code></li> 77 * <li> <code>com::sun::star::beans::XPropertyContainer</code></li> 78 * <li> <code>com::sun::star::beans::XPropertySet</code></li> 79 * <li> <code>com::sun::star::container::XIndexContainer</code></li> 80 * <li> <code>com::sun::star::container::XChild</code></li> 81 * <li> <code>com::sun::star::container::XContainer</code></li> 82 * </ul> <p> 83 * This object test <b> is NOT </b> designed to be run in several 84 * threads concurently. 85 * 86 * @see com.sun.star.io.XPersistObject 87 * @see com.sun.star.container.XNameReplace 88 * @see com.sun.star.form.XReset 89 * @see com.sun.star.script.XEventAttacherManager 90 * @see com.sun.star.form.FormComponent 91 * @see com.sun.star.beans.XFastPropertySet 92 * @see com.sun.star.beans.XMultiPropertySet 93 * @see com.sun.star.container.XElementAccess 94 * @see com.sun.star.form.component.GridControl 95 * @see com.sun.star.view.XSelectionSupplier 96 * @see com.sun.star.container.XEnumerationAccess 97 * @see com.sun.star.beans.XPropertyState 98 * @see com.sun.star.form.FormControlModel 99 * @see com.sun.star.container.XIndexReplace 100 * @see com.sun.star.container.XNamed 101 * @see com.sun.star.container.XIndexAccess 102 * @see com.sun.star.container.XNameContainer 103 * @see com.sun.star.form.XGridColumnFactory 104 * @see com.sun.star.lang.XComponent 105 * @see com.sun.star.container.XNameAccess 106 * @see com.sun.star.beans.XPropertyAccess 107 * @see com.sun.star.beans.XPropertyContainer 108 * @see com.sun.star.beans.XPropertySet 109 * @see com.sun.star.container.XIndexContainer 110 * @see com.sun.star.container.XChild 111 * @see com.sun.star.container.XContainer 112 * @see ifc.io._XPersistObject 113 * @see ifc.container._XNameReplace 114 * @see ifc.form._XReset 115 * @see ifc.script._XEventAttacherManager 116 * @see ifc.form._FormComponent 117 * @see ifc.beans._XFastPropertySet 118 * @see ifc.beans._XMultiPropertySet 119 * @see ifc.container._XElementAccess 120 * @see ifc.form.component._GridControl 121 * @see ifc.view._XSelectionSupplier 122 * @see ifc.container._XEnumerationAccess 123 * @see ifc.beans._XPropertyState 124 * @see ifc.form._FormControlModel 125 * @see ifc.container._XIndexReplace 126 * @see ifc.container._XNamed 127 * @see ifc.container._XIndexAccess 128 * @see ifc.container._XNameContainer 129 * @see ifc.form._XGridColumnFactory 130 * @see ifc.lang._XComponent 131 * @see ifc.container._XNameAccess 132 * @see ifc.beans._XPropertySet 133 * @see ifc.container._XIndexContainer 134 * @see ifc.container._XChild 135 * @see ifc.container._XContainer 136 */ 137 138 public class OGridControlModel extends GenericModelTest { 139 140 /** 141 * Set some member variable of the super class <CODE>GenericModelTest</CODE>: 142 * <pre> 143 * super.m_kindOfControl="CommandButton"; 144 * super.m_ObjectName = "com.sun.star.form.component.CommandButton"; 145 * super.m_LCShape_Type = "CommandButton"; 146 * </pre> 147 * Then <CODE>super.initialize()</CODE> was called. 148 * @param tParam the test parameter 149 * @param log the log writer 150 */ 151 152 protected void initialize(TestParameters tParam, PrintWriter log) { 153 154 super.initialize(tParam, log); 155 156 super.m_kindOfControl="GridControl"; 157 158 super.m_ObjectName = "stardiv.one.form.component.Grid"; 159 160 super.m_LCShape_Type = "GridControl"; 161 162 } 163 /** 164 * calls <CODE>cleanup()</CODE> from it's super class 165 * @param tParam the test parameter 166 * @param log the log writer 167 */ 168 protected void cleanup(TestParameters tParam, PrintWriter log) { 169 super.cleanup(tParam, log); 170 } 171 172 173 /** 174 * calls <CODE>createTestEnvironment()</CODE> from it's super class 175 * @param Param the test parameter 176 * @param log the log writer 177 * @return lib.TestEnvironment 178 */ 179 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, 180 PrintWriter log) { 181 TestEnvironment tEnv = super.createTestEnvironment(Param, log); 182 183 XInterface oObj = tEnv.getTestObject(); 184 185 XPropertySet aControl = null; 186 XPropertySet aControl2 = null; 187 XPropertySet aControl3 = null; 188 XPropertySet aControl4 = null; 189 XPropertySet aControl5 = null; 190 191 try { 192 XGridColumnFactory columns = (XGridColumnFactory) UnoRuntime.queryInterface( 193 XGridColumnFactory.class, oObj); 194 aControl = columns.createColumn("TextField"); 195 aControl2 = columns.createColumn("DateField"); 196 aControl3 = columns.createColumn("TextField"); 197 aControl4 = columns.createColumn("TextField"); 198 aControl5 = columns.createColumn("TextField"); 199 } catch (com.sun.star.lang.IllegalArgumentException e) { 200 // Some exception occures.FAILED 201 log.println("!!! Couldn't create instance : " + e); 202 throw new StatusException("Can't create column instances.", e); 203 } 204 205 XNameContainer aContainer = (XNameContainer) UnoRuntime.queryInterface( 206 XNameContainer.class, oObj); 207 208 try { 209 aContainer.insertByName("First", aControl); 210 aContainer.insertByName("Second", aControl2); 211 } catch (com.sun.star.lang.WrappedTargetException e) { 212 log.println("!!! Could't insert column Instance"); 213 e.printStackTrace(log); 214 throw new StatusException("Can't insert columns", e); 215 } catch (com.sun.star.lang.IllegalArgumentException e) { 216 log.println("!!! Could't insert column Instance"); 217 e.printStackTrace(log); 218 throw new StatusException("Can't insert columns", e); 219 } catch (com.sun.star.container.ElementExistException e) { 220 log.println("!!! Could't insert column Instance"); 221 e.printStackTrace(log); 222 throw new StatusException("Can't insert columns", e); 223 } 224 225 //Relations for XSelectionSupplier 226 tEnv.addObjRelation("Selections", new Object[] { aControl, aControl2 }); 227 228 // adding relation for XNameContainer 229 tEnv.addObjRelation("XNameContainer.AllowDuplicateNames", new Object()); 230 231 232 // adding relation for XContainer 233 tEnv.addObjRelation("INSTANCE", aControl3); 234 tEnv.addObjRelation("INSTANCE1", aControl4); 235 tEnv.addObjRelation("INSTANCE2", aControl5); 236 237 238 tEnv.addObjRelation("Comparer", 239 new Comparator() { 240 public int compare(Object o1, Object o2) { 241 XNamed named1 = (XNamed) UnoRuntime.queryInterface( 242 XNamed.class, o1); 243 XNamed named2 = (XNamed) UnoRuntime.queryInterface( 244 XNamed.class, o2); 245 246 if (named1.getName().equals(named2.getName())) { 247 return 0; 248 } 249 250 return -1; 251 } 252 253 public boolean equals(Object obj) { 254 return compare(this, obj) == 0; 255 } 256 }); 257 258 259 // HashSet exclude = new HashSet(); 260 // 261 // exclude.add("FormatKey"); 262 // 263 // tEnv.addObjRelation("XUpdateBroadcaster.Checker", 264 // new Checker(m_XFormLoader, m_XPS, m_XCtrl, m_ChangePropertyName, m_ChangePropertyValue)); 265 return tEnv; 266 } 267 268 } // finish class OButtonModelold 269 270 271 class OGridControlModelold extends TestCase { 272 XComponent xDrawDoc = null; 273 274 /** 275 * Creates Drawing document. 276 */ 277 protected void initialize(TestParameters tParam, PrintWriter log) { 278 SOfficeFactory SOF = SOfficeFactory.getFactory(((XMultiServiceFactory) tParam.getMSF())); 279 280 log.println("creating a draw document"); 281 282 try { 283 xDrawDoc = SOF.createDrawDoc(null); 284 } catch (com.sun.star.uno.Exception e) { 285 throw new StatusException("Can't create Draw document", e); 286 } 287 } 288 289 /** 290 * Disposes drawing document. 291 */ 292 protected void cleanup(TestParameters tParam, PrintWriter log) { 293 log.println(" disposing xDrawDoc "); 294 295 try { 296 XCloseable closer = (XCloseable) UnoRuntime.queryInterface( 297 XCloseable.class, xDrawDoc); 298 closer.close(true); 299 } catch (com.sun.star.util.CloseVetoException e) { 300 log.println("couldn't close document"); 301 } catch (com.sun.star.lang.DisposedException e) { 302 log.println("couldn't close document"); 303 } 304 } 305 306 /** 307 * <code>GridControl</code> component created and added to the draw 308 * page. Then two columns are created and added to the grid. 309 * Object relations created : 310 * <ul> 311 * <li> <code>'INSTANCE1' ... 'INSTANCEN'</code> for 312 * <code>XNameReplace, XNameContainer, XIndexReplace, 313 * XIndexContainer </code> : objects to be inserted 314 * or replaced with in interface tests. Number of relations 315 * depends on number of interface test threads. For each 316 * thread there must be an individual element. </li> 317 * <li> <code>'XNameContainer.AllowDuplicateNames'</code> : 318 * if this relation exists then container elements can have duplicate 319 * names. <code>GridControl</code> can have.</li> 320 * <li> <code>'OBJNAME'</code> for 321 * {@link ifc.io._XPersistObject} : name of service which is 322 * represented by this object. </li> 323 * <li> <code>'INSTANCE'</code> for 324 * {@link ifc.container._XContainer} : a column instance. </li> 325 * </ul> 326 */ 327 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, 328 PrintWriter log) { 329 XInterface oObj = null; 330 XInterface oInstance = null; 331 XPropertySet aControl = null; 332 XPropertySet aControl2 = null; 333 XPropertySet aControl3 = null; 334 XPropertySet aControl4 = null; 335 XPropertySet aControl5 = null; 336 XGridColumnFactory columns = null; 337 338 339 // creation of testobject here 340 // first we write what we are intend to do to log file 341 log.println("creating a test environment"); 342 343 //get GridControlModel 344 String objName = "Grid"; 345 XControlShape shape = FormTools.insertControlShape(xDrawDoc, 5000, 346 7000, 2000, 2000, 347 "GridControl"); 348 oObj = shape.getControl(); 349 350 log.println("creating a new environment for drawpage object"); 351 352 TestEnvironment tEnv = new TestEnvironment(oObj); 353 354 try { 355 columns = (XGridColumnFactory) UnoRuntime.queryInterface( 356 XGridColumnFactory.class, oObj); 357 aControl = columns.createColumn("TextField"); 358 aControl2 = columns.createColumn("DateField"); 359 aControl3 = columns.createColumn("TextField"); 360 aControl4 = columns.createColumn("TextField"); 361 aControl5 = columns.createColumn("TextField"); 362 } catch (com.sun.star.lang.IllegalArgumentException e) { 363 // Some exception occures.FAILED 364 log.println("!!! Couldn't create instance : " + e); 365 throw new StatusException("Can't create column instances.", e); 366 } 367 368 XNameContainer aContainer = (XNameContainer) UnoRuntime.queryInterface( 369 XNameContainer.class, oObj); 370 371 try { 372 aContainer.insertByName("First", aControl); 373 aContainer.insertByName("Second", aControl2); 374 } catch (com.sun.star.lang.WrappedTargetException e) { 375 log.println("!!! Could't insert column Instance"); 376 e.printStackTrace(log); 377 throw new StatusException("Can't insert columns", e); 378 } catch (com.sun.star.lang.IllegalArgumentException e) { 379 log.println("!!! Could't insert column Instance"); 380 e.printStackTrace(log); 381 throw new StatusException("Can't insert columns", e); 382 } catch (com.sun.star.container.ElementExistException e) { 383 log.println("!!! Could't insert column Instance"); 384 e.printStackTrace(log); 385 throw new StatusException("Can't insert columns", e); 386 } 387 388 //Relations for XSelectionSupplier 389 tEnv.addObjRelation("Selections", new Object[] { aControl, aControl2 }); 390 391 // COMPARER 392 393 int THRCNT = 1; 394 String count = (String)Param.get("THRCNT"); 395 if (count != null) 396 THRCNT = Integer.parseInt(count); 397 398 399 // INSTANCEn : _XNameContainer; _XNameReplace 400 log.println("adding INSTANCEn as obj relation to environment"); 401 402 try { 403 for (int n = 1; n < (3 * THRCNT + 1); n++) { 404 log.println("adding INSTANCE" + n + 405 " as obj relation to environment"); 406 oInstance = columns.createColumn("TextField"); 407 tEnv.addObjRelation("INSTANCE" + n, oInstance); 408 } 409 } catch (com.sun.star.lang.IllegalArgumentException e) { 410 e.printStackTrace(log); 411 throw new StatusException("Can't create 'INSTANCEn' relations", e); 412 } 413 414 415 // adding relation for XNameContainer 416 tEnv.addObjRelation("XNameContainer.AllowDuplicateNames", new Object()); 417 418 // OK tEnv.addObjRelation("OBJNAME", "stardiv.one.form.component." + objName); 419 420 421 // adding relation for XContainer 422 tEnv.addObjRelation("INSTANCE", aControl3); 423 tEnv.addObjRelation("INSTANCE2", aControl4); 424 425 426 //adding ObjRelation for XPersistObject 427 // OK tEnv.addObjRelation("PSEUDOPERSISTENT", new Boolean(true)); // OK 428 429 return tEnv; 430 } // finish method getTestEnvironment 431 } // finish class OGridControlModel 432