Files
ShoeGaze/Tests/LyrebirdShoeGazeTests/ShoeGazeMultiBoardTests.swift
T
2026-06-21 12:25:18 -07:00

92 lines
3.0 KiB
Swift

// ShoeGazeMultiBoardTests.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import Testing
import Foundation
import LyrebirdSynth
import LyrebirdUI
@testable import LyrebirdShoeGaze
@MainActor
@Suite("ShoeGaze multi-board")
struct ShoeGazeMultiBoardTests {
@Test func addBoardAssignsLabelAndFinalizeWiresMasterNode() throws {
let renderDuration: Double = 0.05
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(
duration: renderDuration,
numAudioBuses: 64
)
defer { try? FileManager.default.removeItem(at: url) }
let shoeGaze: ShoeGaze = ShoeGaze(engine: engine)
let board1: PedalBoard = try shoeGaze.addBoard()
#expect(board1.label == "Board 1")
#expect(board1.masterGainNode == nil, "Master node is nil until finalizeBoard")
try board1.add(OverdrivePedal())
try shoeGaze.finalizeBoard(board1)
#expect(board1.masterGainNode != nil, "finalizeBoard must expose the master gain node")
let board2: PedalBoard = try shoeGaze.addBoard()
#expect(board2.label == "Board 2")
try board2.add(DelayPedal())
try shoeGaze.finalizeBoard(board2)
#expect(shoeGaze.boards.count == 2)
}
@Test func removeBoardLeavesOtherBoards() throws {
let renderDuration: Double = 0.05
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(
duration: renderDuration,
numAudioBuses: 64
)
defer { try? FileManager.default.removeItem(at: url) }
let shoeGaze: ShoeGaze = ShoeGaze(engine: engine)
let board1: PedalBoard = try shoeGaze.addBoard()
try board1.add(OverdrivePedal())
try shoeGaze.finalizeBoard(board1)
let board2: PedalBoard = try shoeGaze.addBoard()
try board2.add(DelayPedal())
try shoeGaze.finalizeBoard(board2)
#expect(shoeGaze.boards.count == 2)
shoeGaze.removeBoard(board1)
#expect(shoeGaze.boards.count == 1)
#expect(shoeGaze.boards.first === board2, "Remaining board must be the one not removed")
}
@Test func twoBoardsRenderNonSilent() throws {
let renderDuration: Double = 0.2
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(
duration: renderDuration,
numAudioBuses: 64
)
defer { try? FileManager.default.removeItem(at: url) }
let shoeGaze: ShoeGaze = ShoeGaze(engine: engine)
let board1: PedalBoard = try shoeGaze.addBoard()
try board1.add(OverdrivePedal())
try shoeGaze.finalizeBoard(board1)
let board2: PedalBoard = try shoeGaze.addBoard()
try board2.add(DelayPedal())
try shoeGaze.finalizeBoard(board2)
try engine.start()
let samples: [Float] = readStereoCAF(url: url)
#expect(!samples.isEmpty, "Two-board ShoeGaze produced no samples")
#expect(hasNonSilentOutput(samples), "Two-board ShoeGaze produced silence")
}
}