PostgreSQL Source Code git master
norm_test.c
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 * norm_test.c
3 * Program to test Unicode normalization functions.
4 *
5 * Portions Copyright (c) 2017-2025, PostgreSQL Global Development Group
6 *
7 * IDENTIFICATION
8 * src/common/unicode/norm_test.c
9 *
10 *-------------------------------------------------------------------------
11 */
12#include "postgres_fe.h"
13
14#include <stdio.h>
15#include <stdlib.h>
16#include <string.h>
17
18#include "common/unicode_norm.h"
19
20#include "norm_test_table.h"
21
22static char *
24{
25#define BUF_DIGITS 50
26 static char buf[BUF_DIGITS * 11 + 1];
27 int i;
28 char *p;
29
30 i = 0;
31 p = buf;
32 while (*s && i < BUF_DIGITS)
33 {
34 p += sprintf(p, "U+%04X ", *s);
35 i++;
36 s++;
37 }
38 *p = '\0';
39
40 return buf;
41}
42
43static int
45{
46 for (;;)
47 {
48 if (*s1 < *s2)
49 return -1;
50 if (*s1 > *s2)
51 return 1;
52 if (*s1 == 0)
53 return 0;
54 s1++;
55 s2++;
56 }
57}
58
59int
60main(int argc, char **argv)
61{
62 const pg_unicode_test *test;
63
64 for (test = UnicodeNormalizationTests; test->input[0] != 0; test++)
65 {
66 for (int form = 0; form < 4; form++)
67 {
68 pg_wchar *result;
69
70 result = unicode_normalize(form, test->input);
71
72 if (pg_wcscmp(test->output[form], result) != 0)
73 {
74 printf("FAILURE (NormalizationTest.txt line %d form %d):\n", test->linenum, form);
75 printf("input: %s\n", print_wchar_str(test->input));
76 printf("expected: %s\n", print_wchar_str(test->output[form]));
77 printf("got: %s\n", print_wchar_str(result));
78 printf("\n");
79 exit(1);
80 }
81 }
82 }
83
84 printf("norm_test: All tests successful!\n");
85 exit(0);
86}
int i
Definition: isn.c:72
exit(1)
unsigned int pg_wchar
Definition: mbprint.c:31
static char * print_wchar_str(const pg_wchar *s)
Definition: norm_test.c:23
#define BUF_DIGITS
static int pg_wcscmp(const pg_wchar *s1, const pg_wchar *s2)
Definition: norm_test.c:44
int main(int argc, char **argv)
Definition: norm_test.c:60
static char * buf
Definition: pg_test_fsync.c:72
#define sprintf
Definition: port.h:240
#define printf(...)
Definition: port.h:244
static void test(void)
char * s1
char * s2
pg_wchar * unicode_normalize(UnicodeNormalizationForm form, const pg_wchar *input)
Definition: unicode_norm.c:402