This source file includes following definitions.
- success_callback
- failure_callback
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 #include <config.h>
21
22
23 #include "unicodeio.h"
24
25 #include <locale.h>
26 #include <string.h>
27
28 #include "macros.h"
29
30 #define TEST_CODE 0x2022
31 #define TEST_CODE_AS_UTF8 "\xe2\x80\xa2"
32 #define TEST_CODE_AS_GB18030 "\x81\x36\xa6\x31"
33
34 static char result[64];
35
36 static long
37 success_callback (const char *buf, size_t buflen, void *callback_arg)
38 {
39 memcpy (result, buf, buflen);
40 result[buflen] = '\0';
41 return 42;
42 }
43
44 static long
45 failure_callback (unsigned int code, const char *msg, void *callback_arg)
46 {
47 ASSERT (code == TEST_CODE);
48 strcpy (result, ".");
49 return 55;
50 }
51
52 int
53 main (int argc, char *argv[])
54 {
55
56 if (setlocale (LC_ALL, "") == NULL)
57 return 1;
58
59 switch (unicode_to_mb (TEST_CODE, success_callback, failure_callback, NULL))
60 {
61 case 42:
62 if (argc > 1)
63 switch (argv[1][0])
64 {
65 case '1':
66 case '2':
67 ASSERT (strcmp (result, TEST_CODE_AS_UTF8) == 0);
68 break;
69 case '3':
70 ASSERT (strcmp (result, TEST_CODE_AS_GB18030) == 0);
71 break;
72 }
73 break;
74 case 55:
75 ASSERT (strcmp (result, ".") == 0);
76 break;
77 default:
78 ASSERT (0);
79 }
80
81 return 0;
82 }