/**************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*************************************************************/
package mod._forms;
import com.sun.star.beans.NamedValue;
import com.sun.star.beans.PropertyValue;
import com.sun.star.container.XIndexAccess;
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.XPropertySet;
import com.sun.star.drawing.XControlShape;
import com.sun.star.drawing.XShape;
import com.sun.star.form.XBoundComponent;
import com.sun.star.form.XForm;
import com.sun.star.form.XLoadable;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.lang.XComponent;
import com.sun.star.sdbc.XConnection;
import com.sun.star.sdbc.XResultSetUpdate;
import com.sun.star.sdb.XDocumentDataSource;
import com.sun.star.text.XTextDocument;
import com.sun.star.uno.AnyConverter;
import com.sun.star.uno.Type;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XInterface;
import com.sun.star.util.XCloseable;
import java.util.ArrayList;
import lib.Status;
import util.utils;
/**
* Test for object which is represented by service
* com.sun.star.form.component.DateField
.
* Object implements the following interfaces : *
com::sun::star::io::XPersistObject
com::sun::star::awt::UnoControlDateFieldModel
com::sun::star::form::XReset
com::sun::star::form::XBoundComponent
com::sun::star::form::FormComponent
com::sun::star::form::component::DateField
com::sun::star::beans::XFastPropertySet
com::sun::star::beans::XMultiPropertySet
com::sun::star::form::XUpdateBroadcaster
com::sun::star::form::DataAwareControlModel
com::sun::star::beans::XPropertyState
com::sun::star::form::FormControlModel
com::sun::star::container::XNamed
com::sun::star::lang::XComponent
com::sun::star::lang::XEventListener
com::sun::star::beans::XPropertyAccess
com::sun::star::beans::XPropertyContainer
com::sun::star::beans::XPropertySet
com::sun::star::form::XLoadListener
com::sun::star::container::XChild
* This object test is NOT designed to be run in several
* threads concurently.
* @see com.sun.star.io.XPersistObject
* @see com.sun.star.awt.UnoControlDateFieldModel
* @see com.sun.star.form.XReset
* @see com.sun.star.form.XBoundComponent
* @see com.sun.star.form.FormComponent
* @see com.sun.star.form.component.DateField
* @see com.sun.star.beans.XFastPropertySet
* @see com.sun.star.beans.XMultiPropertySet
* @see com.sun.star.form.XUpdateBroadcaster
* @see com.sun.star.form.DataAwareControlModel
* @see com.sun.star.beans.XPropertyState
* @see com.sun.star.form
* @see com.sun.star.container.XNamed
* @see com.sun.star.lang.XComponent
* @see com.sun.star.lang.XEventListener
* @see com.sun.star.beans.XPropertyAccess
* @see com.sun.star.beans.XPropertyContainer
* @see com.sun.star.beans.XPropertySet
* @see com.sun.star.form.XLoadListener
* @see com.sun.star.container.XChild
* @see ifc.io._XPersistObject
* @see ifc.awt._UnoControlDateFieldModel
* @see ifc.form._XReset
* @see ifc.form._XBoundComponent
* @see ifc.form._FormComponent
* @see ifc.form.component._DateField
* @see ifc.beans._XFastPropertySet
* @see ifc.beans._XMultiPropertySet
* @see ifc.form._XUpdateBroadcaster
* @see ifc.form._DataAwareControlModel
* @see ifc.beans._XPropertyState
* @see ifc.form._FormControlModel
* @see ifc.container._XNamed
* @see ifc.lang._XComponent
* @see ifc.lang._XEventListener
* @see ifc.beans._XPropertySet
* @see ifc.form._XLoadListener
* @see ifc.container._XChild
*/
public class GenericModelTest extends TestCase {
private static XTextDocument m_xTextDoc;
private static Object m_dbSrc = null;
private static DBTools.DataSourceInfo m_srcInf = null;
/**
* This is the name of the Data Base which the test uses: "APITestDatabase"
*/
protected final static String m_dbSourceName = "APITestDatabase";
protected final static String m_TestDB = "TestDB";
private DBTools m_dbTools = null;
private static boolean m_ConnectionColsed = false;
/**
* descibes the kind of the shape which should be created.
* Example: m_kindOfshape=DateFiled
*/
public static String m_kindOfControl = null;
/**
* If your object needs some special propery values you can specify them with this
* ArrayList
. You have to add a NamedValue
to this list.
* Example:
* NamedValue myProp = new NamedValue();
* myProp.Name = "Test";
* myProp.Value = "My special Value";
* m_propertiesToSet.add(myProp);
*/
public static ArrayList m_propertiesToSet = new ArrayList();
/**
* This variable contains the name of the property which should be changed while
* interface com::sun::star::form::XUpdateBroadcaster
is tested. The
* interface test needs the ObjectRelation
* "XUpdateBroadcaster.Checker" which is a ifc.form._XUpdateBroadcaster.UpdateChecker
.
* @see ifc.form._XUpdateBroadcaster.UpdateChecker
* @see ifc.form._XUpdateBroadcaster
*/
public static String m_ChangePropertyName = null;
/**
* This variable contains the value the property should be set while
* interface com::sun::star::form::XUpdateBroadcaster
is tested.
* The interface test needs the ObjectRelation
* "XUpdateBroadcaster.Checker" which is a ifc.form._XUpdateBroadcaster.UpdateChecker
.
* Normaly the Checker
uses util.ValueChanger
to change
* the value of the property. If the current of this property is NULL the
* ValueChanger
is unable to change the value. In this case the value
* of this variable was used.
*/
public static Object m_ChangePropertyValue = null;
/**
* This variable contains the implelemtation name of the object.
*/
public static String m_ObjectName = null;
/**
* For local implementaions of Checker
this variable contains the
* FormLoader
*/
protected static XLoadable m_XFormLoader = null;
/**
* For local implementaions of Checker
this variable contains the
* XPropertySet
*/
protected static XPropertySet m_XPS = null;
/**
* For local implementaions of Checker
this variable contains the
* Control
*/
protected static XInterface m_XCtrl = null;
/**
* The insterface test of ifc.form._DataWareControlModel
expects an
* object relation 'LC'
. This is a XControlModel
of a shape.
* This variable contains the kind of shape to create for the interface test,
* f.e. "FixedText"
* @see ifc.form._DataAwareControlModel
*/
protected static String m_LCShape_Type = null;
protected static String m_XPropertyAccess_propertyToChange = "HelpText";
protected static String m_XPropertyContainer_propertyNotRemovable = "HelpText";
/**
* If this variable is true some more debug info was logged. It was setted by the parameter variable
* debug_is_active
*/
protected static boolean debug = false;
/**
* Creates Writer document where controls are placed.
* @param tParam the test paremter
* @param log the log writer
*/
protected void initialize(TestParameters tParam, PrintWriter log) {
log.println("creating a textdocument");
m_xTextDoc = WriterTools.createTextDoc(((XMultiServiceFactory) tParam.getMSF()));
m_ConnectionColsed = false;
debug = tParam.getBool(util.PropertyName.DEBUG_IS_ACTIVE);
m_propertiesToSet.clear();
}
/**
* close the connection
* close the data source
* close the document
* revoke the data source
* @param tParam the test parameter
* @param log the log writer
*/
protected void cleanup(TestParameters tParam, PrintWriter log) {
log.println("closing connection...");
// some interface tests call cleanup to reset the environment. If such
// a test is the last one cleanup was called twice. The second call
// causes then nasty exceptions...
if (m_ConnectionColsed) return;
try {
XIndexAccess forms = UnoRuntime.queryInterface( XIndexAccess.class,
FormTools.getForms( WriterTools.getDrawPage( m_xTextDoc ) ) );
XForm myForm = (XForm) AnyConverter.toObject(new Type(XForm.class),
forms.getByIndex(0));
if (debug){
if (myForm == null){
log.println("ERROR: could not get 'Standard' from drawpage!");
}
log.println("the draw page contains following elemtens:");
String[] elements = FormTools.getForms(WriterTools.getDrawPage(m_xTextDoc)).getElementNames();
for (int i = 0; i< elements.length; i++){
log.println("Element[" + i + "] :" + elements[i]);
}
}
XPropertySet xSetProp = UnoRuntime.queryInterface( XPropertySet.class, myForm );
XConnection connection = UnoRuntime.queryInterface( XConnection.class, xSetProp.getPropertyValue( "ActiveConnection" ) );
if ( connection == null )
{
if ( debug )
log.println("ERROR: could not get property 'ActiveConnection' from the XForm");
}
else
{
connection.close();
}
} catch (Exception e) {
log.println("ERROR: Can't close the connection: " + e.toString());
e.printStackTrace( log );
}
log.println("closing data source...");
try {
XCloseable closer = (XCloseable) UnoRuntime.queryInterface(
XCloseable.class, m_dbSrc);
if ( closer == null )
{
XDocumentDataSource dataSource = (XDocumentDataSource)UnoRuntime.queryInterface(
XDocumentDataSource.class, m_dbSrc);
if ( dataSource != null )
closer = (XCloseable) UnoRuntime.queryInterface(
XCloseable.class, dataSource.getDatabaseDocument() );
}
if (debug && closer==null){
log.println("ERROR: couldn't get 'XCloseable' from DataSource");
}
closer.close(true);
} catch (com.sun.star.util.CloseVetoException e) {
log.println("ERROR: couldn't close data source: " + e.toString());
} catch (com.sun.star.lang.DisposedException e) {
log.println("ERROR: couldn't close data source: " + e.toString());
} catch (Exception e) {
log.println("ERROR: couldn't close data source: " + e.toString());
}
log.println("disposing data source...");
try {
XComponent dataSourceComp = (XComponent)UnoRuntime.queryInterface(
XComponent.class, m_dbSrc);
dataSourceComp.dispose();
}
catch (Exception e) {
log.println("couldn't dispose the data source");
}
log.println("closing document...");
try {
XCloseable closer = (XCloseable) UnoRuntime.queryInterface(
XCloseable.class, m_xTextDoc);
closer.close(true);
} catch (com.sun.star.util.CloseVetoException e) {
log.println("ERROR: couldn't close document: " + e.toString());
} catch (com.sun.star.lang.DisposedException e) {
log.println("ERROR: couldn't close document: " + e.toString());
} catch (Exception e) {
log.println("ERROR: couldn't close document: " + e.toString());
}
log.println("revoking data source...");
try {
m_dbTools.revokeDB(m_dbSourceName);
} catch (com.sun.star.container.NoSuchElementException e){
} catch (com.sun.star.uno.Exception e) {
log.println("ERROR: Error while object test cleaning up: " + e.toString());
}
m_ConnectionColsed = true;
}
/**
* Creating a Testenvironment for the interfaces to be tested.
* First TestDB
database is registered.
* Creates DateField in the Form, then binds it to TestDB
* database and returns Field's control.
* Object relations created : *
'OBJNAME'
for
* {@link ifc.io._XPersistObject} : name of service which is
* represented by this object. 'LC'
for {@link ifc.form._DataAwareControlModel}.
* Specifies the value for LabelControl property. It is
* FixedText
component added to the document.'FL'
for
* {@link ifc.form._DataAwareControlModel} interface.
* Specifies XLoadable implementation which connects form to
* the data source.'XUpdateBroadcaster.Checker'
:
* _XUpdateBroadcaster.UpdateChecker
interface implementation
* which can update, commit data and check if the data was successfully
* committed.'DataAwareControlModel.NewFieldName'
: for
* com.sun.star.form.DataAwareControlModel
service
* which contains new name of the field ('_DATE') to bind control to.
* 'XFastPropertySet.ExcludeProps'
: for
* com.sun.star.beans.XFastPropertySet
interface
* the property FormatKey can have only restricted set of values.
*