ICU-3499 Move some platform dependent tests to data driven tests.

X-SVN-Rev: 14927
This commit is contained in:
George Rhoten 2004-04-11 00:12:43 +00:00
parent 765dbdb31a
commit f094601d59
3 changed files with 95 additions and 37 deletions

View file

@ -206,6 +206,7 @@ static void DataDrivenPrintf(void) {
int32_t i32;
int64_t i64;
double dbl;
int32_t uBufferLenReturned;
errorCode=U_ZERO_ERROR;
dataModule=TestDataModule::getTestDataModule("icuio", logger, errorCode);
@ -219,6 +220,7 @@ static void DataDrivenPrintf(void) {
errorCode=U_ZERO_ERROR;
continue;
}
u_memset(uBuffer, 0x2A, sizeof(uBuffer)/sizeof(uBuffer[0]));
tempStr=testCase->getString("format", errorCode);
tempStr.extract(format, sizeof(format)/sizeof(format[0]), errorCode);
// tempStr=testCase->getString("locale", errorCode);
@ -228,33 +230,35 @@ static void DataDrivenPrintf(void) {
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));
log_verbose("Test %d: format=\"%s\"\n", i, cBuffer);
switch (testCase->getString("argumentType", errorCode)[0]) {
case 0x64: // 'd' double
dbl = atof(u_austrcpy(cBuffer, argument));
u_sprintf_u(uBuffer, "en_US_POSIX", format, dbl);
uBufferLenReturned = u_sprintf_u(uBuffer, "en_US_POSIX", format, dbl);
break;
case 0x31: // '1' int8_t
i8 = (int8_t)uto64(argument);
u_sprintf_u(uBuffer, "en_US_POSIX", format, i8);
uBufferLenReturned = u_sprintf_u(uBuffer, "en_US_POSIX", format, i8);
break;
case 0x32: // '2' int16_t
i16 = (int16_t)uto64(argument);
u_sprintf_u(uBuffer, "en_US_POSIX", format, i16);
uBufferLenReturned = u_sprintf_u(uBuffer, "en_US_POSIX", format, i16);
break;
case 0x34: // '4' int32_t
i32 = (int32_t)uto64(argument);
u_sprintf_u(uBuffer, "en_US_POSIX", format, i32);
uBufferLenReturned = u_sprintf_u(uBuffer, "en_US_POSIX", format, i32);
break;
case 0x38: // '8' int64_t
i64 = uto64(argument);
u_sprintf_u(uBuffer, "en_US_POSIX", format, i64);
uBufferLenReturned = u_sprintf_u(uBuffer, "en_US_POSIX", format, i64);
break;
case 0x73: // 's' char *
u_austrncpy(cBuffer, uBuffer, sizeof(cBuffer));
u_sprintf_u(uBuffer, "en_US_POSIX", format, cBuffer);
uBufferLenReturned = u_sprintf_u(uBuffer, "en_US_POSIX", format, cBuffer);
break;
case 0x53: // 'S' UChar *
u_sprintf_u(uBuffer, "en_US_POSIX", format, argument);
uBufferLenReturned = u_sprintf_u(uBuffer, "en_US_POSIX", format, argument);
break;
}
if (u_strcmp(uBuffer, expectedResult) != 0) {
@ -263,6 +267,16 @@ static void DataDrivenPrintf(void) {
log_err("FAILURE test case %d - Got: %s\n",
i, cBuffer);
}
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);
}
if(U_FAILURE(errorCode)) {
log_err("error running icuio/printf test case %d - %s\n",
i, u_errorName(errorCode));

View file

@ -351,17 +351,8 @@ static void TestSprintfFormat(void) {
TestSPrintFormat("%10.4f", 123.456789, "%10.4f", 123.456789);
TestSPrintFormat("%-10f", 123.456789, "%-10f", 123.456789);
TestSPrintFormat("%e", 1234567.89, "%e", 1234567.89);
TestSPrintFormat("%E", 1234567.89, "%E", 1234567.89);
TestSPrintFormat("%10e", 1.23456789, "%10e", 1.23456789);
TestSPrintFormat("%10.4e", 1.23456789, "%10.4e", 1.23456789);
TestSPrintFormat("%-10e", 1.23456789, "%-10e", 1.23456789);
TestSPrintFormat("%10e", 123.456789, "%10e", 123.456789);
TestSPrintFormat("%-10e", 123.456789, "%-10e", 123.456789);
TestSPrintFormat("%g", 123456.789, "%g", 123456.789);
TestSPrintFormat("%g", 1234567.89, "%g", 1234567.89);
TestSPrintFormat("%G", 1234567.89, "%G", 1234567.89);
TestSPrintFormat("%G", 123456.789, "%G", 123456.789);
TestSPrintFormat("%10g", 1.23456789, "%10g", 1.23456789);
TestSPrintFormat("%10.4g", 1.23456789, "%10.4g", 1.23456789);
TestSPrintFormat("%-10g", 1.23456789, "%-10g", 1.23456789);
@ -424,21 +415,6 @@ static void TestSprintfFormat(void) {
TestSPrintFormat("%.12d", 123, "%.12d", 123);
TestSPrintFormat("%.12d", -123, "%.12d", -123);
TestSPrintFormat("%-+12.1e", 1.234, "%-+12.1e", 1.234);
TestSPrintFormat("%-+12.1e", -1.234, "%-+12.1e", -1.234);
TestSPrintFormat("%- 12.10e", 1.234, "%- 12.10e", 1.234);
TestSPrintFormat("%- 12.1e", -1.234, "%- 12.1e", -1.234);
TestSPrintFormat("%+12.1e", 1.234, "%+12.1e", 1.234);
TestSPrintFormat("%+12.1e", -1.234, "%+12.1e", -1.234);
TestSPrintFormat("% 12.1e", 1.234, "% 12.1e", 1.234);
TestSPrintFormat("% 12.1e", -1.234, "% 12.1e", -1.234);
TestSPrintFormat("%12.1e", 1.234, "%12.1e", 1.234);
TestSPrintFormat("%12.1e", -1.234, "%12.1e", -1.234);
TestSPrintFormat("%.2e", 1.234, "%.2e", 1.234);
TestSPrintFormat("%.2e", -1.234, "%.2e", -1.234);
TestSPrintFormat("%3e", 1.234, "%3e", 1.234);
TestSPrintFormat("%3e", -1.234, "%3e", -1.234);
TestSPrintFormat("%-+12.1f", 1.234, "%-+12.1f", 1.234);
TestSPrintFormat("%-+12.1f", -1.234, "%-+12.1f", -1.234);
TestSPrintFormat("%- 12.10f", 1.234, "%- 12.10f", 1.234);
@ -637,4 +613,6 @@ addStringTest(TestNode** root) {
addTest(root, &TestSnprintf, "string/TestSnprintf");
addTest(root, &TestSScanset, "string/TestSScanset");
addTest(root, &TestStringCompatibility, "string/TestStringCompatibility");
}
}

View file

@ -37,10 +37,76 @@ icuio {
Headers { "format", "result", "argumentType", "argument" }
Cases {
{
"%e",
"1.200000e+000",
"d",
"1.2"
"%e", "1.200000e+000", "d", "1.2"
}
{
"%e", "1.234568e+006", "d", "1234567.89"
}
{
"%E", "1.234568E+006", "d", "1234567.89"
}
{
"%10e", "1.234568e+000", "d", "1.23456789"
}
{
"%10.4e", "1.2346e+000", "d", "1.23456789"
}
{
"%-10e", "1.234568e+000", "d", "1.23456789"
}
{
"%10e", "1.234568e+002", "d", "123.456789"
}
{
"%-10e", "1.234568e+002", "d", "123.456789"
}
{
"%-+12.1e", "+1.2e+000 ", "d", "1.234"
}
{
"%-+12.1e", "-1.2e+000 ", "d", "-1.234"
}
{
"%- 12.10e", " 1.2340000000e+000", "d", "1.234"
}
{
"%- 12.1e", "-1.2e+000 ", "d", "-1.234"
}
{
"%+12.1e", " +1.2e+000", "d", "1.234"
}
{
"%+12.1e", " -1.2e+000", "d", "-1.234"
}
{
"% 12.1e", " 1.2e+000", "d", "1.234"
}
{
"% 12.1e", " -1.2e+000", "d", "-1.234"
}
{
"%12.1e", " 1.2e+000", "d", "1.234"
}
{
"%12.1e", " -1.2e+000", "d", "-1.234"
}
{
"%.2e", "1.23e+000", "d", "1.234"
}
{
"%.2e", "-1.23e+000", "d", "-1.234"
}
{
"%3e", "1.234000e+000", "d", "1.234"
}
{
"%3e", "-1.234000e+000", "d", "-1.234"
}
{
"%g", "1.23457e+006", "d", "1234567.89"
}
{
"%G", "1.23457E+006", "d", "1234567.89"
}
{
"%hx",