Kaydet (Commit) b77e5e2c authored tarafından Vladimir Glazounov's avatar Vladimir Glazounov

INTEGRATION: CWS qadev21 (1.3.106); FILE MERGED

2005/01/19 17:33:43 cn 1.3.106.1: #i40688# redesign of test: uses GenericModelTest
üst 5dfb4800
......@@ -2,9 +2,9 @@
*
* $RCSfile: OListBoxModel.java,v $
*
* $Revision: 1.3 $
* $Revision: 1.4 $
*
* last change:$Date: 2003-09-08 11:50:19 $
* last change:$Date: 2005-02-24 17:43:35 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
......@@ -60,27 +60,22 @@
************************************************************************/
package mod._forms;
import java.io.PrintWriter;
import lib.StatusException;
import lib.TestCase;
import lib.TestEnvironment;
import lib.TestParameters;
import util.DBTools;
import util.FormTools;
import util.WriterTools;
import com.sun.star.beans.NamedValue;
import com.sun.star.beans.XPropertySet;
import com.sun.star.drawing.XControlShape;
import com.sun.star.drawing.XShape;
import com.sun.star.form.XBoundComponent;
import com.sun.star.form.XLoadable;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.sdbc.SQLException;
import com.sun.star.sdbc.XResultSetUpdate;
import com.sun.star.text.XTextDocument;
import com.sun.star.uno.Exception;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XInterface;
import com.sun.star.util.XCloseable;
import ifc.form._XUpdateBroadcaster.UpdateChecker;
import java.io.PrintWriter;
import lib.TestEnvironment;
import lib.TestParameters;
import util.DBTools;
/**
......@@ -149,148 +144,107 @@ import com.sun.star.util.XCloseable;
* @see ifc.form.component._DatabaseListBox
* @see ifc.container._XChild
*/
public class OListBoxModel extends TestCase {
XTextDocument xTextDoc;
public class OListBoxModel extends GenericModelTest {
/**
* Creates Writer document where controls are placed.
*/
* Set some member variable of the super class <CODE>GenericModelTest</CODE>:
* <pre>
* super.m_ChangePropertyName = "Date";
* super.m_kindOfControl="DateField";
* super.m_ObjectName = "stardiv.one.form.component.DateField";
* NamedValue DataField = new NamedValue();
* DataField.Name = "DataField";
* DataField.Value = DBTools.TST_DATE_F;
* super.m_propertiesToSet.add(DataField);
*
* NamedValue ListSource = new NamedValue();
* ListSource.Name = "ListSource";
* ListSource.Value = new String[] {
* "OListBoxModel1", "OListBoxModel2", "OListBoxModel3"};
* super.m_propertiesToSet.add(ListSource);
* super.m_LCShape_Type = "FixedText";
* </pre>
* Then <CODE>super.initialize()</CODE> was called.
* @param tParam the test parameter
* @param log the log writer
*/
protected void initialize(TestParameters tParam, PrintWriter log) {
log.println("creating a text document");
xTextDoc = WriterTools.createTextDoc(((XMultiServiceFactory) tParam.getMSF()));
}
/**
* Disposes Writer document.
*/
protected void cleanup(TestParameters tParam, PrintWriter log) {
log.println(" disposing xTextDoc ");
try {
XCloseable closer = (XCloseable) UnoRuntime.queryInterface(
XCloseable.class, xTextDoc);
closer.close(true);
} catch (com.sun.star.util.CloseVetoException e) {
log.println("couldn't close document");
} catch (com.sun.star.lang.DisposedException e) {
log.println("couldn't close document");
}
}
/**
* Creating a Testenvironment for the interfaces to be tested.
* First <code>TestDB</code> database is registered.
* Creates ListBox in the Form, then binds it to TestDB
* database and returns Field's control. <p>
* Object relations created :
* <ul>
* <li> <code>'OBJNAME'</code> for
* {@link ifc.io._XPersistObject} : name of service which is
* represented by this object. </li>
* <li> <code>'LC'</code> for {@link ifc.form._DataAwareControlModel}.
* Specifies the value for LabelControl property. It is
* <code>FixedText</code> component added to the document.</li>
* <li> <code>'FL'</code> for
* {@link ifc.form._DataAwareControlModel} interface.
* Specifies XLoadable implementation which connects form to
* the data source.</li>
* <li> <code>'XUpdateBroadcaster.Checker'</code> : <code>
* _XUpdateBroadcaster.UpdateChecker</code> interface implementation
* which can update, commit data and check if the data was successfully
* commited.</li>
* <li> <code>'DataAwareControlModel.NewFieldName'</code> : for
* <code>com.sun.star.form.DataAwareControlModel</code> service
* which contains new name of the field to bind control to.
* </li>
* </ul>
* @see ifc.form._XUpdateBroadcaster
*/
protected synchronized TestEnvironment createTestEnvironment(TestParameters Param,
PrintWriter log) {
XInterface oObj = null;
super.m_ChangePropertyName = "SelectedItems";
// creation of testobject here
// first we write what we are intend to do to log file
log.println("creating a test environment");
super.m_kindOfControl="ListBox";
String objName = "ListBox";
super.m_ObjectName = "stardiv.one.form.component.ListBox";
//get ListBoxModel
XControlShape aShape = FormTools.createControlShape(xTextDoc, 3000,
4500, 15000, 10000,
objName);
NamedValue DataField = new NamedValue();
DataField.Name = "DataField";
DataField.Value = DBTools.TST_STRING_F;
super.m_propertiesToSet.add(DataField);
WriterTools.getDrawPage(xTextDoc).add((XShape) aShape);
oObj = aShape.getControl();
NamedValue ListSource = new NamedValue();
ListSource.Name = "ListSource";
ListSource.Value = new String[] {
"OListBoxModel1", "OListBoxModel2", "OListBoxModel3"};
super.m_propertiesToSet.add(ListSource);
XLoadable formLoader = null;
super.m_LCShape_Type = "FixedText";
try {
DBTools dbTools = new DBTools(((XMultiServiceFactory) Param.getMSF()));
dbTools.registerTestDB((String) System.getProperty("DOCPTH"));
super.initialize(tParam, log);
formLoader = FormTools.bindForm(xTextDoc, "APITestDatabase",
"TestDB");
} catch (com.sun.star.uno.Exception e) {
log.println("!!! Can't access TestDB !!!");
e.printStackTrace(log);
throw new StatusException("Can't access TestDB", e);
}
final XPropertySet ps = (XPropertySet) UnoRuntime.queryInterface(
XPropertySet.class, oObj);
try {
ps.setPropertyValue("DataField", DBTools.TST_STRING_F);
ps.setPropertyValue("ListSource",
new String[] {
"OListBoxModel1", "OListBoxModel2", "OListBoxModel3"
});
} catch (com.sun.star.uno.Exception e) {
// Some exception occures.FAILED
e.printStackTrace(log);
throw new StatusException("Couldn't set Default Date", e);
}
aShape = FormTools.createControlShape(xTextDoc, 6000, 4500, 15000,
10000, "FixedText");
WriterTools.getDrawPage(xTextDoc).add((XShape) aShape);
TestEnvironment tEnv = new TestEnvironment(oObj);
tEnv.addObjRelation("OBJNAME", "stardiv.one.form.component." +
objName);
// adding relations for DataAwareControlModel service
tEnv.addObjRelation("DataAwareControlModel.NewFieldName",
DBTools.TST_STRING_F);
tEnv.addObjRelation("FL", formLoader);
tEnv.addObjRelation("LC", aShape.getControl());
}
/**
* calls <CODE>cleanup()</CODE> from it's super class
* @param tParam the test parameter
* @param log the log writer
*/
protected void cleanup(TestParameters tParam, PrintWriter log) {
super.cleanup(tParam, log);
}
//adding ObjRelation for XPersistObject
tEnv.addObjRelation("PSEUDOPERSISTENT", new Boolean(true));
// adding relation for XUpdateBroadcaster
final XInterface ctrl = oObj;
final XLoadable formLoaderF = formLoader;
/**
* calls <CODE>createTestEnvironment()</CODE> from it's super class
* This test uses not the generic implementaion of <CODE>cecker()</CODE> of its
* super class. This tests uses its own implementation of <CODE>checker()</CODE>
* to test <CODE>com::sun::star::form::XUpdateBroadcaster</CODE>
* @param Param the test parameter
* @param log the log writer
* @return lib.TestEnvironment
*/
protected synchronized TestEnvironment createTestEnvironment(TestParameters Param,
PrintWriter log) {
TestEnvironment tEnv = super.createTestEnvironment(Param, log);
tEnv.addObjRelation("XUpdateBroadcaster.Checker",
new ifc.form._XUpdateBroadcaster.UpdateChecker() {
new Checker(m_XFormLoader, m_XPS, m_XCtrl, m_ChangePropertyName, m_ChangePropertyValue));
return tEnv;
}
static class Checker implements UpdateChecker {
private short lastItem = (short) 0;
XLoadable formLoaderF = null;
XPropertySet ps = null;
XInterface ctrl = null;
String ChangePropertyName = null;
Object ChangePropertyValue = null;
public Checker(XLoadable xl, XPropertySet ps, XInterface ctrl, String ChangePropertyName, Object ChangePropertyValue) {
formLoaderF = xl;
this.ps = ps;
this.ctrl = ctrl;
this.ChangePropertyName=ChangePropertyName;
this.ChangePropertyValue=ChangePropertyValue;
}
public void update() throws com.sun.star.uno.Exception {
public void update() throws Exception {
if (!formLoaderF.isLoaded()) {
formLoaderF.load();
}
lastItem = (short) (1 - lastItem);
ps.setPropertyValue("SelectedItems", new short[] { lastItem });
ps.setPropertyValue(ChangePropertyName, new short[] { lastItem });
}
public void commit() throws com.sun.star.sdbc.SQLException {
public void commit() throws SQLException {
XBoundComponent bound = (XBoundComponent) UnoRuntime.queryInterface(
XBoundComponent.class, ctrl);
XResultSetUpdate update = (XResultSetUpdate) UnoRuntime.queryInterface(
......@@ -301,15 +255,13 @@ public class OListBoxModel extends TestCase {
update.updateRow();
}
public boolean wasCommited() throws com.sun.star.uno.Exception {
public boolean wasCommited() throws Exception {
formLoaderF.reload();
short[] getS = (short[]) ps.getPropertyValue("SelectedItems");
short[] getS = (short[]) ps.getPropertyValue(ChangePropertyName);
return (getS.length > 0) && (lastItem == getS[0]);
}
});
}
return tEnv;
} // finish method getTestEnvironment
} // finish class OListBoxModel
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment