1ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/******************************************************************** 2ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * COPYRIGHT: 31b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert * Copyright (c) 1997-2015, International Business Machines Corporation and 4ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * others. All Rights Reserved. 5ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ********************************************************************/ 6ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/******************************************************************************* 7ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* 8fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius* File creststn.c 9ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* 10ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* Modification History: 11ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* Name Date Description 12ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* Madhu Katragadda 05/09/2000 Ported Tests for New ResourceBundle API 13ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* Madhu Katragadda 05/24/2000 Added new tests to test RES_BINARY for collationElements 14ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru******************************************************************************** 15ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*/ 16ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 17ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 18ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include <time.h> 19ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/utypes.h" 20ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "cintltst.h" 21ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/putil.h" 22ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/ustring.h" 23ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/ucnv.h" 24ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "string.h" 25ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "cstring.h" 26ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/uchar.h" 27ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "ucol_imp.h" /* for U_ICUDATA_COLL */ 28ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "ubrkimpl.h" /* for U_ICUDATA_BRKITR */ 29ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define RESTEST_HEAP_CHECK 0 30ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 31ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/uloc.h" 3285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho#include "unicode/ulocdata.h" 33ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "uresimp.h" 34ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "creststn.h" 35ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/ctest.h" 36ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "ucbuf.h" 3750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho#include "ureslocs.h" 3850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 39ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic int32_t pass; 40ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic int32_t fail; 41ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 42ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/*****************************************************************************/ 43ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 44ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Return a random unsigned long l where 0N <= l <= ULONG_MAX. 45ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 46ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 47ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic uint32_t 48ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querurandul() 49ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 50ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint32_t l=0; 51ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t i; 52ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru static UBool initialized = FALSE; 53ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (!initialized) 54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 55ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru srand((unsigned)time(NULL)); 56ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru initialized = TRUE; 57ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 58ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Assume rand has at least 12 bits of precision */ 59ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 60ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (i=0; i<sizeof(l); ++i) 61ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ((char*)&l)[i] = (char)((rand() & 0x0FF0) >> 4); 62ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return l; 63ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 64ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 65ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 66ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Return a random double x where 0.0 <= x < 1.0. 67ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 68ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic double 69ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querurandd() 70ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 71ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return ((double)randul()) / UINT32_MAX; 72ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 73ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 74ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 75ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Return a random integer i where 0 <= i < n. 76ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 77ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic int32_t randi(int32_t n) 78ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 79ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return (int32_t)(randd() * n); 80ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 81ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/***************************************************************************************/ 82ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 83ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Convert an integer, positive or negative, to a character string radix 10. 84ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 85ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic char* 86ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruitoa1(int32_t i, char* buf) 87ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 88ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char *p = 0; 89ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char* result = buf; 90ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Handle negative */ 91ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(i < 0) { 92ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *buf++ = '-'; 93ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru i = -i; 94ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 95ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 96ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Output digits in reverse order */ 97ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru p = buf; 98ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru do { 99ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *p++ = (char)('0' + (i % 10)); 100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru i /= 10; 101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru while(i); 103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *p-- = 0; 104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Reverse the string */ 106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru while(buf < p) { 107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char c = *buf; 108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *buf++ = *p; 109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *p-- = c; 110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return result; 113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic const int32_t kERROR_COUNT = -1234567; 115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic const UChar kERROR[] = { 0x0045 /*E*/, 0x0052 /*'R'*/, 0x0052 /*'R'*/, 116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 0x004F /*'O'*/, 0x0052/*'R'*/, 0x0000 /*'\0'*/}; 117ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 118ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/*****************************************************************************/ 119ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruenum E_Where 121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 122ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru e_Root, 123ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru e_te, 124ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru e_te_IN, 125ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru e_Where_count 126ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}; 127ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querutypedef enum E_Where E_Where; 128ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/*****************************************************************************/ 129ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 130ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#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)); } 131ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#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); } 132ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#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); } 133ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#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); } 134ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/*#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)); } */ 135ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void 136ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruCONFIRM_ErrorCode(UErrorCode actual,UErrorCode expected) 137ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 138ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if ((expected)==(actual)) 139ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 140ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru record_pass(); 141ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 142ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru record_fail(); 143ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*log_err("%s returned %s instead of %s\n", action, myErrorName(actual), myErrorName(expected)); */ 144ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("returned %s instead of %s\n", myErrorName(actual), myErrorName(expected)); 145ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 146ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 147ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 148ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 149ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* Array of our test objects */ 150ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 151ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic struct 152ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 153ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* name; 154ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode expected_constructor_status; 155ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru E_Where where; 156ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UBool like[e_Where_count]; 157ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UBool inherits[e_Where_count]; 158ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 159ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruparam[] = 160ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 161ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* "te" means test */ 162ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* "IN" means inherits */ 163ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* "NE" or "ne" means "does not exist" */ 164ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 165ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { "root", U_ZERO_ERROR, e_Root, { TRUE, FALSE, FALSE }, { TRUE, FALSE, FALSE } }, 166ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { "te", U_ZERO_ERROR, e_te, { FALSE, TRUE, FALSE }, { TRUE, TRUE, FALSE } }, 167ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { "te_IN", U_ZERO_ERROR, e_te_IN, { FALSE, FALSE, TRUE }, { TRUE, TRUE, TRUE } }, 168ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { "te_NE", U_USING_FALLBACK_WARNING, e_te, { FALSE, TRUE, FALSE }, { TRUE, TRUE, FALSE } }, 169ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { "te_IN_NE", U_USING_FALLBACK_WARNING, e_te_IN, { FALSE, FALSE, TRUE }, { TRUE, TRUE, TRUE } }, 170ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { "ne", U_USING_DEFAULT_WARNING, e_Root, { TRUE, FALSE, FALSE }, { TRUE, FALSE, FALSE } } 171ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}; 172ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 173ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic int32_t bundles_count = sizeof(param) / sizeof(param[0]); 174ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 175ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 17685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 177ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/*static void printUChars(UChar*);*/ 178ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestDecodedBundle(void); 179ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestGetKeywordValues(void); 180ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestGetFunctionalEquivalent(void); 181ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestCLDRStyleAliases(void); 182ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestFallbackCodes(void); 183ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestGetUTF8String(void); 18450294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehostatic void TestCLDRVersion(void); 185ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 186ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/***************************************************************************************/ 187ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 188ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* Array of our test objects */ 189ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 190ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid addNEWResourceBundleTest(TestNode** root) 191ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 192ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestErrorCodes, "tsutil/creststn/TestErrorCodes"); 19350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho#if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION 194ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestEmptyBundle, "tsutil/creststn/TestEmptyBundle"); 195ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestConstruction1, "tsutil/creststn/TestConstruction1"); 196ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestResourceBundles, "tsutil/creststn/TestResourceBundles"); 197ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestNewTypes, "tsutil/creststn/TestNewTypes"); 198ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestEmptyTypes, "tsutil/creststn/TestEmptyTypes"); 199ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestBinaryCollationData, "tsutil/creststn/TestBinaryCollationData"); 200ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestAPI, "tsutil/creststn/TestAPI"); 201ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestErrorConditions, "tsutil/creststn/TestErrorConditions"); 202ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestDecodedBundle, "tsutil/creststn/TestDecodedBundle"); 203ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestResourceLevelAliasing, "tsutil/creststn/TestResourceLevelAliasing"); 204ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestDirectAccess, "tsutil/creststn/TestDirectAccess"); 2058393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius addTest(root, &TestTicket9804, "tsutil/creststn/TestTicket9804"); 20650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho addTest(root, &TestXPath, "tsutil/creststn/TestXPath"); 20750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho addTest(root, &TestCLDRStyleAliases, "tsutil/creststn/TestCLDRStyleAliases"); 20850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho addTest(root, &TestFallbackCodes, "tsutil/creststn/TestFallbackCodes"); 20950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho addTest(root, &TestGetUTF8String, "tsutil/creststn/TestGetUTF8String"); 21050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho addTest(root, &TestCLDRVersion, "tsutil/creststn/TestCLDRVersion"); 21159d709d503bab6e2b61931737e662dd293b40578ccornelius addTest(root, &TestPreventFallback, "tsutil/creststn/TestPreventFallback"); 21250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho#endif 21350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho addTest(root, &TestFallback, "tsutil/creststn/TestFallback"); 21450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho addTest(root, &TestGetVersion, "tsutil/creststn/TestGetVersion"); 21550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho addTest(root, &TestGetVersionColl, "tsutil/creststn/TestGetVersionColl"); 21650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho addTest(root, &TestAliasConflict, "tsutil/creststn/TestAliasConflict"); 217ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestGetKeywordValues, "tsutil/creststn/TestGetKeywordValues"); 218ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestGetFunctionalEquivalent,"tsutil/creststn/TestGetFunctionalEquivalent"); 219ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestJB3763, "tsutil/creststn/TestJB3763"); 220ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestStackReuse, "tsutil/creststn/TestStackReuse"); 221ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 222ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 223ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 224ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/***************************************************************************************/ 225ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic const char* norwayNames[] = { 226ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "no_NO_NY", 227ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "no_NO", 228ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "no", 229ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "nn_NO", 230ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "nn", 231ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "nb_NO", 232ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "nb" 233ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}; 234ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 235ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic const char* norwayLocales[] = { 236ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "nn_NO", 237ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "nb_NO", 238ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "nb", 239ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "nn_NO", 240ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "nn", 241ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "nb_NO", 242ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "nb" 243ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}; 244ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 245ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void checkStatus(int32_t line, UErrorCode expected, UErrorCode status) { 246ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 247ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_data_err("Resource not present, cannot test (%s:%d)\n", __FILE__, line); 248ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 249ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(status != expected) { 25085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(status, "%s:%d: Expected error code %s, got error code %s\n", __FILE__, line, u_errorName(expected), u_errorName(status)); 251ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 252ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 253ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 254ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestErrorCodes(void) { 255ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_USING_DEFAULT_WARNING; 256ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 257ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResourceBundle *r = NULL, *r2 = NULL; 258ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 259ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* First check with ICUDATA */ 260ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* first bundle should return fallback warning */ 261ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru r = ures_open(NULL, "ti_ER_ASSAB", &status); 262ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru checkStatus(__LINE__, U_USING_FALLBACK_WARNING, status); 263ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(r); 264ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 26550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* this bundle should return zero error, so it shouldn't change the status */ 266ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_USING_DEFAULT_WARNING; 267ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru r = ures_open(NULL, "ti_ER", &status); 268ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru checkStatus(__LINE__, U_USING_DEFAULT_WARNING, status); 269ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 270ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* we look up the resource which is aliased, but it lives in fallback */ 27150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 272ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status) && r != NULL) { 27350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho status = U_USING_DEFAULT_WARNING; 2741b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert r2 = ures_getByKey(r, "ExemplarCharacters", NULL, &status); /* ExemplarCharacters lives in ti */ 275ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru checkStatus(__LINE__, U_USING_FALLBACK_WARNING, status); 27650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 277ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(r); 278ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 27950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* this bundle should return zero error, so it shouldn't change the status */ 280ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_USING_DEFAULT_WARNING; 28150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho r = ures_open(U_ICUDATA_REGION, "ti", &status); 282ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru checkStatus(__LINE__, U_USING_DEFAULT_WARNING, status); 283ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(r); 284ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 285ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_USING_FALLBACK_WARNING; 286ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru r = ures_open(NULL, "nolocale", &status); 287ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru checkStatus(__LINE__, U_USING_DEFAULT_WARNING, status); 288ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(r); 289ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(r2); 290ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 291fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius#if !UCONFIG_NO_COLLATION 292ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /** Now, with the collation bundle **/ 29350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 294ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* first bundle should return fallback warning */ 295ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru r = ures_open(U_ICUDATA_COLL, "sr_YU_VOJVODINA", &status); 296ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru checkStatus(__LINE__, U_USING_FALLBACK_WARNING, status); 297ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(r); 298ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 29950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* this bundle should return zero error, so it shouldn't change the status */ 300ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_USING_FALLBACK_WARNING; 301ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru r = ures_open(U_ICUDATA_COLL, "sr", &status); 302ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru checkStatus(__LINE__, U_USING_FALLBACK_WARNING, status); 303ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 304ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* we look up the resource which is aliased */ 305ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status) && r != NULL) { 30650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho status = U_USING_DEFAULT_WARNING; 307ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru r2 = ures_getByKey(r, "collations", NULL, &status); 308ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru checkStatus(__LINE__, U_USING_DEFAULT_WARNING, status); 30950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 310ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(r); 311ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 31250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* this bundle should return zero error, so it shouldn't change the status */ 313ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_USING_DEFAULT_WARNING; 314ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru r = ures_open(U_ICUDATA_COLL, "sr", &status); 315ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru checkStatus(__LINE__, U_USING_DEFAULT_WARNING, status); 316ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 317ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* we look up the resource which is aliased and at our level */ 318ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status) && r != NULL) { 31950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho status = U_USING_DEFAULT_WARNING; 320ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru r2 = ures_getByKey(r, "collations", r2, &status); 321ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru checkStatus(__LINE__, U_USING_DEFAULT_WARNING, status); 322ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 323ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(r); 324ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 325ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_USING_FALLBACK_WARNING; 326ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru r = ures_open(U_ICUDATA_COLL, "nolocale", &status); 327ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru checkStatus(__LINE__, U_USING_DEFAULT_WARNING, status); 328ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(r); 329ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(r2); 330fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius#endif /* !UCONFIG_NO_COLLATION */ 331ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 332ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 333ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestAliasConflict(void) { 334ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 335ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResourceBundle *he = NULL; 336ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResourceBundle *iw = NULL; 337ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResourceBundle *norway = NULL; 338ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const UChar *result = NULL; 339ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t resultLen; 340ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint32_t size = 0; 341ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint32_t i = 0; 342ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char *realName = NULL; 343ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 344ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru he = ures_open(NULL, "he", &status); 345ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru iw = ures_open(NULL, "iw", &status); 346ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 34785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(status, "Failed to get resource with %s\n", myErrorName(status)); 348ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 349ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(iw); 350ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru result = ures_getStringByKey(he, "ExemplarCharacters", &resultLen, &status); 351ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status) || result == NULL) { 35285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(status, "Failed to get resource ExemplarCharacters with %s\n", myErrorName(status)); 353ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 354ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(he); 355ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 356ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru size = sizeof(norwayNames)/sizeof(norwayNames[0]); 357ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(i = 0; i < size; i++) { 358ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 359ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru norway = ures_open(NULL, norwayNames[i], &status); 360ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 36185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(status, "Failed to get resource with %s for %s\n", myErrorName(status), norwayNames[i]); 362ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru continue; 363ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 364ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru realName = ures_getLocale(norway, &status); 365ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("ures_getLocale(\"%s\")=%s\n", norwayNames[i], realName); 366ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(realName == NULL || strcmp(norwayLocales[i], realName) != 0) { 367ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_data_err("Wrong locale name for %s, expected %s, got %s\n", norwayNames[i], norwayLocales[i], realName); 368ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 369ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(norway); 370ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 371ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 372ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 373ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestDecodedBundle(){ 374ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 375ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode error = U_ZERO_ERROR; 376ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 377ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResourceBundle* resB; 378ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 379ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const UChar* srcFromRes; 380ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t len; 381ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru static const UChar uSrc[] = { 382ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 0x0009,0x092F,0x0941,0x0928,0x0947,0x0938,0x094D,0x0915,0x094B,0x0020,0x002E,0x0915,0x0947,0x0020,0x002E,0x090F, 383ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 0x0915,0x0020,0x002E,0x0905,0x0927,0x094D,0x092F,0x092F,0x0928,0x0020,0x002E,0x0915,0x0947,0x0020,0x0905,0x0928, 384ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 0x0941,0x0938,0x093E,0x0930,0x0020,0x0031,0x0039,0x0039,0x0030,0x0020,0x0924,0x0915,0x0020,0x0915,0x0902,0x092A, 385ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 0x094D,0x092F,0x0942,0x091F,0x0930,0x002D,0x092A,0x094D,0x0930,0x092C,0x0902,0x0927,0x093F,0x0924,0x0020,0x0938, 386ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 0x0942,0x091A,0x0928,0x093E,0x092A,0x094D,0x0930,0x0923,0x093E,0x0932,0x0940,0x0020,0x002E,0x0915,0x0947,0x0020, 387ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 0x002E,0x092F,0x094B,0x0917,0x0926,0x093E,0x0928,0x0020,0x002E,0x0915,0x0947,0x0020,0x002E,0x092B,0x0932,0x0938, 388ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 0x094D,0x0935,0x0930,0x0942,0x092A,0x0020,0x002E,0x0935,0x093F,0x0936,0x094D,0x0935,0x0020,0x002E,0x092E,0x0947, 389ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 0x0902,0x0020,0x002E,0x0938,0x093E,0x0932,0x093E,0x0928,0x093E,0x0020,0x002E,0x0032,0x0032,0x0030,0x0030,0x0020, 390ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 0x0905,0x0930,0x092C,0x0020,0x0930,0x0941,0x092A,0x092F,0x0947,0x0020,0x092E,0x0942,0x0932,0x094D,0x092F,0x0915, 391ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 0x0940,0x0020,0x002E,0x0034,0x0935,0x0938,0x094D,0x0924,0x0941,0x0913,0x0902,0x0020,0x002E,0x0034,0x0915,0x093E, 392ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 0x0020,0x002E,0x0034,0x0909,0x0924,0x094D,0x092A,0x093E,0x0926,0x0928,0x0020,0x002E,0x0034,0x0939,0x094B,0x0917, 393ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 0x093E,0x002C,0x0020,0x002E,0x0033,0x091C,0x092C,0x0915,0x093F,0x0020,0x002E,0x0033,0x0915,0x0902,0x092A,0x094D, 394ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 0x092F,0x0942,0x091F,0x0930,0x0020,0x002E,0x0033,0x0915,0x093E,0x0020,0x002E,0x0033,0x0915,0x0941,0x0932,0x0020, 395ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 0x002E,0x0033,0x092F,0x094B,0x0917,0x0926,0x093E,0x0928,0x0020,0x002E,0x0033,0x0907,0x0938,0x0938,0x0947,0x0915, 396ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 0x0939,0x093F,0x0020,0x002E,0x002F,0x091C,0x094D,0x092F,0x093E,0x0926,0x093E,0x0020,0x002E,0x002F,0x0939,0x094B, 397ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 0x0917,0x093E,0x0964,0x0020,0x002E,0x002F,0x0905,0x0928,0x0941,0x0938,0x0902,0x0927,0x093E,0x0928,0x0020,0x002E, 398ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 0x002F,0x0915,0x0940,0x0020,0x002E,0x002F,0x091A,0x0930,0x092E,0x0020,0x0938,0x0940,0x092E,0x093E,0x0913,0x0902, 399ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 0x0020,0x092A,0x0930,0x0020,0x092A,0x0939,0x0941,0x0902,0x091A,0x0928,0x0947,0x0020,0x0915,0x0947,0x0020,0x0932, 400ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 0x093F,0x090F,0x0020,0x0915,0x0902,0x092A,0x094D,0x092F,0x0942,0x091F,0x0930,0x090F,0x0915,0x0020,0x002E,0x002F, 401ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 0x0906,0x092E,0x0020,0x002E,0x002F,0x091C,0x0930,0x0942,0x0930,0x0924,0x0020,0x002E,0x002F,0x091C,0x0948,0x0938, 402ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 0x093E,0x0020,0x092C,0x0928,0x0020,0x0917,0x092F,0x093E,0x0020,0x0939,0x0948,0x0964,0x0020,0x092D,0x093E,0x0930, 403ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 0x0924,0x0020,0x092E,0x0947,0x0902,0x0020,0x092D,0x0940,0x002C,0x0020,0x0916,0x093E,0x0938,0x0915,0x0930,0x0020, 404ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 0x092E,0x094C,0x091C,0x0942,0x0926,0x093E,0x0020,0x0938,0x0930,0x0915,0x093E,0x0930,0x0928,0x0947,0x002C,0x0020, 405ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 0x0915,0x0902,0x092A,0x094D,0x092F,0x0942,0x091F,0x0930,0x0020,0x0915,0x0947,0x0020,0x092A,0x094D,0x0930,0x092F, 406ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 0x094B,0x0917,0x0020,0x092A,0x0930,0x0020,0x091C,0x092C,0x0930,0x0926,0x0938,0x094D,0x0924,0x0020,0x090F,0x095C, 407ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 0x0020,0x0932,0x0917,0x093E,0x092F,0x0940,0x0020,0x0939,0x0948,0x002C,0x0020,0x0915,0x093F,0x0902,0x0924,0x0941, 408ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 0x0020,0x0907,0x0938,0x0915,0x0947,0x0020,0x0938,0x0930,0x092A,0x091F,0x0020,0x0926,0x094C,0x095C,0x0932,0x0917, 409ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 0x093E,0x0928,0x0947,0x0020,0x002E,0x0032,0x0915,0x0947,0x0020,0x002E,0x0032,0x0932,0x093F,0x090F,0x0020,0x002E, 410ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 0x0032,0x0915,0x094D,0x092F,0x093E,0x0020,0x002E,0x0032,0x0938,0x092A,0x093E,0x091F,0x0020,0x002E,0x0032,0x0930, 411ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 0x093E,0x0938,0x094D,0x0924,0x093E,0x0020,0x002E,0x0032,0x0909,0x092A,0x0932,0x092C,0x094D,0x0927,0x0020,0x002E, 412ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 0x0939,0x0948,0x002C,0x0020,0x002E,0x0905,0x0925,0x0935,0x093E,0x0020,0x002E,0x0935,0x093F,0x0936,0x094D,0x0935, 413ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 0x0020,0x002E,0x092E,0x0947,0x0902,0x0020,0x002E,0x0915,0x0902,0x092A,0x094D,0x092F,0x0942,0x091F,0x0930,0x0020, 414ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 0x002E,0x0915,0x0940,0x0938,0x092B,0x0932,0x0924,0x093E,0x0020,0x002E,0x0033,0x0935,0x0020,0x002E,0x0033,0x0935, 415ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 0x093F,0x092B,0x0932,0x0924,0x093E,0x0020,0x002E,0x0033,0x0938,0x0947,0x0020,0x002E,0x0033,0x0938,0x092C,0x0915, 416ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 0x0020,0x002E,0x0033,0x0932,0x0947,0x0020,0x002E,0x0033,0x0915,0x0930,0x0020,0x002E,0x0033,0x0915,0x094D,0x092F, 417ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 0x093E,0x0020,0x002E,0x0033,0x0939,0x092E,0x0020,0x002E,0x0033,0x0907,0x0938,0x0915,0x093E,0x0020,0x002E,0x0033, 418ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 0x092F,0x0941,0x0915,0x094D,0x0924,0x093F,0x092A,0x0942,0x0930,0x094D,0x0923,0x0020,0x002E,0x0032,0x0935,0x093F, 419ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 0x0938,0x094D,0x0924,0x093E,0x0930,0x0020,0x0905,0x092A,0x0947,0x0915,0x094D,0x0937,0x093F,0x0924,0x0020,0x0915, 420ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 0x0930,0x0020,0x0938,0x0915,0x0947,0x0902,0x0917,0x0947,0x0020,0x003F,0x0020, 421ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 0 422ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }; 423ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 424ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* pre-flight */ 425ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t num =0; 426ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char *testdatapath = loadTestData(&error); 4271b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert resB = ures_open(testdatapath, "encoded", &error); 428ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru srcFromRes=tres_getString(resB,-1,"str",&len,&error); 429ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(error)){ 4301b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert log_data_err("Could not find encoded.res from test data bundle. Error: %s\n", u_errorName(error)); 431ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(resB); 432ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 433ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 434ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(u_strncmp(srcFromRes,uSrc,len)!=0){ 435ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Genrb produced res files after decoding failed\n"); 436ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 437ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru while(num<len){ 438ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(uSrc[num]!=srcFromRes[num]){ 439ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose(" Expected: 0x%04X Got: 0x%04X \n", uSrc[num],srcFromRes[num]); 440ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 441ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru num++; 442ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 443ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (len != u_strlen(uSrc)) { 444ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Genrb produced a string larger than expected\n"); 445ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 446ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(resB); 447ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 448ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 449ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestNewTypes() { 450ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResourceBundle* theBundle = NULL; 451ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char action[256]; 452ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* testdatapath; 453ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 454ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResourceBundle* res = NULL; 455ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint8_t *binResult = NULL; 456ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t len = 0; 457ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t i = 0; 458ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t intResult = 0; 459ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint32_t uintResult = 0; 460ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const UChar *empty = NULL; 461ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const UChar *zeroString; 462ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar expected[] = { 'a','b','c','\0','d','e','f' }; 463ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* expect ="tab:\t cr:\r ff:\f newline:\n backslash:\\\\ quote=\\\' doubleQuote=\\\" singlequoutes=''"; 464ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar uExpect[200]; 465ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 466ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru testdatapath=loadTestData(&status); 467ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 468ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) 469ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 47085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_data_err("Could not load testdata.dat %s \n",myErrorName(status)); 471ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 472ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 473ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 474ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru theBundle = ures_open(testdatapath, "testtypes", &status); 475ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 476ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru empty = tres_getString(theBundle, -1, "emptystring", &len, &status); 477ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(empty && (*empty != 0 || len != 0)) { 478ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Empty string returned invalid value\n"); 479ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 480ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 481ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_ErrorCode(status, U_ZERO_ERROR); 482ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 483ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_INT_NE(theBundle, NULL); 484ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 485ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* This test reads the string "abc\u0000def" from the bundle */ 486ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* if everything is working correctly, the size of this string */ 487ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* should be 7. Everything else is a wrong answer, esp. 3 and 6*/ 488ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 489ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcpy(action, "getting and testing of string with embeded zero"); 490ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru res = ures_getByKey(theBundle, "zerotest", res, &status); 491ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_ErrorCode(status, U_ZERO_ERROR); 492ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_INT_EQ(ures_getType(res), URES_STRING); 493ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru zeroString=tres_getString(res, -1, NULL, &len, &status); 494ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)){ 495ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_ErrorCode(status, U_ZERO_ERROR); 496ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_INT_EQ(len, 7); 497ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_INT_NE(len, 3); 498ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 499ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(i=0;i<len;i++){ 500ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(zeroString[i]!= expected[i]){ 501ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Output did not match Expected: \\u%4X Got: \\u%4X", expected[i], zeroString[i]); 502ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 503ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 504ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 505ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcpy(action, "getting and testing of binary type"); 506ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru res = ures_getByKey(theBundle, "binarytest", res, &status); 507ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_ErrorCode(status, U_ZERO_ERROR); 508ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_INT_EQ(ures_getType(res), URES_BINARY); 509ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru binResult=(uint8_t*)ures_getBinary(res, &len, &status); 510ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)){ 511ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_ErrorCode(status, U_ZERO_ERROR); 512ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_INT_EQ(len, 15); 513ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(i = 0; i<15; i++) { 514ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_INT_EQ(binResult[i], i); 515ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 516ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 517ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 518ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcpy(action, "getting and testing of imported binary type"); 519ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru res = ures_getByKey(theBundle, "importtest", res, &status); 520ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_ErrorCode(status, U_ZERO_ERROR); 521ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_INT_EQ(ures_getType(res), URES_BINARY); 522ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru binResult=(uint8_t*)ures_getBinary(res, &len, &status); 523ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)){ 524ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_ErrorCode(status, U_ZERO_ERROR); 525ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_INT_EQ(len, 15); 526ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(i = 0; i<15; i++) { 527ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_INT_EQ(binResult[i], i); 528ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 529ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 530ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 531ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcpy(action, "getting and testing of integer types"); 532ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru res = ures_getByKey(theBundle, "one", res, &status); 533ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_ErrorCode(status, U_ZERO_ERROR); 534ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_INT_EQ(ures_getType(res), URES_INT); 535ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru intResult=ures_getInt(res, &status); 536ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uintResult = ures_getUInt(res, &status); 537ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)){ 538ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_ErrorCode(status, U_ZERO_ERROR); 539ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_INT_EQ(uintResult, (uint32_t)intResult); 540ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_INT_EQ(intResult, 1); 541ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 542ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 543ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcpy(action, "getting minusone"); 544ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru res = ures_getByKey(theBundle, "minusone", res, &status); 545ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_ErrorCode(status, U_ZERO_ERROR); 546ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_INT_EQ(ures_getType(res), URES_INT); 547ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru intResult=ures_getInt(res, &status); 548ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uintResult = ures_getUInt(res, &status); 549ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)){ 550ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_ErrorCode(status, U_ZERO_ERROR); 551ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_INT_EQ(uintResult, 0x0FFFFFFF); /* a 28 bit integer */ 552ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_INT_EQ(intResult, -1); 553ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_INT_NE(uintResult, (uint32_t)intResult); 554ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 555ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 556ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcpy(action, "getting plusone"); 557ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru res = ures_getByKey(theBundle, "plusone", res, &status); 558ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_ErrorCode(status, U_ZERO_ERROR); 559ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_INT_EQ(ures_getType(res), URES_INT); 560ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru intResult=ures_getInt(res, &status); 561ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uintResult = ures_getUInt(res, &status); 562ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)){ 563ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_ErrorCode(status, U_ZERO_ERROR); 564ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_INT_EQ(uintResult, (uint32_t)intResult); 565ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_INT_EQ(intResult, 1); 566ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 567ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 568ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru res = ures_getByKey(theBundle, "onehundredtwentythree", res, &status); 569ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_ErrorCode(status, U_ZERO_ERROR); 570ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_INT_EQ(ures_getType(res), URES_INT); 571ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru intResult=ures_getInt(res, &status); 572ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)){ 573ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_ErrorCode(status, U_ZERO_ERROR); 574ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_INT_EQ(intResult, 123); 575ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 576ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 577ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* this tests if escapes are preserved or not */ 578ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 579ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const UChar* str = tres_getString(theBundle,-1,"testescape",&len,&status); 580ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_ErrorCode(status, U_ZERO_ERROR); 581ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)){ 582ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_charsToUChars(expect,uExpect,(int32_t)strlen(expect)+1); 583ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(u_strcmp(uExpect,str)){ 584ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Did not get the expected string for testescape\n"); 585ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 586ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 587ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 588ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* this tests if unescaping works are expected */ 589ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru len=0; 590ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 591ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char pattern[2048] = ""; 592ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t patternLen; 593ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar* expectedEscaped; 594ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const UChar* got; 595ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t expectedLen; 596ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 597ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* This strcpy fixes compiler warnings about long strings */ 598ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcpy(pattern, "[ \\\\u0020 \\\\u00A0 \\\\u1680 \\\\u2000 \\\\u2001 \\\\u2002 \\\\u2003 \\\\u2004 \\\\u2005 \\\\u2006 \\\\u2007 " 599ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "\\\\u2008 \\\\u2009 \\\\u200A \\u200B \\\\u202F \\u205F \\\\u3000 \\u0000-\\u001F \\u007F \\u0080-\\u009F " 600ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "\\\\u06DD \\\\u070F \\\\u180E \\\\u200C \\\\u200D \\\\u2028 \\\\u2029 \\\\u2060 \\\\u2061 \\\\u2062 \\\\u2063 " 601ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "\\\\u206A-\\\\u206F \\\\uFEFF \\\\uFFF9-\\uFFFC \\U0001D173-\\U0001D17A \\U000F0000-\\U000FFFFD " 602ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "\\U00100000-\\U0010FFFD \\uFDD0-\\uFDEF \\uFFFE-\\uFFFF \\U0001FFFE-\\U0001FFFF \\U0002FFFE-\\U0002FFFF " 603ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ); 604ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcat(pattern, 605ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "\\U0003FFFE-\\U0003FFFF \\U0004FFFE-\\U0004FFFF \\U0005FFFE-\\U0005FFFF \\U0006FFFE-\\U0006FFFF " 606ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "\\U0007FFFE-\\U0007FFFF \\U0008FFFE-\\U0008FFFF \\U0009FFFE-\\U0009FFFF \\U000AFFFE-\\U000AFFFF " 607ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "\\U000BFFFE-\\U000BFFFF \\U000CFFFE-\\U000CFFFF \\U000DFFFE-\\U000DFFFF \\U000EFFFE-\\U000EFFFF " 608ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "\\U000FFFFE-\\U000FFFFF \\U0010FFFE-\\U0010FFFF \\uD800-\\uDFFF \\\\uFFF9 \\\\uFFFA \\\\uFFFB " 609ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "\\uFFFC \\uFFFD \\u2FF0-\\u2FFB \\u0340 \\u0341 \\\\u200E \\\\u200F \\\\u202A \\\\u202B \\\\u202C " 610ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ); 611ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcat(pattern, 612ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "\\\\u202D \\\\u202E \\\\u206A \\\\u206B \\\\u206C \\\\u206D \\\\u206E \\\\u206F \\U000E0001 \\U000E0020-\\U000E007F " 613ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "]" 614ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ); 615ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 616ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru patternLen = (int32_t)uprv_strlen(pattern); 617ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru expectedEscaped = (UChar*)malloc(U_SIZEOF_UCHAR * patternLen); 618ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru got = tres_getString(theBundle,-1,"test_unescaping",&len,&status); 619ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru expectedLen = u_unescape(pattern,expectedEscaped,patternLen); 620ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(got==NULL || u_strncmp(expectedEscaped,got,expectedLen)!=0 || expectedLen != len){ 621ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("genrb failed to unescape string\n"); 622ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 623ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(got != NULL){ 624ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(i=0;i<expectedLen;i++){ 625ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(expectedEscaped[i] != got[i]){ 626ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Expected: 0x%04X Got: 0x%04X \n",expectedEscaped[i], got[i]); 627ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 628ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 629ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 630ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(expectedEscaped); 631ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 632ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 633ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* test for jitterbug#1435 */ 634ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 635ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const UChar* str = tres_getString(theBundle,-1,"test_underscores",&len,&status); 636ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru expect ="test message ...."; 637ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_charsToUChars(expect,uExpect,(int32_t)strlen(expect)+1); 638ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_ErrorCode(status, U_ZERO_ERROR); 63985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if(str == NULL || u_strcmp(uExpect,str)){ 640ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Did not get the expected string for test_underscores.\n"); 641ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 642ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 643ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* test for jitterbug#2626 */ 644ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_COLLATION 645ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 646ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResourceBundle* resB = NULL; 647ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const UChar* str = NULL; 648ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t strLength = 0; 649ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const UChar my[] = {0x0026,0x0027,0x0075,0x0027,0x0020,0x003d,0x0020,0x0027,0xff55,0x0027,0x0000}; /* &'\u0075' = '\uFF55' */ 650ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 651ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru resB = ures_getByKey(theBundle, "collations", resB, &status); 652ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru resB = ures_getByKey(resB, "standard", resB, &status); 653ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru str = tres_getString(resB,-1,"Sequence",&strLength,&status); 654ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(!str || U_FAILURE(status)) { 655ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_data_err("Could not load collations from theBundle: %s\n", u_errorName(status)); 656ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else if(u_strcmp(my,str) != 0){ 657ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Did not get the expected string for escaped \\u0075\n"); 658ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 659ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(resB); 660ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 661ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif 662ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 663ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char *sourcePath = ctest_dataSrcDir(); 664ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t srcPathLen = (int32_t)strlen(sourcePath); 665ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char *deltaPath = ".."U_FILE_SEP_STRING"test"U_FILE_SEP_STRING"testdata"U_FILE_SEP_STRING; 666ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t deltaPathLen = (int32_t)strlen(deltaPath); 667ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char *testDataFileName = (char *) malloc( srcPathLen+ deltaPathLen + 50 ); 668ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char *path = testDataFileName; 669ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 670ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcpy(path, sourcePath); 671ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru path += srcPathLen; 672ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcpy(path, deltaPath); 673ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru path += deltaPathLen; 674ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 675ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 676ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t strLen =0; 677ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const UChar* str = tres_getString(theBundle, -1, "testincludeUTF",&strLen,&status); 678ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcpy(path, "riwords.txt"); 679ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru path[strlen("riwords.txt")]=0; 680ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)){ 681ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Could not get testincludeUTF resource from testtypes bundle. Error: %s\n",u_errorName(status)); 682ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }else{ 683ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* open the file */ 684ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* cp = NULL; 685ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCHARBUF* ucbuf = ucbuf_open(testDataFileName,&cp,FALSE,FALSE,&status); 686ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru len = 0; 687ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)){ 688ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const UChar* buffer = ucbuf_getBuffer(ucbuf,&len,&status); 689ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)){ 690ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* verify the contents */ 691ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(strLen != len ){ 692ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Did not get the expected len for riwords. Expected: %i , Got: %i\n", len ,strLen); 693ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 694ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* test string termination */ 695ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(u_strlen(str) != strLen || str[strLen]!= 0 ){ 696ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("testinclude not null terminated!\n"); 697ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 698ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(u_strncmp(str, buffer,strLen)!=0){ 699ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Did not get the expected string from riwords. Include functionality failed for genrb.\n"); 700ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 701ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }else{ 702ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ucbuf failed to open %s. Error: %s\n", testDataFileName, u_errorName(status)); 703ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 704ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 705ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucbuf_close(ucbuf); 706ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }else{ 707ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Could not get riwords.txt (path : %s). Error: %s\n",testDataFileName,u_errorName(status)); 708ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 709ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 710ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 711ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 712ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 713ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t strLen =0; 714ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const UChar* str = tres_getString(theBundle, -1, "testinclude",&strLen,&status); 715ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcpy(path, "translit_rules.txt"); 716ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru path[strlen("translit_rules.txt")]=0; 717ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 718ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)){ 719ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Could not get testinclude resource from testtypes bundle. Error: %s\n",u_errorName(status)); 720ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }else{ 721ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* open the file */ 722ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* cp=NULL; 723ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCHARBUF* ucbuf = ucbuf_open(testDataFileName,&cp,FALSE,FALSE,&status); 724ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru len = 0; 725ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)){ 726ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const UChar* buffer = ucbuf_getBuffer(ucbuf,&len,&status); 727ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)){ 728ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* verify the contents */ 729ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(strLen != len ){ 730ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Did not get the expected len for translit_rules. Expected: %i , Got: %i\n", len ,strLen); 731ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 732ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(u_strncmp(str, buffer,strLen)!=0){ 733ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Did not get the expected string from translit_rules. Include functionality failed for genrb.\n"); 734ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 735ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }else{ 736ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ucbuf failed to open %s. Error: %s\n", testDataFileName, u_errorName(status)); 737ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 738ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucbuf_close(ucbuf); 739ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }else{ 740ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Could not get translit_rules.txt (path : %s). Error: %s\n",testDataFileName,u_errorName(status)); 741ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 742ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 743ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 744ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(testDataFileName); 745ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 746ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(res); 747ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(theBundle); 748ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 749ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 750ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 751ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestEmptyTypes() { 752ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResourceBundle* theBundle = NULL; 753ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char action[256]; 754ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* testdatapath; 755ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 756ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResourceBundle* res = NULL; 757ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResourceBundle* resArray = NULL; 758ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const uint8_t *binResult = NULL; 759ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t len = 0; 760ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t intResult = 0; 761ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const UChar *zeroString; 76259d709d503bab6e2b61931737e662dd293b40578ccornelius const int32_t *zeroIntVect = NULL; 763ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 764ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcpy(action, "Construction of testtypes bundle"); 765ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru testdatapath=loadTestData(&status); 766ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) 767ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 76885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_data_err("Could not load testdata.dat %s \n",myErrorName(status)); 769ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 770ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 771ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 772ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru theBundle = ures_open(testdatapath, "testtypes", &status); 773ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 774ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_ErrorCode(status, U_ZERO_ERROR); 775ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 776ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_INT_NE(theBundle, NULL); 777ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 778ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* This test reads the string "abc\u0000def" from the bundle */ 779ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* if everything is working correctly, the size of this string */ 780ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* should be 7. Everything else is a wrong answer, esp. 3 and 6*/ 781ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 782ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 783ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcpy(action, "getting and testing of explicit string of zero length string"); 784ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru res = ures_getByKey(theBundle, "emptyexplicitstring", res, &status); 785ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_ErrorCode(status, U_ZERO_ERROR); 786ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_INT_EQ(ures_getType(res), URES_STRING); 787ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru zeroString=tres_getString(res, -1, NULL, &len, &status); 788ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)){ 789ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_ErrorCode(status, U_ZERO_ERROR); 790ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_INT_EQ(len, 0); 791ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_INT_EQ(u_strlen(zeroString), 0); 792ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 793ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else { 794ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Couldn't get emptyexplicitstring\n"); 795ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 796ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 797ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 798ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcpy(action, "getting and testing of normal string of zero length string"); 799ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru res = ures_getByKey(theBundle, "emptystring", res, &status); 800ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_ErrorCode(status, U_ZERO_ERROR); 801ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_INT_EQ(ures_getType(res), URES_STRING); 802ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru zeroString=tres_getString(res, -1, NULL, &len, &status); 803ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)){ 804ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_ErrorCode(status, U_ZERO_ERROR); 805ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_INT_EQ(len, 0); 806ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_INT_EQ(u_strlen(zeroString), 0); 807ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 808ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else { 809ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Couldn't get emptystring\n"); 810ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 811ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 812ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 813ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcpy(action, "getting and testing of empty int"); 814ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru res = ures_getByKey(theBundle, "emptyint", res, &status); 815ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_ErrorCode(status, U_ZERO_ERROR); 816ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_INT_EQ(ures_getType(res), URES_INT); 817ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru intResult=ures_getInt(res, &status); 818ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)){ 819ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_ErrorCode(status, U_ZERO_ERROR); 820ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_INT_EQ(intResult, 0); 821ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 822ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else { 823ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Couldn't get emptystring\n"); 824ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 825ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 826ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 827ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcpy(action, "getting and testing of zero length intvector"); 828ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru res = ures_getByKey(theBundle, "emptyintv", res, &status); 829ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_ErrorCode(status, U_ZERO_ERROR); 830ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_INT_EQ(ures_getType(res), URES_INT_VECTOR); 831ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 832ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)){ 833ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Couldn't get emptyintv key %s\n", u_errorName(status)); 834ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 835ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else { 836ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru zeroIntVect=ures_getIntVector(res, &len, &status); 83759d709d503bab6e2b61931737e662dd293b40578ccornelius (void)zeroIntVect; /* Suppress set but not used warning. */ 838ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(!U_SUCCESS(status) || resArray != NULL || len != 0) { 839ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Shouldn't get emptyintv\n"); 840ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 841ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 842ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 843ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 844ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcpy(action, "getting and testing of zero length emptybin"); 845ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru res = ures_getByKey(theBundle, "emptybin", res, &status); 846ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_ErrorCode(status, U_ZERO_ERROR); 847ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_INT_EQ(ures_getType(res), URES_BINARY); 848ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 849ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)){ 850ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Couldn't get emptybin key %s\n", u_errorName(status)); 851ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 852ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else { 853ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru binResult=ures_getBinary(res, &len, &status); 85459d709d503bab6e2b61931737e662dd293b40578ccornelius (void)binResult; /* Suppress set but not used warning. */ 85550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if(!U_SUCCESS(status) || len != 0) { 85650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("Couldn't get emptybin, or it's not empty\n"); 857ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 858ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 859ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 860ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 861ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcpy(action, "getting and testing of zero length emptyarray"); 862ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru res = ures_getByKey(theBundle, "emptyarray", res, &status); 863ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_ErrorCode(status, U_ZERO_ERROR); 864ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_INT_EQ(ures_getType(res), URES_ARRAY); 865ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 866ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)){ 867ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Couldn't get emptyarray key %s\n", u_errorName(status)); 868ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 869ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else { 870ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru resArray=ures_getByIndex(res, 0, resArray, &status); 871ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status) || resArray != NULL){ 87250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("Shouldn't get emptyarray[0]\n"); 873ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 874ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 875ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 876ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 877ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcpy(action, "getting and testing of zero length emptytable"); 878ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru res = ures_getByKey(theBundle, "emptytable", res, &status); 879ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_ErrorCode(status, U_ZERO_ERROR); 880ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_INT_EQ(ures_getType(res), URES_TABLE); 881ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 882ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)){ 883ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Couldn't get emptytable key %s\n", u_errorName(status)); 884ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 885ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else { 886ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru resArray=ures_getByIndex(res, 0, resArray, &status); 887ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status) || resArray != NULL){ 88850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("Shouldn't get emptytable[0]\n"); 889ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 890ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 891ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 892ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(res); 893ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(theBundle); 894ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 895ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 896ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestEmptyBundle(){ 897ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 898ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* testdatapath=NULL; 899ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResourceBundle *resb=0, *dResB=0; 900ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 901ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru testdatapath=loadTestData(&status); 902ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) 903ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 90485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_data_err("Could not load testdata.dat %s \n",myErrorName(status)); 905ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 906ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 907ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru resb = ures_open(testdatapath, "testempty", &status); 908ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 909ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)){ 910ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru dResB = ures_getByKey(resb,"test",dResB,&status); 911ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(status!= U_MISSING_RESOURCE_ERROR){ 912ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Did not get the expected error from an empty resource bundle. Expected : %s Got: %s\n", 913ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_errorName(U_MISSING_RESOURCE_ERROR),u_errorName(status)); 914ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 915ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 916ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(dResB); 917ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(resb); 918ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 919ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 920ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestBinaryCollationData(){ 921fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius#if !UCONFIG_NO_COLLATION 922ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status=U_ZERO_ERROR; 923ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* locale="te"; 924ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* testdatapath; 925ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResourceBundle *teRes = NULL; 926ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResourceBundle *coll=NULL; 927ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResourceBundle *binColl = NULL; 928ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint8_t *binResult = NULL; 929ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t len=0; 930ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* action="testing the binary collaton data"; 931ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 932ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Testing binary collation data resource......\n"); 933ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 934ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru testdatapath=loadTestData(&status); 935ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) 936ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 93785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_data_err("Could not load testdata.dat %s \n",myErrorName(status)); 938ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 939ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 940ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 941ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 942ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru teRes=ures_open(testdatapath, locale, &status); 943ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)){ 944ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: Failed to get resource for \"te\" with %s", myErrorName(status)); 945ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 946ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 947ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status=U_ZERO_ERROR; 948ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru coll = ures_getByKey(teRes, "collations", coll, &status); 949ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru coll = ures_getByKey(coll, "standard", coll, &status); 950ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)){ 951ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_ErrorCode(status, U_ZERO_ERROR); 952ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_INT_EQ(ures_getType(coll), URES_TABLE); 953ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru binColl=ures_getByKey(coll, "%%CollationBin", binColl, &status); 954ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)){ 955ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_ErrorCode(status, U_ZERO_ERROR); 956ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_INT_EQ(ures_getType(binColl), URES_BINARY); 957ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru binResult=(uint8_t*)ures_getBinary(binColl, &len, &status); 95859d709d503bab6e2b61931737e662dd293b40578ccornelius (void)binResult; /* Suppress set but not used warning. */ 959ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)){ 960ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_ErrorCode(status, U_ZERO_ERROR); 961ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_INT_GE(len, 1); 962ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 963ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 964ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }else{ 965ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: ures_getByKey(locale(te), %%CollationBin) failed\n"); 966ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 967ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 968ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else{ 969ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: ures_getByKey(locale(te), collations) failed\n"); 970ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 971ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 972ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(binColl); 973ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(coll); 974ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(teRes); 975ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif 976ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 977ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 978ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestAPI() { 979ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status=U_ZERO_ERROR; 980ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t len=0; 981ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* key=NULL; 982ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const UChar* value=NULL; 983ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* testdatapath; 984ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar* utestdatapath=NULL; 985ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char convOutput[256]; 986ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar largeBuffer[1025]; 987ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResourceBundle *teRes = NULL; 988ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResourceBundle *teFillin=NULL; 989ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResourceBundle *teFillin2=NULL; 990ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 991ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Testing ures_openU()......\n"); 992ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 993ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru testdatapath=loadTestData(&status); 994ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) 995ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 99685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_data_err("Could not load testdata.dat %s \n",myErrorName(status)); 997ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 998ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 999ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru len =(int32_t)strlen(testdatapath); 1000ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru utestdatapath = (UChar*) malloc((len+10)*sizeof(UChar)); 1001ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1002ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_charsToUChars(testdatapath, utestdatapath, (int32_t)strlen(testdatapath)+1); 1003ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if (U_FILE_SEP_CHAR != U_FILE_ALT_SEP_CHAR) && U_FILE_SEP_CHAR == '\\' 1004ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1005ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Convert all backslashes to forward slashes so that we can make sure that ures_openU 1006ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru can handle invariant characters. */ 1007ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar *backslash; 1008ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru while ((backslash = u_strchr(utestdatapath, 0x005C))) { 1009ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *backslash = 0x002F; 1010ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1011ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1012ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif 1013ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1014ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_memset(largeBuffer, 0x0030, sizeof(largeBuffer)/sizeof(largeBuffer[0])); 1015ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru largeBuffer[sizeof(largeBuffer)/sizeof(largeBuffer[0])-1] = 0; 1016ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1017ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*Test ures_openU */ 1018ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1019ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 1020ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(ures_openU(largeBuffer, "root", &status)); 1021ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(status != U_ILLEGAL_ARGUMENT_ERROR){ 1022ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: ures_openU() worked when the path is very large. It returned %s\n", myErrorName(status)); 1023ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1024ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1025ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 1026ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(ures_openU(NULL, "root", &status)); 1027ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)){ 102885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(status, "ERROR: ures_openU() failed path = NULL with %s\n", myErrorName(status)); 1029ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1030ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1031ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ILLEGAL_ARGUMENT_ERROR; 1032ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(ures_openU(NULL, "root", &status) != NULL){ 1033ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: ures_openU() worked with error status with %s\n", myErrorName(status)); 1034ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1035ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1036ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 1037ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru teRes=ures_openU(utestdatapath, "te", &status); 1038ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)){ 103985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(status, "ERROR: ures_openU() failed path =%s with %s\n", austrdup(utestdatapath), myErrorName(status)); 1040ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 1041ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1042ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*Test ures_getLocale() */ 1043ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Testing ures_getLocale() .....\n"); 1044ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(strcmp(ures_getLocale(teRes, &status), "te") != 0){ 1045ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: ures_getLocale() failed. Expected = te_TE Got = %s\n", ures_getLocale(teRes, &status)); 1046ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1047ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*Test ures_getNextString() */ 1048ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru teFillin=ures_getByKey(teRes, "tagged_array_in_te_te_IN", teFillin, &status); 1049ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru key=ures_getKey(teFillin); 1050ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru value=(UChar*)ures_getNextString(teFillin, &len, &key, &status); 105159d709d503bab6e2b61931737e662dd293b40578ccornelius (void)value; /* Suppress set but not used warning. */ 1052ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_resetIterator(NULL); 1053ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru value=(UChar*)ures_getNextString(teFillin, &len, &key, &status); 1054ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(status !=U_INDEX_OUTOFBOUNDS_ERROR){ 1055ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: calling getNextString where index out of bounds should return U_INDEX_OUTOFBOUNDS_ERROR, Got : %s\n", 1056ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru myErrorName(status)); 1057ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1058ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_resetIterator(teRes); 1059ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*Test ures_getNextResource() where resource is table*/ 1060ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status=U_ZERO_ERROR; 1061ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if (U_CHARSET_FAMILY == U_ASCII_FAMILY) 1062ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* The next key varies depending on the charset. */ 1063ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru teFillin=ures_getNextResource(teRes, teFillin, &status); 1064ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)){ 1065ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: ures_getNextResource() failed \n"); 1066ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1067ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru key=ures_getKey(teFillin); 1068ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*if(strcmp(key, "%%CollationBin") != 0){*/ 1069ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*if(strcmp(key, "array_2d_in_Root_te") != 0){*/ /* added "aliasClient" that goes first */ 1070ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(strcmp(key, "a") != 0){ 1071ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: ures_getNextResource() failed\n"); 1072ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1073ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif 1074ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1075ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*Test ures_getByIndex on string Resource*/ 1076ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru teFillin=ures_getByKey(teRes, "string_only_in_te", teFillin, &status); 1077ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru teFillin2=ures_getByIndex(teFillin, 0, teFillin2, &status); 1078ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)){ 1079ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: ures_getByIndex on string resource failed\n"); 1080ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1081ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(strcmp(u_austrcpy(convOutput, tres_getString(teFillin2, -1, NULL, &len, &status)), "TE") != 0){ 1082ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status=U_ZERO_ERROR; 1083ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: ures_getByIndex on string resource fetched the key=%s, expected \"TE\" \n", austrdup(ures_getString(teFillin2, &len, &status))); 1084ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1085ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1086ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*ures_close(teRes);*/ 1087ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1088ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*Test ures_openFillIn*/ 1089ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Testing ures_openFillIn......\n"); 1090ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status=U_ZERO_ERROR; 1091ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_openFillIn(teRes, testdatapath, "te", &status); 1092ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)){ 1093ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: ures_openFillIn failed\n"); 1094ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 1095ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1096ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(strcmp(ures_getLocale(teRes, &status), "te") != 0){ 1097ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: ures_openFillIn did not open the ResourceBundle correctly\n"); 1098ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1099ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_getByKey(teRes, "string_only_in_te", teFillin, &status); 1100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru teFillin2=ures_getNextResource(teFillin, teFillin2, &status); 1101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(ures_getType(teFillin2) != URES_STRING){ 1102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: getType for getNextResource after ures_openFillIn failed\n"); 1103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru teFillin2=ures_getNextResource(teFillin, teFillin2, &status); 1105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(status !=U_INDEX_OUTOFBOUNDS_ERROR){ 1106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: calling getNextResource where index out of bounds should return U_INDEX_OUTOFBOUNDS_ERROR, Got : %s\n", 1107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru myErrorName(status)); 1108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(teFillin); 1111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(teFillin2); 1112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(teRes); 1113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Test that ures_getLocale() returns the "real" locale ID */ 1115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status=U_ZERO_ERROR; 1116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru teRes=ures_open(NULL, "dE_At_NOWHERE_TO_BE_FOUND", &status); 1117ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 1118ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_data_err("unable to open a locale resource bundle from \"dE_At_NOWHERE_TO_BE_FOUND\"(%s)\n", u_errorName(status)); 1119ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 1120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(0!=strcmp("de_AT", ures_getLocale(teRes, &status))) { 1121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_data_err("ures_getLocale(\"dE_At_NOWHERE_TO_BE_FOUND\")=%s but must be de_AT\n", ures_getLocale(teRes, &status)); 1122ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1123ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(teRes); 1124ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1125ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1126ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* same test, but with an aliased locale resource bundle */ 1127ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status=U_ZERO_ERROR; 1128ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru teRes=ures_open(NULL, "iW_Il_depRecaTed_HebreW", &status); 1129ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 1130ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_data_err("unable to open a locale resource bundle from \"iW_Il_depRecaTed_HebreW\"(%s)\n", u_errorName(status)); 1131ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 1132ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(0!=strcmp("he_IL", ures_getLocale(teRes, &status))) { 1133ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_data_err("ures_getLocale(\"iW_Il_depRecaTed_HebreW\")=%s but must be he_IL\n", ures_getLocale(teRes, &status)); 1134ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1135ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(teRes); 1136ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1137ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(utestdatapath); 1138ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 1139ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1140ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestErrorConditions(){ 1141ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status=U_ZERO_ERROR; 1142ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char *key=NULL; 1143ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const UChar *value=NULL; 1144ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* testdatapath; 1145ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar* utestdatapath; 1146ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t len=0; 1147ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResourceBundle *teRes = NULL; 1148ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResourceBundle *coll=NULL; 1149ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResourceBundle *binColl = NULL; 1150ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResourceBundle *teFillin=NULL; 1151ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResourceBundle *teFillin2=NULL; 1152ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint8_t *binResult = NULL; 1153ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t resultLen; 1154ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1155ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1156ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru testdatapath = loadTestData(&status); 1157ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) 1158ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 115985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_data_err("Could not load testdata.dat %s \n",myErrorName(status)); 1160ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 1161ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1162ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru len = (int32_t)strlen(testdatapath); 1163ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru utestdatapath = (UChar*) malloc(sizeof(UChar) *(len+10)); 1164ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(utestdatapath, testdatapath); 1165ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1166ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*Test ures_openU with status != U_ZERO_ERROR*/ 1167ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Testing ures_openU() with status != U_ZERO_ERROR.....\n"); 1168ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status=U_ILLEGAL_ARGUMENT_ERROR; 1169ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru teRes=ures_openU(utestdatapath, "te", &status); 1170ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)){ 1171ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("ures_openU() failed as expected path =%s with status != U_ZERO_ERROR\n", testdatapath); 1172ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }else{ 1173ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: ures_openU() is supposed to fail path =%s with status != U_ZERO_ERROR\n", austrdup(utestdatapath)); 1174ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(teRes); 1175ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1176ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*Test ures_openFillIn with UResourceBundle = NULL*/ 1177ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Testing ures_openFillIn with UResourceBundle = NULL.....\n"); 1178ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status=U_ZERO_ERROR; 1179ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_openFillIn(NULL, testdatapath, "te", &status); 1180ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(status != U_ILLEGAL_ARGUMENT_ERROR){ 1181ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: ures_openFillIn with UResourceBundle= NULL should fail. Expected U_ILLEGAL_ARGUMENT_ERROR, Got: %s\n", 1182ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru myErrorName(status)); 1183ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1184ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*Test ures_getLocale() with status != U_ZERO_ERROR*/ 1185ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status=U_ZERO_ERROR; 1186ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru teRes=ures_openU(utestdatapath, "te", &status); 1187ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)){ 1188ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: ures_openU() failed path =%s with %s\n", austrdup(utestdatapath), myErrorName(status)); 1189ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 1190ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1191ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status=U_ILLEGAL_ARGUMENT_ERROR; 1192ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(ures_getLocale(teRes, &status) != NULL){ 1193ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: ures_getLocale is supposed to fail with errorCode != U_ZERO_ERROR\n"); 1194ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1195ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*Test ures_getLocale() with UResourceBundle = NULL*/ 1196ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status=U_ZERO_ERROR; 1197ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(ures_getLocale(NULL, &status) != NULL && status != U_ILLEGAL_ARGUMENT_ERROR){ 1198ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: ures_getLocale is supposed to fail when UResourceBundle = NULL. Expected: errorCode = U_ILLEGAL_ARGUMENT_ERROR, Got: errorCode=%s\n", 1199ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru myErrorName(status)); 1200ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1201ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*Test ures_getSize() with UResourceBundle = NULL */ 1202ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status=U_ZERO_ERROR; 1203ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(ures_getSize(NULL) != 0){ 1204ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: ures_getSize() should return 0 when UResourceBundle=NULL. Got =%d\n", ures_getSize(NULL)); 1205ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1206ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*Test ures_getType() with UResourceBundle = NULL should return URES_NONE==-1*/ 1207ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status=U_ZERO_ERROR; 1208ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(ures_getType(NULL) != URES_NONE){ 1209ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: ures_getType() should return URES_NONE when UResourceBundle=NULL. Got =%d\n", ures_getType(NULL)); 1210ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1211ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*Test ures_getKey() with UResourceBundle = NULL*/ 1212ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status=U_ZERO_ERROR; 1213ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(ures_getKey(NULL) != NULL){ 1214ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: ures_getKey() should return NULL when UResourceBundle=NULL. Got =%d\n", ures_getKey(NULL)); 1215ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1216ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*Test ures_hasNext() with UResourceBundle = NULL*/ 1217ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status=U_ZERO_ERROR; 1218ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(ures_hasNext(NULL) != FALSE){ 1219ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: ures_hasNext() should return FALSE when UResourceBundle=NULL. Got =%d\n", ures_hasNext(NULL)); 1220ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1221ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*Test ures_get() with UResourceBundle = NULL*/ 1222ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status=U_ZERO_ERROR; 1223ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(ures_getStringByKey(NULL, "string_only_in_te", &resultLen, &status) != NULL && status != U_ILLEGAL_ARGUMENT_ERROR){ 1224ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: ures_get is supposed to fail when UResourceBundle = NULL. Expected: errorCode = U_ILLEGAL_ARGUMENT_ERROR, Got: errorCode=%s\n", 1225ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru myErrorName(status)); 1226ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1227ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*Test ures_getByKey() with UResourceBundle = NULL*/ 1228ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status=U_ZERO_ERROR; 1229ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru teFillin=ures_getByKey(NULL, "string_only_in_te", teFillin, &status); 1230ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if( teFillin != NULL && status != U_ILLEGAL_ARGUMENT_ERROR){ 1231ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: ures_getByKey is supposed to fail when UResourceBundle = NULL. Expected: errorCode = U_ILLEGAL_ARGUMENT_ERROR, Got: errorCode=%s\n", 1232ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru myErrorName(status)); 1233ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1234ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*Test ures_getByKey() with status != U_ZERO_ERROR*/ 1235ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru teFillin=ures_getByKey(NULL, "string_only_in_te", teFillin, &status); 1236ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(teFillin != NULL ){ 1237ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: ures_getByKey is supposed to fail when errorCode != U_ZERO_ERROR\n"); 1238ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1239ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*Test ures_getStringByKey() with UResourceBundle = NULL*/ 1240ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status=U_ZERO_ERROR; 1241ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(ures_getStringByKey(NULL, "string_only_in_te", &len, &status) != NULL && status != U_ILLEGAL_ARGUMENT_ERROR){ 1242ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: ures_getStringByKey is supposed to fail when UResourceBundle = NULL. Expected: errorCode = U_ILLEGAL_ARGUMENT_ERROR, Got: errorCode=%s\n", 1243ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru myErrorName(status)); 1244ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1245ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*Test ures_getStringByKey() with status != U_ZERO_ERROR*/ 1246ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(ures_getStringByKey(teRes, "string_only_in_te", &len, &status) != NULL){ 1247ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: ures_getStringByKey is supposed to fail when status != U_ZERO_ERROR. Expected: errorCode = U_ILLEGAL_ARGUMENT_ERROR, Got: errorCode=%s\n", 1248ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru myErrorName(status)); 1249ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1250ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*Test ures_getString() with UResourceBundle = NULL*/ 1251ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status=U_ZERO_ERROR; 1252ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(ures_getString(NULL, &len, &status) != NULL && status != U_ILLEGAL_ARGUMENT_ERROR){ 1253ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: ures_getString is supposed to fail when UResourceBundle = NULL. Expected: errorCode = U_ILLEGAL_ARGUMENT_ERROR, Got: errorCode=%s\n", 1254ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru myErrorName(status)); 1255ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1256ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*Test ures_getString() with status != U_ZERO_ERROR*/ 1257ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(ures_getString(teRes, &len, &status) != NULL){ 1258ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: ures_getString is supposed to fail when status != U_ZERO_ERROR. Expected: errorCode = U_ILLEGAL_ARGUMENT_ERROR, Got: errorCode=%s\n", 1259ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru myErrorName(status)); 1260ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1261ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*Test ures_getBinary() with UResourceBundle = NULL*/ 1262ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status=U_ZERO_ERROR; 1263ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(ures_getBinary(NULL, &len, &status) != NULL && status != U_ILLEGAL_ARGUMENT_ERROR){ 1264ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: ures_getBinary is supposed to fail when UResourceBundle = NULL. Expected: errorCode = U_ILLEGAL_ARGUMENT_ERROR, Got: errorCode=%s\n", 1265ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru myErrorName(status)); 1266ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1267ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*Test ures_getBinary(0 status != U_ILLEGAL_ARGUMENT_ERROR*/ 1268ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status=U_ZERO_ERROR; 1269ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru coll = ures_getByKey(teRes, "collations", coll, &status); 1270ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru coll = ures_getByKey(teRes, "standard", coll, &status); 1271ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru binColl=ures_getByKey(coll, "%%CollationBin", binColl, &status); 1272ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1273ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status=U_ILLEGAL_ARGUMENT_ERROR; 1274ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru binResult=(uint8_t*)ures_getBinary(binColl, &len, &status); 1275ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(binResult != NULL){ 1276ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: ures_getBinary() with status != U_ZERO_ERROR is supposed to fail\n"); 1277ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1278ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1279ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*Test ures_getNextResource() with status != U_ZERO_ERROR*/ 1280ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru teFillin=ures_getNextResource(teRes, teFillin, &status); 1281ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(teFillin != NULL){ 1282ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: ures_getNextResource() with errorCode != U_ZERO_ERROR is supposed to fail\n"); 1283ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1284ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*Test ures_getNextResource() with UResourceBundle = NULL*/ 1285ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status=U_ZERO_ERROR; 1286ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru teFillin=ures_getNextResource(NULL, teFillin, &status); 1287ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(teFillin != NULL || status != U_ILLEGAL_ARGUMENT_ERROR){ 1288ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: ures_getNextResource() with UResourceBundle = NULL is supposed to fail. Expected : U_IILEGAL_ARGUMENT_ERROR, Got : %s\n", 1289ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru myErrorName(status)); 1290ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1291ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*Test ures_getNextString with errorCode != U_ZERO_ERROR*/ 1292ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru teFillin=ures_getByKey(teRes, "tagged_array_in_te_te_IN", teFillin, &status); 1293ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru key=ures_getKey(teFillin); 1294ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ILLEGAL_ARGUMENT_ERROR; 1295ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru value=(UChar*)ures_getNextString(teFillin, &len, &key, &status); 1296ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(value != NULL){ 1297ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: ures_getNextString() with errorCode != U_ZERO_ERROR is supposed to fail\n"); 1298ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1299ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*Test ures_getNextString with UResourceBundle = NULL*/ 1300ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status=U_ZERO_ERROR; 1301ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru value=(UChar*)ures_getNextString(NULL, &len, &key, &status); 1302ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(value != NULL || status != U_ILLEGAL_ARGUMENT_ERROR){ 1303ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: ures_getNextString() with UResourceBundle=NULL is supposed to fail\n Expected: U_ILLEGAL_ARGUMENT_ERROR, Got: %s\n", 1304ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru myErrorName(status)); 1305ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1306ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*Test ures_getByIndex with errorCode != U_ZERO_ERROR*/ 1307ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status=U_ZERO_ERROR; 1308ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru teFillin=ures_getByKey(teRes, "array_only_in_te", teFillin, &status); 1309ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(ures_countArrayItems(teRes, "array_only_in_te", &status) != 4) { 1310ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: Wrong number of items in an array!\n"); 1311ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1312ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status=U_ILLEGAL_ARGUMENT_ERROR; 1313ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru teFillin2=ures_getByIndex(teFillin, 0, teFillin2, &status); 1314ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(teFillin2 != NULL){ 1315ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: ures_getByIndex() with errorCode != U_ZERO_ERROR is supposed to fail\n"); 1316ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1317ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*Test ures_getByIndex with UResourceBundle = NULL */ 1318ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status=U_ZERO_ERROR; 1319ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru teFillin2=ures_getByIndex(NULL, 0, teFillin2, &status); 1320ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(status != U_ILLEGAL_ARGUMENT_ERROR){ 1321ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: ures_getByIndex() with UResourceBundle=NULL is supposed to fail\n Expected: U_ILLEGAL_ARGUMENT_ERROR, Got: %s\n", 1322ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru myErrorName(status)); 1323ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1324ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*Test ures_getStringByIndex with errorCode != U_ZERO_ERROR*/ 1325ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status=U_ZERO_ERROR; 1326ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru teFillin=ures_getByKey(teRes, "array_only_in_te", teFillin, &status); 1327ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status=U_ILLEGAL_ARGUMENT_ERROR; 1328ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru value=(UChar*)ures_getStringByIndex(teFillin, 0, &len, &status); 1329ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if( value != NULL){ 1330ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: ures_getSringByIndex() with errorCode != U_ZERO_ERROR is supposed to fail\n"); 1331ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1332ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*Test ures_getStringByIndex with UResourceBundle = NULL */ 1333ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status=U_ZERO_ERROR; 1334ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru value=(UChar*)ures_getStringByIndex(NULL, 0, &len, &status); 1335ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(value != NULL || status != U_ILLEGAL_ARGUMENT_ERROR){ 1336ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: ures_getStringByIndex() with UResourceBundle=NULL is supposed to fail\n Expected: U_ILLEGAL_ARGUMENT_ERROR, Got: %s\n", 1337ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru myErrorName(status)); 1338ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1339ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*Test ures_getStringByIndex with UResourceBundle = NULL */ 1340ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status=U_ZERO_ERROR; 1341ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru value=(UChar*)ures_getStringByIndex(teFillin, 9999, &len, &status); 1342ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(value != NULL || status != U_MISSING_RESOURCE_ERROR){ 1343ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: ures_getStringByIndex() with index that is too big is supposed to fail\n Expected: U_MISSING_RESOURCE_ERROR, Got: %s\n", 1344ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru myErrorName(status)); 1345ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1346ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*Test ures_getInt() where UResourceBundle = NULL */ 1347ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status=U_ZERO_ERROR; 1348ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(ures_getInt(NULL, &status) != -1 && status != U_ILLEGAL_ARGUMENT_ERROR){ 1349ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: ures_getInt() with UResourceBundle = NULL should fail. Expected: U_IILEGAL_ARGUMENT_ERROR, Got: %s\n", 1350ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru myErrorName(status)); 1351ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1352ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*Test ures_getInt() where status != U_ZERO_ERROR */ 1353ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(ures_getInt(teRes, &status) != -1){ 1354ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: ures_getInt() with errorCode != U_ZERO_ERROR should fail\n"); 1355ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1356ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1357ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(teFillin); 1358ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(teFillin2); 1359ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(coll); 1360ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(binColl); 1361ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(teRes); 1362ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(utestdatapath); 1363ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1364ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1365ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 1366ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1367ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestGetVersion(){ 1368ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UVersionInfo minVersionArray = {0x01, 0x00, 0x00, 0x00}; 136985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UVersionInfo maxVersionArray = {0x50, 0xff, 0xcf, 0xcf}; 1370ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UVersionInfo versionArray; 1371ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status= U_ZERO_ERROR; 1372ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResourceBundle* resB = NULL; 1373ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int i=0, j = 0; 1374ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int locCount = uloc_countAvailable(); 1375ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char *locName = "root"; 1376ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1377ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("The ures_getVersion tests begin : \n"); 1378ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1379ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(j = -1; j < locCount; j++) { 1380ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(j >= 0) { 1381ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru locName = uloc_getAvailable(j); 1382ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1383ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Testing version number for locale %s\n", locName); 1384ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru resB = ures_open(NULL,locName, &status); 1385ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)) { 138685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(status, "Resource bundle creation for locale %s failed.: %s\n", locName, myErrorName(status)); 1387ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(resB); 1388ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 1389ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1390ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_getVersion(resB, versionArray); 1391ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (i=0; i<4; ++i) { 1392ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (versionArray[i] < minVersionArray[i] || 1393ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru versionArray[i] > maxVersionArray[i]) 1394ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1395ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Testing ures_getVersion(%-5s) - unexpected result: %d.%d.%d.%d\n", 1396ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru locName, versionArray[0], versionArray[1], versionArray[2], versionArray[3]); 1397ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru break; 1398ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1399ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1400ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(resB); 1401ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1402ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 1403ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1404ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1405ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestGetVersionColl(){ 1406fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius#if !UCONFIG_NO_COLLATION 1407ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UVersionInfo minVersionArray = {0x00, 0x00, 0x00, 0x00}; 1408ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UVersionInfo maxVersionArray = {0x50, 0x80, 0xcf, 0xcf}; 1409ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UVersionInfo versionArray; 1410ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status= U_ZERO_ERROR; 1411ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResourceBundle* resB = NULL; 1412ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UEnumeration *locs= NULL; 1413ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int i=0; 1414ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char *locName = "root"; 1415ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t locLen; 1416ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const UChar* rules =NULL; 1417ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t len = 0; 1418fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius 1419fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius /* test NUL termination of UCARules */ 1420fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius resB = ures_open(U_ICUDATA_COLL,locName, &status); 1421fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius rules = tres_getString(resB,-1,"UCARules",&len, &status); 1422fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius if(!rules || U_FAILURE(status)) { 1423fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius log_data_err("Could not load UCARules for locale %s\n", locName); 1424fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius status = U_ZERO_ERROR; 1425fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius } else if(u_strlen(rules) != len){ 1426fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius log_err("UCARules string not nul terminated! \n"); 1427fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius } 1428fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius ures_close(resB); 1429fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius 1430ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("The ures_getVersion(%s) tests begin : \n", U_ICUDATA_COLL); 1431ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru locs = ures_openAvailableLocales(U_ICUDATA_COLL, &status); 1432ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)) { 143385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(status, "enumeration of %s failed.: %s\n", U_ICUDATA_COLL, myErrorName(status)); 1434ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 1435ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1436ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1437fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius for (;;) { 1438ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Testing version number for locale %s\n", locName); 1439ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru resB = ures_open(U_ICUDATA_COLL,locName, &status); 1440ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)) { 1441ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Resource bundle creation for locale %s:%s failed.: %s\n", U_ICUDATA_COLL, locName, myErrorName(status)); 1442ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(resB); 1443fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius break; 1444ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1445ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_getVersion(resB, versionArray); 1446ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (i=0; i<4; ++i) { 1447ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (versionArray[i] < minVersionArray[i] || 1448ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru versionArray[i] > maxVersionArray[i]) 1449ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1450ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Testing ures_getVersion(%-5s) - unexpected result: %d.%d.%d.%d\n", 1451ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru locName, versionArray[0], versionArray[1], versionArray[2], versionArray[3]); 1452ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru break; 1453ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1454ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1455ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(resB); 1456fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius locName = uenum_next(locs, &locLen, &status); 1457fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius if(U_FAILURE(status)) { 1458fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius log_err("uenum_next(locs) error %s\n", u_errorName(status)); 1459fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius break; 1460fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius } 1461fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius if(locName == NULL) { 1462fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius break; 1463fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius } 1464ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1465ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uenum_close(locs); 1466fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius#endif /* !UCONFIG_NO_COLLATION */ 1467ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 1468ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1469ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestResourceBundles() 1470ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 1471ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 1472ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru loadTestData(&status); 1473ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 147485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_data_err("Could not load testdata.dat, status = %s\n", u_errorName(status)); 1475ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 1476ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1477ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1478ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru testTag("only_in_Root", TRUE, FALSE, FALSE); 1479ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru testTag("in_Root_te", TRUE, TRUE, FALSE); 1480ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru testTag("in_Root_te_te_IN", TRUE, TRUE, TRUE); 1481ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru testTag("in_Root_te_IN", TRUE, FALSE, TRUE); 1482ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru testTag("only_in_te", FALSE, TRUE, FALSE); 1483ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru testTag("only_in_te_IN", FALSE, FALSE, TRUE); 1484ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru testTag("in_te_te_IN", FALSE, TRUE, TRUE); 1485ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru testTag("nonexistent", FALSE, FALSE, FALSE); 1486ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1487ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Passed:= %d Failed= %d \n", pass, fail); 1488ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1489ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 1490ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1491ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1492ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestConstruction1() 1493ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 1494ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResourceBundle *test1 = 0, *test2 = 0,*empty = 0; 1495ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const UChar *result1, *result2; 1496ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status= U_ZERO_ERROR; 1497ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode err = U_ZERO_ERROR; 1498ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* locale="te_IN"; 1499ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* testdatapath; 1500ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1501ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t len1=0; 1502ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t len2=0; 1503ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UVersionInfo versionInfo; 1504ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char versionString[256]; 1505ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char verboseOutput[256]; 1506ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1507ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru U_STRING_DECL(rootVal, "ROOT", 4); 1508ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru U_STRING_DECL(te_inVal, "TE_IN", 5); 1509ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1510ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru U_STRING_INIT(rootVal, "ROOT", 4); 1511ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru U_STRING_INIT(te_inVal, "TE_IN", 5); 1512ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1513ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru testdatapath=loadTestData(&status); 1514ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) 1515ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 151685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_data_err("Could not load testdata.dat %s \n",myErrorName(status)); 1517ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 1518ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1519ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1520ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Testing ures_open()......\n"); 1521ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1522ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru empty = ures_open(testdatapath, "testempty", &status); 1523ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(empty == NULL || U_FAILURE(status)) { 1524ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("opening empty failed!\n"); 1525ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1526ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(empty); 1527ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1528ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru test1=ures_open(testdatapath, NULL, &err); 1529ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1530ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(err)) 1531ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1532ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("construction of NULL did not succeed : %s \n", myErrorName(status)); 1533ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 1534ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1535ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru test2=ures_open(testdatapath, locale, &err); 1536ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(err)) 1537ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1538ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("construction of %s did not succeed : %s \n", locale, myErrorName(status)); 1539ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 1540ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1541ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru result1= tres_getString(test1, -1, "string_in_Root_te_te_IN", &len1, &err); 1542ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru result2= tres_getString(test2, -1, "string_in_Root_te_te_IN", &len2, &err); 1543ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(err) || len1==0 || len2==0) { 1544ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Something threw an error in TestConstruction(): %s\n", myErrorName(status)); 1545ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 1546ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1547ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("for string_in_Root_te_te_IN, default.txt had %s\n", u_austrcpy(verboseOutput, result1)); 1548ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("for string_in_Root_te_te_IN, te_IN.txt had %s\n", u_austrcpy(verboseOutput, result2)); 1549ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(u_strcmp(result1, rootVal) !=0 || u_strcmp(result2, te_inVal) !=0 ){ 1550ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("construction test failed. Run Verbose for more information"); 1551ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1552ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1553ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1554ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Test getVersionNumber*/ 1555ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Testing version number\n"); 1556ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("for getVersionNumber : %s\n", ures_getVersionNumber(test1)); 1557ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1558ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Testing version \n"); 1559ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_getVersion(test1, versionInfo); 1560ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_versionToString(versionInfo, versionString); 1561ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1562ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("for getVersion : %s\n", versionString); 1563ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1564ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(strcmp(versionString, ures_getVersionNumber(test1)) != 0) { 1565ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Versions differ: %s vs %s\n", versionString, ures_getVersionNumber(test1)); 1566ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1567ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1568ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(test1); 1569ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(test2); 1570ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1571ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 1572ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1573ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/*****************************************************************************/ 1574ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/*****************************************************************************/ 1575ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1576ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic UBool testTag(const char* frag, 1577ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UBool in_Root, 1578ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UBool in_te, 1579ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UBool in_te_IN) 1580ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 1581ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t failNum = fail; 1582ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1583ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Make array from input params */ 1584ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1585ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UBool is_in[3]; 1586ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char *NAME[] = { "ROOT", "TE", "TE_IN" }; 1587ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1588ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Now try to load the desired items */ 1589ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResourceBundle* theBundle = NULL; 1590ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char tag[99]; 1591ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char action[256]; 1592ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode expected_status,status = U_ZERO_ERROR,expected_resource_status = U_ZERO_ERROR; 1593ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar* base = NULL; 1594ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar* expected_string = NULL; 1595ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const UChar* string = NULL; 1596ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char buf[5]; 1597ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char item_tag[10]; 1598ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t i,j,row,col, len; 1599ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t actual_bundle; 1600ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t count = 0; 1601ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t row_count=0; 1602ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t column_count=0; 160354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius int32_t idx = 0; 1604ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t tag_count= 0; 1605ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* testdatapath; 1606ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char verboseOutput[256]; 1607ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResourceBundle* array=NULL; 1608ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResourceBundle* array2d=NULL; 1609ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResourceBundle* tags=NULL; 1610ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResourceBundle* arrayItem1=NULL; 1611ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1612ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru testdatapath = loadTestData(&status); 1613ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) 1614ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 161585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_data_err("Could not load testdata.dat %s \n",myErrorName(status)); 1616ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return FALSE; 1617ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1618ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1619ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru is_in[0] = in_Root; 1620ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru is_in[1] = in_te; 1621ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru is_in[2] = in_te_IN; 1622ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1623ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcpy(item_tag, "tag"); 1624ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1625ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (i=0; i<bundles_count; ++i) 1626ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1627ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcpy(action,"construction for "); 1628ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcat(action, param[i].name); 1629ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1630ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1631ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 1632ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1633ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru theBundle = ures_open(testdatapath, param[i].name, &status); 1634ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_ErrorCode(status,param[i].expected_constructor_status); 1635ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1636ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(i == 5) 1637ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru actual_bundle = 0; /* ne -> default */ 1638ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else if(i == 3) 1639ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru actual_bundle = 1; /* te_NE -> te */ 1640ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else if(i == 4) 1641ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru actual_bundle = 2; /* te_IN_NE -> te_IN */ 1642ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else 1643ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru actual_bundle = i; 1644ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1645ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru expected_resource_status = U_MISSING_RESOURCE_ERROR; 1646ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (j=e_te_IN; j>=e_Root; --j) 1647ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1648ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (is_in[j] && param[i].inherits[j]) 1649ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1650ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1651ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(j == actual_bundle) /* it's in the same bundle OR it's a nonexistent=default bundle (5) */ 1652ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru expected_resource_status = U_ZERO_ERROR; 1653ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else if(j == 0) 1654ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru expected_resource_status = U_USING_DEFAULT_WARNING; 1655ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else 1656ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru expected_resource_status = U_USING_FALLBACK_WARNING; 1657ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1658ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("%s[%d]::%s: in<%d:%s> inherits<%d:%s>. actual_bundle=%s\n", 1659ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru param[i].name, 1660ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru i, 1661ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru frag, 1662ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru j, 1663ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru is_in[j]?"Yes":"No", 1664ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru j, 1665ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru param[i].inherits[j]?"Yes":"No", 1666ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru param[actual_bundle].name); 1667ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1668ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru break; 1669ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1670ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1671ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1672ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (j=param[i].where; j>=0; --j) 1673ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1674ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (is_in[j]) 1675ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1676ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(base != NULL) { 1677ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(base); 1678ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru base = NULL; 1679ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1680ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru base=(UChar*)malloc(sizeof(UChar)*(strlen(NAME[j]) + 1)); 1681ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(base,NAME[j]); 1682ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1683ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru break; 1684ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1685ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else { 1686ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(base != NULL) { 1687ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(base); 1688ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru base = NULL; 1689ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1690ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru base = (UChar*) malloc(sizeof(UChar) * 1); 1691ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *base = 0x0000; 1692ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1693ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1694ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1695ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*----string---------------------------------------------------------------- */ 1696ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1697ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcpy(tag,"string_"); 1698ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcat(tag,frag); 1699ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1700ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcpy(action,param[i].name); 1701ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcat(action, ".ures_getStringByKey(" ); 1702ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcat(action,tag); 1703ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcat(action, ")"); 1704ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1705ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1706ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 1707ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru len=0; 1708ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1709ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru string=tres_getString(theBundle, -1, tag, &len, &status); 1710ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)) { 1711ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru expected_string=(UChar*)malloc(sizeof(UChar)*(u_strlen(base) + 4)); 1712ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_strcpy(expected_string,base); 1713ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_INT_EQ(len, u_strlen(expected_string)); 1714ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }else{ 1715ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru expected_string = (UChar*)malloc(sizeof(UChar)*(u_strlen(kERROR) + 1)); 1716ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_strcpy(expected_string,kERROR); 1717ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru string=kERROR; 1718ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1719ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("%s got %d, expected %d\n", action, status, expected_resource_status); 1720ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1721ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_ErrorCode(status, expected_resource_status); 1722ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_EQ(string, expected_string); 1723ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1724ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1725ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1726ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*--------------array------------------------------------------------- */ 1727ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1728ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcpy(tag,"array_"); 1729ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcat(tag,frag); 1730ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1731ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcpy(action,param[i].name); 1732ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcat(action, ".ures_getByKey(" ); 1733ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcat(action,tag); 1734ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcat(action, ")"); 1735ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1736ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru len=0; 1737ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1738ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru count = kERROR_COUNT; 1739ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 1740ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru array=ures_getByKey(theBundle, tag, array, &status); 1741ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_ErrorCode(status,expected_resource_status); 1742ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_SUCCESS(status)) { 1743ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*confirm the resource type is an array*/ 1744ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_INT_EQ(ures_getType(array), URES_ARRAY); 1745ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*confirm the size*/ 1746ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru count=ures_getSize(array); 1747ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_INT_GE(count,1); 1748ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (j=0; j<count; ++j) { 1749ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar element[3]; 1750ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_strcpy(expected_string, base); 1751ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(element, itoa1(j,buf)); 1752ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_strcat(expected_string, element); 1753ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru arrayItem1=ures_getNextResource(array, arrayItem1, &status); 1754ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)){ 1755ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_EQ(tres_getString(arrayItem1, -1, NULL, &len, &status),expected_string); 1756ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1757ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1758ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1759ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1760ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else { 1761ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_INT_EQ(count,kERROR_COUNT); 1762ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_ErrorCode(status, U_MISSING_RESOURCE_ERROR); 1763ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*CONFIRM_INT_EQ((int32_t)(unsigned long)array,(int32_t)0);*/ 1764ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru count = 0; 1765ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1766ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1767ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*--------------arrayItem------------------------------------------------- */ 1768ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1769ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcpy(tag,"array_"); 1770ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcat(tag,frag); 1771ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1772ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcpy(action,param[i].name); 1773ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcat(action, ".ures_getStringByIndex("); 1774ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcat(action, tag); 1775ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcat(action, ")"); 1776ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1777ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1778ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (j=0; j<10; ++j){ 177954dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius idx = count ? (randi(count * 3) - count) : (randi(200) - 100); 1780ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 1781ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru string=kERROR; 1782ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru array=ures_getByKey(theBundle, tag, array, &status); 1783ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(!U_FAILURE(status)){ 1784ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar *t=NULL; 178554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius t=(UChar*)ures_getStringByIndex(array, idx, &len, &status); 1786ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(!U_FAILURE(status)){ 1787ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar element[3]; 1788ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru string=t; 1789ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_strcpy(expected_string, base); 179054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius u_uastrcpy(element, itoa1(idx,buf)); 1791ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_strcat(expected_string, element); 1792ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 1793ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_strcpy(expected_string, kERROR); 1794ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1795ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1796ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 179754dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius expected_status = (idx >= 0 && idx < count) ? expected_resource_status : U_MISSING_RESOURCE_ERROR; 1798ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_ErrorCode(status,expected_status); 1799ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_EQ(string,expected_string); 1800ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1801ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1802ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1803ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1804ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*--------------2dArray------------------------------------------------- */ 1805ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1806ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcpy(tag,"array_2d_"); 1807ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcat(tag,frag); 1808ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1809ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcpy(action,param[i].name); 1810ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcat(action, ".ures_getByKey(" ); 1811ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcat(action,tag); 1812ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcat(action, ")"); 1813ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1814ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1815ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1816ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru row_count = kERROR_COUNT, column_count = kERROR_COUNT; 1817ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 1818ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru array2d=ures_getByKey(theBundle, tag, array2d, &status); 1819ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1820ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_ErrorCode(status,expected_resource_status); 1821ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_SUCCESS(status)) 1822ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1823ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*confirm the resource type is an 2darray*/ 1824ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_INT_EQ(ures_getType(array2d), URES_ARRAY); 1825ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru row_count=ures_getSize(array2d); 1826ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_INT_GE(row_count,1); 1827ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1828ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(row=0; row<row_count; ++row){ 1829ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResourceBundle *tableRow=NULL; 1830ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru tableRow=ures_getByIndex(array2d, row, tableRow, &status); 1831ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_ErrorCode(status, expected_resource_status); 1832ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)){ 1833ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*confirm the resourcetype of each table row is an array*/ 1834ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_INT_EQ(ures_getType(tableRow), URES_ARRAY); 1835ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru column_count=ures_getSize(tableRow); 1836ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_INT_GE(column_count,1); 1837ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1838ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (col=0; j<column_count; ++j) { 1839ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar element[3]; 1840ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_strcpy(expected_string, base); 1841ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(element, itoa1(row, buf)); 1842ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_strcat(expected_string, element); 1843ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(element, itoa1(col, buf)); 1844ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_strcat(expected_string, element); 1845ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru arrayItem1=ures_getNextResource(tableRow, arrayItem1, &status); 1846ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)){ 1847ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const UChar *stringValue=tres_getString(arrayItem1, -1, NULL, &len, &status); 1848ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_EQ(stringValue, expected_string); 1849ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1850ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1851ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1852ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(tableRow); 1853ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1854ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }else{ 1855ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_INT_EQ(row_count,kERROR_COUNT); 1856ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_INT_EQ(column_count,kERROR_COUNT); 1857ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru row_count=column_count=0; 1858ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1859ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1860ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1861ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*------2dArrayItem-------------------------------------------------------------- */ 1862ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* 2dArrayItem*/ 1863ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (j=0; j<10; ++j) 1864ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1865ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru row = row_count ? (randi(row_count * 3) - row_count) : (randi(200) - 100); 1866ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru col = column_count ? (randi(column_count * 3) - column_count) : (randi(200) - 100); 1867ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 1868ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru string = kERROR; 1869ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru len=0; 1870ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru array2d=ures_getByKey(theBundle, tag, array2d, &status); 1871ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)){ 1872ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResourceBundle *tableRow=NULL; 1873ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru tableRow=ures_getByIndex(array2d, row, tableRow, &status); 1874ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)) { 1875ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar *t=NULL; 1876ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru t=(UChar*)ures_getStringByIndex(tableRow, col, &len, &status); 1877ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)){ 1878ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru string=t; 1879ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1880ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1881ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(tableRow); 1882ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1883ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru expected_status = (row >= 0 && row < row_count && col >= 0 && col < column_count) ? 1884ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru expected_resource_status: U_MISSING_RESOURCE_ERROR; 1885ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_ErrorCode(status,expected_status); 1886ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1887ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_SUCCESS(status)){ 1888ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar element[3]; 1889ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_strcpy(expected_string, base); 1890ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(element, itoa1(row, buf)); 1891ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_strcat(expected_string, element); 1892ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(element, itoa1(col, buf)); 1893ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_strcat(expected_string, element); 1894ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 1895ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_strcpy(expected_string,kERROR); 1896ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1897ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_EQ(string,expected_string); 1898ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1899ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1900ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1901ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1902ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*--------------taggedArray----------------------------------------------- */ 1903ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcpy(tag,"tagged_array_"); 1904ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcat(tag,frag); 1905ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1906ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcpy(action,param[i].name); 1907ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcat(action,".ures_getByKey("); 1908ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcat(action, tag); 1909ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcat(action,")"); 1910ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1911ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1912ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 1913ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru tag_count=0; 1914ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru tags=ures_getByKey(theBundle, tag, tags, &status); 1915ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_ErrorCode(status, expected_resource_status); 1916ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_SUCCESS(status)) { 1917ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResType bundleType=ures_getType(tags); 1918ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_INT_EQ(bundleType, URES_TABLE); 1919ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1920ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru tag_count=ures_getSize(tags); 1921ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_INT_GE((int32_t)tag_count, (int32_t)0); 1922ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 192354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius for(idx=0; idx <tag_count; idx++){ 1924ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResourceBundle *tagelement=NULL; 1925ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char *key=NULL; 1926ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar* value=NULL; 192754dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius tagelement=ures_getByIndex(tags, idx, tagelement, &status); 1928ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru key=ures_getKey(tagelement); 1929ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru value=(UChar*)ures_getNextString(tagelement, &len, &key, &status); 1930ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("tag = %s, value = %s\n", key, u_austrcpy(verboseOutput, value)); 1931ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(strncmp(key, "tag", 3) == 0 && u_strncmp(value, base, u_strlen(base)) == 0){ 1932ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru record_pass(); 1933ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }else{ 1934ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru record_fail(); 1935ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1936ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(tagelement); 1937ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1938ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }else{ 1939ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru tag_count=0; 1940ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1941ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1942ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*---------taggedArrayItem----------------------------------------------*/ 1943ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru count = 0; 194454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius for (idx=-20; idx<20; ++idx) 1945ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1946ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1947ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 1948ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru string = kERROR; 1949ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcpy(item_tag, "tag"); 195054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius strcat(item_tag, itoa1(idx,buf)); 1951ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru tags=ures_getByKey(theBundle, tag, tags, &status); 1952ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)){ 1953ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResourceBundle *tagelement=NULL; 1954ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar *t=NULL; 1955ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru tagelement=ures_getByKey(tags, item_tag, tagelement, &status); 1956ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(!U_FAILURE(status)){ 1957ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResType elementType=ures_getType(tagelement); 1958ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_INT_EQ(elementType, URES_STRING); 1959ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(strcmp(ures_getKey(tagelement), item_tag) == 0){ 1960ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru record_pass(); 1961ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }else{ 1962ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru record_fail(); 1963ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1964ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru t=(UChar*)tres_getString(tagelement, -1, NULL, &len, &status); 1965ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(!U_FAILURE(status)){ 1966ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru string=t; 1967ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1968ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 196954dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius if (idx < 0) { 1970ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_ErrorCode(status,U_MISSING_RESOURCE_ERROR); 1971ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1972ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else{ 1973ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (status != U_MISSING_RESOURCE_ERROR) { 1974ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar element[3]; 1975ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_strcpy(expected_string, base); 197654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius u_uastrcpy(element, itoa1(idx,buf)); 1977ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_strcat(expected_string, element); 1978ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_EQ(string,expected_string); 1979ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru count++; 1980ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1981ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1982ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(tagelement); 1983ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1984ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1985ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CONFIRM_INT_EQ(count, tag_count); 1986ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1987ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(expected_string); 1988ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(theBundle); 1989ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1990ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(array); 1991ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(array2d); 1992ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(tags); 1993ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(arrayItem1); 1994ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(base); 1995ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return (UBool)(failNum == fail); 1996ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 1997ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1998ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void record_pass() 1999ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 2000ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ++pass; 2001ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 2002ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2003ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void record_fail() 2004ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 2005ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ++fail; 2006ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 2007ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 200859d709d503bab6e2b61931737e662dd293b40578ccorneliusstatic void TestPreventFallback() { 200959d709d503bab6e2b61931737e662dd293b40578ccornelius UResourceBundle* theBundle = NULL; 201059d709d503bab6e2b61931737e662dd293b40578ccornelius const char* testdatapath; 201159d709d503bab6e2b61931737e662dd293b40578ccornelius UErrorCode status = U_ZERO_ERROR; 201259d709d503bab6e2b61931737e662dd293b40578ccornelius int32_t unused_len = 0; 201359d709d503bab6e2b61931737e662dd293b40578ccornelius 201459d709d503bab6e2b61931737e662dd293b40578ccornelius testdatapath=loadTestData(&status); 201559d709d503bab6e2b61931737e662dd293b40578ccornelius if(U_FAILURE(status)) 201659d709d503bab6e2b61931737e662dd293b40578ccornelius { 201759d709d503bab6e2b61931737e662dd293b40578ccornelius log_data_err("Could not load testdata.dat %s \n",myErrorName(status)); 201859d709d503bab6e2b61931737e662dd293b40578ccornelius return; 201959d709d503bab6e2b61931737e662dd293b40578ccornelius } 202059d709d503bab6e2b61931737e662dd293b40578ccornelius 202159d709d503bab6e2b61931737e662dd293b40578ccornelius // In te_IN locale, fallback of string_in_te_no_te_IN_fallback is blocked 202259d709d503bab6e2b61931737e662dd293b40578ccornelius // with the three empty-set (U+2205) chars. 202359d709d503bab6e2b61931737e662dd293b40578ccornelius theBundle = ures_open(testdatapath, "te_IN_NE", &status); 202459d709d503bab6e2b61931737e662dd293b40578ccornelius if(U_FAILURE(status)) 202559d709d503bab6e2b61931737e662dd293b40578ccornelius { 202659d709d503bab6e2b61931737e662dd293b40578ccornelius log_data_err("Could not open resource bundle te_IN_NE %s \n",myErrorName(status)); 202759d709d503bab6e2b61931737e662dd293b40578ccornelius return; 202859d709d503bab6e2b61931737e662dd293b40578ccornelius } 202959d709d503bab6e2b61931737e662dd293b40578ccornelius 203059d709d503bab6e2b61931737e662dd293b40578ccornelius // Fallback is blocked 203159d709d503bab6e2b61931737e662dd293b40578ccornelius ures_getStringByKeyWithFallback(theBundle, "string_in_te_no_te_IN_fallback", &unused_len, &status); 203259d709d503bab6e2b61931737e662dd293b40578ccornelius if (status != U_MISSING_RESOURCE_ERROR) 203359d709d503bab6e2b61931737e662dd293b40578ccornelius { 203459d709d503bab6e2b61931737e662dd293b40578ccornelius log_err("Expected missing resource error for string_in_te_no_te_IN_fallback."); 203559d709d503bab6e2b61931737e662dd293b40578ccornelius } 203659d709d503bab6e2b61931737e662dd293b40578ccornelius status = U_ZERO_ERROR; 203759d709d503bab6e2b61931737e662dd293b40578ccornelius 203859d709d503bab6e2b61931737e662dd293b40578ccornelius // This fallback should succeed 203959d709d503bab6e2b61931737e662dd293b40578ccornelius ures_getStringByKeyWithFallback(theBundle, "string_only_in_te", &unused_len, &status); 204059d709d503bab6e2b61931737e662dd293b40578ccornelius if(U_FAILURE(status)) 204159d709d503bab6e2b61931737e662dd293b40578ccornelius { 204259d709d503bab6e2b61931737e662dd293b40578ccornelius log_err("Expected to find string_only_in_te %s \n",myErrorName(status)); 204359d709d503bab6e2b61931737e662dd293b40578ccornelius } 204459d709d503bab6e2b61931737e662dd293b40578ccornelius status = U_ZERO_ERROR; 204559d709d503bab6e2b61931737e662dd293b40578ccornelius ures_close(theBundle); 204659d709d503bab6e2b61931737e662dd293b40578ccornelius 204759d709d503bab6e2b61931737e662dd293b40578ccornelius // From te locale, we should be able to fetch string_in_te_no_te_IN_fallback. 204859d709d503bab6e2b61931737e662dd293b40578ccornelius theBundle = ures_open(testdatapath, "te", &status); 204959d709d503bab6e2b61931737e662dd293b40578ccornelius if(U_FAILURE(status)) 205059d709d503bab6e2b61931737e662dd293b40578ccornelius { 205159d709d503bab6e2b61931737e662dd293b40578ccornelius log_data_err("Could not open resource bundle te_IN_NE %s \n",myErrorName(status)); 205259d709d503bab6e2b61931737e662dd293b40578ccornelius return; 205359d709d503bab6e2b61931737e662dd293b40578ccornelius } 205459d709d503bab6e2b61931737e662dd293b40578ccornelius ures_getStringByKeyWithFallback(theBundle, "string_in_te_no_te_IN_fallback", &unused_len, &status); 205559d709d503bab6e2b61931737e662dd293b40578ccornelius if(U_FAILURE(status)) 205659d709d503bab6e2b61931737e662dd293b40578ccornelius { 205759d709d503bab6e2b61931737e662dd293b40578ccornelius log_err("Expected to find string_in_te_no_te_IN_fallback %s \n",myErrorName(status)); 205859d709d503bab6e2b61931737e662dd293b40578ccornelius } 205959d709d503bab6e2b61931737e662dd293b40578ccornelius status = U_ZERO_ERROR; 206059d709d503bab6e2b61931737e662dd293b40578ccornelius ures_close(theBundle); 206159d709d503bab6e2b61931737e662dd293b40578ccornelius} 206259d709d503bab6e2b61931737e662dd293b40578ccornelius 2063ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 2064ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Test to make sure that the U_USING_FALLBACK_ERROR and U_USING_DEFAULT_ERROR 2065ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * are set correctly 2066ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 2067ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2068ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestFallback() 2069ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 2070ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 2071ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResourceBundle *fr_FR = NULL; 2072ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResourceBundle *subResource = NULL; 2073ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const UChar *junk; /* ignored */ 2074ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t resultLen; 2075ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2076ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Opening fr_FR.."); 2077ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru fr_FR = ures_open(NULL, "fr_FR", &status); 2078ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) 2079ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 208085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(status, "Couldn't open fr_FR - %s\n", u_errorName(status)); 2081ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 2082ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2083ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2084ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 2085ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2086ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2087ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* clear it out.. just do some calls to get the gears turning */ 2088ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru junk = tres_getString(fr_FR, -1, "LocaleID", &resultLen, &status); 2089ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 2090ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru junk = tres_getString(fr_FR, -1, "LocaleString", &resultLen, &status); 2091ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 2092ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru junk = tres_getString(fr_FR, -1, "LocaleID", &resultLen, &status); 2093ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 209459d709d503bab6e2b61931737e662dd293b40578ccornelius (void)junk; /* Suppress set but not used warning. */ 2095ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2096ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* OK first one. This should be a Default value. */ 209759d709d503bab6e2b61931737e662dd293b40578ccornelius subResource = ures_getByKey(fr_FR, "layout", NULL, &status); 2098ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(status != U_USING_DEFAULT_WARNING) 2099ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 210059d709d503bab6e2b61931737e662dd293b40578ccornelius log_data_err("Expected U_USING_DEFAULT_ERROR when trying to get layout from fr_FR, got %s\n", 2101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_errorName(status)); 2102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 2105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(subResource); 2106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* and this is a Fallback, to fr */ 210850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho junk = tres_getString(fr_FR, -1, "ExemplarCharacters", &resultLen, &status); 2109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(status != U_USING_FALLBACK_WARNING) 2110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 211150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_data_err("Expected U_USING_FALLBACK_ERROR when trying to get ExemplarCharacters from fr_FR, got %d\n", 2112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status); 2113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 2116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2117ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(fr_FR); 2118ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Temporary hack err actually should be U_USING_FALLBACK_ERROR */ 2119ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Test Jitterbug 552 fallback mechanism of aliased data */ 2120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 2121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode err =U_ZERO_ERROR; 2122ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResourceBundle* myResB = ures_open(NULL,"no_NO_NY",&err); 2123ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResourceBundle* resLocID = ures_getByKey(myResB, "Version", NULL, &err); 2124ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResourceBundle* tResB; 212550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UResourceBundle* zoneResource; 2126ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const UChar* version = NULL; 2127c14898b482f76ecab9026615e2e4c6fe78358bdcFredrik Roubert static const UChar versionStr[] = { 0x0032, 0x002E, 0x0031, 0x002E, 0x0031, 0x0039, 0x002E, 0x0031, 0x0034, 0x0000}; // 2.1.19.14 2128ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2129ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(err != U_ZERO_ERROR){ 2130ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_data_err("Expected U_ZERO_ERROR when trying to test no_NO_NY aliased to nn_NO for Version err=%s\n",u_errorName(err)); 2131ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 2132ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2133ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru version = tres_getString(resLocID, -1, NULL, &resultLen, &err); 2134ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(u_strcmp(version, versionStr) != 0){ 2135ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char x[100]; 2136ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char g[100]; 2137ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_austrcpy(x, versionStr); 2138ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_austrcpy(g, version); 2139ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_data_err("ures_getString(resLocID, &resultLen, &err) returned an unexpected version value. Expected '%s', but got '%s'\n", 2140ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru x, g); 2141ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 214250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho zoneResource = ures_open(U_ICUDATA_ZONE, "no_NO_NY", &err); 214350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho tResB = ures_getByKey(zoneResource, "zoneStrings", NULL, &err); 2144ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(err != U_USING_FALLBACK_WARNING){ 2145ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Expected U_USING_FALLBACK_ERROR when trying to test no_NO_NY aliased with nn_NO_NY for zoneStrings err=%s\n",u_errorName(err)); 2146ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 214750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho ures_close(tResB); 214850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho ures_close(zoneResource); 2149ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(resLocID); 2150ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(myResB); 2151ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2152ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2153ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 2154ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2155ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* static void printUChars(UChar* uchars){ 2156ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/ int16_t i=0; 2157ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/ for(i=0; i<u_strlen(uchars); i++){ 2158ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/ log_err("%04X ", *(uchars+i)); 2159ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/ } 2160ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/ } */ 2161ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2162ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestResourceLevelAliasing(void) { 2163ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 2164ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResourceBundle *aliasB = NULL, *tb = NULL; 2165ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResourceBundle *en = NULL, *uk = NULL, *testtypes = NULL; 2166ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* testdatapath = NULL; 2167ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const UChar *string = NULL, *sequence = NULL; 2168ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*const uint8_t *binary = NULL, *binSequence = NULL;*/ 2169ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t strLen = 0, seqLen = 0;/*, binLen = 0, binSeqLen = 0;*/ 2170ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char buffer[100]; 2171ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char *s; 2172ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2173ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru testdatapath=loadTestData(&status); 2174ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) 2175ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 217685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_data_err("Could not load testdata.dat %s \n",myErrorName(status)); 2177ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 2178ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2179ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2180ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru aliasB = ures_open(testdatapath, "testaliases", &status); 2181ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2182ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) 2183ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 218485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_data_err("Could not load testaliases.res %s \n",myErrorName(status)); 2185ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 2186ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2187ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* this should fail - circular alias */ 2188ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru tb = ures_getByKey(aliasB, "aaa", tb, &status); 2189ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(status != U_TOO_MANY_ALIASES_ERROR) { 2190ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Failed to detect circular alias\n"); 2191ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2192ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else { 2193ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 2194ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2195ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru tb = ures_getByKey(aliasB, "aab", tb, &status); 2196ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(status != U_TOO_MANY_ALIASES_ERROR) { 2197ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Failed to detect circular alias\n"); 2198ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 2199ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 2200ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2201ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status) ) { 2202ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_data_err("err loading tb resource\n"); 2203ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 2204ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* testing aliasing to a non existing resource */ 2205ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru tb = ures_getByKey(aliasB, "nonexisting", tb, &status); 2206ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(status != U_MISSING_RESOURCE_ERROR) { 2207ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Managed to find an alias to non-existing resource\n"); 2208ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 2209ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 2210ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2211ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* testing referencing/composed alias */ 22121b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert uk = ures_findResource("ja/calendar/gregorian/DateTimePatterns/2", uk, &status); 2213ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if((uk == NULL) || U_FAILURE(status)) { 22141b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert log_err_status(status, "Couldn't findResource('ja/calendar/gregorian/DateTimePatterns/2') err %s\n", u_errorName(status)); 2215ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru goto cleanup; 2216ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2217ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2218ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru sequence = tres_getString(uk, -1, NULL, &seqLen, &status); 2219ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2220ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru tb = ures_getByKey(aliasB, "referencingalias", tb, &status); 2221ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru string = tres_getString(tb, -1, NULL, &strLen, &status); 2222ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2223ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(seqLen != strLen || u_strncmp(sequence, string, seqLen) != 0) { 222450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("Referencing alias didn't get the right string (1)\n"); 2225ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2226ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2227ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru string = tres_getString(aliasB, -1, "referencingalias", &strLen, &status); 2228ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(seqLen != strLen || u_strncmp(sequence, string, seqLen) != 0) { 222950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("Referencing alias didn't get the right string (2)\n"); 2230ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2231ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2232ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru checkStatus(__LINE__, U_ZERO_ERROR, status); 22331b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert tb = ures_getByKey(aliasB, "DateTimePatterns", tb, &status); 2234ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru checkStatus(__LINE__, U_ZERO_ERROR, status); 2235ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru tb = ures_getByIndex(tb, 2, tb, &status); 2236ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru checkStatus(__LINE__, U_ZERO_ERROR, status); 2237ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru string = tres_getString(tb, -1, NULL, &strLen, &status); 2238ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru checkStatus(__LINE__, U_ZERO_ERROR, status); 2239ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2240ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 2241ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("%s trying to get string via separate getters\n", u_errorName(status)); 2242ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else if(seqLen != strLen || u_strncmp(sequence, string, seqLen) != 0) { 224350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("Referencing alias didn't get the right string (3)\n"); 2244ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2245ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2246ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* simple alias */ 2247ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru testtypes = ures_open(testdatapath, "testtypes", &status); 2248ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcpy(buffer, "menu/file/open"); 2249ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru s = buffer; 2250ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uk = ures_findSubResource(testtypes, s, uk, &status); 2251ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru sequence = tres_getString(uk, -1, NULL, &seqLen, &status); 2252ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2253ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru tb = ures_getByKey(aliasB, "simplealias", tb, &status); 2254ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru string = tres_getString(tb, -1, NULL, &strLen, &status); 2255ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2256ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status) || seqLen != strLen || u_strncmp(sequence, string, seqLen) != 0) { 225750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("Referencing alias didn't get the right string (4)\n"); 2258ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2259ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2260ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* test indexed aliasing */ 2261ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2262ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru tb = ures_getByKey(aliasB, "zoneTests", tb, &status); 2263ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru tb = ures_getByKey(tb, "zoneAlias2", tb, &status); 2264ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru string = tres_getString(tb, -1, NULL, &strLen, &status); 2265ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 226650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho en = ures_findResource("/ICUDATA-zone/en/zoneStrings/3/0", en, &status); 2267ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru sequence = tres_getString(en, -1, NULL, &seqLen, &status); 2268ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2269ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status) || seqLen != strLen || u_strncmp(sequence, string, seqLen) != 0) { 227050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("Referencing alias didn't get the right string (5)\n"); 2271ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2272ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2273ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* test getting aliased string by index */ 2274ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 2275ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* keys[] = { 2276ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "KeyAlias0PST", 2277ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "KeyAlias1PacificStandardTime", 2278ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "KeyAlias2PDT", 2279ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "KeyAlias3LosAngeles" 2280ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }; 2281ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2282ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* strings[] = { 2283ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "America/Los_Angeles", 2284ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "Pacific Standard Time", 2285ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "PDT", 2286ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "Los Angeles", 2287ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }; 2288ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar uBuffer[256]; 2289ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const UChar* result; 2290ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t uBufferLen = 0, resultLen = 0; 2291ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t i = 0; 2292ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char *key = NULL; 2293ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru tb = ures_getByKey(aliasB, "testGetStringByKeyAliasing", tb, &status); 2294ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 229550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("FAIL: Couldn't get testGetStringByKeyAliasing resource: %s\n", u_errorName(status)); 229650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } else { 229750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho for(i = 0; i < sizeof(strings)/sizeof(strings[0]); i++) { 229850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho result = tres_getString(tb, -1, keys[i], &resultLen, &status); 229950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if(U_FAILURE(status)){ 230050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("(1) Fetching the resource with key %s failed. Error: %s\n", keys[i], u_errorName(status)); 230150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho continue; 230250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 230350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uBufferLen = u_unescape(strings[i], uBuffer, 256); 230450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if(resultLen != uBufferLen || u_strncmp(result, uBuffer, resultLen) != 0) { 230550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("(1) Didn't get correct string while accessing alias table by key (%s)\n", keys[i]); 230650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 2307ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 230850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho for(i = 0; i < sizeof(strings)/sizeof(strings[0]); i++) { 230950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho result = tres_getString(tb, i, NULL, &resultLen, &status); 231050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if(U_FAILURE(status)){ 231150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("(2) Fetching the resource with key %s failed. Error: %s\n", keys[i], u_errorName(status)); 231250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho continue; 231350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 231450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uBufferLen = u_unescape(strings[i], uBuffer, 256); 231550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if(result==NULL || resultLen != uBufferLen || u_strncmp(result, uBuffer, resultLen) != 0) { 231650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("(2) Didn't get correct string while accesing alias table by index (%s)\n", strings[i]); 231750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 2318ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 231950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho for(i = 0; i < sizeof(strings)/sizeof(strings[0]); i++) { 232050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho result = ures_getNextString(tb, &resultLen, &key, &status); 232150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if(U_FAILURE(status)){ 232250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("(3) Fetching the resource with key %s failed. Error: %s\n", keys[i], u_errorName(status)); 232350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho continue; 232450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 232550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uBufferLen = u_unescape(strings[i], uBuffer, 256); 232650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if(result==NULL || resultLen != uBufferLen || u_strncmp(result, uBuffer, resultLen) != 0) { 232750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("(3) Didn't get correct string while iterating over alias table (%s)\n", strings[i]); 232850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 2329ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2330ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2331ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru tb = ures_getByKey(aliasB, "testGetStringByIndexAliasing", tb, &status); 2332ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 233350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("FAIL: Couldn't get testGetStringByIndexAliasing resource: %s\n", u_errorName(status)); 233450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } else { 233550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho for(i = 0; i < sizeof(strings)/sizeof(strings[0]); i++) { 233650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho result = tres_getString(tb, i, NULL, &resultLen, &status); 233750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if(U_FAILURE(status)){ 233850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("Fetching the resource with key %s failed. Error: %s\n", keys[i], u_errorName(status)); 233950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho continue; 234050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 234150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uBufferLen = u_unescape(strings[i], uBuffer, 256); 234250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if(result==NULL || resultLen != uBufferLen || u_strncmp(result, uBuffer, resultLen) != 0) { 234350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("Didn't get correct string while accesing alias by index in an array (%s)\n", strings[i]); 234450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 2345ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 234650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho for(i = 0; i < sizeof(strings)/sizeof(strings[0]); i++) { 234750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho result = ures_getNextString(tb, &resultLen, &key, &status); 234850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if(U_FAILURE(status)){ 234950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("Fetching the resource with key %s failed. Error: %s\n", keys[i], u_errorName(status)); 235050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho continue; 235150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 235250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uBufferLen = u_unescape(strings[i], uBuffer, 256); 235350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if(result==NULL || resultLen != uBufferLen || u_strncmp(result, uBuffer, resultLen) != 0) { 235450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("Didn't get correct string while iterating over aliases in an array (%s)\n", strings[i]); 235550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 2356ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2357ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2358ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2359ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru tb = ures_getByKey(aliasB, "testAliasToTree", tb, &status); 2360ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)){ 2361ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Fetching the resource with key \"testAliasToTree\" failed. Error: %s\n", u_errorName(status)); 236285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho goto cleanup; 2363ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2364ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (strcmp(ures_getKey(tb), "collations") != 0) { 2365ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ures_getKey(aliasB) unexpectedly returned %s instead of \"collations\"\n", ures_getKey(tb)); 2366ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2367ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querucleanup: 2368ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(aliasB); 2369ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(tb); 2370ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(en); 2371ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(uk); 2372ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(testtypes); 2373ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 2374ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2375ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestDirectAccess(void) { 2376ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 2377ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResourceBundle *t = NULL, *t2 = NULL; 2378ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* key = NULL; 2379ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2380ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char buffer[100]; 2381ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char *s; 2382ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*const char* testdatapath=loadTestData(&status); 2383ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)){ 2384ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Could not load testdata.dat %s \n",myErrorName(status)); 2385ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 2386ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }*/ 2387ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2388ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru t = ures_findResource("/testdata/te/zoneStrings/3/2", t, &status); 2389ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 239085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_data_err("Couldn't access indexed resource, error %s\n", u_errorName(status)); 2391ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 2392ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 2393ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru key = ures_getKey(t); 2394ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(key != NULL) { 2395ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Got a strange key, expected NULL, got %s\n", key); 2396ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2397ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2398ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru t = ures_findResource("en/calendar/gregorian/DateTimePatterns/3", t, &status); 2399ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 240085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_data_err("Couldn't access indexed resource, error %s\n", u_errorName(status)); 2401ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 2402ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 2403ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru key = ures_getKey(t); 2404ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(key != NULL) { 2405ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Got a strange key, expected NULL, got %s\n", key); 2406ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2407ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2408ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 24091b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert t = ures_findResource("ja/ExemplarCharacters", t, &status); 2410ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 241185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_data_err("Couldn't access keyed resource, error %s\n", u_errorName(status)); 2412ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 2413ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 2414ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru key = ures_getKey(t); 24151b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert if(strcmp(key, "ExemplarCharacters")!=0) { 24161b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert log_err("Got a strange key, expected 'ExemplarCharacters', got %s\n", key); 2417ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2418ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2419ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 242050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho t2 = ures_open(U_ICUDATA_LANG, "sr", &status); 2421ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 242285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(status, "Couldn't open 'sr' resource bundle, error %s\n", u_errorName(status)); 2423ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_data_err("No 'sr', no test - you have bigger problems than testing direct access. " 2424ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "You probably have no data! Aborting this test\n"); 2425ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2426ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2427ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)) { 2428ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcpy(buffer, "Languages/hr"); 2429ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru s = buffer; 2430ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru t = ures_findSubResource(t2, s, t, &status); 2431ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 2432ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Couldn't access keyed resource, error %s\n", u_errorName(status)); 2433ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 2434ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 2435ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru key = ures_getKey(t); 2436ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(strcmp(key, "hr")!=0) { 2437ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Got a strange key, expected 'hr', got %s\n", key); 2438ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2439ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2440ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2441ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2442ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru t = ures_findResource("root/calendar/islamic-civil/DateTime", t, &status); 2443ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)) { 244485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_data_err("This resource does not exist. How did it get here?\n"); 2445ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2446ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 2447ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2448ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* this one will freeze */ 2449ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru t = ures_findResource("root/calendar/islamic-civil/eras/abbreviated/0/mikimaus/pera", t, &status); 2450ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)) { 245185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_data_err("Second resource does not exist. How did it get here?\n"); 2452ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2453ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 2454ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2455ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(t2); 2456ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru t2 = ures_open(NULL, "he", &status); 2457ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru t2 = ures_getByKeyWithFallback(t2, "calendar", t2, &status); 2458ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru t2 = ures_getByKeyWithFallback(t2, "islamic-civil", t2, &status); 2459ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru t2 = ures_getByKeyWithFallback(t2, "DateTime", t2, &status); 2460ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)) { 2461ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("This resource does not exist. How did it get here?\n"); 2462ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2463ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 2464ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2465ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(t2); 2466ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru t2 = ures_open(NULL, "he", &status); 2467ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* George's fix */ 2468ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru t2 = ures_getByKeyWithFallback(t2, "calendar", t2, &status); 2469ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru t2 = ures_getByKeyWithFallback(t2, "islamic-civil", t2, &status); 2470ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru t2 = ures_getByKeyWithFallback(t2, "eras", t2, &status); 2471ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 247285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(status, "Didn't get Eras. I know they are there!\n"); 2473ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2474ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 2475ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2476ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(t2); 2477ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru t2 = ures_open(NULL, "root", &status); 2478ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru t2 = ures_getByKeyWithFallback(t2, "calendar", t2, &status); 2479ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru t2 = ures_getByKeyWithFallback(t2, "islamic-civil", t2, &status); 2480ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru t2 = ures_getByKeyWithFallback(t2, "DateTime", t2, &status); 2481ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)) { 2482ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("This resource does not exist. How did it get here?\n"); 2483ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2484ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 2485ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2486ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(t2); 2487ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(t); 2488ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 2489ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 24908393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Corneliusstatic void TestTicket9804(void) { 24918393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius UErrorCode status = U_ZERO_ERROR; 24928393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius UResourceBundle *t = NULL; 24938393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius t = ures_open(NULL, "he", &status); 24948393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius t = ures_getByKeyWithFallback(t, "calendar/islamic-civil/DateTime", t, &status); 24958393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius if(U_SUCCESS(status)) { 24968393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius log_err("This resource does not exist. How did it get here?\n"); 24978393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius } 24988393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius status = U_ZERO_ERROR; 24998393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius ures_close(t); 25008393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius t = ures_open(NULL, "he", &status); 25018393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius t = ures_getByKeyWithFallback(t, "calendar/islamic-civil/eras", t, &status); 25028393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius if(U_FAILURE(status)) { 25038393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius log_err_status(status, "Didn't get Eras. I know they are there!\n"); 25048393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius } else { 25058393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius const char *locale = ures_getLocaleByType(t, ULOC_ACTUAL_LOCALE, &status); 25068393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius if (uprv_strcmp("he", locale) != 0) { 25078393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius log_err("Eras should be in the 'he' locale, but was in: %s", locale); 25088393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius } 25098393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius } 25108393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius status = U_ZERO_ERROR; 25118393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius ures_close(t); 25128393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius} 25138393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius 2514ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestJB3763(void) { 2515ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Nasty bug prevented using parent as fill-in, since it would 2516ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * stomp the path information. 2517ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 2518ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResourceBundle *t = NULL; 2519ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 2520ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru t = ures_open(NULL, "sr_Latn", &status); 2521ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru t = ures_getByKeyWithFallback(t, "calendar", t, &status); 2522ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru t = ures_getByKeyWithFallback(t, "gregorian", t, &status); 2523ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru t = ures_getByKeyWithFallback(t, "AmPmMarkers", t, &status); 2524ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 252585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(status, "This resource should be available?\n"); 2526ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2527ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 2528ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2529ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(t); 2530ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2531ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 2532ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2533ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestGetKeywordValues(void) { 2534ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UEnumeration *kwVals; 2535ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UBool foundStandard = FALSE; 2536ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 2537ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char *kw; 2538ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_COLLATION 2539ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru kwVals = ures_getKeywordValues( U_ICUDATA_COLL, "collations", &status); 2540ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2541ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Testing getting collation keyword values:\n"); 2542ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2543ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru while((kw=uenum_next(kwVals, NULL, &status))) { 2544ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose(" %s\n", kw); 2545ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(!strcmp(kw,"standard")) { 2546ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(foundStandard == FALSE) { 2547ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru foundStandard = TRUE; 2548ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 2549ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("'standard' was found twice in the keyword list.\n"); 2550ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2551ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2552ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2553ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(foundStandard == FALSE) { 255485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(status, "'standard' was not found in the keyword list.\n"); 2555ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2556ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uenum_close(kwVals); 2557ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 255885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(status, "err %s getting collation values\n", u_errorName(status)); 2559ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2560ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 2561ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif 2562ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru foundStandard = FALSE; 2563ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru kwVals = ures_getKeywordValues( "ICUDATA", "calendar", &status); 2564ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2565ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Testing getting calendar keyword values:\n"); 2566ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2567ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru while((kw=uenum_next(kwVals, NULL, &status))) { 2568ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose(" %s\n", kw); 2569ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(!strcmp(kw,"japanese")) { 2570ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(foundStandard == FALSE) { 2571ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru foundStandard = TRUE; 2572ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 2573ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("'japanese' was found twice in the calendar keyword list.\n"); 2574ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2575ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2576ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2577ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(foundStandard == FALSE) { 257885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(status, "'japanese' was not found in the calendar keyword list.\n"); 2579ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2580ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uenum_close(kwVals); 2581ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 258285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(status, "err %s getting calendar values\n", u_errorName(status)); 2583ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2584ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 2585ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2586ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestGetFunctionalEquivalentOf(const char *path, const char *resName, const char *keyword, UBool truncate, const char * const testCases[]) { 2587ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t i; 2588ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(i=0;testCases[i];i+=3) { 2589ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UBool expectAvail = (testCases[i][0]=='t')?TRUE:FALSE; 2590ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UBool gotAvail = FALSE; 2591ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char *inLocale = testCases[i+1]; 2592ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char *expectLocale = testCases[i+2]; 2593ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char equivLocale[256]; 2594ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t len; 2595ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 2596ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("%d: %c %s\texpect %s\n",i/3, expectAvail?'t':'f', inLocale, expectLocale); 2597ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru len = ures_getFunctionalEquivalent(equivLocale, 255, path, 2598ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru resName, keyword, inLocale, 2599ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru &gotAvail, truncate, &status); 2600ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status) || (len <= 0)) { 260185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(status, "FAIL: got len %d, err %s on #%d: %c\t%s\t%s\n", 2602ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru len, u_errorName(status), 2603ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru i/3,expectAvail?'t':'f', inLocale, expectLocale); 2604ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 2605ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("got: %c %s\n", expectAvail?'t':'f',equivLocale); 2606ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2607ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if((gotAvail != expectAvail) || strcmp(equivLocale, expectLocale)) { 2608ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: got avail=%c, loc=%s but expected #%d: %c\t%s\t-> loc=%s\n", 2609ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru gotAvail?'t':'f', equivLocale, 2610ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru i/3, 2611ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru expectAvail?'t':'f', inLocale, expectLocale); 2612ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2613ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2614ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2615ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2616ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 2617ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2618ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestGetFunctionalEquivalent(void) { 2619fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius#if !UCONFIG_NO_COLLATION 2620ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru static const char * const collCases[] = { 2621ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* avail locale equiv */ 262259d709d503bab6e2b61931737e662dd293b40578ccornelius "f", "sv_US_CALIFORNIA", "sv", 2623ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "f", "zh_TW@collation=stroke", "zh@collation=stroke", /* alias of zh_Hant_TW */ 2624fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius "f", "zh_Hant_TW@collation=stroke", "zh@collation=stroke", 262559d709d503bab6e2b61931737e662dd293b40578ccornelius "f", "sv_CN@collation=pinyin", "sv", 2626ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "t", "zh@collation=pinyin", "zh", 2627ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "f", "zh_CN@collation=pinyin", "zh", /* alias of zh_Hans_CN */ 2628fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius "f", "zh_Hans_CN@collation=pinyin", "zh", 2629ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "f", "zh_HK@collation=pinyin", "zh", /* alias of zh_Hant_HK */ 2630fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius "f", "zh_Hant_HK@collation=pinyin", "zh", 2631ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "f", "zh_HK@collation=stroke", "zh@collation=stroke", /* alias of zh_Hant_HK */ 2632fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius "f", "zh_Hant_HK@collation=stroke", "zh@collation=stroke", 2633ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "f", "zh_HK", "zh@collation=stroke", /* alias of zh_Hant_HK */ 2634fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius "f", "zh_Hant_HK", "zh@collation=stroke", 2635ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "f", "zh_MO", "zh@collation=stroke", /* alias of zh_Hant_MO */ 2636fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius "f", "zh_Hant_MO", "zh@collation=stroke", 2637ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "f", "zh_TW_STROKE", "zh@collation=stroke", 2638fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius "f", "zh_TW_STROKE@collation=pinyin", "zh", 263959d709d503bab6e2b61931737e662dd293b40578ccornelius "f", "sv_CN@calendar=japanese", "sv", 264059d709d503bab6e2b61931737e662dd293b40578ccornelius "t", "sv@calendar=japanese", "sv", 2641fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius "f", "zh_TW@collation=pinyin", "zh", /* alias of zh_Hant_TW */ 2642fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius "f", "zh_Hant_TW@collation=pinyin", "zh", 2643fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius "f", "zh_CN@collation=stroke", "zh@collation=stroke", /* alias of zh_Hans_CN */ 2644fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius "f", "zh_Hans_CN@collation=stroke", "zh@collation=stroke", 2645fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius "t", "de@collation=phonebook", "de@collation=phonebook", 2646ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "t", "hi@collation=standard", "hi", 2647ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "f", "hi_AU@collation=standard;currency=CHF;calendar=buddhist", "hi", 2648fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius "f", "sv_SE@collation=pinyin", "sv", /* bug 4582 tests */ 264959d709d503bab6e2b61931737e662dd293b40578ccornelius "f", "sv_SE_BONN@collation=pinyin", "sv", 2650ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "t", "nl", "root", 2651fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius "f", "nl_NL", "root", 2652ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "f", "nl_NL_EEXT", "root", 2653ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "t", "nl@collation=stroke", "root", 2654fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius "f", "nl_NL@collation=stroke", "root", 2655ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "f", "nl_NL_EEXT@collation=stroke", "root", 2656ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru NULL 2657ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }; 2658fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius#endif /* !UCONFIG_NO_COLLATION */ 2659ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2660ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru static const char *calCases[] = { 2661ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* avail locale equiv */ 2662b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho "t", "en_US_POSIX", "en@calendar=gregorian", 2663b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho "f", "ja_JP_TOKYO", "ja@calendar=gregorian", 2664ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "f", "ja_JP_TOKYO@calendar=japanese", "ja@calendar=japanese", 2665ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "t", "sr@calendar=gregorian", "sr@calendar=gregorian", 2666ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "t", "en", "en@calendar=gregorian", 2667ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru NULL 2668ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }; 2669ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2670ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_COLLATION 2671ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru TestGetFunctionalEquivalentOf(U_ICUDATA_COLL, "collations", "collation", TRUE, collCases); 2672ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif 2673ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru TestGetFunctionalEquivalentOf("ICUDATA", "calendar", "calendar", FALSE, calCases); 2674ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2675ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_COLLATION 2676ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Testing error conditions:\n"); 2677ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 2678ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char equivLocale[256] = "???"; 2679ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t len; 2680ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 2681ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UBool gotAvail = FALSE; 2682ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2683ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru len = ures_getFunctionalEquivalent(equivLocale, 255, U_ICUDATA_COLL, 2684ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "calendar", "calendar", "ar_EG@calendar=islamic", 2685ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru &gotAvail, FALSE, &status); 268659d709d503bab6e2b61931737e662dd293b40578ccornelius (void)len; /* Suppress set but not used warning. */ 2687ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2688ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(status == U_MISSING_RESOURCE_ERROR) { 2689ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("PASS: Got expected U_MISSING_RESOURCE_ERROR\n"); 2690ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 2691ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ures_getFunctionalEquivalent returned locale %s, avail %c, err %s, but expected U_MISSING_RESOURCE_ERROR \n", 2692ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru equivLocale, gotAvail?'t':'f', u_errorName(status)); 2693ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2694ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2695ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif 2696ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 2697ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2698ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestXPath(void) { 2699ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 2700ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResourceBundle *rb = NULL, *alias = NULL; 2701ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t len = 0; 2702ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const UChar* result = NULL; 2703ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const UChar expResult[] = { 0x0063, 0x006F, 0x0072, 0x0072, 0x0065, 0x0063, 0x0074, 0x0000 }; /* "correct" */ 2704ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*const UChar expResult[] = { 0x0074, 0x0065, 0x0069, 0x006E, 0x0064, 0x0065, 0x0073, 0x0074, 0x0000 }; *//*teindest*/ 2705ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2706ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char *testdatapath=loadTestData(&status); 2707ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) 2708ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 270985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_data_err("Could not load testdata.dat %s \n",myErrorName(status)); 2710ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 2711ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2712ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2713ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Testing ures_open()......\n"); 2714ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2715ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru rb = ures_open(testdatapath, "te_IN", &status); 2716ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 2717ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Could not open te_IN (%s)\n", myErrorName(status)); 2718ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 2719ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2720ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru alias = ures_getByKey(rb, "rootAliasClient", alias, &status); 2721ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 2722ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Couldn't find the aliased resource (%s)\n", myErrorName(status)); 2723ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(rb); 2724ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 2725ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2726ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2727ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru result = tres_getString(alias, -1, NULL, &len, &status); 2728ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status) || result == NULL || u_strcmp(result, expResult)) { 2729ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Couldn't get correct string value (%s)\n", myErrorName(status)); 2730ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2731ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2732ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru alias = ures_getByKey(rb, "aliasClient", alias, &status); 2733ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 2734ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Couldn't find the aliased resource (%s)\n", myErrorName(status)); 2735ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(rb); 2736ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 2737ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2738ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2739ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru result = tres_getString(alias, -1, NULL, &len, &status); 2740ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status) || result == NULL || u_strcmp(result, expResult)) { 2741ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Couldn't get correct string value (%s)\n", myErrorName(status)); 2742ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2743ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2744ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru alias = ures_getByKey(rb, "nestedRootAliasClient", alias, &status); 2745ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 2746ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Couldn't find the aliased resource (%s)\n", myErrorName(status)); 2747ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(rb); 2748ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 2749ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2750ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2751ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru result = tres_getString(alias, -1, NULL, &len, &status); 2752ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status) || result == NULL || u_strcmp(result, expResult)) { 2753ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Couldn't get correct string value (%s)\n", myErrorName(status)); 2754ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2755ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2756ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(alias); 2757ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(rb); 2758ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 2759ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestCLDRStyleAliases(void) { 2760ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 2761ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResourceBundle *rb = NULL, *alias = NULL, *a=NULL; 2762ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t i, len; 2763ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char resource[256]; 2764ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const UChar *result = NULL; 2765ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar expected[256]; 2766ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char *expects[7] = { "", "a41", "a12", "a03", "ar4" }; 2767ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char *testdatapath=loadTestData(&status); 2768ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 276985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_data_err("Could not load testdata.dat %s \n",myErrorName(status)); 2770ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 2771ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2772ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Testing CLDR style aliases......\n"); 2773ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2774ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru rb = ures_open(testdatapath, "te_IN_REVISED", &status); 2775ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 2776ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Could not open te_IN (%s)\n", myErrorName(status)); 2777ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 2778ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2779ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru alias = ures_getByKey(rb, "a", alias, &status); 2780ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 2781ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Couldn't find the aliased with name \"a\" resource (%s)\n", myErrorName(status)); 2782ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(rb); 2783ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 2784ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2785ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(i = 1; i < 5 ; i++) { 2786ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru resource[0]='a'; 2787ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru resource[1]='0'+i; 2788ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru resource[2]=0; 2789ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* instead of sprintf(resource, "a%i", i); */ 2790ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru a = ures_getByKeyWithFallback(alias, resource, a, &status); 2791ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru result = tres_getString(a, -1, NULL, &len, &status); 2792ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_charsToUChars(expects[i], expected, strlen(expects[i])+1); 2793ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status) || !result || u_strcmp(result, expected)) { 2794ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("CLDR style aliases failed resource with name \"%s\" resource, exp %s, got %S (%s)\n", resource, expects[i], result, myErrorName(status)); 2795ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 2796ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2797ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2798ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2799ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(a); 2800ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(alias); 2801ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(rb); 2802ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 2803ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2804ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestFallbackCodes(void) { 2805ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 2806ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char *testdatapath=loadTestData(&status); 2807ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2808ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResourceBundle *res = ures_open(testdatapath, "te_IN", &status); 2809ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2810ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResourceBundle *r = NULL, *fall = NULL; 2811ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2812ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru r = ures_getByKey(res, "tagged_array_in_Root_te_te_IN", r, &status); 2813ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2814ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 2815ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru fall = ures_getByKeyWithFallback(r, "tag2", fall, &status); 2816ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2817ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(status != U_ZERO_ERROR) { 281885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_data_err("Expected error code to be U_ZERO_ERROR, got %s\n", u_errorName(status)); 2819ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 2820ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2821ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2822ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru fall = ures_getByKeyWithFallback(r, "tag7", fall, &status); 2823ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2824ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(status != U_USING_FALLBACK_WARNING) { 282585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_data_err("Expected error code to be U_USING_FALLBACK_WARNING, got %s\n", u_errorName(status)); 2826ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2827ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 2828ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2829ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru fall = ures_getByKeyWithFallback(r, "tag1", fall, &status); 2830ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2831ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(status != U_USING_DEFAULT_WARNING) { 283285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_data_err("Expected error code to be U_USING_DEFAULT_WARNING, got %s\n", u_errorName(status)); 2833ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2834ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 2835ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2836ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(fall); 2837ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(r); 2838ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(res); 2839ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 2840ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2841ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* This test will crash if this doesn't work. Results don't need testing. */ 2842ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestStackReuse(void) { 2843ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResourceBundle table; 2844ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode errorCode = U_ZERO_ERROR; 2845ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResourceBundle *rb = ures_open(NULL, "en_US", &errorCode); 2846ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2847ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(errorCode)) { 284885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_data_err("Could not load en_US locale. status=%s\n",myErrorName(errorCode)); 2849ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 2850ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2851ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_initStackObject(&table); 2852ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_getByKeyWithFallback(rb, "Types", &table, &errorCode); 2853ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_getByKeyWithFallback(&table, "collation", &table, &errorCode); 2854ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(rb); 2855ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(&table); 2856ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 2857ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2858ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* Test ures_getUTF8StringXYZ() --------------------------------------------- */ 2859ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2860ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* 2861ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Replace most ures_getStringXYZ() with this function which wraps the 2862ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * desired call and also calls the UTF-8 variant and checks that it works. 2863ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 2864ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruextern const UChar * 2865ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querutres_getString(const UResourceBundle *resB, 286654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius int32_t idx, const char *key, 2867ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t *length, 2868ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode *status) { 2869ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char buffer8[16]; 2870ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char *p8; 2871ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const UChar *s16; 2872ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char *s8; 2873ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar32 c16, c8; 2874ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t length16, length8, i16, i8; 2875ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UBool forceCopy; 2876ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2877ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(length == NULL) { 2878ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru length = &length16; 2879ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 288054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius if(idx >= 0) { 288154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius s16 = ures_getStringByIndex(resB, idx, length, status); 2882ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else if(key != NULL) { 2883ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru s16 = ures_getStringByKey(resB, key, length, status); 2884ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 2885ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru s16 = ures_getString(resB, length, status); 2886ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2887ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(*status)) { 2888ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return s16; 2889ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2890ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru length16 = *length; 2891ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2892ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* try the UTF-8 variant of ures_getStringXYZ() */ 2893ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(forceCopy = FALSE; forceCopy <= TRUE; ++forceCopy) { 2894ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru p8 = buffer8; 2895ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru length8 = (int32_t)sizeof(buffer8); 289654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius if(idx >= 0) { 289754dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius s8 = ures_getUTF8StringByIndex(resB, idx, p8, &length8, forceCopy, status); 2898ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else if(key != NULL) { 2899ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru s8 = ures_getUTF8StringByKey(resB, key, p8, &length8, forceCopy, status); 2900ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 2901ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru s8 = ures_getUTF8String(resB, p8, &length8, forceCopy, status); 2902ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2903ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(*status == U_INVALID_CHAR_FOUND) { 2904ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* the UTF-16 string contains an unpaired surrogate, can't test UTF-8 variant */ 2905ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return s16; 2906ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2907ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(*status == U_BUFFER_OVERFLOW_ERROR) { 2908ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *status = U_ZERO_ERROR; 2909ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru p8 = (char *)malloc(++length8); 2910ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(p8 == NULL) { 2911ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return s16; 2912ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 291354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius if(idx >= 0) { 291454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius s8 = ures_getUTF8StringByIndex(resB, idx, p8, &length8, forceCopy, status); 2915ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else if(key != NULL) { 2916ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru s8 = ures_getUTF8StringByKey(resB, key, p8, &length8, forceCopy, status); 2917ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 2918ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru s8 = ures_getUTF8String(resB, p8, &length8, forceCopy, status); 2919ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2920ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2921ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(*status)) { 2922ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* something unexpected happened */ 2923ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(p8 != buffer8) { 2924ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(p8); 2925ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2926ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return s16; 2927ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2928ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2929ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(forceCopy && s8 != p8) { 2930ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ures_getUTF8String(%p, %ld, '%s') did not write the string to dest\n", 293154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius resB, (long)idx, key); 2932ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2933ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2934ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* verify NUL-termination */ 2935ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if((p8 != buffer8 || length8 < sizeof(buffer8)) && s8[length8] != 0) { 2936ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ures_getUTF8String(%p, %ld, '%s') did not NUL-terminate\n", 293754dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius resB, (long)idx, key); 2938ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2939ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* verify correct string */ 2940ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru i16 = i8 = 0; 2941ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru while(i16 < length16 && i8 < length8) { 2942ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru U16_NEXT(s16, i16, length16, c16); 2943ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru U8_NEXT(s8, i8, length8, c8); 2944ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(c16 != c8) { 2945ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ures_getUTF8String(%p, %ld, '%s') got a bad string, c16=U+%04lx!=U+%04lx=c8 before i16=%ld\n", 294654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius resB, (long)idx, key, (long)c16, (long)c8, (long)i16); 2947ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2948ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2949ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* verify correct length */ 2950ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(i16 < length16) { 2951ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ures_getUTF8String(%p, %ld, '%s') UTF-8 string too short, length8=%ld, length16=%ld\n", 295254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius resB, (long)idx, key, (long)length8, (long)length16); 2953ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2954ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(i8 < length8) { 2955ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ures_getUTF8String(%p, %ld, '%s') UTF-8 string too long, length8=%ld, length16=%ld\n", 295654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius resB, (long)idx, key, (long)length8, (long)length16); 2957ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2958ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2959ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* clean up */ 2960ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(p8 != buffer8) { 2961ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(p8); 2962ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2963ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2964ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return s16; 2965ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 2966ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2967ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* 2968ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * API tests for ures_getUTF8String(). 2969ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Most cases are handled by tres_getString(), which leaves argument checking 2970ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * to be tested here. 2971ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Since the variants share most of their implementation, we only need to test 2972ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * one of them. 2973ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * We also need not test for checking arguments which will be checked by the 2974ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * UTF-16 ures_getStringXYZ() that are called internally. 2975ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 2976ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void 2977ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruTestGetUTF8String() { 2978ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResourceBundle *res; 2979ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char *testdatapath; 2980ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char buffer8[16]; 2981ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char *s8; 2982ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t length8; 2983ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status; 2984ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2985ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 2986ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru testdatapath = loadTestData(&status); 2987ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 298885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_data_err("Could not load testdata.dat - %s\n", u_errorName(status)); 2989ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 2990ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2991ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2992ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru res = ures_open(testdatapath, "", &status); 2993ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 2994ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Unable to ures_open(testdata, \"\") - %s\n", u_errorName(status)); 2995ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 2996ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2997ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2998ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* one good call */ 2999ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 3000ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru length8 = (int32_t)sizeof(buffer8); 3001ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru s8 = ures_getUTF8StringByKey(res, "string_only_in_Root", buffer8, &length8, FALSE, &status); 300259d709d503bab6e2b61931737e662dd293b40578ccornelius (void)s8; /* Suppress set but not used warning. */ 3003ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(status != U_ZERO_ERROR) { 3004ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ures_getUTF8StringByKey(testdata/root string) malfunctioned - %s\n", u_errorName(status)); 3005ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 3006ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 3007ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* negative capacity */ 3008ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 3009ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru length8 = -1; 3010ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru s8 = ures_getUTF8StringByKey(res, "string_only_in_Root", buffer8, &length8, FALSE, &status); 3011ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(status != U_ILLEGAL_ARGUMENT_ERROR) { 3012ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ures_getUTF8StringByKey(capacity<0) malfunctioned - %s\n", u_errorName(status)); 3013ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 3014ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 3015ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* capacity>0 but dest=NULL */ 3016ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 3017ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru length8 = (int32_t)sizeof(buffer8); 3018ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru s8 = ures_getUTF8StringByKey(res, "string_only_in_Root", NULL, &length8, FALSE, &status); 3019ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(status != U_ILLEGAL_ARGUMENT_ERROR) { 3020ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ures_getUTF8StringByKey(dest=NULL capacity>0) malfunctioned - %s\n", u_errorName(status)); 3021ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 3022ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 3023ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(res); 3024ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 302585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 302650294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehostatic void TestCLDRVersion(void) { 302785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UVersionInfo zeroVersion; 302885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UVersionInfo testExpect; 302985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UVersionInfo testCurrent; 303085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UVersionInfo cldrVersion; 303185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho char tmp[200]; 303285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UErrorCode status = U_ZERO_ERROR; 303385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 303485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho /* setup the constant value */ 303585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho u_versionFromString(zeroVersion, "0.0.0.0"); 303685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 303785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho /* test CLDR value from API */ 303885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho ulocdata_getCLDRVersion(cldrVersion, &status); 303985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if(U_FAILURE(status)) { 304085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho /* the show is pretty much over at this point */ 304185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(status, "FAIL: ulocdata_getCLDRVersion() returned %s\n", u_errorName(status)); 304285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho return; 304385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } else { 304485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho u_versionToString(cldrVersion, tmp); 304585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_info("ulocdata_getCLDRVersion() returned: '%s'\n", tmp); 304685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 304785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 304885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 304985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho /* setup from resource bundle */ 305085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho { 305185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UResourceBundle *res; 305285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho const char *testdatapath; 305385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 305485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho status = U_ZERO_ERROR; 305585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho testdatapath = loadTestData(&status); 305685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if(U_FAILURE(status)) { 305785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_data_err("Could not load testdata.dat - %s\n", u_errorName(status)); 305885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho return; 305985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 306085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 306185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho res = ures_openDirect(testdatapath, "root", &status); 306285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if(U_FAILURE(status)) { 306385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err("Unable to ures_open(testdata, \"\") - %s\n", u_errorName(status 306485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho)); 306585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho return; 306685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 306785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho ures_getVersionByKey(res, "ExpectCLDRVersionAtLeast", testExpect, &status); 306885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho ures_getVersionByKey(res, "CurrentCLDRVersion", testCurrent, &status); 306985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho ures_close(res); 307085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if(U_FAILURE(status)) { 307185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err("Unable to get test data for CLDR version - %s\n", u_errorName(status)); 307285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 307385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 307485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if(U_FAILURE(status)) return; 307585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 307685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 307785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho u_versionToString(testExpect,tmp); 307885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_verbose("(data) ExpectCLDRVersionAtLeast { %s }\n", tmp); 307950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if(memcmp(cldrVersion, testExpect, sizeof(UVersionInfo)) < 0) { 308085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_data_err("CLDR version is too old, expect at least %s.", tmp); 308185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 308285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho u_versionToString(testCurrent,tmp); 308385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_verbose("(data) CurrentCLDRVersion { %s }\n", tmp); 308450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho switch(memcmp(cldrVersion, testCurrent, sizeof(UVersionInfo))) { 308585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho case 0: break; /* OK- current. */ 308685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho case -1: log_info("CLDR version is behind 'current' (for testdata/root.txt) %s. Some things may fail.\n", tmp); break; 308785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho case 1: log_info("CLDR version is ahead of 'current' (for testdata/root.txt) %s. Some things may fail.\n", tmp); break; 308885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 308985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 309085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho} 3091