Commit ebec0a96 authored by Paul Vriens's avatar Paul Vriens Committed by Alexandre Julliard

setupapi: Fix for SetupGetIntField, with tests.

parent 14f86f87
...@@ -1711,21 +1711,26 @@ BOOL WINAPI SetupGetIntField( PINFCONTEXT context, DWORD index, PINT result ) ...@@ -1711,21 +1711,26 @@ BOOL WINAPI SetupGetIntField( PINFCONTEXT context, DWORD index, PINT result )
char *end, *buffer = localbuff; char *end, *buffer = localbuff;
DWORD required; DWORD required;
INT res; INT res;
BOOL ret = FALSE; BOOL ret;
if (!SetupGetStringFieldA( context, index, localbuff, sizeof(localbuff), &required )) if (!(ret = SetupGetStringFieldA( context, index, localbuff, sizeof(localbuff), &required )))
{ {
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) return FALSE; if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) return FALSE;
if (!(buffer = HeapAlloc( GetProcessHeap(), 0, required ))) return FALSE; if (!(buffer = HeapAlloc( GetProcessHeap(), 0, required ))) return FALSE;
if (!SetupGetStringFieldA( context, index, buffer, required, NULL )) goto done; if (!(ret = SetupGetStringFieldA( context, index, buffer, required, NULL ))) goto done;
} }
res = strtol( buffer, &end, 0 ); /* The call to SetupGetStringFieldA succeeded. If buffer is empty we have an optional field */
if (end != buffer && !*end) if (!*buffer) *result = 0;
else
{ {
*result = res; res = strtol( buffer, &end, 0 );
ret = TRUE; if (end != buffer && !*end) *result = res;
else
{
SetLastError( ERROR_INVALID_DATA );
ret = FALSE;
}
} }
else SetLastError( ERROR_INVALID_DATA );
done: done:
if (buffer != localbuff) HeapFree( GetProcessHeap(), 0, buffer ); if (buffer != localbuff) HeapFree( GetProcessHeap(), 0, buffer );
......
...@@ -475,6 +475,67 @@ static void test_pSetupGetField(void) ...@@ -475,6 +475,67 @@ static void test_pSetupGetField(void)
SetupCloseInfFile( hinf ); SetupCloseInfFile( hinf );
} }
static void test_SetupGetIntField(void)
{
static const struct
{
const char *key;
const char *fields;
DWORD index;
INT value;
DWORD err;
} keys[] =
{
/* key fields index expected int errorcode */
{ "Key=", "48", 1, 48, ERROR_SUCCESS },
{ "Key=", "48", 0, -1, ERROR_INVALID_DATA },
{ "123=", "48", 0, 123, ERROR_SUCCESS },
{ "Key=", "0x4", 1, 4, ERROR_SUCCESS },
{ "Key=", "Field1", 1, -1, ERROR_INVALID_DATA },
{ "Key=", "Field1,34", 2, 34, ERROR_SUCCESS },
{ "Key=", "Field1,,Field3", 2, 0, ERROR_SUCCESS },
{ "Key=", "Field1,", 2, 0, ERROR_SUCCESS }
};
unsigned int i;
for (i = 0; i < sizeof(keys)/sizeof(keys[0]); i++)
{
HINF hinf;
char buffer[MAX_INF_STRING_LENGTH];
INFCONTEXT context;
UINT err;
BOOL retb;
INT intfield;
strcpy( buffer, STD_HEADER "[TestSection]\n" );
strcat( buffer, keys[i].key );
strcat( buffer, keys[i].fields );
hinf = test_file_contents( buffer, &err);
ok( hinf != NULL, "Expected valid INF file\n" );
SetupFindFirstLineA( hinf, "TestSection", "Key", &context );
SetLastError( 0xdeadbeef );
intfield = -1;
retb = SetupGetIntField( &context, keys[i].index, &intfield );
if ( keys[i].err == ERROR_SUCCESS )
{
ok( retb, "Expected success\n" );
ok( GetLastError() == ERROR_SUCCESS ||
GetLastError() == 0xdeadbeef /* win9x, NT4 */,
"Expected ERROR_SUCCESS or 0xdeadbeef, got %u\n", GetLastError() );
}
else
{
ok( !retb, "Expected failure\n" );
ok( GetLastError() == keys[i].err,
"Expected %d, got %u\n", keys[i].err, GetLastError() );
}
ok( intfield == keys[i].value, "Expected %d, got %d\n", keys[i].value, intfield );
SetupCloseInfFile( hinf );
}
}
static void test_GLE(void) static void test_GLE(void)
{ {
static const char *inf = static const char *inf =
...@@ -597,6 +658,7 @@ START_TEST(parser) ...@@ -597,6 +658,7 @@ START_TEST(parser)
test_key_names(); test_key_names();
test_close_inf_file(); test_close_inf_file();
test_pSetupGetField(); test_pSetupGetField();
test_SetupGetIntField();
test_GLE(); test_GLE();
DeleteFileA( tmpfilename ); DeleteFileA( tmpfilename );
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment