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