res = nsComponentManager::CreateInstance(kCollationFactoryCID, NULL, NS_GET_IID(nsICollationFactory), (void**) &f);
res = CallCreateInstance(kCollationFactoryCID, &f);
static void TestCollation(nsILocale *locale){//   nsString locale("en-US");   nsICollationFactory *f = NULL;   nsICollation *t = NULL;   nsresult res;   printf("==============================\n");   printf("Start nsICollation Test \n");   printf("==============================\n");      res = nsComponentManager::CreateInstance(kCollationFactoryCID,                                            NULL,                                            NS_GET_IID(nsICollationFactory),                                            (void**) &f);              printf("Test 1 - CreateInstance():\n");   if(NS_FAILED(res) || ( f == NULL ) ) {     printf("\t1st CreateInstance failed\n");   } else {     f->Release();   }   res = nsComponentManager::CreateInstance(kCollationFactoryCID,                                            NULL,                                            NS_GET_IID(nsICollationFactory),                                            (void**) &f);   if(NS_FAILED(res) || ( f == NULL ) ) {     printf("\t2nd CreateInstance failed\n");   }   res = f->CreateCollation(locale, &t);              if(NS_FAILED(res) || ( t == NULL ) ) {     printf("\tCreateCollation failed\n");   } else {     nsString string1("abcde");     nsString string2("ABCDE");     nsString string3("xyz");     nsString string4("abc");     PRUint32 keyLength1, keyLength2, keyLength3;     PRUint8 *aKey1, *aKey2, *aKey3;     PRUint32 i;     PRInt32 result;      printf("String data used:\n");      printf("string1: ");      DebugDump(string1);      printf("string2: ");      DebugDump(string2);      printf("string3: ");      DebugDump(string3);      printf("string4: ");      DebugDump(string4);      printf("Test 2 - CompareString():\n");      res = t->CompareString(nsICollation::kCollationCaseInSensitive, string1, string2, &result);      if(NS_FAILED(res)) {        printf("\tFailed!! return value != NS_OK\n");      }      printf("case insensitive comparison (string1 vs string2): %d\n", result);      res = t->CompareString(nsICollation::kCollationCaseSensitive, string1, string2, &result);      if(NS_FAILED(res)) {        printf("\tFailed!! return value != NS_OK\n");      }      printf("case sensitive comparison (string1 vs string2): %d\n", result);      printf("Test 3 - GetSortKeyLen():\n");      res = t->GetSortKeyLen(nsICollation::kCollationCaseSensitive, string2, &keyLength1);      if(NS_FAILED(res)) {        printf("\tFailed!! return value != NS_OK\n");      }      printf("keyLength: %d\n", keyLength1);      printf("Test 4 - CreateRawSortKey():\n");      aKey1 = (PRUint8 *) new PRUint8[keyLength1];      if (NULL == aKey1) {        printf("\tFailed!! memory allocation failed.\n");      }      res = t->CreateRawSortKey(nsICollation::kCollationCaseSensitive, string2, aKey1, &keyLength1);      if(NS_FAILED(res)) {        printf("\tFailed!! return value != NS_OK\n");      }      printf("case sensitive key creation:\n");      printf("keyLength: %d\n", keyLength1);      DebugDump(string2);      fflush(NULL);      for (i = 0; i < keyLength1; i++) {        printf("%.2x ", aKey1[i]);        //printf("key[" << i << "]: " << aKey1[i] << " ");      }      printf("\n");      res = CreateCollationKey(t, nsICollation::kCollationCaseInSensitive, string2, &aKey2, &keyLength2);      if(NS_FAILED(res)) {        printf("\tFailed!! return value != NS_OK\n");      }      printf("case insensitive key creation:\n");      printf("keyLength: %d\n", keyLength2);      DebugDump(string2);      fflush(NULL);      for (i = 0; i < keyLength2; i++) {       printf("%.2x ", aKey2[i]);       //printf("key[" << i << "]: " << aKey2[i] << " ");      }      printf("\n");      printf("Test 5 - CompareRawSortKey():\n");      res = CreateCollationKey(t, nsICollation::kCollationCaseSensitive, string1, &aKey3, &keyLength3);      if(NS_FAILED(res)) {        printf("\tFailed!! return value != NS_OK\n");      }      res = t->CompareRawSortKey(aKey1, keyLength1, aKey3, keyLength3, &result);      if(NS_FAILED(res)) {        printf("\tFailed!! return value != NS_OK\n");      }      printf("case sensitive comparison (string1 vs string2): %d\n", result);      res = t->CompareRawSortKey(aKey3, keyLength3, aKey1, keyLength1, &result);      if(NS_FAILED(res)) {        printf("\tFailed!! return value != NS_OK\n");      }      printf("case sensitive comparison (string2 vs string1): %d\n", result);      res = t->CompareRawSortKey(aKey2, keyLength2, aKey3, keyLength3, &result);      if(NS_FAILED(res)) {        printf("\tFailed!! return value != NS_OK\n");      }      printf("case insensitive comparison (string1 vs string2): %d\n", result);      if (NULL != aKey1)        delete[] aKey1;       if (NULL != aKey2)        delete[] aKey2;       if (NULL != aKey3)        delete[] aKey3;       res = CreateCollationKey(t, nsICollation::kCollationCaseSensitive, string1, &aKey1, &keyLength1);      if(NS_FAILED(res)) {        printf("\tFailed!! return value != NS_OK\n");      }      res = CreateCollationKey(t, nsICollation::kCollationCaseSensitive, string3, &aKey2, &keyLength2);      if(NS_FAILED(res)) {        printf("\tFailed!! return value != NS_OK\n");      }      res = CreateCollationKey(t, nsICollation::kCollationCaseSensitive, string4, &aKey3, &keyLength3);      if(NS_FAILED(res)) {        printf("\tFailed!! return value != NS_OK\n");      }      res = t->CompareRawSortKey(aKey1, keyLength1, aKey2, keyLength2, &result);      if(NS_FAILED(res)) {        printf("\tFailed!! return value != NS_OK\n");      }      printf("case sensitive comparison (string1 vs string3): %d\n", result);      res = t->CompareRawSortKey(aKey1, keyLength1, aKey3, keyLength3, &result);      if(NS_FAILED(res)) {        printf("\tFailed!! return value != NS_OK\n");      }      printf("case sensitive comparison (string1 vs string4): %d\n", result);      if (NULL != aKey1)        delete[] aKey1;       if (NULL != aKey2)        delete[] aKey2;       if (NULL != aKey3)        delete[] aKey3;      res = t->Release();     res = f->Release();   }   printf("==============================\n");   printf("Finish nsICollation Test \n");   printf("==============================\n");}