📚 Test Examples¶
Real-world test examples for AudioLab
Overview¶
This directory contains example tests demonstrating AudioLab testing patterns:
- example_unit_test.cpp - Simple unit test for audio function
- example_integration_test.cpp - Component integration test
- example_benchmark.cpp - Performance benchmark
- 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¶
- Copy
example_unit_test.cpp - Replace
apply_gain()with your function - Adjust test data and assertions
- Add to CMakeLists.txt
For Your Plugin¶
- Copy
example_integration_test.cpp - Replace processor with your plugin
- Test parameter changes, preset loading, etc.
- Verify latency, state, thread-safety
For Performance Validation¶
- Copy
example_benchmark.cpp - Replace with your DSP algorithm
- Set real-time target based on sample rate
- Run periodically to detect regressions
For Quality Assurance¶
- Copy
example_golden_file_test.cpp - Generate golden files from verified output
- Commit to Git LFS
- Run before releases
Resources¶
- TEST_FRAMEWORK_PHILOSOPHY.md - Testing theory
- TEST_UTILITIES_GUIDE.md - Helper functions
- TEST_CHEAT_SHEET.md - Quick commands
Use these examples as templates for your own tests! 🎧