$(o)/lib/ipaccess-test: $(o)/lib/ipaccess-test.o $(LIBUCW)
TESTS+=$(addprefix $(o)/lib/,regex.test unicode.test hash-test.test mempool.test stkstring.test \
- slists.test kmp-test.test bbuf.test getopt.test fastbuf.test eltpool.test)
+ slists.test kmp-test.test bbuf.test getopt.test fastbuf.test ff-unicode.test eltpool.test)
$(o)/lib/regex.test: $(o)/lib/regex-t
$(o)/lib/unicode.test: $(o)/lib/unicode-t
$(o)/lib/bbuf.test: $(o)/lib/bbuf-t
$(o)/lib/getopt.test: $(o)/lib/getopt-t
$(o)/lib/fastbuf.test: $(o)/lib/fb-file-t $(o)/lib/fb-grow-t $(o)/lib/fb-pool-t
+$(o)/lib/ff-unicode.test: $(o)/lib/ff-unicode-t
$(o)/lib/eltpool.test: $(o)/lib/eltpool-t
ifdef CONFIG_UCW_THREADS
else
ASSERT(0);
}
+
+#ifdef TEST
+
+#include <stdlib.h>
+#include <stdio.h>
+
+int main(int argc, char **argv)
+{
+#define FUNCS \
+ F(BGET_UTF8) F(BGET_UTF8_32) F(BGET_UTF16_BE) F(BGET_UTF16_LE) \
+ F(BPUT_UTF8) F(BPUT_UTF8_32) F(BPUT_UTF16_BE) F(BPUT_UTF16_LE)
+
+ enum {
+#define F(x) FUNC_##x,
+ FUNCS
+#undef F
+ };
+ char *names[] = {
+#define F(x) [FUNC_##x] = #x,
+ FUNCS
+#undef F
+ };
+
+ uns func = ~0U;
+ if (argc > 1)
+ for (uns i = 0; i < ARRAY_SIZE(names); i++)
+ if (!strcasecmp(names[i], argv[1]))
+ func = i;
+ if (!~func)
+ {
+ fprintf(stderr, "Invalid usage!\n");
+ return 1;
+ }
+
+ struct fastbuf *b = fbgrow_create(8);
+ if (func < FUNC_BPUT_UTF8)
+ {
+ uns u;
+ while (scanf("%x", &u) == 1)
+ bputc(b, u);
+ fbgrow_rewind(b);
+ while (bpeekc(b) >= 0)
+ {
+ if (btell(b))
+ putchar(' ');
+ switch (func)
+ {
+ case FUNC_BGET_UTF8:
+ u = bget_utf8_slow(b, UNI_REPLACEMENT);
+ break;
+ case FUNC_BGET_UTF8_32:
+ u = bget_utf8_32_slow(b, UNI_REPLACEMENT);
+ break;
+ case FUNC_BGET_UTF16_BE:
+ u = bget_utf16_be_slow(b, UNI_REPLACEMENT);
+ break;
+ case FUNC_BGET_UTF16_LE:
+ u = bget_utf16_le_slow(b, UNI_REPLACEMENT);
+ break;
+ default:
+ ASSERT(0);
+ }
+ printf("%04x", u);
+ }
+ putchar('\n');
+ }
+ else
+ {
+ uns u, i = 0;
+ while (scanf("%x", &u) == 1)
+ {
+ switch (func)
+ {
+ case FUNC_BPUT_UTF8:
+ bput_utf8_slow(b, u);
+ break;
+ case FUNC_BPUT_UTF8_32:
+ bput_utf8_32_slow(b, u);
+ break;
+ case FUNC_BPUT_UTF16_BE:
+ bput_utf16_be_slow(b, u);
+ break;
+ case FUNC_BPUT_UTF16_LE:
+ bput_utf16_le_slow(b, u);
+ break;
+ default:
+ ASSERT(0);
+ }
+ fbgrow_rewind(b);
+ u = 0;
+ while (bpeekc(b) >= 0)
+ {
+ if (i++)
+ putchar(' ');
+ printf("%02x", bgetc(b));
+ }
+ fbgrow_reset(b);
+ }
+ putchar('\n');
+ }
+ bclose(b);
+
+ return 0;
+}
+
+#endif
--- /dev/null
+# Tests for the Unicode module
+
+Name: bput_utf8
+Run: ../obj/lib/ff-unicode-t bput_utf8
+In: 0041 0048 004f 004a
+Out: 41 48 4f 4a
+
+Name: bget_utf8_32
+Run: ../obj/lib/ff-unicode-t bget_utf8_32
+In: fe 83 81
+Out: fffc
+
+Name: bput_utf16_be
+Run: ../obj/lib/ff-unicode-t bput_utf16_be
+In: 0041 004a 2a5f feff 0000 10ffff ffff 10000
+Out: 00 41 00 4a 2a 5f fe ff 00 00 db ff df ff ff ff d8 00 dc 00
+
+Name: bput_utf16_le
+Run: ../obj/lib/ff-unicode-t bput_utf16_le
+In: 0041 004a 2a5f feff 0000 10ffff ffff 10000
+Out: 41 00 4a 00 5f 2a ff fe 00 00 ff db ff df ff ff 00 d8 00 dc
+
+Name: bget_utf16_be (1)
+Run: ../obj/lib/ff-unicode-t bget_utf16_be
+In: 00 41 00 4a 2a 5f fe ff 00 00 db ff df ff ff ff d8 00 dc 00
+Out: 0041 004a 2a5f feff 0000 10ffff ffff 10000
+
+Name: bget_utf16_be (2)
+Run: ../obj/lib/ff-unicode-t bget_utf16_be
+In: dc 1a 2a 5f d8 01 d8 01 2a 5f d8 01
+Out: fffc 2a5f fffc 2a5f fffc
+
+Name: bget_utf16_le (1)
+Run: ../obj/lib/ff-unicode-t bget_utf16_le
+In: 41 00 4a 00 5f 2a ff fe 00 00 ff db ff df ff ff 00 d8 00 dc
+Out: 0041 004a 2a5f feff 0000 10ffff ffff 10000
+
+Name: bget_utf16_le (2)
+Run: ../obj/lib/ff-unicode-t bget_utf16_le
+In: 1a dc 5f 2a 01 d8 01 d8 5f 2a 01 d8
+Out: fffc 2a5f fffc 2a5f fffc