Add headless regression tests for Prop Editor functionality
- Implement tests for PropFile, including preset conversion, file dictionary conversion, round-trip serialization, version rejection, default values for missing keys, flattening, sanitization, and save/load functionality. - Create tests for PropEditor, covering window title formatting, mode button text, safe saving, and recent file list management. - Add tests for PropTheme, validating fallback behavior, invalid input handling, and default values for primitives and UI tokens. - Introduce tests for ThumbnailCache, ensuring proper key formatting, PNG handling, and behavior with missing files.
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
# Phase 9 Prop Editor - headless regression checks for the ThumbnailCache
|
||||
# extension (prop_file_key / prop_file_png) and PNG round-trip.
|
||||
# Run with:
|
||||
# & "C:\Godot4\Godot_v4.7.1-stable_win64_console.exe" --headless --path "C:\tmp\stickman" --script "res://tests/test_prop_editor_thumb.gd"
|
||||
|
||||
extends SceneTree
|
||||
|
||||
const THUMBNAIL_CACHE := preload("res://scripts/thumbnails/thumbnail_cache.gd")
|
||||
|
||||
var _checks: int = 0
|
||||
var _failures: int = 0
|
||||
|
||||
|
||||
func _initialize() -> void:
|
||||
call_deferred("_run")
|
||||
|
||||
|
||||
func _run() -> void:
|
||||
print("\n=== PHASE 9 PROP THUMB TEST ===")
|
||||
await _test_prop_file_keys()
|
||||
await _test_builtin_prop_png_unchanged()
|
||||
await _test_png_round_trip()
|
||||
await _test_missing_file()
|
||||
print("----------------------------------------")
|
||||
if _failures == 0:
|
||||
print("RESULT: ALL PASSED (%d assertions)" % _checks)
|
||||
quit(0)
|
||||
else:
|
||||
print("RESULT: %d FAILURE(S) out of %d assertions" % [_failures, _checks])
|
||||
quit(1)
|
||||
|
||||
|
||||
func check(label: String, condition: bool) -> void:
|
||||
_checks += 1
|
||||
if condition:
|
||||
print("PASS: %s" % label)
|
||||
else:
|
||||
_failures += 1
|
||||
print("FAIL: %s" % label)
|
||||
|
||||
|
||||
func _test_prop_file_keys() -> void:
|
||||
var cache: ThumbnailCache = THUMBNAIL_CACHE.new()
|
||||
var path := "user://prop_thumb_key_test.prop"
|
||||
var f := FileAccess.open(path, FileAccess.WRITE)
|
||||
f.store_string("{}")
|
||||
f.close()
|
||||
var key: String = cache.prop_file_key(path)
|
||||
var mtime: int = FileAccess.get_modified_time(path)
|
||||
check("prop_file_key format", key == "prop_thumb_key_test_%d" % mtime)
|
||||
check("prop_file_png uses PROP_DIR", cache.prop_file_png(path) == "user://thumbnails/props/%s.png" % key)
|
||||
check("prop_file_key missing file still formats", cache.prop_file_key("res://nope.prop") == "nope_0")
|
||||
DirAccess.remove_absolute(path)
|
||||
|
||||
|
||||
func _test_builtin_prop_png_unchanged() -> void:
|
||||
var cache: ThumbnailCache = THUMBNAIL_CACHE.new()
|
||||
check("prop_png keeps version key", cache.prop_png("crate") == "user://thumbnails/props/crate_v%d.png" % THUMBNAIL_CACHE.PROP_VERSION)
|
||||
check("stickman_png unchanged", cache.stickman_png("abc_123") == "user://thumbnails/stickmen/abc_123.png")
|
||||
|
||||
|
||||
func _test_png_round_trip() -> void:
|
||||
var cache: ThumbnailCache = THUMBNAIL_CACHE.new()
|
||||
var img := Image.create_empty(4, 4, false, Image.FORMAT_RGBA8)
|
||||
img.fill(Color(1.0, 0.0, 0.0, 1.0))
|
||||
var tex := ImageTexture.create_from_image(img)
|
||||
var png_path := "user://thumbnails/props/test_roundtrip_v9.png"
|
||||
var err: Error = cache.save_png(tex, png_path)
|
||||
check("save_png succeeds", err == OK)
|
||||
check("png exists on disk", FileAccess.file_exists(png_path))
|
||||
cache.clear_memory()
|
||||
var loaded: Texture2D = cache.load_png(png_path)
|
||||
check("load_png round trip", loaded != null and loaded.get_size() == Vector2(4, 4))
|
||||
check("save_png null texture rejected", cache.save_png(null, "user://thumbnails/props/null_v9.png") != OK)
|
||||
DirAccess.remove_absolute(png_path)
|
||||
|
||||
|
||||
func _test_missing_file() -> void:
|
||||
var cache: ThumbnailCache = THUMBNAIL_CACHE.new()
|
||||
check("load_png missing -> null", cache.load_png("user://thumbnails/props/definitely_missing.png") == null)
|
||||
Reference in New Issue
Block a user