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

Side by Side Diff: source/test/cintltst/cstrtest.c

Issue 845603002: Update ICU to 54.1 step 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/icu.git@master
Patch Set: remove unusued directories Created 5 years, 11 months 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
« no previous file with comments | « source/test/cintltst/cstrcase.c ('k') | source/test/cintltst/cucdapi.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 ********************************************************************** 2 **********************************************************************
3 * Copyright (C) 1998-2011, International Business Machines Corporation 3 * Copyright (C) 1998-2014, International Business Machines Corporation
4 * and others. All Rights Reserved. 4 * and others. All Rights Reserved.
5 ********************************************************************** 5 **********************************************************************
6 * 6 *
7 * File cstrtest.c 7 * File cstrtest.c
8 * 8 *
9 * Modification History: 9 * Modification History:
10 * 10 *
11 * Date Name Description 11 * Date Name Description
12 * 07/13/2000 Madhu created 12 * 07/13/2000 Madhu created
13 ******************************************************************************* 13 *******************************************************************************
14 */ 14 */
15 15
16 #include "unicode/ustring.h" 16 #include "unicode/ustring.h"
17 #include "unicode/ucnv.h" 17 #include "unicode/ucnv.h"
18 #include "cstring.h" 18 #include "cstring.h"
19 #include "uinvchar.h" 19 #include "uinvchar.h"
20 #include "cintltst.h" 20 #include "cintltst.h"
21 #include "cmemory.h" 21 #include "cmemory.h"
22 22
23 #define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
24
25 static void TestAPI(void); 23 static void TestAPI(void);
26 void addCStringTest(TestNode** root); 24 void addCStringTest(TestNode** root);
27 25
28 static void TestInvariant(void); 26 static void TestInvariant(void);
29 static void TestCompareInvEbcdicAsAscii(void); 27 static void TestCompareInvEbcdicAsAscii(void);
30 28
31 void addCStringTest(TestNode** root) { 29 void addCStringTest(TestNode** root) {
32 addTest(root, &TestAPI, "tsutil/cstrtest/TestAPI"); 30 addTest(root, &TestAPI, "tsutil/cstrtest/TestAPI");
33 addTest(root, &TestInvariant, "tsutil/cstrtest/TestInvariant"); 31 addTest(root, &TestInvariant, "tsutil/cstrtest/TestInvariant");
34 addTest(root, &TestCompareInvEbcdicAsAscii, "tsutil/cstrtest/TestCompareInvE bcdicAsAscii"); 32 addTest(root, &TestCompareInvEbcdicAsAscii, "tsutil/cstrtest/TestCompareInvE bcdicAsAscii");
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 log_err("unable to open the default converter\n"); 240 log_err("unable to open the default converter\n");
243 } else { 241 } else {
244 length=ucnv_fromUChars(cnv, cs, sizeof(cs), invariantUChars, -1, &er rorCode); 242 length=ucnv_fromUChars(cnv, cs, sizeof(cs), invariantUChars, -1, &er rorCode);
245 if(U_FAILURE(errorCode)) { 243 if(U_FAILURE(errorCode)) {
246 log_err("ucnv_fromUChars(invariantUChars) failed - %s\n", u_erro rName(errorCode)); 244 log_err("ucnv_fromUChars(invariantUChars) failed - %s\n", u_erro rName(errorCode));
247 } else if(length!=sizeof(invariantChars)-1 || strcmp(cs, invariantCh ars)!=0) { 245 } else if(length!=sizeof(invariantChars)-1 || strcmp(cs, invariantCh ars)!=0) {
248 log_err("ucnv_fromUChars(invariantUChars) failed\n"); 246 log_err("ucnv_fromUChars(invariantUChars) failed\n");
249 } 247 }
250 248
251 errorCode=U_ZERO_ERROR; 249 errorCode=U_ZERO_ERROR;
252 length=ucnv_toUChars(cnv, us, LENGTHOF(us), invariantChars, -1, &err orCode); 250 length=ucnv_toUChars(cnv, us, UPRV_LENGTHOF(us), invariantChars, -1, &errorCode);
253 if(U_FAILURE(errorCode)) { 251 if(U_FAILURE(errorCode)) {
254 log_err("ucnv_toUChars(invariantChars) failed - %s\n", u_errorNa me(errorCode)); 252 log_err("ucnv_toUChars(invariantChars) failed - %s\n", u_errorNa me(errorCode));
255 } else if(length!=LENGTHOF(invariantUChars)-1 || u_strcmp(us, invari antUChars)!=0) { 253 } else if(length!=UPRV_LENGTHOF(invariantUChars)-1 || u_strcmp(us, i nvariantUChars)!=0) {
256 log_err("ucnv_toUChars(invariantChars) failed\n"); 254 log_err("ucnv_toUChars(invariantChars) failed\n");
257 } 255 }
258 256
259 ucnv_close(cnv); 257 ucnv_close(cnv);
260 } 258 }
261 } 259 }
262 260
263 /* API tests */ 261 /* API tests */
264 if(!uprv_isInvariantString(invariantChars, -1)) { 262 if(!uprv_isInvariantString(invariantChars, -1)) {
265 log_err("uprv_isInvariantString(invariantChars) failed\n"); 263 log_err("uprv_isInvariantString(invariantChars) failed\n");
266 } 264 }
267 if(!uprv_isInvariantUString(invariantUChars, -1)) { 265 if(!uprv_isInvariantUString(invariantUChars, -1)) {
268 log_err("uprv_isInvariantUString(invariantUChars) failed\n"); 266 log_err("uprv_isInvariantUString(invariantUChars) failed\n");
269 } 267 }
270 if(!uprv_isInvariantString(invariantChars+strlen(invariantChars), 1)) { 268 if(!uprv_isInvariantString(invariantChars+strlen(invariantChars), 1)) {
271 log_err("uprv_isInvariantString(\"\\0\") failed\n"); 269 log_err("uprv_isInvariantString(\"\\0\") failed\n");
272 } 270 }
273 271
274 for(i=0; i<(sizeof(variantChars)-1); ++i) { 272 for(i=0; i<(sizeof(variantChars)-1); ++i) {
275 if(uprv_isInvariantString(variantChars+i, 1)) { 273 if(uprv_isInvariantString(variantChars+i, 1)) {
276 log_err("uprv_isInvariantString(variantChars[%d]) failed\n", i); 274 log_err("uprv_isInvariantString(variantChars[%d]) failed\n", i);
277 } 275 }
278 if(uprv_isInvariantUString(variantUChars+i, 1)) { 276 if(uprv_isInvariantUString(variantUChars+i, 1)) {
279 log_err("uprv_isInvariantUString(variantUChars[%d]) failed\n", i); 277 log_err("uprv_isInvariantUString(variantUChars[%d]) failed\n", i);
280 } 278 }
281 } 279 }
282 280
283 for(i=0; i<LENGTHOF(nonASCIIUChars); ++i) { 281 for(i=0; i<UPRV_LENGTHOF(nonASCIIUChars); ++i) {
284 if(uprv_isInvariantUString(nonASCIIUChars+i, 1)) { 282 if(uprv_isInvariantUString(nonASCIIUChars+i, 1)) {
285 log_err("uprv_isInvariantUString(nonASCIIUChars[%d]) failed\n", i); 283 log_err("uprv_isInvariantUString(nonASCIIUChars[%d]) failed\n", i);
286 } 284 }
287 } 285 }
288 } 286 }
289 287
290 static int32_t getSign(int32_t n) { 288 static int32_t getSign(int32_t n) {
291 if(n<0) { 289 if(n<0) {
292 return -1; 290 return -1;
293 } else if(n==0) { 291 } else if(n==0) {
(...skipping 22 matching lines...) Expand all
316 { "\x6d", "_" }, 314 { "\x6d", "_" },
317 { "\x81", "a" }, 315 { "\x81", "a" },
318 { "\x81\xf0\xf0", "a00" }, 316 { "\x81\xf0\xf0", "a00" },
319 { "\x81\xf0\xf0", "a00" }, 317 { "\x81\xf0\xf0", "a00" },
320 { "\x81\x81", "aa" }, 318 { "\x81\x81", "aa" },
321 { "\x81\x81\xf0", "aa0" }, 319 { "\x81\x81\xf0", "aa0" },
322 { "\x81\x81\x81", "aaa" }, 320 { "\x81\x81\x81", "aaa" },
323 { "\x81\x81\x82", "aab" } 321 { "\x81\x81\x82", "aab" }
324 }; 322 };
325 int32_t i; 323 int32_t i;
326 for(i=1; i<LENGTHOF(invStrings); ++i) { 324 for(i=1; i<UPRV_LENGTHOF(invStrings); ++i) {
327 int32_t diff1, diff2; 325 int32_t diff1, diff2;
328 /* compare previous vs. current */ 326 /* compare previous vs. current */
329 diff1=getSign(uprv_compareInvEbcdicAsAscii(invStrings[i-1][0], invString s[i][0])); 327 diff1=getSign(uprv_compareInvEbcdicAsAscii(invStrings[i-1][0], invString s[i][0]));
330 if(diff1>0 || (diff1==0 && 0!=uprv_strcmp(invStrings[i-1][0], invStrings [i][0]))) { 328 if(diff1>0 || (diff1==0 && 0!=uprv_strcmp(invStrings[i-1][0], invStrings [i][0]))) {
331 log_err("uprv_compareInvEbcdicAsAscii(%s, %s)=%hd is wrong\n", 329 log_err("uprv_compareInvEbcdicAsAscii(%s, %s)=%hd is wrong\n",
332 invStrings[i-1][1], invStrings[i][1], (short)diff1); 330 invStrings[i-1][1], invStrings[i][1], (short)diff1);
333 } 331 }
334 /* compare current vs. previous, should be inverse diff */ 332 /* compare current vs. previous, should be inverse diff */
335 diff2=getSign(uprv_compareInvEbcdicAsAscii(invStrings[i][0], invStrings[ i-1][0])); 333 diff2=getSign(uprv_compareInvEbcdicAsAscii(invStrings[i][0], invStrings[ i-1][0]));
336 if(diff2!=-diff1) { 334 if(diff2!=-diff1) {
337 log_err("uprv_compareInvEbcdicAsAscii(%s, %s)=%hd is wrong\n", 335 log_err("uprv_compareInvEbcdicAsAscii(%s, %s)=%hd is wrong\n",
338 invStrings[i][1], invStrings[i-1][1], (short)diff2); 336 invStrings[i][1], invStrings[i-1][1], (short)diff2);
339 } 337 }
340 } 338 }
341 } 339 }
OLDNEW
« no previous file with comments | « source/test/cintltst/cstrcase.c ('k') | source/test/cintltst/cucdapi.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698