1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package ifc.ui.dialogs;
25 
26 import lib.MultiMethodTest;
27 
28 import com.sun.star.ui.dialogs.XControlInformation;
29 
30 /**
31 * Testing <code>com.sun.star.ui.XControlInformation</code>
32 * interface methods :
33 * <ul>
34 *  <li><code> getSupportedControls()</code></li>
35 *  <li><code> isControlSupported()</code></li>
36 *  <li><code> getSupportedControlProperties()</code></li>
37 *  <li><code> isControlPropertySupported()</code></li>
38 * </ul> <p>
39 *
40 * @see com.sun.star.ui.XFolderPicker
41 */
42 public class _XControlInformation extends MultiMethodTest {
43 
44     public XControlInformation oObj = null;
45     private String[] supControls = null ;
46     private String[][] supProperties = null ;
47 
48     /**
49      * Gets supported controls and stores them. <p>
50      * Has <b>OK</b> status if not <code>null</code> returned.
51      */
_getSupportedControls()52     public void _getSupportedControls() {
53         supControls = oObj.getSupportedControls();
54 
55         tRes.tested("getSupportedControls()", supControls != null) ;
56     }
57 
58     /**
59      * For every available control check if it is supported.
60      * Also wrong control name (non-existant and empty) are checked.<p>
61      *
62      * Has <b>OK</b> status if <code>true</code> returned for valid
63      * control names and <code>false</code> for invalid.<p>
64      *
65      * The following method tests are to be completed successfully before :
66      * <ul>
67      *  <li> <code> getSupportedControls </code> to have
68      *      valid control names</li>
69      * </ul>
70      */
_isControlSupported()71     public void _isControlSupported() {
72         requiredMethod("getSupportedControls()") ;
73 
74         boolean result = true ;
75 
76         log.println("Supported controls :");
77         for (int i = 0; i < supControls.length; i++) {
78             log.println("  " + supControls[i]);
79             result &= oObj.isControlSupported(supControls[i]) ;
80         }
81 
82         result &= !oObj.isControlSupported("SuchNameMustNotExist");
83         result &= !oObj.isControlSupported("");
84 
85         tRes.tested("isControlSupported()", result) ;
86     }
87 
88     /**
89      * For each control obtains its properties and stores them. Then tries to
90      * obtain properties for control with invalid name. <p>
91      *
92      * Has <b>OK</b> status if properties arrays are not null and exception
93      * thrown or null returned for control with invalid name <p>
94      *
95      * The following method tests are to be completed successfully before :
96      * <ul>
97      *  <li> <code> getSupportedControls </code> to have
98      *      valid control names</li>
99      * </ul>
100      */
_getSupportedControlProperties()101     public void _getSupportedControlProperties() {
102         requiredMethod("getSupportedControls()") ;
103 
104         boolean result = true;
105 
106         supProperties = new String[supControls.length][];
107         for (int i = 0; i < supControls.length; i++) {
108             log.println("Getting proeprties for control: " + supControls[i]);
109             try {
110                 supProperties[i] =
111                     oObj.getSupportedControlProperties(supControls[i]);
112             } catch (com.sun.star.lang.IllegalArgumentException e) {
113                 log.println("Unexpected exception:" + e);
114                 result = false ;
115             }
116             result &= supProperties[i] != null;
117         }
118 
119         try {
120             Object prop = oObj.getSupportedControlProperties("NoSuchControl") ;
121             result &= prop == null;
122         } catch (com.sun.star.lang.IllegalArgumentException e) {
123             log.println("Expected exception getting properties " +
124                 "for wrong control:" + e);
125         }
126 
127         tRes.tested("getSupportedControlProperties()", true) ;
128     }
129 
130     /**
131      * <ul>
132      *   <li>For each property of each control checks if it is supported.</li>
133      *   <li>For each control checks if non-existent property
134      *      (with wrong name and with empty name) supported.</li>
135      *   <li>Tries to check the property of non-existent control </li>
136      * </ul>
137      * <p>
138      * Has <b>OK</b> status if <code>true</code> returned for the first case,
139      *   <code>false</code> for the second, and <code>false</code> or exception
140      *   for the third.<p>
141      *
142      * The following method tests are to be completed successfully before :
143      * <ul>
144      *  <li> <code> getSupportedControlProperties </code> to have a set of
145      *      valid properties </li>
146      * </ul>
147      */
_isControlPropertySupported()148     public void _isControlPropertySupported() {
149         requiredMethod("getSupportedControlProperties()") ;
150 
151         boolean result = true;
152 
153         for (int i = 0; i < supControls.length; i++) {
154             log.println("Checking proeprties for control " + supControls[i]);
155             for (int j = 0; j < supProperties[i].length; j++) {
156                 log.println("   " + supProperties[i][j]);
157                 try {
158                     result &= oObj.isControlPropertySupported
159                         (supControls[i], supProperties[i][j]) ;
160                 } catch (com.sun.star.lang.IllegalArgumentException e) {
161                     log.println("Unexpected exception:" + e);
162                     result = false ;
163                 }
164             }
165 
166             try {
167                 result &= !oObj.isControlPropertySupported
168                     (supControls[i], "NoSuchPropertyForThisControl") ;
169                 result &= !oObj.isControlPropertySupported
170                     (supControls[i], "") ;
171             } catch (com.sun.star.lang.IllegalArgumentException e) {
172                 log.println
173                     ("Unexpected exception (just false must be returned):" + e);
174                 result = false ;
175             }
176         }
177 
178         try {
179             result &= !oObj.isControlPropertySupported("NoSuchControl", "") ;
180         } catch (com.sun.star.lang.IllegalArgumentException e) {
181             log.println("Expected exception: " + e);
182         }
183 
184         tRes.tested("isControlPropertySupported()", result) ;
185     }
186 }
187 
188 
189