xref: /AOO41X/main/qadevOOo/tests/java/ifc/form/binding/_XBindableValue.java (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 package ifc.form.binding;
28 
29 import com.sun.star.form.binding.XBindableValue;
30 import com.sun.star.form.binding.XValueBinding;
31 import com.sun.star.uno.Type;
32 
33 import java.util.ArrayList;
34 
35 import lib.MultiMethodTest;
36 
37 
38 public class _XBindableValue extends MultiMethodTest {
39     public XBindableValue oObj;
40     protected XValueBinding xValueBinding = null;
41 
42     public void _getValueBinding() {
43         requiredMethod("setValueBinding");
44 
45         boolean res = true;
46         xValueBinding = oObj.getValueBinding();
47         res &= checkValueBinding(xValueBinding);
48         tRes.tested("getValueBinding()", res);
49     }
50 
51     public void _setValueBinding() {
52         String rightOne = "";
53 
54         try {
55             oObj.setValueBinding(new MyValueBinding());
56             rightOne = (String) oObj.getValueBinding().getValue(null);
57         } catch (com.sun.star.form.binding.IncompatibleTypesException e) {
58             e.printStackTrace();
59         }
60 
61         boolean res = rightOne.equals("MyValueBinding");
62 
63         if (!res) {
64             log.println("Excepted: MyValueBinding");
65             log.println("getting: " + rightOne);
66         }
67 
68         tRes.tested("setValueBinding()", res);
69     }
70 
71     protected boolean checkValueBinding(XValueBinding xValueBinding) {
72         boolean res = true;
73         Type[] types = xValueBinding.getSupportedValueTypes();
74         log.println("Checking: ");
75 
76         for (int i = 0; i < types.length; i++) {
77             log.println("\t" + types[i].getTypeName());
78 
79             boolean localRes = xValueBinding.supportsType(types[i]);
80 
81             if (!localRes) {
82                 log.println("\t\tsupportsType returns false -- FAILED");
83             } else {
84                 log.println("\t\tis supported -- OK");
85             }
86 
87             res &= localRes;
88         }
89 
90         return res;
91     }
92 
93     class MyValueBinding implements XValueBinding {
94         private Type[] TypeArray;
95         private ArrayList types = new ArrayList();
96 
97         public com.sun.star.uno.Type[] getSupportedValueTypes() {
98             return TypeArray;
99         }
100 
101         public Object getValue(com.sun.star.uno.Type type)
102             throws com.sun.star.form.binding.IncompatibleTypesException {
103             return "MyValueBinding";
104         }
105 
106         public void setValue(Object obj)
107             throws com.sun.star.form.binding.IncompatibleTypesException,
108                    com.sun.star.lang.NoSupportException {
109         }
110 
111         public boolean supportsType(com.sun.star.uno.Type type) {
112             types.add(type);
113             TypeArray = new Type[types.size()];
114 
115             for (int i = 0; i < types.size(); i++) {
116                 TypeArray[i] = (Type) types.toArray()[i];
117             }
118 
119             return true;
120         }
121     }
122 }