rinkplanner/rinkplanner/tests/run_playback_tests.gd
torsten 74d9d6b61f feat: Cloud-Sync über Dropbox und Google Drive
- FTP-Sync durch Cloud-Backends ersetzt (Dropbox, Google Drive)
- OAuth-Flow mit nutzereigenen Tokens und App-Key-Konfiguration
- Zeit-Tooltips für Timeline-Labels und Abschnittsbanner beim Playback
- Tests, Build-Konfiguration und Doku aktualisiert
2026-11-09 06:25:21 +01:00

592 lines
18 KiB
GDScript

extends SceneTree
## Headless tests for the playback dot and timeline.
##
## Run with:
## godot --headless --path rinkplanner --script res://tests/run_playback_tests.gd
const WhiteboardScene := preload("res://scenes/whiteboard/whiteboard.tscn")
var _assertions: int = 0
var _failures: PackedStringArray = PackedStringArray()
func _init() -> void:
_run.call_deferred()
func _run() -> void:
var scene := WhiteboardScene.instantiate()
var controller := scene as WhiteboardController
if controller != null:
controller.restore_autosave = false
controller.autosave_enabled = false
root.add_child(scene)
await process_frame
_check(controller != null, "playback scene has a controller")
if controller == null:
_finish()
return
_check_approx(controller.get_playback_duration(), 0.0, "empty routine has no duration")
_check(controller.play_button.disabled, "play is disabled without segments")
_check(controller.playback_timeline.editable == false, "timeline is disabled without segments")
var section_one := controller.get_active_section()
var forward := controller.add_segment(
Vector2(-20.0, 0.0),
Vector2(-8.0, 0.0),
PathSegment.Direction.FORWARD,
PathSegment.Edge.OUTSIDE
)
var backward := controller.add_segment(
Vector2(-8.0, 0.0),
Vector2(4.0, 0.0),
PathSegment.Direction.BACKWARD,
PathSegment.Edge.INSIDE
)
var section_two := controller.add_section()
var last := controller.add_segment(
Vector2(4.0, 0.0),
Vector2(16.0, 0.0),
PathSegment.Direction.FORWARD,
PathSegment.Edge.OUTSIDE
)
for segment: PathSegment in [forward, backward, last]:
segment.set_speed_mps(6.0)
controller._update_status()
_check_approx(controller.get_playback_duration(), 6.0, "duration sums all sections")
_check(not controller.play_button.disabled, "play is enabled with segments")
_check(controller.playback_timeline.editable, "timeline is enabled with segments")
_check_approx(
controller.playback_timeline.max_value,
6.0,
"timeline covers the whole routine"
)
controller.play()
controller.advance_playback(0.2)
controller.set_active_section(section_two.section_id)
_check(not controller.is_playing(), "section change stops active playback")
_check_approx(
controller.get_playback_time(),
4.0,
"selecting a section moves the playback to its start"
)
_check_approx(
controller.playback_timeline.value,
4.0,
"timeline slider jumps to the section start"
)
_check(
controller.get_playback_section_id() == section_two.section_id,
"playback reports the newly selected section"
)
_check_vec(
controller.get_playback_position(),
Vector2(4.0, 0.0),
"playback marker sits at the section start"
)
controller.set_active_section(section_one.section_id)
_check_approx(
controller.get_playback_time(),
0.0,
"switching back moves the playback to the first section"
)
_check_approx(
controller.playback_timeline.value,
0.0,
"timeline slider returns to the first section"
)
_check(
controller.get_playback_section_id() == section_one.section_id,
"playback reports the first section again"
)
# Keep the original active section for the marker tests below.
controller.set_active_section(section_two.section_id)
controller.seek_playback(1.0)
_check(not controller.is_playing(), "seeking does not start playback")
_check_vec(
controller.get_playback_position(),
Vector2(-14.0, 0.0),
"dot follows the first segment"
)
_check(
controller.get_playback_heading().x > 0.9,
"forward segment faces the travel direction"
)
_check(
controller.get_playback_section_id() == section_one.section_id,
"playback reports the first section"
)
_check(
controller.get_playback_segment_id() == forward.segment_id,
"playback reports the first segment"
)
_check(
controller.rink_canvas.get_playback_section_id() == section_one.section_id,
"canvas highlights the playing section"
)
_check(
controller.rink_canvas.get_section_banner_text() == section_one.title,
"section banner names the section at playback"
)
_check(
controller._section_buttons[section_one.section_id].text.begins_with("▶ "),
"section list marks the playing section"
)
_check(
controller._section_buttons[section_two.section_id].button_pressed,
"section list keeps the editing selection"
)
controller.seek_playback(3.0)
_check_vec(
controller.get_playback_position(),
Vector2(-2.0, 0.0),
"dot follows the backward segment"
)
_check(
controller.get_playback_heading().x < -0.9,
"backward segment faces against the travel direction"
)
_check(
controller.get_playback_segment_id() == backward.segment_id,
"playback reports the backward segment"
)
controller.seek_playback(5.0)
_check_vec(
controller.get_playback_position(),
Vector2(10.0, 0.0),
"dot follows the second section"
)
_check(
controller.get_playback_section_id() == section_two.section_id,
"playback reports the second section"
)
_check(
controller.get_playback_segment_id() == last.segment_id,
"playback reports the last segment"
)
_check(
controller.rink_canvas.get_playback_section_id() == section_two.section_id,
"canvas highlights the second section"
)
_check(
controller.rink_canvas.get_section_banner_text() == section_two.title,
"section banner follows the new section"
)
_check(
controller._section_buttons[section_two.section_id].text.begins_with("▶ "),
"section list marks the second section"
)
controller.rink_canvas._process(2.1)
_check(
controller.rink_canvas.get_section_banner_text().is_empty(),
"section banner fades out within two seconds"
)
_check(
controller.rink_canvas.get_section_banner_alpha() == 0.0,
"faded section banner has no alpha"
)
controller.play_button.pressed.emit()
_check(controller.is_playing(), "play button starts playback")
controller.play_button.pressed.emit()
_check(not controller.is_playing(), "play button pauses playback")
controller.play()
_check(controller.is_playing(), "play starts playback")
_check(controller.play_button.text == "Pause", "play button switches to pause")
controller.advance_playback(0.5)
_check_approx(controller.get_playback_time(), 5.5, "playback advances by delta")
controller.advance_playback(1.0)
_check(not controller.is_playing(), "playback stops at the end")
_check_approx(controller.get_playback_time(), 6.0, "playback ends at the total duration")
_check(controller.play_button.text == "Start", "play button switches back after the end")
controller.play()
_check_approx(
controller.get_playback_time(),
0.0,
"playing after the end restarts at the start"
)
_check(controller.is_playing(), "restarted playback is running")
controller.pause()
_check(not controller.is_playing(), "pause stops playback")
controller.reset_playback_button.pressed.emit()
_check_approx(controller.get_playback_time(), 0.0, "reset returns to the start")
_check(
controller.rink_canvas.get_playback_section_id().is_empty(),
"reset clears the playback highlight"
)
controller.playback_timeline.value = 2.5
_check_approx(
controller.get_playback_time(),
2.5,
"timeline scrubbing seeks the playback"
)
controller.speed_option.item_selected.emit(4)
_check_approx(controller.get_playback_speed(), 2.0, "speed option selects 2x")
controller.reset_playback()
controller.play()
controller.advance_playback(1.0)
_check_approx(
controller.get_playback_time(),
2.0,
"2x speed doubles the elapsed routine time"
)
controller.pause()
controller.speed_option.item_selected.emit(2)
_check_approx(controller.get_playback_speed(), 1.0, "speed option returns to 1x")
# Element markers take their stand time from the element, not the geometry,
# and a spin rotates the playback dot in place.
var jump_marker := controller.add_element_marker(
Vector2(20.0, 3.0),
PathSegment.ElementType.JUMP,
"3Lz",
0
)
_check_approx(
jump_marker.element_duration_seconds,
0.7,
"jump marker gets a default air time"
)
var spin_marker := controller.add_element_marker(
Vector2(22.0, 6.0),
PathSegment.ElementType.SPIN,
"CCoSp4",
3
)
_check_approx(
spin_marker.element_duration_seconds,
8.0,
"spin marker gets a default stand time"
)
var zero_marker := controller.add_element_marker(
Vector2(24.0, 3.0),
PathSegment.ElementType.SEQUENCE,
"StSq",
0
)
_check_approx(
zero_marker.element_duration_seconds,
0.0,
"sequence marker can have no stand time"
)
controller._update_status()
_check_approx(
controller.get_playback_duration(),
14.7,
"timeline duration includes the element stand times"
)
var jump_start := 6.0
controller.seek_playback(jump_start)
_check(
controller.get_playback_segment_id() == jump_marker.segment_id,
"timeline stops at the jump marker"
)
var jump_heading := controller.get_playback_heading()
controller.seek_playback(jump_start + 0.35)
_check(
jump_heading.dot(controller.get_playback_heading()) > 0.99,
"jump marker keeps the arrival heading"
)
var spin_start := jump_start + 0.7
controller.seek_playback(spin_start)
_check(
controller.get_playback_segment_id() == spin_marker.segment_id,
"timeline stops at the spin marker"
)
var spin_arrival := controller.get_playback_heading()
controller.seek_playback(spin_start + 1.0 / 3.0)
_check(
spin_arrival.dot(controller.get_playback_heading()) < -0.9,
"spin marker rotates the playback dot in place"
)
# Timeline labels: element labels are drawn read-only and a click on the
# lane creates an editable custom label at that time.
forward.label = "Auftakt"
last.label = "Finale"
controller._update_status()
_check(
controller.timeline_label_lane.get_element_label_count() == 5,
"labelled segments and element captions appear on the timeline"
)
var has_element_label := false
var has_jump_caption := false
var has_spin_caption := false
var has_zero_caption := false
for item: Dictionary in controller.timeline_label_lane.get_display_items():
if bool(item["custom"]):
continue
var item_text := str(item["text"])
if item_text == "Auftakt":
has_element_label = true
elif item_text == "3Lz":
has_jump_caption = true
elif item_text.begins_with("CCoSp"):
has_spin_caption = true
elif item_text == "StSq":
has_zero_caption = true
_check(has_element_label, "element label is part of the timeline drawing")
_check(has_jump_caption, "jump caption appears without a free-text label")
_check(has_spin_caption, "spin caption appears without a free-text label")
_check(has_zero_caption, "zero-duration element stays on the timeline")
# Hovering an element label exposes its track time as a tooltip.
controller.timeline_label_lane.size = Vector2(600.0, 44.0)
controller.timeline_label_lane._rebuild_items()
var hover_item: Dictionary = {}
for item: Dictionary in controller.timeline_label_lane.get_display_items():
if not bool(item["custom"]):
hover_item = item
break
_check(not hover_item.is_empty(), "element label can be hovered")
if not hover_item.is_empty():
var hover_x := float(hover_item["x"]) + 4.0
var hover_y := (
controller.timeline_label_lane.size.y
- 5.0
- float(int(hover_item["row"])) * 16.0
- 5.0
)
var hover_position := Vector2(hover_x, hover_y)
_check_approx(
controller.timeline_label_lane.get_label_time_at(hover_position),
float(hover_item["time_seconds"]),
"hovering an element label yields its track time"
)
var tooltip := controller.timeline_label_lane.get_tooltip_at(hover_position)
_check(
not tooltip.contains("Zeit im Track")
and tooltip.contains(
TimelineLabelLane.format_time(float(hover_item["time_seconds"]))
),
"element label tooltip contains only label and track time"
)
_check(
controller.add_timeline_label(5.0, "Musikstart"),
"custom timeline label is added"
)
var custom_labels := controller.get_timeline_labels()
_check(custom_labels.size() == 1, "routine stores the custom timeline label")
if custom_labels.size() == 1:
_check(custom_labels[0]["text"] == "Musikstart", "custom label text survives")
_check_approx(
float(custom_labels[0]["time_seconds"]),
5.0,
"custom label keeps its time"
)
_check(
controller.timeline_label_lane.get_custom_label_count() == 1,
"custom label is shown on the lane"
)
controller.timeline_label_lane.size = Vector2(600.0, 44.0)
controller.timeline_label_lane._rebuild_items()
var lane_click := InputEventMouseButton.new()
lane_click.button_index = MOUSE_BUTTON_LEFT
lane_click.pressed = true
lane_click.position = Vector2(100.0, 20.0)
controller.timeline_label_lane._gui_input(lane_click)
_check(
controller.timeline_label_dialog.visible,
"clicking the empty lane opens the label dialog"
)
controller.timeline_label_dialog.hide()
var label_click := InputEventMouseButton.new()
label_click.button_index = MOUSE_BUTTON_LEFT
label_click.pressed = true
label_click.position = Vector2(
controller.timeline_label_lane._time_to_x(5.0) + 2.0,
20.0
)
controller.timeline_label_lane._gui_input(label_click)
_check(
controller.timeline_label_dialog.visible
and controller.timeline_label_edit.text == "Musikstart",
"clicking a custom label opens it for editing"
)
controller.timeline_label_dialog.hide()
_check(
controller.update_timeline_label(0, "Sprung"),
"custom timeline label can be edited"
)
_check(
controller.get_timeline_labels()[0]["text"] == "Sprung",
"edited label text is stored"
)
_check(controller.undo(), "timeline label edit can be undone")
_check(
controller.get_timeline_labels()[0]["text"] == "Musikstart",
"undo restores the previous label text"
)
_check(controller.redo(), "timeline label edit can be redone")
_check(
controller.get_timeline_labels()[0]["text"] == "Sprung",
"redo restores the edited label text"
)
_check(
controller.remove_timeline_label(0),
"custom timeline label can be removed"
)
_check(
controller.get_timeline_labels().is_empty(),
"removed label is gone from the routine"
)
_check(
controller.timeline_label_lane.get_custom_label_count() == 0,
"removed label disappears from the lane"
)
forward.label = ""
last.label = ""
controller._update_status()
# Music: loading copies the track into the routine folder, the player
# follows the routine clock and the reference is cleared again on removal.
var music_source := "user://test_music.wav"
for old_path: String in [music_source, "user://routines/test_music.wav"]:
if FileAccess.file_exists(old_path):
DirAccess.remove_absolute(ProjectSettings.globalize_path(old_path))
_write_test_wav(music_source)
_check(
controller.load_music_from_path(music_source),
"music file is loaded into the routine"
)
_check(
controller.get_music_file_name() == "test_music.wav",
"routine references the copied music file"
)
_check(
FileAccess.file_exists("user://routines/test_music.wav"),
"music is stored next to the routine JSON"
)
_check(controller.has_music_stream(), "player has an audio stream")
_check(
controller.music_label.text.contains("test_music.wav"),
"playback bar shows the music file"
)
controller.seek_playback(0.5)
controller.play()
_check(controller.music_player.playing, "music starts with routine playback")
_check_approx(
controller.music_player.pitch_scale,
1.0,
"music plays at normal speed at 1x"
)
controller.seek_playback(3.0)
_check_approx(
controller.get_playback_time(),
3.0,
"scrubbing moves the routine clock"
)
controller.speed_option.item_selected.emit(4)
_check_approx(
controller.music_player.pitch_scale,
2.0,
"music follows the selected playback speed"
)
controller.speed_option.item_selected.emit(2)
controller.reset_playback()
_check(not controller.music_player.playing, "reset stops the music")
_check_approx(
controller.music_player.pitch_scale,
1.0,
"reset restores normal music speed"
)
controller._clear_music()
_check(controller.get_music_file_name().is_empty(), "music reference is cleared")
_check(not controller.has_music_stream(), "cleared music has no stream")
_check(
FileAccess.file_exists("user://routines/test_music.wav"),
"clearing keeps the file for other routines"
)
DirAccess.remove_absolute(
ProjectSettings.globalize_path("user://routines/test_music.wav")
)
DirAccess.remove_absolute(ProjectSettings.globalize_path(music_source))
scene.queue_free()
await process_frame
# Give the audio thread one real-time slice so its playback objects are
# released before ObjectDB checks for leaks at exit.
OS.delay_msec(300)
await process_frame
await process_frame
_finish()
func _write_test_wav(path: String) -> void:
const SAMPLE_RATE := 8000
const DATA_SIZE := SAMPLE_RATE * 2
var file := FileAccess.open(path, FileAccess.WRITE)
if file == null:
return
file.store_buffer("RIFF".to_ascii_buffer())
file.store_32(36 + DATA_SIZE)
file.store_buffer("WAVE".to_ascii_buffer())
file.store_buffer("fmt ".to_ascii_buffer())
file.store_32(16)
file.store_16(1)
file.store_16(1)
file.store_32(SAMPLE_RATE)
file.store_32(SAMPLE_RATE * 2)
file.store_16(2)
file.store_16(16)
file.store_buffer("data".to_ascii_buffer())
file.store_32(DATA_SIZE)
var silence := PackedByteArray()
silence.resize(DATA_SIZE)
file.store_buffer(silence)
file.close()
func _check(condition: bool, message: String) -> void:
_assertions += 1
if not condition:
_failures.append(message)
func _check_approx(actual: float, expected: float, message: String) -> void:
_check(
absf(actual - expected) <= 0.001,
"%s (expected %.3f, got %.3f)" % [message, expected, actual]
)
func _check_vec(actual: Vector2, expected: Vector2, message: String) -> void:
_check(
actual.distance_to(expected) <= 0.01,
"%s (expected %s, got %s)" % [message, expected, actual]
)
func _finish() -> void:
if _failures.is_empty():
print("PASS: %d assertions" % _assertions)
quit(0)
return
for failure: String in _failures:
printerr("FAIL: %s" % failure)
printerr("%d of %d assertions failed" % [_failures.size(), _assertions])
quit(1)