ObjFW  Check-in [e7a372fea9]

Overview
Comment:Migration of OFDataArray tests to new testing framework.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: e7a372fea94b52620da8d57270223e3c6d7f4beeb1dcabf028cd8ab0b21a6212
User & Date: js on 2009-09-30 15:01:24
Other Links: manifest | tags
Context
2009-09-30
15:43
Migration of OFHashes tests to new testing framework. check-in: 6d6ac5a6d5 user: js tags: trunk
15:01
Migration of OFDataArray tests to new testing framework. check-in: e7a372fea9 user: js tags: trunk
13:33
Migration of OFXMLElement tests to new testing framework. check-in: 2437d2d0be user: js tags: trunk
Changes

Modified src/OFArray.m from [3bf6c09d87] to [717e5d1c5c].

227
228
229
230
231
232
233






234
}

- removeNObjects: (size_t)nobjects
{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
}






@end







>
>
>
>
>
>

227
228
229
230
231
232
233
234
235
236
237
238
239
240
}

- removeNObjects: (size_t)nobjects
{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
}

/* FIXME: Implement!
- (uint32_t)hash
{
}
*/
@end

Modified src/OFDictionary.m from [3ddd956ea4] to [7f0d5a8891].

277
278
279
280
281
282
283






284
}

- removeObjectForKey: (OFObject*)key
{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
}






@end







>
>
>
>
>
>

277
278
279
280
281
282
283
284
285
286
287
288
289
290
}

- removeObjectForKey: (OFObject*)key
{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
}

/* FIXME: Implement!
- (uint32_t)hash
{
}
*/
@end

Modified src/OFList.m from [b22035331b] to [75c1a9ff27].

226
227
228
229
230
231
232






233
		@throw e;
	}

	new->last = o;

	return new;
}






@end







>
>
>
>
>
>

226
227
228
229
230
231
232
233
234
235
236
237
238
239
		@throw e;
	}

	new->last = o;

	return new;
}

/* FIXME: Implement!
- (uint32_t)hash
{
}
*/
@end

Modified tests/Makefile from [0ad94f9883] to [e430b80025].

1
2
3
4
5
6
7
8
9
10
include ../extra.mk

SUBDIRS = OFDataArray		\
	  OFHashes		\
	  ${OFPLUGIN}		\
	  OFThread		\
	  OFXMLParser		\
	  ${OBJC_SYNC}

include ../buildsys.mk


|
<






1
2
3

4
5
6
7
8
9
include ../extra.mk

SUBDIRS = OFHashes		\

	  ${OFPLUGIN}		\
	  OFThread		\
	  OFXMLParser		\
	  ${OBJC_SYNC}

include ../buildsys.mk

Deleted tests/OFDataArray/Makefile version [c0eeee4d2f].

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
PROG_NOINST = ofdataarray${PROG_SUFFIX}
SRCS = OFDataArray.m

include ../../buildsys.mk
include ../../extra.mk

CPPFLAGS += -I../../src -I../..
LIBS := -L../../src -lobjfw ${LIBS}

.PHONY: run

all: run
run: ${PROG_NOINST}
	rm -f libobjfw.so.0 libobjfw.so.0.1 libobjfw.dll libobjfw.dylib
	if test -f ../../src/libobjfw.so; then \
		ln -s ../../src/libobjfw.so libobjfw.so.0; \
		ln -s ../../src/libobjfw.so libobjfw.so.0.1; \
	fi
	if test -f ../../src/libobjfw.dll; then \
		ln ../../src/libobjfw.dll libobjfw.dll; \
	fi
	if test -f ../../src/libobjfw.dylib; then \
		ln -s ../../src/libobjfw.dylib libobjfw.dylib; \
	fi
	LD_LIBRARY_PATH=.$${LD_LIBRARY_PATH+:}$$LD_LIBRARY_PATH \
	DYLD_LIBRARY_PATH=.$${DYLD_LIBRARY_PATH+:}$$DYLD_LIBRARY_PATH \
	${TEST_LAUNCHER} ./${PROG_NOINST}; EXIT=$$?; \
	rm -f libobjfw.so.0 libobjfw.so.0.1 libobjfw.dll libobjfw.dylib; \
	exit $$EXIT
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<


























































