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