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

Referenced by print_wchar_str().

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 57 of file norm_test.c.

References pg_wcscmp(), print_wchar_str(), printf, test(), and unicode_normalize_kc().

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
static char * print_wchar_str(const pg_wchar *s)
Definition: norm_test.c:23
unsigned int pg_wchar
Definition: mbprint.c:31
pg_wchar * unicode_normalize_kc(const pg_wchar *input)
Definition: unicode_norm.c:307
static int pg_wcscmp(const pg_wchar *s1, const pg_wchar *s2)
Definition: norm_test.c:41

◆ pg_wcscmp()

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

Definition at line 41 of file norm_test.c.

Referenced by main().

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

◆ print_wchar_str()

static char* print_wchar_str ( const pg_wchar s)
static

Definition at line 23 of file norm_test.c.

References buf, BUF_DIGITS, i, and snprintf.

Referenced by main().

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 }
static char * buf
Definition: pg_test_fsync.c:68
#define BUF_DIGITS
int i
#define snprintf
Definition: port.h:192