Deleted tests/OFDataArray/OFDataArray.m version [92c6e56e71].

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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
 * Copyright (c) 2008 - 2009
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * All rights reserved.
 *
 * This file is part of libobjfw. 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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>

#import "OFDataArray.h"
#import "OFAutoreleasePool.h"
#import "OFExceptions.h"

#define CATCH_EXCEPTION(code, exception)		\
	@try {						\
		code;					\
							\
		puts("NOT CAUGHT!");			\
		return 1;				\
	} @catch (exception *e) {			\
		puts("CAUGHT! Error string was:");	\
		puts([[e string] cString]);		\
		puts("Resuming...");			\
	}

const char *str = "Hallo!";

#define TEST(type) \
	puts("Trying to add too much to an array...");			\
	a = [[type alloc] initWithItemSize: 4096];			\
	CATCH_EXCEPTION([a addNItems: SIZE_MAX				\
			  fromCArray: NULL],				\
	    OFOutOfRangeException)					\
									\
	puts("Trying to add something after that error...");		\
	p = [a allocMemoryWithSize: 4096];				\
	memset(p, 255, 4096);						\
	[a addItem: p];							\
	if (!memcmp([a lastItem], p, 4096))				\
		puts("[a lastItem] matches with p!");			\
	else {								\
		puts("[a lastItem] does not match p!");			\
		abort();						\
	}								\
	[a freeMemory: p];						\
									\
	puts("Adding more data...");					\
	q = [a allocMemoryWithSize: 4096];				\
	memset(q, 42, 4096);						\
	[a addItem: q];							\
	if (!memcmp([a lastItem], q, 4096))				\
		puts("[a lastItem] matches with q!");			\
	else {								\
		puts("[a lastItem] does not match q!");			\
		abort();						\
	}								\
	[a freeMemory: q];						\
									\
	puts("Adding multiple items at once...");			\
	p = [a allocMemoryWithSize: 8192];				\
	memset(p, 64, 8192);						\
	[a addNItems: 2							\
	  fromCArray: p];						\
	if (!memcmp([a lastItem], [a itemAtIndex: [a count] - 2], 4096) && \
	    !memcmp([a itemAtIndex: [a count] - 2], p, 4096))		\
		puts("[a lastItem], [a itemAtIndex: [a count] - 2] "	\
		    "and p match!");					\
	else {								\
		puts("[a lastItem], [a itemAtIndex: [a count] - 2] "	\
		    "and p do not match!");				\
		abort();						\
	}								\
	[a freeMemory: p];						\
									\
	i = [a count];							\
	puts("Removing 2 items...");					\
	[a removeNItems: 2];						\
	if ([a count] + 2 != i) {					\
		puts("[a count] + 2 != i!");				\
		abort();						\
	}								\
									\
	puts("Trying to remove more data than we added...");		\
	CATCH_EXCEPTION([a removeNItems: [a count] + 1],		\
	    OFOutOfRangeException);					\
									\
	puts("Trying to access an index that does not exist...");	\
	CATCH_EXCEPTION([a itemAtIndex: [a count]],			\
	    OFOutOfRangeException);					\
									\
	[a release];							\
									\
	puts("Creating new array and using it to build a string...");	\
	a = [[type alloc] initWithItemSize: 1];				\
									\
	for (i = 0; i < strlen(str); i++)				\
		[a addItem: (void*)&str[i]];				\
	[a addItem: ""];						\
									\
	if (!strcmp([a data], str))					\
		puts("Built string matches!");				\
	else {								\
		puts("Built string does not match!");			\
		abort();						\
	}								\
									\
	[a release];

