merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _forms / OFormsCollection.java
blobfee2a9e79fd655a5faa8f329c3c4cfe1bbd15931
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: OFormsCollection.java,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 package mod._forms;
32 import java.io.PrintWriter;
34 import lib.TestCase;
35 import lib.TestEnvironment;
36 import lib.TestParameters;
37 import util.DrawTools;
38 import util.FormTools;
40 import com.sun.star.container.XNameContainer;
41 import com.sun.star.drawing.XDrawPage;
42 import com.sun.star.lang.XComponent;
43 import com.sun.star.lang.XMultiServiceFactory;
44 import com.sun.star.uno.UnoRuntime;
45 import com.sun.star.uno.XInterface;
46 import com.sun.star.util.XCloseable;
49 /**
50 * Test for object which is represented by service
51 * <code>com.sun.star.form.Forms</code>. <p>
52 * Object implements the following interfaces :
53 * <ul>
54 * <li> <code>com::sun::star::container::XNameReplace</code></li>
55 * <li> <code>com::sun::star::container::XIndexReplace</code></li>
56 * <li> <code>com::sun::star::container::XNameContainer</code></li>
57 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
58 * <li> <code>com::sun::star::container::XElementAccess</code></li>
59 * <li> <code>com::sun::star::container::XEnumerationAccess</code></li>
60 * <li> <code>com::sun::star::container::XIndexContainer</code></li>
61 * <li> <code>com::sun::star::container::XNameAccess</code></li>
62 * </ul>
64 * This object test <b> is NOT </b> designed to be run in several
65 * threads concurently.
67 * @see com.sun.star.container.XNameReplace
68 * @see com.sun.star.container.XIndexReplace
69 * @see com.sun.star.container.XNameContainer
70 * @see com.sun.star.container.XIndexAccess
71 * @see com.sun.star.container.XElementAccess
72 * @see com.sun.star.container.XEnumerationAccess
73 * @see com.sun.star.container.XIndexContainer
74 * @see com.sun.star.container.XNameAccess
75 * @see ifc.container._XNameReplace
76 * @see ifc.container._XIndexReplace
77 * @see ifc.container._XNameContainer
78 * @see ifc.container._XIndexAccess
79 * @see ifc.container._XElementAccess
80 * @see ifc.container._XEnumerationAccess
81 * @see ifc.container._XIndexContainer
82 * @see ifc.container._XNameAccess
84 public class OFormsCollection extends TestCase {
85 XComponent xDrawDoc;
87 /**
88 * Creates Drawing document.
90 protected void initialize(TestParameters tParam, PrintWriter log) {
91 log.println("creating a draw document");
92 xDrawDoc = DrawTools.createDrawDoc(((XMultiServiceFactory) tParam.getMSF()));
95 /**
96 * Disposes drawing document.
98 protected void cleanup(TestParameters tParam, PrintWriter log) {
99 log.println(" disposing xDrawDoc ");
101 try {
102 XCloseable closer = (XCloseable) UnoRuntime.queryInterface(
103 XCloseable.class, xDrawDoc);
104 closer.close(true);
105 } catch (com.sun.star.util.CloseVetoException e) {
106 log.println("couldn't close document");
107 } catch (com.sun.star.lang.DisposedException e) {
108 log.println("couldn't close document");
113 * Adds some controls to the 'Standard' form of a draw page,
114 * then adds an empty form to a collection of forms. Then
115 * returns the collection as a test object. <p>
116 * Object relations created :
117 * <ul>
118 * <li> <code>'INSTANCE1' ... 'INSTANCEN'</code> for
119 * <code>XNameReplace, XNameContainer, XIndexReplace,
120 * XIndexContainer </code> : objects to be inserted
121 * or replaced with in interface tests. Number of relations
122 * depends on number of interface test threads. For each
123 * thread there must be an individual element. </li>
124 * <li> <code>'XNameContainer.AllowDuplicateNames'</code> :
125 * if this relation exists then container elements can have duplicate
126 * names. In case of forms' collection forms can have equal names.</li>
127 * </ul>
129 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param,
130 PrintWriter log) {
131 XInterface oObj = null;
132 XDrawPage oDP = null;
135 // creation of testobject here
136 // first we write what we are intend to do to log file
137 log.println("creating a test environment");
139 oDP = DrawTools.getDrawPage(xDrawDoc, 0);
141 (DrawTools.getShapes(oDP))
142 .add(FormTools.createControlShape(xDrawDoc, 2000, 1500, 1000, 1000,
143 "CheckBox"));
144 (DrawTools.getShapes(oDP))
145 .add(FormTools.createControlShape(xDrawDoc, 3000, 4500, 15000,
146 1000, "CommandButton"));
147 (DrawTools.getShapes(oDP))
148 .add(FormTools.createControlShape(xDrawDoc, 5000, 3500, 7500, 5000,
149 "TextField"));
151 oObj = FormTools.getForms(oDP);
152 FormTools.insertForm(xDrawDoc, (XNameContainer) oObj, "SecondForm");
154 log.println("creating a new environment for drawpage object");
156 TestEnvironment tEnv = new TestEnvironment(oObj);
159 // INSTANCEn : _XNameContainer; _XNameReplace
160 log.println("adding INSTANCEn as obj relation to environment");
162 XComponent xComp = (XComponent) UnoRuntime.queryInterface(
163 XComponent.class, xDrawDoc);
164 int THRCNT = 1;
165 if (Param.get("THRCNT")!= null) {
166 THRCNT = Integer.parseInt((String) Param.get("THRCNT"));
169 for (int n = 1; n < (THRCNT + 1); n++) {
170 log.println("adding INSTANCE" + n +
171 " as obj relation to environment");
172 tEnv.addObjRelation("INSTANCE" + n,
173 FormTools.createControl(xComp, "Form"));
177 // adding indicator that this collection can have duplicate
178 // elements with the same names for XNameContainer test.
179 tEnv.addObjRelation("XNameContainer.AllowDuplicateNames", new Object());
181 tEnv.addObjRelation("INSTANCE", FormTools.createControl(xComp, "Form"));
182 tEnv.addObjRelation("INSTANCE2",
183 FormTools.createControl(xComp, "Form"));
185 return tEnv;
186 } // finish method getTestEnvironment
187 } // finish class OFormsCollection