diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-09 20:27:04 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-09 20:27:04 +0100 |
| commit | eff8d43479e7704df65fae2a80eefa787213f502 (patch) | |
| tree | 76f2fb8fe8d3db2c15179449df2cf12f7f54e0bf /src/tests/audio/test_tracker.cc | |
| parent | 12378b1b7e9091ba59895b4360b2fa959180a56a (diff) | |
refactor: Reorganize tests into subsystem subdirectories
Restructured test suite for better organization and targeted testing:
**Structure:**
- src/tests/audio/ - 15 audio system tests
- src/tests/gpu/ - 12 GPU/shader tests
- src/tests/3d/ - 6 3D rendering tests
- src/tests/assets/ - 2 asset system tests
- src/tests/util/ - 3 utility tests
- src/tests/common/ - 3 shared test helpers
- src/tests/scripts/ - 2 bash test scripts (moved conceptually, not physically)
**CMake changes:**
- Updated add_demo_test macro to accept LABEL parameter
- Applied CTest labels to all 36 tests for subsystem filtering
- Updated all test file paths in CMakeLists.txt
- Fixed common helper paths (webgpu_test_fixture, etc.)
- Added custom targets for subsystem testing:
- run_audio_tests, run_gpu_tests, run_3d_tests
- run_assets_tests, run_util_tests, run_all_tests
**Include path updates:**
- Fixed relative includes in GPU tests to reference ../common/
**Documentation:**
- Updated doc/HOWTO.md with subsystem test commands
- Updated doc/CONTRIBUTING.md with new test organization
- Updated scripts/check_all.sh to reflect new structure
**Verification:**
- All 36 tests passing (100%)
- ctest -L <subsystem> filters work correctly
- make run_<subsystem>_tests targets functional
- scripts/check_all.sh passes
Backward compatible: make test and ctest continue to work unchanged.
handoff(Gemini): Test reorganization complete. 36/36 tests passing.
Diffstat (limited to 'src/tests/audio/test_tracker.cc')
| -rw-r--r-- | src/tests/audio/test_tracker.cc | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/src/tests/audio/test_tracker.cc b/src/tests/audio/test_tracker.cc new file mode 100644 index 0000000..6be2a8d --- /dev/null +++ b/src/tests/audio/test_tracker.cc @@ -0,0 +1,73 @@ +// 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" +// #include "generated/music_data.h" // Will be generated by tracker_compiler +#include <assert.h> +#include <stdio.h> + +// Forward declaration for generated data +extern const NoteParams g_tracker_samples[]; +extern const uint32_t g_tracker_samples_count; +extern const TrackerPattern g_tracker_patterns[]; +extern const uint32_t g_tracker_patterns_count; +extern const TrackerScore g_tracker_score; + +void test_tracker_init() { + AudioEngine engine; + engine.init(); + printf("Tracker init test PASSED\n"); + engine.shutdown(); +} + +void test_tracker_pattern_triggering() { + AudioEngine engine; + engine.init(); + + // At time 0.0f, 3 patterns are triggered: + // - crash (1 event at beat 0.0) + // - kick_basic (events at beat 0.0, 2.0, 2.5) + // - hihat_basic (events at beat 0.0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5) + // 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 + // drums_basic: + // 0.00, ASSET_KICK_1 + // 0.00, NOTE_A4 + engine.update(0.0f, 0.0f); + // Expect 2 voices: kick + note + assert(engine.get_active_voice_count() == 2); + + // Test 2: At music_time = 0.25f (beat 0.5 @ 120 BPM), snare event triggers + // 0.25, ASSET_SNARE_1 + engine.update(0.25f, 0.0f); + // Expect at least 2 voices (snare + maybe others) + // Exact count depends on sample duration (kick/note might have finished) + int voices = engine.get_active_voice_count(); + assert(voices >= 2); + + // Test 3: At music_time = 0.5f (beat 1.0), kick event triggers + // 0.50, ASSET_KICK_1 + engine.update(0.5f, 0.0f); + // Expect at least 3 voices (new kick + others) + assert(engine.get_active_voice_count() >= 3); + + // Test 4: Advance to 2.0f - new patterns trigger at time 2.0f + engine.update(2.0f, 0.0f); + // Many events have triggered by now + assert(engine.get_active_voice_count() > 5); + + printf("Tracker pattern triggering test PASSED\n"); + engine.shutdown(); +} + +int main() { + printf("Running Tracker tests...\n"); + test_tracker_init(); + test_tracker_pattern_triggering(); + printf("Tracker tests PASSED\n"); + return 0; +} |
