Add server side ncurses terminal
[oweals/minetest.git] / src / unittest / test_utilities.cpp
index 9678a81eb18acedb0b7c5b2b8150b57d8b022f3d..1785997deb79fbd9390e8ae1026a28f24a5ac42d 100644 (file)
@@ -43,6 +43,7 @@ public:
        void testStrToIntConversion();
        void testStringReplace();
        void testStringAllowed();
+       void testAsciiPrintableHelper();
        void testUTF8();
        void testWrapRows();
        void testIsNumber();
@@ -68,6 +69,7 @@ void TestUtilities::runTests(IGameDef *gamedef)
        TEST(testStrToIntConversion);
        TEST(testStringReplace);
        TEST(testStringAllowed);
+       TEST(testAsciiPrintableHelper);
        TEST(testUTF8);
        TEST(testWrapRows);
        TEST(testIsNumber);
@@ -232,6 +234,18 @@ void TestUtilities::testStringAllowed()
        UASSERT(string_allowed_blacklist("hello123", "123") == false);
 }
 
+void TestUtilities::testAsciiPrintableHelper()
+{
+       UASSERT(IS_ASCII_PRINTABLE_CHAR('e') == true);
+       UASSERT(IS_ASCII_PRINTABLE_CHAR('\0') == false);
+
+       // Ensures that there is no cutting off going on...
+       // If there were, 331 would be cut to 75 in this example
+       // and 73 is a valid ASCII char.
+       int ch = 331;
+       UASSERT(IS_ASCII_PRINTABLE_CHAR(ch) == false);
+}
+
 void TestUtilities::testUTF8()
 {
        UASSERT(wide_to_utf8(utf8_to_wide("")) == "");
@@ -243,13 +257,23 @@ void TestUtilities::testWrapRows()
 {
        UASSERT(wrap_rows("12345678",4) == "1234\n5678");
        // test that wrap_rows doesn't wrap inside multibyte sequences
-       const unsigned char s[] = {
-               0x2f, 0x68, 0x6f, 0x6d, 0x65, 0x2f, 0x72, 0x61, 0x70, 0x74, 0x6f,
-               0x72, 0x2f, 0xd1, 0x82, 0xd0, 0xb5, 0xd1, 0x81, 0xd1, 0x82, 0x2f,
-               0x6d, 0x69, 0x6e, 0x65, 0x74, 0x65, 0x73, 0x74, 0x2f, 0x62, 0x69,
-               0x6e, 0x2f, 0x2e, 0x2e, 0};
-       std::string str((char *)s);
-       UASSERT(utf8_to_wide(wrap_rows(str, 20)) != L"<invalid UTF-8 string>");
+       {
+               const unsigned char s[] = {
+                       0x2f, 0x68, 0x6f, 0x6d, 0x65, 0x2f, 0x72, 0x61, 0x70, 0x74, 0x6f,
+                       0x72, 0x2f, 0xd1, 0x82, 0xd0, 0xb5, 0xd1, 0x81, 0xd1, 0x82, 0x2f,
+                       0x6d, 0x69, 0x6e, 0x65, 0x74, 0x65, 0x73, 0x74, 0x2f, 0x62, 0x69,
+                       0x6e, 0x2f, 0x2e, 0x2e, 0};
+               std::string str((char *)s);
+               UASSERT(utf8_to_wide(wrap_rows(str, 20)) != L"<invalid UTF-8 string>");
+       };
+       {
+               const unsigned char s[] = {
+                       0x74, 0x65, 0x73, 0x74, 0x20, 0xd1, 0x82, 0xd0, 0xb5, 0xd1, 0x81,
+                       0xd1, 0x82, 0x20, 0xd1, 0x82, 0xd0, 0xb5, 0xd1, 0x81, 0xd1, 0x82,
+                       0x20, 0xd1, 0x82, 0xd0, 0xb5, 0xd1, 0x81, 0xd1, 0x82, 0};
+               std::string str((char *)s);
+               UASSERT(utf8_to_wide(wrap_rows(str, 8)) != L"<invalid UTF-8 string>");
+       }
 }
 
 
@@ -272,7 +296,7 @@ void TestUtilities::testIsPowerOfTwo()
                UASSERT(is_power_of_two((1 << exponent)) == true);
                UASSERT(is_power_of_two((1 << exponent) + 1) == false);
        }
-       UASSERT(is_power_of_two((u32)-1) == false);
+       UASSERT(is_power_of_two(U32_MAX) == false);
 }
 
 void TestUtilities::testMyround()