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
|
/*
* Copyright (c) 2008-2021 Jonathan Schleifer <js@nil.im>
*
* All rights reserved.
*
* This file is part of ObjFW. It may be distributed under the terms of the
* Q Public License 1.0, which can be found in the file LICENSE.QPL included in
* the packaging of this file.
*
* Alternatively, it may be distributed under the terms of the GNU General
* 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 *module = @"OFStream";
@interface StreamTester: OFStream
{
int state;
}
@end
@implementation StreamTester
- (bool)lowlevelIsAtEndOfStream
{
return (state > 1);
}
- (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)size
{
|
|
|
|
|
|
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
|
/*
* Copyright (c) 2008-2022 Jonathan Schleifer <js@nil.im>
*
* All rights reserved.
*
* This file is part of ObjFW. It may be distributed under the terms of the
* Q Public License 1.0, which can be found in the file LICENSE.QPL included in
* the packaging of this file.
*
* Alternatively, it may be distributed under the terms of the GNU General
* 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 = @"OFStream";
@interface StreamTest: OFStream
{
int state;
}
@end
@implementation StreamTest
- (bool)lowlevelIsAtEndOfStream
{
return (state > 1);
}
- (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)size
{
|
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
@end
@implementation TestsAppDelegate (OFStreamTests)
- (void)streamTests
{
void *pool = objc_autoreleasePoolPush();
size_t pageSize = [OFSystemInfo pageSize];
StreamTester *t = [[[StreamTester alloc] init] autorelease];
OFString *str;
char *cstr;
cstr = OFAllocMemory(pageSize - 2, 1);
memset(cstr, 'X', pageSize - 3);
cstr[pageSize - 3] = '\0';
TEST(@"-[readLine]", [[t readLine] isEqual: @"foo"] &&
[(str = [t readLine]) length] == pageSize - 3 &&
!strcmp(str.UTF8String, cstr))
OFFreeMemory(cstr);
objc_autoreleasePoolPop(pool);
}
@end
|
|
|
|
|
|
|
>
>
>
|
|
|
|
|
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
|
@end
@implementation TestsAppDelegate (OFStreamTests)
- (void)streamTests
{
void *pool = objc_autoreleasePoolPush();
size_t pageSize = [OFSystemInfo pageSize];
StreamTest *test = [[[StreamTest alloc] init] autorelease];
OFString *string;
char *cString;
cString = OFAllocMemory(pageSize - 2, 1);
memset(cString, 'X', pageSize - 3);
cString[pageSize - 3] = '\0';
TEST(@"-[readLine] #1", [[test readLine] isEqual: @"foo"])
string = [test readLine];
TEST(@"-[readLine] #2", string != nil &&
string.length == pageSize - 3 &&
!strcmp(string.UTF8String, cString))
OFFreeMemory(cString);
objc_autoreleasePoolPop(pool);
}
@end
|