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

Side by Side Diff: source/test/cintltst/ccapitst.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/ccaltst.c ('k') | source/test/cintltst/cdateintervalformattest.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 * COPYRIGHT: 2 * COPYRIGHT:
3 * Copyright (c) 1997-2013, International Business Machines Corporation and 3 * Copyright (c) 1997-2014, International Business Machines Corporation and
4 * others. All Rights Reserved. 4 * others. All Rights Reserved.
5 ********************************************************************/ 5 ********************************************************************/
6 /***************************************************************************** 6 /*****************************************************************************
7 * 7 *
8 * File CU_CAPITST.C 8 * File CU_CAPITST.C
9 * 9 *
10 * Modification History: 10 * Modification History:
11 * Name Description 11 * Name Description
12 * Madhu Katragadda Ported for C API 12 * Madhu Katragadda Ported for C API
13 ****************************************************************************** 13 ******************************************************************************
14 */ 14 */
15 #include <stdio.h> 15 #include <stdio.h>
16 #include <stdlib.h> 16 #include <stdlib.h>
17 #include <string.h> 17 #include <string.h>
18 #include <ctype.h> 18 #include <ctype.h>
19 #include "unicode/uloc.h" 19 #include "unicode/uloc.h"
20 #include "unicode/ucnv.h" 20 #include "unicode/ucnv.h"
21 #include "unicode/ucnv_err.h" 21 #include "unicode/ucnv_err.h"
22 #include "unicode/putil.h" 22 #include "unicode/putil.h"
23 #include "unicode/uset.h" 23 #include "unicode/uset.h"
24 #include "unicode/ustring.h" 24 #include "unicode/ustring.h"
25 #include "ucnv_bld.h" /* for sizeof(UConverter) */ 25 #include "ucnv_bld.h" /* for sizeof(UConverter) */
26 #include "cmemory.h" /* for UAlignedMemory */ 26 #include "cmemory.h" /* for UAlignedMemory */
27 #include "cintltst.h" 27 #include "cintltst.h"
28 #include "ccapitst.h" 28 #include "ccapitst.h"
29 #include "cstring.h" 29 #include "cstring.h"
30 30
31 #define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
32
33 #define NUM_CODEPAGE 1 31 #define NUM_CODEPAGE 1
34 #define MAX_FILE_LEN 1024*20 32 #define MAX_FILE_LEN 1024*20
35 #define UCS_FILE_NAME_SIZE 512 33 #define UCS_FILE_NAME_SIZE 512
36 34
37 /*returns an action other than the one provided*/ 35 /*returns an action other than the one provided*/
38 #if !UCONFIG_NO_LEGACY_CONVERSION 36 #if !UCONFIG_NO_LEGACY_CONVERSION
39 static UConverterFromUCallback otherUnicodeAction(UConverterFromUCallback MIA); 37 static UConverterFromUCallback otherUnicodeAction(UConverterFromUCallback MIA);
40 static UConverterToUCallback otherCharAction(UConverterToUCallback MIA); 38 static UConverterToUCallback otherCharAction(UConverterToUCallback MIA);
41 #endif 39 #endif
42 40
(...skipping 787 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 } 828 }
831 /*testing ucnv_getPlatform() with err != U_ZERO_ERROR*/ 829 /*testing ucnv_getPlatform() with err != U_ZERO_ERROR*/
832 err= U_ILLEGAL_ARGUMENT_ERROR; 830 err= U_ILLEGAL_ARGUMENT_ERROR;
833 if(ucnv_getPlatform(myConverter, &err) != UCNV_UNKNOWN){ 831 if(ucnv_getPlatform(myConverter, &err) != UCNV_UNKNOWN){
834 log_err("ucnv)getPlatform with err != U_ZERO_ERROR is supposed to fa il\n"); 832 log_err("ucnv)getPlatform with err != U_ZERO_ERROR is supposed to fa il\n");
835 } 833 }
836 err=U_ZERO_ERROR; 834 err=U_ZERO_ERROR;
837 835
838 836
839 /*Reads the BOM*/ 837 /*Reads the BOM*/
840 fread(&BOM, sizeof(UChar), 1, ucs_file_in); 838 {
839 // Note: gcc produces a compile warning if the return value from fre ad() is ignored.
840 size_t numRead = fread(&BOM, sizeof(UChar), 1, ucs_file_in);
841 (void)numRead;
842 }
841 if (BOM!=0xFEFF && BOM!=0xFFFE) 843 if (BOM!=0xFEFF && BOM!=0xFFFE)
842 { 844 {
843 log_err("File Missing BOM...Bailing!\n"); 845 log_err("File Missing BOM...Bailing!\n");
844 fclose(ucs_file_in); 846 fclose(ucs_file_in);
845 break; 847 break;
846 } 848 }
847 849
848 850
849 /*Reads in the file*/ 851 /*Reads in the file*/
850 while(!feof(ucs_file_in)&&(i+=fread(ucs_file_buffer+i, sizeof(UChar), 1, ucs_file_in))) 852 while(!feof(ucs_file_in)&&(i+=fread(ucs_file_buffer+i, sizeof(UChar), 1, ucs_file_in)))
(...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after
1669 "UTF-7", 1671 "UTF-7",
1670 #if !UCONFIG_NO_LEGACY_CONVERSION 1672 #if !UCONFIG_NO_LEGACY_CONVERSION
1671 "IMAP-mailbox-name", 1673 "IMAP-mailbox-name",
1672 "ibm-1047-s390" 1674 "ibm-1047-s390"
1673 #else 1675 #else
1674 "IMAP=mailbox-name" 1676 "IMAP=mailbox-name"
1675 #endif 1677 #endif
1676 }; 1678 };
1677 1679
1678 /* store the actual sizes of each converter */ 1680 /* store the actual sizes of each converter */
1679 int32_t actualSizes[LENGTHOF(names)]; 1681 int32_t actualSizes[UPRV_LENGTHOF(names)];
1680 1682
1681 static const int32_t bufferSizes[] = { 1683 static const int32_t bufferSizes[] = {
1682 U_CNV_SAFECLONE_BUFFERSIZE, 1684 U_CNV_SAFECLONE_BUFFERSIZE,
1683 (int32_t)(3*sizeof(UConverter))/2, /* 1.5*sizeof(UConverter) */ 1685 (int32_t)(3*sizeof(UConverter))/2, /* 1.5*sizeof(UConverter) */
1684 (int32_t)sizeof(UConverter)/2 /* 0.5*sizeof(UConverter) */ 1686 (int32_t)sizeof(UConverter)/2 /* 0.5*sizeof(UConverter) */
1685 }; 1687 };
1686 1688
1687 char charBuffer[21]; /* Leave at an odd number for alignment testing */ 1689 char charBuffer[21]; /* Leave at an odd number for alignment testing */
1688 uint8_t buffer[3] [U_CNV_SAFECLONE_BUFFERSIZE]; 1690 uint8_t buffer[3] [U_CNV_SAFECLONE_BUFFERSIZE];
1689 int32_t bufferSize, maxBufferSize; 1691 int32_t bufferSize, maxBufferSize;
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1783 } 1785 }
1784 1786
1785 ucnv_close(cnv); 1787 ucnv_close(cnv);
1786 } 1788 }
1787 1789
1788 maxBufferSize = 0; 1790 maxBufferSize = 0;
1789 maxName = ""; 1791 maxName = "";
1790 1792
1791 /* Do these cloned converters work at all - shuffle UChars to chars & back a gain..*/ 1793 /* Do these cloned converters work at all - shuffle UChars to chars & back a gain..*/
1792 1794
1793 for(j = 0; j < LENGTHOF(bufferSizes); ++j) { 1795 for(j = 0; j < UPRV_LENGTHOF(bufferSizes); ++j) {
1794 for (idx = 0; idx < LENGTHOF(names); idx++) 1796 for (idx = 0; idx < UPRV_LENGTHOF(names); idx++)
1795 { 1797 {
1796 err = U_ZERO_ERROR; 1798 err = U_ZERO_ERROR;
1797 cnv = ucnv_open(names[idx], &err); 1799 cnv = ucnv_open(names[idx], &err);
1798 if(U_FAILURE(err)) { 1800 if(U_FAILURE(err)) {
1799 log_data_err("ucnv_open(\"%s\") failed - %s\n", names[idx], u_er rorName(err)); 1801 log_data_err("ucnv_open(\"%s\") failed - %s\n", names[idx], u_er rorName(err));
1800 continue; 1802 continue;
1801 } 1803 }
1802 1804
1803 if(j == 0) { 1805 if(j == 0) {
1804 /* preflight to get maxBufferSize */ 1806 /* preflight to get maxBufferSize */
(...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after
2508 2510
2509 UErrorCode errorCode; 2511 UErrorCode errorCode;
2510 int32_t i; 2512 int32_t i;
2511 2513
2512 /* test truncated sequences */ 2514 /* test truncated sequences */
2513 errorCode=U_ZERO_ERROR; 2515 errorCode=U_ZERO_ERROR;
2514 ucnv_setToUCallBack(utf8Cnv, UCNV_TO_U_CALLBACK_STOP, NULL, NULL, NULL, &err orCode); 2516 ucnv_setToUCallBack(utf8Cnv, UCNV_TO_U_CALLBACK_STOP, NULL, NULL, NULL, &err orCode);
2515 2517
2516 memcpy(utf8, charUTF8, charUTF8Length); 2518 memcpy(utf8, charUTF8, charUTF8Length);
2517 2519
2518 for(i=0; i<LENGTHOF(badUTF8); ++i) { 2520 for(i=0; i<UPRV_LENGTHOF(badUTF8); ++i) {
2519 /* truncated sequence? */ 2521 /* truncated sequence? */
2520 int32_t length=strlen(badUTF8[i]); 2522 int32_t length=strlen(badUTF8[i]);
2521 if(length>=(1+U8_COUNT_TRAIL_BYTES(badUTF8[i][0]))) { 2523 if(length>=(1+U8_COUNT_TRAIL_BYTES(badUTF8[i][0]))) {
2522 continue; 2524 continue;
2523 } 2525 }
2524 2526
2525 /* assemble a string with the test character and the truncated sequence */ 2527 /* assemble a string with the test character and the truncated sequence */
2526 memcpy(utf8+charUTF8Length, badUTF8[i], length); 2528 memcpy(utf8+charUTF8Length, badUTF8[i], length);
2527 utf8Length=charUTF8Length+length; 2529 utf8Length=charUTF8Length+length;
2528 2530
2529 /* convert and check the invalidChars */ 2531 /* convert and check the invalidChars */
2530 source=utf8; 2532 source=utf8;
2531 target=output; 2533 target=output;
2532 pivotSource=pivotTarget=pivotBuffer; 2534 pivotSource=pivotTarget=pivotBuffer;
2533 errorCode=U_ZERO_ERROR; 2535 errorCode=U_ZERO_ERROR;
2534 ucnv_convertEx(cnv, utf8Cnv, 2536 ucnv_convertEx(cnv, utf8Cnv,
2535 &target, output+sizeof(output), 2537 &target, output+sizeof(output),
2536 &source, utf8+utf8Length, 2538 &source, utf8+utf8Length,
2537 pivotBuffer, &pivotSource, &pivotTarget, pivotBuffer+LENG THOF(pivotBuffer), 2539 pivotBuffer, &pivotSource, &pivotTarget, pivotBuffer+UPRV _LENGTHOF(pivotBuffer),
2538 TRUE, TRUE, /* reset & flush */ 2540 TRUE, TRUE, /* reset & flush */
2539 &errorCode); 2541 &errorCode);
2540 outputLength=(int32_t)(target-output); 2542 outputLength=(int32_t)(target-output);
2541 (void)outputLength; /* Suppress set but not used warning. */ 2543 (void)outputLength; /* Suppress set but not used warning. */
2542 if(errorCode!=U_TRUNCATED_CHAR_FOUND || pivotSource!=pivotBuffer) { 2544 if(errorCode!=U_TRUNCATED_CHAR_FOUND || pivotSource!=pivotBuffer) {
2543 log_err("unexpected error %s from %s badUTF8[%ld]\n", u_errorName(er rorCode), converterName, (long)i); 2545 log_err("unexpected error %s from %s badUTF8[%ld]\n", u_errorName(er rorCode), converterName, (long)i);
2544 continue; 2546 continue;
2545 } 2547 }
2546 2548
2547 errorCode=U_ZERO_ERROR; 2549 errorCode=U_ZERO_ERROR;
(...skipping 24 matching lines...) Expand all
2572 * assemble an input string with the test character between each 2574 * assemble an input string with the test character between each
2573 * bad sequence, 2575 * bad sequence,
2574 * and an expected string with repeated test character output 2576 * and an expected string with repeated test character output
2575 */ 2577 */
2576 memcpy(utf8, charUTF8, charUTF8Length); 2578 memcpy(utf8, charUTF8, charUTF8Length);
2577 utf8Length=charUTF8Length; 2579 utf8Length=charUTF8Length;
2578 2580
2579 memcpy(expect, char0, char0Length); 2581 memcpy(expect, char0, char0Length);
2580 expectLength=char0Length; 2582 expectLength=char0Length;
2581 2583
2582 for(i=0; i<LENGTHOF(badUTF8); ++i) { 2584 for(i=0; i<UPRV_LENGTHOF(badUTF8); ++i) {
2583 int32_t length=strlen(badUTF8[i]); 2585 int32_t length=strlen(badUTF8[i]);
2584 memcpy(utf8+utf8Length, badUTF8[i], length); 2586 memcpy(utf8+utf8Length, badUTF8[i], length);
2585 utf8Length+=length; 2587 utf8Length+=length;
2586 2588
2587 memcpy(utf8+utf8Length, charUTF8, charUTF8Length); 2589 memcpy(utf8+utf8Length, charUTF8, charUTF8Length);
2588 utf8Length+=charUTF8Length; 2590 utf8Length+=charUTF8Length;
2589 2591
2590 memcpy(expect+expectLength, char1, char1Length); 2592 memcpy(expect+expectLength, char1, char1Length);
2591 expectLength+=char1Length; 2593 expectLength+=char1Length;
2592 } 2594 }
(...skipping 29 matching lines...) Expand all
2622 char charUTF8[4], char0[8], char1[8]; 2624 char charUTF8[4], char0[8], char1[8];
2623 int32_t charUTF8Length, char0Length, char1Length; 2625 int32_t charUTF8Length, char0Length, char1Length;
2624 2626
2625 errorCode=U_ZERO_ERROR; 2627 errorCode=U_ZERO_ERROR;
2626 utf8Cnv=ucnv_open("UTF-8", &errorCode); 2628 utf8Cnv=ucnv_open("UTF-8", &errorCode);
2627 if(U_FAILURE(errorCode)) { 2629 if(U_FAILURE(errorCode)) {
2628 log_data_err("unable to open UTF-8 converter - %s\n", u_errorName(errorC ode)); 2630 log_data_err("unable to open UTF-8 converter - %s\n", u_errorName(errorC ode));
2629 return; 2631 return;
2630 } 2632 }
2631 2633
2632 for(i=0; i<LENGTHOF(converterNames); ++i) { 2634 for(i=0; i<UPRV_LENGTHOF(converterNames); ++i) {
2633 errorCode=U_ZERO_ERROR; 2635 errorCode=U_ZERO_ERROR;
2634 cnv=ucnv_open(converterNames[i], &errorCode); 2636 cnv=ucnv_open(converterNames[i], &errorCode);
2635 if(U_FAILURE(errorCode)) { 2637 if(U_FAILURE(errorCode)) {
2636 log_data_err("unable to open %s converter - %s\n", converterNames[i] , u_errorName(errorCode)); 2638 log_data_err("unable to open %s converter - %s\n", converterNames[i] , u_errorName(errorCode));
2637 continue; 2639 continue;
2638 } 2640 }
2639 if(!getTestChar(cnv, converterNames[i], charUTF8, &charUTF8Length, char0 , &char0Length, char1, &char1Length)) { 2641 if(!getTestChar(cnv, converterNames[i], charUTF8, &charUTF8Length, char0 , &char0Length, char1, &char1Length)) {
2640 continue; 2642 continue;
2641 } 2643 }
2642 testFromTruncatedUTF8(utf8Cnv, cnv, converterNames[i], charUTF8, charUTF 8Length, char0, char0Length, char1, char1Length); 2644 testFromTruncatedUTF8(utf8Cnv, cnv, converterNames[i], charUTF8, charUTF 8Length, char0, char0Length, char1, char1Length);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
2681 UChar pivotBuffer[128]; 2683 UChar pivotBuffer[128];
2682 UChar *pivotSource, *pivotTarget; 2684 UChar *pivotSource, *pivotTarget;
2683 2685
2684 errorCode=U_ZERO_ERROR; 2686 errorCode=U_ZERO_ERROR;
2685 utf8Cnv=ucnv_open("UTF-8", &errorCode); 2687 utf8Cnv=ucnv_open("UTF-8", &errorCode);
2686 if(U_FAILURE(errorCode)) { 2688 if(U_FAILURE(errorCode)) {
2687 log_data_err("unable to open UTF-8 converter - %s\n", u_errorName(errorC ode)); 2689 log_data_err("unable to open UTF-8 converter - %s\n", u_errorName(errorC ode));
2688 return; 2690 return;
2689 } 2691 }
2690 2692
2691 for(i=0; i<LENGTHOF(converterNames); ++i) { 2693 for(i=0; i<UPRV_LENGTHOF(converterNames); ++i) {
2692 errorCode=U_ZERO_ERROR; 2694 errorCode=U_ZERO_ERROR;
2693 cnv=ucnv_open(converterNames[i], &errorCode); 2695 cnv=ucnv_open(converterNames[i], &errorCode);
2694 ucnv_setFromUCallBack(cnv, UCNV_FROM_U_CALLBACK_ESCAPE, UCNV_ESCAPE_XML_ DEC, 2696 ucnv_setFromUCallBack(cnv, UCNV_FROM_U_CALLBACK_ESCAPE, UCNV_ESCAPE_XML_ DEC,
2695 NULL, NULL, &errorCode); 2697 NULL, NULL, &errorCode);
2696 if(U_FAILURE(errorCode)) { 2698 if(U_FAILURE(errorCode)) {
2697 log_data_err("unable to open %s converter - %s\n", 2699 log_data_err("unable to open %s converter - %s\n",
2698 converterNames[i], u_errorName(errorCode)); 2700 converterNames[i], u_errorName(errorCode));
2699 continue; 2701 continue;
2700 } 2702 }
2701 src=bad_utf8; 2703 src=bad_utf8;
2702 target=dest; 2704 target=dest;
2703 uprv_memset(dest, 9, sizeof(dest)); 2705 uprv_memset(dest, 9, sizeof(dest));
2704 if(i==LENGTHOF(converterNames)-1) { 2706 if(i==UPRV_LENGTHOF(converterNames)-1) {
2705 /* conversion to UTF-8 yields two U+FFFD directly */ 2707 /* conversion to UTF-8 yields two U+FFFD directly */
2706 expected=twoFFFD; 2708 expected=twoFFFD;
2707 expectedLength=6; 2709 expectedLength=6;
2708 } else { 2710 } else {
2709 /* conversion to a non-Unicode charset yields two NCRs */ 2711 /* conversion to a non-Unicode charset yields two NCRs */
2710 expected=twoNCRs; 2712 expected=twoNCRs;
2711 expectedLength=16; 2713 expectedLength=16;
2712 } 2714 }
2713 pivotBuffer[0]=0; 2715 pivotBuffer[0]=0;
2714 pivotBuffer[1]=1; 2716 pivotBuffer[1]=1;
2715 pivotBuffer[2]=2; 2717 pivotBuffer[2]=2;
2716 pivotSource=pivotTarget=pivotBuffer; 2718 pivotSource=pivotTarget=pivotBuffer;
2717 ucnv_convertEx( 2719 ucnv_convertEx(
2718 cnv, utf8Cnv, 2720 cnv, utf8Cnv,
2719 &target, dest+expectedLength, 2721 &target, dest+expectedLength,
2720 &src, bad_utf8+sizeof(bad_utf8), 2722 &src, bad_utf8+sizeof(bad_utf8),
2721 pivotBuffer, &pivotSource, &pivotTarget, pivotBuffer+LENGTHOF(pivotB uffer), 2723 pivotBuffer, &pivotSource, &pivotTarget, pivotBuffer+UPRV_LENGTHOF(p ivotBuffer),
2722 TRUE, TRUE, &errorCode); 2724 TRUE, TRUE, &errorCode);
2723 if( errorCode!=U_STRING_NOT_TERMINATED_WARNING || src!=bad_utf8+2 || 2725 if( errorCode!=U_STRING_NOT_TERMINATED_WARNING || src!=bad_utf8+2 ||
2724 target!=dest+expectedLength || 0!=uprv_memcmp(dest, expected, expect edLength) || 2726 target!=dest+expectedLength || 0!=uprv_memcmp(dest, expected, expect edLength) ||
2725 dest[expectedLength]!=9 2727 dest[expectedLength]!=9
2726 ) { 2728 ) {
2727 log_err("ucnv_convertEx(UTF-8 C5 F0 -> %s/decimal NCRs) failed\n", c onverterNames[i]); 2729 log_err("ucnv_convertEx(UTF-8 C5 F0 -> %s/decimal NCRs) failed\n", c onverterNames[i]);
2728 } 2730 }
2729 ucnv_close(cnv); 2731 ucnv_close(cnv);
2730 } 2732 }
2731 ucnv_close(utf8Cnv); 2733 ucnv_close(utf8Cnv);
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
2902 { 3, "LMBCS-6"}, 2904 { 3, "LMBCS-6"},
2903 { 3, "LMBCS-8"}, 2905 { 3, "LMBCS-8"},
2904 { 3, "LMBCS-11"}, 2906 { 3, "LMBCS-11"},
2905 { 3, "LMBCS-16"}, 2907 { 3, "LMBCS-16"},
2906 { 3, "LMBCS-17"}, 2908 { 3, "LMBCS-17"},
2907 { 3, "LMBCS-18"}, 2909 { 3, "LMBCS-18"},
2908 { 3, "LMBCS-19"} 2910 { 3, "LMBCS-19"}
2909 }; 2911 };
2910 int32_t idx; 2912 int32_t idx;
2911 2913
2912 for (idx = 0; idx < LENGTHOF(converter); idx++) { 2914 for (idx = 0; idx < UPRV_LENGTHOF(converter); idx++) {
2913 UErrorCode status = U_ZERO_ERROR; 2915 UErrorCode status = U_ZERO_ERROR;
2914 UConverter *cnv = cnv_open(converter[idx].name, &status); 2916 UConverter *cnv = cnv_open(converter[idx].name, &status);
2915 if (U_FAILURE(status)) { 2917 if (U_FAILURE(status)) {
2916 continue; 2918 continue;
2917 } 2919 }
2918 if (converter[idx].maxSize != ucnv_getMaxCharSize(cnv)) { 2920 if (converter[idx].maxSize != ucnv_getMaxCharSize(cnv)) {
2919 log_err("error: ucnv_getMaxCharSize(%s) expected %d, got %d\n", 2921 log_err("error: ucnv_getMaxCharSize(%s) expected %d, got %d\n",
2920 converter[idx].name, converter[idx].maxSize, ucnv_getMaxCharSize (cnv)); 2922 converter[idx].name, converter[idx].maxSize, ucnv_getMaxCharSize (cnv));
2921 } 2923 }
2922 ucnv_close(cnv); 2924 ucnv_close(cnv);
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
3064 3066
3065 pc=strstr(swappedName, UCNV_SWAP_LFNL_OPTION_STRING); 3067 pc=strstr(swappedName, UCNV_SWAP_LFNL_OPTION_STRING);
3066 if(swap != (pc!=NULL)) { 3068 if(swap != (pc!=NULL)) {
3067 log_err("TestEBCDICSwapLFNL error: ucnv_getName(%s,swaplfnl)=%s should ( %d) contain 'swaplfnl'\n", name, swappedName, swap); 3069 log_err("TestEBCDICSwapLFNL error: ucnv_getName(%s,swaplfnl)=%s should ( %d) contain 'swaplfnl'\n", name, swappedName, swap);
3068 goto cleanup; 3070 goto cleanup;
3069 } 3071 }
3070 3072
3071 /* convert to EBCDIC */ 3073 /* convert to EBCDIC */
3072 pcu=text; 3074 pcu=text;
3073 pc=normal; 3075 pc=normal;
3074 ucnv_fromUnicode(cnv, &pc, normal+LENGTHOF(normal), &pcu, text+LENGTHOF(text ), NULL, TRUE, &errorCode); 3076 ucnv_fromUnicode(cnv, &pc, normal+UPRV_LENGTHOF(normal), &pcu, text+UPRV_LEN GTHOF(text), NULL, TRUE, &errorCode);
3075 normalLength=(int32_t)(pc-normal); 3077 normalLength=(int32_t)(pc-normal);
3076 3078
3077 pcu=text; 3079 pcu=text;
3078 pc=swapped; 3080 pc=swapped;
3079 ucnv_fromUnicode(swapCnv, &pc, swapped+LENGTHOF(swapped), &pcu, text+LENGTHO F(text), NULL, TRUE, &errorCode); 3081 ucnv_fromUnicode(swapCnv, &pc, swapped+UPRV_LENGTHOF(swapped), &pcu, text+UP RV_LENGTHOF(text), NULL, TRUE, &errorCode);
3080 swappedLength=(int32_t)(pc-swapped); 3082 swappedLength=(int32_t)(pc-swapped);
3081 3083
3082 if(U_FAILURE(errorCode)) { 3084 if(U_FAILURE(errorCode)) {
3083 log_err("TestEBCDICSwapLFNL error converting to %s - (%s)\n", name, u_er rorName(errorCode)); 3085 log_err("TestEBCDICSwapLFNL error converting to %s - (%s)\n", name, u_er rorName(errorCode));
3084 goto cleanup; 3086 goto cleanup;
3085 } 3087 }
3086 3088
3087 /* compare EBCDIC output */ 3089 /* compare EBCDIC output */
3088 if(normalLength!=swappedLength) { 3090 if(normalLength!=swappedLength) {
3089 log_err("TestEBCDICSwapLFNL error converting to %s - output lengths %d v s. %d\n", name, normalLength, swappedLength); 3091 log_err("TestEBCDICSwapLFNL error converting to %s - output lengths %d v s. %d\n", name, normalLength, swappedLength);
(...skipping 12 matching lines...) Expand all
3102 3104
3103 if(c!=swapped[i]) { 3105 if(c!=swapped[i]) {
3104 log_err("TestEBCDICSwapLFNL error converting to %s - did not swap pr operly, output[%d]=0x%02x\n", name, i, (uint8_t)swapped[i]); 3106 log_err("TestEBCDICSwapLFNL error converting to %s - did not swap pr operly, output[%d]=0x%02x\n", name, i, (uint8_t)swapped[i]);
3105 goto cleanup; 3107 goto cleanup;
3106 } 3108 }
3107 } 3109 }
3108 3110
3109 /* convert back to Unicode (may not roundtrip) */ 3111 /* convert back to Unicode (may not roundtrip) */
3110 pc=normal; 3112 pc=normal;
3111 pu=uNormal; 3113 pu=uNormal;
3112 ucnv_toUnicode(cnv, &pu, uNormal+LENGTHOF(uNormal), (const char **)&pc, norm al+normalLength, NULL, TRUE, &errorCode); 3114 ucnv_toUnicode(cnv, &pu, uNormal+UPRV_LENGTHOF(uNormal), (const char **)&pc, normal+normalLength, NULL, TRUE, &errorCode);
3113 normalLength=(int32_t)(pu-uNormal); 3115 normalLength=(int32_t)(pu-uNormal);
3114 3116
3115 pc=normal; 3117 pc=normal;
3116 pu=uSwapped; 3118 pu=uSwapped;
3117 ucnv_toUnicode(swapCnv, &pu, uSwapped+LENGTHOF(uSwapped), (const char **)&pc , normal+swappedLength, NULL, TRUE, &errorCode); 3119 ucnv_toUnicode(swapCnv, &pu, uSwapped+UPRV_LENGTHOF(uSwapped), (const char * *)&pc, normal+swappedLength, NULL, TRUE, &errorCode);
3118 swappedLength=(int32_t)(pu-uSwapped); 3120 swappedLength=(int32_t)(pu-uSwapped);
3119 3121
3120 if(U_FAILURE(errorCode)) { 3122 if(U_FAILURE(errorCode)) {
3121 log_err("TestEBCDICSwapLFNL error converting from %s - (%s)\n", name, u_ errorName(errorCode)); 3123 log_err("TestEBCDICSwapLFNL error converting from %s - (%s)\n", name, u_ errorName(errorCode));
3122 goto cleanup; 3124 goto cleanup;
3123 } 3125 }
3124 3126
3125 /* compare EBCDIC output */ 3127 /* compare EBCDIC output */
3126 if(normalLength!=swappedLength) { 3128 if(normalLength!=swappedLength) {
3127 log_err("TestEBCDICSwapLFNL error converting from %s - output lengths %d vs. %d\n", name, normalLength, swappedLength); 3129 log_err("TestEBCDICSwapLFNL error converting from %s - output lengths %d vs. %d\n", name, normalLength, swappedLength);
(...skipping 30 matching lines...) Expand all
3158 } tests[]={ 3160 } tests[]={
3159 { "ibm-37", TRUE }, 3161 { "ibm-37", TRUE },
3160 { "ibm-1047", TRUE }, 3162 { "ibm-1047", TRUE },
3161 { "ibm-1140", TRUE }, 3163 { "ibm-1140", TRUE },
3162 { "ibm-930", TRUE }, 3164 { "ibm-930", TRUE },
3163 { "iso-8859-3", FALSE } 3165 { "iso-8859-3", FALSE }
3164 }; 3166 };
3165 3167
3166 int i; 3168 int i;
3167 3169
3168 for(i=0; i<LENGTHOF(tests); ++i) { 3170 for(i=0; i<UPRV_LENGTHOF(tests); ++i) {
3169 testSwap(tests[i].name, tests[i].swap); 3171 testSwap(tests[i].name, tests[i].swap);
3170 } 3172 }
3171 } 3173 }
3172 #else 3174 #else
3173 static void 3175 static void
3174 TestEBCDICSwapLFNL() { 3176 TestEBCDICSwapLFNL() {
3175 /* test nothing... */ 3177 /* test nothing... */
3176 } 3178 }
3177 #endif 3179 #endif
3178 3180
3179 static const UVersionInfo ICU_34 = {3,4,0,0};
3180
3181 static void TestFromUCountPending(){ 3181 static void TestFromUCountPending(){
3182 #if !UCONFIG_NO_LEGACY_CONVERSION 3182 #if !UCONFIG_NO_LEGACY_CONVERSION
3183 UErrorCode status = U_ZERO_ERROR; 3183 UErrorCode status = U_ZERO_ERROR;
3184 /* const UChar expectedUnicode[] = { 0x20ac, 0x0005, 0x0006, 0x000b, 0xdbc 4, 0xde34, 0xd84d, 0xdc56, 0xfffd}; */ 3184 /* const UChar expectedUnicode[] = { 0x20ac, 0x0005, 0x0006, 0x000b, 0xdbc 4, 0xde34, 0xd84d, 0xdc56, 0xfffd}; */
3185 static const struct { 3185 static const struct {
3186 UChar input[6]; 3186 UChar input[6];
3187 int32_t len; 3187 int32_t len;
3188 int32_t exp; 3188 int32_t exp;
3189 }fromUnicodeTests[] = { 3189 }fromUnicodeTests[] = {
3190 /*m:n conversion*/ 3190 /*m:n conversion*/
3191 {{0xdbc4},1,1}, 3191 {{0xdbc4},1,1},
3192 {{ 0xdbc4, 0xde34, 0xd84d},3,1}, 3192 {{ 0xdbc4, 0xde34, 0xd84d},3,1},
3193 {{ 0xdbc4, 0xde34, 0xd900},3,3}, 3193 {{ 0xdbc4, 0xde34, 0xd900},3,3},
3194 }; 3194 };
3195 int i; 3195 int i;
3196 UConverter* cnv = ucnv_openPackage(loadTestData(&status), "test3", &status); 3196 UConverter* cnv = ucnv_openPackage(loadTestData(&status), "test3", &status);
3197 if(U_FAILURE(status)){ 3197 if(U_FAILURE(status)){
3198 log_data_err("Could not create converter for test3. Error: %s\n", u_erro rName(status)); 3198 log_data_err("Could not create converter for test3. Error: %s\n", u_erro rName(status));
3199 return; 3199 return;
3200 } 3200 }
3201 for(i=0; i<LENGTHOF(fromUnicodeTests); ++i) { 3201 for(i=0; i<UPRV_LENGTHOF(fromUnicodeTests); ++i) {
3202 char tgt[10]; 3202 char tgt[10];
3203 char* target = tgt; 3203 char* target = tgt;
3204 char* targetLimit = target + 10; 3204 char* targetLimit = target + 10;
3205 const UChar* source = fromUnicodeTests[i].input; 3205 const UChar* source = fromUnicodeTests[i].input;
3206 const UChar* sourceLimit = source + fromUnicodeTests[i].len; 3206 const UChar* sourceLimit = source + fromUnicodeTests[i].len;
3207 int32_t len = 0; 3207 int32_t len = 0;
3208 ucnv_reset(cnv); 3208 ucnv_reset(cnv);
3209 ucnv_fromUnicode(cnv,&target, targetLimit, &source, sourceLimit, NULL, F ALSE, &status); 3209 ucnv_fromUnicode(cnv,&target, targetLimit, &source, sourceLimit, NULL, F ALSE, &status);
3210 len = ucnv_fromUCountPending(cnv, &status); 3210 len = ucnv_fromUCountPending(cnv, &status);
3211 if(U_FAILURE(status)){ 3211 if(U_FAILURE(status)){
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
3297 }; 3297 };
3298 3298
3299 int i; 3299 int i;
3300 UConverterToUCallback *oldToUAction= NULL; 3300 UConverterToUCallback *oldToUAction= NULL;
3301 UConverter* cnv = ucnv_openPackage(loadTestData(&status), "test3", &status); 3301 UConverter* cnv = ucnv_openPackage(loadTestData(&status), "test3", &status);
3302 if(U_FAILURE(status)){ 3302 if(U_FAILURE(status)){
3303 log_data_err("Could not create converter for test3. Error: %s\n", u_erro rName(status)); 3303 log_data_err("Could not create converter for test3. Error: %s\n", u_erro rName(status));
3304 return; 3304 return;
3305 } 3305 }
3306 ucnv_setToUCallBack(cnv, UCNV_TO_U_CALLBACK_STOP, NULL, oldToUAction, NULL, &status); 3306 ucnv_setToUCallBack(cnv, UCNV_TO_U_CALLBACK_STOP, NULL, oldToUAction, NULL, &status);
3307 for(i=0; i<LENGTHOF(toUnicodeTests); ++i) { 3307 for(i=0; i<UPRV_LENGTHOF(toUnicodeTests); ++i) {
3308 UChar tgt[20]; 3308 UChar tgt[20];
3309 UChar* target = tgt; 3309 UChar* target = tgt;
3310 UChar* targetLimit = target + 20; 3310 UChar* targetLimit = target + 20;
3311 const char* source = toUnicodeTests[i].input; 3311 const char* source = toUnicodeTests[i].input;
3312 const char* sourceLimit = source + toUnicodeTests[i].len; 3312 const char* sourceLimit = source + toUnicodeTests[i].len;
3313 int32_t len = 0; 3313 int32_t len = 0;
3314 ucnv_reset(cnv); 3314 ucnv_reset(cnv);
3315 ucnv_toUnicode(cnv, &target, targetLimit, &source, sourceLimit, NULL, FA LSE, &status); 3315 ucnv_toUnicode(cnv, &target, targetLimit, &source, sourceLimit, NULL, FA LSE, &status);
3316 len = ucnv_toUCountPending(cnv,&status); 3316 len = ucnv_toUCountPending(cnv,&status);
3317 if(U_FAILURE(status)){ 3317 if(U_FAILURE(status)){
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
3535 log_err("ucnv_fromUChars(UTF-32, U+D900) did not write a BOM\n"); 3535 log_err("ucnv_fromUChars(UTF-32, U+D900) did not write a BOM\n");
3536 } 3536 }
3537 3537
3538 /* Simple API test of ucnv_setSubstString() + ucnv_getSubstChars(). */ 3538 /* Simple API test of ucnv_setSubstString() + ucnv_getSubstChars(). */
3539 errorCode=U_ZERO_ERROR; 3539 errorCode=U_ZERO_ERROR;
3540 cnv=ucnv_open("ISO-8859-1", &errorCode); 3540 cnv=ucnv_open("ISO-8859-1", &errorCode);
3541 if(U_FAILURE(errorCode)) { 3541 if(U_FAILURE(errorCode)) {
3542 log_data_err("ucnv_open(ISO-8859-1) failed - %s\n", u_errorName(errorCod e)); 3542 log_data_err("ucnv_open(ISO-8859-1) failed - %s\n", u_errorName(errorCod e));
3543 return; 3543 return;
3544 } 3544 }
3545 ucnv_setSubstString(cnv, sub, LENGTHOF(sub), &errorCode); 3545 ucnv_setSubstString(cnv, sub, UPRV_LENGTHOF(sub), &errorCode);
3546 if(U_FAILURE(errorCode)) { 3546 if(U_FAILURE(errorCode)) {
3547 log_err("ucnv_setSubstString(ISO-8859-1, sub[5]) failed - %s\n", u_error Name(errorCode)); 3547 log_err("ucnv_setSubstString(ISO-8859-1, sub[5]) failed - %s\n", u_error Name(errorCode));
3548 } else { 3548 } else {
3549 len8 = sizeof(buffer); 3549 len8 = sizeof(buffer);
3550 ucnv_getSubstChars(cnv, buffer, &len8, &errorCode); 3550 ucnv_getSubstChars(cnv, buffer, &len8, &errorCode);
3551 /* Stateless converter, we expect the string converted to charset bytes. */ 3551 /* Stateless converter, we expect the string converted to charset bytes. */
3552 if(U_FAILURE(errorCode) || len8!=sizeof(subChars) || 0!=uprv_memcmp(buff er, subChars, len8)) { 3552 if(U_FAILURE(errorCode) || len8!=sizeof(subChars) || 0!=uprv_memcmp(buff er, subChars, len8)) {
3553 log_err("ucnv_getSubstChars(ucnv_setSubstString(ISO-8859-1, sub[5])) failed - %s\n", u_errorName(errorCode)); 3553 log_err("ucnv_getSubstChars(ucnv_setSubstString(ISO-8859-1, sub[5])) failed - %s\n", u_errorName(errorCode));
3554 } 3554 }
3555 } 3555 }
3556 ucnv_close(cnv); 3556 ucnv_close(cnv);
3557 3557
3558 #if !UCONFIG_NO_LEGACY_CONVERSION 3558 #if !UCONFIG_NO_LEGACY_CONVERSION
3559 errorCode=U_ZERO_ERROR; 3559 errorCode=U_ZERO_ERROR;
3560 cnv=ucnv_open("HZ", &errorCode); 3560 cnv=ucnv_open("HZ", &errorCode);
3561 if(U_FAILURE(errorCode)) { 3561 if(U_FAILURE(errorCode)) {
3562 log_data_err("ucnv_open(HZ) failed - %s\n", u_errorName(errorCode)); 3562 log_data_err("ucnv_open(HZ) failed - %s\n", u_errorName(errorCode));
3563 return; 3563 return;
3564 } 3564 }
3565 ucnv_setSubstString(cnv, sub, LENGTHOF(sub), &errorCode); 3565 ucnv_setSubstString(cnv, sub, UPRV_LENGTHOF(sub), &errorCode);
3566 if(U_FAILURE(errorCode)) { 3566 if(U_FAILURE(errorCode)) {
3567 log_err("ucnv_setSubstString(HZ, sub[5]) failed - %s\n", u_errorName(err orCode)); 3567 log_err("ucnv_setSubstString(HZ, sub[5]) failed - %s\n", u_errorName(err orCode));
3568 } else { 3568 } else {
3569 len8 = sizeof(buffer); 3569 len8 = sizeof(buffer);
3570 ucnv_getSubstChars(cnv, buffer, &len8, &errorCode); 3570 ucnv_getSubstChars(cnv, buffer, &len8, &errorCode);
3571 /* Stateful converter, we expect that the Unicode string was set and tha t we get an empty char * string now. */ 3571 /* Stateful converter, we expect that the Unicode string was set and tha t we get an empty char * string now. */
3572 if(U_FAILURE(errorCode) || len8!=0) { 3572 if(U_FAILURE(errorCode) || len8!=0) {
3573 log_err("ucnv_getSubstChars(ucnv_setSubstString(HZ, sub[5])) failed - %s\n", u_errorName(errorCode)); 3573 log_err("ucnv_getSubstChars(ucnv_setSubstString(HZ, sub[5])) failed - %s\n", u_errorName(errorCode));
3574 } 3574 }
3575 } 3575 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
3640 static void TestGetName() { 3640 static void TestGetName() {
3641 static const char *const names[] = { 3641 static const char *const names[] = {
3642 "Unicode", "UTF-16", 3642 "Unicode", "UTF-16",
3643 "UnicodeBigUnmarked", "UTF-16BE", 3643 "UnicodeBigUnmarked", "UTF-16BE",
3644 "UnicodeBig", "UTF-16BE,version=1", 3644 "UnicodeBig", "UTF-16BE,version=1",
3645 "UnicodeLittleUnmarked", "UTF-16LE", 3645 "UnicodeLittleUnmarked", "UTF-16LE",
3646 "UnicodeLittle", "UTF-16LE,version=1", 3646 "UnicodeLittle", "UTF-16LE,version=1",
3647 "x-UTF-16LE-BOM", "UTF-16LE,version=1" 3647 "x-UTF-16LE-BOM", "UTF-16LE,version=1"
3648 }; 3648 };
3649 int32_t i; 3649 int32_t i;
3650 for(i = 0; i < LENGTHOF(names); i += 2) { 3650 for(i = 0; i < UPRV_LENGTHOF(names); i += 2) {
3651 UErrorCode errorCode = U_ZERO_ERROR; 3651 UErrorCode errorCode = U_ZERO_ERROR;
3652 UConverter *cnv = ucnv_open(names[i], &errorCode); 3652 UConverter *cnv = ucnv_open(names[i], &errorCode);
3653 if(U_SUCCESS(errorCode)) { 3653 if(U_SUCCESS(errorCode)) {
3654 const char *name = ucnv_getName(cnv, &errorCode); 3654 const char *name = ucnv_getName(cnv, &errorCode);
3655 if(U_FAILURE(errorCode) || 0 != strcmp(name, names[i+1])) { 3655 if(U_FAILURE(errorCode) || 0 != strcmp(name, names[i+1])) {
3656 log_err("ucnv_getName(%s) = %s != %s -- %s\n", 3656 log_err("ucnv_getName(%s) = %s != %s -- %s\n",
3657 names[i], name, names[i+1], u_errorName(errorCode)); 3657 names[i], name, names[i+1], u_errorName(errorCode));
3658 } 3658 }
3659 ucnv_close(cnv); 3659 ucnv_close(cnv);
3660 } 3660 }
(...skipping 22 matching lines...) Expand all
3683 { 2, 0, 0x61 }, 3683 { 2, 0, 0x61 },
3684 { 4, 0xfe, 0xff, 0, 0x61 }, 3684 { 4, 0xfe, 0xff, 0, 0x61 },
3685 3685
3686 { 2, 0x61, 0 }, 3686 { 2, 0x61, 0 },
3687 { 4, 0xff, 0xfe, 0x61, 0 } 3687 { 4, 0xff, 0xfe, 0x61, 0 }
3688 }; 3688 };
3689 3689
3690 char bytes[10]; 3690 char bytes[10];
3691 int32_t i; 3691 int32_t i;
3692 3692
3693 for(i = 0; i < LENGTHOF(names); ++i) { 3693 for(i = 0; i < UPRV_LENGTHOF(names); ++i) {
3694 UErrorCode errorCode = U_ZERO_ERROR; 3694 UErrorCode errorCode = U_ZERO_ERROR;
3695 UConverter *cnv = ucnv_open(names[i], &errorCode); 3695 UConverter *cnv = ucnv_open(names[i], &errorCode);
3696 int32_t length = 0; 3696 int32_t length = 0;
3697 const uint8_t *exp = expected[i]; 3697 const uint8_t *exp = expected[i];
3698 if (U_FAILURE(errorCode)) { 3698 if (U_FAILURE(errorCode)) {
3699 log_err_status(errorCode, "Unable to open converter: %s got error cod e: %s\n", names[i], u_errorName(errorCode)); 3699 log_err_status(errorCode, "Unable to open converter: %s got error cod e: %s\n", names[i], u_errorName(errorCode));
3700 continue; 3700 continue;
3701 } 3701 }
3702 length = ucnv_fromUChars(cnv, bytes, (int32_t)sizeof(bytes), a16, 1, &er rorCode); 3702 length = ucnv_fromUChars(cnv, bytes, (int32_t)sizeof(bytes), a16, 1, &er rorCode);
3703 3703
3704 if(U_FAILURE(errorCode) || length != exp[0] || 0 != memcmp(bytes, exp+1, length)) { 3704 if(U_FAILURE(errorCode) || length != exp[0] || 0 != memcmp(bytes, exp+1, length)) {
3705 log_err("unexpected %s BOM writing behavior -- %s\n", 3705 log_err("unexpected %s BOM writing behavior -- %s\n",
3706 names[i], u_errorName(errorCode)); 3706 names[i], u_errorName(errorCode));
3707 } 3707 }
3708 ucnv_close(cnv); 3708 ucnv_close(cnv);
3709 } 3709 }
3710 } 3710 }
OLDNEW
« no previous file with comments | « source/test/cintltst/ccaltst.c ('k') | source/test/cintltst/cdateintervalformattest.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698