This source file includes following definitions.
- check
- check_invalid
- 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 static int
26 check (const uint16_t *input, size_t input_length, ucs4_t *puc)
27 {
28 ucs4_t uc;
29
30
31 if (u16_prev (&uc, input + input_length, input) != input)
32 return 1;
33
34
35 {
36 uint16_t buf[100];
37 uint16_t *ptr;
38 size_t i;
39 ucs4_t uc1;
40
41 ptr = buf;
42 *ptr++ = 0x2102;
43 for (i = 0; i < input_length; i++)
44 ptr[i] = input[i];
45
46 if (u16_prev (&uc1, ptr + input_length, buf) != ptr)
47 return 2;
48 if (uc1 != uc)
49 return 3;
50 }
51
52
53 {
54 uint16_t buf[100];
55 uint16_t *ptr;
56 size_t i;
57 ucs4_t uc1;
58
59 ptr = buf;
60 *ptr++ = 0xD835;
61 *ptr++ = 0xDD1E;
62 for (i = 0; i < input_length; i++)
63 ptr[i] = input[i];
64
65 if (u16_prev (&uc1, ptr + input_length, buf) != ptr)
66 return 4;
67 if (uc1 != uc)
68 return 5;
69 }
70
71 *puc = uc;
72 return 0;
73 }
74
75 static int
76 check_invalid (const uint16_t *input, size_t input_length)
77 {
78 ucs4_t uc;
79
80
81 uc = 0xBADFACE;
82 if (u16_prev (&uc, input + input_length, input) != NULL)
83 return 1;
84 if (uc != 0xBADFACE)
85 return 2;
86
87
88 {
89 uint16_t buf[100];
90 uint16_t *ptr;
91 size_t i;
92
93 ptr = buf;
94 *ptr++ = 0x2102;
95 for (i = 0; i < input_length; i++)
96 ptr[i] = input[i];
97
98 uc = 0xBADFACE;
99 if (u16_prev (&uc, ptr + input_length, buf) != NULL)
100 return 3;
101 if (uc != 0xBADFACE)
102 return 4;
103 }
104
105
106 {
107 uint16_t buf[100];
108 uint16_t *ptr;
109 size_t i;
110
111 ptr = buf;
112 *ptr++ = 0xD835;
113 *ptr++ = 0xDD1E;
114 for (i = 0; i < input_length; i++)
115 ptr[i] = input[i];
116
117 uc = 0xBADFACE;
118 if (u16_prev (&uc, ptr + input_length, buf) != NULL)
119 return 5;
120 if (uc != 0xBADFACE)
121 return 6;
122 }
123
124 return 0;
125 }
126
127 int
128 main ()
129 {
130 ucs4_t uc;
131
132
133 {
134 ucs4_t c;
135 uint16_t buf[1];
136
137 for (c = 0; c < 0x80; c++)
138 {
139 buf[0] = c;
140 uc = 0xBADFACE;
141 ASSERT (check (buf, 1, &uc) == 0);
142 ASSERT (uc == c);
143 }
144 }
145
146
147 {
148 static const uint16_t input[] = { 0x20AC };
149 uc = 0xBADFACE;
150 ASSERT (check (input, SIZEOF (input), &uc) == 0);
151 ASSERT (uc == 0x20AC);
152 }
153
154
155 {
156 static const uint16_t input[] = { 0xD835, 0xDD1F };
157 uc = 0xBADFACE;
158 ASSERT (check (input, SIZEOF (input), &uc) == 0);
159 ASSERT (uc == 0x1D51F);
160 }
161
162
163 {
164 static const uint16_t input[] = { 0xD835 };
165 ASSERT (check_invalid (input, SIZEOF (input)) == 0);
166 }
167 {
168 static const uint16_t input[] = { 0xDD1F };
169 ASSERT (check_invalid (input, SIZEOF (input)) == 0);
170 }
171
172 return 0;
173 }