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.
drop.two/Tests/DropTwoCoreTests/ConversionPipelineTests.swift

113 lines
5.1 KiB

import XCTest
@testable import DropTwoCore
final class ConversionPipelineTests: XCTestCase {
private var tempDirectory: URL!
private var outputDirectory: URL!
override func setUpWithError() throws {
tempDirectory = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString)
outputDirectory = tempDirectory.appendingPathComponent("output")
try FileManager.default.createDirectory(at: outputDirectory, withIntermediateDirectories: true)
}
override func tearDownWithError() throws {
try? FileManager.default.removeItem(at: tempDirectory)
}
func testPreviewDestinationMatchesActualOutput() async throws {
let clip = try TestVideoFactory.makeNineBySixteenClip(fileName: "SOMOS-9x16-v3-DE.mov", in: tempDirectory)
let preview = ConversionPipeline.previewDestination(sourceURL: clip.url, outputRootDirectory: outputDirectory)
let outcome = await ConversionPipeline.process(sourceURL: clip.url, outputRootDirectory: outputDirectory)
guard case .succeeded(let success) = outcome else {
return XCTFail("Erwartete .succeeded, bekam \(outcome)")
}
XCTAssertEqual(preview, success.croppedDestination)
}
func testPreviewDestinationIsNilForUnparsableNames() {
let sourceURL = tempDirectory.appendingPathComponent("SOMOS-v3-DE.mov")
XCTAssertNil(ConversionPipeline.previewDestination(sourceURL: sourceURL, outputRootDirectory: outputDirectory))
}
func testProcessesValidFileEndToEnd() async throws {
let clip = try TestVideoFactory.makeNineBySixteenClip(fileName: "SOMOS-9x16-v3-DE.mov", in: tempDirectory)
let outcome = await ConversionPipeline.process(sourceURL: clip.url, outputRootDirectory: outputDirectory)
guard case .succeeded(let success) = outcome else {
return XCTFail("Erwartete .succeeded, bekam \(outcome)")
}
XCTAssertEqual(success.croppedDestination.lastPathComponent, "SOMOS-4x5-v3-DE.mp4")
XCTAssertEqual(success.croppedDestination.deletingLastPathComponent().lastPathComponent, "SOMOS")
XCTAssertTrue(FileManager.default.fileExists(atPath: success.originalDestination.path))
XCTAssertTrue(FileManager.default.fileExists(atPath: success.croppedDestination.path))
XCTAssertEqual(success.croppedInfo.pixelSize, CropEngine.targetSize(forSourceSize: clip.size))
}
func testSkipsWithoutTouchingFileSystem() async {
let sourceURL = tempDirectory.appendingPathComponent("SOMOS-4x5-v3-DE.mov")
let outcome = await ConversionPipeline.process(sourceURL: sourceURL, outputRootDirectory: outputDirectory)
guard case .skipped(let fileName, let reason) = outcome else {
return XCTFail("Erwartete .skipped, bekam \(outcome)")
}
XCTAssertEqual(fileName, "SOMOS-4x5-v3-DE.mov")
XCTAssertEqual(reason, .alreadyTargetFormat)
XCTAssertTrue(try! FileManager.default.contentsOfDirectory(atPath: outputDirectory.path).isEmpty)
}
func testRejectsWithoutTouchingFileSystem() async {
let sourceURL = tempDirectory.appendingPathComponent("SOMOS-v3-DE.mov")
let outcome = await ConversionPipeline.process(sourceURL: sourceURL, outputRootDirectory: outputDirectory)
guard case .rejected(let fileName, let reason) = outcome else {
return XCTFail("Erwartete .rejected, bekam \(outcome)")
}
XCTAssertEqual(fileName, "SOMOS-v3-DE.mov")
XCTAssertEqual(reason, .formatSegmentMissing)
XCTAssertTrue(try! FileManager.default.contentsOfDirectory(atPath: outputDirectory.path).isEmpty)
}
func testFailsWhenSourceHasWrongAspectRatio() async throws {
let clip = try TestVideoFactory.makeClip(
size: CGSize(width: 400, height: 400),
fileName: "SOMOS-9x16-v3-DE.mov",
in: tempDirectory
)
let outcome = await ConversionPipeline.process(sourceURL: clip.url, outputRootDirectory: outputDirectory)
guard case .failed(let fileName, let error) = outcome else {
return XCTFail("Erwartete .failed, bekam \(outcome)")
}
XCTAssertEqual(fileName, "SOMOS-9x16-v3-DE.mov")
guard case CropEngineError.sourceNotNineBySixteen = error else {
return XCTFail("Erwartete CropEngineError.sourceNotNineBySixteen, bekam \(error)")
}
}
func testCanSkipCopyingTheOriginal() async throws {
let clip = try TestVideoFactory.makeNineBySixteenClip(fileName: "SOMOS-9x16-v3-DE.mov", in: tempDirectory)
let outcome = await ConversionPipeline.process(
sourceURL: clip.url,
outputRootDirectory: outputDirectory,
options: .init(copyOriginal: false)
)
guard case .succeeded(let success) = outcome else {
return XCTFail("Erwartete .succeeded, bekam \(outcome)")
}
XCTAssertEqual(success.originalDestination, clip.url)
let projectDirectory = outputDirectory.appendingPathComponent("SOMOS")
let contents = try FileManager.default.contentsOfDirectory(atPath: projectDirectory.path)
XCTAssertEqual(contents, ["SOMOS-4x5-v3-DE.mp4"])
}
}

Powered by TurnKey Linux.