mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-15 01:42:37 +00:00
ICU-6453 update sel test to load data from the correct spot.
X-SVN-Rev: 24462
This commit is contained in:
parent
26259c8299
commit
574f3de194
1 changed files with 88 additions and 38 deletions
|
@ -23,6 +23,37 @@
|
|||
#include "cmemory.h"
|
||||
#include "cstring.h"
|
||||
|
||||
#define FILENAME_BUFFER 1024
|
||||
|
||||
#define TDSRCPATH ".."U_FILE_SEP_STRING"test"U_FILE_SEP_STRING"testdata"U_FILE_SEP_STRING
|
||||
|
||||
|
||||
|
||||
|
||||
static FILE *fopenOrError(const char *filename) {
|
||||
int32_t needLen;
|
||||
FILE *f;
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
char fnbuf[FILENAME_BUFFER];
|
||||
const char* directory= ctest_dataSrcDir();
|
||||
needLen = uprv_strlen(directory)+uprv_strlen(TDSRCPATH)+uprv_strlen(filename)+1;
|
||||
if(needLen > FILENAME_BUFFER) {
|
||||
log_err("FAIL: Could not load %s. Filename buffer overflow, needed %d but buffer is %d\n",
|
||||
filename, needLen, FILENAME_BUFFER);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
strcpy(fnbuf, directory);
|
||||
strcat(fnbuf, TDSRCPATH);
|
||||
strcat(fnbuf, filename);
|
||||
|
||||
f = fopen(fnbuf, "rb");
|
||||
|
||||
if(f == NULL) {
|
||||
log_data_err("FAIL: Could not load %s [%s]\n", fnbuf, filename);
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
void addCnvSelTest(TestNode** root)
|
||||
{
|
||||
|
@ -207,21 +238,20 @@ static void TestConversionUTF8()
|
|||
status = U_ZERO_ERROR;
|
||||
sel = ucnvsel_open((const char**)encodings, testCaseIdx-prev, excluded_sets[excluded_set_id], UCNV_ROUNDTRIP_SET, &status);
|
||||
/* count how many bytes (Is there a portable function that is more efficient than this?) */
|
||||
f1 = fopen("../testdata/ConverterSelectorTestUTF8.txt","rb");
|
||||
if(!f1) {
|
||||
log_err("FAIL: Couldn't find ConverterSelectorTestUTF8.txt\n");
|
||||
return;
|
||||
}
|
||||
counter = 0;
|
||||
while(fread(&c, sizeof(c), 1, f1) > 0) counter++;
|
||||
f1 = fopenOrError("ConverterSelectorTestUTF8.txt");
|
||||
if(!f1) {
|
||||
return;
|
||||
}
|
||||
counter = 0;
|
||||
while(fread(&c, sizeof(c), 1, f1) > 0)
|
||||
counter++;
|
||||
fclose(f1);
|
||||
text = (char*)uprv_malloc((counter+1));
|
||||
f1 = fopen("../testdata/ConverterSelectorTestUTF8.txt","rb");
|
||||
if(!f1) {
|
||||
log_err("FAIL: Couldn't find ConverterSelectorTestUTF8.txt\n");
|
||||
f1 = fopenOrError("ConverterSelectorTestUTF8.txt");
|
||||
if(!f1) {
|
||||
return;
|
||||
}
|
||||
fread(text,1, counter,f1);
|
||||
}
|
||||
fread(text,1, counter,f1);
|
||||
fclose(f1);
|
||||
|
||||
|
||||
|
@ -304,15 +334,19 @@ static void TestConversionUTF8()
|
|||
status = U_ZERO_ERROR;
|
||||
sel = ucnvsel_open((const char**)encodings, testCaseIdx-prev, excluded_sets[excluded_set_id], UCNV_ROUNDTRIP_AND_FALLBACK_SET, &status);
|
||||
/* count how many bytes (Is there a portable function that is more efficient than this?) */
|
||||
f1 = fopen("../testdata/ConverterSelectorTestUTF8.txt","rb");
|
||||
if(!f1) { log_err("FAIL: Couldn't find ConverterSelectorTestUTF8.txt\n"); return; }
|
||||
counter = 0;
|
||||
while(fread(&c, sizeof(c), 1, f1) > 0) counter++;
|
||||
f1 = fopenOrError("ConverterSelectorTestUTF8.txt");
|
||||
if(!f1) {
|
||||
return;
|
||||
}
|
||||
counter = 0;
|
||||
while(fread(&c, sizeof(c), 1, f1) > 0) counter++;
|
||||
fclose(f1);
|
||||
text = (char*)uprv_malloc(counter+1);
|
||||
f1 = fopen("../testdata/ConverterSelectorTestUTF8.txt","rb");
|
||||
if(!f1) {log_err("FAIL: Couldn't find ConverterSelectorTestUTF8.txt\n"); return; }
|
||||
fread(text,1, counter,f1);
|
||||
f1 = fopenOrError("ConverterSelectorTestUTF8.txt");
|
||||
if(!f1) {
|
||||
return;
|
||||
}
|
||||
fread(text,1, counter,f1);
|
||||
fclose(f1);
|
||||
|
||||
|
||||
|
@ -490,15 +524,19 @@ static void TestConversionUTF16()
|
|||
status = U_ZERO_ERROR;
|
||||
sel = ucnvsel_open((const char**)encodings, testCaseIdx-prev, excluded_sets[excluded_set_id], UCNV_ROUNDTRIP_SET, &status);
|
||||
/* count how many bytes (Is there a portable function that is more efficient than this?) */
|
||||
f1 = fopen("../testdata/ConverterSelectorTestUTF16.txt","rb");
|
||||
if(!f1) { log_err("FAIL: Couldn't find ConverterSelectorTestUTF16.txt\n"); return; }
|
||||
counter = 0;
|
||||
while(fread(&c, sizeof(c), 1, f1) > 0) counter++;
|
||||
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 = fopen("../testdata/ConverterSelectorTestUTF16.txt","rb");
|
||||
if(!f1) { log_err("FAIL: Couldn't find ConverterSelectorTestUTF16.txt\n"); return; }
|
||||
fread(text,sizeof(UChar), counter,f1);
|
||||
f1 = fopenOrError("ConverterSelectorTestUTF16.txt");
|
||||
if(!f1) {
|
||||
return; /* error was already printed */
|
||||
}
|
||||
fread(text,sizeof(UChar), counter,f1);
|
||||
fclose(f1);
|
||||
|
||||
|
||||
|
@ -582,14 +620,18 @@ static void TestConversionUTF16()
|
|||
status = U_ZERO_ERROR;
|
||||
sel = ucnvsel_open((const char**)encodings, testCaseIdx-prev, excluded_sets[excluded_set_id], UCNV_ROUNDTRIP_AND_FALLBACK_SET, &status);
|
||||
/* count how many bytes (Is there a portable function that is more efficient than this?) */
|
||||
f1 = fopen("../testdata/ConverterSelectorTestUTF16.txt","rb");
|
||||
if(!f1) { log_err("FAIL: Couldn't find ConverterSelectorTestUTF16.txt\n"); return; }
|
||||
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 = fopen("../testdata/ConverterSelectorTestUTF16.txt","rb");
|
||||
if(!f1) { log_err("FAIL: Couldn't find ConverterSelectorTestUTF16.txt\n"); return; }
|
||||
f1 = fopenOrError("ConverterSelectorTestUTF16.txt");
|
||||
if(!f1) {
|
||||
return; /* error was already printed */
|
||||
}
|
||||
fread(text,sizeof(UChar), counter,f1);
|
||||
fclose(f1);
|
||||
|
||||
|
@ -723,14 +765,18 @@ static void TestSerializationAndUnserialization()
|
|||
sel = ucnvsel_unserialize( buffer, ser_len,&status);
|
||||
|
||||
/* count how many bytes (Is there a portable function that is more efficient than this?) */
|
||||
f1 = fopen("../testdata/ConverterSelectorTestUTF16.txt","rb");
|
||||
if(!f1) { log_err("FAIL: Couldn't find ConverterSelectorTestUTF16.txt\n"); return; }
|
||||
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 = fopen("../testdata/ConverterSelectorTestUTF16.txt","rb");
|
||||
if(!f1) { log_err("FAIL: Couldn't find ConverterSelectorTestUTF16.txt\n"); return; }
|
||||
f1 = fopenOrError("ConverterSelectorTestUTF16.txt");
|
||||
if(!f1) {
|
||||
return; /* error was already printed */
|
||||
}
|
||||
fread(text,sizeof(text[0]), counter,f1);
|
||||
fclose(f1);
|
||||
|
||||
|
@ -825,14 +871,18 @@ static void TestSerializationAndUnserialization()
|
|||
sel = ucnvsel_unserialize( buffer, ser_len,&status);
|
||||
|
||||
/* count how many bytes (Is there a portable function that is more efficient than this?) */
|
||||
f1 = fopen("../testdata/ConverterSelectorTestUTF16.txt","rb");
|
||||
if(!f1) { log_err("FAIL: Couldn't find ConverterSelectorTestUTF16.txt\n"); return; }
|
||||
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 = fopen("../testdata/ConverterSelectorTestUTF16.txt","rb");
|
||||
if(!f1) { log_err("FAIL: Couldn't find ConverterSelectorTestUTF16.txt\n"); return; }
|
||||
f1 = fopenOrError("ConverterSelectorTestUTF16.txt");
|
||||
if(!f1) {
|
||||
return; /* error was already printed */
|
||||
}
|
||||
fread(text,sizeof(text[0]), counter,f1);
|
||||
fclose(f1);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue