.autotest

git-svn-id: svn://ultimatepp.org/upp/trunk@11138 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2017-06-05 15:44:50 +00:00
parent c9ae8f88e9
commit d6993e1e19
2 changed files with 96 additions and 0 deletions

87
autotest/Utf/Utf.cpp Normal file
View file

@ -0,0 +1,87 @@
#include <Core/Core.h>
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<dword> 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<dword> 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<dword> 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");
}

9
autotest/Utf/Utf.upp Normal file
View file

@ -0,0 +1,9 @@
uses
Core;
file
Utf.cpp;
mainconfig
"" = "";