xref: /AOO41X/main/qadevOOo/tests/java/ifc/ui/dialogs/_XControlInformation.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 
28 package ifc.ui.dialogs;
29 
30 import lib.MultiMethodTest;
31 
32 import com.sun.star.ui.dialogs.XControlInformation;
33 
34 /**
35 * Testing <code>com.sun.star.ui.XControlInformation</code>
36 * interface methods :
37 * <ul>
38 *  <li><code> getSupportedControls()</code></li>
39 *  <li><code> isControlSupported()</code></li>
40 *  <li><code> getSupportedControlProperties()</code></li>
41 *  <li><code> isControlPropertySupported()</code></li>
42 * </ul> <p>
43 *
44 * @see com.sun.star.ui.XFolderPicker
45 */
46 public class _XControlInformation extends MultiMethodTest {
47 
48     public XControlInformation oObj = null;
49     private String[] supControls = null ;
50     private String[][] supProperties = null ;
51 
52     /**
53      * Gets supported controls and stores them. <p>
54      * Has <b>OK</b> status if not <code>null</code> returned.
55      */
56     public void _getSupportedControls() {
57         supControls = oObj.getSupportedControls();
58 
59         tRes.tested("getSupportedControls()", supControls != null) ;
60     }
61 
62     /**
63      * For every available control check if it is supported.
64      * Also wrong control name (non-existant and empty) are checked.<p>
65      *
66      * Has <b>OK</b> status if <code>true</code> returned for valid
67      * control names and <code>false</code> for invalid.<p>
68      *
69      * The following method tests are to be completed successfully before :
70      * <ul>
71      *  <li> <code> getSupportedControls </code> to have
72      *      valid control names</li>
73      * </ul>
74      */
75     public void _isControlSupported() {
76         requiredMethod("getSupportedControls()") ;
77 
78         boolean result = true ;
79 
80         log.println("Supported controls :");
81         for (int i = 0; i < supControls.length; i++) {
82             log.println("  " + supControls[i]);
83             result &= oObj.isControlSupported(supControls[i]) ;
84         }
85 
86         result &= !oObj.isControlSupported("SuchNameMustNotExist");
87         result &= !oObj.isControlSupported("");
88 
89         tRes.tested("isControlSupported()", result) ;
90     }
91 
92     /**
93      * For each control obtains its properties and stores them. Then tries to
94      * obtain properties for control with invalid name. <p>
95      *
96      * Has <b>OK</b> status if properties arrays are not null and exception
97      * thrown or null returned for control with invalid name <p>
98      *
99      * The following method tests are to be completed successfully before :
100      * <ul>
101      *  <li> <code> getSupportedControls </code> to have
102      *      valid control names</li>
103      * </ul>
104      */
105     public void _getSupportedControlProperties() {
106         requiredMethod("getSupportedControls()") ;
107 
108         boolean result = true;
109 
110         supProperties = new String[supControls.length][];
111         for (int i = 0; i < supControls.length; i++) {
112             log.println("Getting proeprties for control: " + supControls[i]);
113             try {
114                 supProperties[i] =
115                     oObj.getSupportedControlProperties(supControls[i]);
116             } catch (com.sun.star.lang.IllegalArgumentException e) {
117                 log.println("Unexpected exception:" + e);
118                 result = false ;
119             }
120             result &= supProperties[i] != null;
121         }
122 
123         try {
124             Object prop = oObj.getSupportedControlProperties("NoSuchControl") ;
125             result &= prop == null;
126         } catch (com.sun.star.lang.IllegalArgumentException e) {
127             log.println("Expected exception getting properties " +
128                 "for wrong control:" + e);
129         }
130 
131         tRes.tested("getSupportedControlProperties()", true) ;
132     }
133 
134     /**
135      * <ul>
136      *   <li>For each property of each control checks if it is supported.</li>
137      *   <li>For each control checks if non-existent property
138      *      (with wrong name and with empty name) supported.</li>
139      *   <li>Tries to check the property of non-existent control </li>
140      * </ul>
141      * <p>
142      * Has <b>OK</b> status if <code>true</code> returned for the first case,
143      *   <code>false</code> for the second, and <code>false</code> or exception
144      *   for the third.<p>
145      *
146      * The following method tests are to be completed successfully before :
147      * <ul>
148      *  <li> <code> getSupportedControlProperties </code> to have a set of
149      *      valid properties </li>
150      * </ul>
151      */
152     public void _isControlPropertySupported() {
153         requiredMethod("getSupportedControlProperties()") ;
154 
155         boolean result = true;
156 
157         for (int i = 0; i < supControls.length; i++) {
158             log.println("Checking proeprties for control " + supControls[i]);
159             for (int j = 0; j < supProperties[i].length; j++) {
160                 log.println("   " + supProperties[i][j]);
161                 try {
162                     result &= oObj.isControlPropertySupported
163                         (supControls[i], supProperties[i][j]) ;
164                 } catch (com.sun.star.lang.IllegalArgumentException e) {
165                     log.println("Unexpected exception:" + e);
166                     result = false ;
167                 }
168             }
169 
170             try {
171                 result &= !oObj.isControlPropertySupported
172                     (supControls[i], "NoSuchPropertyForThisControl") ;
173                 result &= !oObj.isControlPropertySupported
174                     (supControls[i], "") ;
175             } catch (com.sun.star.lang.IllegalArgumentException e) {
176                 log.println
177                     ("Unexpected exception (just false must be returned):" + e);
178                 result = false ;
179             }
180         }
181 
182         try {
183             result &= !oObj.isControlPropertySupported("NoSuchControl", "") ;
184         } catch (com.sun.star.lang.IllegalArgumentException e) {
185             log.println("Expected exception: " + e);
186         }
187 
188         tRes.tested("isControlPropertySupported()", result) ;
189     }
190 }
191 
192 
193