Skip to content

Commit

Permalink
Merge pull request #20 from apocolipse/unit-tests
Browse files Browse the repository at this point in the history
Added unit tests
  • Loading branch information
wyland committed Apr 10, 2018
2 parents 756b902 + 847c2ed commit 4b5ba42
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 3 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ dependencies: [

You can compile IDL sources for Swift 3 with the following command:

thrift --gen swift_3 thrift_file
thrift --gen swift thrift_file

## Client Example
```swift
Expand Down Expand Up @@ -90,10 +90,11 @@ func write(_ val: String) throws
#### Generator Flags
| Flag | Description |
| ------------- |:-------------:|
| async_clients | Generate clients which invoke asynchronously via block syntax.Asynchronous classes are appended with `_Async` |
| async_clients | Generate clients which invoke asynchronously via block syntax. Asynchronous classes are appended with `_Async` |
| no_strict* | Generates non-strict structs |
| debug_descriptions | Allow use of debugDescription so the app can add description via a cateogory/extension |
| log_unexpected | Log every time an unexpected field ID or type is encountered. |
| safe_enums | Generate enum types with an unknown case to handle unspecified values rather than throw a serialization error |



Expand Down
68 changes: 67 additions & 1 deletion Tests/ThriftTests/TCompactProtocolTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,70 @@ class TCompactProtocolTests: XCTestCase {
}
}

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),
Expand All @@ -138,7 +202,9 @@ class TCompactProtocolTests: XCTestCase {
("testBoolWriteRead", testBoolWriteRead),
("testStringWriteRead", testStringWriteRead),
("testDataWriteRead", testDataWriteRead),
("testStructWriteRead", testStructWriteRead)
("testStructWriteRead", testStructWriteRead),
("testInt32ZigZag", testInt32ZigZag),
("testInt64ZigZag", testInt64ZigZag)
]
}
}

0 comments on commit 4b5ba42

Please sign in to comment.