xref: /AOO41X/main/qadevOOo/tests/java/mod/_forms/OFormsCollection.java (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 package mod._forms;
28 
29 import java.io.PrintWriter;
30 
31 import lib.TestCase;
32 import lib.TestEnvironment;
33 import lib.TestParameters;
34 import util.DrawTools;
35 import util.FormTools;
36 
37 import com.sun.star.container.XNameContainer;
38 import com.sun.star.drawing.XDrawPage;
39 import com.sun.star.lang.XComponent;
40 import com.sun.star.lang.XMultiServiceFactory;
41 import com.sun.star.uno.UnoRuntime;
42 import com.sun.star.uno.XInterface;
43 import com.sun.star.util.XCloseable;
44 
45 
46 /**
47 * Test for object which is represented by service
48 * <code>com.sun.star.form.Forms</code>. <p>
49 * Object implements the following interfaces :
50 * <ul>
51 *  <li> <code>com::sun::star::container::XNameReplace</code></li>
52 *  <li> <code>com::sun::star::container::XIndexReplace</code></li>
53 *  <li> <code>com::sun::star::container::XNameContainer</code></li>
54 *  <li> <code>com::sun::star::container::XIndexAccess</code></li>
55 *  <li> <code>com::sun::star::container::XElementAccess</code></li>
56 *  <li> <code>com::sun::star::container::XEnumerationAccess</code></li>
57 *  <li> <code>com::sun::star::container::XIndexContainer</code></li>
58 *  <li> <code>com::sun::star::container::XNameAccess</code></li>
59 * </ul>
60 *
61 * This object test <b> is NOT </b> designed to be run in several
62 * threads concurently.
63 *
64 * @see com.sun.star.container.XNameReplace
65 * @see com.sun.star.container.XIndexReplace
66 * @see com.sun.star.container.XNameContainer
67 * @see com.sun.star.container.XIndexAccess
68 * @see com.sun.star.container.XElementAccess
69 * @see com.sun.star.container.XEnumerationAccess
70 * @see com.sun.star.container.XIndexContainer
71 * @see com.sun.star.container.XNameAccess
72 * @see ifc.container._XNameReplace
73 * @see ifc.container._XIndexReplace
74 * @see ifc.container._XNameContainer
75 * @see ifc.container._XIndexAccess
76 * @see ifc.container._XElementAccess
77 * @see ifc.container._XEnumerationAccess
78 * @see ifc.container._XIndexContainer
79 * @see ifc.container._XNameAccess
80 */
81 public class OFormsCollection extends TestCase {
82     XComponent xDrawDoc;
83 
84     /**
85     * Creates Drawing document.
86     */
87     protected void initialize(TestParameters tParam, PrintWriter log) {
88         log.println("creating a draw document");
89         xDrawDoc = DrawTools.createDrawDoc(((XMultiServiceFactory) tParam.getMSF()));
90     }
91 
92     /**
93     * Disposes drawing document.
94     */
95     protected void cleanup(TestParameters tParam, PrintWriter log) {
96         log.println("    disposing xDrawDoc ");
97 
98         try {
99             XCloseable closer = (XCloseable) UnoRuntime.queryInterface(
100                                         XCloseable.class, xDrawDoc);
101             closer.close(true);
102         } catch (com.sun.star.util.CloseVetoException e) {
103             log.println("couldn't close document");
104         } catch (com.sun.star.lang.DisposedException e) {
105             log.println("couldn't close document");
106         }
107     }
108 
109     /**
110     * Adds some controls to the 'Standard' form of a draw page,
111     * then adds an empty form to a collection of forms. Then
112     * returns the collection as a test object. <p>
113     *     Object relations created :
114     * <ul>
115     *  <li> <code>'INSTANCE1' ... 'INSTANCEN'</code> for
116     *    <code>XNameReplace, XNameContainer, XIndexReplace,
117     *     XIndexContainer </code> : objects to be inserted
118     *     or replaced with in interface tests. Number of relations
119     *     depends on number of interface test threads. For each
120     *     thread there must be an individual element. </li>
121     *  <li> <code>'XNameContainer.AllowDuplicateNames'</code> :
122     *   if this relation exists then container elements can have duplicate
123     *   names. In case of forms' collection forms can have equal names.</li>
124     * </ul>
125     */
126     protected synchronized TestEnvironment createTestEnvironment(TestParameters Param,
127                                                                  PrintWriter log) {
128         XInterface oObj = null;
129         XDrawPage oDP = null;
130 
131 
132         // creation of testobject here
133         // first we write what we are intend to do to log file
134         log.println("creating a test environment");
135 
136         oDP = DrawTools.getDrawPage(xDrawDoc, 0);
137 
138         (DrawTools.getShapes(oDP))
139             .add(FormTools.createControlShape(xDrawDoc, 2000, 1500, 1000, 1000,
140                                               "CheckBox"));
141         (DrawTools.getShapes(oDP))
142             .add(FormTools.createControlShape(xDrawDoc, 3000, 4500, 15000,
143                                               1000, "CommandButton"));
144         (DrawTools.getShapes(oDP))
145             .add(FormTools.createControlShape(xDrawDoc, 5000, 3500, 7500, 5000,
146                                               "TextField"));
147 
148         oObj = FormTools.getForms(oDP);
149         FormTools.insertForm(xDrawDoc, (XNameContainer) oObj, "SecondForm");
150 
151         log.println("creating a new environment for drawpage object");
152 
153         TestEnvironment tEnv = new TestEnvironment(oObj);
154 
155 
156         // INSTANCEn : _XNameContainer; _XNameReplace
157         log.println("adding INSTANCEn as obj relation to environment");
158 
159         XComponent xComp = (XComponent) UnoRuntime.queryInterface(
160                                    XComponent.class, xDrawDoc);
161         int THRCNT = 1;
162         if (Param.get("THRCNT")!= null) {
163             THRCNT = Integer.parseInt((String) Param.get("THRCNT"));
164         }
165 
166         for (int n = 1; n < (THRCNT + 1); n++) {
167             log.println("adding INSTANCE" + n +
168                         " as obj relation to environment");
169             tEnv.addObjRelation("INSTANCE" + n,
170                                 FormTools.createControl(xComp, "Form"));
171         }
172 
173 
174         // adding indicator that this collection can have duplicate
175         // elements with the same names for XNameContainer test.
176         tEnv.addObjRelation("XNameContainer.AllowDuplicateNames", new Object());
177 
178         tEnv.addObjRelation("INSTANCE", FormTools.createControl(xComp, "Form"));
179         tEnv.addObjRelation("INSTANCE2",
180                             FormTools.createControl(xComp, "Form"));
181 
182         return tEnv;
183     } // finish method getTestEnvironment
184 } // finish class OFormsCollection
185