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.TestCase; 28 import lib.TestEnvironment; 29 import lib.TestParameters; 30 import util.DrawTools; 31 import util.FormTools; 32 33 import com.sun.star.container.XNameContainer; 34 import com.sun.star.drawing.XDrawPage; 35 import com.sun.star.lang.XComponent; 36 import com.sun.star.lang.XMultiServiceFactory; 37 import com.sun.star.uno.UnoRuntime; 38 import com.sun.star.uno.XInterface; 39 import com.sun.star.util.XCloseable; 40 41 42 /** 43 * Test for object which is represented by service 44 * <code>com.sun.star.form.Forms</code>. <p> 45 * Object implements the following interfaces : 46 * <ul> 47 * <li> <code>com::sun::star::container::XNameReplace</code></li> 48 * <li> <code>com::sun::star::container::XIndexReplace</code></li> 49 * <li> <code>com::sun::star::container::XNameContainer</code></li> 50 * <li> <code>com::sun::star::container::XIndexAccess</code></li> 51 * <li> <code>com::sun::star::container::XElementAccess</code></li> 52 * <li> <code>com::sun::star::container::XEnumerationAccess</code></li> 53 * <li> <code>com::sun::star::container::XIndexContainer</code></li> 54 * <li> <code>com::sun::star::container::XNameAccess</code></li> 55 * </ul> 56 * 57 * This object test <b> is NOT </b> designed to be run in several 58 * threads concurently. 59 * 60 * @see com.sun.star.container.XNameReplace 61 * @see com.sun.star.container.XIndexReplace 62 * @see com.sun.star.container.XNameContainer 63 * @see com.sun.star.container.XIndexAccess 64 * @see com.sun.star.container.XElementAccess 65 * @see com.sun.star.container.XEnumerationAccess 66 * @see com.sun.star.container.XIndexContainer 67 * @see com.sun.star.container.XNameAccess 68 * @see ifc.container._XNameReplace 69 * @see ifc.container._XIndexReplace 70 * @see ifc.container._XNameContainer 71 * @see ifc.container._XIndexAccess 72 * @see ifc.container._XElementAccess 73 * @see ifc.container._XEnumerationAccess 74 * @see ifc.container._XIndexContainer 75 * @see ifc.container._XNameAccess 76 */ 77 public class OFormsCollection extends TestCase { 78 XComponent xDrawDoc; 79 80 /** 81 * Creates Drawing document. 82 */ initialize(TestParameters tParam, PrintWriter log)83 protected void initialize(TestParameters tParam, PrintWriter log) { 84 log.println("creating a draw document"); 85 xDrawDoc = DrawTools.createDrawDoc(((XMultiServiceFactory) tParam.getMSF())); 86 } 87 88 /** 89 * Disposes drawing document. 90 */ cleanup(TestParameters tParam, PrintWriter log)91 protected void cleanup(TestParameters tParam, PrintWriter log) { 92 log.println(" disposing xDrawDoc "); 93 94 try { 95 XCloseable closer = (XCloseable) UnoRuntime.queryInterface( 96 XCloseable.class, xDrawDoc); 97 closer.close(true); 98 } catch (com.sun.star.util.CloseVetoException e) { 99 log.println("couldn't close document"); 100 } catch (com.sun.star.lang.DisposedException e) { 101 log.println("couldn't close document"); 102 } 103 } 104 105 /** 106 * Adds some controls to the 'Standard' form of a draw page, 107 * then adds an empty form to a collection of forms. Then 108 * returns the collection as a test object. <p> 109 * Object relations created : 110 * <ul> 111 * <li> <code>'INSTANCE1' ... 'INSTANCEN'</code> for 112 * <code>XNameReplace, XNameContainer, XIndexReplace, 113 * XIndexContainer </code> : objects to be inserted 114 * or replaced with in interface tests. Number of relations 115 * depends on number of interface test threads. For each 116 * thread there must be an individual element. </li> 117 * <li> <code>'XNameContainer.AllowDuplicateNames'</code> : 118 * if this relation exists then container elements can have duplicate 119 * names. In case of forms' collection forms can have equal names.</li> 120 * </ul> 121 */ createTestEnvironment(TestParameters Param, PrintWriter log)122 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, 123 PrintWriter log) { 124 XInterface oObj = null; 125 XDrawPage oDP = null; 126 127 128 // creation of testobject here 129 // first we write what we are intend to do to log file 130 log.println("creating a test environment"); 131 132 oDP = DrawTools.getDrawPage(xDrawDoc, 0); 133 134 (DrawTools.getShapes(oDP)) 135 .add(FormTools.createControlShape(xDrawDoc, 2000, 1500, 1000, 1000, 136 "CheckBox")); 137 (DrawTools.getShapes(oDP)) 138 .add(FormTools.createControlShape(xDrawDoc, 3000, 4500, 15000, 139 1000, "CommandButton")); 140 (DrawTools.getShapes(oDP)) 141 .add(FormTools.createControlShape(xDrawDoc, 5000, 3500, 7500, 5000, 142 "TextField")); 143 144 oObj = FormTools.getForms(oDP); 145 FormTools.insertForm(xDrawDoc, (XNameContainer) oObj, "SecondForm"); 146 147 log.println("creating a new environment for drawpage object"); 148 149 TestEnvironment tEnv = new TestEnvironment(oObj); 150 151 152 // INSTANCEn : _XNameContainer; _XNameReplace 153 log.println("adding INSTANCEn as obj relation to environment"); 154 155 XComponent xComp = (XComponent) UnoRuntime.queryInterface( 156 XComponent.class, xDrawDoc); 157 int THRCNT = 1; 158 if (Param.get("THRCNT")!= null) { 159 THRCNT = Integer.parseInt((String) Param.get("THRCNT")); 160 } 161 162 for (int n = 1; n < (THRCNT + 1); n++) { 163 log.println("adding INSTANCE" + n + 164 " as obj relation to environment"); 165 tEnv.addObjRelation("INSTANCE" + n, 166 FormTools.createControl(xComp, "Form")); 167 } 168 169 170 // adding indicator that this collection can have duplicate 171 // elements with the same names for XNameContainer test. 172 tEnv.addObjRelation("XNameContainer.AllowDuplicateNames", new Object()); 173 174 tEnv.addObjRelation("INSTANCE", FormTools.createControl(xComp, "Form")); 175 tEnv.addObjRelation("INSTANCE2", 176 FormTools.createControl(xComp, "Form")); 177 178 return tEnv; 179 } // finish method getTestEnvironment 180 } // finish class OFormsCollection 181