diff --git a/autotest/Utf/Utf.cpp b/autotest/Utf/Utf.cpp new file mode 100644 index 000000000..1ed1b30e4 --- /dev/null +++ b/autotest/Utf/Utf.cpp @@ -0,0 +1,87 @@ +#include + +using namespace Upp; + +CONSOLE_APP_MAIN +{ + StdLogSetup(LOG_COUT|LOG_FILE); + + for(dword code = 0; code <= 0x10ffff; code++) { + if(code < 0xee00 || code > 0xeeff) { + String s = ToUtf8(&code, 1); + Vector t = ToUtf32(s); + ASSERT(t[0] == code); + ASSERT(Utf32Len(s) == 1); + + WString ws = ToUtf16(&code, 1); + t = ToUtf32(ws); + ASSERT(t[0] == code); + ASSERT(Utf32Len(ws) == 1); + + ws = ToUtf16(s); + t = ToUtf32(ws); + ASSERT(t[0] == code); + ASSERT(Utf32Len(ws) == 1); + + s = ToUtf8(ws); + t = ToUtf32(s); + ASSERT(t[0] == code); + ASSERT(Utf32Len(ws) == 1); + } + } + + LOG("Single code test passed"); + + SeedRandom(0); + for(int i = 0; i < 10000; i++) { + int n = Random(1000); + Vector text; + while(text.GetCount() < n) { + int code = Random(0x110000); + if(!(code >= 0xee00 && code < 0xeeff || code >= 0xD800 && code < 0xe000)) + text.Add(code); + } + + String s = ToUtf8(text); + Vector t = ToUtf32(s); + ASSERT(t == text); + ASSERT(Utf32Len(s) == n); + + WString ws = ToUtf16(text); + t = ToUtf32(ws); + if(t != text) { + DUMP(text); + DUMP(t); + DUMP(ws); + } + ASSERT(t == text); + ASSERT(Utf32Len(ws) == n); + + ws = ToUtf16(s); + t = ToUtf32(ws); + ASSERT(t == text); + ASSERT(Utf32Len(ws) == n); + + s = ToUtf8(ws); + t = ToUtf32(s); + ASSERT(t == text); + ASSERT(Utf32Len(ws) == n); + } + + LOG("Text test passed"); + + SeedRandom(0); + for(int i = 0; i < 30000; i++) { + int n = Random(1000); + String text; + while(text.GetCount() < n) + text.Cat(Random(256)); + + ASSERT(ToUtf8(ToUtf32(text)) == text); + ASSERT(ToUtf8(ToUtf16(text)) == text); + } + + LOG("Error escape test passed"); + + LOG("========== OK"); +} diff --git a/autotest/Utf/Utf.upp b/autotest/Utf/Utf.upp new file mode 100644 index 000000000..c9f3fc00c --- /dev/null +++ b/autotest/Utf/Utf.upp @@ -0,0 +1,9 @@ +uses + Core; + +file + Utf.cpp; + +mainconfig + "" = ""; +