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