bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _forms / OListBoxModel.java
blob38f92a2cdb7c3acc401a8b13609471923e0a50d8
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;
26 import com.sun.star.sdbc.SQLException;
27 import com.sun.star.sdbc.XResultSetUpdate;
28 import com.sun.star.uno.Exception;
29 import com.sun.star.uno.UnoRuntime;
30 import com.sun.star.uno.XInterface;
31 import ifc.form._XUpdateBroadcaster.UpdateChecker;
32 import java.io.PrintWriter;
33 import lib.TestEnvironment;
34 import lib.TestParameters;
35 import util.DBTools;
38 /**
39 * Test for object which is represented by service
40 * <code>com.sun.star.form.component.DatabaseListBox</code>. <p>
41 * Object implements the following interfaces :
42 * <ul>
43 * <li> <code>com::sun::star::io::XPersistObject</code></li>
44 * <li> <code>com::sun::star::awt::UnoControlListBoxModel</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::form::component::ListBox</code></li>
49 * <li> <code>com::sun::star::beans::XFastPropertySet</code></li>
50 * <li> <code>com::sun::star::beans::XMultiPropertySet</code></li>
51 * <li> <code>com::sun::star::form::XUpdateBroadcaster</code></li>
52 * <li> <code>com::sun::star::form::DataAwareControlModel</code></li>
53 * <li> <code>com::sun::star::beans::XPropertyState</code></li>
54 * <li> <code>com::sun::star::form::FormControlModel</code></li>
55 * <li> <code>com::sun::star::container::XNamed</code></li>
56 * <li> <code>com::sun::star::lang::XComponent</code></li>
57 * <li> <code>com::sun::star::lang::XEventListener</code></li>
58 * <li> <code>com::sun::star::beans::XPropertyAccess</code></li>
59 * <li> <code>com::sun::star::beans::XPropertyContainer</code></li>
60 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
61 * <li> <code>com::sun::star::form::XLoadListener</code></li>
62 * <li> <code>com::sun::star::form::component::DatabaseListBox</code></li>
63 * <li> <code>com::sun::star::container::XChild</code></li>
64 * </ul> <p>
65 * This object test <b> is NOT </b> designed to be run in several
66 * threads concurently.
67 * @see com.sun.star.io.XPersistObject
68 * @see com.sun.star.awt.UnoControlListBoxModel
69 * @see com.sun.star.form.XReset
70 * @see com.sun.star.form.XBoundComponent
71 * @see com.sun.star.form.FormComponent
72 * @see com.sun.star.form.component.ListBox
73 * @see com.sun.star.beans.XFastPropertySet
74 * @see com.sun.star.beans.XMultiPropertySet
75 * @see com.sun.star.form.XUpdateBroadcaster
76 * @see com.sun.star.form.DataAwareControlModel
77 * @see com.sun.star.beans.XPropertyState
78 * @see com.sun.star.form
79 * @see com.sun.star.container.XNamed
80 * @see com.sun.star.lang.XComponent
81 * @see com.sun.star.lang.XEventListener
82 * @see com.sun.star.beans.XPropertyAccess
83 * @see com.sun.star.beans.XPropertyContainer
84 * @see com.sun.star.beans.XPropertySet
85 * @see com.sun.star.form.XLoadListener
86 * @see com.sun.star.form.component.DatabaseListBox
87 * @see com.sun.star.container.XChild
88 * @see ifc.io._XPersistObject
89 * @see ifc.awt._UnoControlListBoxModel
90 * @see ifc.form._XReset
91 * @see ifc.form._XBoundComponent
92 * @see ifc.form._FormComponent
93 * @see ifc.form.component._ListBox
94 * @see ifc.beans._XFastPropertySet
95 * @see ifc.beans._XMultiPropertySet
96 * @see ifc.form._XUpdateBroadcaster
97 * @see ifc.form._DataAwareControlModel
98 * @see ifc.beans._XPropertyState
99 * @see ifc.form._FormControlModel
100 * @see ifc.container._XNamed
101 * @see ifc.lang._XComponent
102 * @see ifc.lang._XEventListener
103 * @see ifc.beans._XPropertySet
104 * @see ifc.form._XLoadListener
105 * @see ifc.form.component._DatabaseListBox
106 * @see ifc.container._XChild
108 public class OListBoxModel extends GenericModelTest {
110 * Set some member variable of the super class <CODE>GenericModelTest</CODE>:
111 * <pre>
112 * super.m_ChangePropertyName = "Date";
113 * super.m_kindOfControl="DateField";
114 * super.m_ObjectName = "stardiv.one.form.component.DateField";
115 * NamedValue DataField = new NamedValue();
116 * DataField.Name = "DataField";
117 * DataField.Value = DBTools.TST_DATE_F;
118 * super.m_propertiesToSet.add(DataField);
120 * NamedValue ListSource = new NamedValue();
121 * ListSource.Name = "ListSource";
122 * ListSource.Value = new String[] {
123 * "OListBoxModel1", "OListBoxModel2", "OListBoxModel3"};
124 * super.m_propertiesToSet.add(ListSource);
125 * super.m_LCShape_Type = "FixedText";
126 * </pre>
127 * Then <CODE>super.initialize()</CODE> was called.
128 * @param tParam the test parameter
129 * @param log the log writer
131 protected void initialize(TestParameters tParam, PrintWriter log) {
133 super.initialize(tParam, log);
135 super.m_ChangePropertyName = "SelectedItems";
137 super.m_kindOfControl="ListBox";
139 super.m_ObjectName = "stardiv.one.form.component.ListBox";
141 NamedValue DataField = new NamedValue();
142 DataField.Name = "DataField";
143 DataField.Value = DBTools.TST_STRING_F;
144 super.m_propertiesToSet.add(DataField);
146 NamedValue ListSource = new NamedValue();
147 ListSource.Name = "ListSource";
148 ListSource.Value = new String[] {
149 "OListBoxModel1", "OListBoxModel2", "OListBoxModel3"};
150 super.m_propertiesToSet.add(ListSource);
152 super.m_LCShape_Type = "FixedText";
156 * calls <CODE>cleanup()</CODE> from it's super class
157 * @param tParam the test parameter
158 * @param log the log writer
160 protected void cleanup(TestParameters tParam, PrintWriter log) {
161 super.cleanup(tParam, log);
166 * calls <CODE>createTestEnvironment()</CODE> from it's super class
167 * This test uses not the generic implementaion of <CODE>cecker()</CODE> of its
168 * super class. This tests uses its own implementation of <CODE>checker()</CODE>
169 * to test <CODE>com::sun::star::form::XUpdateBroadcaster</CODE>
170 * @param Param the test parameter
171 * @param log the log writer
172 * @return lib.TestEnvironment
174 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param,
175 PrintWriter log) {
176 TestEnvironment tEnv = super.createTestEnvironment(Param, log);
178 tEnv.addObjRelation("XUpdateBroadcaster.Checker",
179 new Checker(m_XFormLoader, m_XPS, m_XCtrl, m_ChangePropertyName, m_ChangePropertyValue));
180 return tEnv;
183 static class Checker implements UpdateChecker {
184 private short lastItem = (short) 0;
185 XLoadable formLoaderF = null;
186 XPropertySet ps = null;
187 XInterface ctrl = null;
188 String ChangePropertyName = null;
189 Object ChangePropertyValue = null;
191 public Checker(XLoadable xl, XPropertySet ps, XInterface ctrl, String ChangePropertyName, Object ChangePropertyValue) {
192 formLoaderF = xl;
193 this.ps = ps;
194 this.ctrl = ctrl;
195 this.ChangePropertyName=ChangePropertyName;
196 this.ChangePropertyValue=ChangePropertyValue;
199 public void update() throws Exception {
200 if (!formLoaderF.isLoaded()) {
201 formLoaderF.load();
203 lastItem = (short) (1 - lastItem);
204 ps.setPropertyValue(ChangePropertyName, new short[] { lastItem });
207 public void commit() throws 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 Exception {
219 formLoaderF.reload();
221 short[] getS = (short[]) ps.getPropertyValue(ChangePropertyName);
223 return (getS.length > 0) && (lastItem == getS[0]);
227 } // finish class OListBoxModel