diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-05 19:59:21 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-05 19:59:21 +0100 |
| commit | 6c09e3bdb5128dca64c457c3a6ebeb32adf98c10 (patch) | |
| tree | d943db66547776c295c1895852eaf9a8cbec506b /src/tests/test_tracker.cc | |
| parent | 64c19b368db4aea748467b5f763add99c7deb701 (diff) | |
feat(audio): Complete Phase 2 - Migrate tests to AudioEngine (Task #56)
Migrated all tracker-related tests to use AudioEngine instead of directly
calling synth_init() and tracker_init(), eliminating fragile initialization
order dependencies.
Tests Migrated:
- test_tracker.cc: Basic tracker functionality
- test_tracker_timing.cc: Timing verification with MockAudioBackend (7 tests)
- test_variable_tempo.cc: Variable tempo scaling (6 tests)
- test_wav_dump.cc: WAV dump backend verification
Migration Pattern:
- Added AudioEngine include to all test files
- Replaced synth_init() + tracker_init() with AudioEngine::init()
- Replaced tracker_update(time) with engine.update(time)
- Added engine.shutdown() at end of each test function
- Preserved audio_init()/audio_shutdown() where needed for backends
Results:
- All 20 tests pass (100% pass rate)
- Test suite time: 8.13s (slightly faster)
- No regressions in test behavior
- Cleaner API with single initialization entry point
Next Steps (Phase 3):
- Migrate main.cc and production code to use AudioEngine
- Add backwards compatibility shims during transition
handoff(Claude): Completed Task #56 Phase 2 - all tracker tests now use
AudioEngine. The initialization order fragility is eliminated in test code.
Ready for Phase 3 (production integration).
Diffstat (limited to 'src/tests/test_tracker.cc')
| -rw-r--r-- | src/tests/test_tracker.cc | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/src/tests/test_tracker.cc b/src/tests/test_tracker.cc index 9285728..ae06c5e 100644 --- a/src/tests/test_tracker.cc +++ b/src/tests/test_tracker.cc @@ -1,6 +1,7 @@ // This file is part of the 64k demo project. // It tests the core functionality of the audio tracker engine. +#include "audio/audio_engine.h" #include "audio/gen.h" #include "audio/synth.h" #include "audio/tracker.h" @@ -16,14 +17,15 @@ extern const uint32_t g_tracker_patterns_count; extern const TrackerScore g_tracker_score; void test_tracker_init() { - synth_init(); - tracker_init(); + AudioEngine engine; + engine.init(); printf("Tracker init test PASSED\n"); + engine.shutdown(); } void test_tracker_pattern_triggering() { - synth_init(); - tracker_init(); + AudioEngine engine; + engine.init(); // At time 0.0f, 3 patterns are triggered: // - crash (1 event at beat 0.0) @@ -32,28 +34,29 @@ void test_tracker_pattern_triggering() { // With event-based triggering, only events at beat 0.0 trigger immediately. // Test 1: At music_time = 0.0f, events at beat 0.0 trigger - tracker_update(0.0f); + engine.update(0.0f); // Expect 3 voices: crash (beat 0.0), kick (beat 0.0), hihat (beat 0.0) - assert(synth_get_active_voice_count() == 3); + assert(engine.get_active_voice_count() == 3); // Test 2: At music_time = 0.25f (beat 0.5 @ 120 BPM), hihat event triggers // beat_duration = 60.0f / 120.0f = 0.5s per beat // beat 0.5 = 0.25s - tracker_update(0.25f); + engine.update(0.25f); // Expect 4 voices (3 previous + 1 hihat at beat 0.5) - assert(synth_get_active_voice_count() == 4); + assert(engine.get_active_voice_count() == 4); // Test 3: At music_time = 0.5f (beat 1.0), hihat event triggers - tracker_update(0.5f); + engine.update(0.5f); // Expect 5 voices (4 previous + 1 hihat at beat 1.0) - assert(synth_get_active_voice_count() == 5); + assert(engine.get_active_voice_count() == 5); // Test 4: Advance to 2.0f - new patterns trigger at time 2.0f - tracker_update(2.0f); + engine.update(2.0f); // Many events have triggered by now - assert(synth_get_active_voice_count() > 5); + assert(engine.get_active_voice_count() > 5); printf("Tracker pattern triggering test PASSED\n"); + engine.shutdown(); } int main() { |
