ICU-6453 more test cleanup

X-SVN-Rev: 25870
This commit is contained in:
Markus Scherer 2009-04-22 22:42:40 +00:00
parent 49fe81a7c5
commit 131e1b25ab
2 changed files with 150 additions and 448 deletions

View file

@ -29,10 +29,11 @@
#define TDSRCPATH ".." U_FILE_SEP_STRING "test" U_FILE_SEP_STRING "testdata" U_FILE_SEP_STRING
static void TestSelector(void);
void addCnvSelTest(TestNode** root)
{
addTest(root, &TestSelect, "tsconv/ucnvseltst/TestSelect");
addTest(root, &TestSerializationAndUnserialization, "tsconv/ucnvseltst/TestSerializationAndUnserialization");
addTest(root, &TestSelector, "tsconv/ucnvseltst/TestSelector");
}
static const char **gAvailableNames = NULL;
@ -175,44 +176,86 @@ static FILE *fopenOrError(const char *filename) {
return f;
}
typedef struct TestText {
char *text, *textLimit;
char *limit;
int32_t number;
} TestText;
static void
text_reset(TestText *tt) {
tt->limit = tt->text;
tt->number = 0;
}
static char *
loadText(int32_t *pLength) {
char *text;
FILE *f = fopenOrError("ConverterSelectorTestUTF8.txt");
if(!f) {
*pLength = 0;
text_nextString(TestText *tt, int32_t *pLength) {
char *s = tt->limit;
if (s == tt->textLimit) {
/* we already delivered the last string */
return NULL;
} else if (s == tt->text) {
/* first string */
if ((tt->textLimit - tt->text) >= 3 &&
s[0] == (char)0xef && s[1] == (char)0xbb && s[2] == (char)0xbf
) {
s += 3; /* skip the UTF-8 signature byte sequence (U+FEFF) */
}
} else {
/* skip the string terminator */
++s;
++tt->number;
}
/* find the end of this string */
tt->limit = uprv_strchr(s, 0);
*pLength = (int32_t)(tt->limit - s);
return s;
}
static UBool
text_open(TestText *tt) {
FILE *f;
char *s;
int32_t length;
uprv_memset(tt, 0, sizeof(TestText));
f = fopenOrError("ConverterSelectorTestUTF8.txt");
if(!f) {
return FALSE;
}
fseek(f, 0, SEEK_END);
*pLength = (int32_t)ftell(f);
length = (int32_t)ftell(f);
fseek(f, 0, SEEK_SET);
text = (char *)uprv_malloc(*pLength + 1);
if (*pLength != fread(text, 1, *pLength, f)) {
log_err("error reading %ld bytes from test text file\n", (long)*pLength);
*pLength = 0;
uprv_free(text);
tt->text = (char *)uprv_malloc(length + 1);
if (tt->text == NULL) {
fclose(f);
return FALSE;
}
if (length != fread(tt->text, 1, length, f)) {
log_err("error reading %ld bytes from test text file\n", (long)length);
length = 0;
uprv_free(tt->text);
}
fclose(f);
text[*pLength] = 0;
return text;
tt->textLimit = tt->text + length;
*tt->textLimit = 0;
/* replace all Unicode '#' (U+0023) with NUL */
for(s = tt->text; (s = uprv_strchr(s, 0x23)) != NULL; *s++ = 0) {}
text_reset(tt);
return TRUE;
}
static void
text_close(TestText *tt) {
uprv_free(tt->text);
}
static int32_t findIndex(const char* converterName) {
UErrorCode status = U_ZERO_ERROR;
int32_t i;
for (i = 0 ; i < ucnv_countAvailable() ; i++) {
uint16_t alias_index;
const char* convName = ucnv_getAvailableName(i);
if(ucnv_compareNames(convName, converterName) == 0) {
for (i = 0 ; i < gCountAvailable; i++) {
if(ucnv_compareNames(gAvailableNames[i], converterName) == 0) {
return i;
}
for (alias_index = 0 ; alias_index < ucnv_countAliases(convName, & status) ; alias_index++) {
const char* aliasName = ucnv_getAlias(convName, alias_index, & status);
if(ucnv_compareNames(aliasName, converterName) == 0) {
return i;
}
}
}
return -1;
}
@ -247,6 +290,17 @@ getResultsManually(const char** encodings, int32_t num_encodings,
cp = 0;
encIndex = findIndex(encodings[i]);
/*
* The following is almost, but not entirely, the same as
* resultsManually[encIndex] =
* (UBool)(uset_spanUTF8(set, utf8, length, USET_SPAN_SIMPLE) == length);
* They might be different if the set contains strings,
* or if the utf8 string contains an illegal sequence.
*
* The UConverterSelector does not currently handle strings that can be
* converted, and it treats an illegal sequence as convertible
* while uset_spanUTF8() treats it like U+FFFD which may not be convertible.
*/
resultsManually[encIndex] = TRUE;
while(offset<length) {
U8_NEXT(utf8, offset, length, cp);
@ -284,21 +338,47 @@ static void verifyResult(UEnumeration* res, const UBool *resultsManually) {
uenum_close(res);
}
static void TestSelect()
static UConverterSelector *
serializeAndUnserialize(UConverterSelector *sel, char **buffer, UErrorCode *status) {
char *new_buffer;
int32_t ser_len, ser_len2;
/* preflight */
ser_len = ucnvsel_serialize(sel, NULL, 0, status);
if (*status != U_BUFFER_OVERFLOW_ERROR) {
log_err("ucnvsel_serialize(preflighting) failed: %s\n", u_errorName(*status));
return sel;
}
new_buffer = (char *)uprv_malloc(ser_len);
*status = U_ZERO_ERROR;
ser_len2 = ucnvsel_serialize(sel, new_buffer, ser_len, status);
if (U_FAILURE(*status) || ser_len != ser_len2) {
log_err("ucnvsel_serialize() failed: %s\n", u_errorName(*status));
uprv_free(new_buffer);
return sel;
}
ucnvsel_close(sel);
uprv_free(*buffer);
*buffer = new_buffer;
sel = ucnvsel_openFromSerialized(new_buffer, ser_len, status);
if (U_FAILURE(*status)) {
log_err("ucnvsel_openFromSerialized() failed: %s\n", u_errorName(*status));
return NULL;
}
return sel;
}
static void TestSelector()
{
char *text, *textLimit;
int32_t textLength;
TestText text;
USet* excluded_sets[3] = { NULL };
int32_t i, testCaseIdx;
if (!getAvailableNames()) {
return;
}
text = loadText(&textLength);
if (text == NULL) {
if (!text_open(&text)) {
releaseAvailableNames();;
}
textLimit = text + textLength;
excluded_sets[0] = uset_openEmpty();
for(i = 1 ; i < 3 ; i++) {
@ -315,10 +395,18 @@ static void TestSelect()
continue;
}
for(excluded_set_id = 0 ; excluded_set_id < 3 ; excluded_set_id++) {
int32_t curString;
char *s, *limit;
/*
* for(excluded_set_id = 0 ; excluded_set_id < 3 ; excluded_set_id++)
*
* This loop was replaced by the following statement because
* the loop made the test run longer without adding to the code coverage.
* The handling of the exclusion set is independent of the
* set of encodings, so there is no need to test every combination.
*/
excluded_set_id = testCaseIdx % LENGTHOF(excluded_sets);
{
UConverterSelector *sel_rt, *sel_fb;
char *buffer_fb = NULL;
UErrorCode status = U_ZERO_ERROR;
sel_rt = ucnvsel_open(encodings, num_encodings,
excluded_sets[excluded_set_id],
@ -328,6 +416,11 @@ static void TestSelect()
sel_fb = ucnvsel_open(NULL, 0,
excluded_sets[excluded_set_id],
UCNV_ROUNDTRIP_AND_FALLBACK_SET, &status);
} else if (uset_isEmpty(excluded_sets[excluded_set_id])) {
/* test that a NULL set gives the same results as an empty set */
sel_fb = ucnvsel_open(encodings, num_encodings,
NULL,
UCNV_ROUNDTRIP_AND_FALLBACK_SET, &status);
} else {
sel_fb = ucnvsel_open(encodings, num_encodings,
excluded_sets[excluded_set_id],
@ -340,28 +433,17 @@ static void TestSelect()
continue;
}
curString = 0;
s = text;
if (textLength >= 3 && s[0] == (char)0xef && s[1] == (char)0xbb && s[2] == (char)0xbf) {
s += 3; /* skip the UTF-8 signature byte sequence (U+FEFF) */
}
text_reset(&text);
for (;;) {
UBool *manual_rt, *manual_fb;
static UChar utf16[10000];
char *s;
int32_t length8, length16;
if (QUICK && curString > 2) {
s = text_nextString(&text, &length8);
if (s == NULL || (QUICK && text.number > 3)) {
break;
}
/* find the end of this string */
limit = s;
while (limit != textLimit && *limit != 0x23 /* '#' */) {
++limit;
}
if (limit != textLimit) {
*limit = 0; /* *textLimit already is 0 */
}
length8 = (int32_t)(limit - s);
manual_rt = getResultsManually(encodings, num_encodings,
s, length8,
@ -372,6 +454,7 @@ static void TestSelect()
excluded_sets[excluded_set_id],
UCNV_ROUNDTRIP_AND_FALLBACK_SET);
/* UTF-8 with length */
status = U_ZERO_ERROR;
verifyResult(ucnvsel_selectForUTF8(sel_rt, s, length8, &status), manual_rt);
verifyResult(ucnvsel_selectForUTF8(sel_fb, s, length8, &status), manual_fb);
/* UTF-8 NUL-terminated */
@ -381,409 +464,34 @@ static void TestSelect()
u_strFromUTF8(utf16, LENGTHOF(utf16), &length16, s, length8, &status);
if (U_FAILURE(status)) {
log_err("error converting the test text (string %ld) to UTF-16 - %s\n",
(long)curString, u_errorName(status));
break;
(long)text.number, u_errorName(status));
} else {
/* UTF-16 with length */
verifyResult(ucnvsel_selectForString(sel_rt, utf16, length16, &status), manual_rt);
verifyResult(ucnvsel_selectForString(sel_fb, utf16, length16, &status), manual_fb);
/* UTF-16 NUL-terminated */
verifyResult(ucnvsel_selectForString(sel_rt, utf16, -1, &status), manual_rt);
verifyResult(ucnvsel_selectForString(sel_fb, utf16, -1, &status), manual_fb);
if (text.number == 0) {
sel_fb = serializeAndUnserialize(sel_fb, &buffer_fb, &status);
}
if (U_SUCCESS(status)) {
/* UTF-16 with length */
verifyResult(ucnvsel_selectForString(sel_rt, utf16, length16, &status), manual_rt);
verifyResult(ucnvsel_selectForString(sel_fb, utf16, length16, &status), manual_fb);
/* UTF-16 NUL-terminated */
verifyResult(ucnvsel_selectForString(sel_rt, utf16, -1, &status), manual_rt);
verifyResult(ucnvsel_selectForString(sel_fb, utf16, -1, &status), manual_fb);
}
}
uprv_free(manual_rt);
uprv_free(manual_fb);
if (limit == textLimit) {
break;
} else {
/* restore and skip the string delimiter */
*limit = 0x23;
s = limit + 1;
++curString;
}
}
ucnvsel_close(sel_rt);
ucnvsel_close(sel_fb);
uprv_free(buffer_fb);
}
uprv_free((void *)encodings);
}
releaseAvailableNames();
uprv_free(text);
text_close(&text);
for(i = 0 ; i < 3 ; i++) {
uset_close(excluded_sets[i]);
}
}
/* TODO: clean up the following test function like the previous one; get rid of the helper functions */
/*
* fill a boolean array with whether the conversion succeeded
* or not
*/
static void fillBool(UEnumeration* res, UBool* toFill, int32_t toFillLen) {
UErrorCode status = U_ZERO_ERROR;
int32_t i;
for(i = 0 ; i < toFillLen ; i++)
toFill[i] = FALSE;
for(i = 0 ; i < uenum_count(res,&status) ; i++) {
const char* name = uenum_next(res,NULL, &status);
toFill[findIndex(name)] = TRUE;
}
}
static void verifyResultUTF16(const UChar* const s, const char** encodings, int32_t num_encodings, UEnumeration* res, const USet* excludedEncodings, const UConverterUnicodeSet whichSet) {
UBool* resultsFromSystem;
UBool* resultsManually;
int32_t i;
resultsFromSystem = (UBool*) uprv_malloc(ucnv_countAvailable() * sizeof(UBool));
resultsManually = (UBool*) uprv_malloc(ucnv_countAvailable() * sizeof(UBool));
for(i = 0 ; i < ucnv_countAvailable() ; i++)
resultsFromSystem[i] = resultsManually[i] = FALSE;
for(i = 0 ; i < num_encodings ; i++) {
UErrorCode status = U_ZERO_ERROR;
/* get unicode set for that converter */
USet* unicode_point_set;
UConverter* test_converter;
int32_t offset;
int32_t length;
UChar32 next;
resultsManually[findIndex(encodings[i])] = TRUE;
unicode_point_set = uset_open(1, 0);
test_converter = ucnv_open(encodings[i], &status);
ucnv_getUnicodeSet(test_converter, unicode_point_set,
whichSet, &status);
offset = 0;
length = u_strlen(s);
resultsManually[findIndex(encodings[i])] = TRUE;
next = 0;
while(offset<length) {
/* loop over string */
U16_NEXT(s, offset, length, next)
if (uset_contains(excludedEncodings, next)==FALSE && uset_contains(unicode_point_set, next)==FALSE) {
resultsManually[findIndex(encodings[i])] = FALSE;
break;
}
}
uset_close(unicode_point_set);
ucnv_close(test_converter);
}
/* fill the bool for the selector results! */
fillBool(res, resultsFromSystem, ucnv_countAvailable());
for(i = 0 ; i < ucnv_countAvailable() ; i++) {
if(resultsManually[i] != resultsFromSystem[i]) {
log_err("failure in converter selector converter %s had conflicting results manual: %d, system %d\n",ucnv_getAvailableName(i), resultsManually[i], resultsFromSystem[i]);
}
}
uprv_free(resultsFromSystem);
uprv_free(resultsManually);
}
static void TestSerializationAndUnserialization()
{
/*
* test cases are separated by a -1
* each line is one test case including encodings to check for
* I'd like to generate this array randomly but not sure if this is an allowed practice in ICU
*/
int32_t encodingsTestCases[] = { 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, -1,
1, 3, 7, 9, 11, 13, 12, 15, 19, 20, 22, 24, -1,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1,
0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, -1,
1, 5, 9, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, -1,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129,
130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189,
190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, -1, 1, -1};
int32_t test_case_count = sizeof(encodingsTestCases) / sizeof(encodingsTestCases[0]);
USet* excluded_sets[3];
int32_t i;
int32_t prev, testCaseIdx;
/* try roundtrip mapping */
int32_t excluded_set_id;
int32_t curCase;
if (!getAvailableNames()) {
return;
}
excluded_sets[0] = uset_open(1,0);
for(i = 1 ; i < 3 ; i++)
excluded_sets[i] = uset_open(i*30, i*30+500);
curCase = 0;
for(excluded_set_id = 0 ; excluded_set_id < 3 ; excluded_set_id++)
for(testCaseIdx = 0, prev=0, curCase =0 ; testCaseIdx < test_case_count ; testCaseIdx++)
{
UErrorCode status;
UEnumeration* res1;
int32_t i;
USet* partial_set;
UConverterSelector* sel;
char** encodings;
int32_t num_encodings;
int32_t totalStrLen;
char* names;
char *buffer;
uint32_t ser_len;
FILE* f1;
int32_t counter;
UChar c;
UChar* text;
int32_t curTestCase;
if(encodingsTestCases[testCaseIdx] != -1) continue;
curCase++;
if(QUICK && curCase > 2)
break;
status = U_ZERO_ERROR;
partial_set = NULL;
encodings = (char**) uprv_malloc((testCaseIdx - prev) * sizeof(char*));
num_encodings = testCaseIdx - prev;
totalStrLen = 0;
for(i = prev ; i < testCaseIdx ; i++) {
totalStrLen += uprv_strlen(ucnv_getAvailableName(encodingsTestCases[i]))+1;
}
names = (char*)uprv_malloc(totalStrLen);
uprv_memset(names, 0, totalStrLen);
for(i = prev ; i < testCaseIdx ; i++) {
uprv_memcpy(names, ucnv_getAvailableName(encodingsTestCases[i]), uprv_strlen(ucnv_getAvailableName(encodingsTestCases[i])));
encodings[i-prev] = names;
names+=uprv_strlen(ucnv_getAvailableName(encodingsTestCases[i]))+1;
}
/* first time */
status = U_ZERO_ERROR;
sel = ucnvsel_open((const char**)encodings, testCaseIdx-prev, excluded_sets[excluded_set_id], UCNV_ROUNDTRIP_SET, &status);
if (U_FAILURE(status)) {
log_err("ucnvsel_open(test case %d) failed: %s\n", curCase, u_errorName(status));
uprv_free(encodings);
uprv_free(names);
return;
}
buffer = NULL;
ser_len = ucnvsel_serialize(sel, NULL, 0, &status);
if (status != U_BUFFER_OVERFLOW_ERROR) {
log_err("ucnvsel_serialize(test case %d preflighting) failed: %s\n", curCase, u_errorName(status));
ucnvsel_close(sel);
uprv_free(encodings);
uprv_free(names);
return;
}
buffer = uprv_malloc(ser_len);
status = U_ZERO_ERROR;
ucnvsel_serialize(sel, buffer, ser_len, &status);
ucnvsel_close(sel);
if (U_FAILURE(status)) {
log_err("ucnvsel_serialize(test case %d) failed: %s\n", curCase, u_errorName(status));
uprv_free(encodings);
uprv_free(names);
uprv_free(buffer);
return;
}
sel = ucnvsel_openFromSerialized( buffer, ser_len,&status);
if (U_FAILURE(status)) {
log_err("ucnvsel_openFromSerialized(test case %d) failed: %s\n", curCase, u_errorName(status));
uprv_free(encodings);
uprv_free(names);
uprv_free(buffer);
return;
}
/* count how many bytes (Is there a portable function that is more efficient than this?) */
f1 = fopenOrError("ConverterSelectorTestUTF16.txt");
if(!f1) {
return; /* error was already printed */
}
counter = 0;
while(fread(&c, sizeof(c), 1, f1) > 0) counter++;
fclose(f1);
text = (UChar*)uprv_malloc((counter+1)*sizeof(UChar));
f1 = fopenOrError("ConverterSelectorTestUTF16.txt");
if(!f1) {
return; /* error was already printed */
}
fread(text,sizeof(text[0]), counter,f1);
fclose(f1);
for (i = 0 ; i < counter ; i++) {
if(text[i] == (UChar)'#')
text[i] = 0;
}
text[counter] = 0;
curTestCase=0;
for (i = 0 ; i < counter ; i++) {
if(i==0 || text[i-1] == 0) {
curTestCase++;
if(curTestCase > 2 && QUICK)
break;
/* test, both with length, and NULL terminated */
res1 = ucnvsel_selectForString(sel, text+i, -1, &status);
if (U_FAILURE(status)) {
log_err("ucnvsel_selectForString(test case %d, string %d with NUL) failed: %s\n",
curCase, curTestCase, u_errorName(status));
continue;
}
/* make sure result is correct! */
verifyResultUTF16(text+i, (const char**) encodings, num_encodings, res1, excluded_sets[excluded_set_id], UCNV_ROUNDTRIP_SET);
uenum_close(res1);
res1 = ucnvsel_selectForString(sel, text+i, u_strlen(text+i), &status);
if (U_FAILURE(status)) {
log_err("ucnvsel_selectForString(test case %d, string %d with length) failed: %s\n",
curCase, curTestCase, u_errorName(status));
continue;
}
/* make sure result is correct! */
verifyResultUTF16(text+i, (const char**)encodings, num_encodings, res1, excluded_sets[excluded_set_id], UCNV_ROUNDTRIP_SET);
uenum_close(res1);
}
}
uprv_free(text);
uprv_free(encodings[0]);
uprv_free(encodings);
ucnvsel_close(sel);
prev = testCaseIdx + 1;
uprv_free(buffer);
}
/* ////////////////////////////////////////////////////////////////////////// */
/* try fallback mapping! */
for(excluded_set_id = 0 ; excluded_set_id < 3 ; excluded_set_id++)
for(testCaseIdx = 0, prev=0, curCase=0 ; testCaseIdx < test_case_count ; testCaseIdx++)
{
UErrorCode status;
UEnumeration* res1;
int32_t i;
USet* partial_set;
UConverterSelector* sel;
char** encodings;
int32_t num_encodings;
int32_t totalStrLen;
char* names;
char *buffer;
uint32_t ser_len;
FILE* f1;
int32_t counter;
UChar c;
UChar* text;
int32_t curTestCase;
if(encodingsTestCases[testCaseIdx] != -1) continue;
curCase++;
if(QUICK && curCase > 2)
break;
status = U_ZERO_ERROR;
partial_set = NULL;
encodings = (char**)uprv_malloc((testCaseIdx - prev) * sizeof(char*));
num_encodings = testCaseIdx - prev;
totalStrLen = 0;
for(i = prev ; i < testCaseIdx ; i++) {
totalStrLen += uprv_strlen(ucnv_getAvailableName(encodingsTestCases[i]))+1;
}
names = (char*)uprv_malloc(totalStrLen);
uprv_memset(names, 0, totalStrLen);
for(i = prev ; i < testCaseIdx ; i++) {
uprv_memcpy(names, ucnv_getAvailableName(encodingsTestCases[i]), uprv_strlen(ucnv_getAvailableName(encodingsTestCases[i])));
encodings[i-prev] = names;
names+=uprv_strlen(ucnv_getAvailableName(encodingsTestCases[i]))+1;
}
/* first time */
status = U_ZERO_ERROR;
sel = ucnvsel_open((const char**)encodings, testCaseIdx-prev, excluded_sets[excluded_set_id], UCNV_ROUNDTRIP_AND_FALLBACK_SET, &status);
buffer = NULL;
ser_len = ucnvsel_serialize(sel, NULL, 0, &status);
buffer = uprv_malloc(ser_len);
status = U_ZERO_ERROR;
ucnvsel_serialize(sel, buffer, ser_len, &status);
ucnvsel_close(sel);
sel = ucnvsel_openFromSerialized( buffer, ser_len,&status);
/* count how many bytes (Is there a portable function that is more efficient than this?) */
f1 = fopenOrError("ConverterSelectorTestUTF16.txt");
if(!f1) {
return; /* error was already printed */
}
counter = 0;
while(fread(&c, sizeof(c), 1, f1) > 0) counter++;
fclose(f1);
text = (UChar*)uprv_malloc((counter+1)*sizeof(UChar));
f1 = fopenOrError("ConverterSelectorTestUTF16.txt");
if(!f1) {
return; /* error was already printed */
}
fread(text,sizeof(text[0]), counter,f1);
fclose(f1);
for (i = 0 ; i < counter ; i++) {
if(text[i] == (UChar)'#')
text[i] = 0;
}
text[counter] = 0;
curTestCase=0;
for (i = 0 ; i < counter ; i++) {
if(i==0 || text[i-1] == 0) {
curTestCase++;
if(curTestCase > 2 && QUICK)
break;
/* test, both with length, and NULL terminated */
res1 = ucnvsel_selectForString(sel, text+i, -1, &status);
/* make sure result is correct! */
verifyResultUTF16(text+i, (const char**)encodings, num_encodings, res1,excluded_sets[excluded_set_id], UCNV_ROUNDTRIP_AND_FALLBACK_SET);
uenum_close(res1);
res1 = ucnvsel_selectForString(sel, text+i, u_strlen(text+i), &status);
/* make sure result is correct! */
verifyResultUTF16(text+i, (const char**)encodings, num_encodings, res1,excluded_sets[excluded_set_id], UCNV_ROUNDTRIP_AND_FALLBACK_SET);
uenum_close(res1);
}
}
uprv_free(encodings[0]);
uprv_free(encodings);
uprv_free(text);
ucnvsel_close(sel);
prev = testCaseIdx + 1;
uprv_free(buffer);
}
for(i = 0 ; i < 3 ; i++)
uset_close(excluded_sets[i]);
releaseAvailableNames();
}

View file

@ -18,12 +18,6 @@
#include "unicode/utypes.h"
#include "cintltst.h"
/**
* The function used to test converter selection
**/
static void TestSelect(void);
/**
* The function used to test serialization and unserialization
**/
static void TestSerializationAndUnserialization(void);
/** TODO: Remove this file after ICU 4.2 is released. See ticket #6869. */
#endif