CORE/tests/unit/core.gd

140 lines
4.4 KiB
GDScript3
Raw Normal View History

extends 'res://tests/unitbase.gd'
# Initialization test
func test_initialization() -> void:
# Init CORE
await load_framework()
# Check
if !is_framework_loaded():
test_status = 2
test_message = "is_framework_loaded() returned 'false'"
2024-03-28 15:00:11 +01:00
return
test_status = 0
test_message = ""
# Custom module support
func test_custom_module_support() -> void:
# Init CORE
var config: CoreConfiguration = CoreConfiguration.new()
config.custom_modules = true
var core_test: Core = await load_framework(config)
# Load module
var module: CoreBaseModule = CoreBaseModule.new()
module.set_script(load("res://tests/custom_module.gd"))
# Register module
core_test.register_custom_module("test_module", module)
await wait_process_time()
# Check if registered
if callback != "_initialize" and callback != "_pull_config":
test_status = 2
test_message = "Module did not register"
2024-03-28 15:00:11 +01:00
return
elif core_test.get_node_or_null("Custom Modules/test_module") == null:
test_status = 2
test_message = "Could not find module node"
2024-03-28 15:00:11 +01:00
return
# Get module
var module_get: CoreBaseModule = core_test.get_custom_module("test_module")
if module_get == null:
test_status = 2
test_message = "Got null from get_custom_module method"
2024-03-28 15:00:11 +01:00
return
if module_get != module:
test_status = 2
test_message = "Got invalid node from get_custom_module method"
2024-03-28 15:00:11 +01:00
return
# Get string
if module.hello_test() != "Hello Test!":
test_status = 2
test_message = "Module did not return test string"
2024-03-28 15:00:11 +01:00
return
# Unregister module
core_test.unregister_custom_module("test_module")
await wait_process_time()
# Check if unregistered
if core_test.get_node_or_null("Custom Modules/test_module") == null:
test_status = 0
test_message = "Successfully registered, got, used and unregistered a custom module"
2024-03-28 15:00:11 +01:00
return
func test_reload_config() -> void:
# Variables
var config: CoreConfiguration = CoreConfiguration.new()
# Init CORE
var core_test: Core = await load_framework()
# Update some keys and reload
config.logger_colored = false
config.logger_level = CoreTypes.LoggerLevel.NONE
config.logui_enabled = false
core_test.reload_configuration(config)
await wait_process_time()
# Check config
if core_test.config != config:
test_status = 2
test_message = "Got invalid node from config variable"
2024-03-28 15:00:11 +01:00
return
# Check config in modules
if core_test.logger.config_colored != false or core_test.logger.config_level != CoreTypes.LoggerLevel.NONE or core_test.logui.background.visible != false:
test_status = 2
test_message = "Configuration did not apply all values correctly"
2024-03-28 15:00:11 +01:00
return
test_status = 0
test_message = ""
func test_formatted_string() -> void:
# Init CORE
var core_test: Core = await load_framework()
# Variables
var test_type: String
var test_type_technical: String
var test_semantic: Array[int] = core_test.get_version_semantic()
var test_devmode: String
var test_headless: String
var test_custommodules: String
# test_type & test_type_technical
match(core_test.version_type):
CoreTypes.VersionType.RELEASE:
test_type = "Release"
test_type_technical = "r"
CoreTypes.VersionType.RELEASECANDIDATE:
test_type = "Release Candidate"
test_type_technical = "rc"
CoreTypes.VersionType.BETA:
test_type = "Beta"
test_type_technical = "b"
CoreTypes.VersionType.ALPHA:
test_type = "Alpha"
test_type_technical = "a"
# test_devmode
if core_test.is_devmode(): test_devmode = "Enabled"
else: test_devmode = "Disabled"
# test_headless
if core_test.config.headless: test_headless = "Enabled"
else: test_headless = "Disabled"
# test_custommodules
if core_test.config.custom_modules: test_custommodules = "Enabled"
else: test_custommodules = "Disabled"
var test_raw: String = "version=%version% typerelease=%version_type% semantic=%version_semantic% type=%type% type_technical=%type_technical% devmode=%devmode% headless=%headless% custommodules=%custommodules% HELLO TEST! #TransRightsAreHumanRights"
var test_formatted: String = "version=" + str(core_test.version_version) + " typerelease=" + str(core_test.version_typerelease) + " semantic=" + str(test_semantic[0]) + "." + str(test_semantic[1]) + "." + str(test_semantic[2]) + " type=" + test_type + " type_technical=" + test_type_technical + " devmode=" + test_devmode + " headless=" + test_headless + " custommodules=" + test_custommodules + " HELLO TEST! #TransRightsAreHumanRights"
# Compare
if await core_test.get_formatted_string(test_raw) != test_formatted: test_status = 2
else: test_status = 0