Skip to content

📚 Test Examples

Real-world test examples for AudioLab


Overview

This directory contains example tests demonstrating AudioLab testing patterns:

  1. example_unit_test.cpp - Simple unit test for audio function
  2. example_integration_test.cpp - Component integration test
  3. example_benchmark.cpp - Performance benchmark
  4. example_golden_file_test.cpp - Audio quality validation

Each example is fully documented and ready to run.


Examples

1. Unit Test (example_unit_test.cpp)

Demonstrates: - Basic Catch2 structure - Audio-specific assertions - Floating-point comparisons - Test fixtures

Key patterns:

// Audio epsilon comparison
REQUIRE_THAT(output[i], WithinRel(expected[i], 0.0001f));

// Denormal detection
for (auto sample : output) {
    REQUIRE(std::fpclassify(sample) != FP_SUBNORMAL);
}

2. Integration Test (example_integration_test.cpp)

Demonstrates: - Multi-component testing - Audio buffer management - Parameter automation - State validation

Key patterns:

// Test full signal chain
auto processed = filter.process(reverb.process(input));

// Verify component interaction
REQUIRE(filter.get_latency() == reverb.get_latency());

3. Benchmark (example_benchmark.cpp)

Demonstrates: - Catch2 benchmark framework - Real-time constraint validation - CPU cycle measurement - Regression detection

Key patterns:

BENCHMARK("Process 512 samples @ 48kHz") {
    return processor.process(input.data(), output.data(), 512);
};

// Verify meets real-time deadline
REQUIRE(elapsed_time < 10.67ms);  // 512/48000

4. Golden File Test (example_golden_file_test.cpp)

Demonstrates: - Golden file loading/saving - Audio file comparison - Tolerance-based validation - Regression prevention

Key patterns:

GoldenFileManager golden("../golden_files");
auto reference = golden.load_wav("reverb_output.wav");

// Compare with tolerance
REQUIRE(golden.compare_wav("reverb_output.wav", actual, 0.01));


Building Examples

These are reference examples only (not compiled by default).

To use them:

# Copy to your test directory
cp examples/example_unit_test.cpp tests/test_my_feature.cpp

# Edit CMakeLists.txt
audiolab_add_test(test_my_feature tests/test_my_feature.cpp)

# Build and run
cmake --build build
./build/tests/test_my_feature

Adapting Examples

For Your Audio Function

  1. Copy example_unit_test.cpp
  2. Replace apply_gain() with your function
  3. Adjust test data and assertions
  4. Add to CMakeLists.txt

For Your Plugin

  1. Copy example_integration_test.cpp
  2. Replace processor with your plugin
  3. Test parameter changes, preset loading, etc.
  4. Verify latency, state, thread-safety

For Performance Validation

  1. Copy example_benchmark.cpp
  2. Replace with your DSP algorithm
  3. Set real-time target based on sample rate
  4. Run periodically to detect regressions

For Quality Assurance

  1. Copy example_golden_file_test.cpp
  2. Generate golden files from verified output
  3. Commit to Git LFS
  4. Run before releases

Resources


Use these examples as templates for your own tests! 🎧