]> git.saurik.com Git - apple/objc4.git/blob - test/swiftMetadataInitializerRealloc-dylib1.m
objc4-781.2.tar.gz
[apple/objc4.git] / test / swiftMetadataInitializerRealloc-dylib1.m
1 #include "test.h"
2 #include "swift-class-def.m"
3
4 SWIFT_CLASS(RealSwiftDylib1A, NSObject, nop);
5 SWIFT_STUB_CLASS(SwiftDylib1A, initSwiftDylib1A);
6
7 SWIFT_CLASS(RealSwiftDylib1B, NSObject, nop);
8 SWIFT_STUB_CLASS(SwiftDylib1B, initSwiftDylib1B);
9
10 int Dylib1AInits = 0;
11
12 @interface SwiftDylib1A: NSObject @end
13 @interface SwiftDylib1B: NSObject @end
14
15 @implementation SwiftDylib1A (Category)
16 - (const char *)dylib1ACategoryInSameDylib { return "dylib1ACategoryInSameDylib"; }
17 @end
18 @implementation SwiftDylib1B (Category)
19 - (const char *)dylib1BCategoryInSameDylib { return "dylib1BCategoryInSameDylib"; }
20 @end
21
22 EXTERN_C Class initSwiftDylib1A(Class cls, void *arg)
23 {
24 Dylib1AInits++;
25 testassert(arg == nil);
26 testassert(cls == RawSwiftDylib1A);
27
28 if (Dylib1AInits == 1)
29 _objc_realizeClassFromSwift(RawRealSwiftDylib1A, cls);
30
31 return RawRealSwiftDylib1A;
32 }
33
34 int Dylib1BInits = 0;
35
36 EXTERN_C Class initSwiftDylib1B(Class cls, void *arg)
37 {
38 Dylib1BInits++;
39 testassert(arg == nil);
40 testassert(cls == RawSwiftDylib1B);
41
42 if (Dylib1BInits == 1)
43 _objc_realizeClassFromSwift(RawRealSwiftDylib1B, cls);
44
45 return RawRealSwiftDylib1B;
46 }
47
48 EXTERN_C Class objc_loadClassref(_Nullable Class * _Nonnull clsref);
49
50 void Dylib1Test(void) {
51 testassert((uintptr_t)SwiftDylib1AClassref & 1);
52 Class SwiftDylib1A = objc_loadClassref(&SwiftDylib1AClassref);
53 testassert(((uintptr_t)SwiftDylib1AClassref & 1) == 0);
54 testassert(SwiftDylib1A == [SwiftDylib1A class]);
55 testassert(SwiftDylib1A == SwiftDylib1AClassref);
56 testassert(Dylib1AInits == 2);
57
58 testassert((uintptr_t)SwiftDylib1BClassref & 1);
59 Class SwiftDylib1B = objc_loadClassref(&SwiftDylib1BClassref);
60 testassert(((uintptr_t)SwiftDylib1BClassref & 1) == 0);
61 testassert(SwiftDylib1B == [SwiftDylib1B class]);
62 testassert(SwiftDylib1B == SwiftDylib1BClassref);
63 testassert(Dylib1BInits == 2);
64 }