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.XFilePicker;
29 
30 /**
31 * Testing <code>com.sun.star.ui.XFilePicker</code>
32 * interface methods :
33 * <ul>
34 *  <li><code> setMultiSelectionMode()</code></li>
35 *  <li><code> setDefaultName()</code></li>
36 *  <li><code> setDisplayDirectory()</code></li>
37 *  <li><code> getDisplayDirectory()</code></li>
38 *  <li><code> getPath()</code></li>
39 * </ul> <p>
40 * The following predefined files needed to complete the test:
41 * <ul>
42 *  <li> <code>'space-metal.jpg'</code> : just to exist. </li>
43 * <ul> <p>
44 * Test is <b> NOT </b> multithread compilant. <p>
45 * @see com.sun.star.ui.XFolderPicker
46 */
47 public class _XFilePicker extends MultiMethodTest {
48 
49     public XFilePicker oObj = null;
50     private String dir = null ;
51     private String fname = "space-metal.jpg" ;
52 
53     /**
54     * Sets the current directory to the test document directory. <p>
55     * Has <b>OK</b> status if no exceptions occurred.
56     */
_setDisplayDirectory()57     public void _setDisplayDirectory() {
58         boolean result = true ;
59         dir = util.utils.getFullTestURL("") ;
60 
61         log.println("Trying to set dir '" + dir + "'") ;
62         try {
63             oObj.setDisplayDirectory(dir) ;
64         } catch (com.sun.star.lang.IllegalArgumentException e) {
65             log.println("Directory '" + dir + "' not found :" + e) ;
66             result = false ;
67         }
68 
69         tRes.tested("setDisplayDirectory()", result) ;
70     }
71 
72     /**
73     * Gets the current directory. <p>
74     * Has <b>OK</b> status if get value is equal to set value
75     * passed to <code>setDisplayDirectory</code> <p>
76     * The following method tests are to be completed successfully before :
77     * <ul>
78     *  <li> <code> setDisplayDirectory </code>  </li>
79     * </ul>
80     */
_getDisplayDirectory()81     public void _getDisplayDirectory() {
82         requiredMethod("setDisplayDirectory()") ;
83 
84         String gDir = oObj.getDisplayDirectory() ;
85 
86         log.println("Get dir '" + gDir + "'") ;
87 
88         tRes.tested("getDisplayDirectory()", dir.equals(gDir)) ;
89     }
90 
91     /**
92     * Sets default name to file name existing in test document
93     * directory ('space-metal.jpg'). <p>
94     * Has <b>OK</b> status if no exceptions occurred.
95     */
_setDefaultName()96     public void _setDefaultName() {
97         boolean result = true ;
98 
99         try {
100             oObj.setDefaultName(fname) ;
101         } catch (Exception e) {
102             log.println("Exception setting default name :" + e) ;
103             result = false ;
104         }
105 
106         tRes.tested("setDefaultName()", result) ;
107     }
108 
109     /**
110     * Just switch object to MultiSelectionMode. There is no ways
111     * to check this method (only interactively). <p>
112     * Has <b>OK</b> status if no runtime exceptions occurred.
113     */
_setMultiSelectionMode()114     public void _setMultiSelectionMode() {
115 
116         oObj.setMultiSelectionMode(true) ;
117 
118         tRes.tested("setMultiSelectionMode()", true) ;
119     }
120 
121     /**
122     * Gets completed path from dialog. If <code>execute()</code>
123     * method was not called then zero length array is returned.
124     * So to check actual functionality of this method interactive
125     * testing is required. <p>
126     * Has <b>OK</b> status if zero length array returned (this
127     * occurs if <code>execute()</code>
128     * method was not called yet) or if array contains at least one
129     * element and it equals to <code>[Directory set] +
130     * [Default file name set]</code>. <p>
131     * The following method tests are to be completed successfully before :
132     * <ul>
133     *  <li> <code> setDisplayDirectory </code> </li>
134     *  <li> <code> setDefaultName </code> </li>
135     * </ul>
136     */
_getFiles()137     public void _getFiles() {
138         requiredMethod("setDisplayDirectory()");
139         requiredMethod("setDefaultName()");
140 
141         String[] files = oObj.getFiles();
142 
143         if (files.length > 0) {
144             log.println("Path get : '" + files[0] + "'") ;
145 
146             tRes.tested("getFiles()", (dir + fname).equals(files[0])) ;
147         } else {
148             log.println("No files were selected or execute() method was not called.") ;
149 
150             tRes.tested("getFiles()", true);
151         }
152     }
153 
154 }
155 
156 
157