mirror of
https://github.com/godotengine/godot.git
synced 2025-12-08 06:09:55 +00:00
Port ClassDB tests to use doctest
Extracted the most minimal core initialization functionality from `setup()` and `setup2()` so that `ClassDB` could be tested properly (input, audio, rendering, physics etc, are excluded). Display and rendering servers/singletons are not initialized at all. Due to the fact that most subsystems are disabled, fixed various crashes in the process (in order): - `AcceptDialog` OK/cancel swap behavior (used `DisplayServer` while `register_scene_types()`); - `make_default_theme` which depends on `RenderingServer`; - `XRServer` singleton access while calling `register_modules_types()`; - hidden bug in a way joypads are cleaned up (MacOS and Linux only). Removed manual `ClassDB` init/cleanup calls from `test_validate_testing.h`. ClassDB tests: Co-authored-by: Ignacio Etcheverry <ignalfonsore@gmail.com>
This commit is contained in:
parent
87ae509905
commit
6f426c3360
11 changed files with 905 additions and 903 deletions
|
|
@ -369,16 +369,94 @@ void Main::print_help(const char *p_binary) {
|
|||
#endif
|
||||
}
|
||||
|
||||
#ifdef TESTS_ENABLED
|
||||
// The order is the same as in `Main::setup()`, only core and some editor types
|
||||
// are initialized here. This also combines `Main::setup2()` initialization.
|
||||
Error Main::test_setup() {
|
||||
OS::get_singleton()->initialize();
|
||||
|
||||
engine = memnew(Engine);
|
||||
|
||||
ClassDB::init();
|
||||
|
||||
register_core_types();
|
||||
register_core_driver_types();
|
||||
|
||||
globals = memnew(ProjectSettings);
|
||||
|
||||
GLOBAL_DEF("debug/settings/crash_handler/message",
|
||||
String("Please include this when reporting the bug on https://github.com/godotengine/godot/issues"));
|
||||
|
||||
// From `Main::setup2()`.
|
||||
preregister_module_types();
|
||||
preregister_server_types();
|
||||
|
||||
register_core_singletons();
|
||||
|
||||
register_server_types();
|
||||
register_scene_types();
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
ClassDB::set_current_api(ClassDB::API_EDITOR);
|
||||
EditorNode::register_editor_types();
|
||||
|
||||
ClassDB::set_current_api(ClassDB::API_CORE);
|
||||
#endif
|
||||
register_platform_apis();
|
||||
|
||||
register_module_types();
|
||||
register_driver_types();
|
||||
|
||||
ClassDB::set_current_api(ClassDB::API_NONE);
|
||||
|
||||
_start_success = true;
|
||||
|
||||
return OK;
|
||||
}
|
||||
// The order is the same as in `Main::cleanup()`.
|
||||
void Main::test_cleanup() {
|
||||
ERR_FAIL_COND(!_start_success);
|
||||
|
||||
EngineDebugger::deinitialize();
|
||||
|
||||
ResourceLoader::remove_custom_loaders();
|
||||
ResourceSaver::remove_custom_savers();
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
EditorNode::unregister_editor_types();
|
||||
#endif
|
||||
unregister_driver_types();
|
||||
unregister_module_types();
|
||||
unregister_platform_apis();
|
||||
unregister_scene_types();
|
||||
unregister_server_types();
|
||||
|
||||
OS::get_singleton()->finalize();
|
||||
|
||||
if (globals) {
|
||||
memdelete(globals);
|
||||
}
|
||||
if (engine) {
|
||||
memdelete(engine);
|
||||
}
|
||||
|
||||
unregister_core_driver_types();
|
||||
unregister_core_types();
|
||||
|
||||
OS::get_singleton()->finalize_core();
|
||||
}
|
||||
#endif
|
||||
|
||||
int Main::test_entrypoint(int argc, char *argv[], bool &tests_need_run) {
|
||||
#ifdef TESTS_ENABLED
|
||||
for (int x = 0; x < argc; x++) {
|
||||
if ((strncmp(argv[x], "--test", 6) == 0) && (strlen(argv[x]) == 6)) {
|
||||
tests_need_run = true;
|
||||
OS::get_singleton()->initialize();
|
||||
StringName::setup();
|
||||
// TODO: need to come up with different test contexts.
|
||||
// Not every test requires high-level functionality like `ClassDB`.
|
||||
test_setup();
|
||||
int status = test_main(argc, argv);
|
||||
StringName::cleanup();
|
||||
// TODO: fix OS::singleton cleanup
|
||||
test_cleanup();
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue