1# This file is a Tcl script to test out [incr Widgets] Spindate class.
2# It is organized in the standard fashion for Tcl tests with the following
3# notation for test case labels:
4#
5#   1.x - Construction/Destruction tests
6#   2.x - Configuration option tests
7#   3.x - Method tests
8#
9# Copyright (c) 1995 DSC Technologies Corporation
10#
11# See the file "license.terms" for information on usage and redistribution
12# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
13#
14# @(#) $Id: spindate.test,v 1.3 2001/08/07 19:56:48 smithc Exp $
15
16package require tcltest
17namespace import -force ::tcltest::*
18
19if [catch {package require Iwidgets 4.0}] {
20  # Let's try modifying the auto_path.  Note that the IWIDGETS_LIBRARY
21  # env var is initialized in the Makefile when doing a 'make test'.
22  # If sourcing this file independently, this variable must be set manually.
23  if ![info exists env(IWIDGETS_LIBRARY)] {
24    error "Unable to locate Iwidgets package.  Set your IWIDGETS_LIBRARY\
25      environment\nvariable to the directory that contains iwidgets.tcl"
26  }
27  lappend auto_path $env(IWIDGETS_LIBRARY)
28  package require Iwidgets 4.0
29}
30
31if {[string compare test [info procs test]] == 1} {
32    source defs
33}
34
35wm geometry . {}
36raise .
37
38set c 1
39set o 1
40set m 1
41
42#
43# Initial construction test
44#
45test Spindate-1.$c {Spindate construction} {
46    iwidgets::Spindate .sd
47    pack .sd -padx 10 -pady 10 -fill both -expand yes
48    update 
49} {}
50
51incr c
52
53#
54# Option tests which are successful.
55#
56test Spindate-2.$o {configuration option} {
57    llength [.sd configure]
58} {26}
59
60incr o
61
62foreach test {
63    {-arroworient horizontal horizontal}
64    {-arroworient vertical vertical}
65    {-background #d9d9d9 #d9d9d9}
66    {-cursor gumby gumby}
67    {-datemargin 3 3}
68    {-daylabel Day: Day:}
69    {-dayon false false}
70    {-dayon true true}
71    {-daywidth 4 4}
72    {-labelmargin 4 4}
73    {-labelpos n n}
74    {-labelpos s s}
75    {-labelpos e e}
76    {-labelpos w w}
77    {-monthformat integer integer}
78    {-monthformat brief brief}
79    {-monthformat full full}
80    {-monthlabel Month: Month:}
81    {-monthon false false}
82    {-monthon true true}
83    {-monthwidth 4 4}
84    {-orient horizontal horizontal}
85    {-orient vertical vertical}
86    {-textbackground GhostWhite GhostWhite}
87    {-yeardigits 2 2}
88    {-yeardigits 4 4}
89    {-yearlabel Year: Year:}
90    {-yearon false false}
91    {-yearon true true}
92    {-yearwidth 4 4}} {
93	set option [lindex $test 0]
94	test Spindate-2.$o "configuration options, $option" {
95	    .sd configure $option [lindex $test 1]
96	    lindex [.sd configure $option] 4
97	} [lindex $test 2]
98	update 
99	incr o
100}
101
102#
103# Option tests which fail and produce errors.
104#
105foreach test {
106  {-yeardigits bogus {bad yeardigits option "bogus", should be 2 or 4}}
107  {-monthformat bogus {bad monthformat option "bogus", should be "integer", "brief" or "full"}}} {
108	set option [lindex $test 0]
109        test Spindate-2.$o "configuration options, $option" {
110	    list [catch {.sd configure $option [lindex $test 1]} msg] $msg
111	} [list 1 [lindex $test 2]]
112	incr o
113}
114
115#
116# Method tests which are successful.
117#
118foreach test {
119    {{.sd show 3/3/1960} {}}
120    {{.sd get -string} "03 March 1960"}} {
121	set method [lindex [lindex $test 0] 1]
122	test Spindate-3.$m "object methods, $method" {
123	    list [catch {eval [lindex $test 0]} msg] $msg
124	} [list 0 [lindex $test 1]]
125	update 
126	incr m
127}
128
129foreach test {
130    {{.sd show bogus} {bad date: "bogus", must be a valid date string, clock clicks value or the keyword now}}
131    {{.sd get bogus} {bad format option "bogus": should be -string or -clicks}}} {
132	set method [lindex [lindex $test 0] 1]
133	test ScrolledListBox-3.$m "object methods, $method" {
134	    list [catch {eval [lindex $test 0]} msg] $msg
135	} [list 1 [lindex $test 1]]
136	incr m
137}
138
139#
140# Conclusion of constrcution/destruction tests
141#
142test Spindate-1.$c {Spindate destruction} {
143    destroy .sd
144    update 
145} {}
146
147incr c
148
149test Spindate-1.$c {Spindate construction} {
150    iwidgets::spindate .sd -monthformat brief
151    pack .sd -padx 10 -pady 10 -fill both -expand yes
152    update 
153} {}
154
155incr c
156
157test Spindate-1.$c {Spindate destruction} {
158    destroy .sd
159    update 
160} {}
161
162incr c
163
164test Spindate-1.$c {Spindate destruction} {
165    iwidgets::spindate .sd
166    pack .sd
167    destroy .sd
168    update 
169} {}
170
171::tcltest::cleanupTests
172exit
173