2000-08-10 01:33:48 +00:00
|
|
|
/********************************************************************
|
|
|
|
* COPYRIGHT:
|
2001-03-21 19:46:49 +00:00
|
|
|
* Copyright (c) 2001, International Business Machines Corporation and
|
2000-08-10 01:33:48 +00:00
|
|
|
* others. All Rights Reserved.
|
|
|
|
********************************************************************/
|
|
|
|
/*
|
|
|
|
* File stdnmtst.c
|
|
|
|
*
|
|
|
|
* Modification History:
|
|
|
|
*
|
|
|
|
* Date Name Description
|
|
|
|
* 08/05/2000 Yves Creation
|
|
|
|
*******************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "unicode/ucnv.h"
|
|
|
|
#include "cstring.h"
|
|
|
|
#include "cintltst.h"
|
|
|
|
|
2001-01-31 23:43:27 +00:00
|
|
|
static void TestStandardNames(void);
|
2000-08-10 01:33:48 +00:00
|
|
|
|
2001-05-31 23:07:40 +00:00
|
|
|
void addStandardNamesTest(TestNode** root);
|
2000-08-10 01:33:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
addStandardNamesTest(TestNode** root)
|
|
|
|
{
|
|
|
|
addTest(root, &TestStandardNames, "stdnmtst/TestStandardNames");
|
|
|
|
}
|
|
|
|
|
2000-08-11 04:28:42 +00:00
|
|
|
static int dotestname(const char *name, const char *standard, const char *expected) {
|
|
|
|
int res = 1;
|
|
|
|
|
2000-08-10 01:33:48 +00:00
|
|
|
UErrorCode error;
|
|
|
|
const char *tag;
|
|
|
|
|
|
|
|
error = U_ZERO_ERROR;
|
|
|
|
tag = ucnv_getStandardName(name, standard, &error);
|
|
|
|
if (!tag) {
|
|
|
|
log_err("FAIL: could not find %s standard name for %s\n", standard, name);
|
2000-08-11 19:45:02 +00:00
|
|
|
res = 0;
|
2001-01-02 23:13:54 +00:00
|
|
|
} else if (expected && uprv_stricmp(expected, tag)) {
|
2000-08-10 01:33:48 +00:00
|
|
|
log_err("FAIL: expected %s for %s standard name for %s, got %s\n", expected, standard, name, tag);
|
2000-08-11 19:45:02 +00:00
|
|
|
res = 0;
|
2000-08-10 01:33:48 +00:00
|
|
|
}
|
2000-08-11 04:28:42 +00:00
|
|
|
|
|
|
|
return res;
|
2000-08-10 01:33:48 +00:00
|
|
|
}
|
|
|
|
|
2001-01-31 23:43:27 +00:00
|
|
|
static void TestStandardNames()
|
2000-08-10 01:33:48 +00:00
|
|
|
{
|
2000-08-11 04:28:42 +00:00
|
|
|
int res = 1;
|
|
|
|
|
2000-08-11 19:45:02 +00:00
|
|
|
uint16_t i, count;
|
2000-08-10 21:45:09 +00:00
|
|
|
UErrorCode err;
|
|
|
|
|
|
|
|
/* Iterate over all standards. */
|
2000-08-11 19:45:02 +00:00
|
|
|
|
2000-11-17 19:28:31 +00:00
|
|
|
for (i = 0, count = ucnv_countStandards(); i < count; ++i) {
|
2000-08-10 21:45:09 +00:00
|
|
|
const char *std;
|
|
|
|
|
|
|
|
err = U_ZERO_ERROR;
|
|
|
|
std = ucnv_getStandard(i, &err);
|
|
|
|
if (U_FAILURE(err)) {
|
|
|
|
log_err("FAIL: ucnv_getStandard(%d), error=%s\n", i, u_errorName(err));
|
2000-08-11 04:28:42 +00:00
|
|
|
res = 0;
|
2000-08-10 21:45:09 +00:00
|
|
|
} else if (!std || !*std) {
|
|
|
|
log_err("FAIL: %s standard name at index %d\n", (std ? "empty" :
|
|
|
|
"null"), i);
|
2000-08-11 04:28:42 +00:00
|
|
|
res = 0;
|
2000-08-10 21:45:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
err = U_ZERO_ERROR;
|
|
|
|
if (ucnv_getStandard(i, &err)) {
|
|
|
|
log_err("FAIL: ucnv_getStandard(%d) should return NULL\n", i);
|
2000-08-11 04:28:42 +00:00
|
|
|
res = 0;
|
2000-08-10 21:45:09 +00:00
|
|
|
}
|
|
|
|
|
2000-08-11 04:28:42 +00:00
|
|
|
if (res) {
|
|
|
|
log_verbose("PASS: iterating over standard names works\n");
|
|
|
|
}
|
2000-08-10 21:45:09 +00:00
|
|
|
|
|
|
|
/* Test for some expected results. */
|
|
|
|
|
2000-08-11 04:28:42 +00:00
|
|
|
if (dotestname("ibm-1208", "MIME", "utf-8") &&
|
|
|
|
dotestname("cp1252", "MIME", "windows-1252") &&
|
|
|
|
dotestname("ascii", "MIME", "us-ascii") &&
|
|
|
|
dotestname("ascii", "IANA", "ANSI_X3.4-1968") &&
|
|
|
|
dotestname("cp850", "IANA", "IBM850")) {
|
|
|
|
log_verbose("PASS: getting IANA and MIME stadard names works\n");
|
|
|
|
}
|
2000-08-10 01:33:48 +00:00
|
|
|
}
|
|
|
|
|