1ef39d40dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3ef39d40dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4ef39d40dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5ef39d40dSAndrew Rist * distributed with this work for additional information 6ef39d40dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7ef39d40dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8ef39d40dSAndrew Rist * "License"); you may not use this file except in compliance 9ef39d40dSAndrew Rist * with the License. You may obtain a copy of the License at 10ef39d40dSAndrew Rist * 11ef39d40dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12ef39d40dSAndrew Rist * 13ef39d40dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14ef39d40dSAndrew Rist * software distributed under the License is distributed on an 15ef39d40dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16ef39d40dSAndrew Rist * KIND, either express or implied. See the License for the 17ef39d40dSAndrew Rist * specific language governing permissions and limitations 18ef39d40dSAndrew Rist * under the License. 19ef39d40dSAndrew Rist * 20ef39d40dSAndrew Rist *************************************************************/ 21ef39d40dSAndrew Rist 22ef39d40dSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir package ifc.form; 25cdf0e10cSrcweir 26cdf0e10cSrcweir import lib.MultiPropertyTest; 27cdf0e10cSrcweir import util.utils; 28cdf0e10cSrcweir 29cdf0e10cSrcweir import com.sun.star.form.XLoadable; 30cdf0e10cSrcweir import com.sun.star.uno.XInterface; 31cdf0e10cSrcweir 32cdf0e10cSrcweir /** 33cdf0e10cSrcweir * Testing <code>com.sun.star.form.DataAwareControlModel</code> 34cdf0e10cSrcweir * service properties : 35cdf0e10cSrcweir * <ul> 36cdf0e10cSrcweir * <li><code> DataField</code></li> 37cdf0e10cSrcweir * <li><code> BoundField</code></li> 38cdf0e10cSrcweir * <li><code> LabelControl</code></li> 39cdf0e10cSrcweir * </ul> <p> 40cdf0e10cSrcweir * This test need the following object relations : 41cdf0e10cSrcweir * <ul> 42cdf0e10cSrcweir * <li> <code>'FL'</code> as <code>com.sun.star.form.XLoadable</code> 43cdf0e10cSrcweir * implementation : used to connect control to data source. </li> 44cdf0e10cSrcweir * <li> <code>'LC'</code> as <code>com.sun.star.uno.XInterface</code> 45cdf0e10cSrcweir * implementation : as value for LableControl property (see property 46cdf0e10cSrcweir * documentation). </li> 47cdf0e10cSrcweir * <li> <code>'DataAwareControlModel.NewFieldName'</code> : 48cdf0e10cSrcweir * <b>optional</b> <code>String</code> relation which is used 49*8aad49dcSJohn Bampton * for new value of DataFiled property.</li> 50cdf0e10cSrcweir * <ul> <p> 51cdf0e10cSrcweir * Test is <b> NOT </b> multithread compilant. <p> 52cdf0e10cSrcweir * After test completion object environment has to be recreated. 53cdf0e10cSrcweir * @see com.sun.star.form.DataAwareControlModel 54cdf0e10cSrcweir */ 55cdf0e10cSrcweir public class _DataAwareControlModel extends MultiPropertyTest { 56cdf0e10cSrcweir 57cdf0e10cSrcweir /** 58cdf0e10cSrcweir * First checks if <code>com.sun.star.form.DataAwareControlModel</code> 59cdf0e10cSrcweir * service is supported by the object. Then <code>load</code> method 60cdf0e10cSrcweir * of <code>'FL'</code> relation is called to connect control model 61cdf0e10cSrcweir * to data source. Because the property is READONLY its value is 62cdf0e10cSrcweir * just checked to be non null. After that model is disconnected. <p> 63cdf0e10cSrcweir * Has <b> OK </b> status if the property has non null value. <p> 64cdf0e10cSrcweir * The following property tests are to be completed successfully before : 65cdf0e10cSrcweir * <ul> 66cdf0e10cSrcweir * <li> <code> DataField </code> : to bind the control to some database 67cdf0e10cSrcweir * field.</li> 68cdf0e10cSrcweir * </ul> 69cdf0e10cSrcweir */ _BoundField()70cdf0e10cSrcweir public void _BoundField() { 71cdf0e10cSrcweir requiredMethod("DataField") ; 72cdf0e10cSrcweir 73cdf0e10cSrcweir // This property is TRANSIENT and READONLY. 74cdf0e10cSrcweir boolean bResult = true; 75cdf0e10cSrcweir Object gValue = null; 76cdf0e10cSrcweir 77cdf0e10cSrcweir // get the loader to load the form 78cdf0e10cSrcweir XLoadable loader = (XLoadable) tEnv.getObjRelation("FL"); 79cdf0e10cSrcweir 80cdf0e10cSrcweir try { 81cdf0e10cSrcweir if (loader.isLoaded()) { 82cdf0e10cSrcweir loader.unload() ; 83cdf0e10cSrcweir } 84cdf0e10cSrcweir loader.load(); 85cdf0e10cSrcweir gValue = oObj.getPropertyValue("BoundField"); 86cdf0e10cSrcweir loader.unload(); 87cdf0e10cSrcweir bResult &= gValue != null; 88cdf0e10cSrcweir } catch(com.sun.star.beans.UnknownPropertyException e) { 89cdf0e10cSrcweir e.printStackTrace(log) ; 90cdf0e10cSrcweir bResult = false; 91cdf0e10cSrcweir } catch(com.sun.star.lang.WrappedTargetException e) { 92cdf0e10cSrcweir e.printStackTrace(log) ; 93cdf0e10cSrcweir bResult = false; 94cdf0e10cSrcweir } 95cdf0e10cSrcweir tRes.tested("BoundField", bResult); 96cdf0e10cSrcweir } 97cdf0e10cSrcweir 98cdf0e10cSrcweir /** 99cdf0e10cSrcweir * Sets the property to a Database field name, and then checks 100cdf0e10cSrcweir * if it was properly set. If <code>'DataAwareControlModel.NewFieldName' 101cdf0e10cSrcweir * </code> relation is not found, then new property value is 102cdf0e10cSrcweir * 'Address'. <p> 103*8aad49dcSJohn Bampton * Has <b> OK </b> status if the property was properly set 104cdf0e10cSrcweir * and no exceptions were thrown. If old and new values are equal 105bb6af6bcSPedro Giffuni * the test is OK if no exceptions occurred and the value remains 106cdf0e10cSrcweir * the same.<p> 107cdf0e10cSrcweir */ _DataField()108cdf0e10cSrcweir public void _DataField() { 109cdf0e10cSrcweir String relVal = (String) tEnv.getObjRelation 110cdf0e10cSrcweir ("DataAwareControlModel.NewFieldName") ; 111cdf0e10cSrcweir final String newVal = relVal == null ? "Address" : relVal ; 112cdf0e10cSrcweir testProperty("DataField", new PropertyTester() { 113cdf0e10cSrcweir protected Object getNewValue(String p, Object oldVal) { 114cdf0e10cSrcweir return newVal ; 115cdf0e10cSrcweir } 116cdf0e10cSrcweir protected void checkResult(String propName, Object oldValue, 117cdf0e10cSrcweir Object newValue, Object resValue, Exception exception) 118cdf0e10cSrcweir throws java.lang.Exception{ 119cdf0e10cSrcweir 120cdf0e10cSrcweir if (exception == null && oldValue.equals(newValue)) { 121cdf0e10cSrcweir boolean res = true ; 122cdf0e10cSrcweir if (newValue.equals(resValue)) { 123cdf0e10cSrcweir log.println("Old value is equal to new value ('" + 124cdf0e10cSrcweir oldValue + "'). Possibly no other suitable fields found.") ; 125cdf0e10cSrcweir } else { 126cdf0e10cSrcweir log.println("The value was '" + oldValue + "', set to the" + 127cdf0e10cSrcweir " same value, but result is '" + resValue + "' : FAILED") ; 128cdf0e10cSrcweir res = false ; 129cdf0e10cSrcweir } 130cdf0e10cSrcweir 131cdf0e10cSrcweir tRes.tested(propName, res) ; 132cdf0e10cSrcweir } else { 133cdf0e10cSrcweir super.checkResult(propName, oldValue, newValue, 134cdf0e10cSrcweir resValue, exception); 135cdf0e10cSrcweir } 136cdf0e10cSrcweir } 137cdf0e10cSrcweir }) ; 138cdf0e10cSrcweir } 139cdf0e10cSrcweir 140cdf0e10cSrcweir /** 141cdf0e10cSrcweir * Sets the new value (<code>'LC'</code> relation if <code>null</code> 142cdf0e10cSrcweir * was before, and <code> null </code> otherwise and then checks if 143cdf0e10cSrcweir * the value have successfully changed. <p> 144cdf0e10cSrcweir * Has <b>OK</b> status if the value successfully changed. 145cdf0e10cSrcweir */ _LabelControl()146cdf0e10cSrcweir public void _LabelControl() { 147cdf0e10cSrcweir final XInterface xTextLabel = (XInterface)tEnv.getObjRelation("LC"); 148cdf0e10cSrcweir 149cdf0e10cSrcweir testProperty("LabelControl", new PropertyTester() { 150cdf0e10cSrcweir protected Object getNewValue(String p, Object oldVal) { 151cdf0e10cSrcweir if (utils.isVoid(oldVal)) return xTextLabel ; 152cdf0e10cSrcweir else return super.getNewValue("LabelControl",oldVal); 153cdf0e10cSrcweir } 154cdf0e10cSrcweir }) ; 155cdf0e10cSrcweir } 156cdf0e10cSrcweir 157cdf0e10cSrcweir /** 158cdf0e10cSrcweir * Forces environment recreateation. 159cdf0e10cSrcweir */ after()160cdf0e10cSrcweir public void after() { 161cdf0e10cSrcweir disposeEnvironment() ; 162cdf0e10cSrcweir } 163cdf0e10cSrcweir } 164cdf0e10cSrcweir 165