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 .
20 import java
.io
.PrintWriter
;
23 import lib
.StatusException
;
25 import lib
.TestEnvironment
;
26 import lib
.TestParameters
;
27 import util
.DrawTools
;
28 import util
.SOfficeFactory
;
30 import com
.sun
.star
.awt
.Point
;
31 import com
.sun
.star
.awt
.Size
;
32 import com
.sun
.star
.awt
.XControlModel
;
33 import com
.sun
.star
.beans
.PropertyValue
;
34 import com
.sun
.star
.drawing
.XControlShape
;
35 import com
.sun
.star
.lang
.XComponent
;
36 import com
.sun
.star
.lang
.XMultiServiceFactory
;
37 import com
.sun
.star
.uno
.UnoRuntime
;
38 import com
.sun
.star
.uno
.XInterface
;
39 import com
.sun
.star
.util
.XCloseable
;
43 * Test for object which is represented by service
44 * <code>com.sun.star.form.component.FileControl</code>. <p>
45 * Object implements the following interfaces :
47 * <li> <code>com::sun::star::io::XPersistObject</code></li>
48 * <li> <code>com::sun::star::container::XChild</code></li>
49 * <li> <code>com::sun::star::form::FormControlModel</code></li>
50 * <li> <code>com::sun::star::awt::UnoControlFileControlModel</code></li>
51 * <li> <code>com::sun::star::form::FormComponent</code></li>
52 * <li> <code>com::sun::star::beans::XPropertyAccess</code></li>
53 * <li> <code>com::sun::star::beans::XPropertyContainer</code></li>
54 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
55 * <li> <code>com::sun::star::beans::XFastPropertySet</code></li>
56 * <li> <code>com::sun::star::beans::XPropertyState</code></li>
57 * <li> <code>com::sun::star::container::XNamed</code></li>
58 * <li> <code>com::sun::star::beans::XMultiPropertySet</code></li>
59 * <li> <code>com::sun::star::lang::XComponent</code></li>
60 * <li> <code>com::sun::star::form::component::FileControl</code></li>
62 * This object test <b> is NOT </b> designed to be run in several
63 * threads concurently.
64 * @see com.sun.star.io.XPersistObject
65 * @see com.sun.star.container.XChild
66 * @see com.sun.star.form
67 * @see com.sun.star.awt.UnoControlFileControlModel
68 * @see com.sun.star.form.FormComponent
69 * @see com.sun.star.beans.XPropertyAccess
70 * @see com.sun.star.beans.XPropertyContainer
71 * @see com.sun.star.beans.XPropertySet
72 * @see com.sun.star.beans.XFastPropertySet
73 * @see com.sun.star.beans.XPropertyState
74 * @see com.sun.star.container.XNamed
75 * @see com.sun.star.beans.XMultiPropertySet
76 * @see com.sun.star.lang.XComponent
77 * @see com.sun.star.form.component.FileControl
78 * @see ifc.io._XPersistObject
79 * @see ifc.container._XChild
80 * @see ifc.form._FormControlModel
81 * @see ifc.awt._UnoControlFileControlModel
82 * @see ifc.form._FormComponent
83 * @see ifc.beans._XPropertySet
84 * @see ifc.beans._XFastPropertySet
85 * @see ifc.beans._XPropertyState
86 * @see ifc.container._XNamed
87 * @see ifc.beans._XMultiPropertySet
88 * @see ifc.lang._XComponent
89 * @see ifc.form.component._FileControl
91 public class OFileControlModel
extends TestCase
{
95 * Creates Draw document where controls are placed.
97 protected void initialize(TestParameters tParam
, PrintWriter log
) {
98 SOfficeFactory SOF
= SOfficeFactory
.getFactory(((XMultiServiceFactory
) tParam
.getMSF()));
101 log
.println("creating a draw document");
102 xDrawDoc
= SOF
.createDrawDoc(null);
103 } catch (com
.sun
.star
.uno
.Exception e
) {
104 log
.println("Can't create a document :");
105 e
.printStackTrace(log
);
106 throw new StatusException(Status
.failed("Can't create a document"));
111 * Disposes Draw document.
113 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
114 log
.println(" disposing xDrawDoc ");
117 XCloseable closer
= UnoRuntime
.queryInterface(
118 XCloseable
.class, xDrawDoc
);
120 } catch (com
.sun
.star
.util
.CloseVetoException e
) {
121 log
.println("couldn't close document");
122 } catch (com
.sun
.star
.lang
.DisposedException e
) {
123 log
.println("couldn't close document");
128 * Creating a Testenvironment for the interfaces to be tested.
129 * Creates FileControl in the Form. <p>
130 * Object relations created :
132 * <li> <code>'OBJNAME'</code> for
133 * {@link ifc.io._XPersistObject} : name of service which is
134 * represented by this object. </li>
137 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
,
139 XInterface oObj
= null;
142 // creation of testobject here
143 // first we write what we are intend to do to log file
144 log
.println("creating a test environment");
146 //get FileControlModel
147 String objName
= "FileControl";
149 XControlShape aShape
= null;
151 Size size
= new Size();
152 Point position
= new Point();
153 XControlModel aControl
= null;
156 XMultiServiceFactory oDocMSF
= UnoRuntime
.queryInterface(
157 XMultiServiceFactory
.class,
161 Object oInt
= oDocMSF
.createInstance(
162 "com.sun.star.drawing.ControlShape");
163 Object aCon
= oDocMSF
.createInstance(
164 "com.sun.star.form.component." + objName
);
165 aControl
= UnoRuntime
.queryInterface(
166 XControlModel
.class, aCon
);
167 aShape
= UnoRuntime
.queryInterface(
168 XControlShape
.class, oInt
);
173 aShape
.setSize(size
);
174 aShape
.setPosition(position
);
175 } catch (com
.sun
.star
.uno
.Exception e
) {
176 // Some exception occurs.FAILED
177 log
.println("Couldn't create a component " + e
);
178 throw new StatusException(Status
.failed("Can't create component"));
181 aShape
.setControl(aControl
);
183 DrawTools
.getDrawPage(xDrawDoc
, 0).add(aShape
);
184 oObj
= aShape
.getControl();
186 log
.println("creating a new environment for drawpage object");
188 TestEnvironment tEnv
= new TestEnvironment(oObj
);
190 tEnv
.addObjRelation("OBJNAME", "stardiv.one.form.component." +
192 PropertyValue prop
= new PropertyValue();
193 prop
.Name
= "HelpText";
194 prop
.Value
= "new Help Text since XPropertyAccess";
195 tEnv
.addObjRelation("XPropertyAccess.propertyToChange", prop
);
196 tEnv
.addObjRelation("XPropertyContainer.propertyNotRemovable", "HelpText");
199 } // finish method getTestEnvironment
200 } // finish class OFileControlModel