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

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 49 of file category_test.c.

50 {
51 #ifdef USE_ICU
52  int pg_unicode_version = parse_unicode_version(PG_UNICODE_VERSION);
53  int icu_unicode_version = parse_unicode_version(U_UNICODE_VERSION);
54  int pg_skipped_codepoints = 0;
55  int icu_skipped_codepoints = 0;
56 
57  printf("category_test: Postgres Unicode version:\t%s\n", PG_UNICODE_VERSION);
58  printf("category_test: ICU Unicode version:\t\t%s\n", U_UNICODE_VERSION);
59 
60  for (UChar32 code = 0; code <= 0x10ffff; code++)
61  {
62  uint8_t pg_category = unicode_category(code);
63  uint8_t icu_category = u_charType(code);
64 
65  if (pg_category != icu_category)
66  {
67  /*
68  * A version mismatch means that some assigned codepoints in the
69  * newer version may be unassigned in the older version. That's
70  * OK, though the test will not cover those codepoints marked
71  * unassigned in the older version (that is, it will no longer be
72  * an exhaustive test).
73  */
74  if (pg_category == PG_U_UNASSIGNED &&
75  pg_unicode_version < icu_unicode_version)
76  pg_skipped_codepoints++;
77  else if (icu_category == PG_U_UNASSIGNED &&
78  icu_unicode_version < pg_unicode_version)
79  icu_skipped_codepoints++;
80  else
81  {
82  printf("category_test: FAILURE for codepoint 0x%06x\n", code);
83  printf("category_test: Postgres category: %02d %s %s\n", pg_category,
84  unicode_category_abbrev(pg_category),
85  unicode_category_string(pg_category));
86  printf("category_test: ICU category: %02d %s %s\n", icu_category,
87  unicode_category_abbrev(icu_category),
88  unicode_category_string(icu_category));
89  printf("\n");
90  exit(1);
91  }
92  }
93  }
94 
95  if (pg_skipped_codepoints > 0)
96  printf("category_test: skipped %d codepoints unassigned in Postgres due to Unicode version mismatch\n",
97  pg_skipped_codepoints);
98  if (icu_skipped_codepoints > 0)
99  printf("category_test: skipped %d codepoints unassigned in ICU due to Unicode version mismatch\n",
100  icu_skipped_codepoints);
101 
102  printf("category_test: success\n");
103  exit(0);
104 #else
105  printf("category_test: ICU support required for test; skipping\n");
106  exit(0);
107 #endif
108 }
exit(1)
#define printf(...)
Definition: port.h:244
const char * unicode_category_string(pg_unicode_category category)
const char * unicode_category_abbrev(pg_unicode_category category)
pg_unicode_category unicode_category(pg_wchar ucs)
@ PG_U_UNASSIGNED
#define PG_UNICODE_VERSION
Datum icu_unicode_version(PG_FUNCTION_ARGS)
Definition: varlena.c:6260

References exit(), icu_unicode_version(), PG_U_UNASSIGNED, PG_UNICODE_VERSION, printf, unicode_category(), unicode_category_abbrev(), and unicode_category_string().