Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _forms / OGridControlModel.java
blobb11ca91c82f4e39adba9aa946d64286e3cdb0f49
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.uno.UnoRuntime;
37 import com.sun.star.uno.XInterface;
38 import com.sun.star.util.XCloseable;
41 /**
42 * Test for object which is represented by service
43 * <code>com.sun.star.form.component.GridControl</code>. <p>
44 * Object implements the following interfaces :
45 * <ul>
46 * <li> <code>com::sun::star::io::XPersistObject</code></li>
47 * <li> <code>com::sun::star::container::XNameReplace</code></li>
48 * <li> <code>com::sun::star::form::XReset</code></li>
49 * <li> <code>com::sun::star::script::XEventAttacherManager</code></li>
50 * <li> <code>com::sun::star::form::FormComponent</code></li>
51 * <li> <code>com::sun::star::beans::XFastPropertySet</code></li>
52 * <li> <code>com::sun::star::beans::XMultiPropertySet</code></li>
53 * <li> <code>com::sun::star::container::XElementAccess</code></li>
54 * <li> <code>com::sun::star::form::component::GridControl</code></li>
55 * <li> <code>com::sun::star::view::XSelectionSupplier</code></li>
56 * <li> <code>com::sun::star::container::XEnumerationAccess</code></li>
57 * <li> <code>com::sun::star::beans::XPropertyState</code></li>
58 * <li> <code>com::sun::star::form::FormControlModel</code></li>
59 * <li> <code>com::sun::star::container::XIndexReplace</code></li>
60 * <li> <code>com::sun::star::container::XNamed</code></li>
61 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
62 * <li> <code>com::sun::star::container::XNameContainer</code></li>
63 * <li> <code>com::sun::star::form::XGridColumnFactory</code></li>
64 * <li> <code>com::sun::star::lang::XComponent</code></li>
65 * <li> <code>com::sun::star::container::XNameAccess</code></li>
66 * <li> <code>com::sun::star::beans::XPropertyAccess</code></li>
67 * <li> <code>com::sun::star::beans::XPropertyContainer</code></li>
68 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
69 * <li> <code>com::sun::star::container::XIndexContainer</code></li>
70 * <li> <code>com::sun::star::container::XChild</code></li>
71 * <li> <code>com::sun::star::container::XContainer</code></li>
72 * </ul> <p>
73 * This object test <b> is NOT </b> designed to be run in several
74 * threads concurently.
76 * @see com.sun.star.io.XPersistObject
77 * @see com.sun.star.container.XNameReplace
78 * @see com.sun.star.form.XReset
79 * @see com.sun.star.script.XEventAttacherManager
80 * @see com.sun.star.form.FormComponent
81 * @see com.sun.star.beans.XFastPropertySet
82 * @see com.sun.star.beans.XMultiPropertySet
83 * @see com.sun.star.container.XElementAccess
84 * @see com.sun.star.form.component.GridControl
85 * @see com.sun.star.view.XSelectionSupplier
86 * @see com.sun.star.container.XEnumerationAccess
87 * @see com.sun.star.beans.XPropertyState
88 * @see com.sun.star.form
89 * @see com.sun.star.container.XIndexReplace
90 * @see com.sun.star.container.XNamed
91 * @see com.sun.star.container.XIndexAccess
92 * @see com.sun.star.container.XNameContainer
93 * @see com.sun.star.form.XGridColumnFactory
94 * @see com.sun.star.lang.XComponent
95 * @see com.sun.star.container.XNameAccess
96 * @see com.sun.star.beans.XPropertyAccess
97 * @see com.sun.star.beans.XPropertyContainer
98 * @see com.sun.star.beans.XPropertySet
99 * @see com.sun.star.container.XIndexContainer
100 * @see com.sun.star.container.XChild
101 * @see com.sun.star.container.XContainer
102 * @see ifc.io._XPersistObject
103 * @see ifc.container._XNameReplace
104 * @see ifc.form._XReset
105 * @see ifc.script._XEventAttacherManager
106 * @see ifc.form._FormComponent
107 * @see ifc.beans._XFastPropertySet
108 * @see ifc.beans._XMultiPropertySet
109 * @see ifc.container._XElementAccess
110 * @see ifc.form.component._GridControl
111 * @see ifc.view._XSelectionSupplier
112 * @see ifc.container._XEnumerationAccess
113 * @see ifc.beans._XPropertyState
114 * @see ifc.form._FormControlModel
115 * @see ifc.container._XIndexReplace
116 * @see ifc.container._XNamed
117 * @see ifc.container._XIndexAccess
118 * @see ifc.container._XNameContainer
119 * @see ifc.form._XGridColumnFactory
120 * @see ifc.lang._XComponent
121 * @see ifc.container._XNameAccess
122 * @see ifc.beans._XPropertySet
123 * @see ifc.container._XIndexContainer
124 * @see ifc.container._XChild
125 * @see ifc.container._XContainer
128 public class OGridControlModel extends GenericModelTest {
131 * Set some member variable of the super class <CODE>GenericModelTest</CODE>:
132 * <pre>
133 * super.m_kindOfControl="CommandButton";
134 * super.m_ObjectName = "com.sun.star.form.component.CommandButton";
135 * super.m_LCShape_Type = "CommandButton";
136 * </pre>
137 * Then <CODE>super.initialize()</CODE> was called.
138 * @param tParam the test parameter
139 * @param log the log writer
142 @Override
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";
157 * calls <CODE>createTestEnvironment()</CODE> from it's super class
158 * @param Param the test parameter
159 * @param log the log writer
160 * @return lib.TestEnvironment
162 @Override
163 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param,
164 PrintWriter log) {
165 TestEnvironment tEnv = super.createTestEnvironment(Param, log);
167 XInterface oObj = tEnv.getTestObject();
169 XPropertySet aControl = null;
170 XPropertySet aControl2 = null;
171 XPropertySet aControl3 = null;
172 XPropertySet aControl4 = null;
173 XPropertySet aControl5 = null;
175 try {
176 XGridColumnFactory columns = UnoRuntime.queryInterface(
177 XGridColumnFactory.class, oObj);
178 aControl = columns.createColumn("TextField");
179 aControl2 = columns.createColumn("DateField");
180 aControl3 = columns.createColumn("TextField");
181 aControl4 = columns.createColumn("TextField");
182 aControl5 = columns.createColumn("TextField");
183 } catch (com.sun.star.lang.IllegalArgumentException e) {
184 // Some exception occurs.FAILED
185 log.println("!!! Couldn't create instance : " + e);
186 throw new StatusException("Can't create column instances.", e);
189 XNameContainer aContainer = UnoRuntime.queryInterface(
190 XNameContainer.class, oObj);
192 try {
193 aContainer.insertByName("First", aControl);
194 aContainer.insertByName("Second", aControl2);
195 } catch (com.sun.star.lang.WrappedTargetException e) {
196 log.println("!!! Could't insert column Instance");
197 e.printStackTrace(log);
198 throw new StatusException("Can't insert columns", e);
199 } catch (com.sun.star.lang.IllegalArgumentException e) {
200 log.println("!!! Could't insert column Instance");
201 e.printStackTrace(log);
202 throw new StatusException("Can't insert columns", e);
203 } catch (com.sun.star.container.ElementExistException e) {
204 log.println("!!! Could't insert column Instance");
205 e.printStackTrace(log);
206 throw new StatusException("Can't insert columns", e);
209 //Relations for XSelectionSupplier
210 tEnv.addObjRelation("Selections", new Object[] { aControl, aControl2 });
212 // adding relation for XNameContainer
213 tEnv.addObjRelation("XNameContainer.AllowDuplicateNames", new Object());
216 // adding relation for XContainer
217 tEnv.addObjRelation("INSTANCE", aControl3);
218 tEnv.addObjRelation("INSTANCE1", aControl4);
219 tEnv.addObjRelation("INSTANCE2", aControl5);
222 tEnv.addObjRelation("Comparer",
223 new Comparator<Object>() {
224 public int compare(Object o1, Object o2) {
225 XNamed named1 = UnoRuntime.queryInterface(
226 XNamed.class, o1);
227 XNamed named2 = UnoRuntime.queryInterface(
228 XNamed.class, o2);
230 if (named1.getName().equals(named2.getName())) {
231 return 0;
234 return -1;
239 return tEnv;
242 } // finish class OButtonModelold
245 class OGridControlModelold extends TestCase {
246 XComponent xDrawDoc = null;
249 * Creates Drawing document.
251 @Override
252 protected void initialize(TestParameters tParam, PrintWriter log) {
253 SOfficeFactory SOF = SOfficeFactory.getFactory((tParam.getMSF()));
255 log.println("creating a draw document");
257 try {
258 xDrawDoc = SOF.createDrawDoc(null);
259 } catch (com.sun.star.uno.Exception e) {
260 throw new StatusException("Can't create Draw document", e);
265 * Disposes drawing document.
267 @Override
268 protected void cleanup(TestParameters tParam, PrintWriter log) {
269 log.println(" disposing xDrawDoc ");
271 try {
272 XCloseable closer = UnoRuntime.queryInterface(
273 XCloseable.class, xDrawDoc);
274 closer.close(true);
275 } catch (com.sun.star.util.CloseVetoException e) {
276 log.println("couldn't close document");
277 } catch (com.sun.star.lang.DisposedException e) {
278 log.println("couldn't close document");
283 * <code>GridControl</code> component created and added to the draw
284 * page. Then two columns are created and added to the grid.
285 * Object relations created :
286 * <ul>
287 * <li> <code>'INSTANCE1' ... 'INSTANCEN'</code> for
288 * <code>XNameReplace, XNameContainer, XIndexReplace,
289 * XIndexContainer </code> : objects to be inserted
290 * or replaced with in interface tests. Number of relations
291 * depends on number of interface test threads. For each
292 * thread there must be an individual element. </li>
293 * <li> <code>'XNameContainer.AllowDuplicateNames'</code> :
294 * if this relation exists then container elements can have duplicate
295 * names. <code>GridControl</code> can have.</li>
296 * <li> <code>'OBJNAME'</code> for
297 * {@link ifc.io._XPersistObject} : name of service which is
298 * represented by this object. </li>
299 * <li> <code>'INSTANCE'</code> for
300 * {@link ifc.container._XContainer} : a column instance. </li>
301 * </ul>
303 @Override
304 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param,
305 PrintWriter log) {
306 XInterface oObj = null;
307 XInterface oInstance = null;
308 XPropertySet aControl = null;
309 XPropertySet aControl2 = null;
310 XPropertySet aControl3 = null;
311 XPropertySet aControl4 = null;
312 XGridColumnFactory columns = null;
315 // creation of testobject here
316 // first we write what we are intend to do to log file
317 log.println("creating a test environment");
319 XControlShape shape = FormTools.insertControlShape(xDrawDoc, 5000,
320 7000, 2000, 2000,
321 "GridControl");
322 oObj = shape.getControl();
324 log.println("creating a new environment for drawpage object");
326 TestEnvironment tEnv = new TestEnvironment(oObj);
328 try {
329 columns = UnoRuntime.queryInterface(
330 XGridColumnFactory.class, oObj);
331 aControl = columns.createColumn("TextField");
332 aControl2 = columns.createColumn("DateField");
333 aControl3 = columns.createColumn("TextField");
334 aControl4 = columns.createColumn("TextField");
335 columns.createColumn("TextField");
336 } catch (com.sun.star.lang.IllegalArgumentException e) {
337 // Some exception occurs.FAILED
338 log.println("!!! Couldn't create instance : " + e);
339 throw new StatusException("Can't create column instances.", e);
342 XNameContainer aContainer = UnoRuntime.queryInterface(
343 XNameContainer.class, oObj);
345 try {
346 aContainer.insertByName("First", aControl);
347 aContainer.insertByName("Second", aControl2);
348 } catch (com.sun.star.lang.WrappedTargetException e) {
349 log.println("!!! Could't insert column Instance");
350 e.printStackTrace(log);
351 throw new StatusException("Can't insert columns", e);
352 } catch (com.sun.star.lang.IllegalArgumentException e) {
353 log.println("!!! Could't insert column Instance");
354 e.printStackTrace(log);
355 throw new StatusException("Can't insert columns", e);
356 } catch (com.sun.star.container.ElementExistException e) {
357 log.println("!!! Could't insert column Instance");
358 e.printStackTrace(log);
359 throw new StatusException("Can't insert columns", e);
362 //Relations for XSelectionSupplier
363 tEnv.addObjRelation("Selections", new Object[] { aControl, aControl2 });
365 // COMPARER
367 int THRCNT = 1;
368 String count = (String)Param.get("THRCNT");
369 if (count != null)
370 THRCNT = Integer.parseInt(count);
373 // INSTANCEn : _XNameContainer; _XNameReplace
374 log.println("adding INSTANCEn as obj relation to environment");
376 try {
377 for (int n = 1; n < (3 * THRCNT + 1); n++) {
378 log.println("adding INSTANCE" + n +
379 " as obj relation to environment");
380 oInstance = columns.createColumn("TextField");
381 tEnv.addObjRelation("INSTANCE" + n, oInstance);
383 } catch (com.sun.star.lang.IllegalArgumentException e) {
384 e.printStackTrace(log);
385 throw new StatusException("Can't create 'INSTANCEn' relations", e);
389 // adding relation for XNameContainer
390 tEnv.addObjRelation("XNameContainer.AllowDuplicateNames", new Object());
392 // adding relation for XContainer
393 tEnv.addObjRelation("INSTANCE", aControl3);
394 tEnv.addObjRelation("INSTANCE2", aControl4);
397 return tEnv;
398 } // finish method getTestEnvironment
399 } // finish class OGridControlModel