/**************************************************************
*
* 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 ifc.form;
import lib.MultiPropertyTest;
import util.utils;
import com.sun.star.form.XLoadable;
import com.sun.star.uno.XInterface;
/**
* Testing com.sun.star.form.DataAwareControlModel
* service properties :
*
DataField
BoundField
LabelControl
* This test need the following object relations : *
'FL'
as com.sun.star.form.XLoadable
* implementation : used to connect control to data source. 'LC'
as com.sun.star.uno.XInterface
* implementation : as value for LableControl property (see property
* documentation). 'DataAwareControlModel.NewFieldName'
:
* optional String
relation which is used
* for new value of DataFiled property.* Test is NOT multithread compilant.
* After test completion object environment has to be recreated.
* @see com.sun.star.form.DataAwareControlModel
*/
public class _DataAwareControlModel extends MultiPropertyTest {
/**
* First checks if com.sun.star.form.DataAwareControlModel
* service is supported by the object. Then load
method
* of 'FL'
relation is called to connect control model
* to data source. Because the property is READONLY its value is
* just checked to be non null. After that model is disconnected.
* Has OK status if the property has non null value.
* The following property tests are to be completed successfully before : *
DataField
: to bind the control to some database
* field.'DataAwareControlModel.NewFieldName'
*
relation is not found, then new property value is
* 'Address'. * Has OK status if the property was properly set * and no exceptions were thrown. If old and new values are equal * the test is OK if no exceptions occurred and the value remains * the same.
*/
public void _DataField() {
String relVal = (String) tEnv.getObjRelation
("DataAwareControlModel.NewFieldName") ;
final String newVal = relVal == null ? "Address" : relVal ;
testProperty("DataField", new PropertyTester() {
protected Object getNewValue(String p, Object oldVal) {
return newVal ;
}
protected void checkResult(String propName, Object oldValue,
Object newValue, Object resValue, Exception exception)
throws java.lang.Exception{
if (exception == null && oldValue.equals(newValue)) {
boolean res = true ;
if (newValue.equals(resValue)) {
log.println("Old value is equal to new value ('" +
oldValue + "'). Possibly no other suitable fields found.") ;
} else {
log.println("The value was '" + oldValue + "', set to the" +
" same value, but result is '" + resValue + "' : FAILED") ;
res = false ;
}
tRes.tested(propName, res) ;
} else {
super.checkResult(propName, oldValue, newValue,
resValue, exception);
}
}
}) ;
}
/**
* Sets the new value ('LC'
relation if null
* was before, and null
otherwise and then checks if
* the value have successfully changed.
* Has OK status if the value successfully changed. */ public void _LabelControl() { final XInterface xTextLabel = (XInterface)tEnv.getObjRelation("LC"); testProperty("LabelControl", new PropertyTester() { protected Object getNewValue(String p, Object oldVal) { if (utils.isVoid(oldVal)) return xTextLabel ; else return super.getNewValue("LabelControl",oldVal); } }) ; } /** * Forces environment recreateation. */ public void after() { disposeEnvironment() ; } }