1# This file is a Tcl script to test out [incr Widgets] Datefield 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: datefield.test,v 1.5 2001/11/16 15:28:03 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 Datefield-1.$c {Datefield construction} { 46 iwidgets::Datefield .df -labeltext "Date Field" 47 pack .df -padx 10 -pady 10 -fill both -expand yes 48 update 49} {} 50 51incr c 52 53# 54# Option tests which are successful. First confirm proper number of options. 55# 56test Datefield-2.$o {configuration option} { 57 llength [.df configure] 58} {28} 59 60incr o 61 62foreach test { 63 {-background #d9d9d9 #d9d9d9} 64 {-borderwidth 4 4} 65 {-borderwidth 2 2} 66 {-command {.df configure -background red} {.df configure -background red}} 67 {-cursor gumby gumby} 68 {-exportselection 0 0} 69 {-foreground Green Green} 70 {-foreground Black Black} 71 {-highlightcolor Red Red} 72 {-highlightthickness 2 2} 73 {-insertbackground Yellow Yellow} 74 {-insertbackground Black Black} 75 {-int yes yes} 76 {-int no no} 77 {-iq average average} 78 {-iq high high} 79 {-justify right right} 80 {-justify center center} 81 {-justify left left} 82 {-labelmargin 5 5} 83 {-labelpos w w} 84 {-labelpos nw nw} 85 {-labelpos n n} 86 {-labelpos ne ne} 87 {-labelpos e e} 88 {-labelpos se se} 89 {-labelpos s s} 90 {-labelpos sw sw} 91 {-labeltext Label Label} 92 {-relief raised raised} 93 {-relief sunken sunken} 94 {-gmt true true} 95 {-gmt false false} 96 {-gmt on on} 97 {-gmt off off} 98 {-gmt 1 1} 99 {-gmt 0 0} 100 {-gmt yes yes} 101 {-gmt no no} 102 {-sticky w w} 103 {-sticky nw nw} 104 {-sticky n n} 105 {-sticky ne ne} 106 {-sticky e e} 107 {-sticky se se} 108 {-sticky s s} 109 {-sticky sw sw} 110 {-sticky news news} 111 {-textbackground GhostWhite GhostWhite} 112 {-textbackground #d9d9d9 #d9d9d9}} { 113 set option [lindex $test 0] 114 test Datefield-2.$o "configuration options, $option" { 115 .df configure $option [lindex $test 1] 116 lindex [.df configure $option] 4 117 } [lindex $test 2] 118 update 119 incr o 120} 121 122# 123# Option tests which fail and produce errors. 124# 125foreach test { 126 {-iq bogus {bad iq option "bogus": should be high, average or low}} 127 {-gmt bogus {bad gmt option "bogus": should be boolean}} 128 {-childsitepos bogus {bad childsite option "bogus": should be n, e, s, or w}}} { 129 set option [lindex $test 0] 130 test Datefield-2.$o "configuration options, $option" { 131 list [catch {.df configure $option [lindex $test 1]} msg] $msg 132 } [list 1 [lindex $test 2]] 133 incr o 134} 135 136# 137# Method tests which are successful. 138# 139foreach test { 140 {{.df childsite} {.df.lwchildsite}} 141 {{.df show 03/03/1960} {}} 142 {{.df get} {03/03/1960}} 143 {{.df get -string} {03/03/1960}} 144 {{.df isvalid} {1}} 145 {{.df component date delete 0 end} {}} 146 {{.df component date insert end 03/32/1960} {}} 147 {{.df isvalid} {0}} 148 {{.df show 03/03/1960} {}} 149 {{.df show now} {}}} { 150 set method [lindex [lindex $test 0] 1] 151 test Datefield-3.$m "object methods, $method" { 152 list [catch {eval [lindex $test 0]} msg] $msg 153 } [list 0 [lindex $test 1]] 154 update 155 incr m 156} 157 158test Datefield-3.$m "object methods, clock clicks" { 159 set clicks [clock scan "06/08/1964"] 160 .df show $clicks 161 update 162 .df get 163} {06/08/1964} 164incr m 165 166# 167# Method tests which fail and produce errors 168# 169foreach test { 170 {{.df get bogus} {bad format option "bogus": should be -string or -clicks}} 171 {{.df show bogus} {bad date: "bogus", must be a valid date string, clock clicks value or the keyword now}}} { 172 set method [lindex [lindex $test 0] 1] 173 test Datefield-3.$m "object methods, $method" { 174 list [catch {eval [lindex $test 0]} msg] $msg 175 } [list 1 [lindex $test 1]] 176 incr m 177} 178 179# 180# Conclusion of constrcution/destruction tests 181# 182test Datefield-1.$c {Datefield destruction} { 183 destroy .df 184 update 185} {} 186 187incr c 188 189test Datefield-1.$c {Datefield construction} { 190 iwidgets::datefield .df 191 pack .df -padx 10 -pady 10 192 update 193} {} 194 195incr c 196 197test Datefield-1.$c {Datefield destruction} { 198 destroy .df 199 update 200} {} 201 202::tcltest::cleanupTests 203exit 204