virtual void run() { uint8_t sk1[1024], sk2[1024]; uint8_t *oldSk = NULL, *newSk = sk1; int32_t oldLen = 0; int32_t prev = 0; int32_t i = 0; for(i = 0; i < noLines; i++) { if(lines[i].buflen == 0) { continue; } if(skipLineBecauseOfBug(lines[i].buff, lines[i].buflen)) { continue; } int32_t resLen = coll->getSortKey(lines[i].buff, lines[i].buflen, newSk, 1024); if(oldSk != NULL) { int32_t skres = strcmp((char *)oldSk, (char *)newSk); int32_t cmpres = coll->compare(lines[prev].buff, lines[prev].buflen, lines[i].buff, lines[i].buflen); int32_t cmpres2 = coll->compare(lines[i].buff, lines[i].buflen, lines[prev].buff, lines[prev].buflen); if(cmpres != -cmpres2) { IntlTest::gTest->errln(UnicodeString("Compare result not symmetrical on line ") + (i + 1)); break; } if(cmpres != normalizeResult(skres)) { IntlTest::gTest->errln(UnicodeString("Difference between coll->compare and sortkey compare on line ") + (i + 1)); break; } int32_t res = cmpres; if(res == 0 && !isAtLeastUCA62) { // Up to UCA 6.1, the collation test files use a custom tie-breaker, // comparing the raw input strings. res = u_strcmpCodePointOrder(lines[prev].buff, lines[i].buff); // Starting with UCA 6.2, the collation test files use the standard UCA tie-breaker, // comparing the NFD versions of the input strings, // which we do via setting strength=identical. } if(res > 0) { IntlTest::gTest->errln(UnicodeString("Line is not greater or equal than previous line, for line ") + (i + 1)); break; } } oldSk = newSk; oldLen = resLen; (void)oldLen; // Suppress set but not used warning. prev = i; newSk = (newSk == sk1)?sk2:sk1; } }
int main(int /* argc*/ , const char * /*argv*/ []) { UErrorCode status = U_ZERO_ERROR; int diffs = 0; int gbaddiffs =0; setup(status); if(U_FAILURE(status)) return 1; int expected = PROVIDER_COUNT; for(int l=0;l<LOCALE_COUNT;l++) { printf("\n"); uint8_t oldBytes[200]; int32_t oldLen = -1; for(int v=0;v<=expected;v++) { // Construct the locale ID char locID[200]; strcpy(locID, locale[l]); if((v!=expected)) { // -1 = no version strcat(locID, "@sp=icu"); strcat(locID, provider_version[v]); } printf("%-28s = ", locID); UErrorCode subStatus = U_ZERO_ERROR; uint8_t bytes[200]; uint8_t bytesb[200]; #define USE_CXX 0 #if USE_CXX Collator *col = Collator::createInstance(Locale(locID),subStatus); if(U_FAILURE(subStatus)) { printf("ERR: %s\n", u_errorName(subStatus)); continue; } int32_t len = col->getSortKey(stuff, -1, bytes, 200); #else #if 1 char xbuf2[200]; strcpy(xbuf2,"X/"); strcat(xbuf2,locID); strcat(xbuf2,"/"); //printf(" -> %s\n", xbuf2); UCollator *col = ucol_openFromShortString(xbuf2, FALSE,NULL, &subStatus); #else UCollator *col = ucol_open(locID, &subStatus); #endif if(U_FAILURE(subStatus)) { printf("ERR: %s\n", u_errorName(subStatus)); continue; } char xbuf3[200]; { int32_t def = ucol_getShortDefinitionString(col,locID/*NULL*/,xbuf3,200,&subStatus); if(U_FAILURE(subStatus)) { printf("Err getting short string name: %s\n", u_errorName(subStatus)); } else { printf(" --> %s\n", xbuf3); } } int32_t len = ucol_getSortKey(col, stuff, -1, bytes, 200); #endif printf(" "); int tdiffs=0; for(int i=0;i<len;i++) { if(i<oldLen&&bytes[i]!=oldBytes[i]) { diffs++; printf("*"); } else { printf(" "); } printf("%02X", (0xFF&bytes[i])); } printf("\n"); char xbuf4[200]; UCollator *col2 = ucol_openFromShortString(xbuf3, FALSE, NULL, &subStatus); if(U_FAILURE(subStatus)) { printf("Err opening from new short string : %s\n", u_errorName(subStatus)); continue; } else { int32_t def4 = ucol_getShortDefinitionString(col,locID/*NULL*/,xbuf4,200,&subStatus); if(strcmp(xbuf4,xbuf3)) { printf(" --> reopened = %s (%s)\n", xbuf4, u_errorName(subStatus)); } } int32_t len2 = ucol_getSortKey(col2, stuff, -1, bytesb, 200); int baddiffs=0; for(int i=0;i<len;i++) { if(i<len&&bytes[i]!=bytesb[i]) { baddiffs++; printf("!"); } else { // printf(" "); } // printf("%02X", (0xFF&bytesb[i])); } if(baddiffs>0) { printf(" - ERR! Diffs from %s in %d places\n", xbuf2,baddiffs); gbaddiffs+=baddiffs; } else { //printf(" OK.\n"); } // printf("\n"); #if USE_CXX delete col; #else ucol_close(col); #endif oldLen = len; memcpy(oldBytes, bytes, len); } } if(diffs==0) { #if (U_ICU_VERSION_MAJOR_NUM < 49) printf("ERROR: 0 differences found between platforms. ICU " U_ICU_VERSION " does not support collator plugins properly (not until 49)\n"); #else printf("ERROR: 0 differences found between platforms.. are the platforms installed? Try 'icuinfo -L'\n"); #endif return 1; } else { printf("%d differences found among provider versions!\n", diffs); } if(gbaddiffs>0) { printf("ERROR: %d diffs found between a collator and it's reopened (from shortstring) variant.\n", gbaddiffs); return 2; } else { printf("Collator and reopened (shortstring) are OK.\n"); } printf("Success!\n"); return 0; }