2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import lib
.MultiPropertyTest
;
24 import com
.sun
.star
.form
.XLoadable
;
25 import com
.sun
.star
.uno
.XInterface
;
28 * Testing <code>com.sun.star.form.DataAwareControlModel</code>
29 * service properties :
31 * <li><code> DataField</code></li>
32 * <li><code> BoundField</code></li>
33 * <li><code> LabelControl</code></li>
35 * This test need the following object relations :
37 * <li> <code>'FL'</code> as <code>com.sun.star.form.XLoadable</code>
38 * implementation : used to connect control to data source. </li>
39 * <li> <code>'LC'</code> as <code>com.sun.star.uno.XInterface</code>
40 * implementation : as value for LabelControl property (see property
41 * documentation). </li>
42 * <li> <code>'DataAwareControlModel.NewFieldName'</code> :
43 * <b>optional</b> <code>String</code> relation which is used
44 * for new value of DataField property.</li>
46 * Test is <b> NOT </b> multithread compliant. <p>
47 * After test completion object environment has to be recreated.
48 * @see com.sun.star.form.DataAwareControlModel
50 public class _DataAwareControlModel
extends MultiPropertyTest
{
53 * First checks if <code>com.sun.star.form.DataAwareControlModel</code>
54 * service is supported by the object. Then <code>load</code> method
55 * of <code>'FL'</code> relation is called to connect control model
56 * to data source. Because the property is READONLY its value is
57 * just checked to be non null. After that model is disconnected. <p>
58 * Has <b> OK </b> status if the property has non null value. <p>
59 * The following property tests are to be completed successfully before :
61 * <li> <code> DataField </code> : to bind the control to some database
65 public void _BoundField() {
66 requiredMethod("DataField") ;
68 // This property is TRANSIENT and READONLY.
69 boolean bResult
= true;
72 // get the loader to load the form
73 XLoadable loader
= (XLoadable
) tEnv
.getObjRelation("FL");
76 if (loader
.isLoaded()) {
80 gValue
= oObj
.getPropertyValue("BoundField");
82 bResult
&= gValue
!= null;
83 } catch(com
.sun
.star
.beans
.UnknownPropertyException e
) {
84 e
.printStackTrace(log
) ;
86 } catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
87 e
.printStackTrace(log
) ;
90 tRes
.tested("BoundField", bResult
);
94 * Sets the property to a Database field name, and then checks
95 * if it was properly set. If <code>'DataAwareControlModel.NewFieldName'
96 * </code> relation is not found, then new property value is
98 * Has <b> OK </b> status if the property was properly set
99 * and no exceptions were thrown. If old and new values are equal
100 * the test is OK if no exceptions occurred and the value remains
103 public void _DataField() {
104 String relVal
= (String
) tEnv
.getObjRelation
105 ("DataAwareControlModel.NewFieldName") ;
106 final String newVal
= relVal
== null ?
"Address" : relVal
;
107 testProperty("DataField", new PropertyTester() {
109 protected Object
getNewValue(String p
, Object oldVal
) {
113 protected void checkResult(String propName
, Object oldValue
,
114 Object newValue
, Object resValue
, Exception exception
)
115 throws java
.lang
.Exception
{
117 if (exception
== null && oldValue
.equals(newValue
)) {
119 if (newValue
.equals(resValue
)) {
120 log
.println("Old value is equal to new value ('" +
121 oldValue
+ "'). Possibly no other suitable fields found.") ;
123 log
.println("The value was '" + oldValue
+ "', set to the" +
124 " same value, but result is '" + resValue
+ "' : FAILED") ;
128 tRes
.tested(propName
, res
) ;
130 super.checkResult(propName
, oldValue
, newValue
,
131 resValue
, exception
);
138 * Sets the new value (<code>'LC'</code> relation if <code>null</code>
139 * was before, and <code> null </code> otherwise and then checks if
140 * the value have successfully changed. <p>
141 * Has <b>OK</b> status if the value successfully changed.
143 public void _LabelControl() {
144 final XInterface xTextLabel
= (XInterface
)tEnv
.getObjRelation("LC");
146 testProperty("LabelControl", new PropertyTester() {
148 protected Object
getNewValue(String p
, Object oldVal
) {
149 if (utils
.isVoid(oldVal
)) return xTextLabel
;
150 else return super.getNewValue("LabelControl",oldVal
);
156 * Forces environment recreation.
159 public void after() {
160 disposeEnvironment() ;