bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _forms / OTimeModel.java
blobdff1c7292568e639f21b054a9fc492d51aea8ae2
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.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;
33 import util.DBTools;
37 /**
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 :
41 * <ul>
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>
62 * </ul>
63 * The following files used by this test :
64 * <ul>
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>
68 * </ul> <p>
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>:
113 * <pre>
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";
123 * </pre>
124 * Then <CODE>super.initialize()</CODE> was called.
125 * @param tParam the test parameter
126 * @param log the log writer
128 protected void initialize(TestParameters tParam, PrintWriter log) {
130 super.initialize(tParam, log);
132 super.m_ChangePropertyName = "Time";
134 super.m_kindOfControl="TimeField";
136 super.m_ObjectName = "stardiv.one.form.component.TimeField";
138 NamedValue DataField = new NamedValue();
139 DataField.Name = "DataField";
140 DataField.Value = DBTools.TST_INT_F;
141 super.m_propertiesToSet.add(DataField);
143 super.m_LCShape_Type = "FixedText";
145 } /**
146 * calls <CODE>cleanup()</CODE> from it's super class
147 * @param tParam the test parameter
148 * @param log the log writer
150 protected void cleanup(TestParameters tParam, PrintWriter log) {
151 super.cleanup(tParam, log);
155 * calls <CODE>createTestEnvironment()</CODE> from it's super class
156 * This test uses not the generic implementaion of <CODE>cecker()</CODE> of its
157 * super class. This tests uses its own implementation of <CODE>checker()</CODE>
158 * to test <CODE>com::sun::star::form::XUpdateBroadcaster</CODE>
159 * @param Param the test parameter
160 * @param log the log writer
161 * @return lib.TestEnvironment
163 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param,
164 PrintWriter log) {
165 TestEnvironment tEnv = super.createTestEnvironment(Param, log);
167 HashSet<String> exclude = new HashSet<String>();
169 exclude.add("FormatKey");
171 tEnv.addObjRelation("XUpdateBroadcaster.Checker",
172 new Checker(m_XFormLoader, m_XPS, m_XCtrl, m_ChangePropertyName, m_ChangePropertyValue));
173 return tEnv;
176 static class Checker implements UpdateChecker {
177 XLoadable formLoaderF = null;
178 XPropertySet ps = null;
179 XInterface ctrl = null;
180 String ChangePropertyName = null;
181 Object ChangePropertyValue = null;
183 public Checker(XLoadable xl, XPropertySet ps, XInterface ctrl, String ChangePropertyName, Object ChangePropertyValue) {
184 formLoaderF = xl;
185 this.ps = ps;
186 this.ctrl = ctrl;
187 this.ChangePropertyName=ChangePropertyName;
188 this.ChangePropertyValue=ChangePropertyValue;
191 private int lastTime = 0;
193 public void update() throws com.sun.star.uno.Exception {
194 if (!formLoaderF.isLoaded()) {
195 formLoaderF.load();
198 Integer time = (Integer) ps.getPropertyValue("Time");
200 if (time != null) {
201 lastTime = time.intValue() + 150000;
204 ps.setPropertyValue("Time", new Integer(lastTime));
207 public void commit() throws com.sun.star.sdbc.SQLException {
208 XBoundComponent bound = UnoRuntime.queryInterface(
209 XBoundComponent.class, ctrl);
210 XResultSetUpdate update = UnoRuntime.queryInterface(
211 XResultSetUpdate.class,
212 formLoaderF);
214 bound.commit();
215 update.updateRow();
218 public boolean wasCommited() throws com.sun.star.uno.Exception {
219 formLoaderF.reload();
221 Integer getT = (Integer) ps.getPropertyValue("Time");
223 return (getT != null) &&
224 (Math.abs(getT.intValue() - lastTime) < 100);
227 } // finish class OTimeModel