2011-02-16 08:21:17 +00:00
|
|
|
#import <Foundation/NSAutoreleasePool.h>
|
|
|
|
#import <Foundation/NSTask.h>
|
|
|
|
#import <Foundation/NSFileManager.h>
|
|
|
|
#import <Foundation/NSProcessInfo.h>
|
|
|
|
#import <Foundation/NSBundle.h>
|
|
|
|
#import "ObjectTesting.h"
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
|
|
|
NSFileManager *mgr;
|
|
|
|
NSString *helpers;
|
2022-08-05 10:54:36 +00:00
|
|
|
NSString *testecho;
|
|
|
|
NSString *testcat;
|
2011-02-16 08:21:17 +00:00
|
|
|
NSArray *args;
|
|
|
|
id task;
|
|
|
|
id info;
|
|
|
|
id env;
|
|
|
|
id pth1;
|
|
|
|
id pth2;
|
|
|
|
BOOL yes;
|
|
|
|
|
2024-10-10 09:16:47 +00:00
|
|
|
/* Windows Compiler add the '.exe' suffix to executables
|
2022-08-05 10:54:36 +00:00
|
|
|
*/
|
2024-10-10 09:16:47 +00:00
|
|
|
#if defined(_WIN32)
|
2022-08-05 10:54:36 +00:00
|
|
|
testecho = @"testecho.exe";
|
|
|
|
testcat = @"testcat.exe";
|
|
|
|
#else
|
|
|
|
testecho = @"testecho";
|
|
|
|
testcat = @"testcat";
|
|
|
|
#endif
|
|
|
|
|
2011-02-16 08:21:17 +00:00
|
|
|
info = [NSProcessInfo processInfo];
|
|
|
|
env = [[info environment] mutableCopy];
|
|
|
|
yes = YES;
|
|
|
|
|
|
|
|
PASS(info != nil && [info isKindOfClass: [NSProcessInfo class]]
|
|
|
|
&& env != nil && [env isKindOfClass: [NSMutableDictionary class]]
|
|
|
|
&& yes == YES,
|
|
|
|
"We can build some objects for task tests");
|
|
|
|
|
|
|
|
mgr = [NSFileManager defaultManager];
|
|
|
|
helpers = [mgr currentDirectoryPath];
|
|
|
|
helpers = [helpers stringByAppendingPathComponent: @"Helpers"];
|
|
|
|
helpers = [helpers stringByAppendingPathComponent: @"obj"];
|
|
|
|
|
2022-08-05 10:54:36 +00:00
|
|
|
pth1 = [helpers stringByAppendingPathComponent: testcat];
|
|
|
|
pth2 = [helpers stringByAppendingPathComponent: testecho];
|
2011-02-16 08:21:17 +00:00
|
|
|
|
|
|
|
/* Try some tasks. Make sure the program we use is common between Unix
|
|
|
|
and Windows (and others?) */
|
|
|
|
task = [NSTask launchedTaskWithLaunchPath: pth1
|
|
|
|
arguments: [NSArray array]];
|
|
|
|
[task waitUntilExit];
|
|
|
|
PASS(YES, "launchedTaskWithLaunchPath:arguments: works");
|
|
|
|
|
|
|
|
task = [NSTask new];
|
|
|
|
args = [NSArray arrayWithObjects: @"xxx", @"yyy", nil];
|
|
|
|
[task setEnvironment: env];
|
|
|
|
[task setLaunchPath: pth2];
|
|
|
|
[task setArguments: args];
|
|
|
|
[task launch];
|
|
|
|
[task waitUntilExit];
|
2016-06-26 05:56:10 +00:00
|
|
|
PASS([task terminationReason] == NSTaskTerminationReasonExit,
|
|
|
|
"termination reason for normal exit works");
|
2011-02-16 08:21:17 +00:00
|
|
|
|
|
|
|
[arp release]; arp = nil;
|
|
|
|
return 0;
|
|
|
|
}
|