int
main()
{
	id a;
	void *p, *q;
	size_t i;
	OFDataArray *x, *y;
	OFAutoreleasePool *pool;

	puts("== TESTING OFDataArray ==");
	TEST(OFDataArray)

	puts("== TESTING OFBigArray ==");
	TEST(OFBigDataArray)

	pool = [[OFAutoreleasePool alloc] init];
	x = [OFDataArray dataArrayWithItemSize: 1];
	y = [OFBigDataArray dataArrayWithItemSize: 1];

	if (![x isEqual: y]) {
		puts("FAIL 1!");
		return 1;
	}

	if ([x hash] != [y hash]) {
		puts("FAIL 2!");
		return 1;
	}

	[x addItem: "x"];
	if ([x isEqual: y]) {
		puts("FAIL 3!");
		return 1;
	}
	[pool releaseObjects];

	x = [OFDataArray dataArrayWithItemSize: 2];
	y = [OFBigDataArray dataArrayWithItemSize: 4];

	if ([x isEqual: y]) {
		puts("FAIL 4!");
		return 1;
	}
	[pool releaseObjects];

	x = [OFDataArray dataArrayWithItemSize: 1];
	[x addNItems: 3
	  fromCArray: "abc"];
	y = [x copy];
	if ([x compare: y]) {
		puts("FAIL 5!");
		return 1;
	}

	[y addItem: "de"];
	if ([x compare: y] != -100) {
		puts("FAIL 6!");
		return 1;
	}

	if ([y hash] != 0xCD8B6206) {
		puts("FAIL 7!");
		return 1;
	}
	[pool release];

	return 0;
}
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<


















































































































































































































































































































































































Modified tests_new/Makefile from [98d32fa459] to [2046040715].

1
2

3
4
5
6
7
8
9
PROG_NOINST = tests${PROG_SUFFIX}
SRCS = array.m		\

       dictionary.m	\
       list.m		\
       main.m		\
       object.m		\
       string.m		\
       tcpsocket.m	\
       xmlelement.m


>







1
2
3
4
5
6
7
8
9
10
PROG_NOINST = tests${PROG_SUFFIX}
SRCS = array.m		\
       dataarray.m	\
       dictionary.m	\
       list.m		\
       main.m		\
       object.m		\
       string.m		\
       tcpsocket.m	\
       xmlelement.m

Modified tests_new/array.m from [765475729a] to [92fa8f95cf].

58
59
60
61
62
63
64
65



66
67
68
	    [[a[2] objectAtIndex: 1] isEqual: c_ary[1]] &&
	    [[a[2] objectAtIndex: 2] isEqual: c_ary[2]])

	TEST(@"-[removeNObjects:]", [a[0] removeNObjects: 2] &&
	    [a[0] count] == 1 && [[a[0] objectAtIndex: 0] isEqual: c_ary[0]])

	EXPECT_EXCEPTION(@"Detect out of range in -[objectAtIndex:]",
	    OFOutOfRangeException, [a[0] objectAtIndex: 1])




	[pool release];
}







|
>
>
>



58
59
60
61
62
63
64
65
66
67
68
69
70
71
	    [[a[2] objectAtIndex: 1] isEqual: c_ary[1]] &&
	    [[a[2] objectAtIndex: 2] isEqual: c_ary[2]])

	TEST(@"-[removeNObjects:]", [a[0] removeNObjects: 2] &&
	    [a[0] count] == 1 && [[a[0] objectAtIndex: 0] isEqual: c_ary[0]])

	EXPECT_EXCEPTION(@"Detect out of range in -[objectAtIndex:]",
	    OFOutOfRangeException, [a[0] objectAtIndex: [a[0] count]])

	EXPECT_EXCEPTION(@"Detect out of range in -[removeNItems:]",
	    OFOutOfRangeException, [a[0] removeNObjects: [a[0] count] + 1])

	[pool release];
}

Added tests_new/dataarray.m version [8f9b25b225].















































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
 * Copyright (c) 2008 - 2009
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * All rights reserved.
 *
 * This file is part of libobjfw. 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 "OFArray.h"
#import "OFAutoreleasePool.h"
#import "OFString.h"
#import "OFExceptions.h"

#import "main.h"

static OFString *module;
const char *str = "Hello!";

