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