ReactOS 0.4.15-dev-7942-gd23573b
parser.c File Reference
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "wingdi.h"
#include "winuser.h"
#include "winreg.h"
#include "setupapi.h"
#include "wine/test.h"
Include dependency graph for parser.c:

Go to the source code of this file.

Macros

#define A255
 
#define A256   "a" A255
 
#define A400
 
#define A1200   A400 A400 A400
 
#define A511   A255 A256
 
#define A4096   A256 A256 A256 A256 A256 A256 A256 A256 A256 A256 A256 A256 A256 A256 A256 A256
 
#define A4097   "a" A4096
 
#define STD_HEADER   "[Version]\r\nSignature=\"$CHICAGO$\"\r\n"
 
#define STR_SECTION
 

Functions

static LPCSTR (WINAPI *pSetupGetFieldA)(PINFCONTEXT
 
static LPCWSTR (WINAPI *pSetupGetFieldW)(PINFCONTEXT
 
static BOOL (WINAPI *pSetupEnumInfSectionsA)(HINF hinf
 
static void init_function_pointers (void)
 
static HINF test_file_contents (const char *data, UINT *err_line)
 
static const charget_string_field (INFCONTEXT *context, DWORD index)
 
static const charget_line_text (INFCONTEXT *context)
 
static void test_invalid_files (void)
 
static void test_section_names (void)
 
static void test_enum_sections (void)
 
static const charcheck_key (INFCONTEXT *context, const char *wanted)
 
static void test_key_names (void)
 
static void test_close_inf_file (void)
 
static void test_pSetupGetField (void)
 
static void test_SetupGetIntField (void)
 
static void test_GLE (void)
 
 START_TEST (parser)
 

Variables

static HMODULE hSetupAPI
 
static DWORD
 
static UINT index
 
static UINT PSTR buffer
 
static UINT PSTR DWORD size
 
static UINT PSTR DWORD UINTneed
 
static const char tmpfilename [] = ".\\tmp.inf"
 
struct {
   const char *   data
 
   DWORD   error
 
   UINT   err_line
 
   BOOL   todo
 
invalid_files []
 
struct {
   const char *   data
 
   const char *   section
 
   DWORD   error
 
section_names []
 
struct {
   const char *   data
 
   const char *   key
 
   const char *   fields [10]
 
key_names []
 
static const charcontents
 
static const CHAR getfield_resA [][20]
 
static const WCHAR getfield_resW [][20]
 

Macro Definition Documentation

◆ A1200

#define A1200   A400 A400 A400

Definition at line 60 of file parser.c.

◆ A255

#define A255
Value:
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" \
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" \
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" \
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

Definition at line 52 of file parser.c.

◆ A256

#define A256   "a" A255

Definition at line 56 of file parser.c.

◆ A400

#define A400
Value:
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" \
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" \
"aaaaaaaaaaaaaaaa" A256
#define A256
Definition: parser.c:56

Definition at line 57 of file parser.c.

◆ A4096

Definition at line 62 of file parser.c.

◆ A4097

#define A4097   "a" A4096

Definition at line 63 of file parser.c.

◆ A511

#define A511   A255 A256

Definition at line 61 of file parser.c.

◆ STD_HEADER

#define STD_HEADER   "[Version]\r\nSignature=\"$CHICAGO$\"\r\n"

Definition at line 65 of file parser.c.

◆ STR_SECTION

#define STR_SECTION
Value:
"[Strings]\nfoo=aaa\nbar=bbb\nloop=%loop2%\nloop2=%loop%\n" \
"per%%cent=abcd\nper=1\ncent=2\n22=foo\n" \
"big=" A400 "\n" \
"mydrive=\"C:\\\"\n" \
"verybig=" A1200 "\n"
#define A400
Definition: parser.c:57
#define A1200
Definition: parser.c:60

Definition at line 67 of file parser.c.

Function Documentation

◆ BOOL()

static BOOL ( WINAPI pSetupEnumInfSectionsA)
static

◆ check_key()

static const char * check_key ( INFCONTEXT context,
const char wanted 
)
static

Definition at line 393 of file parser.c.

394{
395 const char *key = get_string_field( context, 0 );
397
398 if (!key)
399 {
400 ok( !wanted, "missing key %s\n", wanted );
401 ok( err == 0 || err == ERROR_INVALID_PARAMETER, "last error set to %u\n", err );
402 }
403 else
404 {
405 ok( !strcmp( key, wanted ), "bad key %s/%s\n", key, wanted );
406 ok( err == 0, "last error set to %u\n", err );
407 }
408 return key;
409}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define ok(value,...)
Definition: atltest.h:57
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
unsigned long DWORD
Definition: ntddk_ex.h:95
static const char * get_string_field(INFCONTEXT *context, DWORD index)
Definition: parser.c:85
const char * key
Definition: parser.c:312
#define err(...)
Definition: http.c:7252
Definition: copy.c:22
DWORD WINAPI GetLastError(void)
Definition: except.c:1042

Referenced by test_key_names().

◆ get_line_text()

static const char * get_line_text ( INFCONTEXT context)
static

Definition at line 92 of file parser.c.

93{
94 static char buffer[MAX_INF_STRING_LENGTH+32];
95 if (SetupGetLineTextA( context, 0, 0, 0, buffer, sizeof(buffer), NULL )) return buffer;
96 return NULL;
97}
#define NULL
Definition: types.h:112
BOOL WINAPI SetupGetLineTextA(PINFCONTEXT context, HINF hinf, PCSTR section_name, PCSTR key_name, PSTR buffer, DWORD size, PDWORD required)
Definition: parser.c:1807
GLuint buffer
Definition: glext.h:5915
#define MAX_INF_STRING_LENGTH
Definition: infsupp.h:34

Referenced by test_key_names().

◆ get_string_field()

static const char * get_string_field ( INFCONTEXT context,
DWORD  index 
)
static

Definition at line 85 of file parser.c.

86{
87 static char buffer[MAX_INF_STRING_LENGTH+32];
88 if (SetupGetStringFieldA( context, index, buffer, sizeof(buffer), NULL )) return buffer;
89 return NULL;
90}
BOOL WINAPI SetupGetStringFieldA(PINFCONTEXT context, DWORD index, PSTR buffer, DWORD size, PDWORD required)
Definition: parser.c:1871
GLuint index
Definition: glext.h:6031

Referenced by check_key(), and test_key_names().

◆ init_function_pointers()

static void init_function_pointers ( void  )
static

Definition at line 38 of file parser.c.

39{
40 hSetupAPI = GetModuleHandleA("setupapi.dll");
41
42 /* Nice, pSetupGetField is either A or W depending on the Windows version! The actual test
43 * takes care of this difference */
44 pSetupGetFieldA = (void *)GetProcAddress(hSetupAPI, "pSetupGetField");
45 pSetupGetFieldW = (void *)GetProcAddress(hSetupAPI, "pSetupGetField");
46 pSetupEnumInfSectionsA = (void *)GetProcAddress(hSetupAPI, "SetupEnumInfSectionsA" );
47}
#define GetProcAddress(x, y)
Definition: compat.h:753
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
static HMODULE hSetupAPI
Definition: parser.c:33

Referenced by START_TEST().

◆ LPCSTR()

static LPCSTR ( WINAPI pSetupGetFieldA)
static

◆ LPCWSTR()

static LPCWSTR ( WINAPI pSetupGetFieldW)
static

◆ START_TEST()

START_TEST ( parser  )

Definition at line 784 of file parser.c.

785{
794 test_GLE();
796}
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
static void test_key_names(void)
Definition: parser.c:411
static const char tmpfilename[]
Definition: parser.c:49
static void test_invalid_files(void)
Definition: parser.c:151
static void test_pSetupGetField(void)
Definition: parser.c:533
static void test_GLE(void)
Definition: parser.c:670
static void init_function_pointers(void)
Definition: parser.c:38
static void test_SetupGetIntField(void)
Definition: parser.c:608
static void test_enum_sections(void)
Definition: parser.c:260
static void test_close_inf_file(void)
Definition: parser.c:496
static void test_section_names(void)
Definition: parser.c:225

◆ test_close_inf_file()

static void test_close_inf_file ( void  )
static

Definition at line 496 of file parser.c.

497{
498 SetLastError(0xdeadbeef);
500 ok(GetLastError() == 0xdeadbeef ||
501 GetLastError() == ERROR_INVALID_PARAMETER, /* Win9x, WinMe */
502 "Expected 0xdeadbeef, got %u\n", GetLastError());
503
504 SetLastError(0xdeadbeef);
506 ok(GetLastError() == 0xdeadbeef ||
507 GetLastError() == ERROR_INVALID_PARAMETER, /* Win9x, WinMe */
508 "Expected 0xdeadbeef, got %u\n", GetLastError());
509}
#define SetLastError(x)
Definition: compat.h:752
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
void WINAPI SetupCloseInfFile(HINF hinf)
Definition: parser.c:1393

Referenced by START_TEST().

◆ test_enum_sections()

static void test_enum_sections ( void  )
static

Definition at line 260 of file parser.c.

261{
262 static const char *contents = STD_HEADER "[s1]\nfoo=bar\n[s2]\nbar=foo\n[s3]\n[strings]\na=b\n";
263
264 BOOL ret;
265 DWORD len;
266 HINF hinf;
267 UINT err, index;
268 char buffer[256];
269
270 if (!pSetupEnumInfSectionsA)
271 {
272 win_skip( "SetupEnumInfSectionsA not available\n" );
273 return;
274 }
275
276 hinf = test_file_contents( contents, &err );
277 ok( hinf != NULL, "Expected valid INF file\n" );
278
279 for (index = 0; ; index++)
280 {
281 SetLastError( 0xdeadbeef );
282 ret = pSetupEnumInfSectionsA( hinf, index, NULL, 0, &len );
283 err = GetLastError();
284 if (!ret && GetLastError() == ERROR_NO_MORE_ITEMS) break;
285 ok( ret, "SetupEnumInfSectionsA failed\n" );
286 ok( len == 3 || len == 8, "wrong len %u\n", len );
287
288 SetLastError( 0xdeadbeef );
289 ret = pSetupEnumInfSectionsA( hinf, index, NULL, sizeof(buffer), &len );
290 err = GetLastError();
291 ok( !ret, "SetupEnumInfSectionsA succeeded\n" );
292 ok( err == ERROR_INVALID_USER_BUFFER, "wrong error %u\n", err );
293 ok( len == 3 || len == 8, "wrong len %u\n", len );
294
295 SetLastError( 0xdeadbeef );
296 ret = pSetupEnumInfSectionsA( hinf, index, buffer, sizeof(buffer), &len );
297 ok( ret, "SetupEnumInfSectionsA failed err %u\n", GetLastError() );
298 ok( len == 3 || len == 8, "wrong len %u\n", len );
299 ok( !lstrcmpiA( buffer, "version" ) || !lstrcmpiA( buffer, "s1" ) ||
300 !lstrcmpiA( buffer, "s2" ) || !lstrcmpiA( buffer, "s3" ) || !lstrcmpiA( buffer, "strings" ),
301 "bad section '%s'\n", buffer );
302 }
303 SetupCloseInfFile( hinf );
304}
#define index(s, c)
Definition: various.h:29
#define ERROR_NO_MORE_ITEMS
Definition: compat.h:105
unsigned int BOOL
Definition: ntddk_ex.h:94
GLenum GLsizei len
Definition: glext.h:6722
int WINAPI lstrcmpiA(LPCSTR lpString1, LPCSTR lpString2)
Definition: lstring.c:42
#define STD_HEADER
Definition: parser.c:65
static HINF test_file_contents(const char *data, UINT *err_line)
Definition: parser.c:74
static const char * contents
Definition: parser.c:511
unsigned int UINT
Definition: ndis.h:50
#define win_skip
Definition: test.h:160
int ret
#define ERROR_INVALID_USER_BUFFER
Definition: winerror.h:1091

Referenced by START_TEST().

◆ test_file_contents()

static HINF test_file_contents ( const char data,
UINT err_line 
)
static

Definition at line 74 of file parser.c.

75{
76 DWORD res;
79 if (handle == INVALID_HANDLE_VALUE) return 0;
80 if (!WriteFile( handle, data, strlen(data), &res, NULL )) trace( "write error\n" );
83}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define trace
Definition: atltest.h:70
#define CloseHandle
Definition: compat.h:739
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:740
#define GENERIC_READ
Definition: compat.h:135
#define FILE_SHARE_READ
Definition: compat.h:136
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
HINF WINAPI SetupOpenInfFileA(PCSTR name, PCSTR class, DWORD style, UINT *error)
Definition: parser.c:1139
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLuint res
Definition: glext.h:9613
#define INF_STYLE_WIN4
Definition: infsupp.h:41
#define CREATE_ALWAYS
Definition: disk.h:72
UINT err_line
Definition: parser.c:106
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define GENERIC_WRITE
Definition: nt_native.h:90

Referenced by test_enum_sections(), test_GLE(), test_invalid_files(), test_key_names(), test_pSetupGetField(), test_section_names(), and test_SetupGetIntField().

◆ test_GLE()

static void test_GLE ( void  )
static

Definition at line 670 of file parser.c.

671{
672 static const char *inf =
673 "[Version]\n"
674 "Signature=\"$Windows NT$\"\n"
675 "[Sectionname]\n"
676 "Keyname1=Field1,Field2,Field3\n"
677 "\n"
678 "Keyname2=Field4,Field5\n";
679 HINF hinf;
680 UINT err;
682 BOOL retb;
683 LONG retl;
686 DWORD retsize;
687
688 hinf = test_file_contents( inf, &err );
689 ok( hinf != NULL, "Expected valid INF file\n" );
690
691 SetLastError(0xdeadbeef);
692 retb = SetupFindFirstLineA( hinf, "ImNotThere", NULL, &context );
693 ok(!retb, "Expected failure\n");
695 "Expected ERROR_LINE_NOT_FOUND, got %08x\n", GetLastError());
696
697 SetLastError(0xdeadbeef);
698 retb = SetupFindFirstLineA( hinf, "ImNotThere", "ImNotThere", &context );
699 ok(!retb, "Expected failure\n");
701 "Expected ERROR_LINE_NOT_FOUND, got %08x\n", GetLastError());
702
703 SetLastError(0xdeadbeef);
704 retb = SetupFindFirstLineA( hinf, "Sectionname", NULL, &context );
705 ok(retb, "Expected success\n");
707 "Expected ERROR_SUCCESS, got %08x\n", GetLastError());
708
709 SetLastError(0xdeadbeef);
710 retb = SetupFindFirstLineA( hinf, "Sectionname", "ImNotThere", &context );
711 ok(!retb, "Expected failure\n");
713 "Expected ERROR_LINE_NOT_FOUND, got %08x\n", GetLastError());
714
715 SetLastError(0xdeadbeef);
716 retb = SetupFindFirstLineA( hinf, "Sectionname", "Keyname1", &context );
717 ok(retb, "Expected success\n");
719 "Expected ERROR_SUCCESS, got %08x\n", GetLastError());
720
721 SetLastError(0xdeadbeef);
722 retb = SetupFindNextMatchLineA( &context, "ImNotThere", &context );
723 ok(!retb, "Expected failure\n");
725 "Expected ERROR_LINE_NOT_FOUND, got %08x\n", GetLastError());
726
727 SetLastError(0xdeadbeef);
728 retb = SetupFindNextMatchLineA( &context, "Keyname2", &context );
729 ok(retb, "Expected success\n");
731 "Expected ERROR_SUCCESS, got %08x\n", GetLastError());
732
733 SetLastError(0xdeadbeef);
734 retl = SetupGetLineCountA( hinf, "ImNotThere");
735 ok(retl == -1, "Expected -1, got %d\n", retl);
737 "Expected ERROR_SECTION_NOT_FOUND, got %08x\n", GetLastError());
738
739 SetLastError(0xdeadbeef);
740 retl = SetupGetLineCountA( hinf, "Sectionname");
741 ok(retl == 2, "Expected 2, got %d\n", retl);
743 "Expected ERROR_SUCCESS, got %08x\n", GetLastError());
744
745 SetLastError(0xdeadbeef);
746 retb = SetupGetLineTextA( NULL, hinf, "ImNotThere", "ImNotThere", buf, bufsize, &retsize);
747 ok(!retb, "Expected failure\n");
749 "Expected ERROR_LINE_NOT_FOUND, got %08x\n", GetLastError());
750
751 SetLastError(0xdeadbeef);
752 retb = SetupGetLineTextA( NULL, hinf, "Sectionname", "ImNotThere", buf, bufsize, &retsize);
753 ok(!retb, "Expected failure\n");
755 "Expected ERROR_LINE_NOT_FOUND, got %08x\n", GetLastError());
756
757 SetLastError(0xdeadbeef);
758 retb = SetupGetLineTextA( NULL, hinf, "Sectionname", "Keyname1", buf, bufsize, &retsize);
759 ok(retb, "Expected success\n");
761 "Expected ERROR_SUCCESS, got %08x\n", GetLastError());
762
763 SetLastError(0xdeadbeef);
764 retb = SetupGetLineByIndexA( hinf, "ImNotThere", 1, &context );
765 ok(!retb, "Expected failure\n");
767 "Expected ERROR_LINE_NOT_FOUND, got %08x\n", GetLastError());
768
769 SetLastError(0xdeadbeef);
770 retb = SetupGetLineByIndexA( hinf, "Sectionname", 1, &context );
771 ok(retb, "Expected success\n");
773 "Expected ERROR_SUCCESS, got %08x\n", GetLastError());
774
775 SetLastError(0xdeadbeef);
776 retb = SetupGetLineByIndexA( hinf, "Sectionname", 3, &context );
777 ok(!retb, "Expected failure\n");
779 "Expected ERROR_LINE_NOT_FOUND, got %08x\n", GetLastError());
780
781 SetupCloseInfFile( hinf );
782}
#define ERROR_SUCCESS
Definition: deptool.c:10
BOOL WINAPI SetupFindNextMatchLineA(PINFCONTEXT context_in, PCSTR key, PINFCONTEXT context_out)
Definition: parser.c:1672
BOOL WINAPI SetupFindFirstLineA(HINF hinf, PCSTR section, PCSTR key, INFCONTEXT *context)
Definition: parser.c:1564
LONG WINAPI SetupGetLineCountA(HINF hinf, PCSTR name)
Definition: parser.c:1475
BOOL WINAPI SetupGetLineByIndexA(HINF hinf, PCSTR section, DWORD index, INFCONTEXT *context)
Definition: parser.c:1515
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLenum GLuint GLsizei bufsize
Definition: glext.h:7473
long LONG
Definition: pedump.c:60
#define ERROR_SECTION_NOT_FOUND
Definition: setupapi.h:293
#define ERROR_LINE_NOT_FOUND
Definition: setupapi.h:294