static void
do_tests(Class class)
{
	OFDataArray *array[2];
	void *data[2];
	Class other;

	TEST(@"+[dataArrayWithItemSize:]",
	    (array[0] = [class dataArrayWithItemSize: 4096]))

	data[0] = [array[0] allocMemoryWithSize: 4096];
	data[1] = [array[0] allocMemoryWithSize: 4096];
	memset(data[0], 0xFF, 4096);
	memset(data[1], 0x42, 4096);

	TEST(@"-[addItem:]", [array[0] addItem: data[0]] &&
	    [array[0] addItem: data[1]])

	TEST(@"-[itemAtIndex:]",
	    !memcmp([array[0] itemAtIndex: 0], data[0], 4096) &&
	    !memcmp([array[0] itemAtIndex: 1], data[1], 4096))

	TEST(@"-[lastItem]", !memcmp([array[0] lastItem], data[1], 4096))

	TEST(@"-[count]", [array[0] count] == 2)

	other = (class == [OFDataArray class]
	    ? [OFBigDataArray class]
	    : [OFDataArray class]);
	TEST(@"-[isEqual:]", (array[1] = [other dataArrayWithItemSize: 4096]) &&
	    [array[1] addNItems: [array[0] count]
		     fromCArray: [array[0] data]] &&
	    [array[1] isEqual: array[0]] &&
	    [array[1] removeNItems: 1] && ![array[0] isEqual: array[1]])

	TEST(@"-[copy]", (array[1] = [[array[0] copy] autorelease]) &&
	    [array[0] isEqual: array[1]])

	TEST(@"-[compare]", [array[0] compare: array[1]] == 0 &&
	    [array[1] removeNItems: 1] &&
	    [array[0] compare: array[1]] == 0x42 &&
	    [array[1] compare: array[0]] == -0x42)

	TEST(@"-[hash]", [array[0] hash] == 0xC54621B6)

	TEST(@"-[removeNItems:]", [array[0] removeNItems: 1])

	TEST(@"Building strings",
	    (array[0] = [class dataArrayWithItemSize: 1]) &&
	    [array[0] addNItems: 6
		     fromCArray: (void*)str] && [array[0] addItem: ""] &&
	    !strcmp([array[0] data], str))

	EXPECT_EXCEPTION(@"Detect out of range in -[itemAtIndex:]",
	    OFOutOfRangeException, [array[0] itemAtIndex: [array[0] count]])

	EXPECT_EXCEPTION(@"Detect out of range in -[addNItems:fromCArray:]",
	    OFOutOfRangeException, [array[0] addNItems: SIZE_MAX
					    fromCArray: NULL])

	EXPECT_EXCEPTION(@"Detect out of range in -[removeNItems:]",
	    OFOutOfRangeException,
	    [array[0] removeNItems: [array[0] count] + 1])
}

void
dataarray_tests()
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];

	module = @"OFDataArray";
	do_tests([OFDataArray class]);

	module = @"OFBigDataArray";
	do_tests([OFBigDataArray class]);

	[pool release];
}

Modified tests_new/main.m from [8a5fa64125] to [d8a71e2ba4].

16
17
18
19
20
21
22

23
24
25
26
27
28
29
#endif
#include <stdlib.h>

#import "OFString.h"
#import "OFAutoreleasePool.h"

extern void array_tests();

extern void dictionary_tests();
extern void list_tests();
extern void object_tests();
extern void string_tests();
extern void tcpsocket_tests();
extern void xmlelement_tests();








>







16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#endif
#include <stdlib.h>

#import "OFString.h"
#import "OFAutoreleasePool.h"

extern void array_tests();
extern void dataarray_tests();
extern void dictionary_tests();
extern void list_tests();
extern void object_tests();
extern void string_tests();
extern void tcpsocket_tests();
extern void xmlelement_tests();

88
89
90
91
92
93
94

95
96
97
98
99
100
101
102
}

int
main()
{
	object_tests();
	string_tests();

	array_tests();
	dictionary_tests();
	list_tests();
	tcpsocket_tests();
	xmlelement_tests();

	return fails;
}







>








89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
}

int
main()
{
	object_tests();
	string_tests();
	dataarray_tests();
	array_tests();
	dictionary_tests();
	list_tests();
	tcpsocket_tests();
	xmlelement_tests();

	return fails;
}