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-2019, 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 
22 static char *
24 {
25 #define BUF_DIGITS 50
26  static char buf[BUF_DIGITS * 2 + 1];
27  int i;
28 
29  i = 0;
30  while (*s && i < BUF_DIGITS)
31  {
32  snprintf(&buf[i * 2], 3, "%04X", *s);
33  i++;
34  s++;
35  }
36  buf[i * 2] = '\0';
37  return buf;
38 }
39 
40 static int
41 pg_wcscmp(const pg_wchar *s1, const pg_wchar *s2)
42 {
43  for (;;)
44  {
45  if (*s1 < *s2)
46  return -1;
47  if (*s1 > *s2)
48  return 1;
49  if (*s1 == 0)
50  return 0;
51  s1++;
52  s2++;
53  }
54 }
55 
56 int
57 main(int argc, char **argv)
58 {
59  const pg_unicode_test *test;
60 
61  for (test = UnicodeNormalizationTests; test->input[0] != 0; test++)
62  {
63  pg_wchar *result;
64 
65  result = unicode_normalize_kc(test->input);
66 
67  if (pg_wcscmp(test->output, result) != 0)
68  {
69  printf("FAILURE (NormalizationTest.txt line %d):\n", test->linenum);
70  printf("input:\t%s\n", print_wchar_str(test->input));
71  printf("expected:\t%s\n", print_wchar_str(test->output));
72  printf("got\t%s\n", print_wchar_str(result));
73  printf("\n");
74  exit(1);
75  }
76  }
77 
78  printf("All tests successful!\n");
79  exit(0);
80 }
static void test(void)
#define printf(...)
Definition: port.h:198
char * s1
static char * buf
Definition: pg_test_fsync.c:68
int main(int argc, char **argv)
Definition: norm_test.c:57
static char * print_wchar_str(const pg_wchar *s)
Definition: norm_test.c:23
unsigned int pg_wchar
Definition: mbprint.c:31
char * s2
pg_wchar * unicode_normalize_kc(const pg_wchar *input)
Definition: unicode_norm.c:307
#define BUF_DIGITS
static int pg_wcscmp(const pg_wchar *s1, const pg_wchar *s2)
Definition: norm_test.c:41
int i
#define snprintf
Definition: port.h:192