Adds a way to verify/exposes Entities ids (#7221)

This commit is contained in:
mustiikhalil
2022-04-06 22:54:01 +02:00
committed by GitHub
parent 832c618f5f
commit 2049e52101
9 changed files with 98 additions and 14 deletions

View File

@@ -201,12 +201,34 @@ final class FlatbuffersVerifierTests: XCTestCase {
XCTAssertNoThrow(try getCheckedRoot(byteBuffer: &byteBuffer) as Movie)
}
func testErrorWrongFileId() {
// swiftformat:disable all
var byteBuffer = ByteBuffer(bytes: [20, 0, 0, 0, 77, 79, 86, 73, 12, 0, 12, 0, 0, 0, 0, 0, 8, 0, 4, 0, 12, 0, 0, 0, 8, 0, 0, 0, 20, 0, 0, 0, 3, 0, 0, 0, 24, 0, 0, 0, 32, 0, 0, 0, 12, 0, 0, 0, 3, 0, 0, 0, 3, 1, 4, 0, 2, 0, 0, 0, 7, 0, 0, 0, 0, 0, 6, 0, 8, 0, 4, 0, 6, 0, 0, 0, 8, 0, 0, 0])
// swiftformat:enable all
XCTAssertThrowsError(try getCheckedRoot(byteBuffer: &byteBuffer, fileId: "FLEX") as Movie)
}
func testVerifyPrefixedBuffer() {
// swiftformat:disable all
var byteBuffer = ByteBuffer(bytes: [0, 0, 0, 1, 20, 0, 0, 0, 77, 79, 86, 73, 12, 0, 12, 0, 0, 0, 0, 0, 8, 0, 4, 0, 12, 0, 0, 0, 8, 0, 0, 0, 20, 0, 0, 0, 3, 0, 0, 0, 24, 0, 0, 0, 32, 0, 0, 0, 12, 0, 0, 0, 3, 0, 0, 0, 3, 1, 4, 0, 2, 0, 0, 0, 7, 0, 0, 0, 0, 0, 6, 0, 8, 0, 4, 0, 6, 0, 0, 0, 8, 0, 0, 0])
// swiftformat:enable all
XCTAssertThrowsError(
try getCheckedPrefixedSizeRoot(byteBuffer: &byteBuffer) as Movie)
}
func testFullVerifier() {
XCTAssertNoThrow(
try getCheckedRoot(
byteBuffer: &validFlatbuffersObject) as MyGame_Example_Monster)
}
func testFullVerifierWithFileId() {
XCTAssertNoThrow(
try getCheckedRoot(
byteBuffer: &validFlatbuffersObject,
fileId: MyGame_Example_Monster.id) as MyGame_Example_Monster)
}
func testInvalidBuffer() {
XCTAssertThrowsError(
try getCheckedRoot(