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