2 * comctl32 MRU unit tests
4 * Copyright (C) 2004 Jon Griffiths <jon_p_griffiths@yahoo.com>
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #include "wine/test.h"
33 /* Keys for testing MRU functions */
34 #define REG_TEST_BASEKEYA "Software\\Wine"
35 #define REG_TEST_BASESUBKEYA "Test"
36 #define REG_TEST_KEYA REG_TEST_BASEKEYA "\\" REG_TEST_BASESUBKEYA
37 #define REG_TEST_SUBKEYA "MRUTest"
38 #define REG_TEST_FULLKEY REG_TEST_KEYA "\\" REG_TEST_SUBKEYA
40 /* Undocumented MRU structures & functions */
41 typedef struct tagCREATEMRULISTA
49 } CREATEMRULISTA, *LPCREATEMRULISTA;
51 #define MRUF_STRING_LIST 0
52 #define MRUF_BINARY_LIST 1
53 #define MRUF_DELAYED_SAVE 2
55 #define LIST_SIZE 3 /* Max entries for each mru */
57 static CREATEMRULISTA mruA =
59 sizeof(CREATEMRULISTA),
67 static HMODULE hComctl32;
68 static HANDLE (WINAPI *pCreateMRUListA)(LPCREATEMRULISTA);
69 static void (WINAPI *pFreeMRUList)(HANDLE);
70 static INT (WINAPI *pAddMRUStringA)(HANDLE,LPCSTR);
72 static INT (WINAPI *pFindMRUStringA)(HANDLE,LPCSTR,LPINT);
73 static INT (WINAPI *pEnumMRUList)(HANDLE,INT,LPVOID,DWORD);
76 static BOOL create_reg_entries(void)
80 ok(!RegCreateKeyA(HKEY_CURRENT_USER, REG_TEST_FULLKEY, &hKey),
81 "Couldn't create test key \"%s\"\n", REG_TEST_KEYA);
82 if (!hKey) return FALSE;
87 static void delete_reg_entries(void)
91 if (RegOpenKeyExA(HKEY_CURRENT_USER, REG_TEST_BASEKEYA, 0, KEY_ALL_ACCESS,
94 SHDeleteKeyA(hKey, REG_TEST_BASESUBKEYA);
98 static void check_reg_entries(const char *mrulist, const char**items)
102 DWORD type, size, ret;
105 ok(!RegOpenKeyA(HKEY_CURRENT_USER, REG_TEST_FULLKEY, &hKey),
106 "Couldn't open test key \"%s\"\n", REG_TEST_FULLKEY);
112 ret = RegQueryValueExA(hKey, "MRUList", NULL, &type, (LPBYTE)buff, &size);
114 ok(!ret && buff[0], "Checking MRU: got %ld from RegQueryValueExW\n", ret);
115 if(ret || !buff[0]) return;
117 ok(strcmp(buff, mrulist) == 0, "Checking MRU: Expected list %s, got %s\n",
119 if(strcmp(buff, mrulist)) return;
121 for (i = 0; i < strlen(mrulist); i++)
124 name[0] = mrulist[i];
129 ret = RegQueryValueExA(hKey, name, NULL, &type, (LPBYTE)buff, &size);
131 "Checking MRU item %d ('%c'): got %ld from RegQueryValueExW\n",
133 if(ret || !buff[0]) return;
134 ok(!strcmp(buff, items[mrulist[i]-'a']),
135 "Checking MRU item %d ('%c'): expected \"%s\", got \"%s\"\n",
136 i, mrulist[i], buff, items[mrulist[i] - 'a']);
140 static INT CALLBACK cmp_mru_strA(LPCVOID data1, LPCVOID data2)
142 return lstrcmpiA(data1, data2);
145 static HANDLE create_mruA(HKEY hKey, DWORD flags, PROC cmp)
147 mruA.dwFlags = flags;
148 mruA.lpfnCompare = cmp;
152 return pCreateMRUListA(&mruA);
155 static void test_MRUListA(void)
157 const char *checks[LIST_SIZE+1];
162 pCreateMRUListA = (void*)GetProcAddress(hComctl32,(LPCSTR)151);
163 pFreeMRUList = (void*)GetProcAddress(hComctl32,(LPCSTR)152);
164 pAddMRUStringA = (void*)GetProcAddress(hComctl32,(LPCSTR)153);
165 if (!pCreateMRUListA || !pFreeMRUList || !pAddMRUStringA)
168 #if 0 /* Create (NULL) - crashes native */
169 hMRU = pCreateMRUListA(NULL);
172 /* Create (size too small) */
173 mruA.cbSize = sizeof(mruA) - 2;
174 hMRU = create_mruA(NULL, MRUF_STRING_LIST, cmp_mru_strA);
175 ok (!hMRU && !GetLastError(),
176 "CreateMRUListA(too small) expected NULL,0 got %p,%ld\n",
177 hMRU, GetLastError());
178 mruA.cbSize = sizeof(mruA);
180 /* Create (size too big) */
181 mruA.cbSize = sizeof(mruA) + 2;
182 hMRU = create_mruA(NULL, MRUF_STRING_LIST, cmp_mru_strA);
183 ok (!hMRU && !GetLastError(),
184 "CreateMRUListA(too big) expected NULL,0 got %p,%ld\n",
185 hMRU, GetLastError());
186 mruA.cbSize = sizeof(mruA);
188 /* Create (NULL hKey) */
189 hMRU = create_mruA(NULL, MRUF_STRING_LIST, cmp_mru_strA);
190 ok (!hMRU && !GetLastError(),
191 "CreateMRUListA(NULL key) expected NULL,0 got %p,%ld\n",
192 hMRU, GetLastError());
194 /* Create (NULL name) */
195 mruA.lpszSubKey = NULL;
196 hMRU = create_mruA(NULL, MRUF_STRING_LIST, cmp_mru_strA);
197 ok (!hMRU && !GetLastError(),
198 "CreateMRUListA(NULL name) expected NULL,0 got %p,%ld\n",
199 hMRU, GetLastError());
200 mruA.lpszSubKey = REG_TEST_SUBKEYA;
202 /* Create a string MRU */
203 ok(!RegCreateKeyA(HKEY_CURRENT_USER, REG_TEST_KEYA, &hKey),
204 "Couldn't create test key \"%s\"\n", REG_TEST_KEYA);
207 hMRU = create_mruA(hKey, MRUF_STRING_LIST, cmp_mru_strA);
208 ok(hMRU && !GetLastError(),
209 "CreateMRUListA(string) expected non-NULL,0 got %p,%ld\n",
210 hMRU, GetLastError());
214 checks[0] = "Test 1";
215 checks[1] = "Test 2";
216 checks[2] = "Test 3";
217 checks[3] = "Test 4";
219 /* Add (NULL list) */
221 iRet = pAddMRUStringA(NULL, checks[0]);
222 ok(iRet == -1 && !GetLastError(),
223 "AddMRUStringA(NULL list) expected -1,0 got %d,%ld\n",
224 iRet, GetLastError());
226 /* Add (NULL string) */
228 /* Some native versions crash when passed NULL or fail to SetLastError() */
230 iRet = pAddMRUStringA(hMRU, NULL);
231 ok(iRet == 0 && GetLastError() == ERROR_INVALID_PARAMETER,
232 "AddMRUStringA(NULL str) expected 0,ERROR_INVALID_PARAMETER got %d,%ld\n",
233 iRet, GetLastError());
236 /* Add 3 strings. Check the registry is correct after each add */
238 iRet = pAddMRUStringA(hMRU, checks[0]);
239 ok(iRet == 0 && !GetLastError(),
240 "AddMRUStringA(1) expected 0,0 got %d,%ld\n",
241 iRet, GetLastError());
242 check_reg_entries("a", checks);
245 iRet = pAddMRUStringA(hMRU, checks[1]);
246 ok(iRet == 1 && !GetLastError(),
247 "AddMRUStringA(2) expected 1,0 got %d,%ld\n",
248 iRet, GetLastError());
249 check_reg_entries("ba", checks);
252 iRet = pAddMRUStringA(hMRU, checks[2]);
253 ok(iRet == 2 && !GetLastError(),
254 "AddMRUStringA(2) expected 2,0 got %d,%ld\n",
255 iRet, GetLastError());
256 check_reg_entries("cba", checks);
258 /* Add a duplicate of the 2nd string - it should move to the front,
259 * but keep the same index in the registry.
262 iRet = pAddMRUStringA(hMRU, checks[1]);
263 ok(iRet == 1 && !GetLastError(),
264 "AddMRUStringA(re-add 1) expected 1,0 got %d,%ld\n",
265 iRet, GetLastError());
266 check_reg_entries("bca", checks);
268 /* Add a new string - replaces the oldest string + moves to the front */
270 iRet = pAddMRUStringA(hMRU, checks[3]);
271 ok(iRet == 0 && !GetLastError(),
272 "AddMRUStringA(add new) expected 0,0 got %d,%ld\n",
273 iRet, GetLastError());
274 checks[0] = checks[3];
275 check_reg_entries("abc", checks);
277 /* Finished with this MRU */
281 /* Free (NULL list) - Doesn't crash */
287 hComctl32 = GetModuleHandleA("comctl32.dll");
291 delete_reg_entries();
292 if (!create_reg_entries())
297 delete_reg_entries();