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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include "wine/test.h"
28 #define TEST_STRING1 "\\Application Name"
29 #define TEST_STRING2 "%49001%\\Application Name"
31 static HRESULT (WINAPI *pGetVersionFromFile)(LPSTR,LPDWORD,LPDWORD,BOOL);
32 static HRESULT (WINAPI *pDelNode)(LPCSTR,DWORD);
33 static HRESULT (WINAPI *pTranslateInfString)(LPSTR,LPSTR,LPSTR,LPSTR,LPSTR,DWORD,LPDWORD,LPVOID);
35 static void version_test(void)
41 hr = pGetVersionFromFile("kernel32.dll", &major, &minor, FALSE);
42 ok (hr == S_OK, "GetVersionFromFileEx(kernel32.dll) failed, returned "
44 trace("kernel32.dll Language ID: 0x%08lx, Codepage ID: 0x%08lx\n",
48 hr = pGetVersionFromFile("kernel32.dll", &major, &minor, TRUE);
49 ok (hr == S_OK, "GetVersionFromFileEx(kernel32.dll) failed, returned "
51 trace("kernel32.dll version: %d.%d.%d.%d\n", HIWORD(major), LOWORD(major),
52 HIWORD(minor), LOWORD(minor));
55 hr = pGetVersionFromFile("advpack.dll", &major, &minor, FALSE);
56 ok (hr == S_OK, "GetVersionFromFileEx(advpack.dll) failed, returned "
58 trace("advpack.dll Language ID: 0x%08lx, Codepage ID: 0x%08lx\n",
62 hr = pGetVersionFromFile("advpack.dll", &major, &minor, TRUE);
63 ok (hr == S_OK, "GetVersionFromFileEx(advpack.dll) failed, returned "
65 trace("advpack.dll version: %d.%d.%d.%d\n", HIWORD(major), LOWORD(major),
66 HIWORD(minor), LOWORD(minor));
69 static void delnode_test(void)
73 CHAR currDir[MAX_PATH];
76 /* Native DelNode apparently does not support relative paths, so we use
77 absolute paths for testing */
78 currDirLen = GetCurrentDirectoryA(sizeof(currDir) / sizeof(CHAR), currDir);
79 assert(currDirLen > 0 && currDirLen < sizeof(currDir) / sizeof(CHAR));
81 if(currDir[currDirLen - 1] == '\\')
82 currDir[--currDirLen] = 0;
84 /* Simple tests; these should fail. */
85 hr = pDelNode(NULL, 0);
86 ok (hr == E_FAIL, "DelNode called with NULL pathname should return E_FAIL\n");
88 ok (hr == E_FAIL, "DelNode called with empty pathname should return E_FAIL\n");
90 /* Test deletion of a file. */
91 hn = CreateFile("DelNodeTestFile1", GENERIC_WRITE, 0, NULL,
92 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
93 assert(hn != INVALID_HANDLE_VALUE);
95 hr = pDelNode(lstrcat(currDir, "\\DelNodeTestFile1"), 0);
96 ok (hr == S_OK, "DelNode failed deleting a single file\n");
97 currDir[currDirLen] = '\0';
99 /* Test deletion of an empty directory. */
100 CreateDirectoryA("DelNodeTestDir", NULL);
101 hr = pDelNode(lstrcat(currDir, "\\DelNodeTestDir"), 0);
102 ok (hr == S_OK, "DelNode failed deleting an empty directory\n");
103 currDir[currDirLen] = '\0';
105 /* Test deletion of a directory containing one file. */
106 CreateDirectoryA("DelNodeTestDir", NULL);
107 hn = CreateFile("DelNodeTestDir\\DelNodeTestFile1", GENERIC_WRITE, 0, NULL,
108 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
109 assert(hn != INVALID_HANDLE_VALUE);
111 hr = pDelNode(lstrcat(currDir, "\\DelNodeTestDir"), 0);
112 ok (hr == S_OK, "DelNode failed deleting a directory containing one file\n");
113 currDir[currDirLen] = '\0';
115 /* Test deletion of a directory containing multiple files. */
116 CreateDirectoryA("DelNodeTestDir", NULL);
117 hn = CreateFile("DelNodeTestDir\\DelNodeTestFile1", GENERIC_WRITE, 0, NULL,
118 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
119 assert(hn != INVALID_HANDLE_VALUE);
121 hn = CreateFile("DelNodeTestDir\\DelNodeTestFile2", GENERIC_WRITE, 0, NULL,
122 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
123 assert(hn != INVALID_HANDLE_VALUE);
125 hn = CreateFile("DelNodeTestDir\\DelNodeTestFile3", GENERIC_WRITE, 0, NULL,
126 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
127 assert(hn != INVALID_HANDLE_VALUE);
129 hr = pDelNode(lstrcat(currDir, "\\DelNodeTestDir"), 0);
130 ok (hr == S_OK, "DelNode failed deleting a directory containing multiple files\n");
131 currDir[currDirLen] = '\0';
134 static void append_str(char **str, const char *data)
137 *str += strlen(*str);
140 static void create_inf_file()
144 DWORD dwNumberOfBytesWritten;
145 HANDLE hf = CreateFile("c:\\test.inf", GENERIC_WRITE, 0, NULL,
146 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
148 append_str(&ptr, "[Version]\n");
149 append_str(&ptr, "Signature=\"$Chicago$\"\n");
150 append_str(&ptr, "[CustInstDestSection]\n");
151 append_str(&ptr, "49001=ProgramFilesDir\n");
152 append_str(&ptr, "[ProgramFilesDir]\n");
153 append_str(&ptr, "HKLM,\"Software\\Microsoft\\Windows\\CurrentVersion\",");
154 append_str(&ptr, "\"ProgramFilesDir\",,\"%%24%%\\%%LProgramF%%\"\n");
155 append_str(&ptr, "[section]\n");
156 append_str(&ptr, "NotACustomDestination=Version\n");
157 append_str(&ptr, "CustomDestination=CustInstDestSection\n");
158 append_str(&ptr, "[Options.NTx86]\n");
159 append_str(&ptr, "49001=ProgramFilesDir\n");
160 append_str(&ptr, "InstallDir=%%49001%%\\%%DefaultAppPath%%\n");
161 append_str(&ptr, "CustomHDestination=CustInstDestSection\n");
162 append_str(&ptr, "[Strings]\n");
163 append_str(&ptr, "DefaultAppPath=\"Application Name\"\n");
164 append_str(&ptr, "LProgramF=\"Program Files\"\n");
166 WriteFile(hf, data, ptr - data, &dwNumberOfBytesWritten, NULL);
170 static void translateinfstring_test()
173 char buffer[MAX_PATH];
178 /* pass in a couple invalid parameters */
179 hr = pTranslateInfString(NULL, NULL, NULL, NULL, buffer, MAX_PATH, &dwSize, NULL);
180 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got 0x%08x\n", (UINT)hr);
182 /* try to open an inf file that doesn't exist */
183 hr = pTranslateInfString("c:\\a.inf", "Options.NTx86", "Options.NTx86",
184 "InstallDir", buffer, MAX_PATH, &dwSize, NULL);
185 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) || hr == E_INVALIDARG ||
186 hr == HRESULT_FROM_WIN32(ERROR_MOD_NOT_FOUND),
187 "Expected E_INVALIDARG, 0x80070002 or 0x8007007e, got 0x%08x\n", (UINT)hr);
189 if(hr == HRESULT_FROM_WIN32(ERROR_MOD_NOT_FOUND))
191 trace("WinNT 3.51 detected. Skipping tests for TranslateInfString()\n");
195 /* try a nonexistent section */
197 hr = pTranslateInfString("c:\\test.inf", "idontexist", "Options.NTx86",
198 "InstallDir", buffer, MAX_PATH, &dwSize, NULL);
199 ok(hr == S_OK, "Expected S_OK, got 0x%08x\n", (UINT)hr);
200 ok(!strcmp(buffer, TEST_STRING2), "Expected %s, got %s\n", TEST_STRING2, buffer);
201 ok(dwSize == 25, "Expected size 25, got %ld\n", dwSize);
204 /* try other nonexistent section */
205 hr = pTranslateInfString("c:\\test.inf", "Options.NTx86", "idontexist",
206 "InstallDir", buffer, MAX_PATH, &dwSize, NULL);
207 ok(hr == SPAPI_E_LINE_NOT_FOUND || hr == E_INVALIDARG,
208 "Expected SPAPI_E_LINE_NOT_FOUND or E_INVALIDARG, got 0x%08x\n", (UINT)hr);
211 /* try nonexistent key */
212 hr = pTranslateInfString("c:\\test.inf", "Options.NTx86", "Options.NTx86",
213 "notvalid", buffer, MAX_PATH, &dwSize, NULL);
214 ok(hr == SPAPI_E_LINE_NOT_FOUND || hr == E_INVALIDARG,
215 "Expected SPAPI_E_LINE_NOT_FOUND or E_INVALIDARG, got 0x%08x\n", (UINT)hr);
218 /* test the behavior of pszInstallSection */
219 hr = pTranslateInfString("c:\\test.inf", "section", "Options.NTx86",
220 "InstallDir", buffer, MAX_PATH, &dwSize, NULL);
221 ok(hr == ERROR_SUCCESS || hr == E_FAIL,
222 "Expected ERROR_SUCCESS or E_FAIL, got 0x%08x\n", (UINT)hr);
224 if(hr == ERROR_SUCCESS)
228 DWORD len = MAX_PATH;
229 char cmpbuffer[MAX_PATH];
230 LONG res = RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion", &key);
231 if(res == ERROR_SUCCESS) {
232 res = RegQueryValueExA(key, "ProgramFilesDir", NULL, NULL, (LPBYTE)cmpbuffer, &len);
233 if(res == ERROR_SUCCESS) {
234 strcat(cmpbuffer, TEST_STRING1);
235 ok(!strcmp(buffer, cmpbuffer), "Expected '%s', got '%s'\n", cmpbuffer, buffer);
236 ok(dwSize == (strlen(cmpbuffer)+1), "Expected size %d, got %ld\n",
237 strlen(cmpbuffer)+1, dwSize);
244 /* try without a pszInstallSection */
245 hr = pTranslateInfString("c:\\test.inf", NULL, "Options.NTx86",
246 "InstallDir", buffer, MAX_PATH, &dwSize, NULL);
247 ok(hr == S_OK, "Expected S_OK, got 0x%08x\n", (UINT)hr);
248 ok(!strcmp(buffer, TEST_STRING2), "Expected %s, got %s\n", TEST_STRING2, buffer);
249 ok(dwSize == 25, "Expected size 25, got %ld\n", dwSize);
251 DeleteFile("c:\\a.inf");
252 DeleteFile("c:\\test.inf");
259 hdll = LoadLibraryA("advpack.dll");
263 pGetVersionFromFile = (void*)GetProcAddress(hdll, "GetVersionFromFile");
264 pDelNode = (void*)GetProcAddress(hdll, "DelNode");
265 pTranslateInfString = (void*)GetProcAddress(hdll, "TranslateInfString");
266 if (!pGetVersionFromFile || !pDelNode || !pTranslateInfString)
271 translateinfstring_test();