summaryrefslogtreecommitdiffstats
path: root/src/utf8proc/test/custom.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-21 11:54:28 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-21 11:54:28 +0000
commite6918187568dbd01842d8d1d2c808ce16a894239 (patch)
tree64f88b554b444a49f656b6c656111a145cbbaa28 /src/utf8proc/test/custom.c
parentInitial commit. (diff)
downloadceph-upstream/18.2.2.tar.xz
ceph-upstream/18.2.2.zip
Adding upstream version 18.2.2.upstream/18.2.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/utf8proc/test/custom.c')
-rw-r--r--src/utf8proc/test/custom.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/utf8proc/test/custom.c b/src/utf8proc/test/custom.c
new file mode 100644
index 000000000..fe4239d91
--- /dev/null
+++ b/src/utf8proc/test/custom.c
@@ -0,0 +1,28 @@
+#include "tests.h"
+
+static int thunk_test = 1;
+
+static utf8proc_int32_t custom(utf8proc_int32_t codepoint, void *thunk)
+{
+ check(((int *) thunk) == &thunk_test, "unexpected thunk passed");
+ if (codepoint == 'a')
+ return 'b';
+ if (codepoint == 'S')
+ return 0x00df; /* ß */
+ return codepoint;
+}
+
+int main(void)
+{
+ utf8proc_uint8_t input[] = {0x41,0x61,0x53,0x62,0xef,0xbd,0x81,0x00}; /* "AaSb\uff41" */
+ utf8proc_uint8_t correct[] = {0x61,0x62,0x73,0x73,0x62,0x61,0x00}; /* "abssba" */
+ utf8proc_uint8_t *output;
+ utf8proc_map_custom(input, 0, &output, UTF8PROC_CASEFOLD | UTF8PROC_COMPOSE | UTF8PROC_COMPAT | UTF8PROC_NULLTERM,
+ custom, &thunk_test);
+ printf("mapped \"%s\" -> \"%s\"\n", (char*)input, (char*)output);
+ check(strlen((char*) output) == 6, "incorrect output length");
+ check(!memcmp(correct, output, 7), "incorrect output data");
+ free(output);
+ printf("map_custom tests SUCCEEDED.\n");
+ return 0;
+}