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 0xBA
26
27 int
28 main ()
29 {
30
31 {
32 ucs4_t uc;
33
34 for (uc = 0; uc < 0x80; uc++)
35 {
36 uint8_t buf[5] = { MAGIC, MAGIC, MAGIC, MAGIC, MAGIC };
37 int ret;
38
39 ret = u8_uctomb (buf, uc, 0);
40 ASSERT (ret == -2);
41 ASSERT (buf[0] == MAGIC);
42
43 ret = u8_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 = 0x00D7;
53 uint8_t buf[5] = { MAGIC, MAGIC, MAGIC, MAGIC, MAGIC };
54 int ret;
55
56 ret = u8_uctomb (buf, uc, 0);
57 ASSERT (ret == -2);
58 ASSERT (buf[0] == MAGIC);
59
60 ret = u8_uctomb (buf, uc, 1);
61 ASSERT (ret == -2);
62 ASSERT (buf[0] == MAGIC);
63
64 ret = u8_uctomb (buf, uc, 2);
65 ASSERT (ret == 2);
66 ASSERT (buf[0] == 0xC3);
67 ASSERT (buf[1] == 0x97);
68 ASSERT (buf[2] == MAGIC);
69 }
70
71
72 {
73 ucs4_t uc = 0x20AC;
74 uint8_t buf[5] = { MAGIC, MAGIC, MAGIC, MAGIC, MAGIC };
75 int ret;
76
77 ret = u8_uctomb (buf, uc, 0);
78 ASSERT (ret == -2);
79 ASSERT (buf[0] == MAGIC);
80
81 ret = u8_uctomb (buf, uc, 1);
82 ASSERT (ret == -2);
83 ASSERT (buf[0] == MAGIC);
84
85 ret = u8_uctomb (buf, uc, 2);
86 ASSERT (ret == -2);
87 ASSERT (buf[0] == MAGIC);
88 ASSERT (buf[1] == MAGIC);
89
90 ret = u8_uctomb (buf, uc, 3);
91 ASSERT (ret == 3);
92 ASSERT (buf[0] == 0xE2);
93 ASSERT (buf[1] == 0x82);
94 ASSERT (buf[2] == 0xAC);
95 ASSERT (buf[3] == MAGIC);
96 }
97
98
99 {
100 ucs4_t uc = 0x10FFFD;
101 uint8_t buf[5] = { MAGIC, MAGIC, MAGIC, MAGIC, MAGIC };
102 int ret;
103
104 ret = u8_uctomb (buf, uc, 0);
105 ASSERT (ret == -2);
106 ASSERT (buf[0] == MAGIC);
107
108 ret = u8_uctomb (buf, uc, 1);
109 ASSERT (ret == -2);
110 ASSERT (buf[0] == MAGIC);
111
112 ret = u8_uctomb (buf, uc, 2);
113 ASSERT (ret == -2);
114 ASSERT (buf[0] == MAGIC);
115 ASSERT (buf[1] == MAGIC);
116
117 ret = u8_uctomb (buf, uc, 3);
118 ASSERT (ret == -2);
119 ASSERT (buf[0] == MAGIC);
120 ASSERT (buf[1] == MAGIC);
121 ASSERT (buf[2] == MAGIC);
122
123 ret = u8_uctomb (buf, uc, 4);
124 ASSERT (ret == 4);
125 ASSERT (buf[0] == 0xF4);
126 ASSERT (buf[1] == 0x8F);
127 ASSERT (buf[2] == 0xBF);
128 ASSERT (buf[3] == 0xBD);
129 ASSERT (buf[4] == MAGIC);
130 }
131
132
133 {
134 ucs4_t invalid[] = { 0x110000, 0xD800, 0xDBFF, 0xDC00, 0xDFFF };
135 uint8_t buf[5] = { MAGIC, MAGIC, MAGIC, MAGIC, MAGIC };
136 size_t i;
137
138 for (i = 0; i < SIZEOF (invalid); i++)
139 {
140 ucs4_t uc = invalid[i];
141 int n;
142
143 for (n = 0; n <= 4; n++)
144 {
145 int ret = u8_uctomb (buf, uc, n);
146 ASSERT (ret == -1);
147 ASSERT (buf[0] == MAGIC);
148 ASSERT (buf[1] == MAGIC);
149 ASSERT (buf[2] == MAGIC);
150 ASSERT (buf[3] == MAGIC);
151 ASSERT (buf[4] == MAGIC);
152 }
153 }
154 }
155
156 return 0;
157 }