ObjFW  Diff

Differences From Artifact [6fb90c3139]:

To Artifact [05d8ab25d4]:


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
15
16
17
18
19
20
21

22
23
24
25
26
27

28
29
30




31
32
33
34
35
36
37







-


+
+
+

-



-
-
-
-







#import <stdlib.h>
#import <string.h>

#import "OFArray.h"
#import "OFExceptions.h"

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

const char *str = "Hallo!";

#define TEST(type) \
	puts("Trying to add too much to an array...");			\
	a = [type newWithItemSize: 4096];				\
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
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







-
+

















-












									\
	puts("Trying to access an index that does not exist...");	\
	CATCH_EXCEPTION([a item: [a items]], OFOutOfRangeException);	\
									\
	[a free];							\
									\
	puts("Creating new array and using it to build a string...");	\
	a = [type newWithItemSize: 1];				\
	a = [type newWithItemSize: 1];					\
									\
	for (i = 0; i < strlen(str); i++)				\
		[a add: (void*)(str + i)];				\
	[a add: ""];							\
									\
	if (!strcmp([a data], str))					\
		puts("Built string matches!");				\
	else {								\
		puts("Built string does not match!");			\
		abort();						\
	}								\
									\
	[a free];

int
main()
{
	BOOL caught;
	id a;
	void *p, *q;
	size_t i;

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

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

	return 0;
}