ICU-10028 u_finit and u_fadopt test
X-SVN-Rev: 34184
This commit is contained in:
parent
e001989611
commit
f2844dc9e1
@ -22,6 +22,8 @@
|
|||||||
|
|
||||||
const char *STANDARD_TEST_FILE = "iotest-c.txt";
|
const char *STANDARD_TEST_FILE = "iotest-c.txt";
|
||||||
|
|
||||||
|
const char *STANDARD_TEST_LOCALE = "en_US_POSIX";
|
||||||
|
|
||||||
|
|
||||||
#if !UCONFIG_NO_FORMATTING
|
#if !UCONFIG_NO_FORMATTING
|
||||||
static void TestFileFromICU(UFILE *myFile) {
|
static void TestFileFromICU(UFILE *myFile) {
|
||||||
@ -98,7 +100,7 @@ static void TestFileFromICU(UFILE *myFile) {
|
|||||||
fprintf(u_fgetfile(myFile), "\tNormal fprintf count value: n=%d\n", (int)*n); /* Should be 27 as stated later on. */
|
fprintf(u_fgetfile(myFile), "\tNormal fprintf count value: n=%d\n", (int)*n); /* Should be 27 as stated later on. */
|
||||||
|
|
||||||
u_fclose(myFile);
|
u_fclose(myFile);
|
||||||
myFile = u_fopen(STANDARD_TEST_FILE, "r", "en_US_POSIX", NULL);
|
myFile = u_fopen(STANDARD_TEST_FILE, "r", STANDARD_TEST_LOCALE, NULL);
|
||||||
|
|
||||||
if (myFile == NULL) {
|
if (myFile == NULL) {
|
||||||
log_err("Can't read test file.");
|
log_err("Can't read test file.");
|
||||||
@ -310,22 +312,26 @@ static void TestFileFromICU(UFILE *myFile) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void TestFile(void) {
|
static void TestFile(void) {
|
||||||
/* FILE *standardFile;*/
|
|
||||||
|
|
||||||
log_verbose("Testing u_fopen\n");
|
log_verbose("Testing u_fopen\n");
|
||||||
TestFileFromICU(u_fopen(STANDARD_TEST_FILE, "w", "en_US_POSIX", NULL));
|
TestFileFromICU(u_fopen(STANDARD_TEST_FILE, "w", STANDARD_TEST_LOCALE, NULL));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void TestFinit(void) {
|
||||||
|
FILE *standardFile;
|
||||||
|
|
||||||
/* Don't know how to make this work without stdout or stderr */
|
|
||||||
/*
|
|
||||||
log_verbose("Testing u_finit\n");
|
log_verbose("Testing u_finit\n");
|
||||||
standardFile = fopen(STANDARD_TEST_FILE, "wb");
|
standardFile = fopen(STANDARD_TEST_FILE, "w");
|
||||||
TestFileFromICU(u_finit(standardFile, NULL, NULL));
|
TestFileFromICU(u_finit(standardFile, STANDARD_TEST_LOCALE, NULL));
|
||||||
fclose(standardFile);
|
fclose(standardFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void TestFadopt(void) {
|
||||||
|
FILE *standardFile;
|
||||||
|
|
||||||
log_verbose("Testing u_fadopt\n");
|
log_verbose("Testing u_fadopt\n");
|
||||||
standardFile = fopen(STANDARD_TEST_FILE, "wb");
|
standardFile = fopen(STANDARD_TEST_FILE, "w");
|
||||||
TestFileFromICU(u_fadopt(standardFile, NULL, NULL));
|
TestFileFromICU(u_fadopt(standardFile, STANDARD_TEST_LOCALE, NULL));
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -917,7 +923,7 @@ static void TestCodepageFlush(void) {
|
|||||||
uint8_t inBuf[200];
|
uint8_t inBuf[200];
|
||||||
size_t inLen =0;
|
size_t inLen =0;
|
||||||
const char *enc = "IBM-1388"; /* GBK EBCDIC stateful */
|
const char *enc = "IBM-1388"; /* GBK EBCDIC stateful */
|
||||||
UFILE *myFile = u_fopen(STANDARD_TEST_FILE, "wb", "en_US_POSIX", enc);
|
UFILE *myFile = u_fopen(STANDARD_TEST_FILE, "wb", STANDARD_TEST_LOCALE, enc);
|
||||||
FILE *myCFile;
|
FILE *myCFile;
|
||||||
int shift = 0;
|
int shift = 0;
|
||||||
int32_t i;
|
int32_t i;
|
||||||
@ -974,7 +980,7 @@ static void TestCodepageFlush(void) {
|
|||||||
|
|
||||||
#if !UCONFIG_NO_FORMATTING
|
#if !UCONFIG_NO_FORMATTING
|
||||||
static void TestFilePrintCompatibility(void) {
|
static void TestFilePrintCompatibility(void) {
|
||||||
UFILE *myFile = u_fopen(STANDARD_TEST_FILE, "wb", "en_US_POSIX", NULL);
|
UFILE *myFile = u_fopen(STANDARD_TEST_FILE, "wb", STANDARD_TEST_LOCALE, NULL);
|
||||||
FILE *myCFile;
|
FILE *myCFile;
|
||||||
int32_t num;
|
int32_t num;
|
||||||
char cVal;
|
char cVal;
|
||||||
@ -988,7 +994,7 @@ static void TestFilePrintCompatibility(void) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#if !UCONFIG_NO_FORMATTING
|
#if !UCONFIG_NO_FORMATTING
|
||||||
if (strcmp(u_fgetlocale(myFile), "en_US_POSIX") != 0) {
|
if (strcmp(u_fgetlocale(myFile), STANDARD_TEST_LOCALE) != 0) {
|
||||||
log_err("Got %s instead of en_US_POSIX for locale\n", u_fgetlocale(myFile));
|
log_err("Got %s instead of en_US_POSIX for locale\n", u_fgetlocale(myFile));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -1112,7 +1118,7 @@ static void TestFilePrintCompatibility(void) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define TestFPrintFormat(uFormat, uValue, cFormat, cValue) \
|
#define TestFPrintFormat(uFormat, uValue, cFormat, cValue) \
|
||||||
myFile = u_fopen(STANDARD_TEST_FILE, "w", "en_US_POSIX", NULL);\
|
myFile = u_fopen(STANDARD_TEST_FILE, "w", STANDARD_TEST_LOCALE, NULL);\
|
||||||
if (myFile == NULL) {\
|
if (myFile == NULL) {\
|
||||||
log_err("Can't write test file for %s.\n", uFormat);\
|
log_err("Can't write test file for %s.\n", uFormat);\
|
||||||
return;\
|
return;\
|
||||||
@ -1123,7 +1129,7 @@ static void TestFilePrintCompatibility(void) {
|
|||||||
\
|
\
|
||||||
uNumPrinted = u_fprintf(myFile, uFormat, uValue);\
|
uNumPrinted = u_fprintf(myFile, uFormat, uValue);\
|
||||||
u_fclose(myFile);\
|
u_fclose(myFile);\
|
||||||
myFile = u_fopen(STANDARD_TEST_FILE, "r", "en_US_POSIX", NULL);\
|
myFile = u_fopen(STANDARD_TEST_FILE, "r", STANDARD_TEST_LOCALE, NULL);\
|
||||||
u_fgets(uBuffer, sizeof(uBuffer)/sizeof(*uBuffer), myFile);\
|
u_fgets(uBuffer, sizeof(uBuffer)/sizeof(*uBuffer), myFile);\
|
||||||
u_fclose(myFile);\
|
u_fclose(myFile);\
|
||||||
u_austrncpy(compBuffer, uBuffer, sizeof(uBuffer)/sizeof(*uBuffer));\
|
u_austrncpy(compBuffer, uBuffer, sizeof(uBuffer)/sizeof(*uBuffer));\
|
||||||
@ -1254,14 +1260,14 @@ static void TestFprintfFormat(void) {
|
|||||||
TestFPrintFormat("%3f", 1.234, "%3f", 1.234);
|
TestFPrintFormat("%3f", 1.234, "%3f", 1.234);
|
||||||
TestFPrintFormat("%3f", -1.234, "%3f", -1.234);
|
TestFPrintFormat("%3f", -1.234, "%3f", -1.234);
|
||||||
|
|
||||||
myFile = u_fopen(STANDARD_TEST_FILE, "w", "en_US_POSIX", NULL);
|
myFile = u_fopen(STANDARD_TEST_FILE, "w", STANDARD_TEST_LOCALE, NULL);
|
||||||
/* Reinitialize the buffer to verify null termination works. */
|
/* Reinitialize the buffer to verify null termination works. */
|
||||||
u_memset(uBuffer, 0x2a, sizeof(uBuffer)/sizeof(*uBuffer));
|
u_memset(uBuffer, 0x2a, sizeof(uBuffer)/sizeof(*uBuffer));
|
||||||
memset(buffer, '*', sizeof(buffer)/sizeof(*buffer));
|
memset(buffer, '*', sizeof(buffer)/sizeof(*buffer));
|
||||||
|
|
||||||
uNumPrinted = u_fprintf(myFile, "%d % d %d", -1234, 1234, 1234);
|
uNumPrinted = u_fprintf(myFile, "%d % d %d", -1234, 1234, 1234);
|
||||||
u_fclose(myFile);
|
u_fclose(myFile);
|
||||||
myFile = u_fopen(STANDARD_TEST_FILE, "r", "en_US_POSIX", NULL);
|
myFile = u_fopen(STANDARD_TEST_FILE, "r", STANDARD_TEST_LOCALE, NULL);
|
||||||
u_fgets(uBuffer, sizeof(uBuffer)/sizeof(*uBuffer), myFile);
|
u_fgets(uBuffer, sizeof(uBuffer)/sizeof(*uBuffer), myFile);
|
||||||
u_fclose(myFile);
|
u_fclose(myFile);
|
||||||
u_austrncpy(compBuffer, uBuffer, sizeof(uBuffer)/sizeof(*uBuffer));
|
u_austrncpy(compBuffer, uBuffer, sizeof(uBuffer)/sizeof(*uBuffer));
|
||||||
@ -1302,7 +1308,7 @@ static void TestFScanSetFormat(const char *format, const UChar *uValue, const ch
|
|||||||
|
|
||||||
u_fprintf(myFile, "%S", uValue);
|
u_fprintf(myFile, "%S", uValue);
|
||||||
u_fclose(myFile);
|
u_fclose(myFile);
|
||||||
myFile = u_fopen(STANDARD_TEST_FILE, "r", "en_US_POSIX", NULL);
|
myFile = u_fopen(STANDARD_TEST_FILE, "r", STANDARD_TEST_LOCALE, NULL);
|
||||||
uNumScanned = u_fscanf(myFile, format, uBuffer);
|
uNumScanned = u_fscanf(myFile, format, uBuffer);
|
||||||
u_fclose(myFile);
|
u_fclose(myFile);
|
||||||
if (expectedToPass) {
|
if (expectedToPass) {
|
||||||
@ -1387,7 +1393,7 @@ static void TestBadFScanfFormat(const char *format, const UChar *uValue, const c
|
|||||||
|
|
||||||
u_fprintf(myFile, "%S", uValue);
|
u_fprintf(myFile, "%S", uValue);
|
||||||
u_fclose(myFile);
|
u_fclose(myFile);
|
||||||
myFile = u_fopen(STANDARD_TEST_FILE, "r", "en_US_POSIX", NULL);
|
myFile = u_fopen(STANDARD_TEST_FILE, "r", STANDARD_TEST_LOCALE, NULL);
|
||||||
uNumScanned = u_fscanf(myFile, format, uBuffer);
|
uNumScanned = u_fscanf(myFile, format, uBuffer);
|
||||||
u_fclose(myFile);
|
u_fclose(myFile);
|
||||||
if (uNumScanned != 0 || uBuffer[0] != 0x2a || uBuffer[1] != 0x2a) {
|
if (uNumScanned != 0 || uBuffer[0] != 0x2a || uBuffer[1] != 0x2a) {
|
||||||
@ -1411,7 +1417,7 @@ static void Test_u_vfprintf(const char *expectedResult, const char *format, ...)
|
|||||||
int32_t count;
|
int32_t count;
|
||||||
UFILE *myFile;
|
UFILE *myFile;
|
||||||
|
|
||||||
myFile = u_fopen(STANDARD_TEST_FILE, "w", "en_US_POSIX", "UTF-8");
|
myFile = u_fopen(STANDARD_TEST_FILE, "w", STANDARD_TEST_LOCALE, "UTF-8");
|
||||||
if (!myFile) {
|
if (!myFile) {
|
||||||
log_err("Test file can't be opened\n");
|
log_err("Test file can't be opened\n");
|
||||||
return;
|
return;
|
||||||
@ -1425,7 +1431,7 @@ static void Test_u_vfprintf(const char *expectedResult, const char *format, ...)
|
|||||||
u_fclose(myFile);
|
u_fclose(myFile);
|
||||||
|
|
||||||
|
|
||||||
myFile = u_fopen(STANDARD_TEST_FILE, "r", "en_US_POSIX", "UTF-8");
|
myFile = u_fopen(STANDARD_TEST_FILE, "r", STANDARD_TEST_LOCALE, "UTF-8");
|
||||||
if (!myFile) {
|
if (!myFile) {
|
||||||
log_err("Test file can't be opened\n");
|
log_err("Test file can't be opened\n");
|
||||||
return;
|
return;
|
||||||
@ -1438,7 +1444,7 @@ static void Test_u_vfprintf(const char *expectedResult, const char *format, ...)
|
|||||||
u_fclose(myFile);
|
u_fclose(myFile);
|
||||||
|
|
||||||
|
|
||||||
myFile = u_fopen(STANDARD_TEST_FILE, "w", "en_US_POSIX", NULL);
|
myFile = u_fopen(STANDARD_TEST_FILE, "w", STANDARD_TEST_LOCALE, NULL);
|
||||||
if (!myFile) {
|
if (!myFile) {
|
||||||
log_err("Test file can't be opened\n");
|
log_err("Test file can't be opened\n");
|
||||||
return;
|
return;
|
||||||
@ -1452,7 +1458,7 @@ static void Test_u_vfprintf(const char *expectedResult, const char *format, ...)
|
|||||||
u_fclose(myFile);
|
u_fclose(myFile);
|
||||||
|
|
||||||
|
|
||||||
myFile = u_fopen(STANDARD_TEST_FILE, "r", "en_US_POSIX", NULL);
|
myFile = u_fopen(STANDARD_TEST_FILE, "r", STANDARD_TEST_LOCALE, NULL);
|
||||||
if (!myFile) {
|
if (!myFile) {
|
||||||
log_err("Test file can't be opened\n");
|
log_err("Test file can't be opened\n");
|
||||||
return;
|
return;
|
||||||
@ -1580,6 +1586,8 @@ U_CFUNC void
|
|||||||
addFileTest(TestNode** root) {
|
addFileTest(TestNode** root) {
|
||||||
#if !UCONFIG_NO_FORMATTING
|
#if !UCONFIG_NO_FORMATTING
|
||||||
addTest(root, &TestFile, "file/TestFile");
|
addTest(root, &TestFile, "file/TestFile");
|
||||||
|
addTest(root, &TestFinit, "file/TestFinit");
|
||||||
|
addTest(root, &TestFadopt, "file/TestFadopt");
|
||||||
#endif
|
#endif
|
||||||
addTest(root, &StdinBuffering, "file/StdinBuffering");
|
addTest(root, &StdinBuffering, "file/StdinBuffering");
|
||||||
addTest(root, &TestfgetsBuffers, "file/TestfgetsBuffers");
|
addTest(root, &TestfgetsBuffers, "file/TestfgetsBuffers");
|
||||||
|
Loading…
Reference in New Issue
Block a user