- Export: Runtime-Bridge-Autoload und Skater-GLB samt Texturen einschließen, Editor-Addons ausschließen - tools/check_export.sh als headless Smoke-Test; ./tools/test.sh --export - RoutineFile: JSON-Format, atomare Saves, Whitelist für Legacy-.tres - Überschreibschutz für Speichern unter/Export, Session- und Autosave-Restore - Globaler Delete-Shortcut blockiert bei offenen Dialogen - Sync akzeptiert .json und Legacy-.tres, Konfliktnamen behalten die Endung - Tests für Dateiformat, Überschreiben, Session und Legacy-Schutz - Quality-Meilenstein mit 'Als Nächstes' und 'Danach' in der Roadmap
275 lines
7.7 KiB
GDScript
275 lines
7.7 KiB
GDScript
extends SceneTree
|
|
|
|
## Headless tests for segment timing, presets and calibration.
|
|
##
|
|
## Run with:
|
|
## godot --headless --path rinkplanner --script res://tests/run_timing_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, "timing scene has a controller")
|
|
if controller == null:
|
|
_finish()
|
|
return
|
|
|
|
_check(
|
|
controller.timing_selection_label.text.contains("Kein Segment"),
|
|
"timing starts without a selected segment"
|
|
)
|
|
_check(
|
|
controller.duration_plus_button.disabled,
|
|
"duration controls start disabled"
|
|
)
|
|
_check(
|
|
controller.profile_option.selected == WhiteboardController.DEFAULT_PROFILE_INDEX,
|
|
"adult gold is the default profile"
|
|
)
|
|
|
|
var segment := controller.add_segment(
|
|
Vector2(-5.0, 0.0),
|
|
Vector2(5.0, 0.0),
|
|
PathSegment.Direction.FORWARD,
|
|
PathSegment.Edge.OUTSIDE
|
|
)
|
|
_check_approx(segment.get_length_m(), 10.0, "test segment is 10 m long")
|
|
_check_approx(
|
|
segment.duration_seconds,
|
|
10.0 / WhiteboardController.DEFAULT_SPEED_MPS,
|
|
"new segments use the default speed"
|
|
)
|
|
_check_approx(
|
|
segment.speed_mps,
|
|
WhiteboardController.DEFAULT_SPEED_MPS,
|
|
"new segment stores the authored speed"
|
|
)
|
|
|
|
controller.select_segment(segment.segment_id)
|
|
_check(
|
|
not controller.duration_plus_button.disabled,
|
|
"timing controls enable with a selection"
|
|
)
|
|
_check(
|
|
controller.timing_selection_label.text.contains("10,0 m"),
|
|
"timing bar shows the segment length"
|
|
)
|
|
_check(
|
|
controller.duration_value_label.text.contains("2,3"),
|
|
"timing bar shows the duration"
|
|
)
|
|
_check(
|
|
controller.speed_value_label.text.contains("4,3"),
|
|
"timing bar shows the speed"
|
|
)
|
|
|
|
var duration_before := segment.duration_seconds
|
|
controller.duration_plus_button.pressed.emit()
|
|
_check_approx(
|
|
segment.duration_seconds,
|
|
duration_before + 0.1,
|
|
"duration plus increases the duration"
|
|
)
|
|
_check(
|
|
segment.timing_mode == PathSegment.TimingMode.DURATION,
|
|
"duration editing switches to duration mode"
|
|
)
|
|
_check(
|
|
segment.get_speed_mps() < WhiteboardController.DEFAULT_SPEED_MPS,
|
|
"a longer duration lowers the implied speed"
|
|
)
|
|
|
|
_check(controller.undo(), "duration change can be undone")
|
|
var restored := controller.get_active_section().get_segment_by_id(
|
|
segment.segment_id
|
|
)
|
|
_check(restored != null, "segment survives undo")
|
|
if restored != null:
|
|
_check_approx(
|
|
restored.duration_seconds,
|
|
duration_before,
|
|
"undo restores the duration"
|
|
)
|
|
_check(
|
|
restored.timing_mode == PathSegment.TimingMode.SPEED,
|
|
"undo restores the timing mode"
|
|
)
|
|
controller.select_segment(restored.segment_id)
|
|
controller.speed_plus_button.pressed.emit()
|
|
_check_approx(
|
|
restored.get_speed_mps(),
|
|
4.4,
|
|
"speed plus increases the speed"
|
|
)
|
|
_check(
|
|
restored.timing_mode == PathSegment.TimingMode.SPEED,
|
|
"speed editing switches to speed mode"
|
|
)
|
|
|
|
var speed_before_profile := restored.get_speed_mps()
|
|
controller.profile_option.item_selected.emit(3)
|
|
_check_approx(
|
|
restored.get_speed_mps(),
|
|
5.0,
|
|
"masters profile applies 5 m/s"
|
|
)
|
|
_check_approx(
|
|
restored.duration_seconds,
|
|
2.0,
|
|
"profile updates the duration"
|
|
)
|
|
_check(controller.undo(), "profile change can be undone")
|
|
restored = controller.get_active_section().get_segment_by_id(segment.segment_id)
|
|
if restored != null:
|
|
_check_approx(
|
|
restored.get_speed_mps(),
|
|
speed_before_profile,
|
|
"undo restores the previous speed"
|
|
)
|
|
controller.select_segment(restored.segment_id)
|
|
|
|
controller.reset_timing_button.pressed.emit()
|
|
_check_approx(
|
|
restored.get_speed_mps(),
|
|
WhiteboardController.DEFAULT_SPEED_MPS,
|
|
"reset applies the default profile speed"
|
|
)
|
|
|
|
controller.calibrate_button.pressed.emit()
|
|
controller.calibration_distance_edit.text = "20"
|
|
controller.calibration_time_edit.text = "4"
|
|
controller.calibration_dialog.confirmed.emit()
|
|
_check_approx(
|
|
restored.get_speed_mps(),
|
|
5.0,
|
|
"calibration derives speed from distance and time"
|
|
)
|
|
_check_approx(
|
|
restored.duration_seconds,
|
|
2.0,
|
|
"calibration updates the duration"
|
|
)
|
|
|
|
controller.set_tool(WhiteboardController.Tool.LINE)
|
|
controller.profile_option.item_selected.emit(0)
|
|
_check_approx(
|
|
controller.get_preset_speed(),
|
|
3.0,
|
|
"profile without selection sets the next-segment speed"
|
|
)
|
|
var bronze := controller.add_segment(
|
|
Vector2(0.0, 8.0),
|
|
Vector2(6.0, 8.0),
|
|
PathSegment.Direction.FORWARD,
|
|
PathSegment.Edge.INSIDE
|
|
)
|
|
_check_approx(bronze.get_speed_mps(), 3.0, "new segment uses the bronze preset")
|
|
_check_approx(bronze.duration_seconds, 2.0, "bronze duration follows the length")
|
|
|
|
var save_path := "user://test_timing.json"
|
|
_check(controller.save_to_path(save_path), "timing routine can be saved")
|
|
_check(controller.load_from_path(save_path), "timing routine can be loaded")
|
|
var loaded_first := controller.get_routine().get_section_by_id(
|
|
"section-001"
|
|
)
|
|
_check(loaded_first != null, "loaded timing routine has its section")
|
|
if loaded_first != null:
|
|
var loaded_arc := loaded_first.get_segment_by_id(segment.segment_id)
|
|
_check(loaded_arc != null, "loaded timing routine has the first segment")
|
|
if loaded_arc != null:
|
|
_check_approx(
|
|
loaded_arc.get_speed_mps(),
|
|
5.0,
|
|
"load preserves the authored speed"
|
|
)
|
|
_check(
|
|
loaded_arc.timing_mode == PathSegment.TimingMode.SPEED,
|
|
"load preserves the timing mode"
|
|
)
|
|
DirAccess.remove_absolute(save_path)
|
|
|
|
# Migration: old routines had no speed field; their duration must survive.
|
|
var old_routine := Routine.new()
|
|
old_routine.schema_version = 1
|
|
old_routine.routine_id = "old-routine"
|
|
old_routine.title = "Alt"
|
|
old_routine.rink = RinkDimensions.new()
|
|
var old_section := RoutineSection.new()
|
|
old_section.section_id = "section-001"
|
|
old_section.title = "Abschnitt 1"
|
|
old_section.sequence_order = 0
|
|
var old_segment := PathSegment.new()
|
|
old_segment.segment_id = "seg-old"
|
|
old_segment.curve = Curve2D.new()
|
|
old_segment.curve.add_point(Vector2(-5.0, 0.0))
|
|
old_segment.curve.add_point(Vector2(5.0, 0.0))
|
|
old_segment.duration_seconds = 5.0
|
|
old_segment.speed_mps = 4.3
|
|
old_segment.timing_mode = PathSegment.TimingMode.SPEED
|
|
old_section.segments = [old_segment]
|
|
old_routine.sections = [old_section]
|
|
|
|
var old_path := "user://test_timing_v1.tres"
|
|
ResourceSaver.save(old_routine, old_path)
|
|
_check(controller.load_from_path(old_path), "schema-1 routine can be loaded")
|
|
var migrated := controller.get_active_section().get_segment_by_id("seg-old")
|
|
_check(migrated != null, "migrated segment exists")
|
|
if migrated != null:
|
|
_check(
|
|
migrated.timing_mode == PathSegment.TimingMode.DURATION,
|
|
"migration preserves the old duration"
|
|
)
|
|
_check_approx(
|
|
migrated.speed_mps,
|
|
2.0,
|
|
"migration derives the old speed"
|
|
)
|
|
_check(
|
|
controller.get_routine().schema_version == Routine.CURRENT_SCHEMA_VERSION,
|
|
"migration updates the schema version"
|
|
)
|
|
DirAccess.remove_absolute(old_path)
|
|
|
|
scene.queue_free()
|
|
await process_frame
|
|
_finish()
|
|
|
|
|
|
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 _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)
|