diff options
| author | peter <peter@pmikkelsen.com> | 2026-08-21 10:55:30 +0000 |
|---|---|---|
| committer | peter <peter@pmikkelsen.com> | 2026-08-21 10:55:30 +0000 |
| commit | 8af7b7fc0a8dbe3502a7cd43c6a10fdcc6013677 (patch) | |
| tree | 68f2456a9f31044ca088a26a2c3306c98e6cce2b /tests | |
| parent | 86feda786f115cb4468957f00b8968b986ed7c54 (diff) | |
Start working on the scanner.
For now, all that is implemented is some functionality which imports UTF-8 into the
memory managed by aplwc, after checking that the data is in fact valid UTF-8.
FossilOrigin-Name: c861e88777d8180cb7b37c11fc7016a900f9d5821a7e3c8e8aab54118d2fca94
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/aplwc_errstr.c | 2 | ||||
| -rw-r--r-- | tests/aplwc_utf8.c | 67 |
2 files changed, 68 insertions, 1 deletions
diff --git a/tests/aplwc_errstr.c b/tests/aplwc_errstr.c index 0efb777..8014c1e 100644 --- a/tests/aplwc_errstr.c +++ b/tests/aplwc_errstr.c @@ -35,7 +35,7 @@ main(void) if(err == NULL) return 1; - for(ret = 0; ret < APLWC_RC_LAST; ret++){ + for(ret = 0; ret <= APLWC_RC_LAST; ret++){ err = aplwc_errstr_rc(ret); if(err == NULL) return 1; diff --git a/tests/aplwc_utf8.c b/tests/aplwc_utf8.c new file mode 100644 index 0000000..b97b978 --- /dev/null +++ b/tests/aplwc_utf8.c @@ -0,0 +1,67 @@ +#include <aplwc.h> + +uint8_t bad1[] = {0xff,0}; +uint8_t bad2[] = {0x80,0}; +uint8_t bad3[] = {0xc0,0x80,0}; +uint8_t bad4[] = {0xc0,0x40,0}; +uint8_t bad5[] = {0xe0,0x80,0x80,0}; +uint8_t bad6[] = {0xc0,0}; +uint8_t bad7[] = {0xF0,0x80,0x80,0x80,0}; + +uint8_t good1[] = {0x61,0x70,0x6c,0x77,0x63,0}; +uint8_t good2[] = {0x41,0xe2,0x89,0xa2,0xce,0x91,0x2e,0}; +uint8_t good3[] = {0xed,0x95,0x9c,0xea,0xb5,0xad,0xec,0x96,0xb4,0}; +uint8_t good4[] = {0xe6,0x97,0xa5,0xe6,0x9c,0xac,0xe8,0xaa,0x9e,0}; +uint8_t good5[] = {0xef,0xbb,0xbf,0xf0,0xa3,0x8e,0xb4,0}; + +int +main(void) +{ + uint8_t data[APLWC_MIN_MEM+64000]; + struct aplwc *aplwc; + struct aplwc_line *line; + enum aplwc_rc ret; + size_t i; + + uint8_t *bad_tests[] = { + bad1, + bad2, + bad3, + bad4, + bad5, + bad6, + bad7 + }; + + uint8_t *good_tests[] = { + good1, + good2, + good3, + good4, + good5 + }; + + ret = aplwc_new(&aplwc, data, sizeof(data)); + if(ret) + return 1; + + for(i = 0; i < (sizeof(bad_tests)/sizeof(*bad_tests)); i++){ + line = aplwc_read(aplwc, (char *)bad_tests[i]); + if(line != NULL) + return 1; + if(aplwc_last_error(aplwc) != APLWC_INVALID_UTF8) + return 1; + aplwc_free_line(line); + } + + for(i = 0; i < (sizeof(good_tests)/sizeof(*good_tests)); i++){ + line = aplwc_read(aplwc, (char *)good_tests[i]); + if((line == NULL) && (aplwc_last_error(aplwc) == APLWC_INVALID_UTF8)) + return 1; + aplwc_free_line(line); + } + + aplwc_destroy(aplwc); + + return 0; +} |