1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: OGridControlModel.java,v $
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 ************************************************************************/
32 import java
.io
.PrintWriter
;
33 import java
.util
.Comparator
;
35 import lib
.StatusException
;
37 import lib
.TestEnvironment
;
38 import lib
.TestParameters
;
39 import util
.FormTools
;
40 import util
.SOfficeFactory
;
42 import com
.sun
.star
.beans
.XPropertySet
;
43 import com
.sun
.star
.container
.XNameContainer
;
44 import com
.sun
.star
.container
.XNamed
;
45 import com
.sun
.star
.drawing
.XControlShape
;
46 import com
.sun
.star
.form
.XGridColumnFactory
;
47 import com
.sun
.star
.lang
.XComponent
;
48 import com
.sun
.star
.lang
.XMultiServiceFactory
;
49 import com
.sun
.star
.uno
.UnoRuntime
;
50 import com
.sun
.star
.uno
.XInterface
;
51 import com
.sun
.star
.util
.XCloseable
;
55 * Test for object which is represented by service
56 * <code>com.sun.star.form.component.GridControl</code>. <p>
57 * Object implements the following interfaces :
59 * <li> <code>com::sun::star::io::XPersistObject</code></li>
60 * <li> <code>com::sun::star::container::XNameReplace</code></li>
61 * <li> <code>com::sun::star::form::XReset</code></li>
62 * <li> <code>com::sun::star::script::XEventAttacherManager</code></li>
63 * <li> <code>com::sun::star::form::FormComponent</code></li>
64 * <li> <code>com::sun::star::beans::XFastPropertySet</code></li>
65 * <li> <code>com::sun::star::beans::XMultiPropertySet</code></li>
66 * <li> <code>com::sun::star::container::XElementAccess</code></li>
67 * <li> <code>com::sun::star::form::component::GridControl</code></li>
68 * <li> <code>com::sun::star::view::XSelectionSupplier</code></li>
69 * <li> <code>com::sun::star::container::XEnumerationAccess</code></li>
70 * <li> <code>com::sun::star::beans::XPropertyState</code></li>
71 * <li> <code>com::sun::star::form::FormControlModel</code></li>
72 * <li> <code>com::sun::star::container::XIndexReplace</code></li>
73 * <li> <code>com::sun::star::container::XNamed</code></li>
74 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
75 * <li> <code>com::sun::star::container::XNameContainer</code></li>
76 * <li> <code>com::sun::star::form::XGridColumnFactory</code></li>
77 * <li> <code>com::sun::star::lang::XComponent</code></li>
78 * <li> <code>com::sun::star::container::XNameAccess</code></li>
79 * <li> <code>com::sun::star::beans::XPropertyAccess</code></li>
80 * <li> <code>com::sun::star::beans::XPropertyContainer</code></li>
81 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
82 * <li> <code>com::sun::star::container::XIndexContainer</code></li>
83 * <li> <code>com::sun::star::container::XChild</code></li>
84 * <li> <code>com::sun::star::container::XContainer</code></li>
86 * This object test <b> is NOT </b> designed to be run in several
87 * threads concurently.
89 * @see com.sun.star.io.XPersistObject
90 * @see com.sun.star.container.XNameReplace
91 * @see com.sun.star.form.XReset
92 * @see com.sun.star.script.XEventAttacherManager
93 * @see com.sun.star.form.FormComponent
94 * @see com.sun.star.beans.XFastPropertySet
95 * @see com.sun.star.beans.XMultiPropertySet
96 * @see com.sun.star.container.XElementAccess
97 * @see com.sun.star.form.component.GridControl
98 * @see com.sun.star.view.XSelectionSupplier
99 * @see com.sun.star.container.XEnumerationAccess
100 * @see com.sun.star.beans.XPropertyState
101 * @see com.sun.star.form.FormControlModel
102 * @see com.sun.star.container.XIndexReplace
103 * @see com.sun.star.container.XNamed
104 * @see com.sun.star.container.XIndexAccess
105 * @see com.sun.star.container.XNameContainer
106 * @see com.sun.star.form.XGridColumnFactory
107 * @see com.sun.star.lang.XComponent
108 * @see com.sun.star.container.XNameAccess
109 * @see com.sun.star.beans.XPropertyAccess
110 * @see com.sun.star.beans.XPropertyContainer
111 * @see com.sun.star.beans.XPropertySet
112 * @see com.sun.star.container.XIndexContainer
113 * @see com.sun.star.container.XChild
114 * @see com.sun.star.container.XContainer
115 * @see ifc.io._XPersistObject
116 * @see ifc.container._XNameReplace
117 * @see ifc.form._XReset
118 * @see ifc.script._XEventAttacherManager
119 * @see ifc.form._FormComponent
120 * @see ifc.beans._XFastPropertySet
121 * @see ifc.beans._XMultiPropertySet
122 * @see ifc.container._XElementAccess
123 * @see ifc.form.component._GridControl
124 * @see ifc.view._XSelectionSupplier
125 * @see ifc.container._XEnumerationAccess
126 * @see ifc.beans._XPropertyState
127 * @see ifc.form._FormControlModel
128 * @see ifc.container._XIndexReplace
129 * @see ifc.container._XNamed
130 * @see ifc.container._XIndexAccess
131 * @see ifc.container._XNameContainer
132 * @see ifc.form._XGridColumnFactory
133 * @see ifc.lang._XComponent
134 * @see ifc.container._XNameAccess
135 * @see ifc.beans._XPropertySet
136 * @see ifc.container._XIndexContainer
137 * @see ifc.container._XChild
138 * @see ifc.container._XContainer
141 public class OGridControlModel
extends GenericModelTest
{
144 * Set some member variable of the super class <CODE>GenericModelTest</CODE>:
146 * super.m_kindOfControl="CommandButton";
147 * super.m_ObjectName = "com.sun.star.form.component.CommandButton";
148 * super.m_LCShape_Type = "CommandButton";
150 * Then <CODE>super.initialize()</CODE> was called.
151 * @param tParam the test parameter
152 * @param log the log writer
155 protected void initialize(TestParameters tParam
, PrintWriter log
) {
157 super.initialize(tParam
, log
);
159 super.m_kindOfControl
="GridControl";
161 super.m_ObjectName
= "stardiv.one.form.component.Grid";
163 super.m_LCShape_Type
= "GridControl";
167 * calls <CODE>cleanup()</CODE> from it's super class
168 * @param tParam the test parameter
169 * @param log the log writer
171 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
172 super.cleanup(tParam
, log
);
177 * calls <CODE>createTestEnvironment()</CODE> from it's super class
178 * @param Param the test parameter
179 * @param log the log writer
180 * @return lib.TestEnvironment
182 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
,
184 TestEnvironment tEnv
= super.createTestEnvironment(Param
, log
);
186 XInterface oObj
= tEnv
.getTestObject();
188 XPropertySet aControl
= null;
189 XPropertySet aControl2
= null;
190 XPropertySet aControl3
= null;
191 XPropertySet aControl4
= null;
192 XPropertySet aControl5
= null;
195 XGridColumnFactory columns
= (XGridColumnFactory
) UnoRuntime
.queryInterface(
196 XGridColumnFactory
.class, oObj
);
197 aControl
= columns
.createColumn("TextField");
198 aControl2
= columns
.createColumn("DateField");
199 aControl3
= columns
.createColumn("TextField");
200 aControl4
= columns
.createColumn("TextField");
201 aControl5
= columns
.createColumn("TextField");
202 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
203 // Some exception occures.FAILED
204 log
.println("!!! Couldn't create instance : " + e
);
205 throw new StatusException("Can't create column instances.", e
);
208 XNameContainer aContainer
= (XNameContainer
) UnoRuntime
.queryInterface(
209 XNameContainer
.class, oObj
);
212 aContainer
.insertByName("First", aControl
);
213 aContainer
.insertByName("Second", aControl2
);
214 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
215 log
.println("!!! Could't insert column Instance");
216 e
.printStackTrace(log
);
217 throw new StatusException("Can't insert columns", e
);
218 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
219 log
.println("!!! Could't insert column Instance");
220 e
.printStackTrace(log
);
221 throw new StatusException("Can't insert columns", e
);
222 } catch (com
.sun
.star
.container
.ElementExistException e
) {
223 log
.println("!!! Could't insert column Instance");
224 e
.printStackTrace(log
);
225 throw new StatusException("Can't insert columns", e
);
228 //Relations for XSelectionSupplier
229 tEnv
.addObjRelation("Selections", new Object
[] { aControl
, aControl2
});
231 // adding relation for XNameContainer
232 tEnv
.addObjRelation("XNameContainer.AllowDuplicateNames", new Object());
235 // adding relation for XContainer
236 tEnv
.addObjRelation("INSTANCE", aControl3
);
237 tEnv
.addObjRelation("INSTANCE1", aControl4
);
238 tEnv
.addObjRelation("INSTANCE2", aControl5
);
241 tEnv
.addObjRelation("Comparer",
243 public int compare(Object o1
, Object o2
) {
244 XNamed named1
= (XNamed
) UnoRuntime
.queryInterface(
246 XNamed named2
= (XNamed
) UnoRuntime
.queryInterface(
249 if (named1
.getName().equals(named2
.getName())) {
256 public boolean equals(Object obj
) {
257 return compare(this, obj
) == 0;
262 // HashSet exclude = new HashSet();
264 // exclude.add("FormatKey");
266 // tEnv.addObjRelation("XUpdateBroadcaster.Checker",
267 // new Checker(m_XFormLoader, m_XPS, m_XCtrl, m_ChangePropertyName, m_ChangePropertyValue));
271 } // finish class OButtonModelold
274 class OGridControlModelold
extends TestCase
{
275 XComponent xDrawDoc
= null;
278 * Creates Drawing document.
280 protected void initialize(TestParameters tParam
, PrintWriter log
) {
281 SOfficeFactory SOF
= SOfficeFactory
.getFactory(((XMultiServiceFactory
) tParam
.getMSF()));
283 log
.println("creating a draw document");
286 xDrawDoc
= SOF
.createDrawDoc(null);
287 } catch (com
.sun
.star
.uno
.Exception e
) {
288 throw new StatusException("Can't create Draw document", e
);
293 * Disposes drawing document.
295 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
296 log
.println(" disposing xDrawDoc ");
299 XCloseable closer
= (XCloseable
) UnoRuntime
.queryInterface(
300 XCloseable
.class, xDrawDoc
);
302 } catch (com
.sun
.star
.util
.CloseVetoException e
) {
303 log
.println("couldn't close document");
304 } catch (com
.sun
.star
.lang
.DisposedException e
) {
305 log
.println("couldn't close document");
310 * <code>GridControl</code> component created and added to the draw
311 * page. Then two columns are created and added to the grid.
312 * Object relations created :
314 * <li> <code>'INSTANCE1' ... 'INSTANCEN'</code> for
315 * <code>XNameReplace, XNameContainer, XIndexReplace,
316 * XIndexContainer </code> : objects to be inserted
317 * or replaced with in interface tests. Number of relations
318 * depends on number of interface test threads. For each
319 * thread there must be an individual element. </li>
320 * <li> <code>'XNameContainer.AllowDuplicateNames'</code> :
321 * if this relation exists then container elements can have duplicate
322 * names. <code>GridControl</code> can have.</li>
323 * <li> <code>'OBJNAME'</code> for
324 * {@link ifc.io._XPersistObject} : name of service which is
325 * represented by this object. </li>
326 * <li> <code>'INSTANCE'</code> for
327 * {@link ifc.container._XContainer} : a column instance. </li>
330 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
,
332 XInterface oObj
= null;
333 XInterface oInstance
= null;
334 XPropertySet aControl
= null;
335 XPropertySet aControl2
= null;
336 XPropertySet aControl3
= null;
337 XPropertySet aControl4
= null;
338 XPropertySet aControl5
= null;
339 XGridColumnFactory columns
= null;
342 // creation of testobject here
343 // first we write what we are intend to do to log file
344 log
.println("creating a test environment");
346 //get GridControlModel
347 String objName
= "Grid";
348 XControlShape shape
= FormTools
.insertControlShape(xDrawDoc
, 5000,
351 oObj
= shape
.getControl();
353 log
.println("creating a new environment for drawpage object");
355 TestEnvironment tEnv
= new TestEnvironment(oObj
);
358 columns
= (XGridColumnFactory
) UnoRuntime
.queryInterface(
359 XGridColumnFactory
.class, oObj
);
360 aControl
= columns
.createColumn("TextField");
361 aControl2
= columns
.createColumn("DateField");
362 aControl3
= columns
.createColumn("TextField");
363 aControl4
= columns
.createColumn("TextField");
364 aControl5
= columns
.createColumn("TextField");
365 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
366 // Some exception occures.FAILED
367 log
.println("!!! Couldn't create instance : " + e
);
368 throw new StatusException("Can't create column instances.", e
);
371 XNameContainer aContainer
= (XNameContainer
) UnoRuntime
.queryInterface(
372 XNameContainer
.class, oObj
);
375 aContainer
.insertByName("First", aControl
);
376 aContainer
.insertByName("Second", aControl2
);
377 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
378 log
.println("!!! Could't insert column Instance");
379 e
.printStackTrace(log
);
380 throw new StatusException("Can't insert columns", e
);
381 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
382 log
.println("!!! Could't insert column Instance");
383 e
.printStackTrace(log
);
384 throw new StatusException("Can't insert columns", e
);
385 } catch (com
.sun
.star
.container
.ElementExistException e
) {
386 log
.println("!!! Could't insert column Instance");
387 e
.printStackTrace(log
);
388 throw new StatusException("Can't insert columns", e
);
391 //Relations for XSelectionSupplier
392 tEnv
.addObjRelation("Selections", new Object
[] { aControl
, aControl2
});
397 String count
= (String
)Param
.get("THRCNT");
399 THRCNT
= Integer
.parseInt(count
);
402 // INSTANCEn : _XNameContainer; _XNameReplace
403 log
.println("adding INSTANCEn as obj relation to environment");
406 for (int n
= 1; n
< (3 * THRCNT
+ 1); n
++) {
407 log
.println("adding INSTANCE" + n
+
408 " as obj relation to environment");
409 oInstance
= columns
.createColumn("TextField");
410 tEnv
.addObjRelation("INSTANCE" + n
, oInstance
);
412 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
413 e
.printStackTrace(log
);
414 throw new StatusException("Can't create 'INSTANCEn' relations", e
);
418 // adding relation for XNameContainer
419 tEnv
.addObjRelation("XNameContainer.AllowDuplicateNames", new Object());
421 // OK tEnv.addObjRelation("OBJNAME", "stardiv.one.form.component." + objName);
424 // adding relation for XContainer
425 tEnv
.addObjRelation("INSTANCE", aControl3
);
426 tEnv
.addObjRelation("INSTANCE2", aControl4
);
429 //adding ObjRelation for XPersistObject
430 // OK tEnv.addObjRelation("PSEUDOPERSISTENT", new Boolean(true)); // OK
433 } // finish method getTestEnvironment
434 } // finish class OGridControlModel