diff options
Diffstat (limited to 'tests/core/config/test_project_settings.h')
| -rw-r--r-- | tests/core/config/test_project_settings.h | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/core/config/test_project_settings.h b/tests/core/config/test_project_settings.h index 1deafccde1..9bd072f511 100644 --- a/tests/core/config/test_project_settings.h +++ b/tests/core/config/test_project_settings.h @@ -32,9 +32,17 @@ #define TEST_PROJECT_SETTINGS_H #include "core/config/project_settings.h" +#include "core/io/dir_access.h" #include "core/variant/variant.h" #include "tests/test_macros.h" +class TestProjectSettingsInternalsAccessor { +public: + static String &resource_path() { + return ProjectSettings::get_singleton()->resource_path; + }; +}; + namespace TestProjectSettings { TEST_CASE("[ProjectSettings] Get existing setting") { @@ -97,6 +105,58 @@ TEST_CASE("[ProjectSettings] Set value should be returned when retrieved") { CHECK(ProjectSettings::get_singleton()->has_setting("my_custom_setting")); } +TEST_CASE("[ProjectSettings] localize_path") { + String old_resource_path = TestProjectSettingsInternalsAccessor::resource_path(); + TestProjectSettingsInternalsAccessor::resource_path() = DirAccess::create(DirAccess::ACCESS_FILESYSTEM)->get_current_dir(); + String root_path = ProjectSettings::get_singleton()->get_resource_path(); +#ifdef WINDOWS_ENABLED + String root_path_win = ProjectSettings::get_singleton()->get_resource_path().replace("/", "\\"); +#endif + + CHECK_EQ(ProjectSettings::get_singleton()->localize_path("filename"), "res://filename"); + CHECK_EQ(ProjectSettings::get_singleton()->localize_path("path/filename"), "res://path/filename"); + CHECK_EQ(ProjectSettings::get_singleton()->localize_path("path/something/../filename"), "res://path/filename"); + CHECK_EQ(ProjectSettings::get_singleton()->localize_path("path/./filename"), "res://path/filename"); +#ifdef WINDOWS_ENABLED + CHECK_EQ(ProjectSettings::get_singleton()->localize_path("path\\filename"), "res://path/filename"); + CHECK_EQ(ProjectSettings::get_singleton()->localize_path("path\\something\\..\\filename"), "res://path/filename"); + CHECK_EQ(ProjectSettings::get_singleton()->localize_path("path\\.\\filename"), "res://path/filename"); +#endif + + // FIXME?: These checks pass, but that doesn't seems correct + CHECK_EQ(ProjectSettings::get_singleton()->localize_path("../filename"), "res://filename"); + CHECK_EQ(ProjectSettings::get_singleton()->localize_path("../path/filename"), "res://path/filename"); + CHECK_EQ(ProjectSettings::get_singleton()->localize_path("..\\path\\filename"), "res://path/filename"); + + CHECK_EQ(ProjectSettings::get_singleton()->localize_path("/testroot/filename"), "/testroot/filename"); + CHECK_EQ(ProjectSettings::get_singleton()->localize_path("/testroot/path/filename"), "/testroot/path/filename"); + CHECK_EQ(ProjectSettings::get_singleton()->localize_path("/testroot/path/something/../filename"), "/testroot/path/filename"); + CHECK_EQ(ProjectSettings::get_singleton()->localize_path("/testroot/path/./filename"), "/testroot/path/filename"); +#ifdef WINDOWS_ENABLED + CHECK_EQ(ProjectSettings::get_singleton()->localize_path("C:/testroot/filename"), "C:/testroot/filename"); + CHECK_EQ(ProjectSettings::get_singleton()->localize_path("C:/testroot/path/filename"), "C:/testroot/path/filename"); + CHECK_EQ(ProjectSettings::get_singleton()->localize_path("C:/testroot/path/something/../filename"), "C:/testroot/path/filename"); + CHECK_EQ(ProjectSettings::get_singleton()->localize_path("C:/testroot/path/./filename"), "C:/testroot/path/filename"); + CHECK_EQ(ProjectSettings::get_singleton()->localize_path("C:\\testroot\\filename"), "C:/testroot/filename"); + CHECK_EQ(ProjectSettings::get_singleton()->localize_path("C:\\testroot\\path\\filename"), "C:/testroot/path/filename"); + CHECK_EQ(ProjectSettings::get_singleton()->localize_path("C:\\testroot\\path\\something\\..\\filename"), "C:/testroot/path/filename"); + CHECK_EQ(ProjectSettings::get_singleton()->localize_path("C:\\testroot\\path\\.\\filename"), "C:/testroot/path/filename"); +#endif + + CHECK_EQ(ProjectSettings::get_singleton()->localize_path(root_path + "/filename"), "res://filename"); + CHECK_EQ(ProjectSettings::get_singleton()->localize_path(root_path + "/path/filename"), "res://path/filename"); + CHECK_EQ(ProjectSettings::get_singleton()->localize_path(root_path + "/path/something/../filename"), "res://path/filename"); + CHECK_EQ(ProjectSettings::get_singleton()->localize_path(root_path + "/path/./filename"), "res://path/filename"); +#ifdef WINDOWS_ENABLED + CHECK_EQ(ProjectSettings::get_singleton()->localize_path(root_path_win + "\\filename"), "res://filename"); + CHECK_EQ(ProjectSettings::get_singleton()->localize_path(root_path_win + "\\path\\filename"), "res://path/filename"); + CHECK_EQ(ProjectSettings::get_singleton()->localize_path(root_path_win + "\\path\\something\\..\\filename"), "res://path/filename"); + CHECK_EQ(ProjectSettings::get_singleton()->localize_path(root_path_win + "\\path\\.\\filename"), "res://path/filename"); +#endif + + TestProjectSettingsInternalsAccessor::resource_path() = old_resource_path; +} + } // namespace TestProjectSettings #endif // TEST_PROJECT_SETTINGS_H |
