ObjFW  Check-in [1c77f45484]

Overview
Comment:Nicer exception catching in tests.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 1c77f454843295d0e5ce048595827c832dd4d9b2cbab222b49d75c4858c2cc81
User & Date: js on 2008-12-21 15:54:29
Other Links: manifest | tags
Context
2008-12-21
16:06
Nicer output for OFString tests. check-in: 70087a1b3b user: js tags: trunk
15:54
Nicer exception catching in tests. check-in: 1c77f45484 user: js tags: trunk
15:42
Initial UTF-8 support for OFString. check-in: b4a4e95798 user: js tags: trunk
Changes

Modified tests/OFArray/OFArray.m from [6fb90c3139] to [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
#import <stdlib.h>
#import <string.h>

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

#define CATCH_EXCEPTION(code, exception)		\
	caught = NO;					\
	@try {						\
		code;					\



	} @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];				\







<


>
>
>

<



<
<
<
<







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)		\

	@try {						\
		code;					\
							\
		puts("NOT CAUGHT!");			\
		return 1;				\
	} @catch (exception *e) {			\

		puts("CAUGHT! Error string was:");	\
		puts([e cString]);			\
		puts("Resuming...");			\




	}

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
									\
	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];				\
									\
	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;
}







|

















<












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];					\
									\
	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()
{

	id a;
	void *p, *q;
	size_t i;

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

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

	return 0;
}

Modified tests/OFObject/OFObject.m from [07688dcb04] to [28e0db1e33].

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
#import <stdio.h>
#import <stdlib.h>

#import "OFObject.h"
#import "OFExceptions.h"

#define CATCH_EXCEPTION(code, exception)		\
	caught = NO;					\
	@try {						\
		code;					\



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

int
main()
{
	OFObject *obj = [OFObject new];
	BOOL caught;
	void *p, *q, *r;

	/* Test freeing memory not allocated by obj */
	puts("Freeing memory not allocated by object (should throw an "
	    "exception)...");
	CATCH_EXCEPTION([obj freeMem: NULL], OFMemNotPartOfObjException)








<


>
>
>

<



<
<
<
<






<







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
#import <stdio.h>
#import <stdlib.h>

#import "OFObject.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 cString]);			\
		puts("Resuming...");			\




	}

int
main()
{
	OFObject *obj = [OFObject new];

	void *p, *q, *r;

	/* Test freeing memory not allocated by obj */
	puts("Freeing memory not allocated by object (should throw an "
	    "exception)...");
	CATCH_EXCEPTION([obj freeMem: NULL], OFMemNotPartOfObjException)