summaryrefslogtreecommitdiff
path: root/libicuuc/tests/basic/driver.c
blob: 92c2b7cad72b2a975cefbf3885b6dcf0912d6889 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* file      : tests/basic/driver.c
 * copyright : Copyright (c) 2009-2019 Code Synthesis Tools CC
 * license   : Unicode License; see accompanying LICENSE file
 */
#include <stdio.h>
#include <assert.h>

#include <unicode/uloc.h>
#include <unicode/udata.h>
#include <unicode/uclean.h>
#include <unicode/utypes.h>
#include <unicode/uversion.h>

/* Usage: argv[0]
 *
 * Test some basic libicuuc functionality:
 *
 * - query and print the library version
 * - set, query and print the default locale
 * - load a portion of the bundled data and print its format id/version
 */
int
main ()
{
  /* Print version.
   */
  UVersionInfo v;
  u_getVersion (v);

  char s[U_MAX_VERSION_STRING_LENGTH];
  u_versionToString (v, s);

  printf ("version: %s\n", s);

  /* Change and print the current locale.
   */
  UErrorCode e = U_ZERO_ERROR;

  uloc_setDefault ("en_GB", &e);

  if (U_FAILURE (e))
  {
    fprintf (stderr, "uloc_setDefault failed: %s\n", u_errorName (e));
    u_cleanup ();
    return 1;
  }

  printf ("locale: %s\n", uloc_getDefault ());

  /* Check that data is properly loaded from the libicudata's data bundle and
   * print its format id/version.
   */
  UDataMemory* d = udata_open (NULL, "res", "en_US", &e);

  if (U_FAILURE (e))
  {
    fprintf (stderr, "udata_open failed: %s\n", u_errorName (e));
    u_cleanup ();
    return 1;
  }

  UDataInfo i;
  i.size = sizeof (UDataInfo);

  udata_getInfo (d, &i);

  assert (i.isBigEndian   == U_IS_BIG_ENDIAN);
  assert (i.charsetFamily == U_CHARSET_FAMILY);

  printf ("data: %.4s/%u.%u.%u.%u %u.%u.%u.%u\n",
          i.dataFormat,
          i.formatVersion[0],
          i.formatVersion[1],
          i.formatVersion[2],
          i.formatVersion[3],
          i.dataVersion[0],
          i.dataVersion[1],
          i.dataVersion[2],
          i.dataVersion[3]);

  udata_close (d);

  u_cleanup ();

  return 0;
}