1 /********************************************************************
3 * Copyright (c) 1998-2003, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
9 * Modification History:
11 * Date Name Description
12 * 02/22/2000 Madhu Creation
13 *******************************************************************************
16 #include "unicode/utypes.h"
17 #include "unicode/udata.h"
18 #include "unicode/uchar.h"
19 #include "unicode/ucnv.h"
20 #include "unicode/ures.h"
21 #include "unicode/ustring.h"
27 #include <sys/types.h>
39 static void TestUDataOpen(void);
40 static void TestUDataOpenChoiceDemo1(void);
41 static void TestUDataOpenChoiceDemo2(void);
42 static void TestUDataGetInfo(void);
43 static void TestUDataGetMemory(void);
44 static void TestUDataSetAppData(void);
45 static void TestErrorConditions(void);
46 static void TestAppData(void);
47 static void TestICUDataName(void);
49 void addUDataTest(TestNode
** root
);
52 addUDataTest(TestNode
** root
)
54 addTest(root
, &TestUDataOpen
, "udatatst/TestUDataOpen" );
55 addTest(root
, &TestUDataOpenChoiceDemo1
, "udatatst/TestUDataOpenChoiceDemo1");
56 addTest(root
, &TestUDataOpenChoiceDemo2
, "udatatst/TestUDataOpenChoiceDemo2");
57 addTest(root
, &TestUDataGetInfo
, "udatatst/TestUDataGetInfo" );
58 addTest(root
, &TestUDataGetMemory
, "udatatst/TestUDataGetMemory" );
59 addTest(root
, &TestUDataSetAppData
, "udatatst/TestUDataSetAppData" );
60 addTest(root
, &TestErrorConditions
, "udatatst/TestErrorConditions");
61 addTest(root
, &TestAppData
, "udatatst/TestAppData" );
62 addTest(root
, &TestICUDataName
, "udatatst/TestICUDataName" );
67 static void lots_of_mallocs()
79 static void TestUDataOpen(){
81 UErrorCode status
=U_ZERO_ERROR
;
82 const char* memMap
[][2]={
86 {"ibm-37_P100-1995", "cnv"}
88 const char* name
= "test";
89 const char* type
= "icu";
90 const char dirSepString
[] = {U_FILE_SEP_CHAR
, 0};
92 char* path
=(char*)malloc(sizeof(char) * (strlen(ctest_dataOutDir())
93 + strlen(U_ICUDATA_NAME
)
94 + strlen("/build")+1 ) );
96 char *icuDataFilePath
= 0;
99 const char* testPath
=loadTestData(&status
);
101 /* lots_of_mallocs(); */
103 strcat(strcpy(path
, ctest_dataOutDir()), U_ICUDATA_NAME
);
105 log_verbose("Testing udata_open()\n");
106 result
=udata_open(testPath
, type
, name
, &status
);
107 if(U_FAILURE(status
)){
108 log_err("FAIL: udata_open() failed for path = %s, name=%s, type=%s, \n errorcode=%s\n", testPath
, name
, type
, myErrorName(status
));
110 log_verbose("PASS: udata_open worked\n");
114 /* If the ICU system common data file is present in this confiugration,
115 * verify that udata_open can explicitly fetch items from it.
116 * If packaging mode == dll, the file may not exist. So, if the file is
117 * missing, skip this test without error.
119 icuDataFilePath
= (char *)malloc(strlen(path
) + 10);
120 strcpy(icuDataFilePath
, path
);
121 strcat(icuDataFilePath
, ".dat");
122 /* lots_of_mallocs(); */
123 if (stat(icuDataFilePath
, &stat_buf
) == 0)
126 log_verbose("Testing udata_open() on %s\n", icuDataFilePath
);
127 for(i
=0; i
<sizeof(memMap
)/sizeof(memMap
[0]); i
++){
128 /* lots_of_mallocs(); */
130 result
=udata_open(path
, memMap
[i
][1], memMap
[i
][0], &status
);
131 if(U_FAILURE(status
)) {
132 log_err("FAIL: udata_open() failed for path = %s, name=%s, type=%s, \n errorcode=%s\n", path
, memMap
[i
][0], memMap
[i
][1], myErrorName(status
));
134 log_verbose("PASS: udata_open worked for path = %s, name=%s, type=%s\n", path
, memMap
[i
][0], memMap
[i
][1]);
141 /* lots_of_mallocs(); */
142 log_verbose("Skipping tests of udata_open() on %s. File not present in this configuration.\n",
145 free(icuDataFilePath
);
146 icuDataFilePath
= NULL
;
147 /* lots_of_mallocs(); */
149 /* If the ICU individual files used to build the ICU system common data are
150 * present in this configuration,
151 * verify that udata_open can explicitly open them.
152 * These data files are present in the ICU data/build directory after a build
153 * completes. Tests are most commonly run with the data directory pointing
154 * back into this directory structure, but this is not required. Soooo, if
155 * the files are missing, skip this test without error.
157 /* lots_of_mallocs(); */
158 icuDataFilePath
= (char *)malloc(strlen(ctest_dataOutDir()) + 50);
159 strcpy(icuDataFilePath
, ctest_dataOutDir());
160 strcat(icuDataFilePath
, "build");
161 strcat(icuDataFilePath
, dirSepString
);
162 strcat(icuDataFilePath
, U_ICUDATA_NAME
);
163 strcat(icuDataFilePath
, "_");
164 strcat(icuDataFilePath
, "tz.icu");
166 /* lots_of_mallocs(); */
167 if (stat(icuDataFilePath
, &stat_buf
) == 0)
170 log_verbose("%s exists, so..\n", icuDataFilePath
);
171 strcpy(icuDataFilePath
, ctest_dataOutDir());
172 strcat(icuDataFilePath
, "build");
173 strcat(icuDataFilePath
, dirSepString
);
174 strcat(icuDataFilePath
, U_ICUDATA_NAME
);
175 log_verbose("Testing udata_open() on %s\n", icuDataFilePath
);
176 for(i
=0; i
<sizeof(memMap
)/sizeof(memMap
[0]); i
++){
178 result
=udata_open(icuDataFilePath
, memMap
[i
][1], memMap
[i
][0], &status
);
179 if(U_FAILURE(status
)) {
180 log_err("FAIL: udata_open() failed for path = %s, name=%s, type=%s, \n errorcode=%s\n", icuDataFilePath
, memMap
[i
][0], memMap
[i
][1], myErrorName(status
));
182 log_verbose("PASS: udata_open worked for path = %s, name=%s, type=%s\n", icuDataFilePath
, memMap
[i
][0], memMap
[i
][1]);
189 log_verbose("Skipping tests of udata_open() on %s. File not present in this configuration.\n",
193 free(icuDataFilePath
);
194 icuDataFilePath
= NULL
;
197 * Test fallback file names for open of separate data files.
198 * With these params to udata_open:
199 * path = wherever/testdata
202 * these files will be tried first:
203 * wherever/testudata_nam.typ
205 * A test data file named testudata_nam.typ exists for the purpose of testing this.
207 log_verbose("Testing udata_open, with base_name.type style fallback to individual file.\n");
209 status
= U_ZERO_ERROR
;
210 result
= udata_open( testPath
, "typ", "nam", &status
);
211 if (status
!= U_ZERO_ERROR
) {
212 log_err("FAIL: udata_open( \"%s\", \"typ\", \"nam\") returned status %s\n", testPath
, u_errorName(status
));
215 free(icuDataFilePath
);
218 /* This type of path is deprecated */
220 * Another fallback test. Paths ending with a trailing directory separator
221 * take a slightly different code path, with the "base name" from the path
222 * being empty in the internal udata_open logic.
225 /* log_verbose("Testing udata_open, with path containing a trailing directory separator.\n"); */
226 /* icuDataFilePath = (char *)malloc(strlen(u_getDataDirectory()) + 50); */
227 /* strcpy(icuDataFilePath, testPath); */
228 /* status = U_ZERO_ERROR; */
229 /* result = udata_open( icuDataFilePath, "cnv", "test1", &status); */
230 /* if (status != U_ZERO_ERROR) { */
231 /* log_err("FAIL: udata_open( \"%s\", \"cnv\", \"test1\") returned status %s\n", icuDataFilePath, u_errorName(status)); */
233 /* udata_close(result); */
234 /* free(icuDataFilePath); */
237 log_verbose("Testing udata_open() with a non existing binary file\n");
238 result
=udata_open("testdata", "tst", "nonexist", &status
);
239 if(status
==U_FILE_ACCESS_ERROR
){
240 log_verbose("Opening udata_open with non-existing file handled correctly.\n");
243 log_err("calling udata_open with non-existing file [testdata | nonexist.tst] not handled correctly\n. Expected: U_FILE_ACCESS_ERROR, Got: %s\n", myErrorName(status
));
244 if(U_SUCCESS(status
)) {
250 log_err("calling udata_open with non-existing file didn't return a null value\n");
252 log_verbose("calling udat_open with non-existing file returned null as expected\n");
260 static void TestUDataSetAppData(){
261 /* UDataMemory *dataItem;*/
263 UErrorCode status
=U_ZERO_ERROR
;
264 int fileHandle
= 0; /* We are going to read the testdata.dat file */
271 /* Open the testdata.dat file, using normal */
272 const char* tdrelativepath
= loadTestData(&status
);
273 char* filePath
=(char*)malloc(sizeof(char) * (strlen(tdrelativepath
) + strlen(".dat") +1 +strlen(tdrelativepath
)) );
275 strcpy(filePath
, tdrelativepath
);
276 strcat(filePath
, ".dat");
278 log_verbose("Testing udata_setAppData() with %s\n", filePath
);
281 fileHandle
= open( filePath
, O_RDONLY
| O_BINARY
);
283 fileHandle
= open( filePath
, O_RDONLY
);
285 if( fileHandle
== -1 ) {
286 log_err("FAIL: TestUDataSetAppData() can not open(\"%s\", O_RDONLY)\n", filePath
);
287 goto cleanupAndReturn
;
291 *Find the size of testdata.dat, and read the whole thing into memory
293 if (fstat(fileHandle
, &statBuf
) == 0) {
294 fileSize
= statBuf
.st_size
;
297 log_err("FAIL: TestUDataSetAppData() can not find size of file \"%s\".\n", filePath
);
298 goto cleanupAndReturn
;
301 fileBuf
= (char *)ctst_malloc(fileSize
);
303 log_err("FAIL: TestUDataSetAppData() can not malloc(%d) for file \"%s\".\n", fileSize
, filePath
);
304 goto cleanupAndReturn
;
307 i
= read(fileHandle
, fileBuf
, fileSize
);
309 log_err("FAIL: TestUDataSetAppData() error reading file \"%s\".\n", filePath
);
310 goto cleanupAndReturn
;
314 * Got testdata.dat into memory, now we try setAppData using the memory image.
318 udata_setAppData("appData1", fileBuf
, &status
);
319 if (status
!= U_ZERO_ERROR
) {
320 log_err("FAIL: TestUDataSetAppData(): udata_setAppData(\"appData1\", fileBuf, status) "
321 " returned status of %s\n", u_errorName(status
));
322 goto cleanupAndReturn
;
325 udata_setAppData("appData2", fileBuf
, &status
);
326 if (status
!= U_ZERO_ERROR
) {
327 log_err("FAIL: TestUDataSetAppData(): udata_setAppData(\"appData2\", fileBuf, status) "
328 " returned status of %s\n", u_errorName(status
));
329 goto cleanupAndReturn
;
332 /* If we try to setAppData with the same name a second time, we should get a
333 * a using default warning.
335 udata_setAppData("appData2", fileBuf
, &status
);
336 if (status
!= U_USING_DEFAULT_WARNING
) {
337 log_err("FAIL: TestUDataSetAppData(): udata_setAppData(\"appData2\", fileBuf, status) "
338 " returned status of %s, expected U_USING_DEFAULT_WARNING.\n", u_errorName(status
));
342 /** It is no longer correct to use udata_setAppData to change the
343 package of a contained item.
345 dataItem = udata_open("appData1", "res", "te_IN", &status); **/
348 /* Note: fileBuf is not deleted because ICU retains a pointer to it
349 * forever (until ICU is shut down).
351 if (fileHandle
> 0) {
359 static UBool U_CALLCONV
360 isAcceptable1(void *context
,
361 const char *type
, const char *name
,
362 const UDataInfo
*pInfo
) {
364 if( pInfo
->size
>=20 &&
365 pInfo
->isBigEndian
==U_IS_BIG_ENDIAN
&&
366 pInfo
->charsetFamily
==U_CHARSET_FAMILY
&&
367 pInfo
->dataFormat
[0]==0x43 && /* dataFormat="CvAl" */
368 pInfo
->dataFormat
[1]==0x76 &&
369 pInfo
->dataFormat
[2]==0x41 &&
370 pInfo
->dataFormat
[3]==0x6c &&
371 pInfo
->formatVersion
[0]==3 )
373 log_verbose("The data from \"%s.%s\" IS acceptable using the verifing function isAcceptable1()\n", name
, type
);
376 log_verbose("The data from \"%s.%s\" IS NOT acceptable using the verifing function isAcceptable1():-\n"
378 "\tisBigEndian = %d\n"
379 "\tcharsetFamily = %d\n"
380 "\tformatVersion[0] = %d\n"
381 "\tdataVersion[0] = %d\n"
382 "\tdataFormat = %c%c%c%c\n",
383 name
, type
, pInfo
->size
, pInfo
->isBigEndian
, pInfo
->charsetFamily
, pInfo
->formatVersion
[0],
384 pInfo
->dataVersion
[0], pInfo
->dataFormat
[0], pInfo
->dataFormat
[1], pInfo
->dataFormat
[2],
385 pInfo
->dataFormat
[3]);
386 log_verbose("Call another verifing function to accept the data\n");
391 static UBool U_CALLCONV
392 isAcceptable2(void *context
,
393 const char *type
, const char *name
,
394 const UDataInfo
*pInfo
){
395 UVersionInfo unicodeVersion
;
397 u_getUnicodeVersion(unicodeVersion
);
399 if( pInfo
->size
>=20 &&
400 pInfo
->isBigEndian
==U_IS_BIG_ENDIAN
&&
401 pInfo
->charsetFamily
==U_CHARSET_FAMILY
&&
402 pInfo
->dataFormat
[0]==0x75 && /* dataFormat="unam" */
403 pInfo
->dataFormat
[1]==0x6e &&
404 pInfo
->dataFormat
[2]==0x61 &&
405 pInfo
->dataFormat
[3]==0x6d &&
406 pInfo
->formatVersion
[0]==1 &&
407 pInfo
->dataVersion
[0]==unicodeVersion
[0] )
409 log_verbose("The data from \"%s.%s\" IS acceptable using the verifing function isAcceptable2()\n", name
, type
);
412 log_verbose("The data from \"%s.%s\" IS NOT acceptable using the verifing function isAcceptable2()\n", name
, type
);
419 static UBool U_CALLCONV
420 isAcceptable3(void *context
,
421 const char *type
, const char *name
,
422 const UDataInfo
*pInfo
){
424 if( pInfo
->size
>=20 &&
425 pInfo
->isBigEndian
==U_IS_BIG_ENDIAN
&&
426 pInfo
->charsetFamily
==U_CHARSET_FAMILY
&&
427 pInfo
->dataFormat
[0]==0x54 && /* dataFormat="test" */
428 pInfo
->dataFormat
[1]==0x65 &&
429 pInfo
->dataFormat
[2]==0x73 &&
430 pInfo
->dataFormat
[3]==0x74 &&
431 pInfo
->formatVersion
[0]==1 &&
432 pInfo
->dataVersion
[0]==1 ) {
433 log_verbose("The data from \"%s.%s\" IS acceptable using the verifing function isAcceptable3()\n", name
, type
);
437 log_verbose("The data from \"%s.%s\" IS NOT acceptable using the verifing function isAcceptable3()\n", name
, type
);
444 static void TestUDataOpenChoiceDemo1() {
446 UErrorCode status
=U_ZERO_ERROR
;
453 const char* type
="icu";
454 const char* testPath
="testdata";
456 result
=udata_openChoice(NULL
, "icu", name
[0], isAcceptable1
, NULL
, &status
);
457 if(U_FAILURE(status
)){
458 log_err("FAIL: udata_openChoice() failed name=%s, type=%s, \n errorcode=%s\n", name
[0], type
, myErrorName(status
));
460 log_verbose("PASS: udata_openChoice worked\n");
464 result
=udata_openChoice(NULL
, type
, name
[1], isAcceptable1
, NULL
, &status
);
465 if(U_FAILURE(status
)){
467 result
=udata_openChoice(NULL
, type
, name
[1], isAcceptable2
, NULL
, &status
);
468 if(U_FAILURE(status
)){
469 log_err("FAIL: udata_openChoice() failed name=%s, type=%s, \n errorcode=%s\n", name
[1], type
, myErrorName(status
));
473 if(U_SUCCESS(status
)){
477 result
=udata_openChoice(testPath
, type
, name
[2], isAcceptable1
, NULL
, &status
);
478 if(U_FAILURE(status
)){
480 result
=udata_openChoice(testPath
, type
, name
[2], isAcceptable3
, NULL
, &status
);
481 if(U_FAILURE(status
)){
482 log_err("FAIL: udata_openChoice() failed path=%s name=%s, type=%s, \n errorcode=%s\n", testPath
, name
[2], type
, myErrorName(status
));
486 if(U_SUCCESS(status
)){
491 static UBool U_CALLCONV
492 isAcceptable(void *context
,
493 const char *type
, const char *name
,
494 const UDataInfo
*pInfo
){
495 if( pInfo
->size
>=20 &&
496 pInfo
->isBigEndian
==U_IS_BIG_ENDIAN
&&
497 pInfo
->charsetFamily
==U_CHARSET_FAMILY
&&
498 pInfo
->dataFormat
[0]==0x54 && /* dataFormat="test" */
499 pInfo
->dataFormat
[1]==0x65 &&
500 pInfo
->dataFormat
[2]==0x73 &&
501 pInfo
->dataFormat
[3]==0x74 &&
502 pInfo
->formatVersion
[0]==1 &&
503 pInfo
->dataVersion
[0]==1 &&
504 *((int*)context
) == 2 ) {
505 log_verbose("The data from\"%s.%s\" IS acceptable using the verifing function isAcceptable()\n", name
, type
);
509 log_verbose("The data from \"%s.%s\" IS NOT acceptable using the verifing function isAcceptable()\n", name
, type
);
515 /* This test checks to see if the isAcceptable function is being called correctly. */
517 static void TestUDataOpenChoiceDemo2() {
519 UErrorCode status
=U_ZERO_ERROR
;
523 const char* name
="test";
524 const char* type
="icu";
525 const char* path
= loadTestData(&status
);
527 result
=udata_openChoice(path
, type
, name
, isAcceptable
, &p
, &status
);
528 if(U_FAILURE(status
)){
529 log_err("failed to load data at p=%s t=%s n=%s, isAcceptable", path
, type
, name
);
531 if(U_SUCCESS(status
) ) {
537 result
=udata_openChoice(path
, type
, name
, isAcceptable
, &p
, &status
);
539 if(U_FAILURE(status
) && status
==U_INVALID_FORMAT_ERROR
){
540 log_verbose("Loads the data but rejects it as expected %s\n", myErrorName(status
));
545 log_err("FAIL: failed to either load the data or to reject the loaded data. ERROR=%s\n", myErrorName(status
) );
549 if(U_FAILURE(status
)) {
550 log_err("FAIL: failed to load the data and accept it. ERROR=%s\n", myErrorName(status
) );
553 log_verbose("Loads the data and accepts it for p==2 as expected\n");
561 static void TestUDataGetInfo() {
564 /* UDataInfo cf. udata.h */
565 static UDataInfo dataInfo
={
566 30, /*sizeof(UDataInfo),*/
574 {0x54, 0x65, 0x73, 0x74}, /* dataFormat="Test" */
575 {9, 0, 0, 0}, /* formatVersion */
576 {4, 0, 0, 0} /* dataVersion */
578 UErrorCode status
=U_ZERO_ERROR
;
579 const char* name
="cnvalias";
580 const char* name2
="test";
581 const char* type
="icu";
583 const char* testPath
=loadTestData(&status
);
585 log_verbose("Testing udata_getInfo() for cnvalias.icu\n");
586 result
=udata_open(NULL
, "icu", name
, &status
);
587 if(U_FAILURE(status
)){
588 log_err("FAIL: udata_open() failed for path = NULL, name=%s, type=%s, \n errorcode=%s\n", name
, type
, myErrorName(status
));
591 udata_getInfo(result
, &dataInfo
);
592 if(dataInfo
.size
==20 && dataInfo
.size
!=30 &&
593 dataInfo
.isBigEndian
==U_IS_BIG_ENDIAN
&&
594 dataInfo
.charsetFamily
==U_CHARSET_FAMILY
&&
595 dataInfo
.dataFormat
[0]==0x43 && dataInfo
.dataFormat
[0]!=0x54 && /* dataFormat="CvAl" and not "Test". The values are set for cnvalias.dat*/
596 dataInfo
.dataFormat
[1]==0x76 && dataInfo
.dataFormat
[1]!=0x65 &&
597 dataInfo
.dataFormat
[2]==0x41 && dataInfo
.dataFormat
[2]!=0x73 &&
598 dataInfo
.dataFormat
[3]==0x6c && dataInfo
.dataFormat
[3]!=0x74 &&
599 dataInfo
.formatVersion
[0]!=9 && /*formatVersion is also set to the one for cnvalias*/
600 dataInfo
.dataVersion
[0]!=4 && /*dataVersion*/
601 dataInfo
.dataVersion
[1]!=0 ){
602 log_verbose("PASS: udata_getInfo() filled in the right values\n");
604 log_err("FAIL: udata_getInfo() filled in the wrong values\n");
609 log_verbose("Testing udata_getInfo() for test.icu\n");
610 result
=udata_open(testPath
, type
, name2
, &status
);
611 if(U_FAILURE(status
)) {
612 log_err("FAIL: udata_open() failed for path=%s name2=%s, type=%s, \n errorcode=%s\n", testPath
, name2
, type
, myErrorName(status
));
615 udata_getInfo(result
, &dataInfo
);
616 if(dataInfo
.size
==20 &&
617 dataInfo
.isBigEndian
==U_IS_BIG_ENDIAN
&&
618 dataInfo
.charsetFamily
==U_CHARSET_FAMILY
&&
619 dataInfo
.dataFormat
[0]==0x54 && /* dataFormat="Test". The values are set for test.dat*/
620 dataInfo
.dataFormat
[1]==0x65 &&
621 dataInfo
.dataFormat
[2]==0x73 &&
622 dataInfo
.dataFormat
[3]==0x74 &&
623 dataInfo
.formatVersion
[0]==1 && /*formatVersion is also set to the one for test*/
624 dataInfo
.dataVersion
[0]==1 && /*dataVersion*/
625 dataInfo
.dataVersion
[1]==0 )
627 log_verbose("PASS: udata_getInfo() filled in the right values\n");
629 log_err("FAIL: udata_getInfo() filled in the wrong values\n");
634 static void TestUDataGetMemory() {
637 const int32_t *table
=NULL
;
638 uint16_t* intValue
=0;
639 UErrorCode status
=U_ZERO_ERROR
;
640 const char* name
="cnvalias";
643 const char* name2
="test";
645 const char* testPath
= loadTestData(&status
);
648 log_verbose("Testing udata_getMemory() for \"cnvalias.icu\"\n");
649 result
=udata_openChoice(NULL
, type
, name
, isAcceptable1
, NULL
, &status
);
650 if(U_FAILURE(status
)){
651 log_err("FAIL: udata_openChoice() failed for name=%s, type=%s, \n errorcode=%s\n", name
, type
, myErrorName(status
));
654 table
=(const int32_t *)udata_getMemory(result
);
656 /* The alias table may list more converters than what's actually available now. [grhoten] */
657 if(ucnv_countAvailable() > table
[1]) /*???*/
658 log_err("FAIL: udata_getMemory() failed ucnv_countAvailable returned = %d, expected = %d\n", ucnv_countAvailable(), table
[1+2*(*table
)]);
663 log_verbose("Testing udata_getMemory for \"test.icu\"()\n");
664 result
=udata_openChoice(testPath
, type
, name2
, isAcceptable3
, NULL
, &status
);
665 if(U_FAILURE(status
)){
666 log_err("FAIL: udata_openChoice() failed for path=%s name=%s, type=%s, \n errorcode=%s\n", testPath
, name2
, type
, myErrorName(status
));
669 intValue
=(uint16_t *)udata_getMemory(result
);
670 /*printf("%d ..... %s", *(intValue), intValue+1));*/
671 if( *intValue
!= 2000 || strcmp((char*)(intValue
+1), "YEAR") != 0 )
672 log_err("FAIL: udata_getMemory() failed: intValue :- Expected:2000 Got:%d \n\tstringValue:- Expected:YEAR Got:%s\n", *intValue
, (intValue
+1));
678 static void TestErrorConditions(){
680 UDataMemory
*result
=NULL
;
681 UErrorCode status
=U_ZERO_ERROR
;
682 uint16_t* intValue
=0;
683 static UDataInfo dataInfo
={
684 30, /*sizeof(UDataInfo),*/
692 {0x54, 0x65, 0x73, 0x74}, /* dataFormat="Test" */
693 {9, 0, 0, 0}, /* formatVersion */
694 {4, 0, 0, 0} /* dataVersion */
697 const char* name
= "test";
698 const char* type
="icu";
700 const char *testPath
= loadTestData(&status
);
702 status
= U_ILLEGAL_ARGUMENT_ERROR
;
703 /*Try udata_open with status != U_ZERO_ERROR*/
704 log_verbose("Testing udata_open() with status != U_ZERO_ERROR\n");
705 result
=udata_open(testPath
, type
, name
, &status
);
707 log_err("FAIL: udata_open() is supposed to fail for path = %s, name=%s, type=%s, \n errorcode !=U_ZERO_ERROR\n", testPath
, name
, type
);
711 log_verbose("PASS: udata_open with errorCode != U_ZERO_ERROR failed as expected\n");
714 /*Try udata_open with data name=NULL*/
715 log_verbose("Testing udata_open() with data name=NULL\n");
717 result
=udata_open(testPath
, type
, NULL
, &status
);
718 if(U_FAILURE(status
)){
719 if(status
!= U_ILLEGAL_ARGUMENT_ERROR
|| result
!= NULL
){
720 log_err("FAIL: udata_open() with name=NULL should return NULL and errocode U_ILLEGAL_ARGUMENT_ERROR, GOT: errorcode=%s\n", myErrorName(status
));
722 log_verbose("PASS: udata_open with name=NULL failed as expected and errorcode = %s as expected\n", myErrorName(status
));
725 log_err("FAIL: udata_open() with data name=NULL is supposed to fail for path = %s, name=NULL type=%s errorcode=U_ZERO_ERROR \n", testPath
, type
);
730 /*Try udata_openChoice with status != U_ZERO_ERROR*/
731 log_verbose("Testing udata_openChoice() with status != U_ZERO_ERROR\n");
732 status
=U_ILLEGAL_ARGUMENT_ERROR
;
733 result
=udata_openChoice(testPath
, type
, name
, isAcceptable3
, NULL
, &status
);
735 log_err("FAIL: udata_openChoice() is supposed to fail for path = %s, name=%s, type=%s, \n errorcode != U_ZERO_ERROR\n", testPath
, name
, type
);
738 log_verbose("PASS: udata_openChoice() with errorCode != U_ZERO_ERROR failed as expected\n");
741 /*Try udata_open with data name=NULL*/
742 log_verbose("Testing udata_openChoice() with data name=NULL\n");
744 result
=udata_openChoice(testPath
, type
, NULL
, isAcceptable3
, NULL
, &status
);
745 if(U_FAILURE(status
)){
746 if(status
!= U_ILLEGAL_ARGUMENT_ERROR
|| result
!= NULL
){
747 log_err("FAIL: udata_openChoice() with name=NULL should return NULL and errocode U_ILLEGAL_ARGUMENT_ERROR, GOT: errorcode=%s\n", myErrorName(status
));
749 log_verbose("PASS: udata_openChoice with name=NULL failed as expected and errorcode = %s as expected\n", myErrorName(status
));
752 log_err("FAIL: udata_openChoice() with data name=NULL is supposed to fail for path = %s, name=NULL type=%s errorcode=U_ZERO_ERROR \n", testPath
, type
);
756 /*Try udata_getMemory with UDataMemory=NULL*/
757 log_verbose("Testing udata_getMemory with UDataMemory=NULL\n");
758 intValue
=(uint16_t*)udata_getMemory(NULL
);
759 if(intValue
!= NULL
){
760 log_err("FAIL: udata_getMemory with UDataMemory = NULL is supposed to fail\n");
763 /*Try udata_getInfo with UDataMemory=NULL*/
765 udata_getInfo(NULL
, &dataInfo
);
766 if(dataInfo
.size
!= 0){
767 log_err("FAIL : udata_getInfo with UDataMemory = NULL us supposed to fail\n");
770 /*Try udata_openChoice with a non existing binary file*/
771 log_verbose("Testing udata_openChoice() with a non existing binary file\n");
772 result
=udata_openChoice(testPath
, "tst", "nonexist", isAcceptable3
, NULL
, &status
);
773 if(status
==U_FILE_ACCESS_ERROR
){
774 log_verbose("Opening udata_openChoice with non-existing file handled correctly.\n");
777 log_err("calling udata_open with non-existing file not handled correctly\n. Expected: U_FILE_ACCESS_ERROR, Got: %s\n", myErrorName(status
));
778 if(U_SUCCESS(status
)) {
784 log_err("calling udata_open with non-existing file didn't return a null value\n");
786 log_verbose("calling udat_open with non-existing file returned null as expected\n");
790 /* Test whether apps and ICU can each have their own root.res */
791 static void TestAppData()
793 UResourceBundle
*icu
, *app
;
794 UResourceBundle
*tmp
= NULL
;
795 UResourceBundle
*tmp2
= NULL
;
797 const UChar
*appString
;
798 const UChar
*icuString
;
802 UErrorCode status
= U_ZERO_ERROR
;
803 char testMsgBuf
[256];
805 const char* testPath
=loadTestData(&status
);
807 icu
= ures_open(NULL
, "root", &status
);
808 if(U_FAILURE(status
))
810 log_err("%s:%d: Couldn't open root ICU bundle- %s", __FILE__
, __LINE__
, u_errorName(status
));
813 /* log_info("Open icu root: %s size_%d\n", u_errorName(status), ures_getSize(icu)); */
814 status
= U_ZERO_ERROR
;
816 app
= ures_open(testPath
, "root", &status
);
817 if(U_FAILURE(status
))
819 log_err("%s:%d: Couldn't open app ICU bundle [%s]- %s", __FILE__
, __LINE__
, testPath
, u_errorName(status
));
822 /* log_info("Open app: %s, size %d\n", u_errorName(status), ures_getSize(app)); */
824 tmp
= ures_getByKey(icu
, "Version", tmp
, &status
);
825 if(U_FAILURE(status
))
827 log_err("%s:%d: Couldn't get Version string from ICU root bundle- %s", __FILE__
, __LINE__
, u_errorName(status
));
831 icuString
= ures_getString(tmp
, &len
, &status
);
832 if(U_FAILURE(status
))
834 log_err("%s:%d: Couldn't get string from Version string from ICU root bundle- %s", __FILE__
, __LINE__
, u_errorName(status
));
837 /* log_info("icuString=%p - %s\n", icuString, austrdup(icuString)); */
840 tmp2
= ures_getByKey(app
, "Version", tmp2
, &status
);
841 if(U_FAILURE(status
))
843 log_err("%s:%d: Couldn't get Version string from App root bundle- %s", __FILE__
, __LINE__
, u_errorName(status
));
847 appString
= ures_getString(tmp2
, &len
, &status
);
848 if(U_FAILURE(status
))
850 log_err("%s:%d: Couldn't get string from Version string from App root bundle- %s", __FILE__
, __LINE__
, u_errorName(status
));
854 /* log_info("appString=%p - %s\n", appString, austrdup(appString)); */
857 if(!u_strcmp(icuString
, appString
))
859 log_err("%s:%d: Error! Expected ICU and App root version strings to be DIFFERENT but they are both %s and %s\n", __FILE__
, __LINE__
, austrdup(icuString
),
860 austrdup(appString
));
864 log_verbose("%s:%d: appstr=%s, icustr=%s\n", __FILE__
,
865 __LINE__
, u_austrcpy(testMsgBuf
, appString
), u_austrcpy(testMsgBuf
, icuString
));
874 static void TestICUDataName()
876 UVersionInfo icuVersion
;
877 char expectDataName
[20];
878 unsigned int expectLen
= 8;
882 /* Print out the version # we have .. */
883 log_verbose("utypes.h says U_ICUDATA_NAME = %s\n", U_ICUDATA_NAME
);
885 /* Build up the version # we expect to get */
886 u_getVersion(icuVersion
);
888 switch(U_CHARSET_FAMILY
)
891 switch(U_IS_BIG_ENDIAN
)
900 log_err("Expected 1 or 0 for U_IS_BIG_ENDIAN, got %d!\n", (int)U_IS_BIG_ENDIAN
);
904 case U_EBCDIC_FAMILY
:
909 sprintf(expectDataName
, "%s%d%d%c",
915 log_verbose("Expected: %s\n", expectDataName
);
916 if(uprv_strlen(expectDataName
) != expectLen
)
918 log_err("*Expected* length is wrong (test err?), should be %d is %d\n",
919 expectLen
, uprv_strlen(expectDataName
));
922 if(uprv_strlen(U_ICUDATA_NAME
) != expectLen
)
924 log_err("U_ICUDATA_NAME length should be %d is %d\n",
925 expectLen
, uprv_strlen(U_ICUDATA_NAME
));
928 if(uprv_strcmp(U_ICUDATA_NAME
, expectDataName
))
930 log_err("U_ICUDATA_NAME should be %s but is %s\n",
931 expectDataName
, U_ICUDATA_NAME
);
934 /* ICUDATA_NAME comes from the build system on *nix */
936 if(uprv_strcmp(U_ICUDATA_NAME
, ICUDATA_NAME
))
938 log_err("ICUDATA_NAME and U_ICUDATA_NAME don't match: "
939 "ICUDATA_NAME=%s, U_ICUDATA_NAME=%s. Check configure.in, icudefs.mk.in, utypes.h...\n", ICUDATA_NAME
, U_ICUDATA_NAME
);
943 log_verbose("ICUDATA_NAME=%s (from icudefs.mk), U_ICUDATA_NAME=%s (from utypes.h)\n", ICUDATA_NAME
, U_ICUDATA_NAME
);