1ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5ef39d40dSAndrew Rist  * distributed with this work for additional information
6ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10ef39d40dSAndrew Rist  *
11ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12ef39d40dSAndrew Rist  *
13ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18ef39d40dSAndrew Rist  * under the License.
19ef39d40dSAndrew Rist  *
20ef39d40dSAndrew Rist  *************************************************************/
21ef39d40dSAndrew Rist 
22ef39d40dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package ifc.ui.dialogs;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import lib.MultiMethodTest;
27cdf0e10cSrcweir import lib.Status;
28cdf0e10cSrcweir import lib.StatusException;
29cdf0e10cSrcweir import util.ValueChanger;
30cdf0e10cSrcweir import util.ValueComparer;
31cdf0e10cSrcweir 
32cdf0e10cSrcweir import com.sun.star.ui.dialogs.XFilePickerControlAccess;
33cdf0e10cSrcweir 
34cdf0e10cSrcweir /**
35cdf0e10cSrcweir * Testing <code>com.sun.star.ui.XFilePickerControlAccess</code>
36cdf0e10cSrcweir * interface methods :
37cdf0e10cSrcweir * <ul>
38cdf0e10cSrcweir *  <li><code> setValue()</code></li>
39cdf0e10cSrcweir *  <li><code> getValue()</code></li>
40cdf0e10cSrcweir *  <li><code> setLabel()</code></li>
41cdf0e10cSrcweir *  <li><code> getLabel()</code></li>
42cdf0e10cSrcweir *  <li><code> getFocused()</code></li>
43cdf0e10cSrcweir *  <li><code> enableControl()</code></li>
44cdf0e10cSrcweir * </ul> <p>
45cdf0e10cSrcweir * This test needs the following object relations :
46cdf0e10cSrcweir * <ul>
47cdf0e10cSrcweir *  <li> <code>'XFilePickerControlAccess.ControlID'</code> (of type
48cdf0e10cSrcweir *    <code>Short</code>) : control identifier in the extended
49cdf0e10cSrcweir *    FilePicker dialog. </li>
50cdf0e10cSrcweir *  <li> <code>'XFilePickerControlAccess.ControlValue'</code> (of type
51*bb6af6bcSPedro Giffuni *    <code>Object</code>) <b>optional</b> (but mostly desirable
52cdf0e10cSrcweir *    since the control has emtpy initial value):
53cdf0e10cSrcweir *    the value which can set for the control . </li>
54cdf0e10cSrcweir * <ul> <p>
55cdf0e10cSrcweir * Test is <b> NOT </b> multithread compilant. <p>
56cdf0e10cSrcweir * @see com.sun.star.ui.XFilePickerControlAccess
57cdf0e10cSrcweir */
58cdf0e10cSrcweir public class _XFilePickerControlAccess extends MultiMethodTest {
59cdf0e10cSrcweir 
60cdf0e10cSrcweir     public XFilePickerControlAccess oObj = null;
61cdf0e10cSrcweir     private short cntlID = -1 ;
62cdf0e10cSrcweir     private Object oldVal = null ;
63cdf0e10cSrcweir     private String oldLab = null ;
64cdf0e10cSrcweir 
65cdf0e10cSrcweir     /**
66cdf0e10cSrcweir     * Retrieves object relations.
67cdf0e10cSrcweir     * @throws StatusException If one of relations not found.
68cdf0e10cSrcweir     */
before()69cdf0e10cSrcweir     public void before() {
70cdf0e10cSrcweir         Short ID = (Short) tEnv.getObjRelation
71cdf0e10cSrcweir             ("XFilePickerControlAccess.ControlID") ;
72cdf0e10cSrcweir         if (ID == null) {
73cdf0e10cSrcweir             log.println("!!! Relation not found !!!") ;
74cdf0e10cSrcweir             throw new StatusException(Status.failed("Relation not found")) ;
75cdf0e10cSrcweir         }
76cdf0e10cSrcweir 
77cdf0e10cSrcweir         cntlID = ID.shortValue() ;
78cdf0e10cSrcweir     }
79cdf0e10cSrcweir 
80cdf0e10cSrcweir     /**
81cdf0e10cSrcweir     * Gets the value of the control and stores it. <p>
82*bb6af6bcSPedro Giffuni     * Has <b>OK</b> status if no runtime exceptions occurred.
83cdf0e10cSrcweir     */
_getValue()84cdf0e10cSrcweir     public void _getValue() {
85cdf0e10cSrcweir         boolean result = true ;
86cdf0e10cSrcweir 
87cdf0e10cSrcweir         try {
88cdf0e10cSrcweir             oldVal = oObj.getValue(cntlID,(short)0);
89cdf0e10cSrcweir         } catch (Exception e) {
90cdf0e10cSrcweir             e.printStackTrace(log) ;
91cdf0e10cSrcweir             result = false ;
92cdf0e10cSrcweir         }
93cdf0e10cSrcweir 
94cdf0e10cSrcweir         tRes.tested("getValue()", result) ;
95cdf0e10cSrcweir     }
96cdf0e10cSrcweir 
97cdf0e10cSrcweir     /**
98cdf0e10cSrcweir     * Changes the value gotten by <code>getValue</code> method,
99cdf0e10cSrcweir     * or gets the value from relation if it exits.
100cdf0e10cSrcweir     * Sets this value and then check if it was properly set. <p>
101cdf0e10cSrcweir     * Has <b>OK</b> status if <code>getValue</code> method returns
102cdf0e10cSrcweir     * the same value which was set. <p>
103cdf0e10cSrcweir     * The following method tests are to be completed successfully before :
104cdf0e10cSrcweir     * <ul>
105cdf0e10cSrcweir     *  <li> <code> getValue </code> </li>
106cdf0e10cSrcweir     * </ul>
107cdf0e10cSrcweir     */
_setValue()108cdf0e10cSrcweir     public void _setValue() {
109cdf0e10cSrcweir         requiredMethod("getValue()") ;
110cdf0e10cSrcweir         boolean result = true ;
111cdf0e10cSrcweir 
112cdf0e10cSrcweir         Object newVal = tEnv.getObjRelation
113cdf0e10cSrcweir             ("XFilePickerControlAccess.ControlValue");
114cdf0e10cSrcweir         if (newVal == null) {
115cdf0e10cSrcweir             newVal = ValueChanger.changePValue(oldVal) ;
116cdf0e10cSrcweir         }
117cdf0e10cSrcweir 
118cdf0e10cSrcweir         Object getVal = null ;
119cdf0e10cSrcweir 
120cdf0e10cSrcweir         try {
121cdf0e10cSrcweir             oObj.setValue(cntlID, (short)0 , newVal) ;
122cdf0e10cSrcweir             getVal = oObj.getValue(cntlID,(short)0) ;
123cdf0e10cSrcweir         } catch (Exception e) {
124cdf0e10cSrcweir             e.printStackTrace(log) ;
125cdf0e10cSrcweir             result = false ;
126cdf0e10cSrcweir         }
127cdf0e10cSrcweir 
128cdf0e10cSrcweir         result &= ValueComparer.equalValue(newVal, getVal) ;
129cdf0e10cSrcweir 
130cdf0e10cSrcweir         tRes.tested("setValue()", result) ;
131cdf0e10cSrcweir     }
132cdf0e10cSrcweir 
133cdf0e10cSrcweir     /**
134cdf0e10cSrcweir     * Gets the label of the control and stores it. <p>
135*bb6af6bcSPedro Giffuni     * Has <b>OK</b> status if no runtime exceptions occurred.
136cdf0e10cSrcweir     */
_getLabel()137cdf0e10cSrcweir     public void _getLabel() {
138cdf0e10cSrcweir 
139cdf0e10cSrcweir         try {
140cdf0e10cSrcweir             oldLab = oObj.getLabel(cntlID);
141cdf0e10cSrcweir         } catch (Exception e) {
142cdf0e10cSrcweir             e.printStackTrace(log) ;
143cdf0e10cSrcweir         }
144cdf0e10cSrcweir 
145cdf0e10cSrcweir         tRes.tested("getLabel()", oldLab != null) ;
146cdf0e10cSrcweir     }
147cdf0e10cSrcweir 
148cdf0e10cSrcweir     /**
149cdf0e10cSrcweir     * Changes the label gotten by <code>getLabel</code> method,
150cdf0e10cSrcweir     * set this label and then check if it was properly set. <p>
151cdf0e10cSrcweir     * Has <b>OK</b> status if <code>getLael</code> method returns
152cdf0e10cSrcweir     * the same value which was set. <p>
153cdf0e10cSrcweir     * The following method tests are to be completed successfully before :
154cdf0e10cSrcweir     * <ul>
155cdf0e10cSrcweir     *  <li> <code> getLabel </code> </li>
156cdf0e10cSrcweir     * </ul>
157cdf0e10cSrcweir     */
_setLabel()158cdf0e10cSrcweir     public void _setLabel() {
159cdf0e10cSrcweir         requiredMethod("getLabel()") ;
160cdf0e10cSrcweir         boolean result = true ;
161cdf0e10cSrcweir 
162cdf0e10cSrcweir         String newVal = oldLab + "_" ;
163cdf0e10cSrcweir         String getVal = null ;
164cdf0e10cSrcweir 
165cdf0e10cSrcweir         try {
166cdf0e10cSrcweir             oObj.setLabel(cntlID, newVal) ;
167cdf0e10cSrcweir             getVal = oObj.getLabel(cntlID) ;
168cdf0e10cSrcweir         } catch (Exception e) {
169cdf0e10cSrcweir             e.printStackTrace(log) ;
170cdf0e10cSrcweir             result = false ;
171cdf0e10cSrcweir         }
172cdf0e10cSrcweir 
173cdf0e10cSrcweir         result &= newVal.equals(getVal) ;
174cdf0e10cSrcweir 
175cdf0e10cSrcweir         tRes.tested("setLabel()", result) ;
176cdf0e10cSrcweir     }
177cdf0e10cSrcweir 
178cdf0e10cSrcweir     /**
179cdf0e10cSrcweir     * Disables and then enables the control. Can be checked only
180cdf0e10cSrcweir     * interactively. <p>
181*bb6af6bcSPedro Giffuni     * Has <b>OK</b> status if no runtime exceptions occurred.
182cdf0e10cSrcweir     */
_enableControl()183cdf0e10cSrcweir     public void _enableControl() {
184cdf0e10cSrcweir         boolean result = true ;
185cdf0e10cSrcweir 
186cdf0e10cSrcweir         try {
187cdf0e10cSrcweir             oObj.enableControl(cntlID, false) ;
188cdf0e10cSrcweir             oObj.enableControl(cntlID, true) ;
189cdf0e10cSrcweir         } catch (Exception e) {
190cdf0e10cSrcweir             e.printStackTrace(log) ;
191cdf0e10cSrcweir             result = false ;
192cdf0e10cSrcweir         }
193cdf0e10cSrcweir 
194cdf0e10cSrcweir         tRes.tested("enableControl()", result) ;
195cdf0e10cSrcweir     }
196cdf0e10cSrcweir }
197cdf0e10cSrcweir 
198cdf0e10cSrcweir 
199