summaryrefslogtreecommitdiffstats
path: root/tests/winMsgbox.test
blob: 85fd44df3fef6d4eb7c9860032b0659babdce728 (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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
# This file is a Tcl script to test the Windows specific message box
#
# Copyright (c) 2007 Pat Thoyts <patthoyts@users.sourceforge.net>
#
# RCS: @(#) $Id: winMsgbox.test,v 1.2 2007/12/13 15:27:55 dgp Exp $

package require tcltest 2.1
eval tcltest::configure $argv
tcltest::loadTestedCommands

testConstraint getwindowinfo [expr {[llength [info command ::testgetwindowinfo]] > 0}]

if {[testConstraint testwinevent]} {
    catch {testwinevent debug 1}
}

proc Click {hwnd button} {
    testwinevent $hwnd $button WM_COMMAND
}

proc GetWindowInfo {title button} {
    global windowInfo
    set windowInfo {}
    set hwnd [testfindwindow $title "#32770"]
    set windowInfo [testgetwindowinfo $hwnd]
    array set a $windowInfo
    set childinfo {} ; set childtext ""
    foreach child $a(children) {
        lappend childinfo $child [set info [testgetwindowinfo $child]]
        array set ca $info
        if {$ca(class) eq "Static"} {
            append childtext $ca(text)
        }
    }
    set a(children) $childinfo
    set a(childtext) $childtext
    set windowInfo [array get a]
    testwinevent $hwnd $button WM_COMMAND
}

# -------------------------------------------------------------------------

test winMsgbox-1.0 {tk_messageBox ok} -constraints {win getwindowinfo} -setup {
    wm iconify .
} -body {
    global windowInfo
    set title "winMsgbox-1.0 [pid]"
    after 100 [list GetWindowInfo $title 2]
    tk_messageBox -icon info -type ok -title $title -message Message
} -cleanup {
    wm deiconify .
} -result {ok}

test winMsgbox-1.1 {tk_messageBox okcancel} -constraints {win getwindowinfo} -setup {
    wm iconify .
} -body {
    global windowInfo
    set title "winMsgbox-1.1 [pid]"
    after 100 [list GetWindowInfo $title 1]
    tk_messageBox -icon info -type okcancel -title $title -message Message
} -cleanup {
    wm deiconify .
} -result {ok}

test winMsgbox-1.2 {tk_messageBox okcancel} -constraints {win getwindowinfo} -setup {
    wm iconify .
} -body {
    global windowInfo
    set title "winMsgbox-1.2 [pid]"
    after 100 [list GetWindowInfo $title 2]
    tk_messageBox -icon info -type okcancel -title $title -message Message
} -cleanup {
    wm deiconify .
} -result {cancel}

test winMsgbox-1.3 {tk_messageBox yesno} -constraints {win getwindowinfo} -setup {
    wm iconify .
} -body {
    global windowInfo
    set title "winMsgbox-1.3 [pid]"
    after 100 [list GetWindowInfo $title 6]
    tk_messageBox -icon info -type yesno -title $title -message Message
} -cleanup {
    wm deiconify .
} -result {yes}

test winMsgbox-1.4 {tk_messageBox yesno} -constraints {win getwindowinfo} -setup {
    wm iconify .
} -body {
    global windowInfo
    set title "winMsgbox-1.4 [pid]"
    after 100 [list GetWindowInfo $title 7]
    tk_messageBox -icon info -type yesno -title $title -message Message
} -cleanup {
    wm deiconify .
} -result {no}

test winMsgbox-1.5 {tk_messageBox abortretryignore} -constraints {win getwindowinfo} -setup {
    wm iconify .
} -body {
    global windowInfo
    set title "winMsgbox-1.5 [pid]"
    after 100 [list GetWindowInfo $title 3]
    tk_messageBox -icon info -type abortretryignore -title $title -message Message
} -cleanup {
    wm deiconify .
} -result {abort}

test winMsgbox-1.6 {tk_messageBox abortretryignore} -constraints {win getwindowinfo} -setup {
    wm iconify .
} -body {
    global windowInfo
    set title "winMsgbox-1.6 [pid]"
    after 100 [list GetWindowInfo $title 4]
    tk_messageBox -icon info -type abortretryignore -title $title -message Message
} -cleanup {
    wm deiconify .
} -result {retry}

test winMsgbox-1.7 {tk_messageBox abortretryignore} -constraints {win getwindowinfo} -setup {
    wm iconify .
} -body {
    global windowInfo
    set title "winMsgbox-1.7 [pid]"
    after 100 [list GetWindowInfo $title 5]
    tk_messageBox -icon info -type abortretryignore -title $title -message Message
} -cleanup {
    wm deiconify .
} -result {ignore}

test winMsgbox-1.8 {tk_messageBox retrycancel} -constraints {win getwindowinfo} -setup {
    wm iconify .
} -body {
    global windowInfo
    set title "winMsgbox-1.8 [pid]"
    after 100 [list GetWindowInfo $title 4]
    tk_messageBox -icon info -type retrycancel -title $title -message Message
} -cleanup {
    wm deiconify .
} -result {retry}

test winMsgbox-1.9 {tk_messageBox retrycancel} -constraints {win getwindowinfo} -setup {
    wm iconify .
} -body {
    global windowInfo
    set title "winMsgbox-1.9 [pid]"
    after 100 [list GetWindowInfo $title 2]
    tk_messageBox -icon info -type retrycancel -title $title -message Message
} -cleanup {
    wm deiconify .
} -result {cancel}

test winMsgbox-1.10 {tk_messageBox yesnocancel} -constraints {win getwindowinfo} -setup {
    wm iconify .
} -body {
    global windowInfo
    set title "winMsgbox-1.10 [pid]"
    after 100 [list GetWindowInfo $title 6]
    tk_messageBox -icon info -type yesnocancel -title $title -message Message
} -cleanup {
    wm deiconify .
} -result {yes}

test winMsgbox-1.11 {tk_messageBox yesnocancel} -constraints {win getwindowinfo} -setup {
    wm iconify .
} -body {
    global windowInfo
    set title "winMsgbox-1.11 [pid]"
    after 100 [list GetWindowInfo $title 7]
    tk_messageBox -icon info -type yesnocancel -title $title -message Message
} -cleanup {
    wm deiconify .
} -result {no}

test winMsgbox-1.12 {tk_messageBox yesnocancel} -constraints {win getwindowinfo} -setup {
    wm iconify .
} -body {
    global windowInfo
    set title "winMsgbox-1.12 [pid]"
    after 100 [list GetWindowInfo $title 2]
    tk_messageBox -icon info -type yesnocancel -title $title -message Message
} -cleanup {
    wm deiconify .
} -result {cancel}

# -------------------------------------------------------------------------

test winMsgbox-2.0 {tk_messageBox message} -constraints {win getwindowinfo} -setup {
    wm iconify .
    unset -nocomplain info
} -body {
    global windowInfo
    set title "winMsgbox-2.0 [pid]"
    set message "message"
    after 100 [list GetWindowInfo $title 2]
    set r [tk_messageBox -type ok -title $title -message $message]
    array set info $windowInfo
    lappend r $info(childtext)
} -cleanup {
    wm deiconify .
} -result [list ok "message"]

test winMsgbox-2.1 {tk_messageBox message (long)} -constraints {
    win getwindowinfo
} -setup {
    wm iconify .
    unset -nocomplain info
} -body {
    global windowInfo
    set title "winMsgbox-2.1 [pid]"
    set message [string repeat Ab 80]
    after 100 [list GetWindowInfo $title 2]
    set r [tk_messageBox -type ok -title $title -message $message]
    array set info $windowInfo
    lappend r $info(childtext)
} -cleanup {
    wm deiconify .
} -result [list ok [string repeat Ab 80]]

test winMsgbox-2.2 {tk_messageBox message (unicode)} -constraints {
    win getwindowinfo
} -setup {
    wm iconify .
    unset -nocomplain info
} -body {
    global windowInfo
    set title "winMsgbox-2.2 [pid]"
    set message "\u041f\u043e\u0438\u0441\u043a\u0020\u0441\u0442\u0440\u0430\u043d\u0438\u0446"
    after 100 [list GetWindowInfo $title 2]
    set r [tk_messageBox -type ok -title $title -message $message]
    array set info $windowInfo
    lappend r $info(childtext)
} -cleanup {
    wm deiconify .
} -result [list ok "\u041f\u043e\u0438\u0441\u043a\u0020\u0441\u0442\u0440\u0430\u043d\u0438\u0446"]

test winMsgbox-2.3 {tk_messageBox message (empty)} -constraints {
    win getwindowinfo
} -setup {
    wm iconify .
    unset -nocomplain info
} -body {
    global windowInfo
    set title "winMsgbox-2.3 [pid]"
    after 100 [list GetWindowInfo $title 2]
    set r [tk_messageBox -type ok -title $title]
    array set info $windowInfo
    lappend r $info(childtext)
} -cleanup {
    wm deiconify .
} -result [list ok ""]

test winMsgbox-3.0 {tk_messageBox detail (sourceforge bug #1692927)} -constraints {
    win getwindowinfo
} -setup {
    wm iconify .
    unset -nocomplain info
} -body {
    global windowInfo
    set title "winMsgbox-3.0 [pid]"
    after 100 [list GetWindowInfo $title 2]
    set r [tk_messageBox -type ok -title $title \
               -message Hello -detail "Pleased to meet you"]
    array set info $windowInfo
    lappend r $info(childtext)
} -cleanup {
    wm deiconify .
} -result [list ok "Hello\n\nPleased to meet you"]

test winMsgbox-3.1 {tk_messageBox detail (unicode)} -constraints {
    win getwindowinfo
} -setup {
    wm iconify .
    unset -nocomplain info
} -body {
    global windowInfo
    set title "winMsgbox-3.1 [pid]"
    set message "\u041f\u043e\u0438\u0441\u043a"
    set detail "\u0441\u0442\u0440\u0430\u043d\u0438\u0446"
    after 100 [list GetWindowInfo $title 2]
    set r [tk_messageBox -type ok -title $title -message $message -detail $detail]
    array set info $windowInfo
    lappend r $info(childtext)
} -cleanup {
    wm deiconify .
} -result [list ok "\u041f\u043e\u0438\u0441\u043a\n\n\u0441\u0442\u0440\u0430\u043d\u0438\u0446"]

# -------------------------------------------------------------------------

if {[testConstraint testwinevent]} {
    catch {testwinevent debug 0}
}
cleanupTests
return

# Local variables:
# mode: tcl
# indent-tabs-mode: nil
# End: