void testStrToIntConversion();
void testStringReplace();
void testStringAllowed();
+ void testAsciiPrintableHelper();
void testUTF8();
+ void testRemoveEscapes();
void testWrapRows();
void testIsNumber();
void testIsPowerOfTwo();
TEST(testStrToIntConversion);
TEST(testStringReplace);
TEST(testStringAllowed);
+ TEST(testAsciiPrintableHelper);
TEST(testUTF8);
+ TEST(testRemoveEscapes);
TEST(testWrapRows);
TEST(testIsNumber);
TEST(testIsPowerOfTwo);
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("")) == "");
== "the shovel dug a crumbly node!");
}
+void TestUtilities::testRemoveEscapes()
+{
+ UASSERT(unescape_enriched<wchar_t>(
+ L"abc\x1bXdef") == L"abcdef");
+ UASSERT(unescape_enriched<wchar_t>(
+ L"abc\x1b(escaped)def") == L"abcdef");
+ UASSERT(unescape_enriched<wchar_t>(
+ L"abc\x1b((escaped with parenthesis\\))def") == L"abcdef");
+ UASSERT(unescape_enriched<wchar_t>(
+ L"abc\x1b(incomplete") == L"abc");
+ UASSERT(unescape_enriched<wchar_t>(
+ L"escape at the end\x1b") == L"escape at the end");
+ // Nested escapes not supported
+ UASSERT(unescape_enriched<wchar_t>(
+ L"abc\x1b(outer \x1b(inner escape)escape)def") == L"abcescape)def");
+}
+
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>");
+ }
}
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()