setupapi: Implement pSetupGetField, with tests
James Hawkins
truiken at gmail.com
Wed Sep 13 16:19:12 CDT 2006
Hi,
This keeps the BITS service installer from crashing, lets it get to
the next bug. http://bugs.winehq.org/show_bug.cgi?id=6194
Changelog:
* Implement pSetupGetField, with tests.
dlls/setupapi/parser.c | 24 ++++++++++++++
dlls/setupapi/setupapi.spec | 2 +
dlls/setupapi/tests/parser.c | 71 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 96 insertions(+), 1 deletions(-)
--
James Hawkins
-------------- next part --------------
diff --git a/dlls/setupapi/parser.c b/dlls/setupapi/parser.c
index 6b2c5d9..17d9cef 100644
--- a/dlls/setupapi/parser.c
+++ b/dlls/setupapi/parser.c
@@ -1875,3 +1875,27 @@ BOOL WINAPI SetupGetMultiSzFieldW( PINFC
*buffer = 0; /* add final null */
return TRUE;
}
+
+/***********************************************************************
+ * pSetupGetField (SETUPAPI.@)
+ */
+LPCWSTR WINAPI pSetupGetField( PINFCONTEXT context, DWORD index )
+{
+ struct inf_file *file = context->CurrentInf;
+ struct line *line = get_line( file, context->Section, context->Line );
+ struct field *field;
+
+ if (!line)
+ {
+ SetLastError( ERROR_LINE_NOT_FOUND );
+ return NULL;
+ }
+ if (index > line->nb_fields)
+ {
+ SetLastError( ERROR_INVALID_PARAMETER );
+ return NULL;
+ }
+ index--; /* fields start at 0 */
+ field = &file->fields[line->first_field + index];
+ return field->text;
+}
diff --git a/dlls/setupapi/setupapi.spec b/dlls/setupapi/setupapi.spec
index fd7ca3f..e68ca69 100644
--- a/dlls/setupapi/setupapi.spec
+++ b/dlls/setupapi/setupapi.spec
@@ -539,7 +539,7 @@ # Yes, Microsoft really misspelled this
@ stub pSetupAppendStringToMultiSz
@ stub pSetupDestroyRunOnceNodeList
@ stub pSetupDirectoryIdToPath
-@ stub pSetupGetField
+@ stdcall pSetupGetField(ptr long)
@ stdcall pSetupGetGlobalFlags()
@ stub pSetupGetOsLoaderDriveAndPath
@ stub pSetupGetQueueFlags
diff --git a/dlls/setupapi/tests/parser.c b/dlls/setupapi/tests/parser.c
index da49904..a4ed913 100644
--- a/dlls/setupapi/tests/parser.c
+++ b/dlls/setupapi/tests/parser.c
@@ -30,6 +30,19 @@ #include "setupapi.h"
#include "wine/test.h"
+/* function pointers */
+static HMODULE hSetupAPI;
+static LPCWSTR (WINAPI *pSetupGetField)(PINFCONTEXT,DWORD);
+
+static void init_function_pointers(void)
+{
+ hSetupAPI = LoadLibraryA("setupapi.dll");
+ if (!hSetupAPI)
+ return;
+
+ pSetupGetField = (void *)GetProcAddress(hSetupAPI, "pSetupGetField");
+}
+
static const char tmpfile[] = ".\\tmp.inf";
/* some large strings */
@@ -394,11 +407,69 @@ static void test_close_inf_file(void)
ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %ld\n", GetLastError());
}
+static const char *contents = "[Version]\n"
+ "Signature=\"$Windows NT$\"\n"
+ "FileVersion=5.1.1.2\n"
+ "[FileBranchInfo]\n"
+ "RTMQFE=\"%RTMGFE_NAME%\",SP1RTM,"A4097"\n"
+ "[Strings]\n"
+ "RTMQFE_NAME = \"RTMQFE\"\n";
+
+static const WCHAR getfield_res[][20] =
+{
+ {'R','T','M','Q','F','E',0},
+ {'%','R','T','M','G','F','E','_','N','A','M','E','%',0},
+ {'S','P','1','R','T','M',0},
+};
+
+static void test_pSetupGetField(void)
+{
+ UINT err;
+ BOOL ret;
+ HINF hinf;
+ LPCWSTR field;
+ INFCONTEXT context;
+ int i;
+
+ hinf = test_file_contents( contents, &err );
+ ok( hinf != NULL, "Expected valid INF file\n" );
+
+ ret = SetupFindFirstLine( hinf, "FileBranchInfo", NULL, &context );
+ ok( ret, "Failed to find first line\n" );
+
+ /* native Windows crashes if a NULL context is sent in */
+
+ for ( i = 0; i < 3; i++ )
+ {
+ field = pSetupGetField( &context, i );
+ ok( field != NULL, "Failed to get field %i\n", i );
+ ok( !lstrcmpW( getfield_res[i], field ), "Wrong string returned\n" );
+
+ ret = HeapFree( GetProcessHeap(), 0, (LPVOID)field );
+ ok( !ret, "Expected HeapFree to fail\n" );
+ ok( GetLastError() == ERROR_INVALID_PARAMETER,
+ "Expected ERROR_INVALID_PARAMETER, got %ld\n", GetLastError() );
+ }
+
+ field = pSetupGetField( &context, 3 );
+ ok( field != NULL, "Failed to get field 3\n" );
+ ok( lstrlenW( field ) == 511, "Expected 511, got %d\n", lstrlenW( field ) );
+
+ field = pSetupGetField( &context, 4 );
+ ok( field == NULL, "Expected NULL, got %p\n", field );
+ ok( GetLastError() == ERROR_INVALID_PARAMETER,
+ "Expected ERROR_INVALID_PARAMETER, got %ld\n", GetLastError() );
+
+ SetupCloseInfFile( hinf );
+}
+
START_TEST(parser)
{
+ init_function_pointers();
test_invalid_files();
test_section_names();
test_key_names();
test_close_inf_file();
+ test_pSetupGetField();
DeleteFileA( tmpfile );
}
--
1.4.2
More information about the wine-patches
mailing list