Skip to content

Commit 625d14f

Browse files
author
culler
committed
Add a non-regression test, which turns out to require considerable extra machinery.
1 parent 04fb6e0 commit 625d14f

File tree

5 files changed

+76
-2
lines changed

5 files changed

+76
-2
lines changed

macosx/tkMacOSXDialog.c

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,41 @@ static filepanelFilterInfo filterInfo;
8787
static NSOpenPanel *openpanel;
8888
static NSSavePanel *savepanel;
8989

90+
/*
91+
* A thread which closes the currently running modal dialog after a timeout.
92+
*/
93+
94+
@interface TKPanelMonitor: NSThread {
95+
@private
96+
NSTimeInterval _timeout;
97+
}
98+
99+
- (id) initWithTimeout: (NSTimeInterval) timeout;
100+
101+
@end
102+
103+
@implementation TKPanelMonitor: NSThread
104+
105+
- (id) initWithTimeout: (NSTimeInterval) timeout {
106+
self = [super init];
107+
if (self) {
108+
_timeout = timeout;
109+
return self;
110+
}
111+
return self;
112+
}
113+
114+
- (void) main
115+
{
116+
[NSThread sleepForTimeInterval:_timeout];
117+
if ([self isCancelled]) {
118+
[NSThread exit];
119+
}
120+
[NSApp stopModalWithCode:modalCancel];
121+
}
122+
@end
123+
124+
90125
static const char *const colorOptionStrings[] = {
91126
"-initialcolor", "-parent", "-title", NULL
92127
};
@@ -870,7 +905,20 @@ Tk_GetOpenFileObjCmd(
870905
parent = nil;
871906
parentIsKey = False;
872907
}
873-
modalReturnCode = showOpenSavePanel(openpanel, parent, interp, cmdObj, multiple);
908+
TKPanelMonitor *monitor;
909+
if (testsAreRunning) {
910+
/*
911+
* We need the panel to close by itself when running tests.
912+
*/
913+
914+
monitor = [[TKPanelMonitor alloc] initWithTimeout: 1.0];
915+
[monitor start];
916+
}
917+
modalReturnCode = showOpenSavePanel(openpanel, parent, interp, cmdObj,
918+
multiple);
919+
if (testsAreRunning) {
920+
[monitor cancel];
921+
}
874922
if (cmdObj) {
875923
Tcl_DecrRefCount(cmdObj);
876924
}

macosx/tkMacOSXInit.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@
2121
#include <sys/stat.h>
2222
#include <sys/utsname.h>
2323

24+
/*
25+
* This flag is set if tests are being run.
26+
*/
27+
28+
int testsAreRunning = 0;
29+
2430
static char tkLibPath[PATH_MAX + 1] = "";
2531

2632
/*
@@ -45,6 +51,7 @@ static Tcl_ObjCmdProc TkMacOSVersionObjCmd;
4551
@synthesize tkLiveResizeEnded = _tkLiveResizeEnded;
4652
@synthesize tkWillExit = _tkWillExit;
4753
@synthesize tkPointerWindow = _tkPointerWindow;
54+
;
4855
- (void) setTkPointerWindow: (TkWindow *)winPtr
4956
{
5057
if (winPtr) {

macosx/tkMacOSXPrivate.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,12 @@
134134
STRINGIFY(symbol)); \
135135
}
136136

137+
/*
138+
* This is set to 1 if tests are being run. Defined in tkMacOSXInit.c.
139+
*/
140+
141+
extern int testsAreRunning;
142+
137143
/*
138144
* The structure of a 32-bit XEvent keycode on macOS. It may be viewed as
139145
* an unsigned int or as having either two or three bitfields.

macosx/tkMacOSXTest.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "tkMacOSXConstants.h"
1717
#include "tkMacOSXWm.h"
1818

19-
2019
/*
2120
* Forward declarations of procedures defined later in this file:
2221
*/
@@ -48,6 +47,12 @@ int
4847
TkplatformtestInit(
4948
Tcl_Interp *interp) /* Interpreter to add commands to. */
5049
{
50+
/*
51+
* Set a flag indicating that testing is in progress.
52+
*/
53+
54+
testsAreRunning = 1;
55+
5156
/*
5257
* Add commands for platform specific tests on MacOS here.
5358
*/

tests/filebox.test

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ test fileDialog-0.2 {GetFileName: file types: MakeFilter() fails} {
2323
regsub -all "\0" $msg {\\0} msg
2424
list $x $msg
2525
} {1 {bad Macintosh file type "\0\0"}}
26+
test fileDialog-0.3 {GetFileName: file types: bad filetype} {
27+
# Check for the crash reported in ticket 080a28104.
28+
29+
set filename [tk_getOpenFile -filetypes {
30+
{"Invalid extension" {x.y}}
31+
{"All files" {*}}
32+
}]
33+
} {}
2634

2735
set tk_strictMotif_old $tk_strictMotif
2836

0 commit comments

Comments
 (0)