1 /*
2  * This file is part of the LibreOffice project.
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  *
8  * This file incorporates work covered by the following license notice:
9  *
10  *   Licensed to the Apache Software Foundation (ASF) under one or more
11  *   contributor license agreements. See the NOTICE file distributed
12  *   with this work for additional information regarding copyright
13  *   ownership. The ASF licenses this file to you under the Apache
14  *   License, Version 2.0 (the "License"); you may not use this file
15  *   except in compliance with the License. You may obtain a copy of
16  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
17  */
18 
19 package ifc.awt;
20 
21 
22 import lib.MultiMethodTest;
23 
24 import com.sun.star.awt.XDateField;
25 import com.sun.star.util.Date;
26 
27 /**
28 * Testing <code>com.sun.star.awt.XDateField</code>
29 * interface methods :
30 * <ul>
31 *  <li><code> setDate()</code></li>
32 *  <li><code> getDate()</code></li>
33 *  <li><code> setMin()</code></li>
34 *  <li><code> getMin()</code></li>
35 *  <li><code> setMax()</code></li>
36 *  <li><code> getMax()</code></li>
37 *  <li><code> setFirst()</code></li>
38 *  <li><code> getFirst()</code></li>
39 *  <li><code> setLast()</code></li>
40 *  <li><code> getLast()</code></li>
41 *  <li><code> setLongFormat()</code></li>
42 *  <li><code> isLongFormat()</code></li>
43 *  <li><code> setEmpty()</code></li>
44 *  <li><code> isEmpty()</code></li>
45 *  <li><code> setStrictFormat()</code></li>
46 *  <li><code> isStrictFormat()</code></li>
47 * </ul> <p>
48 * Test is <b> NOT </b> multithread compliant. <p>
49 * @see com.sun.star.awt.XDateField
50 */
51 public class _XDateField extends MultiMethodTest {
52 
53     public XDateField oObj = null;
54 
55     private boolean strict = false ;
56     private boolean longFormat = false ;
57 
58     /**
59     * Sets a new value and checks if it was correctly set. <p>
60     * Has <b> OK </b> status if set and get values are equal.
61     * The following method tests are to be completed successfully before :
62     * <ul>
63     *  <li> <code> getTime </code> </li>
64     * </ul>
65     */
_setDate()66     public void _setDate() {
67         requiredMethod("getDate()") ;
68 
69         boolean result = true ;
70         oObj.setDate(new Date((short)1, (short)1, (short)1900)) ;
71         Date date = oObj.getDate();
72         result = date.Day == 1 && date.Month == 1 && date.Year == 1900;
73 
74         if (! result ) {
75             System.out.println("getDate: " + oObj.getDate() + " , expected 1900-01-01");
76         }
77 
78         tRes.tested("setDate()", result) ;
79     }
80 
81     /**
82     * Gets the current value. <p>
83     * Has <b> OK </b> status if no runtime exceptions occurred
84     */
_getDate()85     public void _getDate() {
86 
87         boolean result = true ;
88         oObj.getDate() ;
89 
90         tRes.tested("getDate()", result) ;
91     }
92 
93     /**
94     * Sets a new value and checks if it was correctly set. <p>
95     * Has <b> OK </b> status if set and get values are equal.
96     * The following method tests are to be completed successfully before :
97     * <ul>
98     *  <li> <code> getMin </code> </li>
99     * </ul>
100     */
_setMin()101     public void _setMin() {
102 
103         boolean result = true ;
104         oObj.setMin(new Date((short)5, (short)2, (short)1963));
105         Date date = oObj.getMin();
106         result = date.Day == 5 && date.Month == 2 && date.Year == 1963;
107 
108         tRes.tested("setMin()", result) ;
109     }
110 
111     /**
112     * Gets the current value. <p>
113     * Has <b> OK </b> status if no runtime exceptions occurred
114     */
_getMin()115     public void _getMin() {
116 
117         boolean result = true ;
118         oObj.getMin() ;
119 
120         tRes.tested("getMin()", result) ;
121     }
122 
123     /**
124     * Sets a new value and checks if it was correctly set. <p>
125     * Has <b> OK </b> status if set and get values are equal.
126     * The following method tests are to be completed successfully before :
127     * <ul>
128     *  <li> <code> getMax </code> </li>
129     * </ul>
130     */
_setMax()131     public void _setMax() {
132 
133         boolean result = true ;
134         oObj.setMax(new Date((short)18, (short)9, (short)2117)) ;
135         Date date = oObj.getMax();
136         result = date.Day == 18 && date.Month == 9 && date.Year == 2117;
137 
138         tRes.tested("setMax()", result) ;
139     }
140 
141     /**
142     * Gets the current value. <p>
143     * Has <b> OK </b> status if no runtime exceptions occurred
144     */
_getMax()145     public void _getMax() {
146 
147         boolean result = true ;
148         oObj.getMax() ;
149 
150         tRes.tested("getMax()", result) ;
151     }
152 
153     /**
154     * Sets a new value and checks if it was correctly set. <p>
155     * Has <b> OK </b> status if set and get values are equal.
156     * The following method tests are to be completed successfully before :
157     * <ul>
158     *  <li> <code> getFirst </code> </li>
159     * </ul>
160     */
_setFirst()161     public void _setFirst() {
162 
163         boolean result = true ;
164         oObj.setFirst(new Date((short)7, (short)12, (short)1972)) ;
165         Date date = oObj.getFirst();
166         result = date.Day == 7 && date.Month == 12 && date.Year == 1972;
167 
168         if (!result) {
169             log.println("Set to " + 5118 + " but returned " + oObj.getFirst()) ;
170         }
171 
172         tRes.tested("setFirst()", result) ;
173     }
174 
175     /**
176     * Gets the current value. <p>
177     * Has <b> OK </b> status if no runtime exceptions occurred
178     */
_getFirst()179     public void _getFirst() {
180 
181         boolean result = true ;
182         com.sun.star.util.Date val = oObj.getFirst() ;
183 
184         log.println("getFirst() = " + val) ;
185 
186         tRes.tested("getFirst()", result) ;
187     }
188 
189     /**
190     * Sets a new value and checks if it was correctly set. <p>
191     * Has <b> OK </b> status if set and get values are equal.
192     * The following method tests are to be completed successfully before :
193     * <ul>
194     *  <li> <code> getLast </code> </li>
195     * </ul>
196     */
_setLast()197     public void _setLast() {
198 
199         boolean result = true ;
200         oObj.setLast(new Date((short)23, (short)8, (short)2053)) ;
201         Date date = oObj.getLast();
202         result = date.Day == 23 && date.Month == 8 && date.Year == 2053;
203 
204         if (!result) {
205             log.println("Set to 2053-08-23 but returned " + oObj.getLast()) ;
206         }
207 
208         tRes.tested("setLast()", result) ;
209     }
210 
211     /**
212     * Gets the current value. <p>
213     * Has <b> OK </b> status if no runtime exceptions occurred
214     */
_getLast()215     public void _getLast() {
216 
217         boolean result = true ;
218         com.sun.star.util.Date val = oObj.getLast() ;
219 
220         log.println("getLast() = " + val) ;
221 
222         tRes.tested("getLast()", result) ;
223     }
224 
225     /**
226     * Sets the value to empty. <p>
227     * Has <b> OK </b> status if no runtime exceptions occurred
228     * The following method tests are to be completed successfully before :
229     * <ul>
230     *  <li> <code> setTime </code> : value must be not empty </li>
231     * </ul>
232     */
_setEmpty()233     public void _setEmpty() {
234         requiredMethod("setDate()") ;
235 
236         boolean result = true ;
237         oObj.setEmpty() ;
238 
239         tRes.tested("setEmpty()", result) ;
240     }
241 
242     /**
243     * Checks if the field is empty. <p>
244     * Has <b> OK </b> status if the value is empty.<p>
245     * The following method tests are to be completed successfully before :
246     * <ul>
247     *  <li> <code> setEmpty() </code>  </li>
248     * </ul>
249     */
_isEmpty()250     public void _isEmpty() {
251         requiredMethod("setEmpty()") ;
252 
253         boolean result = true ;
254         result = oObj.isEmpty() ;
255 
256         tRes.tested("isEmpty()", result) ;
257     }
258 
259     /**
260     * Checks strict state. <p>
261     * Has <b> OK </b> status if strict format is properly set.
262     * The following method tests are to be completed successfully before :
263     * <ul>
264     *  <li> <code> isStrictFormat </code> </li>
265     * </ul>
266     */
_setStrictFormat()267     public void _setStrictFormat() {
268         requiredMethod("isStrictFormat()") ;
269 
270         boolean result = true ;
271         oObj.setStrictFormat(!strict) ;
272 
273         result = oObj.isStrictFormat() == !strict ;
274 
275         if (!result) {
276             log.println("Was '" + strict + "', set to '" + !strict +
277                 "' but returned '" + oObj.isStrictFormat() + "'") ;
278         }
279 
280         tRes.tested("setStrictFormat()", result) ;
281     }
282 
283     /**
284     * Gets strict state and stores it. <p>
285     * Has <b> OK </b> status if no runtime exceptions occurred.
286     */
_isStrictFormat()287     public void _isStrictFormat() {
288 
289         boolean result = true ;
290         strict = oObj.isStrictFormat() ;
291 
292         tRes.tested("isStrictFormat()", result) ;
293     }
294 
295 
296     /**
297     * Checks long format state. <p>
298     * Has <b> OK </b> status if long format is properly set.
299     * The following method tests are to be completed successfully before :
300     * <ul>
301     *  <li> <code> isLongFormat </code> </li>
302     * </ul>
303     */
_setLongFormat()304     public void _setLongFormat() {
305 
306         boolean result = true ;
307         oObj.setLongFormat(!longFormat) ;
308 
309         result = oObj.isLongFormat() == !longFormat ;
310 
311         if (!result) {
312             log.println("Was '" + longFormat + "', set to '" + !longFormat +
313                 "' but returned '" + oObj.isLongFormat() + "'") ;
314         }
315 
316         tRes.tested("setLongFormat()", result) ;
317     }
318 
319     /**
320     * Gets long format state and stores it. <p>
321     * Has <b> OK </b> status if no runtime exceptions occurred.
322     */
_isLongFormat()323     public void _isLongFormat() {
324 
325         boolean result = true ;
326         longFormat = oObj.isLongFormat() ;
327 
328         tRes.tested("isLongFormat()", result) ;
329     }
330 }
331 
332 
333