1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: OFileControlModel.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 import java
.io
.PrintWriter
;
35 import lib
.StatusException
;
37 import lib
.TestEnvironment
;
38 import lib
.TestParameters
;
39 import util
.DrawTools
;
40 import util
.SOfficeFactory
;
42 import com
.sun
.star
.awt
.Point
;
43 import com
.sun
.star
.awt
.Size
;
44 import com
.sun
.star
.awt
.XControlModel
;
45 import com
.sun
.star
.beans
.PropertyValue
;
46 import com
.sun
.star
.drawing
.XControlShape
;
47 import com
.sun
.star
.drawing
.XShape
;
48 import com
.sun
.star
.lang
.XComponent
;
49 import com
.sun
.star
.lang
.XMultiServiceFactory
;
50 import com
.sun
.star
.uno
.UnoRuntime
;
51 import com
.sun
.star
.uno
.XInterface
;
52 import com
.sun
.star
.util
.XCloseable
;
56 * Test for object which is represented by service
57 * <code>com.sun.star.form.component.FileControl</code>. <p>
58 * Object implements the following interfaces :
60 * <li> <code>com::sun::star::io::XPersistObject</code></li>
61 * <li> <code>com::sun::star::container::XChild</code></li>
62 * <li> <code>com::sun::star::form::FormControlModel</code></li>
63 * <li> <code>com::sun::star::awt::UnoControlFileControlModel</code></li>
64 * <li> <code>com::sun::star::form::FormComponent</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::beans::XFastPropertySet</code></li>
69 * <li> <code>com::sun::star::beans::XPropertyState</code></li>
70 * <li> <code>com::sun::star::container::XNamed</code></li>
71 * <li> <code>com::sun::star::beans::XMultiPropertySet</code></li>
72 * <li> <code>com::sun::star::lang::XComponent</code></li>
73 * <li> <code>com::sun::star::form::component::FileControl</code></li>
75 * This object test <b> is NOT </b> designed to be run in several
76 * threads concurently.
77 * @see com.sun.star.io.XPersistObject
78 * @see com.sun.star.container.XChild
79 * @see com.sun.star.form.FormControlModel
80 * @see com.sun.star.awt.UnoControlFileControlModel
81 * @see com.sun.star.form.FormComponent
82 * @see com.sun.star.beans.XPropertyAccess
83 * @see com.sun.star.beans.XPropertyContainer
84 * @see com.sun.star.beans.XPropertySet
85 * @see com.sun.star.beans.XFastPropertySet
86 * @see com.sun.star.beans.XPropertyState
87 * @see com.sun.star.container.XNamed
88 * @see com.sun.star.beans.XMultiPropertySet
89 * @see com.sun.star.lang.XComponent
90 * @see com.sun.star.form.component.FileControl
91 * @see ifc.io._XPersistObject
92 * @see ifc.container._XChild
93 * @see ifc.form._FormControlModel
94 * @see ifc.awt._UnoControlFileControlModel
95 * @see ifc.form._FormComponent
96 * @see ifc.beans._XPropertySet
97 * @see ifc.beans._XFastPropertySet
98 * @see ifc.beans._XPropertyState
99 * @see ifc.container._XNamed
100 * @see ifc.beans._XMultiPropertySet
101 * @see ifc.lang._XComponent
102 * @see ifc.form.component._FileControl
104 public class OFileControlModel
extends TestCase
{
108 * Creates Draw document where controls are placed.
110 protected void initialize(TestParameters tParam
, PrintWriter log
) {
111 SOfficeFactory SOF
= SOfficeFactory
.getFactory(((XMultiServiceFactory
) tParam
.getMSF()));
114 log
.println("creating a draw document");
115 xDrawDoc
= SOF
.createDrawDoc(null);
116 } catch (com
.sun
.star
.uno
.Exception e
) {
117 log
.println("Can't create a document :");
118 e
.printStackTrace(log
);
119 throw new StatusException(Status
.failed("Can't create a document"));
124 * Disposes Draw document.
126 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
127 log
.println(" disposing xDrawDoc ");
130 XCloseable closer
= (XCloseable
) UnoRuntime
.queryInterface(
131 XCloseable
.class, xDrawDoc
);
133 } catch (com
.sun
.star
.util
.CloseVetoException e
) {
134 log
.println("couldn't close document");
135 } catch (com
.sun
.star
.lang
.DisposedException e
) {
136 log
.println("couldn't close document");
141 * Creating a Testenvironment for the interfaces to be tested.
142 * Creates FileControl in the Form. <p>
143 * Object relations created :
145 * <li> <code>'OBJNAME'</code> for
146 * {@link ifc.io._XPersistObject} : name of service which is
147 * represented by this object. </li>
150 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
,
152 XInterface oObj
= null;
155 // creation of testobject here
156 // first we write what we are intend to do to log file
157 log
.println("creating a test environment");
159 //get FileControlModel
160 String objName
= "FileControl";
162 XControlShape aShape
= null;
164 Size size
= new Size();
165 Point position
= new Point();
166 XControlModel aControl
= null;
169 XMultiServiceFactory oDocMSF
= (XMultiServiceFactory
) UnoRuntime
.queryInterface(
170 XMultiServiceFactory
.class,
174 Object oInt
= oDocMSF
.createInstance(
175 "com.sun.star.drawing.ControlShape");
176 Object aCon
= oDocMSF
.createInstance(
177 "com.sun.star.form.component." + objName
);
178 aControl
= (XControlModel
) UnoRuntime
.queryInterface(
179 XControlModel
.class, aCon
);
180 aShape
= (XControlShape
) UnoRuntime
.queryInterface(
181 XControlShape
.class, oInt
);
186 aShape
.setSize(size
);
187 aShape
.setPosition(position
);
188 } catch (com
.sun
.star
.uno
.Exception e
) {
189 // Some exception occures.FAILED
190 log
.println("Couldn't create a component " + e
);
191 throw new StatusException(Status
.failed("Can't create component"));
194 aShape
.setControl(aControl
);
196 DrawTools
.getDrawPage(xDrawDoc
, 0).add((XShape
) aShape
);
197 oObj
= aShape
.getControl();
199 log
.println("creating a new environment for drawpage object");
201 TestEnvironment tEnv
= new TestEnvironment(oObj
);
203 tEnv
.addObjRelation("OBJNAME", "stardiv.one.form.component." +
205 PropertyValue prop
= new PropertyValue();
206 prop
.Name
= "HelpText";
207 prop
.Value
= "new Help Text since XPropertyAccess";
208 tEnv
.addObjRelation("XPropertyAccess.propertyToChange", prop
);
209 tEnv
.addObjRelation("XPropertyContainer.propertyNotRemovable", "HelpText");
212 } // finish method getTestEnvironment
213 } // finish class OFileControlModel