summaryrefslogtreecommitdiff
path: root/tix/tests/general/filebox.tcl
blob: 4ded2be0854e8d313f35e0e5e80627fe6ab4b3f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# filebox.tcl --
#
#	Tests the File selection box and dialog widget.
#
# Copyright (c) 1996, Expert Interface Technologies
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#

proc About {} {
    return "Testing the (Ex)FileSelectBox and (Ex)FileSelectDialog widgets."
}

proc FdTest_GetFile {args} {
    global fdTest_selected

    set fdTest_selected [tixEvent value]
}

proc Test {} {
    global fdTest_fullPath

    if [tixStrEq [tix platform] "unix"] {
	set fdTest_fullPath /etc/passwd
    } else {
	set fdTest_fullPath C:\\Windows\\System.ini
    }

    Test_FileSelectBox
    Test_FileSelectDialog

    Test_ExFileSelectBox
    Test_ExFileSelectDialog
}

proc Test_FileSelectBox {} {
    global fdTest_selected fdTest_fullPath

    TestBlock filebox-1.1 {FileSelectBox} {
	set w [tixFileSelectBox .f -command FdTest_GetFile]
	pack $w -expand yes -fill both
	update

	InvokeComboBoxByKey [$w subwidget selection] "$fdTest_fullPath"
	Assert {[tixStrEq $fdTest_selected "$fdTest_fullPath"]}
    }
    catch {
	destroy $w
    }
}

proc Test_FileSelectDialog {} {
    global fdTest_selected fdTest_fullPath

    TestBlock filebox-2.1 {FileSelectDialog} {
	set w [tixFileSelectDialog .f -command FdTest_GetFile]
	$w popup
	update

	InvokeComboBoxByKey [$w subwidget fsbox subwidget selection] \
	    "$fdTest_fullPath"
	Assert {[tixStrEq $fdTest_selected "$fdTest_fullPath"]}
    }
    catch {
	destroy $w
    }
}

proc Test_ExFileSelectBox {} {
    global fdTest_selected fdTest_fullPath

    TestBlock filebox-3.1 {ExFileSelectBox} {
	set w [tixExFileSelectBox .f -command FdTest_GetFile]
	pack $w -expand yes -fill both
	update

	$w subwidget file config -selection "$fdTest_fullPath" \
	    -value "$fdTest_fullPath"
	Assert {[tixStrEq $fdTest_selected "$fdTest_fullPath"]}
    }

    TestBlock filebox-3.2 {Keyboard input in ExFileSelectBox entry subwidget} {
	set dirCbx  [$w subwidget dir]
	set fileCbx [$w subwidget file]
	set okBtn   [$w subwidget ok]

	foreach file {Foo bar "Foo Bar"} {
	    set fdTest_selected ""

	    InvokeComboBoxByKey $fileCbx $file
	    set fullPath [tixFSJoin [$dirCbx cget -value] $file]
	    update

	    Assert {[tixStrEq "$fdTest_selected" "$fullPath"]}
	}
    }

    TestBlock filebox-3.3 {Keyboard and then press OK} {
	foreach file {bar "Foo Bar"} {
	    set fdTest_selected ""

	    SetComboBoxByKey $fileCbx $file
	    Click $okBtn
	    set fullPath [tixFSJoin [$dirCbx cget -value] $file]
	    update

	    Assert {[tixStrEq "$fdTest_selected" "$fullPath"]}
	}
    }

    catch {
	destroy $w
    }
}

proc Test_ExFileSelectDialog {} {
    global fdTest_selected fdTest_fullPath

    TestBlock filebox-4.1 {ExFileSelectDialog} {
	set w [tixExFileSelectDialog .f -command FdTest_GetFile]
	$w popup
	update

	InvokeComboBoxByKey [$w subwidget fsbox subwidget file] \
	    $fdTest_fullPath
	Assert {[tixStrEq $fdTest_selected "$fdTest_fullPath"]}
    }

    catch {
	destroy $w
    }
}