ObjFW  Check-in [d7c2d46b2b]

Overview
Comment:Add tests for blocks.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: d7c2d46b2be3d9cb28fdb22ef06f93c964201a85fad1197facc41fad57a58c9a
User & Date: js on 2010-11-12 20:13:20
Other Links: manifest | tags
Context
2010-11-13
16:15
Add support for BOOL to OFNumber. check-in: 0ec87765f4 user: js tags: trunk
2010-11-12
20:13
Add tests for blocks. check-in: d7c2d46b2b user: js tags: trunk
19:36
Ensure OF{Stack,Global,Malloc}Block get initialized. check-in: 38bde7146a user: js tags: trunk
Changes

Modified configure.ac from [759504b92f] to [9f7c24e610].

66
67
68
69
70
71
72

73
74
75
76
77
78
79
OBJCFLAGS="$OBJCFLAGS -fblocks"
AC_TRY_COMPILE([], [
	int (^foo)(int bar);
	foo = ^(int bar) { return 0; }
	], [
	AC_DEFINE(OF_HAVE_BLOCKS, 1, [Compiler support for blocks])
	AC_SUBST(BLOCKS_FLAGS, "-fblocks")

	AC_MSG_RESULT(yes)
	], [
	AC_MSG_RESULT(no)
	OBJCFLAGS="$old_OBJCFLAGS"
	])

AC_CHECK_HEADERS([objfw-rt.h objc/objc.h])







>







66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
OBJCFLAGS="$OBJCFLAGS -fblocks"
AC_TRY_COMPILE([], [
	int (^foo)(int bar);
	foo = ^(int bar) { return 0; }
	], [
	AC_DEFINE(OF_HAVE_BLOCKS, 1, [Compiler support for blocks])
	AC_SUBST(BLOCKS_FLAGS, "-fblocks")
	AC_SUBST(OFBLOCKTESTS_M, "OFBlockTests.m")
	AC_MSG_RESULT(yes)
	], [
	AC_MSG_RESULT(no)
	OBJCFLAGS="$old_OBJCFLAGS"
	])

AC_CHECK_HEADERS([objfw-rt.h objc/objc.h])

Modified extra.mk.in from [0e102eb3db] to [f7112abbb6].

1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
18
19
20
21
22
OBJFW_SHARED_LIB = @OBJFW_SHARED_LIB@
OBJFW_STATIC_LIB = @OBJFW_STATIC_LIB@
OBJFW_LIB_MAJOR = 3
OBJFW_LIB_MINOR = 0
OBJFW_LIB_MAJOR_MINOR = ${OBJFW_LIB_MAJOR}.${OBJFW_LIB_MINOR}

ASPRINTF_M = @ASPRINTF_M@
ATOMIC_H = @ATOMIC_H@
BIN_PREFIX = @BIN_PREFIX@
MACH_ALIAS_LIST = @MACH_ALIAS_LIST@

OBJC_PROPERTIES_M = @OBJC_PROPERTIES_M@
OBJC_SYNC_M = @OBJC_SYNC_M@
OFPLUGIN_M = @OFPLUGIN_M@
OFPLUGINTESTS_M = @OFPLUGINTESTS_M@
OFTHREAD_M = @OFTHREAD_M@
OFTHREADTESTS_M = @OFTHREADTESTS_M@
PROPERTIESTESTS_M = @PROPERTIESTESTS_M@
REEXPORT_LIBOBJC = @REEXPORT_LIBOBJC@
TESTPLUGIN = @TESTPLUGIN@
TESTS = @TESTS@
TEST_LAUNCHER = @TEST_LAUNCHER@
THREADING_H = @THREADING_H@










>












1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
OBJFW_SHARED_LIB = @OBJFW_SHARED_LIB@
OBJFW_STATIC_LIB = @OBJFW_STATIC_LIB@
OBJFW_LIB_MAJOR = 3
OBJFW_LIB_MINOR = 0
OBJFW_LIB_MAJOR_MINOR = ${OBJFW_LIB_MAJOR}.${OBJFW_LIB_MINOR}

ASPRINTF_M = @ASPRINTF_M@
ATOMIC_H = @ATOMIC_H@
BIN_PREFIX = @BIN_PREFIX@
MACH_ALIAS_LIST = @MACH_ALIAS_LIST@
OFBLOCKTESTS_M = @OFBLOCKTESTS_M@
OBJC_PROPERTIES_M = @OBJC_PROPERTIES_M@
OBJC_SYNC_M = @OBJC_SYNC_M@
OFPLUGIN_M = @OFPLUGIN_M@
OFPLUGINTESTS_M = @OFPLUGINTESTS_M@
OFTHREAD_M = @OFTHREAD_M@
OFTHREADTESTS_M = @OFTHREADTESTS_M@
PROPERTIESTESTS_M = @PROPERTIESTESTS_M@
REEXPORT_LIBOBJC = @REEXPORT_LIBOBJC@
TESTPLUGIN = @TESTPLUGIN@
TESTS = @TESTS@
TEST_LAUNCHER = @TEST_LAUNCHER@
THREADING_H = @THREADING_H@

