Tk Source Code

Check-in [1e599672]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Merge trunk
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | revised_text | tip-466
Files: files | file ages | folders
SHA3-256: 1e599672ed3ee123b4615f2095236e22d9009f9c1bfea2c5ff09e0879ce2cec3
User & Date: jan.nijtmans 2025-05-01 06:57:23.379
Context
2025-05-15
13:06
Merge trunk check-in: 454a12d8 user: jan.nijtmans tags: revised_text, tip-466
2025-05-01
06:57
Merge trunk check-in: 1e599672 user: jan.nijtmans tags: revised_text, tip-466
2025-04-30
12:05
Merge-mark check-in: 7af6ab73 user: jan.nijtmans tags: trunk, main
2025-04-11
16:50
Merge trunk check-in: d2eaf413 user: jan.nijtmans tags: revised_text, tip-466
Changes
Unified Diff Ignore Whitespace Patch
Changes to library/fontchooser.tcl.
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
	set S(W) $S(-parent).$windowName
    }

    # Now build the dialog
    if {![winfo exists $S(W)]} {
	toplevel $S(W) -class TkFontDialog
	if {[package provide tcltest] ne {}} {
	    set ::tk_dialog $S(W)
	}
	wm withdraw $S(W)
	wm title $S(W) $S(-title)
	wm transient $S(W) [winfo toplevel $S(-parent)]

	set outer [::ttk::frame $S(W).outer -padding {7.5p 7.5p}]
	::tk::AmpWidget ::ttk::label $S(W).font -text [::msgcat::mc "&Font:"]







|







168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
	set S(W) $S(-parent).$windowName
    }

    # Now build the dialog
    if {![winfo exists $S(W)]} {
	toplevel $S(W) -class TkFontDialog
	if {[package provide tcltest] ne {}} {
	    set ::tk::test::dialog::testDialog $S(W)
	}
	wm withdraw $S(W)
	wm title $S(W) $S(-title)
	wm transient $S(W) [winfo toplevel $S(-parent)]

	set outer [::ttk::frame $S(W).outer -padding {7.5p 7.5p}]
	::tk::AmpWidget ::ttk::label $S(W).font -text [::msgcat::mc "&Font:"]
Changes to library/print.tcl.
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

	    #First, we select the printer.
	    _selectprinter

	    #Next, set values. Some are taken from the printer,
	    #some are sane defaults.

	if {[info exists printer_name] && $printer_name ne ""} {
	    set printargs(hDC) $printer_name
	    set printargs(pw) $paper_width
	    set printargs(pl) $paper_height
	    set printargs(lm) 1000
	    set printargs(tm) 1000
	    set printargs(rm) 1000
	    set printargs(bm) 1000
	    set printargs(resx) $dpi_x
	    set printargs(resy) $dpi_y
	    set printargs(copies) $copies
	    set printargs(resolution) [list $dpi_x $dpi_y]
		}
	}

	# _print_data
	# This function prints multiple-page files, using a line-oriented
	# function, taking advantage of knowing the character widths.
	# Arguments:
	# data -       Text data for printing







|
|
|
|
|
|
|
|
|
|
|
|
|







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

	    #First, we select the printer.
	    _selectprinter

	    #Next, set values. Some are taken from the printer,
	    #some are sane defaults.

	    if {[info exists printer_name] && $printer_name ne ""} {
		set printargs(hDC) $printer_name
		set printargs(pw) $paper_width
		set printargs(pl) $paper_height
		set printargs(lm) 1000
		set printargs(tm) 1000
		set printargs(rm) 1000
		set printargs(bm) 1000
		set printargs(resx) $dpi_x
		set printargs(resy) $dpi_y
		set printargs(copies) $copies
		set printargs(resolution) [list $dpi_x $dpi_y]
	    }
	}

	# _print_data
	# This function prints multiple-page files, using a line-oriented
	# function, taking advantage of knowing the character widths.
	# Arguments:
	# data -       Text data for printing
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290

	    # For normal windows, this may be fine--but for a canvas, one
	    # wants the canvas dimensions, and not the WINDOW dimensions.
	    if {[winfo class $wid] eq "Canvas"} {
		set sc [$wid cget -scrollregion]
		# if there is no scrollregion, use width and height.
		if {$sc eq ""} {
		    set window_x [$wid cget -width]
		    set window_y [$wid cget -height]
		} else {
		    set window_x [lindex $sc 2]
		    set window_y [lindex $sc 3]
		}
	    } else {
		set window_x [winfo width $wid]
		set window_y [winfo height $wid]







|
|







275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290

	    # For normal windows, this may be fine--but for a canvas, one
	    # wants the canvas dimensions, and not the WINDOW dimensions.
	    if {[winfo class $wid] eq "Canvas"} {
		set sc [$wid cget -scrollregion]
		# if there is no scrollregion, use width and height.
		if {$sc eq ""} {
		    set window_x [winfo pixels $wid [$wid cget -width]]
		    set window_y [winfo pixels $wid [$wid cget -height]]
		} else {
		    set window_x [lindex $sc 2]
		    set window_y [lindex $sc 3]
		}
	    } else {
		set window_x [winfo width $wid]
		set window_y [winfo height $wid]
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
	    # at character level, not words, so we do it by ourselves.
	    # compute usable page width in inches
	    set pw [dict get {a4 8.27 legal 8.5 letter 8.5} $media]
	    set pw [expr {
		$pw - ($option(margin-left) + $option(margin-right)) / 72.0
	    }]
	    # set the wrap length at 98% of computed page width in chars
	    # the 9.8 constant is the product 10.0 (default cpi) * 0.95
	    set wl [expr {int( 9.8 * $pw / $tzoom )}]
	    set data [encoding convertto utf-8 [_wrapLines [$w get 1.0 end] $wl]]
	}

	# launch the job in the background
	after idle [namespace code \
	    [list cups print $option(printer) $data {*}$printargs]]







|







1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
	    # at character level, not words, so we do it by ourselves.
	    # compute usable page width in inches
	    set pw [dict get {a4 8.27 legal 8.5 letter 8.5} $media]
	    set pw [expr {
		$pw - ($option(margin-left) + $option(margin-right)) / 72.0
	    }]
	    # set the wrap length at 98% of computed page width in chars
	    # the 9.8 constant is the product 10.0 (default cpi) * 0.98
	    set wl [expr {int( 9.8 * $pw / $tzoom )}]
	    set data [encoding convertto utf-8 [_wrapLines [$w get 1.0 end] $wl]]
	}

	# launch the job in the background
	after idle [namespace code \
	    [list cups print $option(printer) $data {*}$printargs]]
Changes to macosx/tkMacOSXWindowEvent.c.
112
113
114
115
116
117
118












119
120
121
122
123
124
125
	} else {
	    systemDialog = win;
	}
	if (winPtr && Tk_IsMapped(winPtr)) {
	    GenerateActivateEvents(winPtr, true);
	}
    }












}

- (void) windowBoundsChanged: (NSNotification *) notification
{
#ifdef TK_MAC_DEBUG_NOTIFICATIONS
    TKLog(@"-[%@(%p) %s] %@", [self class], self, sel_getName(_cmd), notification);
#endif







>
>
>
>
>
>
>
>
>
>
>
>







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
	} else {
	    systemDialog = win;
	}
	if (winPtr && Tk_IsMapped(winPtr)) {
	    GenerateActivateEvents(winPtr, true);
	}
    }
    /*
     * Make sure that the updated keyWindow is associated with the
     * current TkEventTarget.
     */
 
    NSWindow *keyWin = [NSApp keyWindow];
    if (keyWin) {
	TkWindow *keyWinPtr = TkMacOSXGetTkWindow(keyWin);
	if (keyWinPtr) {
	    [NSApp setTkEventTarget:keyWinPtr];
	}
    }
}

- (void) windowBoundsChanged: (NSNotification *) notification
{
#ifdef TK_MAC_DEBUG_NOTIFICATIONS
    TKLog(@"-[%@(%p) %s] %@", [self class], self, sel_getName(_cmd), notification);
#endif
241
242
243
244
245
246
247



248

249
250


251
252
253
254
255
256
257
    // the window needs to be updated.  That is the purpose of this method.

#ifdef TK_MAC_DEBUG_NOTIFICATIONS
    TKLog(@"-[%@(%p) %s] %@", [self class], self, sel_getName(_cmd), notification);
#endif
    NSWindow *w = [notification object];
    TkWindow *winPtr = TkMacOSXGetTkWindow(w);





    if (winPtr && winPtr->wmInfoPtr->hints.initial_state != IconicState) {
	winPtr->wmInfoPtr->hints.initial_state = IconicState;


	TkWmUnmapWindow(winPtr);
    }
}

- (BOOL) windowShouldClose: (NSWindow *) w
{
#ifdef TK_MAC_DEBUG_NOTIFICATIONS







>
>
>
|
>
|
|
>
>







253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
    // the window needs to be updated.  That is the purpose of this method.

#ifdef TK_MAC_DEBUG_NOTIFICATIONS
    TKLog(@"-[%@(%p) %s] %@", [self class], self, sel_getName(_cmd), notification);
#endif
    NSWindow *w = [notification object];
    TkWindow *winPtr = TkMacOSXGetTkWindow(w);
    NSString *name = [notification name];
    if (!winPtr) {
	return;
    }
    if ([name isEqualToString:NSWindowWillMiniaturizeNotification]) {
	if (winPtr && winPtr->wmInfoPtr->hints.initial_state != IconicState) {
	    winPtr->wmInfoPtr->hints.initial_state = IconicState;
	}
    } else {
	TkWmUnmapWindow(winPtr);
    }
}

- (BOOL) windowShouldClose: (NSWindow *) w
{
#ifdef TK_MAC_DEBUG_NOTIFICATIONS
340
341
342
343
344
345
346

347
348
349
350
351
352
353
    observe(NSWindowDidBecomeKeyNotification, windowActivation:);
    observe(NSWindowDidResignKeyNotification, windowActivation:);
    observe(NSWindowWillCloseNotification, windowActivation:);
    observe(NSWindowDidMoveNotification, windowBoundsChanged:);
    observe(NSWindowDidResizeNotification, windowBoundsChanged:);
    observe(NSWindowDidDeminiaturizeNotification, windowExpanded:);
    observe(NSWindowDidMiniaturizeNotification, windowCollapsed:);

    observe(NSWindowWillOrderOnScreenNotification, windowMapped:);
    observe(NSWindowDidOrderOnScreenNotification, windowBecameVisible:);
    observe(NSWindowWillStartLiveResizeNotification, windowLiveResize:);
    observe(NSWindowDidEndLiveResizeNotification, windowLiveResize:);
    observe(NSWindowDidEnterFullScreenNotification, windowEnteredFullScreen:);
    observe(NSWindowDidExitFullScreenNotification, windowExitedFullScreen:);








>







358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
    observe(NSWindowDidBecomeKeyNotification, windowActivation:);
    observe(NSWindowDidResignKeyNotification, windowActivation:);
    observe(NSWindowWillCloseNotification, windowActivation:);
    observe(NSWindowDidMoveNotification, windowBoundsChanged:);
    observe(NSWindowDidResizeNotification, windowBoundsChanged:);
    observe(NSWindowDidDeminiaturizeNotification, windowExpanded:);
    observe(NSWindowDidMiniaturizeNotification, windowCollapsed:);
    observe(NSWindowWillMiniaturizeNotification, windowCollapsed:);
    observe(NSWindowWillOrderOnScreenNotification, windowMapped:);
    observe(NSWindowDidOrderOnScreenNotification, windowBecameVisible:);
    observe(NSWindowWillStartLiveResizeNotification, windowLiveResize:);
    observe(NSWindowDidEndLiveResizeNotification, windowLiveResize:);
    observe(NSWindowDidEnterFullScreenNotification, windowEnteredFullScreen:);
    observe(NSWindowDidExitFullScreenNotification, windowExitedFullScreen:);

372
373
374
375
376
377
378
379
380
381
382


383
384
385
386
387
388
389

#pragma mark TKApplication(TKApplicationEvent)

@implementation TKApplication(TKApplicationEvent)

- (void) applicationActivate: (NSNotification *) notification
{
    (void)notification;

#ifdef TK_MAC_DEBUG_NOTIFICATIONS
    TKLog(@"-[%@(%p) %s] %@", [self class], self, sel_getName(_cmd), notification);


#endif
    [NSApp tkCheckPasteboard];

    /*
     * When the application is activated with Command-Tab it will create a
     * zombie window for every Tk window which has been withdrawn.  So iterate
     * through the list of windows and order out any withdrawn window.







|



>
>







391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410

#pragma mark TKApplication(TKApplicationEvent)

@implementation TKApplication(TKApplicationEvent)

- (void) applicationActivate: (NSNotification *) notification
{
    NSWindow *iconifiedWindow = nil;

#ifdef TK_MAC_DEBUG_NOTIFICATIONS
    TKLog(@"-[%@(%p) %s] %@", [self class], self, sel_getName(_cmd), notification);
#else
    (void) notification;
#endif
    [NSApp tkCheckPasteboard];

    /*
     * When the application is activated with Command-Tab it will create a
     * zombie window for every Tk window which has been withdrawn.  So iterate
     * through the list of windows and order out any withdrawn window.
399
400
401
402
403
404
405







406
407
408
409
410
411
412
413
414
415
416
	    continue;
	}
	if (winPtr->wmInfoPtr->hints.initial_state == WithdrawnState) {
	    [win orderOut:NSApp];
	}
	if (winPtr->dispPtr->grabWinPtr == winPtr) {
	    Tcl_DoWhenIdle(RefocusGrabWindow, winPtr);







	} else {
	    [[self keyWindow] orderFront: self];
	}
    }
}

- (void) applicationDeactivate: (NSNotification *) notification
{
    (void)notification;

#ifdef TK_MAC_DEBUG_NOTIFICATIONS







>
>
>
>
>
>
>
|
|
|
|







420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
	    continue;
	}
	if (winPtr->wmInfoPtr->hints.initial_state == WithdrawnState) {
	    [win orderOut:NSApp];
	}
	if (winPtr->dispPtr->grabWinPtr == winPtr) {
	    Tcl_DoWhenIdle(RefocusGrabWindow, winPtr);
	}
	if (iconifiedWindow == nil && [win isMiniaturized]) {
	    iconifiedWindow = win;
	}
    }
    if ([self keyWindow] == nil && iconifiedWindow != nil) {
	[iconifiedWindow makeKeyAndOrderFront:self];
    } else {
	[[self keyWindow] orderFront:self];
    }

}

- (void) applicationDeactivate: (NSNotification *) notification
{
    (void)notification;

#ifdef TK_MAC_DEBUG_NOTIFICATIONS
Changes to macosx/tkMacOSXWm.c.
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324







1325
1326
1327
1328
1329
1330
1331
	 * there is no choice for a new key window.  Moreover, if the host
	 * computer has a TouchBar then the TouchBar holds a reference to the
	 * key window which prevents it from being deallocated until it stops
	 * being the key window.  On these systems the only option for
	 * preventing zombies is to set the key window to nil.
	 */

	TkMacOSXAssignNewKeyWindow(Tk_Interp((Tk_Window) winPtr),
				   deadNSWindow);

	/*
	 * Prevent zombies on systems with a TouchBar.
	 */

	if (deadNSWindow == [NSApp keyWindow]) {
	    [NSApp _setKeyWindow:nil];
	    [NSApp _setMainWindow:nil];
	}








	/*
	 * Avoid redrawing the view after it is released.
	 */

	TKContentView *deadView = [deadNSWindow contentView];
	Tcl_CancelIdleCall(TkMacOSXRedrawViewIdleTask, (void *) deadView);







<
<
<








>
>
>
>
>
>
>







1307
1308
1309
1310
1311
1312
1313



1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
	 * there is no choice for a new key window.  Moreover, if the host
	 * computer has a TouchBar then the TouchBar holds a reference to the
	 * key window which prevents it from being deallocated until it stops
	 * being the key window.  On these systems the only option for
	 * preventing zombies is to set the key window to nil.
	 */




	/*
	 * Prevent zombies on systems with a TouchBar.
	 */

	if (deadNSWindow == [NSApp keyWindow]) {
	    [NSApp _setKeyWindow:nil];
	    [NSApp _setMainWindow:nil];
	}
	
	/*
	 * Find a new keyWindow.  It will be assinged as the new
	 * TkEventTarget when [NSApp WindowActivation] is called..
	 */
	
	TkMacOSXAssignNewKeyWindow(Tk_Interp((Tk_Window) winPtr), deadNSWindow);

	/*
	 * Avoid redrawing the view after it is released.
	 */

	TKContentView *deadView = [deadNSWindow contentView];
	Tcl_CancelIdleCall(TkMacOSXRedrawViewIdleTask, (void *) deadView);
Changes to tests/all.tcl.
10
11
12
13
14
15
16
17
18
19
20
21
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.

package require tk ;# This is the Tk test suite; fail early if no Tk!
package require tcltest 2.2
tcltest::configure {*}$argv
tcltest::configure -testdir [file normalize [file dirname [info script]]]
tcltest::configure -loadfile \
    [file join [tcltest::testsDirectory] constraints.tcl]
tcltest::configure -singleproc 1
set ErrorOnFailures [info exists env(ERROR_ON_FAILURES)]
encoding system utf-8
if {[tcltest::runAllTests] && $ErrorOnFailures} {exit 1}







|




10
11
12
13
14
15
16
17
18
19
20
21
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.

package require tk ;# This is the Tk test suite; fail early if no Tk!
package require tcltest 2.2
tcltest::configure {*}$argv
tcltest::configure -testdir [file normalize [file dirname [info script]]]
tcltest::configure -loadfile \
    [file join [tcltest::testsDirectory] main.tcl]
tcltest::configure -singleproc 1
set ErrorOnFailures [info exists env(ERROR_ON_FAILURES)]
encoding system utf-8
if {[tcltest::runAllTests] && $ErrorOnFailures} {exit 1}
Changes to tests/button.test.
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
# This file is a Tcl script to test labels, buttons, checkbuttons, and
# radiobuttons in Tk (i.e., all the widgets defined in tkButton.c).  It is
# organized in the standard fashion for Tcl tests.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994-1996 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands
imageInit

proc bogusTrace args {
    error "trace aborted"
}


test button-1.1 {configuration option: "activebackground" for label} -setup {
    label .l -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .l
    update
} -body {
    .l configure -activebackground #012345
    .l cget -activebackground













<

|
|
|
>








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
# This file is a Tcl script to test labels, buttons, checkbuttons, and
# radiobuttons in Tk (i.e., all the widgets defined in tkButton.c).  It is
# organized in the standard fashion for Tcl tests.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994-1996 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands


# Import utility procs for specific functional areas
testutils import button image

imageInit

test button-1.1 {configuration option: "activebackground" for label} -setup {
    label .l -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .l
    update
} -body {
    .l configure -activebackground #012345
    .l cget -activebackground
4003
4004
4005
4006
4007
4008
4009
4010



4011

4012
4013
4014
4015
4016
4017
    }}}
    pack .b
    bind .b <Configure> {unset var}
    update
    destroy .b
} {}





imageFinish

cleanupTests
return

# Local variables:
# mode: tcl
# End:







|
>
>
>

>






4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
    }}}
    pack .b
    bind .b <Configure> {unset var}
    update
    destroy .b
} {}

#
# CLEANUP
#

imageFinish
testutils forget button image
cleanupTests
return

# Local variables:
# mode: tcl
# End:
Changes to tests/canvImg.test.
1
2
3
4
5
6
7
8
9
10
11
12
13




14
15
16
17
18
19
20
# This file is a Tcl script to test out the procedures in tkCanvImg.c,
# which implement canvas "image" items.  It is organized in the standard
# fashion for Tcl tests.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994-1996 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands




imageInit

# Canvas used in every test case of the whole file
canvas .c
pack .c
update














>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# This file is a Tcl script to test out the procedures in tkCanvImg.c,
# which implement canvas "image" items.  It is organized in the standard
# fashion for Tcl tests.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994-1996 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands

# Import utility procs for specific functional areas
testutils import image

imageInit

# Canvas used in every test case of the whole file
canvas .c
pack .c
update

795
796
797
798
799
800
801



802
803

804
805
806
807
808
809
    after cancel $timer
    return $z
} -cleanup {
    .c delete all
    image delete foo2
} -result {{foo2 display 0 0 80 60}}




# cleanup
imageFinish

cleanupTests
return

# Local variables:
# mode: tcl
# End:







>
>
>
|

>






799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
    after cancel $timer
    return $z
} -cleanup {
    .c delete all
    image delete foo2
} -result {{foo2 display 0 0 80 60}}

#
# CLEANUP
#

imageFinish
testutils forget image
cleanupTests
return

# Local variables:
# mode: tcl
# End:
Changes to tests/canvPs.test.
1
2
3
4
5
6
7
8
9
10
11
12




13
14
15
16
17
18
19
# This file is a Tcl script to test out procedures to write postscript
# for canvases to files and channels. It exercises the procedure
# TkCanvPostscriptCmd in generic/tkCanvPs.c
#
# Copyright © 1995 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands




imageInit

# canvas used in 1.* and 2.* test cases
canvas .c -width 400 -height 300 -bd 2 -relief sunken
.c create rectangle 20 20 80 80 -fill red
pack .c
update












>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# This file is a Tcl script to test out procedures to write postscript
# for canvases to files and channels. It exercises the procedure
# TkCanvPostscriptCmd in generic/tkCanvPs.c
#
# Copyright © 1995 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands

# Import utility procs for specific functional areas
testutils import image

imageInit

# canvas used in 1.* and 2.* test cases
canvas .c -width 400 -height 300 -bd 2 -relief sunken
.c create rectangle 20 20 80 80 -fill red
pack .c
update
195
196
197
198
199
200
201
202


203
204
205

206
207
208
209
210
211
212
    update
    .c create image 50 50 -image ::tk::icons::information
    .c postscript
} -cleanup {
    destroy .c
} -returnCodes ok -match glob -result *




# cleanup
unset -nocomplain foo bar
imageFinish

deleteWindows
cleanupTests
return

# Local variables:
# mode: tcl
# End:







|
>
>
|


>







199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
    update
    .c create image 50 50 -image ::tk::icons::information
    .c postscript
} -cleanup {
    destroy .c
} -returnCodes ok -match glob -result *

#
# CLEANUP
#

unset -nocomplain foo bar
imageFinish
testutils forget image
deleteWindows
cleanupTests
return

# Local variables:
# mode: tcl
# End:
Changes to tests/canvText.test.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# This file is a Tcl script to test out the procedures in tkCanvText.c,
# which implement canvas "text" items.  It is organized in the standard
# fashion for Tcl tests.
#
# Copyright © 1996-1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands

testConstraint failsOnXQuarz [expr {$tcl_platform(os) ne "Darwin" || [tk windowingsystem] ne "x11" }]

# Canvas used in 1.* - 17.* tests
canvas .c -width 400 -height 300 -bd 2 -relief sunken
pack .c
update

# Item used in 1.*  tests
.c create text 20 20 -tag test













<
<







1
2
3
4
5
6
7
8
9
10
11
12
13


14
15
16
17
18
19
20
# This file is a Tcl script to test out the procedures in tkCanvText.c,
# which implement canvas "text" items.  It is organized in the standard
# fashion for Tcl tests.
#
# Copyright © 1996-1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands



# Canvas used in 1.* - 17.* tests
canvas .c -width 400 -height 300 -bd 2 -relief sunken
pack .c
update

# Item used in 1.*  tests
.c create text 20 20 -tag test
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
test canvText-5.1 {ConfigureText procedure: adjust cursor} -body {
    .c create text 10 10 -tag x -fill blue -font "times 40" -stipple gray50 \
	-text "xyz"
    .c delete x
} -result {}


test canvText-6.1 {ComputeTextBbox procedure} -constraints {fonts failsOnXQuarz} -setup {
    .c delete test
} -body {
    set font "-adobe-times-medium-r-normal--*-200-*-*-*-*-*-*"
    set ay [font metrics $font -linespace]
    set ax [font measure $font 0]
    .c create text 0 0 -tag test
    .c itemconfig test -font $font -text 0







|







256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
test canvText-5.1 {ConfigureText procedure: adjust cursor} -body {
    .c create text 10 10 -tag x -fill blue -font "times 40" -stipple gray50 \
	-text "xyz"
    .c delete x
} -result {}


test canvText-6.1 {ComputeTextBbox procedure} -constraints {fonts failsOnXQuartz} -setup {
    .c delete test
} -body {
    set font "-adobe-times-medium-r-normal--*-200-*-*-*-*-*-*"
    set ay [font metrics $font -linespace]
    set ax [font measure $font 0]
    .c create text 0 0 -tag test
    .c itemconfig test -font $font -text 0
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
    .c create text 0 0 -tag test
    .c itemconfig test -font $font -text 0
    expr {[.c itemconfig test -anchor sw; .c bbox test] \
	      eq "-1 -$ay [expr $ax+1] 0"}
} -cleanup {
    .c delete test
} -result 1
test canvText-6.5 {ComputeTextBbox procedure} -constraints {fonts failsOnXQuarz} -setup {
    .c delete test
} -body {
    set font "-adobe-times-medium-r-normal--*-200-*-*-*-*-*-*"
    set ay [font metrics $font -linespace]
    set ax [font measure $font 0]
    .c create text 0 0 -tag test
    .c itemconfig test -font $font -text 0







|







308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
    .c create text 0 0 -tag test
    .c itemconfig test -font $font -text 0
    expr {[.c itemconfig test -anchor sw; .c bbox test] \
	      eq "-1 -$ay [expr $ax+1] 0"}
} -cleanup {
    .c delete test
} -result 1
test canvText-6.5 {ComputeTextBbox procedure} -constraints {fonts failsOnXQuartz} -setup {
    .c delete test
} -body {
    set font "-adobe-times-medium-r-normal--*-200-*-*-*-*-*-*"
    set ay [font metrics $font -linespace]
    set ax [font measure $font 0]
    .c create text 0 0 -tag test
    .c itemconfig test -font $font -text 0
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
    .c create text 0 0 -tag test
    .c itemconfig test -font $font -text 0
    expr {[.c itemconfig test -anchor ne; .c bbox test] \
	      eq "[expr -$ax-1] 0 1 $ay"}
} -cleanup {
    .c delete test
} -result 1
test canvText-6.9 {ComputeTextBbox procedure} -constraints {fonts failsOnXQuarz} -setup {
    .c delete test
} -body {
    set font "-adobe-times-medium-r-normal--*-200-*-*-*-*-*-*"
    set ay [font metrics $font -linespace]
    set ax [font measure $font 0]
    .c create text 0 0 -tag test
    .c itemconfig test -font $font -text 0







|







360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
    .c create text 0 0 -tag test
    .c itemconfig test -font $font -text 0
    expr {[.c itemconfig test -anchor ne; .c bbox test] \
	      eq "[expr -$ax-1] 0 1 $ay"}
} -cleanup {
    .c delete test
} -result 1
test canvText-6.9 {ComputeTextBbox procedure} -constraints {fonts failsOnXQuartz} -setup {
    .c delete test
} -body {
    set font "-adobe-times-medium-r-normal--*-200-*-*-*-*-*-*"
    set ay [font metrics $font -linespace]
    set ax [font measure $font 0]
    .c create text 0 0 -tag test
    .c itemconfig test -font $font -text 0
Changes to tests/canvas.test.
1
2
3
4
5
6
7
8
9
10
11
12




13
14
15
16
17
18
19
# This file is a Tcl script to test out the procedures in tkCanvas.c, which
# implements generic code for canvases. It is organized in the standard
# fashion for Tcl tests.
#
# Copyright © 1995-1996 Sun Microsystems, Inc.
# Copyright © 1998-2000 Ajuba Solutions.
# Copyright © 2008 Donal K. Fellows
# All rights reserved.

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




imageInit

# XXX - This test file is woefully incomplete. At present, only a few of the
# features are tested.

# Canvas used in 1.* test cases
canvas .c












>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# This file is a Tcl script to test out the procedures in tkCanvas.c, which
# implements generic code for canvases. It is organized in the standard
# fashion for Tcl tests.
#
# Copyright © 1995-1996 Sun Microsystems, Inc.
# Copyright © 1998-2000 Ajuba Solutions.
# Copyright © 2008 Donal K. Fellows
# All rights reserved.

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

# Import utility procs for specific functional areas
testutils import image

imageInit

# XXX - This test file is woefully incomplete. At present, only a few of the
# features are tested.

# Canvas used in 1.* test cases
canvas .c
1308
1309
1310
1311
1312
1313
1314



1315
1316

1317
1318
1319
1320
1321
1322
	{#c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0} \
	{#c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0}}
} -cleanup {
    destroy .c
    image delete testimage
} -result 1




# cleanup
imageCleanup

cleanupTests
return

# Local Variables:
# mode: tcl
# End:







>
>
>
|

>






1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
	{#c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0} \
	{#c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0}}
} -cleanup {
    destroy .c
    image delete testimage
} -result 1

#
# CLEANUP
#

imageCleanup
testutils forget image
cleanupTests
return

# Local Variables:
# mode: tcl
# End:
Changes to tests/choosedir.test.
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
# This file is a Tcl script to test out Tk's "tk_chooseDir" and
# It is organized in the standard fashion for Tcl tests.
#
# Copyright © 1996 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands




#----------------------------------------------------------------------
#
# Procedures needed by this test file
#
#----------------------------------------------------------------------

proc ToPressButton {parent btn} {
    after 100 SendButtonPress $parent $btn mouse
}

proc ToEnterDirsByKey {parent dirs} {
    after 100 [list EnterDirsByKey $parent $dirs]
}

proc PressButton {btn} {
    event generate $btn <Enter>
    event generate $btn <Button-1> -x 5 -y 5
    event generate $btn <ButtonRelease-1> -x 5 -y 5
}

proc EnterDirsByKey {parent dirs} {
    global tk_strictMotif
    if {$parent == "."} {
	set w .__tk_choosedir
    } else {
	set w $parent.__tk_choosedir
    }
    upvar ::tk::dialog::file::__tk_choosedir data

    foreach dir $dirs {
	$data(ent) delete 0 end
	$data(ent) insert 0 $dir
	update
	SendButtonPress $parent ok mouse
	after 50
    }
}

proc SendButtonPress {parent btn type} {
    global tk_strictMotif
    if {$parent == "."} {
	set w .__tk_choosedir
    } else {
	set w $parent.__tk_choosedir
    }
    upvar ::tk::dialog::file::__tk_choosedir data

    set button $data($btn\Btn)
    if ![winfo ismapped $button] {
	update
    }

    if {$type == "mouse"} {
	PressButton $button
    } else {
	event generate $w <Enter>
	focus $w
	event generate $button <Enter>
	event generate $w <Key> -keysym Return
    }
}


#----------------------------------------------------------------------
#
# The test suite proper
#
#----------------------------------------------------------------------
# Make a dir for us to rely on for tests











>
>
>







<
<
<
<




<
<
<
<
<
<

<















<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







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
# This file is a Tcl script to test out Tk's "tk_chooseDir" and
# It is organized in the standard fashion for Tcl tests.
#
# Copyright © 1996 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands

# Import utility procs for specific functional areas
testutils import dialog

#----------------------------------------------------------------------
#
# Procedures needed by this test file
#
#----------------------------------------------------------------------





proc ToEnterDirsByKey {parent dirs} {
    after 100 [list EnterDirsByKey $parent $dirs]
}







proc EnterDirsByKey {parent dirs} {

    if {$parent == "."} {
	set w .__tk_choosedir
    } else {
	set w $parent.__tk_choosedir
    }
    upvar ::tk::dialog::file::__tk_choosedir data

    foreach dir $dirs {
	$data(ent) delete 0 end
	$data(ent) insert 0 $dir
	update
	SendButtonPress $parent ok mouse
	after 50
    }
}


























#----------------------------------------------------------------------
#
# The test suite proper
#
#----------------------------------------------------------------------
# Make a dir for us to rely on for tests
164
165
166
167
168
169
170



171
172

173
174
	unix notAqua
} -body {
    ToEnterDirsByKey $parent [list "" $real $real]
    tk_chooseDirectory -title "Clear entry, Press OK; Enter $real, press OK" \
	    -parent $parent
} -result $real




# cleanup
removeDirectory choosedirTest

cleanupTests
return







>
>
>
|

>


131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
	unix notAqua
} -body {
    ToEnterDirsByKey $parent [list "" $real $real]
    tk_chooseDirectory -title "Clear entry, Press OK; Enter $real, press OK" \
	    -parent $parent
} -result $real

#
# CLEANUP
#

removeDirectory choosedirTest
testutils forget dialog
cleanupTests
return
Changes to tests/clipboard.test.
16
17
18
19
20
21
22



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# is grabbing the clipboard (e.g. an X server, or a VNC viewer) #
#################################################################

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands




# set up a very large buffer to test INCR retrievals
set longValue ""
foreach i {a b c d e f g j h i j k l m o p q r s t u v w x y z} {
    set j $i.1$i.2$i.3$i.4$i.5$i.6$i.7$i.8$i.9$i.10$i.11$i.12$i.13$i.14
    append longValue A$j B$j C$j D$j E$j F$j G$j H$j I$j K$j L$j M$j N$j
}

# Now we start the main body of the test code

test clipboard-1.1 {ClipboardHandler procedure} -setup {
    clipboard clear
} -body {
    clipboard append "test"
    clipboard get
} -cleanup {
    clipboard clear







>
>
>









|







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
# is grabbing the clipboard (e.g. an X server, or a VNC viewer) #
#################################################################

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands

# Import utility procs for specific functional areas
testutils import child

# set up a very large buffer to test INCR retrievals
set longValue ""
foreach i {a b c d e f g j h i j k l m o p q r s t u v w x y z} {
    set j $i.1$i.2$i.3$i.4$i.5$i.6$i.7$i.8$i.9$i.10$i.11$i.12$i.13$i.14
    append longValue A$j B$j C$j D$j E$j F$j G$j H$j I$j K$j L$j M$j N$j
}

# Now we start the main body of the test code

test clipboard-1.1 {ClipboardHandler procedure} -setup {
    clipboard clear
} -body {
    clipboard append "test"
    clipboard get
} -cleanup {
    clipboard clear
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
	clipboard get
} -cleanup {
    clipboard clear
}  -returnCodes ok -result {first chunk second chunk}
test clipboard-6.2 {Tk_ClipboardAppend procedure} -constraints x11 -setup {
    clipboard clear
} -body {
    setupbg
    clipboard append -f INTEGER -t TEST "16"
    set result [dobg {clipboard get TEST}]
    return $result
} -cleanup {
    clipboard clear
    cleanupbg
}  -result {0x10 }
test clipboard-6.3 {Tk_ClipboardAppend procedure} -setup {
    clipboard clear
} -body {
    clipboard append -f INTEGER -t TEST "16"
    clipboard append -t TEST "test"
} -cleanup {







|

|



|







235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
	clipboard get
} -cleanup {
    clipboard clear
}  -returnCodes ok -result {first chunk second chunk}
test clipboard-6.2 {Tk_ClipboardAppend procedure} -constraints x11 -setup {
    clipboard clear
} -body {
    childTkProcess create
    clipboard append -f INTEGER -t TEST "16"
    set result [childTkProcess eval {clipboard get TEST}]
    return $result
} -cleanup {
    clipboard clear
    childTkProcess exit
}  -result {0x10 }
test clipboard-6.3 {Tk_ClipboardAppend procedure} -setup {
    clipboard clear
} -body {
    clipboard append -f INTEGER -t TEST "16"
    clipboard append -t TEST "test"
} -cleanup {
350
351
352
353
354
355
356
357



358

359
360
361
362
363
364
    clipboard clear
} -body {
    clipboard append -type
	selection get -selection CLIPBOARD
} -cleanup {
    clipboard clear
} -result {-type}




# cleanup

cleanupTests
return

# Local Variables:
# mode: tcl
# End:







|
>
>
>
|
>






353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
    clipboard clear
} -body {
    clipboard append -type
	selection get -selection CLIPBOARD
} -cleanup {
    clipboard clear
} -result {-type}

#
# CLEANUP
#

testutils forget child
cleanupTests
return

# Local Variables:
# mode: tcl
# End:
Changes to tests/clrpick.test.
1
2
3
4
5
6
7
8
9
10
11



12
13
14
15
16
17
18
# This file is a Tcl script to test out Tk's "tk_chooseColor" command.
# It is organized in the standard fashion for Tcl tests.
#
# Copyright © 1996 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
eval tcltest::configure $argv
tcltest::loadTestedCommands
namespace import -force tcltest::test




if {[testConstraint defaultPseudocolor8]} {
    # let's soak up a bunch of colors...so that
    # machines with small color palettes still fail.
    # some tests will be skipped if there are no more colors
    set numcolors 32
    testConstraint colorsLeftover 1











>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# This file is a Tcl script to test out Tk's "tk_chooseColor" command.
# It is organized in the standard fashion for Tcl tests.
#
# Copyright © 1996 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
eval tcltest::configure $argv
tcltest::loadTestedCommands
namespace import -force tcltest::test

# Import utility procs for specific functional areas
testutils import dialog

if {[testConstraint defaultPseudocolor8]} {
    # let's soak up a bunch of colors...so that
    # machines with small color palettes still fail.
    # some tests will be skipped if there are no more colors
    set numcolors 32
    testConstraint colorsLeftover 1
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
test clrpick-1.6 {tk_chooseColor command} -body {
    tk_chooseColor -initialcolor badbadbaadcolor
} -returnCodes error -result {unknown color name "badbadbaadcolor"}
test clrpick-1.7 {tk_chooseColor command} -body {
    tk_chooseColor -initialcolor ##badbadbaadcolor
} -returnCodes error -result {invalid color name "##badbadbaadcolor"}


# tests 3.1 and 3.2 fail when individually run
# if there is no catch {tk_chooseColor -foo 1} msg
# before setting isNative
catch {tk_chooseColor -foo 1} msg
set isNative [expr {[info commands tk::dialog::color::] eq ""}]

proc ToPressButton {parent btn} {
    global isNative
    if {!$isNative} {
	after 200 "SendButtonPress . $btn mouse"
    }
}

proc ToChooseColorByKey {parent r g b} {
    global isNative
    if {!$isNative} {
	after 200 ChooseColorByKey . $r $g $b
    }
}

proc PressButton {btn} {
    event generate $btn <Enter>
    event generate $btn <Button-1> -x 5 -y 5
    event generate $btn <ButtonRelease-1> -x 5 -y 5
}

proc ChooseColorByKey {parent r g b} {
    set w .__tk__color
    upvar ::tk::dialog::color::[winfo name $w] data

    update
    $data(red,entry)   delete 0 end
    $data(green,entry) delete 0 end
    $data(blue,entry)  delete 0 end

    $data(red,entry)   insert 0 $r
    $data(green,entry) insert 0 $g
    $data(blue,entry)  insert 0 $b

    # Manually force the refresh of the color values instead
    # of counting on the timing of the event stream to change
    # the values for us.
    tk::dialog::color::HandleRGBEntry $w

    SendButtonPress . ok mouse
}

proc SendButtonPress {parent btn type} {
    set w .__tk__color
    upvar ::tk::dialog::color::[winfo name $w] data

    set button $data($btn\Btn)
    if ![winfo ismapped $button] {
	update
    }

    if {$type == "mouse"} {
	PressButton $button
    } else {
	event generate $w <Enter>
	focus $w
	event generate $button <Enter>
	event generate $w <Key> -keysym Return
    }
}


test clrpick-2.1 {tk_chooseColor command} -constraints {
    nonUnixUserInteraction colorsLeftover
} -setup {
    set verylongstring [string repeat longstring: 100]
} -body {
    ToPressButton . ok







<
<
<
<
<
<
<
<
<
<
<
<
<
<

<
|




<
<
<
<
<
<




















<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







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
test clrpick-1.6 {tk_chooseColor command} -body {
    tk_chooseColor -initialcolor badbadbaadcolor
} -returnCodes error -result {unknown color name "badbadbaadcolor"}
test clrpick-1.7 {tk_chooseColor command} -body {
    tk_chooseColor -initialcolor ##badbadbaadcolor
} -returnCodes error -result {invalid color name "##badbadbaadcolor"}















proc ToChooseColorByKey {parent r g b} {

    if {! $::dialogIsNative} {
	after 200 ChooseColorByKey . $r $g $b
    }
}







proc ChooseColorByKey {parent r g b} {
    set w .__tk__color
    upvar ::tk::dialog::color::[winfo name $w] data

    update
    $data(red,entry)   delete 0 end
    $data(green,entry) delete 0 end
    $data(blue,entry)  delete 0 end

    $data(red,entry)   insert 0 $r
    $data(green,entry) insert 0 $g
    $data(blue,entry)  insert 0 $b

    # Manually force the refresh of the color values instead
    # of counting on the timing of the event stream to change
    # the values for us.
    tk::dialog::color::HandleRGBEntry $w

    SendButtonPress . ok mouse
}





















test clrpick-2.1 {tk_chooseColor command} -constraints {
    nonUnixUserInteraction colorsLeftover
} -setup {
    set verylongstring [string repeat longstring: 100]
} -body {
    ToPressButton . ok
193
194
195
196
197
198
199



200

201
202
203
} -body {
    after 50 {set ::scr [winfo screen .__tk__color]}
    ToPressButton . cancel
    tk_chooseColor -parent .
    set ::scr
} -result [winfo screen .]




# cleanup

cleanupTests
return








>
>
>
|
>


<
155
156
157
158
159
160
161
162
163
164
165
166
167
168

} -body {
    after 50 {set ::scr [winfo screen .__tk__color]}
    ToPressButton . cancel
    tk_chooseColor -parent .
    set ::scr
} -result [winfo screen .]

#
# CLEANUP
#

testutils forget dialog
cleanupTests
return

Changes to tests/color.test.
1
2
3
4
5
6
7
8
9
10
11



12
13
14
15
16
17
18
# This file is a Tcl script to test out the procedures in the file
# tkColor.c.  It is organized in the standard fashion for Tcl tests.
#
# Copyright © 1995-1998 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

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




# cname --
# Returns a proper name for a color, given its intensities.
#
# Arguments:
# r, g, b -	Intensities on a 0-255 scale.

proc cname {r g b} {











>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# This file is a Tcl script to test out the procedures in the file
# tkColor.c.  It is organized in the standard fashion for Tcl tests.
#
# Copyright © 1995-1998 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

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

# Import utility procs for specific functional areas
testutils import colors

# cname --
# Returns a proper name for a color, given its intensities.
#
# Arguments:
# r, g, b -	Intensities on a 0-255 scale.

proc cname {r g b} {
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
# vals -	List of intensities.

proc c255 {vals} {
    list [expr {[lindex $vals 0]/256}] [expr {[lindex $vals 1]/256}] \
	    [expr {[lindex $vals 2]/256}]
}

# colorsFree --
#
# Returns 1 if there appear to be free colormap entries in a window,
# 0 otherwise.
#
# Arguments:
# w -			Name of window in which to check.
# red, green, blue -	Intensities to use in a trial color allocation
#			to see if there are colormap entries free.

proc colorsFree {w {red 31} {green 245} {blue 192}} {
    set vals [winfo rgb $w [format #%02x%02x%02x $red $green $blue]]
    expr ([lindex $vals 0]/256 == $red) && ([lindex $vals 1]/256 == $green) \
	    && ([lindex $vals 2]/256 == $blue)
}

# -- WARNING (SB, 6.4.2017) --
#
# The if block below looks _very_ outdated. It didn't get any
# substantial changes as far back as the fossil history goes. It might
# be from a time, when 256 color was the best you could get! :-o.
#
# The problem is, on machines with a fancy 24 truecolor display, the







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







73
74
75
76
77
78
79
















80
81
82
83
84
85
86
# vals -	List of intensities.

proc c255 {vals} {
    list [expr {[lindex $vals 0]/256}] [expr {[lindex $vals 1]/256}] \
	    [expr {[lindex $vals 2]/256}]
}

















# -- WARNING (SB, 6.4.2017) --
#
# The if block below looks _very_ outdated. It didn't get any
# substantial changes as far back as the fossil history goes. It might
# be from a time, when 256 color was the best you could get! :-o.
#
# The problem is, on machines with a fancy 24 truecolor display, the
301
302
303
304
305
306
307



308

309
310
    set result
} -cleanup {
    rename copy {}
} -result {{{1 3}} {{1 2}} {{1 1}} {}}

destroy .t




# cleanup

cleanupTests
return







>
>
>
|
>


288
289
290
291
292
293
294
295
296
297
298
299
300
301
    set result
} -cleanup {
    rename copy {}
} -result {{{1 3}} {{1 2}} {{1 1}} {}}

destroy .t

#
# CLEANUP
#

testutils forget colors
cleanupTests
return
Changes to tests/constraints.tcl.
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
300
301
302



303
304
305
306
307
308
309

310
311
312
313
314
315
316
317
318
319
320
if {[namespace exists tk::test]} {
    deleteWindows
    wm geometry . {}
    raise .
    return
}

package require tk
tk appname tktest
wm title . tktest
# If the main window isn't already mapped (e.g. because the tests are
# being run automatically) , specify a precise size for it so that the
# user won't have to position it manually.

if {![winfo ismapped .]} {
    wm geometry . +0+0
    update
}

package require tcltest 2.2

namespace eval tk {
    namespace eval test {

	namespace export loadTkCommand
	proc loadTkCommand {} {
	    set tklib {}
	    foreach pair [info loaded {}] {
		foreach {lib pfx} $pair break
		if {$pfx eq "Tk"} {
		    set tklib $lib
		    break
		}
	    }
	    return [list load $tklib Tk]
	}

	namespace eval bg {
	    # Manage a background process.
	    # Replace with child interp or thread?
	    namespace import ::tcltest::interpreter
	    namespace import ::tk::test::loadTkCommand
	    namespace export setup cleanup do

	    proc cleanup {} {
		variable fd
		# catch in case the background process has closed $fd
		catch {puts $fd exit}
		catch {close $fd}
		set fd ""
	    }
	    proc setup args {
		variable fd
		if {[info exists fd] && [string length $fd]} {
		    cleanup
		}
		set fd [open "|[list [interpreter] \
			-geometry +0+0 -name tktest] $args" r+]
		puts $fd "puts foo; flush stdout"
		flush $fd
		if {[gets $fd data] < 0} {
		    error "unexpected EOF from \"[interpreter]\""
		}
		if {$data ne "foo"} {
		    error "unexpected output from\
			    background process: \"$data\""
		}
		puts $fd [loadTkCommand]
		flush $fd
		fileevent $fd readable [namespace code Ready]
	    }
	    proc Ready {} {
		variable fd
		variable Data
		variable Done
		set x [gets $fd]
		if {[eof $fd]} {
		    fileevent $fd readable {}
		    set Done 1
		} elseif {$x eq "**DONE**"} {
		    set Done 1
		} else {
		    append Data $x
		}
	    }
	    proc do {cmd {block 0}} {
		variable fd
		variable Data
		variable Done
		if {$block} {
		    fileevent $fd readable {}
		}
		puts $fd "[list catch $cmd msg]; update; puts \$msg;\
			puts **DONE**; flush stdout"
		flush $fd
		set Data {}
		if {$block} {
		    while {![eof $fd]} {
			set line [gets $fd]
			if {$line eq "**DONE**"} {
			    break
			}
			append Data $line
		    }
		} else {
		    set Done 0
		    vwait [namespace which -variable Done]
		}
		return $Data
	    }
	}

	proc Export {internal as external} {
	    uplevel 1 [list namespace import $internal]
	    uplevel 1 [list rename [namespace tail $internal] $external]
	    uplevel 1 [list namespace export $external]
	}
	Export bg::setup as setupbg
	Export bg::cleanup as cleanupbg
	Export bg::do as dobg

	namespace export deleteWindows
	proc deleteWindows {} {
	    destroy {*}[winfo children .]
	    # This update is needed to avoid intermittent failures on macOS in unixEmbed.test
	    # with the (GitHub Actions) CI runner.
	    # Reason for the failures is unclear but could have to do with window ids being deleted
	    # after the destroy command returns. The detailed mechanism of such delayed deletions
	    # is not understood, but it appears that this update prevents the test failures.
	    update
	}

	namespace export fixfocus
	proc fixfocus {} {
	    catch {destroy .focus}
	    toplevel .focus
	    wm geometry .focus +0+0
	    entry .focus.e
	    .focus.e insert 0 "fixfocus"
	    pack .focus.e
	    update
	    focus -force .focus.e
	    destroy .focus
	}

	namespace export imageInit imageFinish imageCleanup imageNames
	variable ImageNames
	proc imageInit {} {
	    variable ImageNames
	    if {![info exists ImageNames]} {
		set ImageNames [lsearch -all -inline -glob -not [lsort [image names]] ::tk::icons::indicator*]
	    }
	    imageCleanup
	    if {[lsort [image names]] ne $ImageNames} {
		return -code error "IMAGE NAMES mismatch: [image names] != $ImageNames"
	    }
	}
	proc imageFinish {} {
	    variable ImageNames
	    set imgs [lsearch -all -inline -glob -not [lsort [image names]] ::tk::icons::indicator*]
	    if {$imgs ne $ImageNames} {
		return -code error "images remaining: [image names] != $ImageNames"
	    }
	    imageCleanup
	}
	proc imageCleanup {} {
	    variable ImageNames
	    foreach img [image names] {
		if {$img ni $ImageNames} {image delete $img}
	    }
	}
	proc imageNames {} {
	    variable ImageNames
	    set r {}
	    foreach img [image names] {
		if {$img ni $ImageNames} {lappend r $img}
	    }
	    return $r
	}

	#
	#  CONTROL TIMING ASPECTS OF POINTER WARPING
	#
	# The proc [controlPointerWarpTiming] is intended to ensure that the (mouse)
	# pointer has actually been moved to its new position after a Tk test issued:
	#
	#    [event generate $w $event -warp 1 ...]
	#
	# It takes care of the following timing details of pointer warping:
	#
	# a. Allow pointer warping to happen if it was scheduled for execution at
	#    idle time. This happens synchronously if $w refers to the
	#    whole screen or if the -when option to [event generate] is "now".
	#
	# b. Work around a race condition associated with OS notification of
	#    mouse motion on Windows.
	#
	#    When calling [event generate $w $event -warp 1 ...], the following
	#    sequence occurs:
	#    - At some point in the processing of this command, either via a
	#      synchronous execution path, or asynchronously at idle time, Tk calls
	#      an OS function* to carry out the mouse cursor motion.
	#    - Tk has previously registered a callback function** with the OS, for
	#      the OS to call in order to notify Tk when a mouse move is completed.
	#    - Tk doesn't wait for the callback function to receive the notification
	#      from the OS, but continues processing. This suits most use cases
	#      because usually the notification arrives fast enough (within a few tens
	#      of microseconds). However ...
	#    - A problem arises if Tk performs some processing, immediately following
	#      up on [event generate $w $event -warp 1 ...], and that processing
	#      relies on the mouse pointer having actually moved. If such processing
	#      happens just before the notification from the OS has been received,
	#      Tk will be using not yet updated info (e.g. mouse coordinates).
	#
	#         Hickup, choke etc ... !
	#
	#            *  the function SendInput() of the Win32 API
	#            ** the callback function is TkWinChildProc()
	#
	#    This timing issue can be addressed by putting the Tk process on hold
	#    (do nothing at all) for a somewhat extended amount of time, while
	#    letting the OS complete its job in the meantime. This is what is
	#    accomplished by calling [after ms].
	#
	#    ----
	#    For the history of this issue please refer to Tk ticket [69b48f427e],
	#    specifically the comment on 2019-10-27 14:24:26.
	#
	#
	# Beware: there are cases, not (yet) exercised by the Tk test suite, where
	# [controlPointerWarpTiming] doesn't ensure the new position of the pointer.
	# For example, when issued under Tk8.7+, if the value for the -when option
	# to [event generate $w] is not "now", and $w refers to a Tk window, i.e. not
	# the whole screen.
	#
	proc controlPointerWarpTiming {{duration 50}} {
		update idletasks ;# see a. above
		if {[tk windowingsystem] eq "win32"} {
			after $duration ;# see b. above
		}
	}
	namespace export controlPointerWarpTiming

	# On macOS windows are not allowed to overlap the menubar at the top of the
	# screen or the dock.  So tests which move a window and then check whether it
	# got moved to the requested location should use a y coordinate larger than the
	# height of the menubar (normally 23 pixels) and an x coordinate larger than the
	# width of the dock, if it happens to be on the left.
	# The C-level command "testmenubarheight" deals with this issue but it may
	# not be available on each platform. Therefore, provide a fallback here.
	if {[llength [info commands testmenubarheight]] == 0} {
	    if {[tk windowingsystem] ne "aqua"} {
		# Windows may overlap the menubar
		proc testmenubarheight {} {
		    return 0
		}
	    } else {
		# Windows may not overlap the menubar
		proc testmenubarheight {} {
		    return 30 ;  # arbitrary value known to be larger than the menubar height
		}
	    }
	    namespace export testmenubarheight
	}
    }
}

namespace import -force tk::test::*

namespace import -force tcltest::testConstraint




testConstraint notAqua [expr {[tk windowingsystem] ne "aqua"}]
testConstraint aqua [expr {[tk windowingsystem] eq "aqua"}]
testConstraint x11 [expr {[tk windowingsystem] eq "x11"}]
testConstraint nonwin [expr {[tk windowingsystem] ne "win32"}]
testConstraint aquaOrWin32 [expr {
    ([tk windowingsystem] eq "win32") || [testConstraint aqua]
}]
testConstraint userInteraction 0
testConstraint nonUnixUserInteraction [expr {
    [testConstraint userInteraction] ||
    ([testConstraint unix] && [testConstraint notAqua])
}]
testConstraint haveDISPLAY [expr {[info exists env(DISPLAY)] && [testConstraint x11]}]
testConstraint altDisplay  [info exists env(TK_ALT_DISPLAY)]

testConstraint deprecated [expr {![::tk::build-info no-deprecate]}]

# constraint for running a test on all windowing system except aqua
# where the test fails due to a known bug
testConstraint aquaKnownBug [expr {[testConstraint notAqua] || [testConstraint knownBug]}]

# constraints for testing facilities defined in the tktest executable...


testConstraint testbitmap      [llength [info commands testbitmap]]
testConstraint testborder      [llength [info commands testborder]]
testConstraint testcbind       [llength [info commands testcbind]]
testConstraint testclipboard   [llength [info commands testclipboard]]
testConstraint testcolor       [llength [info commands testcolor]]
testConstraint testcursor      [llength [info commands testcursor]]
testConstraint testembed       [llength [info commands testembed]]
testConstraint testfont        [llength [info commands testfont]]
testConstraint testImageType   [expr {"test" in [image types]}]
testConstraint testmakeexist   [llength [info commands testmakeexist]]



testConstraint testmenubar     [llength [info commands testmenubar]]
testConstraint testmetrics     [llength [info commands testmetrics]]
testConstraint testmovemouse   [llength [info commands testmovemouse]]
testConstraint testobjconfig   [llength [info commands testobjconfig]]
testConstraint testpressbutton [llength [info commands testpressbutton]]
testConstraint testsend        [llength [info commands testsend]]
testConstraint testtext        [llength [info commands testtext]]

testConstraint testwinevent    [llength [info commands testwinevent]]
testConstraint testwrapper     [llength [info commands testwrapper]]

# constraints about what sort of fonts are available
testConstraint fonts 1
destroy .e
entry .e -width 0 -font {Helvetica -12} -bd 1 -highlightthickness 1
.e insert end a.bcd
if {([winfo reqwidth .e] != 37) || ([winfo reqheight .e] != 20)} {
    testConstraint fonts 0
}
<
<
<
<
<
<
|
<
<
<
<
<
<
|
<
<
<
<
|
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<


>
>
>
>







<
<
<
<
<



<
<




|
>
>
|
|
|
|
|
|
<
<
|
<
>
>
>
|
|
|
|
<
|
|
>
|
<
|
<













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






# constraints.tcl --






#




# This file is sourced by each test file when invoking "tcltest::loadTestedCommands".

# It defines test constraints that are used by several test files in the



























































































































# Tk test suite.


































#






























































# See the file "license.terms" for information on usage and redistribution























# of this file, and for a DISCLAIMER OF ALL WARRANTIES.


namespace import -force tcltest::testConstraint

#
# WINDOWING SYSTEM AND DISPLAY
#
testConstraint notAqua [expr {[tk windowingsystem] ne "aqua"}]
testConstraint aqua [expr {[tk windowingsystem] eq "aqua"}]
testConstraint x11 [expr {[tk windowingsystem] eq "x11"}]
testConstraint nonwin [expr {[tk windowingsystem] ne "win32"}]
testConstraint aquaOrWin32 [expr {
    ([tk windowingsystem] eq "win32") || [testConstraint aqua]
}]





testConstraint haveDISPLAY [expr {[info exists env(DISPLAY)] && [testConstraint x11]}]
testConstraint altDisplay  [info exists env(TK_ALT_DISPLAY)]



# constraint for running a test on all windowing system except aqua
# where the test fails due to a known bug
testConstraint aquaKnownBug [expr {[testConstraint notAqua] || [testConstraint knownBug]}]

# constraint based on whether our display is secure
testutils import child
childTkProcess create
set app [childTkProcess eval {tk appname}]
testConstraint secureserver 0
if {[llength [info commands send]]} {
    testConstraint secureserver 1
    if {[catch {send $app set a 0} msg] == 1} {
	if {[string match "X server insecure *" $msg]} {


	    testConstraint secureserver 0

	}
    }
}
childTkProcess exit
testutils forget child

testConstraint failsOnUbuntu [expr {![info exists ::env(CI)] || ![string match Linux $::tcl_platform(os)]}]

testConstraint failsOnXQuartz [expr {$tcl_platform(os) ne "Darwin" || [tk windowingsystem] ne "x11" }]

#
# FONTS

#

testConstraint fonts 1
destroy .e
entry .e -width 0 -font {Helvetica -12} -bd 1 -highlightthickness 1
.e insert end a.bcd
if {([winfo reqwidth .e] != 37) || ([winfo reqheight .e] != 20)} {
    testConstraint fonts 0
}
382
383
384
385
386
387
388
389



390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407

408

409
410
411
412
413
414

415
416

417
418
419
420
421
422
423
424
425
426
427
428









429
430
431
432
set fixedFont {Courier 12}   ; # warning: must be consistent with the files using the constraint below!
set bigFont   {Helvetica 24} ; # ditto
testConstraint haveBigFontTwiceLargerThanTextFont [expr {
    [font actual $fixedFont -size] * 2 <= [font actual $bigFont -size]
}]
unset fixedFont bigFont

# constraints for the visuals available



testConstraint pseudocolor8 [expr {
    ([catch {
	toplevel .t -visual {pseudocolor 8} -colormap new
    }] == 0) && ([winfo depth .t] == 8)
}]
destroy .t
testConstraint haveTruecolor24 [expr {
    {truecolor 24} in [winfo visualsavailable .]
}]
testConstraint haveGrayscale8 [expr {
    {grayscale 8} in [winfo visualsavailable .]
}]
testConstraint defaultPseudocolor8 [expr {
    ([winfo visual .] eq "pseudocolor") && ([winfo depth .] == 8)
}]

# constraint based on whether our display is secure
setupbg

set app [dobg {tk appname}]

testConstraint secureserver 0
if {[llength [info commands send]]} {
    testConstraint secureserver 1
    if {[catch {send $app set a 0} msg] == 1} {
	if {[string match "X server insecure *" $msg]} {
	    testConstraint secureserver 0

	}
    }

}
cleanupbg

eval tcltest::configure $argv
namespace import -force tcltest::test
namespace import -force tcltest::makeFile
namespace import -force tcltest::removeFile
namespace import -force tcltest::makeDirectory
namespace import -force tcltest::removeDirectory
namespace import -force tcltest::interpreter
namespace import -force tcltest::testsDirectory
namespace import -force tcltest::cleanupTests










deleteWindows
wm geometry . {}
raise .







<
>
>
>
















|
<
>
|
>
|
<
|
<
<
|
>
|
|
>
|
|
|
|
|
|
|
|
|
|
|
|
>
>
>
>
>
>
>
>
>

<
<
|
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
set fixedFont {Courier 12}   ; # warning: must be consistent with the files using the constraint below!
set bigFont   {Helvetica 24} ; # ditto
testConstraint haveBigFontTwiceLargerThanTextFont [expr {
    [font actual $fixedFont -size] * 2 <= [font actual $bigFont -size]
}]
unset fixedFont bigFont


#
# VISUALS
#
testConstraint pseudocolor8 [expr {
    ([catch {
	toplevel .t -visual {pseudocolor 8} -colormap new
    }] == 0) && ([winfo depth .t] == 8)
}]
destroy .t
testConstraint haveTruecolor24 [expr {
    {truecolor 24} in [winfo visualsavailable .]
}]
testConstraint haveGrayscale8 [expr {
    {grayscale 8} in [winfo visualsavailable .]
}]
testConstraint defaultPseudocolor8 [expr {
    ([winfo visual .] eq "pseudocolor") && ([winfo depth .] == 8)
}]



#
# VARIOUS
#
testConstraint userInteraction 0

testConstraint nonUnixUserInteraction [expr {


    [testConstraint userInteraction] ||
    ([testConstraint unix] && [testConstraint notAqua])
}]

testConstraint deprecated [expr {![::tk::build-info no-deprecate]}]

# constraints for testing facilities defined in the tktest executable
testConstraint testbitmap      [llength [info commands testbitmap]]
testConstraint testborder      [llength [info commands testborder]]
testConstraint testcbind       [llength [info commands testcbind]]
testConstraint testclipboard   [llength [info commands testclipboard]]
testConstraint testcolor       [llength [info commands testcolor]]
testConstraint testcursor      [llength [info commands testcursor]]
testConstraint testembed       [llength [info commands testembed]]
testConstraint testfont        [llength [info commands testfont]]
testConstraint testImageType   [expr {"test" in [image types]}]
testConstraint testmakeexist   [llength [info commands testmakeexist]]
testConstraint testmenubar     [llength [info commands testmenubar]]
testConstraint testmetrics     [llength [info commands testmetrics]]
testConstraint testmovemouse   [llength [info commands testmovemouse]]
testConstraint testobjconfig   [llength [info commands testobjconfig]]
testConstraint testpressbutton [llength [info commands testpressbutton]]
testConstraint testsend        [llength [info commands testsend]]
testConstraint testtext        [llength [info commands testtext]]
testConstraint testwinevent    [llength [info commands testwinevent]]
testConstraint testwrapper     [llength [info commands testwrapper]]



# EOF
Changes to tests/dialog.test.
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
# This file is a Tcl script to test out Tk's "tk_dialog" command.
# It is organized in the standard fashion for Tcl tests.

package require tcltest 2.2
eval tcltest::configure $argv
tcltest::loadTestedCommands
namespace import -force tcltest::test




test dialog-1.1 {tk_dialog command} -body {
    tk_dialog
} -match glob -returnCodes error -result {wrong # args: should be "tk_dialog w title text bitmap default *"}
test dialog-1.2 {tk_dialog command} -body {
    tk_dialog foo foo foo foo foo
} -returnCodes error -result {bad window path name "foo"}
test dialog-1.3 {tk_dialog command} -body {
    tk_dialog .d foo foo fooBitmap foo
} -cleanup {
    destroy .d
} -returnCodes error -result {bitmap "fooBitmap" not defined}


test dialog-2.1 {tk_dialog operation} -setup {
    proc PressButton {btn} {

	if {![winfo ismapped $btn]} {
	    update
	}
	event generate $btn <Enter>
	event generate $btn <Button-1> -x 5 -y 5
	event generate $btn <ButtonRelease-1> -x 5 -y 5
    }
} -body {
    set x [after 5000 [list set tk::Priv(button) "no response"]]
    after 100 PressButton .d.button0
    set res [tk_dialog .d foo foo info 0 click]
    after cancel $x
    return $res
} -cleanup {
    destroy .d
} -result 0
test dialog-2.2 {tk_dialog operation} -setup {







>
>
>













<
|
|
>
|


<
|
<

<
<
<







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
# This file is a Tcl script to test out Tk's "tk_dialog" command.
# It is organized in the standard fashion for Tcl tests.

package require tcltest 2.2
eval tcltest::configure $argv
tcltest::loadTestedCommands
namespace import -force tcltest::test

# Import utility procs for specific functional areas
testutils import dialog

test dialog-1.1 {tk_dialog command} -body {
    tk_dialog
} -match glob -returnCodes error -result {wrong # args: should be "tk_dialog w title text bitmap default *"}
test dialog-1.2 {tk_dialog command} -body {
    tk_dialog foo foo foo foo foo
} -returnCodes error -result {bad window path name "foo"}
test dialog-1.3 {tk_dialog command} -body {
    tk_dialog .d foo foo fooBitmap foo
} -cleanup {
    destroy .d
} -returnCodes error -result {bitmap "fooBitmap" not defined}


test dialog-2.1 {tk_dialog operation} -body {
    set x [after 5000 [list set tk::Priv(button) "no response"]]
    after 100 {
	if {![winfo ismapped .d.button0]} {
	    update
	}

	PressButton .d.button0

    }



    set res [tk_dialog .d foo foo info 0 click]
    after cancel $x
    return $res
} -cleanup {
    destroy .d
} -result 0
test dialog-2.2 {tk_dialog operation} -setup {
58
59
60
61
62
63
64





65
66
67
    set res [tk_dialog .d foo foo info 0 click]
    after cancel $x
    return $res
} -cleanup {
    destroy .b
} -result -1






cleanupTests
return








>
>
>
>
>


<
56
57
58
59
60
61
62
63
64
65
66
67
68
69

    set res [tk_dialog .d foo foo info 0 click]
    after cancel $x
    return $res
} -cleanup {
    destroy .b
} -result -1

#
# CLEANUP
#

testutils forget dialog
cleanupTests
return

Changes to tests/entry.test.
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
# This file is a Tcl script to test entry widgets in Tk.  It is
# organized in the standard fashion for Tcl tests.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994-1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands

# For xscrollcommand
set scrollInfo {}
proc scroll args {
    global scrollInfo
    set scrollInfo $args
}
# For trace add variable
proc override args {
    global x
    set x 12345
}

# Procedures used in widget VALIDATION tests
proc doval {W d i P s S v V} {
    set ::vVals [list $W $d $i $P $s $S $v $V]
    return 1
}
proc doval2 {W d i P s S v V} {
    set ::vVals [list $W $d $i $P $s $S $v $V]
    set ::e mydata
    return 1
}
proc doval3 {W d i P s S v V} {
    set ::vVals [list $W $d $i $P $s $S $v $V]
    return 0
}

set cy [font metrics {Courier -12} -linespace]


test entry-1.1 {configuration option: "background" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    update













<
<
|
|
<
|
<
<
<
<
<
|
<
<
|
<

<
<
<
<
<
<
<
<
<
<







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
# This file is a Tcl script to test entry widgets in Tk.  It is
# organized in the standard fashion for Tcl tests.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994-1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands



# Import utility procs for specific functional areas
testutils import entry scroll







foreach i {1 2 3} {


    set validateCmd$i [list validateCommand$i %W %d %i %P %s %S %v %V]

}










set cy [font metrics {Courier -12} -linespace]


test entry-1.1 {configuration option: "background" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    update
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
} -cleanup {
    destroy .e
} -result 0123457890
test entry-3.24 {EntryWidgetCmd procedure, "delete" widget command} -setup {
    entry .e
    pack .e ; update idletasks
    update
    set x {}
} -body {
# UTF
    .e insert end "01234乎67890"
    .e delete 6
    lappend x [.e get]
    .e delete 0 end
    .e insert end "012345乎7890"
    .e delete 6
    lappend x [.e get]
    .e delete 0 end
    .e insert end "0123456乎890"
    .e delete 6
    lappend x [.e get]
} -cleanup {
    destroy .e
} -result [list "01234乎7890" "0123457890" "012345乎890"]
test entry-3.25 {EntryWidgetCmd procedure, "delete" widget command} -setup {
    entry .e
    pack .e ; update idletasks
    update







|




|



|



|







870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
} -cleanup {
    destroy .e
} -result 0123457890
test entry-3.24 {EntryWidgetCmd procedure, "delete" widget command} -setup {
    entry .e
    pack .e ; update idletasks
    update
    set result {}
} -body {
# UTF
    .e insert end "01234乎67890"
    .e delete 6
    lappend result [.e get]
    .e delete 0 end
    .e insert end "012345乎7890"
    .e delete 6
    lappend result [.e get]
    .e delete 0 end
    .e insert end "0123456乎890"
    .e delete 6
    lappend result [.e get]
} -cleanup {
    destroy .e
} -result [list "01234乎7890" "0123457890" "012345乎890"]
test entry-3.25 {EntryWidgetCmd procedure, "delete" widget command} -setup {
    entry .e
    pack .e ; update idletasks
    update
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
    .e insert end "This is quite a long text string, so long that it "
    .e insert end "runs off the end of the window quite a bit."
    .e insert 10 乎
    update
# UTF
# If Tcl_NumUtfChars wasn't used, wrong answer would be:
# 0.106383 0.117021 0.117021
    set x {}
    .e xview moveto .1
    lappend x [format {%.6f} [lindex [.e xview] 0]]
    .e xview moveto .11
    lappend x [format {%.6f} [lindex [.e xview] 0]]
    .e xview moveto .12
    lappend x [format {%.6f} [lindex [.e xview] 0]]
} -cleanup {
    destroy .e
} -result {0.095745 0.106383 0.117021}

test entry-3.82 {EntryWidgetCmd procedure} -setup {
    entry .e -font {Courier -12} -borderwidth 2 -highlightthickness 2
    pack .e ; update idletasks
    update
} -body {
    .e gorp
} -cleanup {
    destroy .e
} -returnCodes error -result {bad option "gorp": must be bbox, cget, configure, delete, get, icursor, index, insert, scan, selection, validate, or xview}

# The test below doesn't actually check anything directly, but if run
# with Purify or some other memory-allocation-checking program it will
# ensure that resources get properly freed.

test entry-4.1 {DestroyEntry procedure} -body {
    entry .e -textvariable x -show *
    pack .e ; update idletasks
    .e insert end "Sample text"
    update
    destroy .e
} -result {}

test entry-5.1 {ConfigureEntry procedure, -textvariable} -body {
    set x 12345
    entry .e -textvariable x
    .e get
} -cleanup {
    destroy .e
} -result 12345
test entry-5.2 {ConfigureEntry procedure, -textvariable} -body {
    set x 12345
    entry .e -textvariable x
    set y abcde
    .e configure -textvariable y
    set x 54321
    .e get
} -cleanup {
    destroy .e
} -result {abcde}
test entry-5.3 {ConfigureEntry procedure, -textvariable} -setup {
    unset -nocomplain x
    entry .e
} -body {
    .e insert 0 "Some text"
    .e configure -textvariable x
    set x
} -cleanup {
    destroy .e
} -result {Some text}
test entry-5.4 {ConfigureEntry procedure, -textvariable} -setup {
    unset -nocomplain x
    entry .e
} -body {
    trace add variable x write override
    .e insert 0 "Some text"
    .e configure -textvariable x
    list $x [.e get]
} -cleanup {
    destroy .e
    trace remove variable x write override
    unset x;
} -result {12345 12345}

test entry-5.5 {ConfigureEntry procedure} -setup {
    set x {}
    entry .e1
    entry .e2
} -body {
    .e2 insert end "This is some sample text"
    .e1 configure -exportselection false
    .e1 insert end "0123456789"
    pack .e1 .e2 ; update idletasks
    .e2 select from 0
    .e2 select to 10
    lappend x [selection get]
    .e1 select from 1
    .e1 select to 5
    lappend x [selection get]
    .e1 configure -exportselection 1
    lappend x [selection get]
    set x
} -cleanup {
    destroy .e1 .e2
} -result {{This is so} {This is so} 1234}
test entry-5.6 {ConfigureEntry procedure} -setup {
    entry .e
    pack .e ; update idletasks
} -body {







|

|

|

|



















|







|
|





|
|


|





|



|
|




|


|

|
|


|
|



|









|


|

|
|







1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
    .e insert end "This is quite a long text string, so long that it "
    .e insert end "runs off the end of the window quite a bit."
    .e insert 10 乎
    update
# UTF
# If Tcl_NumUtfChars wasn't used, wrong answer would be:
# 0.106383 0.117021 0.117021
    set result {}
    .e xview moveto .1
    lappend result [format {%.6f} [lindex [.e xview] 0]]
    .e xview moveto .11
    lappend result [format {%.6f} [lindex [.e xview] 0]]
    .e xview moveto .12
    lappend result [format {%.6f} [lindex [.e xview] 0]]
} -cleanup {
    destroy .e
} -result {0.095745 0.106383 0.117021}

test entry-3.82 {EntryWidgetCmd procedure} -setup {
    entry .e -font {Courier -12} -borderwidth 2 -highlightthickness 2
    pack .e ; update idletasks
    update
} -body {
    .e gorp
} -cleanup {
    destroy .e
} -returnCodes error -result {bad option "gorp": must be bbox, cget, configure, delete, get, icursor, index, insert, scan, selection, validate, or xview}

# The test below doesn't actually check anything directly, but if run
# with Purify or some other memory-allocation-checking program it will
# ensure that resources get properly freed.

test entry-4.1 {DestroyEntry procedure} -body {
    entry .e -textvariable textVar -show *
    pack .e ; update idletasks
    .e insert end "Sample text"
    update
    destroy .e
} -result {}

test entry-5.1 {ConfigureEntry procedure, -textvariable} -body {
    set textVar 12345
    entry .e -textvariable textVar
    .e get
} -cleanup {
    destroy .e
} -result 12345
test entry-5.2 {ConfigureEntry procedure, -textvariable} -body {
    set textVar 12345
    entry .e -textvariable textVar
    set y abcde
    .e configure -textvariable y
    set textVar 54321
    .e get
} -cleanup {
    destroy .e
} -result {abcde}
test entry-5.3 {ConfigureEntry procedure, -textvariable} -setup {
    unset -nocomplain textVar
    entry .e
} -body {
    .e insert 0 "Some text"
    .e configure -textvariable textVar
    set textVar
} -cleanup {
    destroy .e
} -result {Some text}
test entry-5.4 {ConfigureEntry procedure, -textvariable} -setup {
    unset -nocomplain textVar
    entry .e
} -body {
    trace add variable textVar write override
    .e insert 0 "Some text"
    .e configure -textvariable textVar
    list $textVar [.e get]
} -cleanup {
    destroy .e
    trace remove variable textVar write override
    unset textVar
} -result {12345 12345}

test entry-5.5 {ConfigureEntry procedure} -setup {
    set result {}
    entry .e1
    entry .e2
} -body {
    .e2 insert end "This is some sample text"
    .e1 configure -exportselection false
    .e1 insert end "0123456789"
    pack .e1 .e2 ; update idletasks
    .e2 select from 0
    .e2 select to 10
    lappend result [selection get]
    .e1 select from 1
    .e1 select to 5
    lappend result [selection get]
    .e1 configure -exportselection 1
    lappend result [selection get]
    set result
} -cleanup {
    destroy .e1 .e2
} -result {{This is so} {This is so} 1234}
test entry-5.6 {ConfigureEntry procedure} -setup {
    entry .e
    pack .e ; update idletasks
} -body {
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
    destroy .e
} -result {1 5}

test entry-5.7 {ConfigureEntry procedure} -setup {
    entry .e -font {Helvetica -12} -borderwidth 2 -highlightthickness 2
    pack .e ; update idletasks
} -body {
    .e configure -font {Courier -12} -width 4 -xscrollcommand scroll
    .e insert end "01234567890"
    update
    set scrollInfo wrong
    .e configure -width 5
    update
    format {%.6f %.6f} {*}$scrollInfo
} -cleanup {







|







1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
    destroy .e
} -result {1 5}

test entry-5.7 {ConfigureEntry procedure} -setup {
    entry .e -font {Helvetica -12} -borderwidth 2 -highlightthickness 2
    pack .e ; update idletasks
} -body {
    .e configure -font {Courier -12} -width 4 -xscrollcommand setScrollInfo
    .e insert end "01234567890"
    update
    set scrollInfo wrong
    .e configure -width 5
    update
    format {%.6f %.6f} {*}$scrollInfo
} -cleanup {
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
} -setup {
    entry .e -highlightthickness 2 -font {Helvetica -12}
    pack .e ; update idletasks
} -body {
    .e configure -bd 1 -relief raised -width 0 -show .
    .e insert 0 12345
    update
    set x [winfo reqwidth .e]
    .e configure -show X
    lappend x [winfo reqwidth .e]
    .e configure -show ""
    lappend x [winfo reqwidth .e]
} -cleanup {
    destroy .e
} -result {23 53 43}
test entry-6.11 {EntryComputeGeometry procedure} -constraints {
    win
} -setup {
    entry .e -highlightthickness 2
    pack .e ; update idletasks
} -body {
    .e configure -bd 1 -relief raised -width 0 -show . -font {helvetica 12}
    .e insert 0 12345
    update
    set x1 [winfo reqwidth .e]
	set x2 [expr {8+5*[font measure {helvetica 12} .]}]
	set x [expr {$x1 eq $x2}]
    .e configure -show X
	set x1 [winfo reqwidth .e]
	set x2 [expr {8+5*[font measure {helvetica 12} X]}]
    lappend x [expr {$x1 eq $x2}]
    .e configure -show ""
	set x1 [winfo reqwidth .e]
	set x2 [expr {8+[font measure {helvetica 12} 12345]}]
    lappend x [expr {$x1 eq $x2}]
} -cleanup {
    destroy .e
} -result {1 1 1}
test entry-6.12 {EntryComputeGeometry procedure} -constraints {
    fonts
} -setup {
    catch {destroy .e}







|

|

|














|



|



|







1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
} -setup {
    entry .e -highlightthickness 2 -font {Helvetica -12}
    pack .e ; update idletasks
} -body {
    .e configure -bd 1 -relief raised -width 0 -show .
    .e insert 0 12345
    update
    set result [winfo reqwidth .e]
    .e configure -show X
    lappend result [winfo reqwidth .e]
    .e configure -show ""
    lappend result [winfo reqwidth .e]
} -cleanup {
    destroy .e
} -result {23 53 43}
test entry-6.11 {EntryComputeGeometry procedure} -constraints {
    win
} -setup {
    entry .e -highlightthickness 2
    pack .e ; update idletasks
} -body {
    .e configure -bd 1 -relief raised -width 0 -show . -font {helvetica 12}
    .e insert 0 12345
    update
    set x1 [winfo reqwidth .e]
	set x2 [expr {8+5*[font measure {helvetica 12} .]}]
	set result [expr {$x1 eq $x2}]
    .e configure -show X
	set x1 [winfo reqwidth .e]
	set x2 [expr {8+5*[font measure {helvetica 12} X]}]
    lappend result [expr {$x1 eq $x2}]
    .e configure -show ""
	set x1 [winfo reqwidth .e]
	set x2 [expr {8+[font measure {helvetica 12} 12345]}]
    lappend result [expr {$x1 eq $x2}]
} -cleanup {
    destroy .e
} -result {1 1 1}
test entry-6.12 {EntryComputeGeometry procedure} -constraints {
    fonts
} -setup {
    catch {destroy .e}
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030

test entry-7.1 {InsertChars procedure} -setup {
    unset -nocomplain contents
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    focus .e
} -body {
    .e configure -textvariable contents -xscrollcommand scroll
    update
    set scrollInfo wrong
    .e insert 0 abcde
    .e insert 2 XXX
    update
    list [.e get] $contents [format {%.6f %.6f} {*}$scrollInfo]
} -cleanup {
    destroy .e
} -result {abXXXcde abXXXcde {0.000000 1.000000}}

test entry-7.2 {InsertChars procedure} -setup {
    unset -nocomplain contents
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    focus .e
} -body {
    .e configure -textvariable contents -xscrollcommand scroll
    update
    set scrollInfo wrong
    .e insert 0 abcde
    .e insert 500 XXX
    update
    list [.e get] $contents [format {%.6f %.6f} {*}$scrollInfo]
} -cleanup {
    destroy .e
} -result {abcdeXXX abcdeXXX {0.000000 1.000000}}
test entry-7.3 {InsertChars procedure} -setup {
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
} -body {
    .e insert 0 0123456789
    .e select from 2
    .e select to 6
    .e insert 2 XXX
    set x "[.e index sel.first] [.e index sel.last]"
    .e select to 8
    lappend x [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {5 9 5 8}
test entry-7.4 {InsertChars procedure} -setup {
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
} -body {
    .e insert 0 0123456789
    .e select from 2
    .e select to 6
    .e insert 3 XXX
    set x "[.e index sel.first] [.e index sel.last]"
    .e select to 8
    lappend x [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {2 9 2 8}
test entry-7.5 {InsertChars procedure} -setup {
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
} -body {
    .e insert 0 0123456789
    .e select from 2
    .e select to 6
    .e insert 5 XXX
    set x "[.e index sel.first] [.e index sel.last]"
    .e select to 8
    lappend x [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {2 9 2 8}
test entry-7.6 {InsertChars procedure} -setup {
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
} -body {
    .e insert 0 0123456789
    .e select from 2
    .e select to 6
    .e insert 6 XXX
    set x "[.e index sel.first] [.e index sel.last]"
    .e select to 5
    lappend x [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {2 6 2 5}
test entry-7.7 {InsertChars procedure} -setup {
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
} -body {
    .e configure -xscrollcommand scroll
    .e insert 0 0123456789
    .e icursor 4
    .e insert 4 XXX
    .e index insert
} -cleanup {
    destroy .e
} -result 7







|
















|

















|

|











|

|











|

|











|

|







|







1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009

test entry-7.1 {InsertChars procedure} -setup {
    unset -nocomplain contents
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    focus .e
} -body {
    .e configure -textvariable contents -xscrollcommand setScrollInfo
    update
    set scrollInfo wrong
    .e insert 0 abcde
    .e insert 2 XXX
    update
    list [.e get] $contents [format {%.6f %.6f} {*}$scrollInfo]
} -cleanup {
    destroy .e
} -result {abXXXcde abXXXcde {0.000000 1.000000}}

test entry-7.2 {InsertChars procedure} -setup {
    unset -nocomplain contents
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    focus .e
} -body {
    .e configure -textvariable contents -xscrollcommand setScrollInfo
    update
    set scrollInfo wrong
    .e insert 0 abcde
    .e insert 500 XXX
    update
    list [.e get] $contents [format {%.6f %.6f} {*}$scrollInfo]
} -cleanup {
    destroy .e
} -result {abcdeXXX abcdeXXX {0.000000 1.000000}}
test entry-7.3 {InsertChars procedure} -setup {
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
} -body {
    .e insert 0 0123456789
    .e select from 2
    .e select to 6
    .e insert 2 XXX
    set result "[.e index sel.first] [.e index sel.last]"
    .e select to 8
    lappend result [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {5 9 5 8}
test entry-7.4 {InsertChars procedure} -setup {
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
} -body {
    .e insert 0 0123456789
    .e select from 2
    .e select to 6
    .e insert 3 XXX
    set result "[.e index sel.first] [.e index sel.last]"
    .e select to 8
    lappend result [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {2 9 2 8}
test entry-7.5 {InsertChars procedure} -setup {
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
} -body {
    .e insert 0 0123456789
    .e select from 2
    .e select to 6
    .e insert 5 XXX
    set result "[.e index sel.first] [.e index sel.last]"
    .e select to 8
    lappend result [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {2 9 2 8}
test entry-7.6 {InsertChars procedure} -setup {
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
} -body {
    .e insert 0 0123456789
    .e select from 2
    .e select to 6
    .e insert 6 XXX
    set result "[.e index sel.first] [.e index sel.last]"
    .e select to 5
    lappend result [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {2 6 2 5}
test entry-7.7 {InsertChars procedure} -setup {
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
} -body {
    .e configure -xscrollcommand setScrollInfo
    .e insert 0 0123456789
    .e icursor 4
    .e insert 4 XXX
    .e index insert
} -cleanup {
    destroy .e
} -result 7
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180

test entry-8.1 {DeleteChars procedure} -setup {
    unset -nocomplain contents
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    focus .e
} -body {
    .e configure -textvariable contents -xscrollcommand scroll
    update
    set scrollInfo wrong
    .e insert 0 abcde
    .e delete 2 4
    update
    list [.e get] $contents [format {%.6f %.6f} {*}$scrollInfo]
} -cleanup {
    destroy .e
} -result {abe abe {0.000000 1.000000}}
test entry-8.2 {DeleteChars procedure} -setup {
    unset -nocomplain contents
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    focus .e
} -body {
    .e configure -textvariable contents -xscrollcommand scroll
    update
    set scrollInfo wrong
    .e insert 0 abcde
    .e delete {} 2
    update
    list [.e get] $contents [format {%.6f %.6f} {*}$scrollInfo]
} -cleanup {
    destroy .e
} -result {cde cde {0.000000 1.000000}}
test entry-8.3 {DeleteChars procedure} -setup {
    unset -nocomplain contents
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    focus .e
} -body {
    .e configure -textvariable contents -xscrollcommand scroll
    update
    set scrollInfo wrong
    .e insert 0 abcde
    .e delete 3 1000
    update
    list [.e get] $contents [format {%.6f %.6f} {*}$scrollInfo]
} -cleanup {
    destroy .e
} -result {abc abc {0.000000 1.000000}}
test entry-8.4 {DeleteChars procedure} -setup {
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    focus .e
} -body {
    .e insert 0 0123456789abcde
    .e select from 3
    .e select to 8
    .e delete 1 3
    update
    set x "[.e index sel.first] [.e index sel.last]"
    .e select to 5
    lappend x [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {1 6 1 5}
test entry-8.5 {DeleteChars procedure} -setup {
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    focus .e
} -body {
    .e insert 0 0123456789abcde
    .e select from 3
    .e select to 8
    .e delete 1 4
    update
    set x "[.e index sel.first] [.e index sel.last]"
    .e select to 4
    lappend x [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {1 5 1 4}
test entry-8.6 {DeleteChars procedure} -setup {
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    focus .e
} -body {
    .e insert 0 0123456789abcde
    .e select from 3
    .e select to 8
    .e delete 1 7
    update
    set x "[.e index sel.first] [.e index sel.last]"
    .e select to 5
    lappend x [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {1 2 1 5}
test entry-8.7 {DeleteChars procedure} -setup {
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    focus .e







|















|















|



















|

|













|

|













|

|







2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159

test entry-8.1 {DeleteChars procedure} -setup {
    unset -nocomplain contents
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    focus .e
} -body {
    .e configure -textvariable contents -xscrollcommand setScrollInfo
    update
    set scrollInfo wrong
    .e insert 0 abcde
    .e delete 2 4
    update
    list [.e get] $contents [format {%.6f %.6f} {*}$scrollInfo]
} -cleanup {
    destroy .e
} -result {abe abe {0.000000 1.000000}}
test entry-8.2 {DeleteChars procedure} -setup {
    unset -nocomplain contents
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    focus .e
} -body {
    .e configure -textvariable contents -xscrollcommand setScrollInfo
    update
    set scrollInfo wrong
    .e insert 0 abcde
    .e delete {} 2
    update
    list [.e get] $contents [format {%.6f %.6f} {*}$scrollInfo]
} -cleanup {
    destroy .e
} -result {cde cde {0.000000 1.000000}}
test entry-8.3 {DeleteChars procedure} -setup {
    unset -nocomplain contents
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    focus .e
} -body {
    .e configure -textvariable contents -xscrollcommand setScrollInfo
    update
    set scrollInfo wrong
    .e insert 0 abcde
    .e delete 3 1000
    update
    list [.e get] $contents [format {%.6f %.6f} {*}$scrollInfo]
} -cleanup {
    destroy .e
} -result {abc abc {0.000000 1.000000}}
test entry-8.4 {DeleteChars procedure} -setup {
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    focus .e
} -body {
    .e insert 0 0123456789abcde
    .e select from 3
    .e select to 8
    .e delete 1 3
    update
    set result "[.e index sel.first] [.e index sel.last]"
    .e select to 5
    lappend result [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {1 6 1 5}
test entry-8.5 {DeleteChars procedure} -setup {
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    focus .e
} -body {
    .e insert 0 0123456789abcde
    .e select from 3
    .e select to 8
    .e delete 1 4
    update
    set result "[.e index sel.first] [.e index sel.last]"
    .e select to 4
    lappend result [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {1 5 1 4}
test entry-8.6 {DeleteChars procedure} -setup {
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    focus .e
} -body {
    .e insert 0 0123456789abcde
    .e select from 3
    .e select to 8
    .e delete 1 7
    update
    set result "[.e index sel.first] [.e index sel.last]"
    .e select to 5
    lappend result [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {1 2 1 5}
test entry-8.7 {DeleteChars procedure} -setup {
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    focus .e
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
    focus .e
} -body {
    .e insert 0 0123456789abcde
    .e select from 3
    .e select to 8
    .e delete 3 7
    update
    set x "[.e index sel.first] [.e index sel.last]"
    .e select to 8
    lappend x [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {3 4 3 8}
test entry-8.9 {DeleteChars procedure} -setup {
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
} -body {







|

|







2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
    focus .e
} -body {
    .e insert 0 0123456789abcde
    .e select from 3
    .e select to 8
    .e delete 3 7
    update
    set result "[.e index sel.first] [.e index sel.last]"
    .e select to 8
    lappend result [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {3 4 3 8}
test entry-8.9 {DeleteChars procedure} -setup {
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
} -body {
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
    focus .e
} -body {
    .e insert 0 0123456789abcde
    .e select from 8
    .e select to 3
    .e delete 5 8
    update
    set x "[.e index sel.first] [.e index sel.last]"
    .e select to 8
    lappend x [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {3 5 5 8}
test entry-8.11 {DeleteChars procedure} -setup {
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    focus .e
} -body {
    .e insert 0 0123456789abcde
    .e select from 8
    .e select to 3
    .e delete 8 10
    update
    set x "[.e index sel.first] [.e index sel.last]"
    .e select to 4
    lappend x [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {3 8 4 8}
test entry-8.12 {DeleteChars procedure} -setup {
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    focus .e







|

|













|

|







2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
    focus .e
} -body {
    .e insert 0 0123456789abcde
    .e select from 8
    .e select to 3
    .e delete 5 8
    update
    set result "[.e index sel.first] [.e index sel.last]"
    .e select to 8
    lappend result [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {3 5 5 8}
test entry-8.11 {DeleteChars procedure} -setup {
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    focus .e
} -body {
    .e insert 0 0123456789abcde
    .e select from 8
    .e select to 3
    .e delete 8 10
    update
    set result "[.e index sel.first] [.e index sel.last]"
    .e select to 4
    lappend result [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {3 8 4 8}
test entry-8.12 {DeleteChars procedure} -setup {
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    focus .e
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
    expr {[winfo reqwidth .e] == $expected}
} -cleanup {
    destroy .e
    unset XPAD expected
} -result {1}

test entry-9.1 {EntryValueChanged procedure} -setup {
    unset -nocomplain x
} -body {
    trace add variable x write override
    entry .e -textvariable x -width 0
    .e insert 0 foo
    list $x [.e get]
} -cleanup {
    destroy .e
    trace remove variable x write override
    unset x
} -result {12345 12345}


test entry-10.1 {EntrySetValue procedure} -constraints fonts -body {
    set x abcde
    set y ab
    entry .e  -font {Helvetica -12} -highlightthickness 2 -bd 2  -width 0
    pack .e ; update idletasks
    .e configure -textvariable x
    .e configure -textvariable y
    update
    list [.e get] [winfo reqwidth .e]
} -cleanup {
    destroy .e
} -result {ab 24}
test entry-10.2 {EntrySetValue procedure, updating selection} -setup {
    unset -nocomplain x
    entry .e -font {Helvetica -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
} -body {
    .e configure -textvariable x
    .e insert 0 "abcdefghjklmnopqrstu"
    .e selection range 4 10
    set x "a"
    .e index sel.first
} -cleanup {
    destroy .e
} -returnCodes error -result {selection isn't in widget .e}
test entry-10.3 {EntrySetValue procedure, updating selection} -setup {
    unset -nocomplain x
    entry .e -font {Helvetica -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
} -body {
    .e configure -textvariable x
    .e insert 0 "abcdefghjklmnopqrstu"
    .e selection range 4 10
    set x "abcdefg"
    list [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {4 7}
test entry-10.4 {EntrySetValue procedure, updating selection} -setup {
    unset -nocomplain x
    entry .e -font {Helvetica -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
} -body {
    .e configure -textvariable x
    .e insert 0 "abcdefghjklmnopqrstu"
    .e selection range 4 10
    set x "abcdefghijklmn"
    list [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {4 10}
test entry-10.5 {EntrySetValue procedure, updating display position} -setup {
    unset -nocomplain x
    entry .e -highlightthickness 2 -bd 2
    pack .e ; update idletasks
} -body {
    .e configure -width 10 -font {Courier -12} -textvariable x
    .e insert 0 "abcdefghjklmnopqrstuvwxyz"
    .e xview 10
    update
    set x "abcdefg"
    update
    .e index @0
} -cleanup {
    destroy .e
} -result 0
test entry-10.6 {EntrySetValue procedure, updating display position} -setup {
    unset -nocomplain x
    entry .e -highlightthickness 2 -bd 2
    pack .e ; update idletasks
} -body {
    .e configure -width 10 -font {Courier -12} -textvariable x
    pack .e ; update idletasks
    .e insert 0 "abcdefghjklmnopqrstuvwxyz"
    .e xview 10
    update
    set x "1234567890123456789012"
    update
    .e index @0
} -cleanup {
    destroy .e
} -result 10
test entry-10.7 {EntrySetValue procedure, updating insertion cursor} -setup {
    unset -nocomplain x
    entry .e -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    update
} -body {
    .e configure -width 10 -font {Courier -12} -textvariable x
    pack .e ; update idletasks
    .e insert 0 "abcdefghjklmnopqrstuvwxyz"
    .e icursor 5
    set x "123"
    .e index insert
} -cleanup {
    destroy .e
} -result 3
test entry-10.8 {EntrySetValue procedure, updating insertion cursor} -setup {
    unset -nocomplain x
    entry .e -highlightthickness 2 -bd 2
    pack .e ; update idletasks
} -body {
    .e configure -width 10 -font {Courier -12} -textvariable x
    pack .e ; update idletasks
    .e insert 0 "abcdefghjklmnopqrstuvwxyz"
    .e icursor 5
    set x "123456"
    .e index insert
} -cleanup {
    destroy .e
} -result 5

test entry-11.1 {EntryEventProc procedure} -setup {
    entry .e -highlightthickness 2 -bd 2 -font {Helvetica -12}
    pack .e ; update idletasks
} -body {
    .e insert 0 abcdefg
    destroy .e
    update
} -cleanup {
    destroy .e
} -result {}
test entry-11.2 {EntryEventProc procedure} -setup {
    set x {}
} -body {
    entry .e1 -fg #112233
    rename .e1 .e2
    lappend x [winfo children .]
    lappend x [.e2 cget -fg]
    destroy .e1
    lappend x [info command .e*] [winfo children .]
} -cleanup {
    destroy .e1
} -result {.e1 #112233 {} {}}

test entry-12.1 {EntryCmdDeletedProc procedure} -body {
    button .b -text "xyz_123"
    rename .b {}







|

|
|

|


|
|




|



|







|



|


|





|



|


|





|



|


|





|



|



|






|



|




|






|




|



|





|



|



|
















|



|
|

|







2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
    expr {[winfo reqwidth .e] == $expected}
} -cleanup {
    destroy .e
    unset XPAD expected
} -result {1}

test entry-9.1 {EntryValueChanged procedure} -setup {
    unset -nocomplain textVar
} -body {
    trace add variable textVar write override
    entry .e -textvariable textVar -width 0
    .e insert 0 foo
    list $textVar [.e get]
} -cleanup {
    destroy .e
    trace remove variable textVar write override
    unset textVar
} -result {12345 12345}


test entry-10.1 {EntrySetValue procedure} -constraints fonts -body {
    set textVar abcde
    set y ab
    entry .e  -font {Helvetica -12} -highlightthickness 2 -bd 2  -width 0
    pack .e ; update idletasks
    .e configure -textvariable textVar
    .e configure -textvariable y
    update
    list [.e get] [winfo reqwidth .e]
} -cleanup {
    destroy .e
} -result {ab 24}
test entry-10.2 {EntrySetValue procedure, updating selection} -setup {
    unset -nocomplain textVar
    entry .e -font {Helvetica -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
} -body {
    .e configure -textvariable textVar
    .e insert 0 "abcdefghjklmnopqrstu"
    .e selection range 4 10
    set textVar "a"
    .e index sel.first
} -cleanup {
    destroy .e
} -returnCodes error -result {selection isn't in widget .e}
test entry-10.3 {EntrySetValue procedure, updating selection} -setup {
    unset -nocomplain textVar
    entry .e -font {Helvetica -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
} -body {
    .e configure -textvariable textVar
    .e insert 0 "abcdefghjklmnopqrstu"
    .e selection range 4 10
    set textVar "abcdefg"
    list [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {4 7}
test entry-10.4 {EntrySetValue procedure, updating selection} -setup {
    unset -nocomplain textVar
    entry .e -font {Helvetica -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
} -body {
    .e configure -textvariable textVar
    .e insert 0 "abcdefghjklmnopqrstu"
    .e selection range 4 10
    set textVar "abcdefghijklmn"
    list [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {4 10}
test entry-10.5 {EntrySetValue procedure, updating display position} -setup {
    unset -nocomplain textVar
    entry .e -highlightthickness 2 -bd 2
    pack .e ; update idletasks
} -body {
    .e configure -width 10 -font {Courier -12} -textvariable textVar
    .e insert 0 "abcdefghjklmnopqrstuvwxyz"
    .e xview 10
    update
    set textVar "abcdefg"
    update
    .e index @0
} -cleanup {
    destroy .e
} -result 0
test entry-10.6 {EntrySetValue procedure, updating display position} -setup {
    unset -nocomplain textVar
    entry .e -highlightthickness 2 -bd 2
    pack .e ; update idletasks
} -body {
    .e configure -width 10 -font {Courier -12} -textvariable textVar
    pack .e ; update idletasks
    .e insert 0 "abcdefghjklmnopqrstuvwxyz"
    .e xview 10
    update
    set textVar "1234567890123456789012"
    update
    .e index @0
} -cleanup {
    destroy .e
} -result 10
test entry-10.7 {EntrySetValue procedure, updating insertion cursor} -setup {
    unset -nocomplain textVar
    entry .e -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    update
} -body {
    .e configure -width 10 -font {Courier -12} -textvariable textVar
    pack .e ; update idletasks
    .e insert 0 "abcdefghjklmnopqrstuvwxyz"
    .e icursor 5
    set textVar "123"
    .e index insert
} -cleanup {
    destroy .e
} -result 3
test entry-10.8 {EntrySetValue procedure, updating insertion cursor} -setup {
    unset -nocomplain textVar
    entry .e -highlightthickness 2 -bd 2
    pack .e ; update idletasks
} -body {
    .e configure -width 10 -font {Courier -12} -textvariable textVar
    pack .e ; update idletasks
    .e insert 0 "abcdefghjklmnopqrstuvwxyz"
    .e icursor 5
    set textVar "123456"
    .e index insert
} -cleanup {
    destroy .e
} -result 5

test entry-11.1 {EntryEventProc procedure} -setup {
    entry .e -highlightthickness 2 -bd 2 -font {Helvetica -12}
    pack .e ; update idletasks
} -body {
    .e insert 0 abcdefg
    destroy .e
    update
} -cleanup {
    destroy .e
} -result {}
test entry-11.2 {EntryEventProc procedure} -setup {
    set result {}
} -body {
    entry .e1 -fg #112233
    rename .e1 .e2
    lappend result [winfo children .]
    lappend result [.e2 cget -fg]
    destroy .e1
    lappend result [info command .e*] [winfo children .]
} -cleanup {
    destroy .e1
} -result {.e1 #112233 {} {}}

test entry-12.1 {EntryCmdDeletedProc procedure} -body {
    button .b -text "xyz_123"
    rename .b {}
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
    .e select from 1
    .e select to 18
    selection get
} -cleanup {
    destroy .e
} -result {*****************}
test entry-14.3 {EntryFetchSelection procedure} -setup {
    set x {}
    for {set i 1} {$i <= 500} {incr i} {
	append x "This is line $i, out of 500\n"
}
} -body {
    entry .e
    .e insert end $x
    .e select from 0
    .e select to end
    string compare [selection get] $x
} -cleanup {
    destroy .e
} -result 0

test entry-15.1 {EntryLostSelection} -body {
    entry .e
    .e insert 0 "Text"







|

|



|


|







2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
    .e select from 1
    .e select to 18
    selection get
} -cleanup {
    destroy .e
} -result {*****************}
test entry-14.3 {EntryFetchSelection procedure} -setup {
    set textVar {}
    for {set i 1} {$i <= 500} {incr i} {
	append textVar "This is line $i, out of 500\n"
}
} -body {
    entry .e
    .e insert end $textVar
    .e select from 0
    .e select to end
    string compare [selection get] $textVar
} -cleanup {
    destroy .e
} -result 0

test entry-15.1 {EntryLostSelection} -body {
    entry .e
    .e insert 0 "Text"
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
    format {%.6f %.6f} {*}[.e xview]
} -cleanup {
    destroy .e
} -result {0.000000 1.000000}


test entry-17.1 {EntryUpdateScrollbar procedure} -body {
    entry .e -width 10 -xscrollcommand scroll -font {Courier -12}
    pack .e
    update
    set scrollInfo wrong
    .e delete 0 end
    .e insert 0 123
    update
    format {%.6f %.6f} {*}$scrollInfo
} -cleanup {
    destroy .e
} -result {0.000000 1.000000}
test entry-17.2 {EntryUpdateScrollbar procedure} -body {
    entry .e -width 10 -xscrollcommand scroll -font {Courier -12}
    pack .e
    update
    set scrollInfo wrong
    .e insert 0 0123456789abcdef
    .e xview 3
    update
    format {%.6f %.6f} {*}$scrollInfo
} -cleanup {
    destroy .e
} -result {0.187500 0.812500}
test entry-17.3 {EntryUpdateScrollbar procedure} -body {
    entry .e -width 10 -xscrollcommand scroll -font {Courier -12}
    pack .e
    update
    set scrollInfo wrong
    .e insert 0 abcdefghijklmnopqrs
    .e xview 6
    update
    format {%.6f %.6f} {*}$scrollInfo
} -cleanup {
    destroy .e
} -result {0.315789 0.842105}
test entry-17.4 {EntryUpdateScrollbar procedure} -setup {
    proc bgerror msg {
	global x
	set x $msg
}
} -body {
    entry .e -width 5
    pack .e
    update
    set scrollInfo wrong
    .e configure -xscrollcommand thisisnotacommand
    update
    list $x $errorInfo
} -cleanup {
    destroy .e
    rename bgerror {}
} -result {{invalid command name "thisisnotacommand"} {invalid command name "thisisnotacommand"
    while executing
"thisisnotacommand 0.0 1.0"
    (horizontal scrolling command executed by .e)}}







|











|











|












|
|








|







2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
    format {%.6f %.6f} {*}[.e xview]
} -cleanup {
    destroy .e
} -result {0.000000 1.000000}


test entry-17.1 {EntryUpdateScrollbar procedure} -body {
    entry .e -width 10 -xscrollcommand setScrollInfo -font {Courier -12}
    pack .e
    update
    set scrollInfo wrong
    .e delete 0 end
    .e insert 0 123
    update
    format {%.6f %.6f} {*}$scrollInfo
} -cleanup {
    destroy .e
} -result {0.000000 1.000000}
test entry-17.2 {EntryUpdateScrollbar procedure} -body {
    entry .e -width 10 -xscrollcommand setScrollInfo -font {Courier -12}
    pack .e
    update
    set scrollInfo wrong
    .e insert 0 0123456789abcdef
    .e xview 3
    update
    format {%.6f %.6f} {*}$scrollInfo
} -cleanup {
    destroy .e
} -result {0.187500 0.812500}
test entry-17.3 {EntryUpdateScrollbar procedure} -body {
    entry .e -width 10 -xscrollcommand setScrollInfo -font {Courier -12}
    pack .e
    update
    set scrollInfo wrong
    .e insert 0 abcdefghijklmnopqrs
    .e xview 6
    update
    format {%.6f %.6f} {*}$scrollInfo
} -cleanup {
    destroy .e
} -result {0.315789 0.842105}
test entry-17.4 {EntryUpdateScrollbar procedure} -setup {
    proc bgerror msg {
	global textVar
	set textVar $msg
}
} -body {
    entry .e -width 5
    pack .e
    update
    set scrollInfo wrong
    .e configure -xscrollcommand thisisnotacommand
    update
    list $textVar $errorInfo
} -cleanup {
    destroy .e
    rename bgerror {}
} -result {{invalid command name "thisisnotacommand"} {invalid command name "thisisnotacommand"
    while executing
"thisisnotacommand 0.0 1.0"
    (horizontal scrolling command executed by .e)}}
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
# failures aren't good
#

# 19.* test cases in previous version highly depended on the previous
# test cases. This was replaced by inserting recently set configurations
# that matters for the test case
test entry-19.1 {entry widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    entry .e -validate all \
	-validatecommand [list doval %W %d %i %P %s %S %v %V] \
	-invalidcommand bell \
	-textvariable ::e \
	-background red -foreground white
    pack .e ; update idletasks
    .e insert 0 a
    set ::vVals
} -cleanup {
    destroy .e
} -result {.e 1 0 a {} a all key}

test entry-19.2 {entry widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    entry .e -validate all \
	-validatecommand [list doval %W %d %i %P %s %S %v %V] \
	-invalidcommand bell \
	-textvariable ::e \
	-background red -foreground white
    pack .e ; update idletasks
    .e insert 0 a   ;# previous settings
    .e insert 1 b
    return $::vVals
} -cleanup {
    destroy .e
} -result {.e 1 1 ab a b all key}

test entry-19.3 {entry widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    entry .e -validate all \
	-validatecommand [list doval %W %d %i %P %s %S %v %V] \
	-invalidcommand bell \
	-textvariable ::e \
	-background red -foreground white
    pack .e ; update idletasks
    .e insert 0 ab   ;# previous settings
    .e insert end c
    set ::vVals
} -cleanup {
    destroy .e
} -result {.e 1 2 abc ab c all key}

test entry-19.4 {entry widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    entry .e -validate all \
	-validatecommand [list doval %W %d %i %P %s %S %v %V] \
	-invalidcommand bell \
	-textvariable ::e \
	-background red -foreground white
    pack .e ; update idletasks
    .e insert 0 abc   ;# previous settings
    .e insert 1 123
    list $::vVals $::e
} -cleanup {
    destroy .e
} -result {{.e 1 1 a123bc abc 123 all key} a123bc}

test entry-19.5 {entry widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    entry .e -validate all \
	-validatecommand [list doval %W %d %i %P %s %S %v %V] \
	-invalidcommand bell \
	-textvariable ::e \
	-background red -foreground white
    pack .e ; update idletasks
    .e insert 0 a123bc   ;# previous settings
    .e delete 2
    set ::vVals
} -cleanup {
    destroy .e
} -result {.e 0 2 a13bc a123bc 2 all key}

test entry-19.6 {entry widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    entry .e -validate all \
	-validatecommand [list doval %W %d %i %P %s %S %v %V] \
	-invalidcommand bell \
	-textvariable ::e \
	-background red -foreground white
    pack .e ; update idletasks
    .e insert 0 a13bc   ;# previous settings
    .e configure -validate key
    .e delete 1 3
    set ::vVals
} -cleanup {
    destroy .e
} -result {.e 0 1 abc a13bc 13 key key}

test entry-19.7 {entry widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    entry .e -validate focus \
	-validatecommand [list doval %W %d %i %P %s %S %v %V] \
	-invalidcommand bell \
	-textvariable ::e \
	-background red -foreground white
    pack .e ; update idletasks
    .e insert end abc                 ;# previous settings
    set ::vVals {}
    .e insert end d
    set ::vVals
} -cleanup {
    destroy .e
} -result {}

test entry-19.8 {entry widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    entry .e -validate all \
	-validatecommand [list doval %W %d %i %P %s %S %v %V] \
	-invalidcommand bell \
	-textvariable ::e \
	-background red -foreground white
    pack .e ; update idletasks
    .e configure -validate focus    ;# previous settings
    .e insert end abcd              ;# previous settings
    focus -force .e
# update necessary to process FocusIn event
    update
    set ::vVals
} -cleanup {
    destroy .e
} -result {.e -1 -1 abcd abcd {} focus focusin}

test entry-19.9 {entry widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    entry .e -validate focus \
	-validatecommand [list doval %W %d %i %P %s %S %v %V] \
	-invalidcommand bell \
	-textvariable ::e \
	-background red -foreground white
    pack .e ; update idletasks
    .e insert end abcd      ;# previous settings
    focus -force .e         ;# previous settings
    update                  ;# previous settings
# update necessary to process FocusIn event
    focus -force .
# update necessary to process FocusOut event
    update
    set ::vVals
} -cleanup {
    destroy .e
} -result {.e -1 -1 abcd abcd {} focus focusout}

test entry-19.10 {entry widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    entry .e -validate all \
	-validatecommand [list doval %W %d %i %P %s %S %v %V] \
	-invalidcommand bell \
	-textvariable ::e \
	-background red -foreground white
    pack .e ; update idletasks
    .e insert end abcd          ;# previous settings
    focus -force .e
# update necessary to process FocusIn event
    update
    set ::vVals
} -cleanup {
    destroy .e
} -result {.e -1 -1 abcd abcd {} all focusin}

test entry-19.11 {entry widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    entry .e -validate all \
	-validatecommand [list doval %W %d %i %P %s %S %v %V] \
	-invalidcommand bell \
	-textvariable ::e \
	-background red -foreground white
    pack .e ; update idletasks
    .e insert end abcd          ;# previous settings
    focus -force .e             ;# previous settings
# update necessary to process FocusIn event
    update                      ;# previous settings
    focus -force .
# update necessary to process FocusOut event
    update
    set ::vVals
} -cleanup {
    destroy .e
} -result {.e -1 -1 abcd abcd {} all focusout}

test entry-19.12 {entry widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    entry .e -validate focusin \
	-validatecommand [list doval %W %d %i %P %s %S %v %V] \
	-invalidcommand bell \
	-textvariable ::e \
	-background red -foreground white
    pack .e ; update idletasks
    .e insert 0 abcd              ;# previous settings
    focus -force .e
# update necessary to process FocusIn event
    update
    set ::vVals
} -cleanup {
    destroy .e
} -result {.e -1 -1 abcd abcd {} focusin focusin}

test entry-19.13 {entry widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    entry .e -validate focusin \
	-validatecommand [list doval %W %d %i %P %s %S %v %V] \
	-invalidcommand bell \
	-textvariable ::e \
	-background red -foreground white
    pack .e ; update idletasks
    .e insert end abcd              ;# previous settings
    set ::vVals {}
    focus -force .
# update necessary to process FocusOut event
    update
    set ::vVals
} -cleanup {
    destroy .e
} -result {}

test entry-19.14 {entry widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    entry .e -validate focuso \
	-validatecommand [list doval %W %d %i %P %s %S %v %V] \
	-invalidcommand bell \
	-textvariable ::e \
	-background red -foreground white
    pack .e ; update idletasks
    .e insert end abcd              ;# previous settings
    set ::vVals {}                  ;# previous settings
    focus -force .e
# update necessary to process FocusIn event
    update
    set ::vVals
} -cleanup {
    destroy .e
} -result {}

test entry-19.15 {entry widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    entry .e -validate focuso \
	-validatecommand [list doval %W %d %i %P %s %S %v %V] \
	-invalidcommand bell \
	-textvariable ::e \
	-background red -foreground white
    pack .e ; update idletasks
    .e insert end abcd              ;# previous settings
    set ::vVals {}                  ;# previous settings
    focus -force .e                 ;# previous settings
# update necessary to process FocusIn event
    update                          ;# previous settings
    focus -force .
# update necessary to process FocusOut event
    update
    set ::vVals
} -cleanup {
    destroy .e
} -result {.e -1 -1 abcd abcd {} focusout focusout}

# the same as 19.16 but added [.e validate] to returned list
test entry-19.16 {entry widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    entry .e -validate focuso \
	-validatecommand [list doval %W %d %i %P %s %S %v %V] \
	-invalidcommand bell \
	-textvariable ::e \
	-background red -foreground white
    pack .e ; update idletasks
    .e insert end abcd              ;# previous settings
    set ::vVals {}                  ;# previous settings
    focus -force .e                 ;# previous settings
# update necessary to process FocusIn event
    update                          ;# previous settings
    focus -force .
# update necessary to process FocusOut event
    update
    list [.e validate] $::vVals
} -cleanup {
    destroy .e
} -result {1 {.e -1 -1 abcd abcd {} all forced}}


test entry-19.17 {entry widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    entry .e -validate focuso \
	-validatecommand [list doval %W %d %i %P %s %S %v %V] \
	-invalidcommand bell \
	-textvariable ::e \
	-background red -foreground white
    pack .e ; update idletasks
    .e insert end abcd              ;# previous settings
    set ::e newdata
    list [.e cget -validate] $::vVals
} -cleanup {
    destroy .e
} -result {focusout {.e -1 -1 newdata abcd {} focusout forced}}


# proc doval changed - returns 0
test entry-19.18 {entry widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    entry .e -validate all \
	-validatecommand [list doval3 %W %d %i %P %s %S %v %V] \
	-invalidcommand bell \
	-textvariable ::e \
	-background red -foreground white
    pack .e ; update idletasks
    set ::e newdata                 ;# previous settings
    .e configure -validate all
    set ::e nextdata
    list [.e cget -validate] $::vVals
} -cleanup {
    destroy .e
} -result {none {.e -1 -1 nextdata newdata {} all forced}}

## This sets validate to none because it shows that we prevent a possible
## loop condition in the validation, when the entry textvar is also set
# proc doval2 used
test entry-19.19 {entry widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    entry .e -validate all \
	-validatecommand [list doval3 %W %d %i %P %s %S %v %V] \
	-invalidcommand bell \
	-textvariable ::e \
	-background red -foreground white
    pack .e ; update idletasks
    set ::e nextdata                 ;# previous settings

    .e configure -validatecommand [list doval2 %W %d %i %P %s %S %v %V]
    .e validate
    list [.e cget -validate] [.e get] $::vVals
} -cleanup {
    destroy .e
} -result {none nextdata {.e -1 -1 nextdata nextdata {} all forced}}

## This leaves validate alone because we trigger validation through the
## textvar (a write trace), and the write during validation triggers
## nothing (by definition of avoiding loops on var traces).  This is
## one of those "dangerous" conditions where the user will have a
## different value in the entry widget shown as is in the textvar.
test entry-19.20 {entry widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    entry .e -validate all \
	-validatecommand [list doval %W %d %i %P %s %S %v %V] \
	-invalidcommand bell \
	-textvariable ::e \
	-background red -foreground white
    pack .e ; update idletasks
    set ::e nextdata                 ;# previous settings
    .e configure -validatecommand [list doval2 %W %d %i %P %s %S %v %V] ;# prev
    .e validate                     ;# previous settings

    .e configure -validate all
    set ::e testdata
    list [.e cget -validate] [.e get] $::e $::vVals
} -cleanup {
    destroy .e
} -result {all testdata mydata {.e -1 -1 testdata mydata {} all forced}}

## This leaves validate alone because we trigger validation through the
## textvar (a write trace), and the write during validation triggers
## nothing (by definition of avoiding loops on var traces).  This is
## one of those "dangerous" conditions where the user will have a
## different value in the entry widget shown as is in the textvar.
test entry-19.21 {entry widget validation - bug 40e4bf6198} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    entry .e -validate key \
	-validatecommand [list doval2 %W %d %i %P %s %S %v %V] \
	-textvariable ::e
    pack .e ; update idletasks
    set ::e origdata
    .e insert 0 A
    list [.e cget -validate] [.e get] $::e $::vVals
} -cleanup {
    destroy .e
} -result {none origdata mydata {.e 1 0 Aorigdata origdata A key key}}

##
## End validation tests
##







|


|

|



|





|


|

|




|





|


|

|




|





|


|

|




|





|


|

|




|





|


|

|





|





|


|

|



|

|





|


|

|







|





|


|

|









|





|


|

|






|





|


|

|









|





|


|

|






|





|


|

|



|



|





|


|

|



|



|





|


|

|



|






|






|


|

|



|






|






|


|

|



|
|







|


|

|


|

|
|








|


|

|


|

|

|










|


|

|


|
|



|
|










|


|
|

|

|







3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
# failures aren't good
#

# 19.* test cases in previous version highly depended on the previous
# test cases. This was replaced by inserting recently set configurations
# that matters for the test case
test entry-19.1 {entry widget validation} -setup {
    unset -nocomplain textVar validationData
} -body {
    entry .e -validate all \
	-validatecommand $validateCmd1 \
	-invalidcommand bell \
	-textvariable textVar \
	-background red -foreground white
    pack .e ; update idletasks
    .e insert 0 a
    set validationData
} -cleanup {
    destroy .e
} -result {.e 1 0 a {} a all key}

test entry-19.2 {entry widget validation} -setup {
    unset -nocomplain textVar validationData
} -body {
    entry .e -validate all \
	-validatecommand $validateCmd1 \
	-invalidcommand bell \
	-textvariable textVar \
	-background red -foreground white
    pack .e ; update idletasks
    .e insert 0 a   ;# previous settings
    .e insert 1 b
    return $validationData
} -cleanup {
    destroy .e
} -result {.e 1 1 ab a b all key}

test entry-19.3 {entry widget validation} -setup {
    unset -nocomplain textVar validationData
} -body {
    entry .e -validate all \
	-validatecommand $validateCmd1 \
	-invalidcommand bell \
	-textvariable textVar \
	-background red -foreground white
    pack .e ; update idletasks
    .e insert 0 ab   ;# previous settings
    .e insert end c
    set validationData
} -cleanup {
    destroy .e
} -result {.e 1 2 abc ab c all key}

test entry-19.4 {entry widget validation} -setup {
    unset -nocomplain textVar validationData
} -body {
    entry .e -validate all \
	-validatecommand $validateCmd1 \
	-invalidcommand bell \
	-textvariable textVar \
	-background red -foreground white
    pack .e ; update idletasks
    .e insert 0 abc   ;# previous settings
    .e insert 1 123
    list $validationData $textVar
} -cleanup {
    destroy .e
} -result {{.e 1 1 a123bc abc 123 all key} a123bc}

test entry-19.5 {entry widget validation} -setup {
    unset -nocomplain textVar validationData
} -body {
    entry .e -validate all \
	-validatecommand $validateCmd1 \
	-invalidcommand bell \
	-textvariable textVar \
	-background red -foreground white
    pack .e ; update idletasks
    .e insert 0 a123bc   ;# previous settings
    .e delete 2
    set validationData
} -cleanup {
    destroy .e
} -result {.e 0 2 a13bc a123bc 2 all key}

test entry-19.6 {entry widget validation} -setup {
    unset -nocomplain textVar validationData
} -body {
    entry .e -validate all \
	-validatecommand $validateCmd1 \
	-invalidcommand bell \
	-textvariable textVar \
	-background red -foreground white
    pack .e ; update idletasks
    .e insert 0 a13bc   ;# previous settings
    .e configure -validate key
    .e delete 1 3
    set validationData
} -cleanup {
    destroy .e
} -result {.e 0 1 abc a13bc 13 key key}

test entry-19.7 {entry widget validation} -setup {
    unset -nocomplain textVar validationData
} -body {
    entry .e -validate focus \
	-validatecommand $validateCmd1 \
	-invalidcommand bell \
	-textvariable textVar \
	-background red -foreground white
    pack .e ; update idletasks
    .e insert end abc                 ;# previous settings
    set validationData {}
    .e insert end d
    set validationData
} -cleanup {
    destroy .e
} -result {}

test entry-19.8 {entry widget validation} -setup {
    unset -nocomplain textVar validationData
} -body {
    entry .e -validate all \
	-validatecommand $validateCmd1 \
	-invalidcommand bell \
	-textvariable textVar \
	-background red -foreground white
    pack .e ; update idletasks
    .e configure -validate focus    ;# previous settings
    .e insert end abcd              ;# previous settings
    focus -force .e
# update necessary to process FocusIn event
    update
    set validationData
} -cleanup {
    destroy .e
} -result {.e -1 -1 abcd abcd {} focus focusin}

test entry-19.9 {entry widget validation} -setup {
    unset -nocomplain textVar validationData
} -body {
    entry .e -validate focus \
	-validatecommand $validateCmd1 \
	-invalidcommand bell \
	-textvariable textVar \
	-background red -foreground white
    pack .e ; update idletasks
    .e insert end abcd      ;# previous settings
    focus -force .e         ;# previous settings
    update                  ;# previous settings
# update necessary to process FocusIn event
    focus -force .
# update necessary to process FocusOut event
    update
    set validationData
} -cleanup {
    destroy .e
} -result {.e -1 -1 abcd abcd {} focus focusout}

test entry-19.10 {entry widget validation} -setup {
    unset -nocomplain textVar validationData
} -body {
    entry .e -validate all \
	-validatecommand $validateCmd1 \
	-invalidcommand bell \
	-textvariable textVar \
	-background red -foreground white
    pack .e ; update idletasks
    .e insert end abcd          ;# previous settings
    focus -force .e
# update necessary to process FocusIn event
    update
    set validationData
} -cleanup {
    destroy .e
} -result {.e -1 -1 abcd abcd {} all focusin}

test entry-19.11 {entry widget validation} -setup {
    unset -nocomplain textVar validationData
} -body {
    entry .e -validate all \
	-validatecommand $validateCmd1 \
	-invalidcommand bell \
	-textvariable textVar \
	-background red -foreground white
    pack .e ; update idletasks
    .e insert end abcd          ;# previous settings
    focus -force .e             ;# previous settings
# update necessary to process FocusIn event
    update                      ;# previous settings
    focus -force .
# update necessary to process FocusOut event
    update
    set validationData
} -cleanup {
    destroy .e
} -result {.e -1 -1 abcd abcd {} all focusout}

test entry-19.12 {entry widget validation} -setup {
    unset -nocomplain textVar validationData
} -body {
    entry .e -validate focusin \
	-validatecommand $validateCmd1 \
	-invalidcommand bell \
	-textvariable textVar \
	-background red -foreground white
    pack .e ; update idletasks
    .e insert 0 abcd              ;# previous settings
    focus -force .e
# update necessary to process FocusIn event
    update
    set validationData
} -cleanup {
    destroy .e
} -result {.e -1 -1 abcd abcd {} focusin focusin}

test entry-19.13 {entry widget validation} -setup {
    unset -nocomplain textVar validationData
} -body {
    entry .e -validate focusin \
	-validatecommand $validateCmd1 \
	-invalidcommand bell \
	-textvariable textVar \
	-background red -foreground white
    pack .e ; update idletasks
    .e insert end abcd              ;# previous settings
    set validationData {}
    focus -force .
# update necessary to process FocusOut event
    update
    set validationData
} -cleanup {
    destroy .e
} -result {}

test entry-19.14 {entry widget validation} -setup {
    unset -nocomplain textVar validationData
} -body {
    entry .e -validate focuso \
	-validatecommand $validateCmd1 \
	-invalidcommand bell \
	-textvariable textVar \
	-background red -foreground white
    pack .e ; update idletasks
    .e insert end abcd              ;# previous settings
    set validationData {}                  ;# previous settings
    focus -force .e
# update necessary to process FocusIn event
    update
    set validationData
} -cleanup {
    destroy .e
} -result {}

test entry-19.15 {entry widget validation} -setup {
    unset -nocomplain textVar validationData
} -body {
    entry .e -validate focuso \
	-validatecommand $validateCmd1 \
	-invalidcommand bell \
	-textvariable textVar \
	-background red -foreground white
    pack .e ; update idletasks
    .e insert end abcd              ;# previous settings
    set validationData {}                  ;# previous settings
    focus -force .e                 ;# previous settings
# update necessary to process FocusIn event
    update                          ;# previous settings
    focus -force .
# update necessary to process FocusOut event
    update
    set validationData
} -cleanup {
    destroy .e
} -result {.e -1 -1 abcd abcd {} focusout focusout}

# the same as 19.16 but added [.e validate] to returned list
test entry-19.16 {entry widget validation} -setup {
    unset -nocomplain textVar validationData
} -body {
    entry .e -validate focuso \
	-validatecommand $validateCmd1 \
	-invalidcommand bell \
	-textvariable textVar \
	-background red -foreground white
    pack .e ; update idletasks
    .e insert end abcd              ;# previous settings
    set validationData {}                  ;# previous settings
    focus -force .e                 ;# previous settings
# update necessary to process FocusIn event
    update                          ;# previous settings
    focus -force .
# update necessary to process FocusOut event
    update
    list [.e validate] $validationData
} -cleanup {
    destroy .e
} -result {1 {.e -1 -1 abcd abcd {} all forced}}


test entry-19.17 {entry widget validation} -setup {
    unset -nocomplain textVar validationData
} -body {
    entry .e -validate focuso \
	-validatecommand $validateCmd1 \
	-invalidcommand bell \
	-textvariable textVar \
	-background red -foreground white
    pack .e ; update idletasks
    .e insert end abcd              ;# previous settings
    set textVar newdata
    list [.e cget -validate] $validationData
} -cleanup {
    destroy .e
} -result {focusout {.e -1 -1 newdata abcd {} focusout forced}}


# proc doval changed - returns 0
test entry-19.18 {entry widget validation} -setup {
    unset -nocomplain textVar validationData
} -body {
    entry .e -validate all \
	-validatecommand $validateCmd3 \
	-invalidcommand bell \
	-textvariable textVar \
	-background red -foreground white
    pack .e ; update idletasks
    set textVar newdata                 ;# previous settings
    .e configure -validate all
    set textVar nextdata
    list [.e cget -validate] $validationData
} -cleanup {
    destroy .e
} -result {none {.e -1 -1 nextdata newdata {} all forced}}

## This sets validate to none because it shows that we prevent a possible
## loop condition in the validation, when the entry textvar is also set
# proc doval2 used
test entry-19.19 {entry widget validation} -setup {
    unset -nocomplain textVar validationData
} -body {
    entry .e -validate all \
	-validatecommand $validateCmd3 \
	-invalidcommand bell \
	-textvariable textVar \
	-background red -foreground white
    pack .e ; update idletasks
    set textVar nextdata                 ;# previous settings

    .e configure -validatecommand $validateCmd2
    .e validate
    list [.e cget -validate] [.e get] $validationData
} -cleanup {
    destroy .e
} -result {none nextdata {.e -1 -1 nextdata nextdata {} all forced}}

## This leaves validate alone because we trigger validation through the
## textvar (a write trace), and the write during validation triggers
## nothing (by definition of avoiding loops on var traces).  This is
## one of those "dangerous" conditions where the user will have a
## different value in the entry widget shown as is in the textvar.
test entry-19.20 {entry widget validation} -setup {
    unset -nocomplain textVar validationData
} -body {
    entry .e -validate all \
	-validatecommand $validateCmd1 \
	-invalidcommand bell \
	-textvariable textVar \
	-background red -foreground white
    pack .e ; update idletasks
    set textVar nextdata                 ;# previous settings
    .e configure -validatecommand $validateCmd2 ;# prev
    .e validate                     ;# previous settings

    .e configure -validate all
    set textVar testdata
    list [.e cget -validate] [.e get] $textVar $validationData
} -cleanup {
    destroy .e
} -result {all testdata mydata {.e -1 -1 testdata mydata {} all forced}}

## This leaves validate alone because we trigger validation through the
## textvar (a write trace), and the write during validation triggers
## nothing (by definition of avoiding loops on var traces).  This is
## one of those "dangerous" conditions where the user will have a
## different value in the entry widget shown as is in the textvar.
test entry-19.21 {entry widget validation - bug 40e4bf6198} -setup {
    unset -nocomplain textVar validationData
} -body {
    entry .e -validate key \
	-validatecommand $validateCmd2 \
	-textvariable textVar
    pack .e ; update idletasks
    set textVar origdata
    .e insert 0 A
    list [.e cget -validate] [.e get] $textVar $validationData
} -cleanup {
    destroy .e
} -result {none origdata mydata {.e 1 0 Aorigdata origdata A key key}}

##
## End validation tests
##
3620
3621
3622
3623
3624
3625
3626
3627




3628
3629




3630
3631
3632
3633
3634

# Gathered comments about lacks
# XXX Still need to write tests for EntryBlinkProc, EntryFocusProc,
# and EntryTextVarProc.
# No tests for DisplayEntry.
# XXX Still need to write tests for EntryScanTo and EntrySelectTo.
# No tests for EventuallyRedraw





# option clear
# cleanup




cleanupTests
return











>
>
>
>

|
>
>
>
>



<
<
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619



# Gathered comments about lacks
# XXX Still need to write tests for EntryBlinkProc, EntryFocusProc,
# and EntryTextVarProc.
# No tests for DisplayEntry.
# XXX Still need to write tests for EntryScanTo and EntrySelectTo.
# No tests for EventuallyRedraw

#
# CLEANUP
#

# option clear
foreach i {1 2 3} {
    unset validateCmd$i
}
unset i
testutils forget entry scroll
cleanupTests
return



Changes to tests/event.test.
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
    # a focus follows mouse will not steal away
    # the focus if the mouse is moved around.

    if {[focus] != $win} {
	focus -force $win
    }
    event generate $win <Key-$keysym>
    _pause 50
    if {[focus] != $win} {
	focus -force $win
    }
    event generate $win <KeyRelease-$keysym>
    _pause 50
}

# Call _keypress for each character in the given string

proc _keypress_string {win string} {
    foreach letter [split $string ""] {
	_keypress $win $letter
    }
}

# Delay script execution for a given amount of time

proc _pause {{msecs 1000}} {
    global _pause

    if {! [info exists _pause(number)]} {
	set _pause(number) 0
    }

    set num [incr _pause(number)]
    set _pause($num) 0

    after $msecs "set _pause($num) 1"
    vwait _pause($num)
    unset _pause($num)
}

# Helper proc to convert index to x y position

proc _text_ind_to_x_y {text ind} {
    set bbox [$text bbox $ind]
    if {[llength $bbox] != 4} {
	error "got bbox \{$bbox\} from $text, index $ind"
    }







|




|










<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







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
    # a focus follows mouse will not steal away
    # the focus if the mouse is moved around.

    if {[focus] != $win} {
	focus -force $win
    }
    event generate $win <Key-$keysym>
    pause 50
    if {[focus] != $win} {
	focus -force $win
    }
    event generate $win <KeyRelease-$keysym>
    pause 50
}

# Call _keypress for each character in the given string

proc _keypress_string {win string} {
    foreach letter [split $string ""] {
	_keypress $win $letter
    }
}


















# Helper proc to convert index to x y position

proc _text_ind_to_x_y {text ind} {
    set bbox [$text bbox $ind]
    if {[llength $bbox] != 4} {
	error "got bbox \{$bbox\} from $text, index $ind"
    }
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
    tkwait visibility $e
    _keypress_string $e JUMP

    set result [$e get]

    event generate $e <Enter>
    for {set i 0} {$i < 3} {incr i} {
	_pause 100
	event generate $e <Button-1>
	_pause 100
	event generate $e <ButtonRelease-1>
    }

    _keypress $e Delete
    _keypress_string $e UP
    lappend result [$e get]
} -cleanup {







|

|







201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
    tkwait visibility $e
    _keypress_string $e JUMP

    set result [$e get]

    event generate $e <Enter>
    for {set i 0} {$i < 3} {incr i} {
	pause 100
	event generate $e <Button-1>
	pause 100
	event generate $e <ButtonRelease-1>
    }

    _keypress $e Delete
    _keypress_string $e UP
    lappend result [$e get]
} -cleanup {
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
    tkwait visibility $e
    _keypress_string $e JUMP

    set result [$e get 1.0 1.end]

    event generate $e <Enter>
    for {set i 0} {$i < 3} {incr i} {
	_pause 100
	event generate $e <Button-1>
	_pause 100
	event generate $e <ButtonRelease-1>
    }

    _keypress $e Delete
    _keypress_string $e UP
    lappend result [$e get 1.0 1.end]
} -cleanup {







|

|







256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
    tkwait visibility $e
    _keypress_string $e JUMP

    set result [$e get 1.0 1.end]

    event generate $e <Enter>
    for {set i 0} {$i < 3} {incr i} {
	pause 100
	event generate $e <Button-1>
	pause 100
	event generate $e <ButtonRelease-1>
    }

    _keypress $e Delete
    _keypress_string $e UP
    lappend result [$e get 1.0 1.end]
} -cleanup {
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
    # Now drag until selend is highlighted, then click up

    set current $anchor
    while {[$e compare $current <= $selend]} {
	foreach {current_x current_y} [_text_ind_to_x_y $e $current] break
	event generate $e <B1-Motion> -x $current_x -y $current_y
	set current [$e index [list $current + 1 char]]
	_pause 50
    }

    event generate $e <ButtonRelease-1> -x $current_x -y $current_y
    _pause 200

    # Save the position of the insert cursor
    lappend result [$e index insert]

    # Save the highlighted text
    lappend result [_get_selection $e]

    # Now click and click and drag to the left, over "Tcl/Tk selection"

    event generate $e <Button-1> -x $current_x -y $current_y

    while {[$e compare $current >= [list $anchor - 4 char]]} {
	foreach {current_x current_y} [_text_ind_to_x_y $e $current] break
	event generate $e <B1-Motion> -x $current_x -y $current_y
	set current [$e index [list $current - 1 char]]
	_pause 50
    }

    event generate $e <ButtonRelease-1> -x $current_x -y $current_y
    _pause 200

    # Save the position of the insert cursor
    lappend result [$e index insert]

    # Save the highlighted text
    lappend result [_get_selection $e]








|



|















|



|







301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
    # Now drag until selend is highlighted, then click up

    set current $anchor
    while {[$e compare $current <= $selend]} {
	foreach {current_x current_y} [_text_ind_to_x_y $e $current] break
	event generate $e <B1-Motion> -x $current_x -y $current_y
	set current [$e index [list $current + 1 char]]
	pause 50
    }

    event generate $e <ButtonRelease-1> -x $current_x -y $current_y
    pause 200

    # Save the position of the insert cursor
    lappend result [$e index insert]

    # Save the highlighted text
    lappend result [_get_selection $e]

    # Now click and click and drag to the left, over "Tcl/Tk selection"

    event generate $e <Button-1> -x $current_x -y $current_y

    while {[$e compare $current >= [list $anchor - 4 char]]} {
	foreach {current_x current_y} [_text_ind_to_x_y $e $current] break
	event generate $e <B1-Motion> -x $current_x -y $current_y
	set current [$e index [list $current - 1 char]]
	pause 50
    }

    event generate $e <ButtonRelease-1> -x $current_x -y $current_y
    pause 200

    # Save the position of the insert cursor
    lappend result [$e index insert]

    # Save the highlighted text
    lappend result [_get_selection $e]

385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
    # Now drag until selend is highlighted, then click up

    set current $anchor
    while {$current <= $selend} {
	foreach {current_x current_y} [_text_ind_to_x_y $e $current] break
	event generate $e <B1-Motion> -x $current_x -y $current_y
	incr current
	_pause 50
    }

    event generate $e <ButtonRelease-1> -x $current_x -y $current_y
    _pause 200

    # Save the position of the insert cursor
    lappend result [$e index insert]

    # Save the highlighted text
    lappend result [_get_selection $e]

    # Now click and click and drag to the left, over "Tcl/Tk selection"

    event generate $e <Button-1> -x $current_x -y $current_y

    while {$current >= ($anchor - 4)} {
	foreach {current_x current_y} [_text_ind_to_x_y $e $current] break
	event generate $e <B1-Motion> -x $current_x -y $current_y
	incr current -1
	_pause 50
    }

    event generate $e <ButtonRelease-1> -x $current_x -y $current_y
    _pause 200

    # Save the position of the insert cursor
    lappend result [$e index insert]

    # Save the highlighted text
    lappend result [_get_selection $e]








|



|















|



|







368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
    # Now drag until selend is highlighted, then click up

    set current $anchor
    while {$current <= $selend} {
	foreach {current_x current_y} [_text_ind_to_x_y $e $current] break
	event generate $e <B1-Motion> -x $current_x -y $current_y
	incr current
	pause 50
    }

    event generate $e <ButtonRelease-1> -x $current_x -y $current_y
    pause 200

    # Save the position of the insert cursor
    lappend result [$e index insert]

    # Save the highlighted text
    lappend result [_get_selection $e]

    # Now click and click and drag to the left, over "Tcl/Tk selection"

    event generate $e <Button-1> -x $current_x -y $current_y

    while {$current >= ($anchor - 4)} {
	foreach {current_x current_y} [_text_ind_to_x_y $e $current] break
	event generate $e <B1-Motion> -x $current_x -y $current_y
	incr current -1
	pause 50
    }

    event generate $e <ButtonRelease-1> -x $current_x -y $current_y
    pause 200

    # Save the position of the insert cursor
    lappend result [$e index insert]

    # Save the highlighted text
    lappend result [_get_selection $e]

439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494

    # Get the x,y coords of the second e in "select"
    foreach {anchor_x anchor_y} [_text_ind_to_x_y $e $anchor] break

    # Click down, release, then click down again
    event generate $e <Enter>
    event generate $e <Button-1> -x $anchor_x -y $anchor_y
    _pause 50
    event generate $e <ButtonRelease-1> -x $anchor_x -y $anchor_y
    _pause 50
    event generate $e <Button-1> -x $anchor_x -y $anchor_y
    _pause 50

    # Save the highlighted text
    set result [list]
    lappend result [_get_selection $e]

    # Insert cursor should be at beginning of "select"
    lappend result [$e index insert]

    # Move mouse one character to the left
    set current [$e index [list $anchor - 1 char]]
    foreach {current_x current_y} [_text_ind_to_x_y $e $current] break

    event generate $e <B1-Motion> -x $current_x -y $current_y
    _pause 50

    # Insert cursor should be before the l in "select"
    lappend result [$e index insert]

    # Selection should still be the word "select"
    lappend result [_get_selection $e]

    # Move mouse to the space before the word "select"
    set current [$e index [list $current - 3 char]]

    foreach {current_x current_y} [_text_ind_to_x_y $e $current] break
    event generate $e <B1-Motion> -x $current_x -y $current_y
    _pause 200

    lappend result [$e index insert]
    lappend result [_get_selection $e]

    # Move mouse to the r in "Word"
    set current 1.2
    foreach {current_x current_y} [_text_ind_to_x_y $e $current] break

    event generate $e <B1-Motion> -x $current_x -y $current_y
    _pause 50

    # Selection should now be "Word select"
    lappend result [_get_selection $e]

    # Insert cursor should be before the r in "Word"
    lappend result [$e index insert]








|

|

|













|












|









|







422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477

    # Get the x,y coords of the second e in "select"
    foreach {anchor_x anchor_y} [_text_ind_to_x_y $e $anchor] break

    # Click down, release, then click down again
    event generate $e <Enter>
    event generate $e <Button-1> -x $anchor_x -y $anchor_y
    pause 50
    event generate $e <ButtonRelease-1> -x $anchor_x -y $anchor_y
    pause 50
    event generate $e <Button-1> -x $anchor_x -y $anchor_y
    pause 50

    # Save the highlighted text
    set result [list]
    lappend result [_get_selection $e]

    # Insert cursor should be at beginning of "select"
    lappend result [$e index insert]

    # Move mouse one character to the left
    set current [$e index [list $anchor - 1 char]]
    foreach {current_x current_y} [_text_ind_to_x_y $e $current] break

    event generate $e <B1-Motion> -x $current_x -y $current_y
    pause 50

    # Insert cursor should be before the l in "select"
    lappend result [$e index insert]

    # Selection should still be the word "select"
    lappend result [_get_selection $e]

    # Move mouse to the space before the word "select"
    set current [$e index [list $current - 3 char]]

    foreach {current_x current_y} [_text_ind_to_x_y $e $current] break
    event generate $e <B1-Motion> -x $current_x -y $current_y
    pause 200

    lappend result [$e index insert]
    lappend result [_get_selection $e]

    # Move mouse to the r in "Word"
    set current 1.2
    foreach {current_x current_y} [_text_ind_to_x_y $e $current] break

    event generate $e <B1-Motion> -x $current_x -y $current_y
    pause 50

    # Selection should now be "Word select"
    lappend result [_get_selection $e]

    # Insert cursor should be before the r in "Word"
    lappend result [$e index insert]

510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564

    # Get the x,y coords of the second e in "select"
    foreach {anchor_x anchor_y} [_text_ind_to_x_y $e $anchor] break

    # Click down, release, then click down again
    event generate $e <Enter>
    event generate $e <Button-1> -x $anchor_x -y $anchor_y
    _pause 50
    event generate $e <ButtonRelease-1> -x $anchor_x -y $anchor_y
    _pause 50
    event generate $e <Button-1> -x $anchor_x -y $anchor_y
    _pause 50

    set result [list]
    lappend result [_get_selection $e]

    # Insert cursor should be at the end of "select"
    lappend result [$e index insert]

    # Move mouse one character to the left
    set current [expr {$anchor - 1}]
    foreach {current_x current_y} [_text_ind_to_x_y $e $current] break

    event generate $e <B1-Motion> -x $current_x -y $current_y
    _pause 50

    # Insert cursor should be before the l in "select"
    lappend result [$e index insert]

    # Selection should still be the word "select"
    lappend result [_get_selection $e]

    # Move mouse to the space before the word "select"
    set current [expr {$current - 3}]
    foreach {current_x current_y} [_text_ind_to_x_y $e $current] break

    event generate $e <B1-Motion> -x $current_x -y $current_y
    _pause 50

    lappend result [$e index insert]
    lappend result [_get_selection $e]

    # Move mouse to the r in "Word"
    set current [expr {$current - 2}]
    foreach {current_x current_y} [_text_ind_to_x_y $e $current] break

    event generate $e <B1-Motion> -x $current_x -y $current_y
    _pause 50

    # Selection should now be "Word select"
    lappend result [_get_selection $e]

    # Insert cursor should be before the r in "Word"
    lappend result [$e index insert]








|

|

|












|












|









|







493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547

    # Get the x,y coords of the second e in "select"
    foreach {anchor_x anchor_y} [_text_ind_to_x_y $e $anchor] break

    # Click down, release, then click down again
    event generate $e <Enter>
    event generate $e <Button-1> -x $anchor_x -y $anchor_y
    pause 50
    event generate $e <ButtonRelease-1> -x $anchor_x -y $anchor_y
    pause 50
    event generate $e <Button-1> -x $anchor_x -y $anchor_y
    pause 50

    set result [list]
    lappend result [_get_selection $e]

    # Insert cursor should be at the end of "select"
    lappend result [$e index insert]

    # Move mouse one character to the left
    set current [expr {$anchor - 1}]
    foreach {current_x current_y} [_text_ind_to_x_y $e $current] break

    event generate $e <B1-Motion> -x $current_x -y $current_y
    pause 50

    # Insert cursor should be before the l in "select"
    lappend result [$e index insert]

    # Selection should still be the word "select"
    lappend result [_get_selection $e]

    # Move mouse to the space before the word "select"
    set current [expr {$current - 3}]
    foreach {current_x current_y} [_text_ind_to_x_y $e $current] break

    event generate $e <B1-Motion> -x $current_x -y $current_y
    pause 50

    lappend result [$e index insert]
    lappend result [_get_selection $e]

    # Move mouse to the r in "Word"
    set current [expr {$current - 2}]
    foreach {current_x current_y} [_text_ind_to_x_y $e $current] break

    event generate $e <B1-Motion> -x $current_x -y $current_y
    pause 50

    # Selection should now be "Word select"
    lappend result [_get_selection $e]

    # Insert cursor should be before the r in "Word"
    lappend result [$e index insert]

582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
    # Triple click one third line leaving mouse down

    foreach {anchor_x anchor_y} [_text_ind_to_x_y $e $anchor] break

    event generate $e <Enter>

    event generate $e <Button-1> -x $anchor_x -y $anchor_y
    _pause 50
    event generate $e <ButtonRelease-1> -x $anchor_x -y $anchor_y
    _pause 50

    event generate $e <Button-1> -x $anchor_x -y $anchor_y
    _pause 50
    event generate $e <ButtonRelease-1> -x $anchor_x -y $anchor_y
    _pause 50

    event generate $e <Button-1> -x $anchor_x -y $anchor_y
    _pause 50

    set result [list]
    lappend result [_get_selection $e]

    # Drag up to second line

    set current [$e index [list $anchor - 1 line]]
    foreach {current_x current_y} [_text_ind_to_x_y $e $current] break

    event generate $e <B1-Motion> -x $current_x -y $current_y
    _pause 50

    lappend result [_get_selection $e]

    # Drag up to first line

    set current [$e index [list $current - 1 line]]
    foreach {current_x current_y} [_text_ind_to_x_y $e $current] break

    event generate $e <B1-Motion> -x $current_x -y $current_y
    _pause 50

    lappend result [_get_selection $e]

    return $result
} -cleanup {
    deleteWindows
} -result [list "LINE THREE\n" "LINE TWO\nLINE THREE\n" \







|

|


|

|


|










|









|







565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
    # Triple click one third line leaving mouse down

    foreach {anchor_x anchor_y} [_text_ind_to_x_y $e $anchor] break

    event generate $e <Enter>

    event generate $e <Button-1> -x $anchor_x -y $anchor_y
    pause 50
    event generate $e <ButtonRelease-1> -x $anchor_x -y $anchor_y
    pause 50

    event generate $e <Button-1> -x $anchor_x -y $anchor_y
    pause 50
    event generate $e <ButtonRelease-1> -x $anchor_x -y $anchor_y
    pause 50

    event generate $e <Button-1> -x $anchor_x -y $anchor_y
    pause 50

    set result [list]
    lappend result [_get_selection $e]

    # Drag up to second line

    set current [$e index [list $anchor - 1 line]]
    foreach {current_x current_y} [_text_ind_to_x_y $e $current] break

    event generate $e <B1-Motion> -x $current_x -y $current_y
    pause 50

    lappend result [_get_selection $e]

    # Drag up to first line

    set current [$e index [list $current - 1 line]]
    foreach {current_x current_y} [_text_ind_to_x_y $e $current] break

    event generate $e <B1-Motion> -x $current_x -y $current_y
    pause 50

    lappend result [_get_selection $e]

    return $result
} -cleanup {
    deleteWindows
} -result [list "LINE THREE\n" "LINE TWO\nLINE THREE\n" \
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
    set right_x [expr {($x1 + $width) - 2}]
    set right_y $middle_y

    # Double click near left hand egde of the letter A

    event generate $e <Enter>
    event generate $e <Button-1> -x $left_x -y $left_y
    _pause 50
    event generate $e <ButtonRelease-1> -x $left_x -y $left_y
    _pause 50
    event generate $e <Button-1> -x $left_x -y $left_y
    _pause 50
    event generate $e <ButtonRelease-1> -x $left_x -y $left_y
    _pause 50

    set result [list]
    lappend result [$e index insert]
    lappend result [_get_selection $e]

    # Clear selection by clicking at 0,0

    event generate $e <Button-1> -x 0 -y 0
    _pause 50
    event generate $e <ButtonRelease-1> -x 0 -y 0
    _pause 50

    # Double click near right hand edge of the letter A

    event generate $e <Button-1> -x $right_x -y $right_y
    _pause 50
    event generate $e <ButtonRelease-1> -x $right_x -y $right_y
    _pause 50
    event generate $e <Button-1> -x $right_x -y $right_y
    _pause 50
    event generate $e <ButtonRelease-1> -x $right_x -y $right_y
    _pause 50

    lappend result [$e index insert]
    lappend result [_get_selection $e]

    return $result
} -cleanup {
    deleteWindows







|

|

|

|








|

|




|

|

|

|







654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
    set right_x [expr {($x1 + $width) - 2}]
    set right_y $middle_y

    # Double click near left hand egde of the letter A

    event generate $e <Enter>
    event generate $e <Button-1> -x $left_x -y $left_y
    pause 50
    event generate $e <ButtonRelease-1> -x $left_x -y $left_y
    pause 50
    event generate $e <Button-1> -x $left_x -y $left_y
    pause 50
    event generate $e <ButtonRelease-1> -x $left_x -y $left_y
    pause 50

    set result [list]
    lappend result [$e index insert]
    lappend result [_get_selection $e]

    # Clear selection by clicking at 0,0

    event generate $e <Button-1> -x 0 -y 0
    pause 50
    event generate $e <ButtonRelease-1> -x 0 -y 0
    pause 50

    # Double click near right hand edge of the letter A

    event generate $e <Button-1> -x $right_x -y $right_y
    pause 50
    event generate $e <ButtonRelease-1> -x $right_x -y $right_y
    pause 50
    event generate $e <Button-1> -x $right_x -y $right_y
    pause 50
    event generate $e <ButtonRelease-1> -x $right_x -y $right_y
    pause 50

    lappend result [$e index insert]
    lappend result [_get_selection $e]

    return $result
} -cleanup {
    deleteWindows
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
    set right_x [expr {($x1 + $width) - 2}]
    set right_y $middle_y

    # Double click near left hand egde of the letter A

    event generate $e <Enter>
    event generate $e <Button-1> -x $left_x -y $left_y
    _pause 50
    event generate $e <ButtonRelease-1> -x $left_x -y $left_y
    _pause 50
    event generate $e <Button-1> -x $left_x -y $left_y
    _pause 50
    event generate $e <ButtonRelease-1> -x $left_x -y $left_y
    _pause 50

    set result [list]
    lappend result [$e index insert]
    lappend result [_get_selection $e]

    # Clear selection by clicking at 0,0

    event generate $e <Button-1> -x 0 -y 0
    _pause 50
    event generate $e <ButtonRelease-1> -x 0 -y 0
    _pause 50

    # Double click near right hand edge of the letter A

    event generate $e <Button-1> -x $right_x -y $right_y
    _pause 50
    event generate $e <ButtonRelease-1> -x $right_x -y $right_y
    _pause 50
    event generate $e <Button-1> -x $right_x -y $right_y
    _pause 50
    event generate $e <ButtonRelease-1> -x $right_x -y $right_y
    _pause 50

    lappend result [$e index insert]
    lappend result [_get_selection $e]

    return $result
} -cleanup {
    deleteWindows







|

|

|

|








|

|




|

|

|

|







721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
    set right_x [expr {($x1 + $width) - 2}]
    set right_y $middle_y

    # Double click near left hand egde of the letter A

    event generate $e <Enter>
    event generate $e <Button-1> -x $left_x -y $left_y
    pause 50
    event generate $e <ButtonRelease-1> -x $left_x -y $left_y
    pause 50
    event generate $e <Button-1> -x $left_x -y $left_y
    pause 50
    event generate $e <ButtonRelease-1> -x $left_x -y $left_y
    pause 50

    set result [list]
    lappend result [$e index insert]
    lappend result [_get_selection $e]

    # Clear selection by clicking at 0,0

    event generate $e <Button-1> -x 0 -y 0
    pause 50
    event generate $e <ButtonRelease-1> -x 0 -y 0
    pause 50

    # Double click near right hand edge of the letter A

    event generate $e <Button-1> -x $right_x -y $right_y
    pause 50
    event generate $e <ButtonRelease-1> -x $right_x -y $right_y
    pause 50
    event generate $e <Button-1> -x $right_x -y $right_y
    pause 50
    event generate $e <ButtonRelease-1> -x $right_x -y $right_y
    pause 50

    lappend result [$e index insert]
    lappend result [_get_selection $e]

    return $result
} -cleanup {
    deleteWindows
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
} -result {OK}

test event-9.1 {enter . window by destroying a toplevel - bug b1d115fa60} -setup {
    set EnterBind [bind . <Enter>]
} -body {
    wm geometry . 200x200+300+300
    wm deiconify .
    _pause 200
    toplevel .top2 -width 200 -height 200
    wm geometry .top2 +[expr {[winfo rootx .]+50}]+[expr {[winfo rooty .]+50}]
    update idletasks
    wm deiconify .top2
    update idletasks
    raise .top2
    _pause 400
    event generate .top2 <Motion> -warp 1 -x 50 -y 50
    _pause 100
    bind . <Enter> {lappend res %W}
    set res [list ]
    destroy .top2
    update idletasks
    _pause 200
    set res
} -cleanup {
    deleteWindows
    bind . <Enter> $EnterBind
} -result {.}

# This test fails sporadically when run on the macOS CI runner. It does







|






|

|




|







800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
} -result {OK}

test event-9.1 {enter . window by destroying a toplevel - bug b1d115fa60} -setup {
    set EnterBind [bind . <Enter>]
} -body {
    wm geometry . 200x200+300+300
    wm deiconify .
    pause 200
    toplevel .top2 -width 200 -height 200
    wm geometry .top2 +[expr {[winfo rootx .]+50}]+[expr {[winfo rooty .]+50}]
    update idletasks
    wm deiconify .top2
    update idletasks
    raise .top2
    pause 400
    event generate .top2 <Motion> -warp 1 -x 50 -y 50
    pause 100
    bind . <Enter> {lappend res %W}
    set res [list ]
    destroy .top2
    update idletasks
    pause 200
    set res
} -cleanup {
    deleteWindows
    bind . <Enter> $EnterBind
} -result {.}

# This test fails sporadically when run on the macOS CI runner. It does
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
	update
	set iconified true
    }
} -body {
    toplevel .top1
    wm geometry .top1 200x200+300+300
    wm deiconify .top1
    _pause 200
    toplevel .top2 -width 200 -height 200
    wm geometry .top2 +[expr {[winfo rootx .top1]+50}]+[expr {[winfo rooty .top1]+50}]
    _pause 200
    wm deiconify .top2
    update idletasks
    raise .top2
    _pause 400
    event generate .top2 <Motion> -warp 1 -x 50 -y 50
    _pause 100
    bind .top1 <Enter> {lappend res %W}
    set res [list ]
    destroy .top2
    _pause 200
    set res
} -cleanup {
    deleteWindows ; # destroy all children of ".", this already includes .top1
    if {$iconified} {
	wm deiconify .
	update
    }







|


|



|

|



|







837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
	update
	set iconified true
    }
} -body {
    toplevel .top1
    wm geometry .top1 200x200+300+300
    wm deiconify .top1
    pause 200
    toplevel .top2 -width 200 -height 200
    wm geometry .top2 +[expr {[winfo rootx .top1]+50}]+[expr {[winfo rooty .top1]+50}]
    pause 200
    wm deiconify .top2
    update idletasks
    raise .top2
    pause 400
    event generate .top2 <Motion> -warp 1 -x 50 -y 50
    pause 100
    bind .top1 <Enter> {lappend res %W}
    set res [list ]
    destroy .top2
    pause 200
    set res
} -cleanup {
    deleteWindows ; # destroy all children of ".", this already includes .top1
    if {$iconified} {
	wm deiconify .
	update
    }
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958

test event-9.11 {pointer window container = parent} -setup {
    setup_win_mousepointer .one
    wm withdraw .one
    create_and_pack_frames .one
    wm deiconify .one
    tkwait visibility .one.f1.f2
    _pause 200; # needed for Windows
    update idletasks; # finish display of window
    set result "|"
} -body {
    bind all <Leave> {append result "<Leave> %d %W|"}
    bind all <Enter> {append result "<Enter> %d %W|"}
    destroy .one.f1.f2
    update







|







927
928
929
930
931
932
933
934
935
936
937
938
939
940
941

test event-9.11 {pointer window container = parent} -setup {
    setup_win_mousepointer .one
    wm withdraw .one
    create_and_pack_frames .one
    wm deiconify .one
    tkwait visibility .one.f1.f2
    pause 200; # needed for Windows
    update idletasks; # finish display of window
    set result "|"
} -body {
    bind all <Leave> {append result "<Leave> %d %W|"}
    bind all <Enter> {append result "<Enter> %d %W|"}
    destroy .one.f1.f2
    update
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
    wm withdraw .one
    create_and_pack_frames .one
    pack propagate .one.f1.f2 0
    pack [frame .one.g -bg orange -width 80 -height 80] -anchor se -side bottom -in .one.f1.f2
    wm deiconify .one
    tkwait visibility .one.g
    event generate .one <Motion> -warp 1 -x 250 -y 250
    _pause 200; # needed for Windows
    set result "|"
} -body {
    bind all <Leave> {append result "<Leave> %d %W|"}
    bind all <Enter> {append result "<Enter> %d %W|"}
    destroy .one.g
    update
    set result







|







952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
    wm withdraw .one
    create_and_pack_frames .one
    pack propagate .one.f1.f2 0
    pack [frame .one.g -bg orange -width 80 -height 80] -anchor se -side bottom -in .one.f1.f2
    wm deiconify .one
    tkwait visibility .one.g
    event generate .one <Motion> -warp 1 -x 250 -y 250
    pause 200; # needed for Windows
    set result "|"
} -body {
    bind all <Leave> {append result "<Leave> %d %W|"}
    bind all <Enter> {append result "<Enter> %d %W|"}
    destroy .one.g
    update
    set result
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
    # TkPointerDeadWindow() and subsequent reading in GenerateEnterLeave().
    setup_win_mousepointer .one
    wm withdraw .one
    create_and_pack_frames .one
    wm deiconify .one
    tkwait visibility .one.f1.f2
    update idletasks; # finish displaying window
    _pause 200; # needed for Windows
    set result "|"
} -body {
    bind all <Leave> {append result "<Leave> %d %W|"}
    bind all <Enter> {append result "<Enter> %d %W|"}
    destroy .one.f1
    update
    set result







|







1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
    # TkPointerDeadWindow() and subsequent reading in GenerateEnterLeave().
    setup_win_mousepointer .one
    wm withdraw .one
    create_and_pack_frames .one
    wm deiconify .one
    tkwait visibility .one.f1.f2
    update idletasks; # finish displaying window
    pause 200; # needed for Windows
    set result "|"
} -body {
    bind all <Leave> {append result "<Leave> %d %W|"}
    bind all <Enter> {append result "<Enter> %d %W|"}
    destroy .one.f1
    update
    set result
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
    # TkPointerDeadWindow() and subsequent reading in GenerateEnterLeave().
    setup_win_mousepointer .one
    wm withdraw .one
    create_and_pack_frames .one
    wm deiconify .one
    tkwait visibility .one.f1.f2
    update idletasks; # finish displaying window
    _pause 200; # needed for Windows
    set result "|"
} -body {
    bind all <Leave> {append result "<Leave> %d %W|"}
    bind all <Enter> {append result "<Enter> %d %W|"}
    destroy .one.f1.f2
    update; # make sure window is gone
    destroy .one.f1







|







1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
    # TkPointerDeadWindow() and subsequent reading in GenerateEnterLeave().
    setup_win_mousepointer .one
    wm withdraw .one
    create_and_pack_frames .one
    wm deiconify .one
    tkwait visibility .one.f1.f2
    update idletasks; # finish displaying window
    pause 200; # needed for Windows
    set result "|"
} -body {
    bind all <Leave> {append result "<Leave> %d %W|"}
    bind all <Enter> {append result "<Enter> %d %W|"}
    destroy .one.f1.f2
    update; # make sure window is gone
    destroy .one.f1
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
    bind all <Enter> {}
    unset result
} -result {|}

# cleanup
# macOS sometimes has trouble deleting the test window,
# causing a failure in focus.test.
_pause 200;
deleteWindows
update
unset -nocomplain keypress_lookup
rename _init_keypress_lookup {}
rename _keypress_lookup {}
rename _keypress {}
rename _pause {}
rename _text_ind_to_x_y {}
rename _get_selection {}
rename create_and_pack_frames {}
rename setup_win_mousepointer {}

cleanupTests
return









|






<









1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181

1182
1183
1184
1185
1186
1187
1188
1189
1190
    bind all <Enter> {}
    unset result
} -result {|}

# cleanup
# macOS sometimes has trouble deleting the test window,
# causing a failure in focus.test.
pause 200;
deleteWindows
update
unset -nocomplain keypress_lookup
rename _init_keypress_lookup {}
rename _keypress_lookup {}
rename _keypress {}

rename _text_ind_to_x_y {}
rename _get_selection {}
rename create_and_pack_frames {}
rename setup_win_mousepointer {}

cleanupTests
return


Changes to tests/filebox.test.
1
2
3
4
5
6
7
8
9
10
11



12
13
14
15
16
17
18
# This file is a Tcl script to test out Tk's "tk_getOpenFile" and
# "tk_getSaveFile" commands. It is organized in the standard fashion
# for Tcl tests.
#
# Copyright © 1996 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

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




test fileDialog-0.1 {GetFileName: file types: MakeFilter() fails} {
    # MacOS type that is too long

    set res [list [catch {tk_getSaveFile -filetypes {{"foo" .foo {\0\0\0\0\0}}}} msg] $msg]
    regsub -all "\0" $res {\\0}
} {1 {bad Macintosh file type "\0\0\0\0\0"}}











>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# This file is a Tcl script to test out Tk's "tk_getOpenFile" and
# "tk_getSaveFile" commands. It is organized in the standard fashion
# for Tcl tests.
#
# Copyright © 1996 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

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

# Import utility procs for specific functional areas
testutils import dialog

test fileDialog-0.1 {GetFileName: file types: MakeFilter() fails} {
    # MacOS type that is too long

    set res [list [catch {tk_getSaveFile -filetypes {{"foo" .foo {\0\0\0\0\0}}}} msg] $msg]
    regsub -all "\0" $res {\\0}
} {1 {bad Macintosh file type "\0\0\0\0\0"}}
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

#----------------------------------------------------------------------
#
# Procedures needed by this test file
#
#----------------------------------------------------------------------

proc ToPressButton {parent btn} {
    global isNative
    if {!$isNative} {
	after 100 SendButtonPress $parent $btn mouse
    }
}

proc ToEnterFileByKey {parent fileName fileDir} {
    global isNative
    if {!$isNative} {
	after 100 EnterFileByKey $parent [list $fileName] [list $fileDir]
    }
}

proc PressButton {btn} {
    event generate $btn <Enter>
    event generate $btn <Button-1> -x 5 -y 5
    event generate $btn <ButtonRelease-1> -x 5 -y 5
}

proc EnterFileByKey {parent fileName fileDir} {
    global tk_strictMotif
    if {$parent == "."} {
	set w .__tk_filedialog
    } else {
	set w $parent.__tk_filedialog
    }
    upvar ::tk::dialog::file::__tk_filedialog data

    if {$tk_strictMotif} {
	$data(sEnt) delete 0 end
	$data(sEnt) insert 0 [file join $fileDir $fileName]
    } else {
	$data(ent) delete 0 end
	$data(ent) insert 0 $fileName
    }

    update
    SendButtonPress $parent ok mouse
}

proc SendButtonPress {parent btn type} {
    if {$parent == "."} {
	set w .__tk_filedialog
    } else {
	set w $parent.__tk_filedialog
    }
    upvar ::tk::dialog::file::__tk_filedialog data

    set button $data($btn\Btn)
    if ![winfo ismapped $button] {
	update
    }

    if {$type == "mouse"} {
	PressButton $button
    } else {
	event generate $w <Enter>
	focus $w
	event generate $button <Enter>
	event generate $w <Key> -keysym Return
    }
}


#----------------------------------------------------------------------
#
# The test suite proper
#
#----------------------------------------------------------------------








<
<
<
<
<
<
<

<
|




<
<
<
<
<
<




















<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







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

#----------------------------------------------------------------------
#
# Procedures needed by this test file
#
#----------------------------------------------------------------------








proc ToEnterFileByKey {parent fileName fileDir} {

    if {! $::dialogIsNative} {
	after 100 EnterFileByKey $parent [list $fileName] [list $fileDir]
    }
}







proc EnterFileByKey {parent fileName fileDir} {
    global tk_strictMotif
    if {$parent == "."} {
	set w .__tk_filedialog
    } else {
	set w $parent.__tk_filedialog
    }
    upvar ::tk::dialog::file::__tk_filedialog data

    if {$tk_strictMotif} {
	$data(sEnt) delete 0 end
	$data(sEnt) insert 0 [file join $fileDir $fileName]
    } else {
	$data(ent) delete 0 end
	$data(ent) insert 0 $fileName
    }

    update
    SendButtonPress $parent ok mouse
}

























#----------------------------------------------------------------------
#
# The test suite proper
#
#----------------------------------------------------------------------

201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
    test filebox-1.5-$mode "tk_getOpenFile command" -body {
	tk_getOpenFile -parent foo.bar
    } -returnCodes error -result {bad window path name "foo.bar"}
    test filebox-1.6-$mode "tk_getOpenFile command" -body {
	tk_getOpenFile -filetypes {Foo}
    } -returnCodes error -result {bad file type "Foo", should be "typeName {extension ?extensions ...?} ?{macType ?macTypes ...?}?"}

    set isNative [expr {
	[info commands ::tk::MotifFDialog] eq ""   &&
	[info commands ::tk::dialog::file::] eq ""
    }]

    set parent .

    set verylongstring longstring:
    set verylongstring $verylongstring$verylongstring
    set verylongstring $verylongstring$verylongstring
    set verylongstring $verylongstring$verylongstring
    set verylongstring $verylongstring$verylongstring







<
<
<
<
<







166
167
168
169
170
171
172





173
174
175
176
177
178
179
    test filebox-1.5-$mode "tk_getOpenFile command" -body {
	tk_getOpenFile -parent foo.bar
    } -returnCodes error -result {bad window path name "foo.bar"}
    test filebox-1.6-$mode "tk_getOpenFile command" -body {
	tk_getOpenFile -filetypes {Foo}
    } -returnCodes error -result {bad file type "Foo", should be "typeName {extension ?extensions ...?} ?{macType ?macTypes ...?}?"}






    set parent .

    set verylongstring longstring:
    set verylongstring $verylongstring$verylongstring
    set verylongstring $verylongstring$verylongstring
    set verylongstring $verylongstring$verylongstring
    set verylongstring $verylongstring$verylongstring
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
    test filebox-4.5-$mode "tk_getSaveFile command" -body {
	tk_getSaveFile -parent foo.bar
    } -returnCodes error -result {bad window path name "foo.bar"}
    test filebox-4.6-$mode "tk_getSaveFile command" -body {
	tk_getSaveFile -filetypes {Foo}
    } -returnCodes error -result {bad file type "Foo", should be "typeName {extension ?extensions ...?} ?{macType ?macTypes ...?}?"}

    set isNative [expr {
	[info commands ::tk::MotifFDialog] eq "" &&
	[info commands ::tk::dialog::file::] eq ""
    }]

    test filebox-5.1-$mode "tk_getSaveFile command" nonUnixUserInteraction {
	ToPressButton $parent cancel
	tk_getSaveFile -title "Press Cancel ($verylongstring)" -parent $parent
    } ""

    set fileName "12x 455"
    set fileDir [pwd]







<
<
<
<
<







306
307
308
309
310
311
312





313
314
315
316
317
318
319
    test filebox-4.5-$mode "tk_getSaveFile command" -body {
	tk_getSaveFile -parent foo.bar
    } -returnCodes error -result {bad window path name "foo.bar"}
    test filebox-4.6-$mode "tk_getSaveFile command" -body {
	tk_getSaveFile -filetypes {Foo}
    } -returnCodes error -result {bad file type "Foo", should be "typeName {extension ?extensions ...?} ?{macType ?macTypes ...?}?"}






    test filebox-5.1-$mode "tk_getSaveFile command" nonUnixUserInteraction {
	ToPressButton $parent cancel
	tk_getSaveFile -title "Press Cancel ($verylongstring)" -parent $parent
    } ""

    set fileName "12x 455"
    set fileDir [pwd]
482
483
484
485
486
487
488
489
490


491

492

493
494

    # The rest of the tests need to be executed on Unix only.
    # They test whether the dialog box widgets were implemented correctly.
    # These tests are not
    # needed on the other platforms because they use native file dialogs.
}

set tk_strictMotif $tk_strictMotif_old



# cleanup

removeFile filebox.tmp

cleanupTests
return







<
|
>
>
|
>

>


437
438
439
440
441
442
443

444
445
446
447
448
449
450
451
452

    # The rest of the tests need to be executed on Unix only.
    # They test whether the dialog box widgets were implemented correctly.
    # These tests are not
    # needed on the other platforms because they use native file dialogs.
}


#
# CLEANUP
#

set tk_strictMotif $tk_strictMotif_old
removeFile filebox.tmp
testutils forget dialog
cleanupTests
return
Changes to tests/focus.test.
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
# This file is a Tcl script to test out the "focus" command and the
# other procedures in the file tkFocus.c.  It is organized in the
# standard fashion for Tcl tests.
#
# Copyright © 1994-1996 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
eval tcltest::configure $argv
tcltest::loadTestedCommands
namespace import -force tcltest::test
if {[tk windowingsystem] eq "aqua"} {
    interp create childInterp
    load {} Tk childInterp
}



testConstraint failsOnUbuntu [expr {![info exists ::env(CI)] || ![string match Linux $::tcl_platform(os)]}]
testConstraint failsOnXQuarz [expr {$tcl_platform(os) ne "Darwin" || [tk windowingsystem] ne "x11" }]

proc focusSetup {} {
    destroy .t
    toplevel .t
    wm geom .t +0+0
    foreach i {b1 b2 b3 b4} {
	button .t.$i -text .t.$i -relief raised -bd 2
	pack .t.$i












|
|
|
|
>
>
|
<
<








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
# This file is a Tcl script to test out the "focus" command and the
# other procedures in the file tkFocus.c.  It is organized in the
# standard fashion for Tcl tests.
#
# Copyright © 1994-1996 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
eval tcltest::configure $argv
tcltest::loadTestedCommands
namespace import -force tcltest::test

# Import utility procs for specific functional areas
testutils import child

if {[tk windowingsystem] eq "aqua"} {
    childTkInterp childInterp
}



proc focusSetup {} {
    destroy .t
    toplevel .t
    wm geom .t +0+0
    foreach i {b1 b2 b3 b4} {
	button .t.$i -text .t.$i -relief raised -bd 2
	pack .t.$i
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
		    break
		}
	    }
	}
    }
} else {
    proc focusClear {} {
	dobg {after 200; focus -force .; update}
	after 400
	update
    }
}


# Button used in some tests in the whole test file
button .b -text .b -relief raised -bd 2
pack .b

# Make sure the window manager knows who has focus
catch {fixfocus}

# cleanupbg will be after 4.3 test
setupbg
update
bind all <FocusIn> {
    append focusInfo "in %W %d\n"
}
bind all <FocusOut> {
    append focusInfo "out %W %d\n"
}







|













|
|







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
		    break
		}
	    }
	}
    }
} else {
    proc focusClear {} {
	childTkProcess eval {after 200; focus -force .; update}
	after 400
	update
    }
}


# Button used in some tests in the whole test file
button .b -text .b -relief raised -bd 2
pack .b

# Make sure the window manager knows who has focus
catch {fixfocus}

# childTkProcess exit will be after 4.3 test
childTkProcess create
update
bind all <FocusIn> {
    append focusInfo "in %W %d\n"
}
bind all <FocusOut> {
    append focusInfo "out %W %d\n"
}
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
    unix
} -body {
    focus -displayof .lousy
} -returnCodes error -result {bad window path name ".lousy"}
test focus-1.12 {Tk_FocusCmd procedure, -displayof option} -constraints {
    unix
} -body {
    # Move focus to the root window in the child or bg interpreter.
    focusClear
    # The main application does not have focus, so this has no effect now.
    focus .t
    focus -displayof .t.b3
}  -result {}
test focus-1.13 {Tk_FocusCmd procedure, -displayof option} -constraints {
    unix







|







165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
    unix
} -body {
    focus -displayof .lousy
} -returnCodes error -result {bad window path name ".lousy"}
test focus-1.12 {Tk_FocusCmd procedure, -displayof option} -constraints {
    unix
} -body {
    # Move focus to the root window in the child process/interpreter.
    focusClear
    # The main application does not have focus, so this has no effect now.
    focus .t
    focus -displayof .t.b3
}  -result {}
test focus-1.13 {Tk_FocusCmd procedure, -displayof option} -constraints {
    unix
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
    list $focusInfo [focus]
} -result {{out . NotifyNonlinear
in .t NotifyNonlinearVirtual
in .t.b1 NotifyNonlinear
} .t.b1}

test focus-2.6 {TkFocusFilterEvent procedure, FocusIn events} -constraints {
    unix  testwrapper failsOnUbuntu failsOnXQuarz
} -body {
    focus .t.b1
    focus .
    update
    event gen [testwrapper .t] <FocusIn> -detail NotifyAncestor
    set focusInfo {}
    set x [focus]
    event gen . <x>
    list $x $focusInfo
} -result {.t.b1 {press .t.b1 x}}
test focus-2.7 {TkFocusFilterEvent procedure, FocusOut events} -constraints {
    unix  testwrapper failsOnUbuntu failsOnXQuarz
} -body {
    set result {}
    foreach detail {NotifyAncestor NotifyInferior NotifyNonlinear
	    NotifyNonlinearVirtual NotifyPointer NotifyPointerRoot
	    NotifyVirtual} {
	focus -force .t.b1
	event gen [testwrapper .t] <FocusOut> -detail $detail
	update
	lappend result [focus]
    }
    return $result
} -result {{} .t.b1 {} {} .t.b1 .t.b1 {}}
test focus-2.8 {TkFocusFilterEvent procedure, FocusOut events} -constraints {
    unix  testwrapper
} -body {
    focus -force .t.b1
    event gen .t.b1 <FocusOut> -detail NotifyAncestor
    focus
} -result {.t.b1}
test focus-2.9 {TkFocusFilterEvent procedure, FocusOut events} -constraints {
    unix  testwrapper failsOnUbuntu failsOnXQuarz
} -body {
    focus .t.b1
    event gen [testwrapper .] <FocusOut> -detail NotifyAncestor
    focus
} -result {}
test focus-2.10 {TkFocusFilterEvent procedure, Enter events} -constraints {
    unix  testwrapper







|











|




















|







328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
    list $focusInfo [focus]
} -result {{out . NotifyNonlinear
in .t NotifyNonlinearVirtual
in .t.b1 NotifyNonlinear
} .t.b1}

test focus-2.6 {TkFocusFilterEvent procedure, FocusIn events} -constraints {
    unix  testwrapper failsOnUbuntu failsOnXQuartz
} -body {
    focus .t.b1
    focus .
    update
    event gen [testwrapper .t] <FocusIn> -detail NotifyAncestor
    set focusInfo {}
    set x [focus]
    event gen . <x>
    list $x $focusInfo
} -result {.t.b1 {press .t.b1 x}}
test focus-2.7 {TkFocusFilterEvent procedure, FocusOut events} -constraints {
    unix  testwrapper failsOnUbuntu failsOnXQuartz
} -body {
    set result {}
    foreach detail {NotifyAncestor NotifyInferior NotifyNonlinear
	    NotifyNonlinearVirtual NotifyPointer NotifyPointerRoot
	    NotifyVirtual} {
	focus -force .t.b1
	event gen [testwrapper .t] <FocusOut> -detail $detail
	update
	lappend result [focus]
    }
    return $result
} -result {{} .t.b1 {} {} .t.b1 .t.b1 {}}
test focus-2.8 {TkFocusFilterEvent procedure, FocusOut events} -constraints {
    unix  testwrapper
} -body {
    focus -force .t.b1
    event gen .t.b1 <FocusOut> -detail NotifyAncestor
    focus
} -result {.t.b1}
test focus-2.9 {TkFocusFilterEvent procedure, FocusOut events} -constraints {
    unix  testwrapper failsOnUbuntu failsOnXQuartz
} -body {
    focus .t.b1
    event gen [testwrapper .] <FocusOut> -detail NotifyAncestor
    focus
} -result {}
test focus-2.10 {TkFocusFilterEvent procedure, Enter events} -constraints {
    unix  testwrapper
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
} -body {
    focusSetup
    focus -force .t.b2
    update
    destroy .t.b2
    focus
} -result {.t}
cleanupbg


# I don't know how to test most of the remaining procedures of this file
# explicitly;  they've already been exercised by the preceding tests.

# Test 5.1 fails (before and after update)
test focus-5.1 {ChangeXFocus procedure, don't take focus unless have it} -constraints {
    unix testwrapper secureserver failsOnUbuntu failsOnXQuarz
} -body {
    setupbg
    focusSetup
    focus -force .t
    update
    set result [focus]
    send [dobg {tk appname}] {focus -force .; update}
    lappend result [focus]
    focus .t.b2
    update
    lappend result [focus]
} -cleanup {
    cleanupbg
} -result {.t {} {}}
destroy .t
bind all <FocusIn> {}
bind all <FocusOut> {}
bind all <Key> {}









|







|

|




|





|







611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
} -body {
    focusSetup
    focus -force .t.b2
    update
    destroy .t.b2
    focus
} -result {.t}
childTkProcess exit


# I don't know how to test most of the remaining procedures of this file
# explicitly;  they've already been exercised by the preceding tests.

# Test 5.1 fails (before and after update)
test focus-5.1 {ChangeXFocus procedure, don't take focus unless have it} -constraints {
    unix testwrapper secureserver failsOnUbuntu failsOnXQuartz
} -body {
    childTkProcess create
    focusSetup
    focus -force .t
    update
    set result [focus]
    send [childTkProcess eval {tk appname}] {focus -force .; update}
    lappend result [focus]
    focus .t.b2
    update
    lappend result [focus]
} -cleanup {
    childTkProcess exit
} -result {.t {} {}}
destroy .t
bind all <FocusIn> {}
bind all <FocusOut> {}
bind all <Key> {}


700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
    bind all <FocusIn> {}
    bind all <FocusOut> {}
} -result {{.t.f2.e1 {} {focus out .t.f2.e1 NotifyNonlinear} {focus out .t.f2 NotifyNonlinearVirtual} {focus in .t.f1 NotifyNonlinear} | {focus out .t.f1 NotifyNonlinear} {focus in .t.f2 NotifyNonlinearVirtual} {focus in .t.f2.e1 NotifyNonlinear}} {{focus in . NotifyVirtual} {focus in .e1 NotifyAncestor} | {focus out .e1 NotifyAncestor} {focus out . NotifyVirtual}}}

test focus-6.2 {miscellaneous - embedded application in different process} -constraints {
    unix  testwrapper
} -body {
    setupbg
    toplevel .t
    wm geometry .t +0+0
    frame .t.f1 -container 1
    frame .t.f2
    pack .t.f1 .t.f2
    entry .t.f2.e1 -bg red
    pack .t.f2.e1
    bind all <FocusIn> {lappend x "focus in %W %d"}
    bind all <FocusOut> {lappend x "focus out %W %d"}
    setupbg -use [winfo id .t.f1]
    dobg {
	entry .e1 -bg lightBlue
	pack .e1
	bind all <FocusIn> {lappend x "focus in %W %d"}
	bind all <FocusOut> {lappend x "focus out %W %d"}
	set x {}
    }

    # Claim the focus and wait long enough for it to really arrive.

    focus -force .t.f2.e1
    after 300 {set timer 1}
    vwait timer
    set x {}
    lappend x [focus] [dobg focus]

    # See if a "focus" command will move the focus to the embedded
    # application.

    dobg {focus .e1}
    after 300 {set timer 1}
    vwait timer
    lappend x |
    dobg {lappend x |}

    # Bring the focus back to the main application.

    focus .t.f2.e1
    after 300 {set timer 1}
    vwait timer
    set result [list $x [dobg {set x}]]
    return $result
} -cleanup {
    destroy .t
    cleanupbg
    bind all <FocusIn> {}
    bind all <FocusOut> {}
} -result {{.t.f2.e1 {} {focus out .t.f2.e1 NotifyNonlinear} {focus out .t.f2 NotifyNonlinearVirtual} {focus in .t.f1 NotifyNonlinear} | {focus out .t.f1 NotifyNonlinear} {focus in .t.f2 NotifyNonlinearVirtual} {focus in .t.f2.e1 NotifyNonlinear}} {{focus in . NotifyVirtual} {focus in .e1 NotifyAncestor} | {focus out .e1 NotifyAncestor} {focus out . NotifyVirtual}}}

test focus-7.1 {TkSetFocusWin procedure, unmapped windows} -setup {
    # TkSetFocusWin handles the case of not yet mapped windows
    # by not setting the focus on them right at the time it is







|









|
|













|




|



|






|



|







700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
    bind all <FocusIn> {}
    bind all <FocusOut> {}
} -result {{.t.f2.e1 {} {focus out .t.f2.e1 NotifyNonlinear} {focus out .t.f2 NotifyNonlinearVirtual} {focus in .t.f1 NotifyNonlinear} | {focus out .t.f1 NotifyNonlinear} {focus in .t.f2 NotifyNonlinearVirtual} {focus in .t.f2.e1 NotifyNonlinear}} {{focus in . NotifyVirtual} {focus in .e1 NotifyAncestor} | {focus out .e1 NotifyAncestor} {focus out . NotifyVirtual}}}

test focus-6.2 {miscellaneous - embedded application in different process} -constraints {
    unix  testwrapper
} -body {
    childTkProcess create
    toplevel .t
    wm geometry .t +0+0
    frame .t.f1 -container 1
    frame .t.f2
    pack .t.f1 .t.f2
    entry .t.f2.e1 -bg red
    pack .t.f2.e1
    bind all <FocusIn> {lappend x "focus in %W %d"}
    bind all <FocusOut> {lappend x "focus out %W %d"}
    childTkProcess create -use [winfo id .t.f1]
    childTkProcess eval {
	entry .e1 -bg lightBlue
	pack .e1
	bind all <FocusIn> {lappend x "focus in %W %d"}
	bind all <FocusOut> {lappend x "focus out %W %d"}
	set x {}
    }

    # Claim the focus and wait long enough for it to really arrive.

    focus -force .t.f2.e1
    after 300 {set timer 1}
    vwait timer
    set x {}
    lappend x [focus] [childTkProcess eval focus]

    # See if a "focus" command will move the focus to the embedded
    # application.

    childTkProcess eval {focus .e1}
    after 300 {set timer 1}
    vwait timer
    lappend x |
    childTkProcess eval {lappend x |}

    # Bring the focus back to the main application.

    focus .t.f2.e1
    after 300 {set timer 1}
    vwait timer
    set result [list $x [childTkProcess eval {set x}]]
    return $result
} -cleanup {
    destroy .t
    childTkProcess exit
    bind all <FocusIn> {}
    bind all <FocusOut> {}
} -result {{.t.f2.e1 {} {focus out .t.f2.e1 NotifyNonlinear} {focus out .t.f2 NotifyNonlinearVirtual} {focus in .t.f1 NotifyNonlinear} | {focus out .t.f1 NotifyNonlinear} {focus in .t.f2 NotifyNonlinearVirtual} {focus in .t.f2.e1 NotifyNonlinear}} {{focus in . NotifyVirtual} {focus in .e1 NotifyAncestor} | {focus out .e1 NotifyAncestor} {focus out . NotifyVirtual}}}

test focus-7.1 {TkSetFocusWin procedure, unmapped windows} -setup {
    # TkSetFocusWin handles the case of not yet mapped windows
    # by not setting the focus on them right at the time it is
795
796
797
798
799
800
801
802
803


804


805
806
807
808
809
	update
	focus -force .l;  # This line segfaulted *with xvfb*
	set res Reached
    }
    crashit
} -result {Reached}

deleteWindows



# cleanup


cleanupTests
if {[tk windowingsystem] eq "aqua"} {
    interp delete childInterp
}
return







<
|
>
>
|
>
>





795
796
797
798
799
800
801

802
803
804
805
806
807
808
809
810
811
812
	update
	focus -force .l;  # This line segfaulted *with xvfb*
	set res Reached
    }
    crashit
} -result {Reached}


#
# CLEANUP
#

deleteWindows
testutils forget child
cleanupTests
if {[tk windowingsystem] eq "aqua"} {
    interp delete childInterp
}
return
Changes to tests/fontchooser.test.
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
# Test the "tk::fontchooser" command
#
# Copyright © 2008 Pat Thoyts

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

# the following helper functions are related to the functions used
# in winDialog.test where they are used to send messages to the win32
# dialog (hence the weirdness).

proc start {cmd} {
    set ::tk_dialog {}
    set ::iter_after 0
    after 1 $cmd
}
proc then {cmd} {
    set ::command $cmd
    set ::dialogresult {}
    set ::testfont {}
    afterbody
    vwait ::dialogresult
    return $::dialogresult
}
proc afterbody {} {
    if {$::tk_dialog == {}} {
	if {[incr ::iter_after] > 30} {
	    set ::dialogresult ">30 iterations waiting for tk_dialog"
	    return
	}
	after 150 {afterbody}
	return
    }
    uplevel #0 {set dialogresult [eval $command]}
}
proc Click {button} {
    switch -exact -- $button {
	ok { $::tk_dialog.ok invoke }
	cancel { $::tk_dialog.cancel invoke }
	apply { $::tk_dialog.apply invoke }
	default { return -code error "invalid button name \"$button\"" }
    }
}
proc ApplyFont {font} {
#    puts stderr "apply: $font"
    set ::testfont $font
}

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

test fontchooser-1.1 {tk fontchooser: usage} -returnCodes error -body {
    tk fontchooser -z
} -result {unknown or ambiguous subcommand "-z": must be configure, hide, or show}









<
<
<
|
<
|
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
<
<







1
2
3
4
5
6
7
8



9

10


11



























12



13
14
15
16
17
18
19
# Test the "tk::fontchooser" command
#
# Copyright © 2008 Pat Thoyts

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




# Import utility procs for specific functional areas

testutils import dialog






























set applyFontCmd [list set testDialogFont]




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

test fontchooser-1.1 {tk fontchooser: usage} -returnCodes error -body {
    tk fontchooser -z
} -result {unknown or ambiguous subcommand "-z": must be configure, hide, or show}

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
# implementation. They can be tested by sourcing the script file but
# the Tk tests are run with -singleproc 1 and doing this affects the
# result of later attempts to test the native implementations.
#
testConstraint scriptImpl [llength [info proc ::tk::fontchooser::Configure]]

test fontchooser-2.0 {fontchooser -title} -constraints scriptImpl -body {
    start {
	tk::fontchooser::Configure -title "Hello"
	tk::fontchooser::Show
    }
    then {
	set x [wm title $::tk_dialog]
	Click cancel
    }
    set x
} -result {Hello}

test fontchooser-2.1 {fontchooser -title (cyrillic)} -constraints scriptImpl -body {
    start {
	tk::fontchooser::Configure \
	    -title "Привет"
	tk::fontchooser::Show
    }
    then {
	set x [wm title $::tk_dialog]
	Click cancel
    }
    set x
} -result "Привет"

test fontchooser-3.0 {fontchooser -parent} -constraints scriptImpl -body {
    start {
	tk::fontchooser::Configure -parent .
	tk::fontchooser::Show
    }
    then {
	set x [winfo parent $::tk_dialog]
	Click cancel
    }
    set x
} -result {.}

test fontchooser-3.1 {fontchooser -parent (invalid)} -constraints scriptImpl -body {
    tk::fontchooser::Configure -parent junk
} -returnCodes error -match glob -result {bad window path *}

test fontchooser-4.0 {fontchooser -font} -constraints scriptImpl -body {
    start {
	tk::fontchooser::Configure -command ApplyFont -font courier
	tk::fontchooser::Show
    }
    then {
	Click cancel
    }
    set ::testfont
} -result {}

test fontchooser-4.1 {fontchooser -font} -constraints scriptImpl -body {
    start {
	tk::fontchooser::Configure -command ApplyFont -font courier
	tk::fontchooser::Show
    }
    then {
	Click ok
    }
    expr {$::testfont ne {}}
} -result 1

test fontchooser-4.2 {fontchooser -font} -constraints scriptImpl -body {
    start {
	tk::fontchooser::Configure -command ApplyFont -font TkDefaultFont
	tk::fontchooser::Show
    }
    then {
	Click ok
    }
    expr {$::testfont ne {}}
} -result 1

test fontchooser-4.3 {fontchooser -font} -constraints scriptImpl -body {
    start {
	tk::fontchooser::Configure -command ApplyFont -font {times 14 bold}
	tk::fontchooser::Show
    }
    then {
	Click ok
    }
    expr {$::testfont ne {}}
} -result 1

test fontchooser-4.4 {fontchooser -font} -constraints {scriptImpl havePointsize14BoldFont} -body {
    start {
	tk::fontchooser::Configure -command ApplyFont -font {times 14 bold}
	tk::fontchooser::Show
    }
    then {
	Click ok
    }
    lrange $::testfont 1 end
} -result {14 bold}

test fontchooser-5.1 {fontchooser multiple configure} -constraints {scriptImpl} -body {
    tk fontchooser configure -title TestTitle -command foo
    tk fontchooser configure -command bar
    tk fontchooser configure -title
} -result {TestTitle}

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






cleanupTests
return

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







|



|
|






|




|
|






|



|
|










|
|


|


|



|
|


|


|



|
|


|


|



|
|


|


|



|
|


|


|








<
|
>
>
>
>
>







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
# implementation. They can be tested by sourcing the script file but
# the Tk tests are run with -singleproc 1 and doing this affects the
# result of later attempts to test the native implementations.
#
testConstraint scriptImpl [llength [info proc ::tk::fontchooser::Configure]]

test fontchooser-2.0 {fontchooser -title} -constraints scriptImpl -body {
    testDialog launch {
	tk::fontchooser::Configure -title "Hello"
	tk::fontchooser::Show
    }
    testDialog onDisplay {
	set x [wm title $testDialog]
	Click cancel
    }
    set x
} -result {Hello}

test fontchooser-2.1 {fontchooser -title (cyrillic)} -constraints scriptImpl -body {
    testDialog launch {
	tk::fontchooser::Configure \
	    -title "Привет"
	tk::fontchooser::Show
    }
    testDialog onDisplay {
	set x [wm title $testDialog]
	Click cancel
    }
    set x
} -result "Привет"

test fontchooser-3.0 {fontchooser -parent} -constraints scriptImpl -body {
    testDialog launch {
	tk::fontchooser::Configure -parent .
	tk::fontchooser::Show
    }
    testDialog onDisplay {
	set x [winfo parent $testDialog]
	Click cancel
    }
    set x
} -result {.}

test fontchooser-3.1 {fontchooser -parent (invalid)} -constraints scriptImpl -body {
    tk::fontchooser::Configure -parent junk
} -returnCodes error -match glob -result {bad window path *}

test fontchooser-4.0 {fontchooser -font} -constraints scriptImpl -body {
    testDialog launch {
	tk::fontchooser::Configure -command $applyFontCmd -font courier
	tk::fontchooser::Show
    }
    testDialog onDisplay {
	Click cancel
    }
    set testDialogFont
} -result {}

test fontchooser-4.1 {fontchooser -font} -constraints scriptImpl -body {
    testDialog launch {
	tk::fontchooser::Configure -command $applyFontCmd -font courier
	tk::fontchooser::Show
    }
    testDialog onDisplay {
	Click ok
    }
    expr {$testDialogFont ne {}}
} -result 1

test fontchooser-4.2 {fontchooser -font} -constraints scriptImpl -body {
    testDialog launch {
	tk::fontchooser::Configure -command $applyFontCmd -font TkDefaultFont
	tk::fontchooser::Show
    }
    testDialog onDisplay {
	Click ok
    }
    expr {$testDialogFont ne {}}
} -result 1

test fontchooser-4.3 {fontchooser -font} -constraints scriptImpl -body {
    testDialog launch {
	tk::fontchooser::Configure -command $applyFontCmd -font {times 14 bold}
	tk::fontchooser::Show
    }
    testDialog onDisplay {
	Click ok
    }
    expr {$testDialogFont ne {}}
} -result 1

test fontchooser-4.4 {fontchooser -font} -constraints {scriptImpl havePointsize14BoldFont} -body {
    testDialog launch {
	tk::fontchooser::Configure -command $applyFontCmd -font {times 14 bold}
	tk::fontchooser::Show
    }
    testDialog onDisplay {
	Click ok
    }
    lrange $testDialogFont 1 end
} -result {14 bold}

test fontchooser-5.1 {fontchooser multiple configure} -constraints {scriptImpl} -body {
    tk fontchooser configure -title TestTitle -command foo
    tk fontchooser configure -command bar
    tk fontchooser configure -title
} -result {TestTitle}


#
# CLEANUP
#

unset applyFontCmd
testutils forget dialog
cleanupTests
return

# Local Variables:
# mode: tcl
# indent-tabs-mode: nil
# End:
Changes to tests/frame.test.
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
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
tcltest::configure {*}$argv
tcltest::loadTestedCommands

tcltest::testConstraint x11 [expr {[tk windowingsystem] eq "x11"}]

# eatColors --
# Creates a toplevel window and allocates enough colors in it to use up all
# the slots in an 8-bit colormap.
#
# Arguments:
# w -		Name of toplevel window to create.

proc eatColors {w} {
    catch {destroy $w}
    toplevel $w
    wm geom $w +0+0
    canvas $w.c -width 400 -height 200 -bd 0
    pack $w.c
    for {set y 0} {$y < 8} {incr y} {
	for {set x 0} {$x < 40} {incr x} {
	    set color [format #%02x%02x%02x [expr {$x*6}] [expr {$y*30}] 0]
	    $w.c create rectangle [expr {10*$x}] [expr {20*$y}] \
		[expr {10*$x + 10}] [expr {20*$y + 20}] -outline {} \
		-fill $color
	}
    }
    update
}

# colorsFree --
#
# Returns 1 if there appear to be free colormap entries in a window, 0
# otherwise.
#
# Arguments:
# w -			Name of window in which to check.
# red, green, blue -	Intensities to use in a trial color allocation
#			to see if there are colormap entries free.

proc colorsFree {w {red 31} {green 245} {blue 192}} {
    lassign [winfo rgb $w [format "#%02x%02x%02x" $red $green $blue]] r g b
    expr {($r/256 == $red) && ($g/256 == $green) && ($b/256 == $blue)}
}

# uniq --
#
# Returns the unique items of a list in the order they first appear.
#
# Arguments:
# list -		The list to uniq-ify.







<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<







8
9
10
11
12
13
14

15
























16













17
18
19
20
21
22
23
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
tcltest::configure {*}$argv
tcltest::loadTestedCommands


# Import utility procs for specific functional areas
























testutils import colors














# uniq --
#
# Returns the unique items of a list in the order they first appear.
#
# Arguments:
# list -		The list to uniq-ify.
1763
1764
1765
1766
1767
1768
1769
1770



1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
   }
    after cancel $timer
    return [uniq $result]
} -cleanup {
    deleteWindows
    catch {image delete gorp}
} -result {{gorp get} {gorp display 0 0 30 15} {gorp display 0 0 30 10} {gorp display 0 0 20 15} {gorp display 0 0 20 10}}




# cleanup
deleteWindows
apply {cmds {foreach cmd $cmds {rename $cmd {}}}} {
    eatColors colorsFree uniq optnames
}

cleanupTests
return

# Local Variables:
# mode: tcl
# End:







|
>
>
>
|


|

|






1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
   }
    after cancel $timer
    return [uniq $result]
} -cleanup {
    deleteWindows
    catch {image delete gorp}
} -result {{gorp get} {gorp display 0 0 30 15} {gorp display 0 0 30 10} {gorp display 0 0 20 15} {gorp display 0 0 20 10}}

#
# CLEANUP
#

deleteWindows
apply {cmds {foreach cmd $cmds {rename $cmd {}}}} {
    uniq optnames
}
testutils forget colors
cleanupTests
return

# Local Variables:
# mode: tcl
# End:
Changes to tests/geometry.test.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# This file is a Tcl script to test the procedures in the file
# tkGeometry.c (generic support for geometry managers).  It is
# organized in the standard fashion for Tcl tests.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

proc getsize w {
    regexp {(^[^+-]*)} [wm geometry $w] foo x
    return $x
}

package require tcltest 2.2
eval tcltest::configure $argv
tcltest::loadTestedCommands
namespace import -force tcltest::test


wm geometry . 300x300









<
<
<
<
<







1
2
3
4
5
6
7
8
9





10
11
12
13
14
15
16
# This file is a Tcl script to test the procedures in the file
# tkGeometry.c (generic support for geometry managers).  It is
# organized in the standard fashion for Tcl tests.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.






package require tcltest 2.2
eval tcltest::configure $argv
tcltest::loadTestedCommands
namespace import -force tcltest::test


wm geometry . 300x300
Changes to tests/image.test.
8
9
10
11
12
13
14



15
16
17
18
19
20
21
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands




imageInit

# Canvas used in some tests in the whole file
canvas .c -highlightthickness 2
pack .c
update








>
>
>







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands

# Import utility procs for specific functional areas
testutils import image

imageInit

# Canvas used in some tests in the whole file
canvas .c -highlightthickness 2
pack .c
update

580
581
582
583
584
585
586




587
588
589
590
591
592
593
594
595
596
597
    lappend x [imageNames]
    image create photo foo -width 20 -height 20
    lappend x [.c bbox i1] [imageNames]
} -cleanup {
    .c delete all
    imageCleanup
} -result {10 10 20 20 foo {} {10 10 30 30} foo}





destroy .c
imageFinish

# cleanup
cleanupTests
return

# Local variables:
# mode: tcl
# End:







>
>
>
>



|
<






583
584
585
586
587
588
589
590
591
592
593
594
595
596
597

598
599
600
601
602
603
    lappend x [imageNames]
    image create photo foo -width 20 -height 20
    lappend x [.c bbox i1] [imageNames]
} -cleanup {
    .c delete all
    imageCleanup
} -result {10 10 20 20 foo {} {10 10 30 30} foo}

#
# CLEANUP
#

destroy .c
imageFinish
testutils forget image

cleanupTests
return

# Local variables:
# mode: tcl
# End:
Changes to tests/imgBmap.test.
1
2
3
4
5
6
7
8
9
10
11
12
13




14
15
16
17
18
19
20
# This file is a Tcl script to test out images of type "bitmap" (i.e.,
# the procedures in the file tkImgBmap.c).  It is organized in the
# standard fashion for Tcl tests.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994-1995 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands




imageInit

set data1 {#define foo_width 16
#define foo_height 16
#define foo_x_hot 3
#define foo_y_hot 3
static unsigned char foo_bits[] = {













>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# This file is a Tcl script to test out images of type "bitmap" (i.e.,
# the procedures in the file tkImgBmap.c).  It is organized in the
# standard fashion for Tcl tests.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994-1995 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands

# Import utility procs for specific functional areas
testutils import image

imageInit

set data1 {#define foo_width 16
#define foo_height 16
#define foo_x_hot 3
#define foo_y_hot 3
static unsigned char foo_bits[] = {
501
502
503
504
505
506
507




508
509
510
511
512
513
514
515
516
517
518
519
520


test imageBmap-12.1 {ImgBmapCmdDeletedProc procedure} -body {
    image create bitmap i2 -file foo.bm -maskfile foo2.bm
    rename i2 {}
    list [expr {"i2" in [imageNames]}] [catch {i2 foo} msg] $msg
} -result {0 1 {invalid command name "i2"}}





removeFile foo.bm
removeFile foo2.bm
imageFinish

# cleanup
cleanupTests
return

# Local Variables:
# mode: tcl
# fill-column: 78
# End:







>
>
>
>




|
<







505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520

521
522
523
524
525
526
527


test imageBmap-12.1 {ImgBmapCmdDeletedProc procedure} -body {
    image create bitmap i2 -file foo.bm -maskfile foo2.bm
    rename i2 {}
    list [expr {"i2" in [imageNames]}] [catch {i2 foo} msg] $msg
} -result {0 1 {invalid command name "i2"}}

#
# CLEANUP
#

removeFile foo.bm
removeFile foo2.bm
imageFinish
testutils forget image

cleanupTests
return

# Local Variables:
# mode: tcl
# fill-column: 78
# End:
Changes to tests/imgListFormat.test.
8
9
10
11
12
13
14



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Author: Simon Bachmann ([email protected])

package require tcltest 2.2
namespace import ::tcltest::*
tcltest::configure {*}$argv
tcltest::loadTestedCommands




imageInit

set teapotPhotoFile [file join [file dirname [info script]] teapot.ppm]
set transpTeapotPhotoFile [file join [file dirname [info script]] teapotTransparent.png]

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


test imgListFormat-1.1 {ParseFormatOptions: default values} -setup {
    image create photo photo1
} -body {
    photo1 put {{red green} {blue black}}
    lindex [photo1 data] 1 1
} -cleanup {
    imageCleanup







>
>
>







|







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
# Author: Simon Bachmann ([email protected])

package require tcltest 2.2
namespace import ::tcltest::*
tcltest::configure {*}$argv
tcltest::loadTestedCommands

# Import utility procs for specific functional areas
testutils import image

imageInit

set teapotPhotoFile [file join [file dirname [info script]] teapot.ppm]
set transpTeapotPhotoFile [file join [file dirname [info script]] teapotTransparent.png]

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


test imgListFormat-1.1 {ParseFormatOptions: default values} -setup {
    image create photo photo1
} -body {
    photo1 put {{red green} {blue black}}
    lindex [photo1 data] 1 1
} -cleanup {
    imageCleanup
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
    lappend result [photo1 data -format {default -colorformat rgba}]
    lappend result [photo1 data -format {default -colorformat list}]
    set result
} -cleanup {
    imageCleanup
    unset result
} -result {{{#ffffff}} {{#ffffff78}} {{{255 255 255 120}}}}

# GetBadOptMsg: only use case already tested with imgListFormat-1.4

test imgListFormat-3.1 {StringMatchDef: data is not a list} -body {
    testphotostringmatch {not a " proper list}
    # " (this comment is here only for editor highlighting)
} -returnCodes error -result {unmatched open quote in list}
# empty data case tested with imgPhoto-4.95 (imgPhoto.test)
test imgListFormat-3.2 {StringMatchDef: \
	list element not a proper list} -body {







|

|







102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
    lappend result [photo1 data -format {default -colorformat rgba}]
    lappend result [photo1 data -format {default -colorformat list}]
    set result
} -cleanup {
    imageCleanup
    unset result
} -result {{{#ffffff}} {{#ffffff78}} {{{255 255 255 120}}}}

# GetBadOptMsg: only use case already tested with imgListFormat-1.4

test imgListFormat-3.1 {StringMatchDef: data is not a list} -body {
    testphotostringmatch {not a " proper list}
    # " (this comment is here only for editor highlighting)
} -returnCodes error -result {unmatched open quote in list}
# empty data case tested with imgPhoto-4.95 (imgPhoto.test)
test imgListFormat-3.2 {StringMatchDef: \
	list element not a proper list} -body {
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
		{yellow magenta}
		{#000000 #FFFFFFFF}}
    list [image width photo1] [image height photo1] \
	[photo1 get 0 2 -withalpha]
} -cleanup {
    imageCleanup
} -result {2 3 {0 0 0 255}}

# ImgStringRead: most of the error cases cannot be tested with current code,
# as the errors are detected by StringMatchDef
test imgListFormat-4.1 {StringReadDef: use with -format opt} -setup {
    image create photo photo1
} -body {
    photo1 put white -format "default"
    photo1 get 0 0







|







146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
		{yellow magenta}
		{#000000 #FFFFFFFF}}
    list [image width photo1] [image height photo1] \
	[photo1 get 0 2 -withalpha]
} -cleanup {
    imageCleanup
} -result {2 3 {0 0 0 255}}

# ImgStringRead: most of the error cases cannot be tested with current code,
# as the errors are detected by StringMatchDef
test imgListFormat-4.1 {StringReadDef: use with -format opt} -setup {
    image create photo photo1
} -body {
    photo1 put white -format "default"
    photo1 get 0 0
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
    photo2 put #FF0000 -to 0 0 50 50
    photo2 put [photo1 data -format {default -colorformat rgba}] -to 10 10 40 40
    list [photo2 get 0 0 -withalpha] [photo2 get 20 25 -withalpha] \
	[photo2 get 49 49 -withalpha]
} -cleanup {
    imageCleanup
} -result {{255 0 0 255} {0 78 185 225} {255 0 0 255}}

test imgListFormat-5.1 {StringWriteDef: format options not a list} -setup {
    image create photo photo1
} -body {
    photo1 data -format {default " bogus}
    # "
} -cleanup {
    imageCleanup







|







192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
    photo2 put #FF0000 -to 0 0 50 50
    photo2 put [photo1 data -format {default -colorformat rgba}] -to 10 10 40 40
    list [photo2 get 0 0 -withalpha] [photo2 get 20 25 -withalpha] \
	[photo2 get 49 49 -withalpha]
} -cleanup {
    imageCleanup
} -result {{255 0 0 255} {0 78 185 225} {255 0 0 255}}

test imgListFormat-5.1 {StringWriteDef: format options not a list} -setup {
    image create photo photo1
} -body {
    photo1 data -format {default " bogus}
    # "
} -cleanup {
    imageCleanup
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
    lappend result [lindex $imgData 203 157]
    set result
} -cleanup {
    unset imgData
    unset result
    imageCleanup
} -result {{0 78 185 225} {161 65 0 170} {255 202 159 175}}

test imgListFormat-6.1 {ParseColor: empty string} -setup {
    image create photo photo1
    set result {}
} -body {
    photo1 put {{"" ""} {"" ""}}
    lappend result [image width photo1]
    lappend result [image height photo1]







|







307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
    lappend result [lindex $imgData 203 157]
    set result
} -cleanup {
    unset imgData
    unset result
    imageCleanup
} -result {{0 78 185 225} {161 65 0 170} {255 202 159 175}}

test imgListFormat-6.1 {ParseColor: empty string} -setup {
    image create photo photo1
    set result {}
} -body {
    photo1 put {{"" ""} {"" ""}}
    lappend result [image width photo1]
    lappend result [image height photo1]
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
    unset result
} -result \
{{255 250 250 128} {255 250 250 128} {255 250 250 136} {255 250 250 128}\
{255 250 250 136} {255 250 250 128} {255 250 250 128} {255 250 250 136}\
{255 250 250 128} {255 238 238 136} {255 238 238 128} {255 238 238 128}\
{255 250 250 128} {255 250 250 136} {255 250 250 128} {255 250 250 128}\
{255 250 250 255} {255 238 238 136} {255 250 250 128} {255 250 250 255}}

# Note: these tests were written for an earlier implementation of
# ParseColorAsList. For this reason, their order and layout do not follow the
# current code very well. Test coverage is pretty good, nevertheless.
test imgListFormat-7.1 {ParseColorAsList: invalid list} -setup {
    image create photo photo1
} -body {
    photo1 put {{{123 45 67 89} {123 45 " 67}}}







|







396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
    unset result
} -result \
{{255 250 250 128} {255 250 250 128} {255 250 250 136} {255 250 250 128}\
{255 250 250 136} {255 250 250 128} {255 250 250 128} {255 250 250 136}\
{255 250 250 128} {255 238 238 136} {255 238 238 128} {255 238 238 128}\
{255 250 250 128} {255 250 250 136} {255 250 250 128} {255 250 250 128}\
{255 250 250 255} {255 238 238 136} {255 250 250 128} {255 250 250 255}}

# Note: these tests were written for an earlier implementation of
# ParseColorAsList. For this reason, their order and layout do not follow the
# current code very well. Test coverage is pretty good, nevertheless.
test imgListFormat-7.1 {ParseColorAsList: invalid list} -setup {
    image create photo photo1
} -body {
    photo1 put {{{123 45 67 89} {123 45 " 67}}}
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
	image create photo photo1
} -body {
	photo1 put {{"111 222 33 44"}}
	photo1 get 0 0 -withalpha
} -cleanup {
	imageCleanup
} -result {111 222 33 44}

test imgListFormat-8.1 {ParseColorAsHex: RGB format} -setup {
    image create photo photo1
} -body {
    photo1 put {{#010 #001100}}
    photo1 data
} -cleanup {
    imageCleanup







|







475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
	image create photo photo1
} -body {
	photo1 put {{"111 222 33 44"}}
	photo1 get 0 0 -withalpha
} -cleanup {
	imageCleanup
} -result {111 222 33 44}

test imgListFormat-8.1 {ParseColorAsHex: RGB format} -setup {
    image create photo photo1
} -body {
    photo1 put {{#010 #001100}}
    photo1 data
} -cleanup {
    imageCleanup
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
    image create photo photo1
} -body {
    photo1 put {{#9bd5020d #7acF}}
    list [photo1 get 0 0 -withalpha] [photo1 get 1 0 -withalpha]
} -cleanup {
    imageCleanup
} -result {{155 213 2 13} {119 170 204 255}}

test imgListFormat-9.1 {ParseColorAsStandard:
	Tk color, valid suffixes} -setup {
    image create photo photo1
    set result {}
} -body {
    photo1 put {{[email protected] #114433#C} {#8D4#1A magenta}}
    lappend result [photo1 get 0 0 -withalpha]







|







507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
    image create photo photo1
} -body {
    photo1 put {{#9bd5020d #7acF}}
    list [photo1 get 0 0 -withalpha] [photo1 get 1 0 -withalpha]
} -cleanup {
    imageCleanup
} -result {{155 213 2 13} {119 170 204 255}}

test imgListFormat-9.1 {ParseColorAsStandard:
	Tk color, valid suffixes} -setup {
    image create photo photo1
    set result {}
} -body {
    photo1 put {{[email protected] #114433#C} {#8D4#1A magenta}}
    lappend result [photo1 get 0 0 -withalpha]
629
630
631
632
633
634
635
636
637
638

639
640
641
642
643
    image create photo photo1
} -body {
    photo1 put {#1111 #1111#1}
} -cleanup {
    imageCleanup
} -returnCodes error -result {invalid color name "#1111#1"}


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


imageFinish

# cleanup
cleanupTests
return







|
|
|
>

|
<


632
633
634
635
636
637
638
639
640
641
642
643
644

645
646
    image create photo photo1
} -body {
    photo1 put {#1111 #1111#1}
} -cleanup {
    imageCleanup
} -returnCodes error -result {invalid color name "#1111#1"}

#
# CLEANUP
#

imageFinish
testutils forget image

cleanupTests
return
Changes to tests/imgPNG.test.
8
9
10
11
12
13
14




15
16
17
18
19
20
21
# Copyright © 2008 Donal K. Fellows
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands




imageInit

namespace eval png {
    variable encoded
    # Key names are from the names of the source images, which come from
    #    http://www.schaik.com/pngsuite/pngsuite.html
    # The exception is "BadX", which is used to test handling badly compressed







>
>
>
>







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# Copyright © 2008 Donal K. Fellows
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands

# Import utility procs for specific functional areas
testutils import image

imageInit

namespace eval png {
    variable encoded
    # Key names are from the names of the source images, which come from
    #    http://www.schaik.com/pngsuite/pngsuite.html
    # The exception is "BadX", which is used to test handling badly compressed
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
fBcxKuQMrzfLdBoz29fX9led5v6u1XnBJW7vnr/YlrXEoNo22LRYOYlxZ1S6rkOfDcLvPAY/hGmWC7
H68uFI+x0oSPg2MAN/L5/M/vtqSED/T5cMu9J4Wf7HMGsB/4TEv/DFwe3Y/NPN57VXh+5BWApwFLlh
r661tV1eju/ne8YJrkWtES0tmRe2VOviv2j2aBp5nHihiRaz/A4oCnsAsje/+AAAAAElFTkSuQmCC"
    dpi100aspect2
"iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIAAAD91JpzAAAACXBIWXMAAA9hAAAewgEw8YEEAAAA
FklEQVR4nGP4+vXrP11lJgYGhj9xSQAzOwXsETZ69QAAAABJRU5ErkJggg=="
	}

# $encoded(basn0g08), $encoded(basn2c08), $encoded(basn3p08), $encoded(basn6a08)
test imgPNG-1.1 {reading basic images; grayscale} -setup {
    catch {rename foo ""}
} -body {
    image create photo foo -data $encoded(basn0g08)
    list [image width foo] [image height foo]
} -cleanup {







|







1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
fBcxKuQMrzfLdBoz29fX9led5v6u1XnBJW7vnr/YlrXEoNo22LRYOYlxZ1S6rkOfDcLvPAY/hGmWC7
H68uFI+x0oSPg2MAN/L5/M/vtqSED/T5cMu9J4Wf7HMGsB/4TEv/DFwe3Y/NPN57VXh+5BWApwFLlh
r661tV1eju/ne8YJrkWtES0tmRe2VOviv2j2aBp5nHihiRaz/A4oCnsAsje/+AAAAAElFTkSuQmCC"
    dpi100aspect2
"iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIAAAD91JpzAAAACXBIWXMAAA9hAAAewgEw8YEEAAAA
FklEQVR4nGP4+vXrP11lJgYGhj9xSQAzOwXsETZ69QAAAABJRU5ErkJggg=="
	}

# $encoded(basn0g08), $encoded(basn2c08), $encoded(basn3p08), $encoded(basn6a08)
test imgPNG-1.1 {reading basic images; grayscale} -setup {
    catch {rename foo ""}
} -body {
    image create photo foo -data $encoded(basn0g08)
    list [image width foo] [image height foo]
} -cleanup {
1159
1160
1161
1162
1163
1164
1165




1166
1167
1168

1169
1170
1171
1172
1173
1174
1175
    i1 cget -metadata
} -cleanup {
    image delete i1
    file delete $path
} -result {DPI 99.9998 aspect 2.0}

}





namespace delete png
imageFinish

cleanupTests
return

# Local Variables:
# mode: tcl
# fill-column: 78
# End:







>
>
>
>



>







1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
    i1 cget -metadata
} -cleanup {
    image delete i1
    file delete $path
} -result {DPI 99.9998 aspect 2.0}

}

#
# CLEANUP
#

namespace delete png
imageFinish
testutils forget image
cleanupTests
return

# Local Variables:
# mode: tcl
# fill-column: 78
# End:
Changes to tests/imgPPM.test.
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
# This file is a Tcl script to test out the code in tkImgFmtPPM.c,
# which reads and write PPM-format image files for photo widgets.
# The files is organized in the standard fashion for Tcl tests.
#
# Copyright © 1994-1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands




imageInit

# Note that we do not use [tcltest::makeFile] because it is
# only suitable for text files
proc put {file data} {
    set f [open $file w]
    fconfigure $f -translation lf
    puts -nonewline $f $data
    close $f
}

test imgPPM-1.1 {FileReadPPM procedure} -body {
    put test.ppm "P6\n0 256\n255\nabcdef"
    image create photo p1 -file test.ppm
} -returnCodes error -result {PPM image file "test.ppm" has dimension(s) <= 0}
test imgPPM-1.2 {FileReadPPM procedure} -body {
    put test.ppm "P6\n-2 256\n255\nabcdef"
    image create photo p1 -file test.ppm













>
>
>










|







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
# This file is a Tcl script to test out the code in tkImgFmtPPM.c,
# which reads and write PPM-format image files for photo widgets.
# The files is organized in the standard fashion for Tcl tests.
#
# Copyright © 1994-1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands

# Import utility procs for specific functional areas
testutils import image

imageInit

# Note that we do not use [tcltest::makeFile] because it is
# only suitable for text files
proc put {file data} {
    set f [open $file w]
    fconfigure $f -translation lf
    puts -nonewline $f $data
    close $f
}

test imgPPM-1.1 {FileReadPPM procedure} -body {
    put test.ppm "P6\n0 256\n255\nabcdef"
    image create photo p1 -file test.ppm
} -returnCodes error -result {PPM image file "test.ppm" has dimension(s) <= 0}
test imgPPM-1.2 {FileReadPPM procedure} -body {
    put test.ppm "P6\n-2 256\n255\nabcdef"
    image create photo p1 -file test.ppm
221
222
223
224
225
226
227
228
229
230


231

232

233
234
235
236
237
238
    image create photo ppm
} -body {
    ppm put "P6\n5 4\n150\n012345678901234567890123456789012345678901234567890123456789"
    list [image width ppm] [image height ppm]
} -cleanup {
    image delete ppm
} -result {5 4}

imageFinish



# cleanup

catch {file delete test.ppm}

cleanupTests
return

# Local Variables:
# mode: tcl
# End:







|
<
|
>
>
|
>

>






224
225
226
227
228
229
230
231

232
233
234
235
236
237
238
239
240
241
242
243
244
    image create photo ppm
} -body {
    ppm put "P6\n5 4\n150\n012345678901234567890123456789012345678901234567890123456789"
    list [image width ppm] [image height ppm]
} -cleanup {
    image delete ppm
} -result {5 4}


#
# CLEANUP
#

imageFinish
catch {file delete test.ppm}
testutils forget image
cleanupTests
return

# Local Variables:
# mode: tcl
# End:
Changes to tests/imgPhoto.test.
75
76
77
78
79
80
81



82
83
84
85
86
87
88
#

package require tcltest 2.2
namespace import ::tcltest::*
tcltest::configure {*}$argv
tcltest::loadTestedCommands




#
# Used for imgPhoto-4.65 - imgPhoto-4.73
#
proc foreachPixel {img xVar yVar script} {
    upvar 1 $xVar x $yVar y
    set width [image width $img]
    set height [image height $img]







>
>
>







75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#

package require tcltest 2.2
namespace import ::tcltest::*
tcltest::configure {*}$argv
tcltest::loadTestedCommands

# Import utility procs for specific functional areas
testutils import image

#
# Used for imgPhoto-4.65 - imgPhoto-4.73
#
proc foreachPixel {img xVar yVar script} {
    upvar 1 $xVar x $yVar y
    set width [image width $img]
    set height [image height $img]
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
    photo1 get 1 0 -withalpha
} -cleanup {
    imageCleanup
} -result {0 128 0 255}
test imgPhoto-1.14 {options for photo images - error case} -body {
    image create photo photo1 -metadata
} -returnCodes error -result {value for "-metadata" missing}

test imgPhoto-2.1 {ImgPhotoCreate procedure} -setup {
    imageCleanup
} -body {
    catch {image create photo -blah blah}
    imageNames
} -result {}
test imgPhoto-2.2 {ImgPhotoCreate procedure} -setup {







|







189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
    photo1 get 1 0 -withalpha
} -cleanup {
    imageCleanup
} -result {0 128 0 255}
test imgPhoto-1.14 {options for photo images - error case} -body {
    image create photo photo1 -metadata
} -returnCodes error -result {value for "-metadata" missing}

test imgPhoto-2.1 {ImgPhotoCreate procedure} -setup {
    imageCleanup
} -body {
    catch {image create photo -blah blah}
    imageNames
} -result {}
test imgPhoto-2.2 {ImgPhotoCreate procedure} -setup {
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
    image create photo photo2
} -body {
    photo2 configure -data [photo1 data -from 80 90 100 110]
    list [image width photo2] [image height photo2]
} -cleanup {
    imageCleanup
} -result {20 20}

test imgPhoto-4.1 {ImgPhotoCmd procedure} -setup {
    image create photo photo1
} -body {
    photo1
} -returnCodes error -cleanup {
    image delete photo1
} -result {wrong # args: should be "photo1 option ?arg ...?"}







|







270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
    image create photo photo2
} -body {
    photo2 configure -data [photo1 data -from 80 90 100 110]
    list [image width photo2] [image height photo2]
} -cleanup {
    imageCleanup
} -result {20 20}

test imgPhoto-4.1 {ImgPhotoCmd procedure} -setup {
    image create photo photo1
} -body {
    photo1
} -returnCodes error -cleanup {
    image delete photo1
} -result {wrong # args: should be "photo1 option ?arg ...?"}
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
    }
    set result
} -cleanup {
    unset imgData
    unset result
    imageCleanup
} -result {}

test imgPhoto-5.1 {ImgPhotoGet/Free procedures, shared instances} -setup {
    destroy .c
    pack [canvas .c]
    imageCleanup
} -body {
    image create photo photo1 -file $teapotPhotoFile
    .c create image 0 0 -image photo1 -tags photo1.1







|







1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
    }
    set result
} -cleanup {
    unset imgData
    unset result
    imageCleanup
} -result {}

test imgPhoto-5.1 {ImgPhotoGet/Free procedures, shared instances} -setup {
    destroy .c
    pack [canvas .c]
    imageCleanup
} -body {
    image create photo photo1 -file $teapotPhotoFile
    .c create image 0 0 -image photo1 -tags photo1.1
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
} -body {
    photo1 read $f -format default
} -cleanup {
    imageCleanup
    catch {removeFile $f}
    unset f
} -returnCodes error -result {-file option isn't supported for default images}

test imgPhoto-19.1 {MatchStringFormat: with "-format default"} -setup {
    image create photo photo1
} -body {
    photo1 put {{red blue red} {yellow green yellow}} -format default
    list [image width photo1] [image height photo1]
} -cleanup {
    imageCleanup







|







1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
} -body {
    photo1 read $f -format default
} -cleanup {
    imageCleanup
    catch {removeFile $f}
    unset f
} -returnCodes error -result {-file option isn't supported for default images}

test imgPhoto-19.1 {MatchStringFormat: with "-format default"} -setup {
    image create photo photo1
} -body {
    photo1 put {{red blue red} {yellow green yellow}} -format default
    list [image width photo1] [image height photo1]
} -cleanup {
    imageCleanup
2695
2696
2697
2698
2699
2700
2701




2702
2703
2704
2705
2706

2707
2708
2709
2710
2711
2712
2713
2714
2715
    image create photo png1
    catch {png1 read $ousterPhotoFile -from 102 62 2000 1000} msg
    list $msg [image width png1] [image height png1]
} -cleanup {
    catch {image delete png1}
} -result {{coordinates for -from option extend outside source image} 0 0}
unset ousterPhotoFile





catch {rename foreachPixel {}}
catch {rename checkImgTrans {}}
catch {rename checkImgTransLoop {}}
imageFinish


# cleanup
removeFile README-imgPhoto
cleanupTests
return

# Local variables:
# mode: tcl
# End:







>
>
>
>





>

<
|






2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715

2716
2717
2718
2719
2720
2721
2722
    image create photo png1
    catch {png1 read $ousterPhotoFile -from 102 62 2000 1000} msg
    list $msg [image width png1] [image height png1]
} -cleanup {
    catch {image delete png1}
} -result {{coordinates for -from option extend outside source image} 0 0}
unset ousterPhotoFile

#
# CLEANUP
#

catch {rename foreachPixel {}}
catch {rename checkImgTrans {}}
catch {rename checkImgTransLoop {}}
imageFinish
removeFile README-imgPhoto


testutils forget image
cleanupTests
return

# Local variables:
# mode: tcl
# End:
Changes to tests/imgSVGnano.test.
1
2
3
4
5
6
7
8
9
10
11




12
13
14
15
16
17
18
# This file is a Tcl script to test out the code in tkImgSVGnano.c, which reads
# and write SVG-format image files for photo widgets. The files is organized
# in the standard fashion for Tcl tests.
#
# Copyright © 2018 Rene Zaumseil
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands




imageInit

namespace eval svgnano {

    variable data

    set data(plus) {\











>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# This file is a Tcl script to test out the code in tkImgSVGnano.c, which reads
# and write SVG-format image files for photo widgets. The files is organized
# in the standard fashion for Tcl tests.
#
# Copyright © 2018 Rene Zaumseil
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands

# Import utility procs for specific functional areas
testutils import image

imageInit

namespace eval svgnano {

    variable data

    set data(plus) {\
248
249
250
251
252
253
254




255
256
257

258
259
260
261
262
263
264
			</g></svg>}
} -returnCodes error -result {couldn't recognize image data}

    tcltest::removeFile plus.svg
    tcltest::removeFile bad.svg

};# end of namespace svgnano





namespace delete svgnano
imageFinish

cleanupTests
return

# Local Variables:
# mode: tcl
# fill-column: 78
# End:







>
>
>
>



>







252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
			</g></svg>}
} -returnCodes error -result {couldn't recognize image data}

    tcltest::removeFile plus.svg
    tcltest::removeFile bad.svg

};# end of namespace svgnano

#
# CLEANUP
#

namespace delete svgnano
imageFinish
testutils forget image
cleanupTests
return

# Local Variables:
# mode: tcl
# fill-column: 78
# End:
Changes to tests/listbox.test.
3205
3206
3207
3208
3209
3210
3211




3212
3213
3214
3215
3216
3217
3218
3219
    }}}
    pack .b
    bind .b <Configure> {unset -nocomplain var}
    update
    destroy .b
    unset new
} {}





resetGridInfo
deleteWindows
option clear

# cleanup
cleanupTests
return







>
>
>
>




|
<


3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220

3221
3222
    }}}
    pack .b
    bind .b <Configure> {unset -nocomplain var}
    update
    destroy .b
    unset new
} {}

#
# CLEANUP
#

resetGridInfo
deleteWindows
option clear
rename getsize {}

cleanupTests
return
Added tests/main.tcl.




































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
# main.tcl --
#
# This file is loaded by each test file when invoking "tcltest::loadTestedCommands".
# It performs an initial Tk setup for the root window, and loads, in turn,
# definitions of global utility procs and test constraints.
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.

#
# SETUP FOR APPLICATION AND ROOT WINDOW
#
if {[namespace exists tk::test]} {
    # reset windows
    deleteWindows
    wm geometry . {}
    raise .
    return
}

package require tk
tk appname tktest
wm title . tktest
# If the main window isn't already mapped (e.g. because the tests are
# being run automatically) , specify a precise size for it so that the
# user won't have to position it manually.

if {![winfo ismapped .]} {
    wm geometry . +0+0
    update
}

#
# LOAD AND CONFIGURE TEST HARNESS
#
package require tcltest 2.2
eval tcltest::configure $argv
namespace import -force tcltest::test
namespace import -force tcltest::makeFile
namespace import -force tcltest::removeFile
namespace import -force tcltest::makeDirectory
namespace import -force tcltest::removeDirectory
namespace import -force tcltest::interpreter
namespace import -force tcltest::testsDirectory
namespace import -force tcltest::cleanupTests

#
# SOURCE DEFINITIONS OF GLOBAL UTILITY PROCS AND CONSTRAINTS
#
# Note: tcltest uses [uplevel] to evaluate this script. Therefore, [info script]
#       cannot be used to determine the main Tk test directory, and we use
#       [tcltest::configure -loadfile] instead.
#
set mainTestDir [file dirname [tcltest::configure -loadfile]]
source [file join $mainTestDir testutils.tcl]
source [file join $mainTestDir constraints.tcl]
unset mainTestDir

#
# RESET WINDOWS
#
deleteWindows
wm geometry . {}
raise .

# EOF
Changes to tests/menu.test.
1
2
3
4
5
6
7
8
9
10
11




12
13
14
15
16
17
18
# This file is a Tcl script to test menus in Tk.  It is
# organized in the standard fashion for Tcl tests.
#
# Copyright © 1995-1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands




imageInit


test menu-1.1 {Tk_MenuCmd procedure} -body {
    menu
} -returnCodes error -result {wrong # args: should be "menu pathName ?-option value ...?"}
test menu-1.2 {Tk_MenuCmd procedure} -body {











>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# This file is a Tcl script to test menus in Tk.  It is
# organized in the standard fashion for Tcl tests.
#
# Copyright © 1995-1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands

# Import utility procs for specific functional areas
testutils import image

imageInit


test menu-1.1 {Tk_MenuCmd procedure} -body {
    menu
} -returnCodes error -result {wrong # args: should be "menu pathName ?-option value ...?"}
test menu-1.2 {Tk_MenuCmd procedure} -body {
4278
4279
4280
4281
4282
4283
4284



4285
4286
4287

4288
4289
4290
4291
4292
4293
    .m add command -label 2
    .m add command -label 3
    .m index last
} -cleanup {
    destroy .m
} -result {2}




# cleanup
imageFinish
deleteWindows

cleanupTests
return

# Local variables:
# mode: tcl
# End:







>
>
>
|


>






4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
    .m add command -label 2
    .m add command -label 3
    .m index last
} -cleanup {
    destroy .m
} -result {2}

#
# CLEANUP
#

imageFinish
deleteWindows
testutils forget image
cleanupTests
return

# Local variables:
# mode: tcl
# End:
Changes to tests/menuDraw.test.
1
2
3
4
5
6
7
8
9
10
11




12
13
14
15
16
17
18
# This file is a Tcl script to test drawing of menus in Tk.  It is
# organized in the standard fashion for Tcl tests.
#
# Copyright © 1996-1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
eval tcltest::configure $argv
tcltest::loadTestedCommands
namespace import -force tcltest::test




imageInit

test menuDraw-1.1 {TkMenuInitializeDrawingFields} -setup {
    deleteWindows
} -body {
    menu .m1
} -cleanup {











>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# This file is a Tcl script to test drawing of menus in Tk.  It is
# organized in the standard fashion for Tcl tests.
#
# Copyright © 1996-1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
eval tcltest::configure $argv
tcltest::loadTestedCommands
namespace import -force tcltest::test

# Import utility procs for specific functional areas
testutils import image

imageInit

test menuDraw-1.1 {TkMenuInitializeDrawingFields} -setup {
    deleteWindows
} -body {
    menu .m1
} -cleanup {
702
703
704
705
706
707
708



709
710
711

712
713
714
715
716
717
    .m2 add command -label "Hit ESCAPE to make this menu go away"
    set tearoff [tk::TearOffMenu .m1 40 40]
    $tearoff postcascade 0
} -cleanup {
    deleteWindows
} -result {}




# cleanup
imageFinish
deleteWindows

cleanupTests
return

# Local variables:
# mode: tcl
# End:







>
>
>
|


>






706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
    .m2 add command -label "Hit ESCAPE to make this menu go away"
    set tearoff [tk::TearOffMenu .m1 40 40]
    $tearoff postcascade 0
} -cleanup {
    deleteWindows
} -result {}

#
# CLEANUP
#

imageFinish
deleteWindows
testutils forget image
cleanupTests
return

# Local variables:
# mode: tcl
# End:
Changes to tests/menubut.test.
10
11
12
13
14
15
16




17
18
19
20
21
22
23
# XXX of a procedure has tests then the whole procedure has tests,
# XXX but many procedures have no tests.

package require tcltest 2.2
eval tcltest::configure $argv
tcltest::loadTestedCommands
namespace import -force tcltest::test




imageInit

# Create entries in the option database to be sure that geometry options
# like border width have predictable values.

option add *Menubutton.borderWidth 2
option add *Menubutton.highlightThickness 2







>
>
>
>







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# XXX of a procedure has tests then the whole procedure has tests,
# XXX but many procedures have no tests.

package require tcltest 2.2
eval tcltest::configure $argv
tcltest::loadTestedCommands
namespace import -force tcltest::test

# Import utility procs for specific functional areas
testutils import image

imageInit

# Create entries in the option database to be sure that geometry options
# like border width have predictable values.

option add *Menubutton.borderWidth 2
option add *Menubutton.highlightThickness 2
775
776
777
778
779
780
781
782

783
784
785
786
787
788
789
790
791
792
793
794
795
    pack .b
    bind .b <Configure> {unset -nocomplain var}
    update
    destroy .b
    unset new
} {}





deleteWindows
option clear
imageFinish

# cleanup
cleanupTests
return

# Local variables:
# mode: tcl
# End:







|
>
|





|






779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
    pack .b
    bind .b <Configure> {unset -nocomplain var}
    update
    destroy .b
    unset new
} {}

#
# CLEANUP
#

deleteWindows
option clear
imageFinish

testutils forget image
cleanupTests
return

# Local variables:
# mode: tcl
# End:
Changes to tests/msgbox.test.
1
2
3
4
5
6
7
8
9
10
11
12


13
14
15
16
17
18
19
# This file is a Tcl script to test out Tk's "tk_messageBox" command.
# It is organized in the standard fashion for Tcl tests.
#
# Copyright © 1996 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
eval tcltest::configure $argv
tcltest::loadTestedCommands
namespace import -force tcltest::test




test msgbox-1.1.1 {tk_messageBox command} -constraints notAqua -body {
    tk_messageBox -foo
} -returnCodes error -result {bad option "-foo": must be -default, -detail, -icon, -message, -parent, -title, or -type}
test msgbox-1.1.2 {tk_messageBox command} -constraints aqua -body {
    tk_messageBox -foo
} -returnCodes error -result {bad option "-foo": must be -default, -detail, -icon, -message, -parent, -title, -type, or -command}












>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# This file is a Tcl script to test out Tk's "tk_messageBox" command.
# It is organized in the standard fashion for Tcl tests.
#
# Copyright © 1996 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
eval tcltest::configure $argv
tcltest::loadTestedCommands
namespace import -force tcltest::test

# Import utility procs for specific functional areas
testutils import dialog

test msgbox-1.1.1 {tk_messageBox command} -constraints notAqua -body {
    tk_messageBox -foo
} -returnCodes error -result {bad option "-foo": must be -default, -detail, -icon, -message, -parent, -title, or -type}
test msgbox-1.1.2 {tk_messageBox command} -constraints aqua -body {
    tk_messageBox -foo
} -returnCodes error -result {bad option "-foo": must be -default, -detail, -icon, -message, -parent, -title, -type, or -command}
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
} -returnCodes error -result {bad -icon value "foo": must be error, info, question, or warning}

test msgbox-1.19 {tk_messageBox command} -body {
    tk_messageBox -parent foo.bar
} -returnCodes error -result {bad window path name "foo.bar"}


catch {tk_messageBox -foo bar}
set isNative [expr {[info commands tk::MessageBox] == ""}]

proc ChooseMsg {parent btn} {
    global isNative
    if {!$isNative} {
	after 100 SendEventToMsg $parent $btn mouse
    }
}

proc ChooseMsgByKey {parent btn} {
    global isNative
    if {!$isNative} {
	after 100 SendEventToMsg $parent $btn key
    }
}

proc PressButton {btn} {
    event generate $btn <Enter>
    event generate $btn <Button-1> -x 5 -y 5
    event generate $btn <ButtonRelease-1> -x 5 -y 5
}

proc SendEventToMsg {parent btn type} {
    if {$parent != "."} {
	set w $parent.__tk__messagebox
    } else {
	set w .__tk__messagebox
    }
    if ![winfo ismapped $w.$btn] {
	update
    }
    if {$type == "mouse"} {
	PressButton $w.$btn
    } else {
	event generate $w <Enter>
	focus $w
	event generate $w.$btn <Enter>
	event generate $w <Key> -keysym Return
    }
}
#
# Try out all combinations of (type) x (default button) and
# (type) x (icon).
#
test msgbox-2.1 {tk_messageBox command} -constraints {
    nonUnixUserInteraction
} -body {







<
<
<

<
|
|




<
|
|



<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







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
} -returnCodes error -result {bad -icon value "foo": must be error, info, question, or warning}

test msgbox-1.19 {tk_messageBox command} -body {
    tk_messageBox -parent foo.bar
} -returnCodes error -result {bad window path name "foo.bar"}





proc ChooseMsg {parent btn} {

    if {! $::dialogIsNative} {
	after 100 SendButtonPress $parent $btn mouse
    }
}

proc ChooseMsgByKey {parent btn} {

    if {! $::dialogIsNative} {
	after 100 SendButtonPress $parent $btn key
    }
}

























#
# Try out all combinations of (type) x (default button) and
# (type) x (icon).
#
test msgbox-2.1 {tk_messageBox command} -constraints {
    nonUnixUserInteraction
} -body {
436
437
438
439
440
441
442



443

444
445
446
447
    ChooseMsg . "ok"
    tk_messageBox -title Hi -message "Please press ok" \
	    -type ok -default ok
} -cleanup {
    wm deiconify .
} -result {ok}




# cleanup

cleanupTests
return









>
>
>
|
>


<
<
409
410
411
412
413
414
415
416
417
418
419
420
421
422


    ChooseMsg . "ok"
    tk_messageBox -title Hi -message "Please press ok" \
	    -type ok -default ok
} -cleanup {
    wm deiconify .
} -result {ok}

#
# CLEANUP
#

testutils forget dialog
cleanupTests
return


tests/option.file3 became a regular file.
Changes to tests/pack.test.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# This file is a Tcl script to test out the "pack" command of Tk.  It is
# organized in the standard fashion for Tcl tests.
#
# Copyright © 1993 The Regents of the University of California.
# Copyright © 1994 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
eval tcltest::configure $argv
tcltest::loadTestedCommands
namespace import -force tcltest::test

testConstraint failsOnUbuntu [expr {![info exists ::env(CI)] || ![string match Linux $::tcl_platform(os)]}]
testConstraint failsOnXQuarz [expr {$tcl_platform(os) ne "Darwin" || [tk windowingsystem] ne "x11" }]

# Create some test windows.

destroy .pack
toplevel .pack
wm geom .pack 300x200+0+0
wm minsize .pack 1 1
update idletasks













<
<
<







1
2
3
4
5
6
7
8
9
10
11
12
13



14
15
16
17
18
19
20
# This file is a Tcl script to test out the "pack" command of Tk.  It is
# organized in the standard fashion for Tcl tests.
#
# Copyright © 1993 The Regents of the University of California.
# Copyright © 1994 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
eval tcltest::configure $argv
tcltest::loadTestedCommands
namespace import -force tcltest::test




# Create some test windows.

destroy .pack
toplevel .pack
wm geom .pack 300x200+0+0
wm minsize .pack 1 1
update idletasks
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
    winfo manager .pack.a
    winfo geometry .pack.a
    pack info .pack.a
} -returnCodes error -result {window ".pack.a" isn't packed}

# Tests pack-18.1.1 and pack-18.2 are constrained with failsOnUbuntu
# because they are failing in the GitHub CI environment, using Linux Ubuntu.
# These tests are also constrained with failsOnXQuarz because they fail
# on macOS when building with clang --disable-aqua (which uses XQuartz)
# (this is the case both at GitHub CI and on a real Mac).
# Analysis shows that, on both cases, WaitForMapNotify is giving up on
# waiting for the MapNotify event that should show up when running
# 'wm iconify'. The timeout delay (2s) is exceeded without the unmapping
# having happened. The cause for this is unknown (see comments in WaitForMapNotify).








|







1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
    winfo manager .pack.a
    winfo geometry .pack.a
    pack info .pack.a
} -returnCodes error -result {window ".pack.a" isn't packed}

# Tests pack-18.1.1 and pack-18.2 are constrained with failsOnUbuntu
# because they are failing in the GitHub CI environment, using Linux Ubuntu.
# These tests are also constrained with failsOnXQuartz because they fail
# on macOS when building with clang --disable-aqua (which uses XQuartz)
# (this is the case both at GitHub CI and on a real Mac).
# Analysis shows that, on both cases, WaitForMapNotify is giving up on
# waiting for the MapNotify event that should show up when running
# 'wm iconify'. The timeout delay (2s) is exceeded without the unmapping
# having happened. The cause for this is unknown (see comments in WaitForMapNotify).

1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
# account on window remapping.
#
# While these tests pass on macOS, one can see by watching the tests
# that the window .pack is sometimes black, even though the frame is
# colored.  So, evidently, even though the size changes are honored,
# the window is sometimes not completely configured.
test pack-18.1.1 {unmap content when container unmapped} -constraints {
    macOrUnix failsOnUbuntu failsOnXQuarz
} -setup {
    destroy {*}[winfo children .pack]
    # adjust the position of .pack before test to avoid a screen switch
    # that occurs with window managers that have desktops four times as big
    # as the screen (screen switch causes scale and other tests to fail).
    wm geometry .pack +100+100
} -body {







|







1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
# account on window remapping.
#
# While these tests pass on macOS, one can see by watching the tests
# that the window .pack is sometimes black, even though the frame is
# colored.  So, evidently, even though the size changes are honored,
# the window is sometimes not completely configured.
test pack-18.1.1 {unmap content when container unmapped} -constraints {
    macOrUnix failsOnUbuntu failsOnXQuartz
} -setup {
    destroy {*}[winfo children .pack]
    # adjust the position of .pack before test to avoid a screen switch
    # that occurs with window managers that have desktops four times as big
    # as the screen (screen switch causes scale and other tests to fail).
    wm geometry .pack +100+100
} -body {
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
    update
    wm deiconify .pack
    update
    lappend result [winfo width .pack.a] [winfo height .pack.a]
    lappend result [winfo ismapped .pack.a]
} -result {1 0 200 75 1}

test pack-18.2 {unmap content when container unmapped} -constraints {failsOnUbuntu failsOnXQuarz} -setup {
    destroy {*}[winfo children .pack]
    # adjust the position of .pack before test to avoid a screen switch
    # that occurs with window managers that have desktops four times as big
    # as the screen (screen switch causes scale and other tests to fail).
    wm geometry .pack +100+100
} -body {
    frame .pack.a -relief raised -bd 2 -bg green







|







1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
    update
    wm deiconify .pack
    update
    lappend result [winfo width .pack.a] [winfo height .pack.a]
    lappend result [winfo ismapped .pack.a]
} -result {1 0 200 75 1}

test pack-18.2 {unmap content when container unmapped} -constraints {failsOnUbuntu failsOnXQuartz} -setup {
    destroy {*}[winfo children .pack]
    # adjust the position of .pack before test to avoid a screen switch
    # that occurs with window managers that have desktops four times as big
    # as the screen (screen switch causes scale and other tests to fail).
    wm geometry .pack +100+100
} -body {
    frame .pack.a -relief raised -bd 2 -bg green
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
    pack forget .1
    update
    info exists A
} -cleanup {
    bind . <<NoManagedChild>> {}
    destroy .1
} -result 0

# cleanup
cleanupTests
return

# Local Variables:
# mode: tcl
# End:







|







1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
    pack forget .1
    update
    info exists A
} -cleanup {
    bind . <<NoManagedChild>> {}
    destroy .1
} -result 0

# cleanup
cleanupTests
return

# Local Variables:
# mode: tcl
# End:
Changes to tests/place.test.
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands

# Used for constraining memory leak tests
testConstraint memory [llength [info commands memory]]

testConstraint failsOnUbuntu [expr {![info exists ::env(CI)] || ![string match Linux $::tcl_platform(os)]}]
testConstraint failsOnXQuarz [expr {$tcl_platform(os) ne "Darwin" || [tk windowingsystem] ne "x11" }]

# XXX - This test file is woefully incomplete.  At present, only a
# few of the features are tested.

# Widgets used in tests 1.* - 8.*
toplevel .t -width 300 -height 200 -bd 0
wm geom .t +0+0
frame .t.f -width 154 -height 84 -bd 2 -relief raised







<
<
<







9
10
11
12
13
14
15



16
17
18
19
20
21
22
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands

# Used for constraining memory leak tests
testConstraint memory [llength [info commands memory]]




# XXX - This test file is woefully incomplete.  At present, only a
# few of the features are tested.

# Widgets used in tests 1.* - 8.*
toplevel .t -width 300 -height 200 -bd 0
wm geom .t +0+0
frame .t.f -width 154 -height 84 -bd 2 -relief raised
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
    place .t.f2 -width {} -relwidth {} -height {} -relheight {}
    update
    list [winfo width .t.f2] [winfo height .t.f2]
} -result {30 60}

# Tests place-8.1 and place-8.2 are constrained with failsOnUbuntu
# because they are failing in the GitHub CI environment, using Linux Ubuntu.
# These tests are also constrained with failsOnXQuarz because they fail
# on macOS when building with clang --disable-aqua (which uses XQuartz)
# (this is the case both at GitHub CI and on a real Mac).
# Analysis shows that, on both cases, WaitForMapNotify is giving up on
# waiting for the MapNotify event that should show up when running
# 'wm iconify'. The timeout delay (2s) is exceeded without the unmapping
# having happened. The cause for this is unknown (see comments in WaitForMapNotify).

test place-8.1 {PlaceStructureProc, mapping and unmapping content} -constraints {failsOnUbuntu failsOnXQuarz} -setup {
    place forget .t.f2
    place forget .t.f
} -body {
    place .t.f2 -relx 1.0 -rely 1.0 -anchor sw
    update
    set result [winfo ismapped .t.f2]
    wm iconify .t
    lappend result [winfo ismapped .t.f2]
    place .t.f2 -x 40 -y 30 -relx 0 -rely 0 -anchor nw
    update
    lappend result [winfo x .t.f2] [winfo y .t.f2] [winfo ismapped .t.f2]
    wm deiconify .t
    update
    lappend result [winfo ismapped .t.f2]
} -result {1 0 40 30 0 1}
test place-8.2 {PlaceStructureProc, mapping and unmapping content} -constraints {failsOnUbuntu failsOnXQuarz} -setup {
    place forget .t.f2
    place forget .t.f
} -body {
    place .t.f -x 0 -y 0 -width 200 -height 100
    place .t.f2 -in .t.f -relx 1.0 -rely 1.0 -anchor sw -width 50 -height 20
    update
    set result [winfo ismapped .t.f2]







|







|















|







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
    place .t.f2 -width {} -relwidth {} -height {} -relheight {}
    update
    list [winfo width .t.f2] [winfo height .t.f2]
} -result {30 60}

# Tests place-8.1 and place-8.2 are constrained with failsOnUbuntu
# because they are failing in the GitHub CI environment, using Linux Ubuntu.
# These tests are also constrained with failsOnXQuartz because they fail
# on macOS when building with clang --disable-aqua (which uses XQuartz)
# (this is the case both at GitHub CI and on a real Mac).
# Analysis shows that, on both cases, WaitForMapNotify is giving up on
# waiting for the MapNotify event that should show up when running
# 'wm iconify'. The timeout delay (2s) is exceeded without the unmapping
# having happened. The cause for this is unknown (see comments in WaitForMapNotify).

test place-8.1 {PlaceStructureProc, mapping and unmapping content} -constraints {failsOnUbuntu failsOnXQuartz} -setup {
    place forget .t.f2
    place forget .t.f
} -body {
    place .t.f2 -relx 1.0 -rely 1.0 -anchor sw
    update
    set result [winfo ismapped .t.f2]
    wm iconify .t
    lappend result [winfo ismapped .t.f2]
    place .t.f2 -x 40 -y 30 -relx 0 -rely 0 -anchor nw
    update
    lappend result [winfo x .t.f2] [winfo y .t.f2] [winfo ismapped .t.f2]
    wm deiconify .t
    update
    lappend result [winfo ismapped .t.f2]
} -result {1 0 40 30 0 1}
test place-8.2 {PlaceStructureProc, mapping and unmapping content} -constraints {failsOnUbuntu failsOnXQuartz} -setup {
    place forget .t.f2
    place forget .t.f
} -body {
    place .t.f -x 0 -y 0 -width 200 -height 100
    place .t.f2 -in .t.f -relx 1.0 -rely 1.0 -anchor sw -width 50 -height 20
    update
    set result [winfo ismapped .t.f2]
Changes to tests/scrollbar.test.
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
# This file is a Tcl script to test out scrollbar widgets and
# the "scrollbar" command of Tk.  It is organized in the standard
# fashion for Tcl tests.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994-1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

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

proc scroll args {
    global scrollInfo
    set scrollInfo $args
}

proc getTroughSize {w} {
    if {[testConstraint testmetrics]} {
	# Only Windows has [testmetrics]
	if [string match v* [$w cget -orient]] {
	    return [expr {[winfo height $w] - 2*[testmetrics cyvscroll $w]}]
	} else {
	    return [expr {[winfo width $w] - 2*[testmetrics cxhscroll $w]}]













<
<
<
<
<







1
2
3
4
5
6
7
8
9
10
11
12
13





14
15
16
17
18
19
20
# This file is a Tcl script to test out scrollbar widgets and
# the "scrollbar" command of Tk.  It is organized in the standard
# fashion for Tcl tests.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994-1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

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






proc getTroughSize {w} {
    if {[testConstraint testmetrics]} {
	# Only Windows has [testmetrics]
	if [string match v* [$w cget -orient]] {
	    return [expr {[winfo height $w] - 2*[testmetrics cyvscroll $w]}]
	} else {
	    return [expr {[winfo width $w] - 2*[testmetrics cxhscroll $w]}]
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
    catch {destroy .s}
} -body {
    scrollbar .s
} -cleanup {
    destroy .s
} -result .s

scrollbar .s -orient vertical -command scroll -highlightthickness 2 -bd 2
pack .s -side right -fill y
update
test scrollbar-3.1 {ScrollbarWidgetCmd procedure} {
    list [catch {.s} msg] $msg
} {1 {wrong # args: should be ".s option ?arg ...?"}}
test scrollbar-3.2 {ScrollbarWidgetCmd procedure, "cget" option} {
    list [catch {.s cget} msg] $msg







|







128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
    catch {destroy .s}
} -body {
    scrollbar .s
} -cleanup {
    destroy .s
} -result .s

scrollbar .s -orient vertical -highlightthickness 2 -bd 2
pack .s -side right -fill y
update
test scrollbar-3.1 {ScrollbarWidgetCmd procedure} {
    list [catch {.s} msg] $msg
} {1 {wrong # args: should be ".s option ?arg ...?"}}
test scrollbar-3.2 {ScrollbarWidgetCmd procedure, "cget" option} {
    list [catch {.s cget} msg] $msg
Changes to tests/select.test.
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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
#
# Note: Multiple display selection handling will only be tested if the
# environment variable TK_ALT_DISPLAY is set to an alternate display.
#

package require tcltest 2.2
namespace import ::tcltest::*
namespace import ::tk::test:loadTkCommand
eval tcltest::configure $argv
tcltest::loadTestedCommands




testConstraint cliboardManagerPresent 0
if {![catch {selection get -selection CLIPBOARD_MANAGER -type TARGETS}]} {
    if {"SAVE_TARGETS" in [selection get -selection CLIPBOARD_MANAGER -type TARGETS]} {
	testConstraint cliboardManagerPresent 1
    }
}
testConstraint failsOnUbuntu [expr {![info exists ::env(CI)] || ![string match Linux $::tcl_platform(os)]}]

global longValue selValue selInfo

set selValue {}
set selInfo {}

proc handler {type offset count} {
    global selValue selInfo
    lappend selInfo $type $offset $count
    set numBytes [expr {[string length $selValue] - $offset}]
    if {$numBytes <= 0} {
	return ""
    }
    string range $selValue $offset [expr {$numBytes+$offset}]
}

proc errIncrHandler {type offset count} {
    global selValue selInfo pass
    if {$offset == 4000} {
	if {$pass == 0} {
	    # Just sizing the selection;  don't do anything here.
	    set pass 1
	} else {
	    # Fetching the selection;  wait long enough to cause a timeout.
	    after 6000
	}
    }
    lappend selInfo $type $offset $count
    set numBytes [expr {[string length $selValue] - $offset}]
    if {$numBytes <= 0} {
	return ""
    }
    string range $selValue $offset [expr {$numBytes+$offset}]
}

proc errHandler args {
    error "selection handler aborted"
}

proc badHandler {path type offset count} {
    global selValue selInfo
    selection handle -type $type $path {}
    lappend selInfo $path $type $offset $count
    set numBytes [expr {[string length $selValue] - $offset}]
    if {$numBytes <= 0} {
	return ""
    }
    string range $selValue $offset [expr {$numBytes+$offset}]
}
proc reallyBadHandler {path type offset count} {
    global selValue selInfo pass
    if {$offset == 4000} {
	if {$pass == 0} {
	    set pass 1
	} else {
	    selection handle -type $type $path {}
	}
    }
    lappend selInfo $path $type $offset $count
    set numBytes [expr {[string length $selValue] - $offset}]
    if {$numBytes <= 0} {
	return ""
    }
    string range $selValue $offset [expr {$numBytes+$offset}]
}

# Eliminate any existing selection on the screen.  This is needed in case
# there is a selection in some other application, in order to prevent races
# from causing false errors in the tests below.

selection clear .
after 1500

# common setup code
proc setup {{path .f1} {display {}}} {
    catch {destroy $path}
    if {$display == {}} {
	frame $path
    } else {
	toplevel $path -screen $display
	wm geom $path +0+0
    }
    selection own $path
}

# set up a very large buffer to test INCR retrievals
set longValue ""
foreach i {a b c d e f g j h i j k l m o p q r s t u v w x y z} {
    set j $i.1$i.2$i.3$i.4$i.5$i.6$i.7$i.8$i.9$i.10$i.11$i.12$i.13$i.14
    append longValue A$j B$j C$j D$j E$j F$j G$j H$j I$j K$j L$j M$j N$j
}

# Now we start the main body of the test code

test select-1.1 {Tk_CreateSelHandler procedure} -setup {
    setup
} -body {
    lsort [selection get TARGETS]
} -result {MULTIPLE TARGETS TIMESTAMP TK_APPLICATION TK_WINDOW}
test select-1.2 {Tk_CreateSelHandler procedure} -setup {
    setup
} -body {
    selection handle .f1 {handler TEST} TEST
    lsort [selection get TARGETS]
} -result {MULTIPLE TARGETS TEST TIMESTAMP TK_APPLICATION TK_WINDOW}
test select-1.3 {Tk_CreateSelHandler procedure} -setup {
    global selValue selInfo
    setup
} -body {
    selection handle .f1 {handler TEST} TEST
    set selValue "Test value"
    set selInfo ""
    list [selection get TEST] $selInfo
} -result {{Test value} {TEST 0 4000}}
test select-1.4.1 {Tk_CreateSelHandler procedure} -constraints unix -setup {
    setup
} -body {
    selection handle .f1 {handler TEST} TEST
    selection handle .f1 {handler STRING}
    lsort [selection get TARGETS]
} -result {MULTIPLE STRING TARGETS TEST TIMESTAMP TK_APPLICATION TK_WINDOW UTF8_STRING}
test select-1.4.2 {Tk_CreateSelHandler procedure} -constraints win -setup {
    setup
} -body {
    selection handle .f1 {handler TEST} TEST
    selection handle .f1 {handler STRING}
    lsort [selection get TARGETS]
} -result {MULTIPLE STRING TARGETS TEST TIMESTAMP TK_APPLICATION TK_WINDOW}
test select-1.5 {Tk_CreateSelHandler procedure} -setup {
    global selValue selInfo
    setup
} -body {
    selection handle .f1 {handler TEST} TEST
    selection handle .f1 {handler STRING}
    set selValue ""
    set selInfo ""
    list [selection get] $selInfo
} -result {{} {STRING 0 4000}}
test select-1.6.1 {Tk_CreateSelHandler procedure} -constraints unix -setup {
    global selValue selInfo
    setup
} -body {
    selection handle .f1 {handler TEST} TEST
    selection handle .f1 {handler STRING}
    set selValue ""
    set selInfo ""
    selection get
    selection get -type TEST
    selection handle .f1 {handler TEST2} TEST
    selection get -type TEST
    list $selInfo [lsort [selection get TARGETS]]
} -result {{STRING 0 4000 TEST 0 4000 TEST2 0 4000} {MULTIPLE STRING TARGETS TEST TIMESTAMP TK_APPLICATION TK_WINDOW UTF8_STRING}}
test select-1.6.2 {Tk_CreateSelHandler procedure} -constraints win -setup {
    global selValue selInfo
    setup
} -body {
    selection handle .f1 {handler TEST} TEST
    selection handle .f1 {handler STRING}
    set selValue ""
    set selInfo ""
    selection get
    selection get -type TEST
    selection handle .f1 {handler TEST2} TEST
    selection get -type TEST
    list $selInfo [lsort [selection get TARGETS]]
} -result {{STRING 0 4000 TEST 0 4000 TEST2 0 4000} {MULTIPLE STRING TARGETS TEST TIMESTAMP TK_APPLICATION TK_WINDOW}}
test select-1.7.1 {Tk_CreateSelHandler procedure} -constraints unix -setup {
    setup
} -body {
    selection own -selection CLIPBOARD .f1
    selection handle -selection CLIPBOARD .f1 {handler TEST} TEST
    selection handle -selection PRIMARY .f1 {handler TEST2} STRING
    list [lsort [selection get -selection PRIMARY TARGETS]] \
	[lsort [selection get -selection CLIPBOARD TARGETS]]
} -result {{MULTIPLE STRING TARGETS TIMESTAMP TK_APPLICATION TK_WINDOW UTF8_STRING} {MULTIPLE TARGETS TEST TIMESTAMP TK_APPLICATION TK_WINDOW}}
test select-1.7.2 {Tk_CreateSelHandler procedure} -constraints win -setup {
    setup
} -body {
    selection own -selection CLIPBOARD .f1
    selection handle -selection CLIPBOARD .f1 {handler TEST} TEST
    selection handle -selection PRIMARY .f1 {handler TEST2} STRING
    list [lsort [selection get -selection PRIMARY TARGETS]] \
	[lsort [selection get -selection CLIPBOARD TARGETS]]
} -result {{MULTIPLE STRING TARGETS TIMESTAMP TK_APPLICATION TK_WINDOW} {MULTIPLE TARGETS TEST TIMESTAMP TK_APPLICATION TK_WINDOW}}
test select-1.8 {Tk_CreateSelHandler procedure} -setup {
    setup
} -body {
    selection handle -format INTEGER -type TEST .f1 {handler TEST}
    lsort [selection get TARGETS]
} -result {MULTIPLE TARGETS TEST TIMESTAMP TK_APPLICATION TK_WINDOW}

##############################################################################

test select-2.1 {Tk_DeleteSelHandler procedure} -constraints unix -setup {
    setup
} -body {
    selection handle .f1 {handler STRING}
    selection handle -type TEST .f1 {handler TEST}
    selection handle -type USER .f1 {handler USER}
    set result [list [lsort [selection get TARGETS]]]
    selection handle -type TEST .f1 {}
    lappend result [lsort [selection get TARGETS]]
} -result {{MULTIPLE STRING TARGETS TEST TIMESTAMP TK_APPLICATION TK_WINDOW USER UTF8_STRING} {MULTIPLE STRING TARGETS TIMESTAMP TK_APPLICATION TK_WINDOW USER UTF8_STRING}}
test select-2.2 {Tk_DeleteSelHandler procedure} -constraints unix -setup {
    setup
} -body {
    selection handle .f1 {handler STRING}
    selection handle -type TEST .f1 {handler TEST}
    selection handle -type USER .f1 {handler USER}
    set result [list [lsort [selection get TARGETS]]]
    selection handle -type USER .f1 {}
    lappend result [lsort [selection get TARGETS]]
} -result {{MULTIPLE STRING TARGETS TEST TIMESTAMP TK_APPLICATION TK_WINDOW USER UTF8_STRING} {MULTIPLE STRING TARGETS TEST TIMESTAMP TK_APPLICATION TK_WINDOW UTF8_STRING}}
test select-2.3 {Tk_DeleteSelHandler procedure} -constraints unix -setup {
    setup
} -body {
    selection own -selection CLIPBOARD .f1
    selection handle -selection PRIMARY .f1 {handler STRING}
    selection handle -selection CLIPBOARD .f1 {handler STRING}
    selection handle -selection CLIPBOARD .f1 {}
    list [lsort [selection get TARGETS]] \
	[lsort [selection get -selection CLIPBOARD TARGETS]]
} -result {{MULTIPLE STRING TARGETS TIMESTAMP TK_APPLICATION TK_WINDOW UTF8_STRING} {MULTIPLE TARGETS TIMESTAMP TK_APPLICATION TK_WINDOW}}
test select-2.4 {Tk_DeleteSelHandler procedure} -constraints win -setup {
    setup
} -body {
    selection handle .f1 {handler STRING}
    selection handle -type TEST .f1 {handler TEST}
    selection handle -type USER .f1 {handler USER}
    set result [list [lsort [selection get TARGETS]]]
    selection handle -type TEST .f1 {}
    lappend result [lsort [selection get TARGETS]]
} -result {{MULTIPLE STRING TARGETS TEST TIMESTAMP TK_APPLICATION TK_WINDOW USER} {MULTIPLE STRING TARGETS TIMESTAMP TK_APPLICATION TK_WINDOW USER}}
test select-2.5 {Tk_DeleteSelHandler procedure} -constraints win -setup {
    setup
} -body {
    selection handle .f1 {handler STRING}
    selection handle -type TEST .f1 {handler TEST}
    selection handle -type USER .f1 {handler USER}
    set result [list [lsort [selection get TARGETS]]]
    selection handle -type USER .f1 {}
    lappend result [lsort [selection get TARGETS]]
} -result {{MULTIPLE STRING TARGETS TEST TIMESTAMP TK_APPLICATION TK_WINDOW USER} {MULTIPLE STRING TARGETS TEST TIMESTAMP TK_APPLICATION TK_WINDOW}}
test select-2.6 {Tk_DeleteSelHandler procedure} -constraints win -setup {
    setup
} -body {
    selection own -selection CLIPBOARD .f1
    selection handle -selection PRIMARY .f1 {handler STRING}
    selection handle -selection CLIPBOARD .f1 {handler STRING}
    selection handle -selection CLIPBOARD .f1 {}
    list [lsort [selection get TARGETS]] \
	[lsort [selection get -selection CLIPBOARD TARGETS]]
} -result {{MULTIPLE STRING TARGETS TIMESTAMP TK_APPLICATION TK_WINDOW} {MULTIPLE TARGETS TIMESTAMP TK_APPLICATION TK_WINDOW}}
test select-2.7 {Tk_DeleteSelHandler procedure} -setup {
    setup
} -body {
    selection handle .f1 {handler STRING}
    list [selection handle .f1 {}] [selection handle .f1 {}]
} -result {{} {}}

##############################################################################

test select-3.1 {Tk_OwnSelection procedure} -setup {
    setup
} -body {
    selection own
} -result {.f1}
test select-3.2 {Tk_OwnSelection procedure} -body {
    setup .f1
    set result [selection own]
    setup .f2
    lappend result [selection own]
} -result {.f1 .f2}
test select-3.3 {Tk_OwnSelection procedure} -setup {
    setup .f1
    setup .f2
} -body {
    selection own -selection CLIPBOARD .f1
    list [selection own] [selection own -selection CLIPBOARD]
} -result {.f2 .f1}
test select-3.4 {Tk_OwnSelection procedure} -setup {
    global lostSel
    setup
} -body {
    set lostSel {owned}
    selection own -command { set lostSel {lost} } .f1
    selection clear .f1
    set lostSel
} -result {lost}
test select-3.5 {Tk_OwnSelection procedure} -setup {
    global lostSel
    setup .f1
    setup .f2
} -body {
    set lostSel {owned}
    selection own -command { set lostSel {lost1} } .f1
    selection own -command { set lostSel {lost2} } .f2
    list $lostSel [selection own]
} -result {lost1 .f2}
test select-3.6 {Tk_OwnSelection procedure} -setup {
    global lostSel
    setup
} -body {
    set lostSel {owned}
    selection own -command { set lostSel {lost1} } .f1
    selection own -command { set lostSel {lost2} } .f1
    set result $lostSel
    selection clear .f1
    lappend result $lostSel
} -result {owned lost2}
test select-3.7 {Tk_OwnSelection procedure} -constraints x11 -setup {
    global lostSel
    setup
    setupbg
} -body {
    set lostSel {owned}
    selection own -command { set lostSel {lost1} } .f1
    update
    set result {}
    lappend result [dobg { selection own . }]
    lappend result [dobg {selection own}]
    update
    cleanupbg
    lappend result $lostSel
} -result {{} . lost1}
# check reentrancy on selection replacement
test select-3.8 {Tk_OwnSelection procedure} -setup {
    setup
} -body {
    selection own -selection CLIPBOARD -command { destroy .f1 } .f1
    selection own -selection CLIPBOARD .
} -result {}
test select-3.9 {Tk_OwnSelection procedure} -setup {
    setup .f2
    setup .f1
} -body {
    selection own -selection CLIPBOARD -command { destroy .f2 } .f1
    selection own -selection CLIPBOARD .f2
} -result {}
# multiple display tests
test select-3.10 {Tk_OwnSelection procedure} -constraints {
    altDisplay
} -body {
    setup .f1
    setup .f2 $env(TK_ALT_DISPLAY)
    list [selection own -displayof .f1] [selection own -displayof .f2]
} -result {.f1 .f2}
test select-3.11 {Tk_OwnSelection procedure} -constraints {
    altDisplay
} -setup {
    setup .f1
    setup .f2 $env(TK_ALT_DISPLAY)
    setupbg
    update
    set result ""
} -body {
    lappend result [dobg "toplevel .t -screen $env(TK_ALT_DISPLAY); wm geom .t +0+0; selection own .t; update"]
    lappend result [selection own -displayof .f1] \
	    [selection own -displayof .f2]
} -cleanup {
    cleanupbg
} -result {{} .f1 {}}

##############################################################################

test select-4.1 {Tk_ClearSelection procedure} -setup {
    setup
} -body {
    set result [selection own]
    selection clear .f1
    lappend result [selection own]
} -result {.f1 {}}
test select-4.2 {Tk_ClearSelection procedure} -setup {
    setup
} -body {
    selection own -selection CLIPBOARD .f1
    selection clear .f1
    selection own -selection CLIPBOARD
} -result {.f1}
test select-4.3 {Tk_ClearSelection procedure} -setup {
    setup
} -body {
    list [selection clear .f1] [selection clear .f1]
} -result {{} {}}
test select-4.4 {Tk_ClearSelection procedure} -constraints x11 -setup {
    global lostSel
    setup
    setupbg
} -body {
    set lostSel {owned}
    selection own -command { set lostSel {lost1} } .f1
    update
    set result {}
    lappend result [dobg {selection clear; update}]
    update
    cleanupbg
    lappend result [selection own]
} -result {{} {}}
# multiple display tests
test select-4.5 {Tk_ClearSelection procedure} -constraints {
    altDisplay
} -setup {
    global lostSel lostSel2
    setup .f1
    setup .f2 $env(TK_ALT_DISPLAY)
} -body {
    set lostSel {owned}
    set lostSel2 {owned2}
    selection own -command { set lostSel {lost1} } .f1
    selection own -command { set lostSel2 {lost2} } .f2
    update
    selection clear -displayof .f2
    update
    list $lostSel $lostSel2
} -result {owned lost2}
test select-4.6 {Tk_ClearSelection procedure} -constraints {
    x11 altDisplay
} -setup {
    setup .f1
    setup .f2 $env(TK_ALT_DISPLAY)
    setupbg
} -body {
    set lostSel {owned}
    set lostSel2 {owned2}
    selection own -command { set lostSel {lost1} } .f1
    selection own -command { set lostSel2 {lost2} } .f2
    update
    set result ""
    lappend result [dobg "toplevel .t -screen $env(TK_ALT_DISPLAY); wm geom .t +0+0; selection own .t; update"]
    lappend result [selection own -displayof .f1] \
	    [selection own -displayof .f2] $lostSel $lostSel2
    cleanupbg
    set result
} -result {{} .f1 {} owned lost2}

##############################################################################

test select-5.1 {Tk_GetSelection procedure} -returnCodes error -setup {
    setup
} -body {
    selection get TEST
} -result {PRIMARY selection doesn't exist or form "TEST" not defined}
test select-5.2 {Tk_GetSelection procedure} -setup {
    setup
} -body {
    selection get TK_WINDOW
} -result {.f1}
test select-5.3 {Tk_GetSelection procedure} -setup {
    setup
} -body {
    selection handle -selection PRIMARY .f1 {handler TEST} TEST
    set selValue "Test value"
    set selInfo ""
    list [selection get TEST] $selInfo
} -result {{Test value} {TEST 0 4000}}
test select-5.4 {Tk_GetSelection procedure} -setup {
    setup
} -returnCodes error -body {
    selection handle .f1 ERROR errHandler
    selection get ERROR
} -result {PRIMARY selection doesn't exist or form "ERROR" not defined}
test select-5.5 {Tk_GetSelection procedure} -setup {
    setup
} -body {
    set selValue $longValue
    set selInfo ""
    selection handle .f1 {handler STRING}
    list [selection get] $selInfo
} -result "$longValue {STRING 0 4000 STRING 4000 4000 STRING 8000 4000 STRING 12000 4000 STRING 16000 4000}"
test select-5.6 {Tk_GetSelection procedure} -setup {
    setup
} -returnCodes error -body {
    set selValue $longValue
    set selInfo ""
    selection handle .f1 {apply {{type offset count} {
	selection handle .f1 {}
	handler $type $offset $count
    }} STRING}
    selection get
} -result {PRIMARY selection doesn't exist or form "STRING" not defined}
test select-5.7 {Tk_GetSelection procedure} -setup {
    setup
} -returnCodes error -body {
    set selValue "Test Value"
    set selInfo ""
    selection handle .f1 {apply {{type offset count} {
	destroy .f1
	handler $type $offset $count
    }} STRING}
    selection get
} -result {PRIMARY selection doesn't exist or form "STRING" not defined}
test select-5.8 {Tk_GetSelection procedure} -setup {
    setup
} -body {
    set selValue $longValue
    set selInfo ""
    selection handle .f1 {apply {{type offset count} {
	selection clear
	handler $type $offset $count
    }} STRING}
    list [selection get] $selInfo [catch {selection get} msg] $msg
} -result "$longValue {STRING 0 4000 STRING 4000 4000 STRING 8000 4000 STRING 12000 4000 STRING 16000 4000} 1 {PRIMARY selection doesn't exist or form \"STRING\" not defined}"
test select-5.9 {Tk_GetSelection procedure} -constraints x11 -setup {
    setup
    setupbg
} -body {
    selection handle -selection PRIMARY .f1 {handler TEST} TEST
    update
    set selValue "Test value"
    set selInfo ""
    set result ""
    lappend result [dobg {selection get TEST}]
    cleanupbg
    lappend result $selInfo
} -result {{Test value} {TEST 0 4000}}
test select-5.10 {Tk_GetSelection procedure} -constraints x11 -setup {
    setup
    setupbg
} -body {
    selection handle -selection PRIMARY .f1 {handler TEST} TEST
    update
    set selValue "Test value"
    set selInfo ""
    selection own .f1
    set result ""
    lappend result [dobg {selection get TEST} 1]
    cleanupbg
    lappend result $selInfo
} -result {{selection owner didn't respond} {}}
# multiple display tests
test select-5.11 {Tk_GetSelection procedure} -constraints {
    altDisplay
} -setup {
    setup .f1
    setup .f2 $env(TK_ALT_DISPLAY)
} -body {
    selection handle -selection PRIMARY .f1 {handler TEST} TEST
    selection handle -selection PRIMARY .f2 {handler TEST2} TEST
    set selValue "Test value"
    set selInfo ""
    set result [list [selection get TEST] $selInfo]
    set selValue "Test value2"
    set selInfo ""
    lappend result [selection get -displayof .f2 TEST] $selInfo
} -result {{Test value} {TEST 0 4000} {Test value2} {TEST2 0 4000}}
test select-5.12 {Tk_GetSelection procedure} -constraints {
    altDisplay
} -setup {
    global lostSel lostSel2
    setup .f1
    setup .f2 $env(TK_ALT_DISPLAY)
} -body {
    selection handle -selection PRIMARY .f1 {handler TEST} TEST
    selection handle -selection PRIMARY .f2 {} TEST
    set selValue "Test value"
    set selInfo ""
    set result [list [catch {selection get TEST} msg] $msg $selInfo]
    set selValue "Test value2"
    set selInfo ""
    lappend result [catch {selection get -displayof .f2 TEST} msg] $msg \
	    $selInfo
} -result {0 {Test value} {TEST 0 4000} 1 {PRIMARY selection doesn't exist or form "TEST" not defined} {}}
test select-5.13 {Tk_GetSelection procedure} -constraints {
    x11 altDisplay
} -setup {
    setup .f1
    setup .f2 $env(TK_ALT_DISPLAY)
    setupbg
} -body {
    selection handle -selection PRIMARY .f1 {handler TEST} TEST
    selection own .f1
    selection handle -selection PRIMARY .f2 {handler TEST2} TEST
    selection own .f2
    set selValue "Test value"
    set selInfo ""
    update
    set result ""
    lappend result [dobg "toplevel .t -screen $env(TK_ALT_DISPLAY); wm geom .t +0+0; selection get -displayof .t TEST"]
    set selValue "Test value2"
    lappend result [dobg "selection get TEST"]
    cleanupbg
    lappend result $selInfo
} -result {{Test value} {Test value2} {TEST2 0 4000 TEST 0 4000}}
test select-5.14 {Tk_GetSelection procedure} -constraints {
    x11 altDisplay
} -setup {
    setup .f1
    setup .f2 $env(TK_ALT_DISPLAY)
    setupbg
} -body {
    selection handle -selection PRIMARY .f1 {handler TEST} TEST
    selection own .f1
    selection handle -selection PRIMARY .f2 {} TEST
    selection own .f2
    set selValue "Test value"
    set selInfo ""
    update
    set result ""
    lappend result [dobg "toplevel .t -screen $env(TK_ALT_DISPLAY); wm geom .t +0+0; selection get -displayof .t TEST"]
    set selValue "Test value2"
    lappend result [dobg "selection get TEST"]
    cleanupbg
    lappend result $selInfo
} -result {{PRIMARY selection doesn't exist or form "TEST" not defined} {Test value2} {TEST 0 4000}}
test select-5.15 {Tk_GetSelection procedure} -setup {
    setup
    if {[llength [info command ::bgerror]]} {
	rename ::bgerror ::TMPbgerror
    }
    set ::bgerrors {}
} -body {
    proc ::bgerror msg {lappend ::bgerrors $msg}
    selection handle -type ERROR .f1 errHandler







<



>
>
>






<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<




<



<
<
<
<
<
<
<
<
<
<
<
<








|

|




|





<
|







|






|






<
|








<
|












<
|












|








|








|








|









|









|









|









|









|









|








|




|

|



|
|






|








|
|








|










|
|





|
|

|




|





|
|








|
|





|
|
|



|



|





|






|






|





|
|





|

|







|
|













|
|
|







|


|






|




|




|







|





|







|










|










|










|
|






|
|



|
|







|
|






|
|














|
|














|
|
|









|

|
|





|
|
|









|

|
|



|







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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
#
# Note: Multiple display selection handling will only be tested if the
# environment variable TK_ALT_DISPLAY is set to an alternate display.
#

package require tcltest 2.2
namespace import ::tcltest::*

eval tcltest::configure $argv
tcltest::loadTestedCommands

# Import utility procs for specific functional areas
testutils import child select

testConstraint cliboardManagerPresent 0
if {![catch {selection get -selection CLIPBOARD_MANAGER -type TARGETS}]} {
    if {"SAVE_TARGETS" in [selection get -selection CLIPBOARD_MANAGER -type TARGETS]} {
	testConstraint cliboardManagerPresent 1
    }
}



































































# Eliminate any existing selection on the screen.  This is needed in case
# there is a selection in some other application, in order to prevent races
# from causing false errors in the tests below.

selection clear .
after 1500













# set up a very large buffer to test INCR retrievals
set longValue ""
foreach i {a b c d e f g j h i j k l m o p q r s t u v w x y z} {
    set j $i.1$i.2$i.3$i.4$i.5$i.6$i.7$i.8$i.9$i.10$i.11$i.12$i.13$i.14
    append longValue A$j B$j C$j D$j E$j F$j G$j H$j I$j K$j L$j M$j N$j
}

# Now we start the main body of the test code

test select-1.1 {Tk_CreateSelHandler procedure} -setup {
    selectionSetup
} -body {
    lsort [selection get TARGETS]
} -result {MULTIPLE TARGETS TIMESTAMP TK_APPLICATION TK_WINDOW}
test select-1.2 {Tk_CreateSelHandler procedure} -setup {
    selectionSetup
} -body {
    selection handle .f1 {handler TEST} TEST
    lsort [selection get TARGETS]
} -result {MULTIPLE TARGETS TEST TIMESTAMP TK_APPLICATION TK_WINDOW}
test select-1.3 {Tk_CreateSelHandler procedure} -setup {

    selectionSetup
} -body {
    selection handle .f1 {handler TEST} TEST
    set selValue "Test value"
    set selInfo ""
    list [selection get TEST] $selInfo
} -result {{Test value} {TEST 0 4000}}
test select-1.4.1 {Tk_CreateSelHandler procedure} -constraints unix -setup {
    selectionSetup
} -body {
    selection handle .f1 {handler TEST} TEST
    selection handle .f1 {handler STRING}
    lsort [selection get TARGETS]
} -result {MULTIPLE STRING TARGETS TEST TIMESTAMP TK_APPLICATION TK_WINDOW UTF8_STRING}
test select-1.4.2 {Tk_CreateSelHandler procedure} -constraints win -setup {
    selectionSetup
} -body {
    selection handle .f1 {handler TEST} TEST
    selection handle .f1 {handler STRING}
    lsort [selection get TARGETS]
} -result {MULTIPLE STRING TARGETS TEST TIMESTAMP TK_APPLICATION TK_WINDOW}
test select-1.5 {Tk_CreateSelHandler procedure} -setup {

    selectionSetup
} -body {
    selection handle .f1 {handler TEST} TEST
    selection handle .f1 {handler STRING}
    set selValue ""
    set selInfo ""
    list [selection get] $selInfo
} -result {{} {STRING 0 4000}}
test select-1.6.1 {Tk_CreateSelHandler procedure} -constraints unix -setup {

    selectionSetup
} -body {
    selection handle .f1 {handler TEST} TEST
    selection handle .f1 {handler STRING}
    set selValue ""
    set selInfo ""
    selection get
    selection get -type TEST
    selection handle .f1 {handler TEST2} TEST
    selection get -type TEST
    list $selInfo [lsort [selection get TARGETS]]
} -result {{STRING 0 4000 TEST 0 4000 TEST2 0 4000} {MULTIPLE STRING TARGETS TEST TIMESTAMP TK_APPLICATION TK_WINDOW UTF8_STRING}}
test select-1.6.2 {Tk_CreateSelHandler procedure} -constraints win -setup {

    selectionSetup
} -body {
    selection handle .f1 {handler TEST} TEST
    selection handle .f1 {handler STRING}
    set selValue ""
    set selInfo ""
    selection get
    selection get -type TEST
    selection handle .f1 {handler TEST2} TEST
    selection get -type TEST
    list $selInfo [lsort [selection get TARGETS]]
} -result {{STRING 0 4000 TEST 0 4000 TEST2 0 4000} {MULTIPLE STRING TARGETS TEST TIMESTAMP TK_APPLICATION TK_WINDOW}}
test select-1.7.1 {Tk_CreateSelHandler procedure} -constraints unix -setup {
    selectionSetup
} -body {
    selection own -selection CLIPBOARD .f1
    selection handle -selection CLIPBOARD .f1 {handler TEST} TEST
    selection handle -selection PRIMARY .f1 {handler TEST2} STRING
    list [lsort [selection get -selection PRIMARY TARGETS]] \
	[lsort [selection get -selection CLIPBOARD TARGETS]]
} -result {{MULTIPLE STRING TARGETS TIMESTAMP TK_APPLICATION TK_WINDOW UTF8_STRING} {MULTIPLE TARGETS TEST TIMESTAMP TK_APPLICATION TK_WINDOW}}
test select-1.7.2 {Tk_CreateSelHandler procedure} -constraints win -setup {
    selectionSetup
} -body {
    selection own -selection CLIPBOARD .f1
    selection handle -selection CLIPBOARD .f1 {handler TEST} TEST
    selection handle -selection PRIMARY .f1 {handler TEST2} STRING
    list [lsort [selection get -selection PRIMARY TARGETS]] \
	[lsort [selection get -selection CLIPBOARD TARGETS]]
} -result {{MULTIPLE STRING TARGETS TIMESTAMP TK_APPLICATION TK_WINDOW} {MULTIPLE TARGETS TEST TIMESTAMP TK_APPLICATION TK_WINDOW}}
test select-1.8 {Tk_CreateSelHandler procedure} -setup {
    selectionSetup
} -body {
    selection handle -format INTEGER -type TEST .f1 {handler TEST}
    lsort [selection get TARGETS]
} -result {MULTIPLE TARGETS TEST TIMESTAMP TK_APPLICATION TK_WINDOW}

##############################################################################

test select-2.1 {Tk_DeleteSelHandler procedure} -constraints unix -setup {
    selectionSetup
} -body {
    selection handle .f1 {handler STRING}
    selection handle -type TEST .f1 {handler TEST}
    selection handle -type USER .f1 {handler USER}
    set result [list [lsort [selection get TARGETS]]]
    selection handle -type TEST .f1 {}
    lappend result [lsort [selection get TARGETS]]
} -result {{MULTIPLE STRING TARGETS TEST TIMESTAMP TK_APPLICATION TK_WINDOW USER UTF8_STRING} {MULTIPLE STRING TARGETS TIMESTAMP TK_APPLICATION TK_WINDOW USER UTF8_STRING}}
test select-2.2 {Tk_DeleteSelHandler procedure} -constraints unix -setup {
    selectionSetup
} -body {
    selection handle .f1 {handler STRING}
    selection handle -type TEST .f1 {handler TEST}
    selection handle -type USER .f1 {handler USER}
    set result [list [lsort [selection get TARGETS]]]
    selection handle -type USER .f1 {}
    lappend result [lsort [selection get TARGETS]]
} -result {{MULTIPLE STRING TARGETS TEST TIMESTAMP TK_APPLICATION TK_WINDOW USER UTF8_STRING} {MULTIPLE STRING TARGETS TEST TIMESTAMP TK_APPLICATION TK_WINDOW UTF8_STRING}}
test select-2.3 {Tk_DeleteSelHandler procedure} -constraints unix -setup {
    selectionSetup
} -body {
    selection own -selection CLIPBOARD .f1
    selection handle -selection PRIMARY .f1 {handler STRING}
    selection handle -selection CLIPBOARD .f1 {handler STRING}
    selection handle -selection CLIPBOARD .f1 {}
    list [lsort [selection get TARGETS]] \
	[lsort [selection get -selection CLIPBOARD TARGETS]]
} -result {{MULTIPLE STRING TARGETS TIMESTAMP TK_APPLICATION TK_WINDOW UTF8_STRING} {MULTIPLE TARGETS TIMESTAMP TK_APPLICATION TK_WINDOW}}
test select-2.4 {Tk_DeleteSelHandler procedure} -constraints win -setup {
    selectionSetup
} -body {
    selection handle .f1 {handler STRING}
    selection handle -type TEST .f1 {handler TEST}
    selection handle -type USER .f1 {handler USER}
    set result [list [lsort [selection get TARGETS]]]
    selection handle -type TEST .f1 {}
    lappend result [lsort [selection get TARGETS]]
} -result {{MULTIPLE STRING TARGETS TEST TIMESTAMP TK_APPLICATION TK_WINDOW USER} {MULTIPLE STRING TARGETS TIMESTAMP TK_APPLICATION TK_WINDOW USER}}
test select-2.5 {Tk_DeleteSelHandler procedure} -constraints win -setup {
    selectionSetup
} -body {
    selection handle .f1 {handler STRING}
    selection handle -type TEST .f1 {handler TEST}
    selection handle -type USER .f1 {handler USER}
    set result [list [lsort [selection get TARGETS]]]
    selection handle -type USER .f1 {}
    lappend result [lsort [selection get TARGETS]]
} -result {{MULTIPLE STRING TARGETS TEST TIMESTAMP TK_APPLICATION TK_WINDOW USER} {MULTIPLE STRING TARGETS TEST TIMESTAMP TK_APPLICATION TK_WINDOW}}
test select-2.6 {Tk_DeleteSelHandler procedure} -constraints win -setup {
    selectionSetup
} -body {
    selection own -selection CLIPBOARD .f1
    selection handle -selection PRIMARY .f1 {handler STRING}
    selection handle -selection CLIPBOARD .f1 {handler STRING}
    selection handle -selection CLIPBOARD .f1 {}
    list [lsort [selection get TARGETS]] \
	[lsort [selection get -selection CLIPBOARD TARGETS]]
} -result {{MULTIPLE STRING TARGETS TIMESTAMP TK_APPLICATION TK_WINDOW} {MULTIPLE TARGETS TIMESTAMP TK_APPLICATION TK_WINDOW}}
test select-2.7 {Tk_DeleteSelHandler procedure} -setup {
    selectionSetup
} -body {
    selection handle .f1 {handler STRING}
    list [selection handle .f1 {}] [selection handle .f1 {}]
} -result {{} {}}

##############################################################################

test select-3.1 {Tk_OwnSelection procedure} -setup {
    selectionSetup
} -body {
    selection own
} -result {.f1}
test select-3.2 {Tk_OwnSelection procedure} -body {
    selectionSetup .f1
    set result [selection own]
    selectionSetup .f2
    lappend result [selection own]
} -result {.f1 .f2}
test select-3.3 {Tk_OwnSelection procedure} -setup {
    selectionSetup .f1
    selectionSetup .f2
} -body {
    selection own -selection CLIPBOARD .f1
    list [selection own] [selection own -selection CLIPBOARD]
} -result {.f2 .f1}
test select-3.4 {Tk_OwnSelection procedure} -setup {
    global lostSel
    selectionSetup
} -body {
    set lostSel {owned}
    selection own -command { set lostSel {lost} } .f1
    selection clear .f1
    set lostSel
} -result {lost}
test select-3.5 {Tk_OwnSelection procedure} -setup {
    global lostSel
    selectionSetup .f1
    selectionSetup .f2
} -body {
    set lostSel {owned}
    selection own -command { set lostSel {lost1} } .f1
    selection own -command { set lostSel {lost2} } .f2
    list $lostSel [selection own]
} -result {lost1 .f2}
test select-3.6 {Tk_OwnSelection procedure} -setup {
    global lostSel
    selectionSetup
} -body {
    set lostSel {owned}
    selection own -command { set lostSel {lost1} } .f1
    selection own -command { set lostSel {lost2} } .f1
    set result $lostSel
    selection clear .f1
    lappend result $lostSel
} -result {owned lost2}
test select-3.7 {Tk_OwnSelection procedure} -constraints x11 -setup {
    global lostSel
    selectionSetup
    childTkProcess create
} -body {
    set lostSel {owned}
    selection own -command { set lostSel {lost1} } .f1
    update
    set result {}
    lappend result [childTkProcess eval { selection own . }]
    lappend result [childTkProcess eval {selection own}]
    update
    childTkProcess exit
    lappend result $lostSel
} -result {{} . lost1}
# check reentrancy on selection replacement
test select-3.8 {Tk_OwnSelection procedure} -setup {
    selectionSetup
} -body {
    selection own -selection CLIPBOARD -command { destroy .f1 } .f1
    selection own -selection CLIPBOARD .
} -result {}
test select-3.9 {Tk_OwnSelection procedure} -setup {
    selectionSetup .f2
    selectionSetup .f1
} -body {
    selection own -selection CLIPBOARD -command { destroy .f2 } .f1
    selection own -selection CLIPBOARD .f2
} -result {}
# multiple display tests
test select-3.10 {Tk_OwnSelection procedure} -constraints {
    altDisplay
} -body {
    selectionSetup .f1
    selectionSetup .f2 $env(TK_ALT_DISPLAY)
    list [selection own -displayof .f1] [selection own -displayof .f2]
} -result {.f1 .f2}
test select-3.11 {Tk_OwnSelection procedure} -constraints {
    altDisplay
} -setup {
    selectionSetup .f1
    selectionSetup .f2 $env(TK_ALT_DISPLAY)
    childTkProcess create
    update
    set result ""
} -body {
    lappend result [childTkProcess eval "toplevel .t -screen $env(TK_ALT_DISPLAY); wm geom .t +0+0; selection own .t; update"]
    lappend result [selection own -displayof .f1] \
	    [selection own -displayof .f2]
} -cleanup {
    childTkProcess exit
} -result {{} .f1 {}}

##############################################################################

test select-4.1 {Tk_ClearSelection procedure} -setup {
    selectionSetup
} -body {
    set result [selection own]
    selection clear .f1
    lappend result [selection own]
} -result {.f1 {}}
test select-4.2 {Tk_ClearSelection procedure} -setup {
    selectionSetup
} -body {
    selection own -selection CLIPBOARD .f1
    selection clear .f1
    selection own -selection CLIPBOARD
} -result {.f1}
test select-4.3 {Tk_ClearSelection procedure} -setup {
    selectionSetup
} -body {
    list [selection clear .f1] [selection clear .f1]
} -result {{} {}}
test select-4.4 {Tk_ClearSelection procedure} -constraints x11 -setup {
    global lostSel
    selectionSetup
    childTkProcess create
} -body {
    set lostSel {owned}
    selection own -command { set lostSel {lost1} } .f1
    update
    set result {}
    lappend result [childTkProcess eval {selection clear; update}]
    update
    childTkProcess exit
    lappend result [selection own]
} -result {{} {}}
# multiple display tests
test select-4.5 {Tk_ClearSelection procedure} -constraints {
    altDisplay
} -setup {
    global lostSel lostSel2
    selectionSetup .f1
    selectionSetup .f2 $env(TK_ALT_DISPLAY)
} -body {
    set lostSel {owned}
    set lostSel2 {owned2}
    selection own -command { set lostSel {lost1} } .f1
    selection own -command { set lostSel2 {lost2} } .f2
    update
    selection clear -displayof .f2
    update
    list $lostSel $lostSel2
} -result {owned lost2}
test select-4.6 {Tk_ClearSelection procedure} -constraints {
    x11 altDisplay
} -setup {
    selectionSetup .f1
    selectionSetup .f2 $env(TK_ALT_DISPLAY)
    childTkProcess create
} -body {
    set lostSel {owned}
    set lostSel2 {owned2}
    selection own -command { set lostSel {lost1} } .f1
    selection own -command { set lostSel2 {lost2} } .f2
    update
    set result ""
    lappend result [childTkProcess eval "toplevel .t -screen $env(TK_ALT_DISPLAY); wm geom .t +0+0; selection own .t; update"]
    lappend result [selection own -displayof .f1] \
	    [selection own -displayof .f2] $lostSel $lostSel2
    childTkProcess exit
    set result
} -result {{} .f1 {} owned lost2}

##############################################################################

test select-5.1 {Tk_GetSelection procedure} -returnCodes error -setup {
    selectionSetup
} -body {
    selection get TEST
} -result {PRIMARY selection doesn't exist or form "TEST" not defined}
test select-5.2 {Tk_GetSelection procedure} -setup {
    selectionSetup
} -body {
    selection get TK_WINDOW
} -result {.f1}
test select-5.3 {Tk_GetSelection procedure} -setup {
    selectionSetup
} -body {
    selection handle -selection PRIMARY .f1 {handler TEST} TEST
    set selValue "Test value"
    set selInfo ""
    list [selection get TEST] $selInfo
} -result {{Test value} {TEST 0 4000}}
test select-5.4 {Tk_GetSelection procedure} -setup {
    selectionSetup
} -returnCodes error -body {
    selection handle .f1 ERROR errHandler
    selection get ERROR
} -result {PRIMARY selection doesn't exist or form "ERROR" not defined}
test select-5.5 {Tk_GetSelection procedure} -setup {
    selectionSetup
} -body {
    set selValue $longValue
    set selInfo ""
    selection handle .f1 {handler STRING}
    list [selection get] $selInfo
} -result "$longValue {STRING 0 4000 STRING 4000 4000 STRING 8000 4000 STRING 12000 4000 STRING 16000 4000}"
test select-5.6 {Tk_GetSelection procedure} -setup {
    selectionSetup
} -returnCodes error -body {
    set selValue $longValue
    set selInfo ""
    selection handle .f1 {apply {{type offset count} {
	selection handle .f1 {}
	handler $type $offset $count
    }} STRING}
    selection get
} -result {PRIMARY selection doesn't exist or form "STRING" not defined}
test select-5.7 {Tk_GetSelection procedure} -setup {
    selectionSetup
} -returnCodes error -body {
    set selValue "Test Value"
    set selInfo ""
    selection handle .f1 {apply {{type offset count} {
	destroy .f1
	handler $type $offset $count
    }} STRING}
    selection get
} -result {PRIMARY selection doesn't exist or form "STRING" not defined}
test select-5.8 {Tk_GetSelection procedure} -setup {
    selectionSetup
} -body {
    set selValue $longValue
    set selInfo ""
    selection handle .f1 {apply {{type offset count} {
	selection clear
	handler $type $offset $count
    }} STRING}
    list [selection get] $selInfo [catch {selection get} msg] $msg
} -result "$longValue {STRING 0 4000 STRING 4000 4000 STRING 8000 4000 STRING 12000 4000 STRING 16000 4000} 1 {PRIMARY selection doesn't exist or form \"STRING\" not defined}"
test select-5.9 {Tk_GetSelection procedure} -constraints x11 -setup {
    selectionSetup
    childTkProcess create
} -body {
    selection handle -selection PRIMARY .f1 {handler TEST} TEST
    update
    set selValue "Test value"
    set selInfo ""
    set result ""
    lappend result [childTkProcess eval {selection get TEST}]
    childTkProcess exit
    lappend result $selInfo
} -result {{Test value} {TEST 0 4000}}
test select-5.10 {Tk_GetSelection procedure} -constraints x11 -setup {
    selectionSetup
    childTkProcess create
} -body {
    selection handle -selection PRIMARY .f1 {handler TEST} TEST
    update
    set selValue "Test value"
    set selInfo ""
    selection own .f1
    set result ""
    lappend result [childTkProcess eval {selection get TEST} 1]
    childTkProcess exit
    lappend result $selInfo
} -result {{selection owner didn't respond} {}}
# multiple display tests
test select-5.11 {Tk_GetSelection procedure} -constraints {
    altDisplay
} -setup {
    selectionSetup .f1
    selectionSetup .f2 $env(TK_ALT_DISPLAY)
} -body {
    selection handle -selection PRIMARY .f1 {handler TEST} TEST
    selection handle -selection PRIMARY .f2 {handler TEST2} TEST
    set selValue "Test value"
    set selInfo ""
    set result [list [selection get TEST] $selInfo]
    set selValue "Test value2"
    set selInfo ""
    lappend result [selection get -displayof .f2 TEST] $selInfo
} -result {{Test value} {TEST 0 4000} {Test value2} {TEST2 0 4000}}
test select-5.12 {Tk_GetSelection procedure} -constraints {
    altDisplay
} -setup {
    global lostSel lostSel2
    selectionSetup .f1
    selectionSetup .f2 $env(TK_ALT_DISPLAY)
} -body {
    selection handle -selection PRIMARY .f1 {handler TEST} TEST
    selection handle -selection PRIMARY .f2 {} TEST
    set selValue "Test value"
    set selInfo ""
    set result [list [catch {selection get TEST} msg] $msg $selInfo]
    set selValue "Test value2"
    set selInfo ""
    lappend result [catch {selection get -displayof .f2 TEST} msg] $msg \
	    $selInfo
} -result {0 {Test value} {TEST 0 4000} 1 {PRIMARY selection doesn't exist or form "TEST" not defined} {}}
test select-5.13 {Tk_GetSelection procedure} -constraints {
    x11 altDisplay
} -setup {
    selectionSetup .f1
    selectionSetup .f2 $env(TK_ALT_DISPLAY)
    childTkProcess create
} -body {
    selection handle -selection PRIMARY .f1 {handler TEST} TEST
    selection own .f1
    selection handle -selection PRIMARY .f2 {handler TEST2} TEST
    selection own .f2
    set selValue "Test value"
    set selInfo ""
    update
    set result ""
    lappend result [childTkProcess eval "toplevel .t -screen $env(TK_ALT_DISPLAY); wm geom .t +0+0; selection get -displayof .t TEST"]
    set selValue "Test value2"
    lappend result [childTkProcess eval "selection get TEST"]
    childTkProcess exit
    lappend result $selInfo
} -result {{Test value} {Test value2} {TEST2 0 4000 TEST 0 4000}}
test select-5.14 {Tk_GetSelection procedure} -constraints {
    x11 altDisplay
} -setup {
    selectionSetup .f1
    selectionSetup .f2 $env(TK_ALT_DISPLAY)
    childTkProcess create
} -body {
    selection handle -selection PRIMARY .f1 {handler TEST} TEST
    selection own .f1
    selection handle -selection PRIMARY .f2 {} TEST
    selection own .f2
    set selValue "Test value"
    set selInfo ""
    update
    set result ""
    lappend result [childTkProcess eval "toplevel .t -screen $env(TK_ALT_DISPLAY); wm geom .t +0+0; selection get -displayof .t TEST"]
    set selValue "Test value2"
    lappend result [childTkProcess eval "selection get TEST"]
    childTkProcess exit
    lappend result $selInfo
} -result {{PRIMARY selection doesn't exist or form "TEST" not defined} {Test value2} {TEST 0 4000}}
test select-5.15 {Tk_GetSelection procedure} -setup {
    selectionSetup
    if {[llength [info command ::bgerror]]} {
	rename ::bgerror ::TMPbgerror
    }
    set ::bgerrors {}
} -body {
    proc ::bgerror msg {lappend ::bgerrors $msg}
    selection handle -type ERROR .f1 errHandler
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
    selection
} -result {wrong # args: should be "selection option ?arg ...?"}
# selection clear
test select-6.2 {Tk_SelectionCmd procedure} -body {
    selection clear -selection
} -returnCodes error -result {value for "-selection" missing}
test select-6.3 {Tk_SelectionCmd procedure} -setup {
    setup
} -body {
    selection own .
    set result [selection own]
    selection clear -displayof .f1
    lappend result [selection own]
} -result {. {}}
test select-6.4 {Tk_SelectionCmd procedure} -setup {
    setup
} -body {
    selection own -selection CLIPBOARD .f1
    set result [list [selection own] [selection own -selection CLIPBOARD]]
    selection clear -selection CLIPBOARD .f1
    lappend result [selection own] [selection own -selection CLIPBOARD]
} -result {.f1 .f1 .f1 {}}
test select-6.5 {Tk_SelectionCmd procedure} -setup {
    setup
} -body {
    selection own -selection CLIPBOARD .
    set result [list [selection own] [selection own -selection CLIPBOARD]]
    selection clear -selection CLIPBOARD -displayof .f1
    lappend result [selection own] [selection own -selection CLIPBOARD]
} -result {.f1 . .f1 {}}
test select-6.6 {Tk_SelectionCmd procedure} -returnCodes error -body {







|







|







|







570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
    selection
} -result {wrong # args: should be "selection option ?arg ...?"}
# selection clear
test select-6.2 {Tk_SelectionCmd procedure} -body {
    selection clear -selection
} -returnCodes error -result {value for "-selection" missing}
test select-6.3 {Tk_SelectionCmd procedure} -setup {
    selectionSetup
} -body {
    selection own .
    set result [selection own]
    selection clear -displayof .f1
    lappend result [selection own]
} -result {. {}}
test select-6.4 {Tk_SelectionCmd procedure} -setup {
    selectionSetup
} -body {
    selection own -selection CLIPBOARD .f1
    set result [list [selection own] [selection own -selection CLIPBOARD]]
    selection clear -selection CLIPBOARD .f1
    lappend result [selection own] [selection own -selection CLIPBOARD]
} -result {.f1 .f1 .f1 {}}
test select-6.5 {Tk_SelectionCmd procedure} -setup {
    selectionSetup
} -body {
    selection own -selection CLIPBOARD .
    set result [list [selection own] [selection own -selection CLIPBOARD]]
    selection clear -selection CLIPBOARD -displayof .f1
    lappend result [selection own] [selection own -selection CLIPBOARD]
} -result {.f1 . .f1 {}}
test select-6.6 {Tk_SelectionCmd procedure} -returnCodes error -body {
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
    selection clear -displayof .f2
} -returnCodes error -result {bad window path name ".f2"}
test select-6.9 {Tk_SelectionCmd procedure} -body {
    destroy .f2
    selection clear .f2
} -returnCodes error -result {bad window path name ".f2"}
test select-6.10 {Tk_SelectionCmd procedure} -setup {
    setup
} -body {
    set result [selection own -selection PRIMARY]
    selection clear
    lappend result [selection own -selection PRIMARY]
} -result {.f1 {}}
test select-6.11 {Tk_SelectionCmd procedure} -setup {
    setup
} -body {
    selection own -selection CLIPBOARD .f1
    set result [selection own -selection CLIPBOARD]
    selection clear -selection CLIPBOARD
    lappend result [selection own -selection CLIPBOARD]
} -result {.f1 {}}
test select-6.12 {Tk_SelectionCmd procedure} -returnCodes error -body {
    selection clear foo bar
} -result {wrong # args: should be "selection clear ?-option value ...?"}
# selection get
test select-6.13 {Tk_SelectionCmd procedure} -body {
    selection get -selection
} -returnCodes error -result {value for "-selection" missing}
test select-6.14 {Tk_SelectionCmd procedure} -setup {
    global selValue selInfo
    setup
} -body {
    selection handle .f1 {handler TEST}
    set selValue "Test value"
    set selInfo ""
    list [selection get -displayof .f1] $selInfo
} -result {{Test value} {TEST 0 4000}}
test select-6.15 {Tk_SelectionCmd procedure} -setup {
    global selValue selInfo
    setup
} -body {
    selection handle .f1 {handler STRING}
    selection handle -selection CLIPBOARD .f1 {handler TEST}
    selection own -selection CLIPBOARD .f1
    set selValue "Test value"
    set selInfo ""
    list [selection get -selection CLIPBOARD] $selInfo
} -result {{Test value} {TEST 0 4000}}
test select-6.16 {Tk_SelectionCmd procedure} -setup {
    global selValue selInfo
    setup
} -body {
    selection handle -type TEST .f1 {handler TEST}
    selection handle -type STRING .f1 {handler STRING}
    set selValue "Test value"
    set selInfo ""
    list [selection get -type TEST] $selInfo
} -result {{Test value} {TEST 0 4000}}







|






|














<
|







<
|









<
|







608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636

637
638
639
640
641
642
643
644

645
646
647
648
649
650
651
652
653
654

655
656
657
658
659
660
661
662
    selection clear -displayof .f2
} -returnCodes error -result {bad window path name ".f2"}
test select-6.9 {Tk_SelectionCmd procedure} -body {
    destroy .f2
    selection clear .f2
} -returnCodes error -result {bad window path name ".f2"}
test select-6.10 {Tk_SelectionCmd procedure} -setup {
    selectionSetup
} -body {
    set result [selection own -selection PRIMARY]
    selection clear
    lappend result [selection own -selection PRIMARY]
} -result {.f1 {}}
test select-6.11 {Tk_SelectionCmd procedure} -setup {
    selectionSetup
} -body {
    selection own -selection CLIPBOARD .f1
    set result [selection own -selection CLIPBOARD]
    selection clear -selection CLIPBOARD
    lappend result [selection own -selection CLIPBOARD]
} -result {.f1 {}}
test select-6.12 {Tk_SelectionCmd procedure} -returnCodes error -body {
    selection clear foo bar
} -result {wrong # args: should be "selection clear ?-option value ...?"}
# selection get
test select-6.13 {Tk_SelectionCmd procedure} -body {
    selection get -selection
} -returnCodes error -result {value for "-selection" missing}
test select-6.14 {Tk_SelectionCmd procedure} -setup {

    selectionSetup
} -body {
    selection handle .f1 {handler TEST}
    set selValue "Test value"
    set selInfo ""
    list [selection get -displayof .f1] $selInfo
} -result {{Test value} {TEST 0 4000}}
test select-6.15 {Tk_SelectionCmd procedure} -setup {

    selectionSetup
} -body {
    selection handle .f1 {handler STRING}
    selection handle -selection CLIPBOARD .f1 {handler TEST}
    selection own -selection CLIPBOARD .f1
    set selValue "Test value"
    set selInfo ""
    list [selection get -selection CLIPBOARD] $selInfo
} -result {{Test value} {TEST 0 4000}}
test select-6.16 {Tk_SelectionCmd procedure} -setup {

    selectionSetup
} -body {
    selection handle -type TEST .f1 {handler TEST}
    selection handle -type STRING .f1 {handler STRING}
    set selValue "Test value"
    set selInfo ""
    list [selection get -type TEST] $selInfo
} -result {{Test value} {TEST 0 4000}}
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
    catch { destroy .f2 }
    selection get -displayof .f2
} -returnCodes error -result {bad window path name ".f2"}
test select-6.20 {Tk_SelectionCmd procedure} -returnCodes error -body {
    selection get foo bar
} -result {wrong # args: should be "selection get ?-option value ...?"}
test select-6.21 {Tk_SelectionCmd procedure} -setup {
    global selValue selInfo
    setup
} -body {
    selection handle -type TEST .f1 {handler TEST}
    selection handle -type STRING .f1 {handler STRING}
    set selValue "Test value"
    set selInfo ""
    list [selection get TEST] $selInfo
} -result {{Test value} {TEST 0 4000}}
# selection handle
# most of the handle section has been covered earlier
test select-6.22 {Tk_SelectionCmd procedure} -body {
    selection handle -selection
} -returnCodes error -result {value for "-selection" missing}
test select-6.23 {Tk_SelectionCmd procedure} -setup {
    global selValue selInfo
    setup
} -body {
    set selValue "Test value"
    set selInfo ""
    list [selection handle -format INTEGER .f1 {handler TEST}] [selection get -displayof .f1] $selInfo
} -result {{} {Test value} {TEST 0 4000}}
test select-6.24 {Tk_SelectionCmd procedure} -returnCodes error -body {
    selection handle -badopt foo







<
|













<
|







670
671
672
673
674
675
676

677
678
679
680
681
682
683
684
685
686
687
688
689
690

691
692
693
694
695
696
697
698
    catch { destroy .f2 }
    selection get -displayof .f2
} -returnCodes error -result {bad window path name ".f2"}
test select-6.20 {Tk_SelectionCmd procedure} -returnCodes error -body {
    selection get foo bar
} -result {wrong # args: should be "selection get ?-option value ...?"}
test select-6.21 {Tk_SelectionCmd procedure} -setup {

    selectionSetup
} -body {
    selection handle -type TEST .f1 {handler TEST}
    selection handle -type STRING .f1 {handler STRING}
    set selValue "Test value"
    set selInfo ""
    list [selection get TEST] $selInfo
} -result {{Test value} {TEST 0 4000}}
# selection handle
# most of the handle section has been covered earlier
test select-6.22 {Tk_SelectionCmd procedure} -body {
    selection handle -selection
} -returnCodes error -result {value for "-selection" missing}
test select-6.23 {Tk_SelectionCmd procedure} -setup {

    selectionSetup
} -body {
    set selValue "Test value"
    set selInfo ""
    list [selection handle -format INTEGER .f1 {handler TEST}] [selection get -displayof .f1] $selInfo
} -result {{} {Test value} {TEST 0 4000}}
test select-6.24 {Tk_SelectionCmd procedure} -returnCodes error -body {
    selection handle -badopt foo
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
    selection handle .f2 dummy
} -returnCodes error -result {bad window path name ".f2"}
# selection own
test select-6.30 {Tk_SelectionCmd procedure} -body {
    selection own -selection
} -returnCodes error -result {value for "-selection" missing}
test select-6.31 {Tk_SelectionCmd procedure} -setup {
    setup
} -body {
    selection own .
    selection own -displayof .f1
} -result {.}
test select-6.32 {Tk_SelectionCmd procedure} -setup {
    setup
} -body {
    selection own .
    selection own -selection CLIPBOARD .f1
    list [selection own] [selection own -selection CLIPBOARD]
} -result {. .f1}
test select-6.33 {Tk_SelectionCmd procedure} -setup {
    global lostSel
    setup
} -body {
    set lostSel owned
    selection own -command { set lostSel lost } .
    selection own -selection CLIPBOARD .f1
    set result $lostSel
    selection own .f1
    lappend result $lostSel







|





|







|







714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
    selection handle .f2 dummy
} -returnCodes error -result {bad window path name ".f2"}
# selection own
test select-6.30 {Tk_SelectionCmd procedure} -body {
    selection own -selection
} -returnCodes error -result {value for "-selection" missing}
test select-6.31 {Tk_SelectionCmd procedure} -setup {
    selectionSetup
} -body {
    selection own .
    selection own -displayof .f1
} -result {.}
test select-6.32 {Tk_SelectionCmd procedure} -setup {
    selectionSetup
} -body {
    selection own .
    selection own -selection CLIPBOARD .f1
    list [selection own] [selection own -selection CLIPBOARD]
} -result {. .f1}
test select-6.33 {Tk_SelectionCmd procedure} -setup {
    global lostSel
    selectionSetup
} -body {
    set lostSel owned
    selection own -command { set lostSel lost } .
    selection own -selection CLIPBOARD .f1
    set result $lostSel
    selection own .f1
    lappend result $lostSel
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965

##############################################################################

# This test is non-portable because some old X11/News servers ignore a
# selection request when the window doesn't exist, which causes a different
# error message.
test select-7.1 {TkSelDeadWindow procedure} -constraints nonPortable -setup {
    setup
} -body {
    selection handle .f1 { handler TEST }
    set result [selection own]
    destroy .f1
    lappend result [selection own] [catch {selection get} msg] $msg
} -result {.f1 {} 1 {PRIMARY selection doesn't exist or form "STRING" not defined}}

##############################################################################

# Check reentrancy on losing selection
test select-8.1 {TkSelEventProc procedure} -constraints x11 -setup {
    setup
    setupbg
} -body {
    selection own -selection CLIPBOARD -command {destroy .f1} .f1
    update
    dobg {selection own -selection CLIPBOARD .}
    winfo children .
} -cleanup {
    cleanupbg
} -result {}

##############################################################################

test select-9.1 {SelCvtToX and SelCvtFromX procedures} -setup {
    setup
    setupbg
} -constraints x11 -body {
    set selValue "1024"
    set selInfo ""
    selection handle -selection PRIMARY -format INTEGER -type TEST \
	.f1 {handler TEST}
    update
    set result ""
    lappend result [dobg {selection get TEST}]
    cleanupbg
    lappend result $selInfo
} -result {{0x400 } {TEST 0 4000}}
test select-9.2 {SelCvtToX and SelCvtFromX procedures} -setup {
    setup
    setupbg
} -constraints {x11 failsOnUbuntu} -body {
    set selValue "1024 0xffff  2048 -2  "
    set selInfo ""
    selection handle -selection PRIMARY -format INTEGER -type TEST \
	.f1 {handler TEST}
    set result ""
    lappend result [dobg {selection get TEST}]
    cleanupbg
    lappend result $selInfo
} -result {{0x400 0xffff 0x800 0xfffffffe } {TEST 0 4000}}
test select-9.3 {SelCvtToX and SelCvtFromX procedures} -setup {
    setup
    setupbg
} -constraints {x11 failsOnUbuntu} -body {
    set selValue "   "
    set selInfo ""
    selection handle -selection PRIMARY -format INTEGER -type TEST \
	.f1 {handler TEST}
    set result ""
    lappend result [dobg {selection get TEST}]
    cleanupbg
    lappend result $selInfo
} -result {{ } {TEST 0 4000}}
test select-9.4 {SelCvtToX and SelCvtFromX procedures} -setup {
    setup
    setupbg
} -constraints {x11 failsOnUbuntu} -body {
    set selValue "16 foobar 32"
    set selInfo ""
    selection handle -selection PRIMARY -format INTEGER -type TEST \
	.f1 {handler TEST}
    set result ""
    lappend result [dobg {selection get TEST}]
    cleanupbg
    lappend result $selInfo
} -result {{0x10 0x0 0x20 } {TEST 0 4000}}
test select-9.5 {SelCvtToX and SelCvtFromX procedures} -setup {
    setup
    setupbg
} -constraints x11 -body {
    # Ensure that lists of atoms are constructed correctly, even when the
    # atom names have spaces in. [Bug 1353414]
    set selValue "foo bar"
    set selInfo ""
    set selType {text/x-tk-test;detail="foo bar"}
    selection handle -selection PRIMARY -format STRING -type $selType \
    .f1 [list handler $selType]
    lsort [dobg {selection get TARGETS}]
} -cleanup {
    cleanupbg
} -result {MULTIPLE TARGETS TIMESTAMP TK_APPLICATION TK_WINDOW {text/x-tk-test;detail="foo bar"}}

##############################################################################
# note, we are not testing MULTIPLE style selections

# most control paths have been exercised above
test select-10.1 {ConvertSelection procedure, race with selection clear} -constraints {
    x11
} -setup {
    setup
} -body {
    proc Ready {fd} {
	variable x
	lappend x [gets $fd]
    }
    set fd [open "|[list [interpreter] -geometry +0+0 -name tktest]" r+]
    puts $fd "puts foo; [loadTkCommand]; flush stdout"







|











|
|



|


|





|
|







|
|



|
|






|
|



|
|






|
|



|
|






|
|



|
|








|

|









|







764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879

##############################################################################

# This test is non-portable because some old X11/News servers ignore a
# selection request when the window doesn't exist, which causes a different
# error message.
test select-7.1 {TkSelDeadWindow procedure} -constraints nonPortable -setup {
    selectionSetup
} -body {
    selection handle .f1 { handler TEST }
    set result [selection own]
    destroy .f1
    lappend result [selection own] [catch {selection get} msg] $msg
} -result {.f1 {} 1 {PRIMARY selection doesn't exist or form "STRING" not defined}}

##############################################################################

# Check reentrancy on losing selection
test select-8.1 {TkSelEventProc procedure} -constraints x11 -setup {
    selectionSetup
    childTkProcess create
} -body {
    selection own -selection CLIPBOARD -command {destroy .f1} .f1
    update
    childTkProcess eval {selection own -selection CLIPBOARD .}
    winfo children .
} -cleanup {
    childTkProcess exit
} -result {}

##############################################################################

test select-9.1 {SelCvtToX and SelCvtFromX procedures} -setup {
    selectionSetup
    childTkProcess create
} -constraints x11 -body {
    set selValue "1024"
    set selInfo ""
    selection handle -selection PRIMARY -format INTEGER -type TEST \
	.f1 {handler TEST}
    update
    set result ""
    lappend result [childTkProcess eval {selection get TEST}]
    childTkProcess exit
    lappend result $selInfo
} -result {{0x400 } {TEST 0 4000}}
test select-9.2 {SelCvtToX and SelCvtFromX procedures} -setup {
    selectionSetup
    childTkProcess create
} -constraints {x11 failsOnUbuntu} -body {
    set selValue "1024 0xffff  2048 -2  "
    set selInfo ""
    selection handle -selection PRIMARY -format INTEGER -type TEST \
	.f1 {handler TEST}
    set result ""
    lappend result [childTkProcess eval {selection get TEST}]
    childTkProcess exit
    lappend result $selInfo
} -result {{0x400 0xffff 0x800 0xfffffffe } {TEST 0 4000}}
test select-9.3 {SelCvtToX and SelCvtFromX procedures} -setup {
    selectionSetup
    childTkProcess create
} -constraints {x11 failsOnUbuntu} -body {
    set selValue "   "
    set selInfo ""
    selection handle -selection PRIMARY -format INTEGER -type TEST \
	.f1 {handler TEST}
    set result ""
    lappend result [childTkProcess eval {selection get TEST}]
    childTkProcess exit
    lappend result $selInfo
} -result {{ } {TEST 0 4000}}
test select-9.4 {SelCvtToX and SelCvtFromX procedures} -setup {
    selectionSetup
    childTkProcess create
} -constraints {x11 failsOnUbuntu} -body {
    set selValue "16 foobar 32"
    set selInfo ""
    selection handle -selection PRIMARY -format INTEGER -type TEST \
	.f1 {handler TEST}
    set result ""
    lappend result [childTkProcess eval {selection get TEST}]
    childTkProcess exit
    lappend result $selInfo
} -result {{0x10 0x0 0x20 } {TEST 0 4000}}
test select-9.5 {SelCvtToX and SelCvtFromX procedures} -setup {
    selectionSetup
    childTkProcess create
} -constraints x11 -body {
    # Ensure that lists of atoms are constructed correctly, even when the
    # atom names have spaces in. [Bug 1353414]
    set selValue "foo bar"
    set selInfo ""
    set selType {text/x-tk-test;detail="foo bar"}
    selection handle -selection PRIMARY -format STRING -type $selType \
    .f1 [list handler $selType]
    lsort [childTkProcess eval {selection get TARGETS}]
} -cleanup {
    childTkProcess exit
} -result {MULTIPLE TARGETS TIMESTAMP TK_APPLICATION TK_WINDOW {text/x-tk-test;detail="foo bar"}}

##############################################################################
# note, we are not testing MULTIPLE style selections

# most control paths have been exercised above
test select-10.1 {ConvertSelection procedure, race with selection clear} -constraints {
    x11
} -setup {
    selectionSetup
} -body {
    proc Ready {fd} {
	variable x
	lappend x [gets $fd]
    }
    set fd [open "|[list [interpreter] -geometry +0+0 -name tktest]" r+]
    puts $fd "puts foo; [loadTkCommand]; flush stdout"
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159

1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176


1177

1178
1179
1180
1181
1182
1183
    flush $fd
    # Don't understand why, but the [loadTkCommand] above causes
    # a "broken pipe" error when Tk was actually [load]ed in the child.
    catch {close $fd}
    lappend x $selInfo
} -result {{1:PRIMARY selection doesn't exist or form "STRING" not defined} {}}
test select-10.2 {ConvertSelection procedure} -constraints x11 -setup {
    setup
    setupbg
} -body {
    set selValue [string range $longValue 0 3999]
    set selInfo ""
    selection handle .f1 {handler STRING}
    set result ""
    lappend result [dobg {selection get}]
    cleanupbg
    lappend result $selInfo
} -result [list [string range $longValue 0 3999] {STRING 0 4000 STRING 4000 4000 STRING 0 4000 STRING 4000 4000}]
test select-10.3 {ConvertSelection procedure} -constraints x11 -setup {
    setup
    setupbg
} -body {
    selection handle .f1 ERROR errHandler
    dobg {selection get ERROR}
} -cleanup {
    cleanupbg
} -result {PRIMARY selection doesn't exist or form "ERROR" not defined}
# testing timers
# This one hangs in Exceed
test select-10.4 {ConvertSelection procedure} -constraints {
    x11 failsOnUbuntu
} -setup {
    setup
    setupbg
} -body {
    set selValue $longValue
    set selInfo ""
    selection handle .f1 {errIncrHandler STRING}
    set result ""
    set pass 0
    lappend result [dobg {selection get}]
    cleanupbg
    lappend result $selInfo
} -result {{selection owner didn't respond} {STRING 0 4000 STRING 4000 4000 STRING 8000 4000 STRING 12000 4000 STRING 16000 4000 STRING 0 4000 STRING 4000 4000}}
test select-10.5 {ConvertSelection procedure, reentrancy issues} -constraints {
    x11 failsOnUbuntu
} -setup {
    setup
    setupbg
} -body {
    set selValue "Test value"
    set selInfo ""
    selection handle -type TEST .f1 { handler TEST }
    selection handle -type STRING .f1 { badHandler .f1 STRING }
    set result ""
    lappend result [dobg {selection get}]
    cleanupbg
    lappend result $selInfo
} -result {{PRIMARY selection doesn't exist or form "STRING" not defined} {.f1 STRING 0 4000}}
test select-10.6 {ConvertSelection procedure, reentrancy issues} -constraints {
    x11 failsOnUbuntu
} -setup {
    setup
    setupbg
} -body {
    proc weirdHandler {type offset count} {
	destroy .f1
	handler $type $offset $count
    }
    set selValue $longValue
    set selInfo ""
    selection handle .f1 {weirdHandler STRING}
    set result ""
    lappend result [dobg {selection get}]
    cleanupbg
    lappend result $selInfo
} -cleanup {
    rename weirdHandler {}
} -result {{PRIMARY selection doesn't exist or form "STRING" not defined} {STRING 0 4000}}

##############################################################################

# testing reentrancy
test select-11.1 {TkSelPropProc procedure} -constraints {x11 failsOnUbuntu} -setup {
    setup
    setupbg
} -body {
    set selValue $longValue
    set selInfo ""
    selection handle -type TEST .f1 { handler TEST }
    selection handle -type STRING .f1 { reallyBadHandler .f1 STRING }
    set result ""
    set pass 0
    lappend result [dobg {selection get}]
    cleanupbg
    lappend result $selInfo
} -result {{selection owner didn't respond} {.f1 STRING 0 4000 .f1 STRING 4000 4000 .f1 STRING 8000 4000 .f1 STRING 12000 4000 .f1 STRING 16000 4000 .f1 STRING 0 4000 .f1 STRING 4000 4000}}

##############################################################################

# Note, this assumes we are using CurrentTtime
test select-12.1 {DefaultSelection procedure} -constraints x11 -body {
    setup
    set result [selection get -type TIMESTAMP]
    setupbg
    lappend result [dobg {selection get -type TIMESTAMP}]
    cleanupbg
    set result
} -result {0x0 {0x0 }}
test select-12.2 {DefaultSelection procedure} -constraints x11 -body {
    setup
    set result [lsort [list [selection get -type TARGETS]]]
    setupbg
    lappend result [dobg {lsort [selection get -type TARGETS]}]
    cleanupbg
    set result
} -result {{MULTIPLE TARGETS TIMESTAMP TK_APPLICATION TK_WINDOW} {MULTIPLE TARGETS TIMESTAMP TK_APPLICATION TK_WINDOW}}
test select-12.3 {DefaultSelection procedure} -constraints x11 -body {
    setup
    selection handle .f1 {handler TEST} TEST
    set result [list [lsort [selection get -type TARGETS]]]
    setupbg
    lappend result [dobg {lsort [selection get -type TARGETS]}]
    cleanupbg
    set result
} -result {{MULTIPLE TARGETS TEST TIMESTAMP TK_APPLICATION TK_WINDOW} {MULTIPLE TARGETS TEST TIMESTAMP TK_APPLICATION TK_WINDOW}}
test select-12.4 {DefaultSelection procedure} -constraints x11 -setup {
    setup
    set result ""
} -body {
    lappend result [selection get -type TK_APPLICATION]
    setupbg
    lappend result [dobg {selection get -type TK_APPLICATION}]
    cleanupbg
    set result
} -result [list [winfo name .] [winfo name .]]
test select-12.5 {DefaultSelection procedure} -constraints x11 -body {
    setup
    set result [selection get -type TK_WINDOW]
    setupbg
    lappend result [dobg {selection get -type TK_WINDOW}]
    cleanupbg
    set result
} -result {.f1 .f1}
test select-12.6 {DefaultSelection procedure} -body {
    setup
    selection handle .f1 {handler TARGETS.f1} TARGETS
    set selValue "Targets value"
    set selInfo ""
    set result [list [selection get TARGETS] $selInfo]
    selection handle .f1 {} TARGETS
    lappend result [selection get TARGETS]
} -result {{Targets value} {TARGETS.f1 0 4000} {MULTIPLE TARGETS TIMESTAMP TK_APPLICATION TK_WINDOW}}

test select-13.1 {SelectionSize procedure, handler deleted} -constraints {
    x11 failsOnUbuntu
} -setup {
    setup
    setupbg
} -body {
    proc badHandler {path type offset count} {
	global selValue selInfo abortCount
	incr abortCount -1
	if {$abortCount == 0} {
	    selection handle -type $type $path {}
	}
	lappend selInfo $path $type $offset $count
	set numBytes [expr {[string length $selValue] - $offset}]
	if {$numBytes <= 0} {
	    return ""
	}
	string range $selValue $offset [expr {$numBytes+$offset}]
    }
    set selValue $longValue
    set selInfo ""
    selection handle .f1 {badHandler .f1 STRING}
    set result ""
    set abortCount 2
    lappend result [dobg {selection get}]
    cleanupbg

    lappend result $selInfo
} -result {{PRIMARY selection doesn't exist or form "STRING" not defined} {.f1 STRING 0 4000 .f1 STRING 4000 4000}}

test select-14.1 {Bug [73ba07efcd]: Use correct property type when handling MULTIPLE conversion requests} -constraints {
    cliboardManagerPresent
} -setup {
    proc get_clip {offset maxChars} {return abcd}
} -body {
    selection handle -selection CLIPBOARD . get_clip
    selection own -selection CLIPBOARD .
    selection get -selection CLIPBOARD_MANAGER -type SAVE_TARGETS
    clipboard get
} -cleanup {
    rename get_clip {}
} -result {abcd}




# cleanup

cleanupTests
return

# Local Variables:
# mode: tcl
# End:







|
|





|
|



|
|


|

|






|
|






|
|





|
|






|
|





|
|









|
|









|
|







|
|







|

|
|
|



|

|
|
|



|


|
|
|



|



|
|
|



|

|
|
|



|











|
|

<
<
<
<
<
<
<
<
<
<
<
<
<


|


|
<
>















|
|
>
>
|
>






894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053













1054
1055
1056
1057
1058
1059

1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
    flush $fd
    # Don't understand why, but the [loadTkCommand] above causes
    # a "broken pipe" error when Tk was actually [load]ed in the child.
    catch {close $fd}
    lappend x $selInfo
} -result {{1:PRIMARY selection doesn't exist or form "STRING" not defined} {}}
test select-10.2 {ConvertSelection procedure} -constraints x11 -setup {
    selectionSetup
    childTkProcess create
} -body {
    set selValue [string range $longValue 0 3999]
    set selInfo ""
    selection handle .f1 {handler STRING}
    set result ""
    lappend result [childTkProcess eval {selection get}]
    childTkProcess exit
    lappend result $selInfo
} -result [list [string range $longValue 0 3999] {STRING 0 4000 STRING 4000 4000 STRING 0 4000 STRING 4000 4000}]
test select-10.3 {ConvertSelection procedure} -constraints x11 -setup {
    selectionSetup
    childTkProcess create
} -body {
    selection handle .f1 ERROR errHandler
    childTkProcess eval {selection get ERROR}
} -cleanup {
    childTkProcess exit
} -result {PRIMARY selection doesn't exist or form "ERROR" not defined}
# testing timers
# This one hangs in Exceed
test select-10.4 {ConvertSelection procedure} -constraints {
    x11 failsOnUbuntu
} -setup {
    selectionSetup
    childTkProcess create
} -body {
    set selValue $longValue
    set selInfo ""
    selection handle .f1 {errIncrHandler STRING}
    set result ""
    set pass 0
    lappend result [childTkProcess eval {selection get}]
    childTkProcess exit
    lappend result $selInfo
} -result {{selection owner didn't respond} {STRING 0 4000 STRING 4000 4000 STRING 8000 4000 STRING 12000 4000 STRING 16000 4000 STRING 0 4000 STRING 4000 4000}}
test select-10.5 {ConvertSelection procedure, reentrancy issues} -constraints {
    x11 failsOnUbuntu
} -setup {
    selectionSetup
    childTkProcess create
} -body {
    set selValue "Test value"
    set selInfo ""
    selection handle -type TEST .f1 { handler TEST }
    selection handle -type STRING .f1 { badHandler .f1 STRING }
    set result ""
    lappend result [childTkProcess eval {selection get}]
    childTkProcess exit
    lappend result $selInfo
} -result {{PRIMARY selection doesn't exist or form "STRING" not defined} {.f1 STRING 0 4000}}
test select-10.6 {ConvertSelection procedure, reentrancy issues} -constraints {
    x11 failsOnUbuntu
} -setup {
    selectionSetup
    childTkProcess create
} -body {
    proc weirdHandler {type offset count} {
	destroy .f1
	handler $type $offset $count
    }
    set selValue $longValue
    set selInfo ""
    selection handle .f1 {weirdHandler STRING}
    set result ""
    lappend result [childTkProcess eval {selection get}]
    childTkProcess exit
    lappend result $selInfo
} -cleanup {
    rename weirdHandler {}
} -result {{PRIMARY selection doesn't exist or form "STRING" not defined} {STRING 0 4000}}

##############################################################################

# testing reentrancy
test select-11.1 {TkSelPropProc procedure} -constraints {x11 failsOnUbuntu} -setup {
    selectionSetup
    childTkProcess create
} -body {
    set selValue $longValue
    set selInfo ""
    selection handle -type TEST .f1 { handler TEST }
    selection handle -type STRING .f1 { reallyBadHandler .f1 STRING }
    set result ""
    set pass 0
    lappend result [childTkProcess eval {selection get}]
    childTkProcess exit
    lappend result $selInfo
} -result {{selection owner didn't respond} {.f1 STRING 0 4000 .f1 STRING 4000 4000 .f1 STRING 8000 4000 .f1 STRING 12000 4000 .f1 STRING 16000 4000 .f1 STRING 0 4000 .f1 STRING 4000 4000}}

##############################################################################

# Note, this assumes we are using CurrentTtime
test select-12.1 {DefaultSelection procedure} -constraints x11 -body {
    selectionSetup
    set result [selection get -type TIMESTAMP]
    childTkProcess create
    lappend result [childTkProcess eval {selection get -type TIMESTAMP}]
    childTkProcess exit
    set result
} -result {0x0 {0x0 }}
test select-12.2 {DefaultSelection procedure} -constraints x11 -body {
    selectionSetup
    set result [lsort [list [selection get -type TARGETS]]]
    childTkProcess create
    lappend result [childTkProcess eval {lsort [selection get -type TARGETS]}]
    childTkProcess exit
    set result
} -result {{MULTIPLE TARGETS TIMESTAMP TK_APPLICATION TK_WINDOW} {MULTIPLE TARGETS TIMESTAMP TK_APPLICATION TK_WINDOW}}
test select-12.3 {DefaultSelection procedure} -constraints x11 -body {
    selectionSetup
    selection handle .f1 {handler TEST} TEST
    set result [list [lsort [selection get -type TARGETS]]]
    childTkProcess create
    lappend result [childTkProcess eval {lsort [selection get -type TARGETS]}]
    childTkProcess exit
    set result
} -result {{MULTIPLE TARGETS TEST TIMESTAMP TK_APPLICATION TK_WINDOW} {MULTIPLE TARGETS TEST TIMESTAMP TK_APPLICATION TK_WINDOW}}
test select-12.4 {DefaultSelection procedure} -constraints x11 -setup {
    selectionSetup
    set result ""
} -body {
    lappend result [selection get -type TK_APPLICATION]
    childTkProcess create
    lappend result [childTkProcess eval {selection get -type TK_APPLICATION}]
    childTkProcess exit
    set result
} -result [list [winfo name .] [winfo name .]]
test select-12.5 {DefaultSelection procedure} -constraints x11 -body {
    selectionSetup
    set result [selection get -type TK_WINDOW]
    childTkProcess create
    lappend result [childTkProcess eval {selection get -type TK_WINDOW}]
    childTkProcess exit
    set result
} -result {.f1 .f1}
test select-12.6 {DefaultSelection procedure} -body {
    selectionSetup
    selection handle .f1 {handler TARGETS.f1} TARGETS
    set selValue "Targets value"
    set selInfo ""
    set result [list [selection get TARGETS] $selInfo]
    selection handle .f1 {} TARGETS
    lappend result [selection get TARGETS]
} -result {{Targets value} {TARGETS.f1 0 4000} {MULTIPLE TARGETS TIMESTAMP TK_APPLICATION TK_WINDOW}}

test select-13.1 {SelectionSize procedure, handler deleted} -constraints {
    x11 failsOnUbuntu
} -setup {
    selectionSetup
    childTkProcess create
} -body {













    set selValue $longValue
    set selInfo ""
    selection handle .f1 {badHandler2 .f1 STRING}
    set result ""
    set abortCount 2
    lappend result [childTkProcess eval {selection get}]

    childTkProcess exit
    lappend result $selInfo
} -result {{PRIMARY selection doesn't exist or form "STRING" not defined} {.f1 STRING 0 4000 .f1 STRING 4000 4000}}

test select-14.1 {Bug [73ba07efcd]: Use correct property type when handling MULTIPLE conversion requests} -constraints {
    cliboardManagerPresent
} -setup {
    proc get_clip {offset maxChars} {return abcd}
} -body {
    selection handle -selection CLIPBOARD . get_clip
    selection own -selection CLIPBOARD .
    selection get -selection CLIPBOARD_MANAGER -type SAVE_TARGETS
    clipboard get
} -cleanup {
    rename get_clip {}
} -result {abcd}

#
# CLEANUP
#

testutils forget child select
cleanupTests
return

# Local Variables:
# mode: tcl
# End:
Changes to tests/send.test.
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
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.

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

testConstraint xhost [llength [auto_execok xhost]]
testConstraint failsOnUbuntu [expr {![info exists ::env(CI)] || ![string match Linux $::tcl_platform(os)]}]
testConstraint failsOnXQuarz [expr {$tcl_platform(os) ne "Darwin" || [tk windowingsystem] ne "x11" }]

# Compute a script that will load Tk into a child interpreter.

foreach pkg [info loaded] {
    if {[lindex $pkg 1] == "Tk"} {
	set loadTk "load $pkg"
	break
    }
}

# Procedure to create a new application with a given name and class.

proc newApp {screen name class} {
    global loadTk
    interp create $name
    $name eval [list set argv [list -display $screen -name $name -class $class]]
    eval $loadTk $name
}

set name [tk appname]
set commId ""
catch {
    set registry [testsend prop root InterpRegistry]
    set commId [lindex [testsend prop root InterpRegistry] 0]
}







<
<
<
|
<
|
<
<
<
<
|
<
|
<
<
<
<
<
<
<
<







10
11
12
13
14
15
16



17

18




19

20








21
22
23
24
25
26
27
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.

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




# Import utility procs for specific functional areas

testutils import child






testConstraint xhost [llength [auto_execok xhost]]









set name [tk appname]
set commId ""
catch {
    set registry [testsend prop root InterpRegistry]
    set commId [lindex [testsend prop root InterpRegistry] 0]
}
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
    winfo interps
} {test}

if {[testConstraint nonPortable] && [testConstraint xhost]} {
    winfo interps
    tk appname tktest
    update
    setupbg
    set x [split [exec xhost] \n]
    foreach i [lrange $x 1 end]  {
	exec xhost - $i
    }
}

test send-6.1 {ServerSecure procedure} {nonPortable secureserver} {
    set a 44
    list [dobg [list send [tk appname] set a 55]] $a
} {55 55}
test send-6.2 {ServerSecure procedure} {nonPortable secureserver xhost} {
    set a 22
    exec xhost [exec hostname]
    list [catch {dobg [list send [tk appname] set a 33]} msg] $a $msg
} {0 22 {X server insecure (must use xauth-style authorization); command ignored}}
test send-6.3 {ServerSecure procedure} {nonPortable secureserver xhost} {
    set a abc
    exec xhost - [exec hostname]
    list [dobg [list send [tk appname] set a new]] $a
} {new new}
cleanupbg

test send-7.1 {Tk_SetAppName procedure} {secureserver testsend} {
    testsend prop root InterpRegistry ""
    tk appname newName
    list [tk appname oldName] [testsend prop root InterpRegistry]
} "oldName {$commId oldName\n}"
test send-7.2 {Tk_SetAppName procedure, name not in use} {secureserver testsend} {







|








|




|




|

|







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
    winfo interps
} {test}

if {[testConstraint nonPortable] && [testConstraint xhost]} {
    winfo interps
    tk appname tktest
    update
    childTkProcess create
    set x [split [exec xhost] \n]
    foreach i [lrange $x 1 end]  {
	exec xhost - $i
    }
}

test send-6.1 {ServerSecure procedure} {nonPortable secureserver} {
    set a 44
    list [childTkProcess eval [list send [tk appname] set a 55]] $a
} {55 55}
test send-6.2 {ServerSecure procedure} {nonPortable secureserver xhost} {
    set a 22
    exec xhost [exec hostname]
    list [catch {childTkProcess eval [list send [tk appname] set a 33]} msg] $a $msg
} {0 22 {X server insecure (must use xauth-style authorization); command ignored}}
test send-6.3 {ServerSecure procedure} {nonPortable secureserver xhost} {
    set a abc
    exec xhost - [exec hostname]
    list [childTkProcess eval [list send [tk appname] set a new]] $a
} {new new}
childTkProcess exit

test send-7.1 {Tk_SetAppName procedure} {secureserver testsend} {
    testsend prop root InterpRegistry ""
    tk appname newName
    list [tk appname oldName] [testsend prop root InterpRegistry]
} "oldName {$commId oldName\n}"
test send-7.2 {Tk_SetAppName procedure, name not in use} {secureserver testsend} {
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
    tk appname name1
    testsend prop root InterpRegistry "$id foo\n$id foo #2\n$id foo #3\n"
    list [tk appname foo] [testsend prop root InterpRegistry]
} "{foo #4} {$commId foo #4\n$id foo\n$id foo #2\n$id foo #3\n}"

#macOS does not send to other processes
test send-8.1 {Tk_SendCmd procedure, options} {secureserver notAqua} {
    setupbg
    set app [dobg {tk appname}]
    set a 66
    send -async $app [list send [tk appname] set a 77]
    set result $a
    after 200 set x 40
    tkwait variable x
    cleanupbg
    lappend result $a
} {66 77}
test send-8.2 {Tk_SendCmd procedure, options} {secureserver altDisplay} {
    setupbg -display $env(TK_ALT_DISPLAY)
    tk appname xyzgorp
    set a homeDisplay
    set result [dobg "
    toplevel .t -screen [winfo screen .]
    wm geometry .t +0+0
    set a altDisplay
    tk appname xyzgorp
    list \[send xyzgorp set a\] \[send -displayof .t xyzgorp set a\]
    "]
    cleanupbg
    set result
} {altDisplay homeDisplay}
# Since macOS has no registry of interpreters, 8.3 and 8.10 will fail.
test send-8.3 {Tk_SendCmd procedure, options} {secureserver notAqua} {
    list [catch {send -- -async foo bar baz} msg] $msg
} {1 {no application named "-async"}}
test send-8.4 {Tk_SendCmd procedure, options} {secureserver} {







|
|





|



|


|






|







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
    tk appname name1
    testsend prop root InterpRegistry "$id foo\n$id foo #2\n$id foo #3\n"
    list [tk appname foo] [testsend prop root InterpRegistry]
} "{foo #4} {$commId foo #4\n$id foo\n$id foo #2\n$id foo #3\n}"

#macOS does not send to other processes
test send-8.1 {Tk_SendCmd procedure, options} {secureserver notAqua} {
    childTkProcess create
    set app [childTkProcess eval {tk appname}]
    set a 66
    send -async $app [list send [tk appname] set a 77]
    set result $a
    after 200 set x 40
    tkwait variable x
    childTkProcess exit
    lappend result $a
} {66 77}
test send-8.2 {Tk_SendCmd procedure, options} {secureserver altDisplay} {
    childTkProcess create -display $env(TK_ALT_DISPLAY)
    tk appname xyzgorp
    set a homeDisplay
    set result [childTkProcess eval "
    toplevel .t -screen [winfo screen .]
    wm geometry .t +0+0
    set a altDisplay
    tk appname xyzgorp
    list \[send xyzgorp set a\] \[send -displayof .t xyzgorp set a\]
    "]
    childTkProcess exit
    set result
} {altDisplay homeDisplay}
# Since macOS has no registry of interpreters, 8.3 and 8.10 will fail.
test send-8.3 {Tk_SendCmd procedure, options} {secureserver notAqua} {
    list [catch {send -- -async foo bar baz} msg] $msg
} {1 {no application named "-async"}}
test send-8.4 {Tk_SendCmd procedure, options} {secureserver} {
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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
    invoked from within
"send [tk appname] open bad_file"} {posix enoent {no such file or directory}}}
test send-8.10 {Tk_SendCmd procedure, no such interpreter} {secureserver notAqua} {
    list [catch {send bogus_name bogus_command} msg] $msg
} {1 {no application named "bogus_name"}}

catch {
    newApp "" t_s_1 Test
    t_s_1 eval wm withdraw .
}

test send-8.11 {Tk_SendCmd procedure, local execution, different interp} {secureserver testsend} {
    set a us
    send t_s_1 set a them
    list $a [send t_s_1 set a]
} {us them}
test send-8.12 {Tk_SendCmd procedure, local execution, different interp} {secureserver testsend} {
    set a us
    send t_s_1 {set a them}
    list $a [send t_s_1 {set a}]
} {us them}
test send-8.13 {Tk_SendCmd procedure, local execution, different interp} {secureserver testsend} {
    set a us
    send t_s_1 {set a them}
    list $a [send t_s_1 {set a}]
} {us them}
test send-8.14 {Tk_SendCmd procedure, local interp killed by send} {secureserver testsend} {
    newApp "" t_s_2 Test
    list [catch {send t_s_2 {destroy .; concat result}} msg] $msg
} {0 result}

catch {interp delete t_s_2}

test send-8.15 {Tk_SendCmd procedure, local interp, error info} {secureserver testsend failsOnUbuntu} {
    catch {error foo}
    list [catch {send t_s_1 {if 1 {open bogus_file_name}}} msg] $msg $errorInfo $errorCode
} {1 {couldn't open "bogus_file_name": no such file or directory} {couldn't open "bogus_file_name": no such file or directory
    while executing
"open bogus_file_name"
    invoked from within
"if 1 {open bogus_file_name}"
    invoked from within
"send t_s_1 {if 1 {open bogus_file_name}}"} {POSIX ENOENT {no such file or directory}}}
test send-8.16 {Tk_SendCmd procedure, bogusCommWindow} {secureserver testsend failsOnUbuntu failsOnXQuarz} {
    testsend prop root InterpRegistry "10234 bogus\n"
    set result [list [catch {send bogus bogus command} msg] $msg]
    winfo interps
    tk appname tktest
    set result
} {1 {no application named "bogus"}}

catch {interp delete t_s_1}

test send-8.17 {Tk_SendCmd procedure, deferring events} {secureserver nonPortable} {
    # Non-portable because some window managers ignore "raise"
    # requests so can't guarantee that new app's window won't
    # obscure .f, thereby masking the Expose event.

    setupbg
    set app [dobg {tk appname}]
    raise .		; # Don't want new app obscuring .f
    catch {destroy .f}
    frame .f
    place .f -x 0 -y 0
    bind .f <Expose> {set a exposed}
    set a {no event yet}
    set result ""
    lappend result [send $app send [list [tk appname]] set a]
    lappend result $a
    update
    cleanupbg
    lappend result $a
} {{no event yet} {no event yet} exposed}
test send-8.18 {Tk_SendCmd procedure, error in remote app} {secureserver} {
    setupbg
    set app [dobg {tk appname}]
    set result [string tolower [list [catch {send $app open bad_name} msg] \
	    $msg $errorInfo $errorCode]]
    cleanupbg
    set result
} {1 {couldn't open "bad_name": no such file or directory} {couldn't open "bad_name": no such file or directory
    while executing
"open bad_name"
    invoked from within
"send $app open bad_name"} {posix enoent {no such file or directory}}}
test send-8.19 {Tk_SendCmd, using modal timeouts} {secureserver} {
    setupbg
    set app [dobg {tk appname}]
    set x no
    set result ""
    after 0 {set x yes}
    lappend result [send $app {concat x y z}]
    lappend result $x
    update
    cleanupbg
    lappend result $x
} {{x y z} no yes}

tk appname tktest
catch {destroy .f}
frame .f
set id [string range [winfo id .f] 2 end]







|



















|















|














|
|










|



|
|


|







|
|






|







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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
    invoked from within
"send [tk appname] open bad_file"} {posix enoent {no such file or directory}}}
test send-8.10 {Tk_SendCmd procedure, no such interpreter} {secureserver notAqua} {
    list [catch {send bogus_name bogus_command} msg] $msg
} {1 {no application named "bogus_name"}}

catch {
    childTkInterp t_s_1 -class Test
    t_s_1 eval wm withdraw .
}

test send-8.11 {Tk_SendCmd procedure, local execution, different interp} {secureserver testsend} {
    set a us
    send t_s_1 set a them
    list $a [send t_s_1 set a]
} {us them}
test send-8.12 {Tk_SendCmd procedure, local execution, different interp} {secureserver testsend} {
    set a us
    send t_s_1 {set a them}
    list $a [send t_s_1 {set a}]
} {us them}
test send-8.13 {Tk_SendCmd procedure, local execution, different interp} {secureserver testsend} {
    set a us
    send t_s_1 {set a them}
    list $a [send t_s_1 {set a}]
} {us them}
test send-8.14 {Tk_SendCmd procedure, local interp killed by send} {secureserver testsend} {
    childTkInterp t_s_2 -class Test
    list [catch {send t_s_2 {destroy .; concat result}} msg] $msg
} {0 result}

catch {interp delete t_s_2}

test send-8.15 {Tk_SendCmd procedure, local interp, error info} {secureserver testsend failsOnUbuntu} {
    catch {error foo}
    list [catch {send t_s_1 {if 1 {open bogus_file_name}}} msg] $msg $errorInfo $errorCode
} {1 {couldn't open "bogus_file_name": no such file or directory} {couldn't open "bogus_file_name": no such file or directory
    while executing
"open bogus_file_name"
    invoked from within
"if 1 {open bogus_file_name}"
    invoked from within
"send t_s_1 {if 1 {open bogus_file_name}}"} {POSIX ENOENT {no such file or directory}}}
test send-8.16 {Tk_SendCmd procedure, bogusCommWindow} {secureserver testsend failsOnUbuntu failsOnXQuartz} {
    testsend prop root InterpRegistry "10234 bogus\n"
    set result [list [catch {send bogus bogus command} msg] $msg]
    winfo interps
    tk appname tktest
    set result
} {1 {no application named "bogus"}}

catch {interp delete t_s_1}

test send-8.17 {Tk_SendCmd procedure, deferring events} {secureserver nonPortable} {
    # Non-portable because some window managers ignore "raise"
    # requests so can't guarantee that new app's window won't
    # obscure .f, thereby masking the Expose event.

    childTkProcess create
    set app [childTkProcess eval {tk appname}]
    raise .		; # Don't want new app obscuring .f
    catch {destroy .f}
    frame .f
    place .f -x 0 -y 0
    bind .f <Expose> {set a exposed}
    set a {no event yet}
    set result ""
    lappend result [send $app send [list [tk appname]] set a]
    lappend result $a
    update
    childTkProcess exit
    lappend result $a
} {{no event yet} {no event yet} exposed}
test send-8.18 {Tk_SendCmd procedure, error in remote app} {secureserver} {
    childTkProcess create
    set app [childTkProcess eval {tk appname}]
    set result [string tolower [list [catch {send $app open bad_name} msg] \
	    $msg $errorInfo $errorCode]]
    childTkProcess exit
    set result
} {1 {couldn't open "bad_name": no such file or directory} {couldn't open "bad_name": no such file or directory
    while executing
"open bad_name"
    invoked from within
"send $app open bad_name"} {posix enoent {no such file or directory}}}
test send-8.19 {Tk_SendCmd, using modal timeouts} {secureserver} {
    childTkProcess create
    set app [childTkProcess eval {tk appname}]
    set x no
    set result ""
    after 0 {set x yes}
    lappend result [send $app {concat x y z}]
    lappend result $x
    update
    childTkProcess exit
    lappend result $x
} {{x y z} no yes}

tk appname tktest
catch {destroy .f}
frame .f
set id [string range [winfo id .f] 2 end]
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
    testsend prop comm Comm \
	    "r\n-i test1\n-e test2\n-c 4\n-s [testsend serial]\n"
    set errorCode oldErrorCode
    set errorInfo oldErrorInfo
    list [catch {send dummy foo} msg] $msg $errorInfo $errorCode
} {4 {} oldErrorInfo oldErrorCode}
test send-10.18 {SendEventProc procedure, send kills application} {secureserver testsend} {
    setupbg
    dobg {tk appname t_s_3}
    set x [list [catch {send t_s_3 destroy .} msg] $msg]
    cleanupbg
    set x
} {0 {}}
test send-10.19 {SendEventProc procedure, send exits} {secureserver testsend} {
    setupbg
    dobg {tk appname t_s_3}
    set x [list [catch {send t_s_3 exit} msg] $msg]
    cleanupbg
    set x
} {1 {target application died}}

test send-11.1 {AppendPropCarefully and AppendErrorProc procedures} -constraints {secureserver testsend} -body {
    testsend prop root InterpRegistry "0x21447 dummy\n"
    send dummy foo
} -returnCodes 1 -match regexp -result {^(target application died|no application named "dummy")$}







|
|

|



|
|

|







480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
    testsend prop comm Comm \
	    "r\n-i test1\n-e test2\n-c 4\n-s [testsend serial]\n"
    set errorCode oldErrorCode
    set errorInfo oldErrorInfo
    list [catch {send dummy foo} msg] $msg $errorInfo $errorCode
} {4 {} oldErrorInfo oldErrorCode}
test send-10.18 {SendEventProc procedure, send kills application} {secureserver testsend} {
    childTkProcess create
    childTkProcess eval {tk appname t_s_3}
    set x [list [catch {send t_s_3 destroy .} msg] $msg]
    childTkProcess exit
    set x
} {0 {}}
test send-10.19 {SendEventProc procedure, send exits} {secureserver testsend} {
    childTkProcess create
    childTkProcess eval {tk appname t_s_3}
    set x [list [catch {send t_s_3 exit} msg] $msg]
    childTkProcess exit
    set x
} {1 {target application died}}

test send-11.1 {AppendPropCarefully and AppendErrorProc procedures} -constraints {secureserver testsend} -body {
    testsend prop root InterpRegistry "0x21447 dummy\n"
    send dummy foo
} -returnCodes 1 -match regexp -result {^(target application died|no application named "dummy")$}
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610




611
612
613
614
615
616
617
618
619
620
621
catch {testsend prop root InterpRegistry ""}

#macOS does not send to other processes
test send-12.2 {TimeoutProc procedure} {secureserver notAqua} {
    winfo interps
    tk appname tktest
    update
    setupbg
    set app [dobg {
	after 10 {after 10 {after 5000; exit}}
	tk appname
    }]
    after 200
    set result [list [catch {send $app foo} msg] $msg]
    cleanupbg
    set result
} {1 {target application died}}

#macOS does not send to other processes
winfo interps
tk appname tktest
test send-13.1 {DeleteProc procedure} {secureserver notAqua} {
    setupbg
    set app [dobg {rename send {}; tk appname}]
    set result [list [catch {send $app foo} msg] $msg [winfo interps]]
    cleanupbg
    set result
} {1 {no application named "tktest #2"} tktest}
test send-13.2 {DeleteProc procedure} {secureserver notAqua} {
    winfo interps
    tk appname tktest
    rename send {}
    set result {}
    lappend result [winfo interps] [info commands send]
    tk appname foo
    lappend result [winfo interps] [info commands send]
} {{} {} foo send}

test send-14.1 {SendRestrictProc procedure, sends crossing from different displays} {secureserver altDisplay} {
    setupbg -display $env(TK_ALT_DISPLAY)
    set result [dobg "
    toplevel .t -screen [winfo screen .]
    wm geometry .t +0+0
    tk appname xyzgorp1
    set x child
    "]
    toplevel .t -screen $env(TK_ALT_DISPLAY)
    wm geometry .t +0+0
    tk appname xyzgorp2
    update
    set y parent
    set result [send -displayof .t xyzgorp1 {list $x [send -displayof .t xyzgorp2 set y]}]
    destroy .t
    cleanupbg
    set result
} {child parent}

catch {
    testsend prop root InterpRegister $registry
    tk appname tktest
}
test send-15.1 {UpdateCommWindow procedure} {secureserver testsend} {
    set x [list [testsend prop comm TK_APPLICATION]]
    newApp "" t_s_1 Test
    send t_s_1 wm withdraw .
    newApp "" t_s_2 Test
    send t_s_2 wm withdraw .
    lappend x [testsend prop comm TK_APPLICATION]
    interp delete t_s_1
    lappend x [testsend prop comm TK_APPLICATION]
    interp delete t_s_2
    lappend x [testsend prop comm TK_APPLICATION]
} {tktest {t_s_2 t_s_1 tktest} {t_s_2 tktest} tktest}





catch {
    tk appname $name
    testsend prop root InterpRegistry $registry
    testdeleteapps
}
rename newApp {}

# cleanup
cleanupTests
return







|
|





|







|
|

|













|
|












|









|

|







>
>
>
>






<

|


521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603

604
605
606
607
catch {testsend prop root InterpRegistry ""}

#macOS does not send to other processes
test send-12.2 {TimeoutProc procedure} {secureserver notAqua} {
    winfo interps
    tk appname tktest
    update
    childTkProcess create
    set app [childTkProcess eval {
	after 10 {after 10 {after 5000; exit}}
	tk appname
    }]
    after 200
    set result [list [catch {send $app foo} msg] $msg]
    childTkProcess exit
    set result
} {1 {target application died}}

#macOS does not send to other processes
winfo interps
tk appname tktest
test send-13.1 {DeleteProc procedure} {secureserver notAqua} {
    childTkProcess create
    set app [childTkProcess eval {rename send {}; tk appname}]
    set result [list [catch {send $app foo} msg] $msg [winfo interps]]
    childTkProcess exit
    set result
} {1 {no application named "tktest #2"} tktest}
test send-13.2 {DeleteProc procedure} {secureserver notAqua} {
    winfo interps
    tk appname tktest
    rename send {}
    set result {}
    lappend result [winfo interps] [info commands send]
    tk appname foo
    lappend result [winfo interps] [info commands send]
} {{} {} foo send}

test send-14.1 {SendRestrictProc procedure, sends crossing from different displays} {secureserver altDisplay} {
    childTkProcess create -display $env(TK_ALT_DISPLAY)
    set result [childTkProcess eval "
    toplevel .t -screen [winfo screen .]
    wm geometry .t +0+0
    tk appname xyzgorp1
    set x child
    "]
    toplevel .t -screen $env(TK_ALT_DISPLAY)
    wm geometry .t +0+0
    tk appname xyzgorp2
    update
    set y parent
    set result [send -displayof .t xyzgorp1 {list $x [send -displayof .t xyzgorp2 set y]}]
    destroy .t
    childTkProcess exit
    set result
} {child parent}

catch {
    testsend prop root InterpRegister $registry
    tk appname tktest
}
test send-15.1 {UpdateCommWindow procedure} {secureserver testsend} {
    set x [list [testsend prop comm TK_APPLICATION]]
    childTkInterp t_s_1 -class Test
    send t_s_1 wm withdraw .
    childTkInterp t_s_2 -class Test
    send t_s_2 wm withdraw .
    lappend x [testsend prop comm TK_APPLICATION]
    interp delete t_s_1
    lappend x [testsend prop comm TK_APPLICATION]
    interp delete t_s_2
    lappend x [testsend prop comm TK_APPLICATION]
} {tktest {t_s_2 t_s_1 tktest} {t_s_2 tktest} tktest}

#
# CLEANUP
#

catch {
    tk appname $name
    testsend prop root InterpRegistry $registry
    testdeleteapps
}


testutils forget child
cleanupTests
return
Changes to tests/spinbox.test.
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
# This file is a Tcl script to test spinbox widgets in Tk.  It is
# organized in the standard fashion for Tcl tests.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994-1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands

# For xscrollcommand
set scrollInfo {}
proc scroll args {
    global scrollInfo
    set scrollInfo $args
}
# For trace add variable
proc override args {
    global x
    set x 12345
}

# Procedures used in widget VALIDATION tests
proc doval {W d i P s S v V} {
    set ::vVals [list $W $d $i $P $s $S $v $V]
    return 1
}
proc doval2 {W d i P s S v V} {
    set ::vVals [list $W $d $i $P $s $S $v $V]
    set ::e mydata
    return 1
}
proc doval3 {W d i P s S v V} {
    set ::vVals [list $W $d $i $P $s $S $v $V]
    return 0
}

set cy [font metrics {Courier -12} -linespace]

test spinbox-1.1 {configuration option: "activebackground"} -setup {
    spinbox .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12} \
	    -relief sunken
    pack .e
    update
} -body {













<
<
|
|
<
|
<
<
<
<
<
|
<
<
|
<

<
<
|
<
|
<
<
<
<
<
<







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
# This file is a Tcl script to test spinbox widgets in Tk.  It is
# organized in the standard fashion for Tcl tests.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994-1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands



# Import utility procs for specific functional areas
testutils import entry scroll







foreach i {1 2 3} {


    set validateCmd$i [list validateCommand$i %W %d %i %P %s %S %v %V]

}


set cy [font metrics {Courier -12} -linespace]









test spinbox-1.1 {configuration option: "activebackground"} -setup {
    spinbox .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12} \
	    -relief sunken
    pack .e
    update
} -body {
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
} -cleanup {
    destroy .e
} -result 0123457890
test spinbox-3.24 {SpinboxWidgetCmd procedure, "delete" widget command} -setup {
    spinbox .e
    pack .e
    update
    set x {}
} -body {
# UTF
    .e insert end "01234乎67890"
    .e delete 6
    lappend x [.e get]
    .e delete 0 end
    .e insert end "012345乎7890"
    .e delete 6
    lappend x [.e get]
    .e delete 0 end
    .e insert end "0123456乎890"
    .e delete 6
    lappend x [.e get]
} -cleanup {
    destroy .e
} -result [list "01234乎7890" "0123457890" "012345乎890"]
test spinbox-3.25 {SpinboxWidgetCmd procedure, "delete" widget command} -setup {
    spinbox .e
    pack .e
    update







|




|



|



|







1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
} -cleanup {
    destroy .e
} -result 0123457890
test spinbox-3.24 {SpinboxWidgetCmd procedure, "delete" widget command} -setup {
    spinbox .e
    pack .e
    update
    set textVar {}
} -body {
# UTF
    .e insert end "01234乎67890"
    .e delete 6
    lappend textVar [.e get]
    .e delete 0 end
    .e insert end "012345乎7890"
    .e delete 6
    lappend textVar [.e get]
    .e delete 0 end
    .e insert end "0123456乎890"
    .e delete 6
    lappend textVar [.e get]
} -cleanup {
    destroy .e
} -result [list "01234乎7890" "0123457890" "012345乎890"]
test spinbox-3.25 {SpinboxWidgetCmd procedure, "delete" widget command} -setup {
    spinbox .e
    pack .e
    update
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
    .e insert end "This is quite a long text string, so long that it "
    .e insert end "runs off the end of the window quite a bit."
    .e insert 10 乎
    update
# UTF
# If Tcl_NumUtfChars wasn't used, wrong answer would be:
# 0.106383 0.117021 0.117021
    set x {}
    .e xview moveto .1
    lappend x [format {%.6f} [lindex [.e xview] 0]]
    .e xview moveto .11
    lappend x [format {%.6f} [lindex [.e xview] 0]]
    .e xview moveto .12
    lappend x [format {%.6f} [lindex [.e xview] 0]]
} -cleanup {
    destroy .e
} -result {0.095745 0.106383 0.117021}

test spinbox-3.82 {SpinboxWidgetCmd procedure} -setup {
    spinbox .e -font {Courier -12} -borderwidth 2 -highlightthickness 2
    pack .e
    update
} -body {
    .e gorp
} -cleanup {
    destroy .e
} -returnCodes error -result {bad option "gorp": must be bbox, cget, configure, delete, get, icursor, identify, index, insert, invoke, scan, selection, set, validate, or xview}

test spinbox-5.1 {ConfigureSpinbox procedure, -textvariable} -body {
    set x 12345
    spinbox .e -textvariable x
    .e get
} -cleanup {
    destroy .e
} -result 12345
test spinbox-5.2 {ConfigureSpinbox procedure, -textvariable} -body {
    set x 12345
    spinbox .e -textvariable x
    set y abcde
    .e configure -textvariable y
    set x 54321
    .e get
} -cleanup {
    destroy .e
} -result {abcde}
test spinbox-5.3 {ConfigureSpinbox procedure, -textvariable} -setup {
    unset -nocomplain x
    spinbox .e
} -body {
    .e insert 0 "Some text"
    .e configure -textvariable x
    set x
} -cleanup {
    destroy .e
} -result {Some text}
test spinbox-5.4 {ConfigureSpinbox procedure, -textvariable} -setup {
    unset -nocomplain x
    spinbox .e
} -body {
    trace add variable x write override
    .e insert 0 "Some text"
    .e configure -textvariable x
    list $x [.e get]
} -cleanup {
    destroy .e
    trace remove variable x write override
} -result {12345 12345}

test spinbox-5.5 {ConfigureSpinbox procedure} -setup {
    set x {}
    spinbox .e1
    spinbox .e2
} -body {
    .e2 insert end "This is some sample text"
    .e1 configure -exportselection false
    .e1 insert end "0123456789"
    pack .e1 .e2
    .e2 select from 0
    .e2 select to 10
    lappend x [selection get]
    .e1 select from 1
    .e1 select to 5
    lappend x [selection get]
    .e1 configure -exportselection 1
    lappend x [selection get]
    set x
} -cleanup {
    destroy .e1 .e2
} -result {{This is so} {This is so} 1234}
test spinbox-5.6 {ConfigureSpinbox procedure} -setup {
    spinbox .e
    pack .e
} -body {







|

|

|

|















|
|





|
|


|





|



|
|




|


|

|
|


|



|









|


|

|
|







1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
    .e insert end "This is quite a long text string, so long that it "
    .e insert end "runs off the end of the window quite a bit."
    .e insert 10 乎
    update
# UTF
# If Tcl_NumUtfChars wasn't used, wrong answer would be:
# 0.106383 0.117021 0.117021
    set textVar {}
    .e xview moveto .1
    lappend textVar [format {%.6f} [lindex [.e xview] 0]]
    .e xview moveto .11
    lappend textVar [format {%.6f} [lindex [.e xview] 0]]
    .e xview moveto .12
    lappend textVar [format {%.6f} [lindex [.e xview] 0]]
} -cleanup {
    destroy .e
} -result {0.095745 0.106383 0.117021}

test spinbox-3.82 {SpinboxWidgetCmd procedure} -setup {
    spinbox .e -font {Courier -12} -borderwidth 2 -highlightthickness 2
    pack .e
    update
} -body {
    .e gorp
} -cleanup {
    destroy .e
} -returnCodes error -result {bad option "gorp": must be bbox, cget, configure, delete, get, icursor, identify, index, insert, invoke, scan, selection, set, validate, or xview}

test spinbox-5.1 {ConfigureSpinbox procedure, -textvariable} -body {
    set textVar 12345
    spinbox .e -textvariable textVar
    .e get
} -cleanup {
    destroy .e
} -result 12345
test spinbox-5.2 {ConfigureSpinbox procedure, -textvariable} -body {
    set textVar 12345
    spinbox .e -textvariable textVar
    set y abcde
    .e configure -textvariable y
    set textVar 54321
    .e get
} -cleanup {
    destroy .e
} -result {abcde}
test spinbox-5.3 {ConfigureSpinbox procedure, -textvariable} -setup {
    unset -nocomplain textVar
    spinbox .e
} -body {
    .e insert 0 "Some text"
    .e configure -textvariable textVar
    set textVar
} -cleanup {
    destroy .e
} -result {Some text}
test spinbox-5.4 {ConfigureSpinbox procedure, -textvariable} -setup {
    unset -nocomplain textVar
    spinbox .e
} -body {
    trace add variable textVar write override
    .e insert 0 "Some text"
    .e configure -textvariable textVar
    list $textVar [.e get]
} -cleanup {
    destroy .e
    trace remove variable textVar write override
} -result {12345 12345}

test spinbox-5.5 {ConfigureSpinbox procedure} -setup {
    set textVar {}
    spinbox .e1
    spinbox .e2
} -body {
    .e2 insert end "This is some sample text"
    .e1 configure -exportselection false
    .e1 insert end "0123456789"
    pack .e1 .e2
    .e2 select from 0
    .e2 select to 10
    lappend textVar [selection get]
    .e1 select from 1
    .e1 select to 5
    lappend textVar [selection get]
    .e1 configure -exportselection 1
    lappend textVar [selection get]
    set textVar
} -cleanup {
    destroy .e1 .e2
} -result {{This is so} {This is so} 1234}
test spinbox-5.6 {ConfigureSpinbox procedure} -setup {
    spinbox .e
    pack .e
} -body {
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
    destroy .e
} -result {1 5}

test spinbox-5.7 {ConfigureSpinbox procedure} -setup {
    spinbox .e -font {Helvetica -12} -borderwidth 2 -highlightthickness 2
    pack .e
} -body {
    .e configure -font {Courier -12} -width 4 -xscrollcommand scroll
    .e insert end "01234567890"
    update
    set scrollInfo wrong
    .e configure -width 5
    update
    format {%.6f %.6f} {*}$scrollInfo
} -cleanup {







|







1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
    destroy .e
} -result {1 5}

test spinbox-5.7 {ConfigureSpinbox procedure} -setup {
    spinbox .e -font {Helvetica -12} -borderwidth 2 -highlightthickness 2
    pack .e
} -body {
    .e configure -font {Courier -12} -width 4 -xscrollcommand setScrollInfo
    .e insert end "01234567890"
    update
    set scrollInfo wrong
    .e configure -width 5
    update
    format {%.6f %.6f} {*}$scrollInfo
} -cleanup {
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315

test spinbox-7.1 {InsertChars procedure} -setup {
    unset -nocomplain contents
    spinbox .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e
    focus .e
} -body {
    .e configure -textvariable contents -xscrollcommand scroll
    .e insert 0 abcde
    update
    set scrollInfo wrong
    .e insert 2 XXX
    update
    list [.e get] $contents [format {%.6f %.6f} {*}$scrollInfo]
} -cleanup {
    destroy .e
} -result {abXXXcde abXXXcde {0.000000 1.000000}}

test spinbox-7.2 {InsertChars procedure} -setup {
    unset -nocomplain contents
    spinbox .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e
    focus .e
} -body {
    .e configure -textvariable contents -xscrollcommand scroll
    .e insert 0 abcde
    update
    set scrollInfo wrong
    .e insert 500 XXX
    update
    list [.e get] $contents [format {%.6f %.6f} {*}$scrollInfo]
} -cleanup {
    destroy .e
} -result {abcdeXXX abcdeXXX {0.000000 1.000000}}
test spinbox-7.3 {InsertChars procedure} -setup {
    spinbox .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e
} -body {
    .e insert 0 0123456789
    .e select from 2
    .e select to 6
    .e insert 2 XXX
    set x "[.e index sel.first] [.e index sel.last]"
    .e select to 8
    lappend x [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {5 9 5 8}
test spinbox-7.4 {InsertChars procedure} -setup {
    spinbox .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e
} -body {
    .e insert 0 0123456789
    .e select from 2
    .e select to 6
    .e insert 3 XXX
    set x "[.e index sel.first] [.e index sel.last]"
    .e select to 8
    lappend x [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {2 9 2 8}
test spinbox-7.5 {InsertChars procedure} -setup {
    spinbox .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e
} -body {
    .e insert 0 0123456789
    .e select from 2
    .e select to 6
    .e insert 5 XXX
    set x "[.e index sel.first] [.e index sel.last]"
    .e select to 8
    lappend x [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {2 9 2 8}
test spinbox-7.6 {InsertChars procedure} -setup {
    spinbox .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e
} -body {
    .e insert 0 0123456789
    .e select from 2
    .e select to 6
    .e insert 6 XXX
    set x "[.e index sel.first] [.e index sel.last]"
    .e select to 5
    lappend x [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {2 6 2 5}
test spinbox-7.7 {InsertChars procedure} -setup {
    spinbox .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e
} -body {
    .e configure -xscrollcommand scroll
    .e insert 0 0123456789
    .e icursor 4
    .e insert 4 XXX
    .e index insert
} -cleanup {
    destroy .e
} -result 7







|
















|

















|

|











|

|











|

|











|

|







|







2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295

test spinbox-7.1 {InsertChars procedure} -setup {
    unset -nocomplain contents
    spinbox .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e
    focus .e
} -body {
    .e configure -textvariable contents -xscrollcommand setScrollInfo
    .e insert 0 abcde
    update
    set scrollInfo wrong
    .e insert 2 XXX
    update
    list [.e get] $contents [format {%.6f %.6f} {*}$scrollInfo]
} -cleanup {
    destroy .e
} -result {abXXXcde abXXXcde {0.000000 1.000000}}

test spinbox-7.2 {InsertChars procedure} -setup {
    unset -nocomplain contents
    spinbox .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e
    focus .e
} -body {
    .e configure -textvariable contents -xscrollcommand setScrollInfo
    .e insert 0 abcde
    update
    set scrollInfo wrong
    .e insert 500 XXX
    update
    list [.e get] $contents [format {%.6f %.6f} {*}$scrollInfo]
} -cleanup {
    destroy .e
} -result {abcdeXXX abcdeXXX {0.000000 1.000000}}
test spinbox-7.3 {InsertChars procedure} -setup {
    spinbox .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e
} -body {
    .e insert 0 0123456789
    .e select from 2
    .e select to 6
    .e insert 2 XXX
    set textVar "[.e index sel.first] [.e index sel.last]"
    .e select to 8
    lappend textVar [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {5 9 5 8}
test spinbox-7.4 {InsertChars procedure} -setup {
    spinbox .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e
} -body {
    .e insert 0 0123456789
    .e select from 2
    .e select to 6
    .e insert 3 XXX
    set textVar "[.e index sel.first] [.e index sel.last]"
    .e select to 8
    lappend textVar [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {2 9 2 8}
test spinbox-7.5 {InsertChars procedure} -setup {
    spinbox .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e
} -body {
    .e insert 0 0123456789
    .e select from 2
    .e select to 6
    .e insert 5 XXX
    set textVar "[.e index sel.first] [.e index sel.last]"
    .e select to 8
    lappend textVar [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {2 9 2 8}
test spinbox-7.6 {InsertChars procedure} -setup {
    spinbox .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e
} -body {
    .e insert 0 0123456789
    .e select from 2
    .e select to 6
    .e insert 6 XXX
    set textVar "[.e index sel.first] [.e index sel.last]"
    .e select to 5
    lappend textVar [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {2 6 2 5}
test spinbox-7.7 {InsertChars procedure} -setup {
    spinbox .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e
} -body {
    .e configure -xscrollcommand setScrollInfo
    .e insert 0 0123456789
    .e icursor 4
    .e insert 4 XXX
    .e index insert
} -cleanup {
    destroy .e
} -result 7
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465

test spinbox-8.1 {DeleteChars procedure} -setup {
    unset -nocomplain contents
    spinbox .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e
    focus .e
} -body {
    .e configure -textvariable contents -xscrollcommand scroll
    .e insert 0 abcde
    update
    set scrollInfo wrong
    .e delete 2 4
    update
    list [.e get] $contents [format {%.6f %.6f} {*}$scrollInfo]
} -cleanup {
    destroy .e
} -result {abe abe {0.000000 1.000000}}
test spinbox-8.2 {DeleteChars procedure} -setup {
    unset -nocomplain contents
    spinbox .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e
    focus .e
} -body {
    .e configure -textvariable contents -xscrollcommand scroll
    .e insert 0 abcde
    update
    set scrollInfo wrong
    .e delete {} 2
    update
    list [.e get] $contents [format {%.6f %.6f} {*}$scrollInfo]
} -cleanup {
    destroy .e
} -result {cde cde {0.000000 1.000000}}
test spinbox-8.3 {DeleteChars procedure} -setup {
    unset -nocomplain contents
    spinbox .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e
    focus .e
} -body {
    .e configure -textvariable contents -xscrollcommand scroll
    .e insert 0 abcde
    update
    set scrollInfo wrong
    .e delete 3 1000
    update
    list [.e get] $contents [format {%.6f %.6f} {*}$scrollInfo]
} -cleanup {
    destroy .e
} -result {abc abc {0.000000 1.000000}}
test spinbox-8.4 {DeleteChars procedure} -setup {
    spinbox .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e
    focus .e
} -body {
    .e insert 0 0123456789abcde
    .e select from 3
    .e select to 8
    .e delete 1 3
    update
    set x "[.e index sel.first] [.e index sel.last]"
    .e select to 5
    lappend x [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {1 6 1 5}
test spinbox-8.5 {DeleteChars procedure} -setup {
    spinbox .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e
    focus .e
} -body {
    .e insert 0 0123456789abcde
    .e select from 3
    .e select to 8
    .e delete 1 4
    update
    set x "[.e index sel.first] [.e index sel.last]"
    .e select to 4
    lappend x [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {1 5 1 4}
test spinbox-8.6 {DeleteChars procedure} -setup {
    spinbox .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e
    focus .e
} -body {
    .e insert 0 0123456789abcde
    .e select from 3
    .e select to 8
    .e delete 1 7
    update
    set x "[.e index sel.first] [.e index sel.last]"
    .e select to 5
    lappend x [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {1 2 1 5}
test spinbox-8.7 {DeleteChars procedure} -setup {
    spinbox .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e
    focus .e







|















|















|



















|

|













|

|













|

|







2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445

test spinbox-8.1 {DeleteChars procedure} -setup {
    unset -nocomplain contents
    spinbox .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e
    focus .e
} -body {
    .e configure -textvariable contents -xscrollcommand setScrollInfo
    .e insert 0 abcde
    update
    set scrollInfo wrong
    .e delete 2 4
    update
    list [.e get] $contents [format {%.6f %.6f} {*}$scrollInfo]
} -cleanup {
    destroy .e
} -result {abe abe {0.000000 1.000000}}
test spinbox-8.2 {DeleteChars procedure} -setup {
    unset -nocomplain contents
    spinbox .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e
    focus .e
} -body {
    .e configure -textvariable contents -xscrollcommand setScrollInfo
    .e insert 0 abcde
    update
    set scrollInfo wrong
    .e delete {} 2
    update
    list [.e get] $contents [format {%.6f %.6f} {*}$scrollInfo]
} -cleanup {
    destroy .e
} -result {cde cde {0.000000 1.000000}}
test spinbox-8.3 {DeleteChars procedure} -setup {
    unset -nocomplain contents
    spinbox .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e
    focus .e
} -body {
    .e configure -textvariable contents -xscrollcommand setScrollInfo
    .e insert 0 abcde
    update
    set scrollInfo wrong
    .e delete 3 1000
    update
    list [.e get] $contents [format {%.6f %.6f} {*}$scrollInfo]
} -cleanup {
    destroy .e
} -result {abc abc {0.000000 1.000000}}
test spinbox-8.4 {DeleteChars procedure} -setup {
    spinbox .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e
    focus .e
} -body {
    .e insert 0 0123456789abcde
    .e select from 3
    .e select to 8
    .e delete 1 3
    update
    set textVar "[.e index sel.first] [.e index sel.last]"
    .e select to 5
    lappend textVar [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {1 6 1 5}
test spinbox-8.5 {DeleteChars procedure} -setup {
    spinbox .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e
    focus .e
} -body {
    .e insert 0 0123456789abcde
    .e select from 3
    .e select to 8
    .e delete 1 4
    update
    set textVar "[.e index sel.first] [.e index sel.last]"
    .e select to 4
    lappend textVar [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {1 5 1 4}
test spinbox-8.6 {DeleteChars procedure} -setup {
    spinbox .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e
    focus .e
} -body {
    .e insert 0 0123456789abcde
    .e select from 3
    .e select to 8
    .e delete 1 7
    update
    set textVar "[.e index sel.first] [.e index sel.last]"
    .e select to 5
    lappend textVar [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {1 2 1 5}
test spinbox-8.7 {DeleteChars procedure} -setup {
    spinbox .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e
    focus .e
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
    focus .e
} -body {
    .e insert 0 0123456789abcde
    .e select from 3
    .e select to 8
    .e delete 3 7
    update
    set x "[.e index sel.first] [.e index sel.last]"
    .e select to 8
    lappend x [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {3 4 3 8}
test spinbox-8.9 {DeleteChars procedure} -setup {
    spinbox .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e
} -body {







|

|







2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
    focus .e
} -body {
    .e insert 0 0123456789abcde
    .e select from 3
    .e select to 8
    .e delete 3 7
    update
    set textVar "[.e index sel.first] [.e index sel.last]"
    .e select to 8
    lappend textVar [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {3 4 3 8}
test spinbox-8.9 {DeleteChars procedure} -setup {
    spinbox .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e
} -body {
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
    focus .e
} -body {
    .e insert 0 0123456789abcde
    .e select from 8
    .e select to 3
    .e delete 5 8
    update
    set x "[.e index sel.first] [.e index sel.last]"
    .e select to 8
    lappend x [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {3 5 5 8}
test spinbox-8.11 {DeleteChars procedure} -setup {
    spinbox .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e
    focus .e
} -body {
    .e insert 0 0123456789abcde
    .e select from 8
    .e select to 3
    .e delete 8 10
    update
    set x "[.e index sel.first] [.e index sel.last]"
    .e select to 4
    lappend x [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {3 8 4 8}
test spinbox-8.12 {DeleteChars procedure} -setup {
    spinbox .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e
    focus .e







|

|













|

|







2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
    focus .e
} -body {
    .e insert 0 0123456789abcde
    .e select from 8
    .e select to 3
    .e delete 5 8
    update
    set textVar "[.e index sel.first] [.e index sel.last]"
    .e select to 8
    lappend textVar [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {3 5 5 8}
test spinbox-8.11 {DeleteChars procedure} -setup {
    spinbox .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e
    focus .e
} -body {
    .e insert 0 0123456789abcde
    .e select from 8
    .e select to 3
    .e delete 8 10
    update
    set textVar "[.e index sel.first] [.e index sel.last]"
    .e select to 4
    lappend textVar [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {3 8 4 8}
test spinbox-8.12 {DeleteChars procedure} -setup {
    spinbox .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e
    focus .e
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
    expr {[winfo reqwidth .e] == $expected}
} -cleanup {
    destroy .e
    unset XPAD buttonWidth expected
} -result {1}

test spinbox-9.1 {SpinboxValueChanged procedure} -setup {
    unset -nocomplain x
} -body {
    trace add variable x write override
    spinbox .e -textvariable x -width 0
    .e insert 0 foo
    list $x [.e get]
} -cleanup {
    destroy .e
    trace remove variable x write override
} -result {12345 12345}


test spinbox-10.1 {SpinboxSetValue procedure} -constraints fonts -body {
    set x abcde
    set y ab
    spinbox .e  -font {Helvetica -12} -highlightthickness 2 -bd 2  -width 0
    pack .e
    .e configure -textvariable x
    .e configure -textvariable y
    update
    list [.e get] [winfo reqwidth .e]
} -cleanup {
    destroy .e
} -result {ab 35}
test spinbox-10.2 {SpinboxSetValue procedure, updating selection} -setup {
    unset -nocomplain x
    spinbox .e -font {Helvetica -12} -highlightthickness 2 -bd 2
    pack .e
} -body {
    .e configure -textvariable x
    .e insert 0 "abcdefghjklmnopqrstu"
    .e selection range 4 10
    set x "a"
    .e index sel.first
} -cleanup {
    destroy .e
} -returnCodes error -result {selection isn't in widget .e}
test spinbox-10.3 {SpinboxSetValue procedure, updating selection} -setup {
    unset -nocomplain x
    spinbox .e -font {Helvetica -12} -highlightthickness 2 -bd 2
    pack .e
} -body {
    .e configure -textvariable x
    .e insert 0 "abcdefghjklmnopqrstu"
    .e selection range 4 10
    set x "abcdefg"
    list [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {4 7}
test spinbox-10.4 {SpinboxSetValue procedure, updating selection} -setup {
    unset -nocomplain x
    spinbox .e -font {Helvetica -12} -highlightthickness 2 -bd 2
    pack .e
} -body {
    .e configure -textvariable x
    .e insert 0 "abcdefghjklmnopqrstu"
    .e selection range 4 10
    set x "abcdefghijklmn"
    list [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {4 10}
test spinbox-10.5 {SpinboxSetValue procedure, updating display position} -setup {
    unset -nocomplain x
    spinbox .e -highlightthickness 2 -bd 2
    pack .e
} -body {
    .e configure -width 10 -font {Courier -12} -textvariable x
    .e insert 0 "abcdefghjklmnopqrstuvwxyz"
    .e xview 10
    update
    set x "abcdefg"
    update
    .e index @0
} -cleanup {
    destroy .e
} -result 0
test spinbox-10.6 {SpinboxSetValue procedure, updating display position} -setup {
    unset -nocomplain x
    spinbox .e -highlightthickness 2 -bd 2
    pack .e
} -body {
    .e configure -width 10 -font {Courier -12} -textvariable x
    pack .e
    .e insert 0 "abcdefghjklmnopqrstuvwxyz"
    .e xview 10
    update
    set x "1234567890123456789012"
    update
    .e index @0
} -cleanup {
    destroy .e
} -result 10
test spinbox-10.7 {SpinboxSetValue procedure, updating insertion cursor} -setup {
    unset -nocomplain x
    spinbox .e -highlightthickness 2 -bd 2
    pack .e
    update
} -body {
    .e configure -width 10 -font {Courier -12} -textvariable x
    pack .e
    .e insert 0 "abcdefghjklmnopqrstuvwxyz"
    .e icursor 5
    set x "123"
    .e index insert
} -cleanup {
    destroy .e
} -result 3
test spinbox-10.8 {SpinboxSetValue procedure, updating insertion cursor} -setup {
    unset -nocomplain x
    spinbox .e -highlightthickness 2 -bd 2
    pack .e
} -body {
    .e configure -width 10 -font {Courier -12} -textvariable x
    pack .e
    .e insert 0 "abcdefghjklmnopqrstuvwxyz"
    .e icursor 5
    set x "123456"
    .e index insert
} -cleanup {
    destroy .e
} -result 5

test spinbox-11.1 {SpinboxEventProc procedure} -setup {
    spinbox .e -highlightthickness 2 -bd 2 -font {Helvetica -12}
    pack .e
} -body {
    .e insert 0 abcdefg
    destroy .e
    update
} -cleanup {
    destroy .e
} -result {}
test spinbox-11.2 {SpinboxEventProc procedure} -setup {
    set x {}
} -body {
    spinbox .e1 -fg #112233
    rename .e1 .e2
    lappend x [winfo children .]
    lappend x [.e2 cget -fg]
    destroy .e1
    lappend x [info command .e*] [winfo children .]
} -cleanup {
    destroy .e1
} -result {.e1 #112233 {} {}}

test spinbox-12.1 {SpinboxCmdDeletedProc procedure} -body {
    button .b -text "xyz_123"
    rename .b {}







|

|
|

|


|




|



|







|



|


|





|



|


|





|



|


|





|



|



|






|



|




|






|




|



|





|



|



|
















|



|
|

|







2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
    expr {[winfo reqwidth .e] == $expected}
} -cleanup {
    destroy .e
    unset XPAD buttonWidth expected
} -result {1}

test spinbox-9.1 {SpinboxValueChanged procedure} -setup {
    unset -nocomplain textVar
} -body {
    trace add variable textVar write override
    spinbox .e -textvariable textVar -width 0
    .e insert 0 foo
    list $textVar [.e get]
} -cleanup {
    destroy .e
    trace remove variable textVar write override
} -result {12345 12345}


test spinbox-10.1 {SpinboxSetValue procedure} -constraints fonts -body {
    set textVar abcde
    set y ab
    spinbox .e  -font {Helvetica -12} -highlightthickness 2 -bd 2  -width 0
    pack .e
    .e configure -textvariable textVar
    .e configure -textvariable y
    update
    list [.e get] [winfo reqwidth .e]
} -cleanup {
    destroy .e
} -result {ab 35}
test spinbox-10.2 {SpinboxSetValue procedure, updating selection} -setup {
    unset -nocomplain textVar
    spinbox .e -font {Helvetica -12} -highlightthickness 2 -bd 2
    pack .e
} -body {
    .e configure -textvariable textVar
    .e insert 0 "abcdefghjklmnopqrstu"
    .e selection range 4 10
    set textVar "a"
    .e index sel.first
} -cleanup {
    destroy .e
} -returnCodes error -result {selection isn't in widget .e}
test spinbox-10.3 {SpinboxSetValue procedure, updating selection} -setup {
    unset -nocomplain textVar
    spinbox .e -font {Helvetica -12} -highlightthickness 2 -bd 2
    pack .e
} -body {
    .e configure -textvariable textVar
    .e insert 0 "abcdefghjklmnopqrstu"
    .e selection range 4 10
    set textVar "abcdefg"
    list [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {4 7}
test spinbox-10.4 {SpinboxSetValue procedure, updating selection} -setup {
    unset -nocomplain textVar
    spinbox .e -font {Helvetica -12} -highlightthickness 2 -bd 2
    pack .e
} -body {
    .e configure -textvariable textVar
    .e insert 0 "abcdefghjklmnopqrstu"
    .e selection range 4 10
    set textVar "abcdefghijklmn"
    list [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {4 10}
test spinbox-10.5 {SpinboxSetValue procedure, updating display position} -setup {
    unset -nocomplain textVar
    spinbox .e -highlightthickness 2 -bd 2
    pack .e
} -body {
    .e configure -width 10 -font {Courier -12} -textvariable textVar
    .e insert 0 "abcdefghjklmnopqrstuvwxyz"
    .e xview 10
    update
    set textVar "abcdefg"
    update
    .e index @0
} -cleanup {
    destroy .e
} -result 0
test spinbox-10.6 {SpinboxSetValue procedure, updating display position} -setup {
    unset -nocomplain textVar
    spinbox .e -highlightthickness 2 -bd 2
    pack .e
} -body {
    .e configure -width 10 -font {Courier -12} -textvariable textVar
    pack .e
    .e insert 0 "abcdefghjklmnopqrstuvwxyz"
    .e xview 10
    update
    set textVar "1234567890123456789012"
    update
    .e index @0
} -cleanup {
    destroy .e
} -result 10
test spinbox-10.7 {SpinboxSetValue procedure, updating insertion cursor} -setup {
    unset -nocomplain textVar
    spinbox .e -highlightthickness 2 -bd 2
    pack .e
    update
} -body {
    .e configure -width 10 -font {Courier -12} -textvariable textVar
    pack .e
    .e insert 0 "abcdefghjklmnopqrstuvwxyz"
    .e icursor 5
    set textVar "123"
    .e index insert
} -cleanup {
    destroy .e
} -result 3
test spinbox-10.8 {SpinboxSetValue procedure, updating insertion cursor} -setup {
    unset -nocomplain textVar
    spinbox .e -highlightthickness 2 -bd 2
    pack .e
} -body {
    .e configure -width 10 -font {Courier -12} -textvariable textVar
    pack .e
    .e insert 0 "abcdefghjklmnopqrstuvwxyz"
    .e icursor 5
    set textVar "123456"
    .e index insert
} -cleanup {
    destroy .e
} -result 5

test spinbox-11.1 {SpinboxEventProc procedure} -setup {
    spinbox .e -highlightthickness 2 -bd 2 -font {Helvetica -12}
    pack .e
} -body {
    .e insert 0 abcdefg
    destroy .e
    update
} -cleanup {
    destroy .e
} -result {}
test spinbox-11.2 {SpinboxEventProc procedure} -setup {
    set textVar {}
} -body {
    spinbox .e1 -fg #112233
    rename .e1 .e2
    lappend textVar [winfo children .]
    lappend textVar [.e2 cget -fg]
    destroy .e1
    lappend textVar [info command .e*] [winfo children .]
} -cleanup {
    destroy .e1
} -result {.e1 #112233 {} {}}

test spinbox-12.1 {SpinboxCmdDeletedProc procedure} -body {
    button .b -text "xyz_123"
    rename .b {}
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
    .e select from 1
    .e select to 18
    selection get
} -cleanup {
    destroy .e
} -result {his is a test str}
test spinbox-14.3 {SpinboxFetchSelection procedure} -setup {
    set x {}
    for {set i 1} {$i <= 500} {incr i} {
	append x "This is line $i, out of 500\n"
}
} -body {
    spinbox .e
    .e insert end $x
    .e select from 0
    .e select to end
    string compare [selection get] $x
} -cleanup {
    destroy .e
} -result 0

test spinbox-15.1 {SpinboxLostSelection} -body {
    spinbox .e
    .e insert 0 "Text"







|

|



|


|







3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
    .e select from 1
    .e select to 18
    selection get
} -cleanup {
    destroy .e
} -result {his is a test str}
test spinbox-14.3 {SpinboxFetchSelection procedure} -setup {
    set textVar {}
    for {set i 1} {$i <= 500} {incr i} {
	append textVar "This is line $i, out of 500\n"
}
} -body {
    spinbox .e
    .e insert end $textVar
    .e select from 0
    .e select to end
    string compare [selection get] $textVar
} -cleanup {
    destroy .e
} -result 0

test spinbox-15.1 {SpinboxLostSelection} -body {
    spinbox .e
    .e insert 0 "Text"
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
    format {%.6f %.6f} {*}[.e xview]
} -cleanup {
    destroy .e
} -result {0.000000 1.000000}


test spinbox-17.1 {SpinboxUpdateScrollbar procedure} -body {
    spinbox .e -width 10 -xscrollcommand scroll -font {Courier -12}
    pack .e
    update
    set scrollInfo wrong
    .e delete 0 end
    .e insert 0 123
    update
    format {%.6f %.6f} {*}$scrollInfo
} -cleanup {
    destroy .e
} -result {0.000000 1.000000}
test spinbox-17.2 {SpinboxUpdateScrollbar procedure} -body {
    spinbox .e -width 10 -xscrollcommand scroll -font {Courier -12}
    pack .e
    .e insert 0 0123456789abcdef
    update
    set scrollInfo wrong
    .e xview 3
    update
    format {%.6f %.6f} {*}$scrollInfo
} -cleanup {
    destroy .e
} -result {0.187500 0.812500}
test spinbox-17.3 {SpinboxUpdateScrollbar procedure} -body {
    spinbox .e -width 10 -xscrollcommand scroll -font {Courier -12}
    pack .e
    update
    set scrollInfo wrong
    .e insert 0 abcdefghijklmnopqrs
    .e xview
    update
    format {%.6f %.6f} {*}$scrollInfo
} -cleanup {
    destroy .e
} -result {0.000000 0.526316}
test spinbox-17.4 {SpinboxUpdateScrollbar procedure} -setup {
    proc bgerror msg {
	global x
	set x $msg
}
} -body {
    spinbox .e -width 5
    pack .e
    update
    set scrollInfo wrong
    .e configure -xscrollcommand thisisnotacommand
    update
    list $x $errorInfo
} -cleanup {
    destroy .e
    rename bgerror {}
} -result {{invalid command name "thisisnotacommand"} {invalid command name "thisisnotacommand"
    while executing
"thisisnotacommand 0.0 1.0"
    (horizontal scrolling command executed by .e)}}







|











|











|












|
|








|







3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
    format {%.6f %.6f} {*}[.e xview]
} -cleanup {
    destroy .e
} -result {0.000000 1.000000}


test spinbox-17.1 {SpinboxUpdateScrollbar procedure} -body {
    spinbox .e -width 10 -xscrollcommand setScrollInfo -font {Courier -12}
    pack .e
    update
    set scrollInfo wrong
    .e delete 0 end
    .e insert 0 123
    update
    format {%.6f %.6f} {*}$scrollInfo
} -cleanup {
    destroy .e
} -result {0.000000 1.000000}
test spinbox-17.2 {SpinboxUpdateScrollbar procedure} -body {
    spinbox .e -width 10 -xscrollcommand setScrollInfo -font {Courier -12}
    pack .e
    .e insert 0 0123456789abcdef
    update
    set scrollInfo wrong
    .e xview 3
    update
    format {%.6f %.6f} {*}$scrollInfo
} -cleanup {
    destroy .e
} -result {0.187500 0.812500}
test spinbox-17.3 {SpinboxUpdateScrollbar procedure} -body {
    spinbox .e -width 10 -xscrollcommand setScrollInfo -font {Courier -12}
    pack .e
    update
    set scrollInfo wrong
    .e insert 0 abcdefghijklmnopqrs
    .e xview
    update
    format {%.6f %.6f} {*}$scrollInfo
} -cleanup {
    destroy .e
} -result {0.000000 0.526316}
test spinbox-17.4 {SpinboxUpdateScrollbar procedure} -setup {
    proc bgerror msg {
	global textVar
	set textVar $msg
}
} -body {
    spinbox .e -width 5
    pack .e
    update
    set scrollInfo wrong
    .e configure -xscrollcommand thisisnotacommand
    update
    list $textVar $errorInfo
} -cleanup {
    destroy .e
    rename bgerror {}
} -result {{invalid command name "thisisnotacommand"} {invalid command name "thisisnotacommand"
    while executing
"thisisnotacommand 0.0 1.0"
    (horizontal scrolling command executed by .e)}}
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
# The validation tests build each one upon the previous, so cascading
# failures aren't good
#
# 19.* test cases in previous version highly depended on the previous
# test cases. This was replaced by inserting recently set configurations
# that matters for the test case
test spinbox-19.1 {spinbox widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    spinbox .e -validate all \
	-validatecommand [list doval %W %d %i %P %s %S %v %V] \
	-invalidcommand bell \
	-textvariable ::e \
	-background red -foreground white
    pack .e
    .e insert 0 a
    set ::vVals
} -cleanup {
    destroy .e
} -result {.e 1 0 a {} a all key}

test spinbox-19.2 {spinbox widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    spinbox .e -validate all \
	-validatecommand [list doval %W %d %i %P %s %S %v %V] \
	-invalidcommand bell \
	-textvariable ::e \
	-background red -foreground white
    pack .e
    .e insert 0 a   ;# previous settings
    .e insert 1 b
    set ::vVals
} -cleanup {
    destroy .e
} -result {.e 1 1 ab a b all key}

test spinbox-19.3 {spinbox widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    spinbox .e -validate all \
	-validatecommand [list doval %W %d %i %P %s %S %v %V] \
	-invalidcommand bell \
	-textvariable ::e \
	-background red -foreground white
    pack .e
    .e insert 0 ab   ;# previous settings
    .e insert end c
    set ::vVals
} -cleanup {
    destroy .e
} -result {.e 1 2 abc ab c all key}

test spinbox-19.4 {spinbox widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    spinbox .e -validate all \
	-validatecommand [list doval %W %d %i %P %s %S %v %V] \
	-invalidcommand bell \
	-textvariable ::e \
	-background red -foreground white
    pack .e
    .e insert 0 abc   ;# previous settings
    .e insert 1 123
    list $::vVals $::e
} -cleanup {
    destroy .e
} -result {{.e 1 1 a123bc abc 123 all key} a123bc}

test spinbox-19.5 {spinbox widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    spinbox .e -validate all \
	-validatecommand [list doval %W %d %i %P %s %S %v %V] \
	-invalidcommand bell \
	-textvariable ::e \
	-background red -foreground white
    pack .e
    .e insert 0 a123bc   ;# previous settings
    .e delete 2
    set ::vVals
} -cleanup {
    destroy .e
} -result {.e 0 2 a13bc a123bc 2 all key}

test spinbox-19.6 {spinbox widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    spinbox .e -validate all \
	-validatecommand [list doval %W %d %i %P %s %S %v %V] \
	-invalidcommand bell \
	-textvariable ::e \
	-background red -foreground white
    pack .e
    .e insert 0 a13bc   ;# previous settings
    .e configure -validate key
    .e delete 1 3
    set ::vVals
} -cleanup {
    destroy .e
} -result {.e 0 1 abc a13bc 13 key key}

test spinbox-19.7 {spinbox widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    spinbox .e -validate focus \
	-validatecommand [list doval %W %d %i %P %s %S %v %V] \
	-invalidcommand bell \
	-textvariable ::e \
	-background red -foreground white
    pack .e
    .e insert end abc                 ;# previous settings
    set ::vVals {}
    .e insert end d
    set ::vVals
} -cleanup {
    destroy .e
} -result {}

test spinbox-19.8 {spinbox widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    spinbox .e -validate all \
	-validatecommand [list doval %W %d %i %P %s %S %v %V] \
	-invalidcommand bell \
	-textvariable ::e \
	-background red -foreground white
    pack .e
    .e configure -validate focus    ;# previous settings
    .e insert end abcd              ;# previous settings
    focus -force .e
# update necessary to process FocusIn event
    update
    set ::vVals
} -cleanup {
    destroy .e
} -result {.e -1 -1 abcd abcd {} focus focusin}

test spinbox-19.9 {spinbox widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    spinbox .e -validate focus \
	-validatecommand [list doval %W %d %i %P %s %S %v %V] \
	-invalidcommand bell \
	-textvariable ::e \
	-background red -foreground white
    pack .e
    .e insert end abcd      ;# previous settings
    focus -force .e         ;# previous settings
    update                  ;# previous settings
# update necessary to process FocusIn event
    focus -force .
# update necessary to process FocusOut event
    update
    set ::vVals
} -cleanup {
    destroy .e
} -result {.e -1 -1 abcd abcd {} focus focusout}

test spinbox-19.10 {spinbox widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    spinbox .e -validate all \
	-validatecommand [list doval %W %d %i %P %s %S %v %V] \
	-invalidcommand bell \
	-textvariable ::e \
	-background red -foreground white
    pack .e
    .e insert end abcd          ;# previous settings
    focus -force .e
# update necessary to process FocusIn event
    update
    set ::vVals
} -cleanup {
    destroy .e
} -result {.e -1 -1 abcd abcd {} all focusin}

test spinbox-19.11 {spinbox widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    spinbox .e -validate all \
	-validatecommand [list doval %W %d %i %P %s %S %v %V] \
	-invalidcommand bell \
	-textvariable ::e \
	-background red -foreground white
    pack .e
    .e insert end abcd          ;# previous settings
    focus -force .e             ;# previous settings
# update necessary to process FocusIn event
    update                      ;# previous settings
    focus -force .
# update necessary to process FocusOut event
    update
    set ::vVals
} -cleanup {
    destroy .e
} -result {.e -1 -1 abcd abcd {} all focusout}

test spinbox-19.12 {spinbox widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    spinbox .e -validate focusin \
	-validatecommand [list doval %W %d %i %P %s %S %v %V] \
	-invalidcommand bell \
	-textvariable ::e \
	-background red -foreground white
    pack .e
    .e insert 0 abcd              ;# previous settings
    focus -force .e
# update necessary to process FocusIn event
    update
    set ::vVals
} -cleanup {
    destroy .e
} -result {.e -1 -1 abcd abcd {} focusin focusin}

test spinbox-19.13 {spinbox widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    spinbox .e -validate focusin \
	-validatecommand [list doval %W %d %i %P %s %S %v %V] \
	-invalidcommand bell \
	-textvariable ::e \
	-background red -foreground white
    pack .e
    .e insert end abcd              ;# previous settings
    set ::vVals {}
    focus -force .
# update necessary to process FocusOut event
    update
    set ::vVals
} -cleanup {
    destroy .e
} -result {}

test spinbox-19.14 {spinbox widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    spinbox .e -validate focuso \
	-validatecommand [list doval %W %d %i %P %s %S %v %V] \
	-invalidcommand bell \
	-textvariable ::e \
	-background red -foreground white
    pack .e
    .e insert end abcd              ;# previous settings
    set ::vVals {}                  ;# previous settings
    focus -force .e
# update necessary to process FocusIn event
    update
    set ::vVals
} -cleanup {
    destroy .e
} -result {}

test spinbox-19.15 {spinbox widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    spinbox .e -validate focuso \
	-validatecommand [list doval %W %d %i %P %s %S %v %V] \
	-invalidcommand bell \
	-textvariable ::e \
	-background red -foreground white
    pack .e
    .e insert end abcd              ;# previous settings
    set ::vVals {}                  ;# previous settings
    focus -force .e                 ;# previous settings
# update necessary to process FocusIn event
    update                          ;# previous settings
    focus -force .
# update necessary to process FocusOut event
    update
    set ::vVals
} -cleanup {
    destroy .e
} -result {.e -1 -1 abcd abcd {} focusout focusout}

# the same as 19.16 but added [.e validate] to returned list
test spinbox-19.16 {spinbox widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    spinbox .e -validate focuso \
	-validatecommand [list doval %W %d %i %P %s %S %v %V] \
	-invalidcommand bell \
	-textvariable ::e \
	-background red -foreground white
    pack .e
    .e insert end abcd              ;# previous settings
    set ::vVals {}                  ;# previous settings
    focus -force .e                 ;# previous settings
# update necessary to process FocusIn event
    update                          ;# previous settings
    focus -force .
# update necessary to process FocusOut event
    update
    list [.e validate] $::vVals
} -cleanup {
    destroy .e
} -result {1 {.e -1 -1 abcd abcd {} all forced}}


test spinbox-19.17 {spinbox widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    spinbox .e -validate focuso \
	-validatecommand [list doval %W %d %i %P %s %S %v %V] \
	-invalidcommand bell \
	-textvariable ::e \
	-background red -foreground white
    pack .e
    .e insert end abcd              ;# previous settings
    set ::e newdata
    list [.e cget -validate] $::vVals
} -cleanup {
    destroy .e
} -result {focusout {.e -1 -1 newdata abcd {} focusout forced}}


# proc doval changed - returns 0
test spinbox-19.18 {spinbox widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    spinbox .e -validate all \
	-validatecommand [list doval3 %W %d %i %P %s %S %v %V] \
	-invalidcommand bell \
	-textvariable ::e \
	-background red -foreground white
    pack .e
    set ::e newdata                 ;# previous settings
    .e configure -validate all
    set ::e nextdata
    list [.e cget -validate] $::vVals
} -cleanup {
    destroy .e
} -result {none {.e -1 -1 nextdata newdata {} all forced}}


## This sets validate to none because it shows that we prevent a possible
## loop condition in the validation, when the spinbox textvar is also set
# proc doval2 used
test spinbox-19.19 {spinbox widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    spinbox .e -validate all \
	-validatecommand [list doval3 %W %d %i %P %s %S %v %V] \
	-invalidcommand bell \
	-textvariable ::e \
	-background red -foreground white
    pack .e
    set ::e nextdata                 ;# previous settings

    .e configure -validatecommand [list doval2 %W %d %i %P %s %S %v %V]
    .e validate
    list [.e cget -validate] [.e get] $::vVals
} -cleanup {
    destroy .e
} -result {none nextdata {.e -1 -1 nextdata nextdata {} all forced}}

## This leaves validate alone because we trigger validation through the
## textvar (a write trace), and the write during validation triggers
## nothing (by definition of avoiding loops on var traces).  This is
## one of those "dangerous" conditions where the user will have a
## different value in the spinbox widget shown as is in the textvar.
test spinbox-19.20 {spinbox widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    spinbox .e -validate all \
	-validatecommand [list doval %W %d %i %P %s %S %v %V] \
	-invalidcommand bell \
	-textvariable ::e \
	-background red -foreground white
    pack .e
    set ::e nextdata                 ;# previous settings
    .e configure -validatecommand [list doval2 %W %d %i %P %s %S %v %V] ;# prev
    .e validate                     ;# previous settings

    .e configure -validate all
    set ::e testdata
    list [.e cget -validate] [.e get] $::e $::vVals
} -cleanup {
    destroy .e
} -result {all testdata mydata {.e -1 -1 testdata mydata {} all forced}}

## This leaves validate alone because we trigger validation through the
## textvar (a write trace), and the write during validation triggers
## nothing (by definition of avoiding loops on var traces).  This is
## one of those "dangerous" conditions where the user will have a
## different value in the entry widget shown as is in the textvar.
test spinbox-19.21 {spinbox widget validation - bug 40e4bf6198} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    spinbox .e -validate key \
	-validatecommand [list doval2 %W %d %i %P %s %S %v %V] \
	-textvariable ::e
    pack .e
    set ::e origdata
    .e insert 0 A
    list [.e cget -validate] [.e get] $::e $::vVals
} -cleanup {
    destroy .e
} -result {none origdata mydata {.e 1 0 Aorigdata origdata A key key}}

##
## End validation tests
##







|


|

|



|





|


|

|




|





|


|

|




|





|


|

|




|





|


|

|




|





|


|

|





|





|


|

|



|

|





|


|

|







|





|


|

|









|





|


|

|






|





|


|

|









|





|


|

|






|





|


|

|



|



|





|


|

|



|



|





|


|

|



|






|






|


|

|



|






|






|


|

|



|
|





|

|


|

|


|

|
|







|

|


|

|


|

|

|










|


|

|


|
|



|
|










|


|
|

|

|







3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
# The validation tests build each one upon the previous, so cascading
# failures aren't good
#
# 19.* test cases in previous version highly depended on the previous
# test cases. This was replaced by inserting recently set configurations
# that matters for the test case
test spinbox-19.1 {spinbox widget validation} -setup {
    unset -nocomplain textVar validationData
} -body {
    spinbox .e -validate all \
	-validatecommand $validateCmd1 \
	-invalidcommand bell \
	-textvariable textVar \
	-background red -foreground white
    pack .e
    .e insert 0 a
    set validationData
} -cleanup {
    destroy .e
} -result {.e 1 0 a {} a all key}

test spinbox-19.2 {spinbox widget validation} -setup {
    unset -nocomplain textVar validationData
} -body {
    spinbox .e -validate all \
	-validatecommand $validateCmd1 \
	-invalidcommand bell \
	-textvariable textVar \
	-background red -foreground white
    pack .e
    .e insert 0 a   ;# previous settings
    .e insert 1 b
    set validationData
} -cleanup {
    destroy .e
} -result {.e 1 1 ab a b all key}

test spinbox-19.3 {spinbox widget validation} -setup {
    unset -nocomplain textVar validationData
} -body {
    spinbox .e -validate all \
	-validatecommand $validateCmd1 \
	-invalidcommand bell \
	-textvariable textVar \
	-background red -foreground white
    pack .e
    .e insert 0 ab   ;# previous settings
    .e insert end c
    set validationData
} -cleanup {
    destroy .e
} -result {.e 1 2 abc ab c all key}

test spinbox-19.4 {spinbox widget validation} -setup {
    unset -nocomplain textVar validationData
} -body {
    spinbox .e -validate all \
	-validatecommand $validateCmd1 \
	-invalidcommand bell \
	-textvariable textVar \
	-background red -foreground white
    pack .e
    .e insert 0 abc   ;# previous settings
    .e insert 1 123
    list $validationData $textVar
} -cleanup {
    destroy .e
} -result {{.e 1 1 a123bc abc 123 all key} a123bc}

test spinbox-19.5 {spinbox widget validation} -setup {
    unset -nocomplain textVar validationData
} -body {
    spinbox .e -validate all \
	-validatecommand $validateCmd1 \
	-invalidcommand bell \
	-textvariable textVar \
	-background red -foreground white
    pack .e
    .e insert 0 a123bc   ;# previous settings
    .e delete 2
    set validationData
} -cleanup {
    destroy .e
} -result {.e 0 2 a13bc a123bc 2 all key}

test spinbox-19.6 {spinbox widget validation} -setup {
    unset -nocomplain textVar validationData
} -body {
    spinbox .e -validate all \
	-validatecommand $validateCmd1 \
	-invalidcommand bell \
	-textvariable textVar \
	-background red -foreground white
    pack .e
    .e insert 0 a13bc   ;# previous settings
    .e configure -validate key
    .e delete 1 3
    set validationData
} -cleanup {
    destroy .e
} -result {.e 0 1 abc a13bc 13 key key}

test spinbox-19.7 {spinbox widget validation} -setup {
    unset -nocomplain textVar validationData
} -body {
    spinbox .e -validate focus \
	-validatecommand $validateCmd1 \
	-invalidcommand bell \
	-textvariable textVar \
	-background red -foreground white
    pack .e
    .e insert end abc                 ;# previous settings
    set validationData {}
    .e insert end d
    set validationData
} -cleanup {
    destroy .e
} -result {}

test spinbox-19.8 {spinbox widget validation} -setup {
    unset -nocomplain textVar validationData
} -body {
    spinbox .e -validate all \
	-validatecommand $validateCmd1 \
	-invalidcommand bell \
	-textvariable textVar \
	-background red -foreground white
    pack .e
    .e configure -validate focus    ;# previous settings
    .e insert end abcd              ;# previous settings
    focus -force .e
# update necessary to process FocusIn event
    update
    set validationData
} -cleanup {
    destroy .e
} -result {.e -1 -1 abcd abcd {} focus focusin}

test spinbox-19.9 {spinbox widget validation} -setup {
    unset -nocomplain textVar validationData
} -body {
    spinbox .e -validate focus \
	-validatecommand $validateCmd1 \
	-invalidcommand bell \
	-textvariable textVar \
	-background red -foreground white
    pack .e
    .e insert end abcd      ;# previous settings
    focus -force .e         ;# previous settings
    update                  ;# previous settings
# update necessary to process FocusIn event
    focus -force .
# update necessary to process FocusOut event
    update
    set validationData
} -cleanup {
    destroy .e
} -result {.e -1 -1 abcd abcd {} focus focusout}

test spinbox-19.10 {spinbox widget validation} -setup {
    unset -nocomplain textVar validationData
} -body {
    spinbox .e -validate all \
	-validatecommand $validateCmd1 \
	-invalidcommand bell \
	-textvariable textVar \
	-background red -foreground white
    pack .e
    .e insert end abcd          ;# previous settings
    focus -force .e
# update necessary to process FocusIn event
    update
    set validationData
} -cleanup {
    destroy .e
} -result {.e -1 -1 abcd abcd {} all focusin}

test spinbox-19.11 {spinbox widget validation} -setup {
    unset -nocomplain textVar validationData
} -body {
    spinbox .e -validate all \
	-validatecommand $validateCmd1 \
	-invalidcommand bell \
	-textvariable textVar \
	-background red -foreground white
    pack .e
    .e insert end abcd          ;# previous settings
    focus -force .e             ;# previous settings
# update necessary to process FocusIn event
    update                      ;# previous settings
    focus -force .
# update necessary to process FocusOut event
    update
    set validationData
} -cleanup {
    destroy .e
} -result {.e -1 -1 abcd abcd {} all focusout}

test spinbox-19.12 {spinbox widget validation} -setup {
    unset -nocomplain textVar validationData
} -body {
    spinbox .e -validate focusin \
	-validatecommand $validateCmd1 \
	-invalidcommand bell \
	-textvariable textVar \
	-background red -foreground white
    pack .e
    .e insert 0 abcd              ;# previous settings
    focus -force .e
# update necessary to process FocusIn event
    update
    set validationData
} -cleanup {
    destroy .e
} -result {.e -1 -1 abcd abcd {} focusin focusin}

test spinbox-19.13 {spinbox widget validation} -setup {
    unset -nocomplain textVar validationData
} -body {
    spinbox .e -validate focusin \
	-validatecommand $validateCmd1 \
	-invalidcommand bell \
	-textvariable textVar \
	-background red -foreground white
    pack .e
    .e insert end abcd              ;# previous settings
    set validationData {}
    focus -force .
# update necessary to process FocusOut event
    update
    set validationData
} -cleanup {
    destroy .e
} -result {}

test spinbox-19.14 {spinbox widget validation} -setup {
    unset -nocomplain textVar validationData
} -body {
    spinbox .e -validate focuso \
	-validatecommand $validateCmd1 \
	-invalidcommand bell \
	-textvariable textVar \
	-background red -foreground white
    pack .e
    .e insert end abcd              ;# previous settings
    set validationData {}           ;# previous settings
    focus -force .e
# update necessary to process FocusIn event
    update
    set validationData
} -cleanup {
    destroy .e
} -result {}

test spinbox-19.15 {spinbox widget validation} -setup {
    unset -nocomplain textVar validationData
} -body {
    spinbox .e -validate focuso \
	-validatecommand $validateCmd1 \
	-invalidcommand bell \
	-textvariable textVar \
	-background red -foreground white
    pack .e
    .e insert end abcd              ;# previous settings
    set validationData {}           ;# previous settings
    focus -force .e                 ;# previous settings
# update necessary to process FocusIn event
    update                          ;# previous settings
    focus -force .
# update necessary to process FocusOut event
    update
    set validationData
} -cleanup {
    destroy .e
} -result {.e -1 -1 abcd abcd {} focusout focusout}

# the same as 19.16 but added [.e validate] to returned list
test spinbox-19.16 {spinbox widget validation} -setup {
    unset -nocomplain textVar validationData
} -body {
    spinbox .e -validate focuso \
	-validatecommand $validateCmd1 \
	-invalidcommand bell \
	-textvariable textVar \
	-background red -foreground white
    pack .e
    .e insert end abcd              ;# previous settings
    set validationData {}           ;# previous settings
    focus -force .e                 ;# previous settings
# update necessary to process FocusIn event
    update                          ;# previous settings
    focus -force .
# update necessary to process FocusOut event
    update
    list [.e validate] $validationData
} -cleanup {
    destroy .e
} -result {1 {.e -1 -1 abcd abcd {} all forced}}


test spinbox-19.17 {spinbox widget validation} -setup {
    unset -nocomplain textVar validationData
} -body {
    spinbox .e -validate focuso \
	-validatecommand $validateCmd1 \
	-invalidcommand bell \
	-textvariable textVar \
	-background red -foreground white
    pack .e
    .e insert end abcd              ;# previous settings
    set textVar newdata
    list [.e cget -validate] $validationData
} -cleanup {
    destroy .e
} -result {focusout {.e -1 -1 newdata abcd {} focusout forced}}


# Note: changed validateCmd - returns 0
test spinbox-19.18 {spinbox widget validation} -setup {
    unset -nocomplain textVar validationData
} -body {
    spinbox .e -validate all \
	-validatecommand $validateCmd3 \
	-invalidcommand bell \
	-textvariable textVar \
	-background red -foreground white
    pack .e
    set textVar newdata                 ;# previous settings
    .e configure -validate all
    set textVar nextdata
    list [.e cget -validate] $validationData
} -cleanup {
    destroy .e
} -result {none {.e -1 -1 nextdata newdata {} all forced}}


## This sets validate to none because it shows that we prevent a possible
## loop condition in the validation, when the spinbox textvar is also set
# proc validateCmd2 used
test spinbox-19.19 {spinbox widget validation} -setup {
    unset -nocomplain textVar validationData
} -body {
    spinbox .e -validate all \
	-validatecommand $validateCmd3 \
	-invalidcommand bell \
	-textvariable textVar \
	-background red -foreground white
    pack .e
    set textVar nextdata                 ;# previous settings

    .e configure -validatecommand $validateCmd2
    .e validate
    list [.e cget -validate] [.e get] $validationData
} -cleanup {
    destroy .e
} -result {none nextdata {.e -1 -1 nextdata nextdata {} all forced}}

## This leaves validate alone because we trigger validation through the
## textvar (a write trace), and the write during validation triggers
## nothing (by definition of avoiding loops on var traces).  This is
## one of those "dangerous" conditions where the user will have a
## different value in the spinbox widget shown as is in the textvar.
test spinbox-19.20 {spinbox widget validation} -setup {
    unset -nocomplain textVar validationData
} -body {
    spinbox .e -validate all \
	-validatecommand $validateCmd1 \
	-invalidcommand bell \
	-textvariable textVar \
	-background red -foreground white
    pack .e
    set textVar nextdata                 ;# previous settings
    .e configure -validatecommand $validateCmd2 ;# prev
    .e validate                     ;# previous settings

    .e configure -validate all
    set textVar testdata
    list [.e cget -validate] [.e get] $textVar $validationData
} -cleanup {
    destroy .e
} -result {all testdata mydata {.e -1 -1 testdata mydata {} all forced}}

## This leaves validate alone because we trigger validation through the
## textvar (a write trace), and the write during validation triggers
## nothing (by definition of avoiding loops on var traces).  This is
## one of those "dangerous" conditions where the user will have a
## different value in the entry widget shown as is in the textvar.
test spinbox-19.21 {spinbox widget validation - bug 40e4bf6198} -setup {
    unset -nocomplain textVar validationData
} -body {
    spinbox .e -validate key \
	-validatecommand $validateCmd2 \
	-textvariable textVar
    pack .e
    set textVar origdata
    .e insert 0 A
    list [.e cget -validate] [.e get] $textVar $validationData
} -cleanup {
    destroy .e
} -result {none origdata mydata {.e 1 0 Aorigdata origdata A key key}}

##
## End validation tests
##
3911
3912
3913
3914
3915
3916
3917
3918




3919
3920




3921
3922
3923
3924

# Collected comments about lacks from the test
# XXX Still need to write tests for SpinboxBlinkProc, SpinboxFocusProc,
# and SpinboxTextVarProc.
# No tests for DisplaySpinbox.
# XXX Still need to write tests for SpinboxScanTo and SpinboxSelectTo.
# No tests for EventuallyRedraw





# option clear
# cleanup




cleanupTests
return










>
>
>
>

|
>
>
>
>


<
<
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910



# Collected comments about lacks from the test
# XXX Still need to write tests for SpinboxBlinkProc, SpinboxFocusProc,
# and SpinboxTextVarProc.
# No tests for DisplaySpinbox.
# XXX Still need to write tests for SpinboxScanTo and SpinboxSelectTo.
# No tests for EventuallyRedraw

#
# CLEANUP
#

# option clear
foreach i {1 2 3} {
    unset validateCmd$i
}
unset i
testutils forget entry scroll
cleanupTests
return


Added tests/testutils.GUIDE.




























































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
================================================================================
             TESTUTILS GUIDE FOR TEST AUTHORS AND MAINTAINERS

                            Erik Leunissen
================================================================================


INTRODUCTION
============
"testutils" is a mechanism that manages utility procs that are used by multiple
test files:
- it keeps them in a central place to prevent code duplication.
- it provides these utility procs to test files, similar to what a Tcl package
  (using a namespace) does: it exports the utilities, and the test files import
  them.
The entire mechanism is implemented in a single file "testutils.tcl".

Section A of this document explains the usage of the mechanism, targeted at
test authors. Section B provides a more detailed description of the innards and
workings of the testutils mechanism. This information is specifically targeted
at developers carrying out maintenance of the testutils mechanism.


A. USING UTILITY PROCS IN TESTS AND TEST FILES
==============================================
This section explains to test authors how utility procs are organized, how to
use existing utility procs in a test file, and how to create new utility procs.

A1. Organization of utility procs using namespaces
--------------------------------------------------
The utility procs that testutils provides are grouped into functional areas.
These functional areas are also called "domains", or "utility domains". They
carry names such as "dialog","entry", "text", which conform more or less to
names of test files in the Tk test suite.

Utility procs are imported on demand by test files, using the command "testutils".
(See the explanation of this command in the next section.) Utility procs for
the domain "generic" are an exception to this general rule: these procs are
imported into the global namespace as a standard policy. They are readily
available to the test author, in each test file.

Each domain has its own namespace below ::tk::test in which utility procs are
defined. For example: utilities that are specific for Tk dialogs are stored
inside the namespace ::tk::test::dialog.

A2. Using existing utility procs in test files
----------------------------------------------
The command "testutils" is the interface to the testutils mechanism for the test
author. The test author may use it to import utility procs into the namespace
in which tests are executed (normally, this is the global namespace). The command
takes the following form:

    testutils (import|forget) domain ?domain domain ...?

The command "testutils import" is typically invoked at the top of a test file.
The command "testutils forget" is typically invoked at the end of a test file.
These commands take care of the importing and cleaning up of utility procs
for a specific domain. They also take care of importing any namespace variables
associated with these procs so that they can be accessed from within a test.

Typical invocations in a test file (using the domain "dialog" as an example), are:

┃    testutils import dialog
┃    ⋮
┃    test foo-1.0 -body {
┃        ⋮
┃        ⋮
┃        SendButtonPress; # invoke utility proc imported from domain "dialog"
┃        ⋮
┃        ⋮
┃    } -result {foo_result}
┃    ⋮
┃    testutils forget dialog

The command "testutils import" fails if a proc or variable, unrelated to the
testutils mechanism, but having the same name as a utility proc or associated
variable, was already defined in the importing namespace. Therefore, test
authors need to take care that such procs and variables are cleaned up before
the end of a test file.

A3. Adding new utility procs
----------------------------
Test authors may define new utility procs in the file "testutils.tcl". When doing
so, there are several points to be aware of:

1. Consider whether the new utility proc is used in multiple test files. If
   it's not, it may as well be defined inside the specific test file that uses
   it, because in that case the issue of code duplication doesn't exist.

2. Add the proc definition to the proper domain namespace. If necessary, create
   a new domain namespace.

3. It may be the case that tests need to access (read/write) variables that are
   associated with the new utility proc. The command "testutils" also handles
   the importing and initialization of these associated variables, but attention
   is needed for the following:

   Their definition needs to be to placed in the reserved proc "init" (inside
   the proper domain namespace). The command "testutils import" will import any
   variables defined in this proc into the namespace where tests are executing.

   Note that just placing associated namespace variables inside the "namespace eval"
   scope for the specific domain, but outside the init proc, isn't good enough
   because that foregoes the importing of the namespace variables as well as their
   automatic initialization.

   Also: any namespace variables initialized inside the "namespace eval" scope
   for the specific domain, but outside the init proc, will NOT be cleaned up
   upon the invocation of "testutils forget", in contrast to imported
   namespace variables.

4. If you created a new domain namespace in step 2, then export the test
   utilities using the command "testutils export". This ensures that all utility
   procs in the domain namespace are exported, except any init proc.

The file testutils.tcl contains various examples showing this practice.


B. INNER WORKINGS OF THE TESTUTILS MECHANISM
============================================
This section is targeted at developers carrying out maintenance of the testutils
mechanism, whether debugging or improving it otherwise.

B1. Files and file loading
--------------------------
The entire testutils mechanism is implemented in a single file "testutils.tcl".
This file is sourced on behalf of each test file by a command in the file
"main.tcl", which in turn is loaded through the tcltest option "-loadfile" in
the file "all.tcl".

B2. Importing procs and associated namespace variables
------------------------------------------------------
The command "testutils" makes utility procs available to the namespace in which
test files execute. The command employs a plain "namespace export/namespace import"
for importing procs; there is nothing special about that. However, special
attention is needed for those utility procs that store state in a namespace
variable that is also accessed from the namespace in which tests are executing.
Such variables are made available to the namespace in which tests are executing
using an upvar statement. The process of importing these associated namespace
variables needs to handle some specifics:

Besides making them available to test files, some tests require such variables
to be initialized, regardless whatever the previous test file did to them.
Therefore, the proc "testutils" needs to re-initialize these upvar'ed variables
for each test file that imports them. The steps in this auto-initialization
process are as follows:

- if a namespace for a specific functional area holds a proc "init", the
  command "testutils import xxx" will invoke it, thus initializing namespace
  variables. It subsequently imports the variables into the namespace where
  tests are executing, using "upvar";
- upon test file cleanup, "testutils forget xxx" removes the imported utility
  procs and unsets the upvar'ed variables. (Note that this doesn't remove the
  upvar link in the source namespace.) When a subsequent test file invokes
  "testutils import xxx" again, the command will re-initialize the namespace
  variables.

A typical init proc (for a fictitious domain "cuisine") is:

    proc init {} {
	variable doneNess medium-rare
	variable seasonings [list salt pepper]
	variable tasteVerdict
    }

Note that the namespace variables "doneNess" and "seasonings" are initialized
with a value, while the namespace variable "tasteVerdict" is not. Both variants
of declaring/defining a namespace variable are supported.

B3. Tricky aspects of repeated initialization
---------------------------------------------
While the entire Tk test suite is running, many test files are loaded, each of
which may import and subsequently forget utility domains. When tracking a single
utility domain across test files that come and go, associated namespace variables
may be imported, initialized and cleaned up repeatedly. This repetitive cycle
presents tricky aspects for the re-initialization of those namespace variables
that were declared using the "variable" command without supplying a value. This
is caused by the fact that, once established, the upvar link for imported
namespace variables cannot be removed. The tricky details are explicitly
described by comments in the proc testutils.

Another tricky detail - that testutils currently evades - is the fact that
unsetting an upvar'ed namespace variable changes its visibility for "info vars"
in the utility namespace where the variable was defined, but not in the namespace
where the upvar statement was invoked.

B4. Test file
-------------
The correct functioning of the testutils mechanism is tested by the test
file "testutils.test".
Added tests/testutils.tcl.








































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
# testutils.tcl --
#
# This file is sourced by each test file when invoking "tcltest::loadTestedCommands".
# It implements the testutils mechanism which is used to import utility procs
# into test files that need them.
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.

#
# DOCUMENTATION FOR TEST AUTHORS AND MAINTAINERS
#
# The testutils mechanism is documented in the separate file "testutils.GUIDE",
# which is placed in the same directory as this file "testutils.tcl".
#

namespace eval ::tk::test {
    #
    # The namespace ::tk::test itself doesn't contain any procs or variables.
    # The contents of this namespace exist solely in child namespaces that
    # are defined hereafter.
    #
    # Each child namespace represents a functional area, also called "domain".
    #
}


namespace eval ::tk::test::generic {

    proc assert {expr} {
	if {! [uplevel 1 [list expr $expr]]} {
	    return -code error "assertion failed: \"[uplevel 1 [list subst -nocommands $expr]]\""
	}
    }

    # controlPointerWarpTiming --
    #
    # This proc is intended to ensure that the (mouse) pointer has actually
    # been moved to its new position after a Tk test issued:
    #
    #    [event generate $w $event -warp 1 ...]
    #
    # It takes care of the following timing details of pointer warping:
    #
    # a. Allow pointer warping to happen if it was scheduled for execution at
    #    idle time. This happens synchronously if $w refers to the
    #    whole screen or if the -when option to [event generate] is "now".
    #
    # b. Work around a race condition associated with OS notification of
    #    mouse motion on Windows.
    #
    #    When calling [event generate $w $event -warp 1 ...], the following
    #    sequence occurs:
    #    - At some point in the processing of this command, either via a
    #      synchronous execution path, or asynchronously at idle time, Tk calls
    #      an OS function* to carry out the mouse cursor motion.
    #    - Tk has previously registered a callback function** with the OS, for
    #      the OS to call in order to notify Tk when a mouse move is completed.
    #    - Tk doesn't wait for the callback function to receive the notification
    #      from the OS, but continues processing. This suits most use cases
    #      because usually the notification arrives fast enough (within a few tens
    #      of microseconds). However ...
    #    - A problem arises if Tk performs some processing, immediately following
    #      up on [event generate $w $event -warp 1 ...], and that processing
    #      relies on the mouse pointer having actually moved. If such processing
    #      happens just before the notification from the OS has been received,
    #      Tk will be using not yet updated info (e.g. mouse coordinates).
    #
    #         Hickup, choke etc ... !
    #
    #            *  the function SendInput() of the Win32 API
    #            ** the callback function is TkWinChildProc()
    #
    #    This timing issue can be addressed by putting the Tk process on hold
    #    (do nothing at all) for a somewhat extended amount of time, while
    #    letting the OS complete its job in the meantime. This is what is
    #    accomplished by calling [after ms].
    #
    #    ----
    #    For the history of this issue please refer to Tk ticket [69b48f427e],
    #    specifically the comment on 2019-10-27 14:24:26.
    #
    #
    # Beware: there are cases, not (yet) exercised by the Tk test suite, where
    # [controlPointerWarpTiming] doesn't ensure the new position of the pointer.
    # For example, when issued under Tk8.7+, if the value for the -when option
    # to [event generate $w] is not "now", and $w refers to a Tk window, i.e. not
    # the whole screen.
    #
    proc controlPointerWarpTiming {{duration 50}} {
	update idletasks ;# see a. above
	if {[tk windowingsystem] eq "win32"} {
	    after $duration ;# see b. above
	}
    }

    proc deleteWindows {} {
	destroy {*}[winfo children .]
	# This update is needed to avoid intermittent failures on macOS in unixEmbed.test
	# with the (GitHub Actions) CI runner.
	# Reason for the failures is unclear but could have to do with window ids being deleted
	# after the destroy command returns. The detailed mechanism of such delayed deletions
	# is not understood, but it appears that this update prevents the test failures.
	update
    }

    proc fixfocus {} {
	catch {destroy .focus}
	toplevel .focus
	wm geometry .focus +0+0
	entry .focus.e
	.focus.e insert 0 "fixfocus"
	pack .focus.e
	update
	focus -force .focus.e
	destroy .focus
    }

    proc loadTkCommand {} {
	set tklib {}
	foreach pair [info loaded {}] {
	    foreach {lib pfx} $pair break
	    if {$pfx eq "Tk"} {
		set tklib $lib
		break
	    }
	}
	return [list load $tklib Tk]
    }

    # Suspend script execution for a given amount of time, but continue
    # processing events.
    proc pause {ms} {
	variable _pause

	set num [incr _pause(count)]
	set _pause($num) 1

	after $ms [list unset [namespace current]::_pause($num)]
	vwait [namespace current]::_pause($num)
    }

    # On macOS windows are not allowed to overlap the menubar at the top of the
    # screen or the dock.  So tests which move a window and then check whether it
    # got moved to the requested location should use a y coordinate larger than the
    # height of the menubar (normally 23 pixels) and an x coordinate larger than the
    # width of the dock, if it happens to be on the left.
    # The C-level command "testmenubarheight" deals with this issue but it may
    # not be available on each platform. Therefore, provide a fallback here.
    if {[llength [info commands testmenubarheight]] == 0} {
	if {[tk windowingsystem] ne "aqua"} {
	    # Windows may overlap the menubar
	    proc testmenubarheight {} {
		return 0
	    }
	} else {
	    # Windows may not overlap the menubar
	    proc testmenubarheight {} {
		return 30 ;  # arbitrary value known to be larger than the menubar height
	    }
	}
    }

    # testutils --
    #
    #    Takes care of exporting/importing/forgetting utility procs and any
    #    associated variables from a specific test domain (functional area).
    #
    #    More information is available in the file "testutils.GUIDE"
    #
    # Arguments:
    #    subCmd : "export", "import" or "forget"
    #    args   : a sequence of domains that need to be imported/forgotten,
    #             unused for "export"
    #
    proc testutils {subCmd args} {
	variable importedDomains
	variable importVars

	if {$subCmd ni [list export import forget]} {
	    return -code error "invalid subCmd \"$subCmd\". Usage: [lindex [info level 0] 0] export|import|forget ?domain domain ...?"
	}

	set argc [llength $args]
	if {$subCmd eq "export"} {
	    if {$argc != 0} {
		return -code error "invalid #args. Usage: [lindex [info level 0] 0] export"
	    }

	    # export all procs from the invoking domain namespace except "init"
	    uplevel 1 {
		if {[info procs init] eq "init"} {
		    set exports [info procs]
		    namespace export {*}[lremove $exports [lsearch $exports "init"]]
		    unset exports
		} else {
		    namespace export *
		}
	    }
	    return
	}
	if {$argc < 1} {
	    return -code error "invalid #args. Usage: [lindex [info level 0] 0] import|forget domain ?domain ...?"
	}

	# determine the requesting namespace
	set ns [uplevel 1 {namespace current}]

	# import/forget domains
	foreach domain $args {
	    if {! [namespace exists ::tk::test::$domain]} {
		return -code error "testutils domain \"$domain\" doesn't exist"
	    }

	    switch -- $subCmd {
		import {
		    if {[info exists importedDomains($ns)] && ($domain in $importedDomains($ns))} {
			return -code error "testutils domain \"$domain\" was already imported"
		    } else {

			# import procs
			if {[catch {
			    uplevel 1 [list namespace import ::tk::test::${domain}::*]
			} errMsg]} {
			    # revert import of procs already done
			    uplevel 1 [list namespace forget ::tk::test::${domain}::*]
			    return -code error "import from testutils domain \"$domain\" failed: $errMsg"
			}

			# import associated namespace variables declared in the init proc
			if {"init" in [namespace inscope ::tk::test::$domain {info procs init}]} {
			    if {[info exists importVars($ns,$domain)]} {
				#
				# Note [A1]:
				# If test files inadvertently leave behind a variable with the same name
				# as an upvar'ed namespace variable, its last value will serve as a new
				# initial value in case that the init proc declares that variable without
				# a value. Also, the result of "info exists varName" would be different
				# between test files.
				#
				# The next unset prevents such artefacts. See also note [A2] below.
				#
				uplevel 1 [list unset -nocomplain {*}$importVars($ns,$domain)]
			    }
			    ::tk::test::${domain}::init
			    if {($ns ne "::") || (! [info exists importVars($ns,$domain)])} {
				#
				# Importing associated namespace variables into the global namespace where
				# tests are normally executing, needs to be done only once because an upvar
				# link cannot be removed from a namespace. For other requesting namespaces
				# we need to reckon with deletion and re-creation of the namespace in the
				# meantime.
				#
				if {[info exists importVars($ns,$domain)]} {
				    set associatedVars $importVars($ns,$domain)
				} else {
				    set associatedVars [namespace inscope ::tk::test::$domain {info vars}]
				}
				foreach varName $associatedVars {
				    if {[catch {
					uplevel 1 [list upvar #0 ::tk::test::${domain}::$varName $varName]
				    } errMsg]} {
					# revert imported procs and partial variable import
					uplevel 1 [list unset -nocomplain {*}$associatedVars]
					uplevel 1 [list namespace forget ::tk::test::${domain}::*]
					return -code error "import from testutils domain \"$domain\" failed: $errMsg"
				    }
				}
				set importVars($ns,$domain) $associatedVars
			    }
			}

			# register domain as imported
			lappend importedDomains($ns) $domain
		    }
		}
		forget {
		    if {(! [info exists importedDomains($ns)]) || ($domain ni $importedDomains($ns))} {
			return -code error "testutils domain \"$domain\" was not imported"
		    }

		    # remove imported utility procs from the namespace where tests are executing
		    uplevel 1 [list namespace forget ::tk::test::${domain}::*]

		    #
		    # Some namespace variables are meant to persist across test files
		    # in the entire Tk test suite (notably the variable ImageNames,
		    # domain "image"). These variables are also not meant to be accessed
		    # from, and imported into the namespace where tests are executing,
		    # and they should not be cleaned up here.
		    #

		    if {[info exists importVars($ns,$domain)]} {
			#
			# Remove imported namespace variables.
			#
			# Note [A2]:
			# The upvar link in the namespace where tests are executing cannot be removed.
			# Without specific attention, this can cause surprising behaviour upon
			# re-initialization. See also note [A1] above.
			#
			uplevel 1 [list unset -nocomplain {*}$importVars($ns,$domain)]
		    }
		    set importedDomains($ns) [lremove $importedDomains($ns) [lsearch $importedDomains($ns) $domain]]
		}
	    }
	}
    }

    testutils export
}

# Import generic utility procs into the global namespace (in which tests are
# normally executing) as a standard policy.
::tk::test::generic::testutils import generic

namespace eval ::tk::test::button {
    proc bogusTrace args {
	error "trace aborted"
    }
    testutils export
}

namespace eval ::tk::test::child {

    # childTkInterp --
    #
    # 	Create a new Tk application in a child interpreter, with
    #	a given name and class.
    #
    proc childTkInterp {name args} {
	set index [lsearch $args "-safe"]
	if {$index >= 0} {
	    set safe 1
	    set options [lremove $args $index]
	} else {
	    set safe 0
	    set options $args
	}
	if {[llength $options] ni {0 2}} {
	    return -code error "invalid #args"
	}

	set cmdArgs [list -name $name]
	foreach {key value} $options {
	    if {$key ne "-class"} {
		return -code error "invalid option \"$key\""
	    }
	    lappend cmdArgs $key $value
	}

	variable loadTkCmd
	if {! [info exists loadTkCmd]} {
	    foreach pkg [info loaded] {
		if {[lindex $pkg 1] eq "Tk"} {
		    set loadTkCmd "load $pkg"
		    break
		}
	    }
	}
	if {$safe} {
	    interp create -safe $name
	} else {
	    interp create $name
	}

	$name eval [list set argv $cmdArgs]
	catch {eval $loadTkCmd $name}
    }

    # childTkProcess --
    #
    # 	Create a new Tk application in a child process, and enable it to
    #	evaluate scripts on our behalf.
    #
    #	Suggestion: replace with child interp or thread ?
    #
    proc childTkProcess {subcmd args} {
	variable fd
	switch -- $subcmd {
	    create {
		if {[info exists fd] && [string length $fd]} {
		    childTkProcess exit
		}
		set fd [open "|[list [::tcltest::interpreter] \
			-geometry +0+0 -name tktest] $args" r+]
		puts $fd "puts foo; flush stdout"
		flush $fd
		if {[gets $fd data] < 0} {
		    error "unexpected EOF from \"[::tcltest::interpreter]\""
		}
		if {$data ne "foo"} {
		    error "unexpected output from\
			    background process: \"$data\""
		}
		puts $fd [loadTkCommand]
		flush $fd
		fileevent $fd readable [namespace code {childTkProcess read}]
	    }
	    eval {
		variable Data
		variable Done

		set script [lindex $args 0]
		set block 0
		if {[llength $args] == 2} {
		    set block [lindex $args 1]
		}

		if {$block} {
		    fileevent $fd readable {}
		}
		puts $fd "[list catch $script msg]; update; puts \$msg;\
			puts **DONE**; flush stdout"
		flush $fd
		set Data {}
		if {$block} {
		    while {![eof $fd]} {
			set line [gets $fd]
			if {$line eq "**DONE**"} {
			    break
			}
			append Data $line
		    }
		} else {
		    set Done 0
		    vwait [namespace which -variable Done]
		}
		return $Data
	    }
	    exit {
		# catch in case the child process has closed $fd
		catch {puts $fd exit}
		catch {close $fd}
		set fd ""
	    }
	    read {
		variable Data
		variable Done
		set x [gets $fd]
		if {[eof $fd]} {
		    fileevent $fd readable {}
		    set Done 1
		} elseif {$x eq "**DONE**"} {
		    set Done 1
		} else {
		    append Data $x
		}
	    }
	}
    }

    testutils export
}

namespace eval ::tk::test::colors {
    # colorsFree --
    #
    # Returns 1 if there appear to be free colormap entries in a window, 0
    # otherwise.
    #
    # Arguments:
    #	w                : name of window in which to check.
    #	red, green, blue : intensities to use in a trial color allocation
    #	                   to see if there are colormap entries free.
    #
    proc colorsFree {w {red 31} {green 245} {blue 192}} {
	lassign [winfo rgb $w [format "#%02x%02x%02x" $red $green $blue]] r g b
	expr {($r/256 == $red) && ($g/256 == $green) && ($b/256 == $blue)}
    }

    # eatColors --
    #
    # Creates a toplevel window and allocates enough colors in it to use up all
    # the slots in an 8-bit colormap.
    #
    # Arguments:
    #	w : name of toplevel window to create.
    #
    proc eatColors {w} {
	catch {destroy $w}
	toplevel $w
	wm geom $w +0+0
	canvas $w.c -width 400 -height 200 -bd 0
	pack $w.c
	for {set y 0} {$y < 8} {incr y} {
	    for {set x 0} {$x < 40} {incr x} {
		set color [format #%02x%02x%02x [expr {$x*6}] [expr {$y*30}] 0]
		$w.c create rectangle [expr {10*$x}] [expr {20*$y}] \
		    [expr {10*$x + 10}] [expr {20*$y + 20}] -outline {} \
		    -fill $color
	    }
	}
	update
    }

    testutils export
}

namespace eval ::tk::test::dialog {

    # init --
    #
    # This is a reserved proc that is part of the mechanism that the proc
    # testutils employs when making utility procs and associated namespace
    # variables available to test files.
    #
    # Test authors should define and initialize namespace variables here if
    # they need to be imported into the namespace in which tests are executing.
    # This proc must not be exported.
    #
    # For more information, see the documentation in the file "testutils.GUIDE"
    #
    proc init {} {
	variable dialogType [file rootname [file tail [info script]]]
	variable dialogIsNative [isNative $dialogType]
	variable testDialog
	variable testDialogFont
    }

    proc Click {button} {
	variable testDialog
	if {$button ni "ok cancel apply"} {
	    return -code error "invalid button name \"$button\""
	}
	$testDialog.$button invoke
    }

    proc isNative {type} {
	switch -- $type {
	    "choosedir" {
		set cmd ::tk_chooseDirectory
	    }
	    "clrpick" {
		set cmd ::tk_chooseColor
	    }
	    "filebox" {
		set cmd ::tk_getOpenFile
	    }
	    "msgbox" {
		set cmd ::tk_messageBox
	    }
	    "dialog" -
	    "fontchooser" -
	    "winDialog" {
		return "N/A"
	    }
	    default {
		return -code error "invalid dialog type \"$type\""
	    }
	}
	return [expr {[info procs $cmd] eq ""}]
    }

    proc PressButton {btn} {
	event generate $btn <Enter>
	event generate $btn <Button-1> -x 5 -y 5
	event generate $btn <ButtonRelease-1> -x 5 -y 5
    }

    proc SendButtonPress {parent btn buttonType} {
	variable dialogType
	switch -- $dialogType {
	    "choosedir" {
		if {$parent eq "."} {
		    set w .__tk_choosedir
		} else {
		    set w $parent.__tk_choosedir
		}
		upvar ::tk::dialog::file::__tk_choosedir data
	    }
	    "clrpick" {
		set w .__tk__color
		upvar ::tk::dialog::color::[winfo name $w] data
	    }
	    "filebox" {
		if {$parent eq "."} {
		    set w .__tk_filedialog
		} else {
		    set w $parent.__tk_filedialog
		}
		upvar ::tk::dialog::file::__tk_filedialog data
	    }
	    "msgbox" {
		if {$parent eq "."} {
		    set w .__tk__messagebox
		} else {
		    set w $parent.__tk__messagebox
		}
	    }
	    default {
		return -code error "invalid dialog type \"$dialogType\""
	    }
	}

	if {$dialogType eq "msgbox"} {
	    set button $w.$btn
	} else {
	    set button $data($btn\Btn)
	}
	if {! [winfo ismapped $button]} {
	    update
	}

	if {$buttonType eq "mouse"} {
	    PressButton $button
	} else {
	    event generate $w <Enter>
	    focus $w
	    event generate $button <Enter>
	    event generate $w <Key> -keysym Return
	}
    }

    proc testDialog {stage {script ""}} {
	variable testDialogCmd
	variable testDialogResult
	variable testDialogFont
	variable iter_after
	variable testDialog; # On MS Windows, this variable is set at the C level
	                     # by SetTestDialog() in tkWinDialog.c

	switch -- $stage {
	    launch {
		set iter_after 0
		set testDialog {}
		if {$::tcl_platform(platform) eq "windows"} {
		    variable testDialogClass "#32770"
		}

		after 1 $script
	    }
	    onDisplay {
		set testDialogCmd $script
		set testDialogResult {}
		set testDialogFont {}

		if {$::tcl_platform(platform) eq "windows"} {
		    # Do not make the delay too short. The newer Vista dialogs take
		    # time to come up.
		    after 500 [list [namespace current]::testDialog onDisplay2]
		} else {
		    testDialog onDisplay2
		}
		vwait ::tk::test::dialog::testDialogResult
		return $testDialogResult
	    }
	    onDisplay2 {
		set doRepeat 0

		if {$::tcl_platform(platform) eq "windows"} {
		    # On Vista and later, using the new file dialogs we have to
		    # find the window using its title as testDialog will not be
		    # set at the C level.
		    variable testDialogClass
		    if {[catch {testfindwindow "" $testDialogClass} testDialog]} {
			set doRepeat 1
		    }
		} elseif {$testDialog eq ""} {
		    set doRepeat 1
		}

		if {$doRepeat} {
		    if {[incr iter_after] > 30} {
			set testDialogResult ">30 iterations waiting for testDialog"
			return
		    }
		    after 150 [list ::tk::test::dialog::testDialog onDisplay2]
		    return
		}
		set testDialogResult [uplevel #0 $testDialogCmd]
	    }
	    default {
		return -code error "invalid parameter \"$stage\""
	    }
	}
    }

    proc ToPressButton {parent btn} {
	variable dialogIsNative
	if {! $dialogIsNative} {
	    after 100 SendButtonPress $parent $btn mouse
	}
    }

    testutils export
}


namespace eval ::tk::test::entry {

    # init --
    #
    # This is a reserved proc that is part of the mechanism that the proc
    # testutils employs when making utility procs and associated namespace
    # variables available to test files.
    #
    # Test authors should define and initialize namespace variables here if
    # they need to be imported into the namespace in which tests are executing.
    # This proc must not be exported.
    #
    # For more information, see the documentation in the file "testutils.GUIDE"
    #
    proc init {} {
	variable textVar
	variable validationData
    }

    # Handler for variable trace on namespace variable textVar
    proc override args {
	variable textVar 12345
    }

    # Procedures used by widget validation tests
    proc validateCommand1 {W d i P s S v V} {
	variable validationData [list $W $d $i $P $s $S $v $V]
	return 1
    }
    proc validateCommand2 {W d i P s S v V} {
	variable validationData [list $W $d $i $P $s $S $v $V]
	variable textVar mydata
	return 1
    }
    proc validateCommand3 {W d i P s S v V} {
	variable validationData [list $W $d $i $P $s $S $v $V]
	return 0
    }
    proc validateCommand4 {W d i P s S v V} {
	variable validationData [list $W $d $i $P $s $S $v $V]
	.e delete 0 end;
	.e insert end dovaldata
	return 0
    }

    testutils export
}

namespace eval ::tk::test::geometry {
    proc getsize {w} {
	update
	return "[winfo reqwidth $w] [winfo reqheight $w]"
    }

    testutils export
}

namespace eval ::tk::test::image {

    proc imageCleanup {} {
	variable ImageNames
	foreach img [image names] {
	    if {$img ni $ImageNames} {image delete $img}
	}
    }

    proc imageFinish {} {
	variable ImageNames
	set imgs [lsearch -all -inline -glob -not [lsort [image names]] ::tk::icons::indicator*]
	if {$imgs ne $ImageNames} {
	    return -code error "images remaining: [image names] != $ImageNames"
	}
	imageCleanup
    }

    proc imageInit {} {
	variable ImageNames
	if {![info exists ImageNames]} {
	    set ImageNames [lsearch -all -inline -glob -not [lsort [image names]] ::tk::icons::indicator*]
	}
	imageCleanup
	if {[lsort [image names]] ne $ImageNames} {
	    return -code error "IMAGE NAMES mismatch: [image names] != $ImageNames"
	}
    }

    proc imageNames {} {
	variable ImageNames
	set r {}
	foreach img [image names] {
	    if {$img ni $ImageNames} {lappend r $img}
	}
	return $r
    }

    testutils export
}

namespace eval ::tk::test::scroll {

    # init --
    #
    # This is a reserved proc that is part of the mechanism that the proc
    # testutils employs when making utility procs and associated namespace
    # variables available to test files.
    #
    # Test authors should define and initialize namespace variables here if
    # they need to be imported into the namespace in which tests are executing.
    # This proc must not be exported.
    #
    # For more information, see the documentation in the file "testutils.GUIDE"
    #
    proc init {} {
	variable scrollInfo {}
    }

    # Used as the scrolling command for widgets, set with "-[xy]scrollcommand".
    # It saves the scrolling information in a namespace variable "scrollInfo".
    proc setScrollInfo {args} {
	variable scrollInfo $args
    }

    testutils export
}

namespace eval ::tk::test::select {

    # init --
    #
    # This is a reserved proc that is part of the mechanism that the proc
    # testutils employs when making utility procs and associated namespace
    # variables available to test files.
    #
    # Test authors should define and initialize namespace variables here if
    # they need to be imported into the namespace in which tests are executing.
    # This proc must not be exported.
    #
    # For more information, see the documentation in the file "testutils.GUIDE"
    #
    proc init {} {
	variable selValue {} selInfo {}
	variable abortCount
	variable pass
    }

    proc badHandler {path type offset count} {
	variable selInfo
	variable selValue
	selection handle -type $type $path {}
	lappend selInfo $path $type $offset $count
	set numBytes [expr {[string length $selValue] - $offset}]
	if {$numBytes <= 0} {
	    return ""
	}
	string range $selValue $offset [expr {$numBytes+$offset}]
    }

    proc badHandler2 {path type offset count} {
	variable abortCount
	variable selInfo
	variable selValue
	incr abortCount -1
	if {$abortCount == 0} {
	    selection handle -type $type $path {}
	}
	lappend selInfo $path $type $offset $count
	set numBytes [expr {[string length $selValue] - $offset}]
	if {$numBytes <= 0} {
	    return ""
	}
	string range $selValue $offset [expr {$numBytes+$offset}]
    }

    proc errHandler args {
	error "selection handler aborted"
    }

    proc errIncrHandler {type offset count} {
	variable selInfo
	variable selValue
	variable pass
	if {$offset == 4000} {
	    if {$pass == 0} {
		# Just sizing the selection;  don't do anything here.
		set pass 1
	    } else {
		# Fetching the selection;  wait long enough to cause a timeout.
		after 6000
	    }
	}
	lappend selInfo $type $offset $count
	set numBytes [expr {[string length $selValue] - $offset}]
	if {$numBytes <= 0} {
	    return ""
	}
	string range $selValue $offset [expr $numBytes+$offset]
    }

    proc handler {type offset count} {
	variable selInfo
	variable selValue
	lappend selInfo $type $offset $count
	set numBytes [expr {[string length $selValue] - $offset}]
	if {$numBytes <= 0} {
	    return ""
	}
	string range $selValue $offset [expr $numBytes+$offset]
    }

    proc reallyBadHandler {path type offset count} {
	variable selInfo
	variable selValue
	variable pass
	if {$offset == 4000} {
	    if {$pass == 0} {
		set pass 1
	    } else {
		selection handle -type $type $path {}
	    }
	}
	lappend selInfo $path $type $offset $count
	set numBytes [expr {[string length $selValue] - $offset}]
	if {$numBytes <= 0} {
	    return ""
	}
	string range $selValue $offset [expr {$numBytes+$offset}]
    }

    proc selectionSetup {{path .f1} {display {}}} {
	catch {destroy $path}
	if {$display eq ""} {
	    frame $path
	} else {
	    toplevel $path -screen $display
	    wm geom $path +0+0
	}
	selection own $path
    }

    testutils export
}

namespace eval ::tk::test::text {

    # init --
    #
    # This is a reserved proc that is part of the mechanism that the proc
    # testutils employs when making utility procs and associated namespace
    # variables available to test files.
    #
    # Test authors should define and initialize namespace variables here if
    # they need to be imported into the namespace in which tests are executing.
    # This proc must not be exported.
    #
    # For more information, see the documentation in the file "testutils.GUIDE"
    #
    proc init {} {
	variable fixedFont {Courier -12}
	variable fixedWidth [font measure $fixedFont m]
	variable fixedHeight [font metrics $fixedFont -linespace]
	variable fixedAscent [font metrics $fixedFont -ascent]
    }

    # full border size of the text widget, i.e. first x or y coordinate inside the text widget
    # warning:  -padx  is supposed to be the same as  -pady  (same border size horizontally and
    # vertically around the widget)
    proc bo {{w .t}} {
	return [expr {[$w cget -borderwidth] + [$w cget -highlightthickness] + [$w cget -padx]}]
    }

    # x-coordinate of the first pixel of $n-th char (count starts at zero), left justified
    proc xchar {n {w .t}} {
	return [expr {[bo $w] + [xw $n]}]
    }

    # x-width of $n chars, fixed width font
    proc xw {n} {
	variable fixedWidth
	return [expr {$n * $fixedWidth}]
    }

    # y-coordinate of the first pixel of $l-th display line (count starts at 1)
    proc yline {l {w .t}} {
	variable fixedHeight
	return [expr {[bo $w] + ($l - 1) * $fixedHeight}]
    }

    testutils export
}

# EOF
Added tests/testutils.test.
























































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
# Tests for the "testutils" command, defined in testutils.tcl
#
# © 2025 Erik Leunissen
#
# See the file "license.terms" for information on usage and redistribution of
# this file, and for a DISCLAIMER OF ALL WARRANTIES.
#

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

# Notes:
#
# - All tests have been constrained with test constraint "testutils". This
#   constraint isn't set anywhere, and therefore false by default. Therefore,
#   the tests in this file are skipped in a regular invocation of the Tk test
#   suite. In order to run these test, you need to use the tcltest option
#   "-constraints testutils" in the invocation, possibly combined with the
#   option "-file testutils.test" to exclude other test files, or with
#   "-limitconstraints true" to exclude other tests.
#
# - At this place in the test file, the file "testutils.tcl" has already been
#   sourced (through tcltest::loadTestedCommands above), and the utility procs
#   from domain "generic" are already available. Therefore we can make use of
#   proc "assert" here.
#

assert {"testutils" in [info procs testutils]}

#
# Section 1: invalid invocations
#
test testutils-1.1 {invalid subcommand} -constraints testutils -body {
    testutils foo
} -result {invalid subCmd "foo". Usage: testutils export|import|forget ?domain domain ...?} -returnCodes error

test testutils-1.2 {invalid #args for subCmd export} -constraints testutils -body {
    testutils export foo
} -result {invalid #args. Usage: testutils export} -returnCodes error

test testutils-1.3 {invalid #args for subCmd import} -constraints testutils -body {
    testutils import
} -result {invalid #args. Usage: testutils import|forget domain ?domain ...?} -returnCodes error

test testutils-1.4 {invalid #args for subCmd forget} -constraints testutils -body {
    testutils forget
} -result {invalid #args. Usage: testutils import|forget domain ?domain ...?} -returnCodes error

test testutils-1.5 {invalid domain for subCmd import} -constraints testutils -body {
    testutils import foo
} -result {testutils domain "foo" doesn't exist} -returnCodes error

test testutils-1.6 {invalid domain for subCmd forget} -constraints testutils -body {
    testutils forget foo
} -result {testutils domain "foo" doesn't exist} -returnCodes error

#
# Create a domain namespace for testing export, import, forget
#
assert {"::tk::test::foo" ni [namespace children ::tk::test]}
assert {"::tk::test::zez" ni [namespace children ::tk::test]}
catch {rename init {}}
catch {rename kuk {}}
unset -nocomplain bar pip
namespace eval ::tk::test::foo {
    proc init {} {
	variable bar 123
	variable pip
    }
    proc kuk {} {}
    testutils export
}
set initVars [info vars]; lappend initVars initVars

#
# 2. Domain failures for forget and import
#
test testutils-2.1 {forget not-imported domain} -constraints testutils -body {
    testutils forget foo
} -result {testutils domain "foo" was not imported} -returnCodes error

test testutils-2.2 {duplicate import} -constraints testutils -body {
    testutils import foo
    testutils import foo
} -result {testutils domain "foo" was already imported} -returnCodes error -cleanup {
    testutils forget foo
}

#
# 3. Import procs
#
test testutils-3.1 {utility proc is imported and init proc is not} -constraints testutils -body {
    testutils import foo
    expr {([info procs kuk] eq "kuk") && ([info procs init] eq "")}
} -result 1 -cleanup {
    testutils forget foo
}

test testutils-3.2 {forget removes utility proc} -constraints testutils -body {
    testutils import foo
    testutils forget foo
    info procs kuk
} -result {}

test testutils-3.3 {import fails: proc already exists} -constraints testutils -setup {
    namespace eval ::zez {
	proc kuk {} {}
    }
} -body {
    namespace eval ::zez {
	testutils import foo
    }
} -result "import from testutils domain \"foo\" failed: can't import command \"kuk\": already exists" -returnCodes error -cleanup {
    namespace delete ::zez
}

#
# 4. Import variables
#
test testutils-4.1 {associated variables are imported} -constraints testutils -body {
    testutils import foo
    set varNames [info vars]
    foreach name $initVars {
	set varNames [lremove $varNames [lsearch $varNames $name]]
    }
    list [lsort $varNames] [info exists bar] [info exists pip] $bar
} -result [list {bar pip} 1 0 123] -cleanup {
    unset -nocomplain name varNames
    testutils forget foo
}

test testutils-4.2 {
    Repeated initialization keeps imported variable defined without value non-existent,
    even if a test file inadvertently assigns it a value in the meantime.
} -constraints testutils -body {
    catch {
	testutils import foo
    }
    testutils forget foo
    set pip 11111
    testutils import foo
    info exists pip
} -result 0 -cleanup {
    testutils forget foo
}

test testutils-4.3 {import fails: variable already exists} -constraints testutils -setup {
    #
    # We need a pristine new namespace in which the variable bar was never imported
    # and hence no upvar link for it exists.
    #
    namespace eval ::zez {
	set bar 11
    }
} -body {
    namespace eval ::zez {
	testutils import foo
    }
} -result "import from testutils domain \"foo\" failed: variable \"bar\" already exists" -returnCodes error -cleanup {
    namespace delete ::zez
}

test testutils-4.4 {repeated creation/deletion of requesting namespace doesn't fool testutils} -constraints testutils -setup {
} -body {
    namespace eval ::zez {
	testutils import foo
	testutils forget foo
    }
    namespace delete ::zez
    namespace eval ::zez {
	set pip 22
	testutils import foo
	list [info exists bar] [info exists pip] $bar
    }
} -result {1 0 123} -cleanup {
    namespace delete ::zez
}

#
# CLEANUP
#

namespace delete ::tk::test::foo
unset -nocomplain bar initVars pip
cleanupTests

# EOF
Changes to tests/textBTree.test.
1444
1445
1446
1447
1448
1449
1450



1451

1452
1453
1454
1455
1456
1457
1458
    .t tag add x 1.25 1.28

    .t tag remove 1.4 1.23
} -cleanup {
    destroy .t
} -result {}




# cleanup

cleanupTests
return

# Local Variables:
# mode: tcl
# End:
# vi:set ts=8 sw=4:







>
>
>
|
>







1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
    .t tag add x 1.25 1.28

    .t tag remove 1.4 1.23
} -cleanup {
    destroy .t
} -result {}

#
# CLEANUP
#

rename setup {}
cleanupTests
return

# Local Variables:
# mode: tcl
# End:
# vi:set ts=8 sw=4:
Changes to tests/textDisp.test.
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
# This file is a Tcl script to test the code in the file tkTextDisp.c.
# This file is organized in the standard fashion for Tcl tests.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994-1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
eval tcltest::configure $argv
tcltest::loadTestedCommands
namespace import -force tcltest::test




# The delay procedure needs to wait long enough for the asynchronous updates
# performed by the text widget to run.
proc delay {} {
    update
    after 100
    update
}

# The procedure below is used as the scrolling command for the text;
# it just saves the scrolling information in a variable "scrollInfo".

proc scroll args {
    global scrollInfo
    set scrollInfo $args
}

# The procedure below is used to generate errors during scrolling commands.

proc scrollError args {
    error "scrolling error"
}

# Return 1 if the two given lists are the same, otherwise return the two lists.












>
>
>









<
<
<
<
<
<
<
<







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
# This file is a Tcl script to test the code in the file tkTextDisp.c.
# This file is organized in the standard fashion for Tcl tests.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994-1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
eval tcltest::configure $argv
tcltest::loadTestedCommands
namespace import -force tcltest::test

# Import utility procs for specific functional areas
testutils import scroll text

# The delay procedure needs to wait long enough for the asynchronous updates
# performed by the text widget to run.
proc delay {} {
    update
    after 100
    update
}









# The procedure below is used to generate errors during scrolling commands.

proc scrollError args {
    error "scrolling error"
}

# Return 1 if the two given lists are the same, otherwise return the two lists.
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# because some window managers don't allow the overall width of a window
# to get very narrow.

catch {destroy .f .t}
frame .f -width 100 -height 20
pack .f -side left

set fixedFont {Courier -12}
set fixedHeight [font metrics $fixedFont -linespace]
set fixedWidth [font measure $fixedFont m]
set fixedAscent [font metrics $fixedFont -ascent]

set bigFont {Helvetica -24}  ; # note: not a fixed-width font!
set bigHeight [font metrics $bigFont -linespace]
set bigAscent [font metrics $bigFont -ascent]

set ascentDiff [expr {$bigAscent - $fixedAscent}]
set heightDiff [expr {$bigHeight - $fixedHeight}]








<
<
<
<
<







55
56
57
58
59
60
61





62
63
64
65
66
67
68
# because some window managers don't allow the overall width of a window
# to get very narrow.

catch {destroy .f .t}
frame .f -width 100 -height 20
pack .f -side left






set bigFont {Helvetica -24}  ; # note: not a fixed-width font!
set bigHeight [font metrics $bigFont -linespace]
set bigAscent [font metrics $bigFont -ascent]

set ascentDiff [expr {$bigAscent - $fixedAscent}]
set heightDiff [expr {$bigHeight - $fixedHeight}]

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
is $fixedWidth pixels in width while the tests expect between 6 and 8 (inclusive) pixels.\
Some of the upcoming tests will probably fail."
}

# Option  -width 20  (characters) below is a fundamental assumption of many
# upcoming tests when wrapping enters in play
# Also  -height 10  (lines) is an important assumption
text .t -font $fixedFont -width 20 -height 10 -yscrollcommand scroll
pack .t -expand 1 -fill both
.t tag configure big -font $bigFont
.t debug on

wm geometry . {}

# full border size of the text widget, i.e. first x or y coordinate inside the text widget
# warning:  -padx  is supposed to be the same as  -pady  (same border size horizontally and
# vertically around the widget)
proc bo {{w .t}} {
    return [expr {[$w cget -borderwidth] + [$w cget -highlightthickness] + [$w cget -padx]}]
}
# x-width of $n chars, fixed width font
proc xw {n} {
    global fixedWidth
    return [expr {$n * $fixedWidth}]
}
# x-coordinate of the first pixel of $n-th char (count starts at zero), left justified
proc xchar {n {w .t}} {
    return [expr {[bo $w] + [xw $n]}]
}
# x-coordinate in widget $w of the first pixel of $n-th char counted from the right, right justified
proc xcharr {n {w .t}} {
    return [expr {[winfo width $w] - [bo $w] - [xw $n]}]
}
# y-coordinate of the first pixel of $l-th display line (count starts at 1)
proc yline {l {w .t}} {
    global fixedHeight
    return [expr {[bo $w] + ($l - 1) * $fixedHeight}]
}
# x-pixels of empty space in widget $w on a line containing $n chars
proc xe {n {w .t}} {
    return [expr {[winfo width $w] - (2 * [bo $w]) - [xw $n]}]
}

# The statements below reset the main window;  it's needed if the window
# manager is mwm to make mwm forget about a previous minimum size setting.







|






<
<
<
<
<
<
<
<
<
<
<
<
<
<
<




<
<
<
<
<







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
is $fixedWidth pixels in width while the tests expect between 6 and 8 (inclusive) pixels.\
Some of the upcoming tests will probably fail."
}

# Option  -width 20  (characters) below is a fundamental assumption of many
# upcoming tests when wrapping enters in play
# Also  -height 10  (lines) is an important assumption
text .t -font $fixedFont -width 20 -height 10 -yscrollcommand setScrollInfo
pack .t -expand 1 -fill both
.t tag configure big -font $bigFont
.t debug on

wm geometry . {}
















# x-coordinate in widget $w of the first pixel of $n-th char counted from the right, right justified
proc xcharr {n {w .t}} {
    return [expr {[winfo width $w] - [bo $w] - [xw $n]}]
}





# x-pixels of empty space in widget $w on a line containing $n chars
proc xe {n {w .t}} {
    return [expr {[winfo width $w] - (2 * [bo $w]) - [xw $n]}]
}

# The statements below reset the main window;  it's needed if the window
# manager is mwm to make mwm forget about a previous minimum size setting.
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
    foreach i {2 3 4 5 6 7 8 9 10 11 12 13} {
	.t insert end "\nLine $i"
    }
    update
    .t count -update -ypixels 1.0 end ; update
    set scrollInfo
} [list 0.0 [expr {10.0/13}]]
.t configure -yscrollcommand {} -xscrollcommand scroll
test textDisp-6.9 {DisplayText, horizontal scrollbar updates} {
    .t configure -wrap none
    .t delete 1.0 end
    update
    set scrollInfo unchanged
    .t insert end xxxxxxxxx\n
    .t insert end xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n







|







1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
    foreach i {2 3 4 5 6 7 8 9 10 11 12 13} {
	.t insert end "\nLine $i"
    }
    update
    .t count -update -ypixels 1.0 end ; update
    set scrollInfo
} [list 0.0 [expr {10.0/13}]]
.t configure -yscrollcommand {} -xscrollcommand setScrollInfo
test textDisp-6.9 {DisplayText, horizontal scrollbar updates} {
    .t configure -wrap none
    .t delete 1.0 end
    update
    set scrollInfo unchanged
    .t insert end xxxxxxxxx\n
    .t insert end xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
    .t delete 2.19
    update
    set tk_textRedraw
} {2.0 2.20 eof}
test textDisp-8.11 {TkTextChanged, scrollbar notification when changes are off-screen} {
    .t delete 1.0 end
    .t insert end "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n"
    .t configure -yscrollcommand scroll
    update
    set scrollInfo ""
    .t insert end "a\nb\nc\n"
    # We need to wait for our asychronous callbacks to update the
    # scrollbar
    update
    .t count -update -ypixels 1.0 end







|







1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
    .t delete 2.19
    update
    set tk_textRedraw
} {2.0 2.20 eof}
test textDisp-8.11 {TkTextChanged, scrollbar notification when changes are off-screen} {
    .t delete 1.0 end
    .t insert end "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n"
    .t configure -yscrollcommand setScrollInfo
    update
    set scrollInfo ""
    .t insert end "a\nb\nc\n"
    # We need to wait for our asychronous callbacks to update the
    # scrollbar
    update
    .t count -update -ypixels 1.0 end
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
    update
    set x [.t index @0,0]
    lappend expected [.t index "$origin - [expr {int(ceil((50.0+70.0)/$fixedHeight))}] display lines"]
    .t scan dragto 0 72
    update
    lequal [list $x [.t index @0,0]] $expected
} {1}
.t configure -xscrollcommand scroll -yscrollcommand {}

test textDisp-18.1 {GetXView procedure} {
    .t configure -wrap none
    .t delete 1.0 end
    .t insert end xxxxxxxxx\n
    .t insert end xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n
    .t insert end xxxxxxxxxxxxxxxxxxxxxxxxxx







|







2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
    update
    set x [.t index @0,0]
    lappend expected [.t index "$origin - [expr {int(ceil((50.0+70.0)/$fixedHeight))}] display lines"]
    .t scan dragto 0 72
    update
    lequal [list $x [.t index @0,0]] $expected
} {1}
.t configure -xscrollcommand setScrollInfo -yscrollcommand {}

test textDisp-18.1 {GetXView procedure} {
    .t configure -wrap none
    .t delete 1.0 end
    .t insert end xxxxxxxxx\n
    .t insert end xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n
    .t insert end xxxxxxxxxxxxxxxxxxxxxxxxxx
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
    (procedure "scrollError" line 2)
    invoked from within
"scrollError 0.0 1.0"
    (horizontal scrolling command executed by text)}}
catch {rename bgerror {}}
catch {rename bogus {}}

.t configure -xscrollcommand {} -yscrollcommand scroll
test textDisp-19.1 {GetYView procedure} {
    .t configure -wrap char
    .t delete 1.0 end
    update
    set scrollInfo
} {0.0 1.0}
test textDisp-19.2 {GetYView procedure} {







|







2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
    (procedure "scrollError" line 2)
    invoked from within
"scrollError 0.0 1.0"
    (horizontal scrolling command executed by text)}}
catch {rename bgerror {}}
catch {rename bogus {}}

.t configure -xscrollcommand {} -yscrollcommand setScrollInfo
test textDisp-19.1 {GetYView procedure} {
    .t configure -wrap char
    .t delete 1.0 end
    update
    set scrollInfo
} {0.0 1.0}
test textDisp-19.2 {GetYView procedure} {
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
    proc bgerror args {
	global x errorInfo errorCode
	set x [list $args $errorInfo $errorCode]
    }
    .t delete 1.0 end
    update
    rename bgerror {}
    .t configure -yscrollcommand scroll
    set x
} {{{scrolling error}} {scrolling error
    while executing
"error "scrolling error""
    (procedure "scrollError" line 2)
    invoked from within
"scrollError 0.0 1.0"







|







3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
    proc bgerror args {
	global x errorInfo errorCode
	set x [list $args $errorInfo $errorCode]
    }
    .t delete 1.0 end
    update
    rename bgerror {}
    .t configure -yscrollcommand setScrollInfo
    set x
} {{{scrolling error}} {scrolling error
    while executing
"error "scrolling error""
    (procedure "scrollError" line 2)
    invoked from within
"scrollError 0.0 1.0"
4945
4946
4947
4948
4949
4950
4951





4952
4953
4954
4955
4956
4957
   update
   # wish panicks with the legacy text widget
   .t1 yview scroll -1 pixels
} -cleanup {
    destroy .t1
} -result {}






deleteWindows
option clear

# cleanup
cleanupTests
return







>
>
>
>
>


<
<


4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928


4929
4930
   update
   # wish panicks with the legacy text widget
   .t1 yview scroll -1 pixels
} -cleanup {
    destroy .t1
} -result {}

#
# CLEANUP
#

testutils forget scroll text
deleteWindows
option clear


cleanupTests
return
Changes to tests/textImage.test.
1
2
3
4
5
6
7
8
9
10
11
12
13




14
15
16
17
18
19
20
# textImage.test -- test images embedded in text widgets
#
# This file contains a collection of tests for one or more of the Tcl
# built-in commands.  Sourcing this file into Tcl runs the tests and
# generates output for errors.  No output means no errors were found.
#
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands




imageInit

# One time setup.  Create a font to insure the tests are font metric invariant.
destroy .t
font create test_font -family courier -size 14
text .t -font test_font
.t debug on













>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# textImage.test -- test images embedded in text widgets
#
# This file contains a collection of tests for one or more of the Tcl
# built-in commands.  Sourcing this file into Tcl runs the tests and
# generates output for errors.  No output means no errors were found.
#
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands

# Import utility procs for specific functional areas
testutils import image

imageInit

# One time setup.  Create a font to insure the tests are font metric invariant.
destroy .t
font create test_font -family courier -size 14
text .t -font test_font
.t debug on
437
438
439
440
441
442
443



444
445
446
447
448
449
450
451
452
453
454
455
456
    .t insert end test
    update
    destroy .t .tt
} -cleanup {
    image delete small large
} -result {}




# cleanup
destroy .t
font delete test_font
imageFinish

# cleanup
cleanupTests
return

# Local variables:
# mode: tcl
# End:
# vi:set ts=8 sw=4:







>
>
>
|



|
<







441
442
443
444
445
446
447
448
449
450
451
452
453
454
455

456
457
458
459
460
461
462
    .t insert end test
    update
    destroy .t .tt
} -cleanup {
    image delete small large
} -result {}

#
# CLEANUP
#

destroy .t
font delete test_font
imageFinish
testutils forget image

cleanupTests
return

# Local variables:
# mode: tcl
# End:
# vi:set ts=8 sw=4:
Changes to tests/textIndex.test.
1
2
3
4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19
# This file is a Tcl script to test the code in the file tkTextIndex.c.
# This file is organized in the standard fashion for Tcl tests.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
eval tcltest::configure $argv
tcltest::loadTestedCommands
namespace import -force tcltest::test


testConstraint failsOnXQuarz [expr {$tcl_platform(os) ne "Darwin" || [tk windowingsystem] ne "x11" }]

catch {destroy .t}
text .t -font {Courier -12} -width 20 -height 10
pack .t -expand 1 -fill both
update












>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# This file is a Tcl script to test the code in the file tkTextIndex.c.
# This file is organized in the standard fashion for Tcl tests.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
eval tcltest::configure $argv
tcltest::loadTestedCommands
namespace import -force tcltest::test
testutils import text

testConstraint failsOnXQuarz [expr {$tcl_platform(os) ne "Darwin" || [tk windowingsystem] ne "x11" }]

catch {destroy .t}
text .t -font {Courier -12} -width 20 -height 10
pack .t -expand 1 -fill both
update
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
    catch {destroy .t2}
    set res
} {3.4 3.0 1.0}

frame .f -width 100 -height 20
pack .f -side left

set fixedFont {Courier -12}
set fixedHeight [font metrics $fixedFont -linespace]
set fixedWidth [font measure $fixedFont m]

set varFont {Times -14}
set bigFont {Helvetica -24}
destroy .t
text .t -font $fixedFont -width 20 -height 10 -wrap char
pack .t -expand 1 -fill both
.t tag configure big -font $bigFont
wm geometry . {}







<
<
<
<







740
741
742
743
744
745
746




747
748
749
750
751
752
753
    catch {destroy .t2}
    set res
} {3.4 3.0 1.0}

frame .f -width 100 -height 20
pack .f -side left





set varFont {Times -14}
set bigFont {Helvetica -24}
destroy .t
text .t -font $fixedFont -width 20 -height 10 -wrap char
pack .t -expand 1 -fill both
.t tag configure big -font $bigFont
wm geometry . {}
1108
1109
1110
1111
1112
1113
1114

1115
1116
1117
1118
1119
1120
1121
    .t mark set 1.0 1.1
    .t index 1.0
} -result {1.0}

# cleanup
rename textimage {}
catch {destroy .t}

cleanupTests
return

# Local variables:
# mode: tcl
# End:
# vi:set ts=8 sw=4:







>







1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
    .t mark set 1.0 1.1
    .t index 1.0
} -result {1.0}

# cleanup
rename textimage {}
catch {destroy .t}
testutils forget text
cleanupTests
return

# Local variables:
# mode: tcl
# End:
# vi:set ts=8 sw=4:
Changes to tests/textTag.test.
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
# This file is a Tcl script to test the code in the file tkTextTag.c.
# This file is organized in the standard fashion for Tcl tests.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994-1996 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands






set fixedFont {Courier 12}
set bigFont   {Helvetica 24}

# Warn the user if the actual font is too different from what was requested.
if {[font metrics [font actual $fixedFont] -fixed] != 1} {
    puts "---> Warning: the font actually used by the tests, which is \"[font actual $fixedFont]\",\
does not seem to be a fixed-width font as expected. If this is really the case, many upcoming\
tests will fail."
}

destroy .t
text .t -width 20 -height 10 -font $fixedFont

pack .t -expand 1 -fill both
update
.t debug on

wm geometry . {}














>
>
>
>
>
|



|
|





|







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
# This file is a Tcl script to test the code in the file tkTextTag.c.
# This file is organized in the standard fashion for Tcl tests.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994-1996 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands

#
# Don't use the variable name "fixedFont" since that variable is already defined
# in utility namespace ::tk::test::text for importing in the namespace in which
# test files are executing.
#
set fixedFont2 {Courier 12}
set bigFont   {Helvetica 24}

# Warn the user if the actual font is too different from what was requested.
if {[font metrics [font actual $fixedFont2] -fixed] != 1} {
    puts "---> Warning: the font actually used by the tests, which is \"[font actual $fixedFont2]\",\
does not seem to be a fixed-width font as expected. If this is really the case, many upcoming\
tests will fail."
}

destroy .t
text .t -width 20 -height 10 -font $fixedFont2

pack .t -expand 1 -fill both
update
.t debug on

wm geometry . {}

Changes to tests/textWind.test.
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
# This file is a Tcl script to test the code in the file tkTextWind.c.
# This file is organized in the standard fashion for Tcl tests.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994-1995 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
tcltest::configure {*}$argv
tcltest::loadTestedCommands


deleteWindows

set fixedFont {Courier -12}
set fixedHeight [font metrics $fixedFont -linespace]
set fixedWidth [font measure $fixedFont m]
set fixedAscent [font metrics $fixedFont -ascent]

# On Windows at least, the tests do work with {Courier -10}, {Courier -12} or {Courier -14} as fixedFont.
# Warn the user if the actual font is too different from what was requested.
if {[font metrics [font actual $fixedFont] -fixed] != 1} {
    puts "---> Warning: the font actually used by the tests, which is \"[font actual $fixedFont]\",\
does not seem to be a fixed-width font as expected. If this is really the case, many upcoming\
tests will fail."
}













>
|

|
<
<
<








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
# This file is a Tcl script to test the code in the file tkTextWind.c.
# This file is organized in the standard fashion for Tcl tests.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994-1995 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
tcltest::configure {*}$argv
tcltest::loadTestedCommands

# Import utility procs for specific functional areas
testutils import text

deleteWindows




# On Windows at least, the tests do work with {Courier -10}, {Courier -12} or {Courier -14} as fixedFont.
# Warn the user if the actual font is too different from what was requested.
if {[font metrics [font actual $fixedFont] -fixed] != 1} {
    puts "---> Warning: the font actually used by the tests, which is \"[font actual $fixedFont]\",\
does not seem to be a fixed-width font as expected. If this is really the case, many upcoming\
tests will fail."
}
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
text .t -font $fixedFont -width 30 -height 6 -borderwidth 2 -highlightthickness 2
pack .t -expand 1 -fill both
update
.t debug on

wm geometry . {}

# full border size of the text widget, i.e. first x or y coordinate inside the text widget
# warning:  -padx  is supposed to be the same as  -pady  (same border size horizontally and
# vertically around the widget)
proc bo {{w .t}} {
    return [expr {[$w cget -borderwidth] + [$w cget -highlightthickness] + [$w cget -padx]}]
}
# x-width of $n chars, fixed width font
proc xw {n} {
    global fixedWidth
    return [expr {$n * $fixedWidth}]
}
# x-coordinate of the first pixel of $n-th char (count starts at zero), left justified
proc xchar {n {w .t}} {
    return [expr {[bo $w] + [xw $n]}]
}
# y-coordinate of the first pixel of $l-th display line (count starts at 1)
proc yline {l {w .t}} {
    global fixedHeight
    return [expr {[bo $w] + ($l - 1) * $fixedHeight}]
}

set color [expr {[winfo depth .t] > 1 ? "green" : "black"}]

# The statements below reset the main window;  it's needed if the window
# manager is mwm to make mwm forget about a previous minimum size setting.

wm withdraw .
wm minsize . 1 1







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







43
44
45
46
47
48
49





















50
51
52
53
54
55
56
text .t -font $fixedFont -width 30 -height 6 -borderwidth 2 -highlightthickness 2
pack .t -expand 1 -fill both
update
.t debug on

wm geometry . {}






















set color [expr {[winfo depth .t] > 1 ? "green" : "black"}]

# The statements below reset the main window;  it's needed if the window
# manager is mwm to make mwm forget about a previous minimum size setting.

wm withdraw .
wm minsize . 1 1
1660
1661
1662
1663
1664
1665
1666
1667
1668



1669

1670
1671
1672
1673
1674
1675
1676
    # this shall not crash (bug 54fe7a5e71)
    after 100 {.t delete 1.0 end}
    tkwait variable x
} -cleanup {
    destroy .t .f
} -result {}

option clear




# cleanup

cleanupTests
return

# Local variables:
# mode: tcl
# End:
# vi:set ts=8 sw=4:







|
|
>
>
>
|
>







1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
    # this shall not crash (bug 54fe7a5e71)
    after 100 {.t delete 1.0 end}
    tkwait variable x
} -cleanup {
    destroy .t .f
} -result {}


#
# CLEANUP
#

option clear
testutils forget text
cleanupTests
return

# Local variables:
# mode: tcl
# End:
# vi:set ts=8 sw=4:
Changes to tests/ttk/all.tcl.
10
11
12
13
14
15
16
17
18
19
20
21
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.

package require tk ;# This is the Tk test suite; fail early if no Tk!
package require tcltest 2.2
tcltest::configure {*}$argv
tcltest::configure -testdir [file normalize [file dirname [info script]]]
tcltest::configure -loadfile \
    [file join [file dirname [tcltest::testsDirectory]] constraints.tcl]
tcltest::configure -singleproc 1
set ErrorOnFailures [info exists env(ERROR_ON_FAILURES)]
encoding system utf-8
if {[tcltest::runAllTests] && $ErrorOnFailures} {exit 1}







|




10
11
12
13
14
15
16
17
18
19
20
21
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.

package require tk ;# This is the Tk test suite; fail early if no Tk!
package require tcltest 2.2
tcltest::configure {*}$argv
tcltest::configure -testdir [file normalize [file dirname [info script]]]
tcltest::configure -loadfile \
    [file join [file dirname [tcltest::testsDirectory]] main.tcl]
tcltest::configure -singleproc 1
set ErrorOnFailures [info exists env(ERROR_ON_FAILURES)]
encoding system utf-8
if {[tcltest::runAllTests] && $ErrorOnFailures} {exit 1}
Changes to tests/ttk/entry.test.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#
# Tile package: entry widget tests
#

package require tk
package require tcltest 2.2
namespace import -force tcltest::*
loadTestedCommands

variable scrollInfo
proc scroll args {
    global scrollInfo
    set scrollInfo $args
}

# Some of the tests raise background errors;
# override default bgerror to catch them.
#
variable bgerror ""
proc bgerror {error} {
    variable bgerror $error









<
|
|
<
<







1
2
3
4
5
6
7
8
9

10
11


12
13
14
15
16
17
18
#
# Tile package: entry widget tests
#

package require tk
package require tcltest 2.2
namespace import -force tcltest::*
loadTestedCommands


# Import utility procs for specific functional areas
testutils import entry scroll



# Some of the tests raise background errors;
# override default bgerror to catch them.
#
variable bgerror ""
proc bgerror {error} {
    variable bgerror $error
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
    pack [ttk::scrollbar .tsb -orient horizontal -command [list .te xview]] \
	    -expand false -fill x
    update ; # no error
    set res [expr [lindex [.tsb get] 1] < 1] ; # scrollbar did update
} -result 1 -cleanup {destroy .te .tsb}

test entry-2.2 "Initial scroll position" -body {
    ttk::entry .e -font fixed -width 5 -xscrollcommand scroll
    .e insert end "0123456789"
    pack .e;
    set timeout [after 500 {set $scrollInfo "timeout"}]
    vwait scrollInfo
    set scrollInfo
} -cleanup {
    destroy .e
    after cancel $timeout
} -result {0.0 0.5}
# NOTE: result can vary depending on font.







|


|







88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
    pack [ttk::scrollbar .tsb -orient horizontal -command [list .te xview]] \
	    -expand false -fill x
    update ; # no error
    set res [expr [lindex [.tsb get] 1] < 1] ; # scrollbar did update
} -result 1 -cleanup {destroy .te .tsb}

test entry-2.2 "Initial scroll position" -body {
    ttk::entry .e -font fixed -width 5 -xscrollcommand setScrollInfo
    .e insert end "0123456789"
    pack .e;
    set timeout [after 500 {set scrollInfo "timeout"}]
    vwait scrollInfo
    set scrollInfo
} -cleanup {
    destroy .e
    after cancel $timeout
} -result {0.0 0.5}
# NOTE: result can vary depending on font.
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

# TODO: test killing .e in -validatecommand, -invalidcommand, variable trace;


# -textvariable tests.

test entry-6.1 {Update linked variable in write trace} -body {
    proc override args {
	global x
	set x "Overridden!"
    }
    catch {destroy .e}
    set x ""
    trace add variable x write override
    ttk::entry .e -textvariable x
    .e insert 0 "Some text"
    set result [list $x [.e get]]
    set result
} -result {Overridden! Overridden!} -cleanup {

    unset x
    rename override {}
    destroy .e
}

test entry-6.2 {-textvariable tests} -body {
    set result [list]
    ttk::entry .e -textvariable x
    set x "text"
    lappend result [.e get]
    unset x
    lappend result [.e get]
    .e insert end "newtext"
    lappend result [.e get] [set x]
} -result [list "text" "" "newtext" "newtext"] -cleanup {
    destroy .e
    unset -nocomplain x
}

test entry-7.1 {Bad style options} -body {
    ttk::style theme create entry-7.1 -settings {
	ttk::style configure TEntry -foreground BadColor
	ttk::style map TEntry -foreground {readonly AnotherBadColor}
	ttk::style map TEntry -font {readonly ABadFont}







<
<
<
<

|
|
|

|

|
>
|
<





|
|

|


|


|







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

# TODO: test killing .e in -validatecommand, -invalidcommand, variable trace;


# -textvariable tests.

test entry-6.1 {Update linked variable in write trace} -body {




    catch {destroy .e}
    set textVar ""
    trace add variable textVar write override
    ttk::entry .e -textvariable textVar
    .e insert 0 "Some text"
    set result [list $textVar [.e get]]
    set result
} -result {12345 12345} -cleanup {
    trace remove variable textVar write override
    unset textVar

    destroy .e
}

test entry-6.2 {-textvariable tests} -body {
    set result [list]
    ttk::entry .e -textvariable textVar
    set textVar "text"
    lappend result [.e get]
    unset textVar
    lappend result [.e get]
    .e insert end "newtext"
    lappend result [.e get] $textVar
} -result [list "text" "" "newtext" "newtext"] -cleanup {
    destroy .e
    unset -nocomplain textVar
}

test entry-7.1 {Bad style options} -body {
    ttk::style theme create entry-7.1 -settings {
	ttk::style configure TEntry -foreground BadColor
	ttk::style map TEntry -foreground {readonly AnotherBadColor}
	ttk::style map TEntry -font {readonly ABadFont}
403
404
405
406
407
408
409





410
    ttk::style configure customStyle.TEntry
    ttk::entry .w -style customStyle.TEntry
    list [.w cget -style] [.w style] [winfo class .w]
} -cleanup {
    destroy .w
} -result {customStyle.TEntry customStyle.TEntry TEntry}






tcltest::cleanupTests







>
>
>
>
>

396
397
398
399
400
401
402
403
404
405
406
407
408
    ttk::style configure customStyle.TEntry
    ttk::entry .w -style customStyle.TEntry
    list [.w cget -style] [.w style] [winfo class .w]
} -cleanup {
    destroy .w
} -result {customStyle.TEntry customStyle.TEntry TEntry}

#
# CLEANUP
#

testutils forget entry scroll
tcltest::cleanupTests
Changes to tests/ttk/scrollbar.test.
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
package require tk
package require tcltest 2.2
namespace import -force tcltest::*
loadTestedCommands

testConstraint coreScrollbar [expr {[tk windowingsystem] eq "aqua"}]

# Before 2019 the code in library/ttk/scrollbar.tcl would replace the
# constructor of ttk::scrollbar with the constructor of tk::scrollbar
# unless the -class or -style options were specified..
# Now there is an implementation of ttk::scrollbar for macOS.  The
# tests are left in place, though, except that scrollbar-swapout-1
# test was changed to expect the class to be TScrollbar instead of
# Scrollbar.

test scrollbar-swapout-1 "Don't use core scrollbars on OSX..." \
 -constraints {
     coreScrollbar
} -body {
    ttk::scrollbar .sb -command "yadda"
    list [winfo class .sb] [.sb cget -command]
} -result [list TScrollbar yadda] -cleanup {
    destroy .sb
}

test scrollbar-swapout-2 "... regardless of whether -style ..." \
-constraints {
    coreScrollbar
} -body {
    ttk::style layout Vertical.Custom.TScrollbar \
	[ttk::style layout Vertical.TScrollbar] ; # See #1833339
    ttk::scrollbar .sb -command "yadda" -style Custom.TScrollbar
    list [winfo class .sb] [.sb cget -command] [.sb cget -style]
} -result [list TScrollbar yadda Custom.TScrollbar] -cleanup {
    destroy .sb
}

test scrollbar-swapout-3 "... or -class is specified." -constraints {
    coreScrollbar
} -body {
    ttk::scrollbar .sb -command "yadda" -class Custom.TScrollbar
    list [winfo class .sb] [.sb cget -command]
} -result [list Custom.TScrollbar yadda] -cleanup {
    destroy .sb
}






<
<










|









|










|







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
package require tk
package require tcltest 2.2
namespace import -force tcltest::*
loadTestedCommands



# Before 2019 the code in library/ttk/scrollbar.tcl would replace the
# constructor of ttk::scrollbar with the constructor of tk::scrollbar
# unless the -class or -style options were specified..
# Now there is an implementation of ttk::scrollbar for macOS.  The
# tests are left in place, though, except that scrollbar-swapout-1
# test was changed to expect the class to be TScrollbar instead of
# Scrollbar.

test scrollbar-swapout-1 "Don't use core scrollbars on OSX..." \
 -constraints {
     aqua
} -body {
    ttk::scrollbar .sb -command "yadda"
    list [winfo class .sb] [.sb cget -command]
} -result [list TScrollbar yadda] -cleanup {
    destroy .sb
}

test scrollbar-swapout-2 "... regardless of whether -style ..." \
-constraints {
    aqua
} -body {
    ttk::style layout Vertical.Custom.TScrollbar \
	[ttk::style layout Vertical.TScrollbar] ; # See #1833339
    ttk::scrollbar .sb -command "yadda" -style Custom.TScrollbar
    list [winfo class .sb] [.sb cget -command] [.sb cget -style]
} -result [list TScrollbar yadda Custom.TScrollbar] -cleanup {
    destroy .sb
}

test scrollbar-swapout-3 "... or -class is specified." -constraints {
    aqua
} -body {
    ttk::scrollbar .sb -command "yadda" -class Custom.TScrollbar
    list [winfo class .sb] [.sb cget -command]
} -result [list Custom.TScrollbar yadda] -cleanup {
    destroy .sb
}

Changes to tests/ttk/treetags.test.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

package require tk
package require tcltest 2.2
namespace import -force tcltest::*
loadTestedCommands

### treeview tag invariants:
#

proc assert {expr {message ""}} {
    if {![uplevel 1 [list expr $expr]]} {
	error "PANIC: $message ($expr failed)"
    }
}

proc itemConstraints {tv item} {
    # $tag in [$tv item $item -tags] <==> [$tv tag has $tag $item]
    foreach tag [$tv item $item -tags] {
	assert {$item in [$tv tag has $tag]}
    }
    foreach child [$tv children $item] {
	itemConstraints $tv $child









<
<
<
<
<
<







1
2
3
4
5
6
7
8
9






10
11
12
13
14
15
16

package require tk
package require tcltest 2.2
namespace import -force tcltest::*
loadTestedCommands

### treeview tag invariants:
#







proc itemConstraints {tv item} {
    # $tag in [$tv item $item -tags] <==> [$tv tag has $tag $item]
    foreach tag [$tv item $item -tags] {
	assert {$item in [$tv tag has $tag]}
    }
    foreach child [$tv children $item] {
	itemConstraints $tv $child
Changes to tests/ttk/treeview.test.
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
#
# [7Jun2005] TO CHECK: [$tv see {}] -- shouldn't work (at least, shouldn't do
# what it currently does)
#

package require tk
package require tcltest 2.2
namespace import -force tcltest::*
loadTestedCommands




# consistencyCheck --
#	Traverse the tree to make sure the item data structures
#	are properly linked.
#
#	Since [$tv children] follows ->next links and [$tv index]
#	follows ->prev links, this should cover all invariants.
#
proc consistencyCheck {tv {item {}}} {
    set i 0
    foreach child [$tv children $item] {
	assert {[$tv parent $child] == $item} "parent $child = $item"
	assert {[$tv index $child] == $i} "index $child [$tv index $child]=$i"
	incr i
	consistencyCheck $tv $child
    }
}

proc assert {expr {message ""}} {
    if {![uplevel 1 [list expr $expr]]} {
	set error "PANIC! PANIC! PANIC: $message ($expr failed)"
	puts stderr $error
	error $error
    }
}

proc tvSetup {} {
    destroy .tv
    ttk::treeview .tv -columns {a b c}
    pack .tv -expand true -fill both
    .tv column #0 -width 50
    .tv column a -width 50
    .tv column b -width 50










>
>
>










|
|





<
<
<
<
<
<
<
<







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
#
# [7Jun2005] TO CHECK: [$tv see {}] -- shouldn't work (at least, shouldn't do
# what it currently does)
#

package require tk
package require tcltest 2.2
namespace import -force tcltest::*
loadTestedCommands

# Import utility procs for specific functional areas
testutils import scroll

# consistencyCheck --
#	Traverse the tree to make sure the item data structures
#	are properly linked.
#
#	Since [$tv children] follows ->next links and [$tv index]
#	follows ->prev links, this should cover all invariants.
#
proc consistencyCheck {tv {item {}}} {
    set i 0
    foreach child [$tv children $item] {
	assert {[$tv parent $child] eq $item}
	assert {[$tv index $child] == $i}
	incr i
	consistencyCheck $tv $child
    }
}









proc tvSetup {} {
    destroy .tv
    ttk::treeview .tv -columns {a b c}
    pack .tv -expand true -fill both
    .tv column #0 -width 50
    .tv column a -width 50
    .tv column b -width 50
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
    set res
} -cleanup {
    bind .tv <<TreeviewSelect>> {}
} -result {2 3 4}

### NEED: more tests for see/yview/scrolling

proc scrollcallback {args} {
    set ::scrolldata $args
}
test treeview-9.0 "scroll callback - empty tree" -body {
    tvSetup
    .tv configure -yscrollcommand scrollcallback
    .tv delete [.tv children {}]
    update
    set ::scrolldata
} -result [list 0.0 1.0]

test treeview-9.1 "scrolling" -setup {
    pack [ttk::treeview .tree -show tree] -fill y
    for {set i 1} {$i < 100} {incr i} {
	.tree insert {} end -text $i
    }







<
<
<


|


|







604
605
606
607
608
609
610



611
612
613
614
615
616
617
618
619
620
621
622
623
    set res
} -cleanup {
    bind .tv <<TreeviewSelect>> {}
} -result {2 3 4}

### NEED: more tests for see/yview/scrolling




test treeview-9.0 "scroll callback - empty tree" -body {
    tvSetup
    .tv configure -yscrollcommand setScrollInfo
    .tv delete [.tv children {}]
    update
    set scrollInfo
} -result [list 0.0 1.0]

test treeview-9.1 "scrolling" -setup {
    pack [ttk::treeview .tree -show tree] -fill y
    for {set i 1} {$i < 100} {incr i} {
	.tree insert {} end -text $i
    }
1504
1505
1506
1507
1508
1509
1510





1511
    .tv tag configure mytag -imageanchor nw
    .tv tag configure mytag -padding {2 4 6 8}
    .tv tag configure mytag -padding
} -cleanup {
    destroy .tv
} -result {2 4 6 8}






tcltest::cleanupTests







>
>
>
>
>

1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
    .tv tag configure mytag -imageanchor nw
    .tv tag configure mytag -padding {2 4 6 8}
    .tv tag configure mytag -padding
} -cleanup {
    destroy .tv
} -result {2 4 6 8}

#
# CLEANUP
#

testutils forget scroll
tcltest::cleanupTests
Changes to tests/ttk/validate.test.
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
##
## Entry widget validation tests
## Derived from core test suite entry-19.1 through entry-19.20
##

package require tk
package require tcltest 2.2

namespace import -force tcltest::*



loadTestedCommands




testConstraint ttkEntry 1
testConstraint coreEntry [expr {![testConstraint ttkEntry]}]

eval tcltest::configure $argv

test validate-0.0 "Setup" -constraints ttkEntry -body {
    rename entry {}
    interp alias {} entry {} ttk::entry
    return;
}

test validate-0.1 "More setup" -body {
    destroy .e
    catch {unset ::e}
    catch {unset ::vVals}
    entry .e -validate all \
	    -validatecommand [list doval %W %d %i %P %s %S %v %V] \
	    -invalidcommand bell \
	    -textvariable ::e \
	    ;
    pack .e
    proc doval {W d i P s S v V} {
	set ::vVals [list $W $d $i $P $s $S $v $V]
	return 1
    }
}

# The validation tests build each one upon the previous, so cascading
# failures aren't good
#
test validate-1.1 {entry widget validation - insert} -body {
    .e insert 0 a
    set ::vVals
} -result {.e 1 0 a {} a all key}

test validate-1.2 {entry widget validation - insert} -body {
    .e insert 1 b
    set ::vVals
} -result {.e 1 1 ab a b all key}

test validate-1.3 {entry widget validation - insert} -body {
    .e insert end c
    set ::vVals
} -result {.e 1 2 abc ab c all key}

test validate-1.4 {entry widget validation - insert} -body {
    .e insert 1 123
    list $::vVals $::e
} -result {{.e 1 1 a123bc abc 123 all key} a123bc}

test validate-1.5 {entry widget validation - delete} -body {
    .e delete 2
    set ::vVals
} -result {.e 0 2 a13bc a123bc 2 all key}

test validate-1.6 {entry widget validation - delete} -body {
    .e configure -validate key
    .e delete 1 3
    set ::vVals
} -result {.e 0 1 abc a13bc 13 key key}

test validate-1.7 {entry widget validation - vmode focus} -body {
    set ::vVals {}
    .e configure -validate focus
    .e insert end d
    set ::vVals
} -result {}

test validate-1.8 {entry widget validation - vmode focus} -body {
    set ::vVals {}
    set timer [after 300 lappend ::vVals timeout]
    focus -force .e
    vwait ::vVals
    after cancel $timer
    set ::vVals
} -result {.e -1 -1 abcd abcd {} focus focusin}

test validate-1.9 {entry widget validation - vmode focus} -body {
    set ::vVals {}
    set timer [after 300 lappend ::vVals timeout]
    focus -force .
    vwait ::vVals
    after cancel $timer
    set ::vVals
} -result {.e -1 -1 abcd abcd {} focus focusout}

.e configure -validate all
test validate-1.10 {entry widget validation - vmode all} -body {
    set ::vVals {}
    set timer [after 300 lappend ::vVals timeout]
    focus -force .e
    vwait ::vVals
    after cancel $timer
    set ::vVals
} -result {.e -1 -1 abcd abcd {} all focusin}

test validate-1.11 {entry widget validation} -body {
    set ::vVals {}
    set timer [after 300 lappend ::vVals timeout]
    focus -force .
    vwait ::vVals
    after cancel $timer
    set ::vVals
} -result {.e -1 -1 abcd abcd {} all focusout}
.e configure -validate focusin

test validate-1.12 {entry widget validation} -body {
    set ::vVals {}
    set timer [after 300 lappend ::vVals timeout]
    focus -force .e
    vwait ::vVals
    after cancel $timer
    set ::vVals
} -result {.e -1 -1 abcd abcd {} focusin focusin}

test validate-1.13 {entry widget validation} -body {
    set ::vVals {}
    focus -force .
    update
    set ::vVals
} -result {}
.e configure -validate focuso

test validate-1.14 {entry widget validation} -body {
    set ::vVals {}
    focus -force .e
    update
    set ::vVals
} -result {}

test validate-1.15 {entry widget validation} -body {
    focus -force .
    # update necessary to process FocusOut event
    update
    set ::vVals
} -result {.e -1 -1 abcd abcd {} focusout focusout}

# DIFFERENCE: core entry temporarily sets "-validate all", ttk::entry doesn't.
test validate-1.16 {entry widget validation} -body {
    .e configure -validate all
    list [.e validate] $::vVals
} -result {1 {.e -1 -1 abcd abcd {} all forced}}

# DIFFERENCE: ttk::entry does not perform validation when setting the -variable
test validate-1.17 {entry widget validation} -constraints coreEntry -body {
    .e configure -validate all
    set ::e newdata
    list [.e cget -validate] $::vVals
} -result {all {.e -1 -1 newdata abcd {} all forced}}

proc doval {W d i P s S v V} {
    set ::vVals [list $W $d $i $P $s $S $v $V]
    return 0
}

test validate-1.18 {entry widget validation} -constraints coreEntry -body {
    .e configure -validate all
    set ::e nextdata
    list [.e cget -validate] $::vVals
} -result {none {.e -1 -1 nextdata newdata {} all forced}}
# DIFFERENCE: ttk::entry doesn't validate when setting linked -variable
# DIFFERENCE: ttk::entry doesn't disable validation

proc doval {W d i P s S v V} {
    set ::vVals [list $W $d $i $P $s $S $v $V]
    set ::e mydata
    return 1
}

## This sets validate to none because it shows that we prevent a possible
## loop condition in the validation, when the entry textvar is also set
test validate-1.19 {entry widget validation} -constraints coreEntry -body {
    .e configure -validate all
    .e validate
    list [.e cget -validate] [.e get] $::vVals
} -result {none mydata {.e -1 -1 nextdata nextdata {} all forced}}

## This leaves validate alone because we trigger validation through the
## textvar (a write trace), and the write during validation triggers
## nothing (by definition of avoiding loops on var traces).  This is
## one of those "dangerous" conditions where the user will have a
## different value in the entry widget shown as is in the textvar.

# DIFFERENCE: ttk entry doesn't get out of sync w/textvar
test validate-1.20 {entry widget validation} -constraints coreEntry -body {
    .e configure -validate all
    set ::e testdata
    list [.e cget -validate] [.e get] $::e $::vVals
} -result {all testdata mydata {.e -1 -1 testdata mydata {} all forced}}

#
# New tests, -JE:
#
proc doval {W d i P s S v V} {
    set ::vVals [list $W $d $i $P $s $S $v $V]
    .e delete 0 end;
    .e insert end dovaldata
    return 0
}
test validate-2.1 "Validation script changes value" -body {
    .e configure -validate none
    set ::e testdata
    .e configure -validate all
    .e validate
    list [.e get] $::e $::vVals
} -result {dovaldata dovaldata {.e -1 -1 testdata testdata {} all forced}}
# DIFFERENCE: core entry disables validation, ttk entry does not.

destroy .e
catch {unset ::e ::vVals}

# See bug #1236979

test validate-2.2 "configure in -validatecommand" -body {
    proc validate-2.2 {win str} {
	$win configure -foreground black
	return 1







>

>

>
|
>
>
>




<









|
|

|

|


<
<
<
<







|




|




|




|




|





|



|


|



|
|

|

|



|
|

|

|




|
|

|

|



|
|

|

|




|
|

|

|



|


|




|


|






|





|





|
|


<
<
<
<
<

|
|
|




<
<
<
<
<
<



|

|










|
|
|


<
<
<
<
<
<
<
<
<

|
|


|




|







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
##
## Entry widget validation tests
## Derived from core test suite entry-19.1 through entry-19.20
##

package require tk
package require tcltest 2.2
eval tcltest::configure $argv
namespace import -force tcltest::*
loadTestedCommands

# Import utility procs for specific functional areas
testutils import entry
foreach i {1 2 3 4} {
    set validateCmd$i [list validateCommand$i %W %d %i %P %s %S %v %V]
}

testConstraint ttkEntry 1
testConstraint coreEntry [expr {![testConstraint ttkEntry]}]



test validate-0.0 "Setup" -constraints ttkEntry -body {
    rename entry {}
    interp alias {} entry {} ttk::entry
    return;
}

test validate-0.1 "More setup" -body {
    destroy .e
    catch {unset textVar}
    unset -nocomplain validationData; # not necessary
    entry .e -validate all \
	    -validatecommand $validateCmd1 \
	    -invalidcommand bell \
	    -textvariable textVar \
	    ;
    pack .e




}

# The validation tests build each one upon the previous, so cascading
# failures aren't good
#
test validate-1.1 {entry widget validation - insert} -body {
    .e insert 0 a
    set validationData
} -result {.e 1 0 a {} a all key}

test validate-1.2 {entry widget validation - insert} -body {
    .e insert 1 b
    set validationData
} -result {.e 1 1 ab a b all key}

test validate-1.3 {entry widget validation - insert} -body {
    .e insert end c
    set validationData
} -result {.e 1 2 abc ab c all key}

test validate-1.4 {entry widget validation - insert} -body {
    .e insert 1 123
    list $validationData $textVar
} -result {{.e 1 1 a123bc abc 123 all key} a123bc}

test validate-1.5 {entry widget validation - delete} -body {
    .e delete 2
    set validationData
} -result {.e 0 2 a13bc a123bc 2 all key}

test validate-1.6 {entry widget validation - delete} -body {
    .e configure -validate key
    .e delete 1 3
    set validationData
} -result {.e 0 1 abc a13bc 13 key key}

test validate-1.7 {entry widget validation - vmode focus} -body {
    set validationData {}
    .e configure -validate focus
    .e insert end d
    set validationData
} -result {}

test validate-1.8 {entry widget validation - vmode focus} -body {
    set validationData {}
    set timer [after 300 validationData lappend timeout]
    focus -force .e
    vwait validationData
    after cancel $timer
    set validationData
} -result {.e -1 -1 abcd abcd {} focus focusin}

test validate-1.9 {entry widget validation - vmode focus} -body {
    set validationData {}
    set timer [after 300 validationData lappend timeout]
    focus -force .
    vwait validationData
    after cancel $timer
    set validationData
} -result {.e -1 -1 abcd abcd {} focus focusout}

.e configure -validate all
test validate-1.10 {entry widget validation - vmode all} -body {
    set validationData {}
    set timer [after 300 validationData lappend timeout]
    focus -force .e
    vwait validationData
    after cancel $timer
    set validationData
} -result {.e -1 -1 abcd abcd {} all focusin}

test validate-1.11 {entry widget validation} -body {
    set validationData {}
    set timer [after 300 validationData lappend timeout]
    focus -force .
    vwait validationData
    after cancel $timer
    set validationData
} -result {.e -1 -1 abcd abcd {} all focusout}
.e configure -validate focusin

test validate-1.12 {entry widget validation} -body {
    set validationData {}
    set timer [after 300 validationData lappend timeout]
    focus -force .e
    vwait validationData
    after cancel $timer
    set validationData
} -result {.e -1 -1 abcd abcd {} focusin focusin}

test validate-1.13 {entry widget validation} -body {
    set validationData {}
    focus -force .
    update
    set validationData
} -result {}
.e configure -validate focuso

test validate-1.14 {entry widget validation} -body {
    set validationData {}
    focus -force .e
    update
    set validationData
} -result {}

test validate-1.15 {entry widget validation} -body {
    focus -force .
    # update necessary to process FocusOut event
    update
    set validationData
} -result {.e -1 -1 abcd abcd {} focusout focusout}

# DIFFERENCE: core entry temporarily sets "-validate all", ttk::entry doesn't.
test validate-1.16 {entry widget validation} -body {
    .e configure -validate all
    list [.e validate] $validationData
} -result {1 {.e -1 -1 abcd abcd {} all forced}}

# DIFFERENCE: ttk::entry does not perform validation when setting the -variable
test validate-1.17 {entry widget validation} -constraints coreEntry -body {
    .e configure -validate all
    set textVar newdata
    list [.e cget -validate] $validationData
} -result {all {.e -1 -1 newdata abcd {} all forced}}






test validate-1.18 {entry widget validation} -constraints coreEntry -body {
    .e configure -validate all -validatecommand $validateCmd3
    set textVar nextdata
    list [.e cget -validate] $validationData
} -result {none {.e -1 -1 nextdata newdata {} all forced}}
# DIFFERENCE: ttk::entry doesn't validate when setting linked -variable
# DIFFERENCE: ttk::entry doesn't disable validation







## This sets validate to none because it shows that we prevent a possible
## loop condition in the validation, when the entry textvar is also set
test validate-1.19 {entry widget validation} -constraints coreEntry -body {
    .e configure -validate all -validatecommand $validateCmd2
    .e validate
    list [.e cget -validate] [.e get] $validationData
} -result {none mydata {.e -1 -1 nextdata nextdata {} all forced}}

## This leaves validate alone because we trigger validation through the
## textvar (a write trace), and the write during validation triggers
## nothing (by definition of avoiding loops on var traces).  This is
## one of those "dangerous" conditions where the user will have a
## different value in the entry widget shown as is in the textvar.

# DIFFERENCE: ttk entry doesn't get out of sync w/textvar
test validate-1.20 {entry widget validation} -constraints coreEntry -body {
    .e configure -validate all -validatecommand $validateCmd2
    set textVar testdata
    list [.e cget -validate] [.e get] $textVar $validationData
} -result {all testdata mydata {.e -1 -1 testdata mydata {} all forced}}










test validate-2.1 "Validation script changes value" -body {
    .e configure -validate none -validatecommand $validateCmd4
    set textVar testdata
    .e configure -validate all
    .e validate
    list [.e get] $textVar $validationData
} -result {dovaldata dovaldata {.e -1 -1 testdata testdata {} all forced}}
# DIFFERENCE: core entry disables validation, ttk entry does not.

destroy .e
catch {unset textVar}

# See bug #1236979

test validate-2.2 "configure in -validatecommand" -body {
    proc validate-2.2 {win str} {
	$win configure -foreground black
	return 1
277
278
279
280
281
282
283
284


285





286
test validate-3.6 "...until the value becomes valid" -constraints NA -body {
    .e delete 4
    return [list [.e get] [.e state]]
} -result [list 1234 {}]

test validate-3.last "Cleanup" -body { destroy .e }




###





tcltest::cleanupTests







|
>
>
|
>
>
>
>
>

258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
test validate-3.6 "...until the value becomes valid" -constraints NA -body {
    .e delete 4
    return [list [.e get] [.e state]]
} -result [list 1234 {}]

test validate-3.last "Cleanup" -body { destroy .e }

#
# CLEANUP
#

foreach i {1 2 3 4} {
    unset validateCmd$i
}
unset i
testutils forget entry
tcltest::cleanupTests
Changes to tests/unixButton.test.
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
# This file is a Tcl script to test the Unix specific behavior of
# labels, buttons, checkbuttons, and radiobuttons in Tk (i.e., all the
# widgets defined in tkUnixButton.c).  It is organized in the standard
# fashion for Tcl tests.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994-1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2

eval tcltest::configure $argv
tcltest::loadTestedCommands
namespace import -force tcltest::test



imageInit

# Create entries in the option database to be sure that geometry options
# like border width have predictable values.

option add *Label.borderWidth 2
option add *Label.highlightThickness 0
option add *Label.font {Helvetica -12 bold}
option add *Button.borderWidth 2
option add *Button.highlightThickness 2
option add *Button.font {Helvetica -12 bold}
option add *Checkbutton.borderWidth 2
option add *Checkbutton.highlightThickness 2
option add *Checkbutton.font {Helvetica -12 bold}
option add *Radiobutton.borderWidth 2
option add *Radiobutton.highlightThickness 2
option add *Radiobutton.font {Helvetica -12 bold}


proc bogusTrace args {
    error "trace aborted"
}

if {[tk windowingsystem] eq "aqua"} {
    set smallIndicator 20
    set bigIndicator 20
    set defaultBorder 10
} else {
    set smallIndicator 27
    set bigIndicator 40











>


|
>
>
>


















<
<
<
<
<







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
# This file is a Tcl script to test the Unix specific behavior of
# labels, buttons, checkbuttons, and radiobuttons in Tk (i.e., all the
# widgets defined in tkUnixButton.c).  It is organized in the standard
# fashion for Tcl tests.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994-1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import -force tcltest::test
eval tcltest::configure $argv
tcltest::loadTestedCommands

# Import utility procs for specific functional areas
testutils import button image

imageInit

# Create entries in the option database to be sure that geometry options
# like border width have predictable values.

option add *Label.borderWidth 2
option add *Label.highlightThickness 0
option add *Label.font {Helvetica -12 bold}
option add *Button.borderWidth 2
option add *Button.highlightThickness 2
option add *Button.font {Helvetica -12 bold}
option add *Checkbutton.borderWidth 2
option add *Checkbutton.highlightThickness 2
option add *Checkbutton.font {Helvetica -12 bold}
option add *Radiobutton.borderWidth 2
option add *Radiobutton.highlightThickness 2
option add *Radiobutton.font {Helvetica -12 bold}






if {[tk windowingsystem] eq "aqua"} {
    set smallIndicator 20
    set bigIndicator 20
    set defaultBorder 10
} else {
    set smallIndicator 27
    set bigIndicator 40
254
255
256
257
258
259
260
261


262
263

264
265
266
267
268
269
    pack .l .cb0 .cb1 .cb2 .cb3 .rb0 .rb1 .rb2 .rb3 -side top -fill x
    after 400
    set on
} -cleanup {
    deleteWindows
} -result 1




# cleanup
imageFinish

cleanupTests
return

# Local variables:
# mode: tcl
# End:







|
>
>
|

>






253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
    pack .l .cb0 .cb1 .cb2 .cb3 .rb0 .rb1 .rb2 .rb3 -side top -fill x
    after 400
    set on
} -cleanup {
    deleteWindows
} -result 1

#
# CLEANUP
#

imageFinish
testutils forget button image
cleanupTests
return

# Local variables:
# mode: tcl
# End:
Changes to tests/unixEmbed.test.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# This file is a Tcl script to test out the procedures in the file
# tkUnixEmbed.c.  It is organized in the standard fashion for Tcl
# tests.
#
# Copyright © 1996-1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
eval tcltest::configure $argv
tcltest::loadTestedCommands
namespace import -force tcltest::test

testConstraint failsOnUbuntu [expr {![info exists ::env(CI)] || ![string match Linux $::tcl_platform(os)]}]
testConstraint failsOnXQuarz [expr {$tcl_platform(os) ne "Darwin" || [tk windowingsystem] ne "x11" }]

namespace eval ::_test_tmp {}

# ------------------------------------------------------------------------------
#  Proc ::_test_tmp::testInterp
# ------------------------------------------------------------------------------
# Command that creates an child interpreter and tries to load Tk.













|
|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# This file is a Tcl script to test out the procedures in the file
# tkUnixEmbed.c.  It is organized in the standard fashion for Tcl
# tests.
#
# Copyright © 1996-1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
eval tcltest::configure $argv
tcltest::loadTestedCommands
namespace import -force tcltest::test

# Import utility procs for specific functional areas
testutils import colors child

namespace eval ::_test_tmp {}

# ------------------------------------------------------------------------------
#  Proc ::_test_tmp::testInterp
# ------------------------------------------------------------------------------
# Command that creates an child interpreter and tries to load Tk.
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
proc ::_test_tmp::testInterp {name} {
    variable TkLoadCmd
    interp create $name
    $name eval [list set argv [list -name $name]]
    catch {{*}$TkLoadCmd $name}
}

setupbg
dobg {wm withdraw .}

# eatColors --
# Creates a toplevel window and allocates enough colors in it to
# use up all the slots in the colormap.
#
# Arguments:
# w -		Name of toplevel window to create.

proc eatColors {w} {
    catch {destroy $w}
    toplevel $w
    wm geom $w +0+0
    canvas $w.c -width 400 -height 200 -bd 0
    pack $w.c
    for {set y 0} {$y < 8} {incr y} {
	for {set x 0} {$x < 40} {incr x} {
	    set color [format #%02x%02x%02x [expr $x*6] [expr $y*30] 0]
	    $w.c create rectangle [expr 10*$x] [expr 20*$y] \
		    [expr 10*$x + 10] [expr 20*$y + 20] -outline {} \
		    -fill $color
	}
    }
    update
}

# colorsFree --
#
# Returns 1 if there appear to be free colormap entries in a window,
# 0 otherwise.
#
# Arguments:
# w -			Name of window in which to check.
# red, green, blue -	Intensities to use in a trial color allocation
#			to see if there are colormap entries free.

proc colorsFree {w {red 31} {green 245} {blue 192}} {
    set vals [winfo rgb $w [format #%02x%02x%02x $red $green $blue]]
    expr ([lindex $vals 0]/256 == $red) && ([lindex $vals 1]/256 == $green) \
	    && ([lindex $vals 2]/256 == $blue)
}

test unixEmbed-1.1 {Tk_UseWindow procedure, bad window identifier} -constraints {
    unix
} -setup {
    deleteWindows
} -body {
    toplevel .t -use xyz







|
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







41
42
43
44
45
46
47
48
49








































50
51
52
53
54
55
56
proc ::_test_tmp::testInterp {name} {
    variable TkLoadCmd
    interp create $name
    $name eval [list set argv [list -name $name]]
    catch {{*}$TkLoadCmd $name}
}

childTkProcess create
childTkProcess eval {wm withdraw .}









































test unixEmbed-1.1 {Tk_UseWindow procedure, bad window identifier} -constraints {
    unix
} -setup {
    deleteWindows
} -body {
    toplevel .t -use xyz
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
    unix testembed notAqua
} -setup {
    deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    frame .f2 -container 1 -width 200 -height 50
    pack .f1 .f2
    dobg "set w [winfo id .f1]"
    dobg {
	destroy {*}[winfo children .]
	toplevel .t -use $w
	list [testembed] [expr [lindex [lindex [testembed all] 0] 0] - $w]
    }
} -cleanup {
    deleteWindows
} -result {{{XXX {} {} .t}} 0}







|
|







94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
    unix testembed notAqua
} -setup {
    deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    frame .f2 -container 1 -width 200 -height 50
    pack .f1 .f2
    childTkProcess eval "set w [winfo id .f1]"
    childTkProcess eval {
	destroy {*}[winfo children .]
	toplevel .t -use $w
	list [testembed] [expr [lindex [lindex [testembed all] 0] 0] - $w]
    }
} -cleanup {
    deleteWindows
} -result {{{XXX {} {} .t}} 0}
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
    unix testembed notAqua
} -setup {
    deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    frame .f2 -container 1 -width 200 -height 50
    pack .f1 .f2
    dobg "set w1 [winfo id .f1]"
    dobg "set w2 [winfo id .f2]"
    dobg {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1
	toplevel .t2 -use $w2
	testembed
    }
} -cleanup {
    deleteWindows







|
|
|







132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
    unix testembed notAqua
} -setup {
    deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    frame .f2 -container 1 -width 200 -height 50
    pack .f1 .f2
    childTkProcess eval "set w1 [winfo id .f1]"
    childTkProcess eval "set w2 [winfo id .f2]"
    childTkProcess eval {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1
	toplevel .t2 -use $w2
	testembed
    }
} -cleanup {
    deleteWindows
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
test unixEmbed-2.1 {EmbeddedEventProc procedure} -constraints {
    unix testembed notAqua
} -setup {
    deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    dobg "set w1 [winfo id .f1]"
    dobg {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1
	testembed
    }
    destroy .f1
    update
    dobg {
	testembed
    }
} -cleanup {
    deleteWindows
} -result {}
test unixEmbed-2.1a {EmbeddedEventProc procedure} -constraints {
    unix testembed







|
|






|







192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
test unixEmbed-2.1 {EmbeddedEventProc procedure} -constraints {
    unix testembed notAqua
} -setup {
    deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    childTkProcess eval "set w1 [winfo id .f1]"
    childTkProcess eval {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1
	testembed
    }
    destroy .f1
    update
    childTkProcess eval {
	testembed
    }
} -cleanup {
    deleteWindows
} -result {}
test unixEmbed-2.1a {EmbeddedEventProc procedure} -constraints {
    unix testembed
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
test unixEmbed-2.2 {EmbeddedEventProc procedure} -constraints {
    unix testembed notAqua
} -setup {
    deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    dobg "set w1 [winfo id .f1]"
    dobg {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1
	testembed
	destroy .t1
	testembed
    }
} -cleanup {







|
|







237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
test unixEmbed-2.2 {EmbeddedEventProc procedure} -constraints {
    unix testembed notAqua
} -setup {
    deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    childTkProcess eval "set w1 [winfo id .f1]"
    childTkProcess eval {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1
	testembed
	destroy .t1
	testembed
    }
} -cleanup {
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360


test unixEmbed-3.1 {ContainerEventProc procedure, detect creation} -constraints {
    unix testembed nonPortable
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    dobg "set w1 [winfo id .f1]"
    set x [testembed]
    dobg {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1
	wm withdraw .t1
    }
    list $x [testembed]
} -cleanup {
    deleteWindows







|

|







304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320


test unixEmbed-3.1 {ContainerEventProc procedure, detect creation} -constraints {
    unix testembed nonPortable
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    childTkProcess eval "set w1 [winfo id .f1]"
    set x [testembed]
    childTkProcess eval {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1
	wm withdraw .t1
    }
    list $x [testembed]
} -cleanup {
    deleteWindows
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
test unixEmbed-3.3 {ContainerEventProc procedure, disallow position changes} -constraints {
    unix notAqua
} -setup {
    deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    dobg "set w1 [winfo id .f1]"
    dobg {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1 -bd 2 -relief raised
	update
	wm geometry .t1 +30+40
    }
    update
    dobg {
	wm geometry .t1
    }
} -cleanup {
    deleteWindows
} -result {200x200+0+0}
test unixEmbed-3.3a {ContainerEventProc procedure, disallow position changes} -constraints {
    unix







|
|






|







357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
test unixEmbed-3.3 {ContainerEventProc procedure, disallow position changes} -constraints {
    unix notAqua
} -setup {
    deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    childTkProcess eval "set w1 [winfo id .f1]"
    childTkProcess eval {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1 -bd 2 -relief raised
	update
	wm geometry .t1 +30+40
    }
    update
    childTkProcess eval {
	wm geometry .t1
    }
} -cleanup {
    deleteWindows
} -result {200x200+0+0}
test unixEmbed-3.3a {ContainerEventProc procedure, disallow position changes} -constraints {
    unix
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
test unixEmbed-3.4 {ContainerEventProc procedure, disallow position changes} -constraints {
    unix notAqua
} -setup {
    deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    dobg "set w1 [winfo id .f1]"
    dobg {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1
	update
	wm geometry .t1 300x100+30+40
    }
    update
    dobg {
	wm geometry .t1
    }
} -cleanup {
    deleteWindows
} -result {300x100+0+0}
test unixEmbed-3.4a {ContainerEventProc procedure, disallow position changes} -constraints {
    unix







|
|






|







401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
test unixEmbed-3.4 {ContainerEventProc procedure, disallow position changes} -constraints {
    unix notAqua
} -setup {
    deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    childTkProcess eval "set w1 [winfo id .f1]"
    childTkProcess eval {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1
	update
	wm geometry .t1 300x100+30+40
    }
    update
    childTkProcess eval {
	wm geometry .t1
    }
} -cleanup {
    deleteWindows
} -result {300x100+0+0}
test unixEmbed-3.4a {ContainerEventProc procedure, disallow position changes} -constraints {
    unix
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
test unixEmbed-3.5 {ContainerEventProc procedure, geometry requests} -constraints {
    unix notAqua
} -setup {
    deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    dobg "set w1 [winfo id .f1]"
    dobg {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1
    }
    update
    dobg {
	.t1 configure -width 300 -height 80
    }
    update
    list [winfo width .f1] [winfo height .f1] [dobg {wm geometry .t1}]
} -cleanup {
    deleteWindows
} -result {300 80 300x80+0+0}
test unixEmbed-3.5a {ContainerEventProc procedure, geometry requests} -constraints {
    unix
} -setup {
    deleteWindows







|
|




|



|







445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
test unixEmbed-3.5 {ContainerEventProc procedure, geometry requests} -constraints {
    unix notAqua
} -setup {
    deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    childTkProcess eval "set w1 [winfo id .f1]"
    childTkProcess eval {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1
    }
    update
    childTkProcess eval {
	.t1 configure -width 300 -height 80
    }
    update
    list [winfo width .f1] [winfo height .f1] [childTkProcess eval {wm geometry .t1}]
} -cleanup {
    deleteWindows
} -result {300 80 300x80+0+0}
test unixEmbed-3.5a {ContainerEventProc procedure, geometry requests} -constraints {
    unix
} -setup {
    deleteWindows
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
test unixEmbed-3.6 {ContainerEventProc procedure, map requests} -constraints {
    unix notAqua
} -setup {
    deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    dobg "set w1 [winfo id .f1]"
    dobg {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1
	set x unmapped
	bind .t1 <Map> {set x mapped}
    }
    update
    dobg {
	after 100
	update
	set x
    }
} -cleanup {
    deleteWindows
} -result {mapped}







|
|






|







488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
test unixEmbed-3.6 {ContainerEventProc procedure, map requests} -constraints {
    unix notAqua
} -setup {
    deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    childTkProcess eval "set w1 [winfo id .f1]"
    childTkProcess eval {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1
	set x unmapped
	bind .t1 <Map> {set x mapped}
    }
    update
    childTkProcess eval {
	after 100
	update
	set x
    }
} -cleanup {
    deleteWindows
} -result {mapped}
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
test unixEmbed-3.7 {ContainerEventProc procedure, destroy events} -constraints {
    unix notAqua
} -setup {
    deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    dobg "set w1 [winfo id .f1]"
    bind .f1 <Destroy> {set x dead}
    set x alive
    dobg {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1
    }
    update
    dobg {
	destroy .t1
    }
    update
    list $x [winfo exists .f1]
} -cleanup {
    deleteWindows
} -result {dead 0}







|


|




|







536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
test unixEmbed-3.7 {ContainerEventProc procedure, destroy events} -constraints {
    unix notAqua
} -setup {
    deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    childTkProcess eval "set w1 [winfo id .f1]"
    bind .f1 <Destroy> {set x dead}
    set x alive
    childTkProcess eval {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1
    }
    update
    childTkProcess eval {
	destroy .t1
    }
    update
    list $x [winfo exists .f1]
} -cleanup {
    deleteWindows
} -result {dead 0}
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
test unixEmbed-4.1 {EmbedStructureProc procedure, configure events} -constraints {
    unix notAqua
} -setup {
    deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    dobg "set w1 [winfo id .f1]"
    dobg {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1
    }
    update
    dobg {
	.t1 configure -width 180 -height 100
    }
    update
    dobg {
	winfo geometry .t1
    }
} -cleanup {
    deleteWindows
} -result {180x100+0+0}
test unixEmbed-4.1a {EmbedStructureProc procedure, configure events} -constraints {
    unix







|
|




|



|







585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
test unixEmbed-4.1 {EmbedStructureProc procedure, configure events} -constraints {
    unix notAqua
} -setup {
    deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    childTkProcess eval "set w1 [winfo id .f1]"
    childTkProcess eval {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1
    }
    update
    childTkProcess eval {
	.t1 configure -width 180 -height 100
    }
    update
    childTkProcess eval {
	winfo geometry .t1
    }
} -cleanup {
    deleteWindows
} -result {180x100+0+0}
test unixEmbed-4.1a {EmbedStructureProc procedure, configure events} -constraints {
    unix
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
test unixEmbed-4.2 {EmbedStructureProc procedure, destroy events} -constraints {
    unix testembed notAqua
} -setup {
    deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    dobg "set w1 [winfo id .f1]"
    dobg {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1
    }
    update
    set x [testembed]
    destroy .f1
    update







|
|







631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
test unixEmbed-4.2 {EmbedStructureProc procedure, destroy events} -constraints {
    unix testembed notAqua
} -setup {
    deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    childTkProcess eval "set w1 [winfo id .f1]"
    childTkProcess eval {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1
    }
    update
    set x [testembed]
    destroy .f1
    update
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
    unix notAqua
} -setup {
    deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    update
    dobg "set w1 [winfo id .f1]"
    dobg {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1
	bind .t1 <FocusIn> {lappend x "focus in %W"}
	bind .t1 <FocusOut> {lappend x "focus out %W"}
	set x {}
    }
    focus -force .f1
    update
    dobg {set x}
} -cleanup {
    deleteWindows
} -result {{focus in .t1}}
test unixEmbed-5.1a {EmbedFocusProc procedure, FocusIn events} -constraints {
    unix
} -setup {
    deleteWindows







|
|








|







677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
    unix notAqua
} -setup {
    deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    update
    childTkProcess eval "set w1 [winfo id .f1]"
    childTkProcess eval {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1
	bind .t1 <FocusIn> {lappend x "focus in %W"}
	bind .t1 <FocusOut> {lappend x "focus out %W"}
	set x {}
    }
    focus -force .f1
    update
    childTkProcess eval {set x}
} -cleanup {
    deleteWindows
} -result {{focus in .t1}}
test unixEmbed-5.1a {EmbedFocusProc procedure, FocusIn events} -constraints {
    unix
} -setup {
    deleteWindows
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
    unix notAqua
} -setup {
    deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    update
    dobg "set w1 [winfo id .f1]"
    dobg {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1
    }
    update
    dobg {
	after 200 {destroy .t1}
    }
    after 400
    focus -force .f1
    update
} -cleanup {
    deleteWindows







|
|




|







726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
    unix notAqua
} -setup {
    deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    update
    childTkProcess eval "set w1 [winfo id .f1]"
    childTkProcess eval {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1
    }
    update
    childTkProcess eval {
	after 200 {destroy .t1}
    }
    after 400
    focus -force .f1
    update
} -cleanup {
    deleteWindows
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
    unix notAqua
} -setup {
    deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    update
    dobg "set w1 [winfo id .f1]"
    dobg {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1
	bind .t1 <FocusIn> {lappend x "focus in %W"}
	bind .t1 <FocusOut> {lappend x "focus out %W"}
	set x {}
    }
    focus -force .f1
    update
    set x [dobg {update; set x}]
    focus .
    update
    list $x [dobg {update; set x}]
} -cleanup {
    deleteWindows
} -result {{{focus in .t1}} {{focus in .t1} {focus out .t1}}}
test unixEmbed-5.3a {EmbedFocusProc procedure, FocusOut events} -constraints {
    unix
} -setup {
    deleteWindows







|
|








|


|







774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
    unix notAqua
} -setup {
    deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    update
    childTkProcess eval "set w1 [winfo id .f1]"
    childTkProcess eval {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1
	bind .t1 <FocusIn> {lappend x "focus in %W"}
	bind .t1 <FocusOut> {lappend x "focus out %W"}
	set x {}
    }
    focus -force .f1
    update
    set x [childTkProcess eval {update; set x}]
    focus .
    update
    list $x [childTkProcess eval {update; set x}]
} -cleanup {
    deleteWindows
} -result {{{focus in .t1}} {{focus in .t1} {focus out .t1}}}
test unixEmbed-5.3a {EmbedFocusProc procedure, FocusOut events} -constraints {
    unix
} -setup {
    deleteWindows
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
test unixEmbed-6.1 {EmbedGeometryRequest procedure, window changes size} -constraints {
    unix notAqua
} -setup {
    deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    dobg "set w1 [winfo id .f1]"
    dobg {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1
	update
	bind .t1 <Configure> {lappend x {configure .t1 %w %h}}
	set x {}
	.t1 configure -width 300 -height 120
	update







|
|







830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
test unixEmbed-6.1 {EmbedGeometryRequest procedure, window changes size} -constraints {
    unix notAqua
} -setup {
    deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    childTkProcess eval "set w1 [winfo id .f1]"
    childTkProcess eval {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1
	update
	bind .t1 <Configure> {lappend x {configure .t1 %w %h}}
	set x {}
	.t1 configure -width 300 -height 120
	update
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
test unixEmbed-6.2 {EmbedGeometryRequest procedure, window changes size} -constraints {
    unix notAqua
} -setup {
    deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    place .f1 -width 200 -height 200
    dobg "set w1 [winfo id .f1]"
    dobg {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1
	update
	bind .t1 <Configure> {lappend x {configure .t1 %w %h}}
	set x {}
	.t1 configure -width 300 -height 120
	update







|
|







876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
test unixEmbed-6.2 {EmbedGeometryRequest procedure, window changes size} -constraints {
    unix notAqua
} -setup {
    deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    place .f1 -width 200 -height 200
    childTkProcess eval "set w1 [winfo id .f1]"
    childTkProcess eval {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1
	update
	bind .t1 <Configure> {lappend x {configure .t1 %w %h}}
	set x {}
	.t1 configure -width 300 -height 120
	update
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
    unix notAqua
} -setup {
    deleteWindows
} -body {
    deleteWindows
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    dobg "set w1 [winfo id .f1]"
    dobg {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1
    }
    focus -force .
    bind . <Key> {lappend x {key %A %E}}
    set x {}
    set y [dobg {
	update
	bind .t1 <Key> {lappend y {key %A}}
	set y {}
	event generate .t1 <Key> -keysym a
	set y
    }]
    update
    list $x $y
} -cleanup {
    deleteWindows
    bind . <Key> {}
} -result {{{key a 1}} {}}
# TkpRedirectKeyEvent is not implemented in win or aqua.  If someone
# implements it they should change the constraints for this test.
test unixEmbed-7.1a {TkpRedirectKeyEvent procedure, forward keystroke} -constraints {
    unix notAqua failsOnXQuarz
} -setup {
    deleteWindows
    catch {interp delete child}
    ::_test_tmp::testInterp child
    load {} Tktest child
} -body {
    deleteWindows







|
|






|















|







927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
    unix notAqua
} -setup {
    deleteWindows
} -body {
    deleteWindows
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    childTkProcess eval "set w1 [winfo id .f1]"
    childTkProcess eval {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1
    }
    focus -force .
    bind . <Key> {lappend x {key %A %E}}
    set x {}
    set y [childTkProcess eval {
	update
	bind .t1 <Key> {lappend y {key %A}}
	set y {}
	event generate .t1 <Key> -keysym a
	set y
    }]
    update
    list $x $y
} -cleanup {
    deleteWindows
    bind . <Key> {}
} -result {{{key a 1}} {}}
# TkpRedirectKeyEvent is not implemented in win or aqua.  If someone
# implements it they should change the constraints for this test.
test unixEmbed-7.1a {TkpRedirectKeyEvent procedure, forward keystroke} -constraints {
    unix notAqua failsOnXQuartz
} -setup {
    deleteWindows
    catch {interp delete child}
    ::_test_tmp::testInterp child
    load {} Tktest child
} -body {
    deleteWindows
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
test unixEmbed-7.2 {TkpRedirectKeyEvent procedure, don't forward keystroke width} -constraints {
    unix notAqua
} -setup {
    deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    dobg "set w1 [winfo id .f1]"
    dobg {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1
    }
    update
    focus -force .f1
    update
    bind . <Key> {lappend x {key %A}}
    set x {}
    set y [dobg {
	update
	bind .t1 <Key> {lappend y {key %A}}
	set y {}
	event generate .t1 <Key> -keysym b
	set y
    }]
    update







|
|








|







990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
test unixEmbed-7.2 {TkpRedirectKeyEvent procedure, don't forward keystroke width} -constraints {
    unix notAqua
} -setup {
    deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    childTkProcess eval "set w1 [winfo id .f1]"
    childTkProcess eval {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1
    }
    update
    focus -force .f1
    update
    bind . <Key> {lappend x {key %A}}
    set x {}
    set y [childTkProcess eval {
	update
	bind .t1 <Key> {lappend y {key %A}}
	set y {}
	event generate .t1 <Key> -keysym b
	set y
    }]
    update
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
} -cleanup {
    interp delete child
    deleteWindows
    bind . <Key> {}
} -result {{} {{key b}}}

test unixEmbed-8.1 {TkpClaimFocus procedure} -constraints {
    unix notAqua failsOnUbuntu failsOnXQuarz
} -setup {
    deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    frame .f2 -width 200 -height 50
    pack .f1 .f2
    dobg "set w1 [winfo id .f1]"
    dobg {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1 -highlightthickness 2 -bd 2 -relief sunken
    }
    focus -force .f2
    update
    list [dobg {
	focus .t1
	set x [list [focus]]
	update
	after 500
	update
	lappend x [focus]
    }] [focus]







|






|
|





|







1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
} -cleanup {
    interp delete child
    deleteWindows
    bind . <Key> {}
} -result {{} {{key b}}}

test unixEmbed-8.1 {TkpClaimFocus procedure} -constraints {
    unix notAqua failsOnUbuntu failsOnXQuartz
} -setup {
    deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    frame .f2 -width 200 -height 50
    pack .f1 .f2
    childTkProcess eval "set w1 [winfo id .f1]"
    childTkProcess eval {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1 -highlightthickness 2 -bd 2 -relief sunken
    }
    focus -force .f2
    update
    list [childTkProcess eval {
	focus .t1
	set x [list [focus]]
	update
	after 500
	update
	lappend x [focus]
    }] [focus]
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
    unix testembed notAqua
} -setup {
    deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    update
    dobg "set w1 [winfo id .f1]"
    dobg {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1 -highlightthickness 2 -bd 2 -relief sunken
	set x {}
	lappend x [testembed]
	destroy .t1
	lappend x [testembed]
    }







|
|







1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
    unix testembed notAqua
} -setup {
    deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    update
    childTkProcess eval "set w1 [winfo id .f1]"
    childTkProcess eval {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1 -highlightthickness 2 -bd 2 -relief sunken
	set x {}
	lappend x [testembed]
	destroy .t1
	lappend x [testembed]
    }
1318
1319
1320
1321
1322
1323
1324
1325


1326
1327
1328


1329
1330
    testpressbutton $x $y
    update
    set result
} -cleanup {
    deleteWindows
} -result {.main.b {pushed .main.b} .embed.b {pushed .embed.b}}




# cleanup
deleteWindows
cleanupbg


cleanupTests
return







|
>
>
|

<
>
>


1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289

1290
1291
1292
1293
    testpressbutton $x $y
    update
    set result
} -cleanup {
    deleteWindows
} -result {.main.b {pushed .main.b} .embed.b {pushed .embed.b}}

#
# CLEANUP
#

deleteWindows

childTkProcess exit
testutils forget child colors
cleanupTests
return
Changes to tests/unixFont.test.
11
12
13
14
15
16
17



18
19
20
21
22
23
24
# Copyright © 1996 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

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




if {[tk windowingsystem] eq "x11"} {
    if {[testConstraint withXft]} {
	set fontsystemcmd [auto_execok fc-list]
    } else {
	set fontsystemcmd [auto_execok xlsfonts]
    }







>
>
>







11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# Copyright © 1996 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

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

# Import utility procs for specific functional areas
testutils import geometry

if {[tk windowingsystem] eq "x11"} {
    if {[testConstraint withXft]} {
	set fontsystemcmd [auto_execok fc-list]
    } else {
	set fontsystemcmd [auto_execok xlsfonts]
    }
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
pack .b.c
update

set cx [font measure TkFixedFont 0]

set ax [winfo reqwidth .b.l]
set ay [winfo reqheight .b.l]
proc getsize {} {
    update
    return "[winfo reqwidth .b.l] [winfo reqheight .b.l]"
}

test unixfont-1.1 {TkpGetNativeFont procedure: not native} {x11} {
    list [catch {font measure {} xyz} msg] $msg
} {1 {font "" does not exist}}
test unixfont-1.2 {TkpGetNativeFont procedure: native} {x11 haveFixedFamilyFont} {
    font measure fixed 0
} 6







<
<
<
<







70
71
72
73
74
75
76




77
78
79
80
81
82
83
pack .b.c
update

set cx [font measure TkFixedFont 0]

set ax [winfo reqwidth .b.l]
set ay [winfo reqheight .b.l]





test unixfont-1.1 {TkpGetNativeFont procedure: not native} {x11} {
    list [catch {font measure {} xyz} msg] $msg
} {1 {font "" does not exist}}
test unixfont-1.2 {TkpGetNativeFont procedure: native} {x11 haveFixedFamilyFont} {
    font measure fixed 0
} 6
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
    .b.l config -text "\377"
    .b.l config -text "0\3770\377"
    .b.l config -text "000000000000000"
} {}
.b.l config -wrap [expr $ax*10]
test unixfont-5.4 {Tk_MeasureChars procedure: reached right edge} x11 {
    .b.l config -text "0000000000000"
    getsize
} "[expr $ax*10] [expr $ay*2]"
test unixfont-5.5 {Tk_MeasureChars procedure: ran out of chars} x11 {
    .b.l config -text "000000"
    getsize
} "[expr $ax*6] $ay"
test unixfont-5.6 {Tk_MeasureChars procedure: find last word} x11 {
    .b.l config -text "000000 00000"
    getsize
} "[expr $ax*6] [expr $ay*2]"
test unixfont-5.7 {Tk_MeasureChars procedure: already saw space in line} x11 {
    .b.l config -text "000000     00000"
    getsize
} "[expr $ax*6] [expr $ay*2]"
test unixfont-5.8 {Tk_MeasureChars procedure: internal spaces significant} {x11} {
    .b.l config -text "00  000     00000"
    getsize
} "[expr $ax*7] [expr $ay*2]"
test unixfont-5.9 {Tk_MeasureChars procedure: TK_PARTIAL_OK} {x11} {
    .b.c dchars $t 0 end
    .b.c insert $t 0 "0000"
    .b.c index $t @[expr int($ax*2.5)],1
} 2
test unixfont-5.10 {Tk_MeasureChars procedure: TK_AT_LEAST_ONE} x11 {
    .b.l config -text "000000000000"
    getsize
} "[expr $ax*10] [expr $ay*2]"
test unixfont-5.11 {Tk_MeasureChars: TK_AT_LEAST_ONE + not even one char fit!} x11 {
    set a [.b.l cget -wrap]
    .b.l config -text "000000" -wrap 1
    set x [getsize]
    .b.l config -wrap $a
    set x
} "$ax [expr $ay*6]"
test unixfont-5.12 {Tk_MeasureChars procedure: include eol spaces} {x11} {
    .b.l config -text "000   \n000"
    getsize
} "[expr $ax*6] [expr $ay*2]"

test unixfont-6.1 {Tk_DrawChars procedure: loop test} x11 {
    .b.l config -text "a"
    update
} {}
test unixfont-6.2 {Tk_DrawChars procedure: loop test} x11 {







|



|



|



|



|








|




|





|







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
    .b.l config -text "\377"
    .b.l config -text "0\3770\377"
    .b.l config -text "000000000000000"
} {}
.b.l config -wrap [expr $ax*10]
test unixfont-5.4 {Tk_MeasureChars procedure: reached right edge} x11 {
    .b.l config -text "0000000000000"
    getsize .b.l
} "[expr $ax*10] [expr $ay*2]"
test unixfont-5.5 {Tk_MeasureChars procedure: ran out of chars} x11 {
    .b.l config -text "000000"
    getsize .b.l
} "[expr $ax*6] $ay"
test unixfont-5.6 {Tk_MeasureChars procedure: find last word} x11 {
    .b.l config -text "000000 00000"
    getsize .b.l
} "[expr $ax*6] [expr $ay*2]"
test unixfont-5.7 {Tk_MeasureChars procedure: already saw space in line} x11 {
    .b.l config -text "000000     00000"
    getsize .b.l
} "[expr $ax*6] [expr $ay*2]"
test unixfont-5.8 {Tk_MeasureChars procedure: internal spaces significant} {x11} {
    .b.l config -text "00  000     00000"
    getsize .b.l
} "[expr $ax*7] [expr $ay*2]"
test unixfont-5.9 {Tk_MeasureChars procedure: TK_PARTIAL_OK} {x11} {
    .b.c dchars $t 0 end
    .b.c insert $t 0 "0000"
    .b.c index $t @[expr int($ax*2.5)],1
} 2
test unixfont-5.10 {Tk_MeasureChars procedure: TK_AT_LEAST_ONE} x11 {
    .b.l config -text "000000000000"
    getsize .b.l
} "[expr $ax*10] [expr $ay*2]"
test unixfont-5.11 {Tk_MeasureChars: TK_AT_LEAST_ONE + not even one char fit!} x11 {
    set a [.b.l cget -wrap]
    .b.l config -text "000000" -wrap 1
    set x [getsize .b.l]
    .b.l config -wrap $a
    set x
} "$ax [expr $ay*6]"
test unixfont-5.12 {Tk_MeasureChars procedure: include eol spaces} {x11} {
    .b.l config -text "000   \n000"
    getsize .b.l
} "[expr $ax*6] [expr $ay*2]"

test unixfont-6.1 {Tk_DrawChars procedure: loop test} x11 {
    .b.l config -text "a"
    update
} {}
test unixfont-6.2 {Tk_DrawChars procedure: loop test} x11 {
328
329
330
331
332
333
334



335

336
337
    lappend x [.b.c index $t @[expr $ax*1],0]
    lappend x [.b.c index $t @[expr $ax*2],0]
    lappend x [.b.c index $t @[expr $ax*3],0]
    lappend x [.b.c index $t @[expr $ax*4],0]
    lappend x [.b.c index $t @[expr $ax*5],0]
} {0 1 1 1 1 2}




# cleanup

cleanupTests
return







>
>
>
|
>


327
328
329
330
331
332
333
334
335
336
337
338
339
340
    lappend x [.b.c index $t @[expr $ax*1],0]
    lappend x [.b.c index $t @[expr $ax*2],0]
    lappend x [.b.c index $t @[expr $ax*3],0]
    lappend x [.b.c index $t @[expr $ax*4],0]
    lappend x [.b.c index $t @[expr $ax*5],0]
} {0 1 1 1 1 2}

#
# CLEANUP
#

testutils forget geometry
cleanupTests
return
Changes to tests/unixSelect.test.
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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434



435

436
437
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.

package require tcltest 2.2
namespace import ::tcltest::*
tcltest::configure {*}$argv
tcltest::loadTestedCommands

global longValue selValue selInfo

set selValue {}
set selInfo {}

proc handler {type offset count} {
    global selValue selInfo
    lappend selInfo $type $offset $count
    set numBytes [expr {[string length $selValue] - $offset}]
    if {$numBytes <= 0} {
    return ""
    }
    string range $selValue $offset [expr $numBytes+$offset]
}

proc errIncrHandler {type offset count} {
    global selValue selInfo pass
    if {$offset == 4000} {
    if {$pass == 0} {
	# Just sizing the selection;  don't do anything here.
	set pass 1
    } else {
	# Fetching the selection;  wait long enough to cause a timeout.
	after 6000
    }
    }
    lappend selInfo $type $offset $count
    set numBytes [expr {[string length $selValue] - $offset}]
    if {$numBytes <= 0} {
    return ""
    }
    string range $selValue $offset [expr $numBytes+$offset]
}

proc errHandler args {
    error "selection handler aborted"
}

proc badHandler {path type offset count} {
    global selValue selInfo
    selection handle -type $type $path {}
    lappend selInfo $path $type $offset $count
    set numBytes [expr {[string length $selValue] - $offset}]
    if {$numBytes <= 0} {
    return ""
    }
    string range $selValue $offset [expr $numBytes+$offset]
}
proc reallyBadHandler {path type offset count} {
    global selValue selInfo pass
    if {$offset == 4000} {
    if {$pass == 0} {
	set pass 1
    } else {
	selection handle -type $type $path {}
    }
    }
    lappend selInfo $path $type $offset $count
    set numBytes [expr {[string length $selValue] - $offset}]
    if {$numBytes <= 0} {
    return ""
    }
    string range $selValue $offset [expr $numBytes+$offset]
}

# Eliminate any existing selection on the screen.  This is needed in case
# there is a selection in some other application, in order to prevent races
# from causing false errors in the tests below.

selection clear .
after 1500

# common setup code
proc setup {{path .f1} {display {}}} {
    catch {destroy $path}
    if {$display == {}} {
    frame $path
    } else {
    toplevel $path -screen $display
    wm geom $path +0+0
    }
    selection own $path
}

# set up a very large buffer to test INCR retrievals
set longValue ""
foreach i {a b c d e f g j h i j k l m o p q r s t u v w x y z} {
    set j $i.1$i.2$i.3$i.4$i.5$i.6$i.7$i.8$i.9$i.10$i.11$i.12$i.13$i.14
    append longValue A$j B$j C$j D$j E$j F$j G$j H$j I$j K$j L$j M$j N$j
}

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

test unixSelect-1.1 {TkSelGetSelection procedure: simple i18n text} -constraints {
    x11
} -setup {
    destroy .e
    setupbg
} -body {
    pack [entry .e]
    update
    .e insert 0 über
    .e selection range 0 end
    dobg {string length [selection get]}
} -cleanup {
    cleanupbg
    destroy .e
} -result 4

test unixSelect-1.2 {TkSelGetSelection procedure: simple i18n text, iso8859-1} -constraints {
    x11
} -setup {
    setupbg
} -body {
    dobg {
	pack [entry .e]
	update
	.e insert 0 üф
	.e selection range 0 end
    }
    selection get
} -cleanup {
    cleanupbg
} -result ü?

test unixSelect-1.3 {TkSelGetSelection procedure: simple i18n text, iso2022} -constraints {
    x11
} -setup {
    setupbg
    setup
} -body {
    selection handle -type COMPOUND_TEXT -format COMPOUND_TEXT . \
	{handler COMPOUND_TEXT}
    selection own .
    set selValue üф
    set selInfo {}
    set result [dobg {
	set x [selection get -type COMPOUND_TEXT]
	list [string equal üф $x] [string length $x]
    }]
    lappend result $selInfo
} -cleanup {
    cleanupbg
} -result {1 2 {COMPOUND_TEXT 0 4000}}

test unixSelect-1.4 {TkSelGetSelection procedure: INCR i18n text, iso2022} -constraints {
    x11
} -setup {
    setupbg
    setup
} -body {
    # This test is subtle.  The selection ends up getting fetched twice by
    # Tk:  once to compute the length, and again to actually send the data.
    # The first time through, we don't convert the data to ISO2022, so the
    # buffer boundaries end up being different in the two passes.
    selection handle -type COMPOUND_TEXT -format COMPOUND_TEXT . \
	{handler COMPOUND_TEXT}
    selection own .
    set selValue [string repeat x 3999]üф[string repeat x 3999]
    set selInfo {}
    set result [dobg {
	set x [selection get -type COMPOUND_TEXT]
	list [string equal \
	    [string repeat x 3999]üф[string repeat x 3999] $x] \
	    [string length $x]
    }]
    lappend result $selInfo
} -cleanup {
    cleanupbg
} -result {1 8000 {COMPOUND_TEXT 0 4000 COMPOUND_TEXT 4000 3999 COMPOUND_TEXT 7998 4000 COMPOUND_TEXT 0 4000 COMPOUND_TEXT 4000 3998 COMPOUND_TEXT 7997 4000}}

test unixSelect-1.5 {TkSelGetSelection procedure: simple i18n text, iso2022} -constraints {
    x11
} -setup {
    setupbg
    setup
} -body {
    selection handle -type COMPOUND_TEXT -format COMPOUND_TEXT . \
	{handler COMPOUND_TEXT}
    selection own .
    set selValue üф
    set selInfo {}
    set result [dobg {
	set x [selection get -type COMPOUND_TEXT]
	list [string equal üф $x] [string length $x]
    }]
    lappend result $selInfo
} -cleanup {
    cleanupbg
} -result {1 2 {COMPOUND_TEXT 0 4000}}

test unixSelect-1.6 {TkSelGetSelection procedure: INCR i18n text} -constraints {
    x11
} -setup {
    setupbg
} -body {
    dobg [subst -nobackslashes {entry .e; pack .e; update
    .e insert 0 über$longValue
    .e selection range 0 end}]
    string length [selection get]
} -cleanup {
    cleanupbg
} -result [expr {4 + [string length $longValue]}]

test unixSelect-1.7 {TkSelGetSelection procedure: INCR i18n text} -constraints {
    x11
} -setup {
    setupbg
} -body {
    dobg {
	pack [entry .e]
	update
	.e insert 0 [string repeat x 3999]ü
	.e selection range 0 end
    }
    selection get
} -cleanup {
    cleanupbg
} -result [string repeat x 3999]ü

test unixSelect-1.8 {TkSelGetSelection procedure: INCR i18n text} -constraints {
    x11
} -setup {
    setupbg
} -body {
    dobg {
	pack [entry .e]
	update
	.e insert 0 ü[string repeat x 3999]
	.e selection range 0 end
    }
    selection get
} -cleanup {
    cleanupbg
} -result ü[string repeat x 3999]

test unixSelect-1.9 {TkSelGetSelection procedure: INCR i18n text} -constraints {
    x11
} -setup {
    setupbg
} -body {
    dobg {
	pack [entry .e]
	update
	.e insert 0 [string repeat x 3999]ü[string repeat x 4000]
	.e selection range 0 end
    }
    selection get
} -cleanup {
    cleanupbg
} -result [string repeat x 3999]ü[string repeat x 4000]
# Now some tests to make sure that the right thing is done when
# transferring UTF8 selections, to prevent [Bug 614650] and its ilk
# from rearing its ugly head again.

test unixSelect-1.10 {TkSelGetSelection procedure: INCR i18n text, utf-8} -constraints {
    x11
} -setup {
    setupbg
} -body {
    dobg {
	pack [entry .e]
	update
	.e insert 0 [string repeat x 3999]ü
	.e selection range 0 end
    }
    selection get -type UTF8_STRING
} -cleanup {
    cleanupbg
} -result [string repeat x 3999]ü

test unixSelect-1.11 {TkSelGetSelection procedure: INCR i18n text, utf-8} -constraints {
    x11
} -setup {
    setupbg
} -body {
    dobg {
	pack [entry .e]
	update
	.e insert 0 ü[string repeat x 3999]
	.e selection range 0 end
    }
    selection get -type UTF8_STRING
} -cleanup {
    cleanupbg
} -result ü[string repeat x 3999]

test unixSelect-1.12 {TkSelGetSelection procedure: INCR i18n text, utf-8} -constraints {
    x11
} -setup {
    setupbg
} -body {
    dobg {
	pack [entry .e]
	update
	.e insert 0 [string repeat x 3999]ü[string repeat x 4000]
	.e selection range 0 end
    }
    selection get -type UTF8_STRING
} -cleanup {
    cleanupbg
} -result [string repeat x 3999]ü[string repeat x 4000]

test unixSelect-1.13 {TkSelGetSelection procedure: simple i18n text, utf-8} -constraints {
    x11
} -setup {
    destroy .e
    setupbg
} -body {
    pack [entry .e]
    update
    .e insert 0 überф
    .e selection range 0 end
    dobg {string length [selection get -type UTF8_STRING]}
} -cleanup {
    destroy .e
    cleanupbg
} -result 5

test unixSelect-1.14 {TkSelGetSelection procedure: simple i18n text, utf-8} -constraints {
    x11
} -setup {
    setupbg
} -body {
    dobg {
	pack [entry .e]
	update
	.e insert 0 üф
	.e selection range 0 end
    }
    selection get -type UTF8_STRING
} -cleanup {
    cleanupbg
} -result üф

test unixSelect-1.15 {TkSelGetSelection procedure: INCR i18n text, utf-8} -constraints {
    x11
} -setup {
    setupbg
} -body {
    dobg {
	pack [entry .e]
	update
	.e insert 0 [string repeat [string repeat Ää 50]\n 21]
	.e selection range 0 end
    }
    selection get -type UTF8_STRING
} -cleanup {
    cleanupbg
} -result [string repeat [string repeat Ää 50]\n 21]

test unixSelect-1.16 {TkSelGetSelection procedure: INCR i18n text, utf-8} -constraints {
    x11
} -setup {
    setupbg
} -body {
    dobg {
	pack [entry .e]
	update
	.e insert 0 i[string repeat [string repeat Ää 50]\n 21]
	.e selection range 0 end
    }
    selection get -type UTF8_STRING
} -cleanup {
    cleanupbg
} -result i[string repeat [string repeat Ää 50]\n 21]

test unixSelect-1.17 {TkSelGetSelection procedure: INCR i18n text, utf-8} -constraints {
    x11
} -setup {
    setupbg
} -body {
    dobg {
	pack [text .t]
	update
	.t insert 1.0 [string repeat [string repeat Ää 50]\n 21]
	# Has to be selected in a separate stage
	.t tag add sel 1.0 21.end+1c
    }
    after 10
    selection get -type UTF8_STRING
} -cleanup {
    cleanupbg
} -result [string repeat [string repeat Ää 50]\n 21]

test unixSelect-1.18 {TkSelGetSelection procedure: INCR i18n text, utf-8} -constraints {
    x11
} -setup {
    setupbg
} -body {
    dobg {
	pack [text .t]
	update
	.t insert 1.0 i[string repeat [string repeat Ää 50]\n 21]
	# Has to be selected in a separate stage
	.t tag add sel 1.0 21.end+1c
    }
    after 10
    selection get -type UTF8_STRING
} -cleanup {
    cleanupbg
} -result i[string repeat [string repeat Ää 50]\n 21]

test unixSelect-1.19 {Automatic UTF8_STRING support for selection handle} -constraints {
    unix
} -setup {
    destroy .l
} -body {
    # See Bug #666346 "Selection handling crashes under KDE 3.0"
    label .l
    selection handle .l  [list handler STRING]
    set selValue "This is the selection value"
    selection own .l
    selection get -type UTF8_STRING
} -cleanup {
    destroy .l
} -result {This is the selection value}




# cleanup

cleanupTests
return







<
|
<
<
|
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<



<



<
<
<
<
<
<
<
<
<
<
<
<













|





|

|






|

|







|





|
|






|





|





|
|










|







|





|
|






|





|





|

|




|





|

|







|





|

|







|





|

|







|








|

|







|





|

|







|





|

|







|






|





|


|





|

|







|





|

|







|





|

|







|





|

|









|





|

|









|

















>
>
>
|
>


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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.

package require tcltest 2.2
namespace import ::tcltest::*
tcltest::configure {*}$argv
tcltest::loadTestedCommands


# Import utility procs for specific functional areas


testutils import child select




























































# Eliminate any existing selection on the screen.  This is needed in case
# there is a selection in some other application, in order to prevent races
# from causing false errors in the tests below.

selection clear .
after 1500













# set up a very large buffer to test INCR retrievals
set longValue ""
foreach i {a b c d e f g j h i j k l m o p q r s t u v w x y z} {
    set j $i.1$i.2$i.3$i.4$i.5$i.6$i.7$i.8$i.9$i.10$i.11$i.12$i.13$i.14
    append longValue A$j B$j C$j D$j E$j F$j G$j H$j I$j K$j L$j M$j N$j
}

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

test unixSelect-1.1 {TkSelGetSelection procedure: simple i18n text} -constraints {
    x11
} -setup {
    destroy .e
    childTkProcess create
} -body {
    pack [entry .e]
    update
    .e insert 0 über
    .e selection range 0 end
    childTkProcess eval {string length [selection get]}
} -cleanup {
    childTkProcess exit
    destroy .e
} -result 4

test unixSelect-1.2 {TkSelGetSelection procedure: simple i18n text, iso8859-1} -constraints {
    x11
} -setup {
    childTkProcess create
} -body {
    childTkProcess eval {
	pack [entry .e]
	update
	.e insert 0 üф
	.e selection range 0 end
    }
    selection get
} -cleanup {
    childTkProcess exit
} -result ü?

test unixSelect-1.3 {TkSelGetSelection procedure: simple i18n text, iso2022} -constraints {
    x11
} -setup {
    childTkProcess create
    selectionSetup
} -body {
    selection handle -type COMPOUND_TEXT -format COMPOUND_TEXT . \
	{handler COMPOUND_TEXT}
    selection own .
    set selValue üф
    set selInfo {}
    set result [childTkProcess eval {
	set x [selection get -type COMPOUND_TEXT]
	list [string equal üф $x] [string length $x]
    }]
    lappend result $selInfo
} -cleanup {
    childTkProcess exit
} -result {1 2 {COMPOUND_TEXT 0 4000}}

test unixSelect-1.4 {TkSelGetSelection procedure: INCR i18n text, iso2022} -constraints {
    x11
} -setup {
    childTkProcess create
    selectionSetup
} -body {
    # This test is subtle.  The selection ends up getting fetched twice by
    # Tk:  once to compute the length, and again to actually send the data.
    # The first time through, we don't convert the data to ISO2022, so the
    # buffer boundaries end up being different in the two passes.
    selection handle -type COMPOUND_TEXT -format COMPOUND_TEXT . \
	{handler COMPOUND_TEXT}
    selection own .
    set selValue [string repeat x 3999]üф[string repeat x 3999]
    set selInfo {}
    set result [childTkProcess eval {
	set x [selection get -type COMPOUND_TEXT]
	list [string equal \
	    [string repeat x 3999]üф[string repeat x 3999] $x] \
	    [string length $x]
    }]
    lappend result $selInfo
} -cleanup {
    childTkProcess exit
} -result {1 8000 {COMPOUND_TEXT 0 4000 COMPOUND_TEXT 4000 3999 COMPOUND_TEXT 7998 4000 COMPOUND_TEXT 0 4000 COMPOUND_TEXT 4000 3998 COMPOUND_TEXT 7997 4000}}

test unixSelect-1.5 {TkSelGetSelection procedure: simple i18n text, iso2022} -constraints {
    x11
} -setup {
    childTkProcess create
    selectionSetup
} -body {
    selection handle -type COMPOUND_TEXT -format COMPOUND_TEXT . \
	{handler COMPOUND_TEXT}
    selection own .
    set selValue üф
    set selInfo {}
    set result [childTkProcess eval {
	set x [selection get -type COMPOUND_TEXT]
	list [string equal üф $x] [string length $x]
    }]
    lappend result $selInfo
} -cleanup {
    childTkProcess exit
} -result {1 2 {COMPOUND_TEXT 0 4000}}

test unixSelect-1.6 {TkSelGetSelection procedure: INCR i18n text} -constraints {
    x11
} -setup {
    childTkProcess create
} -body {
    childTkProcess eval [subst -nobackslashes {entry .e; pack .e; update
    .e insert 0 über$longValue
    .e selection range 0 end}]
    string length [selection get]
} -cleanup {
    childTkProcess exit
} -result [expr {4 + [string length $longValue]}]

test unixSelect-1.7 {TkSelGetSelection procedure: INCR i18n text} -constraints {
    x11
} -setup {
    childTkProcess create
} -body {
    childTkProcess eval {
	pack [entry .e]
	update
	.e insert 0 [string repeat x 3999]ü
	.e selection range 0 end
    }
    selection get
} -cleanup {
    childTkProcess exit
} -result [string repeat x 3999]ü

test unixSelect-1.8 {TkSelGetSelection procedure: INCR i18n text} -constraints {
    x11
} -setup {
    childTkProcess create
} -body {
    childTkProcess eval {
	pack [entry .e]
	update
	.e insert 0 ü[string repeat x 3999]
	.e selection range 0 end
    }
    selection get
} -cleanup {
    childTkProcess exit
} -result ü[string repeat x 3999]

test unixSelect-1.9 {TkSelGetSelection procedure: INCR i18n text} -constraints {
    x11
} -setup {
    childTkProcess create
} -body {
    childTkProcess eval {
	pack [entry .e]
	update
	.e insert 0 [string repeat x 3999]ü[string repeat x 4000]
	.e selection range 0 end
    }
    selection get
} -cleanup {
    childTkProcess exit
} -result [string repeat x 3999]ü[string repeat x 4000]
# Now some tests to make sure that the right thing is done when
# transferring UTF8 selections, to prevent [Bug 614650] and its ilk
# from rearing its ugly head again.

test unixSelect-1.10 {TkSelGetSelection procedure: INCR i18n text, utf-8} -constraints {
    x11
} -setup {
    childTkProcess create
} -body {
    childTkProcess eval {
	pack [entry .e]
	update
	.e insert 0 [string repeat x 3999]ü
	.e selection range 0 end
    }
    selection get -type UTF8_STRING
} -cleanup {
    childTkProcess exit
} -result [string repeat x 3999]ü

test unixSelect-1.11 {TkSelGetSelection procedure: INCR i18n text, utf-8} -constraints {
    x11
} -setup {
    childTkProcess create
} -body {
    childTkProcess eval {
	pack [entry .e]
	update
	.e insert 0 ü[string repeat x 3999]
	.e selection range 0 end
    }
    selection get -type UTF8_STRING
} -cleanup {
    childTkProcess exit
} -result ü[string repeat x 3999]

test unixSelect-1.12 {TkSelGetSelection procedure: INCR i18n text, utf-8} -constraints {
    x11
} -setup {
    childTkProcess create
} -body {
    childTkProcess eval {
	pack [entry .e]
	update
	.e insert 0 [string repeat x 3999]ü[string repeat x 4000]
	.e selection range 0 end
    }
    selection get -type UTF8_STRING
} -cleanup {
    childTkProcess exit
} -result [string repeat x 3999]ü[string repeat x 4000]

test unixSelect-1.13 {TkSelGetSelection procedure: simple i18n text, utf-8} -constraints {
    x11
} -setup {
    destroy .e
    childTkProcess create
} -body {
    pack [entry .e]
    update
    .e insert 0 überф
    .e selection range 0 end
    childTkProcess eval {string length [selection get -type UTF8_STRING]}
} -cleanup {
    destroy .e
    childTkProcess exit
} -result 5

test unixSelect-1.14 {TkSelGetSelection procedure: simple i18n text, utf-8} -constraints {
    x11
} -setup {
    childTkProcess create
} -body {
    childTkProcess eval {
	pack [entry .e]
	update
	.e insert 0 üф
	.e selection range 0 end
    }
    selection get -type UTF8_STRING
} -cleanup {
    childTkProcess exit
} -result üф

test unixSelect-1.15 {TkSelGetSelection procedure: INCR i18n text, utf-8} -constraints {
    x11
} -setup {
    childTkProcess create
} -body {
    childTkProcess eval {
	pack [entry .e]
	update
	.e insert 0 [string repeat [string repeat Ää 50]\n 21]
	.e selection range 0 end
    }
    selection get -type UTF8_STRING
} -cleanup {
    childTkProcess exit
} -result [string repeat [string repeat Ää 50]\n 21]

test unixSelect-1.16 {TkSelGetSelection procedure: INCR i18n text, utf-8} -constraints {
    x11
} -setup {
    childTkProcess create
} -body {
    childTkProcess eval {
	pack [entry .e]
	update
	.e insert 0 i[string repeat [string repeat Ää 50]\n 21]
	.e selection range 0 end
    }
    selection get -type UTF8_STRING
} -cleanup {
    childTkProcess exit
} -result i[string repeat [string repeat Ää 50]\n 21]

test unixSelect-1.17 {TkSelGetSelection procedure: INCR i18n text, utf-8} -constraints {
    x11
} -setup {
    childTkProcess create
} -body {
    childTkProcess eval {
	pack [text .t]
	update
	.t insert 1.0 [string repeat [string repeat Ää 50]\n 21]
	# Has to be selected in a separate stage
	.t tag add sel 1.0 21.end+1c
    }
    after 10
    selection get -type UTF8_STRING
} -cleanup {
    childTkProcess exit
} -result [string repeat [string repeat Ää 50]\n 21]

test unixSelect-1.18 {TkSelGetSelection procedure: INCR i18n text, utf-8} -constraints {
    x11
} -setup {
    childTkProcess create
} -body {
    childTkProcess eval {
	pack [text .t]
	update
	.t insert 1.0 i[string repeat [string repeat Ää 50]\n 21]
	# Has to be selected in a separate stage
	.t tag add sel 1.0 21.end+1c
    }
    after 10
    selection get -type UTF8_STRING
} -cleanup {
    childTkProcess exit
} -result i[string repeat [string repeat Ää 50]\n 21]

test unixSelect-1.19 {Automatic UTF8_STRING support for selection handle} -constraints {
    unix
} -setup {
    destroy .l
} -body {
    # See Bug #666346 "Selection handling crashes under KDE 3.0"
    label .l
    selection handle .l  [list handler STRING]
    set selValue "This is the selection value"
    selection own .l
    selection get -type UTF8_STRING
} -cleanup {
    destroy .l
} -result {This is the selection value}

#
# CLEANUP
#

testutils forget child select
cleanupTests
return
Changes to tests/unixWm.test.
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
# This file is a Tcl script to test out Tk's interactions with
# the window manager, including the "wm" command.  It is organized
# in the standard fashion for Tcl tests.
#
# Copyright © 1992-1994 The Regents of the University of California.
# Copyright © 1994-1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

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

namespace import -force ::tk::test:loadTkCommand

testConstraint failsOnUbuntu [expr {![info exists ::env(CI)] || ![string match Linux $::tcl_platform(os)]}]
testConstraint failsOnXQuarz [expr {$tcl_platform(os) ne "Darwin" || [tk windowingsystem] ne "x11" }]

proc sleep ms {
    global x
    after $ms {set x 1}
    vwait x
}

# Procedure to set up a collection of top-level windows

proc makeToplevels {} {
    deleteWindows
    foreach i {.raise1 .raise2 .raise3} {
	toplevel $i
	wm geom $i 150x100+0+0













<
<
<
<
<
<
<
<
<
<
<







1
2
3
4
5
6
7
8
9
10
11
12
13











14
15
16
17
18
19
20
# This file is a Tcl script to test out Tk's interactions with
# the window manager, including the "wm" command.  It is organized
# in the standard fashion for Tcl tests.
#
# Copyright © 1992-1994 The Regents of the University of California.
# Copyright © 1994-1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

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












# Procedure to set up a collection of top-level windows

proc makeToplevels {} {
    deleteWindows
    foreach i {.raise1 .raise2 .raise3} {
	toplevel $i
	wm geom $i 150x100+0+0
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
    incr i
}

set i 1
foreach geom "+$X+80 +$X+40 +$X+$Y0" {
    test unixWm-4.$i {moving window while withdrawn} unix {
	wm withdraw .t
	sleep 10
	wm geom .t $geom
	update idletasks
	wm deiconify .t
	sleep 10
	wm geom .t
    } 100x150$geom
    incr i
}

test unixWm-5.1 {compounded state changes} {unix nonPortable} {
    destroy .t







|



|







99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
    incr i
}

set i 1
foreach geom "+$X+80 +$X+40 +$X+$Y0" {
    test unixWm-4.$i {moving window while withdrawn} unix {
	wm withdraw .t
	pause 10
	wm geom .t $geom
	update idletasks
	wm deiconify .t
	pause 10
	wm geom .t
    } 100x150$geom
    incr i
}

test unixWm-5.1 {compounded state changes} {unix nonPortable} {
    destroy .t
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
    list [catch {wm iconwindow} msg] $msg
} {1 {wrong # args: should be "wm option window ?arg ...?"}}
test unixWm-8.3 {icon windows} unix {
    destroy .t
    toplevel .t -width 100 -height 30
    list [catch {wm iconwindow .t b c} msg] $msg
} {1 {wrong # args: should be "wm iconwindow window ?pathName?"}}
test unixWm-8.4 {icon windows} {unix failsOnUbuntu failsOnXQuarz} {
    destroy .t
    destroy .icon
    toplevel .t -width 100 -height 30
    wm geom .t +0+0
    update idletasks
    set result [wm iconwindow .t]
    toplevel .icon -width 50 -height 50 -bg red







|







278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
    list [catch {wm iconwindow} msg] $msg
} {1 {wrong # args: should be "wm option window ?arg ...?"}}
test unixWm-8.3 {icon windows} unix {
    destroy .t
    toplevel .t -width 100 -height 30
    list [catch {wm iconwindow .t b c} msg] $msg
} {1 {wrong # args: should be "wm iconwindow window ?pathName?"}}
test unixWm-8.4 {icon windows} {unix failsOnUbuntu failsOnXQuartz} {
    destroy .t
    destroy .icon
    toplevel .t -width 100 -height 30
    wm geom .t +0+0
    update idletasks
    set result [wm iconwindow .t]
    toplevel .icon -width 50 -height 50 -bg red
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
    destroy .icon
    toplevel .icon -width 50 -height 50 -bg red
    wm iconwindow .t .icon
    set result [list [catch {wm deiconify .icon} msg] $msg]
    destroy .icon
    set result
} {1 {can't deiconify .icon: it is an icon for .t}}
test unixWm-16.3 {Tk_WmCmd procedure, "deiconify" option} {unix failsOnUbuntu failsOnXQuarz} {
    wm iconify .t
    set result {}
    lappend result [winfo ismapped .t] [wm state .t]
    wm deiconify .t
    lappend result [winfo ismapped .t] [wm state .t]
} {0 iconic 1 normal}








|







623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
    destroy .icon
    toplevel .icon -width 50 -height 50 -bg red
    wm iconwindow .t .icon
    set result [list [catch {wm deiconify .icon} msg] $msg]
    destroy .icon
    set result
} {1 {can't deiconify .icon: it is an icon for .t}}
test unixWm-16.3 {Tk_WmCmd procedure, "deiconify" option} {unix failsOnUbuntu failsOnXQuartz} {
    wm iconify .t
    set result {}
    lappend result [winfo ismapped .t] [wm state .t]
    wm deiconify .t
    lappend result [winfo ismapped .t] [wm state .t]
} {0 iconic 1 normal}

847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
    toplevel .t2
    wm geom .t2 +0+0
    wm iconwindow .t .t2
    set result [list [catch {wm iconify .t2} msg] $msg]
    destroy .t2
    set result
} {1 {can't iconify ".t2": it is an icon for ".t"}}
test unixWm-23.5 {Tk_WmCmd procedure, "iconify" option} {unix failsOnUbuntu failsOnXQuarz} {
    destroy .t2
    toplevel .t2
    wm geom .t2 +0+0
    update idletasks
    wm iconify .t2
    update idletasks
    set result [winfo ismapped .t2]
    destroy .t2
    set result
} 0
test unixWm-23.6 {Tk_WmCmd procedure, "iconify" option} {unix failsOnUbuntu failsOnXQuarz} {
    destroy .t2
    toplevel .t2
    wm geom .t2 -0+0
    update idletasks
    set result [winfo ismapped .t2]
    wm iconify .t2
    update idletasks







|










|







836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
    toplevel .t2
    wm geom .t2 +0+0
    wm iconwindow .t .t2
    set result [list [catch {wm iconify .t2} msg] $msg]
    destroy .t2
    set result
} {1 {can't iconify ".t2": it is an icon for ".t"}}
test unixWm-23.5 {Tk_WmCmd procedure, "iconify" option} {unix failsOnUbuntu failsOnXQuartz} {
    destroy .t2
    toplevel .t2
    wm geom .t2 +0+0
    update idletasks
    wm iconify .t2
    update idletasks
    set result [winfo ismapped .t2]
    destroy .t2
    set result
} 0
test unixWm-23.6 {Tk_WmCmd procedure, "iconify" option} {unix failsOnUbuntu failsOnXQuartz} {
    destroy .t2
    toplevel .t2
    wm geom .t2 -0+0
    update idletasks
    set result [winfo ismapped .t2]
    wm iconify .t2
    update idletasks
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
    update
    set result
} {configured: 130 200}

# No tests for ReparentEvent or ComputeReparentGeometry; I can't figure
# out how to exercise these procedures reliably.

test unixWm-42.1 {WrapperEventProc procedure, map and unmap events} {unix failsOnUbuntu failsOnXQuarz} {
    destroy .t
    toplevel .t -width 400 -height 150
    wm geometry .t +0+0
    tkwait visibility .t
    set result {}
    bind .t <Map> {set x "mapped"}
    bind .t <Unmap> {set x "unmapped"}







|







1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
    update
    set result
} {configured: 130 200}

# No tests for ReparentEvent or ComputeReparentGeometry; I can't figure
# out how to exercise these procedures reliably.

test unixWm-42.1 {WrapperEventProc procedure, map and unmap events} {unix failsOnUbuntu failsOnXQuartz} {
    destroy .t
    toplevel .t -width 400 -height 150
    wm geometry .t +0+0
    tkwait visibility .t
    set result {}
    bind .t <Map> {set x "mapped"}
    bind .t <Unmap> {set x "unmapped"}
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
if {[tk windowingsystem] eq "aqua"} {
    # Modern mac windows have no border.
    set result_50_1 {{} {} .t .t .t2 {} .t2 .t .t}
} else {
    # Windows are assumed to have a border (invisible in Gnome 3).
    set result_50_1 {{} {} .t {} .t2 {} .t2 {} .t}
}
test unixWm-50.1 {Tk_CoordsToWindow procedure, finding a toplevel, x-coords, title bar} {unix failsOnUbuntu failsOnXQuarz} {
    update
    toplevel .t -width 300 -height 400 -bg green
    wm geom .t +100+100
    tkwait visibility .t
    toplevel .t2 -width 100 -height 200 -bg red
    wm geom .t2 +200+200
    tkwait visibility .t2







|







1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
if {[tk windowingsystem] eq "aqua"} {
    # Modern mac windows have no border.
    set result_50_1 {{} {} .t .t .t2 {} .t2 .t .t}
} else {
    # Windows are assumed to have a border (invisible in Gnome 3).
    set result_50_1 {{} {} .t {} .t2 {} .t2 {} .t}
}
test unixWm-50.1 {Tk_CoordsToWindow procedure, finding a toplevel, x-coords, title bar} {unix failsOnUbuntu failsOnXQuartz} {
    update
    toplevel .t -width 300 -height 400 -bg green
    wm geom .t +100+100
    tkwait visibility .t
    toplevel .t2 -width 100 -height 200 -bg red
    wm geom .t2 +200+200
    tkwait visibility .t2
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
    set y [expr [winfo rooty .t] + 150]
    list [winfo containing [expr $x + 50] $y] \
	    [winfo containing [expr $x + 150] $y] \
	    [winfo containing [expr $x + 250] $y] \
	    [winfo containing [expr $x + 350] $y] \
	    [winfo containing [expr $x + 450] $y]
} {.t .t.f .t.f.f .t {}}
test unixWm-50.9 {Tk_CoordsToWindow procedure, unmapped windows} {unix failsOnUbuntu failsOnXQuarz} {
    destroy .t
    destroy .t2
    update
    toplevel .t -width 200 -height 200 -bg green
    tkwait visibility .t
    wm geometry .t +20+20
    after 200







|







1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
    set y [expr [winfo rooty .t] + 150]
    list [winfo containing [expr $x + 50] $y] \
	    [winfo containing [expr $x + 150] $y] \
	    [winfo containing [expr $x + 250] $y] \
	    [winfo containing [expr $x + 350] $y] \
	    [winfo containing [expr $x + 450] $y]
} {.t .t.f .t.f.f .t {}}
test unixWm-50.9 {Tk_CoordsToWindow procedure, unmapped windows} {unix failsOnUbuntu failsOnXQuartz} {
    destroy .t
    destroy .t2
    update
    toplevel .t -width 200 -height 200 -bg green
    tkwait visibility .t
    wm geometry .t +20+20
    after 200
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
    wm geometry .t +0+0
    update
    destroy .t2
    toplevel .t2 -width 200 -height 200 -bg red
    # This test assumes that .t2 is not mapped yet, but that is not really guaranteed.
    winfo containing 100 100
} {.t}
test unixWm-51.7 {TkWmRestackToplevel procedure, other window isn't mapped} {unix failsOnXQuarz} {
    foreach w {.t .t2 .t3} {
	destroy $w
	toplevel $w -width 200 -height 200 -bg green
	tkwait visibility $w
	wm geometry $w +100+100
	after 200
	update







|







2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
    wm geometry .t +0+0
    update
    destroy .t2
    toplevel .t2 -width 200 -height 200 -bg red
    # This test assumes that .t2 is not mapped yet, but that is not really guaranteed.
    winfo containing 100 100
} {.t}
test unixWm-51.7 {TkWmRestackToplevel procedure, other window isn't mapped} {unix failsOnXQuartz} {
    foreach w {.t .t2 .t3} {
	destroy $w
	toplevel $w -width 200 -height 200 -bg green
	tkwait visibility $w
	wm geometry $w +100+100
	after 200
	update
Changes to tests/visual.test.
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
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
tcltest::configure {*}$argv
tcltest::loadTestedCommands

update

# eatColors --
# Creates a toplevel window and allocates enough colors in it to
# use up all the slots in the colormap.
#
# Arguments:
# w -        Name of toplevel window to create.

proc eatColors {w} {
    catch {destroy $w}
    toplevel $w
    wm geom $w +0+0
    canvas $w.c -width 400 -height 200 -bd 0
    pack $w.c
    for {set y 0} {$y < 8} {incr y} {
	for {set x 0} {$x < 40} {incr x} {
	    set color [format #%02x%02x%02x [expr {$x*6}] [expr {$y*30}] 0]
	    $w.c create rectangle [expr {10*$x}] [expr {20*$y}] \
		[expr {10*$x + 10}] [expr {20*$y + 20}] -outline {} \
		-fill $color
	}
    }
    update
}

# colorsFree --
#
# Returns 1 if there appear to be free colormap entries in a window,
# 0 otherwise.
#
# Arguments:
# w -            Name of window in which to check.
# red, green, blue -    Intensities to use in a trial color allocation
#            to see if there are colormap entries free.

proc colorsFree {w {red 31} {green 245} {blue 192}} {
    set vals [winfo rgb $w [format #%02x%02x%02x $red $green $blue]]
    expr {([lindex $vals 0]/256 == $red) && ([lindex $vals 1]/256 == $green)
	&& ([lindex $vals 2]/256 == $blue)}
}

# If more than one visual type is available for the screen, pick one
# that is *not* the default.

set default "[winfo visual .] [winfo depth .]"
set avail [winfo visualsavailable .]
set other {}







<
|
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
|
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







8
9
10
11
12
13
14

15






16












17

18

















19
20
21
22
23
24
25
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
tcltest::configure {*}$argv
tcltest::loadTestedCommands


# Import utility procs for specific functional areas






testutils import colors














update


















# If more than one visual type is available for the screen, pick one
# that is *not* the default.

set default "[winfo visual .] [winfo depth .]"
set avail [winfo visualsavailable .]
set other {}
552
553
554
555
556
557
558
559
560
561
562

563
564


565
566
567
568
569
570
    destroy .t3
    destroy .t4
    update
} -cleanup {
    deleteWindows
} -result {}


deleteWindows
rename eatColors {}
rename colorsFree {}


# cleanup


cleanupTests
return

# Local variables:
# mode: tcl
# End:







|
<
<
<
>
|
|
>
>






515
516
517
518
519
520
521
522



523
524
525
526
527
528
529
530
531
532
533
    destroy .t3
    destroy .t4
    update
} -cleanup {
    deleteWindows
} -result {}

#



# CLEANUP
#

deleteWindows
testutils forget colors
cleanupTests
return

# Local variables:
# mode: tcl
# End:
Changes to tests/winButton.test.
8
9
10
11
12
13
14
15
16
17

18

19
20
21
22
23
24
25
26
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
tcltest::configure {*}$argv
tcltest::loadTestedCommands
imageInit

proc bogusTrace args {

    error "trace aborted"

}
option clear

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

test winbutton-1.1 {TkpComputeButtonGeometry procedure} -constraints {
    testImageType win nonPortable
} -setup {







<

|
>
|
>
|







8
9
10
11
12
13
14

15
16
17
18
19
20
21
22
23
24
25
26
27
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
tcltest::configure {*}$argv
tcltest::loadTestedCommands


# Import utility procs for specific functional areas
testutils import button image

imageInit

option clear

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

test winbutton-1.1 {TkpComputeButtonGeometry procedure} -constraints {
    testImageType win nonPortable
} -setup {
187
188
189
190
191
192
193



194
195
196

197
198
199
200
201
202
203
} -body {
    button .b2 -bitmap question -default normal
    list [winfo reqwidth .b2] [winfo reqheight .b2]
} -cleanup {
    deleteWindows
} -result {23 33}




# cleanup
imageFinish
deleteWindows

cleanupTests
return

# Local variables:
# mode: tcl
# End:








>
>
>
|


>







188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
} -body {
    button .b2 -bitmap question -default normal
    list [winfo reqwidth .b2] [winfo reqheight .b2]
} -cleanup {
    deleteWindows
} -result {23 33}

#
# CLEANUP
#

imageFinish
deleteWindows
testutils forget button image
cleanupTests
return

# Local variables:
# mode: tcl
# End:

Changes to tests/winDialog.test.
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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429

430
431
432


433




434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593

594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
# Copyright © 1998-1999 ActiveState Corporation.

package require tcltest 2.2
namespace import ::tcltest::*
tcltest::configure {*}$argv
tcltest::loadTestedCommands





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

# Locale identifier LANG_ENGLISH is 0x09
testConstraint english [expr {
    [llength [info commands testwinlocale]]
    && (([testwinlocale] & 0xff) == 9)
}]

# What directory to use in initialdir tests. Old code used to use
# c:/. However, on Vista/later that is a protected directory if you
# are not running privileged. Moreover, not everyone has a drive c:
# but not having a TEMP would break a lot Windows programs
proc initialdir {} {
    # file join to return in Tcl canonical format (/ separator, not \)
    #return [file join $::env(TEMP)]
    return [tcltest::temporaryDirectory]
}


proc start {arg} {
    set ::tk_dialog 0
    set ::iter_after 0
    set ::dialogclass "#32770"

    after 1 $arg
}

proc then {cmd} {
    set ::command $cmd
    set ::dialogresult {}
    set ::testfont {}

    # Do not make the delay too short. The newer Vista dialogs take
    # time to come up. Even if the testforwindow returns true, the
    # controls are not ready to accept messages
    after 500 afterbody
    vwait ::dialogresult
    return $::dialogresult
}

proc afterbody {} {
    # On Vista and later, using the new file dialogs we have to find
    # the window using its title as tk_dialog will not be set at the C level
    if {[catch {testfindwindow "" $::dialogclass} ::tk_dialog]} {
	if {[incr ::iter_after] > 30} {
	    set ::dialogresult ">30 iterations waiting on tk_dialog"
	    return
	}
	after 150 {afterbody}
	return
    }
    uplevel #0 {set dialogresult [eval $command]}
}

proc Click {button} {

    switch -exact -- $button {
	ok     { set button 1 }
	cancel { set button 2 }
    }
    testwinevent $::tk_dialog $button WM_LBUTTONDOWN 1 0x000a000b
    testwinevent $::tk_dialog $button WM_LBUTTONUP 0 0x000a000b
}

proc GetText {id} {

    switch -exact -- $id {
	ok     { set id 1 }
	cancel { set id 2 }
    }
    return [testwinevent $::tk_dialog $id WM_GETTEXT]
}

proc SetText {id text} {

    return [testwinevent $::tk_dialog $id WM_SETTEXT $text]
}

proc ApplyFont {font} {
     set ::testfont $font
}

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

test winDialog-1.1 {Tk_ChooseColorObjCmd} -constraints {
    testwinevent
} -body {
    start {tk_chooseColor}
    then {
	Click cancel
    }
} -result 0
test winDialog-1.2 {Tk_ChooseColorObjCmd} -constraints {
    testwinevent
} -body {
    start {set clr [tk_chooseColor -initialcolor "#ff9933"]}
    then {
	set x [Click cancel]
    }
    list $x $clr
} -result {0 {}}
test winDialog-1.3 {Tk_ChooseColorObjCmd} -constraints {
    testwinevent
} -body {
    start {set clr [tk_chooseColor -initialcolor "#ff9933"]}
    then {
	set x [Click ok]
    }
    list $x $clr
} -result [list 0 "#ff9933"]
test winDialog-1.4 {Tk_ChooseColorObjCmd: -title} -constraints {
    testwinevent
} -setup {
    catch {unset a x}
} -body {
    set x {}
    start {set clr [tk_chooseColor -initialcolor "#ff9933" -title "Hello"]}
    then {
	if {[catch {
	    array set a [testgetwindowinfo $::tk_dialog]
	    if {[info exists a(text)]} {lappend x $a(text)}
	} err]} { lappend x $err }
	lappend x [Click ok]
    }
    lappend x $clr
} -result [list Hello 0 "#ff9933"]
test winDialog-1.5 {Tk_ChooseColorObjCmd: -title} -constraints {
    testwinevent
} -setup {
    catch {unset a x}
} -body {
    set x {}
    start {
	set clr [tk_chooseColor -initialcolor "#ff9933" \
		     -title "Привет"]
    }
    then {
	if {[catch {
	    array set a [testgetwindowinfo $::tk_dialog]
	    if {[info exists a(text)]} {lappend x $a(text)}
	} err]} { lappend x $err }
	lappend x [Click ok]
    }
    lappend x $clr
} -result [list "Привет" 0 "#ff9933"]
test winDialog-1.6 {Tk_ChooseColorObjCmd: -parent} -constraints {
    testwinevent
} -setup {
    catch {unset a x}
} -body {
    start {set clr [tk_chooseColor -initialcolor "#ff9933" -parent .]}
    set x {}
    then {
	if {[catch {
	    array set a [testgetwindowinfo $::tk_dialog]
	    if {[info exists a(parent)]} {
		append x [expr {$a(parent) == [wm frame .]}]
	    }
	} err]} {lappend x $err}
	Click ok
    }
    list $x $clr
} -result [list 1 "#ff9933"]
test winDialog-1.7 {Tk_ChooseColorObjCmd: -parent} -constraints {
    testwinevent
} -body {
    tk_chooseColor -initialcolor "#ff9933" -parent .xyzzy12
} -returnCodes error -match glob -result {bad window path name*}


test winDialog-2.1 {ColorDlgHookProc} -constraints {emptyTest nt} -body {}

test winDialog-3.1 {Tk_GetOpenFileObjCmd} -constraints {
    nt testwinevent english
} -body {
    start {tk_getOpenFile}
    then {
	set x [GetText cancel]
	Click cancel
    }
    return $x
} -result {Cancel}


test winDialog-4.1 {Tk_GetSaveFileObjCmd} -constraints {
    nt testwinevent english
} -body {
    start {tk_getSaveFile}
    then {
	set x [GetText cancel]
	Click cancel
    }
    return $x
} -result {Cancel}

test winDialog-5.1 {GetFileName: no arguments} -constraints {
    nt testwinevent
} -body {
    start {tk_getOpenFile -title Open}
    then {
	Click cancel
    }
} -result 0
test winDialog-5.2 {GetFileName: one argument} -constraints {
    nt
} -body {
    tk_getOpenFile -foo
} -returnCodes error -result {bad option "-foo": must be -defaultextension, -filetypes, -initialdir, -initialfile, -multiple, -parent, -title, or -typevariable}
test winDialog-5.3 {GetFileName: many arguments} -constraints {
    nt testwinevent
} -body {
    start {tk_getOpenFile -initialdir [initialdir] -parent . -title test -initialfile foo}
    then {
	Click cancel
    }
} -result 0
test winDialog-5.4 {GetFileName: Tcl_GetIndexFromObj() != TCL_OK} -constraints {
    nt
} -body {
    tk_getOpenFile -foo bar -abc
} -returnCodes error -result {bad option "-foo": must be -defaultextension, -filetypes, -initialdir, -initialfile, -multiple, -parent, -title, or -typevariable}
test winDialog-5.5 {GetFileName: Tcl_GetIndexFromObj() == TCL_OK} -constraints {
    nt testwinevent
} -body {
    start {set x [tk_getOpenFile -title bar]}
    set y [then {
	Click cancel
    }]
    # Note this also tests fix for
    # https://core.tcl-lang.org/tk/tktview/4a0451f5291b3c9168cc560747dae9264e1d2ef6
    # $x is expected to be empty
    append x $y
} -result 0
test winDialog-5.6 {GetFileName: valid option, but missing value} -constraints {
    nt
} -body {
    tk_getOpenFile -initialdir bar -title
} -returnCodes error -result {value for "-title" missing}

test winDialog-5.7 {GetFileName: extension begins with .} -constraints {
    nt testwinevent
} -body {
    start {set x [tk_getSaveFile -defaultextension .foo -title Save]}
    set msg {}
    then {
	if {[catch {SetText 0x3e9 bar} msg]} {
	    Click cancel
	} else {
	    Click ok
	}
    }
    set x "[file tail $x]$msg"
} -cleanup {
    unset msg
} -result bar.foo

test winDialog-5.7.1 {GetFileName: extension {} } -constraints {
    nt testwinevent
} -body {
    start {set x [tk_getSaveFile -defaultextension {} -title Save]}
    set msg {}
    then {
	if {[catch {SetText 0x3e9 bar} msg]} {
	    Click cancel
	} else {
	    Click ok
	}
    }
    set x "[file tail $x]$msg"
} -cleanup {
    unset msg
} -result bar

test winDialog-5.7.2 {GetFileName: extension {} Bug 47af31bd3ac6fbbb33cde1a5bab1e756ff2a6e00 } -constraints {
    nt testwinevent
} -body {
    start {set x [tk_getSaveFile -filetypes {{All *}} -defaultextension {} -title Save]}
    set msg {}
    then {
	if {[catch {SetText 0x3e9 bar} msg]} {
	    Click cancel
	} else {
	    Click ok
	}
    }
    set x "[file tail $x]$msg"
} -cleanup {
    unset msg
} -result bar

test winDialog-5.7.3 {GetFileName: extension {} Bug 47af31bd3ac6fbbb33cde1a5bab1e756ff2a6e00 } -constraints {
    nt testwinevent
} -body {
    start {set x [tk_getSaveFile -filetypes {{All *}} -defaultextension {} -title Save]}
    set msg {}
    then {
	if {[catch {SetText 0x3e9 bar.c} msg]} {
	    Click cancel
	} else {
	    Click ok
	}
    }
    set x "[file tail $x]$msg"
} -cleanup {
    unset msg
} -result bar.c

test winDialog-5.7.4 {GetFileName: extension {} } -constraints {
    nt testwinevent
} -body {
    # Although the docs do not explicitly mention, -filetypes seems to
    # override -defaultextension
    start {set x [tk_getSaveFile -filetypes {{C .c} {Tcl .tcl}} -defaultextension {foo} -title Save]}
    set msg {}
    then {
	if {[catch {SetText 0x3e9 bar} msg]} {
	    Click cancel
	} else {
	    Click ok
	}
    }
    set x "[file tail $x]$msg"
} -cleanup {
    unset msg
} -result bar.c

test winDialog-5.7.5 {GetFileName: extension {} } -constraints {
    nt testwinevent
} -body {
    # Although the docs do not explicitly mention, -filetypes seems to
    # override -defaultextension
    start {set x [tk_getSaveFile -filetypes {{C .c} {Tcl .tcl}} -defaultextension {} -title Save]}
    set msg {}
    then {
	if {[catch {SetText 0x3e9 bar} msg]} {
	    Click cancel
	} else {
	    Click ok
	}
    }
    set x "[file tail $x]$msg"
} -cleanup {
    unset msg
} -result bar.c


test winDialog-5.7.6 {GetFileName: All/extension } -constraints {
    nt testwinevent
} -body {
    # In 8.6.4 this combination resulted in bar.aaa.aaa which is bad
    start {set x [tk_getSaveFile -filetypes {{All *}} -defaultextension {aaa} -title Save]}
    set msg {}
    then {
	if {[catch {SetText 0x3e9 bar} msg]} {
	    Click cancel
	} else {
	    Click ok
	}
    }
    set x "[file tail $x]$msg"
} -cleanup {
    unset msg
} -result bar.aaa

test winDialog-5.7.7 {tk_getOpenFile: -defaultextension} -constraints {
    nt testwinevent
} -body {
    unset -nocomplain x
    tcltest::makeFile "" "5 7 7.aaa" [initialdir]
    start {set x [tk_getOpenFile \
		      -defaultextension aaa \
		      -initialdir [file nativename [initialdir]] \
		      -initialfile "5 7 7" -title Foo]}
    then {
	Click ok
    }
    return $x
} -result [file join [initialdir] "5 7 7.aaa"]

test winDialog-5.7.8 {tk_getOpenFile: -defaultextension} -constraints {
    nt testwinevent
} -body {
    unset -nocomplain x
    tcltest::makeFile "" "5 7 8.aaa" [initialdir]
    start {set x [tk_getOpenFile \
		      -defaultextension aaa \
		      -initialdir [file nativename [initialdir]] \
		      -initialfile "5 7 8.aaa" -title Foo]}
    then {
	Click ok
    }
    return $x
} -result [file join [initialdir] "5 7 8.aaa"]

test winDialog-5.8 {GetFileName: extension doesn't begin with .} -constraints {
    nt testwinevent
} -body {
    start {set x [tk_getSaveFile -defaultextension foo -title Save]}
    set msg {}
    then {
	if {[catch {SetText 0x3e9 bar} msg]} {
	    Click cancel
	} else {
	    Click ok
	}
    }
    set x "[file tail $x]$msg"
} -cleanup {
    unset msg
} -result bar.foo
test winDialog-5.9 {GetFileName: file types} -constraints {
    nt testwinevent
} -body {
    #        case FILE_TYPES:

    start {tk_getSaveFile -filetypes {{"foo files" .foo FOOF}} -title Foo}

    # XXX - currently disabled for vista style dialogs because the file
    # types control has no control ID and we don't have a mechanism to
    # locate it.


    then {




	Click cancel
    }
    return 1
} -result 1
test winDialog-5.10 {GetFileName: file types: MakeFilter() fails} -constraints {
    nt
} -body {
#        if (MakeFilter(interp, string, &utfFilterString) != TCL_OK)

    tk_getSaveFile -filetypes {{"foo" .foo FOO}}
} -returnCodes error -result {bad Macintosh file type "FOO"}
test winDialog-5.11 {GetFileName: initial directory} -constraints {
    nt testwinevent
} -body {
#        case FILE_INITDIR:
    unset -nocomplain x
    start {set x [tk_getSaveFile \
		      -initialdir [initialdir] \
		      -initialfile "12x 455" -title Foo]}
    then {
	Click ok
    }
    return $x
} -result [file join [initialdir] "12x 455"]

test winDialog-5.12.4 {tk_getSaveFile: initial directory: unicode} -constraints {
    nt testwinevent
} -body {
    set dir [tcltest::makeDirectory "ŧéŝŧ"]
    unset -nocomplain x
    start {set x [tk_getSaveFile \
		      -initialdir $dir \
		      -initialfile "testfile" -title Foo]}
    then {
	Click ok
    }
    string equal $x [file join $dir testfile]
} -result 1

test winDialog-5.12.5 {tk_getSaveFile: initial directory: nativename} -constraints {
    nt testwinevent
} -body {
    unset -nocomplain x
    start {set x [tk_getSaveFile \
		      -initialdir [file nativename [initialdir]] \
		      -initialfile "5 12 5" -title Foo]}
    then {
	Click ok
    }
    return $x
} -result [file join [initialdir] "5 12 5"]

test winDialog-5.12.6 {tk_getSaveFile: initial directory: relative} -constraints {
    nt testwinevent
} -body {
    # Windows remembers dirs from previous selections so use
    # a subdir for this test, not [initialdir] itself
    set dir [tcltest::makeDirectory "5 12 6"]
    set cur [pwd]
    try {
	cd [file dirname $dir]
	unset -nocomplain x
	start {set x [tk_getSaveFile \
			  -initialdir "5 12 6" \
			  -initialfile "testfile" -title Foo]}
	then {
	    Click ok
	}
    } finally {
	cd $cur
    }
    string equal $x [file join $dir testfile]
} -result 1

test winDialog-5.12.8 {tk_getOpenFile: initial directory: .} -constraints {
    nt testwinevent
} -body {
    # Windows remembers dirs from previous selections so use
    # a subdir for this test, not [initialdir] itself
    set newdir [tcltest::makeDirectory "5 12 8"]
    set path [tcltest::makeFile "" "testfile" $newdir]
    set cur [pwd]
    try {
	cd $newdir
	unset -nocomplain x
	start {set x [tk_getOpenFile \
			  -initialdir . \
			  -initialfile "testfile" -title Foo]}
	then {
	    Click ok
	}
    } finally {
	cd $cur
    }
    string equal $x $path
} -result 1

test winDialog-5.12.9 {tk_getOpenFile: initial directory: unicode} -constraints {
    nt testwinevent
} -body {
    set dir [tcltest::makeDirectory "ŧéŝŧ"]
    set path [tcltest::makeFile "" testfile $dir]
    unset -nocomplain x
    start {set x [tk_getOpenFile \
		      -initialdir $dir \
		      -initialfile "testfile" -title Foo]}
    then {
	Click ok
    }
    string equal $x $path
} -result 1

test winDialog-5.12.10 {tk_getOpenFile: initial directory: nativename} -constraints {
    nt testwinevent
} -body {
    unset -nocomplain x
    tcltest::makeFile "" "5 12 10" [initialdir]
    start {set x [tk_getOpenFile \
		      -initialdir [file nativename [initialdir]] \
		      -initialfile "5 12 10" -title Foo]}
    then {
	Click ok
    }
    return $x
} -result [file join [initialdir] "5 12 10"]

test winDialog-5.12.11 {tk_getOpenFile: initial directory: relative} -constraints {
    nt testwinevent
} -body {
    # Windows remembers dirs from previous selections so use
    # a subdir for this test, not [initialdir] itself
    set dir [tcltest::makeDirectory "5 12 11"]
    set path [tcltest::makeFile "" testfile $dir]
    set cur [pwd]
    try {
	cd [file dirname $dir]
	unset -nocomplain x
	start {set x [tk_getOpenFile \
			  -initialdir [file tail $dir] \
			  -initialfile "testfile" -title Foo]}
	then {
	    Click ok
	}
    } finally {
	cd $cur
    }
    string equal $x $path
} -result 1

test winDialog-5.13 {GetFileName: initial file} -constraints {
    nt testwinevent
} -body {
#        case FILE_INITFILE:

    start {set x [tk_getSaveFile -initialfile "12x 456" -title Foo]}
    then {
	Click ok
    }
    file tail $x
} -result "12x 456"

test winDialog-5.16 {GetFileName: parent} -constraints {
    nt
} -body {
#        case FILE_PARENT:

    toplevel .t
    set x 0
    start {tk_getOpenFile -parent .t -title Parent; set x 1}
    then {
	destroy .t
    }
    return $x
} -result 1
test winDialog-5.17 {GetFileName: title} -constraints {
    nt testwinevent
} -body {
#        case FILE_TITLE:

    start {tk_getOpenFile -title Narf}
    then {
	Click cancel
    }
} -result 0
# In the newer file dialogs, the file type widget does not even exist
# if no file types specified
test winDialog-5.18 {GetFileName: no filter specified} -constraints {
	nt testwinevent
} -body {
    #    if (ofn.lpstrFilter == NULL)
    start {tk_getOpenFile -title Filter}
    then {
	catch {set x [GetText 0x470]} y
	Click cancel
    }
    return $y
} -result {Could not find control with id 1136}

test winDialog-5.19 {GetFileName: parent HWND doesn't yet exist} -constraints {
    nt
} -setup {
    destroy .t
} -body {
#    if (Tk_WindowId(parent) == None)

    toplevel .t
    start {tk_getOpenFile -parent .t -title Open}
    then {
	destroy .t
    }
} -result {}
test winDialog-5.20 {GetFileName: parent HWND already exists} -constraints {
    nt
} -setup {
    destroy .t
} -body {
    toplevel .t
    update
    start {tk_getOpenFile -parent .t -title Open}
    then {
	destroy .t
    }
} -result {}
test winDialog-5.21 {GetFileName: call GetOpenFileName} -constraints {
    nt testwinevent english
} -body {
#        winCode = GetOpenFileName(&ofn);

    start {tk_getOpenFile -title Open}
    then {
	set x [GetText ok]
	Click cancel
    }
    return $x
} -result {&Open}
test winDialog-5.22 {GetFileName: call GetSaveFileName} -constraints {
    nt testwinevent english
} -body {
#        winCode = GetSaveFileName(&ofn);

    start {tk_getSaveFile -title Save}
    then {
	set x [GetText ok]
	Click cancel
    }
    return $x
} -result {&Save}
test winDialog-5.23 {GetFileName: convert \ to /} -constraints {
    nt testwinevent
} -body {
    set msg {}
    start {set x [tk_getSaveFile -title Back]}
    then {
	if {[catch {SetText 0x3e9 [file nativename \
		[file join [initialdir] "12x 457"]]} msg]} {
	    Click cancel
	} else {
	    Click ok
	}
    }
    return $x$msg
} -cleanup {
    unset msg
} -result [file join [initialdir] "12x 457"]
test winDialog-5.24 {GetFileName: file types: MakeFilter() succeeds} -constraints {
    nt
} -body {
    # MacOS type that is correct, but has embedded nulls.

    start {set x [catch {tk_getSaveFile -filetypes {{"foo" .foo {\0\0\0\0}}}}]}
    then {
	Click cancel
    }
    return $x
} -result 0
test winDialog-5.25 {GetFileName: file types: MakeFilter() succeeds} -constraints {
    nt
} -body {
    # MacOS type that is correct, but has embedded high-bit chars.

    start {set x [catch {tk_getSaveFile -filetypes {{"foo" .foo {••••}}}}]}
    then {
	Click cancel
    }
    return $x
} -result 0


test winDialog-6.1 {MakeFilter} -constraints {emptyTest nt} -body {}







>
>
>
>










<
<
<
<
<
<
<
|
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<

>




|
|



>




|



>
|
<
<
<
<







|
|






|
|







|
|










|
|

|












|



|

|











|

|

|




















|
|










|
|









|
|











|
|











|
|
















|

|














|

|














|

|














|

|
















|

|
















|

|
















|

|















|
|

|

|



|





|
|

|

|



|




|

|











|

<
|
<
>
|
|
|
>
>
|
>
>
>
>


|
|












|
|

|



|






|


|









|
|

|



|





|





|


|












|






|


|














|


|









|
|
|

|



|





|






|


|













|
|




>







|
|









|
|






|


|
|





<








|
|










|
|








|
|










|
|









|
|

|








|





|
|









|
|







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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385

386

387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594

595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
# Copyright © 1998-1999 ActiveState Corporation.

package require tcltest 2.2
namespace import ::tcltest::*
tcltest::configure {*}$argv
tcltest::loadTestedCommands

# Import utility procs for specific functional areas
testutils import dialog
set applyFontCmd [list set testDialogFont]

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

# Locale identifier LANG_ENGLISH is 0x09
testConstraint english [expr {
    [llength [info commands testwinlocale]]
    && (([testwinlocale] & 0xff) == 9)
}]








set initialDir [tcltest::temporaryDirectory]






































proc Click {button} {
    variable testDialog
    switch -exact -- $button {
	ok     { set button 1 }
	cancel { set button 2 }
    }
    testwinevent $testDialog $button WM_LBUTTONDOWN 1 0x000a000b
    testwinevent $testDialog $button WM_LBUTTONUP 0 0x000a000b
}

proc GetText {id} {
    variable testDialog
    switch -exact -- $id {
	ok     { set id 1 }
	cancel { set id 2 }
    }
    return [testwinevent $testDialog $id WM_GETTEXT]
}

proc SetText {id text} {
    variable testDialog
    return [testwinevent $testDialog $id WM_SETTEXT $text]




}

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

test winDialog-1.1 {Tk_ChooseColorObjCmd} -constraints {
    testwinevent
} -body {
    testDialog launch {tk_chooseColor}
    testDialog onDisplay {
	Click cancel
    }
} -result 0
test winDialog-1.2 {Tk_ChooseColorObjCmd} -constraints {
    testwinevent
} -body {
    testDialog launch {set clr [tk_chooseColor -initialcolor "#ff9933"]}
    testDialog onDisplay {
	set x [Click cancel]
    }
    list $x $clr
} -result {0 {}}
test winDialog-1.3 {Tk_ChooseColorObjCmd} -constraints {
    testwinevent
} -body {
    testDialog launch {set clr [tk_chooseColor -initialcolor "#ff9933"]}
    testDialog onDisplay {
	set x [Click ok]
    }
    list $x $clr
} -result [list 0 "#ff9933"]
test winDialog-1.4 {Tk_ChooseColorObjCmd: -title} -constraints {
    testwinevent
} -setup {
    catch {unset a x}
} -body {
    set x {}
    testDialog launch {set clr [tk_chooseColor -initialcolor "#ff9933" -title "Hello"]}
    testDialog onDisplay {
	if {[catch {
	    array set a [testgetwindowinfo $testDialog]
	    if {[info exists a(text)]} {lappend x $a(text)}
	} err]} { lappend x $err }
	lappend x [Click ok]
    }
    lappend x $clr
} -result [list Hello 0 "#ff9933"]
test winDialog-1.5 {Tk_ChooseColorObjCmd: -title} -constraints {
    testwinevent
} -setup {
    catch {unset a x}
} -body {
    set x {}
    testDialog launch {
	set clr [tk_chooseColor -initialcolor "#ff9933" \
		     -title "Привет"]
    }
    testDialog onDisplay {
	if {[catch {
	    array set a [testgetwindowinfo $testDialog]
	    if {[info exists a(text)]} {lappend x $a(text)}
	} err]} { lappend x $err }
	lappend x [Click ok]
    }
    lappend x $clr
} -result [list "Привет" 0 "#ff9933"]
test winDialog-1.6 {Tk_ChooseColorObjCmd: -parent} -constraints {
    testwinevent
} -setup {
    catch {unset a x}
} -body {
    testDialog launch {set clr [tk_chooseColor -initialcolor "#ff9933" -parent .]}
    set x {}
    testDialog onDisplay {
	if {[catch {
	    array set a [testgetwindowinfo $testDialog]
	    if {[info exists a(parent)]} {
		append x [expr {$a(parent) == [wm frame .]}]
	    }
	} err]} {lappend x $err}
	Click ok
    }
    list $x $clr
} -result [list 1 "#ff9933"]
test winDialog-1.7 {Tk_ChooseColorObjCmd: -parent} -constraints {
    testwinevent
} -body {
    tk_chooseColor -initialcolor "#ff9933" -parent .xyzzy12
} -returnCodes error -match glob -result {bad window path name*}


test winDialog-2.1 {ColorDlgHookProc} -constraints {emptyTest nt} -body {}

test winDialog-3.1 {Tk_GetOpenFileObjCmd} -constraints {
    nt testwinevent english
} -body {
    testDialog launch {tk_getOpenFile}
    testDialog onDisplay {
	set x [GetText cancel]
	Click cancel
    }
    return $x
} -result {Cancel}


test winDialog-4.1 {Tk_GetSaveFileObjCmd} -constraints {
    nt testwinevent english
} -body {
    testDialog launch {tk_getSaveFile}
    testDialog onDisplay {
	set x [GetText cancel]
	Click cancel
    }
    return $x
} -result {Cancel}

test winDialog-5.1 {GetFileName: no arguments} -constraints {
    nt testwinevent
} -body {
    testDialog launch {tk_getOpenFile -title Open}
    testDialog onDisplay {
	Click cancel
    }
} -result 0
test winDialog-5.2 {GetFileName: one argument} -constraints {
    nt
} -body {
    tk_getOpenFile -foo
} -returnCodes error -result {bad option "-foo": must be -defaultextension, -filetypes, -initialdir, -initialfile, -multiple, -parent, -title, or -typevariable}
test winDialog-5.3 {GetFileName: many arguments} -constraints {
    nt testwinevent
} -body {
    testDialog launch {tk_getOpenFile -initialdir $initialDir -parent . -title test -initialfile foo}
    testDialog onDisplay {
	Click cancel
    }
} -result 0
test winDialog-5.4 {GetFileName: Tcl_GetIndexFromObj() != TCL_OK} -constraints {
    nt
} -body {
    tk_getOpenFile -foo bar -abc
} -returnCodes error -result {bad option "-foo": must be -defaultextension, -filetypes, -initialdir, -initialfile, -multiple, -parent, -title, or -typevariable}
test winDialog-5.5 {GetFileName: Tcl_GetIndexFromObj() == TCL_OK} -constraints {
    nt testwinevent
} -body {
    testDialog launch {set x [tk_getOpenFile -title bar]}
    set y [testDialog onDisplay {
	Click cancel
    }]
    # Note this also tests fix for
    # https://core.tcl-lang.org/tk/tktview/4a0451f5291b3c9168cc560747dae9264e1d2ef6
    # $x is expected to be empty
    append x $y
} -result 0
test winDialog-5.6 {GetFileName: valid option, but missing value} -constraints {
    nt
} -body {
    tk_getOpenFile -initialdir bar -title
} -returnCodes error -result {value for "-title" missing}

test winDialog-5.7 {GetFileName: extension begins with .} -constraints {
    nt testwinevent
} -body {
    testDialog launch {set x [tk_getSaveFile -defaultextension .foo -title Save]}
    set msg {}
    testDialog onDisplay {
	if {[catch {SetText 0x3e9 bar} msg]} {
	    Click cancel
	} else {
	    Click ok
	}
    }
    set x "[file tail $x]$msg"
} -cleanup {
    unset msg
} -result bar.foo

test winDialog-5.7.1 {GetFileName: extension {} } -constraints {
    nt testwinevent
} -body {
    testDialog launch {set x [tk_getSaveFile -defaultextension {} -title Save]}
    set msg {}
    testDialog onDisplay {
	if {[catch {SetText 0x3e9 bar} msg]} {
	    Click cancel
	} else {
	    Click ok
	}
    }
    set x "[file tail $x]$msg"
} -cleanup {
    unset msg
} -result bar

test winDialog-5.7.2 {GetFileName: extension {} Bug 47af31bd3ac6fbbb33cde1a5bab1e756ff2a6e00 } -constraints {
    nt testwinevent
} -body {
    testDialog launch {set x [tk_getSaveFile -filetypes {{All *}} -defaultextension {} -title Save]}
    set msg {}
    testDialog onDisplay {
	if {[catch {SetText 0x3e9 bar} msg]} {
	    Click cancel
	} else {
	    Click ok
	}
    }
    set x "[file tail $x]$msg"
} -cleanup {
    unset msg
} -result bar

test winDialog-5.7.3 {GetFileName: extension {} Bug 47af31bd3ac6fbbb33cde1a5bab1e756ff2a6e00 } -constraints {
    nt testwinevent
} -body {
    testDialog launch {set x [tk_getSaveFile -filetypes {{All *}} -defaultextension {} -title Save]}
    set msg {}
    testDialog onDisplay {
	if {[catch {SetText 0x3e9 bar.c} msg]} {
	    Click cancel
	} else {
	    Click ok
	}
    }
    set x "[file tail $x]$msg"
} -cleanup {
    unset msg
} -result bar.c

test winDialog-5.7.4 {GetFileName: extension {} } -constraints {
    nt testwinevent
} -body {
    # Although the docs do not explicitly mention, -filetypes seems to
    # override -defaultextension
    testDialog launch {set x [tk_getSaveFile -filetypes {{C .c} {Tcl .tcl}} -defaultextension {foo} -title Save]}
    set msg {}
    testDialog onDisplay {
	if {[catch {SetText 0x3e9 bar} msg]} {
	    Click cancel
	} else {
	    Click ok
	}
    }
    set x "[file tail $x]$msg"
} -cleanup {
    unset msg
} -result bar.c

test winDialog-5.7.5 {GetFileName: extension {} } -constraints {
    nt testwinevent
} -body {
    # Although the docs do not explicitly mention, -filetypes seems to
    # override -defaultextension
    testDialog launch {set x [tk_getSaveFile -filetypes {{C .c} {Tcl .tcl}} -defaultextension {} -title Save]}
    set msg {}
    testDialog onDisplay {
	if {[catch {SetText 0x3e9 bar} msg]} {
	    Click cancel
	} else {
	    Click ok
	}
    }
    set x "[file tail $x]$msg"
} -cleanup {
    unset msg
} -result bar.c


test winDialog-5.7.6 {GetFileName: All/extension } -constraints {
    nt testwinevent
} -body {
    # In 8.6.4 this combination resulted in bar.aaa.aaa which is bad
    testDialog launch {set x [tk_getSaveFile -filetypes {{All *}} -defaultextension {aaa} -title Save]}
    set msg {}
    testDialog onDisplay {
	if {[catch {SetText 0x3e9 bar} msg]} {
	    Click cancel
	} else {
	    Click ok
	}
    }
    set x "[file tail $x]$msg"
} -cleanup {
    unset msg
} -result bar.aaa

test winDialog-5.7.7 {tk_getOpenFile: -defaultextension} -constraints {
    nt testwinevent
} -body {
    unset -nocomplain x
    tcltest::makeFile "" "5 7 7.aaa" $initialDir
    testDialog launch {set x [tk_getOpenFile \
		      -defaultextension aaa \
		      -initialdir [file nativename $initialDir] \
		      -initialfile "5 7 7" -title Foo]}
    testDialog onDisplay {
	Click ok
    }
    return $x
} -result [file join $initialDir "5 7 7.aaa"]

test winDialog-5.7.8 {tk_getOpenFile: -defaultextension} -constraints {
    nt testwinevent
} -body {
    unset -nocomplain x
    tcltest::makeFile "" "5 7 8.aaa" $initialDir
    testDialog launch {set x [tk_getOpenFile \
		      -defaultextension aaa \
		      -initialdir [file nativename $initialDir] \
		      -initialfile "5 7 8.aaa" -title Foo]}
    testDialog onDisplay {
	Click ok
    }
    return $x
} -result [file join $initialDir "5 7 8.aaa"]

test winDialog-5.8 {GetFileName: extension doesn't begin with .} -constraints {
    nt testwinevent
} -body {
    testDialog launch {set x [tk_getSaveFile -defaultextension foo -title Save]}
    set msg {}
    testDialog onDisplay {
	if {[catch {SetText 0x3e9 bar} msg]} {
	    Click cancel
	} else {
	    Click ok
	}
    }
    set x "[file tail $x]$msg"
} -cleanup {
    unset msg
} -result bar.foo
test winDialog-5.9 {GetFileName: file types} -constraints {
    nt testwinevent knownBug
} -body {

    #

    # This test was used with MS Windows versions before Windows Vista.
    # Starting from that version, the test is not valid anymore because the
    # dialog's file types control has no control ID and we don't have a
    # mechanism to locate it.
    # The test remains at this place, with constraint knownBug, to serve as an
    # example/template in the event that the situation changes in the future
    # somehow.
    #
    testDialog launch {tk_getSaveFile -filetypes {{"foo files" .foo FOOF}} -title Foo}
    testDialog onDisplay {
	set x [GetText 0x470]
	Click cancel
    }
    return $x
} -result {foo files (*.foo)}
test winDialog-5.10 {GetFileName: file types: MakeFilter() fails} -constraints {
    nt
} -body {
#        if (MakeFilter(interp, string, &utfFilterString) != TCL_OK)

    tk_getSaveFile -filetypes {{"foo" .foo FOO}}
} -returnCodes error -result {bad Macintosh file type "FOO"}
test winDialog-5.11 {GetFileName: initial directory} -constraints {
    nt testwinevent
} -body {
#        case FILE_INITDIR:
    unset -nocomplain x
    testDialog launch {set x [tk_getSaveFile \
		      -initialdir $initialDir \
		      -initialfile "12x 455" -title Foo]}
    testDialog onDisplay {
	Click ok
    }
    return $x
} -result [file join $initialDir "12x 455"]

test winDialog-5.12.4 {tk_getSaveFile: initial directory: unicode} -constraints {
    nt testwinevent
} -body {
    set dir [tcltest::makeDirectory "ŧéŝŧ"]
    unset -nocomplain x
    testDialog launch {set x [tk_getSaveFile \
		      -initialdir $dir \
		      -initialfile "testfile" -title Foo]}
    testDialog onDisplay {
	Click ok
    }
    string equal $x [file join $dir testfile]
} -result 1

test winDialog-5.12.5 {tk_getSaveFile: initial directory: nativename} -constraints {
    nt testwinevent
} -body {
    unset -nocomplain x
    testDialog launch {set x [tk_getSaveFile \
		      -initialdir [file nativename $initialDir] \
		      -initialfile "5 12 5" -title Foo]}
    testDialog onDisplay {
	Click ok
    }
    return $x
} -result [file join $initialDir "5 12 5"]

test winDialog-5.12.6 {tk_getSaveFile: initial directory: relative} -constraints {
    nt testwinevent
} -body {
    # Windows remembers dirs from previous selections so use
    # a subdir for this test, not $initialDir itself
    set dir [tcltest::makeDirectory "5 12 6"]
    set cur [pwd]
    try {
	cd [file dirname $dir]
	unset -nocomplain x
	testDialog launch {set x [tk_getSaveFile \
			  -initialdir "5 12 6" \
			  -initialfile "testfile" -title Foo]}
	testDialog onDisplay {
	    Click ok
	}
    } finally {
	cd $cur
    }
    string equal $x [file join $dir testfile]
} -result 1

test winDialog-5.12.8 {tk_getOpenFile: initial directory: .} -constraints {
    nt testwinevent
} -body {
    # Windows remembers dirs from previous selections so use
    # a subdir for this test, not $initialDir itself
    set newdir [tcltest::makeDirectory "5 12 8"]
    set path [tcltest::makeFile "" "testfile" $newdir]
    set cur [pwd]
    try {
	cd $newdir
	unset -nocomplain x
	testDialog launch {set x [tk_getOpenFile \
			  -initialdir . \
			  -initialfile "testfile" -title Foo]}
	testDialog onDisplay {
	    Click ok
	}
    } finally {
	cd $cur
    }
    string equal $x $path
} -result 1

test winDialog-5.12.9 {tk_getOpenFile: initial directory: unicode} -constraints {
    nt testwinevent
} -body {
    set dir [tcltest::makeDirectory "ŧéŝŧ"]
    set path [tcltest::makeFile "" testfile $dir]
    unset -nocomplain x
    testDialog launch {set x [tk_getOpenFile \
		      -initialdir $dir \
		      -initialfile "testfile" -title Foo]}
    testDialog onDisplay {
	Click ok
    }
    string equal $x $path
} -result 1

test winDialog-5.12.10 {tk_getOpenFile: initial directory: nativename} -constraints {
    nt testwinevent
} -body {
    unset -nocomplain x
    tcltest::makeFile "" "5 12 10" $initialDir
    testDialog launch {set x [tk_getOpenFile \
		      -initialdir [file nativename $initialDir] \
		      -initialfile "5 12 10" -title Foo]}
    testDialog onDisplay {
	Click ok
    }
    return $x
} -result [file join $initialDir "5 12 10"]

test winDialog-5.12.11 {tk_getOpenFile: initial directory: relative} -constraints {
    nt testwinevent
} -body {
    # Windows remembers dirs from previous selections so use
    # a subdir for this test, not $initialDir itself
    set dir [tcltest::makeDirectory "5 12 11"]
    set path [tcltest::makeFile "" testfile $dir]
    set cur [pwd]
    try {
	cd [file dirname $dir]
	unset -nocomplain x
	testDialog launch {set x [tk_getOpenFile \
			  -initialdir [file tail $dir] \
			  -initialfile "testfile" -title Foo]}
	testDialog onDisplay {
	    Click ok
	}
    } finally {
	cd $cur
    }
    string equal $x $path
} -result 1

test winDialog-5.13 {GetFileName: initial file} -constraints {
    nt testwinevent
} -body {
#        case FILE_INITFILE:

    testDialog launch {set x [tk_getSaveFile -initialfile "12x 456" -title Foo]}
    testDialog onDisplay {
	Click ok
    }
    file tail $x
} -result "12x 456"

test winDialog-5.16 {GetFileName: parent} -constraints {
    nt
} -body {
#        case FILE_PARENT:

    toplevel .t
    set x 0
    testDialog launch {tk_getOpenFile -parent .t -title Parent; set x 1}
    testDialog onDisplay {
	destroy .t
    }
    return $x
} -result 1
test winDialog-5.17 {GetFileName: title} -constraints {
    nt testwinevent
} -body {
#        case FILE_TITLE:

    testDialog launch {tk_getOpenFile -title Narf}
    testDialog onDisplay {
	Click cancel
    }
} -result 0
# In the newer file dialogs, the file type widget does not even exist
# if no file types specified
test winDialog-5.18 {GetFileName: no filter specified} -constraints {
    nt testwinevent
} -body {
    #    if (ofn.lpstrFilter == NULL)
    testDialog launch {tk_getOpenFile -title Filter}
    testDialog onDisplay {
	catch {set x [GetText 0x470]} y
	Click cancel
    }
    return $y
} -result {Could not find control with id 1136}

test winDialog-5.19 {GetFileName: parent HWND doesn't yet exist} -constraints {
    nt
} -setup {
    destroy .t
} -body {
#    if (Tk_WindowId(parent) == None)

    toplevel .t
    testDialog launch {tk_getOpenFile -parent .t -title Open}
    testDialog onDisplay {
	destroy .t
    }
} -result {}
test winDialog-5.20 {GetFileName: parent HWND already exists} -constraints {
    nt
} -setup {
    destroy .t
} -body {
    toplevel .t
    update
    testDialog launch {tk_getOpenFile -parent .t -title Open}
    testDialog onDisplay {
	destroy .t
    }
} -result {}
test winDialog-5.21 {GetFileName: call GetOpenFileName} -constraints {
    nt testwinevent english
} -body {
#        winCode = GetOpenFileName(&ofn);

    testDialog launch {tk_getOpenFile -title Open}
    testDialog onDisplay {
	set x [GetText ok]
	Click cancel
    }
    return $x
} -result {&Open}
test winDialog-5.22 {GetFileName: call GetSaveFileName} -constraints {
    nt testwinevent english
} -body {
#        winCode = GetSaveFileName(&ofn);

    testDialog launch {tk_getSaveFile -title Save}
    testDialog onDisplay {
	set x [GetText ok]
	Click cancel
    }
    return $x
} -result {&Save}
test winDialog-5.23 {GetFileName: convert \ to /} -constraints {
    nt testwinevent
} -body {
    set msg {}
    testDialog launch {set x [tk_getSaveFile -title Back]}
    testDialog onDisplay {
	if {[catch {SetText 0x3e9 [file nativename \
		[file join $initialDir "12x 457"]]} msg]} {
	    Click cancel
	} else {
	    Click ok
	}
    }
    return $x$msg
} -cleanup {
    unset msg
} -result [file join $initialDir "12x 457"]
test winDialog-5.24 {GetFileName: file types: MakeFilter() succeeds} -constraints {
    nt
} -body {
    # MacOS type that is correct, but has embedded nulls.

    testDialog launch {set x [catch {tk_getSaveFile -filetypes {{"foo" .foo {\0\0\0\0}}}}]}
    testDialog onDisplay {
	Click cancel
    }
    return $x
} -result 0
test winDialog-5.25 {GetFileName: file types: MakeFilter() succeeds} -constraints {
    nt
} -body {
    # MacOS type that is correct, but has embedded high-bit chars.

    testDialog launch {set x [catch {tk_getSaveFile -filetypes {{"foo" .foo {••••}}}}]}
    testDialog onDisplay {
	Click cancel
    }
    return $x
} -result 0


test winDialog-6.1 {MakeFilter} -constraints {emptyTest nt} -body {}
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904



905


906
907
908
909
910
911
912
## The Tk_ChooseDirectoryObjCmd hang on the static build of Windows
## because somehow the GetOpenFileName ends up a noop in the static
## build.
##
test winDialog-9.1 {Tk_ChooseDirectoryObjCmd: no arguments} -constraints {
    nt testwinevent
} -body {
    start {set x [tk_chooseDirectory]}
    set y [then {
	Click cancel
    }]
    # $x should be "" on a Cancel
    append x $y
} -result 0
test winDialog-9.2 {Tk_ChooseDirectoryObjCmd: one argument} -constraints {
    nt
} -body {
    tk_chooseDirectory -foo
} -returnCodes error -result {bad option "-foo": must be -initialdir, -mustexist, -parent, or -title}
test winDialog-9.3 {Tk_ChooseDirectoryObjCmd: many arguments} -constraints {
    nt testwinevent
} -body {
    start {
	tk_chooseDirectory -initialdir [initialdir] -mustexist 1 -parent . -title test
    }
    then {
	Click cancel
    }
} -result 0
test winDialog-9.4 {Tk_ChooseDirectoryObjCmd: Tcl_GetIndexFromObj() != TCL_OK} -constraints {
    nt
} -body {
    tk_chooseDirectory -foo bar -abc
} -returnCodes error -result {bad option "-foo": must be -initialdir, -mustexist, -parent, or -title}
test winDialog-9.5 {Tk_ChooseDirectoryObjCmd: Tcl_GetIndexFromObj() == TCL_OK} -constraints {
    nt testwinevent
} -body {
    start {tk_chooseDirectory -title bar}
    then {
	Click cancel
    }
} -result 0
test winDialog-9.6 {Tk_ChooseDirectoryObjCmd: valid option, but missing value} -constraints {
    nt
} -body {
    tk_chooseDirectory -initialdir bar -title
} -returnCodes error -result {value for "-title" missing}
test winDialog-9.7 {Tk_ChooseDirectoryObjCmd: -initialdir} -constraints {
    nt testwinevent
} -body {
#        case DIR_INITIAL:

    start {set x [tk_chooseDirectory -initialdir [initialdir] -title Foo]}
    then {
	Click ok
    }
    string tolower [set x]
} -result [string tolower [initialdir]]


test winDialog-10.1 {Tk_FontchooserObjCmd: no arguments} -constraints {
    nt testwinevent
} -body {
    start {tk fontchooser show}
    list [then {
	Click cancel
    }] $::testfont
} -result {0 {}}
test winDialog-10.2 {Tk_FontchooserObjCmd: -initialfont} -constraints {
    nt testwinevent
} -body {
    start {
	tk fontchooser configure -command ApplyFont -font system
	tk fontchooser show
    }
    list [then {
	Click cancel
    }] $::testfont
} -result {0 {}}
test winDialog-10.3 {Tk_FontchooserObjCmd: -initialfont} -constraints {
    nt testwinevent
} -body {
    start {
	tk fontchooser configure -command ApplyFont -font system
	tk fontchooser show
    }
    list [then {
	Click 1
    }] [expr {[llength $::testfont] ne {}}]
} -result {0 1}
test winDialog-10.4 {Tk_FontchooserObjCmd: -title} -constraints {
    nt testwinevent
} -body {
    start {
	tk fontchooser configure -command ApplyFont -title "tk test"
	tk fontchooser show
    }
    list [then {
	Click cancel
    }] $::testfont
} -result {0 {}}
test winDialog-10.5 {Tk_FontchooserObjCmd: -parent} -constraints {
    nt testwinevent
} -setup {
    array set a {parent {}}
} -body {
    start {
	tk fontchooser configure -command ApplyFont -parent .
	tk fontchooser show
    }
    then {
	array set a [testgetwindowinfo $::tk_dialog]
	Click cancel
    }
    list [expr {$a(parent) == [wm frame .]}] $::testfont
} -result {1 {}}
test winDialog-10.6 {Tk_FontchooserObjCmd: -apply} -constraints {
    nt testwinevent
} -body {
    start {
	tk fontchooser configure -command FooBarBaz
	tk fontchooser show
    }
    then {
	Click cancel
    }
} -result 0
test winDialog-10.7 {Tk_FontchooserObjCmd: -apply} -constraints {
    nt testwinevent
} -body {
    start {
	tk fontchooser configure -command ApplyFont -parent .
	tk fontchooser show
    }
    list [then {
	Click [expr {0x0402}] ;# value from XP
	Click cancel
    }] [expr {[llength $::testfont] > 0}]
} -result {0 1}
test winDialog-10.8 {Tk_FontchooserObjCmd: -title} -constraints {
    nt testwinevent
} -setup {
    array set a {text failed}
} -body {
    start {
	tk fontchooser configure -command ApplyFont -title "Hello"
	tk fontchooser show
    }
    then {
	array set a [testgetwindowinfo $::tk_dialog]
	Click cancel
    }
    set a(text)
} -result "Hello"
test winDialog-10.9 {Tk_FontchooserObjCmd: -title} -constraints {
    nt testwinevent
} -setup {
    array set a {text failed}
} -body {
    start {
	tk fontchooser configure -command ApplyFont \
	    -title  "Привет"
	tk fontchooser show
    }
    then {
	array set a [testgetwindowinfo $::tk_dialog]
	Click cancel
    }
    set a(text)
} -result "Привет"

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




# cleanup


cleanupTests
return

# Local variables:
# mode: tcl
# End:








|
|













|
|

|











|
|













|
|



|





|
|

|




|
|


|

|




|
|


|

|




|
|


|

|






|
|


|
|


|




|



|






|
|


|


|






|
|


|
|









|
|



|
|









>
>
>
|
>
>







694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
## The Tk_ChooseDirectoryObjCmd hang on the static build of Windows
## because somehow the GetOpenFileName ends up a noop in the static
## build.
##
test winDialog-9.1 {Tk_ChooseDirectoryObjCmd: no arguments} -constraints {
    nt testwinevent
} -body {
    testDialog launch {set x [tk_chooseDirectory]}
    set y [testDialog onDisplay {
	Click cancel
    }]
    # $x should be "" on a Cancel
    append x $y
} -result 0
test winDialog-9.2 {Tk_ChooseDirectoryObjCmd: one argument} -constraints {
    nt
} -body {
    tk_chooseDirectory -foo
} -returnCodes error -result {bad option "-foo": must be -initialdir, -mustexist, -parent, or -title}
test winDialog-9.3 {Tk_ChooseDirectoryObjCmd: many arguments} -constraints {
    nt testwinevent
} -body {
    testDialog launch {
	tk_chooseDirectory -initialdir $initialDir -mustexist 1 -parent . -title test
    }
    testDialog onDisplay {
	Click cancel
    }
} -result 0
test winDialog-9.4 {Tk_ChooseDirectoryObjCmd: Tcl_GetIndexFromObj() != TCL_OK} -constraints {
    nt
} -body {
    tk_chooseDirectory -foo bar -abc
} -returnCodes error -result {bad option "-foo": must be -initialdir, -mustexist, -parent, or -title}
test winDialog-9.5 {Tk_ChooseDirectoryObjCmd: Tcl_GetIndexFromObj() == TCL_OK} -constraints {
    nt testwinevent
} -body {
    testDialog launch {tk_chooseDirectory -title bar}
    testDialog onDisplay {
	Click cancel
    }
} -result 0
test winDialog-9.6 {Tk_ChooseDirectoryObjCmd: valid option, but missing value} -constraints {
    nt
} -body {
    tk_chooseDirectory -initialdir bar -title
} -returnCodes error -result {value for "-title" missing}
test winDialog-9.7 {Tk_ChooseDirectoryObjCmd: -initialdir} -constraints {
    nt testwinevent
} -body {
#        case DIR_INITIAL:

    testDialog launch {set x [tk_chooseDirectory -initialdir $initialDir -title Foo]}
    testDialog onDisplay {
	Click ok
    }
    string tolower [set x]
} -result [string tolower $initialDir]


test winDialog-10.1 {Tk_FontchooserObjCmd: no arguments} -constraints {
    nt testwinevent
} -body {
    testDialog launch {tk fontchooser show}
    list [testDialog onDisplay {
	Click cancel
    }] $testDialogFont
} -result {0 {}}
test winDialog-10.2 {Tk_FontchooserObjCmd: -initialfont} -constraints {
    nt testwinevent
} -body {
    testDialog launch {
	tk fontchooser configure -command $applyFontCmd -font system
	tk fontchooser show
    }
    list [testDialog onDisplay {
	Click cancel
    }] $testDialogFont
} -result {0 {}}
test winDialog-10.3 {Tk_FontchooserObjCmd: -initialfont} -constraints {
    nt testwinevent
} -body {
    testDialog launch {
	tk fontchooser configure -command $applyFontCmd -font system
	tk fontchooser show
    }
    list [testDialog onDisplay {
	Click 1
    }] [expr {[llength $testDialogFont] ne {}}]
} -result {0 1}
test winDialog-10.4 {Tk_FontchooserObjCmd: -title} -constraints {
    nt testwinevent
} -body {
    testDialog launch {
	tk fontchooser configure -command $applyFontCmd -title "tk test"
	tk fontchooser show
    }
    list [testDialog onDisplay {
	Click cancel
    }] $testDialogFont
} -result {0 {}}
test winDialog-10.5 {Tk_FontchooserObjCmd: -parent} -constraints {
    nt testwinevent
} -setup {
    array set a {parent {}}
} -body {
    testDialog launch {
	tk fontchooser configure -command $applyFontCmd -parent .
	tk fontchooser show
    }
    testDialog onDisplay {
	array set a [testgetwindowinfo $testDialog]
	Click cancel
    }
    list [expr {$a(parent) == [wm frame .]}] $testDialogFont
} -result {1 {}}
test winDialog-10.6 {Tk_FontchooserObjCmd: -apply} -constraints {
    nt testwinevent
} -body {
    testDialog launch {
	tk fontchooser configure -command FooBarBaz
	tk fontchooser show
    }
    testDialog onDisplay {
	Click cancel
    }
} -result 0
test winDialog-10.7 {Tk_FontchooserObjCmd: -apply} -constraints {
    nt testwinevent
} -body {
    testDialog launch {
	tk fontchooser configure -command $applyFontCmd -parent .
	tk fontchooser show
    }
    list [testDialog onDisplay {
	Click [expr {0x0402}] ;# value from XP
	Click cancel
    }] [expr {[llength $testDialogFont] > 0}]
} -result {0 1}
test winDialog-10.8 {Tk_FontchooserObjCmd: -title} -constraints {
    nt testwinevent
} -setup {
    array set a {text failed}
} -body {
    testDialog launch {
	tk fontchooser configure -command $applyFontCmd -title "Hello"
	tk fontchooser show
    }
    testDialog onDisplay {
	array set a [testgetwindowinfo $testDialog]
	Click cancel
    }
    set a(text)
} -result "Hello"
test winDialog-10.9 {Tk_FontchooserObjCmd: -title} -constraints {
    nt testwinevent
} -setup {
    array set a {text failed}
} -body {
    testDialog launch {
	tk fontchooser configure -command $applyFontCmd \
	    -title  "Привет"
	tk fontchooser show
    }
    testDialog onDisplay {
	array set a [testgetwindowinfo $testDialog]
	Click cancel
    }
    set a(text)
} -result "Привет"

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

#
# CLEANUP
#

unset applyFontCmd initialDir
testutils forget dialog
cleanupTests
return

# Local variables:
# mode: tcl
# End:

Changes to tests/winFont.test.
11
12
13
14
15
16
17


18
19
20
21
22
23
24
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
tcltest::configure {*}$argv
tcltest::loadTestedCommands




test winfont-1.1 {TkpGetNativeFont procedure: not native} -constraints {
    win
} -body {
    catch {font delete xyz}
    font measure {} xyz
} -returnCodes error -result {font "" does not exist}







>
>







11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
tcltest::configure {*}$argv
tcltest::loadTestedCommands

# Import utility procs for specific functional areas
testutils import geometry

test winfont-1.1 {TkpGetNativeFont procedure: not native} -constraints {
    win
} -body {
    catch {font delete xyz}
    font measure {} xyz
} -returnCodes error -result {font "" does not exist}
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
set cx [font measure $courier 0]
set t [.t.c create text 0 0 -anchor nw -just left -font $courier]
pack .t.c
update

set ax [winfo reqwidth .t.l]
set ay [winfo reqheight .t.l]
proc getsize {} {
    update
    return "[winfo reqwidth .t.l] [winfo reqheight .t.l]"
}

test winfont-5.1 {Tk_MeasureChars procedure: unbounded right margin} -constraints {
    win
} -setup {
    destroy .t.l
} -body {
    label .t.l -padx 0 -pady 0 -bd 0 -highlightthickness 0 -justify left \







<
<
<
<







123
124
125
126
127
128
129




130
131
132
133
134
135
136
set cx [font measure $courier 0]
set t [.t.c create text 0 0 -anchor nw -just left -font $courier]
pack .t.c
update

set ax [winfo reqwidth .t.l]
set ay [winfo reqheight .t.l]





test winfont-5.1 {Tk_MeasureChars procedure: unbounded right margin} -constraints {
    win
} -setup {
    destroy .t.l
} -body {
    label .t.l -padx 0 -pady 0 -bd 0 -highlightthickness 0 -justify left \
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
    pack .t.l
    update

    set font [.t.l cget -font]
    .t.l config -font {{MS Sans Serif} 8} -text "W"
    set width [winfo reqwidth .t.l]
    .t.l config -text "XaYoYaKaWx"
    set x [lindex [getsize] 0]
    .t.l config -font $font
    expr {$x < ($width*10)}
} -cleanup {
    destroy .t.l
} -result 1









|







326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
    pack .t.l
    update

    set font [.t.l cget -font]
    .t.l config -font {{MS Sans Serif} 8} -text "W"
    set width [winfo reqwidth .t.l]
    .t.l config -text "XaYoYaKaWx"
    set x [lindex [getsize .t.l] 0]
    .t.l config -font $font
    expr {$x < ($width*10)}
} -cleanup {
    destroy .t.l
} -result 1


378
379
380
381
382
383
384



385

386
387
388
389
390
391
392
} -result 0
test winfont-7.4 {InitFont procedure: extract info from textmetric} -constraints {
    win
} -body {
    font metric systemfixed -fixed
} -result 1




# cleanup

cleanupTests
return

# Local variables:
# mode: tcl
# End:








>
>
>
|
>






<
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393

} -result 0
test winfont-7.4 {InitFont procedure: extract info from textmetric} -constraints {
    win
} -body {
    font metric systemfixed -fixed
} -result 1

#
# CLEANUP
#

testutils forget geometry
cleanupTests
return

# Local variables:
# mode: tcl
# End:

Changes to tests/winSend.test.
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
# This file is a Tcl script to test out the "send" command and the
# other procedures in the file tkSend.c.  It is organized in the
# standard fashion for Tcl tests.
#
# Copyright © 1994 Sun Microsystems, Inc.
# Copyright © 1994-1996 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

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

# Compute a script that will load Tk into a child interpreter.

foreach pkg [info loaded] {
    if {[lindex $pkg 1] == "Tk"} {
	set loadTk "load $pkg"
	break
    }
}

# Procedure to create a new application with a given name and class.

proc newApp {name {safe {}}} {
    global loadTk
    if {[string compare $safe "-safe"] == 0} {
	interp create -safe $name
    } else {
	interp create $name
    }
    $name eval [list set argv [list -name $name]]
    catch {eval $loadTk $name}
}

set currentInterps [winfo interps]
if {
    [testConstraint win] &&
    [llength [info commands send]] &&
    [catch {exec [interpreter] &}] == 0
} then {













<
|
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<







1
2
3
4
5
6
7
8
9
10
11
12
13

14






15












16
17
18
19
20
21
22
# This file is a Tcl script to test out the "send" command and the
# other procedures in the file tkSend.c.  It is organized in the
# standard fashion for Tcl tests.
#
# Copyright © 1994 Sun Microsystems, Inc.
# Copyright © 1994-1996 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

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


# Import utility procs for specific functional areas






testutils import child













set currentInterps [winfo interps]
if {
    [testConstraint win] &&
    [llength [info commands send]] &&
    [catch {exec [interpreter] &}] == 0
} then {
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
} else {
    testConstraint winSend 0
}

# setting up dde server is done when the first interp is created and
# cannot be tested very easily.
test winSend-1.1 {Tk_SetAppName - changing name of interp} winSend {
    newApp testApp
    list [testApp eval tk appname testApp2] [interp delete testApp]
} {testApp2 {}}
test winSend-1.2 {Tk_SetAppName - changing name - not front of linked list} winSend {
    newApp testApp
    newApp testApp2
    list [testApp eval tk appname testApp3] [interp delete testApp] [interp delete testApp2]
} {testApp3 {} {}}
test winSend-1.3 {Tk_SetAppName - unique name - no conflicts} winSend {
    newApp testApp
    list [testApp eval tk appname testApp] [interp delete testApp]
} {testApp {}}
test winSend-1.4 {Tk_SetAppName - unique name - one conflict} winSend {
    newApp testApp
    newApp foobar
    list [foobar eval tk appname testApp] [interp delete foobar] [interp delete testApp]
} {{testApp #2} {} {}}
test winSend-1.5 {Tk_SetAppName - unique name - one conflict} winSend {
    newApp testApp
    newApp foobar
    newApp blaz
    foobar eval tk appname testApp
    list [blaz eval tk appname testApp] [interp delete foobar] [interp delete testApp] [interp delete blaz]
} {{testApp #3} {} {} {}}
test winSend-1.6 {Tk_SetAppName - safe interps} winSend {
    newApp testApp -safe
    list [catch {testApp eval send testApp {set foo a}} msg] $msg [interp delete testApp]
} {1 {invalid command name "send"} {}}

test winSend-2.1 {Tk_SendObjCmd - # of args} winSend {
    list [catch {send tktest} msg] $msg
} {1 {wrong # args: should be "send ?-option value ...? interpName arg ?arg ...?"}}
test winSend-2.1a {Tk_SendObjCmd: arguments} winSend {







|



|
|



|



|
|



|
|
|




|







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
} else {
    testConstraint winSend 0
}

# setting up dde server is done when the first interp is created and
# cannot be tested very easily.
test winSend-1.1 {Tk_SetAppName - changing name of interp} winSend {
    childTkInterp testApp
    list [testApp eval tk appname testApp2] [interp delete testApp]
} {testApp2 {}}
test winSend-1.2 {Tk_SetAppName - changing name - not front of linked list} winSend {
    childTkInterp testApp
    childTkInterp testApp2
    list [testApp eval tk appname testApp3] [interp delete testApp] [interp delete testApp2]
} {testApp3 {} {}}
test winSend-1.3 {Tk_SetAppName - unique name - no conflicts} winSend {
    childTkInterp testApp
    list [testApp eval tk appname testApp] [interp delete testApp]
} {testApp {}}
test winSend-1.4 {Tk_SetAppName - unique name - one conflict} winSend {
    childTkInterp testApp
    childTkInterp foobar
    list [foobar eval tk appname testApp] [interp delete foobar] [interp delete testApp]
} {{testApp #2} {} {}}
test winSend-1.5 {Tk_SetAppName - unique name - one conflict} winSend {
    childTkInterp testApp
    childTkInterp foobar
    childTkInterp blaz
    foobar eval tk appname testApp
    list [blaz eval tk appname testApp] [interp delete foobar] [interp delete testApp] [interp delete blaz]
} {{testApp #3} {} {} {}}
test winSend-1.6 {Tk_SetAppName - safe interps} winSend {
    childTkInterp testApp -safe
    list [catch {testApp eval send testApp {set foo a}} msg] $msg [interp delete testApp]
} {1 {invalid command name "send"} {}}

test winSend-2.1 {Tk_SendObjCmd - # of args} winSend {
    list [catch {send tktest} msg] $msg
} {1 {wrong # args: should be "send ?-option value ...? interpName arg ?arg ...?"}}
test winSend-2.1a {Tk_SendObjCmd: arguments} winSend {
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
test winSend-2.1d {Tk_SendObjCmd: arguments} winSend {
    list [catch {send -- -bogus foo} msg] $msg
} {1 {no registered server named "-bogus"}}
test winSend-2.2 {Tk_SendObjCmd - sending to ourselves} winSend {
    list [send [tk appname] {set foo a}]
} {a}
test winSend-2.3 {Tk_SendObjCmd - sending to ourselves in a different interpreter} winSend {
    newApp testApp
    list [catch {send testApp {set foo b}} msg] $msg [interp delete testApp]
} {0 b {}}
test winSend-2.4 {Tk_SendObjCmd - sending to ourselves in a different interp with errors} winSend {
    newApp testApp
    list [catch {send testApp {expr {2 / 0}}} msg] $msg $errorCode $errorInfo [interp delete testApp]
} "1 {divide by zero} {ARITH DIVZERO {divide by zero}} {divide by zero\n    while executing\n\"expr {2 / 0}\"\n    invoked from within\n\"send testApp {expr {2 / 0}}\"} {}"
test winSend-2.5 {Tk_SendObjCmd - sending to another app async} winSend {
    set newInterps [winfo interps]
    foreach interp $newInterps {
	if {[lsearch $currentInterps $interp] < 0} {
	    break







|



|







90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
test winSend-2.1d {Tk_SendObjCmd: arguments} winSend {
    list [catch {send -- -bogus foo} msg] $msg
} {1 {no registered server named "-bogus"}}
test winSend-2.2 {Tk_SendObjCmd - sending to ourselves} winSend {
    list [send [tk appname] {set foo a}]
} {a}
test winSend-2.3 {Tk_SendObjCmd - sending to ourselves in a different interpreter} winSend {
    childTkInterp testApp
    list [catch {send testApp {set foo b}} msg] $msg [interp delete testApp]
} {0 b {}}
test winSend-2.4 {Tk_SendObjCmd - sending to ourselves in a different interp with errors} winSend {
    childTkInterp testApp
    list [catch {send testApp {expr {2 / 0}}} msg] $msg $errorCode $errorInfo [interp delete testApp]
} "1 {divide by zero} {ARITH DIVZERO {divide by zero}} {divide by zero\n    while executing\n\"expr {2 / 0}\"\n    invoked from within\n\"send testApp {expr {2 / 0}}\"} {}"
test winSend-2.5 {Tk_SendObjCmd - sending to another app async} winSend {
    set newInterps [winfo interps]
    foreach interp $newInterps {
	if {[lsearch $currentInterps $interp] < 0} {
	    break
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
test winSend-3.1 {TkGetInterpNames} winSend {
    set origLength [llength $currentInterps]
    set newLength [llength [winfo interps]]
    expr {($newLength - 2) == $origLength}
} 1

test winSend-4.1 {DeleteProc - changing name of app} winSend {
    newApp a
    list [a eval tk appname foo] [interp delete a]
} {foo {}}
test winSend-4.2 {DeleteProc - normal} winSend {
    newApp a
    list [interp delete a]
} {{}}

test winSend-5.1 {ExecuteRemoteObject - no error} winSend {
    set newInterps [winfo interps]
    foreach interp $newInterps {
	if {[lsearch $currentInterps $interp] < 0} {







|



|







132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
test winSend-3.1 {TkGetInterpNames} winSend {
    set origLength [llength $currentInterps]
    set newLength [llength [winfo interps]]
    expr {($newLength - 2) == $origLength}
} 1

test winSend-4.1 {DeleteProc - changing name of app} winSend {
    childTkInterp a
    list [a eval tk appname foo] [interp delete a]
} {foo {}}
test winSend-4.2 {DeleteProc - normal} winSend {
    childTkInterp a
    list [interp delete a]
} {{}}

test winSend-5.1 {ExecuteRemoteObject - no error} winSend {
    set newInterps [winfo interps]
    foreach interp $newInterps {
	if {[lsearch $currentInterps $interp] < 0} {
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
	}
    }
    set command "dde services Tk {}"
    list [catch "send \{$interp\} \{$command\}"]
} 0

test winSend-7.1 {DDEExitProc} winSend {
    newApp testApp
    list [interp delete testApp]
} {{}}

test winSend-8.1 {SendDdeConnect} winSend {
    set newInterps [winfo interps]
    foreach interp $newInterps {
	if {[lsearch $currentInterps $interp] < 0} {







|







248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
	}
    }
    set command "dde services Tk {}"
    list [catch "send \{$interp\} \{$command\}"]
} 0

test winSend-7.1 {DDEExitProc} winSend {
    childTkInterp testApp
    list [interp delete testApp]
} {{}}

test winSend-8.1 {SendDdeConnect} winSend {
    set newInterps [winfo interps]
    foreach interp $newInterps {
	if {[lsearch $currentInterps $interp] < 0} {
398
399
400
401
402
403
404



405

406
407
	    catch {send $interp exit}
	    set newInterps [winfo interps]
	    break
	}
    }
}




# cleanup

cleanupTests
return







>
>
>
|
>


379
380
381
382
383
384
385
386
387
388
389
390
391
392
	    catch {send $interp exit}
	    set newInterps [winfo interps]
	    break
	}
    }
}

#
# CLEANUP
#

testutils forget child
cleanupTests
return
Changes to tests/winWm.test.
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
tcltest::configure {*}$argv
tcltest::loadTestedCommands

testConstraint failsOnUbuntu [expr {![info exists ::env(CI)] || ![string match Linux $::tcl_platform(os)]}]
testConstraint failsOnXQuarz [expr {$tcl_platform(os) ne "Darwin" || [tk windowingsystem] ne "x11" }]

test winWm-1.1 {TkWmMapWindow} -constraints win -setup {
    destroy .t
} -body {
    toplevel .t
    wm override .t 1
    wm geometry .t +0+0
    update







<
<
<







10
11
12
13
14
15
16



17
18
19
20
21
22
23
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
tcltest::configure {*}$argv
tcltest::loadTestedCommands




test winWm-1.1 {TkWmMapWindow} -constraints win -setup {
    destroy .t
} -body {
    toplevel .t
    wm override .t 1
    wm geometry .t +0+0
    update
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
} -cleanup {
    foreach cmd {proc1 proc2 proc3 click} {
	rename winwm91$cmd {}
    }
    destroy .tx .t .sd
} -result ok

test winWm-9.2 "check wm forget for unmapped parent (#3205464,#2967911)" -constraints {failsOnUbuntu failsOnXQuarz} -setup {
    destroy .t
    toplevel .t
    set winwm92 {}
    frame .t.f -background blue -height 200 -width 200
    frame .t.f.x -background red -height 100 -width 100
} -body {
    pack .t.f.x







|







526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
} -cleanup {
    foreach cmd {proc1 proc2 proc3 click} {
	rename winwm91$cmd {}
    }
    destroy .tx .t .sd
} -result ok

test winWm-9.2 "check wm forget for unmapped parent (#3205464,#2967911)" -constraints {failsOnUbuntu failsOnXQuartz} -setup {
    destroy .t
    toplevel .t
    set winwm92 {}
    frame .t.f -background blue -height 200 -width 200
    frame .t.f.x -background red -height 100 -width 100
} -body {
    pack .t.f.x
Changes to tests/window.test.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# This file is a Tcl script to test the procedures in the file
# tkWindow.c.  It is organized in the standard fashion for Tcl tests.
#
# Copyright © 1995 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
tcltest::configure {*}$argv
tcltest::loadTestedCommands
namespace import ::tk::test::loadTkCommand
update
# Move the mouse out of the way for window-2.1
event generate {} <Motion> -warp 1 -x 640 -y 10
# XXX This file is woefully incomplete.  Right now it only tests
# a few parts of a few procedures in tkWindow.c

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











|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# This file is a Tcl script to test the procedures in the file
# tkWindow.c.  It is organized in the standard fashion for Tcl tests.
#
# Copyright © 1995 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
tcltest::configure {*}$argv
tcltest::loadTestedCommands

update
# Move the mouse out of the way for window-2.1
event generate {} <Motion> -warp 1 -x 640 -y 10
# XXX This file is woefully incomplete.  Right now it only tests
# a few parts of a few procedures in tkWindow.c

# ----------------------------------------------------------------------
Changes to tests/winfo.test.
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
# This file is a Tcl script to test out the "winfo" command.  It is
# organized in the standard fashion for Tcl tests.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994-1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
tcltest::configure {*}$argv
tcltest::loadTestedCommands

testConstraint failsOnUbuntu [expr {![info exists ::env(CI)] || ![string match Linux $::tcl_platform(os)]}]
testConstraint failsOnXQuarz [expr {$tcl_platform(os) ne "Darwin" || [tk windowingsystem] ne "x11" }]

# eatColors --
# Creates a toplevel window and allocates enough colors in it to
# use up all the slots in the colormap.
#
# Arguments:
# w -        Name of toplevel window to create.
# options -    Options for w, such as "-colormap new".

proc eatColors {w {options ""}} {
    destroy $w
    eval toplevel $w $options
    wm geom $w +0+0
    canvas $w.c -width 400 -height 200 -bd 0
    pack $w.c
    for {set y 0} {$y < 8} {incr y} {
	for {set x 0} {$x < 40} {incr x} {
	    set color [format #%02x%02x%02x [expr {$x*6}] [expr {$y*30}] 0]
	    $w.c create rectangle [expr {10*$x}] [expr {20*$y}] \
		[expr {10*$x + 10}] [expr {20*$y + 20}] -outline {} \
		-fill $color
	}
    }
    update
}

# XXX - This test file is woefully incomplete.  At present, only a
# few of the winfo options are tested.

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

test winfo-1.1 {"winfo atom" command} -body {













<
<
|
<
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







1
2
3
4
5
6
7
8
9
10
11
12
13


14







15
















16
17
18
19
20
21
22
# This file is a Tcl script to test out the "winfo" command.  It is
# organized in the standard fashion for Tcl tests.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994-1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
tcltest::configure {*}$argv
tcltest::loadTestedCommands



# Import utility procs for specific functional areas







testutils import colors

















# XXX - This test file is woefully incomplete.  At present, only a
# few of the winfo options are tested.

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

test winfo-1.1 {"winfo atom" command} -body {
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
} -returnCodes error -result {wrong # args: should be "winfo viewable window"}
test winfo-9.2 {"winfo viewable" command} -body {
    winfo viewable foo
} -returnCodes error -result {bad window path name "foo"}
test winfo-9.3 {"winfo viewable" command} -body {
    winfo viewable .
} -result 1
test winfo-9.4 {"winfo viewable" command} -constraints {failsOnUbuntu failsOnXQuarz} -body {
    wm iconify .
    winfo viewable .
} -cleanup {
    wm deiconify .
} -result 0
test winfo-9.5 {"winfo viewable" command} -setup {
    deleteWindows







|







265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
} -returnCodes error -result {wrong # args: should be "winfo viewable window"}
test winfo-9.2 {"winfo viewable" command} -body {
    winfo viewable foo
} -returnCodes error -result {bad window path name "foo"}
test winfo-9.3 {"winfo viewable" command} -body {
    winfo viewable .
} -result 1
test winfo-9.4 {"winfo viewable" command} -constraints {failsOnUbuntu failsOnXQuartz} -body {
    wm iconify .
    winfo viewable .
} -cleanup {
    wm deiconify .
} -result 0
test winfo-9.5 {"winfo viewable" command} -setup {
    deleteWindows
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
    frame .f1.f2 -width 50 -height 50 -relief raised -bd 2
    place .f1.f2 -x 0 -y 0
    update
    list [winfo viewable .f1] [winfo viewable .f1.f2]
} -cleanup {
    deleteWindows
} -result {0 0}
test winfo-9.7 {"winfo viewable" command} -constraints {failsOnUbuntu failsOnXQuarz} -setup {
    deleteWindows
} -body {
    frame .f1 -width 100 -height 100 -relief raised -bd 2
    place .f1 -x 0 -y 0
    frame .f1.f2 -width 50 -height 50 -relief raised -bd 2
    place .f1.f2 -x 0 -y 0
    update







|







294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
    frame .f1.f2 -width 50 -height 50 -relief raised -bd 2
    place .f1.f2 -x 0 -y 0
    update
    list [winfo viewable .f1] [winfo viewable .f1.f2]
} -cleanup {
    deleteWindows
} -result {0 0}
test winfo-9.7 {"winfo viewable" command} -constraints {failsOnUbuntu failsOnXQuartz} -setup {
    deleteWindows
} -body {
    frame .f1 -width 100 -height 100 -relief raised -bd 2
    place .f1 -x 0 -y 0
    frame .f1.f2 -width 50 -height 50 -relief raised -bd 2
    place .f1.f2 -x 0 -y 0
    update
482
483
484
485
486
487
488
489




490
491
492
493
494
495
496
497
} -body {
    toplevel .t
    update idletasks
    winfo ismapped .t
} -cleanup {
    destroy .t
} -result 1





deleteWindows
# cleanup
cleanupTests
return

# Local variables:
# mode: tcl
# End:








>
>
>
>

|






457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
} -body {
    toplevel .t
    update idletasks
    winfo ismapped .t
} -cleanup {
    destroy .t
} -result 1

#
# CLEANUP
#

deleteWindows
testutils forget colors
cleanupTests
return

# Local variables:
# mode: tcl
# End:
Changes to tests/wm.test.
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
proc stdWindow {} {
    destroy .t
    toplevel .t -width 100 -height 50
    wm geom .t +0+0
    update
}

testConstraint failsOnUbuntu [expr {![info exists ::env(CI)] || ![string match Linux $::tcl_platform(os)]}]
testConstraint failsOnXQuarz [expr {$tcl_platform(os) ne "Darwin" || [tk windowingsystem] ne "x11" }]

# [raise] and [lower] may return before the window manager has completed the
# operation. The raiseDelay procedure idles for a while to give the operation
# a chance to complete.
#

proc raiseDelay {} {
    after 250;
    update idletasks
    update
}

# How to carry out a small delay while processing events

proc eventDelay {{delay 200}} {
    after $delay "set done 1" ; vwait done
}

deleteWindows

##############################################################################

stdWindow

test wm-1.1 {Tk_WmObjCmd procedure, miscellaneous errors} -returnCodes error -body {







<
<
<











<
<
<
<
<
<







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
proc stdWindow {} {
    destroy .t
    toplevel .t -width 100 -height 50
    wm geom .t +0+0
    update
}




# [raise] and [lower] may return before the window manager has completed the
# operation. The raiseDelay procedure idles for a while to give the operation
# a chance to complete.
#

proc raiseDelay {} {
    after 250;
    update idletasks
    update
}







deleteWindows

##############################################################################

stdWindow

test wm-1.1 {Tk_WmObjCmd procedure, miscellaneous errors} -returnCodes error -body {
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
    focus -force .
    toplevel .t
    lower .t
    update
    lappend results [focus]

    wm attributes .t -fullscreen 1
    eventDelay
    lappend results [focus]

    wm attributes .t -fullscreen 0
    eventDelay
    lappend results [focus]
} -cleanup {
    deleteWindows
} -result {. . .}
test wm-attributes-1.4.1 {setting fullscreen does not generate FocusIn on wrapper create} -setup {
    catch {unset focusin}
} -constraints win -body {
    focus -force .
    toplevel .t
    pack [entry .t.e]
    lower .t
    bind .t <FocusIn> {lappend focusin %W}
    eventDelay

    lappend focusin 1
    focus -force .t.e
    eventDelay

    lappend focusin 2
    wm attributes .t -fullscreen 1
    eventDelay

    lappend focusin 3
    wm attributes .t -fullscreen 0
    eventDelay

    lappend focusin final [focus]
} -cleanup {
    bind . <FocusIn> {}
    bind .t <FocusIn> {}
    deleteWindows
} -result {1 .t .t.e 2 3 final .t.e}

test wm-attributes-1.5.0 {fullscreen stackorder} -setup {
    set results [list]
} -constraints win -body {
    toplevel .t
    lappend results [wm stackorder .]
    eventDelay
    lappend results [wm stackorder .]

    # Default stacking is on top of other windows on the display. Setting the
    # fullscreen attribute does not change this.
    wm attributes .t -fullscreen 1
    eventDelay
    lappend results [wm stackorder .]
} -cleanup {
    deleteWindows
} -result {. {. .t} {. .t}}
test wm-attributes-1.5.1 {fullscreen stackorder} -setup {
    set results [list]
} -constraints win -body {
    toplevel .t
    lower .t
    eventDelay
    lappend results [wm stackorder .]

    # If stacking order is explicitly set, then setting the fullscreen
    # attribute should not change it.
    wm attributes .t -fullscreen 1
    eventDelay
    lappend results [wm stackorder .]
} -cleanup {
    deleteWindows
} -result {{.t .} {.t .}}
test wm-attributes-1.5.2 {fullscreen stackorder} -setup {
    set results [list]
} -constraints win -body {
    toplevel .t
    # lower forces the window to be mapped, it would not be otherwise
    lower .t
    lappend results [wm stackorder .]

    # If stacking order is explicitly set for an unmapped window, then setting
    # the fullscreen attribute should not change it.
    wm attributes .t -fullscreen 1
    eventDelay
    lappend results [wm stackorder .]
} -cleanup {
    deleteWindows
} -result {{.t .} {.t .}}
test wm-attributes-1.5.3 {fullscreen stackorder} -setup {
    set results [list]
} -constraints win -body {
    toplevel .t
    eventDelay
    lappend results [wm stackorder .]

    wm attributes .t -fullscreen 1
    eventDelay
    lappend results [wm stackorder .]

    # Unsetting the fullscreen attribute should not change the stackorder.
    wm attributes .t -fullscreen 0
    eventDelay
    lappend results [wm stackorder .]
} -cleanup {
    deleteWindows
} -result {{. .t} {. .t} {. .t}}
test wm-attributes-1.5.4 {fullscreen stackorder} -setup {
    set results [list]
} -constraints win -body {
    toplevel .t
    lower .t
    eventDelay
    lappend results [wm stackorder .]

    wm attributes .t -fullscreen 1
    eventDelay
    lappend results [wm stackorder .]

    # Unsetting the fullscreen attribute should not change the stackorder.
    wm attributes .t -fullscreen 0
    eventDelay
    lappend results [wm stackorder .]
} -cleanup {
    deleteWindows
} -result {{.t .} {.t .} {.t .}}
test wm-attributes-1.5.5 {fullscreen stackorder} -setup {
    set results [list]
} -constraints win -body {
    toplevel .a
    toplevel .b
    toplevel .c
    raise .a
    raise .b
    raise .c
    eventDelay
    lappend results [wm stackorder .]

    wm attributes .b -fullscreen 1
    eventDelay
    lappend results [wm stackorder .]

    # Unsetting the fullscreen attribute should not change the stackorder.
    wm attributes .b -fullscreen 0
    eventDelay
    lappend results [wm stackorder .]
} -cleanup {
    deleteWindows
} -result {{. .a .b .c} {. .a .b .c} {. .a .b .c}}


stdWindow







|



|












|



|



|



|













|





|









|





|















|








|



|




|









|



|




|













|



|




|







349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
    focus -force .
    toplevel .t
    lower .t
    update
    lappend results [focus]

    wm attributes .t -fullscreen 1
    pause 200
    lappend results [focus]

    wm attributes .t -fullscreen 0
    pause 200
    lappend results [focus]
} -cleanup {
    deleteWindows
} -result {. . .}
test wm-attributes-1.4.1 {setting fullscreen does not generate FocusIn on wrapper create} -setup {
    catch {unset focusin}
} -constraints win -body {
    focus -force .
    toplevel .t
    pack [entry .t.e]
    lower .t
    bind .t <FocusIn> {lappend focusin %W}
    pause 200

    lappend focusin 1
    focus -force .t.e
    pause 200

    lappend focusin 2
    wm attributes .t -fullscreen 1
    pause 200

    lappend focusin 3
    wm attributes .t -fullscreen 0
    pause 200

    lappend focusin final [focus]
} -cleanup {
    bind . <FocusIn> {}
    bind .t <FocusIn> {}
    deleteWindows
} -result {1 .t .t.e 2 3 final .t.e}

test wm-attributes-1.5.0 {fullscreen stackorder} -setup {
    set results [list]
} -constraints win -body {
    toplevel .t
    lappend results [wm stackorder .]
    pause 200
    lappend results [wm stackorder .]

    # Default stacking is on top of other windows on the display. Setting the
    # fullscreen attribute does not change this.
    wm attributes .t -fullscreen 1
    pause 200
    lappend results [wm stackorder .]
} -cleanup {
    deleteWindows
} -result {. {. .t} {. .t}}
test wm-attributes-1.5.1 {fullscreen stackorder} -setup {
    set results [list]
} -constraints win -body {
    toplevel .t
    lower .t
    pause 200
    lappend results [wm stackorder .]

    # If stacking order is explicitly set, then setting the fullscreen
    # attribute should not change it.
    wm attributes .t -fullscreen 1
    pause 200
    lappend results [wm stackorder .]
} -cleanup {
    deleteWindows
} -result {{.t .} {.t .}}
test wm-attributes-1.5.2 {fullscreen stackorder} -setup {
    set results [list]
} -constraints win -body {
    toplevel .t
    # lower forces the window to be mapped, it would not be otherwise
    lower .t
    lappend results [wm stackorder .]

    # If stacking order is explicitly set for an unmapped window, then setting
    # the fullscreen attribute should not change it.
    wm attributes .t -fullscreen 1
    pause 200
    lappend results [wm stackorder .]
} -cleanup {
    deleteWindows
} -result {{.t .} {.t .}}
test wm-attributes-1.5.3 {fullscreen stackorder} -setup {
    set results [list]
} -constraints win -body {
    toplevel .t
    pause 200
    lappend results [wm stackorder .]

    wm attributes .t -fullscreen 1
    pause 200
    lappend results [wm stackorder .]

    # Unsetting the fullscreen attribute should not change the stackorder.
    wm attributes .t -fullscreen 0
    pause 200
    lappend results [wm stackorder .]
} -cleanup {
    deleteWindows
} -result {{. .t} {. .t} {. .t}}
test wm-attributes-1.5.4 {fullscreen stackorder} -setup {
    set results [list]
} -constraints win -body {
    toplevel .t
    lower .t
    pause 200
    lappend results [wm stackorder .]

    wm attributes .t -fullscreen 1
    pause 200
    lappend results [wm stackorder .]

    # Unsetting the fullscreen attribute should not change the stackorder.
    wm attributes .t -fullscreen 0
    pause 200
    lappend results [wm stackorder .]
} -cleanup {
    deleteWindows
} -result {{.t .} {.t .} {.t .}}
test wm-attributes-1.5.5 {fullscreen stackorder} -setup {
    set results [list]
} -constraints win -body {
    toplevel .a
    toplevel .b
    toplevel .c
    raise .a
    raise .b
    raise .c
    pause 200
    lappend results [wm stackorder .]

    wm attributes .b -fullscreen 1
    pause 200
    lappend results [wm stackorder .]

    # Unsetting the fullscreen attribute should not change the stackorder.
    wm attributes .b -fullscreen 0
    pause 200
    lappend results [wm stackorder .]
} -cleanup {
    deleteWindows
} -result {{. .a .b .c} {. .a .b .c} {. .a .b .c}}


stdWindow
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
    frame .t.f -container 1
    toplevel .t2 -use [winfo id .t.f]
    wm iconify .t2
} -returnCodes error -cleanup {
    destroy .t2 .r.f
} -result {can't iconify ".t2": it is an embedded window}

test wm-iconify-3.1 {iconify behavior} -constraints {failsOnUbuntu failsOnXQuarz} -body {
    toplevel .t2
    wm geom .t2 -0+0
    update idletasks
    set result [winfo ismapped .t2]
    wm iconify .t2
    update idletasks
    lappend result [winfo ismapped .t2]







|







933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
    frame .t.f -container 1
    toplevel .t2 -use [winfo id .t.f]
    wm iconify .t2
} -returnCodes error -cleanup {
    destroy .t2 .r.f
} -result {can't iconify ".t2": it is an embedded window}

test wm-iconify-3.1 {iconify behavior} -constraints {failsOnUbuntu failsOnXQuartz} -body {
    toplevel .t2
    wm geom .t2 -0+0
    update idletasks
    set result [winfo ismapped .t2]
    wm iconify .t2
    update idletasks
    lappend result [winfo ismapped .t2]
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
    deleteWindows
} -body {
    wm stackorder .
} -result {.}

deleteWindows

test wm-stackorder-3.1 {unmapped toplevel} -constraints {failsOnUbuntu failsOnXQuarz} -body {
    toplevel .t1 ; update
    raiseDelay
    toplevel .t2 ; update
    raiseDelay
    wm iconify .t1
    raiseDelay
    wm stackorder .







|







1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
    deleteWindows
} -body {
    wm stackorder .
} -result {.}

deleteWindows

test wm-stackorder-3.1 {unmapped toplevel} -constraints {failsOnUbuntu failsOnXQuartz} -body {
    toplevel .t1 ; update
    raiseDelay
    toplevel .t2 ; update
    raiseDelay
    wm iconify .t1
    raiseDelay
    wm stackorder .
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
    raise .
    raiseDelay
    wm stackorder .
} -cleanup {
    destroy .t
} -result {.t .}
test wm-stackorder-5.2 {A normal toplevel can't be raised above an \
    overrideredirect toplevel on unix} -constraints {x11 failsOnUbuntu failsOnXQuarz} -body {
    toplevel .t
    wm overrideredirect .t 1
    tkwait visibility .t
    raise .
    update
    raiseDelay
    wm stackorder . isabove .t







|







1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
    raise .
    raiseDelay
    wm stackorder .
} -cleanup {
    destroy .t
} -result {.t .}
test wm-stackorder-5.2 {A normal toplevel can't be raised above an \
    overrideredirect toplevel on unix} -constraints {x11 failsOnUbuntu failsOnXQuartz} -body {
    toplevel .t
    wm overrideredirect .t 1
    tkwait visibility .t
    raise .
    update
    raiseDelay
    wm stackorder . isabove .t
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
    update
    lappend results [wm state .subject] [winfo ismapped .subject]
} -cleanup {
    deleteWindows
} -result {withdrawn 0 normal 1}

test wm-transient-4.1 {transient toplevel is withdrawn
	when mapped if toplevel is iconic} -constraints {failsOnUbuntu failsOnXQuarz} -body {
    toplevel .top
    wm iconify .top
    update
    toplevel .subject
    wm transient .subject .top
    update
    list [wm state .subject] [winfo ismapped .subject]
} -cleanup {
    deleteWindows
} -result {withdrawn 0}
test wm-transient-4.2 {already mapped transient toplevel
	is withdrawn if toplevel is iconic} -constraints {failsOnUbuntu failsOnXQuarz} -body {
    toplevel .top
    raiseDelay
    wm iconify .top
    update idletasks
    toplevel .subject
    update idletasks
    wm transient .subject .top
    update idletasks
    list [wm state .subject] [winfo ismapped .subject]
} -cleanup {
    deleteWindows
} -result {withdrawn 0}
test wm-transient-4.3 {iconify/deiconify on the toplevel
	does a withdraw/deiconify on the transient} -constraints {failsOnUbuntu failsOnXQuarz} -setup {
    set results [list]
} -body {
    toplevel .top
    toplevel .subject
    update idletasks
    wm transient .subject .top
    wm iconify .top







|











|













|







1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
    update
    lappend results [wm state .subject] [winfo ismapped .subject]
} -cleanup {
    deleteWindows
} -result {withdrawn 0 normal 1}

test wm-transient-4.1 {transient toplevel is withdrawn
	when mapped if toplevel is iconic} -constraints {failsOnUbuntu failsOnXQuartz} -body {
    toplevel .top
    wm iconify .top
    update
    toplevel .subject
    wm transient .subject .top
    update
    list [wm state .subject] [winfo ismapped .subject]
} -cleanup {
    deleteWindows
} -result {withdrawn 0}
test wm-transient-4.2 {already mapped transient toplevel
	is withdrawn if toplevel is iconic} -constraints {failsOnUbuntu failsOnXQuartz} -body {
    toplevel .top
    raiseDelay
    wm iconify .top
    update idletasks
    toplevel .subject
    update idletasks
    wm transient .subject .top
    update idletasks
    list [wm state .subject] [winfo ismapped .subject]
} -cleanup {
    deleteWindows
} -result {withdrawn 0}
test wm-transient-4.3 {iconify/deiconify on the toplevel
	does a withdraw/deiconify on the transient} -constraints {failsOnUbuntu failsOnXQuartz} -setup {
    set results [list]
} -body {
    toplevel .top
    toplevel .subject
    update idletasks
    wm transient .subject .top
    wm iconify .top
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
    destroy .transient
    destroy .t2		;# caused panic in 8.4b1
    destroy .t1		;# so did this
} -cleanup {
    deleteWindows
}

test wm-transient-8.1 {transient to withdrawn window, Bug 1163496} -constraints {failsOnUbuntu failsOnXQuarz} -setup {
    deleteWindows
    set result {}
} -body {
    # Verifies that transients stay on top of their toplevels, even if they were
    # made transients when those toplevels were withdrawn.
    toplevel .t1; wm withdraw  .t1;     update
    toplevel .t2; wm transient .t2 .t1; update







|







2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
    destroy .transient
    destroy .t2		;# caused panic in 8.4b1
    destroy .t1		;# so did this
} -cleanup {
    deleteWindows
}

test wm-transient-8.1 {transient to withdrawn window, Bug 1163496} -constraints {failsOnUbuntu failsOnXQuartz} -setup {
    deleteWindows
    set result {}
} -body {
    # Verifies that transients stay on top of their toplevels, even if they were
    # made transients when those toplevels were withdrawn.
    toplevel .t1; wm withdraw  .t1;     update
    toplevel .t2; wm transient .t2 .t1; update
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
test wm-state-2.7 {state change before map} -body {
    toplevel .t
    wm iconify .t
    wm state .t
} -cleanup {
    deleteWindows
} -result {iconic}
test wm-state-2.8 {state change after map} -constraints {failsOnUbuntu failsOnXQuarz} -body {
    toplevel .t
    update
    wm state .t iconic
    wm state .t
} -cleanup {
    deleteWindows
} -result {iconic}
test wm-state-2.9 {state change after map} -constraints {failsOnUbuntu failsOnXQuarz} -body {
    toplevel .t
    update
    wm iconify .t
    wm state .t
} -cleanup {
    deleteWindows
} -result {iconic}







|







|







2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
test wm-state-2.7 {state change before map} -body {
    toplevel .t
    wm iconify .t
    wm state .t
} -cleanup {
    deleteWindows
} -result {iconic}
test wm-state-2.8 {state change after map} -constraints {failsOnUbuntu failsOnXQuartz} -body {
    toplevel .t
    update
    wm state .t iconic
    wm state .t
} -cleanup {
    deleteWindows
} -result {iconic}
test wm-state-2.9 {state change after map} -constraints {failsOnUbuntu failsOnXQuartz} -body {
    toplevel .t
    update
    wm iconify .t
    wm state .t
} -cleanup {
    deleteWindows
} -result {iconic}
Changes to win/tkWinDialog.c.
145
146
147
148
149
150
151
152

153
154
155
156
157
158
159
/*
 * The following structure is used to pass information between GetFileName
 * function and OFN dialog hook procedures. [Bug 2896501, Patch 2898255]
 */

typedef struct OFNData {
    Tcl_Interp *interp;		/* Interp, used only if debug is turned on,
				 * for setting the "tk_dialog" variable. */

    int dynFileBufferSize;	/* Dynamic filename buffer size, stored to
				 * avoid shrinking and expanding the buffer
				 * when selection changes */
    WCHAR *dynFileBuffer;	/* Dynamic filename buffer */
} OFNData;

/*







|
>







145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
 * The following structure is used to pass information between GetFileName
 * function and OFN dialog hook procedures. [Bug 2896501, Patch 2898255]
 */

typedef struct OFNData {
    Tcl_Interp *interp;		/* Interp, used only if debug is turned on,
				 * for setting the variable
				 * "::tk::test::dialog::testDialog". */
    int dynFileBufferSize;	/* Dynamic filename buffer size, stored to
				 * avoid shrinking and expanding the buffer
				 * when selection changes */
    WCHAR *dynFileBuffer;	/* Dynamic filename buffer */
} OFNData;

/*
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
				    Tcl_Interp *interp, int objc,
				    Tcl_Obj *const objv[], enum OFNOper oper);
static int MakeFilterVista(Tcl_Interp *interp, OFNOpts *optsPtr,
	       DWORD *countPtr, COMDLG_FILTERSPEC **dlgFilterPtrPtr,
	       DWORD *defaultFilterIndexPtr);
static void FreeFilterVista(DWORD count, COMDLG_FILTERSPEC *dlgFilterPtr);
static LRESULT CALLBACK MsgBoxCBTProc(int nCode, WPARAM wParam, LPARAM lParam);
static void		SetTkDialog(void *clientData);
static const char *ConvertExternalFilename(LPCWSTR, Tcl_DString *);

/*
 *-------------------------------------------------------------------------
 *
 * EatSpuriousMessageBugFix --
 *







|







201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
				    Tcl_Interp *interp, int objc,
				    Tcl_Obj *const objv[], enum OFNOper oper);
static int MakeFilterVista(Tcl_Interp *interp, OFNOpts *optsPtr,
	       DWORD *countPtr, COMDLG_FILTERSPEC **dlgFilterPtrPtr,
	       DWORD *defaultFilterIndexPtr);
static void FreeFilterVista(DWORD count, COMDLG_FILTERSPEC *dlgFilterPtr);
static LRESULT CALLBACK MsgBoxCBTProc(int nCode, WPARAM wParam, LPARAM lParam);
static void		SetTestDialog(void *clientData);
static const char *ConvertExternalFilename(LPCWSTR, Tcl_DString *);

/*
 *-------------------------------------------------------------------------
 *
 * EatSpuriousMessageBugFix --
 *
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274

/*
 *-------------------------------------------------------------------------
 *
 * TkWinDialogDebug --
 *
 *	Function to turn on/off debugging support for common dialogs under
 *	windows. The variable "tk_debug" is set to the identifier of the
 *	dialog window when the modal dialog window pops up and it is safe to
 *	send messages to the dialog.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	This variable only makes sense if just one dialog is up at a time.
 *







|
|
|







259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275

/*
 *-------------------------------------------------------------------------
 *
 * TkWinDialogDebug --
 *
 *	Function to turn on/off debugging support for common dialogs under
 *	windows. The variable "::tk::test::dialog::testDialog" is set to the
 *	identifier of the dialog window when the modal dialog window pops up
 *	and it is safe to send messages to the dialog.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	This variable only makes sense if just one dialog is up at a time.
 *
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498

	    Tcl_DStringInit(&ds);
	    SetWindowTextW(hDlg, Tcl_UtfToWCharDString(title, TCL_INDEX_NONE, &ds));
	    Tcl_DStringFree(&ds);
	}
	if (tsdPtr->debugFlag) {
	    tsdPtr->debugInterp = (Tcl_Interp *) ccPtr->lpTemplateName;
	    Tcl_DoWhenIdle(SetTkDialog, hDlg);
	}
	return TRUE;
    }
    return FALSE;
}

/*







|







485
486
487
488
489
490
491
492
493
494
495
496
497
498
499

	    Tcl_DStringInit(&ds);
	    SetWindowTextW(hDlg, Tcl_UtfToWCharDString(title, TCL_INDEX_NONE, &ds));
	    Tcl_DStringFree(&ds);
	}
	if (tsdPtr->debugFlag) {
	    tsdPtr->debugInterp = (Tcl_Interp *) ccPtr->lpTemplateName;
	    Tcl_DoWhenIdle(SetTestDialog, hDlg);
	}
	return TRUE;
    }
    return FALSE;
}

/*
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551

1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568

1569
1570
1571
1572
1573
1574
1575

    return CallNextHookEx(tsdPtr->hMsgBoxHook, nCode, wParam, lParam);
}

/*
 * ----------------------------------------------------------------------
 *
 * SetTkDialog --
 *
 *	Records the HWND for a native dialog in the 'tk_dialog' variable so

 *	that the test-suite can operate on the correct dialog window. Use of
 *	this is enabled when a test program calls TkWinDialogDebug by calling
 *	the test command 'tkwinevent debug 1'.
 *
 * ----------------------------------------------------------------------
 */

static void
SetTkDialog(
    void *clientData)
{
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
    char buf[32];

    snprintf(buf, sizeof(buf), "0x%" TCL_Z_MODIFIER "x", (size_t)clientData);
    Tcl_SetVar2(tsdPtr->debugInterp, "tk_dialog", NULL, buf, TCL_GLOBAL_ONLY);

}

/*
 * Factored out a common pattern in use in this file.
 */

static const char *







|

|
>
|
|
|





|







|
>







1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578

    return CallNextHookEx(tsdPtr->hMsgBoxHook, nCode, wParam, lParam);
}

/*
 * ----------------------------------------------------------------------
 *
 * SetTestDialog --
 *
 *	Records the HWND for a native dialog in the variable
 *	"::tk::test::dialog::testDialog" so that the test-suite can operate
 *	on the correct dialog window. Use of this is enabled when a test
 *	program calls TkWinDialogDebug by calling the test command
 *	'testwinevent debug 1'.
 *
 * ----------------------------------------------------------------------
 */

static void
SetTestDialog(
    void *clientData)
{
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
    char buf[32];

    snprintf(buf, sizeof(buf), "0x%" TCL_Z_MODIFIER "x", (size_t)clientData);
    Tcl_SetVar2(tsdPtr->debugInterp, "::tk::test::dialog::testDialog", NULL,
		buf, TCL_GLOBAL_ONLY);
}

/*
 * Factored out a common pattern in use in this file.
 */

static const char *
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    if (WM_INITDIALOG == msg && lParam != 0) {
	phd = (HookData *) pcf->lCustData;
	phd->hwnd = hwndDlg;
	if (tsdPtr->debugFlag) {
	    tsdPtr->debugInterp = phd->interp;
	    Tcl_DoWhenIdle(SetTkDialog, hwndDlg);
	}
	if (phd->titleObj != NULL) {
	    Tcl_DString title;

	    Tcl_DStringInit(&title);
	    Tcl_UtfToWCharDString(Tcl_GetString(phd->titleObj), TCL_INDEX_NONE, &title);
	    if (Tcl_DStringLength(&title) > 0) {







|







1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    if (WM_INITDIALOG == msg && lParam != 0) {
	phd = (HookData *) pcf->lCustData;
	phd->hwnd = hwndDlg;
	if (tsdPtr->debugFlag) {
	    tsdPtr->debugInterp = phd->interp;
	    Tcl_DoWhenIdle(SetTestDialog, hwndDlg);
	}
	if (phd->titleObj != NULL) {
	    Tcl_DString title;

	    Tcl_DStringInit(&title);
	    Tcl_UtfToWCharDString(Tcl_GetString(phd->titleObj), TCL_INDEX_NONE, &title);
	    if (Tcl_DStringLength(&title) > 0) {
Changes to win/tkWinGDI.c.
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
static int		GdiGetColor(Tcl_Obj *nameObj, COLORREF *color);

/*
 * Helper functions.
 */
static int		GdiMakeLogFont(Tcl_Interp *interp, const char *str,
			    LOGFONTW *lf, HDC hDC);
static int		GdiMakePen(Tcl_Interp *interp, int width,
			    int dashstyle, const char *dashstyledata,
			    int capstyle, int joinstyle,
			    int stipplestyle, const char *stippledata,
			    unsigned long color, HDC hDC, HGDIOBJ *oldPen);
static int		GdiFreePen(Tcl_Interp *interp, HDC hDC, HGDIOBJ oldPen);
static int		GdiMakeBrush(unsigned long color, long hatch,
			    LOGBRUSH *lb, HDC hDC, HBRUSH *oldBrush);







|







53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
static int		GdiGetColor(Tcl_Obj *nameObj, COLORREF *color);

/*
 * Helper functions.
 */
static int		GdiMakeLogFont(Tcl_Interp *interp, const char *str,
			    LOGFONTW *lf, HDC hDC);
static int		GdiMakePen(Tcl_Interp *interp, double dwidth,
			    int dashstyle, const char *dashstyledata,
			    int capstyle, int joinstyle,
			    int stipplestyle, const char *stippledata,
			    unsigned long color, HDC hDC, HGDIOBJ *oldPen);
static int		GdiFreePen(Tcl_Interp *interp, HDC hDC, HGDIOBJ oldPen);
static int		GdiMakeBrush(unsigned long color, long hatch,
			    LOGBRUSH *lb, HDC hDC, HBRUSH *oldBrush);
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
{
    static const char usage_message[] =
	"::tk::print::_gdi arc hdc x1 y1 x2 y2 "
	"-extent angle -start angle -style arcstyle "
	"-fill color -outline color "
	"-width dimension -dash dashrule "
	"-outlinestipple ignored -stipple ignored\n" ;
    int x1, y1, x2, y2;
    int xr0, yr0, xr1, yr1;
    HDC hDC;
    double extent = 0.0, start = 0.0;
    DrawFunc drawfunc;
    int width = 0;
    HPEN hPen;
    COLORREF linecolor = 0, fillcolor = BS_NULL;
    int dolinecolor = 0, dofillcolor = 0;
    HBRUSH hBrush = NULL;
    LOGBRUSH lbrush;
    HGDIOBJ oldobj = NULL;
    int dodash = 0;
    const char *dashdata = 0;

    drawfunc = Pie;

    /* Verrrrrry simple for now.... */
    if (objc < 6) {
	Tcl_AppendResult(interp, usage_message, (char *)NULL);
	return TCL_ERROR;
    }

    hDC = printDC;

    if ((Tcl_GetIntFromObj(interp, objv[2], &x1) != TCL_OK)
	    || (Tcl_GetIntFromObj(interp, objv[3], &y1) != TCL_OK)
	    || (Tcl_GetIntFromObj(interp, objv[4], &x2) != TCL_OK)
	    || (Tcl_GetIntFromObj(interp, objv[5], &y2) != TCL_OK)) {
	return TCL_ERROR;
    }

    objc -= 6;
    objv += 6;
    while (objc >= 2) {
	if (strcmp(Tcl_GetString(objv[0]), "-extent") == 0) {







|




|



















|
|
|
|







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
{
    static const char usage_message[] =
	"::tk::print::_gdi arc hdc x1 y1 x2 y2 "
	"-extent angle -start angle -style arcstyle "
	"-fill color -outline color "
	"-width dimension -dash dashrule "
	"-outlinestipple ignored -stipple ignored\n" ;
    double x1, y1, x2, y2;
    int xr0, yr0, xr1, yr1;
    HDC hDC;
    double extent = 0.0, start = 0.0;
    DrawFunc drawfunc;
    double width = 0.0;
    HPEN hPen;
    COLORREF linecolor = 0, fillcolor = BS_NULL;
    int dolinecolor = 0, dofillcolor = 0;
    HBRUSH hBrush = NULL;
    LOGBRUSH lbrush;
    HGDIOBJ oldobj = NULL;
    int dodash = 0;
    const char *dashdata = 0;

    drawfunc = Pie;

    /* Verrrrrry simple for now.... */
    if (objc < 6) {
	Tcl_AppendResult(interp, usage_message, (char *)NULL);
	return TCL_ERROR;
    }

    hDC = printDC;

    if ((Tcl_GetDoubleFromObj(interp, objv[2], &x1) != TCL_OK)
	    || (Tcl_GetDoubleFromObj(interp, objv[3], &y1) != TCL_OK)
	    || (Tcl_GetDoubleFromObj(interp, objv[4], &x2) != TCL_OK)
	    || (Tcl_GetDoubleFromObj(interp, objv[5], &y2) != TCL_OK)) {
	return TCL_ERROR;
    }

    objc -= 6;
    objv += 6;
    while (objc >= 2) {
	if (strcmp(Tcl_GetString(objv[0]), "-extent") == 0) {
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
		dolinecolor = 1;
	    }
	} else if (strcmp(Tcl_GetString(objv[0]), "-outlinestipple") == 0) {
	    /* ignored */
	} else if (strcmp(Tcl_GetString(objv[0]), "-stipple") == 0) {
	    /* ignored */
	} else if (strcmp(Tcl_GetString(objv[0]), "-width") == 0) {
	    if (Tcl_GetIntFromObj(interp, objv[1], &width)) {
		return TCL_ERROR;
	    }
	} else if (strcmp(Tcl_GetString(objv[0]), "-dash") == 0) {
	    if (Tcl_GetString(objv[1])) {
		dodash = 1;
		dashdata = Tcl_GetString(objv[1]);
	    }







|







210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
		dolinecolor = 1;
	    }
	} else if (strcmp(Tcl_GetString(objv[0]), "-outlinestipple") == 0) {
	    /* ignored */
	} else if (strcmp(Tcl_GetString(objv[0]), "-stipple") == 0) {
	    /* ignored */
	} else if (strcmp(Tcl_GetString(objv[0]), "-width") == 0) {
	    if (Tcl_GetDoubleFromObj(interp, objv[1], &width)) {
		return TCL_ERROR;
	    }
	} else if (strcmp(Tcl_GetString(objv[0]), "-dash") == 0) {
	    if (Tcl_GetString(objv[1])) {
		dodash = 1;
		dashdata = Tcl_GetString(objv[1]);
	    }
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
 *----------------------------------------------------------------------
 */

static int Bezierize(
    POINT* polypoints,
    int npoly,
    int nStep,
    POINT* bpointptr)
{
    /* First, translate my points into a list of doubles. */
    double *inPointList, *outPointList;
    int n;
    int nbpoints = 0;
    POINT* bpoints;








|







559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
 *----------------------------------------------------------------------
 */

static int Bezierize(
    POINT* polypoints,
    int npoly,
    int nStep,
    POINT** bpointptr)
{
    /* First, translate my points into a list of doubles. */
    double *inPointList, *outPointList;
    int n;
    int nbpoints = 0;
    POINT* bpoints;

602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
    }

    for (n=0; n<nbpoints; n++) {
	bpoints[n].x = (long)outPointList[2*n];
	bpoints[n].y = (long)outPointList[2*n + 1];
    }
    ckfree(outPointList);
    *bpointptr = *bpoints;
    return nbpoints;
}

/*
 *----------------------------------------------------------------------
 *
 * GdiLine --







|







602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
    }

    for (n=0; n<nbpoints; n++) {
	bpoints[n].x = (long)outPointList[2*n];
	bpoints[n].y = (long)outPointList[2*n + 1];
    }
    ckfree(outPointList);
    *bpointptr = bpoints;
    return nbpoints;
}

/*
 *----------------------------------------------------------------------
 *
 * GdiLine --
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659

660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684




685
686
687
688
689
690
691
    int x, y;
    HDC hDC;
    HPEN hPen;

    LOGBRUSH lbrush;
    HBRUSH hBrush = NULL;

    int width          = 0;
    COLORREF linecolor = 0;
    int dolinecolor    = 0;
    int dosmooth       = 0;
    int doarrow        = 0; /* 0=none; 1=end; 2=start; 3=both. */
    int arrowshape[3];

    int nStep = 12;

    int dodash = 0;
    const char *dashdata = 0;


    arrowshape[0] = 8;
    arrowshape[1] = 10;
    arrowshape[2] = 3;

    /* Verrrrrry simple for now.... */
    if (objc < 6) {
	Tcl_AppendResult(interp, usage_message, (char *)NULL);
	return TCL_ERROR;
    }

    hDC = printDC;

    polypoints = (POINT *)attemptckalloc((objc - 1) * sizeof(POINT));
    if (polypoints == 0) {
	Tcl_AppendResult(interp, "Out of memory in GdiLine", (char *)NULL);
	return TCL_ERROR;
    }
    if ((Tcl_GetIntFromObj(interp, objv[2], (int *)&polypoints[0].x) != TCL_OK)
	||	(Tcl_GetIntFromObj(interp, objv[3], (int *)&polypoints[0].y) != TCL_OK)
	||	(Tcl_GetIntFromObj(interp, objv[4], (int *)&polypoints[1].x) != TCL_OK)
	||	(Tcl_GetIntFromObj(interp, objv[5], (int *)&polypoints[1].y) != TCL_OK)
    ) {
	return TCL_ERROR;
    }




    objc -= 6;
    objv += 6;
    npoly = 2;

    while (objc >= 2) {
	/* Check for a number. */
	x = strtoul(Tcl_GetString(objv[0]), &strend, 0);







|










>


















|
|
|
|



>
>
>
>







642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
    int x, y;
    HDC hDC;
    HPEN hPen;

    LOGBRUSH lbrush;
    HBRUSH hBrush = NULL;

    double width       = 0.0;
    COLORREF linecolor = 0;
    int dolinecolor    = 0;
    int dosmooth       = 0;
    int doarrow        = 0; /* 0=none; 1=end; 2=start; 3=both. */
    int arrowshape[3];

    int nStep = 12;

    int dodash = 0;
    const char *dashdata = 0;
    double p1x, p1y, p2x, p2y;

    arrowshape[0] = 8;
    arrowshape[1] = 10;
    arrowshape[2] = 3;

    /* Verrrrrry simple for now.... */
    if (objc < 6) {
	Tcl_AppendResult(interp, usage_message, (char *)NULL);
	return TCL_ERROR;
    }

    hDC = printDC;

    polypoints = (POINT *)attemptckalloc((objc - 1) * sizeof(POINT));
    if (polypoints == 0) {
	Tcl_AppendResult(interp, "Out of memory in GdiLine", (char *)NULL);
	return TCL_ERROR;
    }
    if ((Tcl_GetDoubleFromObj(interp, objv[2], &p1x) != TCL_OK)
	||	(Tcl_GetDoubleFromObj(interp, objv[3], &p1y) != TCL_OK)
	||	(Tcl_GetDoubleFromObj(interp, objv[4], &p2x) != TCL_OK)
	||	(Tcl_GetDoubleFromObj(interp, objv[5], &p2y) != TCL_OK)
    ) {
	return TCL_ERROR;
    }
    polypoints[0].x = floor(p1x+0.5);
    polypoints[0].y = floor(p1y+0.5);
    polypoints[1].x = floor(p2x+0.5);
    polypoints[1].y = floor(p2y+0.5);
    objc -= 6;
    objv += 6;
    npoly = 2;

    while (objc >= 2) {
	/* Check for a number. */
	x = strtoul(Tcl_GetString(objv[0]), &strend, 0);
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
	    } else if (strcmp(Tcl_GetString(*objv), "-dashoffset") == 0) {
		objv += 2;
		objc -= 2;
	    } else if (strcmp(Tcl_GetString(*objv), "-stipple") == 0) {
		objv += 2;
		objc -= 2;
	    } else if (strcmp(Tcl_GetString(*objv), "-width") == 0) {
		if (Tcl_GetIntFromObj(interp, objv[1], &width) != TCL_OK) {
		    return TCL_ERROR;
		}
		objv += 2;
		objc -= 2;
	    } else { /* It's an unknown argument!. */
		objc--;
		objv++;







|







782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
	    } else if (strcmp(Tcl_GetString(*objv), "-dashoffset") == 0) {
		objv += 2;
		objc -= 2;
	    } else if (strcmp(Tcl_GetString(*objv), "-stipple") == 0) {
		objv += 2;
		objc -= 2;
	    } else if (strcmp(Tcl_GetString(*objv), "-width") == 0) {
		if (Tcl_GetDoubleFromObj(interp, objv[1], &width) != TCL_OK) {
		    return TCL_ERROR;
		}
		objv += 2;
		objc -= 2;
	    } else { /* It's an unknown argument!. */
		objc--;
		objv++;
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
    }
    if (doarrow != 0) {
	GdiMakeBrush(linecolor, 0, &lbrush, hDC, &hBrush);
    }

    if (dosmooth) { /* Use PolyBezier. */
	int nbpoints;
	POINT *bpoints = 0;

	nbpoints = Bezierize(polypoints,npoly,nStep,bpoints);
	if (nbpoints > 0) {
	    Polyline(hDC, bpoints, nbpoints);
	} else {
	    Polyline(hDC, polypoints, npoly); /* Out of memory? Just draw a regular line. */
	}
	if (bpoints != 0) {
	    ckfree(bpoints);
	}
    } else {
	Polyline(hDC, polypoints, npoly);
    }

    if (dodash && doarrow) {  /* Don't use dashed or thick pen for the arrows! */







|

|





|







807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
    }
    if (doarrow != 0) {
	GdiMakeBrush(linecolor, 0, &lbrush, hDC, &hBrush);
    }

    if (dosmooth) { /* Use PolyBezier. */
	int nbpoints;
	POINT *bpoints = NULL;

	nbpoints = Bezierize(polypoints,npoly,nStep,&bpoints);
	if (nbpoints > 0) {
	    Polyline(hDC, bpoints, nbpoints);
	} else {
	    Polyline(hDC, polypoints, npoly); /* Out of memory? Just draw a regular line. */
	}
	if (bpoints) {
	    ckfree(bpoints);
	}
    } else {
	Polyline(hDC, polypoints, npoly);
    }

    if (dodash && doarrow) {  /* Don't use dashed or thick pen for the arrows! */
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
    Tcl_Interp *interp,
    Tcl_Size objc,
    Tcl_Obj *const *objv)
{
    static const char usage_message[] =
	"::tk::print::_gdi oval hdc x1 y1 x2 y2 -fill color -outline color "
	"-stipple bitmap -width linewid";
    int x1, y1, x2, y2;
    HDC hDC;
    HPEN hPen;
    int width = 0;
    COLORREF linecolor = 0, fillcolor = 0;
    int dolinecolor = 0, dofillcolor = 0;
    HBRUSH hBrush = NULL;
    LOGBRUSH lbrush;
    HGDIOBJ oldobj = NULL;

    int dodash = 0;
    const char *dashdata = 0;

    /* Verrrrrry simple for now.... */
    if (objc < 6) {
	Tcl_AppendResult(interp, usage_message, (char *)NULL);
	return TCL_ERROR;
    }

    hDC = printDC;

    if ((Tcl_GetIntFromObj(interp, objv[2], &x1) != TCL_OK)
	    || (Tcl_GetIntFromObj(interp, objv[3], &y1) != TCL_OK)
	    || (Tcl_GetIntFromObj(interp, objv[4], &x2) != TCL_OK)
	    || (Tcl_GetIntFromObj(interp, objv[5], &y2) != TCL_OK)) {
	return TCL_ERROR;
    }
    if (x1 > x2) {
	int x3 = x1;
	x1 = x2;
	x2 = x3;
    }
    if (y1 > y2) {
	int y3 = y1;
	y1 = y2;
	y2 = y3;
    }
    objc -= 6;
    objv += 6;

    while (objc > 0) {
	/* Now handle any other arguments that occur. */
	if (strcmp(Tcl_GetString(objv[0]), "-fill") == 0) {
	    if (Tcl_GetString(objv[1]) && GdiGetColor(objv[1], &fillcolor)) {
		dofillcolor = 1;
	    }
	} else if (strcmp(Tcl_GetString(objv[0]), "-outline") == 0) {
	    if (Tcl_GetString(objv[1]) && GdiGetColor(objv[1], &linecolor)) {
		dolinecolor = 1;
	    }
	} else if (strcmp(Tcl_GetString(objv[0]), "-stipple") == 0) {
	    /* Not actually implemented */
	} else if (strcmp(Tcl_GetString(objv[0]), "-width") == 0) {
	    if (Tcl_GetString(objv[1])) {
		if (Tcl_GetIntFromObj(interp, objv[1], &width) != TCL_OK) {
		    return TCL_ERROR;
		}
	    }
	} else if (strcmp(Tcl_GetString(objv[0]), "-dash") == 0) {
	    if (Tcl_GetString(objv[1])) {
		dodash = 1;
		dashdata = Tcl_GetString(objv[1]);







|


|

















|
|
|
|



|




|




















|







934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
    Tcl_Interp *interp,
    Tcl_Size objc,
    Tcl_Obj *const *objv)
{
    static const char usage_message[] =
	"::tk::print::_gdi oval hdc x1 y1 x2 y2 -fill color -outline color "
	"-stipple bitmap -width linewid";
    double x1, y1, x2, y2;
    HDC hDC;
    HPEN hPen;
    double width = 0.0;
    COLORREF linecolor = 0, fillcolor = 0;
    int dolinecolor = 0, dofillcolor = 0;
    HBRUSH hBrush = NULL;
    LOGBRUSH lbrush;
    HGDIOBJ oldobj = NULL;

    int dodash = 0;
    const char *dashdata = 0;

    /* Verrrrrry simple for now.... */
    if (objc < 6) {
	Tcl_AppendResult(interp, usage_message, (char *)NULL);
	return TCL_ERROR;
    }

    hDC = printDC;

    if ((Tcl_GetDoubleFromObj(interp, objv[2], &x1) != TCL_OK)
	    || (Tcl_GetDoubleFromObj(interp, objv[3], &y1) != TCL_OK)
	    || (Tcl_GetDoubleFromObj(interp, objv[4], &x2) != TCL_OK)
	    || (Tcl_GetDoubleFromObj(interp, objv[5], &y2) != TCL_OK)) {
	return TCL_ERROR;
    }
    if (x1 > x2) {
	double x3 = x1;
	x1 = x2;
	x2 = x3;
    }
    if (y1 > y2) {
	double y3 = y1;
	y1 = y2;
	y2 = y3;
    }
    objc -= 6;
    objv += 6;

    while (objc > 0) {
	/* Now handle any other arguments that occur. */
	if (strcmp(Tcl_GetString(objv[0]), "-fill") == 0) {
	    if (Tcl_GetString(objv[1]) && GdiGetColor(objv[1], &fillcolor)) {
		dofillcolor = 1;
	    }
	} else if (strcmp(Tcl_GetString(objv[0]), "-outline") == 0) {
	    if (Tcl_GetString(objv[1]) && GdiGetColor(objv[1], &linecolor)) {
		dolinecolor = 1;
	    }
	} else if (strcmp(Tcl_GetString(objv[0]), "-stipple") == 0) {
	    /* Not actually implemented */
	} else if (strcmp(Tcl_GetString(objv[0]), "-width") == 0) {
	    if (Tcl_GetString(objv[1])) {
		if (Tcl_GetDoubleFromObj(interp, objv[1], &width) != TCL_OK) {
		    return TCL_ERROR;
		}
	    }
	} else if (strcmp(Tcl_GetString(objv[0]), "-dash") == 0) {
	    if (Tcl_GetString(objv[1])) {
		dodash = 1;
		dashdata = Tcl_GetString(objv[1]);
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
		0, 0, 0, 0, linecolor, hDC, (HGDIOBJ *)&hPen);
    }
    /*
     * Per Win32, Rectangle includes lower and right edges--per Tcl8.3.2 and
     * earlier documentation, canvas rectangle does not. Thus, add 1 to right
     * and lower bounds to get appropriate behavior.
     */
    Ellipse(hDC, x1, y1, x2+1, y2+1);

    if (width || dolinecolor) {
	GdiFreePen(interp, hDC, hPen);
    }
    if (hBrush) {
	GdiFreeBrush(interp, hDC, hBrush);
    } else {







|







1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
		0, 0, 0, 0, linecolor, hDC, (HGDIOBJ *)&hPen);
    }
    /*
     * Per Win32, Rectangle includes lower and right edges--per Tcl8.3.2 and
     * earlier documentation, canvas rectangle does not. Thus, add 1 to right
     * and lower bounds to get appropriate behavior.
     */
    Ellipse(hDC, floor(x1+0.5), floor(y1+0.5), floor(x2+1.5), floor(y2+1.5));

    if (width || dolinecolor) {
	GdiFreePen(interp, hDC, hPen);
    }
    if (hBrush) {
	GdiFreeBrush(interp, hDC, hBrush);
    } else {
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073

1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094




1095
1096
1097
1098
1099
1100
1101
    POINT *polypoints;
    int npoly;
    int dosmooth = 0;
    int nStep = 12;
    int x, y;
    HDC hDC;
    HPEN hPen;
    int width = 0;
    COLORREF linecolor = 0, fillcolor = BS_NULL;
    int dolinecolor = 0, dofillcolor = 0;
    LOGBRUSH lbrush;
    HBRUSH hBrush = NULL;
    HGDIOBJ oldobj = NULL;

    int dodash = 0;
    const char *dashdata = 0;


    /* Verrrrrry simple for now.... */
    if (objc < 6) {
	Tcl_AppendResult(interp, usage_message, (char *)NULL);
	return TCL_ERROR;
    }

    hDC = printDC;

    polypoints = (POINT *)attemptckalloc((objc - 1) * sizeof(POINT));
    if (polypoints == 0) {
	/* TODO: unreachable */
	Tcl_AppendResult(interp, "Out of memory in GdiLine", (char *)NULL);
	return TCL_ERROR;
    }
    if ((Tcl_GetIntFromObj(interp, objv[2], (int *)&polypoints[0].x) != TCL_OK)
	    || (Tcl_GetIntFromObj(interp, objv[3], (int *)&polypoints[0].y) != TCL_OK)
	    || (Tcl_GetIntFromObj(interp, objv[4], (int *)&polypoints[1].x) != TCL_OK)
	    || (Tcl_GetIntFromObj(interp, objv[5], (int *)&polypoints[1].y) != TCL_OK)) {
	return TCL_ERROR;
    }




    objc -= 6;
    objv += 6;
    npoly = 2;

    while (objc >= 2) {
	/* Check for a number */
	x = strtoul(Tcl_GetString(objv[0]), &strend, 0);







|








>















|
|
|
|


>
>
>
>







1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
    POINT *polypoints;
    int npoly;
    int dosmooth = 0;
    int nStep = 12;
    int x, y;
    HDC hDC;
    HPEN hPen;
    double width = 0.0;
    COLORREF linecolor = 0, fillcolor = BS_NULL;
    int dolinecolor = 0, dofillcolor = 0;
    LOGBRUSH lbrush;
    HBRUSH hBrush = NULL;
    HGDIOBJ oldobj = NULL;

    int dodash = 0;
    const char *dashdata = 0;
    double p1x, p1y, p2x, p2y;

    /* Verrrrrry simple for now.... */
    if (objc < 6) {
	Tcl_AppendResult(interp, usage_message, (char *)NULL);
	return TCL_ERROR;
    }

    hDC = printDC;

    polypoints = (POINT *)attemptckalloc((objc - 1) * sizeof(POINT));
    if (polypoints == 0) {
	/* TODO: unreachable */
	Tcl_AppendResult(interp, "Out of memory in GdiLine", (char *)NULL);
	return TCL_ERROR;
    }
    if ((Tcl_GetDoubleFromObj(interp, objv[2], &p1x) != TCL_OK)
	    || (Tcl_GetDoubleFromObj(interp, objv[3], &p1y) != TCL_OK)
	    || (Tcl_GetDoubleFromObj(interp, objv[4], &p2x) != TCL_OK)
	    || (Tcl_GetDoubleFromObj(interp, objv[5], &p2y) != TCL_OK)) {
	return TCL_ERROR;
    }
    polypoints[0].x = floor(p1x + 0.5);
    polypoints[0].y = floor(p1y + 0.5);
    polypoints[1].x = floor(p2x + 0.5);
    polypoints[1].y = floor(p2y + 0.5);
    objc -= 6;
    objv += 6;
    npoly = 2;

    while (objc >= 2) {
	/* Check for a number */
	x = strtoul(Tcl_GetString(objv[0]), &strend, 0);
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
			return TCL_ERROR;
		    }
		}
	    } else if (strcmp(Tcl_GetString(objv[0]), "-stipple") == 0) {
		/* Not supported */
	    } else if (strcmp(Tcl_GetString(objv[0]), "-width") == 0) {
		if (Tcl_GetString(objv[1])) {
		    if (Tcl_GetIntFromObj(interp, objv[1], &width) != TCL_OK) {
			return TCL_ERROR;
		    }
		}
	    } else if (strcmp(Tcl_GetString(objv[0]), "-dash") == 0) {
		if (Tcl_GetString(objv[1])) {
		    dodash = 1;
		    dashdata = Tcl_GetString(objv[1]);







|







1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
			return TCL_ERROR;
		    }
		}
	    } else if (strcmp(Tcl_GetString(objv[0]), "-stipple") == 0) {
		/* Not supported */
	    } else if (strcmp(Tcl_GetString(objv[0]), "-width") == 0) {
		if (Tcl_GetString(objv[1])) {
		    if (Tcl_GetDoubleFromObj(interp, objv[1], &width) != TCL_OK) {
			return TCL_ERROR;
		    }
		}
	    } else if (strcmp(Tcl_GetString(objv[0]), "-dash") == 0) {
		if (Tcl_GetString(objv[1])) {
		    dodash = 1;
		    dashdata = Tcl_GetString(objv[1]);
1175
1176
1177
1178
1179
1180
1181
1182

1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
    if (width || dolinecolor) {
	GdiMakePen(interp, width, dodash, dashdata, 0, 0, 0, 0,
		linecolor, hDC, (HGDIOBJ *)&hPen);
    }

    if (dosmooth) {
	int nbpoints;
	POINT *bpoints = 0;

	nbpoints = Bezierize(polypoints,npoly,nStep,bpoints);
	if (nbpoints > 0) {
	    Polygon(hDC, bpoints, nbpoints);
	} else {
	    Polygon(hDC, polypoints, npoly);
	}
	if (bpoints != 0) {
	    ckfree(bpoints);
	}
    } else {
	Polygon(hDC, polypoints, npoly);
    }

    if (width || dolinecolor) {







|
>
|





|







1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
    if (width || dolinecolor) {
	GdiMakePen(interp, width, dodash, dashdata, 0, 0, 0, 0,
		linecolor, hDC, (HGDIOBJ *)&hPen);
    }

    if (dosmooth) {
	int nbpoints;
	POINT *bpoints = NULL;

	nbpoints = Bezierize(polypoints, npoly, nStep, &bpoints);
	if (nbpoints > 0) {
	    Polygon(hDC, bpoints, nbpoints);
	} else {
	    Polygon(hDC, polypoints, npoly);
	}
	if (bpoints) {
	    ckfree(bpoints);
	}
    } else {
	Polygon(hDC, polypoints, npoly);
    }

    if (width || dolinecolor) {
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
    Tcl_Obj *const *objv)
{
    static const char usage_message[] =
	"::tk::print::_gdi rectangle hdc x1 y1 x2 y2 "
	"-fill color -outline color "
	"-stipple bitmap -width linewid";

    int x1, y1, x2, y2;
    HDC hDC;
    HPEN hPen;
    int width = 0;
    COLORREF linecolor = 0, fillcolor = BS_NULL;
    int dolinecolor = 0, dofillcolor = 0;
    LOGBRUSH lbrush;
    HBRUSH hBrush = NULL;
    HGDIOBJ oldobj = NULL;

    int dodash = 0;
    const char *dashdata = 0;

    /* Verrrrrry simple for now.... */
    if (objc < 6) {
	Tcl_AppendResult(interp, usage_message, (char *)NULL);
	return TCL_ERROR;
    }

    hDC = printDC;

    if ((Tcl_GetIntFromObj(interp, objv[2], &x1) != TCL_OK)
	    || (Tcl_GetIntFromObj(interp, objv[3], &y1) != TCL_OK)
	    || (Tcl_GetIntFromObj(interp, objv[4], &x2) != TCL_OK)
	    || (Tcl_GetIntFromObj(interp, objv[5], &y2) != TCL_OK)) {
	return TCL_ERROR;
    }
    if (x1 > x2) {
	int x3 = x1;
	x1 = x2;
	x2 = x3;
    }
    if (y1 > y2) {
	int y3 = y1;
	y1 = y2;
	y2 = y3;
    }
    objc -= 6;
    objv += 6;

    /* Now handle any other arguments that occur. */
    while (objc > 1) {
	if (strcmp(Tcl_GetString(objv[0]), "-fill") == 0) {
	    if (Tcl_GetString(objv[1]) && GdiGetColor(objv[1], &fillcolor)) {
		dofillcolor = 1;
	    }
	} else if (strcmp(Tcl_GetString(objv[0]), "-outline") == 0) {
	    if (Tcl_GetString(objv[1]) && GdiGetColor(objv[1], &linecolor)) {
		dolinecolor = 1;
	    }
	} else if (strcmp(Tcl_GetString(objv[0]), "-stipple") == 0) {
	    /* Not supported; ignored */
	} else if (strcmp(Tcl_GetString(objv[0]), "-width") == 0) {
	    if (Tcl_GetString(objv[1])) {
		if (Tcl_GetIntFromObj(interp, objv[1], &width) != TCL_OK) {
		    return TCL_ERROR;
		}
	    }
	} else if (strcmp(Tcl_GetString(objv[0]), "-dash") == 0) {
	    if (Tcl_GetString(objv[1])) {
		dodash = 1;
		dashdata = Tcl_GetString(objv[1]);







|


|

















|
|
|
|



|




|




















|







1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
    Tcl_Obj *const *objv)
{
    static const char usage_message[] =
	"::tk::print::_gdi rectangle hdc x1 y1 x2 y2 "
	"-fill color -outline color "
	"-stipple bitmap -width linewid";

    double x1, y1, x2, y2;
    HDC hDC;
    HPEN hPen;
    double width = 0.0;
    COLORREF linecolor = 0, fillcolor = BS_NULL;
    int dolinecolor = 0, dofillcolor = 0;
    LOGBRUSH lbrush;
    HBRUSH hBrush = NULL;
    HGDIOBJ oldobj = NULL;

    int dodash = 0;
    const char *dashdata = 0;

    /* Verrrrrry simple for now.... */
    if (objc < 6) {
	Tcl_AppendResult(interp, usage_message, (char *)NULL);
	return TCL_ERROR;
    }

    hDC = printDC;

    if ((Tcl_GetDoubleFromObj(interp, objv[2], &x1) != TCL_OK)
	    || (Tcl_GetDoubleFromObj(interp, objv[3], &y1) != TCL_OK)
	    || (Tcl_GetDoubleFromObj(interp, objv[4], &x2) != TCL_OK)
	    || (Tcl_GetDoubleFromObj(interp, objv[5], &y2) != TCL_OK)) {
	return TCL_ERROR;
    }
    if (x1 > x2) {
	double x3 = x1;
	x1 = x2;
	x2 = x3;
    }
    if (y1 > y2) {
	double y3 = y1;
	y1 = y2;
	y2 = y3;
    }
    objc -= 6;
    objv += 6;

    /* Now handle any other arguments that occur. */
    while (objc > 1) {
	if (strcmp(Tcl_GetString(objv[0]), "-fill") == 0) {
	    if (Tcl_GetString(objv[1]) && GdiGetColor(objv[1], &fillcolor)) {
		dofillcolor = 1;
	    }
	} else if (strcmp(Tcl_GetString(objv[0]), "-outline") == 0) {
	    if (Tcl_GetString(objv[1]) && GdiGetColor(objv[1], &linecolor)) {
		dolinecolor = 1;
	    }
	} else if (strcmp(Tcl_GetString(objv[0]), "-stipple") == 0) {
	    /* Not supported; ignored */
	} else if (strcmp(Tcl_GetString(objv[0]), "-width") == 0) {
	    if (Tcl_GetString(objv[1])) {
		if (Tcl_GetDoubleFromObj(interp, objv[1], &width) != TCL_OK) {
		    return TCL_ERROR;
		}
	    }
	} else if (strcmp(Tcl_GetString(objv[0]), "-dash") == 0) {
	    if (Tcl_GetString(objv[1])) {
		dodash = 1;
		dashdata = Tcl_GetString(objv[1]);
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
		0, 0, 0, 0, linecolor, hDC, (HGDIOBJ *)&hPen);
    }
    /*
     * Per Win32, Rectangle includes lower and right edges--per Tcl8.3.2 and
     * earlier documentation, canvas rectangle does not. Thus, add 1 to
     * right and lower bounds to get appropriate behavior.
     */
    Rectangle(hDC, x1, y1, x2+1, y2+1);

    if (width || dolinecolor) {
	GdiFreePen(interp, hDC, hPen);
    }
    if (hBrush) {
	GdiFreeBrush(interp, hDC, hBrush);
    } else {







|







1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
		0, 0, 0, 0, linecolor, hDC, (HGDIOBJ *)&hPen);
    }
    /*
     * Per Win32, Rectangle includes lower and right edges--per Tcl8.3.2 and
     * earlier documentation, canvas rectangle does not. Thus, add 1 to
     * right and lower bounds to get appropriate behavior.
     */
    Rectangle(hDC, floor(x1+0.5), floor(y1+0.5), floor(x2+1.5), floor(y2+1.5));

    if (width || dolinecolor) {
	GdiFreePen(interp, hDC, hPen);
    }
    if (hBrush) {
	GdiFreeBrush(interp, hDC, hBrush);
    } else {
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
	"::tk::print::_gdi text hdc x y -anchor [center|n|e|s|w] "
	"-fill color -font fontname "
	"-justify [left|right|center] "
	"-stipple bitmap -text string -width linelen "
	"-single -backfill";

    HDC hDC;
    int x, y;
    const char *string = 0;
    RECT sizerect;
    UINT format_flags = DT_EXPANDTABS|DT_NOPREFIX; /* Like the canvas. */
    Tk_Anchor anchor = TK_ANCHOR_N;
    LOGFONTW lf;
    HFONT hfont;
    HGDIOBJ oldfont;







|







1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
	"::tk::print::_gdi text hdc x y -anchor [center|n|e|s|w] "
	"-fill color -font fontname "
	"-justify [left|right|center] "
	"-stipple bitmap -text string -width linelen "
	"-single -backfill";

    HDC hDC;
    double x, y;
    const char *string = 0;
    RECT sizerect;
    UINT format_flags = DT_EXPANDTABS|DT_NOPREFIX; /* Like the canvas. */
    Tk_Anchor anchor = TK_ANCHOR_N;
    LOGFONTW lf;
    HFONT hfont;
    HGDIOBJ oldfont;
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
	return TCL_ERROR;
    }

    /* Parse the command. */

    hDC = printDC;

    if ((Tcl_GetIntFromObj(interp, objv[2], &x) != TCL_OK)
	    || (Tcl_GetIntFromObj(interp, objv[3], &y) != TCL_OK)) {
	return TCL_ERROR;
    }
    objc -= 4;
    objv += 4;

    sizerect.left = sizerect.right = x;
    sizerect.top = sizerect.bottom = y;

    while (objc > 0) {
	if (strcmp(Tcl_GetString(objv[0]), "-anchor") == 0) {
	    objc--;
	    objv++;
	    if (objc > 0) {
		Tk_GetAnchor(interp, Tcl_GetString(objv[0]), &anchor);







|
|





|
|







1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
	return TCL_ERROR;
    }

    /* Parse the command. */

    hDC = printDC;

    if ((Tcl_GetDoubleFromObj(interp, objv[2], &x) != TCL_OK)
	    || (Tcl_GetDoubleFromObj(interp, objv[3], &y) != TCL_OK)) {
	return TCL_ERROR;
    }
    objc -= 4;
    objv += 4;

    sizerect.left = sizerect.right = floor(x+0.5);
    sizerect.top = sizerect.bottom = floor(y+0.5);

    while (objc > 0) {
	if (strcmp(Tcl_GetString(objv[0]), "-anchor") == 0) {
	    objc--;
	    objv++;
	    if (objc > 0) {
		Tk_GetAnchor(interp, Tcl_GetString(objv[0]), &anchor);
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
 *	Sets rendering pen.
 *
 *----------------------------------------------------------------------
 */

static int GdiMakePen(
    Tcl_Interp *interp,
    int width,
    int dashstyle,
    const char *dashstyledata,
    TCL_UNUSED(int),		/* Ignored for now. */
    TCL_UNUSED(int),		/* Ignored for now. */
    TCL_UNUSED(int),
    TCL_UNUSED(const char *),	/* Ignored for now. */
    unsigned long color,







|







2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
 *	Sets rendering pen.
 *
 *----------------------------------------------------------------------
 */

static int GdiMakePen(
    Tcl_Interp *interp,
    double dwidth,
    int dashstyle,
    const char *dashstyledata,
    TCL_UNUSED(int),		/* Ignored for now. */
    TCL_UNUSED(int),		/* Ignored for now. */
    TCL_UNUSED(int),
    TCL_UNUSED(const char *),	/* Ignored for now. */
    unsigned long color,
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
     *
     * It seems that converting to ExtCreatePen may be more advantageous, as
     * it matches the Tk canvas pens much better--but not for Win95, which
     * does not support PS_USERSTYLE. An explicit test (or storage in a static
     * after first failure) may suffice for working around this. The
     * ExtCreatePen is not supported at all under Win32.
     */

    HPEN hPen;
    LOGBRUSH lBrush;
    DWORD pStyle = PS_SOLID;           /* -dash should override*/
    DWORD endStyle = PS_ENDCAP_ROUND;  /* -capstyle should override. */
    DWORD joinStyle = PS_JOIN_ROUND;   /* -joinstyle should override. */
    DWORD styleCount = 0;
    DWORD *styleArray = 0;







|







2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
     *
     * It seems that converting to ExtCreatePen may be more advantageous, as
     * it matches the Tk canvas pens much better--but not for Win95, which
     * does not support PS_USERSTYLE. An explicit test (or storage in a static
     * after first failure) may suffice for working around this. The
     * ExtCreatePen is not supported at all under Win32.
     */
    int width = floor(dwidth + 0.5);
    HPEN hPen;
    LOGBRUSH lBrush;
    DWORD pStyle = PS_SOLID;           /* -dash should override*/
    DWORD endStyle = PS_ENDCAP_ROUND;  /* -capstyle should override. */
    DWORD joinStyle = PS_JOIN_ROUND;   /* -joinstyle should override. */
    DWORD styleCount = 0;
    DWORD *styleArray = 0;
3630
3631
3632
3633
3634
3635
3636


















3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647



3648
3649
3650
3651
3652
3653
3654

3655
3656

3657
3658

3659
3660

3661
3662

3663
3664


3665
3666
3667
3668
3669
3670
3671
	    paper_width = (int) localDevmode->dmPaperWidth / 0.254;
	    copies = pd.nCopies;
	    /* Set device context here for all GDI printing operations. */
	    printDC = CreateDCW(L"WINSPOOL", printerName, NULL, localDevmode);
	} else {
	    localDevmode = NULL;
	}


















    }

    if (pd.hDevMode != NULL) {
	GlobalFree(pd.hDevMode);
    }

    /*
     * Store print properties and link variables so they can be accessed from
     * script level.
     */
    if (localPrinterName != NULL) {



	char* varlink1 = (char*)ckalloc(100 * sizeof(char));
	char** varlink2 = (char**)ckalloc(sizeof(char*));
	*varlink2 = varlink1;
	WideCharToMultiByte(CP_UTF8, 0, localPrinterName, -1, varlink1, 0, NULL, NULL);

	Tcl_LinkVar(interp, "::tk::print::printer_name", varlink2,
	    TCL_LINK_STRING | TCL_LINK_READ_ONLY);

	Tcl_LinkVar(interp, "::tk::print::copies", &copies,
	    TCL_LINK_INT | TCL_LINK_READ_ONLY);

	Tcl_LinkVar(interp, "::tk::print::dpi_x", &dpi_x,
	    TCL_LINK_INT | TCL_LINK_READ_ONLY);

	Tcl_LinkVar(interp, "::tk::print::dpi_y", &dpi_y,
	    TCL_LINK_INT | TCL_LINK_READ_ONLY);

	Tcl_LinkVar(interp, "::tk::print::paper_width", &paper_width,
	    TCL_LINK_INT | TCL_LINK_READ_ONLY);

	Tcl_LinkVar(interp, "::tk::print::paper_height", &paper_height,
	    TCL_LINK_INT | TCL_LINK_READ_ONLY);


    }

    return TCL_OK;
}

/*
 * --------------------------------------------------------------------------







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







|



>
>
>
|
|
<
|
|
|
<
>
|
<
>
|
<
>
|
<
>
|
<
>
|
<
>
>







3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681

3682
3683
3684

3685
3686

3687
3688

3689
3690

3691
3692

3693
3694

3695
3696
3697
3698
3699
3700
3701
3702
3703
	    paper_width = (int) localDevmode->dmPaperWidth / 0.254;
	    copies = pd.nCopies;
	    /* Set device context here for all GDI printing operations. */
	    printDC = CreateDCW(L"WINSPOOL", printerName, NULL, localDevmode);
	} else {
	    localDevmode = NULL;
	}
    } else {
	unsigned int errorcode = CommDlgExtendedError();

	/*
	 * The user cancelled, or there was an error
	 * The code on the Tcl side checks if the variable
	 * ::tk::print::printer_name is defined to determine
	 * that a valid selection was made.
	 * So we better unset this here, unconditionally.
	 */
	Tcl_UnsetVar(interp, "::tk::print::printer_name", 0);
	if (errorcode != 0) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf("print failed: error %04x",
		    errorcode));
	    Tcl_SetErrorCode(interp, "TK", "PRINT", "DIALOG", (char*)NULL);
	    return TCL_ERROR;
	}
	return TCL_OK;
    }

    if (pd.hDevMode != NULL) {
	GlobalFree(pd.hDevMode);
    }

    /*
     * Store print properties in variables so they can be accessed from
     * script level.
     */
    if (localPrinterName != NULL) {
	char *prname;
	int size_needed = WideCharToMultiByte(CP_UTF8, 0, localPrinterName,
		-1, NULL, 0, NULL, NULL);

	prname = (char*)ckalloc(size_needed);

	WideCharToMultiByte(CP_UTF8, 0, localPrinterName, -1, prname,
		size_needed, NULL, NULL);
	Tcl_SetVar2Ex(interp, "::tk::print::printer_name", NULL,

		Tcl_NewStringObj(prname, size_needed - 1), 0);
	Tcl_SetVar2Ex(interp, "::tk::print::copies", NULL,

		Tcl_NewIntObj(copies), 0);
	Tcl_SetVar2Ex(interp, "::tk::print::dpi_x", NULL,

		Tcl_NewIntObj(dpi_x), 0);
	Tcl_SetVar2Ex(interp, "::tk::print::dpi_y", NULL,

		Tcl_NewIntObj(dpi_y), 0);
	Tcl_SetVar2Ex(interp, "::tk::print::paper_width", NULL,

		Tcl_NewIntObj(paper_width), 0);
	Tcl_SetVar2Ex(interp, "::tk::print::paper_height", NULL,

		Tcl_NewIntObj(paper_height), 0);
	ckfree(prname);
    }

    return TCL_OK;
}

/*
 * --------------------------------------------------------------------------
Changes to win/tkWinInt.h.
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
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#ifndef _TKWININT
#define _TKWININT

#ifndef _TKINT
#include "tkInt.h"
#endif

/*
 * Include platform specific public interfaces.


 */

#ifndef _TKWIN
#include "tkWin.h"
#endif





/*
 * Define constants missing from older Win32 SDK header files.
 */

#ifndef WS_EX_TOOLWINDOW
#define WS_EX_TOOLWINDOW	0x00000080L







<
<
<
<

|
>
>





>
>
>
>







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
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#ifndef _TKWININT
#define _TKWININT





/*
 * Include platform specific public interfaces as the very first step. This is
 * necessary because definitions provided by subsequent header files depend on
 * the interface versions defined in tkWin.h
 */

#ifndef _TKWIN
#include "tkWin.h"
#endif

#ifndef _TKINT
#include "tkInt.h"
#endif

/*
 * Define constants missing from older Win32 SDK header files.
 */

#ifndef WS_EX_TOOLWINDOW
#define WS_EX_TOOLWINDOW	0x00000080L