You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.9 KiB
58 lines
1.9 KiB
import CoreMedia
|
|
import XCTest
|
|
@testable import DropTwoCore
|
|
|
|
final class VideoInspectorTests: XCTestCase {
|
|
private var tempDirectory: URL!
|
|
|
|
override func setUpWithError() throws {
|
|
tempDirectory = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString)
|
|
try FileManager.default.createDirectory(at: tempDirectory, withIntermediateDirectories: true)
|
|
}
|
|
|
|
override func tearDownWithError() throws {
|
|
try? FileManager.default.removeItem(at: tempDirectory)
|
|
}
|
|
|
|
func testInspectsSynthesizedClip() async throws {
|
|
let clip = try TestVideoFactory.makeNineBySixteenClip(in: tempDirectory)
|
|
|
|
let info = try await VideoInspector.inspect(clip.url)
|
|
|
|
XCTAssertEqual(info.pixelSize, clip.size)
|
|
XCTAssertEqual(info.codec, .h264)
|
|
XCTAssertTrue(info.hasAudioTrack)
|
|
XCTAssertTrue(info.isNineBySixteen)
|
|
XCTAssertEqual(CMTimeGetSeconds(info.duration), clip.seconds, accuracy: 0.2)
|
|
}
|
|
|
|
func testRecognizesNonNineBySixteenAspectRatio() async throws {
|
|
let clip = try TestVideoFactory.makeClip(size: CGSize(width: 400, height: 400), in: tempDirectory)
|
|
|
|
let info = try await VideoInspector.inspect(clip.url)
|
|
|
|
XCTAssertFalse(info.isNineBySixteen)
|
|
}
|
|
|
|
func testDetectsMissingAudioTrack() async throws {
|
|
let clip = try TestVideoFactory.makeNineBySixteenClip(includeAudio: false, in: tempDirectory)
|
|
|
|
let info = try await VideoInspector.inspect(clip.url)
|
|
|
|
XCTAssertFalse(info.hasAudioTrack)
|
|
}
|
|
|
|
func testRejectsUnreadableFile() async {
|
|
let url = tempDirectory.appendingPathComponent("nope.mov")
|
|
|
|
do {
|
|
_ = try await VideoInspector.inspect(url)
|
|
XCTFail("Erwartete Fehler für eine nicht existierende Datei")
|
|
} catch is VideoInspectorError {
|
|
// erwartet
|
|
} catch {
|
|
XCTFail("Unerwarteter Fehlertyp: \(error)")
|
|
}
|
|
}
|
|
}
|