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

Side by Side Diff: source/test/cintltst/udatatst.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/ucnvseltst.c ('k') | source/test/cintltst/udatpg_test.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) 1998-2013, International Business Machines Corporation and 3 * Copyright (c) 1998-2014, International Business Machines Corporation and
4 * others. All Rights Reserved. 4 * others. All Rights Reserved.
5 ********************************************************************/ 5 ********************************************************************/
6 /* 6 /*
7 * File test.c 7 * File udatatst.c
8 * 8 *
9 * Modification History: 9 * Modification History:
10 * 10 *
11 * Date Name Description 11 * Date Name Description
12 * 02/22/2000 Madhu Creation 12 * 02/22/2000 Madhu Creation
13 ****************************************************************************** 13 ******************************************************************************
14 */ 14 */
15 15
16 #include "unicode/utypes.h" 16 #include "unicode/utypes.h"
17 #include "unicode/putil.h" 17 #include "unicode/putil.h"
18 #include "unicode/udata.h" 18 #include "unicode/udata.h"
19 #include "unicode/ucal.h"
19 #include "unicode/uchar.h" 20 #include "unicode/uchar.h"
20 #include "unicode/ucnv.h" 21 #include "unicode/ucnv.h"
21 #include "unicode/ures.h" 22 #include "unicode/ures.h"
22 #include "unicode/ustring.h" 23 #include "unicode/ustring.h"
23 #include "unicode/uclean.h" 24 #include "unicode/uclean.h"
24 #include "cmemory.h" 25 #include "cmemory.h"
25 #include "cstring.h" 26 #include "cstring.h"
26 #include "filestrm.h" 27 #include "filestrm.h"
27 #include "udatamem.h" 28 #include "udatamem.h"
28 #include "cintltst.h" 29 #include "cintltst.h"
(...skipping 19 matching lines...) Expand all
48 /* swapping implementation in i18n */ 49 /* swapping implementation in i18n */
49 #include "uspoof_impl.h" 50 #include "uspoof_impl.h"
50 51
51 U_CAPI int32_t U_EXPORT2 52 U_CAPI int32_t U_EXPORT2
52 unorm2_swap(const UDataSwapper *ds, 53 unorm2_swap(const UDataSwapper *ds,
53 const void *inData, int32_t length, void *outData, 54 const void *inData, int32_t length, void *outData,
54 UErrorCode *pErrorCode); 55 UErrorCode *pErrorCode);
55 56
56 /* other definitions and prototypes */ 57 /* other definitions and prototypes */
57 58
58 #define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
59
60 #if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION 59 #if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
61 static void TestUDataOpen(void); 60 static void TestUDataOpen(void);
62 static void TestUDataOpenChoiceDemo1(void); 61 static void TestUDataOpenChoiceDemo1(void);
63 static void TestUDataOpenChoiceDemo2(void); 62 static void TestUDataOpenChoiceDemo2(void);
64 static void TestUDataGetInfo(void); 63 static void TestUDataGetInfo(void);
65 static void TestUDataGetMemory(void); 64 static void TestUDataGetMemory(void);
66 static void TestErrorConditions(void); 65 static void TestErrorConditions(void);
67 static void TestAppData(void); 66 static void TestAppData(void);
68 static void TestSwapData(void); 67 static void TestSwapData(void);
69 #endif 68 #endif
70 static void TestUDataSetAppData(void); 69 static void TestUDataSetAppData(void);
71 static void TestICUDataName(void); 70 static void TestICUDataName(void);
72 static void PointerTableOfContents(void); 71 static void PointerTableOfContents(void);
73 static void SetBadCommonData(void); 72 static void SetBadCommonData(void);
74 static void TestUDataFileAccess(void); 73 static void TestUDataFileAccess(void);
75 74 #if !UCONFIG_NO_FORMATTING && !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSI ON
75 static void TestTZDataDir(void);
76 #endif
76 77
77 void addUDataTest(TestNode** root); 78 void addUDataTest(TestNode** root);
78 79
79 void 80 void
80 addUDataTest(TestNode** root) 81 addUDataTest(TestNode** root)
81 { 82 {
82 #if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION 83 #if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
83 addTest(root, &TestUDataOpen, "udatatst/TestUDataOpen" ); 84 addTest(root, &TestUDataOpen, "udatatst/TestUDataOpen" );
84 addTest(root, &TestUDataOpenChoiceDemo1, "udatatst/TestUDataOpenChoiceDemo1" ); 85 addTest(root, &TestUDataOpenChoiceDemo1, "udatatst/TestUDataOpenChoiceDemo1" );
85 addTest(root, &TestUDataOpenChoiceDemo2, "udatatst/TestUDataOpenChoiceDemo2" ); 86 addTest(root, &TestUDataOpenChoiceDemo2, "udatatst/TestUDataOpenChoiceDemo2" );
86 addTest(root, &TestUDataGetInfo, "udatatst/TestUDataGetInfo" ); 87 addTest(root, &TestUDataGetInfo, "udatatst/TestUDataGetInfo" );
87 addTest(root, &TestUDataGetMemory, "udatatst/TestUDataGetMemory" ); 88 addTest(root, &TestUDataGetMemory, "udatatst/TestUDataGetMemory" );
88 addTest(root, &TestErrorConditions, "udatatst/TestErrorConditions"); 89 addTest(root, &TestErrorConditions, "udatatst/TestErrorConditions");
89 addTest(root, &TestAppData, "udatatst/TestAppData" ); 90 addTest(root, &TestAppData, "udatatst/TestAppData" );
90 addTest(root, &TestSwapData, "udatatst/TestSwapData" ); 91 addTest(root, &TestSwapData, "udatatst/TestSwapData" );
91 #endif 92 #endif
92 addTest(root, &TestUDataSetAppData, "udatatst/TestUDataSetAppData" ); 93 addTest(root, &TestUDataSetAppData, "udatatst/TestUDataSetAppData" );
93 addTest(root, &TestICUDataName, "udatatst/TestICUDataName" ); 94 addTest(root, &TestICUDataName, "udatatst/TestICUDataName" );
94 addTest(root, &PointerTableOfContents, "udatatst/PointerTableOfContents" ); 95 addTest(root, &PointerTableOfContents, "udatatst/PointerTableOfContents" );
95 addTest(root, &SetBadCommonData, "udatatst/SetBadCommonData" ); 96 addTest(root, &SetBadCommonData, "udatatst/SetBadCommonData" );
96 addTest(root, &TestUDataFileAccess, "udatatst/TestUDataFileAccess" ); 97 addTest(root, &TestUDataFileAccess, "udatatst/TestUDataFileAccess" );
98 #if !UCONFIG_NO_FORMATTING && !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSI ON
99 addTest(root, &TestTZDataDir, "udatatst/TestTZDataDir" );
100 #endif
97 } 101 }
98 102
99 #if 0 103 #if 0
100 static void lots_of_mallocs() 104 static void lots_of_mallocs()
101 { 105 {
102 int q; 106 int q;
103 for(q=1;q<100;q++) 107 for(q=1;q<100;q++)
104 { 108 {
105 free(malloc(q)); 109 free(malloc(q));
106 malloc(q*2); 110 malloc(q*2);
(...skipping 1190 matching lines...) Expand 10 before | Expand all | Expand 10 after
1297 {"*testtable32", "res", ures_swap}, 1301 {"*testtable32", "res", ures_swap},
1298 1302
1299 /* ICU 4.2 resource bundle - data format 1.2 (little-endian ASCII) */ 1303 /* ICU 4.2 resource bundle - data format 1.2 (little-endian ASCII) */
1300 {"*old_l_testtypes", "res", ures_swap}, 1304 {"*old_l_testtypes", "res", ures_swap},
1301 /* same for big-endian EBCDIC */ 1305 /* same for big-endian EBCDIC */
1302 {"*old_e_testtypes", "res", ures_swap}, 1306 {"*old_e_testtypes", "res", ures_swap},
1303 1307
1304 #if !UCONFIG_NO_COLLATION 1308 #if !UCONFIG_NO_COLLATION
1305 /* standalone collation data files */ 1309 /* standalone collation data files */
1306 {"ucadata", "icu", ucol_swap}, 1310 {"ucadata", "icu", ucol_swap},
1311 #if 0
1312 /* Starting with ICU 53, the "inverse UCA" data is integrated into ucadata.i cu. */
1307 {"invuca", "icu", ucol_swapInverseUCA}, 1313 {"invuca", "icu", ucol_swapInverseUCA},
1308 #endif 1314 #endif
1315 #endif
1309 1316
1310 #if !UCONFIG_NO_LEGACY_CONVERSION 1317 #if !UCONFIG_NO_LEGACY_CONVERSION
1311 /* conversion table files */ 1318 /* conversion table files */
1312 1319
1313 /* SBCS conversion table file without extension */ 1320 /* SBCS conversion table file without extension */
1314 {"ibm-913_P100-2000", "cnv", ucnv_swap}, 1321 {"ibm-913_P100-2000", "cnv", ucnv_swap},
1315 /* EBCDIC_STATEFUL conversion table file with extension */ 1322 /* EBCDIC_STATEFUL conversion table file with extension */
1316 {"ibm-1390_P110-2003", "cnv", ucnv_swap}, 1323 {"ibm-1390_P110-2003", "cnv", ucnv_swap},
1317 /* DBCS extension-only conversion table file */ 1324 /* DBCS extension-only conversion table file */
1318 {"ibm-16684_P110-2003", "cnv", ucnv_swap}, 1325 {"ibm-16684_P110-2003", "cnv", ucnv_swap},
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1357 /* 1364 /*
1358 * Starting with ICU4C 3.4, the core Unicode properties files 1365 * Starting with ICU4C 3.4, the core Unicode properties files
1359 * (uprops.icu, ucase.icu, ubidi.icu, unorm.icu) 1366 * (uprops.icu, ucase.icu, ubidi.icu, unorm.icu)
1360 * are hardcoded in the common DLL and therefore not included 1367 * are hardcoded in the common DLL and therefore not included
1361 * in the data package any more. 1368 * in the data package any more.
1362 * Their swapping code is moved from the common DLL to the icuswap tool so t hat 1369 * Their swapping code is moved from the common DLL to the icuswap tool so t hat
1363 * we need not jump through hoops (like adding snapshots of these files 1370 * we need not jump through hoops (like adding snapshots of these files
1364 * to testdata) for code coverage in tests. 1371 * to testdata) for code coverage in tests.
1365 * See Jitterbug 4497. 1372 * See Jitterbug 4497.
1366 * 1373 *
1367 * ICU4C 4.4 adds normalization data files again, e.g., nfc.nrm. 1374 * ICU4C 4.4 adds normalization data files again, e.g., nfkc.nrm.
1368 */ 1375 */
1369 {"uprops", "icu", uprops_swap}, 1376 {"uprops", "icu", uprops_swap},
1370 {"ucase", "icu", ucase_swap}, 1377 {"ucase", "icu", ucase_swap},
1371 {"ubidi", "icu", ubidi_swap}, 1378 {"ubidi", "icu", ubidi_swap},
1372 #endif 1379 #endif
1373 #if !UCONFIG_NO_NORMALIZATION && !UCONFIG_ONLY_COLLATION 1380 #if !UCONFIG_NO_NORMALIZATION && !UCONFIG_ONLY_COLLATION
1374 {"nfc", "nrm", unorm2_swap}, 1381 {"nfkc", "nrm", unorm2_swap},
1375 {"confusables", "cfu", uspoof_swap}, 1382 #if !UCONFIG_NO_REGULAR_EXPRESSIONS
1383 {"confusables", "cfu", uspoof_swap}, /* spoof data missing with out regex */
1384 #endif
1385
1376 #endif 1386 #endif
1377 {"unames", "icu", uchar_swapNames} 1387 {"unames", "icu", uchar_swapNames}
1378 /* the last item should not be #if'ed so that it can reliably omit the last comma */ 1388 /* the last item should not be #if'ed so that it can reliably omit the last comma */
1379 }; 1389 };
1380 1390
1381 /* Large enough for the largest swappable data item. */ 1391 /* Large enough for the largest swappable data item. */
1382 #define SWAP_BUFFER_SIZE 1800000 1392 #define SWAP_BUFFER_SIZE 1800000
1383 1393
1384 static void U_CALLCONV 1394 static void U_CALLCONV
1385 printError(void *context, const char *fmt, va_list args) { 1395 printError(void *context, const char *fmt, va_list args) {
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
1669 errorCode=U_ZERO_ERROR; 1679 errorCode=U_ZERO_ERROR;
1670 memset(buffer, 0, sizeof(2*SWAP_BUFFER_SIZE)); 1680 memset(buffer, 0, sizeof(2*SWAP_BUFFER_SIZE));
1671 ds=udata_openSwapperForInputData(buffer, 2*SWAP_BUFFER_SIZE, 1681 ds=udata_openSwapperForInputData(buffer, 2*SWAP_BUFFER_SIZE,
1672 !U_IS_BIG_ENDIAN, U_ASCII_FAMILY, 1682 !U_IS_BIG_ENDIAN, U_ASCII_FAMILY,
1673 &errorCode); 1683 &errorCode);
1674 if (ds != NULL || errorCode != U_UNSUPPORTED_ERROR) { 1684 if (ds != NULL || errorCode != U_UNSUPPORTED_ERROR) {
1675 log_err("udata_openSwapperForInputData should have returned NULL with ba d argument\n", name); 1685 log_err("udata_openSwapperForInputData should have returned NULL with ba d argument\n", name);
1676 } 1686 }
1677 errorCode=U_ZERO_ERROR; 1687 errorCode=U_ZERO_ERROR;
1678 1688
1679 /* Test argument checking. ucol_swapBinary is normally tested via ures_swap, and isn't normally called directly. */ 1689 /* Test argument checking. ucol_swap is normally tested via ures_swap, and i sn't normally called directly. */
1680 #if !UCONFIG_NO_COLLATION 1690 #if !UCONFIG_NO_COLLATION
1681 ucol_swapBinary(NULL, NULL, -1, NULL, NULL); 1691 ucol_swap(NULL, NULL, -1, NULL, &errorCode);
1682 ucol_swapBinary(NULL, NULL, -1, NULL, &errorCode);
1683 if (errorCode != U_ILLEGAL_ARGUMENT_ERROR) { 1692 if (errorCode != U_ILLEGAL_ARGUMENT_ERROR) {
1684 log_err("ucol_swapBinary did not fail as expected\n", name); 1693 log_err("ucol_swap did not fail as expected\n", name);
1685 } 1694 }
1686 errorCode=U_ZERO_ERROR; 1695 errorCode=U_ZERO_ERROR;
1687 #endif 1696 #endif
1688 1697
1689 for(i=0; i<LENGTHOF(swapCases); ++i) { 1698 for(i=0; i<UPRV_LENGTHOF(swapCases); ++i) {
1690 /* build the name for logging */ 1699 /* build the name for logging */
1691 errorCode=U_ZERO_ERROR; 1700 errorCode=U_ZERO_ERROR;
1692 if(swapCases[i].name[0]=='*') { 1701 if(swapCases[i].name[0]=='*') {
1693 pkg=testPath; 1702 pkg=testPath;
1694 nm=swapCases[i].name+1; 1703 nm=swapCases[i].name+1;
1695 uprv_strcpy(name, "testdata"); 1704 uprv_strcpy(name, "testdata");
1696 } else if (uprv_strcmp(swapCases[i].type, "brk")==0 1705 } else if (uprv_strcmp(swapCases[i].type, "brk")==0
1697 || uprv_strcmp(swapCases[i].type, "dict")==0) { 1706 || uprv_strcmp(swapCases[i].type, "dict")==0) {
1698 pkg=U_ICUDATA_BRKITR; 1707 pkg=U_ICUDATA_BRKITR;
1699 nm=swapCases[i].name; 1708 nm=swapCases[i].name;
1700 uprv_strcpy(name, U_ICUDATA_BRKITR); 1709 uprv_strcpy(name, U_ICUDATA_BRKITR);
1710 #if !UCONFIG_NO_COLLATION
1701 } else if (uprv_strcmp(swapCases[i].name, "ucadata")==0 1711 } else if (uprv_strcmp(swapCases[i].name, "ucadata")==0
1702 || uprv_strcmp(swapCases[i].name, "invuca")==0) { 1712 || uprv_strcmp(swapCases[i].name, "invuca")==0) {
1703 pkg=U_ICUDATA_COLL; 1713 pkg=U_ICUDATA_COLL;
1704 nm=swapCases[i].name; 1714 nm=swapCases[i].name;
1705 uprv_strcpy(name, U_ICUDATA_COLL); 1715 uprv_strcpy(name, U_ICUDATA_COLL);
1716 #endif /* !UCONFIG_NO_COLLATION */
1706 } else { 1717 } else {
1707 pkg=NULL; 1718 pkg=NULL;
1708 nm=swapCases[i].name; 1719 nm=swapCases[i].name;
1709 uprv_strcpy(name, "NULL"); 1720 uprv_strcpy(name, "NULL");
1710 } 1721 }
1711 uprv_strcat(name, "/"); 1722 uprv_strcat(name, "/");
1712 uprv_strcat(name, nm); 1723 uprv_strcat(name, nm);
1713 uprv_strcat(name, "."); 1724 uprv_strcat(name, ".");
1714 uprv_strcat(name, swapCases[i].type); 1725 uprv_strcat(name, swapCases[i].type);
1715 1726
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1802 } 1813 }
1803 1814
1804 /* Check that we verify that the data isn't bad */ 1815 /* Check that we verify that the data isn't bad */
1805 status = U_ZERO_ERROR; 1816 status = U_ZERO_ERROR;
1806 udata_setAppData("invalid path", badBuffer, &status); 1817 udata_setAppData("invalid path", badBuffer, &status);
1807 if (status != U_INVALID_FORMAT_ERROR) { 1818 if (status != U_INVALID_FORMAT_ERROR) {
1808 log_err("FAIL: udata_setAppData doesn't verify data validity.\n"); 1819 log_err("FAIL: udata_setAppData doesn't verify data validity.\n");
1809 } 1820 }
1810 } 1821 }
1811 1822
1823 // Check the override loading of time zone .res files from a specified path
1824 //
1825 // Hand testing notes:
1826 // 1. Run this test with the environment variable set. The following should in duce faiures:
1827 // ICU_TIMEZONE_FILES_DIR=../testdata/out/build LD_LIBRARY_PATH=../../lib :../../stubdata:../../tools/ctestfw:$LD_LIBRARY_PATH ./cintltst /udatatst/TestT ZDataDir
1828 // 2. Build ICU with with U_TIMEZONE_FILES_DIR defined. This should also induc e failures.
1829 // CPPFLAGS=-DU_TIMEZONE_FILES_DIR\=`pwd`/test/testdata/out/testdata ./ru nConfigureICU Linux
1830 // make check
1831
1832 static void TestTZDataDir(void) {
1833 #if !UCONFIG_NO_FORMATTING
1834 UErrorCode status = U_ZERO_ERROR;
1835 const char *tzDataVersion;
1836 const char *testDataPath;
1837
1838 // Verify that default ICU time zone data version is something newer than 20 14a.
1839 tzDataVersion = ucal_getTZDataVersion(&status);
1840 // printf("tz data version is %s\n", tzDataVersion);
1841 if (U_FAILURE(status)) {
1842 log_data_err("Failed call to ucal_getTZDataVersion - %s\n", u_errorName( status));
1843 return;
1844 } else if (strcmp("2014a", tzDataVersion) == 0) {
1845 log_err("File %s:%d - expected something newer than time zone data 2014a .\n", __FILE__, __LINE__, tzDataVersion);
1846 }
1847
1848 testDataPath = loadTestData(&status);
1849 // The path produced by loadTestData() will look something like
1850 // whatever/.../testdata/out/testdata
1851 // The test data puts an old (2014a) version of the time zone data there.
1852
1853 // Switch ICU to the testdata version of zoneinfo64.res, which is verison 20 14a.
1854 ctest_resetICU();
1855 u_setTimeZoneFilesDirectory(testDataPath, &status);
1856 tzDataVersion = ucal_getTZDataVersion(&status);
1857 if (strcmp("2014a", tzDataVersion) != 0) {
1858 log_err("File %s:%d - expected \"2014a\"; actual \"%s\"\n", __FILE__, __ LINE__, tzDataVersion);
1859 }
1860
1861 ctest_resetICU(); // Return ICU to using its standard tz data.
1862 tzDataVersion = ucal_getTZDataVersion(&status);
1863 // printf("tz data version is %s\n", tzDataVersion);
1864 if (strcmp("2014a", tzDataVersion) == 0) {
1865 log_err("File %s:%d - expected something newer than time zone data 2014a .\n", __FILE__, __LINE__, tzDataVersion);
1866 }
1867 #endif
1868 }
OLDNEW
« no previous file with comments | « source/test/cintltst/ucnvseltst.c ('k') | source/test/cintltst/udatpg_test.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698