merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / ifc / form / _DataAwareControlModel.java
blob6cdfb34184be80ed663bcd9e411b81ba6f73fdde
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _DataAwareControlModel.java,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package ifc.form;
33 import lib.MultiPropertyTest;
34 import util.utils;
36 import com.sun.star.form.XLoadable;
37 import com.sun.star.uno.XInterface;
39 /**
40 * Testing <code>com.sun.star.form.DataAwareControlModel</code>
41 * service properties :
42 * <ul>
43 * <li><code> DataField</code></li>
44 * <li><code> BoundField</code></li>
45 * <li><code> LabelControl</code></li>
46 * </ul> <p>
47 * This test need the following object relations :
48 * <ul>
49 * <li> <code>'FL'</code> as <code>com.sun.star.form.XLoadable</code>
50 * implementation : used to connect control to data source. </li>
51 * <li> <code>'LC'</code> as <code>com.sun.star.uno.XInterface</code>
52 * implementation : as value for LableControl property (see property
53 * documentation). </li>
54 * <li> <code>'DataAwareControlModel.NewFieldName'</code> :
55 * <b>optional</b> <code>String</code> relation which is used
56 * for new value of DataFiled proeprty.</li>
57 * <ul> <p>
58 * Test is <b> NOT </b> multithread compilant. <p>
59 * After test completion object environment has to be recreated.
60 * @see com.sun.star.form.DataAwareControlModel
62 public class _DataAwareControlModel extends MultiPropertyTest {
64 /**
65 * First checks if <code>com.sun.star.form.DataAwareControlModel</code>
66 * service is supported by the object. Then <code>load</code> method
67 * of <code>'FL'</code> relation is called to connect control model
68 * to data source. Because the property is READONLY its value is
69 * just checked to be non null. After that model is disconnected. <p>
70 * Has <b> OK </b> status if the property has non null value. <p>
71 * The following property tests are to be completed successfully before :
72 * <ul>
73 * <li> <code> DataField </code> : to bind the control to some database
74 * field.</li>
75 * </ul>
77 public void _BoundField() {
78 requiredMethod("DataField") ;
80 // This property is TRANSIENT and READONLY.
81 boolean bResult = true;
82 Object gValue = null;
84 // get the loader to load the form
85 XLoadable loader = (XLoadable) tEnv.getObjRelation("FL");
87 try {
88 if (loader.isLoaded()) {
89 loader.unload() ;
91 loader.load();
92 gValue = oObj.getPropertyValue("BoundField");
93 loader.unload();
94 bResult &= gValue != null;
95 } catch(com.sun.star.beans.UnknownPropertyException e) {
96 e.printStackTrace(log) ;
97 bResult = false;
98 } catch(com.sun.star.lang.WrappedTargetException e) {
99 e.printStackTrace(log) ;
100 bResult = false;
102 tRes.tested("BoundField", bResult);
106 * Sets the property to a Database field name, and then checks
107 * if it was properly set. If <code>'DataAwareControlModel.NewFieldName'
108 * </code> relation is not found, then new property value is
109 * 'Address'. <p>
110 * Has <b> OK </b> status if the proeprty was properly set
111 * and no exceptions were thrown. If old and new values are equal
112 * the test is OK if no exceptions occured and the value remains
113 * the same.<p>
115 public void _DataField() {
116 String relVal = (String) tEnv.getObjRelation
117 ("DataAwareControlModel.NewFieldName") ;
118 final String newVal = relVal == null ? "Address" : relVal ;
119 testProperty("DataField", new PropertyTester() {
120 protected Object getNewValue(String p, Object oldVal) {
121 return newVal ;
123 protected void checkResult(String propName, Object oldValue,
124 Object newValue, Object resValue, Exception exception)
125 throws java.lang.Exception{
127 if (exception == null && oldValue.equals(newValue)) {
128 boolean res = true ;
129 if (newValue.equals(resValue)) {
130 log.println("Old value is equal to new value ('" +
131 oldValue + "'). Possibly no other suitable fields found.") ;
132 } else {
133 log.println("The value was '" + oldValue + "', set to the" +
134 " same value, but result is '" + resValue + "' : FAILED") ;
135 res = false ;
138 tRes.tested(propName, res) ;
139 } else {
140 super.checkResult(propName, oldValue, newValue,
141 resValue, exception);
144 }) ;
148 * Sets the new value (<code>'LC'</code> relation if <code>null</code>
149 * was before, and <code> null </code> otherwise and then checks if
150 * the value have successfully changed. <p>
151 * Has <b>OK</b> status if the value successfully changed.
153 public void _LabelControl() {
154 final XInterface xTextLabel = (XInterface)tEnv.getObjRelation("LC");
156 testProperty("LabelControl", new PropertyTester() {
157 protected Object getNewValue(String p, Object oldVal) {
158 if (utils.isVoid(oldVal)) return xTextLabel ;
159 else return super.getNewValue("LabelControl",oldVal);
161 }) ;
165 * Forces environment recreateation.
167 public void after() {
168 disposeEnvironment() ;