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 com
.sun
.star
.beans
.PropertyValue
;
21 import java
.io
.PrintWriter
;
23 import lib
.StatusException
;
25 import lib
.TestEnvironment
;
26 import lib
.TestParameters
;
27 import util
.DrawTools
;
28 import util
.FormTools
;
29 import util
.SOfficeFactory
;
31 import com
.sun
.star
.container
.XNameContainer
;
32 import com
.sun
.star
.drawing
.XDrawPage
;
33 import com
.sun
.star
.lang
.XComponent
;
34 import com
.sun
.star
.lang
.XMultiServiceFactory
;
35 import com
.sun
.star
.uno
.AnyConverter
;
36 import com
.sun
.star
.uno
.Type
;
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.HiddenControl</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::form::component::HiddenControl</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>
61 * This object test <b> is NOT </b> designed to be run in several
62 * threads concurently.
63 * @see com.sun.star.io.XPersistObject
64 * @see com.sun.star.container.XChild
65 * @see com.sun.star.form
66 * @see com.sun.star.form.component.HiddenControl
67 * @see com.sun.star.form.FormComponent
68 * @see com.sun.star.beans.XPropertyAccess
69 * @see com.sun.star.beans.XPropertyContainer
70 * @see com.sun.star.beans.XPropertySet
71 * @see com.sun.star.beans.XFastPropertySet
72 * @see com.sun.star.beans.XPropertyState
73 * @see com.sun.star.container.XNamed
74 * @see com.sun.star.beans.XMultiPropertySet
75 * @see com.sun.star.lang.XComponent
76 * @see ifc.io._XPersistObject
77 * @see ifc.container._XChild
78 * @see ifc.form._FormControlModel
79 * @see ifc.form.component._HiddenControl
80 * @see ifc.form._FormComponent
81 * @see ifc.beans._XPropertySet
82 * @see ifc.beans._XFastPropertySet
83 * @see ifc.beans._XPropertyState
84 * @see ifc.container._XNamed
85 * @see ifc.beans._XMultiPropertySet
86 * @see ifc.lang._XComponent
88 public class OHiddenModel
extends TestCase
{
92 * Creates Drawing document.
94 protected void initialize(TestParameters tParam
, PrintWriter log
) {
95 SOfficeFactory SOF
= SOfficeFactory
.getFactory(((XMultiServiceFactory
) tParam
.getMSF()));
98 log
.println("creating a draw document");
99 xDrawDoc
= SOF
.createDrawDoc(null);
100 } catch (com
.sun
.star
.uno
.Exception e
) {
101 // Some exception occurs.FAILED
102 e
.printStackTrace(log
);
103 throw new StatusException("Couldn't create document", e
);
108 * Disposes drawing document.
110 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
111 log
.println(" disposing xDrawDoc ");
114 XCloseable closer
= UnoRuntime
.queryInterface(
115 XCloseable
.class, xDrawDoc
);
117 } catch (com
.sun
.star
.util
.CloseVetoException e
) {
118 log
.println("couldn't close document");
119 } catch (com
.sun
.star
.lang
.DisposedException e
) {
120 log
.println("couldn't close document");
125 * Creates hidden component, then adds Form into draw page,
126 * and inserts the component into Form components' collection.
127 * Object relations created :
129 * <li> <code>'OBJNAME'</code> for
130 * {@link ifc.io._XPersistObject} : name of service which is
131 * represented by this object. </li>
134 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
,
136 XInterface oObj
= null;
139 // creation of testobject here
140 // first we write what we are intend to do to log file
141 log
.println("creating a test environment");
143 // get a soffice factory object
144 SOfficeFactory SOF
= SOfficeFactory
.getFactory(((XMultiServiceFactory
) Param
.getMSF()));
145 String objName
= "HiddenControl";
146 XInterface ctrl
= SOF
.createControl(xDrawDoc
, objName
);
149 XDrawPage oDP
= DrawTools
.getDrawPage(xDrawDoc
, 0);
151 XNameContainer nc
= FormTools
.getForms(oDP
);
152 FormTools
.insertForm(xDrawDoc
, nc
, "OHiddenModelForm");
154 Object frm
= nc
.getByName("OHiddenModelForm");
156 XNameContainer frmNC
= UnoRuntime
.queryInterface(
157 XNameContainer
.class, frm
);
159 frmNC
.insertByName("OHiddenModel", ctrl
);
160 oObj
= (XInterface
) AnyConverter
.toObject(
161 new Type(XInterface
.class),
162 frmNC
.getByName("OHiddenModel"));
163 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
164 e
.printStackTrace(log
);
165 throw new StatusException("Can't create and add control", e
);
166 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
167 e
.printStackTrace(log
);
168 throw new StatusException("Can't create and add control", e
);
169 } catch (com
.sun
.star
.container
.NoSuchElementException e
) {
170 e
.printStackTrace(log
);
171 throw new StatusException("Can't create and add control", e
);
172 } catch (com
.sun
.star
.container
.ElementExistException e
) {
173 e
.printStackTrace(log
);
174 throw new StatusException("Can't create and add control", e
);
177 log
.println("creating a new environment for drawpage object");
179 TestEnvironment tEnv
= new TestEnvironment(oObj
);
181 util
.dbg
.getSuppServices(oObj
);
183 log
.println("adding DrawDocument as obj relation to environment");
184 tEnv
.addObjRelation("OBJNAME", "stardiv.one.form.component.Hidden");
186 PropertyValue prop
= new PropertyValue();
188 prop
.Value
= "new Text since XPropertyAccess";
189 tEnv
.addObjRelation("XPropertyAccess.propertyToChange", prop
);
190 tEnv
.addObjRelation("XPropertyContainer.propertyNotRemovable", "Name");
193 } // finish method getTestEnvironment
194 } // finish class OHiddenModel