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
|
/*
* Copyright (c) 2008-2021 Jonathan Schleifer <js@nil.im>
*
* 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.QPL included in
* the packaging of this file.
*
* Alternatively, it may be distributed under the terms of the GNU General
* Public License, either version 2 or 3, which can be found in the file
* LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
* file.
*/
#include "config.h"
#import "TestsAppDelegate.h"
static OFString *module = @"Runtime";
@interface OFObject (SuperTest)
- (id)superTest;
@end
@interface RuntimeTest: OFObject
{
|
|
|
|
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
|
/*
* Copyright (c) 2008-2022 Jonathan Schleifer <js@nil.im>
*
* 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.QPL included in
* the packaging of this file.
*
* Alternatively, it may be distributed under the terms of the GNU General
* Public License, either version 2 or 3, which can be found in the file
* LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
* file.
*/
#include "config.h"
#import "TestsAppDelegate.h"
static OFString *const module = @"Runtime";
@interface OFObject (SuperTest)
- (id)superTest;
@end
@interface RuntimeTest: OFObject
{
|
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
|
}
@end
@implementation TestsAppDelegate (RuntimeTests)
- (void)runtimeTests
{
void *pool = objc_autoreleasePoolPush();
RuntimeTest *rt = [[[RuntimeTest alloc] init] autorelease];
OFString *t, *foo;
#ifdef OF_OBJFW_RUNTIME
int cid1, cid2;
uintmax_t value;
id object;
#endif
EXPECT_EXCEPTION(@"Calling a non-existent method via super",
OFNotImplementedException, [rt superTest])
TEST(@"Calling a method via a super with self == nil",
[rt nilSuperTest] == nil)
t = [OFMutableString stringWithString: @"foo"];
foo = @"foo";
[rt setFoo: t];
TEST(@"copy, nonatomic properties", [rt.foo isEqual: foo] &&
rt.foo != foo && rt.foo.retainCount == 1)
rt.bar = t;
TEST(@"retain, atomic properties", rt.bar == t && t.retainCount == 3)
#ifdef OF_OBJFW_RUNTIME
if (sizeof(uintptr_t) == 8)
value = 0xDEADBEEFDEADBEF;
else if (sizeof(uintptr_t) == 4)
value = 0xDEADBEF;
else
abort();
TEST(@"Tagged pointers",
(cid1 = objc_registerTaggedPointerClass([OFString class])) != -1 &&
(cid2 = objc_registerTaggedPointerClass([OFNumber class])) != -1 &&
(object = objc_createTaggedPointer(cid2, (uintptr_t)value)) &&
object_getClass(object) == [OFNumber class] &&
[object class] == [OFNumber class] &&
object_getTaggedPointerValue(object) == value &&
objc_createTaggedPointer(cid2, UINTPTR_MAX >> 4) != nil &&
objc_createTaggedPointer(cid2, (UINTPTR_MAX >> 4) + 1) == nil)
#endif
objc_autoreleasePoolPop(pool);
}
@end
|
|
|
|
|
|
|
|
|
|
|
|
>
|
|
>
|
|
|
|
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
|
}
@end
@implementation TestsAppDelegate (RuntimeTests)
- (void)runtimeTests
{
void *pool = objc_autoreleasePoolPush();
RuntimeTest *test = [[[RuntimeTest alloc] init] autorelease];
OFString *string, *foo;
#ifdef OF_OBJFW_RUNTIME
int classID;
uintmax_t value;
id object;
#endif
EXPECT_EXCEPTION(@"Calling a non-existent method via super",
OFNotImplementedException, [test superTest])
TEST(@"Calling a method via a super with self == nil",
[test nilSuperTest] == nil)
string = [OFMutableString stringWithString: @"foo"];
foo = @"foo";
test.foo = string;
TEST(@"copy, nonatomic properties", [test.foo isEqual: foo] &&
test.foo != foo && test.foo.retainCount == 1)
test.bar = string;
TEST(@"retain, atomic properties",
test.bar == string && string.retainCount == 3)
#ifdef OF_OBJFW_RUNTIME
if (sizeof(uintptr_t) == 8)
value = 0xDEADBEEFDEADBEF;
else if (sizeof(uintptr_t) == 4)
value = 0xDEADBEF;
else
abort();
TEST(@"Tagged pointers",
objc_registerTaggedPointerClass([OFString class]) != -1 &&
(classID = objc_registerTaggedPointerClass([OFNumber class])) !=
-1 &&
(object = objc_createTaggedPointer(classID, (uintptr_t)value)) &&
object_getClass(object) == [OFNumber class] &&
[object class] == [OFNumber class] &&
object_getTaggedPointerValue(object) == value &&
objc_createTaggedPointer(classID, UINTPTR_MAX >> 4) != nil &&
objc_createTaggedPointer(classID, (UINTPTR_MAX >> 4) + 1) == nil)
#endif
objc_autoreleasePoolPop(pool);
}
@end
|