2024-03-29 02:41:36 +01:00
extends ' res://tests/unitbase.gd '
2024-03-28 14:48:50 +01:00
# Initialization test
func test_initialization ( ) - > void :
# Init CORE
2024-03-29 02:41:36 +01:00
await load_framework ( )
2024-03-28 14:48:50 +01:00
# Check
2024-03-29 02:41:36 +01:00
if ! is_framework_loaded ( ) :
2024-03-29 02:53:16 +01:00
rerror ( " is_framework_loaded() returned ' false ' " )
2024-03-28 15:00:11 +01:00
return
2024-03-28 14:48:50 +01:00
2024-03-29 02:53:16 +01:00
rok ( )
2024-03-28 14:48:50 +01:00
# Custom module support
func test_custom_module_support ( ) - > void :
# Init CORE
var config : CoreConfiguration = CoreConfiguration . new ( )
config . custom_modules = true
2024-03-31 11:23:36 +02:00
core_test = await load_framework ( config )
2024-03-28 14:48:50 +01:00
# Load module
var module : CoreBaseModule = CoreBaseModule . new ( )
2024-03-31 11:22:57 +02:00
module . set_script ( load ( " res://tests/test_resources/custom_module.gd " ) )
2024-03-28 14:48:50 +01:00
# Register module
2024-03-31 11:22:57 +02:00
core_test . register_custom_module ( " test_module " , " tests/test_resources/custom_module.gd " , module )
2024-03-29 02:41:36 +01:00
await wait_process_time ( )
2024-03-28 14:48:50 +01:00
# Check if registered
if callback != " _initialize " and callback != " _pull_config " :
2024-03-29 02:53:16 +01:00
rerror ( " Module did not register " )
2024-03-28 15:00:11 +01:00
return
2024-03-29 02:41:36 +01:00
elif core_test . get_node_or_null ( " Custom Modules/test_module " ) == null :
2024-03-29 02:53:16 +01:00
rerror ( " Could not find module node " )
2024-03-28 15:00:11 +01:00
return
2024-03-28 14:48:50 +01:00
# Get module
2024-03-29 02:41:36 +01:00
var module_get : CoreBaseModule = core_test . get_custom_module ( " test_module " )
2024-03-28 14:48:50 +01:00
if module_get == null :
2024-03-29 02:53:16 +01:00
rerror ( " Got null from get_custom_module method " )
2024-03-28 15:00:11 +01:00
return
2024-03-28 14:48:50 +01:00
if module_get != module :
2024-03-29 02:53:16 +01:00
rerror ( " Got invalid node from get_custom_module method " )
2024-03-28 15:00:11 +01:00
return
2024-03-28 14:48:50 +01:00
# Get string
if module . hello_test ( ) != " Hello Test! " :
2024-03-29 02:53:16 +01:00
rerror ( " Module did not return test string " )
2024-03-28 15:00:11 +01:00
return
2024-03-28 14:48:50 +01:00
# Unregister module
2024-03-29 02:41:36 +01:00
core_test . unregister_custom_module ( " test_module " )
await wait_process_time ( )
2024-03-28 14:48:50 +01:00
# Check if unregistered
2024-03-29 02:41:36 +01:00
if core_test . get_node_or_null ( " Custom Modules/test_module " ) == null :
2024-03-29 02:53:16 +01:00
rok ( " Successfully registered, got, used and unregistered a custom module " )
2024-03-28 15:00:11 +01:00
return
2024-03-28 14:48:50 +01:00
func test_reload_config ( ) - > void :
# Variables
var config : CoreConfiguration = CoreConfiguration . new ( )
# Init CORE
2024-03-31 11:23:36 +02:00
core_test = await load_framework ( )
2024-03-28 14:48:50 +01:00
# Update some keys and reload
config . logger_colored = false
config . logger_level = CoreTypes . LoggerLevel . NONE
config . logui_enabled = false
2024-03-29 02:41:36 +01:00
core_test . reload_configuration ( config )
await wait_process_time ( )
2024-03-28 14:48:50 +01:00
# Check config
2024-03-29 02:41:36 +01:00
if core_test . config != config :
2024-03-29 02:53:16 +01:00
rerror ( " Got invalid node from config variable " )
2024-03-28 15:00:11 +01:00
return
2024-03-28 14:48:50 +01:00
# Check config in modules
2024-03-29 02:41:36 +01:00
if core_test . logger . config_colored != false or core_test . logger . config_level != CoreTypes . LoggerLevel . NONE or core_test . logui . background . visible != false :
2024-03-29 02:53:16 +01:00
rerror ( " Configuration did not apply all values correctly " )
2024-03-28 15:00:11 +01:00
return
2024-03-28 14:48:50 +01:00
2024-03-29 02:53:16 +01:00
rok ( )
2024-03-28 14:48:50 +01:00
func test_formatted_string ( ) - > void :
# Init CORE
2024-03-31 11:23:36 +02:00
core_test = await load_framework ( )
2024-03-28 14:48:50 +01:00
# Variables
var test_type : String
var test_type_technical : String
2024-03-29 02:41:36 +01:00
var test_semantic : Array [ int ] = core_test . get_version_semantic ( )
2024-03-28 14:48:50 +01:00
var test_devmode : String
var test_headless : String
var test_custommodules : String
# test_type & test_type_technical
2024-03-29 02:41:36 +01:00
match ( core_test . version_type ) :
2024-03-28 14:48:50 +01:00
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
2024-03-29 02:41:36 +01:00
if core_test . is_devmode ( ) : test_devmode = " Enabled "
2024-03-28 14:48:50 +01:00
else : test_devmode = " Disabled "
# test_headless
2024-03-29 02:41:36 +01:00
if core_test . config . headless : test_headless = " Enabled "
2024-03-28 14:48:50 +01:00
else : test_headless = " Disabled "
# test_custommodules
2024-03-29 02:41:36 +01:00
if core_test . config . custom_modules : test_custommodules = " Enabled "
2024-03-28 14:48:50 +01:00
else : test_custommodules = " Disabled "
var test_raw : String = " version= % version % typerelease= % version_type % s emantic= % version_semantic % type= % type % type_technical= % type_technical % d evmode= %d evmode % he adless= %he adless % c ustommodules= %c ustommodules % HELLO TEST! #TransRightsAreHumanRights "
2024-03-29 02:41:36 +01:00
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 "
2024-03-28 14:48:50 +01:00
# Compare
2024-03-29 02:53:16 +01:00
if await core_test . get_formatted_string ( test_raw ) != test_formatted : rerror ( " Test did not return the right value (in ' " + test_raw + " ' , expected ' " + test_formatted + " ' , got ' " + await core_test . get_formatted_string ( test_raw ) + " ' ) " )
else : rok ( )