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
|
* Public License, either version 2 or 3, which can be found in the file
* LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
* file.
*/
#include "config.h"
#import "TestsAppDelegate.h"
static OFString *const module = @"OFSubprocess";
@implementation TestsAppDelegate (OFSubprocessTests)
- (void)subprocessTests
{
void *pool = objc_autoreleasePoolPush();
#ifdef OF_HAVE_FILES
OFString *program = [@"subprocess" stringByAppendingPathComponent:
@"subprocess" @PROG_SUFFIX];
#else
OFString *program = @"subprocess/subprocess" @PROG_SUFFIX;
#endif
OFArray *arguments = [OFArray arrayWithObjects: @"tést", @"123", nil];
OFMutableDictionary *environment =
[[[OFApplication environment] mutableCopy] autorelease];
OFSubprocess *subprocess;
[environment setObject: @"yés" forKey: @"tëst"];
TEST(@"+[subprocessWithProgram:programName:arguments:environment]",
(subprocess =
[OFSubprocess subprocessWithProgram: program
programName: program
arguments: arguments
environment: environment]))
TEST(@"Standard input", R([subprocess writeLine: @"Hellö world!"]))
TEST(@"Standard output",
[[subprocess readLine] isEqual: @"HELLÖ WORLD!"])
TEST(@"-[closeForWriting]", R([subprocess closeForWriting]))
TEST(@"-[waitForTermination]", [subprocess waitForTermination] == 0)
objc_autoreleasePoolPop(pool);
}
@end
|
|
>
|
>
|
|
<
<
<
|
|
|
|
|
<
<
|
|
|
|
<
<
|
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
|
* Public License, either version 2 or 3, which can be found in the file
* LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
* file.
*/
#include "config.h"
#import "ObjFW.h"
#import "ObjFWTest.h"
@interface OFSubprocessTests: OTTestCase
@end
@implementation OFSubprocessTests
- (void)testSubprocess
{
#ifdef OF_HAVE_FILES
OFString *program = [@"subprocess" stringByAppendingPathComponent:
@"subprocess" @PROG_SUFFIX];
#else
OFString *program = @"subprocess/subprocess" @PROG_SUFFIX;
#endif
OFArray *arguments = [OFArray arrayWithObjects: @"tést", @"123", nil];
OFMutableDictionary *environment =
[[[OFApplication environment] mutableCopy] autorelease];
OFSubprocess *subprocess;
[environment setObject: @"yés" forKey: @"tëst"];
subprocess = [OFSubprocess subprocessWithProgram: program
programName: program
arguments: arguments
environment: environment];
[subprocess writeLine: @"Hellö world!"];
OTAssertEqualObjects([subprocess readLine], @"HELLÖ WORLD!");
[subprocess closeForWriting];
OTAssertEqual([subprocess waitForTermination], 0);
}
@end
|