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