forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPrintPointer.swift
41 lines (32 loc) · 1.23 KB
/
PrintPointer.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
// RUN: %target-run-simple-swift
// REQUIRES: executable_test
import StdlibUnittest
let PrintTests = TestSuite("PrintPointer")
PrintTests.test("Printable") {
let lowUP = UnsafeMutablePointer<Float>(bitPattern: 0x1)!
let fourByteUP = UnsafeMutablePointer<Float>(bitPattern: 0xabcd1234 as UInt)!
#if !(arch(i386) || arch(arm))
let eightByteAddr: UInt = 0xabcddcba12344321
let eightByteUP = UnsafeMutablePointer<Float>(bitPattern: eightByteAddr)!
#endif
#if arch(i386) || arch(arm)
let expectedLow = "0x00000001"
expectPrinted("0xabcd1234", fourByteUP)
#else
let expectedLow = "0x0000000000000001"
expectPrinted("0x00000000abcd1234", fourByteUP)
expectPrinted("0xabcddcba12344321", eightByteUP)
#endif
expectPrinted(expectedLow, lowUP)
expectPrinted("UnsafeBufferPointer(start: \(fourByteUP), count: 0)",
UnsafeBufferPointer(start: fourByteUP, count: 0))
expectPrinted("UnsafeMutableBufferPointer(start: \(fourByteUP), count: 0)",
UnsafeMutableBufferPointer(start: fourByteUP, count: 0))
let lowOpaque = OpaquePointer(lowUP)
expectPrinted(expectedLow, lowOpaque)
#if _runtime(_ObjC)
let lowAutoUP = AutoreleasingUnsafeMutablePointer<Int>(lowUP)
expectPrinted(expectedLow, lowAutoUP)
#endif
}
runAllTests()