This source file includes following definitions.
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include <config.h>
20
21 #include "unistr.h"
22
23 #include "macros.h"
24
25 #define MAGIC 0xBADE
26
27 int
28 main ()
29 {
30
31 {
32 ucs4_t uc;
33
34 for (uc = 0; uc < 0x80; uc++)
35 {
36 uint16_t buf[3] = { MAGIC, MAGIC, MAGIC };
37 int ret;
38
39 ret = u16_uctomb (buf, uc, 0);
40 ASSERT (ret == -2);
41 ASSERT (buf[0] == MAGIC);
42
43 ret = u16_uctomb (buf, uc, 1);
44 ASSERT (ret == 1);
45 ASSERT (buf[0] == uc);
46 ASSERT (buf[1] == MAGIC);
47 }
48 }
49
50
51 {
52 ucs4_t uc = 0x20AC;
53 uint16_t buf[3] = { MAGIC, MAGIC, MAGIC };
54 int ret;
55
56 ret = u16_uctomb (buf, uc, 0);
57 ASSERT (ret == -2);
58 ASSERT (buf[0] == MAGIC);
59
60 ret = u16_uctomb (buf, uc, 1);
61 ASSERT (ret == 1);
62 ASSERT (buf[0] == uc);
63 ASSERT (buf[1] == MAGIC);
64 }
65
66
67 {
68 ucs4_t uc = 0x10FFFD;
69 uint16_t buf[3] = { MAGIC, MAGIC, MAGIC };
70 int ret;
71
72 ret = u16_uctomb (buf, uc, 0);
73 ASSERT (ret == -2);
74 ASSERT (buf[0] == MAGIC);
75
76 ret = u16_uctomb (buf, uc, 1);
77 ASSERT (ret == -2);
78 ASSERT (buf[0] == MAGIC);
79
80 ret = u16_uctomb (buf, uc, 2);
81 ASSERT (ret == 2);
82 ASSERT (buf[0] == 0xDBFF);
83 ASSERT (buf[1] == 0xDFFD);
84 ASSERT (buf[2] == MAGIC);
85 }
86
87
88 {
89 ucs4_t invalid[] = { 0x110000, 0xD800, 0xDBFF, 0xDC00, 0xDFFF };
90 uint16_t buf[3] = { MAGIC, MAGIC, MAGIC };
91 size_t i;
92
93 for (i = 0; i < SIZEOF (invalid); i++)
94 {
95 ucs4_t uc = invalid[i];
96 int n;
97
98 for (n = 0; n <= 2; n++)
99 {
100 int ret = u16_uctomb (buf, uc, n);
101 ASSERT (ret == -1);
102 ASSERT (buf[0] == MAGIC);
103 ASSERT (buf[1] == MAGIC);
104 ASSERT (buf[2] == MAGIC);
105 }
106 }
107 }
108
109 return 0;
110 }