FakeMoteurAudioCapture.swift 27 lignes · 861 octets
import Foundation
@testable import Card2vcf

/// Faux MoteurAudioCapture pour les tests d'AudioNoteRecorder.
/// Permet de simuler des échantillons PCM sans matériel audio réel.
final class FakeMoteurAudioCapture: MoteurAudioCapture {
    private(set) var estDemarre = false
    private var callback: (([Int16]) -> Void)?
    /// Si non nil, `demarrer` lève cette erreur.
    var prochainErreur: Error?

    func demarrer(onEchantillons: @escaping ([Int16]) -> Void) throws {
        if let erreur = prochainErreur { throw erreur }
        estDemarre = true
        callback = onEchantillons
    }

    func arreter() {
        estDemarre = false
        callback = nil
    }

    /// Pousse des échantillons PCM vers l'enregistreur comme si le matériel les avait capturés.
    func simulerEchantillons(_ data: [Int16]) {
        callback?(data)
    }
}