bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _forms / OFileControlModel.java
blobb44bbbb8a29ad5e4a4c0f8a2c85bf843b455e55e
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;
22 import lib.Status;
23 import lib.StatusException;
24 import lib.TestCase;
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;
42 /**
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 :
46 * <ul>
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>
61 * </ul>
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 {
92 XComponent xDrawDoc;
94 /**
95 * Creates Draw document where controls are placed.
97 @Override
98 protected void initialize(TestParameters tParam, PrintWriter log) {
99 SOfficeFactory SOF = SOfficeFactory.getFactory((tParam.getMSF()));
101 try {
102 log.println("creating a draw document");
103 xDrawDoc = SOF.createDrawDoc(null);
104 } catch (com.sun.star.uno.Exception e) {
105 throw new StatusException(e, Status.failed("Can't create a document"));
110 * Disposes Draw document.
112 @Override
113 protected void cleanup(TestParameters tParam, PrintWriter log) {
114 log.println(" disposing xDrawDoc ");
116 try {
117 XCloseable closer = UnoRuntime.queryInterface(
118 XCloseable.class, xDrawDoc);
119 closer.close(true);
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 :
131 * <ul>
132 * <li> <code>'OBJNAME'</code> for
133 * {@link ifc.io._XPersistObject} : name of service which is
134 * represented by this object. </li>
135 * </ul>
137 @Override
138 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param,
139 PrintWriter log) {
140 XInterface oObj = null;
143 // creation of testobject here
144 // first we write what we are intend to do to log file
145 log.println("creating a test environment");
147 //get FileControlModel
148 String objName = "FileControl";
150 XControlShape aShape = null;
152 Size size = new Size();
153 Point position = new Point();
154 XControlModel aControl = null;
156 //get MSF
157 XMultiServiceFactory oDocMSF = UnoRuntime.queryInterface(
158 XMultiServiceFactory.class,
159 xDrawDoc);
161 try {
162 Object oInt = oDocMSF.createInstance(
163 "com.sun.star.drawing.ControlShape");
164 Object aCon = oDocMSF.createInstance(
165 "com.sun.star.form.component." + objName);
166 aControl = UnoRuntime.queryInterface(
167 XControlModel.class, aCon);
168 aShape = UnoRuntime.queryInterface(
169 XControlShape.class, oInt);
170 size.Height = 1500;
171 size.Width = 3000;
172 position.X = 1000;
173 position.Y = 1000;
174 aShape.setSize(size);
175 aShape.setPosition(position);
176 } catch (com.sun.star.uno.Exception e) {
177 throw new StatusException(e, Status.failed("Can't create component"));
180 aShape.setControl(aControl);
182 DrawTools.getDrawPage(xDrawDoc, 0).add(aShape);
183 oObj = aShape.getControl();
185 log.println("creating a new environment for drawpage object");
187 TestEnvironment tEnv = new TestEnvironment(oObj);
189 tEnv.addObjRelation("OBJNAME", "stardiv.one.form.component." +
190 objName);
191 PropertyValue prop = new PropertyValue();
192 prop.Name = "HelpText";
193 prop.Value = "new Help Text since XPropertyAccess";
194 tEnv.addObjRelation("XPropertyAccess.propertyToChange", prop);
195 tEnv.addObjRelation("XPropertyContainer.propertyNotRemovable", "HelpText");
197 return tEnv;
198 } // finish method getTestEnvironment
199 } // finish class OFileControlModel