Update Swift Library and tests
diff --git a/lib/swift/Tests/ThriftTests/TBinaryProtocolTests.swift b/lib/swift/Tests/ThriftTests/TBinaryProtocolTests.swift
index f0e48b9..56a5572 100644
--- a/lib/swift/Tests/ThriftTests/TBinaryProtocolTests.swift
+++ b/lib/swift/Tests/ThriftTests/TBinaryProtocolTests.swift
@@ -129,6 +129,28 @@
XCTAssertFalse(true, "Caught Error attempting to read \(error)")
}
}
+ func testUnsafeBitcastUpdate() {
+ let value: Double = 3.14159
+ let val: Int64 = 31415926
+ let uval: UInt64 = 31415926
+
+ let i64 = Int64(bitPattern: value.bitPattern)
+ let ubc = unsafeBitCast(value, to: Int64.self)
+
+ XCTAssertEqual(i64, ubc, "Bitcast Double-> i64 Values don't match")
+
+ let dbl = Double(bitPattern: UInt64(val))
+ let ubdb = unsafeBitCast(val, to: Double.self)
+
+ XCTAssertEqual(dbl, ubdb, "Bitcast i64 -> Double Values don't match")
+
+ let db2 = Double(bitPattern: uval)
+ let usbc2 = unsafeBitCast(uval, to: Double.self)
+
+ XCTAssertEqual(db2, usbc2, "Bitcast u64 -> Double Values don't match")
+
+
+ }
static var allTests : [(String, (TBinaryProtocolTests) -> () throws -> Void)] {
return [
diff --git a/lib/swift/Tests/ThriftTests/TCompactProtocolTests.swift b/lib/swift/Tests/ThriftTests/TCompactProtocolTests.swift
index ccc32aa..882c260 100644
--- a/lib/swift/Tests/ThriftTests/TCompactProtocolTests.swift
+++ b/lib/swift/Tests/ThriftTests/TCompactProtocolTests.swift
@@ -128,6 +128,70 @@
}
}
+ func testInt32ZigZag() {
+ let zero: Int32 = 0
+ let one: Int32 = 1
+ let nOne: Int32 = -1
+ let two: Int32 = 2
+ let nTwo: Int32 = -2
+ let max = Int32.max
+ let min = Int32.min
+
+ XCTAssertEqual(proto.i32ToZigZag(zero), UInt32(0), "Error 32bit zigzag on \(zero)")
+ XCTAssertEqual(proto.zigZagToi32(0), zero, "Error 32bit zigzag on \(zero)")
+
+ XCTAssertEqual(proto.i32ToZigZag(nOne), UInt32(1), "Error 32bit zigzag on \(nOne)")
+ XCTAssertEqual(proto.zigZagToi32(1), nOne, "Error 32bit zigzag on \(nOne)")
+
+ XCTAssertEqual(proto.i32ToZigZag(one), UInt32(2), "Error 32bit zigzag on \(one)")
+ XCTAssertEqual(proto.zigZagToi32(2), one, "Error 32bit zigzag on \(one)")
+
+ XCTAssertEqual(proto.i32ToZigZag(nTwo), UInt32(3), "Error 32bit zigzag on \(nTwo)")
+ XCTAssertEqual(proto.zigZagToi32(3), nTwo, "Error 32bit zigzag on \(nTwo)")
+
+ XCTAssertEqual(proto.i32ToZigZag(two), UInt32(4), "Error 32bit zigzag on \(two)")
+ XCTAssertEqual(proto.zigZagToi32(4), two, "Error 32bit zigzag on \(two)")
+
+ let uMaxMinusOne: UInt32 = UInt32.max - 1
+ XCTAssertEqual(proto.i32ToZigZag(max), uMaxMinusOne, "Error 32bit zigzag on \(max)")
+ XCTAssertEqual(proto.zigZagToi32(uMaxMinusOne), max, "Error 32bit zigzag on \(max)")
+
+ XCTAssertEqual(proto.i32ToZigZag(min), UInt32.max, "Error 32bit zigzag on \(min)")
+ XCTAssertEqual(proto.zigZagToi32(UInt32.max), min, "Error 32bit zigzag on \(min)")
+ }
+
+ func testInt64ZigZag() {
+ let zero: Int64 = 0
+ let one: Int64 = 1
+ let nOne: Int64 = -1
+ let two: Int64 = 2
+ let nTwo: Int64 = -2
+ let max = Int64.max
+ let min = Int64.min
+
+ XCTAssertEqual(proto.i64ToZigZag(zero), UInt64(0), "Error 64bit zigzag on \(zero)")
+ XCTAssertEqual(proto.zigZagToi64(0), zero, "Error 64bit zigzag on \(zero)")
+
+ XCTAssertEqual(proto.i64ToZigZag(nOne), UInt64(1), "Error 64bit zigzag on \(nOne)")
+ XCTAssertEqual(proto.zigZagToi64(1), nOne, "Error 64bit zigzag on \(nOne)")
+
+ XCTAssertEqual(proto.i64ToZigZag(one), UInt64(2), "Error 64bit zigzag on \(one)")
+ XCTAssertEqual(proto.zigZagToi64(2), one, "Error 64bit zigzag on \(one)")
+
+ XCTAssertEqual(proto.i64ToZigZag(nTwo), UInt64(3), "Error 64bit zigzag on \(nTwo)")
+ XCTAssertEqual(proto.zigZagToi64(3), nTwo, "Error 64bit zigzag on \(nTwo)")
+
+ XCTAssertEqual(proto.i64ToZigZag(two), UInt64(4), "Error 64bit zigzag on \(two)")
+ XCTAssertEqual(proto.zigZagToi64(4), two, "Error 64bit zigzag on \(two)")
+
+ let uMaxMinusOne: UInt64 = UInt64.max - 1
+ XCTAssertEqual(proto.i64ToZigZag(max), uMaxMinusOne, "Error 64bit zigzag on \(max)")
+ XCTAssertEqual(proto.zigZagToi64(uMaxMinusOne), max, "Error 64bit zigzag on \(max)")
+
+ XCTAssertEqual(proto.i64ToZigZag(min), UInt64.max, "Error 64bit zigzag on \(min)")
+ XCTAssertEqual(proto.zigZagToi64(UInt64.max), min, "Error 64bit zigzag on \(min)")
+ }
+
static var allTests : [(String, (TCompactProtocolTests) -> () throws -> Void)] {
return [
("testInt8WriteRead", testInt8WriteRead),
@@ -138,7 +202,9 @@
("testBoolWriteRead", testBoolWriteRead),
("testStringWriteRead", testStringWriteRead),
("testDataWriteRead", testDataWriteRead),
- ("testStructWriteRead", testStructWriteRead)
+ ("testStructWriteRead", testStructWriteRead),
+ ("testInt32ZigZag", testInt32ZigZag),
+ ("testInt64ZigZag", testInt64ZigZag)
]
}
}
diff --git a/lib/swift/Tests/ThriftTests/ThriftTests.swift b/lib/swift/Tests/ThriftTests/ThriftTests.swift
index 0c81330..9316100 100644
--- a/lib/swift/Tests/ThriftTests/ThriftTests.swift
+++ b/lib/swift/Tests/ThriftTests/ThriftTests.swift
@@ -3,13 +3,13 @@
class ThriftTests: XCTestCase {
func testVersion() {
- XCTAssertEqual(Thrift().version, "0.0.1")
+ XCTAssertEqual(Thrift().version, "1.1.0")
}
-
+
func test_in_addr_extension() {
-
+
}
-
+
static var allTests : [(String, (ThriftTests) -> () throws -> Void)] {
return [
("testVersion", testVersion),