xref: /AOO41X/main/qadevOOo/tests/java/mod/_forms/OHiddenModel.java (revision 47148b3bc50811ceb41802e4cc50a5db21535900)
1ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5ef39d40dSAndrew Rist  * distributed with this work for additional information
6ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18ef39d40dSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20ef39d40dSAndrew Rist  *************************************************************/
21ef39d40dSAndrew Rist 
22ef39d40dSAndrew Rist 
23cdf0e10cSrcweir package mod._forms;
24cdf0e10cSrcweir 
25cdf0e10cSrcweir import com.sun.star.beans.PropertyValue;
26cdf0e10cSrcweir import java.io.PrintWriter;
27cdf0e10cSrcweir 
28cdf0e10cSrcweir import lib.StatusException;
29cdf0e10cSrcweir import lib.TestCase;
30cdf0e10cSrcweir import lib.TestEnvironment;
31cdf0e10cSrcweir import lib.TestParameters;
32cdf0e10cSrcweir import util.DrawTools;
33cdf0e10cSrcweir import util.FormTools;
34cdf0e10cSrcweir import util.SOfficeFactory;
35cdf0e10cSrcweir 
36cdf0e10cSrcweir import com.sun.star.container.XNameContainer;
37cdf0e10cSrcweir import com.sun.star.drawing.XDrawPage;
38cdf0e10cSrcweir import com.sun.star.lang.XComponent;
39cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
40cdf0e10cSrcweir import com.sun.star.uno.AnyConverter;
41cdf0e10cSrcweir import com.sun.star.uno.Type;
42cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
43cdf0e10cSrcweir import com.sun.star.uno.XInterface;
44cdf0e10cSrcweir import com.sun.star.util.XCloseable;
45cdf0e10cSrcweir 
46cdf0e10cSrcweir 
47cdf0e10cSrcweir /**
48cdf0e10cSrcweir  * Test for object which is represented by service
49cdf0e10cSrcweir  * <code>com.sun.star.form.component.HiddenControl</code>. <p>
50cdf0e10cSrcweir  * Object implements the following interfaces :
51cdf0e10cSrcweir  * <ul>
52cdf0e10cSrcweir  *  <li> <code>com::sun::star::io::XPersistObject</code></li>
53cdf0e10cSrcweir  *  <li> <code>com::sun::star::container::XChild</code></li>
54cdf0e10cSrcweir  *  <li> <code>com::sun::star::form::FormControlModel</code></li>
55cdf0e10cSrcweir  *  <li> <code>com::sun::star::form::component::HiddenControl</code></li>
56cdf0e10cSrcweir  *  <li> <code>com::sun::star::form::FormComponent</code></li>
57cdf0e10cSrcweir  *  <li> <code>com::sun::star::beans::XPropertyAccess</code></li>
58cdf0e10cSrcweir *  <li> <code>com::sun::star::beans::XPropertyContainer</code></li>
59cdf0e10cSrcweir *  <li> <code>com::sun::star::beans::XPropertySet</code></li>
60cdf0e10cSrcweir  *  <li> <code>com::sun::star::beans::XFastPropertySet</code></li>
61cdf0e10cSrcweir  *  <li> <code>com::sun::star::beans::XPropertyState</code></li>
62cdf0e10cSrcweir  *  <li> <code>com::sun::star::container::XNamed</code></li>
63cdf0e10cSrcweir  *  <li> <code>com::sun::star::beans::XMultiPropertySet</code></li>
64cdf0e10cSrcweir  *  <li> <code>com::sun::star::lang::XComponent</code></li>
65cdf0e10cSrcweir  * </ul> <p>
66cdf0e10cSrcweir  * This object test <b> is NOT </b> designed to be run in several
67cdf0e10cSrcweir  * threads concurently.
68cdf0e10cSrcweir  * @see com.sun.star.io.XPersistObject
69cdf0e10cSrcweir  * @see com.sun.star.container.XChild
70*5496b966SPedro Giffuni  * @see com.sun.star.form
71cdf0e10cSrcweir  * @see com.sun.star.form.component.HiddenControl
72cdf0e10cSrcweir  * @see com.sun.star.form.FormComponent
73cdf0e10cSrcweir  * @see com.sun.star.beans.XPropertyAccess
74cdf0e10cSrcweir * @see com.sun.star.beans.XPropertyContainer
75cdf0e10cSrcweir * @see com.sun.star.beans.XPropertySet
76cdf0e10cSrcweir  * @see com.sun.star.beans.XFastPropertySet
77cdf0e10cSrcweir  * @see com.sun.star.beans.XPropertyState
78cdf0e10cSrcweir  * @see com.sun.star.container.XNamed
79cdf0e10cSrcweir  * @see com.sun.star.beans.XMultiPropertySet
80cdf0e10cSrcweir  * @see com.sun.star.lang.XComponent
81cdf0e10cSrcweir  * @see ifc.io._XPersistObject
82cdf0e10cSrcweir  * @see ifc.container._XChild
83cdf0e10cSrcweir  * @see ifc.form._FormControlModel
84cdf0e10cSrcweir  * @see ifc.form.component._HiddenControl
85cdf0e10cSrcweir  * @see ifc.form._FormComponent
86cdf0e10cSrcweir  * @see ifc.beans._XPropertySet
87cdf0e10cSrcweir  * @see ifc.beans._XFastPropertySet
88cdf0e10cSrcweir  * @see ifc.beans._XPropertyState
89cdf0e10cSrcweir  * @see ifc.container._XNamed
90cdf0e10cSrcweir  * @see ifc.beans._XMultiPropertySet
91cdf0e10cSrcweir  * @see ifc.lang._XComponent
92cdf0e10cSrcweir  */
93cdf0e10cSrcweir public class OHiddenModel extends TestCase {
94cdf0e10cSrcweir     XComponent xDrawDoc;
95cdf0e10cSrcweir 
96cdf0e10cSrcweir     /**
97cdf0e10cSrcweir      * Creates Drawing document.
98cdf0e10cSrcweir      */
initialize(TestParameters tParam, PrintWriter log)99cdf0e10cSrcweir     protected void initialize(TestParameters tParam, PrintWriter log) {
100cdf0e10cSrcweir         SOfficeFactory SOF = SOfficeFactory.getFactory(((XMultiServiceFactory) tParam.getMSF()));
101cdf0e10cSrcweir 
102cdf0e10cSrcweir         try {
103cdf0e10cSrcweir             log.println("creating a draw document");
104cdf0e10cSrcweir             xDrawDoc = SOF.createDrawDoc(null);
105cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception e) {
106cdf0e10cSrcweir             // Some exception occures.FAILED
107cdf0e10cSrcweir             e.printStackTrace(log);
108cdf0e10cSrcweir             throw new StatusException("Couldn't create document", e);
109cdf0e10cSrcweir         }
110cdf0e10cSrcweir     }
111cdf0e10cSrcweir 
112cdf0e10cSrcweir     /**
113cdf0e10cSrcweir      * Disposes drawing document.
114cdf0e10cSrcweir      */
cleanup(TestParameters tParam, PrintWriter log)115cdf0e10cSrcweir     protected void cleanup(TestParameters tParam, PrintWriter log) {
116cdf0e10cSrcweir         log.println("    disposing xDrawDoc ");
117cdf0e10cSrcweir 
118cdf0e10cSrcweir         try {
119cdf0e10cSrcweir             XCloseable closer = (XCloseable) UnoRuntime.queryInterface(
120cdf0e10cSrcweir                     XCloseable.class, xDrawDoc);
121cdf0e10cSrcweir             closer.close(true);
122cdf0e10cSrcweir         } catch (com.sun.star.util.CloseVetoException e) {
123cdf0e10cSrcweir             log.println("couldn't close document");
124cdf0e10cSrcweir         } catch (com.sun.star.lang.DisposedException e) {
125cdf0e10cSrcweir             log.println("couldn't close document");
126cdf0e10cSrcweir         }
127cdf0e10cSrcweir     }
128cdf0e10cSrcweir 
129cdf0e10cSrcweir     /**
130cdf0e10cSrcweir      * Creates hidden component, then adds Form into draw page,
131cdf0e10cSrcweir      * and inserts the component into Form components' collection.
132cdf0e10cSrcweir      *     Object relations created :
133cdf0e10cSrcweir      * <ul>
134cdf0e10cSrcweir      *  <li> <code>'OBJNAME'</code> for
135cdf0e10cSrcweir      *      {@link ifc.io._XPersistObject} : name of service which is
136cdf0e10cSrcweir      *    represented by this object. </li>
137cdf0e10cSrcweir      * </ul>
138cdf0e10cSrcweir      */
createTestEnvironment(TestParameters Param, PrintWriter log)139cdf0e10cSrcweir     protected synchronized TestEnvironment createTestEnvironment(TestParameters Param,
140cdf0e10cSrcweir             PrintWriter log) {
141cdf0e10cSrcweir         XInterface oObj = null;
142cdf0e10cSrcweir 
143cdf0e10cSrcweir 
144cdf0e10cSrcweir         // creation of testobject here
145cdf0e10cSrcweir         // first we write what we are intend to do to log file
146cdf0e10cSrcweir         log.println("creating a test environment");
147cdf0e10cSrcweir 
148cdf0e10cSrcweir         // get a soffice factory object
149cdf0e10cSrcweir         SOfficeFactory SOF = SOfficeFactory.getFactory(((XMultiServiceFactory) Param.getMSF()));
150cdf0e10cSrcweir         String objName = "HiddenControl";
151cdf0e10cSrcweir         XInterface ctrl = SOF.createControl(xDrawDoc, objName);
152cdf0e10cSrcweir 
153cdf0e10cSrcweir         try {
154cdf0e10cSrcweir             XDrawPage oDP = DrawTools.getDrawPage(xDrawDoc, 0);
155cdf0e10cSrcweir 
156cdf0e10cSrcweir             XNameContainer nc = FormTools.getForms(oDP);
157cdf0e10cSrcweir             FormTools.insertForm(xDrawDoc, nc, "OHiddenModelForm");
158cdf0e10cSrcweir 
159cdf0e10cSrcweir             Object frm = nc.getByName("OHiddenModelForm");
160cdf0e10cSrcweir 
161cdf0e10cSrcweir             XNameContainer frmNC = (XNameContainer) UnoRuntime.queryInterface(
162cdf0e10cSrcweir                     XNameContainer.class, frm);
163cdf0e10cSrcweir 
164cdf0e10cSrcweir             frmNC.insertByName("OHiddenModel", ctrl);
165cdf0e10cSrcweir             oObj = (XInterface) AnyConverter.toObject(
166cdf0e10cSrcweir                     new Type(XInterface.class),
167cdf0e10cSrcweir                     frmNC.getByName("OHiddenModel"));
168cdf0e10cSrcweir         } catch (com.sun.star.lang.WrappedTargetException e) {
169cdf0e10cSrcweir             e.printStackTrace(log);
170cdf0e10cSrcweir             throw new StatusException("Can't create and add control", e);
171cdf0e10cSrcweir         } catch (com.sun.star.lang.IllegalArgumentException e) {
172cdf0e10cSrcweir             e.printStackTrace(log);
173cdf0e10cSrcweir             throw new StatusException("Can't create and add control", e);
174cdf0e10cSrcweir         } catch (com.sun.star.container.NoSuchElementException e) {
175cdf0e10cSrcweir             e.printStackTrace(log);
176cdf0e10cSrcweir             throw new StatusException("Can't create and add control", e);
177cdf0e10cSrcweir         } catch (com.sun.star.container.ElementExistException e) {
178cdf0e10cSrcweir             e.printStackTrace(log);
179cdf0e10cSrcweir             throw new StatusException("Can't create and add control", e);
180cdf0e10cSrcweir         }
181cdf0e10cSrcweir 
182cdf0e10cSrcweir         log.println("creating a new environment for drawpage object");
183cdf0e10cSrcweir 
184cdf0e10cSrcweir         TestEnvironment tEnv = new TestEnvironment(oObj);
185cdf0e10cSrcweir 
186cdf0e10cSrcweir         util.dbg.getSuppServices(oObj);
187cdf0e10cSrcweir 
188cdf0e10cSrcweir         log.println("adding DrawDocument as obj relation to environment");
189cdf0e10cSrcweir         tEnv.addObjRelation("OBJNAME", "stardiv.one.form.component.Hidden");
190cdf0e10cSrcweir 
191cdf0e10cSrcweir         PropertyValue prop = new PropertyValue();
192cdf0e10cSrcweir         prop.Name = "Name";
193cdf0e10cSrcweir         prop.Value = "new Text since XPropertyAccess";
194cdf0e10cSrcweir         tEnv.addObjRelation("XPropertyAccess.propertyToChange", prop);
195cdf0e10cSrcweir         tEnv.addObjRelation("XPropertyContainer.propertyNotRemovable", "Name");
196cdf0e10cSrcweir 
197cdf0e10cSrcweir         return tEnv;
198cdf0e10cSrcweir     } // finish method getTestEnvironment
199cdf0e10cSrcweir } // finish class OHiddenModel
200