Skip to content

Commit

Permalink
Added initialization tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Szaq committed Apr 13, 2016
1 parent ca81ab0 commit 1b0be5b
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions BinaryDataTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,47 @@ class BinaryDataTests: XCTestCase {
block()
}
}

//MARK: - Initialization

func testArrayLiteralInit() {
let data:BinaryData = [0xf, 0x00, 0x1, 0xa]
XCTAssertEqual(data.data, [0xf, 0x00, 0x1, 0xa])
XCTAssertTrue(data.bigEndian)
}

func testArrayInit() {
let data = BinaryData(data: [0xf, 0x00, 0x1, 0xa])
XCTAssertEqual(data.data, [0xf, 0x00, 0x1, 0xa])
XCTAssertTrue(data.bigEndian)

let dataExplicitBigEndianTrue = BinaryData(data: [0xf, 0x00, 0x1, 0xa], bigEndian: true)
XCTAssertEqual(dataExplicitBigEndianTrue.data, [0xf, 0x00, 0x1, 0xa])
XCTAssertTrue(dataExplicitBigEndianTrue.bigEndian)

let dataExplicitBigEndianFalse = BinaryData(data: [0xf, 0x00, 0x1, 0xa], bigEndian: false)
XCTAssertEqual(dataExplicitBigEndianFalse.data, [0xf, 0x00, 0x1, 0xa])
XCTAssertFalse(dataExplicitBigEndianFalse.bigEndian)
}

func testNSDataInit() {
guard let nsData = NSData(base64EncodedString: "MTIzNA==", options: NSDataBase64DecodingOptions())
else { XCTFail("Failed to decode test Base64 string"); return}

let data = BinaryData(data: nsData)
XCTAssertEqual(data.data, [49, 50, 51, 52])
XCTAssertTrue(data.bigEndian)

let dataExplicitBigEndianTrue = BinaryData(data: nsData, bigEndian: true)
XCTAssertEqual(dataExplicitBigEndianTrue.data, [49, 50, 51, 52])
XCTAssertTrue(dataExplicitBigEndianTrue.bigEndian)

let dataExplicitBigEndianFalse = BinaryData(data: nsData, bigEndian: false)
XCTAssertEqual(dataExplicitBigEndianFalse.data, [49, 50, 51, 52])
XCTAssertFalse(dataExplicitBigEndianFalse.bigEndian)
}



//MARK: - Reading One - byte values

Expand Down

0 comments on commit 1b0be5b

Please sign in to comment.