21 #include <unicode/uchar.h>
39 if (
lower != iculower || title != icutitle ||
upper != icuupper)
41 printf(
"case_test: FAILURE for codepoint 0x%06x\n", code);
42 printf(
"case_test: Postgres lower/title/upper: 0x%06x/0x%06x/0x%06x\n",
44 printf(
"case_test: ICU lower/title/upper: 0x%06x/0x%06x/0x%06x\n",
45 iculower, icutitle, icuupper);
58 int skipped_mismatch = 0;
60 for (
pg_wchar code = 0; code <= 0x10ffff; code++)
66 uint8_t icu_category = u_charType(code);
74 icu_test_simple(code);
79 if (skipped_mismatch > 0)
80 printf(
"case_test: skipped %d codepoints unassigned in ICU due to Unicode version mismatch\n",
83 printf(
"case_test: ICU simple mapping test: %d codepoints successful\n",
91 size_t src1len = strlen(test_string);
93 size_t dst1len = strlen(expected);
94 size_t dst2len = strlen(expected) + 1;
95 char *src1 =
malloc(src1len);
96 char *dst1 =
malloc(dst1len);
97 char *src2 = strdup(test_string);
98 char *dst2 =
malloc(dst2len);
101 memcpy(src1, test_string, src1len);
104 memset(dst1, 0x7F, dst1len);
106 if (needed != strlen(expected))
108 printf(
"case_test: convert_case test1 FAILURE: needed %zu\n", needed);
111 if (memcmp(dst1, expected, dst1len) != 0)
113 printf(
"case_test: convert_case test1 FAILURE: test: '%s' result: '%.*s' expected: '%s'\n",
114 test_string, (
int) dst1len, dst1, expected);
119 memset(dst2, 0x7F, dst2len);
121 if (needed != strlen(expected))
123 printf(
"case_test: convert_case test2 FAILURE: needed %zu\n", needed);
126 if (strcmp(dst2, expected) != 0)
128 printf(
"case_test: convert_case test2 FAILURE: test: '%s' result: '%s' expected: '%s'\n",
129 test_string, dst2, expected);
134 memset(dst1, 0x7F, dst1len);
136 if (needed != strlen(expected))
138 printf(
"case_test: convert_case test3 FAILURE: needed %zu\n", needed);
141 if (memcmp(dst1, expected, dst1len) != 0)
143 printf(
"case_test: convert_case test3 FAILURE: test: '%s' result: '%.*s' expected: '%s'\n",
144 test_string, (
int) dst1len, dst1, expected);
149 memset(dst2, 0x7F, dst2len);
151 if (needed != strlen(expected))
153 printf(
"case_test: convert_case test4 FAILURE: needed %zu\n", needed);
156 if (strcmp(dst2, expected) != 0)
158 printf(
"case_test: convert_case test4 FAILURE: test: '%s' result: '%s' expected: '%s'\n",
159 test_string, dst2, expected);
179 printf(
"case_test: convert_case: success\n");
187 printf(
"case_test: ICU Unicode version:\t\t%s\n", U_UNICODE_VERSION);
190 printf(
"case_test: ICU not available; skipping\n");
static void test_convert_case()
int main(int argc, char **argv)
static void test_strlower(const char *test_string, const char *expected)
Datum lower(PG_FUNCTION_ARGS)
Datum upper(PG_FUNCTION_ARGS)
pg_wchar unicode_uppercase_simple(pg_wchar code)
size_t unicode_strlower(char *dst, size_t dstsize, const char *src, ssize_t srclen)
pg_wchar unicode_titlecase_simple(pg_wchar code)
pg_wchar unicode_lowercase_simple(pg_wchar code)
pg_unicode_category unicode_category(pg_wchar code)
#define PG_UNICODE_VERSION