1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 package mod._forms;
24 
25 import com.sun.star.beans.NamedValue;
26 import com.sun.star.beans.XPropertySet;
27 import com.sun.star.form.XBoundComponent;
28 import com.sun.star.form.XLoadable;
29 import com.sun.star.sdbc.XResultSetUpdate;
30 import com.sun.star.uno.UnoRuntime;
31 import com.sun.star.uno.XInterface;
32 import java.io.PrintWriter;
33 import java.util.HashSet;
34 import ifc.form._XUpdateBroadcaster.UpdateChecker;
35 
36 import lib.TestEnvironment;
37 import lib.TestParameters;
38 import util.DBTools;
39 
40 
41 
42 /**
43 * Test for object which is represented by service
44 * <code>com.sun.star.form.component.TimeField</code>. <p>
45 * Object implements the following interfaces :
46 * <ul>
47 *  <li> <code>com::sun::star::awt::UnoControlTimeFieldModel</code></li>
48 *  <li> <code>com::sun::star::io::XPersistObject</code></li>
49 *  <li> <code>com::sun::star::form::component::TimeField</code></li>
50 *  <li> <code>com::sun::star::form::XReset</code></li>
51 *  <li> <code>com::sun::star::form::XBoundComponent</code></li>
52 *  <li> <code>com::sun::star::form::FormComponent</code></li>
53 *  <li> <code>com::sun::star::beans::XFastPropertySet</code></li>
54 *  <li> <code>com::sun::star::beans::XMultiPropertySet</code></li>
55 *  <li> <code>com::sun::star::form::XUpdateBroadcaster</code></li>
56 *  <li> <code>com::sun::star::form::DataAwareControlModel</code></li>
57 *  <li> <code>com::sun::star::beans::XPropertyState</code></li>
58 *  <li> <code>com::sun::star::form::FormControlModel</code></li>
59 *  <li> <code>com::sun::star::container::XNamed</code></li>
60 *  <li> <code>com::sun::star::lang::XComponent</code></li>
61 *  <li> <code>com::sun::star::lang::XEventListener</code></li>
62 *  <li> <code>com::sun::star::beans::XPropertyAccess</code></li>
63 *  <li> <code>com::sun::star::beans::XPropertyContainer</code></li>
64 *  <li> <code>com::sun::star::beans::XPropertySet</code></li>
65 *  <li> <code>com::sun::star::form::XLoadListener</code></li>
66 *  <li> <code>com::sun::star::container::XChild</code></li>
67 * </ul>
68 * The following files used by this test :
69 * <ul>
70 *  <li><b> TestDB </b> (directory) : directory with test database </li>
71 *  <li><b> TestDB/TestDB.dbf </b> : table file. See
72 *    {@link util.DBTools DBTools} class for more information.</li>
73 * </ul> <p>
74 * This object test <b> is NOT </b> designed to be run in several
75 * threads concurently.
76 * @see com.sun.star.awt.UnoControlTimeFieldModel
77 * @see com.sun.star.io.XPersistObject
78 * @see com.sun.star.form.component.TimeField
79 * @see com.sun.star.form.XReset
80 * @see com.sun.star.form.XBoundComponent
81 * @see com.sun.star.form.FormComponent
82 * @see com.sun.star.beans.XFastPropertySet
83 * @see com.sun.star.beans.XMultiPropertySet
84 * @see com.sun.star.form.XUpdateBroadcaster
85 * @see com.sun.star.form.DataAwareControlModel
86 * @see com.sun.star.beans.XPropertyState
87 * @see com.sun.star.form
88 * @see com.sun.star.container.XNamed
89 * @see com.sun.star.lang.XComponent
90 * @see com.sun.star.lang.XEventListener
91 * @see com.sun.star.beans.XPropertyAccess
92 * @see com.sun.star.beans.XPropertyContainer
93 * @see com.sun.star.beans.XPropertySet
94 * @see com.sun.star.form.XLoadListener
95 * @see com.sun.star.container.XChild
96 * @see ifc.awt._UnoControlTimeFieldModel
97 * @see ifc.io._XPersistObject
98 * @see ifc.form.component._TimeField
99 * @see ifc.form._XReset
100 * @see ifc.form._XBoundComponent
101 * @see ifc.form._FormComponent
102 * @see ifc.beans._XFastPropertySet
103 * @see ifc.beans._XMultiPropertySet
104 * @see ifc.form._XUpdateBroadcaster
105 * @see ifc.form._DataAwareControlModel
106 * @see ifc.beans._XPropertyState
107 * @see ifc.form._FormControlModel
108 * @see ifc.container._XNamed
109 * @see ifc.lang._XComponent
110 * @see ifc.lang._XEventListener
111 * @see ifc.beans._XPropertySet
112 * @see ifc.form._XLoadListener
113 * @see ifc.container._XChild
114 */
115 public class OTimeModel extends GenericModelTest {
116     /**
117      * Set some member variable of the super class <CODE>GenericModelTest</CODE>:
118      * <pre>
119      *    super.m_ChangePropertyName = "Time";
120      *    super.m_kindOfControl="TimeField";
121      *    super.m_ObjectName = "stardiv.one.form.component.TimeField";
122      *    NamedValue DataField = new NamedValue();
123      *    DataField.Name = "DataField";
124      *    DataField.Value = DBTools.TST_INT_F;
125      *    super.m_propertiesToSet.add(DataField);
126      *
127      *    super.m_LCShape_Type = "FixedText";
128      * </pre>
129      * Then <CODE>super.initialize()</CODE> was called.
130      * @param tParam the test parameter
131      * @param log the log writer
132      */
initialize(TestParameters tParam, PrintWriter log)133     protected void initialize(TestParameters tParam, PrintWriter log) {
134 
135         super.initialize(tParam, log);
136 
137         super.m_ChangePropertyName = "Time";
138 
139         super.m_kindOfControl="TimeField";
140 
141         super.m_ObjectName = "stardiv.one.form.component.TimeField";
142 
143         NamedValue DataField = new NamedValue();
144         DataField.Name = "DataField";
145         DataField.Value = DBTools.TST_INT_F;
146         super.m_propertiesToSet.add(DataField);
147 
148         super.m_LCShape_Type = "FixedText";
149 
150     }    /**
151      * calls <CODE>cleanup()</CODE> from it's super class
152      * @param tParam the test parameter
153      * @param log the log writer
154      */
cleanup(TestParameters tParam, PrintWriter log)155     protected void cleanup(TestParameters tParam, PrintWriter log) {
156         super.cleanup(tParam, log);
157     }
158 
159     /**
160      * calls <CODE>createTestEnvironment()</CODE> from it's super class
161      * This test uses not the generic implementaion of <CODE>cecker()</CODE> of its
162      * super class. This tests uses its own implementation of <CODE>checker()</CODE>
163      * to test <CODE>com::sun::star::form::XUpdateBroadcaster</CODE>
164      * @param Param the test parameter
165      * @param log the log writer
166      * @return lib.TestEnvironment
167      */
createTestEnvironment(TestParameters Param, PrintWriter log)168     protected synchronized TestEnvironment createTestEnvironment(TestParameters Param,
169                                                                  PrintWriter log) {
170         TestEnvironment tEnv = super.createTestEnvironment(Param, log);
171 
172         HashSet exclude = new HashSet();
173 
174         exclude.add("FormatKey");
175 
176         tEnv.addObjRelation("XUpdateBroadcaster.Checker",
177                             new Checker(m_XFormLoader, m_XPS, m_XCtrl, m_ChangePropertyName, m_ChangePropertyValue));
178         return tEnv;
179     }
180 
181     static class Checker implements UpdateChecker {
182             private short lastItem = (short) 0;
183             XLoadable formLoaderF = null;
184             XPropertySet ps = null;
185             XInterface ctrl = null;
186             String ChangePropertyName = null;
187             Object ChangePropertyValue = null;
188 
Checker(XLoadable xl, XPropertySet ps, XInterface ctrl, String ChangePropertyName, Object ChangePropertyValue)189             public Checker(XLoadable xl, XPropertySet ps, XInterface ctrl, String ChangePropertyName, Object ChangePropertyValue) {
190                 formLoaderF = xl;
191                 this.ps = ps;
192                 this.ctrl = ctrl;
193                 this.ChangePropertyName=ChangePropertyName;
194                 this.ChangePropertyValue=ChangePropertyValue;
195             }
196 
197             private int lastTime = 0;
198 
update()199             public void update() throws com.sun.star.uno.Exception {
200                 if (!formLoaderF.isLoaded()) {
201                     formLoaderF.load();
202                 }
203 
204                 Integer time = (Integer) ps.getPropertyValue("Time");
205 
206                 if (time != null) {
207                     lastTime = time.intValue() + 150000;
208                 }
209 
210                 ps.setPropertyValue("Time", new Integer(lastTime));
211             }
212 
commit()213             public void commit() throws com.sun.star.sdbc.SQLException {
214                 XBoundComponent bound = (XBoundComponent) UnoRuntime.queryInterface(
215                                                 XBoundComponent.class, ctrl);
216                 XResultSetUpdate update = (XResultSetUpdate) UnoRuntime.queryInterface(
217                                                   XResultSetUpdate.class,
218                                                   formLoaderF);
219 
220                 bound.commit();
221                 update.updateRow();
222             }
223 
wasCommited()224             public boolean wasCommited() throws com.sun.star.uno.Exception {
225                 formLoaderF.reload();
226 
227                 Integer getT = (Integer) ps.getPropertyValue("Time");
228 
229                 return (getT != null) &&
230                        (Math.abs(getT.intValue() - lastTime) < 100);
231             }
232     }
233 } // finish class OTimeModel
234