2000-01-15 02:00:06 +00:00
|
|
|
/********************************************************************
|
|
|
|
* COPYRIGHT:
|
2014-01-10 19:20:16 +00:00
|
|
|
* Copyright (c) 1997-2014, International Business Machines Corporation and
|
2000-01-15 02:00:06 +00:00
|
|
|
* others. All Rights Reserved.
|
|
|
|
********************************************************************/
|
1999-08-16 21:50:52 +00:00
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/utypes.h"
|
1999-12-01 21:27:44 +00:00
|
|
|
|
|
|
|
#include "cstring.h"
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/unistr.h"
|
2002-03-20 01:10:04 +00:00
|
|
|
#include "unicode/uniset.h"
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/resbund.h"
|
1999-12-01 21:27:44 +00:00
|
|
|
#include "restest.h"
|
2002-07-12 21:42:24 +00:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <string.h>
|
2001-01-03 02:48:20 +00:00
|
|
|
#include <limits.h>
|
1999-12-01 21:27:44 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
//***************************************************************************************
|
|
|
|
|
2000-05-15 18:44:20 +00:00
|
|
|
static const UChar kErrorUChars[] = { 0x45, 0x52, 0x52, 0x4f, 0x52, 0 };
|
2000-05-23 22:02:38 +00:00
|
|
|
static const int32_t kErrorLength = 5;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
//***************************************************************************************
|
|
|
|
|
|
|
|
enum E_Where
|
|
|
|
{
|
2000-05-15 18:44:20 +00:00
|
|
|
e_Root,
|
1999-08-16 21:50:52 +00:00
|
|
|
e_te,
|
|
|
|
e_te_IN,
|
|
|
|
e_Where_count
|
|
|
|
};
|
|
|
|
|
|
|
|
//***************************************************************************************
|
|
|
|
|
2001-03-06 01:53:46 +00:00
|
|
|
#define CONFIRM_EQ(actual, expected, myAction) if ((expected)==(actual)) { record_pass(myAction); } else { record_fail(myAction + (UnicodeString)" returned " + (actual) + (UnicodeString)" instead of " + (expected) + "\n");}
|
|
|
|
#define CONFIRM_GE(actual, expected, myAction) if ((actual)>=(expected)) { record_pass(myAction); } else { record_fail(myAction + (UnicodeString)" returned " + (actual) + (UnicodeString)" instead of x >= " + (expected) + "\n");}
|
|
|
|
#define CONFIRM_NE(actual, expected, myAction) if ((expected)!=(actual)) { record_pass(myAction); } else { record_fail(myAction + (UnicodeString)" returned " + (actual) + (UnicodeString)" instead of x != " + (expected) + "\n");}
|
1999-09-03 22:08:47 +00:00
|
|
|
|
2001-03-06 01:53:46 +00:00
|
|
|
#define CONFIRM_UErrorCode(actual, expected, myAction) if ((expected)==(actual)) { record_pass(myAction); } else { record_fail(myAction + (UnicodeString)" returned " + u_errorName(actual) + " instead of " + u_errorName(expected) + "\n"); }
|
1999-12-08 23:31:17 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
//***************************************************************************************
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert an integer, positive or negative, to a character string radix 10.
|
|
|
|
*/
|
|
|
|
char*
|
|
|
|
itoa(int32_t i, char* buf)
|
|
|
|
{
|
|
|
|
char* result = buf;
|
|
|
|
|
|
|
|
// Handle negative
|
|
|
|
if (i < 0)
|
|
|
|
{
|
|
|
|
*buf++ = '-';
|
|
|
|
i = -i;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Output digits in reverse order
|
|
|
|
char* p = buf;
|
|
|
|
do
|
|
|
|
{
|
2000-08-14 21:42:36 +00:00
|
|
|
*p++ = (char)('0' + (i % 10));
|
1999-08-16 21:50:52 +00:00
|
|
|
i /= 10;
|
|
|
|
}
|
|
|
|
while (i);
|
|
|
|
*p-- = 0;
|
|
|
|
|
|
|
|
// Reverse the string
|
|
|
|
while (buf < p)
|
|
|
|
{
|
|
|
|
char c = *buf;
|
|
|
|
*buf++ = *p;
|
|
|
|
*p-- = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//***************************************************************************************
|
|
|
|
|
|
|
|
// Array of our test objects
|
|
|
|
|
2005-04-01 22:50:37 +00:00
|
|
|
static struct
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
const char* name;
|
|
|
|
Locale *locale;
|
|
|
|
UErrorCode expected_constructor_status;
|
|
|
|
E_Where where;
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool like[e_Where_count];
|
|
|
|
UBool inherits[e_Where_count];
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
param[] =
|
|
|
|
{
|
|
|
|
// "te" means test
|
|
|
|
// "IN" means inherits
|
|
|
|
// "NE" or "ne" means "does not exist"
|
|
|
|
|
2001-02-28 01:47:51 +00:00
|
|
|
{ "root", NULL, U_ZERO_ERROR, e_Root, { TRUE, FALSE, FALSE }, { TRUE, FALSE, FALSE } },
|
|
|
|
{ "te", NULL, U_ZERO_ERROR, e_te, { FALSE, TRUE, FALSE }, { TRUE, TRUE, FALSE } },
|
|
|
|
{ "te_IN", NULL, U_ZERO_ERROR, e_te_IN, { FALSE, FALSE, TRUE }, { TRUE, TRUE, TRUE } },
|
2002-08-21 19:09:33 +00:00
|
|
|
{ "te_NE", NULL, U_USING_FALLBACK_WARNING, e_te, { FALSE, TRUE, FALSE }, { TRUE, TRUE, FALSE } },
|
|
|
|
{ "te_IN_NE", NULL, U_USING_FALLBACK_WARNING, e_te_IN, { FALSE, FALSE, TRUE }, { TRUE, TRUE, TRUE } },
|
|
|
|
{ "ne", NULL, U_USING_DEFAULT_WARNING, e_Root, { TRUE, FALSE, FALSE }, { TRUE, FALSE, FALSE } }
|
1999-08-16 21:50:52 +00:00
|
|
|
};
|
|
|
|
|
2005-04-01 22:50:37 +00:00
|
|
|
static const int32_t bundles_count = sizeof(param) / sizeof(param[0]);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
//***************************************************************************************
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a random unsigned long l where 0N <= l <= ULONG_MAX.
|
|
|
|
*/
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
randul()
|
|
|
|
{
|
2000-05-18 22:08:39 +00:00
|
|
|
static UBool initialized = FALSE;
|
1999-08-16 21:50:52 +00:00
|
|
|
if (!initialized)
|
|
|
|
{
|
|
|
|
srand((unsigned)time(NULL));
|
|
|
|
initialized = TRUE;
|
|
|
|
}
|
|
|
|
// Assume rand has at least 12 bits of precision
|
2000-08-14 21:42:36 +00:00
|
|
|
uint32_t l = 0;
|
2000-08-16 01:28:16 +00:00
|
|
|
for (uint32_t i=0; i<sizeof(l); ++i)
|
2000-08-14 21:42:36 +00:00
|
|
|
((char*)&l)[i] = (char)((rand() & 0x0FF0) >> 4);
|
1999-08-16 21:50:52 +00:00
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a random double x where 0.0 <= x < 1.0.
|
|
|
|
*/
|
|
|
|
double
|
|
|
|
randd()
|
|
|
|
{
|
2001-01-03 02:48:20 +00:00
|
|
|
return (double)(randul() / ULONG_MAX);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a random integer i where 0 <= i < n.
|
|
|
|
*/
|
|
|
|
int32_t randi(int32_t n)
|
|
|
|
{
|
|
|
|
return (int32_t)(randd() * n);
|
|
|
|
}
|
|
|
|
|
|
|
|
//***************************************************************************************
|
|
|
|
|
2001-02-28 01:47:51 +00:00
|
|
|
/*
|
|
|
|
Don't use more than one of these at a time because of the Locale names
|
|
|
|
*/
|
1999-08-16 21:50:52 +00:00
|
|
|
ResourceBundleTest::ResourceBundleTest()
|
|
|
|
: pass(0),
|
2003-10-15 08:03:56 +00:00
|
|
|
fail(0)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-02-28 01:47:51 +00:00
|
|
|
if (param[5].locale == NULL) {
|
|
|
|
param[0].locale = new Locale("root");
|
|
|
|
param[1].locale = new Locale("te");
|
|
|
|
param[2].locale = new Locale("te", "IN");
|
|
|
|
param[3].locale = new Locale("te", "NE");
|
|
|
|
param[4].locale = new Locale("te", "IN", "NE");
|
|
|
|
param[5].locale = new Locale("ne");
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ResourceBundleTest::~ResourceBundleTest()
|
|
|
|
{
|
2001-02-28 01:47:51 +00:00
|
|
|
if (param[5].locale) {
|
|
|
|
int idx;
|
|
|
|
for (idx = 0; idx < (int)(sizeof(param)/sizeof(param[0])); idx++) {
|
|
|
|
delete param[idx].locale;
|
|
|
|
param[idx].locale = NULL;
|
|
|
|
}
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2000-08-23 19:11:16 +00:00
|
|
|
void ResourceBundleTest::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par*/ )
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
if (exec) logln("TestSuite ResourceBundleTest: ");
|
|
|
|
switch (index) {
|
2009-08-04 21:09:17 +00:00
|
|
|
#if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
|
1999-08-16 21:50:52 +00:00
|
|
|
case 0: name = "TestResourceBundles"; if (exec) TestResourceBundles(); break;
|
|
|
|
case 1: name = "TestConstruction"; if (exec) TestConstruction(); break;
|
2009-08-04 21:09:17 +00:00
|
|
|
case 2: name = "TestGetSize"; if (exec) TestGetSize(); break;
|
|
|
|
case 3: name = "TestGetLocaleByType"; if (exec) TestGetLocaleByType(); break;
|
|
|
|
#else
|
|
|
|
case 0: case 1: case 2: case 3: name = "skip"; break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
case 4: name = "TestExemplar"; if (exec) TestExemplar(); break;
|
1999-08-16 21:50:52 +00:00
|
|
|
default: name = ""; break; //needed to end loop
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//***************************************************************************************
|
|
|
|
|
|
|
|
void
|
|
|
|
ResourceBundleTest::TestResourceBundles()
|
|
|
|
{
|
2006-08-29 02:09:12 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2006-11-08 07:13:34 +00:00
|
|
|
|
2006-08-29 02:09:12 +00:00
|
|
|
loadTestData(status);
|
|
|
|
if(U_FAILURE(status))
|
|
|
|
{
|
2009-06-12 19:34:21 +00:00
|
|
|
dataerrln("Could not load testdata.dat %s " + UnicodeString(u_errorName(status)));
|
2006-08-29 02:09:12 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-11-08 07:13:34 +00:00
|
|
|
/* Make sure that users using te_IN for the default locale don't get test failures. */
|
|
|
|
Locale originalDefault;
|
2006-11-08 16:57:14 +00:00
|
|
|
if (Locale::getDefault() == Locale("te_IN")) {
|
|
|
|
Locale::setDefault(Locale("en_US"), status);
|
|
|
|
}
|
2006-11-08 07:13:34 +00:00
|
|
|
|
2000-05-15 18:44:20 +00:00
|
|
|
testTag("only_in_Root", TRUE, FALSE, FALSE);
|
1999-08-16 21:50:52 +00:00
|
|
|
testTag("only_in_te", FALSE, TRUE, FALSE);
|
|
|
|
testTag("only_in_te_IN", FALSE, FALSE, TRUE);
|
2000-05-15 18:44:20 +00:00
|
|
|
testTag("in_Root_te", TRUE, TRUE, FALSE);
|
|
|
|
testTag("in_Root_te_te_IN", TRUE, TRUE, TRUE);
|
|
|
|
testTag("in_Root_te_IN", TRUE, FALSE, TRUE);
|
1999-08-16 21:50:52 +00:00
|
|
|
testTag("in_te_te_IN", FALSE, TRUE, TRUE);
|
|
|
|
testTag("nonexistent", FALSE, FALSE, FALSE);
|
2002-03-28 18:26:25 +00:00
|
|
|
logln("Passed: %d\nFailed: %d", pass, fail);
|
2006-11-08 07:13:34 +00:00
|
|
|
|
|
|
|
/* Restore the default locale for the other tests. */
|
|
|
|
Locale::setDefault(originalDefault, status);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ResourceBundleTest::TestConstruction()
|
|
|
|
{
|
2006-11-08 07:13:34 +00:00
|
|
|
UErrorCode err = U_ZERO_ERROR;
|
|
|
|
Locale locale("te", "IN");
|
|
|
|
|
|
|
|
const char* testdatapath=loadTestData(err);
|
|
|
|
if(U_FAILURE(err))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2009-06-12 19:34:21 +00:00
|
|
|
dataerrln("Could not load testdata.dat " + UnicodeString(testdatapath) + ", " + UnicodeString(u_errorName(err)));
|
2006-11-08 07:13:34 +00:00
|
|
|
return;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2006-11-08 07:13:34 +00:00
|
|
|
/* Make sure that users using te_IN for the default locale don't get test failures. */
|
|
|
|
Locale originalDefault;
|
2006-11-08 16:57:14 +00:00
|
|
|
if (Locale::getDefault() == Locale("te_IN")) {
|
|
|
|
Locale::setDefault(Locale("en_US"), err);
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2006-11-08 07:13:34 +00:00
|
|
|
ResourceBundle test1((UnicodeString)testdatapath, err);
|
|
|
|
ResourceBundle test2(testdatapath, locale, err);
|
|
|
|
//ResourceBundle test1("c:\\icu\\icu\\source\\test\\testdata\\testdata", err);
|
|
|
|
//ResourceBundle test2("c:\\icu\\icu\\source\\test\\testdata\\testdata", locale, err);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2006-11-08 07:13:34 +00:00
|
|
|
UnicodeString result1(test1.getStringEx("string_in_Root_te_te_IN", err));
|
|
|
|
UnicodeString result2(test2.getStringEx("string_in_Root_te_te_IN", err));
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2006-11-08 07:13:34 +00:00
|
|
|
if (U_FAILURE(err)) {
|
|
|
|
errln("Something threw an error in TestConstruction()");
|
|
|
|
return;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2006-11-08 07:13:34 +00:00
|
|
|
logln("for string_in_Root_te_te_IN, default.txt had " + result1);
|
|
|
|
logln("for string_in_Root_te_te_IN, te_IN.txt had " + result2);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2006-11-08 07:13:34 +00:00
|
|
|
if (result1 != "ROOT" || result2 != "TE_IN")
|
|
|
|
errln("Construction test failed; run verbose for more information");
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2006-11-08 07:13:34 +00:00
|
|
|
const char* version1;
|
|
|
|
const char* version2;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2006-11-08 07:13:34 +00:00
|
|
|
version1 = test1.getVersionNumber();
|
|
|
|
version2 = test2.getVersionNumber();
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2006-11-08 07:13:34 +00:00
|
|
|
char *versionID1 = new char[1+strlen(version1)]; // + 1 for zero byte
|
|
|
|
char *versionID2 = new char[1+ strlen(version2)]; // + 1 for zero byte
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2006-11-08 07:13:34 +00:00
|
|
|
strcpy(versionID1, "44.0"); // hardcoded, please change if the default.txt file or ResourceBundle::kVersionSeparater is changed.
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2006-11-08 07:13:34 +00:00
|
|
|
strcpy(versionID2, "55.0"); // hardcoded, please change if the te_IN.txt file or ResourceBundle::kVersionSeparater is changed.
|
2000-06-29 19:42:17 +00:00
|
|
|
|
2006-11-08 07:13:34 +00:00
|
|
|
logln(UnicodeString("getVersionNumber on default.txt returned ") + version1);
|
|
|
|
logln(UnicodeString("getVersionNumber on te_IN.txt returned ") + version2);
|
|
|
|
|
|
|
|
if (strcmp(version1, versionID1) != 0 || strcmp(version2, versionID2) != 0)
|
|
|
|
errln("getVersionNumber() failed");
|
|
|
|
|
|
|
|
delete[] versionID1;
|
|
|
|
delete[] versionID2;
|
|
|
|
|
|
|
|
/* Restore the default locale for the other tests. */
|
|
|
|
Locale::setDefault(originalDefault, err);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//***************************************************************************************
|
|
|
|
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool
|
1999-08-16 21:50:52 +00:00
|
|
|
ResourceBundleTest::testTag(const char* frag,
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool in_Root,
|
|
|
|
UBool in_te,
|
|
|
|
UBool in_te_IN)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-03-28 18:35:11 +00:00
|
|
|
int32_t failOrig = fail;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
// Make array from input params
|
|
|
|
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool is_in[] = { in_Root, in_te, in_te_IN };
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-05-15 18:44:20 +00:00
|
|
|
const char* NAME[] = { "ROOT", "TE", "TE_IN" };
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
// Now try to load the desired items
|
|
|
|
|
1999-12-01 21:27:44 +00:00
|
|
|
char tag[100];
|
1999-08-16 21:50:52 +00:00
|
|
|
UnicodeString action;
|
|
|
|
|
2001-03-06 01:53:46 +00:00
|
|
|
int32_t i,j,actual_bundle;
|
|
|
|
// int32_t row,col;
|
1999-08-16 21:50:52 +00:00
|
|
|
int32_t index;
|
2002-01-29 03:56:11 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2002-02-07 19:37:34 +00:00
|
|
|
const char* testdatapath;
|
|
|
|
testdatapath=loadTestData(status);
|
2002-01-29 03:56:11 +00:00
|
|
|
if(U_FAILURE(status))
|
|
|
|
{
|
2009-06-12 19:34:21 +00:00
|
|
|
dataerrln("Could not load testdata.dat %s " + UnicodeString(u_errorName(status)));
|
2002-01-29 03:56:11 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-03-06 01:53:46 +00:00
|
|
|
for (i=0; i<bundles_count; ++i)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
action = "Constructor for ";
|
|
|
|
action += param[i].name;
|
|
|
|
|
2002-01-29 03:56:11 +00:00
|
|
|
status = U_ZERO_ERROR;
|
2000-05-15 18:44:20 +00:00
|
|
|
ResourceBundle theBundle( testdatapath, *param[i].locale, status);
|
|
|
|
//ResourceBundle theBundle( "c:\\icu\\icu\\source\\test\\testdata\\testdata", *param[i].locale, status);
|
2001-03-06 01:53:46 +00:00
|
|
|
CONFIRM_UErrorCode(status, param[i].expected_constructor_status, action);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
1999-12-01 21:27:44 +00:00
|
|
|
if(i == 5)
|
|
|
|
actual_bundle = 0; /* ne -> default */
|
|
|
|
else if(i == 3)
|
|
|
|
actual_bundle = 1; /* te_NE -> te */
|
|
|
|
else if(i == 4)
|
|
|
|
actual_bundle = 2; /* te_IN_NE -> te_IN */
|
|
|
|
else
|
|
|
|
actual_bundle = i;
|
1999-09-03 22:08:47 +00:00
|
|
|
|
|
|
|
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode expected_resource_status = U_MISSING_RESOURCE_ERROR;
|
2000-05-15 18:44:20 +00:00
|
|
|
for (j=e_te_IN; j>=e_Root; --j)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
if (is_in[j] && param[i].inherits[j])
|
2001-03-06 01:53:46 +00:00
|
|
|
{
|
1999-12-01 21:27:44 +00:00
|
|
|
if(j == actual_bundle) /* it's in the same bundle OR it's a nonexistent=default bundle (5) */
|
|
|
|
expected_resource_status = U_ZERO_ERROR;
|
|
|
|
else if(j == 0)
|
2002-08-21 19:09:33 +00:00
|
|
|
expected_resource_status = U_USING_DEFAULT_WARNING;
|
1999-12-01 21:27:44 +00:00
|
|
|
else
|
2002-08-21 19:09:33 +00:00
|
|
|
expected_resource_status = U_USING_FALLBACK_WARNING;
|
1999-12-01 21:27:44 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UErrorCode expected_status;
|
|
|
|
|
|
|
|
UnicodeString base;
|
|
|
|
for (j=param[i].where; j>=0; --j)
|
|
|
|
{
|
|
|
|
if (is_in[j])
|
|
|
|
{
|
|
|
|
base = NAME[j];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
// string
|
|
|
|
|
2000-05-15 18:44:20 +00:00
|
|
|
uprv_strcpy(tag, "string_");
|
|
|
|
uprv_strcat(tag, frag);
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
action = param[i].name;
|
|
|
|
action += ".getString(";
|
|
|
|
action += tag;
|
|
|
|
action += ")";
|
|
|
|
|
|
|
|
|
1999-10-07 00:07:53 +00:00
|
|
|
status = U_ZERO_ERROR;
|
2000-05-15 18:44:20 +00:00
|
|
|
|
2001-03-06 01:53:46 +00:00
|
|
|
UnicodeString string(theBundle.getStringEx(tag, status));
|
2000-05-15 18:44:20 +00:00
|
|
|
|
|
|
|
if(U_FAILURE(status)) {
|
|
|
|
string.setTo(TRUE, kErrorUChars, kErrorLength);
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-03-06 01:53:46 +00:00
|
|
|
CONFIRM_UErrorCode(status, expected_resource_status, action);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-07-11 21:03:51 +00:00
|
|
|
UnicodeString expected_string(kErrorUChars);
|
|
|
|
if (U_SUCCESS(status)) {
|
|
|
|
expected_string = base;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-03-06 01:53:46 +00:00
|
|
|
CONFIRM_EQ(string, expected_string, action);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
// array
|
|
|
|
|
2000-05-15 18:44:20 +00:00
|
|
|
uprv_strcpy(tag, "array_");
|
|
|
|
uprv_strcat(tag, frag);
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
action = param[i].name;
|
2001-03-06 01:53:46 +00:00
|
|
|
action += ".get(";
|
1999-08-16 21:50:52 +00:00
|
|
|
action += tag;
|
|
|
|
action += ")";
|
|
|
|
|
1999-10-07 00:07:53 +00:00
|
|
|
status = U_ZERO_ERROR;
|
2001-03-06 01:53:46 +00:00
|
|
|
ResourceBundle arrayBundle(theBundle.get(tag, status));
|
|
|
|
CONFIRM_UErrorCode(status, expected_resource_status, action);
|
|
|
|
int32_t count = arrayBundle.getSize();
|
1999-08-16 21:50:52 +00:00
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_SUCCESS(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-03-06 01:53:46 +00:00
|
|
|
CONFIRM_GE(count, 1, action);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-03-06 01:53:46 +00:00
|
|
|
for (j=0; j < count; ++j)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
char buf[32];
|
2001-03-06 01:53:46 +00:00
|
|
|
UnicodeString value(arrayBundle.getStringEx(j, status));
|
1999-08-16 21:50:52 +00:00
|
|
|
expected_string = base;
|
|
|
|
expected_string += itoa(j,buf);
|
2001-03-06 01:53:46 +00:00
|
|
|
CONFIRM_EQ(value, expected_string, action);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-03-06 01:53:46 +00:00
|
|
|
action = param[i].name;
|
|
|
|
action += ".getStringEx(";
|
|
|
|
action += tag;
|
|
|
|
action += ")";
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-03-06 01:53:46 +00:00
|
|
|
for (j=0; j<100; ++j)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-03-06 01:53:46 +00:00
|
|
|
index = count ? (randi(count * 3) - count) : (randi(200) - 100);
|
|
|
|
status = U_ZERO_ERROR;
|
2001-07-11 21:03:51 +00:00
|
|
|
string = kErrorUChars;
|
2001-03-06 01:53:46 +00:00
|
|
|
UnicodeString t(arrayBundle.getStringEx(index, status));
|
|
|
|
expected_status = (index >= 0 && index < count) ? expected_resource_status : U_MISSING_RESOURCE_ERROR;
|
|
|
|
CONFIRM_UErrorCode(status, expected_status, action);
|
|
|
|
|
|
|
|
if (U_SUCCESS(status))
|
|
|
|
{
|
|
|
|
char buf[32];
|
|
|
|
expected_string = base;
|
|
|
|
expected_string += itoa(index,buf);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-07-11 21:03:51 +00:00
|
|
|
expected_string = kErrorUChars;
|
2001-03-06 01:53:46 +00:00
|
|
|
}
|
|
|
|
CONFIRM_EQ(string, expected_string, action);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2001-03-06 01:53:46 +00:00
|
|
|
}
|
|
|
|
else if (status != expected_resource_status)
|
|
|
|
{
|
|
|
|
record_fail("Error getting " + (UnicodeString)tag);
|
|
|
|
return (UBool)(failOrig != fail);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2001-03-06 01:53:46 +00:00
|
|
|
|
2000-12-11 18:12:30 +00:00
|
|
|
return (UBool)(failOrig != fail);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-03-06 01:53:46 +00:00
|
|
|
ResourceBundleTest::record_pass(UnicodeString passMessage)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-03-06 01:53:46 +00:00
|
|
|
logln(passMessage);
|
|
|
|
++pass;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
void
|
2001-03-06 01:53:46 +00:00
|
|
|
ResourceBundleTest::record_fail(UnicodeString errMessage)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-03-06 01:53:46 +00:00
|
|
|
err(errMessage);
|
|
|
|
++fail;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2002-03-20 01:10:04 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
ResourceBundleTest::TestExemplar(){
|
|
|
|
|
|
|
|
int32_t locCount = uloc_countAvailable();
|
|
|
|
int32_t locIndex=0;
|
|
|
|
int num=0;
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
for(;locIndex<locCount;locIndex++){
|
|
|
|
const char* locale = uloc_getAvailable(locIndex);
|
|
|
|
UResourceBundle *resb =ures_open(NULL,locale,&status);
|
|
|
|
if(U_SUCCESS(status) && status!=U_USING_FALLBACK_WARNING && status!=U_USING_DEFAULT_WARNING){
|
|
|
|
int32_t len=0;
|
|
|
|
const UChar* strSet = ures_getStringByKey(resb,"ExemplarCharacters",&len,&status);
|
|
|
|
UnicodeSet set(strSet,status);
|
|
|
|
if(U_FAILURE(status)){
|
|
|
|
errln("Could not construct UnicodeSet from pattern for ExemplarCharacters in locale : %s. Error: %s",locale,u_errorName(status));
|
|
|
|
status=U_ZERO_ERROR;
|
|
|
|
}
|
|
|
|
num++;
|
|
|
|
}
|
|
|
|
ures_close(resb);
|
|
|
|
}
|
|
|
|
logln("Number of installed locales with exemplar characters that could be tested: %d",num);
|
|
|
|
|
|
|
|
}
|
2003-11-07 08:43:01 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
ResourceBundleTest::TestGetSize(void)
|
|
|
|
{
|
2003-11-27 01:37:21 +00:00
|
|
|
const struct {
|
|
|
|
const char* key;
|
|
|
|
int32_t size;
|
|
|
|
} test[] = {
|
|
|
|
{ "zerotest", 1},
|
|
|
|
{ "one", 1},
|
|
|
|
{ "importtest", 1},
|
|
|
|
{ "integerarray", 1},
|
|
|
|
{ "emptyarray", 0},
|
|
|
|
{ "emptytable", 0},
|
|
|
|
{ "emptystring", 1}, /* empty string is still a string */
|
|
|
|
{ "emptyint", 1},
|
|
|
|
{ "emptybin", 1},
|
|
|
|
{ "testinclude", 1},
|
|
|
|
{ "collations", 1}, /* not 2 - there is hidden %%CollationBin */
|
|
|
|
};
|
|
|
|
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
|
|
|
|
const char* testdatapath = loadTestData(status);
|
|
|
|
int32_t i = 0, j = 0;
|
|
|
|
int32_t size = 0;
|
|
|
|
|
2003-11-07 08:43:01 +00:00
|
|
|
if(U_FAILURE(status))
|
|
|
|
{
|
2009-06-12 19:34:21 +00:00
|
|
|
dataerrln("Could not load testdata.dat %s\n", u_errorName(status));
|
2003-11-07 08:43:01 +00:00
|
|
|
return;
|
|
|
|
}
|
2003-11-27 01:37:21 +00:00
|
|
|
|
|
|
|
ResourceBundle rb(testdatapath, "testtypes", status);
|
|
|
|
if(U_FAILURE(status))
|
|
|
|
{
|
|
|
|
err("Could not testtypes resource bundle %s\n", u_errorName(status));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i = 0; i < (int32_t)(sizeof(test)/sizeof(test[0])); i++) {
|
|
|
|
ResourceBundle res = rb.get(test[i].key, status);
|
|
|
|
if(U_FAILURE(status))
|
|
|
|
{
|
|
|
|
err("Couldn't find the key %s. Error: %s\n", u_errorName(status));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
size = res.getSize();
|
|
|
|
if(size != test[i].size) {
|
|
|
|
err("Expected size %i, got size %i for key %s\n", test[i].size, size, test[i].key);
|
|
|
|
for(j = 0; j < size; j++) {
|
|
|
|
ResourceBundle helper = res.get(j, status);
|
|
|
|
err("%s\n", helper.getKey());
|
|
|
|
}
|
|
|
|
}
|
2003-11-07 08:43:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ResourceBundleTest::TestGetLocaleByType(void)
|
|
|
|
{
|
2003-11-27 01:37:21 +00:00
|
|
|
const struct {
|
|
|
|
const char *requestedLocale;
|
|
|
|
const char *resourceKey;
|
|
|
|
const char *validLocale;
|
|
|
|
const char *actualLocale;
|
|
|
|
} test[] = {
|
|
|
|
{ "te_IN_BLAH", "string_only_in_te_IN", "te_IN", "te_IN" },
|
|
|
|
{ "te_IN_BLAH", "string_only_in_te", "te_IN", "te" },
|
|
|
|
{ "te_IN_BLAH", "string_only_in_Root", "te_IN", "root" },
|
|
|
|
{ "te_IN_BLAH_01234567890_01234567890_01234567890_01234567890_01234567890_01234567890", "array_2d_only_in_Root", "te_IN", "root" },
|
|
|
|
{ "te_IN_BLAH@currency=euro", "array_2d_only_in_te_IN", "te_IN", "te_IN" },
|
|
|
|
{ "te_IN_BLAH@calendar=thai;collation=phonebook", "array_2d_only_in_te", "te_IN", "te" }
|
|
|
|
};
|
|
|
|
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
|
|
|
|
const char* testdatapath = loadTestData(status);
|
|
|
|
int32_t i = 0;
|
|
|
|
Locale locale;
|
|
|
|
|
2003-11-07 08:43:01 +00:00
|
|
|
if(U_FAILURE(status))
|
|
|
|
{
|
2009-06-12 19:34:21 +00:00
|
|
|
dataerrln("Could not load testdata.dat %s\n", u_errorName(status));
|
2003-11-27 01:37:21 +00:00
|
|
|
return;
|
2003-11-07 08:43:01 +00:00
|
|
|
}
|
2003-11-27 01:37:21 +00:00
|
|
|
|
|
|
|
for(i = 0; i < (int32_t)(sizeof(test)/sizeof(test[0])); i++) {
|
|
|
|
ResourceBundle rb(testdatapath, test[i].requestedLocale, status);
|
|
|
|
if(U_FAILURE(status))
|
|
|
|
{
|
|
|
|
err("Could not open resource bundle %s (error %s)\n", test[i].requestedLocale, u_errorName(status));
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
ResourceBundle res = rb.get(test[i].resourceKey, status);
|
|
|
|
if(U_FAILURE(status))
|
|
|
|
{
|
|
|
|
err("Couldn't find the key %s. Error: %s\n", test[i].resourceKey, u_errorName(status));
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
continue;
|
|
|
|
}
|
2014-08-27 21:27:37 +00:00
|
|
|
|
2003-11-27 01:37:21 +00:00
|
|
|
locale = res.getLocale(ULOC_REQUESTED_LOCALE, status);
|
2014-08-27 21:27:37 +00:00
|
|
|
if(U_SUCCESS(status) && locale != Locale::getDefault()) {
|
2003-11-27 01:37:21 +00:00
|
|
|
err("Expected requested locale to be %s. Got %s\n", test[i].requestedLocale, locale.getName());
|
|
|
|
}
|
2014-08-27 21:27:37 +00:00
|
|
|
status = U_ZERO_ERROR;
|
2003-11-27 01:37:21 +00:00
|
|
|
locale = res.getLocale(ULOC_VALID_LOCALE, status);
|
|
|
|
if(strcmp(locale.getName(), test[i].validLocale) != 0) {
|
|
|
|
err("Expected valid locale to be %s. Got %s\n", test[i].requestedLocale, locale.getName());
|
|
|
|
}
|
|
|
|
locale = res.getLocale(ULOC_ACTUAL_LOCALE, status);
|
|
|
|
if(strcmp(locale.getName(), test[i].actualLocale) != 0) {
|
|
|
|
err("Expected actual locale to be %s. Got %s\n", test[i].requestedLocale, locale.getName());
|
|
|
|
}
|
2003-11-07 08:43:01 +00:00
|
|
|
}
|
|
|
|
}
|