diff options
author | sfan5 <sfan5@live.de> | 2021-12-05 14:40:30 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-05 14:40:30 +0100 |
commit | ff934d538c00518476c31f5df6ebc4be5ca79591 (patch) | |
tree | f4e261ef192fe4410fc1f5e56e04d8c7645d92dc /src/unittest | |
parent | 7a043b3ebbbf250890f39a9afecebba1cc9826a6 (diff) | |
download | minetest-ff934d538c00518476c31f5df6ebc4be5ca79591.tar.gz minetest-ff934d538c00518476c31f5df6ebc4be5ca79591.tar.bz2 minetest-ff934d538c00518476c31f5df6ebc4be5ca79591.zip |
Fix various code & correctness issues (#11815)
Diffstat (limited to 'src/unittest')
-rw-r--r-- | src/unittest/test_gettext.cpp | 36 | ||||
-rw-r--r-- | src/unittest/test_utilities.cpp | 8 |
2 files changed, 20 insertions, 24 deletions
diff --git a/src/unittest/test_gettext.cpp b/src/unittest/test_gettext.cpp index 98f73ec62..338a416d7 100644 --- a/src/unittest/test_gettext.cpp +++ b/src/unittest/test_gettext.cpp @@ -7,13 +7,12 @@ class TestGettext : public TestBase public: TestGettext() { TestManager::registerTestModule(this); - } + } const char *getName() { return "TestGettext"; } void runTests(IGameDef *gamedef); - void testSnfmtgettext(); void testFmtgettext(); }; @@ -24,24 +23,21 @@ void TestGettext::runTests(IGameDef *gamedef) TEST(testFmtgettext); } +// Make sure updatepo.sh does not pick up the strings +#define dummyname fmtgettext + void TestGettext::testFmtgettext() { - std::string buf = fmtgettext("Viewing range changed to %d", 12); - UASSERTEQ(std::string, buf, "Viewing range changed to 12"); - buf = fmtgettext( - "You are about to join this server with the name \"%s\" for the " - "first time.\n" - "If you proceed, a new account using your credentials will be " - "created on this server.\n" - "Please retype your password and click 'Register and Join' to " - "confirm account creation, or click 'Cancel' to abort." - , "A"); - UASSERTEQ(std::string, buf, - "You are about to join this server with the name \"A\" for the " - "first time.\n" - "If you proceed, a new account using your credentials will be " - "created on this server.\n" - "Please retype your password and click 'Register and Join' to " - "confirm account creation, or click 'Cancel' to abort." - ); + std::string buf = dummyname("sample text %d", 12); + UASSERTEQ(std::string, buf, "sample text 12"); + + std::string src, expect; + src = "You are about to join this server with the name \"%s\".\n"; + expect = "You are about to join this server with the name \"foo\".\n"; + for (int i = 0; i < 20; i++) { + src.append("loooong text"); + expect.append("loooong text"); + } + buf = dummyname(src.c_str(), "foo"); + UASSERTEQ(const std::string &, buf, expect); } diff --git a/src/unittest/test_utilities.cpp b/src/unittest/test_utilities.cpp index 039110d54..743fe4462 100644 --- a/src/unittest/test_utilities.cpp +++ b/src/unittest/test_utilities.cpp @@ -392,9 +392,9 @@ void TestUtilities::testIsPowerOfTwo() UASSERT(is_power_of_two(2) == true); UASSERT(is_power_of_two(3) == false); for (int exponent = 2; exponent <= 31; ++exponent) { - UASSERT(is_power_of_two((1 << exponent) - 1) == false); - UASSERT(is_power_of_two((1 << exponent)) == true); - UASSERT(is_power_of_two((1 << exponent) + 1) == false); + UASSERT(is_power_of_two((1U << exponent) - 1) == false); + UASSERT(is_power_of_two((1U << exponent)) == true); + UASSERT(is_power_of_two((1U << exponent) + 1) == false); } UASSERT(is_power_of_two(U32_MAX) == false); } @@ -629,4 +629,4 @@ void TestUtilities::testBase64() UASSERT(base64_is_valid("AAA=A") == false); UASSERT(base64_is_valid("AAAA=A") == false); UASSERT(base64_is_valid("AAAAA=A") == false); -}
\ No newline at end of file +} |