2000-05-15 18:39:17 +00:00
/********************************************************************
* COPYRIGHT :
2001-03-21 19:46:49 +00:00
* Copyright ( c ) 1997 - 2001 , International Business Machines Corporation and
2000-05-15 18:39:17 +00:00
* others . All Rights Reserved .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/********************************************************************************
*
* File CRESTST . C
*
* Modification History :
2000-05-24 23:42:34 +00:00
* Name Date Description
* Madhu Katragadda 05 / 09 / 2000 Ported Tests for New ResourceBundle API
* Madhu Katragadda 05 / 24 / 2000 Added new tests to test RES_BINARY for collationElements
2000-05-15 18:39:17 +00:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
2000-08-28 21:43:03 +00:00
# include <time.h>
2000-05-15 18:39:17 +00:00
# include "unicode/utypes.h"
# include "cintltst.h"
# include "unicode/utypes.h"
# include "unicode/ustring.h"
2001-11-01 19:42:38 +00:00
# include "unicode/ucnv.h"
2000-05-15 18:39:17 +00:00
# include "string.h"
# include "cstring.h"
2001-05-24 20:59:12 +00:00
# include "cmemory.h"
2000-05-15 18:39:17 +00:00
# define RESTEST_HEAP_CHECK 0
# include "unicode/uloc.h"
# include "unicode/ures.h"
# include "creststn.h"
# include "unicode/ctest.h"
2001-08-27 18:51:43 +00:00
static int32_t pass ;
static int32_t fail ;
2000-05-15 18:39:17 +00:00
/*****************************************************************************/
/**
* Return a random unsigned long l where 0 N < = l < = ULONG_MAX .
*/
static uint32_t
randul ( )
{
2000-08-14 17:13:09 +00:00
uint32_t l = 0 ;
2000-08-09 23:34:41 +00:00
int32_t i ;
2000-05-18 22:08:39 +00:00
static UBool initialized = FALSE ;
2000-05-15 18:39:17 +00:00
if ( ! initialized )
{
srand ( ( unsigned ) time ( NULL ) ) ;
initialized = TRUE ;
}
2000-05-15 22:22:48 +00:00
/* Assume rand has at least 12 bits of precision */
2000-05-15 18:39:17 +00:00
2000-08-21 22:28:56 +00:00
for ( i = 0 ; i < sizeof ( l ) ; + + i )
( ( char * ) & l ) [ i ] = ( char ) ( ( rand ( ) & 0x0FF0 ) > > 4 ) ;
2000-05-15 18:39:17 +00:00
return l ;
}
/**
* Return a random double x where 0.0 < = x < 1.0 .
*/
static double
randd ( )
{
2001-01-02 02:28:45 +00:00
return ( ( double ) randul ( ) ) / UINT32_MAX ;
2000-05-15 18:39:17 +00:00
}
/**
* Return a random integer i where 0 < = i < n .
*/
static int32_t randi ( int32_t n )
{
return ( int32_t ) ( randd ( ) * n ) ;
}
2000-05-15 22:22:48 +00:00
/***************************************************************************************/
2000-05-15 18:39:17 +00:00
/**
* Convert an integer , positive or negative , to a character string radix 10.
*/
static char *
itoa1 ( int32_t i , char * buf )
{
char * p = 0 ;
char * result = buf ;
/* Handle negative */
if ( i < 0 ) {
* buf + + = ' - ' ;
i = - i ;
}
/* Output digits in reverse order */
p = buf ;
do {
2000-08-09 23:34:41 +00:00
* p + + = ( char ) ( ' 0 ' + ( i % 10 ) ) ;
2000-05-15 18:39:17 +00:00
i / = 10 ;
}
while ( i ) ;
* p - - = 0 ;
/* Reverse the string */
while ( buf < p ) {
char c = * buf ;
* buf + + = * p ;
* p - - = c ;
}
return result ;
}
static const int32_t kERROR_COUNT = - 1234567 ;
static const UChar kERROR [ ] = { 0x0045 /*E*/ , 0x0052 /*'R'*/ , 0x0052 /*'R'*/ ,
0x004F /*'O'*/ , 0x0052 /*'R'*/ , 0x0000 /*'\0'*/ } ;
/*****************************************************************************/
enum E_Where
{
e_Root ,
e_te ,
e_te_IN ,
e_Where_count
} ;
typedef enum E_Where E_Where ;
/*****************************************************************************/
2001-03-22 18:32:54 +00:00
# define CONFIRM_EQ(actual,expected) if (u_strcmp(expected,actual)==0){ record_pass(); } else { record_fail(); log_err("%s returned %s instead of %s\n", action, austrdup(actual), austrdup(expected)); }
# define CONFIRM_INT_EQ(actual,expected) if ((expected)==(actual)) { record_pass(); } else { record_fail(); log_err("%s returned %d instead of %d\n", action, actual, expected); }
# define CONFIRM_INT_GE(actual,expected) if ((actual)>=(expected)) { record_pass(); } else { record_fail(); log_err("%s returned %d instead of x >= %d\n", action, actual, expected); }
# define CONFIRM_INT_NE(actual,expected) if ((expected)!=(actual)) { record_pass(); } else { record_fail(); log_err("%s returned %d instead of x != %d\n", action, actual, expected); }
# define CONFIRM_ErrorCode(actual,expected) if ((expected)==(actual)) { record_pass(); } else { record_fail(); log_err("%s returned %s instead of %s\n", action, myErrorName(actual), myErrorName(expected)); }
2000-05-15 18:39:17 +00:00
/* Array of our test objects */
static struct
{
const char * name ;
UErrorCode expected_constructor_status ;
E_Where where ;
2000-05-18 22:08:39 +00:00
UBool like [ e_Where_count ] ;
UBool inherits [ e_Where_count ] ;
2000-05-15 18:39:17 +00:00
}
param [ ] =
{
/* "te" means test */
/* "IN" means inherits */
/* "NE" or "ne" means "does not exist" */
{ " root " , U_ZERO_ERROR , e_Root , { TRUE , FALSE , FALSE } , { TRUE , FALSE , FALSE } } ,
{ " te " , U_ZERO_ERROR , e_te , { FALSE , TRUE , FALSE } , { TRUE , TRUE , FALSE } } ,
{ " te_IN " , U_ZERO_ERROR , e_te_IN , { FALSE , FALSE , TRUE } , { TRUE , TRUE , TRUE } } ,
{ " te_NE " , U_USING_FALLBACK_ERROR , e_te , { FALSE , TRUE , FALSE } , { TRUE , TRUE , FALSE } } ,
{ " te_IN_NE " , U_USING_FALLBACK_ERROR , e_te_IN , { FALSE , FALSE , TRUE } , { TRUE , TRUE , TRUE } } ,
{ " ne " , U_USING_DEFAULT_ERROR , e_Root , { TRUE , FALSE , FALSE } , { TRUE , FALSE , FALSE } }
} ;
static int32_t bundles_count = sizeof ( param ) / sizeof ( param [ 0 ] ) ;
static void printUChars ( UChar * ) ;
2001-11-13 23:04:29 +00:00
static void TestDecodedBundle ( void ) ;
2001-03-21 00:55:52 +00:00
2000-05-15 18:39:17 +00:00
/***************************************************************************************/
/* Array of our test objects */
void addNEWResourceBundleTest ( TestNode * * root )
{
2001-08-17 22:15:39 +00:00
addTest ( root , & TestEmptyBundle , " tsutil/creststn/TestEmptyBundle " ) ;
2000-08-28 21:43:03 +00:00
addTest ( root , & TestConstruction1 , " tsutil/creststn/TestConstruction1 " ) ;
addTest ( root , & TestConstruction2 , " tsutil/creststn/TestConstruction2 " ) ;
addTest ( root , & TestResourceBundles , " tsutil/creststn/TestResourceBundle " ) ;
addTest ( root , & TestFallback , " tsutil/creststn/TestFallback " ) ;
2001-03-22 18:32:54 +00:00
addTest ( root , & TestGetVersion , " tsutil/creststn/TestGetVersion " ) ;
2000-08-28 21:43:03 +00:00
addTest ( root , & TestAliasConflict , " tsutil/creststn/TestAlias " ) ;
addTest ( root , & TestNewTypes , " tsutil/creststn/TestNewTypes " ) ;
2001-08-27 18:51:43 +00:00
addTest ( root , & TestEmptyTypes , " tsutil/creststn/TestEmptyTypes " ) ;
2000-08-28 21:43:03 +00:00
addTest ( root , & TestBinaryCollationData , " tsutil/creststn/TestBinaryCollationData " ) ;
addTest ( root , & TestAPI , " tsutil/creststn/TestAPI " ) ;
addTest ( root , & TestErrorConditions , " tsutil/creststn/TestErrorConditions " ) ;
2001-11-01 19:42:38 +00:00
addTest ( root , & TestDecodedBundle , " tsutil/creststn/TestDecodedBundle " ) ;
2000-05-15 18:39:17 +00:00
}
/***************************************************************************************/
2001-04-17 19:09:23 +00:00
static const char * norwayNames [ ] = {
" no_NO_NY " ,
" no_NO " ,
" no " ,
" nn_NO " ,
" nn " ,
" nb_NO " ,
" nb "
} ;
static const char * norwayLocales [ ] = {
" nn_NO " ,
" nb_NO " ,
" nb " ,
" nn_NO " ,
" nn " ,
" nb_NO " ,
" nb "
} ;
2000-11-21 04:05:39 +00:00
static void TestAliasConflict ( void ) {
2000-05-15 18:39:17 +00:00
UErrorCode status = U_ZERO_ERROR ;
UResourceBundle * he = NULL ;
UResourceBundle * iw = NULL ;
2001-04-17 19:09:23 +00:00
UResourceBundle * norway = NULL ;
2000-05-15 18:39:17 +00:00
const UChar * result = NULL ;
2001-03-22 00:42:37 +00:00
int32_t resultLen ;
2001-04-17 19:09:23 +00:00
uint32_t size = 0 ;
uint32_t i = 0 ;
const char * realName = NULL ;
2000-08-28 21:43:03 +00:00
2000-05-15 18:39:17 +00:00
he = ures_open ( NULL , " he " , & status ) ;
iw = ures_open ( NULL , " iw " , & status ) ;
if ( U_FAILURE ( status ) ) {
log_err ( " Failed to get resource with %s " , myErrorName ( status ) ) ;
}
ures_close ( iw ) ;
2001-03-22 00:42:37 +00:00
result = ures_getStringByKey ( he , " ShortLanguage " , & resultLen , & status ) ;
2000-05-15 18:39:17 +00:00
if ( U_FAILURE ( status ) | | result = = NULL ) {
log_err ( " Failed to get resource with %s " , myErrorName ( status ) ) ;
}
ures_close ( he ) ;
2001-04-17 19:09:23 +00:00
size = sizeof ( norwayNames ) / sizeof ( norwayNames [ 0 ] ) ;
for ( i = 0 ; i < size ; i + + ) {
norway = ures_open ( NULL , norwayNames [ i ] , & status ) ;
realName = ures_getLocale ( norway , & status ) ;
log_verbose ( " ures_getLocale( \" %s \" )=%s \n " , norwayNames [ i ] , realName ) ;
if ( strcmp ( norwayLocales [ i ] , realName ) ! = 0 ) {
log_err ( " Wrong locale name for %s, expected %s, got %s \n " , norwayNames [ i ] , norwayLocales [ i ] , realName ) ;
}
ures_close ( norway ) ;
}
2000-05-15 18:39:17 +00:00
}
2001-11-01 19:42:38 +00:00
static void TestDecodedBundle ( ) {
UErrorCode error = U_ZERO_ERROR ;
UResourceBundle * resB ;
int32_t len = 0 ;
const UChar * srcFromRes ;
UChar src [ ] = {
2001-11-01 22:55:51 +00:00
0x30a7 , 0x30a8 , 0x30c9 , 0x0061 , 0xFFFD , 0x30f3 , 0x30c0 , 0x30b0 , 0x30b3 , 0x30c5 ,
2001-11-01 19:42:38 +00:00
0x30d5 , 0x30d9 , 0x30ca , 0x30eb , 0x305a , 0x304a , 0x3049 , 0x3048 , 0x3046 ,
0x3044 , 0x3053 , 0x3054 , 0x3064 , 0x3074 , 0x3084 , 0x3093 , 0x3062 , 0x3060 ,
0x3080 , 0x3090 , 0x30a2 , 0x30b2 , 0x30b6 , 0x30b7 , 0x30b8 , 0x30d8 , 0x30d7 ,
0x30d3 , 0x30d1 , 0x0000
} ;
/* pre-flight */
int32_t num = 0 ;
char testdatapath [ 256 ] ;
const char * directory = u_getDataDirectory ( ) ;
strcpy ( testdatapath , directory ) ;
strcat ( testdatapath , " testdata " ) ;
resB = ures_open ( testdatapath , " ja_data " , & error ) ;
srcFromRes = ures_getStringByKey ( resB , " str " , & len , & error ) ;
if ( u_strncmp ( srcFromRes , src , len ) ! = 0 ) {
log_err ( " Genrb produced res files after decoding failed \n " ) ;
}
while ( num < len ) {
if ( src [ num ] ! = srcFromRes [ num ] ) {
log_verbose ( " Expected: 0x%04X Got: 0x%04X \n " , src [ num ] , srcFromRes [ num ] ) ;
}
num + + ;
}
2001-11-13 22:25:38 +00:00
ures_close ( resB ) ;
2001-11-01 19:42:38 +00:00
}
2000-11-21 04:05:39 +00:00
static void TestNewTypes ( ) {
2000-08-28 21:43:03 +00:00
UResourceBundle * theBundle = NULL ;
char action [ 256 ] ;
char testdatapath [ 256 ] ;
2000-12-03 04:07:13 +00:00
const char * directory = u_getDataDirectory ( ) ;
2000-08-28 21:43:03 +00:00
UErrorCode status = U_ZERO_ERROR ;
UResourceBundle * res = NULL ;
uint8_t * binResult = NULL ;
int32_t len = 0 ;
int32_t i = 0 ;
int32_t intResult = 0 ;
2001-09-18 16:09:48 +00:00
uint32_t uintResult = 0 ;
const UChar * empty = NULL ;
2001-07-27 17:20:48 +00:00
const UChar * zeroString ;
2001-07-30 20:25:43 +00:00
UChar expected [ ] = { ' a ' , ' b ' , ' c ' , ' \0 ' , ' d ' , ' e ' , ' f ' } ;
2001-09-20 02:39:50 +00:00
const char * expect = " tab: \t cr: \r ff: \f newline: \n backslash: \\ \\ quote= \\ \' doubleQuote= \\ \" singlequoutes='' " ;
UChar uExpect [ 200 ] ;
2002-01-21 21:10:18 +00:00
const char * tdrelativepath = " .. " U_FILE_SEP_STRING " test " U_FILE_SEP_STRING " testdata " U_FILE_SEP_STRING " out " U_FILE_SEP_STRING ;
2001-09-20 02:39:50 +00:00
u_charsToUChars ( expect , uExpect , uprv_strlen ( expect ) + 1 ) ;
2000-08-28 21:43:03 +00:00
strcpy ( action , " Construction of testtypes bundle " ) ;
strcpy ( testdatapath , directory ) ;
2002-01-21 21:10:18 +00:00
strcat ( testdatapath , tdrelativepath ) ;
2000-08-28 21:43:03 +00:00
strcat ( testdatapath , " testdata " ) ;
theBundle = ures_open ( testdatapath , " testtypes " , & status ) ;
2001-09-18 16:09:48 +00:00
empty = ures_getStringByKey ( theBundle , " emptystring " , & len , & status ) ;
2002-01-21 21:10:18 +00:00
if ( empty & & ( * empty ! = 0 | | len ! = 0 ) ) {
2001-09-18 16:09:48 +00:00
log_err ( " Empty string returned invalid value \n " ) ;
}
2000-08-28 21:43:03 +00:00
CONFIRM_ErrorCode ( status , U_ZERO_ERROR ) ;
CONFIRM_INT_NE ( theBundle , NULL ) ;
2001-07-27 17:20:48 +00:00
/* This test reads the string "abc\u0000def" from the bundle */
/* if everything is working correctly, the size of this string */
/* should be 7. Everything else is a wrong answer, esp. 3 and 6*/
strcpy ( action , " getting and testing of string with embeded zero " ) ;
res = ures_getByKey ( theBundle , " zerotest " , res , & status ) ;
CONFIRM_ErrorCode ( status , U_ZERO_ERROR ) ;
CONFIRM_INT_EQ ( ures_getType ( res ) , RES_STRING ) ;
zeroString = ures_getString ( res , & len , & status ) ;
if ( U_SUCCESS ( status ) ) {
CONFIRM_ErrorCode ( status , U_ZERO_ERROR ) ;
CONFIRM_INT_EQ ( len , 7 ) ;
CONFIRM_INT_NE ( len , 3 ) ;
}
2001-07-30 20:25:43 +00:00
for ( i = 0 ; i < len ; i + + ) {
if ( zeroString [ i ] ! = expected [ i ] ) {
log_verbose ( " Output didnot match Expected: \\ u%4X Got: \\ u%4X " , expected [ i ] , zeroString [ i ] ) ;
}
}
2001-07-27 17:20:48 +00:00
2000-08-28 21:43:03 +00:00
strcpy ( action , " getting and testing of binary type " ) ;
res = ures_getByKey ( theBundle , " binarytest " , res , & status ) ;
2000-07-11 23:27:11 +00:00
CONFIRM_ErrorCode ( status , U_ZERO_ERROR ) ;
2000-08-28 21:43:03 +00:00
CONFIRM_INT_EQ ( ures_getType ( res ) , RES_BINARY ) ;
binResult = ( uint8_t * ) ures_getBinary ( res , & len , & status ) ;
if ( U_SUCCESS ( status ) ) {
CONFIRM_ErrorCode ( status , U_ZERO_ERROR ) ;
CONFIRM_INT_EQ ( len , 15 ) ;
for ( i = 0 ; i < 15 ; i + + ) {
CONFIRM_INT_EQ ( binResult [ i ] , i ) ;
}
2000-07-11 23:27:11 +00:00
}
2000-08-28 21:43:03 +00:00
strcpy ( action , " getting and testing of imported binary type " ) ;
res = ures_getByKey ( theBundle , " importtest " , res , & status ) ;
2000-07-11 23:27:11 +00:00
CONFIRM_ErrorCode ( status , U_ZERO_ERROR ) ;
2000-08-28 21:43:03 +00:00
CONFIRM_INT_EQ ( ures_getType ( res ) , RES_BINARY ) ;
binResult = ( uint8_t * ) ures_getBinary ( res , & len , & status ) ;
if ( U_SUCCESS ( status ) ) {
CONFIRM_ErrorCode ( status , U_ZERO_ERROR ) ;
CONFIRM_INT_EQ ( len , 15 ) ;
for ( i = 0 ; i < 15 ; i + + ) {
CONFIRM_INT_EQ ( binResult [ i ] , i ) ;
}
2000-07-11 23:27:11 +00:00
}
2000-08-28 21:43:03 +00:00
strcpy ( action , " getting and testing of integer types " ) ;
res = ures_getByKey ( theBundle , " one " , res , & status ) ;
2000-07-11 23:27:11 +00:00
CONFIRM_ErrorCode ( status , U_ZERO_ERROR ) ;
2000-08-28 21:43:03 +00:00
CONFIRM_INT_EQ ( ures_getType ( res ) , RES_INT ) ;
intResult = ures_getInt ( res , & status ) ;
2001-09-18 16:09:48 +00:00
uintResult = ures_getUInt ( res , & status ) ;
if ( U_SUCCESS ( status ) ) {
CONFIRM_ErrorCode ( status , U_ZERO_ERROR ) ;
CONFIRM_INT_EQ ( uintResult , ( uint32_t ) intResult ) ;
CONFIRM_INT_EQ ( intResult , 1 ) ;
}
strcpy ( action , " getting minusone " ) ;
res = ures_getByKey ( theBundle , " minusone " , res , & status ) ;
CONFIRM_ErrorCode ( status , U_ZERO_ERROR ) ;
CONFIRM_INT_EQ ( ures_getType ( res ) , RES_INT ) ;
intResult = ures_getInt ( res , & status ) ;
uintResult = ures_getUInt ( res , & status ) ;
if ( U_SUCCESS ( status ) ) {
CONFIRM_ErrorCode ( status , U_ZERO_ERROR ) ;
CONFIRM_INT_EQ ( uintResult , 0x0FFFFFFF ) ; /* a 28 bit integer */
CONFIRM_INT_EQ ( intResult , - 1 ) ;
CONFIRM_INT_NE ( uintResult , ( uint32_t ) intResult ) ;
}
strcpy ( action , " getting plusone " ) ;
res = ures_getByKey ( theBundle , " plusone " , res , & status ) ;
CONFIRM_ErrorCode ( status , U_ZERO_ERROR ) ;
CONFIRM_INT_EQ ( ures_getType ( res ) , RES_INT ) ;
intResult = ures_getInt ( res , & status ) ;
uintResult = ures_getUInt ( res , & status ) ;
2000-08-28 21:43:03 +00:00
if ( U_SUCCESS ( status ) ) {
CONFIRM_ErrorCode ( status , U_ZERO_ERROR ) ;
2001-09-18 16:09:48 +00:00
CONFIRM_INT_EQ ( uintResult , ( uint32_t ) intResult ) ;
2000-08-28 21:43:03 +00:00
CONFIRM_INT_EQ ( intResult , 1 ) ;
}
2000-07-11 23:27:11 +00:00
2000-08-28 21:43:03 +00:00
res = ures_getByKey ( theBundle , " onehundredtwentythree " , res , & status ) ;
2000-07-11 23:27:11 +00:00
CONFIRM_ErrorCode ( status , U_ZERO_ERROR ) ;
2000-08-28 21:43:03 +00:00
CONFIRM_INT_EQ ( ures_getType ( res ) , RES_INT ) ;
intResult = ures_getInt ( res , & status ) ;
if ( U_SUCCESS ( status ) ) {
CONFIRM_ErrorCode ( status , U_ZERO_ERROR ) ;
CONFIRM_INT_EQ ( intResult , 123 ) ;
}
2000-07-11 23:27:11 +00:00
2001-09-20 02:39:50 +00:00
/* this tests if escapes are preserved or not */
{
const UChar * str = ures_getStringByKey ( theBundle , " testescape " , & len , & status ) ;
CONFIRM_ErrorCode ( status , U_ZERO_ERROR ) ;
2001-09-20 02:39:51 +00:00
if ( U_SUCCESS ( status ) ) {
if ( u_strcmp ( uExpect , str ) ) {
log_err ( " Did not get the expected string for testescape " ) ;
}
2001-09-20 02:39:50 +00:00
}
}
2001-11-06 00:46:23 +00:00
/* test for jitterbug#1435 */
{
const UChar * str = ures_getStringByKey ( theBundle , " test_underscores " , & len , & status ) ;
2001-11-13 23:04:29 +00:00
expect = " test message .... " ;
2001-11-06 00:46:23 +00:00
u_charsToUChars ( expect , uExpect , uprv_strlen ( expect ) + 1 ) ;
CONFIRM_ErrorCode ( status , U_ZERO_ERROR ) ;
if ( u_strcmp ( uExpect , str ) ) {
log_err ( " Did not get the expected string for test_underscores. " ) ;
}
}
2000-08-28 21:43:03 +00:00
ures_close ( res ) ;
ures_close ( theBundle ) ;
2000-07-11 23:27:11 +00:00
}
2001-08-27 18:51:43 +00:00
static void TestEmptyTypes ( ) {
UResourceBundle * theBundle = NULL ;
char action [ 256 ] ;
char testdatapath [ 256 ] ;
const char * directory = u_getDataDirectory ( ) ;
UErrorCode status = U_ZERO_ERROR ;
UResourceBundle * res = NULL ;
UResourceBundle * resArray = NULL ;
const uint8_t * binResult = NULL ;
int32_t len = 0 ;
int32_t intResult = 0 ;
const UChar * zeroString ;
const int32_t * zeroIntVect ;
2002-01-21 21:10:18 +00:00
const char * tdrelativepath = " .. " U_FILE_SEP_STRING " test " U_FILE_SEP_STRING " testdata " U_FILE_SEP_STRING " out " U_FILE_SEP_STRING ;
2001-08-27 18:51:43 +00:00
strcpy ( action , " Construction of testtypes bundle " ) ;
strcpy ( testdatapath , directory ) ;
2002-01-21 21:10:18 +00:00
strcat ( testdatapath , tdrelativepath ) ;
2001-08-27 18:51:43 +00:00
strcat ( testdatapath , " testdata " ) ;
theBundle = ures_open ( testdatapath , " testtypes " , & status ) ;
CONFIRM_ErrorCode ( status , U_ZERO_ERROR ) ;
CONFIRM_INT_NE ( theBundle , NULL ) ;
/* This test reads the string "abc\u0000def" from the bundle */
/* if everything is working correctly, the size of this string */
/* should be 7. Everything else is a wrong answer, esp. 3 and 6*/
status = U_ZERO_ERROR ;
strcpy ( action , " getting and testing of explicit string of zero length string " ) ;
res = ures_getByKey ( theBundle , " emptyexplicitstring " , res , & status ) ;
CONFIRM_ErrorCode ( status , U_ZERO_ERROR ) ;
CONFIRM_INT_EQ ( ures_getType ( res ) , RES_STRING ) ;
zeroString = ures_getString ( res , & len , & status ) ;
if ( U_SUCCESS ( status ) ) {
CONFIRM_ErrorCode ( status , U_ZERO_ERROR ) ;
CONFIRM_INT_EQ ( len , 0 ) ;
CONFIRM_INT_EQ ( u_strlen ( zeroString ) , 0 ) ;
}
else {
log_err ( " Couldn't get emptyexplicitstring \n " ) ;
}
status = U_ZERO_ERROR ;
strcpy ( action , " getting and testing of normal string of zero length string " ) ;
res = ures_getByKey ( theBundle , " emptystring " , res , & status ) ;
CONFIRM_ErrorCode ( status , U_ZERO_ERROR ) ;
CONFIRM_INT_EQ ( ures_getType ( res ) , RES_STRING ) ;
zeroString = ures_getString ( res , & len , & status ) ;
if ( U_SUCCESS ( status ) ) {
CONFIRM_ErrorCode ( status , U_ZERO_ERROR ) ;
CONFIRM_INT_EQ ( len , 0 ) ;
CONFIRM_INT_EQ ( u_strlen ( zeroString ) , 0 ) ;
}
else {
log_err ( " Couldn't get emptystring \n " ) ;
}
status = U_ZERO_ERROR ;
strcpy ( action , " getting and testing of empty int " ) ;
res = ures_getByKey ( theBundle , " emptyint " , res , & status ) ;
CONFIRM_ErrorCode ( status , U_ZERO_ERROR ) ;
CONFIRM_INT_EQ ( ures_getType ( res ) , RES_INT ) ;
intResult = ures_getInt ( res , & status ) ;
if ( U_SUCCESS ( status ) ) {
CONFIRM_ErrorCode ( status , U_ZERO_ERROR ) ;
CONFIRM_INT_EQ ( intResult , 0 ) ;
}
else {
log_err ( " Couldn't get emptystring \n " ) ;
}
status = U_ZERO_ERROR ;
strcpy ( action , " getting and testing of zero length intvector " ) ;
res = ures_getByKey ( theBundle , " emptyintv " , res , & status ) ;
CONFIRM_ErrorCode ( status , U_ZERO_ERROR ) ;
CONFIRM_INT_EQ ( ures_getType ( res ) , RES_INT_VECTOR ) ;
if ( U_FAILURE ( status ) ) {
log_err ( " Couldn't get emptyintv key %s \n " , u_errorName ( status ) ) ;
}
else {
zeroIntVect = ures_getIntVector ( res , & len , & status ) ;
2001-09-05 18:44:27 +00:00
if ( ! U_SUCCESS ( status ) | | resArray ! = NULL | | len ! = 0 ) {
2001-08-27 18:51:43 +00:00
log_err ( " Shouldn't get emptyintv \n " ) ;
}
}
status = U_ZERO_ERROR ;
strcpy ( action , " getting and testing of zero length emptybin " ) ;
res = ures_getByKey ( theBundle , " emptybin " , res , & status ) ;
CONFIRM_ErrorCode ( status , U_ZERO_ERROR ) ;
CONFIRM_INT_EQ ( ures_getType ( res ) , RES_BINARY ) ;
if ( U_FAILURE ( status ) ) {
log_err ( " Couldn't get emptybin key %s \n " , u_errorName ( status ) ) ;
}
else {
binResult = ures_getBinary ( res , & len , & status ) ;
2001-09-05 18:44:27 +00:00
if ( ! U_SUCCESS ( status ) | | binResult ! = NULL | | len ! = 0 ) {
2001-08-27 18:51:43 +00:00
log_err ( " Shouldn't get emptybin \n " ) ;
}
}
status = U_ZERO_ERROR ;
strcpy ( action , " getting and testing of zero length emptyarray " ) ;
res = ures_getByKey ( theBundle , " emptyarray " , res , & status ) ;
CONFIRM_ErrorCode ( status , U_ZERO_ERROR ) ;
CONFIRM_INT_EQ ( ures_getType ( res ) , RES_ARRAY ) ;
if ( U_FAILURE ( status ) ) {
log_err ( " Couldn't get emptyarray key %s \n " , u_errorName ( status ) ) ;
}
else {
resArray = ures_getByIndex ( res , 0 , resArray , & status ) ;
if ( U_SUCCESS ( status ) | | resArray ! = NULL ) {
log_err ( " Shouldn't get emptyarray \n " ) ;
}
}
status = U_ZERO_ERROR ;
strcpy ( action , " getting and testing of zero length emptytable " ) ;
res = ures_getByKey ( theBundle , " emptytable " , res , & status ) ;
CONFIRM_ErrorCode ( status , U_ZERO_ERROR ) ;
CONFIRM_INT_EQ ( ures_getType ( res ) , RES_TABLE ) ;
if ( U_FAILURE ( status ) ) {
log_err ( " Couldn't get emptytable key %s \n " , u_errorName ( status ) ) ;
}
else {
resArray = ures_getByIndex ( res , 0 , resArray , & status ) ;
if ( U_SUCCESS ( status ) | | resArray ! = NULL ) {
log_err ( " Shouldn't get emptytable \n " ) ;
}
}
ures_close ( res ) ;
ures_close ( theBundle ) ;
}
2001-08-17 22:15:39 +00:00
static void TestEmptyBundle ( ) {
UErrorCode status = U_ZERO_ERROR ;
char testdatapath [ 256 ] ;
const char * directory = u_getDataDirectory ( ) ;
UResourceBundle * resb = 0 , * dResB = 0 ;
2002-01-21 21:10:18 +00:00
const char * tdrelativepath = " .. " U_FILE_SEP_STRING " test " U_FILE_SEP_STRING " testdata " U_FILE_SEP_STRING " out " U_FILE_SEP_STRING ;
2001-08-17 22:15:39 +00:00
strcpy ( testdatapath , directory ) ;
2002-01-21 21:10:18 +00:00
strcat ( testdatapath , tdrelativepath ) ;
2001-08-17 22:15:39 +00:00
strcat ( testdatapath , " testdata " ) ;
resb = ures_open ( testdatapath , " testempty " , & status ) ;
if ( U_SUCCESS ( status ) ) {
dResB = ures_getByKey ( resb , " test " , dResB , & status ) ;
if ( status ! = U_MISSING_RESOURCE_ERROR ) {
log_err ( " Did not get the expected error from an empty resource bundle. Expected : %s Got: %s \n " ,
u_errorName ( U_MISSING_RESOURCE_ERROR ) , u_errorName ( status ) ) ;
}
}
ures_close ( dResB ) ;
ures_close ( resb ) ;
}
2000-11-21 04:05:39 +00:00
static void TestBinaryCollationData ( ) {
2000-08-28 21:43:03 +00:00
UErrorCode status = U_ZERO_ERROR ;
2000-05-24 23:42:34 +00:00
const char * directory = NULL ;
const char * locale = " te " ;
char testdatapath [ 256 ] ;
2000-08-28 21:43:03 +00:00
UResourceBundle * teRes = NULL ;
UResourceBundle * coll = NULL ;
UResourceBundle * binColl = NULL ;
uint8_t * binResult = NULL ;
int32_t len = 0 ;
2001-03-22 18:32:54 +00:00
const char * action = " testing the binary collaton data " ;
2002-01-21 21:10:18 +00:00
const char * tdrelativepath = " .. " U_FILE_SEP_STRING " test " U_FILE_SEP_STRING " testdata " U_FILE_SEP_STRING " out " U_FILE_SEP_STRING ;
2000-05-24 23:42:34 +00:00
2000-12-03 04:07:13 +00:00
directory = u_getDataDirectory ( ) ;
2000-05-24 23:42:34 +00:00
uprv_strcpy ( testdatapath , directory ) ;
2002-01-21 21:10:18 +00:00
uprv_strcat ( testdatapath , tdrelativepath ) ;
2000-05-24 23:42:34 +00:00
uprv_strcat ( testdatapath , " testdata " ) ;
log_verbose ( " Testing binary collation data resource...... \n " ) ;
2000-08-28 21:43:03 +00:00
teRes = ures_open ( testdatapath , locale , & status ) ;
if ( U_FAILURE ( status ) ) {
log_err ( " ERROR: Failed to get resource for \" te \" with %s " , myErrorName ( status ) ) ;
return ;
}
status = U_ZERO_ERROR ;
2000-05-24 23:42:34 +00:00
coll = ures_getByKey ( teRes , " CollationElements " , coll , & status ) ;
2000-08-28 21:43:03 +00:00
if ( U_SUCCESS ( status ) ) {
2000-05-24 23:42:34 +00:00
CONFIRM_ErrorCode ( status , U_ZERO_ERROR ) ;
2000-07-14 22:31:35 +00:00
CONFIRM_INT_EQ ( ures_getType ( coll ) , RES_TABLE ) ;
2001-03-16 22:17:57 +00:00
binColl = ures_getByKey ( teRes , " %%CollationNew " , binColl , & status ) ;
2000-08-28 21:43:03 +00:00
if ( U_SUCCESS ( status ) ) {
CONFIRM_ErrorCode ( status , U_ZERO_ERROR ) ;
CONFIRM_INT_EQ ( ures_getType ( binColl ) , RES_BINARY ) ;
binResult = ( uint8_t * ) ures_getBinary ( binColl , & len , & status ) ;
if ( U_SUCCESS ( status ) ) {
CONFIRM_ErrorCode ( status , U_ZERO_ERROR ) ;
CONFIRM_INT_GE ( len , 1 ) ;
}
} else {
2001-03-16 22:17:57 +00:00
log_err ( " ERROR: ures_getByKey(locale(te), %%CollationNew) failed \n " ) ;
2000-08-28 21:43:03 +00:00
}
}
else {
2001-01-23 02:51:46 +00:00
log_err ( " ERROR: ures_getByKey(locale(te), CollationElements) failed \n " ) ;
2000-08-28 21:43:03 +00:00
return ;
}
2000-07-12 22:59:57 +00:00
ures_close ( binColl ) ;
ures_close ( coll ) ;
ures_close ( teRes ) ;
2000-05-24 23:42:34 +00:00
}
2000-11-21 04:05:39 +00:00
static void TestAPI ( ) {
2000-07-12 01:09:23 +00:00
UErrorCode status = U_ZERO_ERROR ;
const char * directory = NULL ;
int32_t len = 0 ;
const char * key = NULL ;
const UChar * value = NULL ;
char testdatapath [ 256 ] ;
UChar utestdatapath [ 256 ] ;
2001-05-25 18:25:49 +00:00
char convOutput [ 256 ] ;
2000-08-28 21:43:03 +00:00
UResourceBundle * teRes = NULL ;
2000-07-12 01:09:23 +00:00
UResourceBundle * teFillin = NULL ;
UResourceBundle * teFillin2 = NULL ;
2002-01-21 21:10:18 +00:00
char * tdrelativepath = " .. " U_FILE_SEP_STRING " test " U_FILE_SEP_STRING " testdata " U_FILE_SEP_STRING " out " U_FILE_SEP_STRING ;
2000-12-03 04:07:13 +00:00
directory = u_getDataDirectory ( ) ;
2000-07-12 01:09:23 +00:00
uprv_strcpy ( testdatapath , directory ) ;
2002-01-21 21:10:18 +00:00
uprv_strcat ( testdatapath , tdrelativepath ) ;
2000-07-12 01:09:23 +00:00
uprv_strcat ( testdatapath , " testdata " ) ;
2000-08-02 19:06:18 +00:00
u_charsToUChars ( testdatapath , utestdatapath , strlen ( testdatapath ) + 1 ) ;
/*u_uastrcpy(utestdatapath, testdatapath);*/
2000-07-12 01:09:23 +00:00
/*Test ures_openU */
log_verbose ( " Testing ures_openU()...... \n " ) ;
2000-08-28 21:43:03 +00:00
teRes = ures_openU ( utestdatapath , " te " , & status ) ;
if ( U_FAILURE ( status ) ) {
log_err ( " ERROR: ures_openU() failed path =%s with %s " , austrdup ( utestdatapath ) , myErrorName ( status ) ) ;
return ;
}
2000-07-12 01:09:23 +00:00
/*Test ures_getLocale() */
log_verbose ( " Testing ures_getLocale() ..... \n " ) ;
if ( strcmp ( ures_getLocale ( teRes , & status ) , " te " ) ! = 0 ) {
log_err ( " ERROR: ures_getLocale() failed. Expected = te_TE Got = %s \n " , ures_getLocale ( teRes , & status ) ) ;
}
/*Test ures_getNextString() */
teFillin = ures_getByKey ( teRes , " tagged_array_in_te_te_IN " , teFillin , & status ) ;
key = ures_getKey ( teFillin ) ;
value = ( UChar * ) ures_getNextString ( teFillin , & len , & key , & status ) ;
ures_resetIterator ( NULL ) ;
value = ( UChar * ) ures_getNextString ( teFillin , & len , & key , & status ) ;
if ( status ! = U_INDEX_OUTOFBOUNDS_ERROR ) {
log_err ( " ERROR: calling getNextString where index out of bounds should return U_INDEX_OUTOFBOUNDS_ERROR, Got : %s \n " ,
myErrorName ( status ) ) ;
}
ures_resetIterator ( teRes ) ;
/*Test ures_getNextResource() where resource is table*/
status = U_ZERO_ERROR ;
teFillin = ures_getNextResource ( teRes , teFillin , & status ) ;
if ( U_FAILURE ( status ) ) {
log_err ( " ERROR: ures_getNextResource() failed \n " ) ;
}
key = ures_getKey ( teFillin ) ;
2001-03-16 22:17:57 +00:00
if ( strcmp ( key , " %%CollationNew " ) ! = 0 ) {
2000-07-12 01:09:23 +00:00
log_err ( " ERROR: ures_getNextResource() failed \n " ) ;
}
/*Test ures_getByIndex on string Resource*/
teFillin = ures_getByKey ( teRes , " string_only_in_te " , teFillin , & status ) ;
teFillin2 = ures_getByIndex ( teFillin , 0 , teFillin2 , & status ) ;
if ( U_FAILURE ( status ) ) {
log_err ( " ERROR: ures_getByIndex on string resource failed \n " ) ;
}
2001-05-25 18:25:49 +00:00
if ( strcmp ( u_austrcpy ( convOutput , ures_getString ( teFillin2 , & len , & status ) ) , " TE " ) ! = 0 ) {
2000-07-12 01:09:23 +00:00
status = U_ZERO_ERROR ;
log_err ( " ERROR: ures_getByIndex on string resource fetched the key=%s, expected \" TE \" \n " , austrdup ( ures_getString ( teFillin2 , & len , & status ) ) ) ;
}
2000-08-28 21:43:03 +00:00
2000-07-12 22:59:57 +00:00
/*ures_close(teRes);*/
2000-08-28 21:43:03 +00:00
2000-07-12 01:09:23 +00:00
/*Test ures_openFillIn*/
log_verbose ( " Testing ures_openFillIn...... \n " ) ;
status = U_ZERO_ERROR ;
ures_openFillIn ( teRes , testdatapath , " te " , & status ) ;
if ( U_FAILURE ( status ) ) {
log_err ( " ERROR: ures_openFillIn failed \n " ) ;
return ;
}
if ( strcmp ( ures_getLocale ( teRes , & status ) , " te " ) ! = 0 ) {
log_err ( " ERROR: ures_openFillIn did not open the ResourceBundle correctly \n " ) ;
}
ures_getByKey ( teRes , " string_only_in_te " , teFillin , & status ) ;
teFillin2 = ures_getNextResource ( teFillin , teFillin2 , & status ) ;
if ( ures_getType ( teFillin2 ) ! = RES_STRING ) {
log_err ( " ERROR: getType for getNextResource after ures_openFillIn failed \n " ) ;
}
teFillin2 = ures_getNextResource ( teFillin , teFillin2 , & status ) ;
if ( status ! = U_INDEX_OUTOFBOUNDS_ERROR ) {
log_err ( " ERROR: calling getNextResource where index out of bounds should return U_INDEX_OUTOFBOUNDS_ERROR, Got : %s \n " ,
myErrorName ( status ) ) ;
}
2000-08-28 21:43:03 +00:00
2000-07-12 22:59:57 +00:00
ures_close ( teFillin ) ;
ures_close ( teFillin2 ) ;
2000-07-12 01:09:23 +00:00
ures_close ( teRes ) ;
2001-10-11 00:52:21 +00:00
/* Test that ures_getLocale() returns the "real" locale ID */
status = U_ZERO_ERROR ;
teRes = ures_open ( NULL , " dE_At_NOWHERE_TO_BE_FOUND " , & status ) ;
if ( U_FAILURE ( status ) ) {
log_err ( " unable to open a locale resource bundle from \" dE_At_NOWHERE_TO_BE_FOUND \" (%s) \n " , u_errorName ( status ) ) ;
} else {
if ( 0 ! = strcmp ( " de_AT " , ures_getLocale ( teRes , & status ) ) ) {
log_err ( " ures_getLocale( \" dE_At_NOWHERE_TO_BE_FOUND \" )=%s but must be de_AT \n " , ures_getLocale ( teRes , & status ) ) ;
}
ures_close ( teRes ) ;
}
2001-10-11 16:12:08 +00:00
/* same test, but with an aliased locale resource bundle */
status = U_ZERO_ERROR ;
teRes = ures_open ( NULL , " iW_Il_depRecaTed_HebreW " , & status ) ;
if ( U_FAILURE ( status ) ) {
log_err ( " unable to open a locale resource bundle from \" iW_Il_depRecaTed_HebreW \" (%s) \n " , u_errorName ( status ) ) ;
} else {
if ( 0 ! = strcmp ( " he_IL " , ures_getLocale ( teRes , & status ) ) ) {
log_err ( " ures_getLocale( \" iW_Il_depRecaTed_HebreW \" )=%s but must be he_IL \n " , ures_getLocale ( teRes , & status ) ) ;
}
ures_close ( teRes ) ;
}
2000-07-12 01:09:23 +00:00
}
2000-11-21 04:05:39 +00:00
static void TestErrorConditions ( ) {
2000-07-12 01:09:23 +00:00
UErrorCode status ;
const char * directory = NULL ;
const char * key = NULL ;
const UChar * value = NULL ;
char testdatapath [ 256 ] ;
UChar utestdatapath [ 256 ] ;
int32_t len = 0 ;
2000-08-28 21:43:03 +00:00
UResourceBundle * teRes = NULL ;
2000-07-12 01:09:23 +00:00
UResourceBundle * coll = NULL ;
2000-08-28 21:43:03 +00:00
UResourceBundle * binColl = NULL ;
2000-07-12 01:09:23 +00:00
UResourceBundle * teFillin = NULL ;
UResourceBundle * teFillin2 = NULL ;
2000-08-28 21:43:03 +00:00
uint8_t * binResult = NULL ;
2001-03-22 00:42:37 +00:00
int32_t resultLen ;
2002-01-21 21:10:18 +00:00
const char * tdrelativepath = " .. " U_FILE_SEP_STRING " test " U_FILE_SEP_STRING " testdata " U_FILE_SEP_STRING " out " U_FILE_SEP_STRING ;
2000-05-24 23:42:34 +00:00
2000-12-03 04:07:13 +00:00
directory = u_getDataDirectory ( ) ;
2000-07-12 01:09:23 +00:00
uprv_strcpy ( testdatapath , directory ) ;
2002-01-21 21:10:18 +00:00
uprv_strcat ( testdatapath , tdrelativepath ) ;
2000-07-12 01:09:23 +00:00
uprv_strcat ( testdatapath , " testdata " ) ;
u_uastrcpy ( utestdatapath , testdatapath ) ;
/*Test ures_openU with status != U_ZERO_ERROR*/
log_verbose ( " Testing ures_openU() with status != U_ZERO_ERROR..... \n " ) ;
status = U_ILLEGAL_ARGUMENT_ERROR ;
2000-08-28 21:43:03 +00:00
teRes = ures_openU ( utestdatapath , " te " , & status ) ;
if ( U_FAILURE ( status ) ) {
2001-05-25 18:25:49 +00:00
log_verbose ( " ERROR: ures_openU() failed as expected path =%s with status != U_ZERO_ERROR " , testdatapath ) ;
2000-07-12 01:09:23 +00:00
} else {
log_err ( " ERROR: ures_openU() is supposed to fail path =%s with status != U_ZERO_ERROR " , austrdup ( utestdatapath ) ) ;
ures_close ( teRes ) ;
}
/*Test ures_openFillIn with UResourceBundle = NULL*/
log_verbose ( " Testing ures_openFillIn with UResourceBundle = NULL..... \n " ) ;
status = U_ZERO_ERROR ;
ures_openFillIn ( NULL , testdatapath , " te " , & status ) ;
if ( status ! = U_INTERNAL_PROGRAM_ERROR ) {
log_err ( " ERROR: ures_openFillIn with UResourceBundle= NULL should fail. Expected U_INTERNAL_PROGRAM_ERROR, Got: %s \n " ,
myErrorName ( status ) ) ;
}
/*Test ures_getLocale() with status != U_ZERO_ERROR*/
status = U_ZERO_ERROR ;
teRes = ures_openU ( utestdatapath , " te " , & status ) ;
2000-08-28 21:43:03 +00:00
if ( U_FAILURE ( status ) ) {
log_err ( " ERROR: ures_openU() failed path =%s with %s " , austrdup ( utestdatapath ) , myErrorName ( status ) ) ;
return ;
}
2000-07-12 01:09:23 +00:00
status = U_ILLEGAL_ARGUMENT_ERROR ;
if ( ures_getLocale ( teRes , & status ) ! = NULL ) {
log_err ( " ERROR: ures_getLocale is supposed to fail with errorCode != U_ZERO_ERROR \n " ) ;
}
/*Test ures_getLocale() with UResourceBundle = NULL*/
status = U_ZERO_ERROR ;
if ( ures_getLocale ( NULL , & status ) ! = NULL & & status ! = U_ILLEGAL_ARGUMENT_ERROR ) {
log_err ( " ERROR: ures_getLocale is supposed to fail when UResourceBundle = NULL. Expected: errorCode = U_ILLEGAL_ARGUMENT_ERROR, Got: errorCode=%s \n " ,
myErrorName ( status ) ) ;
}
/*Test ures_getSize() with UResourceBundle = NULL */
status = U_ZERO_ERROR ;
if ( ures_getSize ( NULL ) ! = 0 ) {
log_err ( " ERROR: ures_getSize() should return 0 when UResourceBundle=NULL. Got =%d \n " , ures_getSize ( NULL ) ) ;
}
/*Test ures_getType() with UResourceBundle = NULL should return RES_BOGUS or -1*/
status = U_ZERO_ERROR ;
2000-08-16 20:45:23 +00:00
if ( ures_getType ( NULL ) ! = RES_NONE ) {
log_err ( " ERROR: ures_getType() should return RES_NONE when UResourceBundle=NULL. Got =%d \n " , ures_getType ( NULL ) ) ;
2000-07-12 01:09:23 +00:00
}
/*Test ures_getKey() with UResourceBundle = NULL*/
status = U_ZERO_ERROR ;
if ( ures_getKey ( NULL ) ! = NULL ) {
log_err ( " ERROR: ures_getKey() should return NULL when UResourceBundle=NULL. Got =%d \n " , ures_getKey ( NULL ) ) ;
}
/*Test ures_hasNext() with UResourceBundle = NULL*/
status = U_ZERO_ERROR ;
if ( ures_hasNext ( NULL ) ! = FALSE ) {
log_err ( " ERROR: ures_hasNext() should return FALSE when UResourceBundle=NULL. Got =%d \n " , ures_hasNext ( NULL ) ) ;
}
/*Test ures_get() with UResourceBundle = NULL*/
status = U_ZERO_ERROR ;
2001-03-22 00:42:37 +00:00
if ( ures_getStringByKey ( NULL , " string_only_in_te " , & resultLen , & status ) ! = NULL & & status ! = U_ILLEGAL_ARGUMENT_ERROR ) {
2000-07-12 01:09:23 +00:00
log_err ( " ERROR: ures_get is supposed to fail when UResourceBundle = NULL. Expected: errorCode = U_ILLEGAL_ARGUMENT_ERROR, Got: errorCode=%s \n " ,
myErrorName ( status ) ) ;
}
/*Test ures_getByKey() with UResourceBundle = NULL*/
status = U_ZERO_ERROR ;
teFillin = ures_getByKey ( NULL , " string_only_in_te " , teFillin , & status ) ;
if ( teFillin ! = NULL & & status ! = U_ILLEGAL_ARGUMENT_ERROR ) {
log_err ( " ERROR: ures_getByKey is supposed to fail when UResourceBundle = NULL. Expected: errorCode = U_ILLEGAL_ARGUMENT_ERROR, Got: errorCode=%s \n " ,
myErrorName ( status ) ) ;
}
/*Test ures_getByKey() with status != U_ZERO_ERROR*/
teFillin = ures_getByKey ( NULL , " string_only_in_te " , teFillin , & status ) ;
if ( teFillin ! = NULL ) {
log_err ( " ERROR: ures_getByKey is supposed to fail when errorCode != U_ZERO_ERROR \n " ) ;
}
/*Test ures_getStringByKey() with UResourceBundle = NULL*/
status = U_ZERO_ERROR ;
if ( ures_getStringByKey ( NULL , " string_only_in_te " , & len , & status ) ! = NULL & & status ! = U_ILLEGAL_ARGUMENT_ERROR ) {
log_err ( " ERROR: ures_getStringByKey is supposed to fail when UResourceBundle = NULL. Expected: errorCode = U_ILLEGAL_ARGUMENT_ERROR, Got: errorCode=%s \n " ,
myErrorName ( status ) ) ;
}
/*Test ures_getStringByKey() with status != U_ZERO_ERROR*/
if ( ures_getStringByKey ( teRes , " string_only_in_te " , & len , & status ) ! = NULL ) {
log_err ( " ERROR: ures_getStringByKey is supposed to fail when status != U_ZERO_ERROR. Expected: errorCode = U_ILLEGAL_ARGUMENT_ERROR, Got: errorCode=%s \n " ,
myErrorName ( status ) ) ;
}
/*Test ures_getString() with UResourceBundle = NULL*/
status = U_ZERO_ERROR ;
if ( ures_getString ( NULL , & len , & status ) ! = NULL & & status ! = U_ILLEGAL_ARGUMENT_ERROR ) {
log_err ( " ERROR: ures_getString is supposed to fail when UResourceBundle = NULL. Expected: errorCode = U_ILLEGAL_ARGUMENT_ERROR, Got: errorCode=%s \n " ,
myErrorName ( status ) ) ;
}
/*Test ures_getString() with status != U_ZERO_ERROR*/
if ( ures_getString ( teRes , & len , & status ) ! = NULL ) {
log_err ( " ERROR: ures_getString is supposed to fail when status != U_ZERO_ERROR. Expected: errorCode = U_ILLEGAL_ARGUMENT_ERROR, Got: errorCode=%s \n " ,
myErrorName ( status ) ) ;
}
/*Test ures_getBinary() with UResourceBundle = NULL*/
status = U_ZERO_ERROR ;
if ( ures_getBinary ( NULL , & len , & status ) ! = NULL & & status ! = U_ILLEGAL_ARGUMENT_ERROR ) {
log_err ( " ERROR: ures_getBinary is supposed to fail when UResourceBundle = NULL. Expected: errorCode = U_ILLEGAL_ARGUMENT_ERROR, Got: errorCode=%s \n " ,
myErrorName ( status ) ) ;
}
/*Test ures_getBinary(0 status != U_ILLEGAL_ARGUMENT_ERROR*/
status = U_ZERO_ERROR ;
coll = ures_getByKey ( teRes , " CollationElements " , coll , & status ) ;
2001-03-17 00:56:21 +00:00
binColl = ures_getByKey ( teRes , " %%CollationNew " , binColl , & status ) ;
2000-08-28 21:43:03 +00:00
2000-07-12 01:09:23 +00:00
status = U_ILLEGAL_ARGUMENT_ERROR ;
2000-08-28 21:43:03 +00:00
binResult = ( uint8_t * ) ures_getBinary ( binColl , & len , & status ) ;
2000-07-12 01:09:23 +00:00
if ( binResult ! = NULL ) {
log_err ( " ERROR: ures_getBinary() with status != U_ZERO_ERROR is supposed to fail \n " ) ;
}
/*Test ures_getNextResource() with status != U_ZERO_ERROR*/
teFillin = ures_getNextResource ( teRes , teFillin , & status ) ;
if ( teFillin ! = NULL ) {
log_err ( " ERROR: ures_getNextResource() with errorCode != U_ZERO_ERROR is supposed to fail \n " ) ;
}
/*Test ures_getNextResource() with UResourceBundle = NULL*/
status = U_ZERO_ERROR ;
teFillin = ures_getNextResource ( NULL , teFillin , & status ) ;
if ( teFillin ! = NULL | | status ! = U_ILLEGAL_ARGUMENT_ERROR ) {
log_err ( " ERROR: ures_getNextResource() with UResourceBundle = NULL is supposed to fail. Expected : U_IILEGAL_ARGUMENT_ERROR, Got : %s \n " ,
myErrorName ( status ) ) ;
}
/*Test ures_getNextString with errorCode != U_ZERO_ERROR*/
teFillin = ures_getByKey ( teRes , " tagged_array_in_te_te_IN " , teFillin , & status ) ;
key = ures_getKey ( teFillin ) ;
status = U_ILLEGAL_ARGUMENT_ERROR ;
value = ( UChar * ) ures_getNextString ( teFillin , & len , & key , & status ) ;
if ( value ! = NULL ) {
log_err ( " ERROR: ures_getNextString() with errorCode != U_ZERO_ERROR is supposed to fail \n " ) ;
}
/*Test ures_getNextString with UResourceBundle = NULL*/
status = U_ZERO_ERROR ;
value = ( UChar * ) ures_getNextString ( NULL , & len , & key , & status ) ;
if ( value ! = NULL | | status ! = U_ILLEGAL_ARGUMENT_ERROR ) {
log_err ( " ERROR: ures_getNextString() with UResourceBundle=NULL is supposed to fail \n Expected: U_ILLEGAL_ARGUMENT_ERROR, Got: %s \n " ,
myErrorName ( status ) ) ;
}
/*Test ures_getByIndex with errorCode != U_ZERO_ERROR*/
status = U_ZERO_ERROR ;
teFillin = ures_getByKey ( teRes , " array_only_in_te " , teFillin , & status ) ;
2001-09-18 16:09:48 +00:00
if ( ures_countArrayItems ( teRes , " array_only_in_te " , & status ) ! = 4 ) {
log_err ( " ERROR: Wrong number of items in an array! \n " ) ;
}
2000-07-12 01:09:23 +00:00
status = U_ILLEGAL_ARGUMENT_ERROR ;
teFillin2 = ures_getByIndex ( teFillin , 0 , teFillin2 , & status ) ;
if ( teFillin2 ! = NULL ) {
log_err ( " ERROR: ures_getByIndex() with errorCode != U_ZERO_ERROR is supposed to fail \n " ) ;
}
/*Test ures_getByIndex with UResourceBundle = NULL */
status = U_ZERO_ERROR ;
teFillin2 = ures_getByIndex ( NULL , 0 , teFillin2 , & status ) ;
if ( status ! = U_ILLEGAL_ARGUMENT_ERROR ) {
log_err ( " ERROR: ures_getByIndex() with UResourceBundle=NULL is supposed to fail \n Expected: U_ILLEGAL_ARGUMENT_ERROR, Got: %s \n " ,
myErrorName ( status ) ) ;
}
/*Test ures_getStringByIndex with errorCode != U_ZERO_ERROR*/
status = U_ZERO_ERROR ;
teFillin = ures_getByKey ( teRes , " array_only_in_te " , teFillin , & status ) ;
status = U_ILLEGAL_ARGUMENT_ERROR ;
value = ( UChar * ) ures_getStringByIndex ( teFillin , 0 , & len , & status ) ;
if ( value ! = NULL ) {
log_err ( " ERROR: ures_getSringByIndex() with errorCode != U_ZERO_ERROR is supposed to fail \n " ) ;
}
/*Test ures_getStringByIndex with UResourceBundle = NULL */
status = U_ZERO_ERROR ;
value = ( UChar * ) ures_getStringByIndex ( NULL , 0 , & len , & status ) ;
if ( value ! = NULL | | status ! = U_ILLEGAL_ARGUMENT_ERROR ) {
log_err ( " ERROR: ures_getStringByIndex() with UResourceBundle=NULL is supposed to fail \n Expected: U_ILLEGAL_ARGUMENT_ERROR, Got: %s \n " ,
myErrorName ( status ) ) ;
}
2001-09-18 16:09:48 +00:00
/*Test ures_getStringByIndex with UResourceBundle = NULL */
status = U_ZERO_ERROR ;
value = ( UChar * ) ures_getStringByIndex ( teFillin , 9999 , & len , & status ) ;
if ( value ! = NULL | | status ! = U_MISSING_RESOURCE_ERROR ) {
log_err ( " ERROR: ures_getStringByIndex() with index that is too big is supposed to fail \n Expected: U_MISSING_RESOURCE_ERROR, Got: %s \n " ,
myErrorName ( status ) ) ;
}
2000-07-12 01:09:23 +00:00
/*Test ures_getInt() where UResourceBundle = NULL */
status = U_ZERO_ERROR ;
if ( ures_getInt ( NULL , & status ) ! = - 1 & & status ! = U_ILLEGAL_ARGUMENT_ERROR ) {
log_err ( " ERROR: ures_getInt() with UResourceBundle = NULL should fail. Expected: U_IILEGAL_ARGUMENT_ERROR, Got: %s \n " ,
myErrorName ( status ) ) ;
}
/*Test ures_getInt() where status != U_ZERO_ERROR */
if ( ures_getInt ( teRes , & status ) ! = - 1 ) {
log_err ( " ERROR: ures_getInt() with errorCode != U_ZERO_ERROR should fail \n " ) ;
}
2000-07-12 22:59:57 +00:00
ures_close ( teFillin ) ;
ures_close ( teFillin2 ) ;
ures_close ( coll ) ;
ures_close ( binColl ) ;
2000-07-12 01:09:23 +00:00
ures_close ( teRes ) ;
}
2000-05-15 18:39:17 +00:00
2001-03-21 00:55:52 +00:00
static void TestGetVersion ( ) {
UVersionInfo minVersionArray = { 0x01 , 0x01 , 0x00 , 0x00 } ;
UVersionInfo maxVersionArray = { 0x50 , 0x80 , 0xcf , 0xcf } ;
UVersionInfo versionArray ;
UErrorCode status = U_ZERO_ERROR ;
UResourceBundle * resB = ures_open ( NULL , " root " , & status ) ;
int i = 0 ;
log_verbose ( " The ures_getVersion tests begin : \n " ) ;
if ( U_FAILURE ( status ) ) {
log_err ( " Default en_US resource bundle creation failed.: %s \n " , myErrorName ( status ) ) ;
return ;
}
ures_getVersion ( resB , versionArray ) ;
for ( i = 0 ; i < 4 ; + + i ) {
2001-05-25 18:25:49 +00:00
if ( versionArray [ i ] < minVersionArray [ i ] | |
versionArray [ i ] > maxVersionArray [ i ] )
{
log_err ( " Testing ucol_getVersion() - unexpected result: %d.%d.%d.%d \n " ,
versionArray [ 0 ] , versionArray [ 1 ] , versionArray [ 2 ] , versionArray [ 3 ] ) ;
break ;
}
2001-03-21 00:55:52 +00:00
}
2001-05-25 18:25:49 +00:00
ures_close ( resB ) ;
2001-03-21 00:55:52 +00:00
}
2000-11-21 04:05:39 +00:00
static void TestResourceBundles ( )
2000-05-15 18:39:17 +00:00
{
testTag ( " only_in_Root " , TRUE , FALSE , FALSE ) ;
testTag ( " in_Root_te " , TRUE , TRUE , FALSE ) ;
testTag ( " in_Root_te_te_IN " , TRUE , TRUE , TRUE ) ;
testTag ( " in_Root_te_IN " , TRUE , FALSE , TRUE ) ;
testTag ( " only_in_te " , FALSE , TRUE , FALSE ) ;
testTag ( " only_in_te_IN " , FALSE , FALSE , TRUE ) ;
testTag ( " in_te_te_IN " , FALSE , TRUE , TRUE ) ;
testTag ( " nonexistent " , FALSE , FALSE , FALSE ) ;
log_verbose ( " Passed:= %d Failed= %d \n " , pass , fail ) ;
}
2000-11-21 04:05:39 +00:00
static void TestConstruction1 ( )
2000-05-15 18:39:17 +00:00
{
2001-04-17 19:09:23 +00:00
UResourceBundle * test1 = 0 , * test2 = 0 , * empty = 0 ;
2000-08-28 21:43:03 +00:00
const UChar * result1 , * result2 ;
UErrorCode status = U_ZERO_ERROR ;
UErrorCode err = U_ZERO_ERROR ;
const char * directory = NULL ;
const char * locale = " te_IN " ;
char testdatapath [ 256 ] ;
2002-01-21 21:10:18 +00:00
const char * tdrelativepath = " .. " U_FILE_SEP_STRING " test " U_FILE_SEP_STRING " testdata " U_FILE_SEP_STRING " out " U_FILE_SEP_STRING ;
2000-08-28 21:43:03 +00:00
int32_t len1 = 0 ;
int32_t len2 = 0 ;
UVersionInfo versionInfo ;
char versionString [ 256 ] ;
2001-05-25 18:25:49 +00:00
char verboseOutput [ 256 ] ;
2000-08-28 21:43:03 +00:00
U_STRING_DECL ( rootVal , " ROOT " , 4 ) ;
U_STRING_DECL ( te_inVal , " TE_IN " , 5 ) ;
U_STRING_INIT ( rootVal , " ROOT " , 4 ) ;
U_STRING_INIT ( te_inVal , " TE_IN " , 5 ) ;
2000-12-03 04:07:13 +00:00
directory = u_getDataDirectory ( ) ;
2000-08-28 21:43:03 +00:00
uprv_strcpy ( testdatapath , directory ) ;
2002-01-21 21:10:18 +00:00
uprv_strcat ( testdatapath , tdrelativepath ) ;
uprv_strcat ( testdatapath , " testdata " ) ;
2000-08-28 21:43:03 +00:00
log_verbose ( " Testing ures_open()...... \n " ) ;
2001-10-11 18:41:03 +00:00
empty = ures_open ( testdatapath , " testempty " , & status ) ;
2001-04-17 19:09:23 +00:00
if ( empty = = NULL | | U_FAILURE ( status ) ) {
2001-05-25 18:25:49 +00:00
log_err ( " opening empty failed! \n " ) ;
2001-04-17 19:09:23 +00:00
}
ures_close ( empty ) ;
2000-08-28 21:43:03 +00:00
test1 = ures_open ( testdatapath , NULL , & err ) ;
if ( U_FAILURE ( err ) )
2000-05-15 18:39:17 +00:00
{
2002-01-21 21:10:18 +00:00
log_err ( " construction of NULL did not succeed : %s \n " , myErrorName ( status ) ) ;
return ;
}
test2 = ures_open ( testdatapath , locale , & err ) ;
if ( U_FAILURE ( err ) )
{
log_err ( " construction of %s did not succeed : %s \n " , locale , myErrorName ( status ) ) ;
2000-08-28 21:43:03 +00:00
return ;
2000-05-15 18:39:17 +00:00
}
2000-08-28 21:43:03 +00:00
result1 = ures_getStringByKey ( test1 , " string_in_Root_te_te_IN " , & len1 , & err ) ;
result2 = ures_getStringByKey ( test2 , " string_in_Root_te_te_IN " , & len2 , & err ) ;
if ( U_FAILURE ( err ) | | len1 = = 0 | | len2 = = 0 ) {
log_err ( " Something threw an error in TestConstruction(): %s \n " , myErrorName ( status ) ) ;
return ;
}
2001-05-25 18:25:49 +00:00
log_verbose ( " for string_in_Root_te_te_IN, default.txt had %s \n " , u_austrcpy ( verboseOutput , result1 ) ) ;
log_verbose ( " for string_in_Root_te_te_IN, te_IN.txt had %s \n " , u_austrcpy ( verboseOutput , result2 ) ) ;
2000-08-28 21:43:03 +00:00
if ( u_strcmp ( result1 , rootVal ) ! = 0 | | u_strcmp ( result2 , te_inVal ) ! = 0 ) {
log_err ( " construction test failed. Run Verbose for more information " ) ;
}
2000-05-15 18:39:17 +00:00
2000-08-28 21:43:03 +00:00
/* Test getVersionNumber*/
log_verbose ( " Testing version number \n " ) ;
log_verbose ( " for getVersionNumber : %s \n " , ures_getVersionNumber ( test1 ) ) ;
2000-05-15 18:39:17 +00:00
2000-08-28 21:43:03 +00:00
log_verbose ( " Testing version \n " ) ;
ures_getVersion ( test1 , versionInfo ) ;
u_versionToString ( versionInfo , versionString ) ;
2000-08-10 20:20:10 +00:00
2000-08-28 21:43:03 +00:00
log_verbose ( " for getVersion : %s \n " , versionString ) ;
2000-08-10 20:20:10 +00:00
2000-08-28 21:43:03 +00:00
if ( strcmp ( versionString , ures_getVersionNumber ( test1 ) ) ! = 0 ) {
log_err ( " Versions differ: %s vs %s \n " , versionString , ures_getVersionNumber ( test1 ) ) ;
}
2000-08-10 20:20:10 +00:00
2000-08-28 21:43:03 +00:00
ures_close ( test1 ) ;
ures_close ( test2 ) ;
2001-04-17 19:09:23 +00:00
2000-05-15 18:39:17 +00:00
}
2000-11-21 04:05:39 +00:00
static void TestConstruction2 ( )
2000-05-15 18:39:17 +00:00
{
2000-08-28 21:43:03 +00:00
UChar temp [ 7 ] ;
UResourceBundle * test4 = 0 ;
const UChar * result4 ;
UErrorCode err = U_ZERO_ERROR ;
const char * directory ;
const char * locale = " te_IN " ;
wchar_t widedirectory [ 256 ] ;
char testdatapath [ 256 ] ;
int32_t len = 0 ;
2001-05-25 18:25:49 +00:00
char verboseOutput [ 256 ] ;
2000-05-15 18:39:17 +00:00
2000-12-03 04:07:13 +00:00
directory = u_getDataDirectory ( ) ;
2000-08-28 21:43:03 +00:00
uprv_strcpy ( testdatapath , directory ) ;
uprv_strcat ( testdatapath , " testdata " ) ;
mbstowcs ( widedirectory , testdatapath , 256 ) ;
2000-05-15 18:39:17 +00:00
2000-08-28 21:43:03 +00:00
log_verbose ( " Testing ures_openW()....... \n " ) ;
2000-05-15 18:39:17 +00:00
2000-08-28 21:43:03 +00:00
test4 = ures_openW ( widedirectory , locale , & err ) ;
if ( U_FAILURE ( err ) ) {
log_err ( " Error in the construction using ures_openW(): %s \n " , myErrorName ( err ) ) ;
return ;
}
2000-05-15 18:39:17 +00:00
2000-08-28 21:43:03 +00:00
result4 = ures_getStringByKey ( test4 , " string_in_Root_te_te_IN " , & len , & err ) ;
if ( U_FAILURE ( err ) | | len = = 0 ) {
log_err ( " Something threw an error in TestConstruction() %s \n " , myErrorName ( err ) ) ;
return ;
}
2001-05-25 18:25:49 +00:00
log_verbose ( " for string_in_Root_te_te_IN, te_IN.txt had %s \n " , u_austrcpy ( verboseOutput , result4 ) ) ;
2000-08-28 21:43:03 +00:00
u_uastrcpy ( temp , " TE_IN " ) ;
if ( u_strcmp ( result4 , temp ) ! = 0 )
{
log_err ( " Construction test failed for ures_openW(); \n " ) ;
if ( ! VERBOSITY )
log_info ( " (run verbose for more information) \n " ) ;
log_verbose ( " \n Got-> " ) ;
printUChars ( ( UChar * ) result4 ) ;
log_verbose ( " Want-> " ) ;
printUChars ( temp ) ;
log_verbose ( " \n " ) ;
}
ures_close ( test4 ) ;
2000-05-15 18:39:17 +00:00
}
/*****************************************************************************/
/*****************************************************************************/
2000-11-21 04:05:39 +00:00
static UBool testTag ( const char * frag ,
2000-05-18 22:08:39 +00:00
UBool in_Root ,
UBool in_te ,
UBool in_te_IN )
2000-05-15 18:39:17 +00:00
{
2001-03-22 18:32:54 +00:00
int32_t failNum = fail ;
2000-08-28 21:43:03 +00:00
/* Make array from input params */
UBool is_in [ 3 ] ;
const char * NAME [ ] = { " ROOT " , " TE " , " TE_IN " } ;
/* Now try to load the desired items */
UResourceBundle * theBundle = NULL ;
char tag [ 99 ] ;
char action [ 256 ] ;
UErrorCode expected_status , status = U_ZERO_ERROR , expected_resource_status = U_ZERO_ERROR ;
UChar * base = NULL ;
UChar * expected_string = NULL ;
const UChar * string = NULL ;
char buf [ 5 ] ;
char item_tag [ 10 ] ;
int32_t i , j , row , col , len ;
int32_t actual_bundle ;
int32_t count = 0 ;
int32_t row_count = 0 ;
int32_t column_count = 0 ;
int32_t index = 0 ;
int32_t tag_count = 0 ;
char testdatapath [ 256 ] ;
2001-05-25 18:25:49 +00:00
char verboseOutput [ 256 ] ;
2000-08-28 21:43:03 +00:00
UResourceBundle * array = NULL ;
UResourceBundle * array2d = NULL ;
UResourceBundle * tags = NULL ;
UResourceBundle * arrayItem1 = NULL ;
2000-12-03 04:07:13 +00:00
const char * directory = u_getDataDirectory ( ) ;
2002-01-21 21:10:18 +00:00
const char * tdrelativepath = " .. " U_FILE_SEP_STRING " test " U_FILE_SEP_STRING " testdata " U_FILE_SEP_STRING " out " U_FILE_SEP_STRING ;
2000-08-28 21:43:03 +00:00
uprv_strcpy ( testdatapath , directory ) ;
2002-01-21 21:10:18 +00:00
uprv_strcat ( testdatapath , tdrelativepath ) ;
2000-08-28 21:43:03 +00:00
uprv_strcat ( testdatapath , " testdata " ) ;
is_in [ 0 ] = in_Root ;
is_in [ 1 ] = in_te ;
is_in [ 2 ] = in_te_IN ;
strcpy ( item_tag , " tag " ) ;
for ( i = 0 ; i < bundles_count ; + + i )
2000-05-15 18:39:17 +00:00
{
2001-10-11 18:41:03 +00:00
strcpy ( action , " construction for " ) ;
2000-08-28 21:43:03 +00:00
strcat ( action , param [ i ] . name ) ;
2000-05-15 18:39:17 +00:00
2000-08-28 21:43:03 +00:00
status = U_ZERO_ERROR ;
2000-05-15 18:39:17 +00:00
2000-08-28 21:43:03 +00:00
theBundle = ures_open ( testdatapath , param [ i ] . name , & status ) ;
CONFIRM_ErrorCode ( status , param [ i ] . expected_constructor_status ) ;
2000-05-15 18:39:17 +00:00
2000-08-28 21:43:03 +00:00
if ( i = = 5 )
actual_bundle = 0 ; /* ne -> default */
else if ( i = = 3 )
actual_bundle = 1 ; /* te_NE -> te */
else if ( i = = 4 )
actual_bundle = 2 ; /* te_IN_NE -> te_IN */
else
actual_bundle = i ;
2000-05-15 18:39:17 +00:00
2000-08-28 21:43:03 +00:00
expected_resource_status = U_MISSING_RESOURCE_ERROR ;
for ( j = e_te_IN ; j > = e_Root ; - - j )
2000-05-15 18:39:17 +00:00
{
2000-08-28 21:43:03 +00:00
if ( is_in [ j ] & & param [ i ] . inherits [ j ] )
2000-05-15 18:39:17 +00:00
{
2000-08-28 21:43:03 +00:00
if ( j = = actual_bundle ) /* it's in the same bundle OR it's a nonexistent=default bundle (5) */
expected_resource_status = U_ZERO_ERROR ;
else if ( j = = 0 )
expected_resource_status = U_USING_DEFAULT_ERROR ;
else
expected_resource_status = U_USING_FALLBACK_ERROR ;
log_verbose ( " %s[%d]::%s: in<%d:%s> inherits<%d:%s>. actual_bundle=%s \n " ,
param [ i ] . name ,
i ,
frag ,
j ,
is_in [ j ] ? " Yes " : " No " ,
j ,
param [ i ] . inherits [ j ] ? " Yes " : " No " ,
param [ actual_bundle ] . name ) ;
break ;
2000-05-15 18:39:17 +00:00
}
}
2000-08-28 21:43:03 +00:00
for ( j = param [ i ] . where ; j > = 0 ; - - j )
2000-05-15 18:39:17 +00:00
{
2000-08-28 21:43:03 +00:00
if ( is_in [ j ] )
{
if ( base ! = NULL ) {
free ( base ) ;
base = NULL ;
}
2001-05-24 20:59:12 +00:00
base = ( UChar * ) uprv_malloc ( sizeof ( UChar ) * ( strlen ( NAME [ j ] ) + 1 ) ) ;
2000-08-28 21:43:03 +00:00
u_uastrcpy ( base , NAME [ j ] ) ;
break ;
}
else {
if ( base ! = NULL ) {
free ( base ) ;
base = NULL ;
}
2001-05-24 20:59:12 +00:00
base = ( UChar * ) uprv_malloc ( sizeof ( UChar ) * 1 ) ;
2000-08-28 21:43:03 +00:00
* base = 0x0000 ;
2000-05-15 18:39:17 +00:00
}
}
2000-08-28 21:43:03 +00:00
/*----string---------------------------------------------------------------- */
2000-05-15 18:39:17 +00:00
2000-08-28 21:43:03 +00:00
strcpy ( tag , " string_ " ) ;
strcat ( tag , frag ) ;
2000-05-15 18:39:17 +00:00
2000-08-28 21:43:03 +00:00
strcpy ( action , param [ i ] . name ) ;
strcat ( action , " .ures_getStringByKey( " ) ;
strcat ( action , tag ) ;
strcat ( action , " ) " ) ;
status = U_ZERO_ERROR ;
len = 0 ;
string = ures_getStringByKey ( theBundle , tag , & len , & status ) ;
if ( U_SUCCESS ( status ) ) {
2001-05-24 20:59:12 +00:00
expected_string = ( UChar * ) uprv_malloc ( sizeof ( UChar ) * ( u_strlen ( base ) + 4 ) ) ;
2000-08-28 21:43:03 +00:00
u_strcpy ( expected_string , base ) ;
CONFIRM_INT_EQ ( len , u_strlen ( expected_string ) ) ;
} else {
2001-05-24 20:59:12 +00:00
expected_string = ( UChar * ) uprv_malloc ( sizeof ( UChar ) * ( u_strlen ( kERROR ) + 1 ) ) ;
2000-08-28 21:43:03 +00:00
u_strcpy ( expected_string , kERROR ) ;
string = kERROR ;
}
log_verbose ( " %s got %d, expected %d \n " , action , status , expected_resource_status ) ;
CONFIRM_ErrorCode ( status , expected_resource_status ) ;
CONFIRM_EQ ( string , expected_string ) ;
/*--------------array------------------------------------------------- */
strcpy ( tag , " array_ " ) ;
strcat ( tag , frag ) ;
strcpy ( action , param [ i ] . name ) ;
strcat ( action , " .ures_getByKey( " ) ;
strcat ( action , tag ) ;
strcat ( action , " ) " ) ;
len = 0 ;
count = kERROR_COUNT ;
status = U_ZERO_ERROR ;
array = ures_getByKey ( theBundle , tag , array , & status ) ;
CONFIRM_ErrorCode ( status , expected_resource_status ) ;
if ( U_SUCCESS ( status ) ) {
/*confirm the resource type is an array*/
CONFIRM_INT_EQ ( ures_getType ( array ) , RES_ARRAY ) ;
/*confirm the size*/
count = ures_getSize ( array ) ;
2000-05-15 18:39:17 +00:00
CONFIRM_INT_GE ( count , 1 ) ;
for ( j = 0 ; j < count ; + + j ) {
2000-08-28 21:43:03 +00:00
UChar element [ 3 ] ;
2000-05-15 18:39:17 +00:00
u_strcpy ( expected_string , base ) ;
u_uastrcpy ( element , itoa1 ( j , buf ) ) ;
2000-08-28 21:43:03 +00:00
u_strcat ( expected_string , element ) ;
arrayItem1 = ures_getNextResource ( array , arrayItem1 , & status ) ;
if ( U_SUCCESS ( status ) ) {
CONFIRM_EQ ( ures_getString ( arrayItem1 , & len , & status ) , expected_string ) ;
}
2000-05-15 18:39:17 +00:00
}
2000-08-28 21:43:03 +00:00
}
else {
2000-05-15 18:39:17 +00:00
CONFIRM_INT_EQ ( count , kERROR_COUNT ) ;
2000-07-06 23:01:50 +00:00
CONFIRM_ErrorCode ( status , U_MISSING_RESOURCE_ERROR ) ;
2000-08-28 21:43:03 +00:00
/*CONFIRM_INT_EQ((int32_t)(unsigned long)array,(int32_t)0);*/
2000-05-15 18:39:17 +00:00
count = 0 ;
2000-08-28 21:43:03 +00:00
}
/*--------------arrayItem------------------------------------------------- */
strcpy ( tag , " array_ " ) ;
strcat ( tag , frag ) ;
strcpy ( action , param [ i ] . name ) ;
strcat ( action , " .ures_getStringByIndex( " ) ;
strcat ( action , tag ) ;
strcat ( action , " ) " ) ;
for ( j = 0 ; j < 10 ; + + j ) {
index = count ? ( randi ( count * 3 ) - count ) : ( randi ( 200 ) - 100 ) ;
status = U_ZERO_ERROR ;
string = kERROR ;
array = ures_getByKey ( theBundle , tag , array , & status ) ;
if ( ! U_FAILURE ( status ) ) {
UChar * t = NULL ;
t = ( UChar * ) ures_getStringByIndex ( array , index , & len , & status ) ;
if ( ! U_FAILURE ( status ) ) {
UChar element [ 3 ] ;
string = t ;
u_strcpy ( expected_string , base ) ;
u_uastrcpy ( element , itoa1 ( index , buf ) ) ;
u_strcat ( expected_string , element ) ;
} else {
u_strcpy ( expected_string , kERROR ) ;
}
}
expected_status = ( index > = 0 & & index < count ) ? expected_resource_status : U_MISSING_RESOURCE_ERROR ;
CONFIRM_ErrorCode ( status , expected_status ) ;
CONFIRM_EQ ( string , expected_string ) ;
}
/*--------------2dArray------------------------------------------------- */
strcpy ( tag , " array_2d_ " ) ;
2000-05-15 18:39:17 +00:00
strcat ( tag , frag ) ;
strcpy ( action , param [ i ] . name ) ;
strcat ( action , " .ures_getByKey( " ) ;
strcat ( action , tag ) ;
strcat ( action , " ) " ) ;
row_count = kERROR_COUNT , column_count = kERROR_COUNT ;
status = U_ZERO_ERROR ;
2000-08-28 21:43:03 +00:00
array2d = ures_getByKey ( theBundle , tag , array2d , & status ) ;
2000-05-15 18:39:17 +00:00
CONFIRM_ErrorCode ( status , expected_resource_status ) ;
if ( U_SUCCESS ( status ) )
{
2000-08-28 21:43:03 +00:00
/*confirm the resource type is an 2darray*/
2000-05-15 18:39:17 +00:00
CONFIRM_INT_EQ ( ures_getType ( array2d ) , RES_ARRAY ) ;
2000-08-28 21:43:03 +00:00
row_count = ures_getSize ( array2d ) ;
CONFIRM_INT_GE ( row_count , 1 ) ;
for ( row = 0 ; row < row_count ; + + row ) {
UResourceBundle * tableRow = NULL ;
tableRow = ures_getByIndex ( array2d , row , tableRow , & status ) ;
CONFIRM_ErrorCode ( status , expected_resource_status ) ;
2000-05-15 18:39:17 +00:00
if ( U_SUCCESS ( status ) ) {
2000-08-28 21:43:03 +00:00
/*confirm the resourcetype of each table row is an array*/
CONFIRM_INT_EQ ( ures_getType ( tableRow ) , RES_ARRAY ) ;
column_count = ures_getSize ( tableRow ) ;
2000-05-15 18:39:17 +00:00
CONFIRM_INT_GE ( column_count , 1 ) ;
2000-08-28 21:43:03 +00:00
2000-05-15 18:39:17 +00:00
for ( col = 0 ; j < column_count ; + + j ) {
2000-08-28 21:43:03 +00:00
UChar element [ 3 ] ;
u_strcpy ( expected_string , base ) ;
u_uastrcpy ( element , itoa1 ( row , buf ) ) ;
u_strcat ( expected_string , element ) ;
u_uastrcpy ( element , itoa1 ( col , buf ) ) ;
u_strcat ( expected_string , element ) ;
arrayItem1 = ures_getNextResource ( tableRow , arrayItem1 , & status ) ;
if ( U_SUCCESS ( status ) ) {
const UChar * stringValue = ures_getString ( arrayItem1 , & len , & status ) ;
CONFIRM_EQ ( stringValue , expected_string ) ;
}
}
}
2000-07-06 23:01:50 +00:00
ures_close ( tableRow ) ;
2000-08-28 21:43:03 +00:00
}
} else {
CONFIRM_INT_EQ ( row_count , kERROR_COUNT ) ;
2000-05-15 18:39:17 +00:00
CONFIRM_INT_EQ ( column_count , kERROR_COUNT ) ;
row_count = column_count = 0 ;
2000-08-28 21:43:03 +00:00
}
/*------2dArrayItem-------------------------------------------------------------- */
/* 2dArrayItem*/
for ( j = 0 ; j < 10 ; + + j )
{
row = row_count ? ( randi ( row_count * 3 ) - row_count ) : ( randi ( 200 ) - 100 ) ;
col = column_count ? ( randi ( column_count * 3 ) - column_count ) : ( randi ( 200 ) - 100 ) ;
status = U_ZERO_ERROR ;
string = kERROR ;
len = 0 ;
array2d = ures_getByKey ( theBundle , tag , array2d , & status ) ;
if ( U_SUCCESS ( status ) ) {
2000-05-15 18:39:17 +00:00
UResourceBundle * tableRow = NULL ;
2000-08-28 21:43:03 +00:00
tableRow = ures_getByIndex ( array2d , row , tableRow , & status ) ;
2000-05-15 18:39:17 +00:00
if ( U_SUCCESS ( status ) ) {
UChar * t = NULL ;
2000-08-28 21:43:03 +00:00
t = ( UChar * ) ures_getStringByIndex ( tableRow , col , & len , & status ) ;
if ( U_SUCCESS ( status ) ) {
string = t ;
}
}
2000-07-06 23:01:50 +00:00
ures_close ( tableRow ) ;
2000-08-28 21:43:03 +00:00
}
expected_status = ( row > = 0 & & row < row_count & & col > = 0 & & col < column_count ) ?
expected_resource_status : U_MISSING_RESOURCE_ERROR ;
CONFIRM_ErrorCode ( status , expected_status ) ;
if ( U_SUCCESS ( status ) ) {
UChar element [ 3 ] ;
u_strcpy ( expected_string , base ) ;
u_uastrcpy ( element , itoa1 ( row , buf ) ) ;
u_strcat ( expected_string , element ) ;
u_uastrcpy ( element , itoa1 ( col , buf ) ) ;
u_strcat ( expected_string , element ) ;
} else {
2000-05-15 18:39:17 +00:00
u_strcpy ( expected_string , kERROR ) ;
2000-08-28 21:43:03 +00:00
}
CONFIRM_EQ ( string , expected_string ) ;
2000-05-15 18:39:17 +00:00
}
2000-07-06 23:01:50 +00:00
2000-08-28 21:43:03 +00:00
/*--------------taggedArray----------------------------------------------- */
strcpy ( tag , " tagged_array_ " ) ;
strcat ( tag , frag ) ;
strcpy ( action , param [ i ] . name ) ;
strcat ( action , " .ures_getByKey( " ) ;
strcat ( action , tag ) ;
strcat ( action , " ) " ) ;
status = U_ZERO_ERROR ;
tag_count = 0 ;
tags = ures_getByKey ( theBundle , tag , tags , & status ) ;
CONFIRM_ErrorCode ( status , expected_resource_status ) ;
if ( U_SUCCESS ( status ) ) {
2000-05-15 18:39:17 +00:00
UResType bundleType = ures_getType ( tags ) ;
2000-08-28 21:43:03 +00:00
CONFIRM_INT_EQ ( bundleType , RES_TABLE ) ;
tag_count = ures_getSize ( tags ) ;
2000-05-15 18:39:17 +00:00
CONFIRM_INT_GE ( ( int32_t ) tag_count , ( int32_t ) 0 ) ;
2000-08-28 21:43:03 +00:00
for ( index = 0 ; index < tag_count ; index + + ) {
UResourceBundle * tagelement = NULL ;
const char * key = NULL ;
UChar * value = NULL ;
tagelement = ures_getByIndex ( tags , index , tagelement , & status ) ;
key = ures_getKey ( tagelement ) ;
value = ( UChar * ) ures_getNextString ( tagelement , & len , & key , & status ) ;
2001-05-25 18:25:49 +00:00
log_verbose ( " tag = %s, value = %s \n " , key , u_austrcpy ( verboseOutput , value ) ) ;
2000-08-28 21:43:03 +00:00
if ( strncmp ( key , " tag " , 3 ) = = 0 & & u_strncmp ( value , base , u_strlen ( base ) ) = = 0 ) {
record_pass ( ) ;
} else {
record_fail ( ) ;
}
ures_close ( tagelement ) ;
}
} else {
tag_count = 0 ;
}
/*---------taggedArrayItem----------------------------------------------*/
count = 0 ;
2000-05-15 18:39:17 +00:00
for ( index = - 20 ; index < 20 ; + + index )
{
2000-08-28 21:43:03 +00:00
status = U_ZERO_ERROR ;
2000-05-15 18:39:17 +00:00
string = kERROR ;
2000-08-28 21:43:03 +00:00
strcpy ( item_tag , " tag " ) ;
2000-05-15 18:39:17 +00:00
strcat ( item_tag , itoa1 ( index , buf ) ) ;
2000-08-28 21:43:03 +00:00
tags = ures_getByKey ( theBundle , tag , tags , & status ) ;
if ( U_SUCCESS ( status ) ) {
UResourceBundle * tagelement = NULL ;
UChar * t = NULL ;
tagelement = ures_getByKey ( tags , item_tag , tagelement , & status ) ;
if ( ! U_FAILURE ( status ) ) {
UResType elementType = ures_getType ( tagelement ) ;
CONFIRM_INT_EQ ( elementType , RES_STRING ) ;
if ( strcmp ( ures_getKey ( tagelement ) , item_tag ) = = 0 ) {
record_pass ( ) ;
} else {
record_fail ( ) ;
}
t = ( UChar * ) ures_getString ( tagelement , & len , & status ) ;
if ( ! U_FAILURE ( status ) ) {
string = t ;
}
}
if ( index < 0 ) {
CONFIRM_ErrorCode ( status , U_MISSING_RESOURCE_ERROR ) ;
}
2000-05-15 18:39:17 +00:00
else {
2000-08-28 21:43:03 +00:00
if ( status ! = U_MISSING_RESOURCE_ERROR ) {
UChar element [ 3 ] ;
u_strcpy ( expected_string , base ) ;
u_uastrcpy ( element , itoa1 ( index , buf ) ) ;
u_strcat ( expected_string , element ) ;
CONFIRM_EQ ( string , expected_string ) ;
count + + ;
}
}
2000-07-06 23:01:50 +00:00
ures_close ( tagelement ) ;
2000-08-28 21:43:03 +00:00
}
}
CONFIRM_INT_EQ ( count , tag_count ) ;
free ( expected_string ) ;
ures_close ( theBundle ) ;
2000-05-15 18:39:17 +00:00
}
2000-08-28 21:43:03 +00:00
ures_close ( array ) ;
ures_close ( array2d ) ;
ures_close ( tags ) ;
ures_close ( arrayItem1 ) ;
free ( base ) ;
2001-03-22 18:32:54 +00:00
return ( UBool ) ( failNum = = fail ) ;
2000-05-15 18:39:17 +00:00
}
2000-11-21 04:05:39 +00:00
static void record_pass ( )
2000-05-15 18:39:17 +00:00
{
2000-08-28 21:43:03 +00:00
+ + pass ;
2000-05-15 18:39:17 +00:00
}
2000-11-21 04:05:39 +00:00
static void record_fail ( )
2000-05-15 18:39:17 +00:00
{
2000-08-28 21:43:03 +00:00
+ + fail ;
2000-05-15 18:39:17 +00:00
}
/**
* Test to make sure that the U_USING_FALLBACK_ERROR and U_USING_DEFAULT_ERROR
* are set correctly
*/
2000-11-21 04:05:39 +00:00
static void TestFallback ( )
2000-05-15 18:39:17 +00:00
{
2000-08-28 21:43:03 +00:00
UErrorCode status = U_ZERO_ERROR ;
UResourceBundle * fr_FR = NULL ;
const UChar * junk ; /* ignored */
2001-03-22 00:42:37 +00:00
int32_t resultLen ;
2000-08-28 21:43:03 +00:00
log_verbose ( " Opening fr_FR.. " ) ;
fr_FR = ures_open ( NULL , " fr_FR " , & status ) ;
if ( U_FAILURE ( status ) )
2000-05-15 18:39:17 +00:00
{
2000-08-28 21:43:03 +00:00
log_err ( " Couldn't open fr_FR - %d \n " , status ) ;
return ;
2000-05-15 18:39:17 +00:00
}
2000-08-28 21:43:03 +00:00
status = U_ZERO_ERROR ;
2000-05-15 18:39:17 +00:00
2000-08-28 21:43:03 +00:00
/* clear it out.. just do some calls to get the gears turning */
2001-03-22 00:42:37 +00:00
junk = ures_getStringByKey ( fr_FR , " LocaleID " , & resultLen , & status ) ;
2000-08-28 21:43:03 +00:00
status = U_ZERO_ERROR ;
2001-03-22 00:42:37 +00:00
junk = ures_getStringByKey ( fr_FR , " LocaleString " , & resultLen , & status ) ;
2000-08-28 21:43:03 +00:00
status = U_ZERO_ERROR ;
2001-03-22 00:42:37 +00:00
junk = ures_getStringByKey ( fr_FR , " LocaleID " , & resultLen , & status ) ;
2000-08-28 21:43:03 +00:00
status = U_ZERO_ERROR ;
2000-05-15 18:39:17 +00:00
2000-08-28 21:43:03 +00:00
/* OK first one. This should be a Default value. */
2002-01-16 04:33:47 +00:00
junk = ures_getStringByKey ( fr_FR , " %%PREEURO " , & resultLen , & status ) ;
2000-08-28 21:43:03 +00:00
if ( status ! = U_USING_DEFAULT_ERROR )
2000-05-15 18:39:17 +00:00
{
2001-03-20 23:05:42 +00:00
log_err ( " Expected U_USING_DEFAULT_ERROR when trying to get %%EURO from fr_FR, got %s \n " ,
u_errorName ( status ) ) ;
2000-05-15 18:39:17 +00:00
}
2000-08-28 21:43:03 +00:00
status = U_ZERO_ERROR ;
/* and this is a Fallback, to fr */
2001-03-22 00:42:37 +00:00
junk = ures_getStringByKey ( fr_FR , " ShortLanguage " , & resultLen , & status ) ;
2000-08-28 21:43:03 +00:00
if ( status ! = U_USING_FALLBACK_ERROR )
2000-05-15 18:39:17 +00:00
{
2000-08-28 21:43:03 +00:00
log_err ( " Expected U_USING_FALLBACK_ERROR when trying to get ShortLanguage from fr_FR, got %d \n " ,
status ) ;
2000-05-15 18:39:17 +00:00
}
2001-03-21 01:50:24 +00:00
2000-08-28 21:43:03 +00:00
status = U_ZERO_ERROR ;
ures_close ( fr_FR ) ;
2001-03-21 02:20:51 +00:00
/* Temporary hack err actually should be U_USING_FALLBACK_ERROR */
2001-03-21 01:50:24 +00:00
/* Test Jitterbug 552 fallback mechanism of aliased data */
{
2001-05-24 20:59:12 +00:00
char tempChars [ 256 ] ;
2001-03-21 01:50:24 +00:00
UErrorCode err = U_ZERO_ERROR ;
2001-03-21 02:20:51 +00:00
UResourceBundle * myResB = ures_open ( NULL , " no_NO_NY " , & err ) ;
2001-03-22 00:42:37 +00:00
const UChar * myLocID = ures_getStringByKey ( myResB , " LocaleID " , & resultLen , & err ) ;
2001-05-24 20:59:12 +00:00
UResourceBundle * tResB ;
if ( err ! = U_ZERO_ERROR ) {
log_err ( " Expected U_ZERO_ERROR when trying to test no_NO_NY aliased to nn_NO for LocaleID err=%s \n " , u_errorName ( err ) ) ;
}
u_UCharsToChars ( myLocID , tempChars , u_strlen ( myLocID ) + 1 ) ;
if ( uprv_strcmp ( tempChars , " 0814 " ) ) {
log_err ( " Expected LocaleID=814, but got %s \n " , tempChars ) ;
}
tResB = ures_getByKey ( myResB , " DayNames " , NULL , & err ) ;
if ( err ! = U_USING_FALLBACK_ERROR ) {
log_err ( " Expected U_USING_FALLBACK_ERROR when trying to test no_NO_NY aliased with nn_NO_NY for DayNames err=%s \n " , u_errorName ( err ) ) ;
2001-03-21 01:50:24 +00:00
}
2001-03-21 02:20:51 +00:00
ures_close ( myResB ) ;
ures_close ( tResB ) ;
2001-03-21 01:50:24 +00:00
}
2000-05-15 18:39:17 +00:00
}
2000-08-28 21:43:03 +00:00
2000-11-21 04:05:39 +00:00
static void printUChars ( UChar * uchars ) {
2000-08-28 21:43:03 +00:00
int16_t i = 0 ;
for ( i = 0 ; i < u_strlen ( uchars ) ; i + + ) {
2001-05-24 20:59:12 +00:00
log_err ( " %04X " , * ( uchars + i ) ) ;
2000-08-28 21:43:03 +00:00
}
2000-05-15 18:39:17 +00:00
}