+static void TestUnicodeIDs() {
+ UEnumeration *uenum;
+ UTransliterator *utrans;
+ const UChar *id, *id2;
+ int32_t idLength, id2Length, count, count2;
+
+ UErrorCode errorCode;
+
+ errorCode=U_ZERO_ERROR;
+ uenum=utrans_openIDs(&errorCode);
+ if(U_FAILURE(errorCode)) {
+ log_err("utrans_openIDs() failed - %s\n", u_errorName(errorCode));
+ return;
+ }
+
+ count=uenum_count(uenum, &errorCode);
+ if(U_FAILURE(errorCode) || count<1) {
+ log_err("uenum_count(transliterator IDs)=%d - %s\n", count, u_errorName(errorCode));
+ }
+
+ count=0;
+ for(;;) {
+ id=uenum_unext(uenum, &idLength, &errorCode);
+ if(U_FAILURE(errorCode)) {
+ log_err("uenum_unext(transliterator ID %d) failed - %s\n", count, u_errorName(errorCode));
+ break;
+ }
+ if(id==NULL) {
+ break;
+ }
+
+ if(++count>10) {
+ /* try to actually open only a few transliterators */
+ continue;
+ }
+
+ utrans=utrans_openU(id, idLength, UTRANS_FORWARD, NULL, 0, NULL, &errorCode);
+ if(U_FAILURE(errorCode)) {
+ log_err("utrans_openU(%s) failed - %s\n", aescstrdup(id, idLength), u_errorName(errorCode));
+ continue;
+ }
+
+ id2=utrans_getUnicodeID(utrans, &id2Length);
+ if(idLength!=id2Length || 0!=u_memcmp(id, id2, idLength)) {
+ log_err("utrans_getUnicodeID(%s) does not match the original ID\n", aescstrdup(id, idLength));
+ }
+
+ utrans_close(utrans);
+ }
+
+ uenum_reset(uenum, &errorCode);
+ if(U_FAILURE(errorCode) || count<1) {
+ log_err("uenum_reset(transliterator IDs) failed - %s\n", u_errorName(errorCode));
+ } else {
+ count2=uenum_count(uenum, &errorCode);
+ if(U_FAILURE(errorCode) || count<1) {
+ log_err("2nd uenum_count(transliterator IDs)=%d - %s\n", count2, u_errorName(errorCode));
+ } else if(count!=count2) {
+ log_err("uenum_unext(transliterator IDs) returned %d IDs but uenum_count() after uenum_reset() claims there are %d\n", count, count2);
+ }
+ }
+
+ uenum_close(uenum);
+}
+