Skip to content

Commit def2846

Browse files
committed
Add an executable test for objc_runtime_visible classes + dynamic casting.
1 parent 336b719 commit def2846

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
__attribute__((objc_runtime_visible))
2+
@interface OS_dispatch_queue
3+
@end
4+
5+
__attribute__((objc_runtime_visible))
6+
@interface OS_object
7+
@end
8+
9+
__attribute__((objc_runtime_visible))
10+
@interface OS_dispatch_source
11+
@end
12+
13+
id dispatch_get_current_queue(void);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module DispatchObjects {
2+
header "DispatchObjects.h"
3+
}

test/Interpreter/SDK/OS_objects.swift

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// RUN: rm -rf %t
2+
// RUN: mkdir -p %t
3+
//
4+
// RUN: cp %s %t/main.swift
5+
// RUN: %target-build-swift %t/main.swift -I %S/Inputs/custom-modules/ -o %t/OS_objects -Xfrontend -disable-access-control
6+
// RUN: %target-run %t/OS_objects 2>&1 | FileCheck %s
7+
8+
// REQUIRES: objc_interop
9+
10+
// Note: Test the use of the Clang objc_runtime_visible attribute via
11+
// known OS objects on Darwin.
12+
13+
import ObjectiveC
14+
import DispatchObjects
15+
16+
// CHECK: Get current queue
17+
print("Get current queue")
18+
let obj = dispatch_get_current_queue();
19+
20+
// CHECK-NEXT: Object is a dispatch queue
21+
if let q = obj as? OS_dispatch_queue {
22+
print("Object is a dispatch queue")
23+
}
24+
25+
// CHECK-NEXT: Object is an OS object
26+
if let q = obj as? OS_object {
27+
print("Object is an OS object")
28+
}
29+
30+
// CHECK-NEXT: Object is an NSObject
31+
if let q = obj as? NSObject {
32+
print("Object is an NSObject")
33+
}
34+
35+
// CHECK-NEXT: Object is not a dispatch source
36+
if let q = obj as? OS_dispatch_source {
37+
print("Object is a dispatch source!?!?")
38+
} else {
39+
print("Object is not a dispatch source")
40+
}
41+
42+
// CHECK-NEXT: DONE
43+
print("DONE");

0 commit comments

Comments
 (0)