From dc50f84fa723ec33ec5d4a9c865d131af82a18e5 Mon Sep 17 00:00:00 2001 From: "smontagu%smontagu.org" Date: Tue, 27 Feb 2007 22:49:17 +0000 Subject: [PATCH] Removing obsolete files not part of the build. Bug 371990, r=sayrer git-svn-id: svn://10.0.0.236/trunk@221033 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/intl/locale/tests/LocaleSelfTest.cpp | 1079 ------------------ mozilla/intl/locale/tests/nsLocaleTest.cpp | 966 ---------------- 2 files changed, 2045 deletions(-) delete mode 100644 mozilla/intl/locale/tests/LocaleSelfTest.cpp delete mode 100644 mozilla/intl/locale/tests/nsLocaleTest.cpp diff --git a/mozilla/intl/locale/tests/LocaleSelfTest.cpp b/mozilla/intl/locale/tests/LocaleSelfTest.cpp deleted file mode 100644 index 84e4cad8968..00000000000 --- a/mozilla/intl/locale/tests/LocaleSelfTest.cpp +++ /dev/null @@ -1,1079 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Pierre Phaneuf - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include -#include -#include "nsISupports.h" -#include "nsIComponentManager.h" -#include "nsILocale.h" -#include "nsILocaleFactory.h" -#include "nsLocaleCID.h" -#if defined(XP_MAC) || defined(XP_MACOSX) -#include "nsIMacLocale.h" -#include -#elif defined(XP_WIN) || defined(XP_OS2) -#include "nsIWin32Locale.h" -#else -#include "nsIPosixLocale.h" -#endif -#include "nsCollationCID.h" -#include "nsICollation.h" -#include "nsDateTimeFormatCID.h" -#include "nsIDateTimeFormat.h" -#include "nsReadableUtils.h" - -#ifdef XP_MAC -#define LOCALE_DLL_NAME "NSLOCALE_DLL" -#define UCONV_DLL "UCONV_DLL" -#define UCVLATIN_DLL "UCVLATIN_DLL" -#define UNICHARUTIL_DLL_NAME "UNICHARUTIL_DLL" -#elif defined(XP_WIN) || defined(XP_OS2) -#define LOCALE_DLL_NAME "NSLOCALE.DLL" -#define UCONV_DLL "uconv.dll" -#define UCVLATIN_DLL "ucvlatin.dll" -#define UNICHARUTIL_DLL_NAME "unicharutil.dll" -#else -#define LOCALE_DLL_NAME "libnslocale"MOZ_DLL_SUFFIX -#define UCONV_DLL "libuconv"MOZ_DLL_SUFFIX -#define UCVLATIN_DLL "libucvlatin"MOZ_DLL_SUFFIX -#define UNICHARUTIL_DLL_NAME "libunicharutil"MOZ_DLL_SUFFIX -#endif - - - -// Collation -// -static NS_DEFINE_CID(kCollationFactoryCID, NS_COLLATIONFACTORY_CID); -// Date and Time -// -static NS_DEFINE_CID(kDateTimeFormatCID, NS_DATETIMEFORMAT_CID); -// locale -// -static NS_DEFINE_CID(kLocaleFactoryCID, NS_LOCALEFACTORY_CID); -// platform specific -// -#if defined(XP_MAC) || defined(XP_MACOSX) -static NS_DEFINE_IID(kMacLocaleFactoryCID, NS_MACLOCALEFACTORY_CID); -static NS_DEFINE_IID(kIMacLocaleIID, NS_MACLOCALE_CID); -#elif defined(XP_WIN) || defined(XP_OS2) -static NS_DEFINE_CID(kWin32LocaleFactoryCID, NS_WIN32LOCALEFACTORY_CID); -static NS_DEFINE_IID(kIWin32LocaleIID, NS_IWIN32LOCALE_IID); -#else -static NS_DEFINE_IID(kPosixLocaleFactoryCID, NS_POSIXLOCALEFACTORY_CID); -static NS_DEFINE_IID(kIPosixLocaleIID, NS_IPOSIXLOCALE_IID); -#endif - -// global variable -static PRBool g_verbose = PR_FALSE; -static FILE *g_outfp = NULL; -static char g_usage[] = " usage:\n-date\tdate time format test\n-col\tcollation test\n-sort\tsort test\n\ --f file\tsort data file\n-o out file\tsort result file\n-case\tcase sensitive sort\n-locale\tlocale\n-v\tverbose\n"; - -// Create a collation key, the memory is allocated using new which need to be deleted by a caller. -// -static nsresult CreateCollationKey(nsICollation *t, PRInt32 strength, - nsString& stringIn, PRUint8 **aKey, PRUint32 *keyLength) -{ - nsresult res; - - // create a raw collation key - res = t->GetSortKeyLen(strength, stringIn, keyLength); - if(NS_FAILED(res)) { - printf("\tFailed!! return value != NS_OK\n"); - } - *aKey = (PRUint8 *) new PRUint8[*keyLength]; - if (NULL == *aKey) { - printf("\tFailed!! memory allocation failed.\n"); - } - res = t->CreateRawSortKey(strength, stringIn, *aKey, keyLength); - if(NS_FAILED(res)) { - printf("\tFailed!! return value != NS_OK\n"); - } - - // create a key in nsString - nsString aKeyString; - res = t->CreateSortKey(strength, stringIn, aKeyString); - if(NS_FAILED(res)) { - printf("\tFailed!! return value != NS_OK\n"); - } - - // compare the generated key - nsString tempString; - tempString.SetString((PRUnichar *) *aKey, *keyLength / sizeof(PRUnichar)); - NS_ASSERTION(aKeyString == tempString, "created key mismatch"); - - return res; -} - -static void DebugDump(nsString& aString) { -#ifdef WIN32 - char s[512]; - int len = WideCharToMultiByte(GetACP(), 0, - (LPCWSTR ) aString.get(), aString.Length(), - s, 512, NULL, NULL); - s[len] = '\0'; - fflush(stdout); - printf("%s\n", s); -#elif defined(XP_MAC) || defined(XP_MACOSX) - // Use TEC (Text Encoding Conversion Manager) - TextEncoding outEncoding; - TECObjectRef anEncodingConverter; - ByteCount oInputRead, oOutputLen; - char oOutputStr[512]; - OSStatus err = 0; - err = UpgradeScriptInfoToTextEncoding (smSystemScript/*smCurrentScript*/, kTextLanguageDontCare, kTextRegionDontCare, NULL, &outEncoding); - err = TECCreateConverter(&anEncodingConverter, kTextEncodingUnicodeV2_0, outEncoding); - err = TECConvertText(anEncodingConverter, - (ConstTextPtr) aString.get(), aString.Length() * sizeof(PRUnichar), &oInputRead, - (TextPtr) oOutputStr, 512, &oOutputLen); - err = TECDisposeConverter(anEncodingConverter); - - oOutputStr[oOutputLen] = '\0'; - fflush(NULL); - printf("%s\n", oOutputStr); -#else - for (int i = 0; i < aString.Length(); i++) { - putchar((char) aString[i]); - } - printf("\n"); -#endif -} - -// Test all functions in nsICollation. -// -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 = CallCreateInstance(kCollationFactoryCID, &f); - - printf("Test 1 - CreateInstance():\n"); - if(NS_FAILED(res) || ( f == NULL ) ) { - printf("\t1st CreateInstance failed\n"); - } else { - f->Release(); - } - - res = CallCreateInstance(kCollationFactoryCID, &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"); - -} - -// Sort test using qsort -// - -static nsICollation *g_collationInst = NULL; -static PRInt32 g_CollationStrength= nsICollation::kCollationCaseInSensitive; - - -static void TestSortPrint1(nsString *string_array, int len) -{ - for (int i = 0; i < len; i++) { - //string_array[i].DebugDump(cout); - DebugDump(string_array[i]); - } - printf("\n"); -} - -static void TestSortPrintToFile(nsString *string_array, int len) -{ - for (int i = 0; i < len; i++) { -#ifdef WIN32 - char cstr[512]; - int len = WideCharToMultiByte(GetACP(), 0, - (LPCWSTR ) string_array[i].get(), string_array[i].Length(), - cstr, 512, NULL, NULL); - cstr[len] = '\0'; - fprintf(g_outfp, "%s\n", cstr); -#else - fprintf(g_outfp, "%s\n", - NS_LossyConvertUCS2ToASCII(string_array[i]).get()); -#endif - } - fprintf(g_outfp, "\n"); -} - -static void DebugPrintCompResult(const nsString& string1, const nsString& string2, int result) -{ -#ifdef WIN32 - char s[512]; - int len = WideCharToMultiByte(GetACP(), 0, - (LPCWSTR ) string1.get(), string1.Length(), - s, 512, NULL, NULL); - s[len] = '\0'; - printf("%s ", s); - - switch ((int)result) { - case 0: - printf("=="); - break; - case 1: - printf(">"); - break; - case -1: - printf("<"); - break; - } - - len = WideCharToMultiByte(GetACP(), 0, - (LPCWSTR ) string2.get(), string2.Length(), - s, 512, NULL, NULL); - s[len] = '\0'; - printf(" %s\n", s); -#else - // Warning: casting to char* - printf(NS_LossyConvertUTF16toASCII(string1).get() << ' '); - - switch ((int)result) { - case 0: - printf("=="); - break; - case 1: - printf('>'); - break; - case -1: - printf('<'); - break; - } - printf(' ' << NS_LossyConvertUTF16toASCII(string2).get() << '\n'); -#endif -} - -static int compare1( const void *arg1, const void *arg2 ) -{ - nsString string1, string2; - PRInt32 result,result2; - nsresult res; - - string1 = *(nsString *) arg1; - string2 = *(nsString *) arg2; - - res = g_collationInst->CompareString(g_CollationStrength, string1, string2, &result2); - - nsString key1,key2; - res = g_collationInst->CreateSortKey(g_CollationStrength, string1, key1); - NS_ASSERTION(NS_SUCCEEDED(res), "CreateSortKey"); - res = g_collationInst->CreateSortKey(g_CollationStrength, string2, key2); - NS_ASSERTION(NS_SUCCEEDED(res), "CreateSortKey"); - - // dump collation keys - if (g_verbose) { - int i; - for (i = 0; i < key1.Length(); i++) - printf("%.2x", key1[i]); - printf(" "); - for (i = 0; i < key2.Length(); i++) - printf("%.2x", key2[i]); - printf("\n"); - } - - res = g_collationInst->CompareSortKey(key1, key2, &result); - NS_ASSERTION(NS_SUCCEEDED(res), "CreateSortKey"); - NS_ASSERTION(NS_SUCCEEDED((PRBool)(result == result2)), "result unmatch"); - if (g_verbose) { - DebugPrintCompResult(string1, string2, result); - } - - return (int) result; -} - - -typedef struct { - PRUint8 *aKey; - PRUint32 aLength; -} collation_rec; - -static int compare2( const void *arg1, const void *arg2 ) -{ - collation_rec *keyrec1, *keyrec2; - PRInt32 result; - nsresult res; - - keyrec1 = (collation_rec *) arg1; - keyrec2 = (collation_rec *) arg2; - - res = g_collationInst->CompareRawSortKey(keyrec1->aKey, keyrec1->aLength, - keyrec2->aKey, keyrec2->aLength, &result); - - return (int) result; -} - -static void TestSortPrint2(collation_rec *key_array, int len) -{ - PRUint32 aLength; - PRUint8 *aKey; - - fflush(NULL); - for (int i = 0; i < len; i++) { - aLength = key_array[i].aLength; - aKey = key_array[i].aKey; - for (int j = 0; j < (int)aLength; j++) { - printf("%.2x ", aKey[j]); - } - printf("\n"); - } - printf("\n"); -} - -// Sort test by reading data from a file. -// -static void SortTestFile(nsICollation* collationInst, FILE* fp) -{ - nsString string_array[256]; - char buf[512]; - int i = 0; - - // read lines and put them to nsStrings - while (fgets(buf, 512, fp)) { - if (*buf == '\n' || *buf == '\r') - continue; - // trim LF CR - char *cp = buf + (strlen(buf) - 1); - while (*cp) { - if (*cp == '\n' || *cp == '\r') - *cp = '\0'; - else - break; - cp--; - } -#ifdef WIN32 - wchar_t wcs[512]; - int len = MultiByteToWideChar(GetACP(), 0, buf, strlen(buf), wcs, 512); - wcs[len] = L'\0'; - string_array[i].SetString((PRUnichar *)wcs); -#else - string_array[i].SetString(buf); -#endif - i++; - } - printf("print string before sort\n"); - TestSortPrint1(string_array, i); - - g_collationInst = collationInst; - qsort( (void *)string_array, i, sizeof(nsString), compare1 ); - - printf("print string after sort\n"); - (g_outfp == NULL) ? TestSortPrint1(string_array, i) : TestSortPrintToFile(string_array, i); -} - -// Use nsICollation for qsort. -// -static void TestSort(nsILocale *locale, PRInt32 collationStrength, FILE *fp) -{ - nsresult res; - nsICollationFactory *factoryInst; - nsICollation *collationInst; - PRInt32 strength; - collation_rec key_array[5]; - PRUint8 *aKey; - PRUint32 aLength; - //nsString locale("en-US"); - nsString string1("AAC"); - nsString string2("aac"); - nsString string3("AAC"); - nsString string4("aac"); - nsString string5("AAC"); - nsString string_array[5]; - - printf("==============================\n"); - printf("Start sort Test \n"); - printf("==============================\n"); - - res = CallCreateInstance(kCollationFactoryCID, &factoryInst); - if(NS_FAILED(res)) { - printf("\tFailed!! return value != NS_OK\n"); - } - - res = factoryInst->CreateCollation(locale, &collationInst); - if(NS_FAILED(res)) { - printf("\tFailed!! return value != NS_OK\n"); - } - - // set collation strength - g_CollationStrength = collationStrength; - strength = g_CollationStrength; - - if (fp != NULL) { - res = NS_ADDREF(collationInst); - SortTestFile(collationInst, fp); - NS_RELEASE(collationInst); - return; - } - - printf("==============================\n"); - printf("Sort Test by comparestring.\n"); - printf("==============================\n"); - string_array[0] = string1; - string_array[1] = string2; - string_array[2] = string3; - string_array[3] = string4; - string_array[4] = string5; - - printf("print string before sort\n"); - TestSortPrint1(string_array, 5); - - g_collationInst = collationInst; - res = collationInst->AddRef(); - qsort( (void *)string_array, 5, sizeof(nsString), compare1 ); - res = collationInst->Release(); - - printf("print string after sort\n"); - TestSortPrint1(string_array, 5); - - printf("==============================\n"); - printf("Sort Test by collation key.\n"); - printf("==============================\n"); - - - res = CreateCollationKey(collationInst, strength, string1, &aKey, &aLength); - if(NS_FAILED(res)) { - printf("\tFailed!! return value != NS_OK\n"); - } - key_array[0].aKey = aKey; - key_array[0].aLength = aLength; - - res = CreateCollationKey(collationInst, strength, string2, &aKey, &aLength); - if(NS_FAILED(res)) { - printf("\tFailed!! return value != NS_OK\n"); - } - key_array[1].aKey = aKey; - key_array[1].aLength = aLength; - - res = CreateCollationKey(collationInst, strength, string3, &aKey, &aLength); - if(NS_FAILED(res)) { - printf("\tFailed!! return value != NS_OK\n"); - } - key_array[2].aKey = aKey; - key_array[2].aLength = aLength; - - res = CreateCollationKey(collationInst, strength, string4, &aKey, &aLength); - if(NS_FAILED(res)) { - printf("\tFailed!! return value != NS_OK\n"); - } - key_array[3].aKey = aKey; - key_array[3].aLength = aLength; - - res = CreateCollationKey(collationInst, strength, string5, &aKey, &aLength); - if(NS_FAILED(res)) { - printf("\tFailed!! return value != NS_OK\n"); - } - key_array[4].aKey = aKey; - key_array[4].aLength = aLength; - - printf("print key before sort\n"); - TestSortPrint2(key_array, 5); - - g_collationInst = collationInst; - res = collationInst->AddRef(); - qsort( (void *)key_array, 5, sizeof(collation_rec), compare2 ); - res = collationInst->Release(); - - printf("print key after sort\n"); - TestSortPrint2(key_array, 5); - - - res = collationInst->Release(); - - res = factoryInst->Release(); - - for (int i = 0; i < 5; i++) { - delete [] key_array[i].aKey; - } - - printf("==============================\n"); - printf("Finish sort Test \n"); - printf("==============================\n"); -} - -// Test all functions in nsIDateTimeFormat. -// -static void TestDateTimeFormat(nsILocale *locale) -{ - nsresult res; - - printf("==============================\n"); - printf("Start nsIScriptableDateFormat Test \n"); - printf("==============================\n"); - - nsIScriptableDateFormat *aScriptableDateFormat; - res = CallCreateInstance(kDateTimeFormatCID, &aScriptableDateFormat); - if(NS_FAILED(res) || ( aScriptableDateFormat == NULL ) ) { - printf("\tnsIScriptableDateFormat CreateInstance failed\n"); - } - - PRUnichar *aUnichar; - nsString aString; - PRUnichar aLocaleUnichar[1]; - *aLocaleUnichar = 0; - res = aScriptableDateFormat->FormatDateTime(aLocaleUnichar, kDateFormatShort, kTimeFormatSeconds, - 1999, - 7, - 31, - 8, - 21, - 58, - &aUnichar); - aString.SetString(aUnichar); - DebugDump(aString); - - res = aScriptableDateFormat->FormatDate(aLocaleUnichar, kDateFormatLong, - 1970, - 4, - 20, - &aUnichar); - aString.SetString(aUnichar); - DebugDump(aString); - - res = aScriptableDateFormat->FormatTime(aLocaleUnichar, kTimeFormatSecondsForce24Hour, - 13, - 59, - 31, - &aUnichar); - aString.SetString(aUnichar); - DebugDump(aString); - - aScriptableDateFormat->Release(); - - printf("==============================\n"); - printf("Start nsIDateTimeFormat Test \n"); - printf("==============================\n"); - - nsIDateTimeFormat *t = NULL; - res = CallCreateInstance(kDateTimeFormatCID, &t); - - printf("Test 1 - CreateInstance():\n"); - if(NS_FAILED(res) || ( t == NULL ) ) { - printf("\t1st CreateInstance failed\n"); - } else { - t->Release(); - } - - res = CallCreateInstance(kDateTimeFormatCID, &t); - - if(NS_FAILED(res) || ( t == NULL ) ) { - printf("\t2nd CreateInstance failed\n"); - } else { - } - - - nsAutoString dateString; -// nsString locale("en-GB"); - time_t timetTime; - - - printf("Test 2 - FormatTime():\n"); - time( &timetTime ); - res = t->FormatTime(locale, kDateFormatShort, kTimeFormatSeconds, timetTime, dateString); - DebugDump(dateString); - - printf("Test 3 - FormatTMTime():\n"); - time_t ltime; - time( <ime ); - - // try (almost) all format combination - res = t->FormatTMTime(locale, kDateFormatNone, kTimeFormatNone, localtime( <ime ), dateString); - printf("kDateFormatNone, kTimeFormatNone:\n"); - DebugDump(dateString); - res = t->FormatTMTime(locale, kDateFormatNone, kTimeFormatSeconds, localtime( <ime ), dateString); - printf("kDateFormatNone, kTimeFormatSeconds:\n"); - DebugDump(dateString); - res = t->FormatTMTime(locale, kDateFormatNone, kTimeFormatNoSeconds, localtime( <ime ), dateString); - printf("kDateFormatNone, kTimeFormatNoSeconds:\n"); - DebugDump(dateString); - res = t->FormatTMTime(locale, kDateFormatLong, kTimeFormatNone, localtime( <ime ), dateString); - printf("kDateFormatLong, kTimeFormatNone:\n"); - DebugDump(dateString); - res = t->FormatTMTime(locale, kDateFormatLong, kTimeFormatSeconds, localtime( <ime ), dateString); - printf("kDateFormatLong, kTimeFormatSeconds:\n"); - DebugDump(dateString); - res = t->FormatTMTime(locale, kDateFormatLong, kTimeFormatNoSeconds, localtime( <ime ), dateString); - printf("kDateFormatLong, kTimeFormatNoSeconds:\n"); - DebugDump(dateString); - res = t->FormatTMTime(locale, kDateFormatShort, kTimeFormatNone, localtime( <ime ), dateString); - printf("kDateFormatShort, kTimeFormatNone:\n"); - DebugDump(dateString); - res = t->FormatTMTime(locale, kDateFormatShort, kTimeFormatSeconds, localtime( <ime ), dateString); - printf("kDateFormatShort, kTimeFormatSeconds:\n"); - DebugDump(dateString); - res = t->FormatTMTime(locale, kDateFormatShort, kTimeFormatNoSeconds, localtime( <ime ), dateString); - printf("kDateFormatShort, kTimeFormatNoSeconds:\n"); - DebugDump(dateString); - res = t->FormatTMTime(locale, kDateFormatYearMonth, kTimeFormatNone, localtime( <ime ), dateString); - printf("kDateFormatYearMonth, kTimeFormatNone:\n"); - DebugDump(dateString); - res = t->FormatTMTime(locale, kDateFormatYearMonth, kTimeFormatSeconds, localtime( <ime ), dateString); - printf("kDateFormatYearMonth, kTimeFormatSeconds:\n"); - DebugDump(dateString); - res = t->FormatTMTime(locale, kDateFormatYearMonth, kTimeFormatNoSeconds, localtime( <ime ), dateString); - printf("kDateFormatYearMonth, kTimeFormatNoSeconds:\n"); - DebugDump(dateString); - res = t->FormatTMTime(locale, kDateFormatWeekday, kTimeFormatNone, localtime( <ime ), dateString); - printf("kDateFormatWeekday, kTimeFormatNone:\n"); - DebugDump(dateString); - res = t->FormatTMTime(locale, kDateFormatWeekday, kTimeFormatSeconds, localtime( <ime ), dateString); - printf("kDateFormatWeekday, kTimeFormatSeconds:\n"); - DebugDump(dateString); - res = t->FormatTMTime(locale, kDateFormatWeekday, kTimeFormatNoSeconds, localtime( <ime ), dateString); - printf("kDateFormatWeekday, kTimeFormatNoSeconds:\n"); - DebugDump(dateString); - res = t->FormatTMTime(locale, kDateFormatWeekday, kTimeFormatSecondsForce24Hour, localtime( <ime ), dateString); - printf("kDateFormatWeekday, kTimeFormatSecondsForce24Hour:\n"); - DebugDump(dateString); - res = t->FormatTMTime(locale, kDateFormatWeekday, kTimeFormatNoSecondsForce24Hour, localtime( <ime ), dateString); - printf("kDateFormatWeekday, kTimeFormatNoSecondsForce24Hour:\n"); - DebugDump(dateString); - - res = t->Release(); - - printf("==============================\n"); - printf("Finish nsIDateTimeFormat Test \n"); - printf("==============================\n"); -} - -static nsresult NewLocale(const nsString* localeName, nsILocale** locale) -{ - nsresult res; - - nsCOMPtr localeFactory = do_GetClassObject(kLocaleFactoryCID, &res); - if (NS_FAILED(res) || localeFactory == nsnull) printf("FindFactory nsILocaleFactory failed\n"); - - res = localeFactory->NewLocale(localeName, locale); - if (NS_FAILED(res) || locale == nsnull) printf("NewLocale failed\n"); - - return res; -} - -static void Test_nsLocale() -{ -#if defined(XP_MAC) || defined(XP_MACOSX) - nsAutoString localeName; - nsCOMPtr macLocale; - short script, lang; - nsresult res; - - nsCOMPtr win32Locale = do_CreateInstance(kMacLocaleFactoryCID); - if (macLocale) { - localeName.AssignLiteral("en-US"); - res = macLocale->GetPlatformLocale(localeName, &script, &lang); - printf("script for en-US is 0\n"); - printf("result: script = %d lang = %d\n", script, lang); - - localeName.AssignLiteral("en-GB"); - res = macLocale->GetPlatformLocale(localeName, &script, &lang); - printf("script for en-GB is 0\n"); - printf("result: script = %d lang = %d\n", script, lang); - - localeName.AssignLiteral("fr-FR"); - res = macLocale->GetPlatformLocale(localeName, &script, &lang); - printf("script for fr-FR is 0\n"); - printf("result: script = %d lang = %d\n", script, lang); - - localeName.AssignLiteral("de-DE"); - res = macLocale->GetPlatformLocale(localeName, &script, &lang); - printf("script for de-DE is 0\n"); - printf("result: script = %d lang = %d\n", script, lang); - - localeName.AssignLiteral("ja-JP"); - res = macLocale->GetPlatformLocale(localeName, &script, &lang); - printf("script for ja-JP is 1\n"); - printf("result: script = %d lang = %d\n", script, lang); - } -#elif defined(XP_WIN) || defined(XP_OS2) - nsAutoString localeName; - LCID lcid; - nsresult res; - - nsCOMPtr win32Locale = do_CreateInstance(kWin32LocaleFactoryCID); - if (win32Locale) { - localeName.AssignLiteral("en-US"); - res = win32Locale->GetPlatformLocale(localeName, &lcid); - printf("LCID for en-US is 1033\n"); - printf("result: locale = %s LCID = 0x%0.4x %d\n", NS_LossyConvertUTF16toASCII(localeName).get(), lcid, lcid); - - localeName.AssignLiteral("en-GB"); - res = win32Locale->GetPlatformLocale(localeName, &lcid); - printf("LCID for en-GB is 2057\n"); - printf("result: locale = %s LCID = 0x%0.4x %d\n", NS_LossyConvertUTF16toASCII(localeName).get(), lcid, lcid); - - localeName.AssignLiteral("fr-FR"); - res = win32Locale->GetPlatformLocale(localeName, &lcid); - printf("LCID for fr-FR is 1036\n"); - printf("result: locale = %s LCID = 0x%0.4x %d\n", NS_LossyConvertUTF16toASCII(localeName).get(), lcid, lcid); - - localeName.AssignLiteral("de-DE"); - res = win32Locale->GetPlatformLocale(localeName, &lcid); - printf("LCID for de-DE is 1031\n"); - printf("result: locale = %s LCID = 0x%0.4x %d\n", NS_LossyConvertUTF16toASCII(localeName).get(), lcid, lcid); - - localeName.AssignLiteral("ja-JP"); - res = win32Locale->GetPlatformLocale(localeName, &lcid); - printf("LCID for ja-JP is 1041\n"); - printf("result: locale = %s LCID = 0x%0.4x %d\n", NS_LossyConvertUTF16toASCII(localeName).get(), lcid, lcid); - - } -#else - nsAutoString localeName; - char locale[32]; - size_t length = 32; - nsresult res; - - nsCOMPtr posixLocale = do_CreateInstance(kPosixLocaleFactoryCID); - if (posixLocale) { - localeName.AssignLiteral("en-US"); - res = posixLocale->GetPlatformLocale(localeName, locale, length); - printf("result: locale = %s POSIX = %s\n", NS_LossyConvertUTF16toASCII(localeName).get(), locale); - - localeName.AssignLiteral("en-GB"); - res = posixLocale->GetPlatformLocale(localeName, locale, length); - printf("result: locale = %s POSIX = %s\n", NS_LossyConvertUTF16toASCII(localeName).get(), locale); - - localeName.AssignLiteral("fr-FR"); - res = posixLocale->GetPlatformLocale(localeName, locale, length); - printf("result: locale = %s POSIX = %s\n", NS_LossyConvertUTF16toASCII(localeName).get(), locale); - - localeName.AssignLiteral("de-DE"); - res = posixLocale->GetPlatformLocale(localeName, locale, length); - printf("result: locale = %s POSIX = %s\n", NS_LossyConvertUTF16toASCII(localeName).get(), locale); - - localeName.AssignLiteral("ja-JP"); - res = posixLocale->GetPlatformLocale(localeName, locale, length); - printf("result: locale = %s POSIX = %s\n", NS_LossyConvertUTF16toASCII(localeName).get(), locale); - - } - else { - printf("Fail: CreateInstance PosixLocale\n"); - } -#endif -} - -static char* get_option(int argc, char** argv, char* arg) -{ - for (int i = 0; i < argc; i++) { - if (!strcmp(argv[i], arg)) { - NS_ASSERTION((i <= argc && argv[i+1]), "option not specified"); - return argv[i+1]; - } - } - return NULL; -} -static char* find_option(int argc, char** argv, char* arg) -{ - for (int i = 0; i < argc; i++) { - if (!strcmp(argv[i], arg)) { - return argv[i]; - } - } - return NULL; -} - -#ifdef XP_MAC -#define kMaxArgs 16 -static char g_arg_array[kMaxArgs][256]; -static int make_args(char **argv) -{ - int argc = 0; - char *token; - char s[256]; - char seps[] = " ,\t"; - - strcpy(g_arg_array[argc], "LocaleSelfTest"); - argc++; - - printf("%s\ntype option(s) then hit return\n", g_usage); - if (gets(s)) { - token = strtok(s, seps); - while (token != NULL && argc < kMaxArgs) { - strcpy(g_arg_array[argc], token); - argv[argc] = g_arg_array[argc]; - argc++; - token = strtok(NULL, seps); - } - printf("\noptions specified: "); - - for (int i = 0; i < argc; i++) { - printf("%s ", argv[i]); - } - printf("\n"); - } - - return argc; -} -#endif//XP_MAC - -int main(int argc, char** argv) { -#ifdef XP_MAC - char *mac_argv[kMaxArgs]; - argc = make_args(mac_argv); - argv = mac_argv; -#endif//XP_MAC - nsCOMPtr locale; - nsresult res; - - nsCOMPtr localeFactory = do_GetClassObject(kLocaleFactoryCID, &res); - if (NS_FAILED(res) || localeFactory == nsnull) printf("FindFactory nsILocaleFactory failed\n"); - - res = localeFactory->GetApplicationLocale(getter_AddRefs(locale)); - if (NS_FAILED(res) || locale == nsnull) printf("GetApplicationLocale failed\n"); - - // -------------------------------------------- - PRInt32 strength = nsICollation::kCollationCaseInSensitive; - FILE *fp = NULL; - - if (argc == 1) { - TestCollation(locale); - TestSort(locale, nsICollation::kCollationCaseInSensitive, NULL); - TestDateTimeFormat(locale); - } - else { - char *s; - s = find_option(argc, argv, "-h"); - if (s) { - printf(argv[0] << g_usage); - return 0; - } - s = find_option(argc, argv, "-v"); - if (s) { - g_verbose = PR_TRUE; - //test for locale - Test_nsLocale(); - } - s = get_option(argc, argv, "-f"); - if (s) { - fp = fopen(s, "r"); - } - s = get_option(argc, argv, "-o"); - if (s) { - g_outfp = fopen(s, "w"); - } - s = find_option(argc, argv, "-case"); - if (s) { - strength = nsICollation::kCollationCaseSensitive; - } - s = get_option(argc, argv, "-locale"); - if (s) { - nsString localeName(s); - res = NewLocale(localeName, getter_AddRefs(locale)); // reset the locale - } - - // print locale string - nsAutoString localeStr; - locale->GetCategory(NS_LITERAL_STRING("NSILOCALE_COLLATE"), localeStr); - printf("locale setting for collation is "); - DebugDump(localeStr); - locale->GetCategory(NS_LITERAL_STRING("NSILOCALE_TIME"), localeStr); - printf("locale setting for time is "); - DebugDump(localeStr); - - while (argc--) { - if (!strcmp(argv[argc], "-col")) - TestCollation(locale); - else if (!strcmp(argv[argc], "-sort")) - TestSort(locale, strength, fp); - else if (!strcmp(argv[argc], "-date")) - TestDateTimeFormat(locale); - } - if (fp != NULL) { - fclose(fp); - } - if (g_outfp != NULL) { - fclose(g_outfp); - } - } - - // -------------------------------------------- - - printf("Finish All The Test Cases\n"); - - return 0; -} diff --git a/mozilla/intl/locale/tests/nsLocaleTest.cpp b/mozilla/intl/locale/tests/nsLocaleTest.cpp deleted file mode 100644 index e5375871f17..00000000000 --- a/mozilla/intl/locale/tests/nsLocaleTest.cpp +++ /dev/null @@ -1,966 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ -#include -#include "nsILocale.h" -#include "nsILocaleFactory.h" -#include "nsLocaleCID.h" -#include "nsIComponentManager.h" -#include "nsILocaleService.h" - -#if defined(XP_WIN) || defined(XP_OS2) -#include "nsIWin32Locale.h" -#include -#endif -#ifdef XP_UNIX -#include "nsIPosixLocale.h" -#endif -#ifdef XP_MAC -#include "nsIMacLocale.h" -#endif - -NS_DEFINE_CID(kLocaleFactoryCID, NS_LOCALEFACTORY_CID); -NS_DEFINE_IID(kILocaleFactoryIID, NS_ILOCALEFACTORY_IID); -NS_DEFINE_IID(kILocaleServiceIID,NS_ILOCALESERVICE_IID); -NS_DEFINE_CID(kLocaleServiceCID,NS_LOCALESERVICE_CID); -NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID); -NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); - -#if defined(XP_WIN) || defined(XP_OS2) -NS_DEFINE_CID(kWin32LocaleFactoryCID, NS_WIN32LOCALEFACTORY_CID); -NS_DEFINE_IID(kIWin32LocaleIID, NS_IWIN32LOCALE_IID); - -#define USER_DEFINED_PRIMARYLANG 0x0200 -#define USER_DEFINED_SUBLANGUAGE 0x20 - -#endif -#ifdef XP_UNIX -NS_DEFINE_CID(kPosixLocaleFactoryCID, NS_POSIXLOCALEFACTORY_CID); -NS_DEFINE_IID(kIPosixLocaleIID, NS_IPOSIXLOCALE_IID); -#endif -#ifdef XP_MAC -NS_DEFINE_CID(kMacLocaleFactoryCID, NS_MACLOCALEFACTORY_CID); -NS_DEFINE_IID(kIMacLocaleIID, NS_IMACLOCALE_IID); -#endif - -char* localeCategoryList[6] = { "NSILOCALE_TIME", - "NSILOCALE_COLLATE", - "NSILOCALE_CTYPE", - "NSILOCALE_MONETARY", - "NSILOCALE_MESSAGES", - "NSILOCALE_NUMERIC" -}; - -void -serivce_create_interface(void) -{ - nsresult result; - nsILocaleService* localeService; - - result = CallCreateInstance(kLocaleServiceCID, &localeService); - NS_ASSERTION(localeService!=NULL,"nsLocaleTest: service_create_interface failed."); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: service_create_interface failed"); - - localeService->Release(); -} - -void -factory_create_interface(void) -{ - nsresult result; - nsILocaleFactory* localeFactory; - nsIFactory* genericFactory; - - result = CallCreateInstance(kLocaleFactoryCID, &localeFactory); - NS_ASSERTION(localeFactory!=NULL,"nsLocaleTest: factory_create_interface failed."); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_create_interface failed"); - - localeFactory->Release(); - - result = CallCreateInstance(kLocaleFactoryCID, &genericFactory); - NS_ASSERTION(localeFactory!=NULL,"nsLocaleTest: factory_create_interface failed."); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_create_interface failed"); - - genericFactory->Release(); -} - -void -factory_test_isupports(void) -{ - nsresult result; - nsCOMPtr localeFactory; - nsCOMPtr genericInterface1, genericInterface2; - nsCOMPtr genericFactory1, genericFactory2; - - localeFactory = do_GetClassObject(kLocaleFactoryCID, &result); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_create_interface failed"); - - // - // test generic interface - // - result = localeFactory->QueryInterface(kISupportsIID, getter_AddRefs(genericInterface1)); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_test_isupports failed."); - - result = localeFactory->QueryInterface(kISupportsIID, getter_AddRefs(genericInterface2)); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_test_isupports failed."); - NS_ASSERTION(genericInterface1==genericInterface2,"nsLocaleTest: factory_test_isupports failed."); - - // - // test generic factory - // - result = localeFactory->QueryInterface(kIFactoryIID, getter_AddRefs(genericFactory1)); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_test_isupports failed."); - - result = localeFactory->QueryInterface(kIFactoryIID, getter_AddRefs(genericFactory2)); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_test_isupports failed."); - NS_ASSERTION(genericFactory1==genericFactory2,"nsLocaleTest: factory_test_isupports failed."); - -} - -void -factory_new_locale(void) -{ - nsresult result; - nsCOMPtr localeFactory; - nsCOMPtr locale; - nsString* *category, *value; - int i; - nsString** categoryList, **valueList; - PRUnichar *lc_name_unichar; - - localeFactory = do_GetClassObject(kLocaleFactoryCID, &result); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_create_interface failed"); - - - // - // test NewLocale - // - nsAutoString localeName(NS_LITERALSTRING("ja-JP")); - result = localeFactory->NewLocale(localeName, getter_AddRefs(locale)); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_new_interface failed"); - NS_ASSERTION(locale!=NULL,"nsLocaleTest: factory_new_interface failed"); - - for(i=0;i<6;i++) - { - category = new nsString(localeCategoryList[i]); - value = new nsString(); - - result = locale->GetCategory(category, &lc_name_unichar); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_new_interface failed"); - - value->SetString(lc_name_unichar); - delete category; - delete value; - } - - categoryList = new nsStringArray(6); - valueList = new nsStringArray(6); - - for(i=0;i<6;i++) - { - categoryList.InsertStringAt(localeCategoryList[i], i); - valueList[i] = InsertStringAt(NS_LITERAL_STRING("x-netscape"), i); - } - - result = localeFactory->NewLocale(categoryList,valueList,6,&locale); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_new_interface failed"); - NS_ASSERTION(locale!=NULL,"nsLocaleTest: factory_new_interface failed"); - - for(i=0;i<6;i++) - { - value = new nsString(); - result = locale->GetCategory(categoryList[i], &lc_name_unichar); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_new_interface failed"); - - value->SetString(lc_name_unichar); - delete value; - } - - for(i=0;i<6;i++) - { - delete categoryList.RemoveStringAt(i); - delete valueList.RemoveStringAt(i); - } - - delete categoryList; - delete valueList; -} - - -void -factory_get_locale(void) -{ - nsresult result; - nsCOMPtr localeFactory; - nsCOMPtr locale; - nsString* category; - nsString* value; - const char* acceptLangString = "ja;q=0.9,en;q=1.0,*"; - PRUnichar *lc_name_unichar; - - localeFactory = do_GetClassObject(kLocaleFactoryCID, &result); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_create_interface failed"); - - // - // get the application locale - // - result = localeFactory->GetApplicationLocale(getter_AddRefs(locale)); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_get_locale failed"); - - // - // test and make sure the locale is a valid Interface - // - locale->AddRef(); - - category = new nsString("NSILOCALE_CTYPE"); - value = new nsString(); - - result = locale->GetCategory(category, &lc_name_unichar); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_get_locale failed"); - - value->SetString(lc_name_unichar); - - delete category; - delete value; - - // - // test GetSystemLocale - // - result = localeFactory->GetSystemLocale(getter_AddRefs(locale)); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_get_locale failed"); - NS_ASSERTION(locale!=NULL,"nsLocaleTest: factory_get_locale failed"); - - // - // test and make sure the locale is a valid Interface - // - - category = new nsString("NSILOCALE_CTYPE"); - value = new nsString(); - - result = locale->GetCategory(category->get(),&lc_name_unichar); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_get_locale failed"); - - value->SetString(lc_name_unichar); - - delete category; - delete value; - - // - // test GetLocaleFromAcceptLanguage - // - result = localeFactory->GetLocaleFromAcceptLanguage(acceptLangString,getter_AddRefs(locale)); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_get_locale failed"); - - // - // test and make sure the locale is a valid Interface - // - category = new nsString("NSILOCALE_CTYPE"); - value = new nsString(); - - result = locale->GetCategory(category, &lc_name_unichar); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_get_locale failed"); - - value->SetString(lc_name_unichar); - - delete category; - delete value; - -} - - -#if defined(XP_WIN) || defined(XP_OS2) - -void -win32factory_create_interface(void) -{ - nsresult result; - nsIFactory* factory; - nsIWin32Locale* win32Locale; - - result = CallCreateInstance(kWin32LocaleFactoryCID, &factory); - NS_ASSERTION(factory!=NULL,"nsLocaleTest: factory_create_interface failed."); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_create_interface failed"); - - factory->Release(); - - result = CallCreateInstance(kWin32LocaleFactoryCID, &win32Locale); - NS_ASSERTION(win32Locale!=NULL,"nsLocaleTest: factory_create_interface failed."); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_create_interface failed"); - - win32Locale->Release(); -} - -void -win32locale_test(void) -{ - nsresult result; - nsIWin32Locale* win32Locale; - nsAutoString locale; - LCID loc_id; - - // - // test with a simple locale - // - locale.AssignLiteral("en-US"); - loc_id = 0; - - result = CallCreateInstance(kWin32LocaleFactoryCID, &win32Locale); - NS_ASSERTION(win32Locale!=NULL,"nsLocaleTest: factory_create_interface failed."); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_create_interface failed"); - - result = win32Locale->GetPlatformLocale(locale,&loc_id); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed."); - NS_ASSERTION(loc_id==MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT), - "nsLocaleTest: GetPlatformLocale failed."); - - - // - // test with a not so simple locale - // - locale.AssignLiteral("x-netscape"); - loc_id = 0; - - result = win32Locale->GetPlatformLocale(locale,&loc_id); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed."); - NS_ASSERTION(loc_id==MAKELCID(MAKELANGID(USER_DEFINED_PRIMARYLANG,USER_DEFINED_SUBLANGUAGE),SORT_DEFAULT), - "nsLocaleTest: GetPlatformLocale failed."); - - - locale.AssignLiteral("en"); - loc_id = 0; - - result = win32Locale->GetPlatformLocale(locale,&loc_id); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed."); - NS_ASSERTION(loc_id==MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_DEFAULT),SORT_DEFAULT), - "nsLocaleTest: GetPlatformLocale failed."); - - win32Locale->Release(); -} - -void -win32locale_conversion_test(void) -{ - nsresult result; - nsIWin32Locale* win32Locale; - nsString* locale; - LCID loc_id; - - result = CallCreateInstance(kWin32LocaleFactoryCID, &win32Locale); - NS_ASSERTION(win32Locale!=NULL,"nsLocaleTest: factory_create_interface failed."); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_create_interface failed"); - - // - // check english variants - // - locale.AssignLiteral("en"); // generic english - loc_id = 0; - - result = win32Locale->GetPlatformLocale(locale,&loc_id); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed."); - NS_ASSERTION(loc_id==MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_DEFAULT),SORT_DEFAULT), - "nsLocaleTest: GetPlatformLocale failed."); - - locale.AssignLiteral("en-US"); // US english - loc_id = 0; - - result = win32Locale->GetPlatformLocale(locale,&loc_id); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed."); - NS_ASSERTION(loc_id==MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT), - "nsLocaleTest: GetPlatformLocale failed."); - - locale.AssignLiteral("en-GB"); // UK english - loc_id = 0; - - result = win32Locale->GetPlatformLocale(locale,&loc_id); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed."); - NS_ASSERTION(loc_id==MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_UK),SORT_DEFAULT), - "nsLocaleTest: GetPlatformLocale failed."); - - locale.AssignLiteral("en-CA"); // Canadian english - loc_id = 0; - - result = win32Locale->GetPlatformLocale(locale,&loc_id); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed."); - NS_ASSERTION(loc_id==MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_CAN),SORT_DEFAULT), - "nsLocaleTest: GetPlatformLocale failed."); - - // - // japanese - // - locale.AssignLiteral("ja"); - loc_id = 0; - - result = win32Locale->GetPlatformLocale(locale,&loc_id); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed."); - NS_ASSERTION(loc_id==MAKELCID(MAKELANGID(LANG_JAPANESE,SUBLANG_DEFAULT),SORT_DEFAULT), - "nsLocaleTest: GetPlatformLocale failed."); - - locale.AssignLiteral("ja-JP"); - loc_id = 0; - - result = win32Locale->GetPlatformLocale(locale,&loc_id); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed."); - NS_ASSERTION(loc_id==MAKELCID(MAKELANGID(LANG_JAPANESE,SUBLANG_DEFAULT),SORT_DEFAULT), - "nsLocaleTest: GetPlatformLocale failed."); - - // - // chinese Locales - // - locale.AssignLiteral("zh"); - loc_id = 0; - - result = win32Locale->GetPlatformLocale(locale,&loc_id); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed."); - NS_ASSERTION(loc_id==MAKELCID(MAKELANGID(LANG_CHINESE,SUBLANG_DEFAULT),SORT_DEFAULT), - "nsLocaleTest: GetPlatformLocale failed."); - - locale.AssignLiteral("zh-CN"); - loc_id = 0; - - result = win32Locale->GetPlatformLocale(locale,&loc_id); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed."); - NS_ASSERTION(loc_id==MAKELCID(MAKELANGID(LANG_CHINESE,SUBLANG_CHINESE_SIMPLIFIED),SORT_DEFAULT), - "nsLocaleTest: GetPlatformLocale failed."); - - locale.AssignLiteral("zh-TW"); - loc_id = 0; - - result = win32Locale->GetPlatformLocale(locale,&loc_id); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed."); - NS_ASSERTION(loc_id==MAKELCID(MAKELANGID(LANG_CHINESE,SUBLANG_CHINESE_TRADITIONAL),SORT_DEFAULT), - "nsLocaleTest: GetPlatformLocale failed."); - - // - // german and variants - // - locale.AssignLiteral("de"); - loc_id = 0; - - result = win32Locale->GetPlatformLocale(locale,&loc_id); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed."); - NS_ASSERTION(loc_id==MAKELCID(MAKELANGID(LANG_GERMAN,SUBLANG_DEFAULT),SORT_DEFAULT), - "nsLocaleTest: GetPlatformLocale failed."); - - locale.AssignLiteral("de-DE"); - loc_id = 0; - - result = win32Locale->GetPlatformLocale(locale,&loc_id); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed."); - NS_ASSERTION(loc_id==MAKELCID(MAKELANGID(LANG_GERMAN,SUBLANG_GERMAN),SORT_DEFAULT), - "nsLocaleTest: GetPlatformLocale failed."); - - locale.AssignLiteral("de-AT"); - loc_id = 0; - - result = win32Locale->GetPlatformLocale(locale,&loc_id); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed."); - NS_ASSERTION(loc_id==MAKELCID(MAKELANGID(LANG_GERMAN,SUBLANG_GERMAN_AUSTRIAN),SORT_DEFAULT), - "nsLocaleTest: GetPlatformLocale failed."); - - // - // french and it's variants - // - locale.AssignLiteral("fr"); - loc_id = 0; - - result = win32Locale->GetPlatformLocale(locale,&loc_id); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed."); - NS_ASSERTION(loc_id==MAKELCID(MAKELANGID(LANG_FRENCH,SUBLANG_DEFAULT),SORT_DEFAULT), - "nsLocaleTest: GetPlatformLocale failed."); - - locale.AssignLiteral("fr-FR"); - loc_id = 0; - - result = win32Locale->GetPlatformLocale(locale,&loc_id); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed."); - NS_ASSERTION(loc_id==MAKELCID(MAKELANGID(LANG_FRENCH,SUBLANG_FRENCH),SORT_DEFAULT), - "nsLocaleTest: GetPlatformLocale failed."); - - locale.AssignLiteral("fr-CA"); - loc_id = 0; - - result = win32Locale->GetPlatformLocale(locale,&loc_id); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed."); - NS_ASSERTION(loc_id==MAKELCID(MAKELANGID(LANG_FRENCH,SUBLANG_FRENCH_CANADIAN),SORT_DEFAULT), - "nsLocaleTest: GetPlatformLocale failed."); - - // - // delete the XPCOM inteface - // - win32Locale->Release(); -} - -void -win32locale_reverse_conversion_test(void) -{ - nsresult result; - nsIWin32Locale* win32Locale; - - result = CallCreateInstance(kWin32LocaleFactoryCID, &win32Locale); - NS_ASSERTION(win32Locale!=NULL,"nsLocaleTest: factory_create_interface failed."); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_create_interface failed"); - - // - // english and variants - // - win32Locale->Release(); -} - -void -win32_test_special_locales(void) -{ - nsresult result; - nsCOMPtr win32Locale; - nsCOMPtr xp_locale_factory; - nsCOMPtr xp_locale; - nsString* locale, *result_locale, *category; - LCID sys_lcid, user_lcid; - PRUnichar *lc_name_unichar; - - win32Locale = do_CreateInstance(kWin32LocaleFactoryCID, &result); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_create_interface failed"); - - xp_locale_factory = do_GetClassObject(kLocaleFactoryCID, &result); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_create_interface failed"); - - category = new nsString(localeCategoryList[0]); - - // - // derive a system locale - // - result = xp_locale_factory->GetSystemLocale(getter_AddRefs(xp_locale)); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_create_interface failed"); - - sys_lcid = GetSystemDefaultLCID(); - locale = new nsString(); - result_locale = new nsString(); - - result = win32Locale->GetXPLocale(sys_lcid,locale); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_create_interface failed"); - result = xp_locale->GetCategory(category, &lc_name_unichar); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_create_interface failed"); - - result_locale->SetString(lc_name_unichar); - delete result_locale; - - // - // derive a system locale - // - result = xp_locale_factory->GetApplicationLocale(getter_AddRefs(xp_locale)); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_create_interface failed"); - - user_lcid = GetUserDefaultLCID(); - locale = new nsString(); - result_locale = new nsString(); - - result = win32Locale->GetXPLocale(user_lcid,locale); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_create_interface failed"); - result = xp_locale->GetCategory(category, &lc_name_unichar); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_create_interface failed"); - - result_locale->SetString(lc_name_unichar); - delete result_locale; - - delete category; - -} - -#endif - -#ifdef XP_UNIX -void -posixfactory_create_interface(void) -{ - nsresult result; - nsIFactory* factory; - nsIPosixLocale* posix_locale; - - result = CallCreateInstance(kPosixLocaleFactoryCID, &factory); - NS_ASSERTION(factory!=NULL,"nsLocaleTest: factory_create_interface failed."); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_create_interface failed"); - - factory->Release(); - - result = CallCreateInstance(kPosixLocaleFactoryCID, &posix_locale); - NS_ASSERTION(posix_locale!=NULL,"nsLocaleTest: factory_create_interface failed."); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_create_interface failed"); - - posix_locale->Release(); -} - -void -posixlocale_test(void) -{ - nsresult result; - nsIPosixLocale* posix_locale; - nsAutoString locale; - char posix_locale_string[9]; - - // - // create the locale object - // - result = CallCreateInstance(kPosixLocaleFactoryCID, &posix_locale); - NS_ASSERTION(posix_locale!=NULL,"nsLocaleTest: create interface failed.\n"); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: create interface failed\n"); - - // - // test with a simple locale - // - locale.AssignLiteral("en-US"); - result = posix_locale->GetPlatformLocale(locale,posix_locale_string,9); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed.\n"); - NS_ASSERTION(strcmp("en_US",posix_locale_string)==0,"nsLocaleTest: GetPlatformLocale failed.\n"); - - // - // test with a not so simple locale - // - locale.AssignLiteral("x-netscape"); - result = posix_locale->GetPlatformLocale(locale,posix_locale_string,9); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed.\n"); - NS_ASSERTION(strcmp("C",posix_locale_string)==0,"nsLocaleTest: GetPlatformLocale failed.\n"); - - // - // test with a generic locale - // - locale.AssignLiteral("en"); - result = posix_locale->GetPlatformLocale(locale,posix_locale_string,9); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed.\n"); - NS_ASSERTION(strcmp("en",posix_locale_string)==0,"nsLocaleTest: GetPlatformLocale failed.\n"); - - - // - // release the locale interface - // - posix_locale->Release(); -} - -void -posixlocale_conversion_test() -{ - nsresult result; - nsIPosixLocale* posix_locale; - nsString* locale; - char posix_locale_result[9]; - - result = CallCreateInstance(kPosixLocaleFactoryCID, &posix_locale); - NS_ASSERTION(posix_locale!=NULL,"nsLocaleTest: factory_create_interface failed."); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_create_interface failed"); - - // - // check english variants - // - locale.AssignLiteral("en"); // generic english - result = posix_locale->GetPlatformLocale(locale,posix_locale_result,9); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed."); - NS_ASSERTION(strcmp("en",posix_locale_result)==0,"nsLocaleTest: GetPlatformLocale failed.\n"); - - locale.AssignLiteral("en-US"); // US english - result = posix_locale->GetPlatformLocale(locale,posix_locale_result,9); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed."); - NS_ASSERTION(strcmp("en_US",posix_locale_result)==0,"nsLocaleTest: GetPlatformLocale failed.\n"); - - locale.AssignLiteral("en-GB"); // UK english - result = posix_locale->GetPlatformLocale(locale,posix_locale_result,9); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed."); - NS_ASSERTION(strcmp("en_GB",posix_locale_result)==0,"nsLocaleTest: GetPlatformLocale failed.\n"); - - locale.AssignLiteral("en-CA"); // Canadian english - result = posix_locale->GetPlatformLocale(locale,posix_locale_result,9); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed."); - NS_ASSERTION(strcmp("en_CA",posix_locale_result)==0,"nsLocaleTest: GetPlatformLocale failed.\n"); - - // - // japanese - // - locale.AssignLiteral("ja"); - result = posix_locale->GetPlatformLocale(locale,posix_locale_result,9); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed."); - NS_ASSERTION(strcmp("ja",posix_locale_result)==0,"nsLocaleTest: GetPlatformLocale failed.\n"); - - locale.AssignLiteral("ja-JP"); - result = posix_locale->GetPlatformLocale(locale,posix_locale_result,9); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed."); - NS_ASSERTION(strcmp("ja_JP",posix_locale_result)==0,"nsLocaleTest: GetPlatformLocale failed.\n"); - - // - // chinese Locales - // - locale.AssignLiteral("zh"); - result = posix_locale->GetPlatformLocale(locale,posix_locale_result,9); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed."); - NS_ASSERTION(strcmp("zh",posix_locale_result)==0,"nsLocaleTest: GetPlatformLocale failed.\n"); - - locale.AssignLiteral("zh-CN"); - result = posix_locale->GetPlatformLocale(locale,posix_locale_result,9); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed."); - NS_ASSERTION(strcmp("zh_CN",posix_locale_result)==0,"nsLocaleTest: GetPlatformLocale failed.\n"); - - locale.AssignLiteral("zh-TW"); - result = posix_locale->GetPlatformLocale(locale,posix_locale_result,9); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed."); - NS_ASSERTION(strcmp("zh_TW",posix_locale_result)==0,"nsLocaleTest: GetPlatformLocale failed.\n"); - - // - // german and variants - // - locale.AssignLiteral("de"); - result = posix_locale->GetPlatformLocale(locale,posix_locale_result,9); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed."); - NS_ASSERTION(strcmp("de",posix_locale_result)==0,"nsLocaleTest: GetPlatformLocale failed.\n"); - - locale.AssignLiteral("de-DE"); - result = posix_locale->GetPlatformLocale(locale,posix_locale_result,9); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed."); - NS_ASSERTION(strcmp("de_DE",posix_locale_result)==0,"nsLocaleTest: GetPlatformLocale failed.\n"); - - locale.AssignLiteral("de-AT"); - result = posix_locale->GetPlatformLocale(locale,posix_locale_result,9); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed."); - NS_ASSERTION(strcmp("de_AT",posix_locale_result)==0,"nsLocaleTest: GetPlatformLocale failed.\n"); - - // - // french and it's variants - // - locale.AssignLiteral("fr"); - result = posix_locale->GetPlatformLocale(locale,posix_locale_result,9); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed."); - NS_ASSERTION(strcmp("fr",posix_locale_result)==0,"nsLocaleTest: GetPlatformLocale failed.\n"); - - locale.AssignLiteral("fr-FR"); - result = posix_locale->GetPlatformLocale(locale,posix_locale_result,9); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed."); - NS_ASSERTION(strcmp("fr_FR",posix_locale_result)==0,"nsLocaleTest: GetPlatformLocale failed.\n"); - - locale.AssignLiteral("fr-CA"); - result = posix_locale->GetPlatformLocale(locale,posix_locale_result,9); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed."); - NS_ASSERTION(strcmp("fr_CA",posix_locale_result)==0,"nsLocaleTest: GetPlatformLocale failed.\n"); - - // - // delete the XPCOM inteface - // - posix_locale->Release(); -} - -void -posixlocale_reverse_conversion_test() -{ - nsresult result; - nsIPosixLocale* posix_locale; - nsAutoString locale; - - // - // create the locale object - // - result = CallCreateInstance(kPosixLocaleFactoryCID, &posix_locale); - NS_ASSERTION(posix_locale!=NULL,"nsLocaleTest: create interface failed.\n"); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: create interface failed\n"); - - // - // test with a simple locale - // - result = posix_locale->GetXPLocale("en_US",locale); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetXPLocale failed.\n"); - NS_ASSERTION(locale.EqualsLiteral("en-US"),"nsLocaleTest: GetXPLocale failed.\n"); - - result = posix_locale->GetXPLocale("C",locale); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetXPLocale failed.\n"); - NS_ASSERTION(locale.EqualsLiteral("en"),"nsLocaleTest: GetXPLocale failed.\n"); - - result = posix_locale->GetXPLocale("en",locale); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetXPLocale failed.\n"); - NS_ASSERTION(locale.EqualsLiteral("en"),"nsLocaleTest: GetXPLocale failed.\n"); - - posix_locale->Release(); - -} - -void -posixlocale_test_special(void) -{ - nsresult result; - nsCOMPtr xp_factory; - nsCOMPtr xp_locale; - const PRUnichar *lc_name_unichar; - nsString* locale, *result_locale; - nsString* lc_message; - - // - // create the locale objects - // - xp_factory = do_GetClassObject(kLocaleFactoryCID, &result); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_create_interface failed"); - - // - // settup strings - // - locale.AssignLiteral("en"); - result_locale = new nsString(); - lc_message = new nsString("NSILOCALE_MESSAGES"); - - // - // test GetSystemLocale - // - result = xp_factory->GetSystemLocale(getter_AddRefs(xp_locale)); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetSystemLocale failed.\n"); - - result = xp_locale->GetCategory(lc_message, &lc_name_unichar); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetSystemLocale failed.\n"); - - result_locale->SetString(lc_name_unichar); - - result = xp_factory->GetApplicationLocale(getter_AddRefs(xp_locale)); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetApplicationLocale failed.\n"); - - - result = xp_locale->GetCategory(lc_message, &lc_name_unichar); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetSystemLocale failed.\n"); - result_locale->SetString(lc_name_unichar); - - // - // delete strings - // - delete result_locale; - delete lc_message; - - -} - -#endif - -#ifdef XP_MAC - -void -macfactory_create_interface(void) -{ - nsresult result; - nsIFactory* factory; - nsIMacLocale* mac_locale; - - result = CallCreateInstance(kMacLocaleFactoryCID, &factory); - NS_ASSERTION(factory!=NULL,"nsLocaleTest: factory_create_interface failed."); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_create_interface failed"); - - factory->Release(); - - result = CallCreateInstance(kMacLocaleFactoryCID, &mac_locale); - NS_ASSERTION(posix_locale!=NULL,"nsLocaleTest: factory_create_interface failed."); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_create_interface failed"); - - mac_locale->Release(); -} - -void -maclocale_test(void) -{ - nsresult result; - nsIMacLocale* mac_locale; - nsString* locale; - short script_code; - - // - // create the locale object - // - result = CallCreateInstance(kMacLocaleFactoryCID, &mac_locale); - NS_ASSERTION(posix_locale!=NULL,"nsLocaleTest: create interface failed.\n"); - NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: create interface failed\n"); - - // - // release the locale interface - // - mac_locale->Release(); -} - - -#endif - -int -main(int argc, char** argv) -{ - - // - // what are we doing? - // - printf("Starting nsLocaleTest\n"); - printf("---------------------\n"); - printf("This test has completed successfully if no error messages are printed.\n"); - - // - // run the nsILocaleFactory tests (nsILocale gets tested in the prcoess) - // - factory_create_interface(); - factory_get_locale(); - factory_new_locale(); - -#if defined(XP_WIN) || defined(XP_OS2) - - // - // run the nsIWin32LocaleFactory tests - // - win32factory_create_interface(); - win32locale_test(); - win32locale_conversion_test(); - win32locale_reverse_conversion_test(); - win32_test_special_locales(); -#elif defined(XP_UNIX) - - // - // do the younicks tests - // - posixfactory_create_interface(); - posixlocale_test(); - posixlocale_conversion_test(); - posixlocale_reverse_conversion_test(); - posixlocale_test_special(); - -#elif defined(XP_MAC) - - // - // do the Mac specific tests - // - macfactory_create_interface(); - maclocale_test(); - -#endif - - // - // we done - // - printf("---------------------\n"); - printf("Finished nsLocaleTest\n"); - - return 0; -}