xref: /AOO41X/main/qadevOOo/tests/java/ifc/form/binding/_XBindableValue.java (revision ef39d40d3f5e66cf3f035b3e93783012b340500d)
1*ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ef39d40dSAndrew Rist  * distributed with this work for additional information
6*ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9*ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15*ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18*ef39d40dSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*ef39d40dSAndrew Rist  *************************************************************/
21*ef39d40dSAndrew Rist 
22*ef39d40dSAndrew Rist 
23cdf0e10cSrcweir package ifc.form.binding;
24cdf0e10cSrcweir 
25cdf0e10cSrcweir import com.sun.star.form.binding.XBindableValue;
26cdf0e10cSrcweir import com.sun.star.form.binding.XValueBinding;
27cdf0e10cSrcweir import com.sun.star.uno.Type;
28cdf0e10cSrcweir 
29cdf0e10cSrcweir import java.util.ArrayList;
30cdf0e10cSrcweir 
31cdf0e10cSrcweir import lib.MultiMethodTest;
32cdf0e10cSrcweir 
33cdf0e10cSrcweir 
34cdf0e10cSrcweir public class _XBindableValue extends MultiMethodTest {
35cdf0e10cSrcweir     public XBindableValue oObj;
36cdf0e10cSrcweir     protected XValueBinding xValueBinding = null;
37cdf0e10cSrcweir 
_getValueBinding()38cdf0e10cSrcweir     public void _getValueBinding() {
39cdf0e10cSrcweir         requiredMethod("setValueBinding");
40cdf0e10cSrcweir 
41cdf0e10cSrcweir         boolean res = true;
42cdf0e10cSrcweir         xValueBinding = oObj.getValueBinding();
43cdf0e10cSrcweir         res &= checkValueBinding(xValueBinding);
44cdf0e10cSrcweir         tRes.tested("getValueBinding()", res);
45cdf0e10cSrcweir     }
46cdf0e10cSrcweir 
_setValueBinding()47cdf0e10cSrcweir     public void _setValueBinding() {
48cdf0e10cSrcweir         String rightOne = "";
49cdf0e10cSrcweir 
50cdf0e10cSrcweir         try {
51cdf0e10cSrcweir             oObj.setValueBinding(new MyValueBinding());
52cdf0e10cSrcweir             rightOne = (String) oObj.getValueBinding().getValue(null);
53cdf0e10cSrcweir         } catch (com.sun.star.form.binding.IncompatibleTypesException e) {
54cdf0e10cSrcweir             e.printStackTrace();
55cdf0e10cSrcweir         }
56cdf0e10cSrcweir 
57cdf0e10cSrcweir         boolean res = rightOne.equals("MyValueBinding");
58cdf0e10cSrcweir 
59cdf0e10cSrcweir         if (!res) {
60cdf0e10cSrcweir             log.println("Excepted: MyValueBinding");
61cdf0e10cSrcweir             log.println("getting: " + rightOne);
62cdf0e10cSrcweir         }
63cdf0e10cSrcweir 
64cdf0e10cSrcweir         tRes.tested("setValueBinding()", res);
65cdf0e10cSrcweir     }
66cdf0e10cSrcweir 
checkValueBinding(XValueBinding xValueBinding)67cdf0e10cSrcweir     protected boolean checkValueBinding(XValueBinding xValueBinding) {
68cdf0e10cSrcweir         boolean res = true;
69cdf0e10cSrcweir         Type[] types = xValueBinding.getSupportedValueTypes();
70cdf0e10cSrcweir         log.println("Checking: ");
71cdf0e10cSrcweir 
72cdf0e10cSrcweir         for (int i = 0; i < types.length; i++) {
73cdf0e10cSrcweir             log.println("\t" + types[i].getTypeName());
74cdf0e10cSrcweir 
75cdf0e10cSrcweir             boolean localRes = xValueBinding.supportsType(types[i]);
76cdf0e10cSrcweir 
77cdf0e10cSrcweir             if (!localRes) {
78cdf0e10cSrcweir                 log.println("\t\tsupportsType returns false -- FAILED");
79cdf0e10cSrcweir             } else {
80cdf0e10cSrcweir                 log.println("\t\tis supported -- OK");
81cdf0e10cSrcweir             }
82cdf0e10cSrcweir 
83cdf0e10cSrcweir             res &= localRes;
84cdf0e10cSrcweir         }
85cdf0e10cSrcweir 
86cdf0e10cSrcweir         return res;
87cdf0e10cSrcweir     }
88cdf0e10cSrcweir 
89cdf0e10cSrcweir     class MyValueBinding implements XValueBinding {
90cdf0e10cSrcweir         private Type[] TypeArray;
91cdf0e10cSrcweir         private ArrayList types = new ArrayList();
92cdf0e10cSrcweir 
getSupportedValueTypes()93cdf0e10cSrcweir         public com.sun.star.uno.Type[] getSupportedValueTypes() {
94cdf0e10cSrcweir             return TypeArray;
95cdf0e10cSrcweir         }
96cdf0e10cSrcweir 
getValue(com.sun.star.uno.Type type)97cdf0e10cSrcweir         public Object getValue(com.sun.star.uno.Type type)
98cdf0e10cSrcweir             throws com.sun.star.form.binding.IncompatibleTypesException {
99cdf0e10cSrcweir             return "MyValueBinding";
100cdf0e10cSrcweir         }
101cdf0e10cSrcweir 
setValue(Object obj)102cdf0e10cSrcweir         public void setValue(Object obj)
103cdf0e10cSrcweir             throws com.sun.star.form.binding.IncompatibleTypesException,
104cdf0e10cSrcweir                    com.sun.star.lang.NoSupportException {
105cdf0e10cSrcweir         }
106cdf0e10cSrcweir 
supportsType(com.sun.star.uno.Type type)107cdf0e10cSrcweir         public boolean supportsType(com.sun.star.uno.Type type) {
108cdf0e10cSrcweir             types.add(type);
109cdf0e10cSrcweir             TypeArray = new Type[types.size()];
110cdf0e10cSrcweir 
111cdf0e10cSrcweir             for (int i = 0; i < types.size(); i++) {
112cdf0e10cSrcweir                 TypeArray[i] = (Type) types.toArray()[i];
113cdf0e10cSrcweir             }
114cdf0e10cSrcweir 
115cdf0e10cSrcweir             return true;
116cdf0e10cSrcweir         }
117cdf0e10cSrcweir     }
118cdf0e10cSrcweir }