Commit 45169132 authored by Lev Walkin's avatar Lev Walkin

more structured testing

parent a2f95b0e
...@@ -7,11 +7,6 @@ ...@@ -7,11 +7,6 @@
#include <constraints.c> #include <constraints.c>
#include <sys/time.h> #include <sys/time.h>
static int errlog(const void *buf, size_t size, void *key) {
fwrite(buf, 1, size, stdout);
return 0;
}
static void static void
check(int expect_length, char *buf, int buflen) { check(int expect_length, char *buf, int buflen) {
UTF8String_t st; UTF8String_t st;
...@@ -25,7 +20,7 @@ check(int expect_length, char *buf, int buflen) { ...@@ -25,7 +20,7 @@ check(int expect_length, char *buf, int buflen) {
for(ret = 0; ret < buflen; ret++) for(ret = 0; ret < buflen; ret++)
printf("%c", buf[ret]); printf("%c", buf[ret]);
ret = UTF8String_length(&st, 0, errlog, 0); ret = UTF8String_length(&st);
printf("]: size=%d, expect=%d, got=%d\n", printf("]: size=%d, expect=%d, got=%d\n",
buflen, expect_length, ret); buflen, expect_length, ret);
assert(ret == expect_length); assert(ret == expect_length);
...@@ -49,14 +44,14 @@ check_speed() { ...@@ -49,14 +44,14 @@ check_speed() {
st.buf = long_test; st.buf = long_test;
st.size = sizeof(long_test) - 1; st.size = sizeof(long_test) - 1;
ret = UTF8String_length(&st, 0, errlog, 0); ret = UTF8String_length(&st);
assert(ret == 40); assert(ret == 40);
printf("Now wait a bit...\n"); printf("Now wait a bit...\n");
gettimeofday(&tv, 0); gettimeofday(&tv, 0);
start = tv.tv_sec + tv.tv_usec / 1000000.0; start = tv.tv_sec + tv.tv_usec / 1000000.0;
for(i = 0; i < cycles; i++) { for(i = 0; i < cycles; i++) {
ret += UTF8String_length(&st, 0, errlog, 0); ret += UTF8String_length(&st);
} }
gettimeofday(&tv, 0); gettimeofday(&tv, 0);
stop = tv.tv_sec + tv.tv_usec / 1000000.0; stop = tv.tv_sec + tv.tv_usec / 1000000.0;
...@@ -71,16 +66,23 @@ main() { ...@@ -71,16 +66,23 @@ main() {
check(0, "", 0); check(0, "", 0);
check(1, "\0", 1); check(1, "\0", 1);
check(-1, "\377", 1);
check(1, "a", 1); check(1, "a", 1);
check(2, "ab", 2); check(2, "ab", 2);
check(3, "abc", 3); check(3, "abc", 3);
assert(sizeof("a\303\237cd") == 6); assert(sizeof("a\303\237cd") == 6);
check(4, "a\303\237cd", 5); check(4, "a\303\237cd", 5);
check(-1, "a\303", 2); check(3, "a\370\211\200\201\257c", 7);
check(-1, "a\370\200\200\200c", 5); check(3, "\320\273\320\265\320\262", 6);
check(3, "a\370\201\200\201\257c", 7);
/* not yet check(-1, "a\370\200\200\200\257c", 7); */ check(-1, "a\303", 2); /* Truncated */
check(-2, "\377", 1); /* Invalid UTF-8 sequence start */
check(-2, "\200", 1);
check(-2, "\320\273\265\320\262", 5);
check(-3, "\320c", 2); /* Not continuation */
check(-3, "a\370\200\200\200c", 6);
check(-4, "a\370\200\200\200\257c", 7);
check(-4, "\320\273\320\265\340\200\262", 7);
check(-5, 0, 0);
check_speed(); check_speed();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment