ObjFW  Check-in [aa3e784dd8]

Overview
Comment:Add tests for OFStream.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: aa3e784dd81a1566825ccffefb8fc267830b635d90b3354cb0ffa6591ddf2172
User & Date: js on 2010-03-13 21:27:27
Other Links: manifest | tags
Context
2010-03-13
22:27
Add -[{and,or,xor,shiftLeft,shiftRight}:] to OFNumber. check-in: a57d46cb3b user: js tags: trunk
21:27
Add tests for OFStream. check-in: aa3e784dd8 user: js tags: trunk
21:24
Add global variable of_pagesize and use it to reduce code duplication. check-in: 382ed34d40 user: js tags: trunk
Changes

Modified tests/Makefile from [d8581cadf1] to [83972f22ab].

1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
include ../extra.mk

SUBDIRS = ${TESTPLUGIN}

PROG_NOINST = tests${PROG_SUFFIX}
SRCS = OFArray.m	\
       OFDataArray.m	\
       OFDictionary.m	\
       OFHashes.m	\
       OFList.m		\
       OFNumber.m	\
       OFObject.m	\
       ${OFPLUGIN_M}	\

       OFString.m	\
       OFTCPSocket.m	\
       ${OFTHREAD_M}	\
       OFXMLElement.m	\
       OFXMLParser.m	\
       main.m		\
       ${PROPERTIES_M}













>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
include ../extra.mk

SUBDIRS = ${TESTPLUGIN}

PROG_NOINST = tests${PROG_SUFFIX}
SRCS = OFArray.m	\
       OFDataArray.m	\
       OFDictionary.m	\
       OFHashes.m	\
       OFList.m		\
       OFNumber.m	\
       OFObject.m	\
       ${OFPLUGIN_M}	\
       OFStream.m	\
       OFString.m	\
       OFTCPSocket.m	\
       ${OFTHREAD_M}	\
       OFXMLElement.m	\
       OFXMLParser.m	\
       main.m		\
       ${PROPERTIES_M}

Added tests/OFStream.m version [eef8cfeb9a].































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
36
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
/*
 * Copyright (c) 2008 - 2010
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * 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 included in
 * the packaging of this file.
 */

#include "config.h"

#include <string.h>

#import "OFStream.h"
#import "OFAutoreleasePool.h"

#import "main.h"

static OFString *module = @"OFStream";

@interface StreamTester: OFStream
{
	int state;
}
@end

@implementation StreamTester
- (BOOL)atEndOfStreamWithoutCache
{
	return (state > 1 ? YES : NO);
}

- (size_t)readNBytesWithoutCache: (size_t)size
		      intoBuffer: (char*)buf
{
	switch (state) {
	case 0:
		if (size < 1)
			return 0;

		memcpy(buf, "f", 1);

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

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

		state++;
		return of_pagesize;
	}

	return 0;
}
@end

void
stream_tests()
{
	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 cString], cstr))

	[pool drain];
}

Modified tests/main.m from [b7276b4531] to [ff9398bf83].

28
29
30
31
32
33
34

35
36
37
38
39
40
41
extern void object_tests();
#ifdef OF_PLUGINS
extern void plugin_tests();
#endif
#ifdef OF_HAVE_PROPERTIES
extern void properties_tests();
#endif

extern void string_tests();
extern void tcpsocket_tests();
#ifdef OF_THREADS
extern void thread_tests();
#endif
extern void xmlelement_tests();
extern void xmlparser_tests();







>







28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
extern void object_tests();
#ifdef OF_PLUGINS
extern void plugin_tests();
#endif
#ifdef OF_HAVE_PROPERTIES
extern void properties_tests();
#endif
extern void stream_tests();
extern void string_tests();
extern void tcpsocket_tests();
#ifdef OF_THREADS
extern void thread_tests();
#endif
extern void xmlelement_tests();
extern void xmlparser_tests();
107
108
109
110
111
112
113

114
115
116
117
118
119
120
	hashes_tests();
	string_tests();
	dataarray_tests();
	array_tests();
	dictionary_tests();
	list_tests();
	number_tests();

	tcpsocket_tests();
#ifdef OF_THREADS
	thread_tests();
#endif
	xmlelement_tests();
	xmlparser_tests();
#ifdef OF_PLUGINS







>







108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
	hashes_tests();
	string_tests();
	dataarray_tests();
	array_tests();
	dictionary_tests();
	list_tests();
	number_tests();
	stream_tests();
	tcpsocket_tests();
#ifdef OF_THREADS
	thread_tests();
#endif
	xmlelement_tests();
	xmlparser_tests();
#ifdef OF_PLUGINS