1Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
2DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3
4This code is free software; you can redistribute it and/or modify it
5under the terms of the GNU General Public License version 2 only, as
6published by the Free Software Foundation.
7
8This code is distributed in the hope that it will be useful, but WITHOUT
9ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11version 2 for more details (a copy is included in the LICENSE file that
12accompanied this code).
13
14You should have received a copy of the GNU General Public License version
152 along with this work; if not, write to the Free Software Foundation,
16Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17
18Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
19or visit www.oracle.com if you need additional information or have any
20questions.
21
22 CALENDAR TEST SCRIPT
23
24 Masayoshi Okutsu
25 2005-03-18
26
27Introduction
28------------
29
30Calendar Test Script is a simple scripting language to describe test cases
31for java.util.Calendar and its subclasses. It should be much more
32productive to use this script language than writing test programs in Java.
33
34A script looks like below.
35
361 locale ja JP JP
372 timezone Asia/Tokyo
383 new instance jcal
394 test day of week on Heisei 1 Jan 8
405 use jcal
416 clear all
427 set date Heisei 1 Jan 8
438 check day_of_week Sun
44
45The first line defines a Locale to be used for creating Calendar
46instances. Line 2 defines the current TimeZone to be Asia/Tokyo that is
47used creating Calendar instances. Line 3 creates a Calendar instance with
48the Locale and TimeZone instances. Its reference name is `jcal'. Line 4
49indicates a start point for a test case with a short test case
50description. Line 5 designates `jcal' as the current Calendar
51instance. All calendar operation commands are applied to the current
52Calendar instance. Line 6 clears all of the calendar fields (e.g., ERA,
53YEAR, MONTH, etc.). Line 7 sets the ERA, YEAR, MONTH and DAY_OF_MONTH
54fields to Heisei, 1, JANUARY and 8, respectively. Line 8 checks if the
55DAY_OF_WEEK value is SUNDAY. If it's not, then a RuntimeException is
56thrown.
57
58Script Grammar
59--------------
60
61A line is a comment, blank or command line. Any text after '#' is always
62treated as a comment and ignored, like a shell script.
63
64 # This is a comment line.
65
66A command line consists of a command and its parameters, optionally
67followed by a comment. For example,
68
69 set date Heisei 1 Jan 8 # The first day of Heisei
70
71`set' is a command to set `date' to Heisei year 1 January 8th. `Heisei' is
72a constant for the Japanese Heisei era value which is consistent with the
73Japanese imperial calendar implementation. `Jan' is a constant for
74Calendar.SUNDAY. The text after '#' is ignored.
75
76Keywords are case-insensitive.
77
78 set DAY_OF_WEEK MON
79 SET day_of_week Mon
80
81are the same thing.
82
83Lexical analysis is very simple. A command must be complete in a single
84line. Keywords and symbols must be separated by white space. For example,
85"$result+1" is parsed as one token. It must be written as "$result + 1".
86
87Variables
88---------
89
90Variables can be used in any context to store an integer value and are
91referenced in any contexts where an integer value is required. A variable
92name must start with a '$', such as `$maxyear'. The integer value is
93handled as a long.
94
95`$result' is reserved for storing a result of a get commend operation. For
96example, executing the following command:
97
98 get day_of_month
99
100sets $result to the get(Calendar.DAY_OF_MONTH) value of the current
101Calendar instance. (See NEW and USE commands for the current Calendar
102instance.)
103
104Commands
105--------
106
107The following defines each command and its syntax. Keywords are described
108in upper case below.
109
110LOCALE language [country [variant]]
111
112 Creates a Locale instance by calling new Locale(language, country,
113 variant). country and variant are optional. Defining LOCALE overrides
114 the previously defined Locale value if any. The initial Locale value
115 is Locale.getDefault().
116
117TIMEZONE tzid
118
119 Creates a TimeZone instance by calling
120 TimeZone.getTimeZone(tzid). Defining TIMEZONE overrides the previously
121 defined Locale value if any. The initial TimeZone value is
122 TimeZone.getDefault().
123
124NEW INSTANCE calendarname
125
126 Creates a Calendar instance by calling Calendar.getInstance(TimeZone,
127 Locale). TimeZone and Locale are those defined by TIMEZONE and LOCALE
128 commands (or their initial values), respectively. The instance is
129 associated with `calendarname' and becomes the current Calendar
130 instance to be used for testing.
131
132NEW GREGORIAN calendarname
133
134 Creates a Calendar instance by calling new GregorianCalendar(TimeZone,
135 Locale). TimeZone and Locale are those defined by TIMEZONE and LOCALE
136 commands (or their initial values), respectively. The instance is
137 associated with `calendarname' and becomes the current Calendar
138 instance to be used for testing.
139
140TEST [comments...]
141
142 Declares the beginning of a test case. `comments...' gives a short
143 description of a test case. (Multiple lines are not supported.) The
144 test system displays `comments...' to System.out. For example, the
145 following command:
146
147 test A test case for non-lenient mode
148
149 will output:
150
151 Test #n: A test case for non-lenient mode
152
153 where `n' is a sequence number of TEST command lines appeared in a
154 test script file.
155
156USE calendarname
157
158 Specifies the current Calendar instance to use for testing by
159 `calendarname'. If you need to use more than one Calendar instances,
160 then you have to switch those Calendar instances by the USE command.
161
162ASSIGN value variable
163
164 Assigns `value' to `variable'. `value' can be an integer literal, a
165 variable name or a constant. Examples are:
166
167 assign 2005 $year
168 assign $result $temp
169 assign Sun $Microsystems
170
171ASSIGN value variable IF condition
172
173 Assigns `value' to `variable' if `condition' is true. `condition' is a
174 relational expression as:
175
176 value1 relOp value2
177
178 `relOp' must be one of >, >=, ==, !=, <=, <.
179
180EVAL expression
181
182 Evaluates the given *simple* expression and assigns the expression
183 value to $result if `op' is one of the arithmetic operators (+, -, *,
184 /, %). If `op' is one of the relational operators (>, >=, ==, !=, <=,
185 <), then EVAL throws an exception if the expression value is false, or
186 does nothing if the value is true. Note that an operator and values
187 must be separated by white space.
188
189 The following is an example of the ASSIGN and EVAL commands usage to
190 get the next day of week value. Then, it's used to check the
191 roll(DAY_OF_WEEK) result.
192
193 get day_of_week
194 eval $result + 1
195 assign $result $nextDayOfWeek
196 assign Sun $nextDayOfWeek if $nextDayOfWeek > Sat
197 roll day_of_week 1
198 check day_of_week $nextDayOfWeek
199
200CLEAR ALL
201
202 Clears all the calendar fields of the current Calendar instance by
203 calling Calendar.clear().
204
205CLEAR field
206
207 Clears the specified calendar `field' of the current Calendar instance
208 by calling Calendar.clear(field).`field' must be one of the Calendar
209 field indices, ERA, YEAR, MONTH, DAY_OF_MONTH, WEEK_OF_YEAR, etc.
210
211GET MILLIS
212
213 Gets the millisecond value of the current Calendar instance by calling
214 Calendar.getTimeInMillis(). The value is assigned to $result.
215
216GET field
217
218 Gets the `field' value specified of the current Calendar instance by
219 calling Calendar.get(field). The value is assigned to $result.
220
221GET MIN field
222
223 Gets the minimum value of the specified `field' of the current
224 Calendar instance by calling Calendar.getMinimum(field). The value is
225 assigned to $result.
226
227GET GREATESTMIN field
228
229 Gets the greatest minimum value of the specified `field' of the
230 current Calendar instance by calling
231 Calendar.getGreatestMinimum(field). The value is assigned to $result.
232
233GET ACTUALMIN field
234
235 Gets the actual minimum value of the specified `field' of the current
236 Calendar instance by calling Calendar.getActualMinimum(field). The
237 value is assigned to $result.
238
239GET MAX field
240
241 Gets the maximum value of the specified `field' of the current
242 Calendar instance by calling Calendar.getMaximum(field). The value is
243 assigned to $result.
244
245GET LEASTMAX field
246
247 Gets the least maximum value of the specified `field' of the current
248 Calendar instance by calling Calendar.getLeastMaximum(field). The
249 value is assigned to $result.
250
251GET ACTUALMAX field
252
253 Gets the actual maximum value of the specified `field' of the current
254 Calendar instance by calling Calendar.getActualMaximum(field). The
255 value is assigned to $result.
256
257GET FIRSTDAYOFWEEK
258
259 Gets the first day of week value of the current Calendar instance by
260 calling Calendar.getFirstDayOfWeek(). The value is assigned to
261 $result.
262
263GET MINIMALDAYSINFIRSTWEEK
264
265 Gets the minimal days in first week value of the current Calendar
266 instance by calling Calendar.getMinimalDaysInFirstWeek(). The value is
267 assigned to $result.
268
269ADD field amount
270
271 Adds `amount' to the specified `field' of the current Calendar
272 instance by calling Calendar.add(field, amount).
273
274ROLL field amount
275
276 Rolls `amount' of the specified `field' of the current Calendar
277 instance by calling Calendar.roll(field, amount).
278
279SET MILLIS value
280
281 Sets the millisecond value of the current Calendar instance to `value'
282 by calling Calendar.setTimeInMillis(value).
283
284SET field value
285
286 Sets the `field' value of the current Calendar instance to `value' by
287 calling Calendar.set(field, value).
288
289SET DATE era year month dayOfMonth
290
291 Sets the date of the current Calendar instance to the date specified
292 by `era', `year', `month' and `dayOfMonth' by calling
293 Calendar.set(ERA, era) and Calendar.set(year, month,
294 dayOfMonth). Please note that `month' follows the Calendar convention
295 and is 0-based. (e.g., JANUARY is 0)
296
297SET DATE year month dayOfMonth
298
299 Sets the date of the current Calendar instance to the date specified
300 by `year', `month' and `dayOfMonth' by calling
301 Calendar.set(year, month, dayOfMont). Please note that `month'
302 follows the Calendar convention and is 0-based. (e.g., JANUARY is 0)
303
304SET DATETIME year month dayOfMonth hourOfDay minute second
305
306 Sets the date and time of the current Calendar instance to the date
307 and time specified by `year', `month', `dayOfMonth', `hourOfDay',
308 `minute', and `second' by calling Calendar.set(year, month,
309 dayOfMonth, hourOfDay, minute, second). Please note that `hourOfDay'
310 is the 24-hour clock.
311
312SET TIMEOFDAY hourOfDay minute second millisecond
313
314 Sets the date and time of the current Calendar instance to the date
315 and time specified by `year', `month', `dayOfMonth', `hourOfDay',
316 `minute', and `second' by calling Calendar.set(HOUR_OF_DAY,
317 hourOfDay), Calendar.set(MINUTE, minute), and Calendar.set(SECOND,
318 second).
319
320SET FIRSTDAYOFWEEK value
321
322 Sets the first day of week value of the current Calendar instance to
323 `value' by calling Calendar.setFirstDayOfWeek(value).
324
325SET MINIMALDAYSINFIRSTWEEK value
326
327 Sets the minimal days in the first week value of the current Calendar
328 instance to `value' by calling Calendar.setMinimalDaysInFirstWeek(value).
329
330SET LENIENT
331
332 Sets the lenient mode in the current Calendar instance by calling
333 Calendar.setLenient(true).
334
335SET NON-LENIENT
336
337 Sets the non-lenient mode in the current Calendar instance by calling
338 Calendar.setLenient(false).
339
340CHECK MILLIS value
341
342 Checks if the specified `value' is the same as the millisecond value
343 of the current Calendar instance given by calling
344 Calendar.getTimeInMillis(). If the values are different, an exception
345 is thrown.
346
347CHECK DATE era year month dayOfMonth
348
349 Checks if the date specified by `era', `year', `month' and
350 `dayOfMonth' is the same date of the current Calendar instance. The
351 calendar date is given by calling Calendar.get(ERA),
352 Calendar.get(YEAR), Calendar.get(MONTH), and
353 Calendar.get(DAY_OF_MONTH). If the dates are different, an exception
354 is thrown.
355
356CHECK DATE year month dayOfMonth
357
358 Checks if the date specified by `year', `month' and `dayOfMonth' is
359 the same date of the current Calendar instance. The calendar date is
360 given by calling Calendar.get(YEAR), Calendar.get(MONTH), and
361 Calendar.get(DAY_OF_MONTH). If the dates are different, an exception
362 is thrown.
363
364CHECK DATETIME year month dayOfMonth hourOfDay minute second
365
366 Checks if the date and time specified by `year', `month',
367 `dayOfMonth', `hourOfDay', `minute', and `second' are the same ones of
368 the current Calendar instance. The calendar date and time are given by
369 calling Calendar.get(YEAR), Calendar.get(MONTH),
370 Calendar.get(DAY_OF_MONTH), Calendar.get(HOUR_OF_DAY),
371 Calendar.get(MINUTE) and Calendar.get(SECOND). If the dates or times
372 are different, an exception is thrown.
373
374CHECK DATETIME year month dayOfMonth hourOfDay minute second millisecond
375
376 Checks if the date and time specified by `year', `month',
377 `dayOfMonth', `hourOfDay', `minute', `second' and `millisecond' are
378 the same ones of the current Calendar instance. The calendar date and
379 time are given by calling Calendar.get(YEAR), Calendar.get(MONTH),
380 Calendar.get(DAY_OF_MONTH), Calendar.get(HOUR_OF_DAY),
381 Calendar.get(MINUTE), Calendar.get(SECOND) and
382 Calendar.get(MILLISECOND). If the dates or times are different, an
383 exception is thrown.
384
385CHECK TIMEOFDAY hourOfDay minute second millisecond
386
387 Checks if the time of day specified by `hourOfDay', `minute', `second'
388 and `millisecond' are the same ones of the current Calendar
389 instance. The calendar date and time are given by calling
390 Calendar.get(HOUR_OF_DAY), Calendar.get(MINUTE), Calendar.get(SECOND)
391 and Calendar.get(MILLISECOND). If the times are different, an
392 exception is thrown.
393
394CHECK field value
395
396 Checks if the value of the given `field' of the current Calendar
397 instance is equal to the given `value'. If it doesn't, an exception is
398 thrown.
399
400CHECK MIN field value
401
402 Checks if the minimum value of the specified `field' of the current
403 Calendar instance is equal to the specified `value'. If not, an
404 exception is thrown.
405
406CHECK GREATESTMIN field value
407
408 Checks if the greatest minimum value of the specified `field' of the
409 current Calendar instance is equal to the specified `value'. If not,
410 an exception is thrown.
411
412CHECK ACTUALMIN field value
413
414 Checks if the actual minimum value of the specified `field' of the
415 current Calendar instance is equal to the specified `value'. If not,
416 an exception is thrown.
417
418CHECK MAX field value
419
420 Checks if the maximum value of the specified `field' of the current
421 Calendar instance is equal to the specified `value'. If not, an
422 exception is thrown.
423
424CHECK LEASTMAX field value
425
426 Checks if the least maximum value of the specified `field' of the
427 current Calendar instance is equal to the specified `value'. If not,
428 an exception is thrown.
429
430CHECK ACTUALMAX field value
431
432 Checks if the actual maximum value of the specified `field' of the
433 current Calendar instance is equal to the specified `value'. If not,
434 an exception is thrown.
435
436EXCEPTION exceptionname
437
438 Checks if the previous command threw the specified exception by
439 `exceptionname'. For example, the following tests invalid date
440 detection in non-lenient.
441
442 set non-lenient
443 set date 2005 Feb 29 # 2005 isn't a leap year.
444 get millis
445 exception IllegalArgumentException
446
447PRINT variable
448
449 Prints the value of `variable'.
450
451PRINT INSTANCE [calendarname]
452
453 Prints the Calendar.toString() value of the current Calendar instance
454 or the instance given by `calendarname'.
455
456PRINT field
457
458 Prints the value of the specified `field' of the current Calendar
459 instance. The value is obtained by calling Calendar.get(field).
460
461PRINT MILLIS
462
463 Prints the millisecond value of the current Calendar instance. The
464 value is obtained by calling Calendar.getTimeInMillis().
465
466PRINT MIN field
467
468 Prints the minimum value of the specified field by `field' of the
469 current Calendar instance. The value is obtained by calling
470 Calendar.getMinimum(field).
471
472PRINT GREATESTMIN field
473
474 Prints the greatest minimum value of the specified field by `field' of
475 the current Calendar instance. The value is obtained by calling
476 Calendar.getGreatestMinimum(field).
477
478PRINT ACTUALMIN field
479
480 Prints the actual minimum value of the specified field by `field' of
481 the current Calendar instance by calling
482 Calendar.getActualMinimum(field).
483
484PRINT MAX field
485
486 Prints the maximum value of the specified field by `field' of the
487 current Calendar instance. The value is obtained by calling
488 Calendar.getMaximum(field).
489
490PRINT LEASTMAX field
491
492 Prints the least maximum value of the specified field by `field' of
493 the current Calendar instance. The value is obtained by calling
494 Calendar.getLeastMaximum(field).
495
496PRINT ACTUALMAX field
497
498 Prints the actual maximum value of the specified field by `field' of
499 the current Calendar instance. The value is obtained by calling
500 Calendar.getActualMaximum(field).
501
502PRINT DATE
503
504 Prints the date of the current Calendar instance in format
505 "[ERA] yyyy-MM-dd". The date is obtained by calling Calendar.get(ERA),
506 Calendar.get(YEAR), Calendar.get(MONTH), and
507 Calendar.get(DAY_OF_MONTH).
508
509PRINT DATETIME
510
511 Prints the date and time of the current Calendar instance in an ISO
512 8601-style format "[ERA] yyyy-MM-ddTHH:mm:ss.SSS{Z|{+|-}hhmm}". The
513 date and time are obtained by calling Calendar.get(ERA),
514 Calendar.get(YEAR), Calendar.get(MONTH), Calendar.get(DAY_OF_MONTH),
515 Calendar.get(HOUR_OF_DAY), Calendar.get(MINUTE), Calendar.get(SECOND),
516 Calendar.get(MILLISECOND), Calendar.get(ZONE_OFFSET), and
517 Calendar.get(DST_OFFSET).
518
519PRINT TIMEZONE
520
521 Prints the toString() value of the current TimeZone.
522
523PRINT LOCALE
524
525 Prints the toString() value of the current Locale.
526
527Usage
528-----
529
530The usage of the test script system at this directory is:
531
532 $ javac -d classes --add-exports java.base/sun.util=ALL-UNNAMED --add-exports java.base/sun.util.calendar=ALL-UNNAMED *.java
533 $ java -cp classes CalendarTestEngine scriptfiles...
534
535A script file has suffix ".cts" by convention. If multiple script files
536are specified. Those files are sequentially executed as if those are a
537single test script. For example, if we have the following script files:
538
539 file1.cts:
540 locale ja JP JP
541 timezone Asia/Tokyo
542 file2.cts:
543 new instance jcal
544 new gregorian gcal
545 test example
546 use jcal
547 print datetime
548 get millis
549 print $result
550 use gcal
551 set millis $result
552 print datetime
553
554running CalendarTestEngine with those files will produce:
555
556 $ java -cp classes CalendarTestEngine file1.cts file2.cts
557 Starting file1.cts...
558 Completed file1.cts
559 Starting file2.cts...
560 Test #1: example
561 file2.cts:5: Heisei 0017-03-18T20:00:25.402+0900
562 file2.cts:7: $result=1111143625402
563 file2.cts:10: 2005-03-18T20:00:25.402+0900
564 Completed file2.cts
565
566[end of README]
567