xref: /AOO41X/main/qadevOOo/tests/java/mod/_forms/OHiddenModel.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 com.sun.star.beans.PropertyValue;
30 import java.io.PrintWriter;
31 
32 import lib.StatusException;
33 import lib.TestCase;
34 import lib.TestEnvironment;
35 import lib.TestParameters;
36 import util.DrawTools;
37 import util.FormTools;
38 import util.SOfficeFactory;
39 
40 import com.sun.star.container.XNameContainer;
41 import com.sun.star.drawing.XDrawPage;
42 import com.sun.star.lang.XComponent;
43 import com.sun.star.lang.XMultiServiceFactory;
44 import com.sun.star.uno.AnyConverter;
45 import com.sun.star.uno.Type;
46 import com.sun.star.uno.UnoRuntime;
47 import com.sun.star.uno.XInterface;
48 import com.sun.star.util.XCloseable;
49 
50 
51 /**
52  * Test for object which is represented by service
53  * <code>com.sun.star.form.component.HiddenControl</code>. <p>
54  * Object implements the following interfaces :
55  * <ul>
56  *  <li> <code>com::sun::star::io::XPersistObject</code></li>
57  *  <li> <code>com::sun::star::container::XChild</code></li>
58  *  <li> <code>com::sun::star::form::FormControlModel</code></li>
59  *  <li> <code>com::sun::star::form::component::HiddenControl</code></li>
60  *  <li> <code>com::sun::star::form::FormComponent</code></li>
61  *  <li> <code>com::sun::star::beans::XPropertyAccess</code></li>
62 *  <li> <code>com::sun::star::beans::XPropertyContainer</code></li>
63 *  <li> <code>com::sun::star::beans::XPropertySet</code></li>
64  *  <li> <code>com::sun::star::beans::XFastPropertySet</code></li>
65  *  <li> <code>com::sun::star::beans::XPropertyState</code></li>
66  *  <li> <code>com::sun::star::container::XNamed</code></li>
67  *  <li> <code>com::sun::star::beans::XMultiPropertySet</code></li>
68  *  <li> <code>com::sun::star::lang::XComponent</code></li>
69  * </ul> <p>
70  * This object test <b> is NOT </b> designed to be run in several
71  * threads concurently.
72  * @see com.sun.star.io.XPersistObject
73  * @see com.sun.star.container.XChild
74  * @see com.sun.star.form.FormControlModel
75  * @see com.sun.star.form.component.HiddenControl
76  * @see com.sun.star.form.FormComponent
77  * @see com.sun.star.beans.XPropertyAccess
78 * @see com.sun.star.beans.XPropertyContainer
79 * @see com.sun.star.beans.XPropertySet
80  * @see com.sun.star.beans.XFastPropertySet
81  * @see com.sun.star.beans.XPropertyState
82  * @see com.sun.star.container.XNamed
83  * @see com.sun.star.beans.XMultiPropertySet
84  * @see com.sun.star.lang.XComponent
85  * @see ifc.io._XPersistObject
86  * @see ifc.container._XChild
87  * @see ifc.form._FormControlModel
88  * @see ifc.form.component._HiddenControl
89  * @see ifc.form._FormComponent
90  * @see ifc.beans._XPropertySet
91  * @see ifc.beans._XFastPropertySet
92  * @see ifc.beans._XPropertyState
93  * @see ifc.container._XNamed
94  * @see ifc.beans._XMultiPropertySet
95  * @see ifc.lang._XComponent
96  */
97 public class OHiddenModel extends TestCase {
98     XComponent xDrawDoc;
99 
100     /**
101      * Creates Drawing document.
102      */
103     protected void initialize(TestParameters tParam, PrintWriter log) {
104         SOfficeFactory SOF = SOfficeFactory.getFactory(((XMultiServiceFactory) tParam.getMSF()));
105 
106         try {
107             log.println("creating a draw document");
108             xDrawDoc = SOF.createDrawDoc(null);
109         } catch (com.sun.star.uno.Exception e) {
110             // Some exception occures.FAILED
111             e.printStackTrace(log);
112             throw new StatusException("Couldn't create document", e);
113         }
114     }
115 
116     /**
117      * Disposes drawing document.
118      */
119     protected void cleanup(TestParameters tParam, PrintWriter log) {
120         log.println("    disposing xDrawDoc ");
121 
122         try {
123             XCloseable closer = (XCloseable) UnoRuntime.queryInterface(
124                     XCloseable.class, xDrawDoc);
125             closer.close(true);
126         } catch (com.sun.star.util.CloseVetoException e) {
127             log.println("couldn't close document");
128         } catch (com.sun.star.lang.DisposedException e) {
129             log.println("couldn't close document");
130         }
131     }
132 
133     /**
134      * Creates hidden component, then adds Form into draw page,
135      * and inserts the component into Form components' collection.
136      *     Object relations created :
137      * <ul>
138      *  <li> <code>'OBJNAME'</code> for
139      *      {@link ifc.io._XPersistObject} : name of service which is
140      *    represented by this object. </li>
141      * </ul>
142      */
143     protected synchronized TestEnvironment createTestEnvironment(TestParameters Param,
144             PrintWriter log) {
145         XInterface oObj = null;
146 
147 
148         // creation of testobject here
149         // first we write what we are intend to do to log file
150         log.println("creating a test environment");
151 
152         // get a soffice factory object
153         SOfficeFactory SOF = SOfficeFactory.getFactory(((XMultiServiceFactory) Param.getMSF()));
154         String objName = "HiddenControl";
155         XInterface ctrl = SOF.createControl(xDrawDoc, objName);
156 
157         try {
158             XDrawPage oDP = DrawTools.getDrawPage(xDrawDoc, 0);
159 
160             XNameContainer nc = FormTools.getForms(oDP);
161             FormTools.insertForm(xDrawDoc, nc, "OHiddenModelForm");
162 
163             Object frm = nc.getByName("OHiddenModelForm");
164 
165             XNameContainer frmNC = (XNameContainer) UnoRuntime.queryInterface(
166                     XNameContainer.class, frm);
167 
168             frmNC.insertByName("OHiddenModel", ctrl);
169             oObj = (XInterface) AnyConverter.toObject(
170                     new Type(XInterface.class),
171                     frmNC.getByName("OHiddenModel"));
172         } catch (com.sun.star.lang.WrappedTargetException e) {
173             e.printStackTrace(log);
174             throw new StatusException("Can't create and add control", e);
175         } catch (com.sun.star.lang.IllegalArgumentException e) {
176             e.printStackTrace(log);
177             throw new StatusException("Can't create and add control", e);
178         } catch (com.sun.star.container.NoSuchElementException e) {
179             e.printStackTrace(log);
180             throw new StatusException("Can't create and add control", e);
181         } catch (com.sun.star.container.ElementExistException e) {
182             e.printStackTrace(log);
183             throw new StatusException("Can't create and add control", e);
184         }
185 
186         log.println("creating a new environment for drawpage object");
187 
188         TestEnvironment tEnv = new TestEnvironment(oObj);
189 
190         util.dbg.getSuppServices(oObj);
191 
192         log.println("adding DrawDocument as obj relation to environment");
193         tEnv.addObjRelation("OBJNAME", "stardiv.one.form.component.Hidden");
194 
195         PropertyValue prop = new PropertyValue();
196         prop.Name = "Name";
197         prop.Value = "new Text since XPropertyAccess";
198         tEnv.addObjRelation("XPropertyAccess.propertyToChange", prop);
199         tEnv.addObjRelation("XPropertyContainer.propertyNotRemovable", "Name");
200 
201         return tEnv;
202     } // finish method getTestEnvironment
203 } // finish class OHiddenModel
204