Exit test after first TranslateInfString() failure, which seems to be
[wine/multimedia.git] / dlls / advpack / tests / advpack.c
blob675b4b5fbed6aa4f4b9a1efd5c5af5695bc3c71d
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <stdio.h>
23 #include <windows.h>
24 #include <advpub.h>
25 #include <assert.h>
26 #include "wine/test.h"
28 #define TEST_STRING1 "C:\\Program Files\\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)
37 HRESULT hr;
38 DWORD major, minor;
40 major = minor = 0;
41 hr = pGetVersionFromFile("kernel32.dll", &major, &minor, FALSE);
42 ok (hr == S_OK, "GetVersionFromFileEx(kernel32.dll) failed, returned "
43 "0x%08lx\n", hr);
44 trace("kernel32.dll Language ID: 0x%08lx, Codepage ID: 0x%08lx\n",
45 major, minor);
47 major = minor = 0;
48 hr = pGetVersionFromFile("kernel32.dll", &major, &minor, TRUE);
49 ok (hr == S_OK, "GetVersionFromFileEx(kernel32.dll) failed, returned "
50 "0x%08lx\n", hr);
51 trace("kernel32.dll version: %d.%d.%d.%d\n", HIWORD(major), LOWORD(major),
52 HIWORD(minor), LOWORD(minor));
54 major = minor = 0;
55 hr = pGetVersionFromFile("advpack.dll", &major, &minor, FALSE);
56 ok (hr == S_OK, "GetVersionFromFileEx(advpack.dll) failed, returned "
57 "0x%08lx\n", hr);
58 trace("advpack.dll Language ID: 0x%08lx, Codepage ID: 0x%08lx\n",
59 major, minor);
61 major = minor = 0;
62 hr = pGetVersionFromFile("advpack.dll", &major, &minor, TRUE);
63 todo_wine
64 ok (hr == S_OK, "GetVersionFromFileEx(advpack.dll) failed, returned "
65 "0x%08lx\n", hr);
66 trace("advpack.dll version: %d.%d.%d.%d\n", HIWORD(major), LOWORD(major),
67 HIWORD(minor), LOWORD(minor));
70 static void delnode_test(void)
72 HRESULT hr;
73 HANDLE hn;
74 CHAR currDir[MAX_PATH];
75 int currDirLen;
77 /* Native DelNode apparently does not support relative paths, so we use
78 absolute paths for testing */
79 currDirLen = GetCurrentDirectoryA(sizeof(currDir) / sizeof(CHAR), currDir);
80 assert(currDirLen > 0 && currDirLen < sizeof(currDir) / sizeof(CHAR));
82 if(currDir[currDirLen - 1] == '\\')
83 currDir[--currDirLen] = 0;
85 /* Simple tests; these should fail. */
86 hr = pDelNode(NULL, 0);
87 ok (hr == E_FAIL, "DelNode called with NULL pathname should return E_FAIL\n");
88 hr = pDelNode("", 0);
89 ok (hr == E_FAIL, "DelNode called with empty pathname should return E_FAIL\n");
91 /* Test deletion of a file. */
92 hn = CreateFile("DelNodeTestFile1", GENERIC_WRITE, 0, NULL,
93 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
94 assert(hn != INVALID_HANDLE_VALUE);
95 CloseHandle(hn);
96 hr = pDelNode(lstrcat(currDir, "\\DelNodeTestFile1"), 0);
97 ok (hr == S_OK, "DelNode failed deleting a single file\n");
98 currDir[currDirLen] = '\0';
100 /* Test deletion of an empty directory. */
101 CreateDirectoryA("DelNodeTestDir", NULL);
102 hr = pDelNode(lstrcat(currDir, "\\DelNodeTestDir"), 0);
103 ok (hr == S_OK, "DelNode failed deleting an empty directory\n");
104 currDir[currDirLen] = '\0';
106 /* Test deletion of a directory containing one file. */
107 CreateDirectoryA("DelNodeTestDir", NULL);
108 hn = CreateFile("DelNodeTestDir\\DelNodeTestFile1", GENERIC_WRITE, 0, NULL,
109 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
110 assert(hn != INVALID_HANDLE_VALUE);
111 CloseHandle(hn);
112 hr = pDelNode(lstrcat(currDir, "\\DelNodeTestDir"), 0);
113 ok (hr == S_OK, "DelNode failed deleting a directory containing one file\n");
114 currDir[currDirLen] = '\0';
116 /* Test deletion of a directory containing multiple files. */
117 CreateDirectoryA("DelNodeTestDir", NULL);
118 hn = CreateFile("DelNodeTestDir\\DelNodeTestFile1", GENERIC_WRITE, 0, NULL,
119 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
120 assert(hn != INVALID_HANDLE_VALUE);
121 CloseHandle(hn);
122 hn = CreateFile("DelNodeTestDir\\DelNodeTestFile2", GENERIC_WRITE, 0, NULL,
123 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
124 assert(hn != INVALID_HANDLE_VALUE);
125 CloseHandle(hn);
126 hn = CreateFile("DelNodeTestDir\\DelNodeTestFile3", GENERIC_WRITE, 0, NULL,
127 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
128 assert(hn != INVALID_HANDLE_VALUE);
129 CloseHandle(hn);
130 hr = pDelNode(lstrcat(currDir, "\\DelNodeTestDir"), 0);
131 ok (hr == S_OK, "DelNode failed deleting a directory containing multiple files\n");
132 currDir[currDirLen] = '\0';
135 static void append_str(char **str, const char *data)
137 sprintf(*str, data);
138 *str += strlen(*str);
141 static void create_inf_file()
143 char data[1024];
144 char *ptr = data;
145 DWORD dwNumberOfBytesWritten;
146 HANDLE hf = CreateFile("c:\\test.inf", GENERIC_WRITE, 0, NULL,
147 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
149 append_str(&ptr, "[Version]\n");
150 append_str(&ptr, "Signature=\"$Chicago$\"\n");
151 append_str(&ptr, "[CustInstDestSection]\n");
152 append_str(&ptr, "49001=ProgramFilesDir\n");
153 append_str(&ptr, "[ProgramFilesDir]\n");
154 append_str(&ptr, "HKLM,\"Software\\Microsoft\\Windows\\CurrentVersion\",");
155 append_str(&ptr, "\"ProgramFilesDir\",,\"%%24%%\\%%LProgramF%%\"\n");
156 append_str(&ptr, "[section]\n");
157 append_str(&ptr, "NotACustomDestination=Version\n");
158 append_str(&ptr, "CustomDestination=CustInstDestSection\n");
159 append_str(&ptr, "[Options.NTx86]\n");
160 append_str(&ptr, "49001=ProgramFilesDir\n");
161 append_str(&ptr, "InstallDir=%%49001%%\\%%DefaultAppPath%%\n");
162 append_str(&ptr, "CustomHDestination=CustInstDestSection\n");
163 append_str(&ptr, "[Strings]\n");
164 append_str(&ptr, "DefaultAppPath=\"Application Name\"\n");
165 append_str(&ptr, "LProgramF=\"Program Files\"\n");
167 WriteFile(hf, data, ptr - data, &dwNumberOfBytesWritten, NULL);
168 CloseHandle(hf);
171 static void translateinfstring_test()
173 HRESULT hr;
174 char buffer[MAX_PATH];
175 DWORD dwSize;
177 create_inf_file();
179 /* pass in a couple invalid parameters */
180 hr = pTranslateInfString(NULL, NULL, NULL, NULL, buffer, MAX_PATH, &dwSize, NULL);
181 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got 0x%08x\n", (UINT)hr);
183 /* try to open an inf file that doesn't exist */
184 hr = pTranslateInfString("c:\\a.inf", "Options.NTx86", "Options.NTx86",
185 "InstallDir", buffer, MAX_PATH, &dwSize, NULL);
186 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) || hr == E_INVALIDARG ||
187 hr == HRESULT_FROM_WIN32(ERROR_MOD_NOT_FOUND),
188 "Expected E_INVALIDARG, 0x80070002 or 0x8007007e, got 0x%08x\n", (UINT)hr);
190 if(hr == HRESULT_FROM_WIN32(ERROR_MOD_NOT_FOUND))
192 trace("WinNT 3.51 detected. Skipping tests for TranslateInfString()");
193 return;
196 /* try a nonexistent section */
197 buffer[0] = 0;
198 hr = pTranslateInfString("c:\\test.inf", "idontexist", "Options.NTx86",
199 "InstallDir", buffer, MAX_PATH, &dwSize, NULL);
200 ok(hr == S_OK, "Expected S_OK, got 0x%08x\n", (UINT)hr);
201 ok(!strcmp(buffer, TEST_STRING2), "Expected %s, got %s\n", TEST_STRING2, buffer);
202 ok(dwSize == 25, "Expected size 25, got %ld\n", dwSize);
204 buffer[0] = 0;
205 /* try other nonexistent section */
206 hr = pTranslateInfString("c:\\test.inf", "Options.NTx86", "idontexist",
207 "InstallDir", buffer, MAX_PATH, &dwSize, NULL);
208 ok(hr == SPAPI_E_LINE_NOT_FOUND || hr == E_INVALIDARG,
209 "Expected SPAPI_E_LINE_NOT_FOUND or E_INVALIDARG, got 0x%08x\n", (UINT)hr);
211 buffer[0] = 0;
212 /* try nonexistent key */
213 hr = pTranslateInfString("c:\\test.inf", "Options.NTx86", "Options.NTx86",
214 "notvalid", buffer, MAX_PATH, &dwSize, NULL);
215 ok(hr == SPAPI_E_LINE_NOT_FOUND || hr == E_INVALIDARG,
216 "Expected SPAPI_E_LINE_NOT_FOUND or E_INVALIDARG, got 0x%08x\n", (UINT)hr);
218 buffer[0] = 0;
219 /* test the behavior of pszInstallSection */
220 hr = pTranslateInfString("c:\\test.inf", "section", "Options.NTx86",
221 "InstallDir", buffer, MAX_PATH, &dwSize, NULL);
222 ok(hr == ERROR_SUCCESS || hr == E_FAIL,
223 "Expected ERROR_SUCCESS or E_FAIL, got 0x%08x\n", (UINT)hr);
225 if(hr == ERROR_SUCCESS)
226 todo_wine
228 ok(!strcmp(buffer, TEST_STRING1), "Expected %s, got %s\n", TEST_STRING1, buffer);
229 ok(dwSize == 34, "Expected size 34, got %ld\n", dwSize);
232 buffer[0] = 0;
233 /* try without a pszInstallSection */
234 hr = pTranslateInfString("c:\\test.inf", NULL, "Options.NTx86",
235 "InstallDir", buffer, MAX_PATH, &dwSize, NULL);
236 ok(hr == S_OK, "Expected S_OK, got 0x%08x\n", (UINT)hr);
237 ok(!strcmp(buffer, TEST_STRING2), "Expected %s, got %s\n", TEST_STRING2, buffer);
238 ok(dwSize == 25, "Expected size 25, got %ld\n", dwSize);
240 DeleteFile("c:\\a.inf");
241 DeleteFile("c:\\test.inf");
244 START_TEST(advpack)
246 HMODULE hdll;
248 hdll = LoadLibraryA("advpack.dll");
249 if (!hdll)
250 return;
252 pGetVersionFromFile = (void*)GetProcAddress(hdll, "GetVersionFromFile");
253 pDelNode = (void*)GetProcAddress(hdll, "DelNode");
254 pTranslateInfString = (void*)GetProcAddress(hdll, "TranslateInfString");
255 if (!pGetVersionFromFile || !pDelNode || !pTranslateInfString)
256 return;
258 version_test();
259 delnode_test();
260 translateinfstring_test();
262 FreeLibrary(hdll);