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()
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());
232 hShlwapi
= LoadLibraryA("shlwapi.dll");
233 ok(hShlwapi
!= 0, "LoadLibraryA failed\n");
237 pGetAcceptLanguagesA
= (void*)GetProcAddress(hShlwapi
, (LPSTR
)14);
238 pSHSearchMapInt
= (void*)GetProcAddress(hShlwapi
, (LPSTR
)198);
239 pSHAllocShared
=(void*)GetProcAddress(hShlwapi
,(char*)7);
240 pSHLockShared
=(void*)GetProcAddress(hShlwapi
,(char*)8);
241 pSHUnlockShared
=(void*)GetProcAddress(hShlwapi
,(char*)9);
242 pSHFreeShared
=(void*)GetProcAddress(hShlwapi
,(char*)10);
244 test_GetAcceptLanguagesA();
245 test_SHSearchMapInt();
247 FreeLibrary(hShlwapi
);