2 * Tests for MSI Source functions
4 * Copyright (C) 2006 James Hawkins
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
29 #include "wine/test.h"
31 /* copied from dlls/msi/registry.c */
32 static BOOL squash_guid(LPCWSTR in, LPWSTR out)
37 if (FAILED(CLSIDFromString((LPOLESTR)in, &guid)))
51 out[17+i*2] = in[n++];
52 out[16+i*2] = in[n++];
57 out[17+i*2] = in[n++];
58 out[16+i*2] = in[n++];
64 static void create_test_guid(LPSTR prodcode, LPSTR squashed)
66 WCHAR guidW[MAX_PATH];
67 WCHAR squashedW[MAX_PATH];
72 hr = CoCreateGuid(&guid);
73 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
75 size = StringFromGUID2(&guid, (LPOLESTR)guidW, MAX_PATH);
76 ok(size == 39, "Expected 39, got %d\n", hr);
78 WideCharToMultiByte(CP_ACP, 0, guidW, size, prodcode, MAX_PATH, NULL, NULL);
79 squash_guid(guidW, squashedW);
80 WideCharToMultiByte(CP_ACP, 0, squashedW, -1, squashed, MAX_PATH, NULL, NULL);
83 static void get_user_sid(LPSTR *usersid)
90 OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token);
92 GetTokenInformation(token, TokenUser, (void *)buf, size, &size);
93 user = (PTOKEN_USER)buf;
94 ConvertSidToStringSid(user->User.Sid, usersid);
97 static void test_MsiSourceListGetInfo(void)
99 CHAR prodcode[MAX_PATH];
100 CHAR prod_squashed[MAX_PATH];
101 CHAR keypath[MAX_PATH*2];
102 CHAR value[MAX_PATH];
110 create_test_guid(prodcode, prod_squashed);
111 get_user_sid(&usersid);
113 /* NULL szProductCodeOrPatchCode */
114 r = MsiSourceListGetInfoA(NULL, usersid, MSIINSTALLCONTEXT_USERUNMANAGED,
115 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAME, NULL, NULL);
116 ok(r == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", r);
118 /* empty szProductCodeOrPatchCode */
119 r = MsiSourceListGetInfoA("", usersid, MSIINSTALLCONTEXT_USERUNMANAGED,
120 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAME, NULL, NULL);
121 ok(r == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", r);
123 /* garbage szProductCodeOrPatchCode */
124 r = MsiSourceListGetInfoA("garbage", usersid, MSIINSTALLCONTEXT_USERUNMANAGED,
125 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAME, NULL, NULL);
126 ok(r == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", r);
128 /* szProductCodeOrPatchCode */
129 r = MsiSourceListGetInfoA("garbage", usersid, MSIINSTALLCONTEXT_USERUNMANAGED,
130 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAME, NULL, NULL);
131 ok(r == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", r);
133 /* guid without brackets */
134 r = MsiSourceListGetInfoA("51CD2AD5-0482-4C46-8DDD-0ED1022AA1AA", usersid, MSIINSTALLCONTEXT_USERUNMANAGED,
135 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAME, NULL, NULL);
136 ok(r == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", r);
138 /* guid with brackets */
139 r = MsiSourceListGetInfoA("{51CD2AD5-0482-4C46-8DDD-0ED1022AA1AA}", usersid, MSIINSTALLCONTEXT_USERUNMANAGED,
140 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAME, NULL, NULL);
141 ok(r == ERROR_UNKNOWN_PRODUCT, "Expected ERROR_UNKNOWN_PRODUCT, got %d\n", r);
143 /* same length as guid, but random */
144 r = MsiSourceListGetInfoA("ADKD-2KSDFF2-DKK1KNFJASD9GLKWME-1I3KAD", usersid, MSIINSTALLCONTEXT_USERUNMANAGED,
145 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAME, NULL, NULL);
146 ok(r == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", r);
148 /* invalid context */
149 r = MsiSourceListGetInfoA(prodcode, usersid, MSIINSTALLCONTEXT_NONE,
150 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAME, NULL, NULL);
151 ok(r == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", r);
153 /* another invalid context */
154 r = MsiSourceListGetInfoA(prodcode, usersid, MSIINSTALLCONTEXT_ALLUSERMANAGED,
155 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAME, NULL, NULL);
156 ok(r == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", r);
158 /* yet another invalid context */
159 r = MsiSourceListGetInfoA(prodcode, usersid, MSIINSTALLCONTEXT_ALL,
160 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAME, NULL, NULL);
161 ok(r == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", r);
163 /* mix two valid contexts */
164 r = MsiSourceListGetInfoA(prodcode, usersid, MSIINSTALLCONTEXT_USERMANAGED | MSIINSTALLCONTEXT_USERUNMANAGED,
165 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAME, NULL, NULL);
166 ok(r == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", r);
169 r = MsiSourceListGetInfoA(prodcode, usersid, MSIINSTALLCONTEXT_USERUNMANAGED,
170 4, INSTALLPROPERTY_PACKAGENAME, NULL, NULL);
171 ok(r == ERROR_UNKNOWN_PRODUCT, "Expected ERROR_UNKNOWN_PRODUCT, got %d\n", r);
174 r = MsiSourceListGetInfoA(prodcode, usersid, MSIINSTALLCONTEXT_USERUNMANAGED,
175 MSICODE_PRODUCT, NULL, NULL, NULL);
176 ok(r == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", r);
179 r = MsiSourceListGetInfoA(prodcode, usersid, MSIINSTALLCONTEXT_USERUNMANAGED,
180 MSICODE_PRODUCT, "", NULL, NULL);
181 ok(r == ERROR_UNKNOWN_PRODUCT, "Expected ERROR_UNKNOWN_PRODUCT, got %d\n", r);
183 /* value is non-NULL while size is NULL */
184 r = MsiSourceListGetInfoA(prodcode, usersid, MSIINSTALLCONTEXT_USERUNMANAGED,
185 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAME, value, NULL);
186 ok(r == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", r);
188 /* size is non-NULL while value is NULL */
189 r = MsiSourceListGetInfoA(prodcode, usersid, MSIINSTALLCONTEXT_USERUNMANAGED,
190 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAME, NULL, &size);
191 ok(r == ERROR_UNKNOWN_PRODUCT, "Expected ERROR_UNKNOWN_PRODUCT, got %d\n", r);
193 lstrcpyA(keypath, "Software\\Microsoft\\Installer\\Products\\");
194 lstrcatA(keypath, prod_squashed);
196 res = RegCreateKeyA(HKEY_CURRENT_USER, keypath, &userkey);
197 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
199 /* user product key exists */
200 r = MsiSourceListGetInfoA(prodcode, usersid, MSIINSTALLCONTEXT_USERUNMANAGED,
201 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAME, NULL, &size);
202 ok(r == ERROR_BAD_CONFIGURATION, "Expected ERROR_BAD_CONFIGURATION, got %d\n", r);
204 res = RegCreateKeyA(userkey, "SourceList", &hkey);
205 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
207 /* SourceList key exists */
209 r = MsiSourceListGetInfoA(prodcode, usersid, MSIINSTALLCONTEXT_USERUNMANAGED,
210 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAME, NULL, &size);
211 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
212 ok(size == 0, "Expected 0, got %d\n", size);
214 data = "msitest.msi";
215 res = RegSetValueExA(hkey, "PackageName", 0, REG_SZ, (const BYTE *)data, lstrlenA(data) + 1);
216 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
218 /* PackageName value exists */
220 r = MsiSourceListGetInfoA(prodcode, usersid, MSIINSTALLCONTEXT_USERUNMANAGED,
221 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAME, NULL, &size);
222 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
223 ok(size == 11, "Expected 11, got %d\n", size);
225 /* read the value, don't change size */
226 lstrcpyA(value, "aaa");
227 r = MsiSourceListGetInfoA(prodcode, usersid, MSIINSTALLCONTEXT_USERUNMANAGED,
228 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAME, value, &size);
229 ok(r == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %d\n", r);
230 ok(!lstrcmpA(value, "aaa"), "Expected 'aaa', got %s\n", value);
231 ok(size == 11, "Expected 11, got %d\n", size);
233 /* read the value, fix size */
235 r = MsiSourceListGetInfoA(prodcode, usersid, MSIINSTALLCONTEXT_USERUNMANAGED,
236 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAME, value, &size);
237 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
238 ok(!lstrcmpA(value, "msitest.msi"), "Expected 'msitest.msi', got %s\n", value);
239 ok(size == 11, "Expected 11, got %d\n", size);
241 /* empty property now that product key exists */
243 r = MsiSourceListGetInfoA(prodcode, usersid, MSIINSTALLCONTEXT_USERUNMANAGED,
244 MSICODE_PRODUCT, "", NULL, &size);
245 ok(r == ERROR_UNKNOWN_PROPERTY, "Expected ERROR_UNKNOWN_PROPERTY, got %d\n", r);
246 ok(size == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", size);
248 /* nonexistent property now that product key exists */
250 r = MsiSourceListGetInfoA(prodcode, usersid, MSIINSTALLCONTEXT_USERUNMANAGED,
251 MSICODE_PRODUCT, "nonexistent", NULL, &size);
252 ok(r == ERROR_UNKNOWN_PROPERTY, "Expected ERROR_UNKNOWN_PROPERTY, got %d\n", r);
253 ok(size == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", size);
256 res = RegSetValueExA(hkey, "nonexistent", 0, REG_SZ, (const BYTE *)data, lstrlenA(data) + 1);
257 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
259 /* nonexistent property now that nonexistent value exists */
261 r = MsiSourceListGetInfoA(prodcode, usersid, MSIINSTALLCONTEXT_USERUNMANAGED,
262 MSICODE_PRODUCT, "nonexistent", NULL, &size);
263 ok(r == ERROR_UNKNOWN_PROPERTY, "Expected ERROR_UNKNOWN_PROPERTY, got %d\n", r);
264 ok(size == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", size);
266 /* invalid option now that product key exists */
268 r = MsiSourceListGetInfoA(prodcode, usersid, MSIINSTALLCONTEXT_USERUNMANAGED,
269 4, INSTALLPROPERTY_PACKAGENAME, NULL, &size);
270 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
271 ok(size == 11, "Expected 11, got %d\n", size);
273 RegDeleteValueA(hkey, "nonexistent");
274 RegDeleteValueA(hkey, "PackageName");
275 RegDeleteKeyA(hkey, "");
276 RegDeleteKeyA(userkey, "");
278 RegCloseKey(userkey);
282 r = MsiSourceListGetInfoA(prodcode, usersid, MSIINSTALLCONTEXT_USERUNMANAGED,
283 MSICODE_PATCH, INSTALLPROPERTY_PACKAGENAME, NULL, &size);
284 ok(r == ERROR_UNKNOWN_PATCH, "Expected ERROR_UNKNOWN_PATCH, got %d\n", r);
285 ok(size == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", size);
287 lstrcpyA(keypath, "Software\\Microsoft\\Installer\\Patches\\");
288 lstrcatA(keypath, prod_squashed);
290 res = RegCreateKeyA(HKEY_CURRENT_USER, keypath, &userkey);
291 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
294 * NOTE: using prodcode guid, but it really doesn't matter
297 r = MsiSourceListGetInfoA(prodcode, usersid, MSIINSTALLCONTEXT_USERUNMANAGED,
298 MSICODE_PATCH, INSTALLPROPERTY_PACKAGENAME, NULL, &size);
299 ok(r == ERROR_BAD_CONFIGURATION, "Expected ERROR_BAD_CONFIGURATION, got %d\n", r);
300 ok(size == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", size);
302 res = RegCreateKeyA(userkey, "SourceList", &hkey);
303 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
305 /* SourceList key exists */
307 r = MsiSourceListGetInfoA(prodcode, usersid, MSIINSTALLCONTEXT_USERUNMANAGED,
308 MSICODE_PATCH, INSTALLPROPERTY_PACKAGENAME, NULL, &size);
309 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
310 ok(size == 0, "Expected 0, got %d\n", size);
312 RegDeleteKeyA(hkey, "");
313 RegDeleteKeyA(userkey, "");
315 RegCloseKey(userkey);
320 test_MsiSourceListGetInfo();