msvcp90: Add codecvt<wchar_t>::do_encoding that returns 0.
[wine.git] / dlls / advpack / tests / advpack.c
blobf7ac66b90d91c41d8af3d37c0a561f50aaa5dd5a
1 /*
2 * Unit tests for advpack.dll
4 * Copyright (C) 2005 Robert Reif
5 * Copyright (C) 2005 Sami Aario
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <stdio.h>
23 #include <stdarg.h>
24 #include <windows.h>
25 #include <advpub.h>
26 #include <assert.h>
27 #include "wine/test.h"
29 /* defines for the TranslateInfString/Ex tests */
30 #define TEST_STRING1 "\\Application Name"
31 #define TEST_STRING2 "%49001%\\Application Name"
33 /* defines for the SetPerUserSecValues tests */
34 #define GUID_KEY "SOFTWARE\\Microsoft\\Active Setup\\Installed Components\\guid"
35 #define REG_VAL_EXISTS(key, value) !RegQueryValueExA(key, value, NULL, NULL, NULL, NULL)
36 #define OPEN_GUID_KEY() !RegOpenKeyA(HKEY_LOCAL_MACHINE, GUID_KEY, &guid)
38 static HMODULE hAdvPack;
39 static HRESULT (WINAPI *pCloseINFEngine)(HINF);
40 static HRESULT (WINAPI *pDelNode)(LPCSTR,DWORD);
41 static HRESULT (WINAPI *pGetVersionFromFile)(LPCSTR,LPDWORD,LPDWORD,BOOL);
42 static HRESULT (WINAPI *pOpenINFEngine)(PCSTR,PCSTR,DWORD,HINF*,PVOID);
43 static HRESULT (WINAPI *pSetPerUserSecValues)(PPERUSERSECTIONA pPerUser);
44 static HRESULT (WINAPI *pTranslateInfString)(LPCSTR,LPCSTR,LPCSTR,LPCSTR,LPSTR,DWORD,LPDWORD,LPVOID);
45 static HRESULT (WINAPI *pTranslateInfStringEx)(HINF,PCSTR,PCSTR,PCSTR,PSTR,DWORD,PDWORD,PVOID);
47 static CHAR inf_file[MAX_PATH];
48 static CHAR PROG_FILES_ROOT[MAX_PATH];
49 static CHAR PROG_FILES[MAX_PATH];
50 static CHAR APP_PATH[MAX_PATH];
51 static DWORD APP_PATH_LEN;
53 static void get_progfiles_dir(void)
55 HKEY hkey;
56 DWORD size = MAX_PATH;
58 RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion", &hkey);
59 RegQueryValueExA(hkey, "ProgramFilesDir", NULL, NULL, (LPBYTE)PROG_FILES_ROOT, &size);
60 RegCloseKey(hkey);
62 lstrcpyA(PROG_FILES, PROG_FILES_ROOT + 3); /* skip C:\ */
63 lstrcpyA(APP_PATH, PROG_FILES_ROOT);
64 lstrcatA(APP_PATH, TEST_STRING1);
65 APP_PATH_LEN = lstrlenA(APP_PATH) + 1;
68 static BOOL init_function_pointers(void)
70 hAdvPack = LoadLibraryA("advpack.dll");
72 if (!hAdvPack)
73 return FALSE;
75 pCloseINFEngine = (void*)GetProcAddress(hAdvPack, "CloseINFEngine");
76 pDelNode = (void *)GetProcAddress(hAdvPack, "DelNode");
77 pGetVersionFromFile = (void *)GetProcAddress(hAdvPack, "GetVersionFromFile");
78 pOpenINFEngine = (void*)GetProcAddress(hAdvPack, "OpenINFEngine");
79 pSetPerUserSecValues = (void*)GetProcAddress(hAdvPack, "SetPerUserSecValues");
80 pTranslateInfString = (void *)GetProcAddress(hAdvPack, "TranslateInfString");
81 pTranslateInfStringEx = (void*)GetProcAddress(hAdvPack, "TranslateInfStringEx");
83 if (!pCloseINFEngine || !pDelNode || !pGetVersionFromFile ||
84 !pOpenINFEngine || !pSetPerUserSecValues || !pTranslateInfString)
86 win_skip("Needed functions are not available\n");
87 FreeLibrary(hAdvPack);
88 return FALSE;
91 return TRUE;
94 static void version_test(void)
96 HRESULT hr;
97 DWORD major, minor;
99 major = minor = 0;
100 hr = pGetVersionFromFile("kernel32.dll", &major, &minor, FALSE);
101 ok (hr == S_OK, "GetVersionFromFileEx(kernel32.dll) failed, returned "
102 "0x%08x\n", hr);
103 trace("kernel32.dll Language ID: 0x%08x, Codepage ID: 0x%08x\n",
104 major, minor);
106 major = minor = 0;
107 hr = pGetVersionFromFile("kernel32.dll", &major, &minor, TRUE);
108 ok (hr == S_OK, "GetVersionFromFileEx(kernel32.dll) failed, returned "
109 "0x%08x\n", hr);
110 trace("kernel32.dll version: %d.%d.%d.%d\n", HIWORD(major), LOWORD(major),
111 HIWORD(minor), LOWORD(minor));
113 major = minor = 0;
114 hr = pGetVersionFromFile("advpack.dll", &major, &minor, FALSE);
115 ok (hr == S_OK, "GetVersionFromFileEx(advpack.dll) failed, returned "
116 "0x%08x\n", hr);
117 trace("advpack.dll Language ID: 0x%08x, Codepage ID: 0x%08x\n",
118 major, minor);
120 major = minor = 0;
121 hr = pGetVersionFromFile("advpack.dll", &major, &minor, TRUE);
122 ok (hr == S_OK, "GetVersionFromFileEx(advpack.dll) failed, returned "
123 "0x%08x\n", hr);
124 trace("advpack.dll version: %d.%d.%d.%d\n", HIWORD(major), LOWORD(major),
125 HIWORD(minor), LOWORD(minor));
128 static void delnode_test(void)
130 HRESULT hr;
131 HANDLE hn;
132 CHAR currDir[MAX_PATH];
133 UINT currDirLen;
135 /* Native DelNode apparently does not support relative paths, so we use
136 absolute paths for testing */
137 currDirLen = GetCurrentDirectoryA(sizeof(currDir) / sizeof(CHAR), currDir);
138 assert(currDirLen > 0 && currDirLen < sizeof(currDir) / sizeof(CHAR));
140 if(currDir[currDirLen - 1] == '\\')
141 currDir[--currDirLen] = 0;
143 /* Simple tests; these should fail. */
144 hr = pDelNode(NULL, 0);
145 ok (hr == E_FAIL, "DelNode called with NULL pathname should return E_FAIL\n");
146 hr = pDelNode("", 0);
147 ok (hr == E_FAIL, "DelNode called with empty pathname should return E_FAIL\n");
149 /* Test deletion of a file. */
150 hn = CreateFileA("DelNodeTestFile1", GENERIC_WRITE, 0, NULL,
151 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
152 assert(hn != INVALID_HANDLE_VALUE);
153 CloseHandle(hn);
154 hr = pDelNode(lstrcatA(currDir, "\\DelNodeTestFile1"), 0);
155 ok (hr == S_OK, "DelNode failed deleting a single file\n");
156 currDir[currDirLen] = '\0';
158 /* Test deletion of an empty directory. */
159 CreateDirectoryA("DelNodeTestDir", NULL);
160 hr = pDelNode(lstrcatA(currDir, "\\DelNodeTestDir"), 0);
161 ok (hr == S_OK, "DelNode failed deleting an empty directory\n");
162 currDir[currDirLen] = '\0';
164 /* Test deletion of a directory containing one file. */
165 CreateDirectoryA("DelNodeTestDir", NULL);
166 hn = CreateFileA("DelNodeTestDir\\DelNodeTestFile1", GENERIC_WRITE, 0, NULL,
167 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
168 assert(hn != INVALID_HANDLE_VALUE);
169 CloseHandle(hn);
170 hr = pDelNode(lstrcatA(currDir, "\\DelNodeTestDir"), 0);
171 ok (hr == S_OK, "DelNode failed deleting a directory containing one file\n");
172 currDir[currDirLen] = '\0';
174 /* Test deletion of a directory containing multiple files. */
175 CreateDirectoryA("DelNodeTestDir", NULL);
176 hn = CreateFileA("DelNodeTestDir\\DelNodeTestFile1", GENERIC_WRITE, 0, NULL,
177 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
178 assert(hn != INVALID_HANDLE_VALUE);
179 CloseHandle(hn);
180 hn = CreateFileA("DelNodeTestDir\\DelNodeTestFile2", GENERIC_WRITE, 0, NULL,
181 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
182 assert(hn != INVALID_HANDLE_VALUE);
183 CloseHandle(hn);
184 hn = CreateFileA("DelNodeTestDir\\DelNodeTestFile3", GENERIC_WRITE, 0, NULL,
185 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
186 assert(hn != INVALID_HANDLE_VALUE);
187 CloseHandle(hn);
188 hr = pDelNode(lstrcatA(currDir, "\\DelNodeTestDir"), 0);
189 ok (hr == S_OK, "DelNode failed deleting a directory containing multiple files\n");
192 static void append_str(char **str, const char *data, ...)
194 va_list valist;
196 va_start(valist, data);
197 vsprintf(*str, data, valist);
198 *str += strlen(*str);
199 va_end(valist);
202 static void create_inf_file(void)
204 char data[1024];
205 char *ptr = data;
206 DWORD dwNumberOfBytesWritten;
207 HANDLE hf = CreateFileA(inf_file, GENERIC_WRITE, 0, NULL,
208 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
210 append_str(&ptr, "[Version]\n");
211 append_str(&ptr, "Signature=\"$Chicago$\"\n");
212 append_str(&ptr, "[CustInstDestSection]\n");
213 append_str(&ptr, "49001=ProgramFilesDir\n");
214 append_str(&ptr, "49010=DestA,1\n");
215 append_str(&ptr, "49020=DestB\n");
216 append_str(&ptr, "49030=DestC\n");
217 append_str(&ptr, "[ProgramFilesDir]\n");
218 append_str(&ptr, "HKLM,\"Software\\Microsoft\\Windows\\CurrentVersion\",");
219 append_str(&ptr, "\"ProgramFilesDir\",,\"%%24%%\\%%LProgramF%%\"\n");
220 append_str(&ptr, "[section]\n");
221 append_str(&ptr, "NotACustomDestination=Version\n");
222 append_str(&ptr, "CustomDestination=CustInstDestSection\n");
223 append_str(&ptr, "[Options.NTx86]\n");
224 append_str(&ptr, "49001=ProgramFilesDir\n");
225 append_str(&ptr, "InstallDir=%%49001%%\\%%DefaultAppPath%%\n");
226 append_str(&ptr, "Result1=%%49010%%\n");
227 append_str(&ptr, "Result2=%%49020%%\n");
228 append_str(&ptr, "Result3=%%49030%%\n");
229 append_str(&ptr, "CustomHDestination=CustInstDestSection\n");
230 append_str(&ptr, "[Strings]\n");
231 append_str(&ptr, "DefaultAppPath=\"Application Name\"\n");
232 append_str(&ptr, "LProgramF=\"%s\"\n", PROG_FILES);
233 append_str(&ptr, "[DestA]\n");
234 append_str(&ptr, "HKLM,\"Software\\Garbage\",\"ProgramFilesDir\",,'%%24%%\\%%LProgramF%%'\n");
235 append_str(&ptr, "[DestB]\n");
236 append_str(&ptr, "'HKLM','Software\\Microsoft\\Windows\\CurrentVersion',");
237 append_str(&ptr, "'ProgramFilesDir',,\"%%24%%\"\n");
238 append_str(&ptr, "[DestC]\n");
239 append_str(&ptr, "HKLM,\"Software\\Garbage\",\"ProgramFilesDir\",,'%%24%%'\n");
241 WriteFile(hf, data, ptr - data, &dwNumberOfBytesWritten, NULL);
242 CloseHandle(hf);
245 static void translateinfstring_test(void)
247 HRESULT hr;
248 char buffer[MAX_PATH];
249 DWORD dwSize;
251 create_inf_file();
253 /* pass in a couple invalid parameters */
254 hr = pTranslateInfString(NULL, NULL, NULL, NULL, buffer, MAX_PATH, &dwSize, NULL);
255 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got 0x%08x\n", (UINT)hr);
257 /* try to open an inf file that doesn't exist */
258 hr = pTranslateInfString("c:\\a.inf", "Options.NTx86", "Options.NTx86",
259 "InstallDir", buffer, MAX_PATH, &dwSize, NULL);
260 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) || hr == E_INVALIDARG ||
261 hr == HRESULT_FROM_WIN32(ERROR_MOD_NOT_FOUND),
262 "Expected E_INVALIDARG, 0x80070002 or 0x8007007e, got 0x%08x\n", (UINT)hr);
264 if(hr == HRESULT_FROM_WIN32(ERROR_MOD_NOT_FOUND))
266 win_skip("WinNT 3.51 detected. Skipping tests for TranslateInfString()\n");
267 return;
270 /* try a nonexistent section */
271 buffer[0] = 0;
272 hr = pTranslateInfString(inf_file, "idontexist", "Options.NTx86",
273 "InstallDir", buffer, MAX_PATH, &dwSize, NULL);
274 if (hr == E_ACCESSDENIED)
276 skip("TranslateInfString is broken\n");
277 return;
279 ok(hr == S_OK, "Expected S_OK, got 0x%08x\n", (UINT)hr);
280 ok(!strcmp(buffer, TEST_STRING2), "Expected %s, got %s\n", TEST_STRING2, buffer);
281 ok(dwSize == 25, "Expected size 25, got %d\n", dwSize);
283 buffer[0] = 0;
284 /* try other nonexistent section */
285 hr = pTranslateInfString(inf_file, "Options.NTx86", "idontexist",
286 "InstallDir", buffer, MAX_PATH, &dwSize, NULL);
287 ok(hr == SPAPI_E_LINE_NOT_FOUND || hr == E_INVALIDARG,
288 "Expected SPAPI_E_LINE_NOT_FOUND or E_INVALIDARG, got 0x%08x\n", (UINT)hr);
290 buffer[0] = 0;
291 /* try nonexistent key */
292 hr = pTranslateInfString(inf_file, "Options.NTx86", "Options.NTx86",
293 "notvalid", buffer, MAX_PATH, &dwSize, NULL);
294 ok(hr == SPAPI_E_LINE_NOT_FOUND || hr == E_INVALIDARG,
295 "Expected SPAPI_E_LINE_NOT_FOUND or E_INVALIDARG, got 0x%08x\n", (UINT)hr);
297 buffer[0] = 0;
298 /* test the behavior of pszInstallSection */
299 hr = pTranslateInfString(inf_file, "section", "Options.NTx86",
300 "InstallDir", buffer, MAX_PATH, &dwSize, NULL);
301 ok(hr == ERROR_SUCCESS || hr == E_FAIL,
302 "Expected ERROR_SUCCESS or E_FAIL, got 0x%08x\n", (UINT)hr);
304 if(hr == ERROR_SUCCESS)
306 ok(!strcmp(buffer, APP_PATH), "Expected '%s', got '%s'\n", APP_PATH, buffer);
307 ok(dwSize == APP_PATH_LEN, "Expected size %d, got %d\n", APP_PATH_LEN, dwSize);
310 buffer[0] = 0;
311 /* try without a pszInstallSection */
312 hr = pTranslateInfString(inf_file, NULL, "Options.NTx86",
313 "InstallDir", buffer, MAX_PATH, &dwSize, NULL);
314 ok(hr == S_OK, "Expected S_OK, got 0x%08x\n", (UINT)hr);
315 todo_wine
317 ok(!strcmp(buffer, TEST_STRING2), "Expected %s, got %s\n", TEST_STRING2, buffer);
318 ok(dwSize == 25, "Expected size 25, got %d\n", dwSize);
321 DeleteFileA("c:\\a.inf");
322 DeleteFileA(inf_file);
325 static void translateinfstringex_test(void)
327 HINF hinf;
328 HRESULT hr;
329 char buffer[MAX_PATH];
330 DWORD size = MAX_PATH;
332 hr = pOpenINFEngine(inf_file, NULL, 0, &hinf, NULL);
333 if (hr == E_UNEXPECTED)
335 win_skip("Skipping tests on win9x because of brokenness\n");
336 return;
339 create_inf_file();
341 /* need to see if there are any flags */
343 /* try a NULL filename */
344 hr = pOpenINFEngine(NULL, "Options.NTx86", 0, &hinf, NULL);
345 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
347 /* try an empty filename */
348 hr = pOpenINFEngine("", "Options.NTx86", 0, &hinf, NULL);
349 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) /* NT+ */ ||
350 hr == HRESULT_FROM_WIN32(E_UNEXPECTED) /* 9x */,
351 "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND or E_UNEXPECTED), got %08x\n", hr);
353 /* try a NULL hinf */
354 hr = pOpenINFEngine(inf_file, "Options.NTx86", 0, NULL, NULL);
355 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
357 /* open the INF without the Install section specified */
358 hr = pOpenINFEngine(inf_file, NULL, 0, &hinf, NULL);
359 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
361 /* try a NULL hinf */
362 hr = pTranslateInfStringEx(NULL, inf_file, "Options.NTx86", "InstallDir",
363 buffer, size, &size, NULL);
364 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
366 /* try a NULL filename */
367 hr = pTranslateInfStringEx(hinf, NULL, "Options.NTx86", "InstallDir",
368 buffer, size, &size, NULL);
369 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
371 /* try an empty filename */
372 memset(buffer, 'a', 25);
373 buffer[24] = '\0';
374 size = MAX_PATH;
375 hr = pTranslateInfStringEx(hinf, "", "Options.NTx86", "InstallDir",
376 buffer, size, &size, NULL);
377 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
378 todo_wine
380 ok(!strcmp(buffer, TEST_STRING2), "Expected %s, got %s\n", TEST_STRING2, buffer);
381 ok(size == 25, "Expected size 25, got %d\n", size);
384 /* try a NULL translate section */
385 hr = pTranslateInfStringEx(hinf, inf_file, NULL, "InstallDir",
386 buffer, size, &size, NULL);
387 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
389 /* try an empty translate section */
390 hr = pTranslateInfStringEx(hinf, inf_file, "", "InstallDir",
391 buffer, size, &size, NULL);
392 ok(hr == SPAPI_E_LINE_NOT_FOUND, "Expected SPAPI_E_LINE_NOT_FOUND, got %08x\n", hr);
394 /* try a NULL translate key */
395 hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", NULL,
396 buffer, size, &size, NULL);
397 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
399 /* try an empty translate key */
400 hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "",
401 buffer, size, &size, NULL);
402 ok(hr == SPAPI_E_LINE_NOT_FOUND, "Expected SPAPI_E_LINE_NOT_FOUND, got %08x\n", hr);
404 /* successfully translate the string */
405 memset(buffer, 'a', 25);
406 buffer[24] = '\0';
407 size = MAX_PATH;
408 hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "InstallDir",
409 buffer, size, &size, NULL);
410 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
411 todo_wine
413 ok(!strcmp(buffer, TEST_STRING2), "Expected %s, got %s\n", TEST_STRING2, buffer);
414 ok(size == 25, "Expected size 25, got %d\n", size);
417 /* try a NULL hinf */
418 hr = pCloseINFEngine(NULL);
419 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
421 /* successfully close the hinf */
422 hr = pCloseINFEngine(hinf);
423 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
425 /* open the inf with the install section */
426 hr = pOpenINFEngine(inf_file, "section", 0, &hinf, NULL);
427 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
429 /* translate the string with the install section specified */
430 memset(buffer, 'a', APP_PATH_LEN);
431 buffer[APP_PATH_LEN - 1] = '\0';
432 size = MAX_PATH;
433 hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "InstallDir",
434 buffer, size, &size, NULL);
435 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
436 ok(!strcmp(buffer, APP_PATH), "Expected %s, got %s\n", APP_PATH, buffer);
437 ok(size == APP_PATH_LEN, "Expected size %d, got %d\n", APP_PATH_LEN, size);
439 /* Single quote test (Note size includes null on return from call) */
440 memset(buffer, 'a', APP_PATH_LEN);
441 buffer[APP_PATH_LEN - 1] = '\0';
442 size = MAX_PATH;
443 hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "Result1",
444 buffer, size, &size, NULL);
445 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
446 ok(!lstrcmpiA(buffer, PROG_FILES_ROOT),
447 "Expected %s, got %s\n", PROG_FILES_ROOT, buffer);
448 ok(size == strlen(PROG_FILES_ROOT)+1, "Expected size %d, got %d\n",
449 lstrlenA(PROG_FILES_ROOT)+1, size);
451 memset(buffer, 'a', APP_PATH_LEN);
452 buffer[APP_PATH_LEN - 1] = '\0';
453 size = MAX_PATH;
454 hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "Result2",
455 buffer, size, &size, NULL);
456 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
457 ok(!lstrcmpiA(buffer, PROG_FILES_ROOT),
458 "Expected %s, got %s\n", PROG_FILES_ROOT, buffer);
459 ok(size == strlen(PROG_FILES_ROOT)+1, "Expected size %d, got %d\n",
460 lstrlenA(PROG_FILES_ROOT)+1, size);
463 char drive[MAX_PATH];
464 lstrcpyA(drive, PROG_FILES_ROOT);
465 drive[3] = 0x00; /* Just keep the system drive plus '\' */
467 memset(buffer, 'a', APP_PATH_LEN);
468 buffer[APP_PATH_LEN - 1] = '\0';
469 size = MAX_PATH;
470 hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "Result3",
471 buffer, size, &size, NULL);
472 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
473 ok(!lstrcmpiA(buffer, drive),
474 "Expected %s, got %s\n", drive, buffer);
475 ok(size == strlen(drive)+1, "Expected size %d, got %d\n",
476 lstrlenA(drive)+1, size);
479 /* close the INF again */
480 hr = pCloseINFEngine(hinf);
481 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
483 DeleteFileA(inf_file);
485 /* Create another .inf file which is just here to trigger a wine bug */
487 char data[1024];
488 char *ptr = data;
489 DWORD dwNumberOfBytesWritten;
490 HANDLE hf = CreateFileA(inf_file, GENERIC_WRITE, 0, NULL,
491 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
493 append_str(&ptr, "[Version]\n");
494 append_str(&ptr, "Signature=\"$Chicago$\"\n");
495 append_str(&ptr, "[section]\n");
496 append_str(&ptr, "NotACustomDestination=Version\n");
497 append_str(&ptr, "CustomDestination=CustInstDestSection\n");
498 append_str(&ptr, "[CustInstDestSection]\n");
499 append_str(&ptr, "49010=DestA,1\n");
500 append_str(&ptr, "49020=DestB\n");
501 append_str(&ptr, "49030=DestC\n");
502 append_str(&ptr, "49040=DestD\n");
503 append_str(&ptr, "[Options.NTx86]\n");
504 append_str(&ptr, "Result2=%%49030%%\n");
505 append_str(&ptr, "[DestA]\n");
506 append_str(&ptr, "HKLM,\"Software\\Garbage\",\"ProgramFilesDir\",,'%%24%%'\n");
507 /* The point of this test is to have HKCU just before the quoted HKLM */
508 append_str(&ptr, "[DestB]\n");
509 append_str(&ptr, "HKCU,\"Software\\Garbage\",\"ProgramFilesDir\",,'%%24%%'\n");
510 append_str(&ptr, "[DestC]\n");
511 append_str(&ptr, "'HKLM','Software\\Microsoft\\Windows\\CurrentVersion',");
512 append_str(&ptr, "'ProgramFilesDir',,\"%%24%%\"\n");
513 append_str(&ptr, "[DestD]\n");
514 append_str(&ptr, "HKLM,\"Software\\Garbage\",\"ProgramFilesDir\",,'%%24%%'\n");
516 WriteFile(hf, data, ptr - data, &dwNumberOfBytesWritten, NULL);
517 CloseHandle(hf);
520 /* open the inf with the install section */
521 hr = pOpenINFEngine(inf_file, "section", 0, &hinf, NULL);
522 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
524 /* Single quote test (Note size includes null on return from call) */
525 memset(buffer, 'a', APP_PATH_LEN);
526 buffer[APP_PATH_LEN - 1] = '\0';
527 size = MAX_PATH;
528 hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "Result2",
529 buffer, size, &size, NULL);
530 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
531 ok(!lstrcmpiA(buffer, PROG_FILES_ROOT),
532 "Expected %s, got %s\n", PROG_FILES_ROOT, buffer);
533 ok(size == strlen(PROG_FILES_ROOT)+1, "Expected size %d, got %d\n",
534 lstrlenA(PROG_FILES_ROOT)+1, size);
536 /* close the INF again */
537 hr = pCloseINFEngine(hinf);
538 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
540 DeleteFileA(inf_file);
543 static BOOL check_reg_str(HKEY hkey, LPCSTR name, LPCSTR value)
545 DWORD size = MAX_PATH;
546 char check[MAX_PATH];
548 if (RegQueryValueExA(hkey, name, NULL, NULL, (LPBYTE)check, &size))
549 return FALSE;
551 return !lstrcmpA(check, value);
554 static BOOL check_reg_dword(HKEY hkey, LPCSTR name, DWORD value)
556 DWORD size = sizeof(DWORD);
557 DWORD check;
559 if (RegQueryValueExA(hkey, name, NULL, NULL, (LPBYTE)&check, &size))
560 return FALSE;
562 return (check == value);
565 static void setperusersecvalues_test(void)
567 PERUSERSECTIONA peruser;
568 HRESULT hr;
569 HKEY guid;
571 lstrcpyA(peruser.szDispName, "displayname");
572 lstrcpyA(peruser.szLocale, "locale");
573 lstrcpyA(peruser.szStub, "stub");
574 lstrcpyA(peruser.szVersion, "1,1,1,1");
575 lstrcpyA(peruser.szCompID, "compid");
576 peruser.dwIsInstalled = 1;
577 peruser.bRollback = FALSE;
579 /* try a NULL pPerUser */
580 if (0)
582 /* This crashes on systems with IE7 */
583 hr = pSetPerUserSecValues(NULL);
584 todo_wine
585 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
586 ok(!OPEN_GUID_KEY(), "Expected guid key to not exist\n");
589 /* at the very least, szGUID must be valid */
590 peruser.szGUID[0] = '\0';
591 hr = pSetPerUserSecValues(&peruser);
592 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
593 ok(!OPEN_GUID_KEY(), "Expected guid key to not exist\n");
595 /* set initial values */
596 lstrcpyA(peruser.szGUID, "guid");
597 hr = pSetPerUserSecValues(&peruser);
598 if (hr == E_FAIL)
600 skip("SetPerUserSecValues is broken\n");
601 return;
603 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
604 ok(OPEN_GUID_KEY(), "Expected guid key to exist\n");
605 ok(check_reg_str(guid, NULL, "displayname"), "Expected displayname\n");
606 ok(check_reg_str(guid, "ComponentID", "compid"), "Expected compid\n");
607 ok(check_reg_str(guid, "Locale", "locale"), "Expected locale\n");
608 ok(check_reg_str(guid, "StubPath", "stub"), "Expected stub\n");
609 ok(check_reg_str(guid, "Version", "1,1,1,1"), "Expected 1,1,1,1\n");
610 ok(check_reg_dword(guid, "IsInstalled", 1), "Expected 1\n");
611 ok(!REG_VAL_EXISTS(guid, "OldDisplayName"), "Expected OldDisplayName to not exist\n");
612 ok(!REG_VAL_EXISTS(guid, "OldLocale"), "Expected OldLocale to not exist\n");
613 ok(!REG_VAL_EXISTS(guid, "OldStubPath"), "Expected OldStubPath to not exist\n");
614 ok(!REG_VAL_EXISTS(guid, "OldVersion"), "Expected OldVersion to not exist\n");
615 ok(!REG_VAL_EXISTS(guid, "RealStubPath"), "Expected RealStubPath to not exist\n");
617 /* raise the version, but bRollback is FALSE, so vals not saved */
618 lstrcpyA(peruser.szVersion, "2,1,1,1");
619 hr = pSetPerUserSecValues(&peruser);
620 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
621 ok(check_reg_str(guid, NULL, "displayname"), "Expected displayname\n");
622 ok(check_reg_str(guid, "ComponentID", "compid"), "Expected compid\n");
623 ok(check_reg_str(guid, "Locale", "locale"), "Expected locale\n");
624 ok(check_reg_str(guid, "StubPath", "stub"), "Expected stub\n");
625 ok(check_reg_str(guid, "Version", "2,1,1,1"), "Expected 2,1,1,1\n");
626 ok(check_reg_dword(guid, "IsInstalled", 1), "Expected 1\n");
627 ok(!REG_VAL_EXISTS(guid, "OldDisplayName"), "Expected OldDisplayName to not exist\n");
628 ok(!REG_VAL_EXISTS(guid, "OldLocale"), "Expected OldLocale to not exist\n");
629 ok(!REG_VAL_EXISTS(guid, "OldStubPath"), "Expected OldStubPath to not exist\n");
630 ok(!REG_VAL_EXISTS(guid, "OldVersion"), "Expected OldVersion to not exist\n");
631 ok(!REG_VAL_EXISTS(guid, "RealStubPath"), "Expected RealStubPath to not exist\n");
633 /* raise the version again, bRollback is TRUE so vals are saved */
634 peruser.bRollback = TRUE;
635 lstrcpyA(peruser.szVersion, "3,1,1,1");
636 hr = pSetPerUserSecValues(&peruser);
637 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
638 ok(check_reg_str(guid, NULL, "displayname"), "Expected displayname\n");
639 ok(check_reg_str(guid, "ComponentID", "compid"), "Expected compid\n");
640 ok(check_reg_str(guid, "Locale", "locale"), "Expected locale\n");
641 ok(check_reg_dword(guid, "IsInstalled", 1), "Expected 1\n");
642 ok(check_reg_str(guid, "Version", "3,1,1,1"), "Expected 3,1,1,1\n");
643 todo_wine
645 ok(check_reg_str(guid, "OldDisplayName", "displayname"), "Expected displayname\n");
646 ok(check_reg_str(guid, "OldLocale", "locale"), "Expected locale\n");
647 ok(check_reg_str(guid, "RealStubPath", "stub"), "Expected stub\n");
648 ok(check_reg_str(guid, "OldStubPath", "stub"), "Expected stub\n");
649 ok(check_reg_str(guid, "OldVersion", "2,1,1,1"), "Expected 2,1,1,1\n");
650 ok(check_reg_str(guid, "StubPath",
651 "rundll32.exe advpack.dll,UserInstStubWrapper guid"),
652 "Expected real stub\n");
655 RegDeleteKeyA(HKEY_LOCAL_MACHINE, GUID_KEY);
658 START_TEST(advpack)
660 if (!init_function_pointers())
661 return;
663 /* Make sure we create the temporary file in a directory
664 * where we have adequate rights
666 GetTempPathA(MAX_PATH, inf_file);
667 lstrcatA(inf_file,"test.inf");
669 get_progfiles_dir();
671 version_test();
672 delnode_test();
673 setperusersecvalues_test();
674 translateinfstring_test();
675 translateinfstringex_test();
677 FreeLibrary(hAdvPack);