1 /*
2  * This file is part of the LibreOffice project.
3  *
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/.
7  *
8  * This file incorporates work covered by the following license notice:
9  *
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 .
17  */
18 package mod._forms;
19 
20 import com.sun.star.beans.NamedValue;
21 import com.sun.star.beans.XPropertySet;
22 import com.sun.star.form.XBoundComponent;
23 import com.sun.star.form.XLoadable;
24 import com.sun.star.sdbc.XResultSetUpdate;
25 import com.sun.star.uno.UnoRuntime;
26 import com.sun.star.uno.XInterface;
27 import java.io.PrintWriter;
28 import ifc.form._XUpdateBroadcaster.UpdateChecker;
29 
30 import lib.TestEnvironment;
31 import lib.TestParameters;
32 import util.DBTools;
33 
34 
35 
36 /**
37 * Test for object which is represented by service
38 * <code>com.sun.star.form.component.TimeField</code>. <p>
39 * Object implements the following interfaces :
40 * <ul>
41 *  <li> <code>com::sun::star::awt::UnoControlTimeFieldModel</code></li>
42 *  <li> <code>com::sun::star::io::XPersistObject</code></li>
43 *  <li> <code>com::sun::star::form::component::TimeField</code></li>
44 *  <li> <code>com::sun::star::form::XReset</code></li>
45 *  <li> <code>com::sun::star::form::XBoundComponent</code></li>
46 *  <li> <code>com::sun::star::form::FormComponent</code></li>
47 *  <li> <code>com::sun::star::beans::XFastPropertySet</code></li>
48 *  <li> <code>com::sun::star::beans::XMultiPropertySet</code></li>
49 *  <li> <code>com::sun::star::form::XUpdateBroadcaster</code></li>
50 *  <li> <code>com::sun::star::form::DataAwareControlModel</code></li>
51 *  <li> <code>com::sun::star::beans::XPropertyState</code></li>
52 *  <li> <code>com::sun::star::form::FormControlModel</code></li>
53 *  <li> <code>com::sun::star::container::XNamed</code></li>
54 *  <li> <code>com::sun::star::lang::XComponent</code></li>
55 *  <li> <code>com::sun::star::lang::XEventListener</code></li>
56 *  <li> <code>com::sun::star::beans::XPropertyAccess</code></li>
57 *  <li> <code>com::sun::star::beans::XPropertyContainer</code></li>
58 *  <li> <code>com::sun::star::beans::XPropertySet</code></li>
59 *  <li> <code>com::sun::star::form::XLoadListener</code></li>
60 *  <li> <code>com::sun::star::container::XChild</code></li>
61 * </ul>
62 * The following files used by this test :
63 * <ul>
64 *  <li><b> TestDB </b> (directory) : directory with test database </li>
65 *  <li><b> TestDB/TestDB.dbf </b> : table file. See
66 *    {@link util.DBTools DBTools} class for more information.</li>
67 * </ul> <p>
68 * This object test <b> is NOT </b> designed to be run in several
69 * threads concurrently.
70 * @see com.sun.star.awt.UnoControlTimeFieldModel
71 * @see com.sun.star.io.XPersistObject
72 * @see com.sun.star.form.component.TimeField
73 * @see com.sun.star.form.XReset
74 * @see com.sun.star.form.XBoundComponent
75 * @see com.sun.star.form.FormComponent
76 * @see com.sun.star.beans.XFastPropertySet
77 * @see com.sun.star.beans.XMultiPropertySet
78 * @see com.sun.star.form.XUpdateBroadcaster
79 * @see com.sun.star.form.DataAwareControlModel
80 * @see com.sun.star.beans.XPropertyState
81 * @see com.sun.star.form
82 * @see com.sun.star.container.XNamed
83 * @see com.sun.star.lang.XComponent
84 * @see com.sun.star.lang.XEventListener
85 * @see com.sun.star.beans.XPropertyAccess
86 * @see com.sun.star.beans.XPropertyContainer
87 * @see com.sun.star.beans.XPropertySet
88 * @see com.sun.star.form.XLoadListener
89 * @see com.sun.star.container.XChild
90 * @see ifc.awt._UnoControlTimeFieldModel
91 * @see ifc.io._XPersistObject
92 * @see ifc.form.component._TimeField
93 * @see ifc.form._XReset
94 * @see ifc.form._XBoundComponent
95 * @see ifc.form._FormComponent
96 * @see ifc.beans._XFastPropertySet
97 * @see ifc.beans._XMultiPropertySet
98 * @see ifc.form._XUpdateBroadcaster
99 * @see ifc.form._DataAwareControlModel
100 * @see ifc.beans._XPropertyState
101 * @see ifc.form._FormControlModel
102 * @see ifc.container._XNamed
103 * @see ifc.lang._XComponent
104 * @see ifc.lang._XEventListener
105 * @see ifc.beans._XPropertySet
106 * @see ifc.form._XLoadListener
107 * @see ifc.container._XChild
108 */
109 public class OTimeModel extends GenericModelTest {
110     /**
111      * Set some member variable of the super class <CODE>GenericModelTest</CODE>:
112      * <pre>
113      *    super.m_ChangePropertyName = "Time";
114      *    super.m_kindOfControl="TimeField";
115      *    super.m_ObjectName = "stardiv.one.form.component.TimeField";
116      *    NamedValue DataField = new NamedValue();
117      *    DataField.Name = "DataField";
118      *    DataField.Value = DBTools.TST_INT_F;
119      *    super.m_propertiesToSet.add(DataField);
120      *
121      *    super.m_LCShape_Type = "FixedText";
122      * </pre>
123      * Then <CODE>super.initialize()</CODE> was called.
124      * @param tParam the test parameter
125      * @param log the log writer
126      */
127     @Override
initialize(TestParameters tParam, PrintWriter log)128     protected void initialize(TestParameters tParam, PrintWriter log) throws Exception {
129 
130         super.initialize(tParam, log);
131 
132         super.m_ChangePropertyName = "Time";
133 
134         super.m_kindOfControl="TimeField";
135 
136         super.m_ObjectName = "stardiv.one.form.component.TimeField";
137 
138         NamedValue DataField = new NamedValue();
139         DataField.Name = "DataField";
140         DataField.Value = DBTools.TST_INT_F;
141         super.m_propertiesToSet.add(DataField);
142 
143         super.m_LCShape_Type = "FixedText";
144 
145     }
146 
147     /**
148      * calls <CODE>createTestEnvironment()</CODE> from its super class
149      * This test uses not the generic implementation of <CODE>checker()</CODE> of its
150      * super class. This tests uses its own implementation of <CODE>checker()</CODE>
151      * to test <CODE>com::sun::star::form::XUpdateBroadcaster</CODE>
152      * @param Param the test parameter
153      * @param log the log writer
154      * @return lib.TestEnvironment
155      */
156     @Override
createTestEnvironment(TestParameters Param, PrintWriter log)157     protected TestEnvironment createTestEnvironment(TestParameters Param,
158                                                                  PrintWriter log) throws Exception {
159         TestEnvironment tEnv = super.createTestEnvironment(Param, log);
160 
161         tEnv.addObjRelation("XUpdateBroadcaster.Checker",
162                             new Checker(m_XFormLoader, m_XPS, m_XCtrl));
163         return tEnv;
164     }
165 
166     private static class Checker implements UpdateChecker {
167             private XLoadable formLoaderF = null;
168             private XPropertySet ps = null;
169             private XInterface ctrl = null;
170 
Checker(XLoadable xl, XPropertySet ps, XInterface ctrl)171             public Checker(XLoadable xl, XPropertySet ps, XInterface ctrl) {
172                 formLoaderF = xl;
173                 this.ps = ps;
174                 this.ctrl = ctrl;
175             }
176 
177             private int lastTime = 0;
178 
update()179             public void update() throws com.sun.star.uno.Exception {
180                 if (!formLoaderF.isLoaded()) {
181                     formLoaderF.load();
182                 }
183 
184                 Integer time = (Integer) ps.getPropertyValue("Time");
185 
186                 if (time != null) {
187                     lastTime = time.intValue() + 150000;
188                 }
189 
190                 ps.setPropertyValue("Time", Integer.valueOf(lastTime));
191             }
192 
commit()193             public void commit() throws com.sun.star.sdbc.SQLException {
194                 XBoundComponent bound = UnoRuntime.queryInterface(
195                                                 XBoundComponent.class, ctrl);
196                 XResultSetUpdate update = UnoRuntime.queryInterface(
197                                                   XResultSetUpdate.class,
198                                                   formLoaderF);
199 
200                 bound.commit();
201                 update.updateRow();
202             }
203 
wasCommited()204             public boolean wasCommited() throws com.sun.star.uno.Exception {
205                 formLoaderF.reload();
206 
207                 Integer getT = (Integer) ps.getPropertyValue("Time");
208 
209                 return (getT != null) &&
210                        (Math.abs(getT.intValue() - lastTime) < 100);
211             }
212     }
213 } // finish class OTimeModel
214