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 60 of file norm_test.c.

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

61 {
62  const pg_unicode_test *test;
63 
64  for (test = UnicodeNormalizationTests; test->input[0] != 0; test++)
65  {
66  pg_wchar *result;
67 
68  result = unicode_normalize_kc(test->input);
69 
70  if (pg_wcscmp(test->output, result) != 0)
71  {
72  printf("FAILURE (NormalizationTest.txt line %d):\n", test->linenum);
73  printf("input: %s\n", print_wchar_str(test->input));
74  printf("expected: %s\n", print_wchar_str(test->output));
75  printf("got: %s\n", print_wchar_str(result));
76  printf("\n");
77  exit(1);
78  }
79  }
80 
81  printf("All tests successful!\n");
82  exit(0);
83 }
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:44

◆ pg_wcscmp()

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

Definition at line 44 of file norm_test.c.

Referenced by main().

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

◆ 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 sprintf.

Referenced by main().

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