/********************************************************************
* COPYRIGHT:
- * Copyright (c) 1997-2004, International Business Machines Corporation and
+ * Copyright (c) 1997-2008, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
/********************************************************************************
UCollator *c1, *c2, *c3;
UCollationElements *iter;
UErrorCode status = U_ZERO_ERROR;
+ UChar test1[50];
+ UChar test2[50];
- test1=(UChar*)malloc(sizeof(UChar) * 50);
- test2=(UChar*)malloc(sizeof(UChar) * 50);
u_uastrcpy(test1, "What subset of all possible test cases?");
u_uastrcpy(test2, "has the highest probability of detecting");
coll = ucol_open("en_US", &status);
ucol_close(coll);
free(source);
- free(test1);
- free(test2);
}
/**
UCollator *en_us=NULL;
UCollationElements *iter, *pristine;
int32_t offset;
- int32_t *orders;
+ OrderAndOffset *orders;
int32_t orderLength=0;
int count = 0;
- test1=(UChar*)malloc(sizeof(UChar) * 50);
- test2=(UChar*)malloc(sizeof(UChar) * 50);
+ UChar test1[50];
+ UChar test2[50];
+
u_uastrcpy(test1, "What subset of all possible test cases?");
u_uastrcpy(test2, "has the highest probability of detecting");
en_us = ucol_open("en_US", &status);
switch (count) {
case 0:
if (ucol_getOffset(iter) != 1) {
- log_err("ERROR: Offset of iteration should be 0\n");
+ log_err("ERROR: Offset of iteration should be 1\n");
}
break;
case 3:
U_SUCCESS(status)) {
switch (count) {
case 0:
+ case 1:
if (ucol_getOffset(iter) != 3) {
log_err("ERROR: Offset of iteration should be 3\n");
}
break;
+ case 2:
+ if (ucol_getOffset(iter) != 1) {
+ log_err("ERROR: Offset of iteration should be 1\n");
+ }
+ break;
default:
if (ucol_getOffset(iter) != 0) {
log_err("ERROR: Offset of iteration should be 0\n");
ucol_closeElements(iter);
ucol_close(en_us);
- free(test1);
- free(test2);
}
/**
UErrorCode status = U_ZERO_ERROR;
UCollator *en_us=NULL;
UCollationElements *iter1, *iter2;
- test1=(UChar*)malloc(sizeof(UChar) * 50);
- test2=(UChar*)malloc(sizeof(UChar) * 50);
+ UChar test1[50];
+ UChar test2[50];
+
u_uastrcpy(test1, "What subset of all possible test cases?");
u_uastrcpy(test2, "has the highest probability of detecting");
en_us = ucol_open("en_US", &status);
ucol_closeElements(iter2);
ucol_closeElements(iter1);
ucol_close(en_us);
- free(test1);
- free(test2);
}
/** @bug 4108762
UCollationElements *testiter,
*iter;
int32_t count = 0;
- int32_t *testorders,
+ OrderAndOffset *testorders,
*orders;
UChar teststr[500];
while (count != 0) {
/* UCA collation element for 0x0F76 */
- if ((count > 250 && testorders[-- count] != orders[1]) ||
- (count <= 250 && testorders[-- count] != orders[0])) {
+ if ((count > 250 && testorders[-- count].order != orders[1].order) ||
+ (count <= 250 && testorders[-- count].order != orders[0].order)) {
log_err("Error decomposition does not give the right collation element at %d count\n", count);
break;
}
* @param codepoints array for storage, assuming size > 5
* @return position at the end of the codepoint section
*/
-static char * getCodePoints(char *str, UChar *codepoints) {
+static char * getCodePoints(char *str, UChar *codepoints, UChar *contextCPs) {
char *pStartCP = str;
char *pEndCP = str + 4;
(hex2num(*(pStartCP + 1)) << 8) |
(hex2num(*(pStartCP + 2)) << 4) |
(hex2num(*(pStartCP + 3))));
+ if (*pEndCP == '|' || *(pEndCP+1) == '|') {
+ /* pre-context rule */
+ pStartCP = pEndCP;
+ while (*pStartCP==' ' || *pStartCP== '|' ) {
+ pStartCP++;
+ }
+ pEndCP = pStartCP+4;
+ *contextCPs = *codepoints;
+ *(++codepoints) = (UChar)((hex2num(*pStartCP) << 12) |
+ (hex2num(*(pStartCP + 1)) << 8) |
+ (hex2num(*(pStartCP + 2)) << 4) |
+ (hex2num(*(pStartCP + 3))));
+ contextCPs++;
+ }
+ *contextCPs = 0;
codepoints ++;
while (*pEndCP != ';') {
pStartCP = pEndCP + 1;
FileStream *file = NULL;
char line[1024];
char *str;
- UChar codepoints[5];
+ UChar codepoints[10];
uint32_t ces[20];
UErrorCode status = U_ZERO_ERROR;
UCollator *coll = ucol_open("", &status);
uint32_t lineNo = 0;
+ UChar contextCPs[5];
if (U_FAILURE(status)) {
log_err("Error in opening root collator\n");
while (T_FileStream_readLine(file, line, sizeof(line)) != NULL) {
int count = 0;
UCollationElements *iter;
+ int32_t preContextCeLen=0;
lineNo++;
/* skip this line if it is empty or a comment or is a return value
or start of some variable section */
continue;
}
- str = getCodePoints(line, codepoints);
+ str = getCodePoints(line, codepoints, contextCPs);
/* these are 'fake' codepoints in the fractional UCA, and are used just
* for positioning of indirect values. They should not go through this
if(*codepoints == 0xFDD0) {
continue;
}
+ if (*contextCPs != 0) {
+ iter = ucol_openElements(coll, contextCPs, -1, &status);
+ if (U_FAILURE(status)) {
+ log_err("Error in opening collation elements\n");
+ break;
+ }
+ while((ces[preContextCeLen] = ucol_next(iter, &status)) != (uint32_t)UCOL_NULLORDER) {
+ preContextCeLen++;
+ }
+ ucol_closeElements(iter);
+ }
- getCEs(str, ces, &status);
+ getCEs(str, ces+preContextCeLen, &status);
if (U_FAILURE(status)) {
log_err("Error in parsing collation elements in FractionalUCA.txt\n");
break;
str[UCOL_EXPAND_CE_BUFFER_SIZE] = 0x0042; /* 'B' */
iter = ucol_openElements(coll, str, UCOL_EXPAND_CE_BUFFER_SIZE + 1,
&status);
- if (ucol_previous(iter, &status) != UCOL_NULLORDER ||
- status != U_BUFFER_OVERFLOW_ERROR) {
- log_err("CE buffer expected to overflow with long string of trail surrogates\n");
+ if (ucol_previous(iter, &status) == UCOL_NULLORDER ||
+ status == U_BUFFER_OVERFLOW_ERROR) {
+ log_err("CE buffer should not overflow with long string of trail surrogates\n");
}
ucol_closeElements(iter);
ucol_close(coll);
/* tailored locales */
char locale[][11] = {"fr_FR", "ko_KR", "sh_YU", "th_TH", "zh_CN", "zh__PINYIN"};
const char *loc;
- FileStream *file = getFractionalUCA();
+ FileStream *file = NULL;
char line[1024];
UChar codepoints[10];
int count = 0;
int maxCount = 0;
+ UChar contextCPs[3];
UParseError parseError;
if (U_FAILURE(status)) {
log_err("en_US collator creation failed\n");
return;
}
log_verbose("Testing UCA elements\n");
+ file = getFractionalUCA();
if (file == NULL) {
log_err("Fractional UCA data can not be opened\n");
return;
continue;
}
- getCodePoints(line, codepoints);
+ getCodePoints(line, codepoints, contextCPs);
checkCEValidity(coll, codepoints, u_strlen(codepoints), 5, 86);
}
/* en_US has no tailorings */
UCollator *coll = ucol_open("en_US", &status);
/* tailored locales */
- char locale[][6] = {"fr_FR\0", "ko_KR\0", "sh_YU\0", "th_TH\0", "zh_CN\0"};
- FileStream *file = getFractionalUCA();
+ char locale[][6] = {"fr_FR", "ko_KR", "sh_YU", "th_TH", "zh_CN"};
+ FileStream *file = NULL;
char line[1024];
UChar codepoints[10];
int count = 0;
+ UChar contextCPs[5];
UParseError parseError;
if (U_FAILURE(status)) {
log_err("en_US collator creation failed\n");
return;
}
log_verbose("Testing UCA elements\n");
+ file = getFractionalUCA();
if (file == NULL) {
log_err("Fractional UCA data can not be opened\n");
return;
continue;
}
- getCodePoints(line, codepoints);
+ getCodePoints(line, codepoints, contextCPs);
checkSortKeyValidity(coll, codepoints, u_strlen(codepoints));
}