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