ObjFW  Diff

Differences From Artifact [6be1a5b957]:

To Artifact [e6328e2572]:


16
17
18
19
20
21
22

23
24
25
26
27
28
29

#include "config.h"

#include <string.h>

#import "OFStream.h"
#import "OFString.h"

#import "OFAutoreleasePool.h"

#import "TestsAppDelegate.h"

static OFString *module = @"OFStream";

@interface StreamTester: OFStream







>







16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

#include "config.h"

#include <string.h>

#import "OFStream.h"
#import "OFString.h"
#import "OFSystemInfo.h"
#import "OFAutoreleasePool.h"

#import "TestsAppDelegate.h"

static OFString *module = @"OFStream";

@interface StreamTester: OFStream
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
{
	return (state > 1 ? YES : NO);
}

- (size_t)lowlevelReadIntoBuffer: (void*)buffer
			  length: (size_t)size
{


	switch (state) {
	case 0:
		if (size < 1)
			return 0;

		memcpy(buffer, "f", 1);

		state++;
		return 1;
	case 1:
		if (size < of_pagesize)
			return 0;

		memcpy(buffer, "oo\n", 3);
		memset((char*)buffer + 3, 'X', of_pagesize - 3);

		state++;
		return of_pagesize;
	}

	return 0;
}
@end

@implementation TestsAppDelegate (OFStreamTests)
- (void)streamTests
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];

	StreamTester *t = [[[StreamTester alloc] init] autorelease];
	OFString *str;
	char *cstr;

	cstr = [t allocMemoryWithSize: of_pagesize - 2];
	memset(cstr, 'X', of_pagesize - 3);
	cstr[of_pagesize - 3] = '\0';

	TEST(@"-[readLine]", [[t readLine] isEqual: @"foo"] &&
	    [(str = [t readLine]) length] == of_pagesize - 3 &&
	    !strcmp([str UTF8String], cstr))

	[pool drain];
}
@end







>
>










|



|


|










>




|
|
|


|





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
{
	return (state > 1 ? YES : NO);
}

- (size_t)lowlevelReadIntoBuffer: (void*)buffer
			  length: (size_t)size
{
	size_t pageSize = [OFSystemInfo pageSize];

	switch (state) {
	case 0:
		if (size < 1)
			return 0;

		memcpy(buffer, "f", 1);

		state++;
		return 1;
	case 1:
		if (size < pageSize)
			return 0;

		memcpy(buffer, "oo\n", 3);
		memset((char*)buffer + 3, 'X', pageSize - 3);

		state++;
		return pageSize;
	}

	return 0;
}
@end

@implementation TestsAppDelegate (OFStreamTests)
- (void)streamTests
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	size_t pageSize = [OFSystemInfo pageSize];
	StreamTester *t = [[[StreamTester alloc] init] autorelease];
	OFString *str;
	char *cstr;

	cstr = [t allocMemoryWithSize: pageSize - 2];
	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))

	[pool drain];
}
@end