From 0dac9b66c59170ce3b0ffa0ec2e1df1f7d5fcc17 Mon Sep 17 00:00:00 2001 From: JeremyStarTM Date: Sun, 31 Mar 2024 17:08:55 +0200 Subject: [PATCH] Add tests for sms module + update Bessere Tests Good that I decided to introduce unit tests to CORE because I found multiple issues in the Scene Manager which I was now able to fix. See 52c6d029d9aa5912a71d96fa5fe73f177fb4f3ad, 25c4667a0508f46c973905679abebc2e253cc6c8 and 32b82c8f5bd299fa0653af25fc9092ef1bbe9dca. --- dist/submodules/besseretests | 2 +- tests/test_resources/scene.gd | 5 + tests/test_resources/scene.tscn | 12 ++ tests/unit/sms.gd | 215 ++++++++++++++++++++++++++++++++ 4 files changed, 233 insertions(+), 1 deletion(-) create mode 100644 tests/test_resources/scene.gd create mode 100644 tests/test_resources/scene.tscn create mode 100644 tests/unit/sms.gd diff --git a/dist/submodules/besseretests b/dist/submodules/besseretests index 82cf251..a58bfb2 160000 --- a/dist/submodules/besseretests +++ b/dist/submodules/besseretests @@ -1 +1 @@ -Subproject commit 82cf251ecee89f3f2a575b1b322c1df48ea42aaf +Subproject commit a58bfb23dc389ec60e3f45fbb0433e107755c4ea diff --git a/tests/test_resources/scene.gd b/tests/test_resources/scene.gd new file mode 100644 index 0000000..867922e --- /dev/null +++ b/tests/test_resources/scene.gd @@ -0,0 +1,5 @@ +extends Control + +@onready var suite: BessereTestsTest = get_node_or_null("/root/suite_sms") + +func _ready() -> void: suite.callback = "_ready" diff --git a/tests/test_resources/scene.tscn b/tests/test_resources/scene.tscn new file mode 100644 index 0000000..63e166f --- /dev/null +++ b/tests/test_resources/scene.tscn @@ -0,0 +1,12 @@ +[gd_scene load_steps=2 format=3 uid="uid://cyixk2ixllyp5"] + +[ext_resource type="Script" path="res://tests/test_resources/scene.gd" id="1_k6cu8"] + +[node name="Scene" type="Control"] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("1_k6cu8") diff --git a/tests/unit/sms.gd b/tests/unit/sms.gd new file mode 100644 index 0000000..069184e --- /dev/null +++ b/tests/unit/sms.gd @@ -0,0 +1,215 @@ +extends 'res://tests/unitbase.gd' + +var test_scene: Node = load("res://tests/test_resources/scene.tscn").instantiate() +var test_scene_duplicate: Node + +func after_each() -> void: + if test_scene_duplicate != null: test_scene_duplicate.queue_free() + await super() + +func after_all() -> void: test_scene.queue_free() + +func test_agr_debug() -> void: + await load_framework() + + test_scene_duplicate = test_scene.duplicate() + core.sms.add_scene("test_scene", test_scene_duplicate, CoreTypes.SceneType.DEBUG) + await wait_process_time() + if callback != "_ready": + rerror("Scene was not added") + return + if core.sms.get_scene("test_scene") == null: + rerror("Got null from 'get_scene' method") + return + elif core.sms.get_scene("test_scene") != test_scene_duplicate: + rerror("Got invalid node from 'get_scene' method") + return + core.sms.remove_scene("test_scene") + + rok() + +func test_agr_cutscene() -> void: + await load_framework() + + test_scene_duplicate = test_scene.duplicate() + core.sms.add_scene("test_scene", test_scene_duplicate, CoreTypes.SceneType.CUTSCENE) + await wait_process_time() + if callback != "_ready": + rerror("Scene was not added") + return + if core.sms.get_scene("test_scene") == null: + rerror("Got null from 'get_scene' method") + return + elif core.sms.get_scene("test_scene") != test_scene_duplicate: + rerror("Got invalid node from 'get_scene' method") + return + core.sms.remove_scene("test_scene") + + rok() + +func test_agr_menu() -> void: + await load_framework() + + test_scene_duplicate = test_scene.duplicate() + core.sms.add_scene("test_scene", test_scene_duplicate, CoreTypes.SceneType.MENU) + await wait_process_time() + if callback != "_ready": + rerror("Scene was not added") + return + if core.sms.get_scene("test_scene") == null: + rerror("Got null from 'get_scene' method") + return + elif core.sms.get_scene("test_scene") != test_scene_duplicate: + rerror("Got invalid node from 'get_scene' method") + return + core.sms.remove_scene("test_scene") + + rok() + +func test_agr_main() -> void: + await load_framework() + + test_scene_duplicate = test_scene.duplicate() + core.sms.add_scene("test_scene", test_scene_duplicate, CoreTypes.SceneType.MAIN) + await wait_process_time() + if callback != "_ready": + rerror("Scene was not added") + return + if core.sms.get_scene("test_scene") == null: + rerror("Got null from 'get_scene' method") + return + elif core.sms.get_scene("test_scene") != test_scene_duplicate: + rerror("Got invalid node from 'get_scene' method") + return + core.sms.remove_scene("test_scene") + + rok() + +func test_agr_background() -> void: + await load_framework() + + test_scene_duplicate = test_scene.duplicate() + core.sms.add_scene("test_scene", test_scene_duplicate, CoreTypes.SceneType.BACKGROUND) + await wait_process_time() + if callback != "_ready": + rerror("Scene was not added") + return + if core.sms.get_scene("test_scene") == null: + rerror("Got null from 'get_scene' method") + return + elif core.sms.get_scene("test_scene") != test_scene_duplicate: + rerror("Got invalid node from 'get_scene' method") + return + core.sms.remove_scene("test_scene") + + rok() + +func test_sc_debug() -> void: + await load_framework() + + if core.sms.get_scene_collection(CoreTypes.SceneType.DEBUG) == core.sms.scenes_debug: rok() + else: rerror("Got invalid node from 'get_scene_collection' method") + +func test_sc_cutscene() -> void: + await load_framework() + + if core.sms.get_scene_collection(CoreTypes.SceneType.CUTSCENE) == core.sms.scenes_cutscene: rok() + else: rerror("Got invalid node from 'get_scene_collection' method") + +func test_sc_menu() -> void: + await load_framework() + + if core.sms.get_scene_collection(CoreTypes.SceneType.MENU) == core.sms.scenes_menu: rok() + else: rerror("Got invalid node from 'get_scene_collection' method") + +func test_sc_main() -> void: + await load_framework() + + if core.sms.get_scene_collection(CoreTypes.SceneType.MAIN) == core.sms.scenes_main: rok() + else: rerror("Got invalid node from 'get_scene_collection' method") + +func test_sc_background() -> void: + await load_framework() + + if core.sms.get_scene_collection(CoreTypes.SceneType.BACKGROUND) == core.sms.scenes_background: rok() + else: rerror("Got invalid node from 'get_scene_collection' method") + +func test_sclistcount_debug() -> void: + await load_framework() + + test_scene_duplicate = test_scene.duplicate() + core.sms.add_scene("test_scene", test_scene_duplicate, CoreTypes.SceneType.DEBUG) + await wait_process_time() + if callback != "_ready": + rerror("Scene was not added") + return + + var test_sclist: Array[Node] = core.sms.get_scene_collection_list(CoreTypes.SceneType.DEBUG) + if test_sclist.size() != 1: rerror("Method 'get_scene_collection_list' did not return '1' (returned '" + str(test_sclist.size()) + "')") + elif test_sclist[0] != test_scene_duplicate: rerror("Method 'get_scene_collection_list' returned an invalid node (in Array[Node])") + elif core.sms.get_scene_collection_count(CoreTypes.SceneType.DEBUG) != 1: rerror("Method 'get_scene_collection_count' did not return '1' (returned '" + str(core.sms.get_scene_collection_count(CoreTypes.SceneType.DEBUG)) + "'") + else: rok() + +func test_sclistcount_cutscene() -> void: + await load_framework() + + test_scene_duplicate = test_scene.duplicate() + core.sms.add_scene("test_scene", test_scene_duplicate, CoreTypes.SceneType.CUTSCENE) + await wait_process_time() + if callback != "_ready": + rerror("Scene was not added") + return + + var test_sclist: Array[Node] = core.sms.get_scene_collection_list(CoreTypes.SceneType.CUTSCENE) + if test_sclist.size() != 1: rerror("Method 'get_scene_collection_list' did not return '1' (returned '" + str(test_sclist.size()) + "')") + elif test_sclist[0] != test_scene_duplicate: rerror("Method 'get_scene_collection_list' returned an invalid node (in Array[Node])") + elif core.sms.get_scene_collection_count(CoreTypes.SceneType.CUTSCENE) != 1: rerror("Method 'get_scene_collection_count' did not return '1' (returned '" + str(core.sms.get_scene_collection_count(CoreTypes.SceneType.CUTSCENE)) + "'") + else: rok() + +func test_sclistcount_menu() -> void: + await load_framework() + + test_scene_duplicate = test_scene.duplicate() + core.sms.add_scene("test_scene", test_scene_duplicate, CoreTypes.SceneType.MENU) + await wait_process_time() + if callback != "_ready": + rerror("Scene was not added") + return + + var test_sclist: Array[Node] = core.sms.get_scene_collection_list(CoreTypes.SceneType.MENU) + if test_sclist.size() != 1: rerror("Method 'get_scene_collection_list' did not return '1' (returned '" + str(test_sclist.size()) + "')") + elif test_sclist[0] != test_scene_duplicate: rerror("Method 'get_scene_collection_list' returned an invalid node (in Array[Node])") + elif core.sms.get_scene_collection_count(CoreTypes.SceneType.MENU) != 1: rerror("Method 'get_scene_collection_count' did not return '1' (returned '" + str(core.sms.get_scene_collection_count(CoreTypes.SceneType.MENU)) + "'") + else: rok() + +func test_sclistcount_main() -> void: + await load_framework() + + test_scene_duplicate = test_scene.duplicate() + core.sms.add_scene("test_scene", test_scene_duplicate, CoreTypes.SceneType.MAIN) + await wait_process_time() + if callback != "_ready": + rerror("Scene was not added") + return + + var test_sclist: Array[Node] = core.sms.get_scene_collection_list(CoreTypes.SceneType.MAIN) + if test_sclist.size() != 1: rerror("Method 'get_scene_collection_list' did not return '1' (returned '" + str(test_sclist.size()) + "')") + elif test_sclist[0] != test_scene_duplicate: rerror("Method 'get_scene_collection_list' returned an invalid node (in Array[Node])") + elif core.sms.get_scene_collection_count(CoreTypes.SceneType.MAIN) != 1: rerror("Method 'get_scene_collection_count' did not return '1' (returned '" + str(core.sms.get_scene_collection_count(CoreTypes.SceneType.MAIN)) + "'") + else: rok() + +func test_sclistcount_background() -> void: + await load_framework() + + test_scene_duplicate = test_scene.duplicate() + core.sms.add_scene("test_scene", test_scene_duplicate, CoreTypes.SceneType.BACKGROUND) + await wait_process_time() + if callback != "_ready": + rerror("Scene was not added") + return + + var test_sclist: Array[Node] = core.sms.get_scene_collection_list(CoreTypes.SceneType.BACKGROUND) + if test_sclist.size() != 1: rerror("Method 'get_scene_collection_list' did not return '1' (returned '" + str(test_sclist.size()) + "')") + elif test_sclist[0] != test_scene_duplicate: rerror("Method 'get_scene_collection_list' returned an invalid node (in Array[Node])") + elif core.sms.get_scene_collection_count(CoreTypes.SceneType.BACKGROUND) != 1: rerror("Method 'get_scene_collection_count' did not return '1' (returned '" + str(core.sms.get_scene_collection_count(CoreTypes.SceneType.BACKGROUND)) + "'") + else: rok()