diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/tests/test_wav_dump.cc | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/tests/test_wav_dump.cc b/src/tests/test_wav_dump.cc index aa195cc..529d086 100644 --- a/src/tests/test_wav_dump.cc +++ b/src/tests/test_wav_dump.cc @@ -238,6 +238,58 @@ void test_clipping_detection() { printf(" ✓ Clipping detection works correctly\n"); } +void test_invalid_file_paths() { + printf("Test: Error handling for invalid file paths...\n"); + + // Test 1: Null filename (should handle gracefully) + { + WavDumpBackend wav_backend; + wav_backend.set_output_file(nullptr); + wav_backend.init(); // Should print error but not crash + + // Verify file didn't open + float samples[10] = {0.5f}; + wav_backend.write_audio(samples, 10); // Should do nothing + + assert(wav_backend.get_samples_written() == 0); + wav_backend.shutdown(); + + printf(" ✓ Null filename handled gracefully\n"); + } + + // Test 2: Invalid directory path + { + WavDumpBackend wav_backend; + wav_backend.set_output_file("/nonexistent/directory/test.wav"); + wav_backend.init(); // Should print error but not crash + + float samples[10] = {0.5f}; + wav_backend.write_audio(samples, 10); // Should do nothing + + assert(wav_backend.get_samples_written() == 0); + wav_backend.shutdown(); + + printf(" ✓ Invalid directory path handled gracefully\n"); + } + + // Test 3: Read-only location (permissions error) + { + WavDumpBackend wav_backend; + wav_backend.set_output_file("/test.wav"); // Root directory (no write permission) + wav_backend.init(); // Should print error but not crash + + float samples[10] = {0.5f}; + wav_backend.write_audio(samples, 10); // Should do nothing + + assert(wav_backend.get_samples_written() == 0); + wav_backend.shutdown(); + + printf(" ✓ Permission denied handled gracefully\n"); + } + + printf(" ✓ All error cases handled without crashes\n"); +} + #endif /* !defined(STRIP_ALL) */ int main() { @@ -246,6 +298,7 @@ int main() { test_wav_format_matches_live_audio(); test_wav_stereo_buffer_size(); test_clipping_detection(); + test_invalid_file_paths(); printf("\n✅ All WAV Dump tests PASSED\n"); return 0; #else |
