Module: wine Branch: master Commit: 7588b669d8331ff64fc3b75cebe40ef518cd0de1 URL: http://source.winehq.org/git/?p=wine.git;a=commit;h=7588b669d8331ff64fc3b75c...
Author: James Hawkins truiken@gmail.com Date: Wed Sep 13 14:19:12 2006 -0700
setupapi: Implement pSetupGetField, with tests.
---
dlls/setupapi/parser.c | 16 +++++++++ dlls/setupapi/setupapi.spec | 2 + dlls/setupapi/tests/parser.c | 71 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+), 1 deletions(-)
diff --git a/dlls/setupapi/parser.c b/dlls/setupapi/parser.c index 6b2c5d9..72ce612 100644 --- a/dlls/setupapi/parser.c +++ b/dlls/setupapi/parser.c @@ -1875,3 +1875,19 @@ 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 field *field = get_field( file, context->Section, context->Line, index ); + + if (!field) + { + SetLastError( ERROR_INVALID_PARAMETER ); + return NULL; + } + 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 ); }