summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/core/io/test_marshalls.h99
-rw-r--r--tests/core/string/test_translation.h2
-rw-r--r--tests/core/string/test_translation_server.h88
-rw-r--r--tests/scene/test_audio_stream_wav.h2
-rw-r--r--tests/scene/test_viewport.h2
5 files changed, 168 insertions, 25 deletions
diff --git a/tests/core/io/test_marshalls.h b/tests/core/io/test_marshalls.h
index de8d6e1406..6716984681 100644
--- a/tests/core/io/test_marshalls.h
+++ b/tests/core/io/test_marshalls.h
@@ -160,7 +160,7 @@ TEST_CASE("[Marshalls] NIL Variant encoding") {
uint8_t buffer[4];
CHECK(encode_variant(variant, buffer, r_len) == OK);
- CHECK_MESSAGE(r_len == 4, "Length == 4 bytes for header");
+ CHECK_MESSAGE(r_len == 4, "Length == 4 bytes for header.");
CHECK_MESSAGE(buffer[0] == 0x00, "Variant::NIL");
CHECK(buffer[1] == 0x00);
CHECK(buffer[2] == 0x00);
@@ -174,7 +174,7 @@ TEST_CASE("[Marshalls] INT 32 bit Variant encoding") {
uint8_t buffer[8];
CHECK(encode_variant(variant, buffer, r_len) == OK);
- CHECK_MESSAGE(r_len == 8, "Length == 4 bytes for header + 4 bytes for int32_t");
+ CHECK_MESSAGE(r_len == 8, "Length == 4 bytes for header + 4 bytes for `int32_t`.");
CHECK_MESSAGE(buffer[0] == 0x02, "Variant::INT");
CHECK(buffer[1] == 0x00);
CHECK(buffer[2] == 0x00);
@@ -192,7 +192,7 @@ TEST_CASE("[Marshalls] INT 64 bit Variant encoding") {
uint8_t buffer[12];
CHECK(encode_variant(variant, buffer, r_len) == OK);
- CHECK_MESSAGE(r_len == 12, "Length == 4 bytes for header + 8 bytes for int64_t");
+ CHECK_MESSAGE(r_len == 12, "Length == 4 bytes for header + 8 bytes for `int64_t`.");
CHECK_MESSAGE(buffer[0] == 0x02, "Variant::INT");
CHECK(buffer[1] == 0x00);
CHECK_MESSAGE(buffer[2] == 0x01, "HEADER_DATA_FLAG_64");
@@ -214,7 +214,7 @@ TEST_CASE("[Marshalls] FLOAT single precision Variant encoding") {
uint8_t buffer[8];
CHECK(encode_variant(variant, buffer, r_len) == OK);
- CHECK_MESSAGE(r_len == 8, "Length == 4 bytes for header + 4 bytes for float");
+ CHECK_MESSAGE(r_len == 8, "Length == 4 bytes for header + 4 bytes for `float`.");
CHECK_MESSAGE(buffer[0] == 0x03, "Variant::FLOAT");
CHECK(buffer[1] == 0x00);
CHECK(buffer[2] == 0x00);
@@ -232,7 +232,7 @@ TEST_CASE("[Marshalls] FLOAT double precision Variant encoding") {
uint8_t buffer[12];
CHECK(encode_variant(variant, buffer, r_len) == OK);
- CHECK_MESSAGE(r_len == 12, "Length == 4 bytes for header + 8 bytes for double");
+ CHECK_MESSAGE(r_len == 12, "Length == 4 bytes for header + 8 bytes for `double`.");
CHECK_MESSAGE(buffer[0] == 0x03, "Variant::FLOAT");
CHECK(buffer[1] == 0x00);
CHECK_MESSAGE(buffer[2] == 0x01, "HEADER_DATA_FLAG_64");
@@ -335,10 +335,10 @@ TEST_CASE("[Marshalls] Typed array encoding") {
uint8_t buffer[24];
CHECK(encode_variant(array, buffer, r_len) == OK);
- CHECK_MESSAGE(r_len == 24, "Length == 4 bytes for header + 4 bytes for array type + 4 bytes for array size + 12 bytes for element");
+ CHECK_MESSAGE(r_len == 24, "Length == 4 bytes for header + 4 bytes for array type + 4 bytes for array size + 12 bytes for element.");
CHECK_MESSAGE(buffer[0] == 0x1c, "Variant::ARRAY");
CHECK(buffer[1] == 0x00);
- CHECK_MESSAGE(buffer[2] == 0x01, "HEADER_DATA_FIELD_TYPED_ARRAY_BUILTIN");
+ CHECK_MESSAGE(buffer[2] == 0x01, "CONTAINER_TYPE_KIND_BUILTIN");
CHECK(buffer[3] == 0x00);
// Check array type.
CHECK_MESSAGE(buffer[4] == 0x02, "Variant::INT");
@@ -370,7 +370,7 @@ TEST_CASE("[Marshalls] Typed array decoding") {
Variant variant;
int r_len;
uint8_t buffer[] = {
- 0x1c, 0x00, 0x01, 0x00, // Variant::ARRAY, HEADER_DATA_FIELD_TYPED_ARRAY_BUILTIN
+ 0x1c, 0x00, 0x01, 0x00, // Variant::ARRAY, CONTAINER_TYPE_KIND_BUILTIN
0x02, 0x00, 0x00, 0x00, // Array type (Variant::INT).
0x01, 0x00, 0x00, 0x00, // Array size.
0x02, 0x00, 0x01, 0x00, // Element type (Variant::INT, HEADER_DATA_FLAG_64).
@@ -386,6 +386,89 @@ TEST_CASE("[Marshalls] Typed array decoding") {
CHECK(array[0] == Variant(uint64_t(0x0f123456789abcdef)));
}
+TEST_CASE("[Marshalls] Typed dicttionary encoding") {
+ int r_len;
+ Dictionary dictionary;
+ dictionary.set_typed(Variant::INT, StringName(), Ref<Script>(), Variant::INT, StringName(), Ref<Script>());
+ dictionary[Variant(uint64_t(0x0f123456789abcdef))] = Variant(uint64_t(0x0f123456789abcdef));
+ uint8_t buffer[40];
+
+ CHECK(encode_variant(dictionary, buffer, r_len) == OK);
+ CHECK_MESSAGE(r_len == 40, "Length == 4 bytes for header + 8 bytes for dictionary type + 4 bytes for dictionary size + 24 bytes for key-value pair.");
+ CHECK_MESSAGE(buffer[0] == 0x1b, "Variant::DICTIONARY");
+ CHECK(buffer[1] == 0x00);
+ CHECK_MESSAGE(buffer[2] == 0x05, "key: CONTAINER_TYPE_KIND_BUILTIN | value: CONTAINER_TYPE_KIND_BUILTIN");
+ CHECK(buffer[3] == 0x00);
+ // Check dictionary key type.
+ CHECK_MESSAGE(buffer[4] == 0x02, "Variant::INT");
+ CHECK(buffer[5] == 0x00);
+ CHECK(buffer[6] == 0x00);
+ CHECK(buffer[7] == 0x00);
+ // Check dictionary value type.
+ CHECK_MESSAGE(buffer[8] == 0x02, "Variant::INT");
+ CHECK(buffer[9] == 0x00);
+ CHECK(buffer[10] == 0x00);
+ CHECK(buffer[11] == 0x00);
+ // Check dictionary size.
+ CHECK(buffer[12] == 0x01);
+ CHECK(buffer[13] == 0x00);
+ CHECK(buffer[14] == 0x00);
+ CHECK(buffer[15] == 0x00);
+ // Check key type.
+ CHECK_MESSAGE(buffer[16] == 0x02, "Variant::INT");
+ CHECK(buffer[17] == 0x00);
+ CHECK_MESSAGE(buffer[18] == 0x01, "HEADER_DATA_FLAG_64");
+ CHECK(buffer[19] == 0x00);
+ // Check key value.
+ CHECK(buffer[20] == 0xef);
+ CHECK(buffer[21] == 0xcd);
+ CHECK(buffer[22] == 0xab);
+ CHECK(buffer[23] == 0x89);
+ CHECK(buffer[24] == 0x67);
+ CHECK(buffer[25] == 0x45);
+ CHECK(buffer[26] == 0x23);
+ CHECK(buffer[27] == 0xf1);
+ // Check value type.
+ CHECK_MESSAGE(buffer[28] == 0x02, "Variant::INT");
+ CHECK(buffer[29] == 0x00);
+ CHECK_MESSAGE(buffer[30] == 0x01, "HEADER_DATA_FLAG_64");
+ CHECK(buffer[31] == 0x00);
+ // Check value value.
+ CHECK(buffer[32] == 0xef);
+ CHECK(buffer[33] == 0xcd);
+ CHECK(buffer[34] == 0xab);
+ CHECK(buffer[35] == 0x89);
+ CHECK(buffer[36] == 0x67);
+ CHECK(buffer[37] == 0x45);
+ CHECK(buffer[38] == 0x23);
+ CHECK(buffer[39] == 0xf1);
+}
+
+TEST_CASE("[Marshalls] Typed dictionary decoding") {
+ Variant variant;
+ int r_len;
+ uint8_t buffer[] = {
+ 0x1b, 0x00, 0x05, 0x00, // Variant::DICTIONARY, key: CONTAINER_TYPE_KIND_BUILTIN | value: CONTAINER_TYPE_KIND_BUILTIN
+ 0x02, 0x00, 0x00, 0x00, // Dictionary key type (Variant::INT).
+ 0x02, 0x00, 0x00, 0x00, // Dictionary value type (Variant::INT).
+ 0x01, 0x00, 0x00, 0x00, // Dictionary size.
+ 0x02, 0x00, 0x01, 0x00, // Key type (Variant::INT, HEADER_DATA_FLAG_64).
+ 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0xf1, // Key value.
+ 0x02, 0x00, 0x01, 0x00, // Value type (Variant::INT, HEADER_DATA_FLAG_64).
+ 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0xf1, // Value value.
+ };
+
+ CHECK(decode_variant(variant, buffer, 40, &r_len) == OK);
+ CHECK(r_len == 40);
+ CHECK(variant.get_type() == Variant::DICTIONARY);
+ Dictionary dictionary = variant;
+ CHECK(dictionary.get_typed_key_builtin() == Variant::INT);
+ CHECK(dictionary.get_typed_value_builtin() == Variant::INT);
+ CHECK(dictionary.size() == 1);
+ CHECK(dictionary.has(Variant(uint64_t(0x0f123456789abcdef))));
+ CHECK(dictionary[Variant(uint64_t(0x0f123456789abcdef))] == Variant(uint64_t(0x0f123456789abcdef)));
+}
+
} // namespace TestMarshalls
#endif // TEST_MARSHALLS_H
diff --git a/tests/core/string/test_translation.h b/tests/core/string/test_translation.h
index 7c389191e3..2b1069d40c 100644
--- a/tests/core/string/test_translation.h
+++ b/tests/core/string/test_translation.h
@@ -161,7 +161,7 @@ TEST_CASE("[TranslationCSV] CSV import") {
List<String> gen_files;
- Error result = import_csv_translation->import(TestUtils::get_data_path("translations.csv"),
+ Error result = import_csv_translation->import(0, TestUtils::get_data_path("translations.csv"),
"", options, nullptr, &gen_files);
CHECK(result == OK);
CHECK(gen_files.size() == 4);
diff --git a/tests/core/string/test_translation_server.h b/tests/core/string/test_translation_server.h
index ac1599f2e8..6668a7b57b 100644
--- a/tests/core/string/test_translation_server.h
+++ b/tests/core/string/test_translation_server.h
@@ -37,27 +37,37 @@
namespace TestTranslationServer {
TEST_CASE("[TranslationServer] Translation operations") {
- Ref<Translation> t = memnew(Translation);
- t->set_locale("uk");
- t->add_message("Good Morning", String::utf8("Добрий ранок"));
+ Ref<Translation> t1 = memnew(Translation);
+ t1->set_locale("uk");
+ t1->add_message("Good Morning", String(U"Добрий ранок"));
+
+ Ref<Translation> t2 = memnew(Translation);
+ t2->set_locale("uk");
+ t2->add_message("Hello Godot", String(U"你好戈多"));
TranslationServer *ts = TranslationServer::get_singleton();
+ // Adds translation for UK locale for the first time.
int l_count_before = ts->get_loaded_locales().size();
- ts->add_translation(t);
+ ts->add_translation(t1);
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());
+ // Adds translation for UK locale again.
+ ts->add_translation(t2);
+ CHECK_EQ(ts->get_loaded_locales().size(), l_count_after);
+
+ // Removing that translation.
+ ts->remove_translation(t2);
+ CHECK_EQ(ts->get_loaded_locales().size(), l_count_after);
+
+ CHECK(ts->get_translation_object("uk").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());
+ ts->remove_translation(t1);
+ CHECK(ts->get_translation_object("uk").is_null());
// If no suitable Translation object has been found - the original message should be returned.
CHECK(ts->translate("Good Morning") == "Good Morning");
}
@@ -110,18 +120,50 @@ TEST_CASE("[TranslationServer] Comparing locales") {
locale_a = "sr-Latn-CS";
locale_b = "sr-Latn-RS";
- // Two elements from locales match.
+ // Script matches (+1) but country doesn't (-1).
res = ts->compare_locales(locale_a, locale_b);
- CHECK(res == 2);
+ CHECK(res == 5);
locale_a = "uz-Cyrl-UZ";
locale_b = "uz-Latn-UZ";
- // Two elements match, but they are not sequentual.
+ // Country matches (+1) but script doesn't (-1).
+ res = ts->compare_locales(locale_a, locale_b);
+
+ CHECK(res == 5);
+
+ locale_a = "aa-Latn-ER";
+ locale_b = "aa-Latn-ER-saaho";
+
+ // Script and country match (+2) with variant on one locale (+0).
res = ts->compare_locales(locale_a, locale_b);
- CHECK(res == 2);
+ CHECK(res == 7);
+
+ locale_a = "uz-Cyrl-UZ";
+ locale_b = "uz-Latn-KG";
+
+ // Both script and country mismatched (-2).
+ res = ts->compare_locales(locale_a, locale_b);
+
+ CHECK(res == 3);
+
+ locale_a = "es-ES";
+ locale_b = "es-AR";
+
+ // Mismatched country (-1).
+ res = ts->compare_locales(locale_a, locale_b);
+
+ CHECK(res == 4);
+
+ locale_a = "es";
+ locale_b = "es-AR";
+
+ // No country for one locale (+0).
+ res = ts->compare_locales(locale_a, locale_b);
+
+ CHECK(res == 5);
locale_a = "es-EC";
locale_b = "fr-LU";
@@ -130,6 +172,24 @@ TEST_CASE("[TranslationServer] Comparing locales") {
res = ts->compare_locales(locale_a, locale_b);
CHECK(res == 0);
+
+ locale_a = "zh-HK";
+ locale_b = "zh";
+
+ // In full standardization, zh-HK becomes zh_Hant_HK and zh becomes
+ // zh_Hans_CN. Both script and country mismatch (-2).
+ res = ts->compare_locales(locale_a, locale_b);
+
+ CHECK(res == 3);
+
+ locale_a = "zh-CN";
+ locale_b = "zh";
+
+ // In full standardization, zh and zh-CN both become zh_Hans_CN for an
+ // exact match.
+ res = ts->compare_locales(locale_a, locale_b);
+
+ CHECK(res == 10);
}
} // namespace TestTranslationServer
diff --git a/tests/scene/test_audio_stream_wav.h b/tests/scene/test_audio_stream_wav.h
index d3d5cc8a30..7276dd0878 100644
--- a/tests/scene/test_audio_stream_wav.h
+++ b/tests/scene/test_audio_stream_wav.h
@@ -162,7 +162,7 @@ void run_test(String file_name, AudioStreamWAV::Format data_format, bool stereo,
// Compressed streams can't be saved, disable compression.
options_map["compress/mode"] = 0;
- REQUIRE(wav_importer->import(save_path, save_path, options_map, nullptr) == OK);
+ REQUIRE(wav_importer->import(0, save_path, save_path, options_map, nullptr) == OK);
String load_path = save_path + "." + wav_importer->get_save_extension();
Ref<AudioStreamWAV> loaded_stream = ResourceLoader::load(load_path, "AudioStreamWAV", ResourceFormatImporter::CACHE_MODE_IGNORE, &error);
diff --git a/tests/scene/test_viewport.h b/tests/scene/test_viewport.h
index dde37944ec..06a38f234b 100644
--- a/tests/scene/test_viewport.h
+++ b/tests/scene/test_viewport.h
@@ -1577,7 +1577,7 @@ TEST_CASE("[SceneTree][Viewport] Physics Picking 2D") {
PickingCollider pc;
pc.a = memnew(TestArea2D);
pc.c = memnew(CollisionShape2D);
- pc.r = Ref<RectangleShape2D>(memnew(RectangleShape2D));
+ pc.r.instantiate();
pc.r->set_size(Size2(150, 150));
pc.c->set_shape(pc.r);
pc.a->add_child(pc.c);