1 /* Unit test suite for SHLWAPI ordinal functions
3 * Copyright 2004 Jon Griffiths
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "wine/test.h"
27 /* Function ptrs for ordinal calls */
28 static HMODULE hShlwapi;
29 static int (WINAPI *pSHSearchMapInt)(const int*,const int*,int,int);
30 static HRESULT (WINAPI *pGetAcceptLanguagesA)(LPSTR,LPDWORD);
32 static HANDLE (WINAPI *pSHAllocShared)(LPCVOID,DWORD,DWORD);
33 static LPVOID (WINAPI *pSHLockShared)(HANDLE,DWORD);
34 static BOOL (WINAPI *pSHUnlockShared)(LPVOID);
35 static BOOL (WINAPI *pSHFreeShared)(HANDLE,DWORD);
37 static void test_GetAcceptLanguagesA(void)
39 DWORD buffersize, buffersize2, exactsize;
42 if (!pGetAcceptLanguagesA)
45 buffersize = sizeof(buffer);
46 memset(buffer, 0, sizeof(buffer));
47 SetLastError(ERROR_SUCCESS);
48 retval = pGetAcceptLanguagesA( buffer, &buffersize);
49 trace("GetAcceptLanguagesA: retval %08lx, size %08lx, buffer (%s),"
50 " last error %ld\n", retval, buffersize, buffer, GetLastError());
52 trace("GetAcceptLanguagesA: skipping tests\n");
55 ok( (ERROR_NO_IMPERSONATION_TOKEN == GetLastError()) ||
56 (ERROR_CLASS_DOES_NOT_EXIST == GetLastError()) ||
57 (ERROR_PROC_NOT_FOUND == GetLastError()) ||
58 (ERROR_CALL_NOT_IMPLEMENTED == GetLastError()) ||
59 (ERROR_SUCCESS == GetLastError()), "last error set to %ld\n", GetLastError());
60 exactsize = strlen(buffer);
62 SetLastError(ERROR_SUCCESS);
63 retval = pGetAcceptLanguagesA( NULL, NULL);
65 "function result wrong: got %08lx; expected E_FAIL\n", retval);
66 ok(ERROR_SUCCESS == GetLastError(), "last error set to %ld\n", GetLastError());
68 buffersize = sizeof(buffer);
69 SetLastError(ERROR_SUCCESS);
70 retval = pGetAcceptLanguagesA( NULL, &buffersize);
72 "function result wrong: got %08lx; expected E_FAIL\n", retval);
73 ok(buffersize == sizeof(buffer),
74 "buffersize was changed (2nd parameter; not on Win2k)\n");
75 ok(ERROR_SUCCESS == GetLastError(), "last error set to %ld\n", GetLastError());
77 SetLastError(ERROR_SUCCESS);
78 retval = pGetAcceptLanguagesA( buffer, NULL);
80 "function result wrong: got %08lx; expected E_FAIL\n", retval);
81 ok(ERROR_SUCCESS == GetLastError(), "last error set to %ld\n", GetLastError());
84 memset(buffer, 0, sizeof(buffer));
85 SetLastError(ERROR_SUCCESS);
86 retval = pGetAcceptLanguagesA( buffer, &buffersize);
88 "function result wrong: got %08lx; expected E_FAIL\n", retval);
90 "buffersize wrong(changed) got %08lx; expected 0 (2nd parameter; not on Win2k)\n", buffersize);
91 ok(ERROR_SUCCESS == GetLastError(), "last error set to %ld\n", GetLastError());
93 buffersize = buffersize2 = 1;
94 memset(buffer, 0, sizeof(buffer));
95 SetLastError(ERROR_SUCCESS);
96 retval = pGetAcceptLanguagesA( buffer, &buffersize);
99 if(buffersize == exactsize) {
100 ok( (ERROR_SUCCESS == GetLastError()) || (ERROR_CALL_NOT_IMPLEMENTED == GetLastError()) ||
101 (ERROR_PROC_NOT_FOUND == GetLastError()) || (ERROR_NO_IMPERSONATION_TOKEN == GetLastError()),
102 "last error wrong: got %08lx; expected ERROR_SUCCESS(NT4)/ERROR_CALL_NOT_IMPLEMENTED(98/ME)/"
103 "ERROR_PROC_NOT_FOUND(NT4)/ERROR_NO_IMPERSONATION_TOKEN(XP)\n", GetLastError());
104 ok(exactsize == strlen(buffer),
105 "buffer content (length) wrong: got %08x, expected %08lx \n", strlen(buffer), exactsize);
106 } else if((buffersize +1) == buffersize2) {
107 ok(ERROR_SUCCESS == GetLastError(),
108 "last error wrong: got %08lx; expected ERROR_SUCCESS\n", GetLastError());
109 ok(buffersize == strlen(buffer),
110 "buffer content (length) wrong: got %08x, expected %08lx \n", strlen(buffer), buffersize);
112 ok( 0, "retval %08lx, size %08lx, buffer (%s), last error %ld\n",
113 retval, buffersize, buffer, GetLastError());
117 "buffersize wrong: got %08lx, expected 0 (2nd parameter;Win2k)\n", buffersize);
118 ok(ERROR_INSUFFICIENT_BUFFER == GetLastError(),
119 "last error wrong: got %08lx; expected ERROR_INSUFFICIENT_BUFFER\n", GetLastError());
120 ok(buffersize2 == strlen(buffer),
121 "buffer content (length) wrong: got %08x, expected %08lx \n", strlen(buffer), buffersize2);
124 ok( 0, "retval %08lx, size %08lx, buffer (%s), last error %ld\n",
125 retval, buffersize, buffer, GetLastError());
129 buffersize = buffersize2 = exactsize;
130 memset(buffer, 0, sizeof(buffer));
131 SetLastError(ERROR_SUCCESS);
132 retval = pGetAcceptLanguagesA( buffer, &buffersize);
135 ok(ERROR_SUCCESS == GetLastError(),
136 "last error wrong: got %08lx; expected ERROR_SUCCESS\n", GetLastError());
137 if((buffersize == exactsize) /* XP */ ||
138 ((buffersize +1)== exactsize) /* 98 */)
139 ok(buffersize == strlen(buffer),
140 "buffer content (length) wrong: got %08x, expected %08lx \n", strlen(buffer), buffersize);
142 ok( 0, "retval %08lx, size %08lx, buffer (%s), last error %ld\n",
143 retval, buffersize, buffer, GetLastError());
147 "buffersize wrong: got %08lx, expected 0 (2nd parameter;Win2k)\n", buffersize);
148 ok(ERROR_INSUFFICIENT_BUFFER == GetLastError(),
149 "last error wrong: got %08lx; expected ERROR_INSUFFICIENT_BUFFER\n", GetLastError());
150 ok(buffersize2 == strlen(buffer),
151 "buffer content (length) wrong: got %08x, expected %08lx \n", strlen(buffer), buffersize2);
154 ok( 0, "retval %08lx, size %08lx, buffer (%s), last error %ld\n",
155 retval, buffersize, buffer, GetLastError());
160 static void test_SHSearchMapInt(void)
162 int keys[8], values[8];
165 if (!pSHSearchMapInt)
168 memset(keys, 0, sizeof(keys));
169 memset(values, 0, sizeof(values));
170 keys[0] = 99; values[0] = 101;
172 /* NULL key/value lists crash native, so skip testing them */
175 i = pSHSearchMapInt(keys, values, 1, keys[0]);
176 ok(i == values[0], "Len 1, expected %d, got %d\n", values[0], i);
178 /* Key doesn't exist */
179 i = pSHSearchMapInt(keys, values, 1, 100);
180 ok(i == -1, "Len 1 - bad key, expected -1, got %d\n", i);
182 /* Len = 0 => not found */
183 i = pSHSearchMapInt(keys, values, 0, keys[0]);
184 ok(i == -1, "Len 1 - passed len 0, expected -1, got %d\n", i);
186 /* 2 elements, len = 1 */
187 keys[1] = 98; values[1] = 102;
188 i = pSHSearchMapInt(keys, values, 1, keys[1]);
189 ok(i == -1, "Len 1 - array len 2, expected -1, got %d\n", i);
191 /* 2 elements, len = 2 */
192 i = pSHSearchMapInt(keys, values, 2, keys[1]);
193 ok(i == values[1], "Len 2, expected %d, got %d\n", values[1], i);
195 /* Searches forward */
196 keys[2] = 99; values[2] = 103;
197 i = pSHSearchMapInt(keys, values, 3, keys[0]);
198 ok(i == values[0], "Len 3, expected %d, got %d\n", values[0], i);
201 static void test_alloc_shared(void)
209 procid=GetCurrentProcessId();
210 hmem=pSHAllocShared(NULL,10,procid);
211 ok(hmem!=NULL,"SHAllocShared(NULL...) failed: %ld\n", GetLastError());
212 ret = pSHFreeShared(hmem, procid);
213 ok( ret, "SHFreeShared failed: %ld\n", GetLastError());
216 hmem=pSHAllocShared(&val,4,procid);
217 ok(hmem!=NULL,"SHAllocShared(NULL...) failed: %ld\n", GetLastError());
219 p=(int*)pSHLockShared(hmem,procid);
220 ok(p!=NULL,"SHLockShared failed: %ld\n", GetLastError());
222 ok(*p==val,"Wrong value in shared memory: %d instead of %d\n",*p,val);
223 ret = pSHUnlockShared(p);
224 ok( ret, "SHUnlockShared failed: %ld\n", GetLastError());
226 ret = pSHFreeShared(hmem, procid);
227 ok( ret, "SHFreeShared failed: %ld\n", GetLastError());
230 static void test_fdsa(void)
234 DWORD num_items; /* Number of elements inserted */
235 void *mem; /* Ptr to array */
236 DWORD blocks_alloced; /* Number of elements allocated */
237 BYTE inc; /* Number of elements to grow by when we need to expand */
238 BYTE block_size; /* Size in bytes of an element */
239 BYTE flags; /* Flags */
242 BOOL (WINAPI *pFDSA_Initialize)(DWORD block_size, DWORD inc, FDSA_info *info, void *mem,
244 BOOL (WINAPI *pFDSA_Destroy)(FDSA_info *info);
245 DWORD (WINAPI *pFDSA_InsertItem)(FDSA_info *info, DWORD where, void *block);
246 BOOL (WINAPI *pFDSA_DeleteItem)(FDSA_info *info, DWORD where);
249 int block_size = 10, init_blocks = 4, inc = 2;
253 pFDSA_Initialize = (void *)GetProcAddress(hShlwapi, (LPSTR)208);
254 pFDSA_Destroy = (void *)GetProcAddress(hShlwapi, (LPSTR)209);
255 pFDSA_InsertItem = (void *)GetProcAddress(hShlwapi, (LPSTR)210);
256 pFDSA_DeleteItem = (void *)GetProcAddress(hShlwapi, (LPSTR)211);
258 mem = HeapAlloc(GetProcessHeap(), 0, block_size * init_blocks);
259 memset(&info, 0, sizeof(info));
261 ok(pFDSA_Initialize(block_size, inc, &info, mem, init_blocks), "FDSA_Initialize rets FALSE\n");
262 ok(info.num_items == 0, "num_items = %ld\n", info.num_items);
263 ok(info.mem == mem, "mem = %p\n", info.mem);
264 ok(info.blocks_alloced == init_blocks, "blocks_alloced = %ld\n", info.blocks_alloced);
265 ok(info.inc == inc, "inc = %d\n", info.inc);
266 ok(info.block_size == block_size, "block_size = %d\n", info.block_size);
267 ok(info.flags == 0, "flags = %d\n", info.flags);
269 ret = pFDSA_InsertItem(&info, 1234, "1234567890");
270 ok(ret == 0, "ret = %ld\n", ret);
271 ok(info.num_items == 1, "num_items = %ld\n", info.num_items);
272 ok(info.mem == mem, "mem = %p\n", info.mem);
273 ok(info.blocks_alloced == init_blocks, "blocks_alloced = %ld\n", info.blocks_alloced);
274 ok(info.inc == inc, "inc = %d\n", info.inc);
275 ok(info.block_size == block_size, "block_size = %d\n", info.block_size);
276 ok(info.flags == 0, "flags = %d\n", info.flags);
278 ret = pFDSA_InsertItem(&info, 1234, "abcdefghij");
279 ok(ret == 1, "ret = %ld\n", ret);
281 ret = pFDSA_InsertItem(&info, 1, "klmnopqrst");
282 ok(ret == 1, "ret = %ld\n", ret);
284 ret = pFDSA_InsertItem(&info, 0, "uvwxyzABCD");
285 ok(ret == 0, "ret = %ld\n", ret);
286 ok(info.mem == mem, "mem = %p\n", info.mem);
287 ok(info.flags == 0, "flags = %d\n", info.flags);
289 /* This next InsertItem will cause shlwapi to allocate its own mem buffer */
290 ret = pFDSA_InsertItem(&info, 0, "EFGHIJKLMN");
291 ok(ret == 0, "ret = %ld\n", ret);
292 ok(info.mem != mem, "mem = %p\n", info.mem);
293 ok(info.blocks_alloced == init_blocks + inc, "blocks_alloced = %ld\n", info.blocks_alloced);
294 ok(info.flags == 0x1, "flags = %d\n", info.flags);
296 ok(!memcmp(info.mem, "EFGHIJKLMNuvwxyzABCD1234567890klmnopqrstabcdefghij", 50), "mem %s\n", (char*)info.mem);
298 ok(pFDSA_DeleteItem(&info, 2), "rets FALSE\n");
299 ok(info.mem != mem, "mem = %p\n", info.mem);
300 ok(info.blocks_alloced == init_blocks + inc, "blocks_alloced = %ld\n", info.blocks_alloced);
301 ok(info.flags == 0x1, "flags = %d\n", info.flags);
303 ok(!memcmp(info.mem, "EFGHIJKLMNuvwxyzABCDklmnopqrstabcdefghij", 40), "mem %s\n", (char*)info.mem);
305 ok(pFDSA_DeleteItem(&info, 3), "rets FALSE\n");
306 ok(info.mem != mem, "mem = %p\n", info.mem);
307 ok(info.blocks_alloced == init_blocks + inc, "blocks_alloced = %ld\n", info.blocks_alloced);
308 ok(info.flags == 0x1, "flags = %d\n", info.flags);
310 ok(!memcmp(info.mem, "EFGHIJKLMNuvwxyzABCDklmnopqrst", 30), "mem %s\n", (char*)info.mem);
312 ok(!pFDSA_DeleteItem(&info, 4), "does not ret FALSE\n");
314 /* As shlwapi has allocated memory internally, Destroy will ret FALSE */
315 ok(!pFDSA_Destroy(&info), "FDSA_Destroy does not ret FALSE\n");
318 /* When Initialize is called with inc = 0, set it to 1 */
319 ok(pFDSA_Initialize(block_size, 0, &info, mem, init_blocks), "FDSA_Initialize rets FALSE\n");
320 ok(info.inc == 1, "inc = %d\n", info.inc);
322 /* This time, because shlwapi hasn't had to allocate memory
323 internally, Destroy rets non-zero */
324 ok(pFDSA_Destroy(&info), "FDSA_Destroy rets FALSE\n");
327 HeapFree(GetProcessHeap(), 0, mem);
332 hShlwapi = LoadLibraryA("shlwapi.dll");
333 ok(hShlwapi != 0, "LoadLibraryA failed\n");
337 pGetAcceptLanguagesA = (void*)GetProcAddress(hShlwapi, (LPSTR)14);
338 pSHSearchMapInt = (void*)GetProcAddress(hShlwapi, (LPSTR)198);
339 pSHAllocShared=(void*)GetProcAddress(hShlwapi,(char*)7);
340 pSHLockShared=(void*)GetProcAddress(hShlwapi,(char*)8);
341 pSHUnlockShared=(void*)GetProcAddress(hShlwapi,(char*)9);
342 pSHFreeShared=(void*)GetProcAddress(hShlwapi,(char*)10);
344 test_GetAcceptLanguagesA();
345 test_SHSearchMapInt();
349 FreeLibrary(hShlwapi);