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
10*ef39d40dSAndrew Rist  *
11*ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ef39d40dSAndrew Rist  *
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.
19*ef39d40dSAndrew Rist  *
20*ef39d40dSAndrew Rist  *************************************************************/
21*ef39d40dSAndrew Rist 
22*ef39d40dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package ifc.ui.dialogs;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import lib.MultiMethodTest;
27cdf0e10cSrcweir import lib.Status;
28cdf0e10cSrcweir import lib.StatusException;
29cdf0e10cSrcweir 
30cdf0e10cSrcweir import com.sun.star.ui.dialogs.XControlAccess;
31cdf0e10cSrcweir import com.sun.star.ui.dialogs.XControlInformation;
32cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
33cdf0e10cSrcweir 
34cdf0e10cSrcweir /**
35cdf0e10cSrcweir * Testing <code>com.sun.star.ui.XFilePicker</code>
36cdf0e10cSrcweir * interface methods :
37cdf0e10cSrcweir * <ul>
38cdf0e10cSrcweir *  <li><code> setControlProperty()</code></li>
39cdf0e10cSrcweir *  <li><code> getControlProperty()</code></li>
40cdf0e10cSrcweir * </ul> <p>
41cdf0e10cSrcweir *
42cdf0e10cSrcweir * For testing this interface the component must implement
43cdf0e10cSrcweir * <code>com.sun.star.ui.dialogs.XControlInformation</code>
44cdf0e10cSrcweir * interface. <p>
45cdf0e10cSrcweir *
46cdf0e10cSrcweir * Test is <b> NOT </b> multithread compilant. <p>
47cdf0e10cSrcweir * @see com.sun.star.ui.XFolderPicker
48cdf0e10cSrcweir */
49cdf0e10cSrcweir public class _XControlAccess extends MultiMethodTest {
50cdf0e10cSrcweir 
51cdf0e10cSrcweir     public XControlAccess oObj = null;
52cdf0e10cSrcweir     private XControlInformation xCI = null ;
53cdf0e10cSrcweir     private String[] supControls = null ;
54cdf0e10cSrcweir     private String[][] supProperties = null ;
55cdf0e10cSrcweir 
56cdf0e10cSrcweir     /**
57cdf0e10cSrcweir      * Tries to query <code>com.sun.star.ui.dialogs.XControlInformation</code>
58cdf0e10cSrcweir      * interface, and obtain properties' names of each available
59cdf0e10cSrcweir      * control. <p>
60cdf0e10cSrcweir      *
61cdf0e10cSrcweir      * @throw StatusException if interface is not supported or
62cdf0e10cSrcweir      * properties couldn't be get.
63cdf0e10cSrcweir      */
before()64cdf0e10cSrcweir     protected void before() {
65cdf0e10cSrcweir         xCI = (XControlInformation) UnoRuntime.queryInterface
66cdf0e10cSrcweir             (XControlInformation.class, oObj);
67cdf0e10cSrcweir 
68cdf0e10cSrcweir         if (xCI == null) throw new StatusException
69cdf0e10cSrcweir             (Status.failed("XControlInformation not supported")) ;
70cdf0e10cSrcweir 
71cdf0e10cSrcweir         supControls = xCI.getSupportedControls();
72cdf0e10cSrcweir         supProperties = new String[supControls.length][];
73cdf0e10cSrcweir         for (int i = 0; i < supControls.length; i++) {
74cdf0e10cSrcweir             try {
75cdf0e10cSrcweir                 supProperties[i] =
76cdf0e10cSrcweir                     xCI.getSupportedControlProperties(supControls[i]);
77cdf0e10cSrcweir             } catch (com.sun.star.lang.IllegalArgumentException e) {
78cdf0e10cSrcweir                 e.printStackTrace(log);
79cdf0e10cSrcweir                 throw new StatusException
80cdf0e10cSrcweir                     ("Exception while init.", e) ;
81cdf0e10cSrcweir             }
82cdf0e10cSrcweir         }
83cdf0e10cSrcweir     }
84cdf0e10cSrcweir 
85cdf0e10cSrcweir     /**
86cdf0e10cSrcweir      * Tries to change each property of each control.
87cdf0e10cSrcweir      * Has <b>OK</b> status if values are properly changed.
88cdf0e10cSrcweir      */
_setControlProperty()89cdf0e10cSrcweir     public void _setControlProperty() {
90cdf0e10cSrcweir         boolean result = true ;
91cdf0e10cSrcweir         String error = "";
92cdf0e10cSrcweir 
93cdf0e10cSrcweir         for (int i = 0; i < supControls.length; i++) {
94cdf0e10cSrcweir             log.println("Checking properties for control " + supControls[i]);
95cdf0e10cSrcweir             for (int j = 0; j < supProperties[i].length; j++) {
96cdf0e10cSrcweir                 log.println("\t" + supProperties[i][j]);
97cdf0e10cSrcweir                 try {
98cdf0e10cSrcweir                     Object oldVal = oObj.getControlProperty(supControls[i],
99cdf0e10cSrcweir                         supProperties[i][j]);
100cdf0e10cSrcweir                     Object newVal = util.ValueChanger.changePValue(oldVal);
101cdf0e10cSrcweir                     if (supProperties[i][j].startsWith("Help")) {
102cdf0e10cSrcweir                         newVal = "HID:133";
103cdf0e10cSrcweir                     }
104cdf0e10cSrcweir                     oObj.setControlProperty
105cdf0e10cSrcweir                         (supControls[i], supProperties[i][j], newVal) ;
106cdf0e10cSrcweir                     Object resVal = oObj.getControlProperty(supControls[i],
107cdf0e10cSrcweir                         supProperties[i][j]);
108cdf0e10cSrcweir                     log.println("\t Old:" + oldVal + ",New:" + newVal
109cdf0e10cSrcweir                         + ",Result:" + resVal);
110cdf0e10cSrcweir                     if (!util.ValueComparer.equalValue(newVal, resVal)) {
111cdf0e10cSrcweir                         error += "####Property '"+supProperties[i][j]+
112cdf0e10cSrcweir                             " of "+supControls[i]+" didn't work\n\r"+
113cdf0e10cSrcweir                             "\t Old:" + oldVal + ",New:" + newVal
114cdf0e10cSrcweir                         + ",Result:" + resVal+ "\n\r";
115cdf0e10cSrcweir                     }
116cdf0e10cSrcweir                     result &= util.ValueComparer.equalValue(newVal, resVal);
117cdf0e10cSrcweir                 } catch (com.sun.star.lang.IllegalArgumentException e) {
118cdf0e10cSrcweir                     log.println("Unexpected exception:" );
119cdf0e10cSrcweir                     e.printStackTrace(log);
120cdf0e10cSrcweir                     result = false ;
121cdf0e10cSrcweir                 }
122cdf0e10cSrcweir             }
123cdf0e10cSrcweir         }
124cdf0e10cSrcweir 
125cdf0e10cSrcweir         log.println(error);
126cdf0e10cSrcweir 
127cdf0e10cSrcweir         tRes.tested("setControlProperty()", result) ;
128cdf0e10cSrcweir         tRes.tested("getControlProperty()", result) ;
129cdf0e10cSrcweir     }
130cdf0e10cSrcweir 
131cdf0e10cSrcweir     /**
132cdf0e10cSrcweir      * Does nothing. Testing performed in <code>setControlProperty</code>
133cdf0e10cSrcweir      * method test.
134cdf0e10cSrcweir      */
_getControlProperty()135cdf0e10cSrcweir     public void _getControlProperty() {}
136cdf0e10cSrcweir }
137cdf0e10cSrcweir 
138cdf0e10cSrcweir 
139