xref: /AOO41X/main/qadevOOo/tests/java/mod/_forms/OFileControlModel.java (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
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.Status;
32 import lib.StatusException;
33 import lib.TestCase;
34 import lib.TestEnvironment;
35 import lib.TestParameters;
36 import util.DrawTools;
37 import util.SOfficeFactory;
38 
39 import com.sun.star.awt.Point;
40 import com.sun.star.awt.Size;
41 import com.sun.star.awt.XControlModel;
42 import com.sun.star.beans.PropertyValue;
43 import com.sun.star.drawing.XControlShape;
44 import com.sun.star.drawing.XShape;
45 import com.sun.star.lang.XComponent;
46 import com.sun.star.lang.XMultiServiceFactory;
47 import com.sun.star.uno.UnoRuntime;
48 import com.sun.star.uno.XInterface;
49 import com.sun.star.util.XCloseable;
50 
51 
52 /**
53  * Test for object which is represented by service
54  * <code>com.sun.star.form.component.FileControl</code>. <p>
55  * Object implements the following interfaces :
56  * <ul>
57  *  <li> <code>com::sun::star::io::XPersistObject</code></li>
58  *  <li> <code>com::sun::star::container::XChild</code></li>
59  *  <li> <code>com::sun::star::form::FormControlModel</code></li>
60  *  <li> <code>com::sun::star::awt::UnoControlFileControlModel</code></li>
61  *  <li> <code>com::sun::star::form::FormComponent</code></li>
62  *  <li> <code>com::sun::star::beans::XPropertyAccess</code></li>
63 *  <li> <code>com::sun::star::beans::XPropertyContainer</code></li>
64 *  <li> <code>com::sun::star::beans::XPropertySet</code></li>
65  *  <li> <code>com::sun::star::beans::XFastPropertySet</code></li>
66  *  <li> <code>com::sun::star::beans::XPropertyState</code></li>
67  *  <li> <code>com::sun::star::container::XNamed</code></li>
68  *  <li> <code>com::sun::star::beans::XMultiPropertySet</code></li>
69  *  <li> <code>com::sun::star::lang::XComponent</code></li>
70  *  <li> <code>com::sun::star::form::component::FileControl</code></li>
71  * </ul>
72  * This object test <b> is NOT </b> designed to be run in several
73  * threads concurently.
74  * @see com.sun.star.io.XPersistObject
75  * @see com.sun.star.container.XChild
76  * @see com.sun.star.form.FormControlModel
77  * @see com.sun.star.awt.UnoControlFileControlModel
78  * @see com.sun.star.form.FormComponent
79  * @see com.sun.star.beans.XPropertyAccess
80 * @see com.sun.star.beans.XPropertyContainer
81 * @see com.sun.star.beans.XPropertySet
82  * @see com.sun.star.beans.XFastPropertySet
83  * @see com.sun.star.beans.XPropertyState
84  * @see com.sun.star.container.XNamed
85  * @see com.sun.star.beans.XMultiPropertySet
86  * @see com.sun.star.lang.XComponent
87  * @see com.sun.star.form.component.FileControl
88  * @see ifc.io._XPersistObject
89  * @see ifc.container._XChild
90  * @see ifc.form._FormControlModel
91  * @see ifc.awt._UnoControlFileControlModel
92  * @see ifc.form._FormComponent
93  * @see ifc.beans._XPropertySet
94  * @see ifc.beans._XFastPropertySet
95  * @see ifc.beans._XPropertyState
96  * @see ifc.container._XNamed
97  * @see ifc.beans._XMultiPropertySet
98  * @see ifc.lang._XComponent
99  * @see ifc.form.component._FileControl
100  */
101 public class OFileControlModel extends TestCase {
102     XComponent xDrawDoc;
103 
104     /**
105      * Creates Draw document where controls are placed.
106      */
107     protected void initialize(TestParameters tParam, PrintWriter log) {
108         SOfficeFactory SOF = SOfficeFactory.getFactory(((XMultiServiceFactory) tParam.getMSF()));
109 
110         try {
111             log.println("creating a draw document");
112             xDrawDoc = SOF.createDrawDoc(null);
113         } catch (com.sun.star.uno.Exception e) {
114             log.println("Can't create a document :");
115             e.printStackTrace(log);
116             throw new StatusException(Status.failed("Can't create a document"));
117         }
118     }
119 
120     /**
121      * Disposes Draw document.
122      */
123     protected void cleanup(TestParameters tParam, PrintWriter log) {
124         log.println("    disposing xDrawDoc ");
125 
126         try {
127             XCloseable closer = (XCloseable) UnoRuntime.queryInterface(
128                 XCloseable.class, xDrawDoc);
129             closer.close(true);
130         } catch (com.sun.star.util.CloseVetoException e) {
131             log.println("couldn't close document");
132         } catch (com.sun.star.lang.DisposedException e) {
133             log.println("couldn't close document");
134         }
135     }
136 
137     /**
138      * Creating a Testenvironment for the interfaces to be tested.
139      * Creates FileControl in the Form. <p>
140      *     Object relations created :
141      * <ul>
142      *  <li> <code>'OBJNAME'</code> for
143      *      {@link ifc.io._XPersistObject} : name of service which is
144      *    represented by this object. </li>
145      * </ul>
146      */
147     protected synchronized TestEnvironment createTestEnvironment(TestParameters Param,
148         PrintWriter log) {
149         XInterface oObj = null;
150 
151 
152         // creation of testobject here
153         // first we write what we are intend to do to log file
154         log.println("creating a test environment");
155 
156         //get FileControlModel
157         String objName = "FileControl";
158 
159         XControlShape aShape = null;
160 
161         Size size = new Size();
162         Point position = new Point();
163         XControlModel aControl = null;
164 
165         //get MSF
166         XMultiServiceFactory oDocMSF = (XMultiServiceFactory) UnoRuntime.queryInterface(
167             XMultiServiceFactory.class,
168             xDrawDoc);
169 
170         try {
171             Object oInt = oDocMSF.createInstance(
172                 "com.sun.star.drawing.ControlShape");
173             Object aCon = oDocMSF.createInstance(
174                 "com.sun.star.form.component." + objName);
175             aControl = (XControlModel) UnoRuntime.queryInterface(
176                 XControlModel.class, aCon);
177             aShape = (XControlShape) UnoRuntime.queryInterface(
178                 XControlShape.class, oInt);
179             size.Height = 1500;
180             size.Width = 3000;
181             position.X = 1000;
182             position.Y = 1000;
183             aShape.setSize(size);
184             aShape.setPosition(position);
185         } catch (com.sun.star.uno.Exception e) {
186             // Some exception occures.FAILED
187             log.println("Couldn't create a component " + e);
188             throw new StatusException(Status.failed("Can't create component"));
189         }
190 
191         aShape.setControl(aControl);
192 
193         DrawTools.getDrawPage(xDrawDoc, 0).add((XShape) aShape);
194         oObj = aShape.getControl();
195 
196         log.println("creating a new environment for drawpage object");
197 
198         TestEnvironment tEnv = new TestEnvironment(oObj);
199 
200         tEnv.addObjRelation("OBJNAME", "stardiv.one.form.component." +
201             objName);
202         PropertyValue prop = new PropertyValue();
203         prop.Name = "HelpText";
204         prop.Value = "new Help Text since XPropertyAccess";
205         tEnv.addObjRelation("XPropertyAccess.propertyToChange", prop);
206         tEnv.addObjRelation("XPropertyContainer.propertyNotRemovable", "HelpText");
207 
208         return tEnv;
209     } // finish method getTestEnvironment
210 } // finish class OFileControlModel
211