forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUnmanaged.swift
43 lines (33 loc) · 956 Bytes
/
Unmanaged.swift
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
// RUN: %target-run-simple-swift
// REQUIRES: executable_test
// XFAIL: interpret
import StdlibUnittest
// Check that the generic parameter is called 'Instance'.
protocol TestProtocol1 {}
extension Unmanaged where Instance : TestProtocol1 {
var _instanceIsTestProtocol1: Bool {
fatalError("not implemented")
}
}
var UnmanagedTests = TestSuite("Unmanaged")
UnmanagedTests.test("fromOpaque()/trap")
.skip(.Custom(
{ !_isDebugAssertConfiguration() },
reason: "fromOpaque() does a _debugPrecondition() for null pointers"))
.code {
let null = getPointer(COpaquePointer())
expectCrashLater()
let unmanaged = Unmanaged<AnyObject>.fromOpaque(null)
_blackHole(unmanaged)
}
class FooClass {}
UnmanagedTests.test("unsafeBitCast(Unmanaged, Int)") {
let ref = FooClass()
expectNotEqual(
0,
unsafeBitCast(
Unmanaged.passUnretained(ref) as Unmanaged<AnyObject>,
Int.self))
_fixLifetime(ref)
}
runAllTests()