Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / ifc / form / _DataAwareControlModel.java
blob7cd6bf913afe5266ed67ffaaaa1299ad49b7ea5d
1 /*
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 .
19 package ifc.form;
21 import lib.MultiPropertyTest;
22 import util.utils;
24 import com.sun.star.form.XLoadable;
25 import com.sun.star.uno.XInterface;
27 /**
28 * Testing <code>com.sun.star.form.DataAwareControlModel</code>
29 * service properties :
30 * <ul>
31 * <li><code> DataField</code></li>
32 * <li><code> BoundField</code></li>
33 * <li><code> LabelControl</code></li>
34 * </ul> <p>
35 * This test need the following object relations :
36 * <ul>
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>
45 * <ul> <p>
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 {
52 /**
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 :
60 * <ul>
61 * <li> <code> DataField </code> : to bind the control to some database
62 * field.</li>
63 * </ul>
65 public void _BoundField() {
66 requiredMethod("DataField") ;
68 // This property is TRANSIENT and READONLY.
69 boolean bResult = true;
70 Object gValue = null;
72 // get the loader to load the form
73 XLoadable loader = (XLoadable) tEnv.getObjRelation("FL");
75 try {
76 if (loader.isLoaded()) {
77 loader.unload() ;
79 loader.load();
80 gValue = oObj.getPropertyValue("BoundField");
81 loader.unload();
82 bResult &= gValue != null;
83 } catch(com.sun.star.beans.UnknownPropertyException e) {
84 e.printStackTrace(log) ;
85 bResult = false;
86 } catch(com.sun.star.lang.WrappedTargetException e) {
87 e.printStackTrace(log) ;
88 bResult = false;
90 tRes.tested("BoundField", bResult);
93 /**
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
97 * 'Address'. <p>
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
101 * the same.<p>
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() {
108 @Override
109 protected Object getNewValue(String p, Object oldVal) {
110 return newVal ;
112 @Override
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)) {
118 boolean res = true ;
119 if (newValue.equals(resValue)) {
120 log.println("Old value is equal to new value ('" +
121 oldValue + "'). Possibly no other suitable fields found.") ;
122 } else {
123 log.println("The value was '" + oldValue + "', set to the" +
124 " same value, but result is '" + resValue + "' : FAILED") ;
125 res = false ;
128 tRes.tested(propName, res) ;
129 } else {
130 super.checkResult(propName, oldValue, newValue,
131 resValue, exception);
134 }) ;
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() {
147 @Override
148 protected Object getNewValue(String p, Object oldVal) {
149 if (utils.isVoid(oldVal)) return xTextLabel ;
150 else return super.getNewValue("LabelControl",oldVal);
152 }) ;
156 * Forces environment recreateation.
158 @Override
159 public void after() {
160 disposeEnvironment() ;