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
.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 java
.util
.HashSet
;
29 import ifc
.form
._XUpdateBroadcaster
.UpdateChecker
;
31 import lib
.TestEnvironment
;
32 import lib
.TestParameters
;
38 * Test for object which is represented by service
39 * <code>com.sun.star.form.component.TimeField</code>. <p>
40 * Object implements the following interfaces :
42 * <li> <code>com::sun::star::awt::UnoControlTimeFieldModel</code></li>
43 * <li> <code>com::sun::star::io::XPersistObject</code></li>
44 * <li> <code>com::sun::star::form::component::TimeField</code></li>
45 * <li> <code>com::sun::star::form::XReset</code></li>
46 * <li> <code>com::sun::star::form::XBoundComponent</code></li>
47 * <li> <code>com::sun::star::form::FormComponent</code></li>
48 * <li> <code>com::sun::star::beans::XFastPropertySet</code></li>
49 * <li> <code>com::sun::star::beans::XMultiPropertySet</code></li>
50 * <li> <code>com::sun::star::form::XUpdateBroadcaster</code></li>
51 * <li> <code>com::sun::star::form::DataAwareControlModel</code></li>
52 * <li> <code>com::sun::star::beans::XPropertyState</code></li>
53 * <li> <code>com::sun::star::form::FormControlModel</code></li>
54 * <li> <code>com::sun::star::container::XNamed</code></li>
55 * <li> <code>com::sun::star::lang::XComponent</code></li>
56 * <li> <code>com::sun::star::lang::XEventListener</code></li>
57 * <li> <code>com::sun::star::beans::XPropertyAccess</code></li>
58 * <li> <code>com::sun::star::beans::XPropertyContainer</code></li>
59 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
60 * <li> <code>com::sun::star::form::XLoadListener</code></li>
61 * <li> <code>com::sun::star::container::XChild</code></li>
63 * The following files used by this test :
65 * <li><b> TestDB </b> (directory) : directory with test database </li>
66 * <li><b> TestDB/TestDB.dbf </b> : table file. See
67 * {@link util.DBTools DBTools} class for more information.</li>
69 * This object test <b> is NOT </b> designed to be run in several
70 * threads concurently.
71 * @see com.sun.star.awt.UnoControlTimeFieldModel
72 * @see com.sun.star.io.XPersistObject
73 * @see com.sun.star.form.component.TimeField
74 * @see com.sun.star.form.XReset
75 * @see com.sun.star.form.XBoundComponent
76 * @see com.sun.star.form.FormComponent
77 * @see com.sun.star.beans.XFastPropertySet
78 * @see com.sun.star.beans.XMultiPropertySet
79 * @see com.sun.star.form.XUpdateBroadcaster
80 * @see com.sun.star.form.DataAwareControlModel
81 * @see com.sun.star.beans.XPropertyState
82 * @see com.sun.star.form
83 * @see com.sun.star.container.XNamed
84 * @see com.sun.star.lang.XComponent
85 * @see com.sun.star.lang.XEventListener
86 * @see com.sun.star.beans.XPropertyAccess
87 * @see com.sun.star.beans.XPropertyContainer
88 * @see com.sun.star.beans.XPropertySet
89 * @see com.sun.star.form.XLoadListener
90 * @see com.sun.star.container.XChild
91 * @see ifc.awt._UnoControlTimeFieldModel
92 * @see ifc.io._XPersistObject
93 * @see ifc.form.component._TimeField
94 * @see ifc.form._XReset
95 * @see ifc.form._XBoundComponent
96 * @see ifc.form._FormComponent
97 * @see ifc.beans._XFastPropertySet
98 * @see ifc.beans._XMultiPropertySet
99 * @see ifc.form._XUpdateBroadcaster
100 * @see ifc.form._DataAwareControlModel
101 * @see ifc.beans._XPropertyState
102 * @see ifc.form._FormControlModel
103 * @see ifc.container._XNamed
104 * @see ifc.lang._XComponent
105 * @see ifc.lang._XEventListener
106 * @see ifc.beans._XPropertySet
107 * @see ifc.form._XLoadListener
108 * @see ifc.container._XChild
110 public class OTimeModel
extends GenericModelTest
{
112 * Set some member variable of the super class <CODE>GenericModelTest</CODE>:
114 * super.m_ChangePropertyName = "Time";
115 * super.m_kindOfControl="TimeField";
116 * super.m_ObjectName = "stardiv.one.form.component.TimeField";
117 * NamedValue DataField = new NamedValue();
118 * DataField.Name = "DataField";
119 * DataField.Value = DBTools.TST_INT_F;
120 * super.m_propertiesToSet.add(DataField);
122 * super.m_LCShape_Type = "FixedText";
124 * Then <CODE>super.initialize()</CODE> was called.
125 * @param tParam the test parameter
126 * @param log the log writer
129 protected void initialize(TestParameters tParam
, PrintWriter log
) {
131 super.initialize(tParam
, log
);
133 super.m_ChangePropertyName
= "Time";
135 super.m_kindOfControl
="TimeField";
137 super.m_ObjectName
= "stardiv.one.form.component.TimeField";
139 NamedValue DataField
= new NamedValue();
140 DataField
.Name
= "DataField";
141 DataField
.Value
= DBTools
.TST_INT_F
;
142 super.m_propertiesToSet
.add(DataField
);
144 super.m_LCShape_Type
= "FixedText";
149 * calls <CODE>createTestEnvironment()</CODE> from it's super class
150 * This test uses not the generic implementaion of <CODE>cecker()</CODE> of its
151 * super class. This tests uses its own implementation of <CODE>checker()</CODE>
152 * to test <CODE>com::sun::star::form::XUpdateBroadcaster</CODE>
153 * @param Param the test parameter
154 * @param log the log writer
155 * @return lib.TestEnvironment
158 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
,
160 TestEnvironment tEnv
= super.createTestEnvironment(Param
, log
);
162 HashSet
<String
> exclude
= new HashSet
<String
>();
164 exclude
.add("FormatKey");
166 tEnv
.addObjRelation("XUpdateBroadcaster.Checker",
167 new Checker(m_XFormLoader
, m_XPS
, m_XCtrl
));
171 private static class Checker
implements UpdateChecker
{
172 private XLoadable formLoaderF
= null;
173 private XPropertySet ps
= null;
174 private XInterface ctrl
= null;
176 public Checker(XLoadable xl
, XPropertySet ps
, XInterface ctrl
) {
182 private int lastTime
= 0;
184 public void update() throws com
.sun
.star
.uno
.Exception
{
185 if (!formLoaderF
.isLoaded()) {
189 Integer time
= (Integer
) ps
.getPropertyValue("Time");
192 lastTime
= time
.intValue() + 150000;
195 ps
.setPropertyValue("Time", Integer
.valueOf(lastTime
));
198 public void commit() throws com
.sun
.star
.sdbc
.SQLException
{
199 XBoundComponent bound
= UnoRuntime
.queryInterface(
200 XBoundComponent
.class, ctrl
);
201 XResultSetUpdate update
= UnoRuntime
.queryInterface(
202 XResultSetUpdate
.class,
209 public boolean wasCommited() throws com
.sun
.star
.uno
.Exception
{
210 formLoaderF
.reload();
212 Integer getT
= (Integer
) ps
.getPropertyValue("Time");
214 return (getT
!= null) &&
215 (Math
.abs(getT
.intValue() - lastTime
) < 100);
218 } // finish class OTimeModel