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 import lib.Status;
32 import lib.StatusException;
33 import util.ValueChanger;
34 import util.ValueComparer;
35 
36 import com.sun.star.ui.dialogs.XFilePickerControlAccess;
37 
38 /**
39 * Testing <code>com.sun.star.ui.XFilePickerControlAccess</code>
40 * interface methods :
41 * <ul>
42 *  <li><code> setValue()</code></li>
43 *  <li><code> getValue()</code></li>
44 *  <li><code> setLabel()</code></li>
45 *  <li><code> getLabel()</code></li>
46 *  <li><code> getFocused()</code></li>
47 *  <li><code> enableControl()</code></li>
48 * </ul> <p>
49 * This test needs the following object relations :
50 * <ul>
51 *  <li> <code>'XFilePickerControlAccess.ControlID'</code> (of type
52 *    <code>Short</code>) : control identifier in the extended
53 *    FilePicker dialog. </li>
54 *  <li> <code>'XFilePickerControlAccess.ControlValue'</code> (of type
55 *    <code>Object</code>) <b>optional</b> (but mostly desireable
56 *    since the control has emtpy initial value):
57 *    the value which can set for the control . </li>
58 * <ul> <p>
59 * Test is <b> NOT </b> multithread compilant. <p>
60 * @see com.sun.star.ui.XFilePickerControlAccess
61 */
62 public class _XFilePickerControlAccess extends MultiMethodTest {
63 
64     public XFilePickerControlAccess oObj = null;
65     private short cntlID = -1 ;
66     private Object oldVal = null ;
67     private String oldLab = null ;
68 
69     /**
70     * Retrieves object relations.
71     * @throws StatusException If one of relations not found.
72     */
73     public void before() {
74         Short ID = (Short) tEnv.getObjRelation
75             ("XFilePickerControlAccess.ControlID") ;
76         if (ID == null) {
77             log.println("!!! Relation not found !!!") ;
78             throw new StatusException(Status.failed("Relation not found")) ;
79         }
80 
81         cntlID = ID.shortValue() ;
82     }
83 
84     /**
85     * Gets the value of the control and stores it. <p>
86     * Has <b>OK</b> status if no runtime exceptions occured.
87     */
88     public void _getValue() {
89         boolean result = true ;
90 
91         try {
92             oldVal = oObj.getValue(cntlID,(short)0);
93         } catch (Exception e) {
94             e.printStackTrace(log) ;
95             result = false ;
96         }
97 
98         tRes.tested("getValue()", result) ;
99     }
100 
101     /**
102     * Changes the value gotten by <code>getValue</code> method,
103     * or gets the value from relation if it exits.
104     * Sets this value and then check if it was properly set. <p>
105     * Has <b>OK</b> status if <code>getValue</code> method returns
106     * the same value which was set. <p>
107     * The following method tests are to be completed successfully before :
108     * <ul>
109     *  <li> <code> getValue </code> </li>
110     * </ul>
111     */
112     public void _setValue() {
113         requiredMethod("getValue()") ;
114         boolean result = true ;
115 
116         Object newVal = tEnv.getObjRelation
117             ("XFilePickerControlAccess.ControlValue");
118         if (newVal == null) {
119             newVal = ValueChanger.changePValue(oldVal) ;
120         }
121 
122         Object getVal = null ;
123 
124         try {
125             oObj.setValue(cntlID, (short)0 , newVal) ;
126             getVal = oObj.getValue(cntlID,(short)0) ;
127         } catch (Exception e) {
128             e.printStackTrace(log) ;
129             result = false ;
130         }
131 
132         result &= ValueComparer.equalValue(newVal, getVal) ;
133 
134         tRes.tested("setValue()", result) ;
135     }
136 
137     /**
138     * Gets the label of the control and stores it. <p>
139     * Has <b>OK</b> status if no runtime exceptions occured.
140     */
141     public void _getLabel() {
142 
143         try {
144             oldLab = oObj.getLabel(cntlID);
145         } catch (Exception e) {
146             e.printStackTrace(log) ;
147         }
148 
149         tRes.tested("getLabel()", oldLab != null) ;
150     }
151 
152     /**
153     * Changes the label gotten by <code>getLabel</code> method,
154     * set this label and then check if it was properly set. <p>
155     * Has <b>OK</b> status if <code>getLael</code> method returns
156     * the same value which was set. <p>
157     * The following method tests are to be completed successfully before :
158     * <ul>
159     *  <li> <code> getLabel </code> </li>
160     * </ul>
161     */
162     public void _setLabel() {
163         requiredMethod("getLabel()") ;
164         boolean result = true ;
165 
166         String newVal = oldLab + "_" ;
167         String getVal = null ;
168 
169         try {
170             oObj.setLabel(cntlID, newVal) ;
171             getVal = oObj.getLabel(cntlID) ;
172         } catch (Exception e) {
173             e.printStackTrace(log) ;
174             result = false ;
175         }
176 
177         result &= newVal.equals(getVal) ;
178 
179         tRes.tested("setLabel()", result) ;
180     }
181 
182     /**
183     * Disables and then enables the control. Can be checked only
184     * interactively. <p>
185     * Has <b>OK</b> status if no runtime exceptions occured.
186     */
187     public void _enableControl() {
188         boolean result = true ;
189 
190         try {
191             oObj.enableControl(cntlID, false) ;
192             oObj.enableControl(cntlID, true) ;
193         } catch (Exception e) {
194             e.printStackTrace(log) ;
195             result = false ;
196         }
197 
198         tRes.tested("enableControl()", result) ;
199     }
200 }
201 
202 
203