mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-18 11:14:22 +00:00
ICU-2329 do not use invariant-character conversion for strings with variant characters
X-SVN-Rev: 12585
This commit is contained in:
parent
b1d2d830bd
commit
84bd0babfa
5 changed files with 65 additions and 53 deletions
|
@ -227,7 +227,6 @@ void TestCzechMonths459()
|
|||
UCalendar *cal;
|
||||
UDate june, july, d;
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
char buffer[512];
|
||||
UChar *date;
|
||||
|
||||
fmt = udat_open(UDAT_FULL, UDAT_FULL, "cs", NULL, 0, NULL, 0, &status);
|
||||
|
@ -263,19 +262,17 @@ void TestCzechMonths459()
|
|||
}
|
||||
d = udat_parse(fmt, juneStr, u_strlen(juneStr), &pos, &status);
|
||||
date = myDateFormat(fmt, d);
|
||||
u_UCharsToChars(date, buffer, (int32_t)(u_strlen(date)+1));
|
||||
if(u_strcmp(myDateFormat(fmt, june), myDateFormat(fmt, d) ) !=0)
|
||||
log_err("Error in handling the czech month june\n");
|
||||
else
|
||||
log_verbose("Pass: Date = %s\n", buffer );
|
||||
log_verbose("Pass: Date = %s\n", aescstrdup(fmt, -1));
|
||||
pos=0;
|
||||
d = udat_parse(fmt, julyStr, u_strlen(julyStr), &pos, &status);
|
||||
date = myDateFormat(fmt, d);
|
||||
u_UCharsToChars(date, buffer, (int32_t)(u_strlen(date)+1));
|
||||
if(u_strcmp(myDateFormat(fmt, july), myDateFormat(fmt, d) ) !=0)
|
||||
log_err("Error in handling the czech month july\n");
|
||||
else
|
||||
log_verbose("Pass: Date = %s\n", buffer );
|
||||
log_verbose("Pass: Date = %s\n", aescstrdup(date, -1));
|
||||
|
||||
udat_close(fmt);
|
||||
ucal_close(cal);
|
||||
|
|
|
@ -404,17 +404,17 @@ static void TestCurrencySign(void)
|
|||
static void TestCurrency(void)
|
||||
{
|
||||
UNumberFormat *currencyFmt;
|
||||
UChar *str=NULL, *res=NULL;
|
||||
UChar *str;
|
||||
int32_t lneed, i;
|
||||
UFieldPosition pos;
|
||||
char cStr[100];
|
||||
UChar res[100];
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
const char* locale[]={"fr_CA", "de_DE_PREEURO", "fr_FR_PREEURO"};
|
||||
const char* result[]={"1,50 $", "1,50 DM", "1,50 F"};
|
||||
log_verbose("\nTesting the number format with different currency patterns\n");
|
||||
for(i=0; i < 3; i++)
|
||||
{
|
||||
cStr[0]=0;
|
||||
str=NULL;
|
||||
currencyFmt = unum_open(UNUM_CURRENCY, NULL,0,locale[i],NULL, &status);
|
||||
if(U_FAILURE(status)){
|
||||
log_err("Error in the construction of number format with style currency:\n%s\n",
|
||||
|
@ -431,15 +431,12 @@ static void TestCurrency(void)
|
|||
if(U_FAILURE(status)) {
|
||||
log_err("Error in formatting using unum_formatDouble(.....): %s\n", myErrorName(status) );
|
||||
}
|
||||
res=(UChar*)malloc(sizeof(UChar) * (strlen(result[i])+1) );
|
||||
u_uastrcpy(res, result[i]);
|
||||
u_UCharsToChars(str,cStr,u_strlen(res));
|
||||
u_charsToUChars(result[i], res, strlen(result[i])+1);
|
||||
if (u_strcmp(str, res) != 0){
|
||||
log_err("FAIL: Expected %s Got: %s for locale: %s\n", result[i],cStr,locale[i]);
|
||||
log_err("FAIL: Expected %s Got: %s for locale: %s\n", result[i], aescstrdup(str, -1), locale[i]);
|
||||
}
|
||||
unum_close(currencyFmt);
|
||||
free(str);
|
||||
free(res);
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
@ -489,9 +486,8 @@ static void TestCurrencyPreEuro(void)
|
|||
}
|
||||
res=(UChar*)malloc(sizeof(UChar) * (strlen(result[i])+1) );
|
||||
u_unescape(result[i],res,(int32_t)(strlen(result[i])+1));
|
||||
u_UCharsToChars(str,cStr,u_strlen(str));
|
||||
if (u_strcmp(str, res) != 0){
|
||||
log_err("FAIL: Expected %s Got: %s for locale: %s\n", result[i],cStr,locale[i]);
|
||||
log_err("FAIL: Expected %s Got: %s for locale: %s\n", result[i],aescstrdup(str, -1),locale[i]);
|
||||
}
|
||||
|
||||
unum_close(currencyFmt);
|
||||
|
@ -570,9 +566,8 @@ static void TestCurrencyObject(void)
|
|||
}
|
||||
res=(UChar*)malloc(sizeof(UChar) * (strlen(result[i])+1) );
|
||||
u_unescape(result[i],res, (int32_t)(strlen(result[i])+1));
|
||||
u_UCharsToChars(str,cStr,u_strlen(str));
|
||||
if (u_strcmp(str, res) != 0){
|
||||
log_err("FAIL: Expected %s Got: %s for locale: %s\n", result[i],cStr,locale[i]);
|
||||
log_err("FAIL: Expected %s Got: %s for locale: %s\n", result[i],aescstrdup(str, -1),locale[i]);
|
||||
}
|
||||
|
||||
unum_close(currencyFmt);
|
||||
|
|
|
@ -160,13 +160,17 @@ static void expectContainment(const USet* set,
|
|||
UBool isIn) {
|
||||
const char* p = list;
|
||||
UChar ustr[128];
|
||||
char pat[128];
|
||||
char *pat;
|
||||
UErrorCode ec;
|
||||
int32_t rangeStart = -1, rangeEnd = -1;
|
||||
int32_t rangeStart = -1, rangeEnd = -1, length;
|
||||
|
||||
ec = U_ZERO_ERROR;
|
||||
uset_toPattern(set, ustr, sizeof(ustr), TRUE, &ec);
|
||||
u_UCharsToChars(ustr, pat, u_strlen(ustr)+1);
|
||||
length = uset_toPattern(set, ustr, sizeof(ustr), TRUE, &ec);
|
||||
if(U_FAILURE(ec)) {
|
||||
log_err("FAIL: uset_toPattern() fails in expectContainment() - %s\n", u_errorName(ec));
|
||||
return;
|
||||
}
|
||||
pat=aescstrdup(ustr, length);
|
||||
|
||||
while (*p) {
|
||||
if (*p=='{') {
|
||||
|
@ -243,7 +247,7 @@ static void expectContainment(const USet* set,
|
|||
}
|
||||
}
|
||||
|
||||
/* This only works for BMP chars */
|
||||
/* This only works for invariant BMP chars */
|
||||
static char oneUCharToChar(UChar32 c) {
|
||||
UChar ubuf[1];
|
||||
char buf[1];
|
||||
|
@ -256,21 +260,22 @@ static void expectItems(const USet* set,
|
|||
const char* items) {
|
||||
const char* p = items;
|
||||
UChar ustr[128], itemStr[128];
|
||||
char pat[128], buf[128];
|
||||
char buf[128];
|
||||
char *pat;
|
||||
UErrorCode ec;
|
||||
int32_t expectedSize = 0;
|
||||
int32_t itemCount = uset_getItemCount(set);
|
||||
int32_t itemIndex = 0;
|
||||
UChar32 start = 1, end = 0;
|
||||
int32_t itemLen = 0;
|
||||
int32_t itemLen = 0, length;
|
||||
|
||||
ec = U_ZERO_ERROR;
|
||||
uset_toPattern(set, ustr, sizeof(ustr), TRUE, &ec);
|
||||
length = uset_toPattern(set, ustr, sizeof(ustr), TRUE, &ec);
|
||||
if (U_FAILURE(ec)) {
|
||||
log_err("FAIL: uset_toPattern => %s\n", u_errorName(ec));
|
||||
return;
|
||||
}
|
||||
u_UCharsToChars(ustr, pat, u_strlen(ustr)+1);
|
||||
pat=aescstrdup(ustr, length);
|
||||
|
||||
if (uset_isEmpty(set) != (strlen(items)==0)) {
|
||||
log_err("FAIL: %s should return %s from isEmpty\n",
|
||||
|
@ -279,7 +284,7 @@ static void expectItems(const USet* set,
|
|||
}
|
||||
|
||||
/* Don't test patterns starting with "[^" */
|
||||
if (strlen(pat) > 2 && pat[1] == '^') {
|
||||
if (u_strlen(ustr) > 2 && ustr[1] == 0x5e /*'^'*/) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -1175,29 +1175,49 @@ void RegexTest::API_Pattern() {
|
|||
// A description of the test data format is included in that file.
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
const char *
|
||||
RegexTest::getPath(char buffer[2048], const char *filename) {
|
||||
UErrorCode status=U_ZERO_ERROR;
|
||||
const char *testDataDirectory = loadTestData(status);
|
||||
if (U_FAILURE(status)) {
|
||||
errln("ERROR: loadTestData() failed - %s", u_errorName(status));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char *folder=U_FILE_SEP_STRING "out" U_FILE_SEP_STRING "testdata";
|
||||
const char *outTestdata=strstr(testDataDirectory, folder);
|
||||
if(outTestdata!=NULL) {
|
||||
/* skip the initial '/' */
|
||||
outTestdata+=strlen(U_FILE_SEP_STRING);
|
||||
int32_t length=outTestdata-testDataDirectory;
|
||||
|
||||
/* replace the trailing folder with the filename */
|
||||
memcpy(buffer, testDataDirectory, length);
|
||||
strcpy(buffer+length, filename);
|
||||
return buffer;
|
||||
} else {
|
||||
errln("Could not find test data file %s because test data directory does not contain %s", filename, folder);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void RegexTest::Extended() {
|
||||
char tdd[2048];
|
||||
const char *path;
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
int32_t lineNum = 0;
|
||||
|
||||
//
|
||||
// Open and read the test data file.
|
||||
//
|
||||
const char *testDataDirectory = loadTestData(status);
|
||||
if (U_FAILURE(status)) {
|
||||
errln("ERROR: could not open test data %s", u_errorName(status));
|
||||
return;
|
||||
}
|
||||
UnicodeString tdd(testDataDirectory);
|
||||
RegexMatcher m("([/\\\\])out[/\\\\]testdata", tdd, 0, status);
|
||||
if(U_SUCCESS(status)) {
|
||||
tdd = m.replaceFirst("$1regextst.txt", status);
|
||||
} else {
|
||||
errln("Couldn't set up tests. Error %s", u_errorName(status));
|
||||
return;
|
||||
path=getPath(tdd, "regextst.txt");
|
||||
if(path==NULL) {
|
||||
return; /* something went wrong, error already output */
|
||||
}
|
||||
|
||||
int len;
|
||||
UChar *testData = ReadAndConvertFile((const char *)CharString(tdd), len, status);
|
||||
UChar *testData = ReadAndConvertFile(path, len, status);
|
||||
|
||||
//
|
||||
// Put the test data into a UnicodeString
|
||||
|
@ -1502,28 +1522,21 @@ cleanUpAndReturn:
|
|||
//
|
||||
//-------------------------------------------------------------------------------
|
||||
void RegexTest::PerlTests() {
|
||||
char tdd[2048];
|
||||
const char *path;
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
UParseError pe;
|
||||
|
||||
//
|
||||
// Open and read the test data file.
|
||||
//
|
||||
const char *testDataDirectory = loadTestData(status);
|
||||
if (U_FAILURE(status)) {
|
||||
errln("ERROR: could not open test data %s", u_errorName(status));
|
||||
return;
|
||||
}
|
||||
UnicodeString tdd(testDataDirectory);
|
||||
RegexMatcher m("([/\\\\])out[/\\\\]testdata", tdd, 0, status);
|
||||
if(U_SUCCESS(status)) {
|
||||
tdd = m.replaceFirst("$1re_tests.txt", status);
|
||||
} else {
|
||||
errln("Couldn't set up tests. Error %s", u_errorName(status));
|
||||
return;
|
||||
path=getPath(tdd, "re_tests.txt");
|
||||
if(path==NULL) {
|
||||
return; /* something went wrong, error already output */
|
||||
}
|
||||
|
||||
int len;
|
||||
UChar *testData = ReadAndConvertFile((const char *)CharString(tdd), len, status);
|
||||
UChar *testData = ReadAndConvertFile(path, len, status);
|
||||
|
||||
//
|
||||
// Put the test data into a UnicodeString
|
||||
|
|
|
@ -39,6 +39,8 @@ public:
|
|||
virtual void regex_err(const char *pat, int32_t errline, int32_t errcol,
|
||||
UErrorCode expectedStatus, int line);
|
||||
virtual UChar *ReadAndConvertFile(const char *fileName, int &len, UErrorCode &status);
|
||||
virtual const char *getPath(char buffer[2048], const char *filename);
|
||||
|
||||
};
|
||||
|
||||
#endif // !UCONFIG_NO_REGULAR_EXPRESSIONS
|
||||
|
|
Loading…
Add table
Reference in a new issue