Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(152)

Side by Side Diff: icu46/source/test/cintltst/utexttst.c

Issue 5516007: Check in the pristine copy of ICU 4.6... (Closed) Base URL: svn://chrome-svn/chrome/trunk/deps/third_party/
Patch Set: Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « icu46/source/test/cintltst/usrchtst.c ('k') | icu46/source/test/cintltst/utf16tst.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 /********************************************************************
2 * COPYRIGHT:
3 * Copyright (c) 2005-2009, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
6 /*
7 * File utexttst.c
8 *
9 * Modification History:
10 *
11 * Date Name Description
12 * 06/13/2005 Andy Heninger Creation
13 *******************************************************************************
14 */
15
16 #include "unicode/utypes.h"
17 #include "unicode/utext.h"
18 #include "unicode/ustring.h"
19 #include "cintltst.h"
20 #include "memory.h"
21 #include "string.h"
22
23
24 static void TestAPI(void);
25 void addUTextTest(TestNode** root);
26
27
28 void
29 addUTextTest(TestNode** root)
30 {
31 addTest(root, &TestAPI , "tsutil/UTextTest/TestAPI");
32 }
33
34
35 #define TEST_ASSERT(x) \
36 {if ((x)==FALSE) {log_err("Test failure in file %s at line %d\n", __FILE__, _ _LINE__);\
37 gFailed = TRUE;\
38 }}
39
40
41 #define TEST_SUCCESS(status) \
42 {if (U_FAILURE(status)) {log_err("Test failure in file %s at line %d. Error = \"%s\"\n", \
43 __FILE__, __LINE__, u_errorName(status)); \
44 gFailed = TRUE;\
45 }}
46
47
48
49 /*
50 * TestAPI verify that the UText API is accessible from C programs.
51 * This is not intended to be a complete test of the API functionalit y. That is
52 * in the C++ intltest program.
53 * This test is intended to check that everything can be accessed and built in
54 * a pure C enviornment.
55 */
56
57
58 static void TestAPI(void) {
59 UErrorCode status = U_ZERO_ERROR;
60 UBool gFailed = FALSE;
61
62 /* Open */
63 {
64 UText utLoc = UTEXT_INITIALIZER;
65 const char * cString = "\x61\x62\x63\x64";
66 UChar uString[] = {0x41, 0x42, 0x43, 0};
67 UText *uta;
68 UText *utb;
69 UChar c;
70
71 uta = utext_openUChars(NULL, uString, -1, &status);
72 TEST_SUCCESS(status);
73 c = utext_next32(uta);
74 TEST_ASSERT(c == 0x41);
75 utb = utext_close(uta);
76 TEST_ASSERT(utb == NULL);
77
78 uta = utext_openUTF8(&utLoc, cString, -1, &status);
79 TEST_SUCCESS(status);
80 TEST_ASSERT(uta == &utLoc);
81
82 uta = utext_close(&utLoc);
83 TEST_ASSERT(uta == &utLoc);
84 }
85
86 /* utext_clone() */
87 {
88 UChar uString[] = {0x41, 0x42, 0x43, 0};
89 int64_t len;
90 UText *uta;
91 UText *utb;
92
93 status = U_ZERO_ERROR;
94 uta = utext_openUChars(NULL, uString, -1, &status);
95 TEST_SUCCESS(status);
96 utb = utext_clone(NULL, uta, FALSE, FALSE, &status);
97 TEST_SUCCESS(status);
98 TEST_ASSERT(utb != NULL);
99 TEST_ASSERT(utb != uta);
100 len = utext_nativeLength(uta);
101 TEST_ASSERT(len == u_strlen(uString));
102 utext_close(uta);
103 utext_close(utb);
104 }
105
106 /* basic access functions */
107 {
108 UChar uString[] = {0x41, 0x42, 0x43, 0};
109 UText *uta;
110 UChar32 c;
111 int64_t len;
112 UBool b;
113 int64_t i;
114
115 status = U_ZERO_ERROR;
116 uta = utext_openUChars(NULL, uString, -1, &status);
117 TEST_ASSERT(uta!=NULL);
118 TEST_SUCCESS(status);
119 b = utext_isLengthExpensive(uta);
120 TEST_ASSERT(b==TRUE);
121 len = utext_nativeLength(uta);
122 TEST_ASSERT(len == u_strlen(uString));
123 b = utext_isLengthExpensive(uta);
124 TEST_ASSERT(b==FALSE);
125
126 c = utext_char32At(uta, 0);
127 TEST_ASSERT(c==uString[0]);
128
129 c = utext_current32(uta);
130 TEST_ASSERT(c==uString[0]);
131
132 c = utext_next32(uta);
133 TEST_ASSERT(c==uString[0]);
134 c = utext_current32(uta);
135 TEST_ASSERT(c==uString[1]);
136
137 c = utext_previous32(uta);
138 TEST_ASSERT(c==uString[0]);
139 c = utext_current32(uta);
140 TEST_ASSERT(c==uString[0]);
141
142 c = utext_next32From(uta, 1);
143 TEST_ASSERT(c==uString[1]);
144 c = utext_next32From(uta, u_strlen(uString));
145 TEST_ASSERT(c==U_SENTINEL);
146
147 c = utext_previous32From(uta, 2);
148 TEST_ASSERT(c==uString[1]);
149 i = utext_getNativeIndex(uta);
150 TEST_ASSERT(i == 1);
151
152 utext_setNativeIndex(uta, 0);
153 b = utext_moveIndex32(uta, 1);
154 TEST_ASSERT(b==TRUE);
155 i = utext_getNativeIndex(uta);
156 TEST_ASSERT(i==1);
157
158 b = utext_moveIndex32(uta, u_strlen(uString)-1);
159 TEST_ASSERT(b==TRUE);
160 i = utext_getNativeIndex(uta);
161 TEST_ASSERT(i==u_strlen(uString));
162
163 b = utext_moveIndex32(uta, 1);
164 TEST_ASSERT(b==FALSE);
165 i = utext_getNativeIndex(uta);
166 TEST_ASSERT(i==u_strlen(uString));
167
168 utext_setNativeIndex(uta, 0);
169 c = UTEXT_NEXT32(uta);
170 TEST_ASSERT(c==uString[0]);
171 c = utext_current32(uta);
172 TEST_ASSERT(c==uString[1]);
173
174 c = UTEXT_PREVIOUS32(uta);
175 TEST_ASSERT(c==uString[0]);
176 c = UTEXT_PREVIOUS32(uta);
177 TEST_ASSERT(c==U_SENTINEL);
178
179
180 utext_close(uta);
181 }
182
183 {
184 /*
185 * UText opened on a NULL string with zero length
186 */
187 UText *uta;
188 UChar32 c;
189
190 status = U_ZERO_ERROR;
191 uta = utext_openUChars(NULL, NULL, 0, &status);
192 TEST_SUCCESS(status);
193 c = UTEXT_NEXT32(uta);
194 TEST_ASSERT(c == U_SENTINEL);
195 utext_close(uta);
196
197 uta = utext_openUTF8(NULL, NULL, 0, &status);
198 TEST_SUCCESS(status);
199 c = UTEXT_NEXT32(uta);
200 TEST_ASSERT(c == U_SENTINEL);
201 utext_close(uta);
202 }
203
204
205 {
206 /*
207 * extract
208 */
209 UText *uta;
210 UChar uString[] = {0x41, 0x42, 0x43, 0};
211 UChar buf[100];
212 int32_t i;
213
214 status = U_ZERO_ERROR;
215 uta = utext_openUChars(NULL, uString, -1, &status);
216 TEST_SUCCESS(status);
217
218 status = U_ZERO_ERROR;
219 i = utext_extract(uta, 0, 100, NULL, 0, &status);
220 TEST_ASSERT(status==U_BUFFER_OVERFLOW_ERROR);
221 TEST_ASSERT(i == u_strlen(uString));
222
223 status = U_ZERO_ERROR;
224 memset(buf, 0, sizeof(buf));
225 i = utext_extract(uta, 0, 100, buf, 100, &status);
226 TEST_SUCCESS(status);
227 TEST_ASSERT(i == u_strlen(uString));
228 i = u_strcmp(uString, buf);
229 TEST_ASSERT(i == 0);
230 utext_close(uta);
231 }
232
233 {
234 /*
235 * Copy, Replace, isWritable
236 * Can't create an editable UText from plain C, so all we
237 * can easily do is check that errors returned.
238 */
239 UText *uta;
240 UChar uString[] = {0x41, 0x42, 0x43, 0};
241 UBool b;
242
243 status = U_ZERO_ERROR;
244 uta = utext_openUChars(NULL, uString, -1, &status);
245 TEST_SUCCESS(status);
246
247 b = utext_isWritable(uta);
248 TEST_ASSERT(b == FALSE);
249
250 b = utext_hasMetaData(uta);
251 TEST_ASSERT(b == FALSE);
252
253 utext_replace(uta,
254 0, 1, /* start, limit */
255 uString, -1, /* replacement, replacement length */
256 &status);
257 TEST_ASSERT(status == U_NO_WRITE_PERMISSION);
258
259
260 utext_copy(uta,
261 0, 1, /* start, limit */
262 2, /* destination index */
263 FALSE, /* move flag */
264 &status);
265 TEST_ASSERT(status == U_NO_WRITE_PERMISSION);
266
267 utext_close(uta);
268 }
269
270
271 }
272
OLDNEW
« no previous file with comments | « icu46/source/test/cintltst/usrchtst.c ('k') | icu46/source/test/cintltst/utf16tst.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698