2024-03-31 18:03:57 +02:00
|
|
|
# CORE FRAMEWORK TEST FILE
|
|
|
|
# Copyright (c) 2024 The StarOpenSource Project & Contributors
|
|
|
|
# Licensed under the GNU Affero General Public License v3
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2024-03-29 02:41:36 +01:00
|
|
|
extends BessereTestsTest
|
2024-03-28 14:48:50 +01:00
|
|
|
|
2024-03-29 02:41:36 +01:00
|
|
|
# CORE
|
2024-03-28 14:48:50 +01:00
|
|
|
var core: Core
|
|
|
|
|
2024-03-31 11:23:36 +02:00
|
|
|
# Used during testing
|
|
|
|
var callback: String = ""
|
|
|
|
|
2024-03-29 02:41:36 +01:00
|
|
|
# Unload framework after each test
|
|
|
|
func after_each() -> void:
|
|
|
|
callback = ""
|
2024-05-09 15:21:12 +02:00
|
|
|
await wait_process_time() # Prevent output overflows
|
2024-03-29 02:41:36 +01:00
|
|
|
await unload_framework()
|
|
|
|
|
2024-03-28 14:48:50 +01:00
|
|
|
# Framework management
|
2024-03-31 16:20:34 +02:00
|
|
|
func load_framework(config: CoreConfiguration = CoreConfiguration.new()) -> void:
|
2024-04-06 13:13:27 +02:00
|
|
|
if is_framework_loaded(): await unload_framework()
|
|
|
|
ldiag("Loading framework")
|
2024-04-06 13:58:37 +02:00
|
|
|
config.logger_level = CoreTypes.LoggerLevel.DIAG
|
2024-05-10 21:21:20 +02:00
|
|
|
core = await Core.new(config)
|
2024-03-28 14:48:50 +01:00
|
|
|
get_tree().root.add_child(core)
|
2024-04-23 21:34:38 +02:00
|
|
|
core.welcomed = true # Hides the welcome message shown by CORE so it doesn't bloat the log
|
2024-03-28 14:48:50 +01:00
|
|
|
await get_tree().process_frame
|
|
|
|
await core.complete_init()
|
|
|
|
|
|
|
|
func unload_framework() -> void:
|
2024-03-29 02:41:36 +01:00
|
|
|
if is_framework_loaded():
|
2024-04-06 13:13:27 +02:00
|
|
|
ldiag("Unloading framework")
|
2024-03-29 02:41:36 +01:00
|
|
|
await core.cleanup()
|
|
|
|
get_tree().root.remove_child.call_deferred(core)
|
|
|
|
core = null
|
|
|
|
await get_tree().process_frame
|
2024-04-06 13:58:37 +02:00
|
|
|
else:
|
|
|
|
if test_status == 3: lerror("Can't unload framework: Framework is not loaded")
|
|
|
|
else: lcrash("Can't unload framework: Framework is not loaded")
|
2024-03-28 14:48:50 +01:00
|
|
|
|
|
|
|
func is_framework_loaded() -> bool: return get_node_or_null("/root/CORE") != null
|
|
|
|
|
|
|
|
# Helper functions
|
2024-04-06 13:13:27 +02:00
|
|
|
func wait_process_time() -> void:
|
|
|
|
ldiag("Waiting process time")
|
|
|
|
await get_tree().create_timer(0.1).timeout
|