Add gdlint and gdformat scripts
This commit is contained in:
@@ -12,6 +12,7 @@ var audio_manager: Node
|
||||
var original_music_volume: float
|
||||
var original_sfx_volume: float
|
||||
|
||||
|
||||
func _initialize():
|
||||
# Wait for autoloads to initialize
|
||||
await process_frame
|
||||
@@ -22,6 +23,7 @@ func _initialize():
|
||||
# Exit after tests complete
|
||||
quit()
|
||||
|
||||
|
||||
func run_tests():
|
||||
TestHelper.print_test_header("AudioManager")
|
||||
|
||||
@@ -54,11 +56,16 @@ func run_tests():
|
||||
|
||||
TestHelper.print_test_footer("AudioManager")
|
||||
|
||||
|
||||
func test_basic_functionality():
|
||||
TestHelper.print_step("Basic Functionality")
|
||||
|
||||
# Test that AudioManager has expected properties
|
||||
TestHelper.assert_has_properties(audio_manager, ["music_player", "ui_click_player", "click_stream"], "AudioManager properties")
|
||||
TestHelper.assert_has_properties(
|
||||
audio_manager,
|
||||
["music_player", "ui_click_player", "click_stream"],
|
||||
"AudioManager properties"
|
||||
)
|
||||
|
||||
# Test that AudioManager has expected methods
|
||||
var expected_methods = ["update_music_volume", "play_ui_click"]
|
||||
@@ -66,7 +73,10 @@ func test_basic_functionality():
|
||||
|
||||
# Test that AudioManager has expected constants
|
||||
TestHelper.assert_true("MUSIC_PATH" in audio_manager, "MUSIC_PATH constant exists")
|
||||
TestHelper.assert_true("UI_CLICK_SOUND_PATH" in audio_manager, "UI_CLICK_SOUND_PATH constant exists")
|
||||
TestHelper.assert_true(
|
||||
"UI_CLICK_SOUND_PATH" in audio_manager, "UI_CLICK_SOUND_PATH constant exists"
|
||||
)
|
||||
|
||||
|
||||
func test_audio_constants():
|
||||
TestHelper.print_step("Audio File Constants")
|
||||
@@ -76,7 +86,9 @@ func test_audio_constants():
|
||||
var click_path = audio_manager.UI_CLICK_SOUND_PATH
|
||||
|
||||
TestHelper.assert_true(music_path.begins_with("res://"), "Music path uses res:// protocol")
|
||||
TestHelper.assert_true(click_path.begins_with("res://"), "Click sound path uses res:// protocol")
|
||||
TestHelper.assert_true(
|
||||
click_path.begins_with("res://"), "Click sound path uses res:// protocol"
|
||||
)
|
||||
|
||||
# Test file extensions
|
||||
var valid_audio_extensions = [".wav", ".ogg", ".mp3"]
|
||||
@@ -96,22 +108,39 @@ func test_audio_constants():
|
||||
TestHelper.assert_true(ResourceLoader.exists(music_path), "Music file exists at path")
|
||||
TestHelper.assert_true(ResourceLoader.exists(click_path), "Click sound file exists at path")
|
||||
|
||||
|
||||
func test_audio_player_initialization():
|
||||
TestHelper.print_step("Audio Player Initialization")
|
||||
|
||||
# Test music player initialization
|
||||
TestHelper.assert_not_null(audio_manager.music_player, "Music player is initialized")
|
||||
TestHelper.assert_true(audio_manager.music_player is AudioStreamPlayer, "Music player is AudioStreamPlayer type")
|
||||
TestHelper.assert_true(audio_manager.music_player.get_parent() == audio_manager, "Music player is child of AudioManager")
|
||||
TestHelper.assert_true(
|
||||
audio_manager.music_player is AudioStreamPlayer, "Music player is AudioStreamPlayer type"
|
||||
)
|
||||
TestHelper.assert_true(
|
||||
audio_manager.music_player.get_parent() == audio_manager,
|
||||
"Music player is child of AudioManager"
|
||||
)
|
||||
|
||||
# Test UI click player initialization
|
||||
TestHelper.assert_not_null(audio_manager.ui_click_player, "UI click player is initialized")
|
||||
TestHelper.assert_true(audio_manager.ui_click_player is AudioStreamPlayer, "UI click player is AudioStreamPlayer type")
|
||||
TestHelper.assert_true(audio_manager.ui_click_player.get_parent() == audio_manager, "UI click player is child of AudioManager")
|
||||
TestHelper.assert_true(
|
||||
audio_manager.ui_click_player is AudioStreamPlayer,
|
||||
"UI click player is AudioStreamPlayer type"
|
||||
)
|
||||
TestHelper.assert_true(
|
||||
audio_manager.ui_click_player.get_parent() == audio_manager,
|
||||
"UI click player is child of AudioManager"
|
||||
)
|
||||
|
||||
# Test audio bus assignment
|
||||
TestHelper.assert_equal("Music", audio_manager.music_player.bus, "Music player assigned to Music bus")
|
||||
TestHelper.assert_equal("SFX", audio_manager.ui_click_player.bus, "UI click player assigned to SFX bus")
|
||||
TestHelper.assert_equal(
|
||||
"Music", audio_manager.music_player.bus, "Music player assigned to Music bus"
|
||||
)
|
||||
TestHelper.assert_equal(
|
||||
"SFX", audio_manager.ui_click_player.bus, "UI click player assigned to SFX bus"
|
||||
)
|
||||
|
||||
|
||||
func test_stream_loading_and_validation():
|
||||
TestHelper.print_step("Stream Loading and Validation")
|
||||
@@ -119,12 +148,16 @@ func test_stream_loading_and_validation():
|
||||
# Test music stream loading
|
||||
TestHelper.assert_not_null(audio_manager.music_player.stream, "Music stream is loaded")
|
||||
if audio_manager.music_player.stream:
|
||||
TestHelper.assert_true(audio_manager.music_player.stream is AudioStream, "Music stream is AudioStream type")
|
||||
TestHelper.assert_true(
|
||||
audio_manager.music_player.stream is AudioStream, "Music stream is AudioStream type"
|
||||
)
|
||||
|
||||
# Test click stream loading
|
||||
TestHelper.assert_not_null(audio_manager.click_stream, "Click stream is loaded")
|
||||
if audio_manager.click_stream:
|
||||
TestHelper.assert_true(audio_manager.click_stream is AudioStream, "Click stream is AudioStream type")
|
||||
TestHelper.assert_true(
|
||||
audio_manager.click_stream is AudioStream, "Click stream is AudioStream type"
|
||||
)
|
||||
|
||||
# Test stream resource loading directly
|
||||
var loaded_music = load(audio_manager.MUSIC_PATH)
|
||||
@@ -135,6 +168,7 @@ func test_stream_loading_and_validation():
|
||||
TestHelper.assert_not_null(loaded_click, "Click resource loads successfully")
|
||||
TestHelper.assert_true(loaded_click is AudioStream, "Loaded click sound is AudioStream type")
|
||||
|
||||
|
||||
func test_audio_bus_configuration():
|
||||
TestHelper.print_step("Audio Bus Configuration")
|
||||
|
||||
@@ -147,10 +181,17 @@ func test_audio_bus_configuration():
|
||||
|
||||
# Test player bus assignments match actual AudioServer buses
|
||||
if music_bus_index >= 0:
|
||||
TestHelper.assert_equal("Music", audio_manager.music_player.bus, "Music player correctly assigned to Music bus")
|
||||
TestHelper.assert_equal(
|
||||
"Music", audio_manager.music_player.bus, "Music player correctly assigned to Music bus"
|
||||
)
|
||||
|
||||
if sfx_bus_index >= 0:
|
||||
TestHelper.assert_equal("SFX", audio_manager.ui_click_player.bus, "UI click player correctly assigned to SFX bus")
|
||||
TestHelper.assert_equal(
|
||||
"SFX",
|
||||
audio_manager.ui_click_player.bus,
|
||||
"UI click player correctly assigned to SFX bus"
|
||||
)
|
||||
|
||||
|
||||
func test_volume_management():
|
||||
TestHelper.print_step("Volume Management")
|
||||
@@ -162,33 +203,49 @@ func test_volume_management():
|
||||
|
||||
# Test volume update to valid range
|
||||
audio_manager.update_music_volume(0.5)
|
||||
TestHelper.assert_float_equal(linear_to_db(0.5), audio_manager.music_player.volume_db, 0.001, "Music volume set correctly")
|
||||
TestHelper.assert_float_equal(
|
||||
linear_to_db(0.5), audio_manager.music_player.volume_db, 0.001, "Music volume set correctly"
|
||||
)
|
||||
|
||||
# Test volume update to zero (should stop music)
|
||||
audio_manager.update_music_volume(0.0)
|
||||
TestHelper.assert_equal(linear_to_db(0.0), audio_manager.music_player.volume_db, "Zero volume set correctly")
|
||||
TestHelper.assert_equal(
|
||||
linear_to_db(0.0), audio_manager.music_player.volume_db, "Zero volume set correctly"
|
||||
)
|
||||
# Note: We don't test playing state as it depends on initialization conditions
|
||||
|
||||
# Test volume update to maximum
|
||||
audio_manager.update_music_volume(1.0)
|
||||
TestHelper.assert_equal(linear_to_db(1.0), audio_manager.music_player.volume_db, "Maximum volume set correctly")
|
||||
TestHelper.assert_equal(
|
||||
linear_to_db(1.0), audio_manager.music_player.volume_db, "Maximum volume set correctly"
|
||||
)
|
||||
|
||||
# Test volume range validation
|
||||
var test_volumes = [0.0, 0.25, 0.5, 0.75, 1.0]
|
||||
for volume in test_volumes:
|
||||
audio_manager.update_music_volume(volume)
|
||||
var expected_db = linear_to_db(volume)
|
||||
TestHelper.assert_float_equal(expected_db, audio_manager.music_player.volume_db, 0.001, "Volume %f converts correctly to dB" % volume)
|
||||
TestHelper.assert_float_equal(
|
||||
expected_db,
|
||||
audio_manager.music_player.volume_db,
|
||||
0.001,
|
||||
"Volume %f converts correctly to dB" % volume
|
||||
)
|
||||
|
||||
# Restore original volume
|
||||
audio_manager.update_music_volume(original_volume)
|
||||
|
||||
|
||||
func test_music_playback_control():
|
||||
TestHelper.print_step("Music Playback Control")
|
||||
|
||||
# Test that music player exists and has a stream
|
||||
TestHelper.assert_not_null(audio_manager.music_player, "Music player exists for playback testing")
|
||||
TestHelper.assert_not_null(audio_manager.music_player.stream, "Music player has stream for playback testing")
|
||||
TestHelper.assert_not_null(
|
||||
audio_manager.music_player, "Music player exists for playback testing"
|
||||
)
|
||||
TestHelper.assert_not_null(
|
||||
audio_manager.music_player.stream, "Music player has stream for playback testing"
|
||||
)
|
||||
|
||||
# Test playback state management
|
||||
# Note: We test the control methods exist and can be called safely
|
||||
@@ -213,6 +270,7 @@ func test_music_playback_control():
|
||||
audio_manager.update_music_volume(0.0)
|
||||
TestHelper.assert_true(true, "Volume-based playback stop works")
|
||||
|
||||
|
||||
func test_ui_sound_effects():
|
||||
TestHelper.print_step("UI Sound Effects")
|
||||
|
||||
@@ -225,7 +283,11 @@ func test_ui_sound_effects():
|
||||
audio_manager.play_ui_click()
|
||||
|
||||
# Verify click stream was assigned to player
|
||||
TestHelper.assert_equal(audio_manager.click_stream, audio_manager.ui_click_player.stream, "Click stream assigned to player")
|
||||
TestHelper.assert_equal(
|
||||
audio_manager.click_stream,
|
||||
audio_manager.ui_click_player.stream,
|
||||
"Click stream assigned to player"
|
||||
)
|
||||
|
||||
# Test multiple rapid clicks (should not cause errors)
|
||||
for i in range(3):
|
||||
@@ -239,6 +301,7 @@ func test_ui_sound_effects():
|
||||
TestHelper.assert_true(true, "Null click stream handled safely")
|
||||
audio_manager.click_stream = backup_stream
|
||||
|
||||
|
||||
func test_stream_loop_configuration():
|
||||
TestHelper.print_step("Stream Loop Configuration")
|
||||
|
||||
@@ -250,7 +313,11 @@ func test_stream_loop_configuration():
|
||||
var has_loop_mode = "loop_mode" in music_stream
|
||||
TestHelper.assert_true(has_loop_mode, "WAV stream has loop_mode property")
|
||||
if has_loop_mode:
|
||||
TestHelper.assert_equal(AudioStreamWAV.LOOP_FORWARD, music_stream.loop_mode, "WAV stream set to forward loop")
|
||||
TestHelper.assert_equal(
|
||||
AudioStreamWAV.LOOP_FORWARD,
|
||||
music_stream.loop_mode,
|
||||
"WAV stream set to forward loop"
|
||||
)
|
||||
elif music_stream is AudioStreamOggVorbis:
|
||||
# For OGG files, check loop property
|
||||
var has_loop = "loop" in music_stream
|
||||
@@ -261,6 +328,7 @@ func test_stream_loop_configuration():
|
||||
# Test loop configuration for different stream types
|
||||
TestHelper.assert_true(true, "Stream loop configuration tested based on type")
|
||||
|
||||
|
||||
func test_error_handling():
|
||||
TestHelper.print_step("Error Handling")
|
||||
|
||||
@@ -268,11 +336,17 @@ func test_error_handling():
|
||||
# We can't actually break the resources in tests, but we can verify error handling patterns
|
||||
|
||||
# Test that AudioManager initializes even with potential issues
|
||||
TestHelper.assert_not_null(audio_manager, "AudioManager initializes despite potential resource issues")
|
||||
TestHelper.assert_not_null(
|
||||
audio_manager, "AudioManager initializes despite potential resource issues"
|
||||
)
|
||||
|
||||
# Test that players are still created even if streams fail to load
|
||||
TestHelper.assert_not_null(audio_manager.music_player, "Music player created regardless of stream loading")
|
||||
TestHelper.assert_not_null(audio_manager.ui_click_player, "UI click player created regardless of stream loading")
|
||||
TestHelper.assert_not_null(
|
||||
audio_manager.music_player, "Music player created regardless of stream loading"
|
||||
)
|
||||
TestHelper.assert_not_null(
|
||||
audio_manager.ui_click_player, "UI click player created regardless of stream loading"
|
||||
)
|
||||
|
||||
# Test null stream handling in play_ui_click
|
||||
var original_click_stream = audio_manager.click_stream
|
||||
@@ -292,6 +366,7 @@ func test_error_handling():
|
||||
audio_manager.update_music_volume(1.0)
|
||||
TestHelper.assert_true(true, "Maximum volume handled safely")
|
||||
|
||||
|
||||
func cleanup_tests():
|
||||
TestHelper.print_step("Cleanup")
|
||||
|
||||
@@ -303,4 +378,4 @@ func cleanup_tests():
|
||||
# Update AudioManager to original settings
|
||||
audio_manager.update_music_volume(original_music_volume)
|
||||
|
||||
TestHelper.assert_true(true, "Test cleanup completed")
|
||||
TestHelper.assert_true(true, "Test cleanup completed")
|
||||
|
||||
Reference in New Issue
Block a user