Files
AV-Live/shared/AVLiveWire/Tests/AVLiveWireTests/FrameHeaderTests.swift
L'électron rare 077a7f707f feat(avlivewire): fixed 19-byte frame header codec
Add FrameHeader, a fixed-size binary record so the demuxer can
frame and resync the iPhone USB stream. Layout is big-endian:
4-byte magic AVL1, tag u8, pid i16, timestamp f64, length u32.

The magic prefix lets a reader detect and skip corrupt bytes.
Decoding rejects short buffers and bad magic by returning nil.
Big-endian append/parse helpers are added as Data/UInt extensions
to keep the codec self-contained.
2026-05-18 15:34:45 +02:00

25 lines
752 B
Swift

import XCTest
@testable import AVLiveWire
final class FrameHeaderTests: XCTestCase {
func testRoundTrip() {
let h = FrameHeader(tag: .skeleton, pid: 7,
timestamp: 12.5, length: 1092)
let bytes = h.encoded()
XCTAssertEqual(bytes.count, FrameHeader.byteCount)
let decoded = FrameHeader(decoding: bytes)
XCTAssertEqual(decoded, h)
}
func testRejectsBadMagic() {
var bytes = FrameHeader(tag: .video, pid: -1,
timestamp: 0, length: 0).encoded()
bytes[0] = 0x00
XCTAssertNil(FrameHeader(decoding: bytes))
}
func testRejectsShortBuffer() {
XCTAssertNil(FrameHeader(decoding: Data([0x41, 0x56])))
}
}