-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix array encode with alignment. More tests.
- Loading branch information
Showing
8 changed files
with
151 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
///// | ||
//// CDRCodableDecodingArrayTests.swift | ||
/// Copyright © 2024 Dmitriy Borovikov. All rights reserved. | ||
// | ||
|
||
import XCTest | ||
@testable import CDRCodable | ||
|
||
class CDRCodableDecodingArrayTests: XCTestCase { | ||
var decoder: CDRDecoder! | ||
|
||
override func setUp() { | ||
self.decoder = CDRDecoder() | ||
} | ||
|
||
func testDecodeData() { | ||
let data = Data([5, 0, 0, 0, 0x68, 0x65, 0x6C, 0x6C, 0x6F]) | ||
let value = try! decoder.decode(Data.self, from: data) | ||
XCTAssertEqual(value, "hello".data(using: .utf8)) | ||
} | ||
|
||
func testDecodeArray8() { | ||
let data = Data([3, 0, 0, 0, 0xff, 2, 3, 0]) | ||
let value = try! decoder.decode([Int8].self, from: data) | ||
XCTAssertEqual(value, [-1, 2, 3]) | ||
} | ||
|
||
func testDecodeArray16() { | ||
let data = Data([3, 0, 0, 0, 0xff, 0xff, 2, 0, 3, 0, 0, 0]) | ||
let value = try! decoder.decode([Int16].self, from: data) | ||
XCTAssertEqual(value, [-1, 2, 3]) | ||
} | ||
|
||
func testDecodeArray32() { | ||
let data = Data([3, 0, 0, 0, 0xff, 0xff, 0xff, 0xff, 2, 0, 0, 0, 3, 0, 0, 0]) | ||
let value = try! decoder.decode([Int32].self, from: data) | ||
XCTAssertEqual(value, [-1, 2, 3]) | ||
} | ||
|
||
func testDecodeArray64() { | ||
let data = Data([3, 0, 0, 0, | ||
0, 0, 0, 0, | ||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
2, 0, 0, 0, 0, 0, 0, 0, | ||
3, 0, 0, 0, 0, 0, 0, 0]) | ||
let value = try! decoder.decode([Int64].self, from: data) | ||
XCTAssertEqual(value, [-1, 2, 3]) | ||
} | ||
|
||
func testDecodeArrayFloat() { | ||
let data = Data([3, 0, 0, 0, | ||
0, 0, 0x80, 0x3f, | ||
0, 0, 0, 0x40, | ||
0, 0, 0x40, 0x40]) | ||
let value = try! decoder.decode([Float].self, from: data) | ||
XCTAssertEqual(value, [1, 2, 3]) | ||
} | ||
|
||
func testDecodeArrayDoble() { | ||
let data = Data([3, 0, 0, 0, | ||
0, 0, 0, 0, | ||
0, 0, 0, 0, 0, 0, 0xf0, 0x3f, | ||
0, 0, 0, 0, 0, 0, 0, 0x40, | ||
0, 0, 0, 0, 0, 0, 8, 0x40]) | ||
let value = try! decoder.decode([Double].self, from: data) | ||
XCTAssertEqual(value, [1, 2, 3]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
///// | ||
//// CDRCodableEncodingArrayTests.swift | ||
/// Copyright © 2024 Dmitriy Borovikov. All rights reserved. | ||
// | ||
|
||
import XCTest | ||
@testable import CDRCodable | ||
|
||
class CDRCodableEncodingArrayTests: XCTestCase { | ||
var encoder: CDREncoder! | ||
|
||
override func setUp() { | ||
self.encoder = CDREncoder() | ||
} | ||
|
||
func testEncodeData() { | ||
let data = "hello".data(using: .utf8) | ||
let value = try! encoder.encode(data) | ||
XCTAssertEqual(value, Data([5, 0, 0, 0, 0x68, 0x65, 0x6C, 0x6C, 0x6F, 0, 0, 0])) | ||
} | ||
|
||
func testEncodeArray8() { | ||
let array: [Int8] = [-1, 2, 3] | ||
let value = try! encoder.encode(array) | ||
XCTAssertEqual(value, Data([3, 0, 0, 0, 0xff, 2, 3, 0])) | ||
} | ||
|
||
func testEncodeArray16() { | ||
let array: [Int16] = [-1, 2, 3] | ||
let value = try! encoder.encode(array) | ||
XCTAssertEqual(value, Data([3, 0, 0, 0, 0xff, 0xff, 2, 0, 3, 0, 0, 0])) | ||
} | ||
|
||
func testEncodeArray32() { | ||
let array: [Int32] = [-1, 2, 3] | ||
let value = try! encoder.encode(array) | ||
XCTAssertEqual(value, Data([3, 0, 0, 0, 0xff, 0xff, 0xff, 0xff, 2, 0, 0, 0, 3, 0, 0, 0])) | ||
} | ||
|
||
func testEncodeArray64() { | ||
let array: [Int64] = [-1, 2, 3] | ||
let value = try! encoder.encode(array) | ||
XCTAssertEqual(value, Data([3, 0, 0, 0, | ||
0, 0, 0, 0, | ||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
2, 0, 0, 0, 0, 0, 0, 0, | ||
3, 0, 0, 0, 0, 0, 0, 0])) | ||
} | ||
|
||
func testEncodeArrayFloat() { | ||
let array: [Float] = [1, 2, 3] | ||
let value = try! encoder.encode(array) | ||
XCTAssertEqual(value, Data([3, 0, 0, 0, | ||
0, 0, 0x80, 0x3f, | ||
0, 0, 0, 0x40, | ||
0, 0, 0x40, 0x40])) | ||
} | ||
|
||
func testEncodeArrayDouble() { | ||
let array: [Double] = [1, 2, 3] | ||
let value = try! encoder.encode(array) | ||
XCTAssertEqual(value, Data([3, 0, 0, 0, | ||
0, 0, 0, 0, | ||
0, 0, 0, 0, 0, 0, 0xf0, 0x3f, | ||
0, 0, 0, 0, 0, 0, 0, 0x40, | ||
0, 0, 0, 0, 0, 0, 8, 0x40])) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters