2000-01-15 02:00:06 +00:00
|
|
|
/********************************************************************
|
|
|
|
* COPYRIGHT:
|
|
|
|
* Copyright (c) 1997-1999, International Business Machines Corporation and
|
|
|
|
* others. All Rights Reserved.
|
|
|
|
********************************************************************/
|
|
|
|
/********************************************************************************
|
1999-08-16 21:50:52 +00:00
|
|
|
*
|
|
|
|
* File CLOCTST.C
|
|
|
|
*
|
|
|
|
* Modification History:
|
|
|
|
* Name Description
|
1999-10-18 22:48:32 +00:00
|
|
|
* Madhu Katragadda Ported for C API
|
1999-08-16 21:50:52 +00:00
|
|
|
*********************************************************************************
|
|
|
|
*/
|
2000-08-28 21:43:03 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/utypes.h"
|
|
|
|
#include "unicode/utypes.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
#include "cloctst.h"
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/uloc.h"
|
|
|
|
#include "unicode/ustring.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
#include "cintltst.h"
|
2000-03-22 01:57:16 +00:00
|
|
|
#include "ccolltst.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
void PrintDataTable();
|
|
|
|
|
2000-08-14 23:35:57 +00:00
|
|
|
/*---------------------------------------------------
|
|
|
|
table of valid data
|
|
|
|
--------------------------------------------------- */
|
2000-12-15 19:16:43 +00:00
|
|
|
#define LOCALE_SIZE 5
|
|
|
|
#define LOCALE_INFO_SIZE 23
|
2000-08-14 23:35:57 +00:00
|
|
|
|
2000-12-15 19:16:43 +00:00
|
|
|
static const char* rawData2[LOCALE_INFO_SIZE][LOCALE_SIZE] = {
|
2000-08-14 23:35:57 +00:00
|
|
|
/* language code */
|
|
|
|
{ "en", "fr", "hr", "el", "no" },
|
|
|
|
/* country code */
|
|
|
|
{ "US", "FR", "HR", "GR", "NO" },
|
|
|
|
/* variant code */
|
|
|
|
{ "", "", "", "", "NY" },
|
|
|
|
/* full name */
|
|
|
|
{ "en_US", "fr_FR", "hr_HR", "el_GR", "no_NO_NY" },
|
|
|
|
/* ISO-3 language */
|
|
|
|
{ "eng", "fra", "hrv", "ell", "nor" },
|
|
|
|
/* ISO-3 country */
|
|
|
|
{ "USA", "FRA", "HRV", "GRC", "NOR" },
|
|
|
|
/* LCID (not currently public) */
|
|
|
|
{ "409", "40c", "41a", "408", "814" },
|
|
|
|
|
|
|
|
/* display langage (English) */
|
|
|
|
{ "English", "French", "Croatian", "Greek", "Norwegian" },
|
|
|
|
/* display country (English) */
|
|
|
|
{ "United States", "France", "Croatia", "Greece", "Norway" },
|
|
|
|
/* display variant (English) */
|
|
|
|
{ "", "", "", "", "Nynorsk" },
|
|
|
|
/* display name (English) */
|
|
|
|
{ "English (United States)", "French (France)", "Croatian (Croatia)", "Greek (Greece)", "Norwegian (Norway, Nynorsk)" },
|
|
|
|
|
|
|
|
/* display langage (French) */
|
2000-10-30 21:05:32 +00:00
|
|
|
{ "anglais", "fran\\u00E7ais", "croate", "grec", "norv\\u00E9gien" },
|
2000-08-14 23:35:57 +00:00
|
|
|
/* display country (French) */
|
2000-10-30 21:05:32 +00:00
|
|
|
{ "\\u00C9tats-Unis", "France", "Croatie", "Gr\\u00E8ce", "Norv\\u00E8ge" },
|
2000-08-14 23:35:57 +00:00
|
|
|
/* display variant (French) */
|
|
|
|
{ "", "", "", "", "Nynorsk" },
|
|
|
|
/* display name (French) */
|
2000-10-30 21:05:32 +00:00
|
|
|
{ "anglais (\\u00C9tats-Unis)", "fran\\u00E7ais (France)", "croate (Croatie)", "grec (Gr\\u00E8ce)", "norv\\u00E9gien (Norv\\u00E8ge, Nynorsk)" },
|
2000-08-14 23:35:57 +00:00
|
|
|
|
|
|
|
/* display langage (Croatian) */
|
2000-12-15 19:16:43 +00:00
|
|
|
{ "", "", "hrvatski", "", "" },
|
|
|
|
/* display country (Croatian) */
|
|
|
|
{ "", "", "Hrvatska", "", "" },
|
2000-08-14 23:35:57 +00:00
|
|
|
/* display variant (Croatian) */
|
2000-12-15 19:16:43 +00:00
|
|
|
{ "", "", "", "", "" },
|
2000-08-14 23:35:57 +00:00
|
|
|
/* display name (Croatian) */
|
|
|
|
{ "", "", "hrvatski (Hrvatska)", "", "" },
|
|
|
|
|
2000-12-15 19:16:43 +00:00
|
|
|
/* display langage (Greek) */
|
|
|
|
{ "", "", "", "\\u03b5\\u03bb\\u03bb\\u03b7\\u03bd\\u03b9\\u03ba\\u03ac", "" },
|
|
|
|
/* display country (Greek) */
|
|
|
|
{ "", "", "", "\\u0395\\u03bb\\u03bb\\u03ac\\u03b4\\u03b1", "" },
|
2000-08-14 23:35:57 +00:00
|
|
|
/* display variant (Greek) */
|
2000-12-15 19:16:43 +00:00
|
|
|
{ "", "", "", "", "" },
|
|
|
|
/* display name (Greek) */
|
|
|
|
{ "", "", "", "\\u03b5\\u03bb\\u03bb\\u03b7\\u03bd\\u03b9\\u03ba\\u03ac (\\u0395\\u03bb\\u03bb\\u03ac\\u03b4\\u03b1)", "" }
|
2000-08-14 23:35:57 +00:00
|
|
|
};
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
static UChar*** dataTable=0;
|
|
|
|
enum {
|
|
|
|
ENGLISH = 0,
|
|
|
|
FRENCH = 1,
|
|
|
|
CROATIAN = 2,
|
|
|
|
GREEKS = 3,
|
|
|
|
NORWEGIAN = 4,
|
|
|
|
MAX_LOCALES = 4
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
LANG = 0,
|
|
|
|
CTRY = 1,
|
|
|
|
VAR = 2,
|
|
|
|
NAME = 3,
|
|
|
|
LANG3 = 4,
|
|
|
|
CTRY3 = 5,
|
|
|
|
LCID = 6,
|
|
|
|
DLANG_EN = 7,
|
|
|
|
DCTRY_EN = 8,
|
|
|
|
DVAR_EN = 9,
|
|
|
|
DNAME_EN = 10,
|
|
|
|
DLANG_FR = 11,
|
|
|
|
DCTRY_FR = 12,
|
|
|
|
DVAR_FR = 13,
|
|
|
|
DNAME_FR = 14,
|
|
|
|
DLANG_HR = 15,
|
|
|
|
DCTRY_HR = 16,
|
|
|
|
DVAR_HR = 17,
|
|
|
|
DNAME_HR = 18,
|
|
|
|
DLANG_EL = 19,
|
|
|
|
DCTRY_EL = 20,
|
|
|
|
DVAR_EL = 21,
|
|
|
|
DNAME_EL = 22
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void addLocaleTest(TestNode** root)
|
|
|
|
{
|
2000-06-22 17:39:34 +00:00
|
|
|
addTest(root, &TestBasicGetters, "tsutil/cloctst/TestBasicGetters");
|
|
|
|
addTest(root, &TestSimpleResourceInfo, "tsutil/cloctst/TestSimpleResourceInfo");
|
|
|
|
addTest(root, &TestDisplayNames, "tsutil/cloctst/TestDisplayNames");
|
|
|
|
addTest(root, &TestGetAvailableLocales, "tsutil/cloctst/TestGetAvailableLocales");
|
|
|
|
addTest(root, &TestDataDirectory, "tsutil/cloctst/TestDataDirectory");
|
|
|
|
addTest(root, &TestISOFunctions, "tsutil/cloctst/TestISOFunctions");
|
|
|
|
addTest(root, &TestISO3Fallback, "tsutil/cloctst/TestISO3Fallback");
|
|
|
|
addTest(root, &TestUninstalledISO3Names, "tsutil/cloctst/TestUninstalledISO3Names");
|
|
|
|
addTest(root, &TestSimpleDisplayNames, "tsutil/cloctst/TestSimpleDisplayNames");
|
|
|
|
addTest(root, &TestVariantParsing, "tsutil/cloctst/TestVariantParsing");
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2000-12-15 19:16:43 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
/* testing uloc(), uloc_getName(), uloc_getLanguage(), uloc_getVariant(), uloc_getCountry() */
|
2000-11-21 04:05:39 +00:00
|
|
|
static void TestBasicGetters() {
|
1999-08-16 21:50:52 +00:00
|
|
|
int32_t i;
|
|
|
|
int32_t cap;
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
char *testLocale = 0;
|
|
|
|
char *temp = 0, *name = 0;
|
|
|
|
log_verbose("Testing Basic Getters\n");
|
|
|
|
for (i = 0; i <= MAX_LOCALES; i++) {
|
|
|
|
testLocale=(char*)malloc(sizeof(char) * (strlen(rawData2[NAME][i])+1));
|
|
|
|
strcpy(testLocale,rawData2[NAME][i]);
|
2000-08-15 01:13:48 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
log_verbose("Testing %s .....\n", testLocale);
|
|
|
|
cap=uloc_getLanguage(testLocale, NULL, 0, &status);
|
1999-10-07 00:07:53 +00:00
|
|
|
if(status==U_BUFFER_OVERFLOW_ERROR){
|
|
|
|
status=U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
temp=(char*)malloc(sizeof(char) * (cap+1));
|
|
|
|
uloc_getLanguage(testLocale, temp, cap, &status);
|
|
|
|
}
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status)){
|
1999-08-16 21:50:52 +00:00
|
|
|
log_err("ERROR: in uloc_getLanguage %s\n", myErrorName(status));
|
|
|
|
}
|
|
|
|
if (0 !=strcmp(temp,rawData2[LANG][i])) {
|
|
|
|
log_err(" Language code mismatch: %s versus %s\n", temp, rawData2[LANG][i]);
|
|
|
|
}
|
2000-08-15 01:13:48 +00:00
|
|
|
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
cap=uloc_getCountry(testLocale, temp, cap, &status);
|
1999-10-07 00:07:53 +00:00
|
|
|
if(status==U_BUFFER_OVERFLOW_ERROR){
|
|
|
|
status=U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
temp=(char*)realloc(temp, sizeof(char) * (cap+1));
|
|
|
|
uloc_getCountry(testLocale, temp, cap, &status);
|
|
|
|
}
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status)){
|
1999-08-16 21:50:52 +00:00
|
|
|
log_err("ERROR: in uloc_getCountry %s\n", myErrorName(status));
|
|
|
|
}
|
|
|
|
if (0 != strcmp(temp, rawData2[CTRY][i])) {
|
|
|
|
log_err(" Country code mismatch: %s versus %s\n", temp, rawData2[CTRY][i]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
cap=uloc_getVariant(testLocale, temp, cap, &status);
|
1999-10-07 00:07:53 +00:00
|
|
|
if(status==U_BUFFER_OVERFLOW_ERROR){
|
|
|
|
status=U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
temp=(char*)realloc(temp, sizeof(char) * (cap+1));
|
|
|
|
uloc_getVariant(testLocale, temp, cap, &status);
|
|
|
|
}
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status)){
|
1999-08-16 21:50:52 +00:00
|
|
|
log_err("ERROR: in uloc_getVariant %s\n", myErrorName(status));
|
|
|
|
}
|
|
|
|
if (0 != strcmp(temp, rawData2[VAR][i])) {
|
|
|
|
log_err("Variant code mismatch: %s versus %s\n", temp, rawData2[VAR][i]);
|
2000-12-15 19:16:43 +00:00
|
|
|
}
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
cap=uloc_getName(testLocale, NULL, 0, &status);
|
1999-10-07 00:07:53 +00:00
|
|
|
if(status==U_BUFFER_OVERFLOW_ERROR){
|
|
|
|
status=U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
name=(char*)malloc(sizeof(char) * (cap+1));
|
|
|
|
uloc_getName(testLocale, name, cap, &status);
|
|
|
|
}
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status)){
|
1999-08-16 21:50:52 +00:00
|
|
|
log_err("ERROR: in uloc_getName %s\n", myErrorName(status));
|
|
|
|
}
|
|
|
|
if (0 != strcmp(name, rawData2[NAME][i])){
|
|
|
|
log_err(" Mismatch in getName: %s versus %s\n", name, rawData2[NAME][i]);
|
|
|
|
}
|
|
|
|
|
2000-08-15 01:13:48 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
free(temp);
|
|
|
|
free(name);
|
2000-08-15 01:13:48 +00:00
|
|
|
|
2000-12-15 19:16:43 +00:00
|
|
|
free(testLocale);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
}
|
2000-11-21 04:05:39 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
/* testing uloc_getISO3Language(), uloc_getISO3Country(), */
|
2000-11-21 04:05:39 +00:00
|
|
|
static void TestSimpleResourceInfo() {
|
1999-08-16 21:50:52 +00:00
|
|
|
int32_t i;
|
|
|
|
char* testLocale = 0;
|
|
|
|
UChar* expected = 0;
|
2000-08-15 01:13:48 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
const char* temp;
|
2000-06-22 17:39:34 +00:00
|
|
|
char temp2[20];
|
1999-08-16 21:50:52 +00:00
|
|
|
testLocale=(char*)malloc(sizeof(char) * 1);
|
|
|
|
expected=(UChar*)malloc(sizeof(UChar) * 1);
|
2000-08-15 01:13:48 +00:00
|
|
|
|
2000-12-15 19:16:43 +00:00
|
|
|
setUpDataTable();
|
1999-08-16 21:50:52 +00:00
|
|
|
log_verbose("Testing getISO3Language and getISO3Country\n");
|
|
|
|
for (i = 0; i <= MAX_LOCALES; i++) {
|
2000-12-15 19:16:43 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
testLocale=(char*)realloc(testLocale, sizeof(char) * (u_strlen(dataTable[NAME][i])+1));
|
|
|
|
u_austrcpy(testLocale, dataTable[NAME][i]);
|
2000-12-15 19:16:43 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
log_verbose("Testing %s ......\n", testLocale);
|
2000-12-15 19:16:43 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
temp=uloc_getISO3Language(testLocale);
|
|
|
|
expected=(UChar*)realloc(expected, sizeof(UChar) * (strlen(temp) + 1));
|
|
|
|
u_uastrcpy(expected,temp);
|
|
|
|
if (0 != u_strcmp(expected, dataTable[LANG3][i])) {
|
|
|
|
log_err(" ISO-3 language code mismatch: %s versus %s\n", austrdup(expected),
|
|
|
|
austrdup(dataTable[LANG3][i]));
|
2000-12-15 19:16:43 +00:00
|
|
|
}
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
temp=uloc_getISO3Country(testLocale);
|
|
|
|
expected=(UChar*)realloc(expected, sizeof(UChar) * (strlen(temp) + 1));
|
|
|
|
u_uastrcpy(expected,temp);
|
|
|
|
if (0 != u_strcmp(expected, dataTable[CTRY3][i])) {
|
|
|
|
log_err(" ISO-3 Country code mismatch: %s versus %s\n", austrdup(expected),
|
|
|
|
austrdup(dataTable[CTRY3][i]));
|
2000-12-15 19:16:43 +00:00
|
|
|
}
|
2000-06-22 17:39:34 +00:00
|
|
|
sprintf(temp2, "%x", uloc_getLCID(testLocale));
|
|
|
|
if (strcmp(temp2, rawData2[LCID][i]) != 0) {
|
2000-12-19 21:49:55 +00:00
|
|
|
log_err("LCID mismatch: %s versus %s\n", temp2 , rawData2[LCID][i]);
|
2000-06-22 17:39:34 +00:00
|
|
|
}
|
2000-12-15 19:16:43 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2000-12-15 19:16:43 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
free(expected);
|
|
|
|
free(testLocale);
|
2000-12-15 19:16:43 +00:00
|
|
|
cleanUpDataTable();
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2000-11-21 04:05:39 +00:00
|
|
|
|
|
|
|
static void TestDisplayNames()
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
/* sfb 990721
|
|
|
|
Can't just save a pointer to the default locale.
|
|
|
|
Although the pointer won't change, the contents will, so the
|
|
|
|
restore at the end doesn't actually restore the original.
|
|
|
|
*/
|
|
|
|
const char *saveDefault;
|
|
|
|
char *defaultLocale;
|
2000-12-15 19:16:43 +00:00
|
|
|
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode err = U_ZERO_ERROR;
|
2000-12-15 19:16:43 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
saveDefault = uloc_getDefault();
|
|
|
|
defaultLocale = (char*) malloc(strlen(saveDefault) + 1);
|
|
|
|
if(defaultLocale == 0) {
|
|
|
|
log_err("out of memory");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
strcpy(defaultLocale, saveDefault);
|
|
|
|
|
|
|
|
uloc_setDefault("en_US", &err);
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_FAILURE(err)) {
|
1999-08-16 21:50:52 +00:00
|
|
|
log_err("uloc_setDefault returned error code ");
|
|
|
|
return;
|
|
|
|
}
|
2000-12-15 19:16:43 +00:00
|
|
|
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
log_verbose("Testing getDisplayName for different locales\n");
|
|
|
|
log_verbose("With default = en_US...\n");
|
2000-12-15 19:16:43 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
log_verbose(" In default locale...\n");
|
|
|
|
doTestDisplayNames(" ", DLANG_EN, FALSE);
|
|
|
|
log_verbose(" In locale = en_US...\n");
|
|
|
|
doTestDisplayNames("en_US", DLANG_EN, FALSE);
|
|
|
|
log_verbose(" In locale = fr_FR....\n");
|
|
|
|
doTestDisplayNames("fr_FR", DLANG_FR, FALSE);
|
|
|
|
log_verbose(" In locale = hr_HR...\n");
|
|
|
|
doTestDisplayNames("hr_HR", DLANG_HR, FALSE);
|
|
|
|
log_verbose(" In locale = gr_EL..\n");
|
|
|
|
doTestDisplayNames("el_GR", DLANG_EL, FALSE);
|
|
|
|
|
2000-11-21 04:05:39 +00:00
|
|
|
uloc_setDefault("fr_FR", &err);
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_FAILURE(err)) {
|
1999-08-16 21:50:52 +00:00
|
|
|
log_err("Locale::setDefault returned error code %s\n", myErrorName(err));
|
|
|
|
return;
|
|
|
|
}
|
2000-12-15 19:16:43 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
log_verbose("With default = fr_FR...\n");
|
2000-12-15 19:16:43 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
log_verbose(" In default locale...\n");
|
|
|
|
doTestDisplayNames(" ", DLANG_FR, TRUE);
|
|
|
|
log_verbose(" In locale = en_US...\n");
|
|
|
|
doTestDisplayNames("en_US", DLANG_EN, TRUE);
|
|
|
|
log_verbose(" In locale = fr_FR....\n");
|
|
|
|
doTestDisplayNames("fr_FR", DLANG_FR, TRUE);
|
|
|
|
log_verbose(" In locale = hr_HR...\n");
|
|
|
|
doTestDisplayNames("hr_HR", DLANG_HR, TRUE);
|
|
|
|
log_verbose(" In locale = el_GR...\n");
|
|
|
|
doTestDisplayNames("el_GR", DLANG_EL, TRUE);
|
|
|
|
|
|
|
|
uloc_setDefault(defaultLocale, &err);
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_FAILURE(err)) {
|
1999-08-16 21:50:52 +00:00
|
|
|
log_err("Locale::setDefault returned error code %s\n", myErrorName(err));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(defaultLocale);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* test for uloc_getAvialable() and uloc_countAvilable()*/
|
2000-11-21 04:05:39 +00:00
|
|
|
static void TestGetAvailableLocales()
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
const char *locList;
|
|
|
|
int32_t locCount,i;
|
2000-12-15 19:16:43 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
log_verbose("Testing the no of avialable locales\n");
|
|
|
|
locCount=uloc_countAvailable();
|
|
|
|
if (locCount == 0)
|
|
|
|
log_err("countAvailable() returned an empty list!\n");
|
2000-12-15 19:16:43 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
/* use something sensible w/o hardcoding the count */
|
|
|
|
else if(locCount < 0){
|
|
|
|
log_err("countAvailable() returned a wrong value!= %d\n", locCount);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
log_info("Number of locales returned = %d\n", locCount);
|
|
|
|
}
|
|
|
|
for(i=0;i<locCount;i++){
|
|
|
|
locList=uloc_getAvailable(i);
|
2000-12-15 19:16:43 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
log_verbose(" %s\n", locList);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-12-14 19:14:27 +00:00
|
|
|
/* test for u_getDataDirectory, u_setDataDirectory, uloc_getISO3Language */
|
2000-11-21 04:05:39 +00:00
|
|
|
static void TestDataDirectory()
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
char oldDirectory[80];
|
|
|
|
const char *temp,*testValue1,*testValue2,*testValue3;
|
1999-11-23 22:48:46 +00:00
|
|
|
const char path[40] ="d:\\icu\\source\\test\\intltest" U_FILE_SEP_STRING; /*give the required path */
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
log_verbose("Testing getDataDirectory()\n");
|
1999-12-14 19:14:27 +00:00
|
|
|
temp = u_getDataDirectory();
|
1999-08-16 21:50:52 +00:00
|
|
|
strcpy(oldDirectory, temp);
|
|
|
|
|
|
|
|
testValue1=uloc_getISO3Language("en_US");
|
|
|
|
log_verbose("first fetch of language retrieved %s\n", testValue1);
|
|
|
|
|
|
|
|
if (0 != strcmp(testValue1,"eng")){
|
|
|
|
log_err("Initial check of ISO3 language failed: expected \"eng\", got %s \n", testValue1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*defining the path for DataDirectory */
|
|
|
|
log_verbose("Testing setDataDirectory\n");
|
1999-12-14 19:14:27 +00:00
|
|
|
u_setDataDirectory( path );
|
|
|
|
if(strcmp(path, u_getDataDirectory())==0)
|
1999-08-16 21:50:52 +00:00
|
|
|
log_verbose("setDataDirectory working fine\n");
|
|
|
|
else
|
1999-12-14 19:14:27 +00:00
|
|
|
log_err("Error in setDataDirectory. Directory not set correctly - came back as [%s], expected [%s]\n", u_getDataDirectory(), path);
|
2000-12-15 19:16:43 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
testValue2=uloc_getISO3Language("en_US");
|
|
|
|
log_verbose("second fetch of language retrieved %s \n", testValue2);
|
2000-12-15 19:16:43 +00:00
|
|
|
|
1999-12-14 19:14:27 +00:00
|
|
|
u_setDataDirectory(oldDirectory);
|
1999-08-16 21:50:52 +00:00
|
|
|
testValue3=uloc_getISO3Language("en_US");
|
|
|
|
log_verbose("third fetch of language retrieved %s \n", testValue3);
|
2000-12-15 19:16:43 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
if (0 != strcmp(testValue3,"eng")) {
|
|
|
|
log_err("get/setDataDirectory() failed: expected \"eng\", got \" %s \" \n", testValue3);
|
2000-12-15 19:16:43 +00:00
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*=========================================================== */
|
|
|
|
|
2000-11-21 04:05:39 +00:00
|
|
|
static void doTestDisplayNames(const char* inLocale,
|
1999-08-16 21:50:52 +00:00
|
|
|
int32_t compareIndex,
|
|
|
|
int32_t defaultIsFrench)
|
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
int32_t i;
|
|
|
|
int32_t maxresultsize;
|
2000-12-15 19:16:43 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
char* testLocale;
|
2000-12-15 19:16:43 +00:00
|
|
|
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
UChar *testLang = 0;
|
|
|
|
UChar *testCtry = 0;
|
|
|
|
UChar *testVar = 0;
|
|
|
|
UChar *testName = 0;
|
2000-12-15 19:16:43 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
UChar* expectedLang = 0;
|
|
|
|
UChar* expectedCtry = 0;
|
|
|
|
UChar* expectedVar = 0;
|
|
|
|
UChar* expectedName = 0;
|
|
|
|
char temp[5];
|
|
|
|
const char* defaultDefaultLocale=" ";
|
2000-12-15 19:16:43 +00:00
|
|
|
|
|
|
|
setUpDataTable();
|
|
|
|
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
uloc_getLanguage(uloc_getDefault(), temp, 5, &status);
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status)){
|
1999-08-16 21:50:52 +00:00
|
|
|
log_err("ERROR: in getDefault %s \n", myErrorName(status));
|
|
|
|
}
|
|
|
|
if (defaultIsFrench && 0 != strcmp(temp, "fr")) {
|
|
|
|
log_err("Default locale should be French, but it's really %s\n", temp);
|
|
|
|
}
|
|
|
|
else if (!defaultIsFrench && 0 != strcmp(temp, "en")){
|
|
|
|
log_err("Default locale should be English, but it's really %s\n", temp);
|
|
|
|
}
|
|
|
|
|
2000-12-15 19:16:43 +00:00
|
|
|
testLocale = (char*)malloc(sizeof(char) * 1);
|
|
|
|
|
|
|
|
|
|
|
|
for(i=0;i<MAX_LOCALES; ++i)
|
|
|
|
{
|
1999-08-16 21:50:52 +00:00
|
|
|
testLocale=(char*)realloc(testLocale, sizeof(char) * (u_strlen(dataTable[NAME][i])+1));
|
|
|
|
u_austrcpy(testLocale,dataTable[NAME][i]);
|
2000-12-15 19:16:43 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
log_verbose("Testing..... %s\n", testLocale);
|
2000-12-15 19:16:43 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
if (strcmp(inLocale, defaultDefaultLocale)==0) {
|
|
|
|
maxresultsize=0;
|
|
|
|
maxresultsize=uloc_getDisplayLanguage(testLocale, NULL, NULL, maxresultsize, &status);
|
1999-10-07 00:07:53 +00:00
|
|
|
if(status==U_BUFFER_OVERFLOW_ERROR)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
status=U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
testLang=(UChar*)malloc(sizeof(UChar) * (maxresultsize + 1));
|
|
|
|
uloc_getDisplayLanguage(testLocale, NULL, testLang, maxresultsize, &status);
|
|
|
|
}
|
2000-12-15 19:16:43 +00:00
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status)){
|
1999-08-16 21:50:52 +00:00
|
|
|
log_err("Error in getDisplayLanguage() %s\n", myErrorName(status));
|
|
|
|
}
|
|
|
|
maxresultsize=0;
|
|
|
|
maxresultsize=uloc_getDisplayCountry(testLocale, NULL, NULL, maxresultsize, &status);
|
1999-10-07 00:07:53 +00:00
|
|
|
if(status==U_BUFFER_OVERFLOW_ERROR)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
status=U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
testCtry=(UChar*)malloc(sizeof(UChar) * (maxresultsize + 1));
|
|
|
|
uloc_getDisplayCountry(testLocale, NULL, testCtry, maxresultsize, &status);
|
|
|
|
}
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status)){
|
1999-08-16 21:50:52 +00:00
|
|
|
log_err("Error in getDisplayCountry() %s\n", myErrorName(status));
|
|
|
|
}
|
2000-12-15 19:16:43 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
maxresultsize=0;
|
|
|
|
maxresultsize=uloc_getDisplayVariant(testLocale, NULL, NULL, maxresultsize, &status);
|
1999-10-07 00:07:53 +00:00
|
|
|
if(status==U_BUFFER_OVERFLOW_ERROR)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
status=U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
testVar=(UChar*)malloc(sizeof(UChar) * (maxresultsize+1));
|
|
|
|
uloc_getDisplayVariant(testLocale, NULL, testVar, maxresultsize, &status);
|
|
|
|
}
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status)){
|
1999-08-16 21:50:52 +00:00
|
|
|
log_err("Error in getDisplayVariant() %s\n", myErrorName(status));
|
|
|
|
}
|
|
|
|
maxresultsize=0;
|
|
|
|
maxresultsize=uloc_getDisplayName(testLocale, NULL, NULL, maxresultsize, &status);
|
1999-10-07 00:07:53 +00:00
|
|
|
if(status==U_BUFFER_OVERFLOW_ERROR)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
status=U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
testName=(UChar*)malloc(sizeof(UChar) * (maxresultsize+1));
|
|
|
|
uloc_getDisplayName(testLocale, NULL, testName, maxresultsize, &status);
|
|
|
|
}
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status)){
|
1999-08-16 21:50:52 +00:00
|
|
|
log_err("Error in getDisplayName() %s\n", myErrorName(status));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
maxresultsize=0;
|
|
|
|
maxresultsize=uloc_getDisplayLanguage(testLocale, inLocale, NULL, maxresultsize, &status);
|
1999-10-07 00:07:53 +00:00
|
|
|
if(status==U_BUFFER_OVERFLOW_ERROR)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
status=U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
testLang=(UChar*)malloc(sizeof(UChar) * (maxresultsize+1));
|
|
|
|
uloc_getDisplayLanguage(testLocale, inLocale, testLang, maxresultsize, &status);
|
|
|
|
}
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status)){
|
1999-08-16 21:50:52 +00:00
|
|
|
log_err("Error in getDisplayLanguage() %s\n", myErrorName(status));
|
|
|
|
}
|
|
|
|
|
|
|
|
maxresultsize=0;
|
|
|
|
maxresultsize=uloc_getDisplayCountry(testLocale, inLocale, NULL, maxresultsize, &status);
|
1999-10-07 00:07:53 +00:00
|
|
|
if(status==U_BUFFER_OVERFLOW_ERROR)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
status=U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
testCtry=(UChar*)malloc(sizeof(UChar) * (maxresultsize+1));
|
|
|
|
uloc_getDisplayCountry(testLocale, inLocale, testCtry, maxresultsize, &status);
|
|
|
|
}
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status)){
|
1999-08-16 21:50:52 +00:00
|
|
|
log_err("Error in getDisplayCountry() %s\n", myErrorName(status));
|
|
|
|
}
|
|
|
|
|
|
|
|
maxresultsize=0;
|
|
|
|
maxresultsize=uloc_getDisplayVariant(testLocale, inLocale, NULL, maxresultsize, &status);
|
1999-10-07 00:07:53 +00:00
|
|
|
if(status==U_BUFFER_OVERFLOW_ERROR)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
status=U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
testVar=(UChar*)malloc(sizeof(UChar) * (maxresultsize+1));
|
|
|
|
uloc_getDisplayVariant(testLocale, inLocale, testVar, maxresultsize, &status);
|
|
|
|
}
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status)){
|
1999-08-16 21:50:52 +00:00
|
|
|
log_err("Error in getDisplayVariant() %s\n", myErrorName(status));
|
|
|
|
}
|
|
|
|
|
|
|
|
maxresultsize=0;
|
|
|
|
maxresultsize=uloc_getDisplayName(testLocale, inLocale, NULL, maxresultsize, &status);
|
1999-10-07 00:07:53 +00:00
|
|
|
if(status==U_BUFFER_OVERFLOW_ERROR)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
status=U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
testName=(UChar*)malloc(sizeof(UChar) * (maxresultsize+1));
|
|
|
|
uloc_getDisplayName(testLocale, inLocale, testName, maxresultsize, &status);
|
|
|
|
}
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status)){
|
1999-08-16 21:50:52 +00:00
|
|
|
log_err("Error in getDisplayName() %s\n", myErrorName(status));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2000-12-15 19:16:43 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
expectedLang=dataTable[compareIndex][i];
|
2000-12-15 19:16:43 +00:00
|
|
|
if(u_strlen(expectedLang) == 0 && defaultIsFrench)
|
1999-08-16 21:50:52 +00:00
|
|
|
expectedLang=dataTable[DLANG_FR][i];
|
|
|
|
if(u_strlen(expectedLang)== 0)
|
|
|
|
expectedLang=dataTable[DLANG_EN][i];
|
|
|
|
|
2000-12-15 19:16:43 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
expectedCtry=dataTable[compareIndex + 1][i];
|
|
|
|
if(u_strlen(expectedCtry) == 0 && defaultIsFrench)
|
|
|
|
expectedCtry=dataTable[DCTRY_FR][i];
|
|
|
|
if(u_strlen(expectedCtry)== 0)
|
2000-12-15 19:16:43 +00:00
|
|
|
expectedCtry=dataTable[DCTRY_EN][i];
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
expectedVar=dataTable[compareIndex + 2][i];
|
|
|
|
if(u_strlen(expectedVar) == 0 && defaultIsFrench)
|
|
|
|
expectedVar=dataTable[DVAR_FR][i];
|
|
|
|
if(u_strlen(expectedCtry)== 0)
|
|
|
|
expectedVar=dataTable[DVAR_EN][i];
|
2000-12-15 19:16:43 +00:00
|
|
|
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
expectedName=dataTable[compareIndex + 3][i];
|
|
|
|
if(u_strlen(expectedName) ==0 && defaultIsFrench)
|
|
|
|
expectedName=dataTable[DNAME_FR][i];
|
|
|
|
if(u_strlen(expectedName) == 0)
|
|
|
|
expectedName=dataTable[DNAME_EN][i];
|
2000-12-15 19:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
if (0 !=u_strcmp(testLang,expectedLang)) {
|
1999-08-16 21:50:52 +00:00
|
|
|
log_err(" Display Language mismatch: %s versus %s\n", austrdup(testLang), austrdup(expectedLang));
|
2000-12-15 19:16:43 +00:00
|
|
|
}
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
if (0 != u_strcmp(testCtry,expectedCtry)) {
|
|
|
|
log_err(" Display Country mismatch: %s versus %s\n", austrdup(testCtry), austrdup(expectedCtry));
|
2000-12-15 19:16:43 +00:00
|
|
|
}
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
if (0 != u_strcmp(testVar,expectedVar)) {
|
|
|
|
log_err(" Display Variant mismatch: %s versus %s\n", austrdup(testVar), austrdup(expectedVar));
|
2000-12-15 19:16:43 +00:00
|
|
|
}
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
if(0 != u_strcmp(testName, expectedName)) {
|
|
|
|
log_err(" Display Name mismatch: %s versus %s\n", austrdup(testName), austrdup(expectedName));
|
|
|
|
}
|
2000-12-15 19:16:43 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
free(testName);
|
|
|
|
free(testLang);
|
|
|
|
free(testCtry);
|
|
|
|
free(testVar);
|
|
|
|
|
|
|
|
}
|
|
|
|
free(testLocale);
|
2000-12-15 19:16:43 +00:00
|
|
|
cleanUpDataTable();
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2000-11-21 04:05:39 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
/* test for uloc_getISOLanguages, uloc_getISOCountries */
|
2000-11-21 04:05:39 +00:00
|
|
|
static void TestISOFunctions()
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
const char* const* str=uloc_getISOLanguages();
|
|
|
|
const char* const* str1=uloc_getISOCountries();
|
2000-12-15 19:16:43 +00:00
|
|
|
int32_t count = 0;
|
|
|
|
UBool done = FALSE;
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
/* test getISOLanguages*/
|
|
|
|
/*str=uloc_getISOLanguages(); */
|
|
|
|
log_verbose("Testing ISO Languages: \n");
|
2000-12-15 19:16:43 +00:00
|
|
|
|
|
|
|
while(!done)
|
|
|
|
{
|
1999-08-16 21:50:52 +00:00
|
|
|
if(*(str+count++) == 0)
|
2000-12-15 19:16:43 +00:00
|
|
|
{
|
1999-08-16 21:50:52 +00:00
|
|
|
done = TRUE;
|
2000-12-15 19:16:43 +00:00
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
count--;
|
2000-12-15 19:16:43 +00:00
|
|
|
if(count!=142) {
|
1999-08-16 21:50:52 +00:00
|
|
|
log_err("There is an error in getISOLanguages %d\n", count);
|
2000-12-15 19:16:43 +00:00
|
|
|
}
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
log_verbose("Testing ISO Countries");
|
|
|
|
count=0;
|
|
|
|
done=FALSE;
|
|
|
|
while(!done)
|
|
|
|
{
|
|
|
|
if(*(str1 + count++)==0)
|
2000-12-15 19:16:43 +00:00
|
|
|
{
|
1999-08-16 21:50:52 +00:00
|
|
|
done=TRUE;
|
2000-12-15 19:16:43 +00:00
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
count--;
|
|
|
|
if(count!=239)
|
2000-12-15 19:16:43 +00:00
|
|
|
{
|
1999-08-16 21:50:52 +00:00
|
|
|
log_err("There is an error in getISOCountries %d \n", count);
|
2000-12-15 19:16:43 +00:00
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2000-11-21 04:05:39 +00:00
|
|
|
static void setUpDataTable()
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
int32_t i,j;
|
2000-12-15 19:16:43 +00:00
|
|
|
dataTable = (UChar***)(calloc(sizeof(UChar**),LOCALE_INFO_SIZE));
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-08-15 01:13:48 +00:00
|
|
|
for (i = 0; i < 23; i++) {
|
2000-12-15 19:16:43 +00:00
|
|
|
dataTable[i] = (UChar**)(calloc(sizeof(UChar*),LOCALE_SIZE));
|
2000-08-15 01:13:48 +00:00
|
|
|
for (j = 0; j < 5; j++){
|
|
|
|
dataTable[i][j] = CharsToUChars(rawData2[i][j]);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2000-08-15 01:13:48 +00:00
|
|
|
}
|
2000-12-15 19:16:43 +00:00
|
|
|
}
|
2000-08-15 01:13:48 +00:00
|
|
|
|
2000-12-15 19:16:43 +00:00
|
|
|
static void cleanUpDataTable()
|
|
|
|
{
|
|
|
|
int32_t i,j;
|
|
|
|
if(dataTable != NULL) {
|
|
|
|
for (i=0; i<LOCALE_INFO_SIZE; i++) {
|
|
|
|
for(j = 0; j < LOCALE_SIZE; j++) {
|
|
|
|
free(dataTable[i][j]);
|
|
|
|
}
|
|
|
|
free(dataTable[i]);
|
|
|
|
}
|
|
|
|
free(dataTable);
|
|
|
|
}
|
|
|
|
dataTable = NULL;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2000-11-21 04:05:39 +00:00
|
|
|
|
2000-06-22 17:39:34 +00:00
|
|
|
/**
|
|
|
|
* @bug 4011756 4011380
|
|
|
|
*/
|
2000-11-21 04:05:39 +00:00
|
|
|
static void TestISO3Fallback()
|
2000-06-22 17:39:34 +00:00
|
|
|
{
|
|
|
|
const char* test="xx_YY";
|
|
|
|
|
|
|
|
const char * result;
|
|
|
|
|
|
|
|
result = uloc_getISO3Language(test);
|
|
|
|
|
2000-06-29 02:53:29 +00:00
|
|
|
/* Conform to C API usage */
|
2000-06-22 17:39:34 +00:00
|
|
|
|
|
|
|
if (!result || (result[0] != 0))
|
|
|
|
log_err("getISO3Language() on xx_YY returned %s instead of \"\"");
|
|
|
|
|
|
|
|
result = uloc_getISO3Country(test);
|
|
|
|
|
|
|
|
if (!result || (result[0] != 0))
|
|
|
|
log_err("getISO3Country() on xx_YY returned %s instead of \"\"");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @bug 4118587
|
|
|
|
*/
|
2000-11-21 04:05:39 +00:00
|
|
|
static void TestSimpleDisplayNames()
|
2000-06-22 17:39:34 +00:00
|
|
|
{
|
2000-06-29 02:53:29 +00:00
|
|
|
/*
|
|
|
|
This test is different from TestDisplayNames because TestDisplayNames checks
|
|
|
|
fallback behavior, combination of language and country names to form locale
|
|
|
|
names, and other stuff like that. This test just checks specific language
|
|
|
|
and country codes to make sure we have the correct names for them.
|
|
|
|
*/
|
2000-06-22 17:39:34 +00:00
|
|
|
char languageCodes[] [4] = { "he", "id", "iu", "ug", "yi", "za" };
|
|
|
|
const char* languageNames [] = { "Hebrew", "Indonesian", "Inukitut", "Uighur", "Yiddish",
|
|
|
|
"Zhuang" };
|
|
|
|
UErrorCode status=U_ZERO_ERROR;
|
|
|
|
|
|
|
|
int32_t i;
|
|
|
|
for (i = 0; i < 6; i++) {
|
|
|
|
UChar *testLang=0;
|
|
|
|
UChar *expectedLang=0;
|
|
|
|
int size=0;
|
|
|
|
size=uloc_getDisplayLanguage(languageCodes[i], "en_US", NULL, size, &status);
|
|
|
|
if(status==U_BUFFER_OVERFLOW_ERROR) {
|
|
|
|
status=U_ZERO_ERROR;
|
|
|
|
testLang=(UChar*)malloc(sizeof(UChar) * (size + 1));
|
|
|
|
uloc_getDisplayLanguage(languageCodes[i], "en_US", testLang, size, &status);
|
|
|
|
}
|
|
|
|
expectedLang=(UChar*)malloc(sizeof(UChar) * (strlen(languageNames[i])+1));
|
|
|
|
u_uastrcpy(expectedLang, languageNames[i]);
|
|
|
|
if (u_strcmp(testLang, expectedLang) != 0)
|
|
|
|
log_err("Got wrong display name for %s : Expected \"%s\", got \"%s\".\n",
|
|
|
|
languageCodes[i], languageNames[i], austrdup(testLang));
|
|
|
|
free(testLang);
|
|
|
|
free(expectedLang);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @bug 4118595
|
|
|
|
*/
|
2000-11-21 04:05:39 +00:00
|
|
|
static void TestUninstalledISO3Names()
|
2000-06-22 17:39:34 +00:00
|
|
|
{
|
2000-06-29 02:53:29 +00:00
|
|
|
/* This test checks to make sure getISO3Language and getISO3Country work right
|
|
|
|
even for locales that are not installed. */
|
2000-06-22 17:39:34 +00:00
|
|
|
const char iso2Languages [][4] = { "am", "ba", "fy", "mr", "rn",
|
|
|
|
"ss", "tw", "zu" };
|
|
|
|
const char iso3Languages [][5] = { "amh", "bak", "fry", "mar", "run",
|
|
|
|
"ssw", "twi", "zul" };
|
|
|
|
char iso2Countries [][6] = { "am_AF", "ba_BW", "fy_KZ", "mr_MO", "rn_MN",
|
|
|
|
"ss_SB", "tw_TC", "zu_ZW" };
|
|
|
|
char iso3Countries [][4] = { "AFG", "BWA", "KAZ", "MAC", "MNG",
|
|
|
|
"SLB", "TCA", "ZWE" };
|
|
|
|
int32_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
UErrorCode err = U_ZERO_ERROR;
|
|
|
|
const char *test;
|
|
|
|
test = uloc_getISO3Language(iso2Languages[i]);
|
|
|
|
if(strcmp(test, iso3Languages[i]) !=0 || U_FAILURE(err))
|
|
|
|
log_err("Got wrong ISO3 code for %s : Expected \"%s\", got \"%s\". %s\n",
|
|
|
|
iso2Languages[i], iso3Languages[i], test, myErrorName(err));
|
|
|
|
}
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
UErrorCode err = U_ZERO_ERROR;
|
|
|
|
const char *test;
|
|
|
|
test = uloc_getISO3Country(iso2Countries[i]);
|
|
|
|
if(strcmp(test, iso3Countries[i]) !=0 || U_FAILURE(err))
|
|
|
|
log_err("Got wrong ISO3 code for %s : Expected \"%s\", got \"%s\". %s\n",
|
|
|
|
iso2Countries[i], iso3Countries[i], test, myErrorName(err));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-11-21 04:05:39 +00:00
|
|
|
static void TestVariantParsing()
|
2000-06-22 17:39:34 +00:00
|
|
|
{
|
|
|
|
const char* en_US_custom="en_US_De Anza_Cupertino_California_United States_Earth";
|
|
|
|
const char* dispName="English (United States, DE ANZA_CUPERTINO_CALIFORNIA_UNITED STATES_EARTH)";
|
|
|
|
const char* dispVar="DE ANZA_CUPERTINO_CALIFORNIA_UNITED STATES_EARTH";
|
|
|
|
const char* shortVariant="fr_FR_foo";
|
|
|
|
const char* bogusVariant="fr_FR__foo";
|
|
|
|
const char* bogusVariant2="fr_FR_foo_";
|
|
|
|
const char* bogusVariant3="fr_FR__foo_";
|
|
|
|
|
|
|
|
|
|
|
|
UChar displayVar[100];
|
|
|
|
UChar displayName[100];
|
|
|
|
UErrorCode status=U_ZERO_ERROR;
|
|
|
|
UChar* got=0;
|
|
|
|
int32_t size=0;
|
|
|
|
size=uloc_getDisplayVariant(en_US_custom, "en_US", NULL, size, &status);
|
|
|
|
if(status==U_BUFFER_OVERFLOW_ERROR) {
|
|
|
|
status=U_ZERO_ERROR;
|
2000-07-06 23:01:50 +00:00
|
|
|
got=(UChar*)realloc(got, sizeof(UChar) * (size+1));
|
2000-06-22 17:39:34 +00:00
|
|
|
uloc_getDisplayVariant(en_US_custom, "en_US", got, size, &status);
|
|
|
|
}
|
|
|
|
u_uastrcpy(displayVar, dispVar);
|
|
|
|
if(u_strcmp(got,displayVar)!=0) {
|
|
|
|
log_err("FAIL: getDisplayVariant() Wanted %s, got %s\n", dispVar, austrdup(got));
|
|
|
|
}
|
|
|
|
size=0;
|
|
|
|
size=uloc_getDisplayName(en_US_custom, "en_US", NULL, size, &status);
|
|
|
|
if(status==U_BUFFER_OVERFLOW_ERROR) {
|
|
|
|
status=U_ZERO_ERROR;
|
|
|
|
got=(UChar*)realloc(got, sizeof(UChar) * (size+1));
|
|
|
|
uloc_getDisplayName(en_US_custom, "en_US", got, size, &status);
|
|
|
|
}
|
|
|
|
u_uastrcpy(displayName, dispName);
|
|
|
|
if(u_strcmp(got,displayName)!=0) {
|
|
|
|
log_err("FAIL: getDisplayName() Wanted %s, got %s\n", dispName, austrdup(got));
|
|
|
|
}
|
|
|
|
|
|
|
|
size=0;
|
|
|
|
status=U_ZERO_ERROR;
|
|
|
|
size=uloc_getDisplayVariant(shortVariant, NULL, NULL, size, &status);
|
|
|
|
if(status==U_BUFFER_OVERFLOW_ERROR) {
|
|
|
|
status=U_ZERO_ERROR;
|
|
|
|
got=(UChar*)realloc(got, sizeof(UChar) * (size+1));
|
|
|
|
uloc_getDisplayVariant(shortVariant, NULL, got, size, &status);
|
|
|
|
}
|
|
|
|
if(strcmp(austrdup(got),"FOO")!=0) {
|
|
|
|
log_err("FAIL: getDisplayVariant() Wanted: foo Got: %s\n", austrdup(got));
|
|
|
|
}
|
|
|
|
size=0;
|
|
|
|
status=U_ZERO_ERROR;
|
|
|
|
size=uloc_getDisplayVariant(bogusVariant, NULL, NULL, size, &status);
|
|
|
|
if(status==U_BUFFER_OVERFLOW_ERROR) {
|
|
|
|
status=U_ZERO_ERROR;
|
|
|
|
got=(UChar*)realloc(got, sizeof(UChar) * (size+1));
|
|
|
|
uloc_getDisplayVariant(bogusVariant, NULL, got, size, &status);
|
|
|
|
}
|
|
|
|
if(strcmp(austrdup(got),"_FOO")!=0) {
|
|
|
|
log_err("FAIL: getDisplayVariant() Wanted: _FOO Got: %s\n", austrdup(got));
|
|
|
|
}
|
|
|
|
size=0;
|
|
|
|
status=U_ZERO_ERROR;
|
|
|
|
size=uloc_getDisplayVariant(bogusVariant2, NULL, NULL, size, &status);
|
|
|
|
if(status==U_BUFFER_OVERFLOW_ERROR) {
|
|
|
|
status=U_ZERO_ERROR;
|
|
|
|
got=(UChar*)realloc(got, sizeof(UChar) * (size+1));
|
|
|
|
uloc_getDisplayVariant(bogusVariant2, NULL, got, size, &status);
|
|
|
|
}
|
|
|
|
if(strcmp(austrdup(got),"FOO_")!=0) {
|
|
|
|
log_err("FAIL: getDisplayVariant() Wanted: FOO_ Got: %s\n", austrdup(got));
|
|
|
|
}
|
|
|
|
size=0;
|
|
|
|
status=U_ZERO_ERROR;
|
|
|
|
size=uloc_getDisplayVariant(bogusVariant3, NULL, NULL, size, &status);
|
|
|
|
if(status==U_BUFFER_OVERFLOW_ERROR) {
|
|
|
|
status=U_ZERO_ERROR;
|
|
|
|
got=(UChar*)realloc(got, sizeof(UChar) * (size+1));
|
|
|
|
uloc_getDisplayVariant(bogusVariant3, NULL, got, size, &status);
|
|
|
|
}
|
|
|
|
if(strcmp(austrdup(got),"_FOO_")!=0) {
|
|
|
|
log_err("FAIL: getDisplayVariant() Wanted: _FOO_ Got: %s\n", austrdup(got));
|
|
|
|
}
|
2000-07-06 23:01:50 +00:00
|
|
|
free(got);
|
2000-06-22 17:39:34 +00:00
|
|
|
}
|