[PATCH] Fix for SetupGetIntField, with tests
Paul Vriens
Paul.Vriens.Wine at gmail.com
Mon Mar 31 12:44:49 CDT 2008
---
dlls/setupapi/parser.c | 3 +-
dlls/setupapi/tests/parser.c | 63 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 65 insertions(+), 1 deletions(-)
diff --git a/dlls/setupapi/parser.c b/dlls/setupapi/parser.c
index f6de4ed..b92c50e 100644
--- a/dlls/setupapi/parser.c
+++ b/dlls/setupapi/parser.c
@@ -1719,8 +1719,9 @@ BOOL WINAPI SetupGetIntField( PINFCONTEXT context, DWORD index, PINT result )
if (!(buffer = HeapAlloc( GetProcessHeap(), 0, required ))) return FALSE;
if (!SetupGetStringFieldA( context, index, buffer, required, NULL )) goto done;
}
+ /* The call to SetupGetStringFieldA succeeded. If buffer is empty we have an optional field */
res = strtol( buffer, &end, 0 );
- if (end != buffer && !*end)
+ if (!*buffer || ( end != buffer && !*end ))
{
*result = res;
ret = TRUE;
diff --git a/dlls/setupapi/tests/parser.c b/dlls/setupapi/tests/parser.c
index d49c37f..5d6a006 100644
--- a/dlls/setupapi/tests/parser.c
+++ b/dlls/setupapi/tests/parser.c
@@ -475,6 +475,68 @@ static void test_pSetupGetField(void)
SetupCloseInfFile( hinf );
}
+static void test_SetupGetIntField(void)
+{
+ static const struct
+ {
+ const char *key;
+ const char *fields;
+ DWORD index;
+ INT value;
+ DWORD err;
+ int todo;
+ } 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 const char *inf =
@@ -597,6 +659,7 @@ START_TEST(parser)
test_key_names();
test_close_inf_file();
test_pSetupGetField();
+ test_SetupGetIntField();
test_GLE();
DeleteFileA( tmpfilename );
}
--
1.5.4.1
--------------060908060407030200040600--
More information about the wine-patches
mailing list