extends GutTest const AudioLibrary = preload("res://scripts/infrastructure/audio_library.gd") func test_missing_audio_directories_are_silent_for_known_requests() -> void: var library := AudioLibrary.new("res://tests/fixtures/missing-dcwascii") add_child_autofree(library) library.set_ambience_context("exploration") library.play_sfx("attack_given") assert_eq(library.current_ambience_context, "exploration") assert_eq(library.get_last_ambience_path(), "") assert_eq(library.get_last_sfx_path(), "") assert_false(library.has_playable_ambience()) assert_false(library.has_playable_sfx()) func test_unknown_requests_are_silent() -> void: var library := AudioLibrary.new("res://tests/fixtures/missing-dcwascii") add_child_autofree(library) library.set_ambience_context("exploration") library.set_ambience_context("unknown") library.play_sfx("unknown") assert_eq(library.current_ambience_context, "exploration") assert_eq(library.get_last_ambience_path(), "") assert_eq(library.get_last_sfx_path(), "") assert_false(library.has_playable_ambience()) assert_false(library.has_playable_sfx()) func test_legacy_external_directory_override_is_ignored_and_invalid_wavs_stay_silent() -> void: var root := ProjectSettings.globalize_path("user://s4-external-audio-library") var nominal_path := root.path_join("audio/exploration/silence.wav") var invalid_path := root.path_join("sfx/attack_given/not-a-wave.wav") DirAccess.make_dir_recursive_absolute(nominal_path.get_base_dir()) DirAccess.make_dir_recursive_absolute(invalid_path.get_base_dir()) var nominal_file := FileAccess.open(nominal_path, FileAccess.WRITE) nominal_file.store_string("this must not be loaded by the audio library") nominal_file.close() var invalid_file := FileAccess.open(invalid_path, FileAccess.WRITE) invalid_file.store_string("this is not a WAV file") invalid_file.close() var library := AudioLibrary.new(root) add_child_autofree(library) library.set_ambience_context("exploration") library.play_sfx("attack_given") assert_eq(library.get_last_ambience_path(), "") assert_eq(library.get_last_sfx_path(), "") assert_false(library.has_playable_ambience()) assert_false(library.has_playable_sfx())