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