bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _forms / OGridControlModel.java
blob490162dd6d670c647ab85e27f32f68014265e684
1 /*
2 * This file is part of the LibreOffice project.
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/.
8 * This file incorporates work covered by the following license notice:
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 .
18 package mod._forms;
20 import java.io.PrintWriter;
21 import java.util.Comparator;
23 import lib.StatusException;
24 import lib.TestCase;
25 import lib.TestEnvironment;
26 import lib.TestParameters;
27 import util.FormTools;
28 import util.SOfficeFactory;
30 import com.sun.star.beans.XPropertySet;
31 import com.sun.star.container.XNameContainer;
32 import com.sun.star.container.XNamed;
33 import com.sun.star.drawing.XControlShape;
34 import com.sun.star.form.XGridColumnFactory;
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;
42 /**
43 * Test for object which is represented by service
44 * <code>com.sun.star.form.component.GridControl</code>. <p>
45 * Object implements the following interfaces :
46 * <ul>
47 * <li> <code>com::sun::star::io::XPersistObject</code></li>
48 * <li> <code>com::sun::star::container::XNameReplace</code></li>
49 * <li> <code>com::sun::star::form::XReset</code></li>
50 * <li> <code>com::sun::star::script::XEventAttacherManager</code></li>
51 * <li> <code>com::sun::star::form::FormComponent</code></li>
52 * <li> <code>com::sun::star::beans::XFastPropertySet</code></li>
53 * <li> <code>com::sun::star::beans::XMultiPropertySet</code></li>
54 * <li> <code>com::sun::star::container::XElementAccess</code></li>
55 * <li> <code>com::sun::star::form::component::GridControl</code></li>
56 * <li> <code>com::sun::star::view::XSelectionSupplier</code></li>
57 * <li> <code>com::sun::star::container::XEnumerationAccess</code></li>
58 * <li> <code>com::sun::star::beans::XPropertyState</code></li>
59 * <li> <code>com::sun::star::form::FormControlModel</code></li>
60 * <li> <code>com::sun::star::container::XIndexReplace</code></li>
61 * <li> <code>com::sun::star::container::XNamed</code></li>
62 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
63 * <li> <code>com::sun::star::container::XNameContainer</code></li>
64 * <li> <code>com::sun::star::form::XGridColumnFactory</code></li>
65 * <li> <code>com::sun::star::lang::XComponent</code></li>
66 * <li> <code>com::sun::star::container::XNameAccess</code></li>
67 * <li> <code>com::sun::star::beans::XPropertyAccess</code></li>
68 * <li> <code>com::sun::star::beans::XPropertyContainer</code></li>
69 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
70 * <li> <code>com::sun::star::container::XIndexContainer</code></li>
71 * <li> <code>com::sun::star::container::XChild</code></li>
72 * <li> <code>com::sun::star::container::XContainer</code></li>
73 * </ul> <p>
74 * This object test <b> is NOT </b> designed to be run in several
75 * threads concurently.
77 * @see com.sun.star.io.XPersistObject
78 * @see com.sun.star.container.XNameReplace
79 * @see com.sun.star.form.XReset
80 * @see com.sun.star.script.XEventAttacherManager
81 * @see com.sun.star.form.FormComponent
82 * @see com.sun.star.beans.XFastPropertySet
83 * @see com.sun.star.beans.XMultiPropertySet
84 * @see com.sun.star.container.XElementAccess
85 * @see com.sun.star.form.component.GridControl
86 * @see com.sun.star.view.XSelectionSupplier
87 * @see com.sun.star.container.XEnumerationAccess
88 * @see com.sun.star.beans.XPropertyState
89 * @see com.sun.star.form
90 * @see com.sun.star.container.XIndexReplace
91 * @see com.sun.star.container.XNamed
92 * @see com.sun.star.container.XIndexAccess
93 * @see com.sun.star.container.XNameContainer
94 * @see com.sun.star.form.XGridColumnFactory
95 * @see com.sun.star.lang.XComponent
96 * @see com.sun.star.container.XNameAccess
97 * @see com.sun.star.beans.XPropertyAccess
98 * @see com.sun.star.beans.XPropertyContainer
99 * @see com.sun.star.beans.XPropertySet
100 * @see com.sun.star.container.XIndexContainer
101 * @see com.sun.star.container.XChild
102 * @see com.sun.star.container.XContainer
103 * @see ifc.io._XPersistObject
104 * @see ifc.container._XNameReplace
105 * @see ifc.form._XReset
106 * @see ifc.script._XEventAttacherManager
107 * @see ifc.form._FormComponent
108 * @see ifc.beans._XFastPropertySet
109 * @see ifc.beans._XMultiPropertySet
110 * @see ifc.container._XElementAccess
111 * @see ifc.form.component._GridControl
112 * @see ifc.view._XSelectionSupplier
113 * @see ifc.container._XEnumerationAccess
114 * @see ifc.beans._XPropertyState
115 * @see ifc.form._FormControlModel
116 * @see ifc.container._XIndexReplace
117 * @see ifc.container._XNamed
118 * @see ifc.container._XIndexAccess
119 * @see ifc.container._XNameContainer
120 * @see ifc.form._XGridColumnFactory
121 * @see ifc.lang._XComponent
122 * @see ifc.container._XNameAccess
123 * @see ifc.beans._XPropertySet
124 * @see ifc.container._XIndexContainer
125 * @see ifc.container._XChild
126 * @see ifc.container._XContainer
129 public class OGridControlModel extends GenericModelTest {
132 * Set some member variable of the super class <CODE>GenericModelTest</CODE>:
133 * <pre>
134 * super.m_kindOfControl="CommandButton";
135 * super.m_ObjectName = "com.sun.star.form.component.CommandButton";
136 * super.m_LCShape_Type = "CommandButton";
137 * </pre>
138 * Then <CODE>super.initialize()</CODE> was called.
139 * @param tParam the test parameter
140 * @param log the log writer
143 protected void initialize(TestParameters tParam, PrintWriter log) {
145 super.initialize(tParam, log);
147 super.m_kindOfControl="GridControl";
149 super.m_ObjectName = "stardiv.one.form.component.Grid";
151 super.m_LCShape_Type = "GridControl";
155 * calls <CODE>cleanup()</CODE> from it's super class
156 * @param tParam the test parameter
157 * @param log the log writer
159 protected void cleanup(TestParameters tParam, PrintWriter log) {
160 super.cleanup(tParam, log);
165 * calls <CODE>createTestEnvironment()</CODE> from it's super class
166 * @param Param the test parameter
167 * @param log the log writer
168 * @return lib.TestEnvironment
170 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param,
171 PrintWriter log) {
172 TestEnvironment tEnv = super.createTestEnvironment(Param, log);
174 XInterface oObj = tEnv.getTestObject();
176 XPropertySet aControl = null;
177 XPropertySet aControl2 = null;
178 XPropertySet aControl3 = null;
179 XPropertySet aControl4 = null;
180 XPropertySet aControl5 = null;
182 try {
183 XGridColumnFactory columns = UnoRuntime.queryInterface(
184 XGridColumnFactory.class, oObj);
185 aControl = columns.createColumn("TextField");
186 aControl2 = columns.createColumn("DateField");
187 aControl3 = columns.createColumn("TextField");
188 aControl4 = columns.createColumn("TextField");
189 aControl5 = columns.createColumn("TextField");
190 } catch (com.sun.star.lang.IllegalArgumentException e) {
191 // Some exception occurs.FAILED
192 log.println("!!! Couldn't create instance : " + e);
193 throw new StatusException("Can't create column instances.", e);
196 XNameContainer aContainer = UnoRuntime.queryInterface(
197 XNameContainer.class, oObj);
199 try {
200 aContainer.insertByName("First", aControl);
201 aContainer.insertByName("Second", aControl2);
202 } catch (com.sun.star.lang.WrappedTargetException e) {
203 log.println("!!! Could't insert column Instance");
204 e.printStackTrace(log);
205 throw new StatusException("Can't insert columns", e);
206 } catch (com.sun.star.lang.IllegalArgumentException e) {
207 log.println("!!! Could't insert column Instance");
208 e.printStackTrace(log);
209 throw new StatusException("Can't insert columns", e);
210 } catch (com.sun.star.container.ElementExistException e) {
211 log.println("!!! Could't insert column Instance");
212 e.printStackTrace(log);
213 throw new StatusException("Can't insert columns", e);
216 //Relations for XSelectionSupplier
217 tEnv.addObjRelation("Selections", new Object[] { aControl, aControl2 });
219 // adding relation for XNameContainer
220 tEnv.addObjRelation("XNameContainer.AllowDuplicateNames", new Object());
223 // adding relation for XContainer
224 tEnv.addObjRelation("INSTANCE", aControl3);
225 tEnv.addObjRelation("INSTANCE1", aControl4);
226 tEnv.addObjRelation("INSTANCE2", aControl5);
229 tEnv.addObjRelation("Comparer",
230 new Comparator<Object>() {
231 public int compare(Object o1, Object o2) {
232 XNamed named1 = UnoRuntime.queryInterface(
233 XNamed.class, o1);
234 XNamed named2 = UnoRuntime.queryInterface(
235 XNamed.class, o2);
237 if (named1.getName().equals(named2.getName())) {
238 return 0;
241 return -1;
246 // HashSet exclude = new HashSet();
248 // exclude.add("FormatKey");
250 // tEnv.addObjRelation("XUpdateBroadcaster.Checker",
251 // new Checker(m_XFormLoader, m_XPS, m_XCtrl, m_ChangePropertyName, m_ChangePropertyValue));
252 return tEnv;
255 } // finish class OButtonModelold
258 class OGridControlModelold extends TestCase {
259 XComponent xDrawDoc = null;
262 * Creates Drawing document.
264 protected void initialize(TestParameters tParam, PrintWriter log) {
265 SOfficeFactory SOF = SOfficeFactory.getFactory(((XMultiServiceFactory) tParam.getMSF()));
267 log.println("creating a draw document");
269 try {
270 xDrawDoc = SOF.createDrawDoc(null);
271 } catch (com.sun.star.uno.Exception e) {
272 throw new StatusException("Can't create Draw document", e);
277 * Disposes drawing document.
279 protected void cleanup(TestParameters tParam, PrintWriter log) {
280 log.println(" disposing xDrawDoc ");
282 try {
283 XCloseable closer = UnoRuntime.queryInterface(
284 XCloseable.class, xDrawDoc);
285 closer.close(true);
286 } catch (com.sun.star.util.CloseVetoException e) {
287 log.println("couldn't close document");
288 } catch (com.sun.star.lang.DisposedException e) {
289 log.println("couldn't close document");
294 * <code>GridControl</code> component created and added to the draw
295 * page. Then two columns are created and added to the grid.
296 * Object relations created :
297 * <ul>
298 * <li> <code>'INSTANCE1' ... 'INSTANCEN'</code> for
299 * <code>XNameReplace, XNameContainer, XIndexReplace,
300 * XIndexContainer </code> : objects to be inserted
301 * or replaced with in interface tests. Number of relations
302 * depends on number of interface test threads. For each
303 * thread there must be an individual element. </li>
304 * <li> <code>'XNameContainer.AllowDuplicateNames'</code> :
305 * if this relation exists then container elements can have duplicate
306 * names. <code>GridControl</code> can have.</li>
307 * <li> <code>'OBJNAME'</code> for
308 * {@link ifc.io._XPersistObject} : name of service which is
309 * represented by this object. </li>
310 * <li> <code>'INSTANCE'</code> for
311 * {@link ifc.container._XContainer} : a column instance. </li>
312 * </ul>
314 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param,
315 PrintWriter log) {
316 XInterface oObj = null;
317 XInterface oInstance = null;
318 XPropertySet aControl = null;
319 XPropertySet aControl2 = null;
320 XPropertySet aControl3 = null;
321 XPropertySet aControl4 = null;
322 XGridColumnFactory columns = null;
325 // creation of testobject here
326 // first we write what we are intend to do to log file
327 log.println("creating a test environment");
329 XControlShape shape = FormTools.insertControlShape(xDrawDoc, 5000,
330 7000, 2000, 2000,
331 "GridControl");
332 oObj = shape.getControl();
334 log.println("creating a new environment for drawpage object");
336 TestEnvironment tEnv = new TestEnvironment(oObj);
338 try {
339 columns = UnoRuntime.queryInterface(
340 XGridColumnFactory.class, oObj);
341 aControl = columns.createColumn("TextField");
342 aControl2 = columns.createColumn("DateField");
343 aControl3 = columns.createColumn("TextField");
344 aControl4 = columns.createColumn("TextField");
345 columns.createColumn("TextField");
346 } catch (com.sun.star.lang.IllegalArgumentException e) {
347 // Some exception occurs.FAILED
348 log.println("!!! Couldn't create instance : " + e);
349 throw new StatusException("Can't create column instances.", e);
352 XNameContainer aContainer = UnoRuntime.queryInterface(
353 XNameContainer.class, oObj);
355 try {
356 aContainer.insertByName("First", aControl);
357 aContainer.insertByName("Second", aControl2);
358 } catch (com.sun.star.lang.WrappedTargetException e) {
359 log.println("!!! Could't insert column Instance");
360 e.printStackTrace(log);
361 throw new StatusException("Can't insert columns", e);
362 } catch (com.sun.star.lang.IllegalArgumentException e) {
363 log.println("!!! Could't insert column Instance");
364 e.printStackTrace(log);
365 throw new StatusException("Can't insert columns", e);
366 } catch (com.sun.star.container.ElementExistException e) {
367 log.println("!!! Could't insert column Instance");
368 e.printStackTrace(log);
369 throw new StatusException("Can't insert columns", e);
372 //Relations for XSelectionSupplier
373 tEnv.addObjRelation("Selections", new Object[] { aControl, aControl2 });
375 // COMPARER
377 int THRCNT = 1;
378 String count = (String)Param.get("THRCNT");
379 if (count != null)
380 THRCNT = Integer.parseInt(count);
383 // INSTANCEn : _XNameContainer; _XNameReplace
384 log.println("adding INSTANCEn as obj relation to environment");
386 try {
387 for (int n = 1; n < (3 * THRCNT + 1); n++) {
388 log.println("adding INSTANCE" + n +
389 " as obj relation to environment");
390 oInstance = columns.createColumn("TextField");
391 tEnv.addObjRelation("INSTANCE" + n, oInstance);
393 } catch (com.sun.star.lang.IllegalArgumentException e) {
394 e.printStackTrace(log);
395 throw new StatusException("Can't create 'INSTANCEn' relations", e);
399 // adding relation for XNameContainer
400 tEnv.addObjRelation("XNameContainer.AllowDuplicateNames", new Object());
402 // OK tEnv.addObjRelation("OBJNAME", "stardiv.one.form.component." + objName);
405 // adding relation for XContainer
406 tEnv.addObjRelation("INSTANCE", aControl3);
407 tEnv.addObjRelation("INSTANCE2", aControl4);
410 //adding ObjRelation for XPersistObject
411 // OK tEnv.addObjRelation("PSEUDOPERSISTENT", new Boolean(true)); // OK
413 return tEnv;
414 } // finish method getTestEnvironment
415 } // finish class OGridControlModel