2000-08-10 19:45:46 +00:00
|
|
|
//**********************************************************************
|
|
|
|
//* Copyright (C) 2000, International Business Machines Corporation
|
|
|
|
//* and others. All Rights Reserved.
|
|
|
|
//**********************************************************************
|
|
|
|
// lcid.cpp - Test for establishing conformance of data in resource bundles to
|
|
|
|
// lcid <-> POSIX mapping
|
|
|
|
// Created by: Vladimir Weinstein
|
|
|
|
// Date: 08/09/2000
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2000-10-10 00:16:43 +00:00
|
|
|
#include <stdlib.h>
|
2000-08-10 19:45:46 +00:00
|
|
|
#include "unicode/utypes.h"
|
|
|
|
#include "locmap.h"
|
|
|
|
#include "cstring.h"
|
|
|
|
#include "unicode/resbund.h"
|
|
|
|
|
2000-10-28 00:39:54 +00:00
|
|
|
static void
|
|
|
|
testLCID(const char *localeName);
|
|
|
|
|
|
|
|
static void
|
|
|
|
testLCID(const char *localeName,
|
|
|
|
const UnicodeString &posixName,
|
|
|
|
uint32_t *errors,
|
|
|
|
uint32_t *warnings)
|
|
|
|
{
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
uint32_t lcid;
|
|
|
|
uint32_t expectedLCID;
|
|
|
|
char lcidStringC[1024];
|
2001-03-14 19:06:01 +00:00
|
|
|
char cLocaleName[256] = {'\0'};
|
|
|
|
|
|
|
|
u_UCharsToChars(posixName.getUChars(),cLocaleName,posixName.length());
|
|
|
|
ResourceBundle posixLocale((char *)0, Locale(cLocaleName), status);
|
2000-10-28 00:39:54 +00:00
|
|
|
if(status != U_ZERO_ERROR) {
|
|
|
|
if(U_SUCCESS(status)) {
|
|
|
|
printf("ERROR: Locale %-5s not installed, and it should be!\n", localeName);
|
|
|
|
} else {
|
|
|
|
printf("%%%%%%% Unexpected error %d %%%%%%%", u_errorName(status));
|
|
|
|
}
|
|
|
|
(*errors)++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
UnicodeString lcidString(posixLocale.getStringEx("LocaleID", status));
|
|
|
|
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
printf("ERROR: %s does not have a LocaleID (%s)\n", localeName, u_errorName(status));
|
|
|
|
(*errors)++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
lcidString.extract(0, lcidString.length(), lcidStringC, "");
|
|
|
|
lcidStringC[lcidString.length()] = '\0';
|
|
|
|
expectedLCID = uprv_strtoul(lcidStringC, NULL, 16);
|
|
|
|
|
|
|
|
lcid = IGlobalLocales::convertToLCID(localeName, &status);
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
printf("WARNING: %-5s does not have an LCID mapping\n", localeName);
|
|
|
|
(*warnings)++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
uprv_strcpy(lcidStringC, IGlobalLocales::convertToPosix(expectedLCID, &status));
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
printf("ERROR: %.4x does not have a POSIX mapping due to %s\n", expectedLCID, u_errorName(status));
|
|
|
|
(*errors)++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(lcid != expectedLCID) {
|
|
|
|
printf("ERROR: Locale %-5s wrongfully has 0x%.4x instead of 0x%.4x for LCID\n", localeName, expectedLCID, lcid);
|
|
|
|
(*errors)++;
|
|
|
|
}
|
|
|
|
if(strcmp(localeName, lcidStringC) != 0) {
|
|
|
|
char langName[1024];
|
|
|
|
char langLCID[1024];
|
|
|
|
uloc_getLanguage(localeName, langName, sizeof(langName), &status);
|
|
|
|
uloc_getLanguage(lcidStringC, langLCID, sizeof(langLCID), &status);
|
|
|
|
|
|
|
|
if (expectedLCID == lcid && strcmp(langName, langLCID) == 0) {
|
|
|
|
printf("WARNING: %-5s resolves to %s (0x%.4x)\n", localeName, lcidStringC, lcid);
|
|
|
|
(*warnings)++;
|
|
|
|
}
|
|
|
|
else if (expectedLCID == lcid) {
|
|
|
|
printf("ERROR: 0x%.4x is from %-5s and the number resolves wrongfully to %s\n", expectedLCID, localeName, lcidStringC);
|
|
|
|
(*errors)++;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf("ERROR: 0x%.4x is from %-5s and the number resolves wrongfully to %s. It should be 0x%x.\n", expectedLCID, localeName, lcidStringC, lcid);
|
|
|
|
(*errors)++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
//printf("0x%x is from %s and it resolves correctly to %s(0x%x)\n", expectedLCID, localeName, lcidStringC, lcid);
|
|
|
|
//printf("%s: %x->%x\n", localeName, expectedLCID, lcid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-08-10 19:45:46 +00:00
|
|
|
int main() {
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
ResourceBundle index((char *)0, Locale("index"), status);
|
|
|
|
uint32_t errors = 0;
|
2000-10-28 00:39:54 +00:00
|
|
|
uint32_t warnings = 0;
|
2000-08-10 19:45:46 +00:00
|
|
|
|
|
|
|
if(U_SUCCESS(status)) {
|
|
|
|
ResourceBundle installedLocales = index.get("InstalledLocales", status);
|
|
|
|
if(U_SUCCESS(status)) {
|
|
|
|
installedLocales.resetIterator();
|
|
|
|
while(installedLocales.hasNext()) {
|
|
|
|
char localeName[1024];
|
|
|
|
UnicodeString posixName = installedLocales.getNextString(status);
|
2000-10-28 00:39:54 +00:00
|
|
|
|
2000-08-10 19:45:46 +00:00
|
|
|
posixName.extract(0, posixName.length(), localeName, "");
|
|
|
|
localeName[posixName.length()] = '\0';
|
2000-10-28 00:39:54 +00:00
|
|
|
testLCID(localeName, posixName, &errors, &warnings);
|
2000-08-10 19:45:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(errors > 0) {
|
|
|
|
printf("There were %d error(s)\n", errors);
|
|
|
|
} else {
|
|
|
|
printf("There were no errors\n");
|
|
|
|
}
|
|
|
|
|
2000-10-28 00:39:54 +00:00
|
|
|
if(warnings > 0) {
|
|
|
|
printf("There were %d warning(s)\n", warnings);
|
|
|
|
}
|
|
|
|
|
2000-10-10 00:16:43 +00:00
|
|
|
char temp;
|
|
|
|
scanf("%c", &temp);
|
|
|
|
|
2000-08-10 19:45:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|