2 * INF file parsing tests
4 * Copyright 2002, 2005 Alexandre Julliard for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
31 #include "wine/test.h"
33 /* function pointers */
34 static HMODULE hSetupAPI
;
35 static LPCWSTR (WINAPI
*pSetupGetField
)(PINFCONTEXT
,DWORD
);
37 static void init_function_pointers(void)
39 hSetupAPI
= GetModuleHandleA("setupapi.dll");
41 pSetupGetField
= (void *)GetProcAddress(hSetupAPI
, "pSetupGetField");
44 static const char tmpfilename
[] = ".\\tmp.inf";
46 /* some large strings */
47 #define A255 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" \
48 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" \
49 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" \
50 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
52 #define A400 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" \
53 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" \
54 "aaaaaaaaaaaaaaaa" A256
55 #define A1200 A400 A400 A400
56 #define A511 A255 A256
57 #define A4097 "a" A256 A256 A256 A256 A256 A256 A256 A256 A256 A256 A256 A256 A256 A256 A256 A256
59 #define STD_HEADER "[Version]\r\nSignature=\"$CHICAGO$\"\r\n"
61 #define STR_SECTION "[Strings]\nfoo=aaa\nbar=bbb\nloop=%loop2%\nloop2=%loop%\n" \
62 "per%%cent=abcd\nper=1\ncent=2\n22=foo\n" \
64 "mydrive=\"C:\\\"\n" \
67 /* create a new file with specified contents and open it */
68 static HINF
test_file_contents( const char *data
, UINT
*err_line
)
71 HANDLE handle
= CreateFileA( tmpfilename
, GENERIC_READ
|GENERIC_WRITE
,
72 FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, CREATE_ALWAYS
, 0, 0 );
73 if (handle
== INVALID_HANDLE_VALUE
) return 0;
74 if (!WriteFile( handle
, data
, strlen(data
), &res
, NULL
)) trace( "write error\n" );
75 CloseHandle( handle
);
76 return SetupOpenInfFileA( tmpfilename
, 0, INF_STYLE_WIN4
, err_line
);
79 static const char *get_string_field( INFCONTEXT
*context
, DWORD index
)
81 static char buffer
[MAX_INF_STRING_LENGTH
+32];
82 if (SetupGetStringFieldA( context
, index
, buffer
, sizeof(buffer
), NULL
)) return buffer
;
86 static const char *get_line_text( INFCONTEXT
*context
)
88 static char buffer
[MAX_INF_STRING_LENGTH
+32];
89 if (SetupGetLineTextA( context
, 0, 0, 0, buffer
, sizeof(buffer
), NULL
)) return buffer
;
94 /* Test various valid/invalid file formats */
104 /* file contents expected error (or 0) errline todo */
105 { "\r\n", ERROR_WRONG_INF_STYLE
, 0, 0 },
106 { "abcd\r\n", ERROR_WRONG_INF_STYLE
, 0, 1 },
107 { "[Version]\r\n", ERROR_WRONG_INF_STYLE
, 0, 0 },
108 { "[Version]\nSignature=", ERROR_WRONG_INF_STYLE
, 0, 0 },
109 { "[Version]\nSignature=foo", ERROR_WRONG_INF_STYLE
, 0, 0 },
110 { "[version]\nsignature=$chicago$", 0, 0, 0 },
111 { "[VERSION]\nSIGNATURE=$CHICAGO$", 0, 0, 0 },
112 { "[Version]\nSignature=$chicago$,abcd", 0, 0, 0 },
113 { "[Version]\nabc=def\nSignature=$chicago$", 0, 0, 0 },
114 { "[Version]\nabc=def\n[Version]\nSignature=$chicago$", 0, 0, 0 },
115 { STD_HEADER
, 0, 0, 0 },
116 { STD_HEADER
"[]\r\n", 0, 0, 0 },
117 { STD_HEADER
"]\r\n", 0, 0, 0 },
118 { STD_HEADER
"[" A255
"]\r\n", 0, 0, 0 },
119 { STD_HEADER
"[ab\r\n", ERROR_BAD_SECTION_NAME_LINE
, 3, 0 },
120 { STD_HEADER
"\n\n[ab\x1a]\n", ERROR_BAD_SECTION_NAME_LINE
, 5, 0 },
121 { STD_HEADER
"[" A256
"]\r\n", ERROR_SECTION_NAME_TOO_LONG
, 3, 0 },
122 { "[abc]\n" STD_HEADER
, 0, 0, 0 },
123 { "abc\r\n" STD_HEADER
, ERROR_EXPECTED_SECTION_NAME
, 1, 0 },
124 { ";\n;\nabc\r\n" STD_HEADER
, ERROR_EXPECTED_SECTION_NAME
, 3, 0 },
125 { ";\n;\nab\nab\n" STD_HEADER
, ERROR_EXPECTED_SECTION_NAME
, 3, 0 },
126 { ";aa\n;bb\n" STD_HEADER
, 0, 0, 0 },
127 { STD_HEADER
" [TestSection\x00] \n", ERROR_BAD_SECTION_NAME_LINE
, 3, 0 },
128 { STD_HEADER
" [Test\x00Section] \n", ERROR_BAD_SECTION_NAME_LINE
, 3, 0 },
129 { STD_HEADER
" [TestSection\x00] \n", ERROR_BAD_SECTION_NAME_LINE
, 3, 0 },
130 { STD_HEADER
" [Test\x00Section] \n", ERROR_BAD_SECTION_NAME_LINE
, 3, 0 },
133 static void test_invalid_files(void)
140 for (i
= 0; i
< sizeof(invalid_files
)/sizeof(invalid_files
[0]); i
++)
142 SetLastError( 0xdeadbeef );
143 err_line
= 0xdeadbeef;
144 hinf
= test_file_contents( invalid_files
[i
].data
, &err_line
);
145 err
= GetLastError();
146 trace( "hinf=%p err=0x%x line=%d\n", hinf
, err
, err_line
);
147 if (invalid_files
[i
].error
) /* should fail */
149 ok( hinf
== INVALID_HANDLE_VALUE
, "file %u: Open succeeded\n", i
);
150 if (invalid_files
[i
].todo
) todo_wine
152 ok( err
== invalid_files
[i
].error
, "file %u: Bad error %u/%u\n",
153 i
, err
, invalid_files
[i
].error
);
154 ok( err_line
== invalid_files
[i
].err_line
, "file %u: Bad error line %d/%d\n",
155 i
, err_line
, invalid_files
[i
].err_line
);
159 ok( err
== invalid_files
[i
].error
, "file %u: Bad error %u/%u\n",
160 i
, err
, invalid_files
[i
].error
);
161 ok( err_line
== invalid_files
[i
].err_line
, "file %u: Bad error line %d/%d\n",
162 i
, err_line
, invalid_files
[i
].err_line
);
165 else /* should succeed */
167 ok( hinf
!= INVALID_HANDLE_VALUE
, "file %u: Open failed\n", i
);
168 ok( err
== 0, "file %u: Error code set to %u\n", i
, err
);
170 SetupCloseInfFile( hinf
);
175 /* Test various section names */
184 /* file contents section name error code */
185 { STD_HEADER
"[TestSection]", "TestSection", 0 },
186 { STD_HEADER
"[TestSection]\n", "TestSection", 0 },
187 { STD_HEADER
"[TESTSECTION]\r\n", "TestSection", 0 },
188 { STD_HEADER
"[TestSection]\n[abc]", "testsection", 0 },
189 { STD_HEADER
";[TestSection]\n", "TestSection", ERROR_SECTION_NOT_FOUND
},
190 { STD_HEADER
"[TestSection]\n", "Bad name", ERROR_SECTION_NOT_FOUND
},
192 { STD_HEADER
"[TestSection] \r\n", "TestSection", 0 },
193 { STD_HEADER
" [TestSection]\r\n", "TestSection", 0 },
194 { STD_HEADER
" [TestSection] dummy\r\n", "TestSection", 0 },
195 { STD_HEADER
" [TestSection] [foo]\r\n", "TestSection", 0 },
196 { STD_HEADER
" [ Test Section ] dummy\r\n", " Test Section ", 0 },
197 { STD_HEADER
"[TestSection] \032\ndummy", "TestSection", 0 },
198 { STD_HEADER
"[TestSection] \n\032dummy", "TestSection", 0 },
199 /* special chars in section name */
200 { STD_HEADER
"[Test[Section]\r\n", "Test[Section", 0 },
201 { STD_HEADER
"[Test[S]ection]\r\n", "Test[S", 0 },
202 { STD_HEADER
"[Test[[[Section]\r\n", "Test[[[Section", 0 },
203 { STD_HEADER
"[]\r\n", "", 0 },
204 { STD_HEADER
"[[[]\n", "[[", 0 },
205 { STD_HEADER
"[Test\"Section]\r\n", "Test\"Section", 0 },
206 { STD_HEADER
"[Test\\Section]\r\n", "Test\\Section", 0 },
207 { STD_HEADER
"[Test\\ Section]\r\n", "Test\\ Section", 0 },
208 { STD_HEADER
"[Test;Section]\r\n", "Test;Section", 0 },
209 /* various control chars */
210 { STD_HEADER
" [Test\r\b\tSection] \n", "Test\r\b\tSection", 0 },
214 static void test_section_names(void)
222 for (i
= 0; i
< sizeof(section_names
)/sizeof(section_names
[0]); i
++)
224 SetLastError( 0xdeadbeef );
225 hinf
= test_file_contents( section_names
[i
].data
, &err_line
);
226 ok( hinf
!= INVALID_HANDLE_VALUE
, "line %u: open failed err %u\n", i
, GetLastError() );
227 if (hinf
== INVALID_HANDLE_VALUE
) continue;
229 ret
= SetupGetLineCountA( hinf
, section_names
[i
].section
);
230 err
= GetLastError();
231 trace( "hinf=%p ret=%d err=0x%x\n", hinf
, ret
, err
);
234 ok( !section_names
[i
].error
, "line %u: section name %s found\n",
235 i
, section_names
[i
].section
);
236 ok( !err
, "line %u: bad error code %u\n", i
, err
);
240 ok( section_names
[i
].error
, "line %u: section name %s not found\n",
241 i
, section_names
[i
].section
);
242 ok( err
== section_names
[i
].error
, "line %u: bad error %u/%u\n",
243 i
, err
, section_names
[i
].error
);
245 SetupCloseInfFile( hinf
);
250 /* Test various key and value names */
256 const char *fields
[10];
259 /* file contents expected key expected fields */
260 { "ab=cd", "ab", { "cd" } },
261 { "ab=cd,ef,gh,ij", "ab", { "cd", "ef", "gh", "ij" } },
262 { "ab", "ab", { "ab" } },
263 { "ab,cd", NULL
, { "ab", "cd" } },
264 { "ab,cd=ef", NULL
, { "ab", "cd=ef" } },
265 { "=abcd,ef", "", { "abcd", "ef" } },
267 { "ba\\\ncd=ef", "bacd", { "ef" } },
268 { "ab \\ \ncd=ef", "abcd", { "ef" } },
269 { "ab\\\ncd,ef", NULL
, { "abcd", "ef" } },
270 { "ab \\ ;cc\ncd=ef", "abcd", { "ef" } },
271 { "ab \\ \\ \ncd=ef", "abcd", { "ef" } },
272 { "ba \\ dc=xx", "ba \\ dc", { "xx" } },
273 { "ba \\\\ \nc=d", "bac", { "d" } },
274 { "a=b\\\\c", "a", { "b\\\\c" } },
275 { "ab=cd \\ ", "ab", { "cd" } },
276 { "ba=c \\ \n \\ \n a", "ba", { "ca" } },
277 { "ba=c \\ \n \\ a", "ba", { "c\\ a" } },
278 { " \\ a= \\ b", "\\ a", { "\\ b" } },
280 { "Ab\"Cd\"=Ef", "AbCd", { "Ef" } },
281 { "Ab\"Cd=Ef\"", "AbCd=Ef", { "AbCd=Ef" } },
282 { "ab\"\"\"cd,ef=gh\"", "ab\"cd,ef=gh", { "ab\"cd,ef=gh" } },
283 { "ab\"\"cd=ef", "abcd", { "ef" } },
284 { "ab\"\"cd=ef,gh", "abcd", { "ef", "gh" } },
285 { "ab=cd\"\"ef", "ab", { "cdef" } },
286 { "ab=cd\",\"ef", "ab", { "cd,ef" } },
287 { "ab=cd\",ef", "ab", { "cd,ef" } },
288 { "ab=cd\",ef\\\nab", "ab", { "cd,ef\\" } },
290 /* single quotes (unhandled)*/
291 { "HKLM,A,B,'C',D", NULL
, { "HKLM", "A","B","'C'","D" } },
293 { " a b = c , d \n", "a b", { "c", "d" } },
294 { " a b = c ,\" d\" \n", "a b", { "c", " d" } },
295 { " a b\r = c\r\n", "a b", { "c" } },
297 { "a=b,,,c,,,d", "a", { "b", "", "", "c", "", "", "d" } },
298 { "a=b,\"\",c,\" \",d", "a", { "b", "", "c", " ", "d" } },
299 { "=,,b", "", { "", "", "b" } },
300 { ",=,,b", NULL
, { "", "=", "", "b" } },
301 { "a=\n", "a", { "" } },
304 { "ab=c\032d", "ab", { "c" } },
305 { "ab\032=cd", "ab", { "ab" } },
307 { "abcd=ef\x0gh", "abcd", { "ef" } },
308 /* multiple sections with same name */
309 { "[Test2]\nab\n[Test]\nee=ff\n", "ee", { "ff" } },
310 /* string substitution */
311 { "%foo%=%bar%\n" STR_SECTION
, "aaa", { "bbb" } },
312 { "%foo%xx=%bar%yy\n" STR_SECTION
, "aaaxx", { "bbbyy" } },
313 { "%% %foo%=%bar%\n" STR_SECTION
, "% aaa", { "bbb" } },
314 { "%f\"o\"o%=ccc\n" STR_SECTION
, "aaa", { "ccc" } },
315 { "abc=%bar;bla%\n" STR_SECTION
, "abc", { "%bar" } },
316 { "loop=%loop%\n" STR_SECTION
, "loop", { "%loop2%" } },
317 { "%per%%cent%=100\n" STR_SECTION
, "12", { "100" } },
318 { "a=%big%\n" STR_SECTION
, "a", { A400
} },
319 { "a=%verybig%\n" STR_SECTION
, "a", { A511
} }, /* truncated to 511, not on Vista/W2K8 */
320 { "a=%big%%big%%big%%big%\n" STR_SECTION
, "a", { A400 A400 A400 A400
} },
321 { "a=%big%%big%%big%%big%%big%%big%%big%%big%%big%\n" STR_SECTION
, "a", { A400 A400 A400 A400 A400 A400 A400 A400 A400
} },
322 { "a=%big%%big%%big%%big%%big%%big%%big%%big%%big%%big%%big%\n" STR_SECTION
, "a", { A4097
/*MAX_INF_STRING_LENGTH+1*/ } },
324 /* Prove expansion of system entries removes extra \'s and string
325 replacements doesn't */
326 { "ab=\"%24%\"\n" STR_SECTION
, "ab", { "C:\\" } },
327 { "ab=\"%mydrive%\"\n" STR_SECTION
, "ab", { "C:\\" } },
328 { "ab=\"%24%\\fred\"\n" STR_SECTION
, "ab", { "C:\\fred" } },
329 { "ab=\"%mydrive%\\fred\"\n" STR_SECTION
,"ab", { "C:\\\\fred" } },
330 /* Confirm duplicate \'s kept */
331 { "ab=\"%24%\\\\fred\"", "ab", { "C:\\\\fred" } },
332 { "ab=C:\\\\FRED", "ab", { "C:\\\\FRED" } },
335 /* check the key of a certain line */
336 static const char *check_key( INFCONTEXT
*context
, const char *wanted
)
338 const char *key
= get_string_field( context
, 0 );
339 DWORD err
= GetLastError();
343 ok( !wanted
, "missing key %s\n", wanted
);
344 ok( err
== 0 || err
== ERROR_INVALID_PARAMETER
, "last error set to %u\n", err
);
348 ok( !strcmp( key
, wanted
), "bad key %s/%s\n", key
, wanted
);
349 ok( err
== 0, "last error set to %u\n", err
);
354 static void test_key_names(void)
356 char buffer
[MAX_INF_STRING_LENGTH
+32];
357 const char *key
, *line
;
358 unsigned int i
, index
, count
;
365 for (i
= 0; i
< sizeof(key_names
)/sizeof(key_names
[0]); i
++)
367 strcpy( buffer
, STD_HEADER
"[Test]\n" );
368 strcat( buffer
, key_names
[i
].data
);
369 SetLastError( 0xdeadbeef );
370 hinf
= test_file_contents( buffer
, &err_line
);
371 ok( hinf
!= INVALID_HANDLE_VALUE
, "line %u: open failed err %u\n", i
, GetLastError() );
372 if (hinf
== INVALID_HANDLE_VALUE
) continue;
374 ret
= SetupFindFirstLineA( hinf
, "Test", 0, &context
);
377 key
= check_key( &context
, key_names
[i
].key
);
379 buffer
[0] = buffer
[1] = 0; /* build the full line */
380 for (index
= 0; ; index
++)
382 const char *field
= get_string_field( &context
, index
+ 1 );
383 err
= GetLastError();
386 ok( err
== 0, "line %u: bad error %u\n", i
, err
);
387 if (key_names
[i
].fields
[index
])
390 ok( !strcmp( field
, key_names
[i
].fields
[index
] ) ||
391 !strcmp( field
, A1200
), /* Vista, W2K8 */
392 "line %u: bad field %s/%s\n",
393 i
, field
, key_names
[i
].fields
[index
] );
395 ok( !strcmp( field
, key_names
[i
].fields
[index
] ), "line %u: bad field %s/%s\n",
396 i
, field
, key_names
[i
].fields
[index
] );
399 ok( 0, "line %u: got extra field %s\n", i
, field
);
400 strcat( buffer
, "," );
401 strcat( buffer
, field
);
405 ok( err
== 0 || err
== ERROR_INVALID_PARAMETER
,
406 "line %u: bad error %u\n", i
, err
);
407 if (key_names
[i
].fields
[index
])
408 ok( 0, "line %u: missing field %s\n", i
, key_names
[i
].fields
[index
] );
410 if (!key_names
[i
].fields
[index
]) break;
412 count
= SetupGetFieldCount( &context
);
413 ok( count
== index
, "line %u: bad count %d/%d\n", i
, index
, count
);
415 line
= get_line_text( &context
);
416 ok( line
!= NULL
, "line %u: SetupGetLineText failed\n", i
);
417 if (line
) ok( !strcmp( line
, buffer
+1 ), "line %u: bad text %s/%s\n", i
, line
, buffer
+1 );
419 SetupCloseInfFile( hinf
);
424 static void test_close_inf_file(void)
426 SetLastError(0xdeadbeef);
427 SetupCloseInfFile(NULL
);
428 ok(GetLastError() == 0xdeadbeef ||
429 GetLastError() == ERROR_INVALID_PARAMETER
, /* Win9x, WinMe */
430 "Expected 0xdeadbeef, got %u\n", GetLastError());
432 SetLastError(0xdeadbeef);
433 SetupCloseInfFile(INVALID_HANDLE_VALUE
);
434 ok(GetLastError() == 0xdeadbeef ||
435 GetLastError() == ERROR_INVALID_PARAMETER
, /* Win9x, WinMe */
436 "Expected 0xdeadbeef, got %u\n", GetLastError());
439 static const char *contents
= "[Version]\n"
440 "Signature=\"$Windows NT$\"\n"
441 "FileVersion=5.1.1.2\n"
443 "RTMQFE=\"%RTMGFE_NAME%\",SP1RTM,"A4097
"\n"
445 "RTMQFE_NAME = \"RTMQFE\"\n";
447 static const WCHAR getfield_res
[][20] =
449 {'R','T','M','Q','F','E',0},
450 {'%','R','T','M','G','F','E','_','N','A','M','E','%',0},
451 {'S','P','1','R','T','M',0},
454 static void test_pSetupGetField(void)
464 hinf
= test_file_contents( contents
, &err
);
465 ok( hinf
!= NULL
, "Expected valid INF file\n" );
467 ret
= SetupFindFirstLine( hinf
, "FileBranchInfo", NULL
, &context
);
468 ok( ret
, "Failed to find first line\n" );
470 /* native Windows crashes if a NULL context is sent in */
472 for ( i
= 0; i
< 3; i
++ )
474 field
= pSetupGetField( &context
, i
);
475 ok( field
!= NULL
, "Failed to get field %i\n", i
);
476 ok( !lstrcmpW( getfield_res
[i
], field
), "Wrong string returned\n" );
479 field
= pSetupGetField( &context
, 3 );
480 ok( field
!= NULL
, "Failed to get field 3\n" );
481 len
= lstrlenW( field
);
482 ok( len
== 511 /* NT4, W2K, XP and W2K3 */ ||
483 len
== 4096 /* Vista */ ||
484 len
== 256 /* Win9x and WinME */,
485 "Unexpected length, got %d\n", len
);
487 field
= pSetupGetField( &context
, 4 );
488 ok( field
== NULL
, "Expected NULL, got %p\n", field
);
489 ok( GetLastError() == ERROR_INVALID_PARAMETER
,
490 "Expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError() );
492 SetupCloseInfFile( hinf
);
495 static void test_SetupGetIntField(void)
506 /* key fields index expected int errorcode */
507 { "Key=", "48", 1, 48, ERROR_SUCCESS
},
508 { "Key=", "48", 0, -1, ERROR_INVALID_DATA
},
509 { "123=", "48", 0, 123, ERROR_SUCCESS
},
510 { "Key=", "0x4", 1, 4, ERROR_SUCCESS
},
511 { "Key=", "Field1", 1, -1, ERROR_INVALID_DATA
},
512 { "Key=", "Field1,34", 2, 34, ERROR_SUCCESS
},
513 { "Key=", "Field1,,Field3", 2, 0, ERROR_SUCCESS
},
514 { "Key=", "Field1,", 2, 0, ERROR_SUCCESS
}
518 for (i
= 0; i
< sizeof(keys
)/sizeof(keys
[0]); i
++)
521 char buffer
[MAX_INF_STRING_LENGTH
];
527 strcpy( buffer
, STD_HEADER
"[TestSection]\n" );
528 strcat( buffer
, keys
[i
].key
);
529 strcat( buffer
, keys
[i
].fields
);
530 hinf
= test_file_contents( buffer
, &err
);
531 ok( hinf
!= NULL
, "Expected valid INF file\n" );
533 SetupFindFirstLineA( hinf
, "TestSection", "Key", &context
);
534 SetLastError( 0xdeadbeef );
536 retb
= SetupGetIntField( &context
, keys
[i
].index
, &intfield
);
537 if ( keys
[i
].err
== ERROR_SUCCESS
)
539 ok( retb
, "Expected success\n" );
540 ok( GetLastError() == ERROR_SUCCESS
||
541 GetLastError() == 0xdeadbeef /* win9x, NT4 */,
542 "Expected ERROR_SUCCESS or 0xdeadbeef, got %u\n", GetLastError() );
546 ok( !retb
, "Expected failure\n" );
547 ok( GetLastError() == keys
[i
].err
,
548 "Expected %d, got %u\n", keys
[i
].err
, GetLastError() );
550 ok( intfield
== keys
[i
].value
, "Expected %d, got %d\n", keys
[i
].value
, intfield
);
552 SetupCloseInfFile( hinf
);
556 static void test_GLE(void)
558 static const char *inf
=
560 "Signature=\"$Windows NT$\"\n"
562 "Keyname1=Field1,Field2,Field3\n"
564 "Keyname2=Field4,Field5\n";
570 char buf
[MAX_INF_STRING_LENGTH
];
571 int bufsize
= MAX_INF_STRING_LENGTH
;
574 hinf
= test_file_contents( inf
, &err
);
575 ok( hinf
!= NULL
, "Expected valid INF file\n" );
577 SetLastError(0xdeadbeef);
578 retb
= SetupFindFirstLineA( hinf
, "ImNotThere", NULL
, &context
);
579 ok(!retb
, "Expected failure\n");
580 ok(GetLastError() == ERROR_LINE_NOT_FOUND
,
581 "Expected ERROR_LINE_NOT_FOUND, got %08x\n", GetLastError());
583 SetLastError(0xdeadbeef);
584 retb
= SetupFindFirstLineA( hinf
, "ImNotThere", "ImNotThere", &context
);
585 ok(!retb
, "Expected failure\n");
586 ok(GetLastError() == ERROR_LINE_NOT_FOUND
,
587 "Expected ERROR_LINE_NOT_FOUND, got %08x\n", GetLastError());
589 SetLastError(0xdeadbeef);
590 retb
= SetupFindFirstLineA( hinf
, "Sectionname", NULL
, &context
);
591 ok(retb
, "Expected success\n");
592 ok(GetLastError() == ERROR_SUCCESS
,
593 "Expected ERROR_SUCCESS, got %08x\n", GetLastError());
595 SetLastError(0xdeadbeef);
596 retb
= SetupFindFirstLineA( hinf
, "Sectionname", "ImNotThere", &context
);
597 ok(!retb
, "Expected failure\n");
598 ok(GetLastError() == ERROR_LINE_NOT_FOUND
,
599 "Expected ERROR_LINE_NOT_FOUND, got %08x\n", GetLastError());
601 SetLastError(0xdeadbeef);
602 retb
= SetupFindFirstLineA( hinf
, "Sectionname", "Keyname1", &context
);
603 ok(retb
, "Expected success\n");
604 ok(GetLastError() == ERROR_SUCCESS
,
605 "Expected ERROR_SUCCESS, got %08x\n", GetLastError());
607 SetLastError(0xdeadbeef);
608 retb
= SetupFindNextMatchLineA( &context
, "ImNotThere", &context
);
609 ok(!retb
, "Expected failure\n");
610 ok(GetLastError() == ERROR_LINE_NOT_FOUND
,
611 "Expected ERROR_LINE_NOT_FOUND, got %08x\n", GetLastError());
613 SetLastError(0xdeadbeef);
614 retb
= SetupFindNextMatchLineA( &context
, "Keyname2", &context
);
615 ok(retb
, "Expected success\n");
616 ok(GetLastError() == ERROR_SUCCESS
,
617 "Expected ERROR_SUCCESS, got %08x\n", GetLastError());
619 SetLastError(0xdeadbeef);
620 retl
= SetupGetLineCountA( hinf
, "ImNotThere");
621 ok(retl
== -1, "Expected -1, got %d\n", retl
);
622 ok(GetLastError() == ERROR_SECTION_NOT_FOUND
,
623 "Expected ERROR_SECTION_NOT_FOUND, got %08x\n", GetLastError());
625 SetLastError(0xdeadbeef);
626 retl
= SetupGetLineCountA( hinf
, "Sectionname");
627 ok(retl
== 2, "Expected 2, got %d\n", retl
);
628 ok(GetLastError() == ERROR_SUCCESS
,
629 "Expected ERROR_SUCCESS, got %08x\n", GetLastError());
631 SetLastError(0xdeadbeef);
632 retb
= SetupGetLineTextA( NULL
, hinf
, "ImNotThere", "ImNotThere", buf
, bufsize
, &retsize
);
633 ok(!retb
, "Expected failure\n");
634 ok(GetLastError() == ERROR_LINE_NOT_FOUND
,
635 "Expected ERROR_LINE_NOT_FOUND, got %08x\n", GetLastError());
637 SetLastError(0xdeadbeef);
638 retb
= SetupGetLineTextA( NULL
, hinf
, "Sectionname", "ImNotThere", buf
, bufsize
, &retsize
);
639 ok(!retb
, "Expected failure\n");
640 ok(GetLastError() == ERROR_LINE_NOT_FOUND
,
641 "Expected ERROR_LINE_NOT_FOUND, got %08x\n", GetLastError());
643 SetLastError(0xdeadbeef);
644 retb
= SetupGetLineTextA( NULL
, hinf
, "Sectionname", "Keyname1", buf
, bufsize
, &retsize
);
645 ok(retb
, "Expected success\n");
646 ok(GetLastError() == ERROR_SUCCESS
,
647 "Expected ERROR_SUCCESS, got %08x\n", GetLastError());
649 SetLastError(0xdeadbeef);
650 retb
= SetupGetLineByIndexA( hinf
, "ImNotThere", 1, &context
);
651 ok(!retb
, "Expected failure\n");
652 ok(GetLastError() == ERROR_LINE_NOT_FOUND
,
653 "Expected ERROR_LINE_NOT_FOUND, got %08x\n", GetLastError());
655 SetLastError(0xdeadbeef);
656 retb
= SetupGetLineByIndexA( hinf
, "Sectionname", 1, &context
);
657 ok(retb
, "Expected success\n");
658 ok(GetLastError() == ERROR_SUCCESS
,
659 "Expected ERROR_SUCCESS, got %08x\n", GetLastError());
661 SetLastError(0xdeadbeef);
662 retb
= SetupGetLineByIndexA( hinf
, "Sectionname", 3, &context
);
663 ok(!retb
, "Expected failure\n");
664 ok(GetLastError() == ERROR_LINE_NOT_FOUND
,
665 "Expected ERROR_LINE_NOT_FOUND, got %08x\n", GetLastError());
667 SetupCloseInfFile( hinf
);
672 init_function_pointers();
673 test_invalid_files();
674 test_section_names();
676 test_close_inf_file();
677 test_pSetupGetField();
678 test_SetupGetIntField();
680 DeleteFileA( tmpfilename
);