|
37 | 37 |
|
38 | 38 | namespace TestTranslationServer { |
39 | 39 | TEST_CASE("[TranslationServer] Translation operations") { |
40 | | - Ref<Translation> t = memnew(Translation); |
41 | | - t->set_locale("uk"); |
42 | | - t->add_message("Good Morning", String::utf8("Добрий ранок")); |
| 40 | + Ref<Translation> t1 = memnew(Translation); |
| 41 | + t1->set_locale("uk"); |
| 42 | + t1->add_message("Good Morning", String(U"Добрий ранок")); |
| 43 | + |
| 44 | + Ref<Translation> t2 = memnew(Translation); |
| 45 | + t2->set_locale("uk"); |
| 46 | + t2->add_message("Hello Godot", String(U"你好戈多")); |
43 | 47 |
|
44 | 48 | TranslationServer *ts = TranslationServer::get_singleton(); |
45 | 49 |
|
| 50 | + // Adds translation for UK locale for the first time. |
46 | 51 | int l_count_before = ts->get_loaded_locales().size(); |
47 | | - ts->add_translation(t); |
| 52 | + ts->add_translation(t1); |
48 | 53 | int l_count_after = ts->get_loaded_locales().size(); |
49 | | - // Newly created Translation object should be added to the list, so the counter should increase, too. |
50 | 54 | CHECK(l_count_after > l_count_before); |
51 | 55 |
|
52 | | - Ref<Translation> trans = ts->get_translation_object("uk"); |
53 | | - CHECK(trans.is_valid()); |
| 56 | + // Adds translation for UK locale again. |
| 57 | + ts->add_translation(t2); |
| 58 | + CHECK_EQ(ts->get_loaded_locales().size(), l_count_after); |
| 59 | + |
| 60 | + // Removing that translation. |
| 61 | + ts->remove_translation(t2); |
| 62 | + CHECK_EQ(ts->get_loaded_locales().size(), l_count_after); |
| 63 | + |
| 64 | + CHECK(ts->get_translation_object("uk").is_valid()); |
54 | 65 |
|
55 | 66 | ts->set_locale("uk"); |
56 | 67 | CHECK(ts->translate("Good Morning") == String::utf8("Добрий ранок")); |
57 | 68 |
|
58 | | - ts->remove_translation(t); |
59 | | - trans = ts->get_translation_object("uk"); |
60 | | - CHECK(trans.is_null()); |
| 69 | + ts->remove_translation(t1); |
| 70 | + CHECK(ts->get_translation_object("uk").is_null()); |
61 | 71 | // If no suitable Translation object has been found - the original message should be returned. |
62 | 72 | CHECK(ts->translate("Good Morning") == "Good Morning"); |
63 | 73 | } |
|
0 commit comments