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
30 #include "wine/test.h"
32 /* function pointers */
33 static HMODULE hSetupAPI
;
34 static LPCSTR (WINAPI
*pSetupGetFieldA
)(PINFCONTEXT
,DWORD
);
35 static LPCWSTR (WINAPI
*pSetupGetFieldW
)(PINFCONTEXT
,DWORD
);
36 static BOOL (WINAPI
*pSetupEnumInfSectionsA
)( HINF hinf
, UINT index
, PSTR buffer
, DWORD size
, UINT
*need
);
38 static void init_function_pointers(void)
40 hSetupAPI
= GetModuleHandleA("setupapi.dll");
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" );
49 static const char tmpfilename
[] = ".\\tmp.inf";
51 /* some large strings */
52 #define A255 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" \
53 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" \
54 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" \
55 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
57 #define A400 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" \
58 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" \
59 "aaaaaaaaaaaaaaaa" A256
60 #define A1200 A400 A400 A400
61 #define A511 A255 A256
62 #define A4097 "a" A256 A256 A256 A256 A256 A256 A256 A256 A256 A256 A256 A256 A256 A256 A256 A256
64 #define STD_HEADER "[Version]\r\nSignature=\"$CHICAGO$\"\r\n"
66 #define STR_SECTION "[Strings]\nfoo=aaa\nbar=bbb\nloop=%loop2%\nloop2=%loop%\n" \
67 "per%%cent=abcd\nper=1\ncent=2\n22=foo\n" \
69 "mydrive=\"C:\\\"\n" \
72 /* create a new file with specified contents and open it */
73 static HINF
test_file_contents( const char *data
, UINT
*err_line
)
76 HANDLE handle
= CreateFileA( tmpfilename
, GENERIC_READ
|GENERIC_WRITE
,
77 FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, CREATE_ALWAYS
, 0, 0 );
78 if (handle
== INVALID_HANDLE_VALUE
) return 0;
79 if (!WriteFile( handle
, data
, strlen(data
), &res
, NULL
)) trace( "write error\n" );
80 CloseHandle( handle
);
81 return SetupOpenInfFileA( tmpfilename
, 0, INF_STYLE_WIN4
, err_line
);
84 static const char *get_string_field( INFCONTEXT
*context
, DWORD index
)
86 static char buffer
[MAX_INF_STRING_LENGTH
+32];
87 if (SetupGetStringFieldA( context
, index
, buffer
, sizeof(buffer
), NULL
)) return buffer
;
91 static const char *get_line_text( INFCONTEXT
*context
)
93 static char buffer
[MAX_INF_STRING_LENGTH
+32];
94 if (SetupGetLineTextA( context
, 0, 0, 0, buffer
, sizeof(buffer
), NULL
)) return buffer
;
99 /* Test various valid/invalid file formats */
109 /* file contents expected error (or 0) errline todo */
110 { "\r\n", ERROR_WRONG_INF_STYLE
, 0, FALSE
},
111 { "abcd\r\n", ERROR_WRONG_INF_STYLE
, 0, TRUE
},
112 { "[Version]\r\n", ERROR_WRONG_INF_STYLE
, 0, FALSE
},
113 { "[Version]\nSignature=", ERROR_WRONG_INF_STYLE
, 0, FALSE
},
114 { "[Version]\nSignature=foo", ERROR_WRONG_INF_STYLE
, 0, FALSE
},
115 { "[version]\nsignature=$chicago$", 0, 0, FALSE
},
116 { "[VERSION]\nSIGNATURE=$CHICAGO$", 0, 0, FALSE
},
117 { "[Version]\nSignature=$chicago$,abcd", 0, 0, FALSE
},
118 { "[Version]\nabc=def\nSignature=$chicago$", 0, 0, FALSE
},
119 { "[Version]\nabc=def\n[Version]\nSignature=$chicago$", 0, 0, FALSE
},
120 { STD_HEADER
, 0, 0, FALSE
},
121 { STD_HEADER
"[]\r\n", 0, 0, FALSE
},
122 { STD_HEADER
"]\r\n", 0, 0, FALSE
},
123 { STD_HEADER
"[" A255
"]\r\n", 0, 0, FALSE
},
124 { STD_HEADER
"[ab\r\n", ERROR_BAD_SECTION_NAME_LINE
, 3, FALSE
},
125 { STD_HEADER
"\n\n[ab\x1a]\n", ERROR_BAD_SECTION_NAME_LINE
, 5, FALSE
},
126 { STD_HEADER
"[" A256
"]\r\n", ERROR_SECTION_NAME_TOO_LONG
, 3, FALSE
},
127 { "[abc]\n" STD_HEADER
, 0, 0, FALSE
},
128 { "abc\r\n" STD_HEADER
, ERROR_EXPECTED_SECTION_NAME
, 1, FALSE
},
129 { ";\n;\nabc\r\n" STD_HEADER
, ERROR_EXPECTED_SECTION_NAME
, 3, FALSE
},
130 { ";\n;\nab\nab\n" STD_HEADER
, ERROR_EXPECTED_SECTION_NAME
, 3, FALSE
},
131 { ";aa\n;bb\n" STD_HEADER
, 0, 0, FALSE
},
132 { STD_HEADER
" [TestSection\x00]\n", ERROR_BAD_SECTION_NAME_LINE
, 3, FALSE
},
133 { STD_HEADER
" [Test\x00Section]\n", ERROR_BAD_SECTION_NAME_LINE
, 3, FALSE
},
134 { STD_HEADER
" [TestSection\x00]\n", ERROR_BAD_SECTION_NAME_LINE
, 3, FALSE
},
135 { STD_HEADER
" [Test\x00Section]\n", ERROR_BAD_SECTION_NAME_LINE
, 3, FALSE
},
138 static void test_invalid_files(void)
145 for (i
= 0; i
< sizeof(invalid_files
)/sizeof(invalid_files
[0]); i
++)
147 SetLastError( 0xdeadbeef );
148 err_line
= 0xdeadbeef;
149 hinf
= test_file_contents( invalid_files
[i
].data
, &err_line
);
150 err
= GetLastError();
151 trace( "hinf=%p err=0x%x line=%d\n", hinf
, err
, err_line
);
152 if (invalid_files
[i
].error
) /* should fail */
154 ok( hinf
== INVALID_HANDLE_VALUE
, "file %u: Open succeeded\n", i
);
155 if (invalid_files
[i
].todo
) todo_wine
157 ok( err
== invalid_files
[i
].error
, "file %u: Bad error %u/%u\n",
158 i
, err
, invalid_files
[i
].error
);
159 ok( err_line
== invalid_files
[i
].err_line
, "file %u: Bad error line %d/%d\n",
160 i
, err_line
, invalid_files
[i
].err_line
);
164 ok( err
== invalid_files
[i
].error
, "file %u: Bad error %u/%u\n",
165 i
, err
, invalid_files
[i
].error
);
166 ok( err_line
== invalid_files
[i
].err_line
, "file %u: Bad error line %d/%d\n",
167 i
, err_line
, invalid_files
[i
].err_line
);
170 else /* should succeed */
172 ok( hinf
!= INVALID_HANDLE_VALUE
, "file %u: Open failed\n", i
);
173 ok( err
== 0, "file %u: Error code set to %u\n", i
, err
);
175 SetupCloseInfFile( hinf
);
180 /* Test various section names */
189 /* file contents section name error code */
190 { STD_HEADER
"[TestSection]", "TestSection", 0 },
191 { STD_HEADER
"[TestSection]\n", "TestSection", 0 },
192 { STD_HEADER
"[TESTSECTION]\r\n", "TestSection", 0 },
193 { STD_HEADER
"[TestSection]\n[abc]", "testsection", 0 },
194 { STD_HEADER
";[TestSection]\n", "TestSection", ERROR_SECTION_NOT_FOUND
},
195 { STD_HEADER
"[TestSection]\n", "Bad name", ERROR_SECTION_NOT_FOUND
},
197 { STD_HEADER
"[TestSection] \r\n", "TestSection", 0 },
198 { STD_HEADER
" [TestSection]\r\n", "TestSection", 0 },
199 { STD_HEADER
" [TestSection] dummy\r\n", "TestSection", 0 },
200 { STD_HEADER
" [TestSection] [foo]\r\n", "TestSection", 0 },
201 { STD_HEADER
" [ Test Section ] dummy\r\n", " Test Section ", 0 },
202 { STD_HEADER
"[TestSection] \032\ndummy", "TestSection", 0 },
203 { STD_HEADER
"[TestSection] \n\032dummy", "TestSection", 0 },
204 /* special chars in section name */
205 { STD_HEADER
"[Test[Section]\r\n", "Test[Section", 0 },
206 { STD_HEADER
"[Test[S]ection]\r\n", "Test[S", 0 },
207 { STD_HEADER
"[Test[[[Section]\r\n", "Test[[[Section", 0 },
208 { STD_HEADER
"[]\r\n", "", 0 },
209 { STD_HEADER
"[[[]\n", "[[", 0 },
210 { STD_HEADER
"[Test\"Section]\r\n", "Test\"Section", 0 },
211 { STD_HEADER
"[Test\\Section]\r\n", "Test\\Section", 0 },
212 { STD_HEADER
"[Test\\ Section]\r\n", "Test\\ Section", 0 },
213 { STD_HEADER
"[Test;Section]\r\n", "Test;Section", 0 },
214 /* various control chars */
215 { STD_HEADER
" [Test\r\b\tSection] \n", "Test\r\b\tSection", 0 },
219 static void test_section_names(void)
227 for (i
= 0; i
< sizeof(section_names
)/sizeof(section_names
[0]); i
++)
229 SetLastError( 0xdeadbeef );
230 hinf
= test_file_contents( section_names
[i
].data
, &err_line
);
231 ok( hinf
!= INVALID_HANDLE_VALUE
, "line %u: open failed err %u\n", i
, GetLastError() );
232 if (hinf
== INVALID_HANDLE_VALUE
) continue;
234 ret
= SetupGetLineCountA( hinf
, section_names
[i
].section
);
235 err
= GetLastError();
236 trace( "hinf=%p ret=%d err=0x%x\n", hinf
, ret
, err
);
239 ok( !section_names
[i
].error
, "line %u: section name %s found\n",
240 i
, section_names
[i
].section
);
241 ok( !err
, "line %u: bad error code %u\n", i
, err
);
245 ok( section_names
[i
].error
, "line %u: section name %s not found\n",
246 i
, section_names
[i
].section
);
247 ok( err
== section_names
[i
].error
, "line %u: bad error %u/%u\n",
248 i
, err
, section_names
[i
].error
);
250 SetupCloseInfFile( hinf
);
254 static void test_enum_sections(void)
256 static const char *contents
= STD_HEADER
"[s1]\nfoo=bar\n[s2]\nbar=foo\n[s3]\n[strings]\na=b\n";
264 if (!pSetupEnumInfSectionsA
)
266 win_skip( "SetupEnumInfSectionsA not available\n" );
270 hinf
= test_file_contents( contents
, &err
);
271 ok( hinf
!= NULL
, "Expected valid INF file\n" );
273 for (index
= 0; ; index
++)
275 SetLastError( 0xdeadbeef );
276 ret
= pSetupEnumInfSectionsA( hinf
, index
, NULL
, 0, &len
);
277 err
= GetLastError();
278 if (!ret
&& GetLastError() == ERROR_NO_MORE_ITEMS
) break;
279 ok( ret
, "SetupEnumInfSectionsA failed\n" );
280 ok( len
== 3 || len
== 8, "wrong len %u\n", len
);
282 SetLastError( 0xdeadbeef );
283 ret
= pSetupEnumInfSectionsA( hinf
, index
, NULL
, sizeof(buffer
), &len
);
284 err
= GetLastError();
285 ok( !ret
, "SetupEnumInfSectionsA succeeded\n" );
286 ok( err
== ERROR_INVALID_USER_BUFFER
, "wrong error %u\n", err
);
287 ok( len
== 3 || len
== 8, "wrong len %u\n", len
);
289 SetLastError( 0xdeadbeef );
290 ret
= pSetupEnumInfSectionsA( hinf
, index
, buffer
, sizeof(buffer
), &len
);
291 ok( ret
, "SetupEnumInfSectionsA failed err %u\n", GetLastError() );
292 ok( len
== 3 || len
== 8, "wrong len %u\n", len
);
293 ok( !lstrcmpiA( buffer
, "version" ) || !lstrcmpiA( buffer
, "s1" ) ||
294 !lstrcmpiA( buffer
, "s2" ) || !lstrcmpiA( buffer
, "s3" ) || !lstrcmpiA( buffer
, "strings" ),
295 "bad section '%s'\n", buffer
);
297 SetupCloseInfFile( hinf
);
301 /* Test various key and value names */
307 const char *fields
[10];
310 /* file contents expected key expected fields */
311 { "ab=cd", "ab", { "cd" } },
312 { "ab=cd,ef,gh,ij", "ab", { "cd", "ef", "gh", "ij" } },
313 { "ab", "ab", { "ab" } },
314 { "ab,cd", NULL
, { "ab", "cd" } },
315 { "ab,cd=ef", NULL
, { "ab", "cd=ef" } },
316 { "=abcd,ef", "", { "abcd", "ef" } },
318 { "ba\\\ncd=ef", "bacd", { "ef" } },
319 { "ab \\ \ncd=ef", "abcd", { "ef" } },
320 { "ab\\\ncd,ef", NULL
, { "abcd", "ef" } },
321 { "ab \\ ;cc\ncd=ef", "abcd", { "ef" } },
322 { "ab \\ \\ \ncd=ef", "abcd", { "ef" } },
323 { "ba \\ dc=xx", "ba \\ dc", { "xx" } },
324 { "ba \\\\ \nc=d", "bac", { "d" } },
325 { "a=b\\\\c", "a", { "b\\\\c" } },
326 { "ab=cd \\ ", "ab", { "cd" } },
327 { "ba=c \\ \n \\ \n a", "ba", { "ca" } },
328 { "ba=c \\ \n \\ a", "ba", { "c\\ a" } },
329 { " \\ a= \\ b", "\\ a", { "\\ b" } },
331 { "Ab\"Cd\"=Ef", "AbCd", { "Ef" } },
332 { "Ab\"Cd=Ef\"", "AbCd=Ef", { "AbCd=Ef" } },
333 { "ab\"\"\"cd,ef=gh\"", "ab\"cd,ef=gh", { "ab\"cd,ef=gh" } },
334 { "ab\"\"cd=ef", "abcd", { "ef" } },
335 { "ab\"\"cd=ef,gh", "abcd", { "ef", "gh" } },
336 { "ab=cd\"\"ef", "ab", { "cdef" } },
337 { "ab=cd\",\"ef", "ab", { "cd,ef" } },
338 { "ab=cd\",ef", "ab", { "cd,ef" } },
339 { "ab=cd\",ef\\\nab", "ab", { "cd,ef\\" } },
341 /* single quotes (unhandled)*/
342 { "HKLM,A,B,'C',D", NULL
, { "HKLM", "A","B","'C'","D" } },
344 { " a b = c , d \n", "a b", { "c", "d" } },
345 { " a b = c ,\" d\" \n", "a b", { "c", " d" } },
346 { " a b\r = c\r\n", "a b", { "c" } },
348 { "a=b,,,c,,,d", "a", { "b", "", "", "c", "", "", "d" } },
349 { "a=b,\"\",c,\" \",d", "a", { "b", "", "c", " ", "d" } },
350 { "=,,b", "", { "", "", "b" } },
351 { ",=,,b", NULL
, { "", "=", "", "b" } },
352 { "a=\n", "a", { "" } },
355 { "ab=c\032d", "ab", { "c" } },
356 { "ab\032=cd", "ab", { "ab" } },
358 { "abcd=ef\x0gh", "abcd", { "ef" } },
359 /* multiple sections with same name */
360 { "[Test2]\nab\n[Test]\nee=ff\n", "ee", { "ff" } },
361 /* string substitution */
362 { "%foo%=%bar%\n" STR_SECTION
, "aaa", { "bbb" } },
363 { "%foo%xx=%bar%yy\n" STR_SECTION
, "aaaxx", { "bbbyy" } },
364 { "%% %foo%=%bar%\n" STR_SECTION
, "% aaa", { "bbb" } },
365 { "%f\"o\"o%=ccc\n" STR_SECTION
, "aaa", { "ccc" } },
366 { "abc=%bar;bla%\n" STR_SECTION
, "abc", { "%bar" } },
367 { "loop=%loop%\n" STR_SECTION
, "loop", { "%loop2%" } },
368 { "%per%%cent%=100\n" STR_SECTION
, "12", { "100" } },
369 { "a=%big%\n" STR_SECTION
, "a", { A400
} },
370 { "a=%verybig%\n" STR_SECTION
, "a", { A511
} }, /* truncated to 511, not on Vista/W2K8 */
371 { "a=%big%%big%%big%%big%\n" STR_SECTION
, "a", { A400 A400 A400 A400
} },
372 { "a=%big%%big%%big%%big%%big%%big%%big%%big%%big%\n" STR_SECTION
, "a", { A400 A400 A400 A400 A400 A400 A400 A400 A400
} },
373 { "a=%big%%big%%big%%big%%big%%big%%big%%big%%big%%big%%big%\n" STR_SECTION
, "a", { A4097
/*MAX_INF_STRING_LENGTH+1*/ } },
375 /* Prove expansion of system entries removes extra \'s and string
376 replacements doesn't */
377 { "ab=\"%24%\"\n" STR_SECTION
, "ab", { "C:\\" } },
378 { "ab=\"%mydrive%\"\n" STR_SECTION
, "ab", { "C:\\" } },
379 { "ab=\"%24%\\fred\"\n" STR_SECTION
, "ab", { "C:\\fred" } },
380 { "ab=\"%mydrive%\\fred\"\n" STR_SECTION
,"ab", { "C:\\\\fred" } },
381 /* Confirm duplicate \'s kept */
382 { "ab=\"%24%\\\\fred\"", "ab", { "C:\\\\fred" } },
383 { "ab=C:\\\\FRED", "ab", { "C:\\\\FRED" } },
386 /* check the key of a certain line */
387 static const char *check_key( INFCONTEXT
*context
, const char *wanted
)
389 const char *key
= get_string_field( context
, 0 );
390 DWORD err
= GetLastError();
394 ok( !wanted
, "missing key %s\n", wanted
);
395 ok( err
== 0 || err
== ERROR_INVALID_PARAMETER
, "last error set to %u\n", err
);
399 ok( !strcmp( key
, wanted
), "bad key %s/%s\n", key
, wanted
);
400 ok( err
== 0, "last error set to %u\n", err
);
405 static void test_key_names(void)
407 char buffer
[MAX_INF_STRING_LENGTH
+32];
409 unsigned int i
, index
, count
;
416 for (i
= 0; i
< sizeof(key_names
)/sizeof(key_names
[0]); i
++)
418 strcpy( buffer
, STD_HEADER
"[Test]\n" );
419 strcat( buffer
, key_names
[i
].data
);
420 SetLastError( 0xdeadbeef );
421 hinf
= test_file_contents( buffer
, &err_line
);
422 ok( hinf
!= INVALID_HANDLE_VALUE
, "line %u: open failed err %u\n", i
, GetLastError() );
423 if (hinf
== INVALID_HANDLE_VALUE
) continue;
425 ret
= SetupFindFirstLineA( hinf
, "Test", 0, &context
);
426 ok(ret
, "SetupFindFirstLineA failed: le=%u\n", GetLastError());
429 SetupCloseInfFile( hinf
);
433 check_key( &context
, key_names
[i
].key
);
435 buffer
[0] = buffer
[1] = 0; /* build the full line */
436 for (index
= 0; ; index
++)
438 const char *field
= get_string_field( &context
, index
+ 1 );
439 err
= GetLastError();
442 ok( err
== 0, "line %u: bad error %u\n", i
, err
);
443 if (key_names
[i
].fields
[index
])
446 ok( !strcmp( field
, key_names
[i
].fields
[index
] ) ||
447 !strcmp( field
, A1200
), /* Vista, W2K8 */
448 "line %u: bad field %s/%s\n",
449 i
, field
, key_names
[i
].fields
[index
] );
450 else /* don't compare drive letter of paths */
451 if (field
[0] && field
[1] == ':' && field
[2] == '\\')
452 ok( !strcmp( field
+ 1, key_names
[i
].fields
[index
] + 1 ),
453 "line %u: bad field %s/%s\n",
454 i
, field
, key_names
[i
].fields
[index
] );
456 ok( !strcmp( field
, key_names
[i
].fields
[index
] ), "line %u: bad field %s/%s\n",
457 i
, field
, key_names
[i
].fields
[index
] );
460 ok( 0, "line %u: got extra field %s\n", i
, field
);
461 strcat( buffer
, "," );
462 strcat( buffer
, field
);
466 ok( err
== 0 || err
== ERROR_INVALID_PARAMETER
,
467 "line %u: bad error %u\n", i
, err
);
468 if (key_names
[i
].fields
[index
])
469 ok( 0, "line %u: missing field %s\n", i
, key_names
[i
].fields
[index
] );
471 if (!key_names
[i
].fields
[index
]) break;
473 count
= SetupGetFieldCount( &context
);
474 ok( count
== index
, "line %u: bad count %d/%d\n", i
, index
, count
);
476 line
= get_line_text( &context
);
477 ok( line
!= NULL
, "line %u: SetupGetLineText failed\n", i
);
478 if (line
) ok( !strcmp( line
, buffer
+1 ), "line %u: bad text %s/%s\n", i
, line
, buffer
+1 );
480 SetupCloseInfFile( hinf
);
485 static void test_close_inf_file(void)
487 SetLastError(0xdeadbeef);
488 SetupCloseInfFile(NULL
);
489 ok(GetLastError() == 0xdeadbeef ||
490 GetLastError() == ERROR_INVALID_PARAMETER
, /* Win9x, WinMe */
491 "Expected 0xdeadbeef, got %u\n", GetLastError());
493 SetLastError(0xdeadbeef);
494 SetupCloseInfFile(INVALID_HANDLE_VALUE
);
495 ok(GetLastError() == 0xdeadbeef ||
496 GetLastError() == ERROR_INVALID_PARAMETER
, /* Win9x, WinMe */
497 "Expected 0xdeadbeef, got %u\n", GetLastError());
500 static const char *contents
= "[Version]\n"
501 "Signature=\"$Windows NT$\"\n"
502 "FileVersion=5.1.1.2\n"
504 "RTMQFE=\"%RTMGFE_NAME%\",SP1RTM,"A4097
"\n"
506 "RTMQFE_NAME = \"RTMQFE\"\n";
508 static const CHAR getfield_resA
[][20] =
515 static const WCHAR getfield_resW
[][20] =
517 {'R','T','M','Q','F','E',0},
518 {'%','R','T','M','G','F','E','_','N','A','M','E','%',0},
519 {'S','P','1','R','T','M',0},
522 static void test_pSetupGetField(void)
534 SetLastError(0xdeadbeef);
535 lstrcmpW(NULL
, NULL
);
536 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
538 win_skip("Using A-functions instead of W\n");
542 hinf
= test_file_contents( contents
, &err
);
543 ok( hinf
!= NULL
, "Expected valid INF file\n" );
545 ret
= SetupFindFirstLineA( hinf
, "FileBranchInfo", NULL
, &context
);
546 ok( ret
, "Failed to find first line\n" );
548 /* native Windows crashes if a NULL context is sent in */
550 for ( i
= 0; i
< 3; i
++ )
554 fieldW
= pSetupGetFieldW( &context
, i
);
555 ok( fieldW
!= NULL
, "Failed to get field %i\n", i
);
556 ok( !lstrcmpW( getfield_resW
[i
], fieldW
), "Wrong string returned\n" );
560 fieldA
= pSetupGetFieldA( &context
, i
);
561 ok( fieldA
!= NULL
, "Failed to get field %i\n", i
);
562 ok( !lstrcmpA( getfield_resA
[i
], fieldA
), "Wrong string returned\n" );
568 fieldW
= pSetupGetFieldW( &context
, 3 );
569 ok( fieldW
!= NULL
, "Failed to get field 3\n" );
570 len
= lstrlenW( fieldW
);
571 ok( len
== 511 || /* NT4, W2K, XP and W2K3 */
572 len
== 4096, /* Vista */
573 "Unexpected length, got %d\n", len
);
575 fieldW
= pSetupGetFieldW( &context
, 4 );
576 ok( fieldW
== NULL
, "Expected NULL, got %p\n", fieldW
);
577 ok( GetLastError() == ERROR_INVALID_PARAMETER
,
578 "Expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError() );
582 fieldA
= pSetupGetFieldA( &context
, 3 );
583 ok( fieldA
!= NULL
, "Failed to get field 3\n" );
584 len
= lstrlenA( fieldA
);
585 ok( len
== 511, /* Win9x, WinME */
586 "Unexpected length, got %d\n", len
);
588 fieldA
= pSetupGetFieldA( &context
, 4 );
589 ok( fieldA
== NULL
, "Expected NULL, got %p\n", fieldA
);
590 ok( GetLastError() == ERROR_INVALID_PARAMETER
,
591 "Expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError() );
594 SetupCloseInfFile( hinf
);
597 static void test_SetupGetIntField(void)
608 /* key fields index expected int errorcode */
609 { "Key", "48", 1, 48, ERROR_SUCCESS
},
610 { "Key", "48", 0, -1, ERROR_INVALID_DATA
},
611 { "123", "48", 0, 123, ERROR_SUCCESS
},
612 { "Key", "0x4", 1, 4, ERROR_SUCCESS
},
613 { "Key", "Field1", 1, -1, ERROR_INVALID_DATA
},
614 { "Key", "Field1,34", 2, 34, ERROR_SUCCESS
},
615 { "Key", "Field1,,Field3", 2, 0, ERROR_SUCCESS
},
616 { "Key", "Field1,", 2, 0, ERROR_SUCCESS
}
620 for (i
= 0; i
< sizeof(keys
)/sizeof(keys
[0]); i
++)
623 char buffer
[MAX_INF_STRING_LENGTH
];
629 strcpy( buffer
, STD_HEADER
"[TestSection]\n" );
630 strcat( buffer
, keys
[i
].key
);
631 strcat( buffer
, "=" );
632 strcat( buffer
, keys
[i
].fields
);
633 hinf
= test_file_contents( buffer
, &err
);
634 ok( hinf
!= NULL
, "Expected valid INF file\n" );
636 SetupFindFirstLineA( hinf
, "TestSection", keys
[i
].key
, &context
);
637 SetLastError( 0xdeadbeef );
639 retb
= SetupGetIntField( &context
, keys
[i
].index
, &intfield
);
640 if ( keys
[i
].err
== ERROR_SUCCESS
)
642 ok( retb
, "%u: Expected success\n", i
);
643 ok( GetLastError() == ERROR_SUCCESS
||
644 GetLastError() == 0xdeadbeef /* win9x, NT4 */,
645 "%u: Expected ERROR_SUCCESS or 0xdeadbeef, got %u\n", i
, GetLastError() );
649 ok( !retb
, "%u: Expected failure\n", i
);
650 ok( GetLastError() == keys
[i
].err
,
651 "%u: Expected %d, got %u\n", i
, keys
[i
].err
, GetLastError() );
653 ok( intfield
== keys
[i
].value
, "%u: Expected %d, got %d\n", i
, keys
[i
].value
, intfield
);
655 SetupCloseInfFile( hinf
);
659 static void test_GLE(void)
661 static const char *inf
=
663 "Signature=\"$Windows NT$\"\n"
665 "Keyname1=Field1,Field2,Field3\n"
667 "Keyname2=Field4,Field5\n";
673 char buf
[MAX_INF_STRING_LENGTH
];
674 int bufsize
= MAX_INF_STRING_LENGTH
;
677 hinf
= test_file_contents( inf
, &err
);
678 ok( hinf
!= NULL
, "Expected valid INF file\n" );
680 SetLastError(0xdeadbeef);
681 retb
= SetupFindFirstLineA( hinf
, "ImNotThere", NULL
, &context
);
682 ok(!retb
, "Expected failure\n");
683 ok(GetLastError() == ERROR_LINE_NOT_FOUND
,
684 "Expected ERROR_LINE_NOT_FOUND, got %08x\n", GetLastError());
686 SetLastError(0xdeadbeef);
687 retb
= SetupFindFirstLineA( hinf
, "ImNotThere", "ImNotThere", &context
);
688 ok(!retb
, "Expected failure\n");
689 ok(GetLastError() == ERROR_LINE_NOT_FOUND
,
690 "Expected ERROR_LINE_NOT_FOUND, got %08x\n", GetLastError());
692 SetLastError(0xdeadbeef);
693 retb
= SetupFindFirstLineA( hinf
, "Sectionname", NULL
, &context
);
694 ok(retb
, "Expected success\n");
695 ok(GetLastError() == ERROR_SUCCESS
,
696 "Expected ERROR_SUCCESS, got %08x\n", GetLastError());
698 SetLastError(0xdeadbeef);
699 retb
= SetupFindFirstLineA( hinf
, "Sectionname", "ImNotThere", &context
);
700 ok(!retb
, "Expected failure\n");
701 ok(GetLastError() == ERROR_LINE_NOT_FOUND
,
702 "Expected ERROR_LINE_NOT_FOUND, got %08x\n", GetLastError());
704 SetLastError(0xdeadbeef);
705 retb
= SetupFindFirstLineA( hinf
, "Sectionname", "Keyname1", &context
);
706 ok(retb
, "Expected success\n");
707 ok(GetLastError() == ERROR_SUCCESS
,
708 "Expected ERROR_SUCCESS, got %08x\n", GetLastError());
710 SetLastError(0xdeadbeef);
711 retb
= SetupFindNextMatchLineA( &context
, "ImNotThere", &context
);
712 ok(!retb
, "Expected failure\n");
713 ok(GetLastError() == ERROR_LINE_NOT_FOUND
,
714 "Expected ERROR_LINE_NOT_FOUND, got %08x\n", GetLastError());
716 SetLastError(0xdeadbeef);
717 retb
= SetupFindNextMatchLineA( &context
, "Keyname2", &context
);
718 ok(retb
, "Expected success\n");
719 ok(GetLastError() == ERROR_SUCCESS
,
720 "Expected ERROR_SUCCESS, got %08x\n", GetLastError());
722 SetLastError(0xdeadbeef);
723 retl
= SetupGetLineCountA( hinf
, "ImNotThere");
724 ok(retl
== -1, "Expected -1, got %d\n", retl
);
725 ok(GetLastError() == ERROR_SECTION_NOT_FOUND
,
726 "Expected ERROR_SECTION_NOT_FOUND, got %08x\n", GetLastError());
728 SetLastError(0xdeadbeef);
729 retl
= SetupGetLineCountA( hinf
, "Sectionname");
730 ok(retl
== 2, "Expected 2, got %d\n", retl
);
731 ok(GetLastError() == ERROR_SUCCESS
,
732 "Expected ERROR_SUCCESS, got %08x\n", GetLastError());
734 SetLastError(0xdeadbeef);
735 retb
= SetupGetLineTextA( NULL
, hinf
, "ImNotThere", "ImNotThere", buf
, bufsize
, &retsize
);
736 ok(!retb
, "Expected failure\n");
737 ok(GetLastError() == ERROR_LINE_NOT_FOUND
,
738 "Expected ERROR_LINE_NOT_FOUND, got %08x\n", GetLastError());
740 SetLastError(0xdeadbeef);
741 retb
= SetupGetLineTextA( NULL
, hinf
, "Sectionname", "ImNotThere", buf
, bufsize
, &retsize
);
742 ok(!retb
, "Expected failure\n");
743 ok(GetLastError() == ERROR_LINE_NOT_FOUND
,
744 "Expected ERROR_LINE_NOT_FOUND, got %08x\n", GetLastError());
746 SetLastError(0xdeadbeef);
747 retb
= SetupGetLineTextA( NULL
, hinf
, "Sectionname", "Keyname1", buf
, bufsize
, &retsize
);
748 ok(retb
, "Expected success\n");
749 ok(GetLastError() == ERROR_SUCCESS
,
750 "Expected ERROR_SUCCESS, got %08x\n", GetLastError());
752 SetLastError(0xdeadbeef);
753 retb
= SetupGetLineByIndexA( hinf
, "ImNotThere", 1, &context
);
754 ok(!retb
, "Expected failure\n");
755 ok(GetLastError() == ERROR_LINE_NOT_FOUND
,
756 "Expected ERROR_LINE_NOT_FOUND, got %08x\n", GetLastError());
758 SetLastError(0xdeadbeef);
759 retb
= SetupGetLineByIndexA( hinf
, "Sectionname", 1, &context
);
760 ok(retb
, "Expected success\n");
761 ok(GetLastError() == ERROR_SUCCESS
,
762 "Expected ERROR_SUCCESS, got %08x\n", GetLastError());
764 SetLastError(0xdeadbeef);
765 retb
= SetupGetLineByIndexA( hinf
, "Sectionname", 3, &context
);
766 ok(!retb
, "Expected failure\n");
767 ok(GetLastError() == ERROR_LINE_NOT_FOUND
,
768 "Expected ERROR_LINE_NOT_FOUND, got %08x\n", GetLastError());
770 SetupCloseInfFile( hinf
);
775 init_function_pointers();
776 test_invalid_files();
777 test_section_names();
778 test_enum_sections();
780 test_close_inf_file();
781 test_pSetupGetField();
782 test_SetupGetIntField();
784 DeleteFileA( tmpfilename
);