extends GdUnitTestSuite ## Reading songs from files by their type. @warning_ignore("unused_parameter") func test_playable_types_load( file_name: String, type: GDScript, test_parameters: Array = [ ["short.mp3", AudioStreamMP3], ["short.ogg", AudioStreamOggVorbis], ["short.wav", AudioStreamWAV], ], ) -> void: var stream: AudioStream = AudioFile.load("res://tests/data/" + file_name) assert_object(stream).is_not_null() assert_bool(is_instance_of(stream, type)).is_true() assert_float(stream.get_length()).is_greater(0.0) func test_missing_file_gives_null() -> void: assert_object(AudioFile.load("res://tests/data/missing.mp3")).is_null() func test_other_types_give_null() -> void: var path: String = create_temp_dir("audio_file").path_join("song.flac") FileAccess.open(path, FileAccess.WRITE).store_buffer( FileAccess.get_file_as_bytes("res://tests/data/short.mp3")) assert_object(AudioFile.load(path)).is_null() func test_broken_file_gives_null() -> void: var path: String = create_temp_dir("audio_file").path_join("broken.mp3") FileAccess.open(path, FileAccess.WRITE).store_string("not a song") assert_object(AudioFile.load(path)).is_null() func test_playable_types() -> void: assert_bool(AudioFile.is_playable("a/b/Song.MP3")).is_true() assert_bool(AudioFile.is_playable("Song.ogg")).is_true() assert_bool(AudioFile.is_playable("Song.wav")).is_true() assert_bool(AudioFile.is_playable("Song.flac")).is_false() assert_bool(AudioFile.is_playable("cover.jpg")).is_false()