1# This file is a Tcl script to test out [incr Widgets] Finddialog 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#   4.x - Other tests
9#
10# Copyright (c) 1995 DSC Technologies Corporation
11#
12# See the file "license.terms" for information on usage and redistribution
13# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
14#
15# @(#) $Id: finddialog.test,v 1.3 2001/08/07 19:56:48 smithc Exp $
16
17package require tcltest
18namespace import -force ::tcltest::*
19
20if [catch {package require Iwidgets 4.0}] {
21  # Let's try modifying the auto_path.  Note that the IWIDGETS_LIBRARY
22  # env var is initialized in the Makefile when doing a 'make test'.
23  # If sourcing this file independently, this variable must be set manually.
24  if ![info exists env(IWIDGETS_LIBRARY)] {
25    error "Unable to locate Iwidgets package.  Set your IWIDGETS_LIBRARY\
26      environment\nvariable to the directory that contains iwidgets.tcl"
27  }
28  lappend auto_path $env(IWIDGETS_LIBRARY)
29  package require Iwidgets 4.0
30}
31
32if {[string compare test [info procs test]] == 1} {
33    source defs
34}
35
36wm geometry . {}
37raise .
38
39set c 1
40set o 1
41set m 1
42
43#
44# Initial construction test
45#
46test Finddialog-1.$c {Finddialog construction} {
47    iwidgets::Scrolledlistbox .slb
48    iwidgets::Scrolledtext .st
49    pack .st
50    .st insert end "Now is the time for all good men\\n" 
51    .st insert end "to come to the aid of their country"
52
53    iwidgets::Finddialog .fd
54    .fd center .st
55    .fd activate
56} {}
57
58incr c
59
60#
61# Option tests which are successful.
62#
63test Finddialog-2.$o {configuration option} {
64    llength [.fd configure]
65} {43}
66
67incr o
68
69foreach test {
70    {-background #d9d9d9 #d9d9d9} 
71    {-buttonboxpadx 10 10} 
72    {-buttonboxpady 10 10} 
73    {-cursor gumby gumby} 
74    {-textwidget .st .st}
75    {-patternbackground blue blue}
76    {-patternforeground white white}
77    {-searchbackground skyblue skyblue}
78    {-searchforeground white white}
79    {-title "Find Dialog" "Find Dialog"}} {
80	set option [lindex $test 0]
81	test Finddialog-2.$o "configuration options, $option" {
82	    .fd configure $option [lindex $test 1]
83	    lindex [.fd configure $option] 4
84	} [lindex $test 2]
85	update 
86	incr o
87}
88
89#
90# Option tests which fail and produce errors.
91#
92foreach test {
93  {-buttonboxpos bogus {bad buttonboxpos option "bogus": should be n, s, e, or w}}
94  {-modality bogus {bad modality option "bogus": should be none, application, or global}}} {
95	set option [lindex $test 0]
96        test Finddialog-2.$o "configuration options, $option" {
97	    list [catch {.fd configure $option [lindex $test 1]} msg] $msg
98	} [list 1 [lindex $test 2]]
99	incr o
100}
101
102#
103# Method tests which are successful.
104#
105foreach test {
106    {{.fd component pattern insert end "the"} {}}
107    {{.fd find} 1.7}
108    {{.fd find} 1.45}
109    {{.fd clear} {}}
110    {{.fd invoke Find} {}}
111    {{.fd buttonconfigure Find -text Search} {}}} {
112	set method [lindex [lindex $test 0] 1]
113	test Finddialog-3.$m "object methods, $method" {
114	    list [catch {eval [lindex $test 0]} msg] $msg
115	} [list 0 [lindex $test 1]]
116	update 
117	incr m
118}
119
120.fd configure -textwidget .bogus
121
122#
123# Method tests which fail and produce errors
124#
125test Finddialog-3.$m "Non existant textwidget" {
126    list [catch {.fd find} msg] $msg
127} [list 1 {bad finddialog text widget value: ".bogus", the widget doesn't exist}]
128update
129incr m
130
131.fd configure -textwidget .slb
132
133test Finddialog-3.$m "Wrong class of textwidget" {
134    list [catch {.fd find} msg] $msg
135} [list 1 {bad finddialog text widget value: ".slb", must be of the class Text or based on Scrolledtext}]
136update
137incr m
138
139#
140# Destruction test
141#
142test Finddialog-1.$c {Finddialog destruction} {
143    destroy .slb
144    destroy .st
145    destroy .fd
146    update 
147} {}
148incr c
149
150#
151# Initial construction test
152#
153test Finddialog-1.$c {Finddialog construction} {
154    iwidgets::Finddialog .fd
155} {.fd}
156
157incr c
158
159#
160# Destruction test
161#
162test Finddialog-1.$c {Finddialog destruction} {
163    destroy .fd
164    update 
165} {}
166
167::tcltest::cleanupTests
168exit
169