ICU-3499 %[] doesn't work on AIX. Test it a different way.
X-SVN-Rev: 15157
This commit is contained in:
parent
3839065ad3
commit
6b08c5f001
@ -1073,7 +1073,6 @@ static void TestFScanset(void) {
|
||||
TestFScanSetFormat("%[^dc]", abcUChars, abcChars, TRUE);
|
||||
TestFScanSetFormat("%[^e] ", abcUChars, abcChars, TRUE);
|
||||
|
||||
TestFScanSetFormat("%[] ", abcUChars, abcChars, TRUE);
|
||||
TestFScanSetFormat("%1[ab] ", abcUChars, abcChars, TRUE);
|
||||
TestFScanSetFormat("%2[^f]", abcUChars, abcChars, TRUE);
|
||||
|
||||
@ -1087,6 +1086,33 @@ static void TestFScanset(void) {
|
||||
/* TODO: Need to specify precision with a "*" */
|
||||
}
|
||||
|
||||
static void TestBadFScanfFormat(const char *format, const UChar *uValue, const char *cValue) {
|
||||
UFILE *myFile;
|
||||
UChar uBuffer[256];
|
||||
int32_t uNumScanned;
|
||||
|
||||
myFile = u_fopen(STANDARD_TEST_FILE, "w", NULL, NULL);
|
||||
/* Reinitialize the buffer to verify null termination works. */
|
||||
u_memset(uBuffer, 0x2a, sizeof(uBuffer)/sizeof(*uBuffer));
|
||||
uBuffer[sizeof(uBuffer)/sizeof(*uBuffer)-1] = 0;
|
||||
|
||||
u_fprintf(myFile, "%S", uValue);
|
||||
u_fclose(myFile);
|
||||
myFile = u_fopen(STANDARD_TEST_FILE, "r", "en_US_POSIX", NULL);
|
||||
uNumScanned = u_fscanf(myFile, format, uBuffer);
|
||||
u_fclose(myFile);
|
||||
if (uNumScanned != 0 || uBuffer[0] != 0x2a || uBuffer[1] != 0x2a) {
|
||||
log_err("%s too much stored on a failure\n", format);
|
||||
}
|
||||
}
|
||||
|
||||
static void TestBadScanfFormat(void) {
|
||||
static const UChar abcUChars[] = {0x61,0x62,0x63,0x63,0x64,0x65,0x66,0x67,0};
|
||||
static const char abcChars[] = "abccdefg";
|
||||
|
||||
TestBadFScanfFormat("%[] ", abcUChars, abcChars);
|
||||
}
|
||||
|
||||
static void TestTranslitOps(void)
|
||||
{
|
||||
UFILE *f;
|
||||
@ -1248,6 +1274,7 @@ addFileTest(TestNode** root) {
|
||||
addTest(root, &TestFScanset, "file/TestFScanset");
|
||||
addTest(root, &TestCodepage, "file/TestCodepage");
|
||||
addTest(root, &TestFilePrintCompatibility, "file/TestFilePrintCompatibility");
|
||||
addTest(root, &TestBadScanfFormat, "file/TestBadScanfFormat");
|
||||
|
||||
addTest(root, &TestTranslitOps, "file/translit/ops");
|
||||
addTest(root, &TestTranslitOut, "file/translit/out");
|
||||
|
@ -341,6 +341,188 @@ static void DataDrivenPrintf(void) {
|
||||
}
|
||||
}
|
||||
|
||||
static void DataDrivenScanf(void) {
|
||||
UErrorCode errorCode;
|
||||
TestDataModule *dataModule;
|
||||
TestData *testData;
|
||||
const DataMap *testCase;
|
||||
DataDrivenLogger logger;
|
||||
UChar uBuffer[512];
|
||||
char cBuffer[512];
|
||||
char cFormat[sizeof(cBuffer)];
|
||||
char cExpected[sizeof(cBuffer)];
|
||||
UnicodeString tempStr;
|
||||
UChar format[512];
|
||||
UChar expectedResult[512];
|
||||
UChar argument[512];
|
||||
int32_t i;
|
||||
int8_t i8, expected8;
|
||||
int16_t i16, expected16;
|
||||
int32_t i32, expected32;
|
||||
int64_t i64, expected64;
|
||||
double dbl, expectedDbl;
|
||||
int32_t uBufferLenReturned;
|
||||
|
||||
const char *fileLocale = "en_US_POSIX";
|
||||
//int32_t uFileBufferLenReturned;
|
||||
//UFILE *testFile;
|
||||
|
||||
errorCode=U_ZERO_ERROR;
|
||||
dataModule=TestDataModule::getTestDataModule("icuio", logger, errorCode);
|
||||
if(U_SUCCESS(errorCode)) {
|
||||
testData=dataModule->createTestData("scanf", errorCode);
|
||||
if(U_SUCCESS(errorCode)) {
|
||||
for(i=0; testData->nextCase(testCase, errorCode); ++i) {
|
||||
if(U_FAILURE(errorCode)) {
|
||||
log_err("error retrieving icuio/printf test case %d - %s\n",
|
||||
i, u_errorName(errorCode));
|
||||
errorCode=U_ZERO_ERROR;
|
||||
continue;
|
||||
}
|
||||
/* testFile = u_fopen(STANDARD_TEST_FILE, "w", fileLocale, "UTF-8");
|
||||
if (!testFile) {
|
||||
log_err("Can't open test file - %s\n",
|
||||
STANDARD_TEST_FILE);
|
||||
}*/
|
||||
u_memset(uBuffer, 0x2A, sizeof(uBuffer)/sizeof(uBuffer[0]));
|
||||
uBuffer[sizeof(uBuffer)/sizeof(uBuffer[0])-1] = 0;
|
||||
tempStr=testCase->getString("format", errorCode);
|
||||
tempStr.extract(format, sizeof(format)/sizeof(format[0]), errorCode);
|
||||
tempStr=testCase->getString("result", errorCode);
|
||||
tempStr.extract(expectedResult, sizeof(expectedResult)/sizeof(expectedResult[0]), errorCode);
|
||||
tempStr=testCase->getString("argument", errorCode);
|
||||
tempStr.extract(argument, sizeof(argument)/sizeof(argument[0]), errorCode);
|
||||
u_austrncpy(cBuffer, format, sizeof(cBuffer));
|
||||
if(U_FAILURE(errorCode)) {
|
||||
log_err("error retrieving icuio/printf test case %d - %s\n",
|
||||
i, u_errorName(errorCode));
|
||||
errorCode=U_ZERO_ERROR;
|
||||
continue;
|
||||
}
|
||||
log_verbose("Test %d: format=\"%s\"\n", i, cBuffer);
|
||||
switch (testCase->getString("argumentType", errorCode)[0]) {
|
||||
case 0x64: // 'd' double
|
||||
expectedDbl = atof(u_austrcpy(cBuffer, expectedResult));
|
||||
uBufferLenReturned = u_sscanf_u(argument, format, &dbl);
|
||||
//uFileBufferLenReturned = u_fscanf_u(testFile, format, dbl);
|
||||
if (dbl != expectedDbl) {
|
||||
log_err("error in scanf test case Got: %f Exp: %f\n",
|
||||
dbl, expectedDbl);
|
||||
}
|
||||
break;
|
||||
case 0x31: // '1' int8_t
|
||||
expected8 = (int8_t)uto64(argument);
|
||||
uBufferLenReturned = u_sscanf_u(argument, format, &i8);
|
||||
//uFileBufferLenReturned = u_fscanf_u(testFile, format, i8);
|
||||
if (i8 != expected8) {
|
||||
log_err("error in scanf test case Got: %02X Exp: %02X\n",
|
||||
i8, expected8);
|
||||
}
|
||||
break;
|
||||
case 0x32: // '2' int16_t
|
||||
expected16 = (int16_t)uto64(argument);
|
||||
uBufferLenReturned = u_sscanf_u(argument, format, &i16);
|
||||
//uFileBufferLenReturned = u_fscanf_u(testFile, format, i16);
|
||||
if (i16 != expected16) {
|
||||
log_err("error in scanf test case Got: %04X Exp: %04X\n",
|
||||
i16, expected16);
|
||||
}
|
||||
break;
|
||||
case 0x34: // '4' int32_t
|
||||
expected32 = (int32_t)uto64(argument);
|
||||
uBufferLenReturned = u_sscanf_u(argument, format, &i32);
|
||||
//uFileBufferLenReturned = u_fscanf_u(testFile, format, i32);
|
||||
if (i32 != expected32) {
|
||||
log_err("error in scanf test case Got: %08X Exp: %08X\n",
|
||||
i32, expected32);
|
||||
}
|
||||
break;
|
||||
case 0x38: // '8' int64_t
|
||||
expected64 = uto64(argument);
|
||||
uBufferLenReturned = u_sscanf_u(argument, format, &i64);
|
||||
//uFileBufferLenReturned = u_fscanf_u(testFile, format, i64);
|
||||
if (i64 != expected64) {
|
||||
log_err("error in scanf 64-bit. Test case = %d\n", i);
|
||||
}
|
||||
break;
|
||||
case 0x73: // 's' char *
|
||||
u_austrncpy(cExpected, uBuffer, sizeof(cBuffer));
|
||||
uBufferLenReturned = u_sscanf_u(argument, format, cBuffer);
|
||||
//uFileBufferLenReturned = u_fscanf_u(testFile, format, cBuffer);
|
||||
if (strcmp(cBuffer, cExpected) != 0) {
|
||||
log_err("error in scanf char * string. Test case = %d\n", i);
|
||||
}
|
||||
break;
|
||||
case 0x53: // 'S' UChar *
|
||||
uBufferLenReturned = u_sscanf_u(argument, format, uBuffer);
|
||||
//uFileBufferLenReturned = u_fscanf_u(testFile, format, argument);
|
||||
if (u_strcmp(uBuffer, expectedResult) != 0) {
|
||||
log_err("error in scanf UChar * string. Test case = %d\n", i);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (uBufferLenReturned != 1) {
|
||||
log_err("error scanf converted %d arguments\n", uBufferLenReturned);
|
||||
}
|
||||
/* if (u_strcmp(uBuffer, expectedResult) != 0) {
|
||||
u_austrncpy(cBuffer, uBuffer, sizeof(cBuffer));
|
||||
u_austrncpy(cFormat, format, sizeof(cFormat));
|
||||
u_austrncpy(cExpected, expectedResult, sizeof(cExpected));
|
||||
cBuffer[sizeof(cBuffer)-1] = 0;
|
||||
log_err("FAILURE string test case %d \"%s\" - Got: \"%s\" Expected: \"%s\"\n",
|
||||
i, cFormat, cBuffer, cExpected);
|
||||
}
|
||||
if (uBuffer[uBufferLenReturned-1] == 0
|
||||
|| uBuffer[uBufferLenReturned] != 0
|
||||
|| uBuffer[uBufferLenReturned+1] != 0x2A
|
||||
|| uBuffer[uBufferLenReturned+2] != 0x2A)
|
||||
{
|
||||
u_austrncpy(cBuffer, uBuffer, sizeof(cBuffer));
|
||||
cBuffer[sizeof(cBuffer)-1] = 0;
|
||||
log_err("FAILURE test case %d - \"%s\" wrong amount of characters was written. Got %d.\n",
|
||||
i, cBuffer, uBufferLenReturned);
|
||||
}*/
|
||||
/* u_fclose(testFile);
|
||||
testFile = u_fopen(STANDARD_TEST_FILE, "r", fileLocale, "UTF-8");
|
||||
if (!testFile) {
|
||||
log_err("Can't open test file - %s\n",
|
||||
STANDARD_TEST_FILE);
|
||||
}
|
||||
uBuffer[0];
|
||||
u_fgets(uBuffer, sizeof(uBuffer)/sizeof(uBuffer[0]), testFile);
|
||||
if (u_strcmp(uBuffer, expectedResult) != 0) {
|
||||
u_austrncpy(cBuffer, uBuffer, sizeof(cBuffer));
|
||||
u_austrncpy(cFormat, format, sizeof(cFormat));
|
||||
u_austrncpy(cExpected, expectedResult, sizeof(cExpected));
|
||||
cBuffer[sizeof(cBuffer)-1] = 0;
|
||||
log_err("FAILURE file test case %d \"%s\" - Got: \"%s\" Expected: \"%s\"\n",
|
||||
i, cFormat, cBuffer, cExpected);
|
||||
}
|
||||
if (uFileBufferLenReturned != uBufferLenReturned)
|
||||
{
|
||||
u_austrncpy(cBuffer, uBuffer, sizeof(cBuffer));
|
||||
cBuffer[sizeof(cBuffer)-1] = 0;
|
||||
log_err("FAILURE uFileBufferLenReturned(%d) != uBufferLenReturned(%d)\n",
|
||||
uFileBufferLenReturned, uBufferLenReturned);
|
||||
}
|
||||
*/
|
||||
if(U_FAILURE(errorCode)) {
|
||||
log_err("error running icuio/printf test case %d - %s\n",
|
||||
i, u_errorName(errorCode));
|
||||
errorCode=U_ZERO_ERROR;
|
||||
continue;
|
||||
}
|
||||
// u_fclose(testFile);
|
||||
}
|
||||
delete testData;
|
||||
}
|
||||
delete dataModule;
|
||||
}
|
||||
else {
|
||||
log_err("Failed: could not load test icuio data\n");
|
||||
}
|
||||
}
|
||||
|
||||
static void DataDrivenPrintfPrecision(void) {
|
||||
UErrorCode errorCode;
|
||||
TestDataModule *dataModule;
|
||||
@ -524,8 +706,9 @@ static void addAllTests(TestNode** root) {
|
||||
addFileTest(root);
|
||||
addStringTest(root);
|
||||
|
||||
addTest(root, &DataDrivenPrintf, "data/DataDrivenPrintf");
|
||||
addTest(root, &DataDrivenPrintfPrecision, "data/DataDrivenPrintfPrecision");
|
||||
addTest(root, &DataDrivenPrintf, "datadriv/DataDrivenPrintf");
|
||||
addTest(root, &DataDrivenPrintfPrecision, "datadriv/DataDrivenPrintfPrecision");
|
||||
addTest(root, &DataDrivenScanf, "datadriv/DataDrivenScanf");
|
||||
addTest(root, &TestStream, "stream/TestStream");
|
||||
}
|
||||
|
||||
|
@ -518,6 +518,27 @@ static void TestStringCompatibility(void) {
|
||||
}
|
||||
}
|
||||
|
||||
static void TestArgumentSkipping(void) {
|
||||
#if 0
|
||||
UChar uBuffer[256];
|
||||
char buffer[256];
|
||||
char compBuffer[256];
|
||||
int32_t uNumScanned;
|
||||
int32_t cNumScanned;
|
||||
char ch1 = 0, ch2 = 0;
|
||||
|
||||
/* Reinitialize the buffer to verify null termination works.*/
|
||||
u_memset(uBuffer, 0x2a, sizeof(uBuffer)/sizeof(*uBuffer));
|
||||
uBuffer[sizeof(uBuffer)/sizeof(*uBuffer)-1] = 0;
|
||||
memset(buffer, 0x2a, sizeof(buffer)/sizeof(*buffer));
|
||||
buffer[sizeof(buffer)/sizeof(*buffer)-1] = 0;
|
||||
|
||||
strcpy(buffer, "123456789");
|
||||
u_uastrcpy(uBuffer, "123456789");
|
||||
uNumScanned = sscanf(buffer, "%*c%c", &ch1, &ch2);
|
||||
uNumScanned = u_sscanf(uBuffer, "%*c%c", &ch1, &ch2);
|
||||
#endif
|
||||
}
|
||||
static void TestSScanSetFormat(const char *format, const UChar *uValue, const char *cValue, UBool expectedToPass) {
|
||||
UChar uBuffer[256];
|
||||
char buffer[256];
|
||||
@ -552,27 +573,6 @@ static void TestSScanSetFormat(const char *format, const UChar *uValue, const ch
|
||||
}
|
||||
}
|
||||
|
||||
static void TestArgumentSkipping(void) {
|
||||
#if 0
|
||||
UChar uBuffer[256];
|
||||
char buffer[256];
|
||||
char compBuffer[256];
|
||||
int32_t uNumScanned;
|
||||
int32_t cNumScanned;
|
||||
char ch1 = 0, ch2 = 0;
|
||||
|
||||
/* Reinitialize the buffer to verify null termination works.*/
|
||||
u_memset(uBuffer, 0x2a, sizeof(uBuffer)/sizeof(*uBuffer));
|
||||
uBuffer[sizeof(uBuffer)/sizeof(*uBuffer)-1] = 0;
|
||||
memset(buffer, 0x2a, sizeof(buffer)/sizeof(*buffer));
|
||||
buffer[sizeof(buffer)/sizeof(*buffer)-1] = 0;
|
||||
|
||||
strcpy(buffer, "123456789");
|
||||
u_uastrcpy(uBuffer, "123456789");
|
||||
uNumScanned = sscanf(buffer, "%*c%c", &ch1, &ch2);
|
||||
uNumScanned = u_sscanf(uBuffer, "%*c%c", &ch1, &ch2);
|
||||
#endif
|
||||
}
|
||||
static void TestSScanset(void) {
|
||||
static const UChar abcUChars[] = {0x61,0x62,0x63,0x63,0x64,0x65,0x66,0x67,0};
|
||||
static const char abcChars[] = "abccdefg";
|
||||
@ -615,6 +615,27 @@ static void TestSScanset(void) {
|
||||
/* TODO: Need to specify precision with a "*" */
|
||||
}
|
||||
|
||||
static void TestBadSScanfFormat(const char *format, const UChar *uValue, const char *cValue) {
|
||||
UChar uBuffer[256];
|
||||
int32_t uNumScanned;
|
||||
|
||||
/* Reinitialize the buffer to verify null termination works. */
|
||||
u_memset(uBuffer, 0x2a, sizeof(uBuffer)/sizeof(*uBuffer));
|
||||
uBuffer[sizeof(uBuffer)/sizeof(*uBuffer)-1] = 0;
|
||||
|
||||
uNumScanned = u_sscanf(uValue, format, uBuffer);
|
||||
if (uNumScanned != 0 || uBuffer[0] != 0x2a || uBuffer[1] != 0x2a) {
|
||||
log_err("%s too much stored on a failure\n", format);
|
||||
}
|
||||
}
|
||||
|
||||
static void TestBadScanfFormat(void) {
|
||||
static const UChar abcUChars[] = {0x61,0x62,0x63,0x63,0x64,0x65,0x66,0x67,0};
|
||||
static const char abcChars[] = "abccdefg";
|
||||
|
||||
TestBadSScanfFormat("%[] ", abcUChars, abcChars);
|
||||
}
|
||||
|
||||
U_CFUNC void
|
||||
addStringTest(TestNode** root) {
|
||||
addTest(root, &TestString, "string/TestString");
|
||||
@ -623,6 +644,7 @@ addStringTest(TestNode** root) {
|
||||
addTest(root, &TestSScanset, "string/TestSScanset");
|
||||
addTest(root, &TestArgumentSkipping, "string/TestArgumentSkipping");
|
||||
addTest(root, &TestStringCompatibility, "string/TestStringCompatibility");
|
||||
addTest(root, &TestBadScanfFormat, "string/TestBadScanfFormat");
|
||||
}
|
||||
|
||||
|
||||
|
8
icu4c/source/test/testdata/icuio.txt
vendored
8
icu4c/source/test/testdata/icuio.txt
vendored
@ -136,5 +136,13 @@ icuio {
|
||||
}
|
||||
}
|
||||
}
|
||||
scanf {
|
||||
Headers { "format", "argument", "argumentType", "result" }
|
||||
Cases {
|
||||
{
|
||||
"%e", "1.200000e+000", "d", "1.2"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user