Modified tests/Makefile from [f777dfe80b] to [9471e121b4].

1
2
3
4
5
6

7
8
9
10
11
12
13
include ../extra.mk

SUBDIRS = ${TESTPLUGIN}

PROG_NOINST = tests${PROG_SUFFIX}
SRCS = OFArrayTests.m			\

       OFDataArrayTests.m		\
       OFDictionaryTests.m		\
       OFFileTests.m			\
       OFListTests.m			\
       OFMD5HashTests.m			\
       OFNumberTests.m			\
       OFObjectTests.m			\






>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
include ../extra.mk

SUBDIRS = ${TESTPLUGIN}

PROG_NOINST = tests${PROG_SUFFIX}
SRCS = OFArrayTests.m			\
       ${OFBLOCKTESTS_M}		\
       OFDataArrayTests.m		\
       OFDictionaryTests.m		\
       OFFileTests.m			\
       OFListTests.m			\
       OFMD5HashTests.m			\
       OFNumberTests.m			\
       OFObjectTests.m			\

Added tests/OFBlockTests.m version [3714ef1c3f].



















































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
/*
 * 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"

#import "OFString.h"
#import "OFBlock.h"
#import "OFAutoreleasePool.h"
#import "OFExceptions.h"

#if defined(OF_OBJFW_RUNTIME)
# include <objfw-rt.h>
#elif defined(OF_GNU_RUNTIME)
# include <objc/objc-api.h>
#endif
#if defined(OF_GNU_RUNTIME) || defined(OF_OBJFW_RUNTIME)
# define objc_getClass objc_get_class
#endif

#import "TestsAppDelegate.h"

static OFString *module = @"OFBlock";

extern void *_NSConcreteStackBlock;
extern void *_NSConcreteGlobalBlock;
extern void *_NSConcreteMallocBlock;

@implementation TestsAppDelegate (OFBlockTests)
- (void)blockTests
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	__block int x;
	void (^s)() = ^ { x = 0; };
	void (^g)() = ^ {};
	void (^m)();

	TEST(@"Class of stack block",
	    (Class)&_NSConcreteStackBlock == objc_getClass("OFStackBlock") &&
	    [s isKindOfClass: [OFBlock class]])

	TEST(@"Class of global block",
	    (Class)&_NSConcreteGlobalBlock == objc_getClass("OFGlobalBlock") &&
	    [g isKindOfClass: [OFBlock class]])

	TEST(@"Class of a malloc block",
	    (Class)&_NSConcreteMallocBlock == objc_getClass("OFMallocBlock"))

	TEST(@"Copying a stack block",
	    (m = [s copy]) && [m class] == objc_getClass("OFMallocBlock") &&
	    [m isKindOfClass: [OFBlock class]])

	TEST(@"Copying a global block", (id)g == [g copy])

	TEST(@"Copying a malloc block",
	    (id)m == [m copy] && [m retainCount] == 2)

	TEST(@"Autorelease a stack block", R([s autorelease]))

	TEST(@"Autorelease a global block", R([g autorelease]))

	TEST(@"Autorelease a malloc block", R([m autorelease]))

	[pool drain];
}
@end

Modified tests/TestsAppDelegate.h from [2f884ceb5c] to [4c6e17c535].

67
68
69
70
71
72
73




74
75
76
77
78
79
80
- (void)outputFailure: (OFString*)test
	     inModule: (OFString*)module;
@end

@interface TestsAppDelegate (OFArrayTests)
- (void)arrayTests;
@end





@interface TestsAppDelegate (OFDataArrayTests)
- (void)dataArrayTests;
@end

@interface TestsAppDelegate (OFDictionaryTests)
- (void)dictionaryTests;







>
>
>
>







67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
- (void)outputFailure: (OFString*)test
	     inModule: (OFString*)module;
@end

@interface TestsAppDelegate (OFArrayTests)
- (void)arrayTests;
@end

@interface TestsAppDelegate (OFBlockTests)
- (void)blockTests;
@end

@interface TestsAppDelegate (OFDataArrayTests)
- (void)dataArrayTests;
@end

@interface TestsAppDelegate (OFDictionaryTests)
- (void)dictionaryTests;

Modified tests/TestsAppDelegate.m from [9f82cc5699] to [0af66a545f].

73
74
75
76
77
78
79



80
81
82
83
84
85
86
		 withColor: 2];
	[pool release];
}

- (void)applicationDidFinishLaunching
{
	[self objectTests];



	[self stringTests];
	[self fileTests];
	[self MD5HashTests];
	[self SHA1HashTests];
	[self dataArrayTests];
	[self arrayTests];
	[self dictionaryTests];







>
>
>







73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
		 withColor: 2];
	[pool release];
}

- (void)applicationDidFinishLaunching
{
	[self objectTests];
#ifdef OF_HAVE_BLOCKS
	[self blockTests];
#endif
	[self stringTests];
	[self fileTests];
	[self MD5HashTests];
	[self SHA1HashTests];
	[self dataArrayTests];
	[self arrayTests];
	[self dictionaryTests];