summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
Diffstat (limited to 'main')
-rw-r--r--main/main.cpp102
-rw-r--r--main/main.h6
2 files changed, 90 insertions, 18 deletions
diff --git a/main/main.cpp b/main/main.cpp
index 5f791159f9..e45162c0f3 100644
--- a/main/main.cpp
+++ b/main/main.cpp
@@ -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) {
+ 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;
}
}
@@ -1079,14 +1157,11 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/driver/driver_name",
PropertyInfo(Variant::STRING,
"rendering/quality/driver/driver_name",
- PROPERTY_HINT_ENUM, "Vulkan,GLES2"));
+ PROPERTY_HINT_ENUM, "Vulkan"));
if (display_driver == "") {
display_driver = GLOBAL_GET("rendering/quality/driver/driver_name");
}
- // Assigning here even though it's GLES2-specific, to be sure that it appears in docs
- GLOBAL_DEF("rendering/quality/2d/gles2_use_nvidia_rect_flicker_workaround", false);
-
GLOBAL_DEF("display/window/size/width", 1024);
ProjectSettings::get_singleton()->set_custom_property_info("display/window/size/width",
PropertyInfo(Variant::INT, "display/window/size/width",
@@ -1143,7 +1218,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
}
if (bool(GLOBAL_GET("display/window/size/always_on_top"))) {
- window_flags |= DisplayServer::WINDOW_FLAG_ALWAYS_ON_TOP;
+ window_flags |= DisplayServer::WINDOW_FLAG_ALWAYS_ON_TOP_BIT;
}
}
@@ -2203,13 +2278,6 @@ bool Main::start() {
}
if (project_manager || editor) {
- if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_CONSOLE_WINDOW)) {
- // Hide console window if requested (Windows-only).
- bool hide_console = EditorSettings::get_singleton()->get_setting(
- "interface/editor/hide_console_window");
- DisplayServer::get_singleton()->console_set_visible(!hide_console);
- }
-
// Load SSL Certificates from Editor Settings (or builtin)
Crypto::load_default_certificates(EditorSettings::get_singleton()->get_setting(
"network/ssl/editor_ssl_certificates")
diff --git a/main/main.h b/main/main.h
index 20c0bebefa..75a1c0d8cd 100644
--- a/main/main.h
+++ b/main/main.h
@@ -48,6 +48,10 @@ public:
static int test_entrypoint(int argc, char *argv[], bool &tests_need_run);
static Error setup(const char *execpath, int argc, char *argv[], bool p_second_phase = true);
static Error setup2(Thread::ID p_main_tid_override = 0);
+#ifdef TESTS_ENABLED
+ static Error test_setup();
+ static void test_cleanup();
+#endif
static bool start();
static bool iteration();
@@ -58,7 +62,7 @@ public:
static void cleanup();
};
-// Test main override is for the testing behaviour
+// Test main override is for the testing behaviour.
#define TEST_MAIN_OVERRIDE \
bool run_test = false; \
int return_code = Main::test_entrypoint(argc, argv, run_test); \