Referenced by START_TEST().

◆ test_invalid_files()

static void test_invalid_files ( void  )
static

Definition at line 151 of file parser.c.

152{
153 unsigned int i;
155 HINF hinf;
156 DWORD err;
157
158 for (i = 0; i < ARRAY_SIZE(invalid_files); i++)
159 {
160 SetLastError( 0xdeadbeef );
161 err_line = 0xdeadbeef;
163 err = GetLastError();
164 trace( "hinf=%p err=0x%x line=%d\n", hinf, err, err_line );
165 if (invalid_files[i].error) /* should fail */
166 {
167 ok( hinf == INVALID_HANDLE_VALUE, "file %u: Open succeeded\n", i );
169 {
170 ok( err == invalid_files[i].error, "file %u: Bad error %u/%u\n",
172 ok( err_line == invalid_files[i].err_line, "file %u: Bad error line %d/%d\n",
174 }
175 }
176 else /* should succeed */
177 {
178 ok( hinf != INVALID_HANDLE_VALUE, "file %u: Open failed\n", i );
179 ok( err == 0, "file %u: Error code set to %u\n", i, err );
180 }
181 SetupCloseInfFile( hinf );
182 }
183}
#define ARRAY_SIZE(A)
Definition: main.h:33
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define error(str)
Definition: mkdosfs.c:1605
#define todo_wine_if(is_todo)
Definition: custom.c:76
static const struct @1696 invalid_files[]
BOOL todo
Definition: parser.c:107

Referenced by START_TEST().

◆ test_key_names()

static void test_key_names ( void  )
static

Definition at line 411 of file parser.c.

412{
414 const char *line;
415 unsigned int i, index, count;
417 HINF hinf;
418 DWORD err;
419 BOOL ret;
421
422 for (i = 0; i < ARRAY_SIZE(key_names); i++)
423 {
424 strcpy( buffer, STD_HEADER "[Test]\n" );
426 SetLastError( 0xdeadbeef );
428 ok( hinf != INVALID_HANDLE_VALUE, "line %u: open failed err %u\n", i, GetLastError() );
429 if (hinf == INVALID_HANDLE_VALUE) continue;
430
431 ret = SetupFindFirstLineA( hinf, "Test", 0, &context );
432 ok(ret, "SetupFindFirstLineA failed: le=%u\n", GetLastError());
433 if (!ret)
434 {
435 SetupCloseInfFile( hinf );
436 continue;
437 }
438
440
441 buffer[0] = buffer[1] = 0; /* build the full line */
442 for (index = 0; ; index++)
443 {
444 const char *field = get_string_field( &context, index + 1 );
445 err = GetLastError();
446 if (field)
447 {
448 ok( err == 0, "line %u: bad error %u\n", i, err );
449 if (key_names[i].fields[index])
450 {
451 if (i == 49)
453 !strcmp( field, A1200), /* Vista, W2K8 */
454 "line %u: bad field %s/%s\n",
456 else if (i == 52)
458 !strcmp( field, A4096), /* Win10 >= 1709 */
459 "line %u: bad field %s/%s\n",
461 else /* don't compare drive letter of paths */
462 if (field[0] && field[1] == ':' && field[2] == '\\')
463 ok( !strcmp( field + 1, key_names[i].fields[index] + 1 ),
464 "line %u: bad field %s/%s\n",
466 else
467 ok( !strcmp( field, key_names[i].fields[index] ), "line %u: bad field %s/%s\n",
469 }
470 else
471 ok( 0, "line %u: got extra field %s\n", i, field );
472 strcat( buffer, "," );
473 strcat( buffer, field );
474 }
475 else
476 {
477 ok( err == 0 || err == ERROR_INVALID_PARAMETER,
478 "line %u: bad error %u\n", i, err );
479 if (key_names[i].fields[index])
480 ok( 0, "line %u: missing field %s\n", i, key_names[i].fields[index] );
481 }
482 if (!key_names[i].fields[index]) break;
483 }
485 ok( count == index, "line %u: bad count %d/%d\n", i, index, count );
486
488 ok( line != NULL, "line %u: SetupGetLineText failed\n", i );
489 if (line) ok( !strcmp( line, buffer+1 ), "line %u: bad text %s/%s\n", i, line, buffer+1 );
490
491 SetupCloseInfFile( hinf );
492 }
493
494}
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
GLuint GLuint GLsizei count
Definition: gl.h:1545
const char * fields[10]
Definition: parser.c:313
static const char * check_key(INFCONTEXT *context, const char *wanted)
Definition: parser.c:393
static const struct @1698 key_names[]
#define A4096
Definition: parser.c:62
static const char * get_line_text(INFCONTEXT *context)
Definition: parser.c:92
Definition: parser.c:44
Definition: parser.c:49
ULONG WINAPI SetupGetFieldCount(IN PINFCONTEXT Context)
Definition: infsupp.c:93

Referenced by START_TEST().

◆ test_pSetupGetField()

static void test_pSetupGetField ( void  )
static

Definition at line 533 of file parser.c.

534{
535 UINT err;
536 BOOL ret;
537 HINF hinf;
538 LPCSTR fieldA;
539 LPCWSTR fieldW;
541 int i;
542 int len;
543 BOOL unicode = TRUE;
544
545 SetLastError(0xdeadbeef);
548 {
549 win_skip("Using A-functions instead of W\n");
550 unicode = FALSE;
551 }
552
553 hinf = test_file_contents( contents, &err );
554 ok( hinf != NULL, "Expected valid INF file\n" );
555
556 ret = SetupFindFirstLineA( hinf, "FileBranchInfo", NULL, &context );
557 ok( ret, "Failed to find first line\n" );
558
559 /* native Windows crashes if a NULL context is sent in */
560
561 for ( i = 0; i < 3; i++ )
562 {
563 if (unicode)
564 {
565 fieldW = pSetupGetFieldW( &context, i );
566 ok( fieldW != NULL, "Failed to get field %i\n", i );
567 ok( !lstrcmpW( getfield_resW[i], fieldW ), "Wrong string returned\n" );
568 }
569 else
570 {
571 fieldA = pSetupGetFieldA( &context, i );
572 ok( fieldA != NULL, "Failed to get field %i\n", i );
573 ok( !lstrcmpA( getfield_resA[i], fieldA ), "Wrong string returned\n" );
574 }
575 }
576
577 if (unicode)
578 {
579 fieldW = pSetupGetFieldW( &context, 3 );
580 ok( fieldW != NULL, "Failed to get field 3\n" );
581 len = lstrlenW( fieldW );
582 ok( len == 511 || /* NT4, W2K, XP and W2K3 */
583 len == 4096, /* Vista */
584 "Unexpected length, got %d\n", len );
585
586 fieldW = pSetupGetFieldW( &context, 4 );
587 ok( fieldW == NULL, "Expected NULL, got %p\n", fieldW );
589 "Expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError() );
590 }
591 else
592 {
593 fieldA = pSetupGetFieldA( &context, 3 );
594 ok( fieldA != NULL, "Failed to get field 3\n" );
595 len = lstrlenA( fieldA );
596 ok( len == 511, /* Win9x, WinME */
597 "Unexpected length, got %d\n", len );
598
599 fieldA = pSetupGetFieldA( &context, 4 );
600 ok( fieldA == NULL, "Expected NULL, got %p\n", fieldA );
602 "Expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError() );
603 }
604
605 SetupCloseInfFile( hinf );
606}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:102
#define lstrlenW
Definition: compat.h:750
int WINAPI lstrcmpW(LPCWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:170
int WINAPI lstrcmpA(LPCSTR lpString1, LPCSTR lpString2)
Definition: lstring.c:18
int WINAPI lstrlenA(LPCSTR lpString)
Definition: lstring.c:145
static const CHAR getfield_resA[][20]
Definition: parser.c:519
static const WCHAR getfield_resW[][20]
Definition: parser.c:526
const char * LPCSTR
Definition: xmlstorage.h:183
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

Referenced by START_TEST().

◆ test_section_names()

static void test_section_names ( void  )
static

Definition at line 225 of file parser.c.

226{
227 unsigned int i;
229 HINF hinf;
230 DWORD err;
231 LONG ret;
232
233 for (i = 0; i < ARRAY_SIZE(section_names); i++)
234 {
235 SetLastError( 0xdeadbeef );
237 ok( hinf != INVALID_HANDLE_VALUE, "line %u: open failed err %u\n", i, GetLastError() );
238 if (hinf == INVALID_HANDLE_VALUE) continue;
239
241 err = GetLastError();
242 trace( "hinf=%p ret=%d err=0x%x\n", hinf, ret, err );
243 if (ret != -1)
244 {
245 ok( !section_names[i].error, "line %u: section name %s found\n",
247 ok( !err, "line %u: bad error code %u\n", i, err );
248 }
249 else
250 {
251 ok( section_names[i].error, "line %u: section name %s not found\n",
253 ok( err == section_names[i].error, "line %u: bad error %u/%u\n",
255 }
256 SetupCloseInfFile( hinf );
257 }
258}
static const struct @1697 section_names[]
Definition: parser.c:56

Referenced by START_TEST().

◆ test_SetupGetIntField()

static void test_SetupGetIntField ( void  )
static

Definition at line 608 of file parser.c.

609{
610 static const struct
611 {
612 const char *key;
613 const char *fields;
614 DWORD index;
615 INT value;
616 DWORD err;
617 } keys[] =
618 {
619 /* key fields index expected int errorcode */
620 { "Key", "48", 1, 48, ERROR_SUCCESS },
621 { "Key", "48", 0, -1, ERROR_INVALID_DATA },
622 { "123", "48", 0, 123, ERROR_SUCCESS },
623 { "Key", "0x4", 1, 4, ERROR_SUCCESS },
624 { "Key", "Field1", 1, -1, ERROR_INVALID_DATA },
625 { "Key", "Field1,34", 2, 34, ERROR_SUCCESS },
626 { "Key", "Field1,,Field3", 2, 0, ERROR_SUCCESS },
627 { "Key", "Field1,", 2, 0, ERROR_SUCCESS }
628 };
629 unsigned int i;
630
631 for (i = 0; i < ARRAY_SIZE(keys); i++)
632 {
633 HINF hinf;
636 UINT err;
637 BOOL retb;
638 INT intfield;
639
640 strcpy( buffer, STD_HEADER "[TestSection]\n" );
641 strcat( buffer, keys[i].key );
642 strcat( buffer, "=" );
643 strcat( buffer, keys[i].fields );
644 hinf = test_file_contents( buffer, &err);
645 ok( hinf != NULL, "Expected valid INF file\n" );
646
647 SetupFindFirstLineA( hinf, "TestSection", keys[i].key, &context );
648 SetLastError( 0xdeadbeef );
649 intfield = -1;
650 retb = SetupGetIntField( &context, keys[i].index, &intfield );
651 if ( keys[i].err == ERROR_SUCCESS )
652 {
653 ok( retb, "%u: Expected success\n", i );
655 GetLastError() == 0xdeadbeef /* win9x, NT4 */,
656 "%u: Expected ERROR_SUCCESS or 0xdeadbeef, got %u\n", i, GetLastError() );
657 }
658 else
659 {
660 ok( !retb, "%u: Expected failure\n", i );
661 ok( GetLastError() == keys[i].err,
662 "%u: Expected %d, got %u\n", i, keys[i].err, GetLastError() );
663 }
664 ok( intfield == keys[i].value, "%u: Expected %d, got %d\n", i, keys[i].value, intfield );
665
666 SetupCloseInfFile( hinf );
667 }
668}
BOOL WINAPI SetupGetIntField(PINFCONTEXT context, DWORD index, PINT result)
Definition: parser.c:1933
int32_t INT
Definition: typedefs.h:58
Definition: pdh_main.c:94
#define ERROR_INVALID_DATA
Definition: winerror.h:116

Referenced by START_TEST().

Variable Documentation

◆ buffer

Definition at line 36 of file parser.c.

◆ contents

const char* contents
static
Initial value:
= "[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"
#define A4097
Definition: parser.c:63

Definition at line 511 of file parser.c.

Referenced by create_cdf_file(), create_stream(), D3DReadFileToBlob(), DataCacheEntry_Save(), DoReadAllOfFile(), import_reg(), CZipCreatorImpl::JustDoIt(), makeFile(), merge_old_directory_into_tree(), save_dib(), save_emf(), save_mfpict(), test__hwrite(), test__lwrite(), test_create_file_imp(), test_enum_sections(), test_profile_delete_on_close(), test_pSetupGetField(), test_read_write(), tmp_fill_segdir_seg(), write_reg_file(), and xwin_toggle_fullscreen().

◆ data

Definition at line 104 of file parser.c.

◆ DWORD

Definition at line 34 of file parser.c.

◆ err_line

◆ error

return error = FT_THROW( Invalid_CharMap_Format )

Definition at line 105 of file parser.c.

◆ fields

◆ getfield_resA

const CHAR getfield_resA[][20]
static
Initial value:
=
{
"RTMQFE",
"%RTMGFE_NAME%",
"SP1RTM",
}

Definition at line 519 of file parser.c.

Referenced by test_pSetupGetField().

◆ getfield_resW

const WCHAR getfield_resW[][20]
static
Initial value:
=
{
{'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},
}

Definition at line 526 of file parser.c.

Referenced by test_pSetupGetField().

◆ hSetupAPI

HMODULE hSetupAPI
static

Definition at line 33 of file parser.c.

Referenced by init_function_pointers().

◆ index

Definition at line 36 of file parser.c.

◆ 

const struct { ... } invalid_files[]

Referenced by test_invalid_files().

◆ key

Definition at line 312 of file parser.c.

Referenced by check_key(), and test_SetupGetIntField().

◆ 

const struct { ... } key_names[]

Referenced by test_key_names().

◆ need

◆ section

Definition at line 191 of file parser.c.

◆ 

const struct { ... } section_names[]

Referenced by test_section_names().

◆ size

Definition at line 36 of file parser.c.

Referenced by xmlParseBalancedChunkMemoryInternal().

◆ tmpfilename

◆ todo

BOOL todo

Definition at line 107 of file parser.c.

Referenced by test_invalid_files().