PostgreSQL Source Code  git master
norm_test.c File Reference
#include "postgres_fe.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "common/unicode_norm.h"
#include "norm_test_table.h"
Include dependency graph for norm_test.c:

Go to the source code of this file.

Macros

#define BUF_DIGITS   50
 

Functions

static char * print_wchar_str (const pg_wchar *s)
 
static int pg_wcscmp (const pg_wchar *s1, const pg_wchar *s2)
 
int main (int argc, char **argv)
 

Macro Definition Documentation

◆ BUF_DIGITS

#define BUF_DIGITS   50

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 60 of file norm_test.c.

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 }
exit(1)
unsigned int pg_wchar
Definition: mbprint.c:31
static int pg_wcscmp(const pg_wchar *s1, const pg_wchar *s2)
Definition: norm_test.c:44
static char * print_wchar_str(const pg_wchar *s)
Definition: norm_test.c:23
#define printf(...)
Definition: port.h:244
static void test(void)
pg_wchar * unicode_normalize(UnicodeNormalizationForm form, const pg_wchar *input)
Definition: unicode_norm.c:402

References exit(), pg_wcscmp(), print_wchar_str(), printf, test(), and unicode_normalize().

◆ pg_wcscmp()

static int pg_wcscmp ( const pg_wchar s1,
const pg_wchar s2 
)
static

Definition at line 44 of file norm_test.c.

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 }
char * s1
char * s2

References s1, and s2.

Referenced by main().

◆ print_wchar_str()

static char* print_wchar_str ( const pg_wchar s)
static

Definition at line 23 of file norm_test.c.

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 }
int i
Definition: isn.c:73
#define BUF_DIGITS
static char * buf
Definition: pg_test_fsync.c:73
#define sprintf
Definition: port.h:240

References buf, BUF_DIGITS, i, and sprintf.

Referenced by main().