CORE/tests/unit/sms.gd
JeremyStarTM 0dac9b66c5
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 52c6d029d9, 25c4667a05 and 32b82c8f5b.
2024-03-31 17:08:55 +02:00

215 lines
8.5 KiB
GDScript

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()