feat: godot-engine-source-4.3-stable
This commit is contained in:
parent
c59a7dcade
commit
7125d019b5
11149 changed files with 5070401 additions and 0 deletions
225
engine/tests/core/string/test_node_path.h
Normal file
225
engine/tests/core/string/test_node_path.h
Normal file
|
|
@ -0,0 +1,225 @@
|
|||
/**************************************************************************/
|
||||
/* test_node_path.h */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef TEST_NODE_PATH_H
|
||||
#define TEST_NODE_PATH_H
|
||||
|
||||
#include "core/string/node_path.h"
|
||||
|
||||
#include "tests/test_macros.h"
|
||||
|
||||
namespace TestNodePath {
|
||||
|
||||
TEST_CASE("[NodePath] Relative path") {
|
||||
const NodePath node_path_relative = NodePath("Path2D/PathFollow2D/Sprite2D:position:x");
|
||||
|
||||
CHECK_MESSAGE(
|
||||
node_path_relative.get_as_property_path() == NodePath(":Path2D/PathFollow2D/Sprite2D:position:x"),
|
||||
"The returned property path should match the expected value.");
|
||||
CHECK_MESSAGE(
|
||||
node_path_relative.get_concatenated_subnames() == "position:x",
|
||||
"The returned concatenated subnames should match the expected value.");
|
||||
|
||||
CHECK_MESSAGE(
|
||||
node_path_relative.get_name(0) == "Path2D",
|
||||
"The returned name at index 0 should match the expected value.");
|
||||
CHECK_MESSAGE(
|
||||
node_path_relative.get_name(1) == "PathFollow2D",
|
||||
"The returned name at index 1 should match the expected value.");
|
||||
CHECK_MESSAGE(
|
||||
node_path_relative.get_name(2) == "Sprite2D",
|
||||
"The returned name at index 2 should match the expected value.");
|
||||
ERR_PRINT_OFF;
|
||||
CHECK_MESSAGE(
|
||||
node_path_relative.get_name(3) == "",
|
||||
"The returned name at invalid index 3 should match the expected value.");
|
||||
CHECK_MESSAGE(
|
||||
node_path_relative.get_name(-1) == "",
|
||||
"The returned name at invalid index -1 should match the expected value.");
|
||||
ERR_PRINT_ON;
|
||||
|
||||
CHECK_MESSAGE(
|
||||
node_path_relative.get_name_count() == 3,
|
||||
"The returned number of names should match the expected value.");
|
||||
|
||||
CHECK_MESSAGE(
|
||||
node_path_relative.get_subname(0) == "position",
|
||||
"The returned subname at index 0 should match the expected value.");
|
||||
CHECK_MESSAGE(
|
||||
node_path_relative.get_subname(1) == "x",
|
||||
"The returned subname at index 1 should match the expected value.");
|
||||
ERR_PRINT_OFF;
|
||||
CHECK_MESSAGE(
|
||||
node_path_relative.get_subname(2) == "",
|
||||
"The returned subname at invalid index 2 should match the expected value.");
|
||||
CHECK_MESSAGE(
|
||||
node_path_relative.get_subname(-1) == "",
|
||||
"The returned subname at invalid index -1 should match the expected value.");
|
||||
ERR_PRINT_ON;
|
||||
|
||||
CHECK_MESSAGE(
|
||||
node_path_relative.get_subname_count() == 2,
|
||||
"The returned number of subnames should match the expected value.");
|
||||
|
||||
CHECK_MESSAGE(
|
||||
!node_path_relative.is_absolute(),
|
||||
"The node path should be considered relative.");
|
||||
|
||||
CHECK_MESSAGE(
|
||||
!node_path_relative.is_empty(),
|
||||
"The node path shouldn't be considered empty.");
|
||||
}
|
||||
|
||||
TEST_CASE("[NodePath] Absolute path") {
|
||||
const NodePath node_path_absolute = NodePath("/root/Sprite2D");
|
||||
|
||||
CHECK_MESSAGE(
|
||||
node_path_absolute.get_as_property_path() == NodePath(":root/Sprite2D"),
|
||||
"The returned property path should match the expected value.");
|
||||
CHECK_MESSAGE(
|
||||
node_path_absolute.get_concatenated_subnames() == "",
|
||||
"The returned concatenated subnames should match the expected value.");
|
||||
|
||||
CHECK_MESSAGE(
|
||||
node_path_absolute.get_name(0) == "root",
|
||||
"The returned name at index 0 should match the expected value.");
|
||||
CHECK_MESSAGE(
|
||||
node_path_absolute.get_name(1) == "Sprite2D",
|
||||
"The returned name at index 1 should match the expected value.");
|
||||
ERR_PRINT_OFF;
|
||||
CHECK_MESSAGE(
|
||||
node_path_absolute.get_name(2) == "",
|
||||
"The returned name at invalid index 2 should match the expected value.");
|
||||
CHECK_MESSAGE(
|
||||
node_path_absolute.get_name(-1) == "",
|
||||
"The returned name at invalid index -1 should match the expected value.");
|
||||
ERR_PRINT_ON;
|
||||
|
||||
CHECK_MESSAGE(
|
||||
node_path_absolute.get_name_count() == 2,
|
||||
"The returned number of names should match the expected value.");
|
||||
|
||||
CHECK_MESSAGE(
|
||||
node_path_absolute.get_subname_count() == 0,
|
||||
"The returned number of subnames should match the expected value.");
|
||||
|
||||
CHECK_MESSAGE(
|
||||
node_path_absolute.is_absolute(),
|
||||
"The node path should be considered absolute.");
|
||||
|
||||
CHECK_MESSAGE(
|
||||
!node_path_absolute.is_empty(),
|
||||
"The node path shouldn't be considered empty.");
|
||||
}
|
||||
|
||||
TEST_CASE("[NodePath] Empty path") {
|
||||
const NodePath node_path_empty = NodePath();
|
||||
|
||||
CHECK_MESSAGE(
|
||||
node_path_empty.get_as_property_path() == NodePath(),
|
||||
"The returned property path should match the expected value.");
|
||||
ERR_PRINT_OFF;
|
||||
CHECK_MESSAGE(
|
||||
node_path_empty.get_concatenated_subnames() == "",
|
||||
"The returned concatenated subnames should match the expected value.");
|
||||
ERR_PRINT_ON;
|
||||
|
||||
CHECK_MESSAGE(
|
||||
node_path_empty.get_name_count() == 0,
|
||||
"The returned number of names should match the expected value.");
|
||||
|
||||
CHECK_MESSAGE(
|
||||
node_path_empty.get_subname_count() == 0,
|
||||
"The returned number of subnames should match the expected value.");
|
||||
|
||||
CHECK_MESSAGE(
|
||||
!node_path_empty.is_absolute(),
|
||||
"The node path shouldn't be considered absolute.");
|
||||
|
||||
CHECK_MESSAGE(
|
||||
node_path_empty.is_empty(),
|
||||
"The node path should be considered empty.");
|
||||
}
|
||||
|
||||
TEST_CASE("[NodePath] Slice") {
|
||||
const NodePath node_path_relative = NodePath("Parent/Child:prop");
|
||||
const NodePath node_path_absolute = NodePath("/root/Parent/Child:prop");
|
||||
CHECK_MESSAGE(
|
||||
node_path_relative.slice(0, 2) == NodePath("Parent/Child"),
|
||||
"The slice lower bound should be inclusive and the slice upper bound should be exclusive.");
|
||||
CHECK_MESSAGE(
|
||||
node_path_relative.slice(3) == NodePath(":prop"),
|
||||
"Slicing on the length of the path should return the last entry.");
|
||||
CHECK_MESSAGE(
|
||||
node_path_relative.slice(1, 3) == NodePath("Child:prop"),
|
||||
"Slicing should include names and subnames.");
|
||||
CHECK_MESSAGE(
|
||||
node_path_relative.slice(-1) == NodePath(":prop"),
|
||||
"Slicing on -1 should return the last entry.");
|
||||
CHECK_MESSAGE(
|
||||
node_path_relative.slice(0, -1) == NodePath("Parent/Child"),
|
||||
"Slicing up to -1 should include the second-to-last entry.");
|
||||
CHECK_MESSAGE(
|
||||
node_path_relative.slice(-2, -1) == NodePath("Child"),
|
||||
"Slicing from negative to negative should treat lower bound as inclusive and upper bound as exclusive.");
|
||||
CHECK_MESSAGE(
|
||||
node_path_relative.slice(0, 10) == NodePath("Parent/Child:prop"),
|
||||
"Slicing past the length of the path should work like slicing up to the last entry.");
|
||||
CHECK_MESSAGE(
|
||||
node_path_relative.slice(-10, 2) == NodePath("Parent/Child"),
|
||||
"Slicing negatively past the length of the path should work like slicing from the first entry.");
|
||||
CHECK_MESSAGE(
|
||||
node_path_relative.slice(1, 1) == NodePath(""),
|
||||
"Slicing with a lower bound equal to upper bound should return empty path.");
|
||||
|
||||
CHECK_MESSAGE(
|
||||
node_path_absolute.slice(0, 2) == NodePath("/root/Parent"),
|
||||
"Slice from beginning of an absolute path should be an absolute path.");
|
||||
CHECK_MESSAGE(
|
||||
node_path_absolute.slice(1, 4) == NodePath("Parent/Child:prop"),
|
||||
"Slice of an absolute path that does not start at the beginning should be a relative path.");
|
||||
CHECK_MESSAGE(
|
||||
node_path_absolute.slice(3, 4) == NodePath(":prop"),
|
||||
"Slice of an absolute path that does not start at the beginning should be a relative path.");
|
||||
|
||||
CHECK_MESSAGE(
|
||||
NodePath("").slice(0, 1) == NodePath(""),
|
||||
"Slice of an empty path should be an empty path.");
|
||||
CHECK_MESSAGE(
|
||||
NodePath("").slice(-1, 2) == NodePath(""),
|
||||
"Slice of an empty path should be an empty path.");
|
||||
CHECK_MESSAGE(
|
||||
NodePath("/").slice(-1, 2) == NodePath("/"),
|
||||
"Slice of an empty absolute path should be an empty absolute path.");
|
||||
}
|
||||
|
||||
} // namespace TestNodePath
|
||||
|
||||
#endif // TEST_NODE_PATH_H
|
||||
1943
engine/tests/core/string/test_string.h
Normal file
1943
engine/tests/core/string/test_string.h
Normal file
File diff suppressed because it is too large
Load diff
204
engine/tests/core/string/test_translation.h
Normal file
204
engine/tests/core/string/test_translation.h
Normal file
|
|
@ -0,0 +1,204 @@
|
|||
/**************************************************************************/
|
||||
/* test_translation.h */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef TEST_TRANSLATION_H
|
||||
#define TEST_TRANSLATION_H
|
||||
|
||||
#include "core/string/optimized_translation.h"
|
||||
#include "core/string/translation.h"
|
||||
#include "core/string/translation_po.h"
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
#include "editor/import/resource_importer_csv_translation.h"
|
||||
#endif
|
||||
|
||||
#include "tests/test_macros.h"
|
||||
#include "tests/test_utils.h"
|
||||
|
||||
namespace TestTranslation {
|
||||
|
||||
TEST_CASE("[Translation] Messages") {
|
||||
Ref<Translation> translation = memnew(Translation);
|
||||
translation->set_locale("fr");
|
||||
translation->add_message("Hello", "Bonjour");
|
||||
CHECK(translation->get_message("Hello") == "Bonjour");
|
||||
|
||||
translation->erase_message("Hello");
|
||||
// The message no longer exists, so it returns an empty string instead.
|
||||
CHECK(translation->get_message("Hello") == "");
|
||||
|
||||
List<StringName> messages;
|
||||
translation->get_message_list(&messages);
|
||||
CHECK(translation->get_message_count() == 0);
|
||||
CHECK(messages.size() == 0);
|
||||
|
||||
translation->add_message("Hello2", "Bonjour2");
|
||||
translation->add_message("Hello3", "Bonjour3");
|
||||
messages.clear();
|
||||
translation->get_message_list(&messages);
|
||||
CHECK(translation->get_message_count() == 2);
|
||||
CHECK(messages.size() == 2);
|
||||
// Messages are stored in a Map, don't assume ordering.
|
||||
CHECK(messages.find("Hello2"));
|
||||
CHECK(messages.find("Hello3"));
|
||||
}
|
||||
|
||||
TEST_CASE("[TranslationPO] Messages with context") {
|
||||
Ref<TranslationPO> translation = memnew(TranslationPO);
|
||||
translation->set_locale("fr");
|
||||
translation->add_message("Hello", "Bonjour");
|
||||
translation->add_message("Hello", "Salut", "friendly");
|
||||
CHECK(translation->get_message("Hello") == "Bonjour");
|
||||
CHECK(translation->get_message("Hello", "friendly") == "Salut");
|
||||
CHECK(translation->get_message("Hello", "nonexistent_context") == "");
|
||||
|
||||
// Only remove the message for the default context, not the "friendly" context.
|
||||
translation->erase_message("Hello");
|
||||
// The message no longer exists, so it returns an empty string instead.
|
||||
CHECK(translation->get_message("Hello") == "");
|
||||
CHECK(translation->get_message("Hello", "friendly") == "Salut");
|
||||
CHECK(translation->get_message("Hello", "nonexistent_context") == "");
|
||||
|
||||
List<StringName> messages;
|
||||
translation->get_message_list(&messages);
|
||||
|
||||
// `get_message_count()` takes all contexts into account.
|
||||
CHECK(translation->get_message_count() == 1);
|
||||
// Only the default context is taken into account.
|
||||
// Since "Hello" is now only present in a non-default context, it is not counted in the list of messages.
|
||||
CHECK(messages.size() == 0);
|
||||
|
||||
translation->add_message("Hello2", "Bonjour2");
|
||||
translation->add_message("Hello2", "Salut2", "friendly");
|
||||
translation->add_message("Hello3", "Bonjour3");
|
||||
messages.clear();
|
||||
translation->get_message_list(&messages);
|
||||
|
||||
// `get_message_count()` takes all contexts into account.
|
||||
CHECK(translation->get_message_count() == 4);
|
||||
// Only the default context is taken into account.
|
||||
CHECK(messages.size() == 2);
|
||||
// Messages are stored in a Map, don't assume ordering.
|
||||
CHECK(messages.find("Hello2"));
|
||||
CHECK(messages.find("Hello3"));
|
||||
}
|
||||
|
||||
TEST_CASE("[TranslationPO] Plural messages") {
|
||||
Ref<TranslationPO> translation = memnew(TranslationPO);
|
||||
translation->set_locale("fr");
|
||||
translation->set_plural_rule("Plural-Forms: nplurals=2; plural=(n >= 2);");
|
||||
CHECK(translation->get_plural_forms() == 2);
|
||||
|
||||
PackedStringArray plurals;
|
||||
plurals.push_back("Il y a %d pomme");
|
||||
plurals.push_back("Il y a %d pommes");
|
||||
translation->add_plural_message("There are %d apples", plurals);
|
||||
ERR_PRINT_OFF;
|
||||
// This is invalid, as the number passed to `get_plural_message()` may not be negative.
|
||||
CHECK(vformat(translation->get_plural_message("There are %d apples", "", -1), -1) == "");
|
||||
ERR_PRINT_ON;
|
||||
CHECK(vformat(translation->get_plural_message("There are %d apples", "", 0), 0) == "Il y a 0 pomme");
|
||||
CHECK(vformat(translation->get_plural_message("There are %d apples", "", 1), 1) == "Il y a 1 pomme");
|
||||
CHECK(vformat(translation->get_plural_message("There are %d apples", "", 2), 2) == "Il y a 2 pommes");
|
||||
}
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
TEST_CASE("[OptimizedTranslation] Generate from Translation and read messages") {
|
||||
Ref<Translation> translation = memnew(Translation);
|
||||
translation->set_locale("fr");
|
||||
translation->add_message("Hello", "Bonjour");
|
||||
translation->add_message("Hello2", "Bonjour2");
|
||||
translation->add_message("Hello3", "Bonjour3");
|
||||
|
||||
Ref<OptimizedTranslation> optimized_translation = memnew(OptimizedTranslation);
|
||||
optimized_translation->generate(translation);
|
||||
CHECK(optimized_translation->get_message("Hello") == "Bonjour");
|
||||
CHECK(optimized_translation->get_message("Hello2") == "Bonjour2");
|
||||
CHECK(optimized_translation->get_message("Hello3") == "Bonjour3");
|
||||
CHECK(optimized_translation->get_message("DoesNotExist") == "");
|
||||
|
||||
List<StringName> messages;
|
||||
// `get_message_list()` can't return the list of messages stored in an OptimizedTranslation.
|
||||
optimized_translation->get_message_list(&messages);
|
||||
CHECK(optimized_translation->get_message_count() == 0);
|
||||
CHECK(messages.size() == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("[TranslationCSV] CSV import") {
|
||||
Ref<ResourceImporterCSVTranslation> import_csv_translation = memnew(ResourceImporterCSVTranslation);
|
||||
|
||||
HashMap<StringName, Variant> options;
|
||||
options["compress"] = false;
|
||||
options["delimiter"] = 0;
|
||||
|
||||
List<String> gen_files;
|
||||
|
||||
Error result = import_csv_translation->import(TestUtils::get_data_path("translations.csv"),
|
||||
"", options, nullptr, &gen_files);
|
||||
CHECK(result == OK);
|
||||
CHECK(gen_files.size() == 4);
|
||||
|
||||
TranslationServer *ts = TranslationServer::get_singleton();
|
||||
|
||||
for (const String &file : gen_files) {
|
||||
Ref<Translation> translation = ResourceLoader::load(file);
|
||||
CHECK(translation.is_valid());
|
||||
ts->add_translation(translation);
|
||||
}
|
||||
|
||||
ts->set_locale("en");
|
||||
|
||||
// `tr` can be called on any Object, we reuse TranslationServer for convenience.
|
||||
CHECK(ts->tr("GOOD_MORNING") == "Good Morning");
|
||||
CHECK(ts->tr("GOOD_EVENING") == "Good Evening");
|
||||
|
||||
ts->set_locale("de");
|
||||
|
||||
CHECK(ts->tr("GOOD_MORNING") == "Guten Morgen");
|
||||
CHECK(ts->tr("GOOD_EVENING") == "Good Evening"); // Left blank in CSV, should source from 'en'.
|
||||
|
||||
ts->set_locale("ja");
|
||||
|
||||
CHECK(ts->tr("GOOD_MORNING") == String::utf8("おはよう"));
|
||||
CHECK(ts->tr("GOOD_EVENING") == String::utf8("こんばんは"));
|
||||
|
||||
/* FIXME: This passes, but triggers a chain reaction that makes test_viewport
|
||||
* and test_text_edit explode in a billion glittery Unicode particles.
|
||||
ts->set_locale("fa");
|
||||
|
||||
CHECK(ts->tr("GOOD_MORNING") == String::utf8("صبح بخیر"));
|
||||
CHECK(ts->tr("GOOD_EVENING") == String::utf8("عصر بخیر"));
|
||||
*/
|
||||
}
|
||||
#endif // TOOLS_ENABLED
|
||||
|
||||
} // namespace TestTranslation
|
||||
|
||||
#endif // TEST_TRANSLATION_H
|
||||
136
engine/tests/core/string/test_translation_server.h
Normal file
136
engine/tests/core/string/test_translation_server.h
Normal file
|
|
@ -0,0 +1,136 @@
|
|||
/**************************************************************************/
|
||||
/* test_translation_server.h */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef TEST_TRANSLATION_SERVER_H
|
||||
#define TEST_TRANSLATION_SERVER_H
|
||||
|
||||
#include "core/string/translation.h"
|
||||
|
||||
#include "tests/test_macros.h"
|
||||
|
||||
namespace TestTranslationServer {
|
||||
TEST_CASE("[TranslationServer] Translation operations") {
|
||||
Ref<Translation> t = memnew(Translation);
|
||||
t->set_locale("uk");
|
||||
t->add_message("Good Morning", String::utf8("Добрий ранок"));
|
||||
|
||||
TranslationServer *ts = TranslationServer::get_singleton();
|
||||
|
||||
int l_count_before = ts->get_loaded_locales().size();
|
||||
ts->add_translation(t);
|
||||
int l_count_after = ts->get_loaded_locales().size();
|
||||
// Newly created Translation object should be added to the list, so the counter should increase, too.
|
||||
CHECK(l_count_after > l_count_before);
|
||||
|
||||
Ref<Translation> trans = ts->get_translation_object("uk");
|
||||
CHECK(trans.is_valid());
|
||||
|
||||
ts->set_locale("uk");
|
||||
CHECK(ts->translate("Good Morning") == String::utf8("Добрий ранок"));
|
||||
|
||||
ts->remove_translation(t);
|
||||
trans = ts->get_translation_object("uk");
|
||||
CHECK(trans.is_null());
|
||||
// If no suitable Translation object has been found - the original message should be returned.
|
||||
CHECK(ts->translate("Good Morning") == "Good Morning");
|
||||
}
|
||||
|
||||
TEST_CASE("[TranslationServer] Locale operations") {
|
||||
TranslationServer *ts = TranslationServer::get_singleton();
|
||||
|
||||
// Language variant test; we supplied the variant of Español and the result should be the same string.
|
||||
String loc = "es_Hani_ES_tradnl";
|
||||
String res = ts->standardize_locale(loc);
|
||||
|
||||
CHECK(res == loc);
|
||||
|
||||
// No such variant in variant_map; should return everything except the variant.
|
||||
loc = "es_Hani_ES_missing";
|
||||
res = ts->standardize_locale(loc);
|
||||
|
||||
CHECK(res == "es_Hani_ES");
|
||||
|
||||
// Non-ISO language name check (Windows issue).
|
||||
loc = "iw_Hani_IL";
|
||||
res = ts->standardize_locale(loc);
|
||||
|
||||
CHECK(res == "he_Hani_IL");
|
||||
|
||||
// Country rename check.
|
||||
loc = "uk_Hani_UK";
|
||||
res = ts->standardize_locale(loc);
|
||||
|
||||
CHECK(res == "uk_Hani_GB");
|
||||
|
||||
// Supplying a script name that is not in the list.
|
||||
loc = "de_Wrong_DE";
|
||||
res = ts->standardize_locale(loc);
|
||||
|
||||
CHECK(res == "de_DE");
|
||||
}
|
||||
|
||||
TEST_CASE("[TranslationServer] Comparing locales") {
|
||||
TranslationServer *ts = TranslationServer::get_singleton();
|
||||
|
||||
String locale_a = "es";
|
||||
String locale_b = "es";
|
||||
|
||||
// Exact match check.
|
||||
int res = ts->compare_locales(locale_a, locale_b);
|
||||
|
||||
CHECK(res == 10);
|
||||
|
||||
locale_a = "sr-Latn-CS";
|
||||
locale_b = "sr-Latn-RS";
|
||||
|
||||
// Two elements from locales match.
|
||||
res = ts->compare_locales(locale_a, locale_b);
|
||||
|
||||
CHECK(res == 2);
|
||||
|
||||
locale_a = "uz-Cyrl-UZ";
|
||||
locale_b = "uz-Latn-UZ";
|
||||
|
||||
// Two elements match, but they are not sequentual.
|
||||
res = ts->compare_locales(locale_a, locale_b);
|
||||
|
||||
CHECK(res == 2);
|
||||
|
||||
locale_a = "es-EC";
|
||||
locale_b = "fr-LU";
|
||||
|
||||
// No match.
|
||||
res = ts->compare_locales(locale_a, locale_b);
|
||||
|
||||
CHECK(res == 0);
|
||||
}
|
||||
} // namespace TestTranslationServer
|
||||
|
||||
#endif // TEST_TRANSLATION_SERVER_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue