ntdll/tests: Add tests for RtlU(long|short)ByteSwap().
[wine.git] / dlls / ntdll / tests / rtl.c
blob1e5e8c2580c6528026ac0fd662a5e9d2cbe182a0
1 /* Unit test suite for Rtl* API functions
3 * Copyright 2003 Thomas Mertes
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 * NOTES
20 * We use function pointers here as there is no import library for NTDLL on
21 * windows.
24 #include <stdlib.h>
26 #include "ntdll_test.h"
27 #include "in6addr.h"
28 #include "inaddr.h"
29 #include "ip2string.h"
30 #include "wine/asm.h"
32 #ifndef __WINE_WINTERNL_H
34 typedef struct _RTL_HANDLE
36 struct _RTL_HANDLE * Next;
37 } RTL_HANDLE;
39 typedef struct _RTL_HANDLE_TABLE
41 ULONG MaxHandleCount;
42 ULONG HandleSize;
43 ULONG Unused[2];
44 PVOID NextFree;
45 PVOID FirstHandle;
46 PVOID ReservedMemory;
47 PVOID MaxHandle;
48 } RTL_HANDLE_TABLE;
50 #endif
52 /* avoid #include <winsock2.h> */
53 #undef htons
54 #ifdef WORDS_BIGENDIAN
55 #define htons(s) ((USHORT)(s))
56 #else /* WORDS_BIGENDIAN */
57 static inline USHORT __my_ushort_swap(USHORT s)
59 return (s >> 8) | (s << 8);
61 #define htons(s) __my_ushort_swap(s)
62 #endif /* WORDS_BIGENDIAN */
65 #ifdef __ASM_USE_FASTCALL_WRAPPER
66 extern ULONG WINAPI wrap_fastcall_func1( void *func, ULONG a );
67 __ASM_STDCALL_FUNC( wrap_fastcall_func1, 8,
68 "popl %ecx\n\t"
69 "popl %eax\n\t"
70 "xchgl (%esp),%ecx\n\t"
71 "jmp *%eax" )
72 #define call_fastcall_func1(func,a) wrap_fastcall_func1(func,a)
73 #else
74 #define call_fastcall_func1(func,a) func(a)
75 #endif
78 /* Function ptrs for ntdll calls */
79 static HMODULE hntdll = 0;
80 static VOID (WINAPI *pRtlMoveMemory)(LPVOID,LPCVOID,SIZE_T);
81 static VOID (WINAPI *pRtlFillMemory)(LPVOID,SIZE_T,BYTE);
82 static VOID (WINAPI *pRtlFillMemoryUlong)(LPVOID,SIZE_T,ULONG);
83 static VOID (WINAPI *pRtlZeroMemory)(LPVOID,SIZE_T);
84 static USHORT (FASTCALL *pRtlUshortByteSwap)(USHORT source);
85 static ULONG (FASTCALL *pRtlUlongByteSwap)(ULONG source);
86 static ULONGLONG (FASTCALL *pRtlUlonglongByteSwap)(ULONGLONG source);
87 static DWORD (WINAPI *pRtlGetThreadErrorMode)(void);
88 static NTSTATUS (WINAPI *pRtlSetThreadErrorMode)(DWORD, LPDWORD);
89 static NTSTATUS (WINAPI *pRtlIpv4AddressToStringExA)(const IN_ADDR *, USHORT, LPSTR, PULONG);
90 static NTSTATUS (WINAPI *pRtlIpv4StringToAddressExA)(PCSTR, BOOLEAN, IN_ADDR *, PUSHORT);
91 static NTSTATUS (WINAPI *pRtlIpv6AddressToStringExA)(struct in6_addr *, ULONG, USHORT, PCHAR, PULONG);
92 static NTSTATUS (WINAPI *pRtlIpv6StringToAddressExA)(PCSTR, struct in6_addr *, PULONG, PUSHORT);
93 static NTSTATUS (WINAPI *pRtlIpv6StringToAddressExW)(PCWSTR, struct in6_addr *, PULONG, PUSHORT);
94 static BOOL (WINAPI *pRtlIsCriticalSectionLocked)(CRITICAL_SECTION *);
95 static BOOL (WINAPI *pRtlIsCriticalSectionLockedByThread)(CRITICAL_SECTION *);
96 static NTSTATUS (WINAPI *pRtlInitializeCriticalSectionEx)(CRITICAL_SECTION *, ULONG, ULONG);
97 static NTSTATUS (WINAPI *pLdrEnumerateLoadedModules)(void *, void *, void *);
98 static NTSTATUS (WINAPI *pLdrRegisterDllNotification)(ULONG, PLDR_DLL_NOTIFICATION_FUNCTION, void *, void **);
99 static NTSTATUS (WINAPI *pLdrUnregisterDllNotification)(void *);
101 static HMODULE hkernel32 = 0;
102 static BOOL (WINAPI *pIsWow64Process)(HANDLE, PBOOL);
105 #define LEN 16
106 static const char* src_src = "This is a test!"; /* 16 bytes long, incl NUL */
107 static WCHAR ws2_32dllW[] = {'w','s','2','_','3','2','.','d','l','l',0};
108 static WCHAR nsidllW[] = {'n','s','i','.','d','l','l',0};
109 static WCHAR wintrustdllW[] = {'w','i','n','t','r','u','s','t','.','d','l','l',0};
110 static WCHAR crypt32dllW[] = {'c','r','y','p','t','3','2','.','d','l','l',0};
111 static ULONG src_aligned_block[4];
112 static ULONG dest_aligned_block[32];
113 static const char *src = (const char*)src_aligned_block;
114 static char* dest = (char*)dest_aligned_block;
115 const WCHAR *expected_dll = nsidllW;
117 static void InitFunctionPtrs(void)
119 hntdll = LoadLibraryA("ntdll.dll");
120 ok(hntdll != 0, "LoadLibrary failed\n");
121 if (hntdll) {
122 pRtlMoveMemory = (void *)GetProcAddress(hntdll, "RtlMoveMemory");
123 pRtlFillMemory = (void *)GetProcAddress(hntdll, "RtlFillMemory");
124 pRtlFillMemoryUlong = (void *)GetProcAddress(hntdll, "RtlFillMemoryUlong");
125 pRtlZeroMemory = (void *)GetProcAddress(hntdll, "RtlZeroMemory");
126 pRtlUshortByteSwap = (void *)GetProcAddress(hntdll, "RtlUshortByteSwap");
127 pRtlUlongByteSwap = (void *)GetProcAddress(hntdll, "RtlUlongByteSwap");
128 pRtlUlonglongByteSwap = (void *)GetProcAddress(hntdll, "RtlUlonglongByteSwap");
129 pRtlGetThreadErrorMode = (void *)GetProcAddress(hntdll, "RtlGetThreadErrorMode");
130 pRtlSetThreadErrorMode = (void *)GetProcAddress(hntdll, "RtlSetThreadErrorMode");
131 pRtlIpv4AddressToStringExA = (void *)GetProcAddress(hntdll, "RtlIpv4AddressToStringExA");
132 pRtlIpv4StringToAddressExA = (void *)GetProcAddress(hntdll, "RtlIpv4StringToAddressExA");
133 pRtlIpv6AddressToStringExA = (void *)GetProcAddress(hntdll, "RtlIpv6AddressToStringExA");
134 pRtlIpv6StringToAddressExA = (void *)GetProcAddress(hntdll, "RtlIpv6StringToAddressExA");
135 pRtlIpv6StringToAddressExW = (void *)GetProcAddress(hntdll, "RtlIpv6StringToAddressExW");
136 pRtlIsCriticalSectionLocked = (void *)GetProcAddress(hntdll, "RtlIsCriticalSectionLocked");
137 pRtlIsCriticalSectionLockedByThread = (void *)GetProcAddress(hntdll, "RtlIsCriticalSectionLockedByThread");
138 pRtlInitializeCriticalSectionEx = (void *)GetProcAddress(hntdll, "RtlInitializeCriticalSectionEx");
139 pLdrEnumerateLoadedModules = (void *)GetProcAddress(hntdll, "LdrEnumerateLoadedModules");
140 pLdrRegisterDllNotification = (void *)GetProcAddress(hntdll, "LdrRegisterDllNotification");
141 pLdrUnregisterDllNotification = (void *)GetProcAddress(hntdll, "LdrUnregisterDllNotification");
143 hkernel32 = LoadLibraryA("kernel32.dll");
144 ok(hkernel32 != 0, "LoadLibrary failed\n");
145 if (hkernel32) {
146 pIsWow64Process = (void *)GetProcAddress(hkernel32, "IsWow64Process");
148 strcpy((char*)src_aligned_block, src_src);
149 ok(strlen(src) == 15, "Source must be 16 bytes long!\n");
152 static void test_RtlQueryProcessDebugInformation(void)
154 DEBUG_BUFFER *buffer;
155 NTSTATUS status;
157 buffer = RtlCreateQueryDebugBuffer( 0, 0 );
158 ok( buffer != NULL, "RtlCreateQueryDebugBuffer returned NULL" );
160 status = RtlQueryProcessDebugInformation( GetCurrentThreadId(), PDI_HEAPS | PDI_HEAP_BLOCKS, buffer );
161 ok( status == STATUS_INVALID_CID, "RtlQueryProcessDebugInformation returned %lx\n", status );
163 status = RtlQueryProcessDebugInformation( GetCurrentProcessId(), PDI_HEAPS | PDI_HEAP_BLOCKS, buffer );
164 ok( !status, "RtlQueryProcessDebugInformation returned %lx\n", status );
166 status = RtlDestroyQueryDebugBuffer( buffer );
167 ok( !status, "RtlDestroyQueryDebugBuffer returned %lx\n", status );
170 #define COMP(str1,str2,cmplen,len) size = RtlCompareMemory(str1, str2, cmplen); \
171 ok(size == len, "Expected %Id, got %Id\n", size, (SIZE_T)len)
173 static void test_RtlCompareMemory(void)
175 SIZE_T size;
177 strcpy(dest, src);
179 COMP(src,src,0,0);
180 COMP(src,src,LEN,LEN);
181 dest[0] = 'x';
182 COMP(src,dest,LEN,0);
185 static void test_RtlCompareMemoryUlong(void)
187 ULONG a[10];
188 ULONG result;
190 a[0]= 0x0123;
191 a[1]= 0x4567;
192 a[2]= 0x89ab;
193 a[3]= 0xcdef;
194 result = RtlCompareMemoryUlong(a, 0, 0x0123);
195 ok(result == 0, "RtlCompareMemoryUlong(%p, 0, 0x0123) returns %lu, expected 0\n", a, result);
196 result = RtlCompareMemoryUlong(a, 3, 0x0123);
197 ok(result == 0, "RtlCompareMemoryUlong(%p, 3, 0x0123) returns %lu, expected 0\n", a, result);
198 result = RtlCompareMemoryUlong(a, 4, 0x0123);
199 ok(result == 4, "RtlCompareMemoryUlong(%p, 4, 0x0123) returns %lu, expected 4\n", a, result);
200 result = RtlCompareMemoryUlong(a, 5, 0x0123);
201 ok(result == 4, "RtlCompareMemoryUlong(%p, 5, 0x0123) returns %lu, expected 4\n", a, result);
202 result = RtlCompareMemoryUlong(a, 7, 0x0123);
203 ok(result == 4, "RtlCompareMemoryUlong(%p, 7, 0x0123) returns %lu, expected 4\n", a, result);
204 result = RtlCompareMemoryUlong(a, 8, 0x0123);
205 ok(result == 4, "RtlCompareMemoryUlong(%p, 8, 0x0123) returns %lu, expected 4\n", a, result);
206 result = RtlCompareMemoryUlong(a, 9, 0x0123);
207 ok(result == 4, "RtlCompareMemoryUlong(%p, 9, 0x0123) returns %lu, expected 4\n", a, result);
208 result = RtlCompareMemoryUlong(a, 4, 0x0127);
209 ok(result == 0, "RtlCompareMemoryUlong(%p, 4, 0x0127) returns %lu, expected 0\n", a, result);
210 result = RtlCompareMemoryUlong(a, 4, 0x7123);
211 ok(result == 0, "RtlCompareMemoryUlong(%p, 4, 0x7123) returns %lu, expected 0\n", a, result);
212 result = RtlCompareMemoryUlong(a, 16, 0x4567);
213 ok(result == 0, "RtlCompareMemoryUlong(%p, 16, 0x4567) returns %lu, expected 0\n", a, result);
215 a[1]= 0x0123;
216 result = RtlCompareMemoryUlong(a, 3, 0x0123);
217 ok(result == 0, "RtlCompareMemoryUlong(%p, 3, 0x0123) returns %lu, expected 0\n", a, result);
218 result = RtlCompareMemoryUlong(a, 4, 0x0123);
219 ok(result == 4, "RtlCompareMemoryUlong(%p, 4, 0x0123) returns %lu, expected 4\n", a, result);
220 result = RtlCompareMemoryUlong(a, 5, 0x0123);
221 ok(result == 4, "RtlCompareMemoryUlong(%p, 5, 0x0123) returns %lu, expected 4\n", a, result);
222 result = RtlCompareMemoryUlong(a, 7, 0x0123);
223 ok(result == 4, "RtlCompareMemoryUlong(%p, 7, 0x0123) returns %lu, expected 4\n", a, result);
224 result = RtlCompareMemoryUlong(a, 8, 0x0123);
225 ok(result == 8, "RtlCompareMemoryUlong(%p, 8, 0x0123) returns %lu, expected 8\n", a, result);
226 result = RtlCompareMemoryUlong(a, 9, 0x0123);
227 ok(result == 8, "RtlCompareMemoryUlong(%p, 9, 0x0123) returns %lu, expected 8\n", a, result);
230 #define COPY(len) memset(dest,0,sizeof(dest_aligned_block)); pRtlMoveMemory(dest, src, len)
231 #define CMP(str) ok(strcmp(dest,str) == 0, "Expected '%s', got '%s'\n", str, dest)
233 static void test_RtlMoveMemory(void)
235 if (!pRtlMoveMemory)
237 win_skip("RtlMoveMemory is not available\n");
238 return;
241 /* Length should be in bytes and not rounded. Use strcmp to ensure we
242 * didn't write past the end (it checks for the final NUL left by memset)
244 COPY(0); CMP("");
245 COPY(1); CMP("T");
246 COPY(2); CMP("Th");
247 COPY(3); CMP("Thi");
248 COPY(4); CMP("This");
249 COPY(5); CMP("This ");
250 COPY(6); CMP("This i");
251 COPY(7); CMP("This is");
252 COPY(8); CMP("This is ");
253 COPY(9); CMP("This is a");
255 /* Overlapping */
256 strcpy(dest, src); pRtlMoveMemory(dest, dest + 1, strlen(src) - 1);
257 CMP("his is a test!!");
258 strcpy(dest, src); pRtlMoveMemory(dest + 1, dest, strlen(src));
259 CMP("TThis is a test!");
262 #define FILL(len) memset(dest,0,sizeof(dest_aligned_block)); strcpy(dest, src); pRtlFillMemory(dest,len,'x')
264 static void test_RtlFillMemory(void)
266 if (!pRtlFillMemory)
268 win_skip("RtlFillMemory is not available\n");
269 return;
272 /* Length should be in bytes and not rounded. Use strcmp to ensure we
273 * didn't write past the end (the remainder of the string should match)
275 FILL(0); CMP("This is a test!");
276 FILL(1); CMP("xhis is a test!");
277 FILL(2); CMP("xxis is a test!");
278 FILL(3); CMP("xxxs is a test!");
279 FILL(4); CMP("xxxx is a test!");
280 FILL(5); CMP("xxxxxis a test!");
281 FILL(6); CMP("xxxxxxs a test!");
282 FILL(7); CMP("xxxxxxx a test!");
283 FILL(8); CMP("xxxxxxxxa test!");
284 FILL(9); CMP("xxxxxxxxx test!");
287 #define LFILL(len) memset(dest,0,sizeof(dest_aligned_block)); strcpy(dest, src); pRtlFillMemoryUlong(dest,len,val)
289 static void test_RtlFillMemoryUlong(void)
291 ULONG val = ('x' << 24) | ('x' << 16) | ('x' << 8) | 'x';
292 if (!pRtlFillMemoryUlong)
294 win_skip("RtlFillMemoryUlong is not available\n");
295 return;
298 /* Length should be in bytes and not rounded. Use strcmp to ensure we
299 * didn't write past the end (the remainder of the string should match)
301 LFILL(0); CMP("This is a test!");
302 LFILL(1); CMP("This is a test!");
303 LFILL(2); CMP("This is a test!");
304 LFILL(3); CMP("This is a test!");
305 LFILL(4); CMP("xxxx is a test!");
306 LFILL(5); CMP("xxxx is a test!");
307 LFILL(6); CMP("xxxx is a test!");
308 LFILL(7); CMP("xxxx is a test!");
309 LFILL(8); CMP("xxxxxxxxa test!");
310 LFILL(9); CMP("xxxxxxxxa test!");
313 #define ZERO(len) memset(dest,0,sizeof(dest_aligned_block)); strcpy(dest, src); pRtlZeroMemory(dest,len)
314 #define MCMP(str) ok(memcmp(dest,str,LEN) == 0, "Memcmp failed\n")
316 static void test_RtlZeroMemory(void)
318 if (!pRtlZeroMemory)
320 win_skip("RtlZeroMemory is not available\n");
321 return;
324 /* Length should be in bytes and not rounded. */
325 ZERO(0); MCMP("This is a test!");
326 ZERO(1); MCMP("\0his is a test!");
327 ZERO(2); MCMP("\0\0is is a test!");
328 ZERO(3); MCMP("\0\0\0s is a test!");
329 ZERO(4); MCMP("\0\0\0\0 is a test!");
330 ZERO(5); MCMP("\0\0\0\0\0is a test!");
331 ZERO(6); MCMP("\0\0\0\0\0\0s a test!");
332 ZERO(7); MCMP("\0\0\0\0\0\0\0 a test!");
333 ZERO(8); MCMP("\0\0\0\0\0\0\0\0a test!");
334 ZERO(9); MCMP("\0\0\0\0\0\0\0\0\0 test!");
337 static void test_RtlByteSwap(void)
339 ULONGLONG llresult;
340 ULONG lresult;
341 USHORT sresult;
343 #ifdef _WIN64
344 /* the Rtl*ByteSwap() are always inlined and not exported from ntdll on 64bit */
345 sresult = RtlUshortByteSwap( 0x1234 );
346 ok( 0x3412 == sresult,
347 "inlined RtlUshortByteSwap() returns 0x%x\n", sresult );
348 lresult = RtlUlongByteSwap( 0x87654321 );
349 ok( 0x21436587 == lresult,
350 "inlined RtlUlongByteSwap() returns 0x%lx\n", lresult );
351 llresult = RtlUlonglongByteSwap( 0x7654321087654321ull );
352 ok( 0x2143658710325476 == llresult,
353 "inlined RtlUlonglongByteSwap() returns %#I64x\n", llresult );
354 #else
355 ok( pRtlUshortByteSwap != NULL, "RtlUshortByteSwap is not available\n" );
356 if ( pRtlUshortByteSwap )
358 sresult = call_fastcall_func1( pRtlUshortByteSwap, 0x1234u );
359 ok( 0x3412u == sresult,
360 "ntdll.RtlUshortByteSwap() returns %#x\n", sresult );
363 ok( pRtlUlongByteSwap != NULL, "RtlUlongByteSwap is not available\n" );
364 if ( pRtlUlongByteSwap )
366 lresult = call_fastcall_func1( pRtlUlongByteSwap, 0x87654321ul );
367 ok( 0x21436587ul == lresult,
368 "ntdll.RtlUlongByteSwap() returns %#lx\n", lresult );
371 ok( pRtlUlonglongByteSwap != NULL, "RtlUlonglongByteSwap is not available\n");
372 if ( pRtlUlonglongByteSwap )
374 llresult = pRtlUlonglongByteSwap( 0x7654321087654321ull );
375 ok( 0x2143658710325476ull == llresult,
376 "ntdll.RtlUlonglongByteSwap() returns %#I64x\n", llresult );
378 #endif
382 static void test_RtlUniform(void)
384 ULONGLONG num;
385 ULONG seed;
386 ULONG seed_bak;
387 ULONG expected;
388 ULONG result;
391 * According to the documentation RtlUniform is using D.H. Lehmer's 1948
392 * algorithm. This algorithm is:
394 * seed = (seed * const_1 + const_2) % const_3;
396 * According to the documentation the random number is distributed over
397 * [0..MAXLONG]. Therefore const_3 is MAXLONG + 1:
399 * seed = (seed * const_1 + const_2) % (MAXLONG + 1);
401 * Because MAXLONG is 0x7fffffff (and MAXLONG + 1 is 0x80000000) the
402 * algorithm can be expressed without division as:
404 * seed = (seed * const_1 + const_2) & MAXLONG;
406 * To find out const_2 we just call RtlUniform with seed set to 0:
408 seed = 0;
409 expected = 0x7fffffc3;
410 result = RtlUniform(&seed);
411 ok(result == expected,
412 "RtlUniform(&seed (seed == 0)) returns %lx, expected %lx\n",
413 result, expected);
415 * The algorithm is now:
417 * seed = (seed * const_1 + 0x7fffffc3) & MAXLONG;
419 * To find out const_1 we can use:
421 * const_1 = RtlUniform(1) - 0x7fffffc3;
423 * If that does not work a search loop can try all possible values of
424 * const_1 and compare to the result to RtlUniform(1).
425 * This way we find out that const_1 is 0xffffffed.
427 * For seed = 1 the const_2 is 0x7fffffc4:
429 seed = 1;
430 expected = seed * 0xffffffed + 0x7fffffc3 + 1;
431 result = RtlUniform(&seed);
432 ok(result == expected,
433 "RtlUniform(&seed (seed == 1)) returns %lx, expected %lx\n",
434 result, expected);
436 * For seed = 2 the const_2 is 0x7fffffc3:
438 seed = 2;
439 expected = seed * 0xffffffed + 0x7fffffc3;
440 result = RtlUniform(&seed);
443 * Windows Vista uses different algorithms, so skip the rest of the tests
444 * until that is figured out. Trace output for the failures is about 10.5 MB!
447 if (result == 0x7fffff9f) {
448 skip("Most likely running on Windows Vista which uses a different algorithm\n");
449 return;
452 ok(result == expected,
453 "RtlUniform(&seed (seed == 2)) returns %lx, expected %lx\n",
454 result, expected);
457 * More tests show that if seed is odd the result must be incremented by 1:
459 seed = 3;
460 expected = seed * 0xffffffed + 0x7fffffc3 + (seed & 1);
461 result = RtlUniform(&seed);
462 ok(result == expected,
463 "RtlUniform(&seed (seed == 3)) returns %lx, expected %lx\n",
464 result, expected);
466 seed = 0x6bca1aa;
467 expected = seed * 0xffffffed + 0x7fffffc3;
468 result = RtlUniform(&seed);
469 ok(result == expected,
470 "RtlUniform(&seed (seed == 0x6bca1aa)) returns %lx, expected %lx\n",
471 result, expected);
473 seed = 0x6bca1ab;
474 expected = seed * 0xffffffed + 0x7fffffc3 + 1;
475 result = RtlUniform(&seed);
476 ok(result == expected,
477 "RtlUniform(&seed (seed == 0x6bca1ab)) returns %lx, expected %lx\n",
478 result, expected);
480 * When seed is 0x6bca1ac there is an exception:
482 seed = 0x6bca1ac;
483 expected = seed * 0xffffffed + 0x7fffffc3 + 2;
484 result = RtlUniform(&seed);
485 ok(result == expected,
486 "RtlUniform(&seed (seed == 0x6bca1ac)) returns %lx, expected %lx\n",
487 result, expected);
489 * Note that up to here const_3 is not used
490 * (the highest bit of the result is not set).
492 * Starting with 0x6bca1ad: If seed is even the result must be incremented by 1:
494 seed = 0x6bca1ad;
495 expected = (seed * 0xffffffed + 0x7fffffc3) & MAXLONG;
496 result = RtlUniform(&seed);
497 ok(result == expected,
498 "RtlUniform(&seed (seed == 0x6bca1ad)) returns %lx, expected %lx\n",
499 result, expected);
501 seed = 0x6bca1ae;
502 expected = (seed * 0xffffffed + 0x7fffffc3 + 1) & MAXLONG;
503 result = RtlUniform(&seed);
504 ok(result == expected,
505 "RtlUniform(&seed (seed == 0x6bca1ae)) returns %lx, expected %lx\n",
506 result, expected);
508 * There are several ranges where for odd or even seed the result must be
509 * incremented by 1. You can see this ranges in the following test.
511 * For a full test use one of the following loop heads:
513 * for (num = 0; num <= 0xffffffff; num++) {
514 * seed = num;
515 * ...
517 * seed = 0;
518 * for (num = 0; num <= 0xffffffff; num++) {
519 * ...
521 seed = 0;
522 for (num = 0; num <= 100000; num++) {
524 expected = seed * 0xffffffed + 0x7fffffc3;
525 if (seed < 0x6bca1ac) {
526 expected = expected + (seed & 1);
527 } else if (seed == 0x6bca1ac) {
528 expected = (expected + 2) & MAXLONG;
529 } else if (seed < 0xd79435c) {
530 expected = (expected + (~seed & 1)) & MAXLONG;
531 } else if (seed < 0x1435e50b) {
532 expected = expected + (seed & 1);
533 } else if (seed < 0x1af286ba) {
534 expected = (expected + (~seed & 1)) & MAXLONG;
535 } else if (seed < 0x21af2869) {
536 expected = expected + (seed & 1);
537 } else if (seed < 0x286bca18) {
538 expected = (expected + (~seed & 1)) & MAXLONG;
539 } else if (seed < 0x2f286bc7) {
540 expected = expected + (seed & 1);
541 } else if (seed < 0x35e50d77) {
542 expected = (expected + (~seed & 1)) & MAXLONG;
543 } else if (seed < 0x3ca1af26) {
544 expected = expected + (seed & 1);
545 } else if (seed < 0x435e50d5) {
546 expected = (expected + (~seed & 1)) & MAXLONG;
547 } else if (seed < 0x4a1af284) {
548 expected = expected + (seed & 1);
549 } else if (seed < 0x50d79433) {
550 expected = (expected + (~seed & 1)) & MAXLONG;
551 } else if (seed < 0x579435e2) {
552 expected = expected + (seed & 1);
553 } else if (seed < 0x5e50d792) {
554 expected = (expected + (~seed & 1)) & MAXLONG;
555 } else if (seed < 0x650d7941) {
556 expected = expected + (seed & 1);
557 } else if (seed < 0x6bca1af0) {
558 expected = (expected + (~seed & 1)) & MAXLONG;
559 } else if (seed < 0x7286bc9f) {
560 expected = expected + (seed & 1);
561 } else if (seed < 0x79435e4e) {
562 expected = (expected + (~seed & 1)) & MAXLONG;
563 } else if (seed < 0x7ffffffd) {
564 expected = expected + (seed & 1);
565 } else if (seed < 0x86bca1ac) {
566 expected = (expected + (~seed & 1)) & MAXLONG;
567 } else if (seed == 0x86bca1ac) {
568 expected = (expected + 1) & MAXLONG;
569 } else if (seed < 0x8d79435c) {
570 expected = expected + (seed & 1);
571 } else if (seed < 0x9435e50b) {
572 expected = (expected + (~seed & 1)) & MAXLONG;
573 } else if (seed < 0x9af286ba) {
574 expected = expected + (seed & 1);
575 } else if (seed < 0xa1af2869) {
576 expected = (expected + (~seed & 1)) & MAXLONG;
577 } else if (seed < 0xa86bca18) {
578 expected = expected + (seed & 1);
579 } else if (seed < 0xaf286bc7) {
580 expected = (expected + (~seed & 1)) & MAXLONG;
581 } else if (seed == 0xaf286bc7) {
582 expected = (expected + 2) & MAXLONG;
583 } else if (seed < 0xb5e50d77) {
584 expected = expected + (seed & 1);
585 } else if (seed < 0xbca1af26) {
586 expected = (expected + (~seed & 1)) & MAXLONG;
587 } else if (seed < 0xc35e50d5) {
588 expected = expected + (seed & 1);
589 } else if (seed < 0xca1af284) {
590 expected = (expected + (~seed & 1)) & MAXLONG;
591 } else if (seed < 0xd0d79433) {
592 expected = expected + (seed & 1);
593 } else if (seed < 0xd79435e2) {
594 expected = (expected + (~seed & 1)) & MAXLONG;
595 } else if (seed < 0xde50d792) {
596 expected = expected + (seed & 1);
597 } else if (seed < 0xe50d7941) {
598 expected = (expected + (~seed & 1)) & MAXLONG;
599 } else if (seed < 0xebca1af0) {
600 expected = expected + (seed & 1);
601 } else if (seed < 0xf286bc9f) {
602 expected = (expected + (~seed & 1)) & MAXLONG;
603 } else if (seed < 0xf9435e4e) {
604 expected = expected + (seed & 1);
605 } else if (seed < 0xfffffffd) {
606 expected = (expected + (~seed & 1)) & MAXLONG;
607 } else {
608 expected = expected + (seed & 1);
609 } /* if */
610 seed_bak = seed;
611 result = RtlUniform(&seed);
612 ok(result == expected,
613 "test: 0x%s RtlUniform(&seed (seed == %lx)) returns %lx, expected %lx\n",
614 wine_dbgstr_longlong(num), seed_bak, result, expected);
615 ok(seed == expected,
616 "test: 0x%s RtlUniform(&seed (seed == %lx)) sets seed to %lx, expected %lx\n",
617 wine_dbgstr_longlong(num), seed_bak, result, expected);
618 } /* for */
620 * Further investigation shows: In the different regions the highest bit
621 * is set or cleared when even or odd seeds need an increment by 1.
622 * This leads to a simplified algorithm:
624 * seed = seed * 0xffffffed + 0x7fffffc3;
625 * if (seed == 0xffffffff || seed == 0x7ffffffe) {
626 * seed = (seed + 2) & MAXLONG;
627 * } else if (seed == 0x7fffffff) {
628 * seed = 0;
629 * } else if ((seed & 0x80000000) == 0) {
630 * seed = seed + (~seed & 1);
631 * } else {
632 * seed = (seed + (seed & 1)) & MAXLONG;
635 * This is also the algorithm used for RtlUniform of wine (see dlls/ntdll/rtl.c).
637 * Now comes the funny part:
638 * It took me one weekend, to find the complicated algorithm and one day more,
639 * to find the simplified algorithm. Several weeks later I found out: The value
640 * MAXLONG (=0x7fffffff) is never returned, neither with the native function
641 * nor with the simplified algorithm. In reality the native function and our
642 * function return a random number distributed over [0..MAXLONG-1]. Note
643 * that this is different from what native documentation states [0..MAXLONG].
644 * Expressed with D.H. Lehmer's 1948 algorithm it looks like:
646 * seed = (seed * const_1 + const_2) % MAXLONG;
648 * Further investigations show that the real algorithm is:
650 * seed = (seed * 0x7fffffed + 0x7fffffc3) % MAXLONG;
652 * This is checked with the test below:
654 seed = 0;
655 for (num = 0; num <= 100000; num++) {
656 expected = (seed * 0x7fffffed + 0x7fffffc3) % 0x7fffffff;
657 seed_bak = seed;
658 result = RtlUniform(&seed);
659 ok(result == expected,
660 "test: 0x%s RtlUniform(&seed (seed == %lx)) returns %lx, expected %lx\n",
661 wine_dbgstr_longlong(num), seed_bak, result, expected);
662 ok(seed == expected,
663 "test: 0x%s RtlUniform(&seed (seed == %lx)) sets seed to %lx, expected %lx\n",
664 wine_dbgstr_longlong(num), seed_bak, result, expected);
665 } /* for */
667 * More tests show that RtlUniform does not return 0x7ffffffd for seed values
668 * in the range [0..MAXLONG-1]. Additionally 2 is returned twice. This shows
669 * that there is more than one cycle of generated randon numbers ...
674 static void test_RtlRandom(void)
676 int i, j;
677 ULONG seed;
678 ULONG res[512];
680 seed = 0;
681 for (i = 0; i < ARRAY_SIZE(res); i++)
683 res[i] = RtlRandom(&seed);
684 ok(seed != res[i], "%i: seed is same as res %lx\n", i, seed);
685 for (j = 0; j < i; j++)
686 ok(res[i] != res[j], "res[%i] (%lx) is same as res[%i] (%lx)\n", j, res[j], i, res[i]);
691 typedef struct {
692 ACCESS_MASK GrantedAccess;
693 ACCESS_MASK DesiredAccess;
694 BOOLEAN result;
695 } all_accesses_t;
697 static const all_accesses_t all_accesses[] = {
698 {0xFEDCBA76, 0xFEDCBA76, 1},
699 {0x00000000, 0xFEDCBA76, 0},
700 {0xFEDCBA76, 0x00000000, 1},
701 {0x00000000, 0x00000000, 1},
702 {0xFEDCBA76, 0xFEDCBA70, 1},
703 {0xFEDCBA70, 0xFEDCBA76, 0},
704 {0xFEDCBA76, 0xFEDC8A76, 1},
705 {0xFEDC8A76, 0xFEDCBA76, 0},
706 {0xFEDCBA76, 0xC8C4B242, 1},
707 {0xC8C4B242, 0xFEDCBA76, 0},
711 static void test_RtlAreAllAccessesGranted(void)
713 unsigned int test_num;
714 BOOLEAN result;
716 for (test_num = 0; test_num < ARRAY_SIZE(all_accesses); test_num++) {
717 result = RtlAreAllAccessesGranted(all_accesses[test_num].GrantedAccess,
718 all_accesses[test_num].DesiredAccess);
719 ok(all_accesses[test_num].result == result,
720 "(test %d): RtlAreAllAccessesGranted(%08lx, %08lx) returns %d, expected %d\n",
721 test_num, all_accesses[test_num].GrantedAccess,
722 all_accesses[test_num].DesiredAccess,
723 result, all_accesses[test_num].result);
724 } /* for */
728 typedef struct {
729 ACCESS_MASK GrantedAccess;
730 ACCESS_MASK DesiredAccess;
731 BOOLEAN result;
732 } any_accesses_t;
734 static const any_accesses_t any_accesses[] = {
735 {0xFEDCBA76, 0xFEDCBA76, 1},
736 {0x00000000, 0xFEDCBA76, 0},
737 {0xFEDCBA76, 0x00000000, 0},
738 {0x00000000, 0x00000000, 0},
739 {0xFEDCBA76, 0x01234589, 0},
740 {0x00040000, 0xFEDCBA76, 1},
741 {0x00040000, 0xFED8BA76, 0},
742 {0xFEDCBA76, 0x00040000, 1},
743 {0xFED8BA76, 0x00040000, 0},
747 static void test_RtlAreAnyAccessesGranted(void)
749 unsigned int test_num;
750 BOOLEAN result;
752 for (test_num = 0; test_num < ARRAY_SIZE(any_accesses); test_num++) {
753 result = RtlAreAnyAccessesGranted(any_accesses[test_num].GrantedAccess,
754 any_accesses[test_num].DesiredAccess);
755 ok(any_accesses[test_num].result == result,
756 "(test %d): RtlAreAnyAccessesGranted(%08lx, %08lx) returns %d, expected %d\n",
757 test_num, any_accesses[test_num].GrantedAccess,
758 any_accesses[test_num].DesiredAccess,
759 result, any_accesses[test_num].result);
760 } /* for */
763 static void test_RtlComputeCrc32(void)
765 DWORD crc = 0;
767 crc = RtlComputeCrc32(crc, (const BYTE *)src, LEN);
768 ok(crc == 0x40861dc2,"Expected 0x40861dc2, got %8lx\n", crc);
772 typedef struct MY_HANDLE
774 RTL_HANDLE RtlHandle;
775 void * MyValue;
776 } MY_HANDLE;
778 static inline void RtlpMakeHandleAllocated(RTL_HANDLE * Handle)
780 ULONG_PTR *AllocatedBit = (ULONG_PTR *)(&Handle->Next);
781 *AllocatedBit = *AllocatedBit | 1;
784 static void test_HandleTables(void)
786 BOOLEAN result;
787 NTSTATUS status;
788 ULONG Index;
789 MY_HANDLE * MyHandle;
790 RTL_HANDLE_TABLE HandleTable;
792 RtlInitializeHandleTable(0x3FFF, sizeof(MY_HANDLE), &HandleTable);
793 MyHandle = (MY_HANDLE *)RtlAllocateHandle(&HandleTable, &Index);
794 ok(MyHandle != NULL, "RtlAllocateHandle failed\n");
795 RtlpMakeHandleAllocated(&MyHandle->RtlHandle);
796 MyHandle = NULL;
797 result = RtlIsValidIndexHandle(&HandleTable, Index, (RTL_HANDLE **)&MyHandle);
798 ok(result, "Handle %p wasn't valid\n", MyHandle);
799 result = RtlFreeHandle(&HandleTable, &MyHandle->RtlHandle);
800 ok(result, "Couldn't free handle %p\n", MyHandle);
801 status = RtlDestroyHandleTable(&HandleTable);
802 ok(status == STATUS_SUCCESS, "RtlDestroyHandleTable failed with error 0x%08lx\n", status);
805 static void test_RtlAllocateAndInitializeSid(void)
807 NTSTATUS ret;
808 SID_IDENTIFIER_AUTHORITY sia = {{ 1, 2, 3, 4, 5, 6 }};
809 PSID psid;
811 ret = RtlAllocateAndInitializeSid(&sia, 0, 1, 2, 3, 4, 5, 6, 7, 8, &psid);
812 ok(!ret, "RtlAllocateAndInitializeSid error %08lx\n", ret);
813 ret = RtlFreeSid(psid);
814 ok(!ret, "RtlFreeSid error %08lx\n", ret);
816 /* these tests crash on XP */
817 if (0)
819 RtlAllocateAndInitializeSid(NULL, 0, 1, 2, 3, 4, 5, 6, 7, 8, &psid);
820 RtlAllocateAndInitializeSid(&sia, 0, 1, 2, 3, 4, 5, 6, 7, 8, NULL);
823 ret = RtlAllocateAndInitializeSid(&sia, 9, 1, 2, 3, 4, 5, 6, 7, 8, &psid);
824 ok(ret == STATUS_INVALID_SID, "wrong error %08lx\n", ret);
827 static void test_RtlDeleteTimer(void)
829 NTSTATUS ret;
831 ret = RtlDeleteTimer(NULL, NULL, NULL);
832 ok(ret == STATUS_INVALID_PARAMETER_1 ||
833 ret == STATUS_INVALID_PARAMETER, /* W2K */
834 "expected STATUS_INVALID_PARAMETER_1 or STATUS_INVALID_PARAMETER, got %lx\n", ret);
837 static void test_RtlThreadErrorMode(void)
839 DWORD oldmode;
840 BOOL is_wow64;
841 DWORD mode;
842 NTSTATUS status;
844 if (!pRtlGetThreadErrorMode || !pRtlSetThreadErrorMode)
846 win_skip("RtlGetThreadErrorMode and/or RtlSetThreadErrorMode not available\n");
847 return;
850 if (!pIsWow64Process || !pIsWow64Process(GetCurrentProcess(), &is_wow64))
851 is_wow64 = FALSE;
853 oldmode = pRtlGetThreadErrorMode();
855 status = pRtlSetThreadErrorMode(0x70, &mode);
856 ok(status == STATUS_SUCCESS ||
857 status == STATUS_WAIT_1, /* Vista */
858 "RtlSetThreadErrorMode failed with error 0x%08lx\n", status);
859 ok(mode == oldmode,
860 "RtlSetThreadErrorMode returned mode 0x%lx, expected 0x%lx\n",
861 mode, oldmode);
862 ok(pRtlGetThreadErrorMode() == 0x70,
863 "RtlGetThreadErrorMode returned 0x%lx, expected 0x%x\n", mode, 0x70);
864 if (!is_wow64)
866 ok(NtCurrentTeb()->HardErrorDisabled == 0x70,
867 "The TEB contains 0x%lx, expected 0x%x\n",
868 NtCurrentTeb()->HardErrorDisabled, 0x70);
871 status = pRtlSetThreadErrorMode(0, &mode);
872 ok(status == STATUS_SUCCESS ||
873 status == STATUS_WAIT_1, /* Vista */
874 "RtlSetThreadErrorMode failed with error 0x%08lx\n", status);
875 ok(mode == 0x70,
876 "RtlSetThreadErrorMode returned mode 0x%lx, expected 0x%x\n",
877 mode, 0x70);
878 ok(pRtlGetThreadErrorMode() == 0,
879 "RtlGetThreadErrorMode returned 0x%lx, expected 0x%x\n", mode, 0);
880 if (!is_wow64)
882 ok(NtCurrentTeb()->HardErrorDisabled == 0,
883 "The TEB contains 0x%lx, expected 0x%x\n",
884 NtCurrentTeb()->HardErrorDisabled, 0);
887 for (mode = 1; mode; mode <<= 1)
889 status = pRtlSetThreadErrorMode(mode, NULL);
890 if (mode & 0x70)
891 ok(status == STATUS_SUCCESS ||
892 status == STATUS_WAIT_1, /* Vista */
893 "RtlSetThreadErrorMode(%lx,NULL) failed with error 0x%08lx\n",
894 mode, status);
895 else
896 ok(status == STATUS_INVALID_PARAMETER_1,
897 "RtlSetThreadErrorMode(%lx,NULL) returns 0x%08lx, "
898 "expected STATUS_INVALID_PARAMETER_1\n",
899 mode, status);
902 pRtlSetThreadErrorMode(oldmode, NULL);
905 static void test_LdrProcessRelocationBlock(void)
907 IMAGE_BASE_RELOCATION *ret;
908 USHORT reloc;
909 DWORD addr32;
910 SHORT addr16;
912 addr32 = 0x50005;
913 reloc = IMAGE_REL_BASED_HIGHLOW<<12;
914 ret = LdrProcessRelocationBlock(&addr32, 1, &reloc, 0x500050);
915 ok((USHORT*)ret == &reloc+1, "ret = %p, expected %p\n", ret, &reloc+1);
916 ok(addr32 == 0x550055, "addr32 = %lx, expected 0x550055\n", addr32);
918 addr16 = 0x505;
919 reloc = IMAGE_REL_BASED_HIGH<<12;
920 ret = LdrProcessRelocationBlock(&addr16, 1, &reloc, 0x500060);
921 ok((USHORT*)ret == &reloc+1, "ret = %p, expected %p\n", ret, &reloc+1);
922 ok(addr16 == 0x555, "addr16 = %x, expected 0x555\n", addr16);
924 addr16 = 0x505;
925 reloc = IMAGE_REL_BASED_LOW<<12;
926 ret = LdrProcessRelocationBlock(&addr16, 1, &reloc, 0x500060);
927 ok((USHORT*)ret == &reloc+1, "ret = %p, expected %p\n", ret, &reloc+1);
928 ok(addr16 == 0x565, "addr16 = %x, expected 0x565\n", addr16);
931 static void test_RtlIpv4AddressToString(void)
933 CHAR buffer[20];
934 CHAR *res;
935 IN_ADDR ip;
936 DWORD_PTR len;
938 ip.S_un.S_un_b.s_b1 = 1;
939 ip.S_un.S_un_b.s_b2 = 2;
940 ip.S_un.S_un_b.s_b3 = 3;
941 ip.S_un.S_un_b.s_b4 = 4;
943 memset(buffer, '#', sizeof(buffer) - 1);
944 buffer[sizeof(buffer) -1] = 0;
945 res = RtlIpv4AddressToStringA(&ip, buffer);
946 len = strlen(buffer);
947 ok(res == (buffer + len), "got %p with '%s' (expected %p)\n", res, buffer, buffer + len);
949 res = RtlIpv4AddressToStringA(&ip, NULL);
950 ok( (res == (char *)~0) ||
951 broken(res == (char *)len), /* XP and w2003 */
952 "got %p (expected ~0)\n", res);
954 if (0) {
955 /* this crashes in windows */
956 memset(buffer, '#', sizeof(buffer) - 1);
957 buffer[sizeof(buffer) -1] = 0;
958 res = RtlIpv4AddressToStringA(NULL, buffer);
959 trace("got %p with '%s'\n", res, buffer);
962 if (0) {
963 /* this crashes in windows */
964 res = RtlIpv4AddressToStringA(NULL, NULL);
965 trace("got %p\n", res);
969 static void test_RtlIpv4AddressToStringEx(void)
971 CHAR ip_1234[] = "1.2.3.4";
972 CHAR ip_1234_80[] = "1.2.3.4:80";
973 LPSTR expect;
974 CHAR buffer[30];
975 NTSTATUS res;
976 IN_ADDR ip;
977 ULONG size;
978 DWORD used;
979 USHORT port;
981 if (!pRtlIpv4AddressToStringExA)
983 win_skip("RtlIpv4AddressToStringExA not available\n");
984 return;
987 ip.S_un.S_un_b.s_b1 = 1;
988 ip.S_un.S_un_b.s_b2 = 2;
989 ip.S_un.S_un_b.s_b3 = 3;
990 ip.S_un.S_un_b.s_b4 = 4;
992 port = htons(80);
993 expect = ip_1234_80;
995 size = sizeof(buffer);
996 memset(buffer, '#', sizeof(buffer) - 1);
997 buffer[sizeof(buffer) -1] = 0;
998 res = pRtlIpv4AddressToStringExA(&ip, port, buffer, &size);
999 used = strlen(buffer);
1000 ok( (res == STATUS_SUCCESS) &&
1001 (size == strlen(expect) + 1) && !strcmp(buffer, expect),
1002 "got 0x%lx and size %ld with '%s'\n", res, size, buffer);
1004 size = used + 1;
1005 memset(buffer, '#', sizeof(buffer) - 1);
1006 buffer[sizeof(buffer) -1] = 0;
1007 res = pRtlIpv4AddressToStringExA(&ip, port, buffer, &size);
1008 ok( (res == STATUS_SUCCESS) &&
1009 (size == strlen(expect) + 1) && !strcmp(buffer, expect),
1010 "got 0x%lx and size %ld with '%s'\n", res, size, buffer);
1012 size = used;
1013 memset(buffer, '#', sizeof(buffer) - 1);
1014 buffer[sizeof(buffer) -1] = 0;
1015 res = pRtlIpv4AddressToStringExA(&ip, port, buffer, &size);
1016 ok( (res == STATUS_INVALID_PARAMETER) && (size == used + 1),
1017 "got 0x%lx and %ld with '%s' (expected STATUS_INVALID_PARAMETER and %ld)\n",
1018 res, size, buffer, used + 1);
1020 size = used - 1;
1021 memset(buffer, '#', sizeof(buffer) - 1);
1022 buffer[sizeof(buffer) -1] = 0;
1023 res = pRtlIpv4AddressToStringExA(&ip, port, buffer, &size);
1024 ok( (res == STATUS_INVALID_PARAMETER) && (size == used + 1),
1025 "got 0x%lx and %ld with '%s' (expected STATUS_INVALID_PARAMETER and %ld)\n",
1026 res, size, buffer, used + 1);
1029 /* to get only the ip, use 0 as port */
1030 port = 0;
1031 expect = ip_1234;
1033 size = sizeof(buffer);
1034 memset(buffer, '#', sizeof(buffer) - 1);
1035 buffer[sizeof(buffer) -1] = 0;
1036 res = pRtlIpv4AddressToStringExA(&ip, port, buffer, &size);
1037 used = strlen(buffer);
1038 ok( (res == STATUS_SUCCESS) &&
1039 (size == strlen(expect) + 1) && !strcmp(buffer, expect),
1040 "got 0x%lx and size %ld with '%s'\n", res, size, buffer);
1042 size = used + 1;
1043 memset(buffer, '#', sizeof(buffer) - 1);
1044 buffer[sizeof(buffer) -1] = 0;
1045 res = pRtlIpv4AddressToStringExA(&ip, port, buffer, &size);
1046 ok( (res == STATUS_SUCCESS) &&
1047 (size == strlen(expect) + 1) && !strcmp(buffer, expect),
1048 "got 0x%lx and size %ld with '%s'\n", res, size, buffer);
1050 size = used;
1051 memset(buffer, '#', sizeof(buffer) - 1);
1052 buffer[sizeof(buffer) -1] = 0;
1053 res = pRtlIpv4AddressToStringExA(&ip, port, buffer, &size);
1054 ok( (res == STATUS_INVALID_PARAMETER) && (size == used + 1),
1055 "got 0x%lx and %ld with '%s' (expected STATUS_INVALID_PARAMETER and %ld)\n",
1056 res, size, buffer, used + 1);
1058 size = used - 1;
1059 memset(buffer, '#', sizeof(buffer) - 1);
1060 buffer[sizeof(buffer) -1] = 0;
1061 res = pRtlIpv4AddressToStringExA(&ip, port, buffer, &size);
1062 ok( (res == STATUS_INVALID_PARAMETER) && (size == used + 1),
1063 "got 0x%lx and %ld with '%s' (expected STATUS_INVALID_PARAMETER and %ld)\n",
1064 res, size, buffer, used + 1);
1067 /* parameters are checked */
1068 memset(buffer, '#', sizeof(buffer) - 1);
1069 buffer[sizeof(buffer) -1] = 0;
1070 res = pRtlIpv4AddressToStringExA(&ip, 0, buffer, NULL);
1071 ok(res == STATUS_INVALID_PARAMETER,
1072 "got 0x%lx with '%s' (expected STATUS_INVALID_PARAMETER)\n", res, buffer);
1074 size = sizeof(buffer);
1075 res = pRtlIpv4AddressToStringExA(&ip, 0, NULL, &size);
1076 ok( res == STATUS_INVALID_PARAMETER,
1077 "got 0x%lx and size %ld (expected STATUS_INVALID_PARAMETER)\n", res, size);
1079 size = sizeof(buffer);
1080 memset(buffer, '#', sizeof(buffer) - 1);
1081 buffer[sizeof(buffer) -1] = 0;
1082 res = pRtlIpv4AddressToStringExA(NULL, 0, buffer, &size);
1083 ok( res == STATUS_INVALID_PARAMETER,
1084 "got 0x%lx and size %ld with '%s' (expected STATUS_INVALID_PARAMETER)\n",
1085 res, size, buffer);
1088 static struct
1090 PCSTR address;
1091 NTSTATUS res;
1092 int terminator_offset;
1093 int ip[4];
1094 enum { normal_4, strict_diff_4 = 1, ex_fail_4 = 2 } flags;
1095 NTSTATUS res_strict;
1096 int terminator_offset_strict;
1097 int ip_strict[4];
1098 } ipv4_tests[] =
1100 { "", STATUS_INVALID_PARAMETER, 0, { -1 } },
1101 { " ", STATUS_INVALID_PARAMETER, 0, { -1 } },
1102 { "1.1.1.1", STATUS_SUCCESS, 7, { 1, 1, 1, 1 } },
1103 { "0.0.0.0", STATUS_SUCCESS, 7, { 0, 0, 0, 0 } },
1104 { "255.255.255.255", STATUS_SUCCESS, 15, { 255, 255, 255, 255 } },
1105 { "255.255.255.255:123", STATUS_SUCCESS, 15, { 255, 255, 255, 255 } },
1106 { "255.255.255.256", STATUS_INVALID_PARAMETER, 15, { -1 } },
1107 { "255.255.255.4294967295", STATUS_INVALID_PARAMETER, 22, { -1 } },
1108 { "255.255.255.4294967296", STATUS_INVALID_PARAMETER, 21, { -1 } },
1109 { "255.255.255.4294967297", STATUS_INVALID_PARAMETER, 21, { -1 } },
1110 { "a", STATUS_INVALID_PARAMETER, 0, { -1 } },
1111 { "1.1.1.0xaA", STATUS_SUCCESS, 10, { 1, 1, 1, 170 }, strict_diff_4,
1112 STATUS_INVALID_PARAMETER, 8, { -1 } },
1113 { "1.1.1.0XaA", STATUS_SUCCESS, 10, { 1, 1, 1, 170 }, strict_diff_4,
1114 STATUS_INVALID_PARAMETER, 8, { -1 } },
1115 { "1.1.1.0x", STATUS_INVALID_PARAMETER, 8, { -1 } },
1116 { "1.1.1.0xff", STATUS_SUCCESS, 10, { 1, 1, 1, 255 }, strict_diff_4,
1117 STATUS_INVALID_PARAMETER, 8, { -1 } },
1118 { "1.1.1.0x100", STATUS_INVALID_PARAMETER, 11, { -1 }, strict_diff_4,
1119 STATUS_INVALID_PARAMETER, 8, { -1 } },
1120 { "1.1.1.0xffffffff", STATUS_INVALID_PARAMETER, 16, { -1 }, strict_diff_4,
1121 STATUS_INVALID_PARAMETER, 8, { -1 } },
1122 { "1.1.1.0x100000000", STATUS_INVALID_PARAMETER, 16, { -1, 0, 0, 0 }, strict_diff_4,
1123 STATUS_INVALID_PARAMETER, 8, { -1 } },
1124 { "1.1.1.010", STATUS_SUCCESS, 9, { 1, 1, 1, 8 }, strict_diff_4,
1125 STATUS_INVALID_PARAMETER, 7, { -1 } },
1126 { "1.1.1.00", STATUS_SUCCESS, 8, { 1, 1, 1, 0 }, strict_diff_4,
1127 STATUS_INVALID_PARAMETER, 7, { -1 } },
1128 { "1.1.1.007", STATUS_SUCCESS, 9, { 1, 1, 1, 7 }, strict_diff_4,
1129 STATUS_INVALID_PARAMETER, 7, { -1 } },
1130 { "1.1.1.08", STATUS_INVALID_PARAMETER, 7, { -1 } },
1131 { "1.1.1.008", STATUS_SUCCESS, 8, { 1, 1, 1, 0 }, strict_diff_4 | ex_fail_4,
1132 STATUS_INVALID_PARAMETER, 7, { -1 } },
1133 { "1.1.1.0a", STATUS_SUCCESS, 7, { 1, 1, 1, 0 }, ex_fail_4 },
1134 { "1.1.1.0o10", STATUS_SUCCESS, 7, { 1, 1, 1, 0 }, ex_fail_4 },
1135 { "1.1.1.0b10", STATUS_SUCCESS, 7, { 1, 1, 1, 0 }, ex_fail_4 },
1136 { "1.1.1.-2", STATUS_INVALID_PARAMETER, 6, { -1 } },
1137 { "1", STATUS_SUCCESS, 1, { 0, 0, 0, 1 }, strict_diff_4,
1138 STATUS_INVALID_PARAMETER, 1, { -1 } },
1139 { "-1", STATUS_INVALID_PARAMETER, 0, { -1 } },
1140 { "1.2", STATUS_SUCCESS, 3, { 1, 0, 0, 2 }, strict_diff_4,
1141 STATUS_INVALID_PARAMETER, 3, { -1 } },
1142 { "1000.2000", STATUS_INVALID_PARAMETER, 9, { -1 } },
1143 { "1.2.", STATUS_INVALID_PARAMETER, 4, { -1 } },
1144 { "1..2", STATUS_INVALID_PARAMETER, 3, { -1 } },
1145 { "1...2", STATUS_INVALID_PARAMETER, 3, { -1 } },
1146 { "1.2.3", STATUS_SUCCESS, 5, { 1, 2, 0, 3 }, strict_diff_4,
1147 STATUS_INVALID_PARAMETER, 5, { -1 } },
1148 { "1.2.3.", STATUS_INVALID_PARAMETER, 6, { -1 } },
1149 { "203569230", STATUS_SUCCESS, 9, { 12, 34, 56, 78 }, strict_diff_4,
1150 STATUS_INVALID_PARAMETER, 9, { -1 } },
1151 { "1.223756", STATUS_SUCCESS, 8, { 1, 3, 106, 12 }, strict_diff_4,
1152 STATUS_INVALID_PARAMETER, 8, { -1 } },
1153 { "3.4.756", STATUS_SUCCESS, 7, { 3, 4, 2, 244 }, strict_diff_4,
1154 STATUS_INVALID_PARAMETER, 7, { -1 } },
1155 { "756.3.4", STATUS_INVALID_PARAMETER, 7, { -1 } },
1156 { "3.756.4", STATUS_INVALID_PARAMETER, 7, { -1 } },
1157 { "3.4.756.1", STATUS_INVALID_PARAMETER, 9, { -1 } },
1158 { "3.4.65536", STATUS_INVALID_PARAMETER, 9, { -1 } },
1159 { "3.4.5.6.7", STATUS_INVALID_PARAMETER, 7, { -1 } },
1160 { "3.4.5.+6", STATUS_INVALID_PARAMETER, 6, { -1 } },
1161 { " 3.4.5.6", STATUS_INVALID_PARAMETER, 0, { -1 } },
1162 { "\t3.4.5.6", STATUS_INVALID_PARAMETER, 0, { -1 } },
1163 { "3.4.5.6 ", STATUS_SUCCESS, 7, { 3, 4, 5, 6 }, ex_fail_4 },
1164 { "3. 4.5.6", STATUS_INVALID_PARAMETER, 2, { -1 } },
1165 { ".", STATUS_INVALID_PARAMETER, 1, { -1 } },
1166 { "..", STATUS_INVALID_PARAMETER, 1, { -1 } },
1167 { "1.", STATUS_INVALID_PARAMETER, 2, { -1 } },
1168 { "1..", STATUS_INVALID_PARAMETER, 3, { -1 } },
1169 { ".1", STATUS_INVALID_PARAMETER, 1, { -1 } },
1170 { ".1.", STATUS_INVALID_PARAMETER, 1, { -1 } },
1171 { ".1.2.3", STATUS_INVALID_PARAMETER, 1, { -1 } },
1172 { ".1.2.3.4", STATUS_INVALID_PARAMETER, 1, { -1 } },
1173 { "0.1.2.3", STATUS_SUCCESS, 7, { 0, 1, 2, 3 } },
1174 { "0.1.2.3.", STATUS_INVALID_PARAMETER, 7, { -1 } },
1175 { "[0.1.2.3]", STATUS_INVALID_PARAMETER, 0, { -1 } },
1176 { "0x00010203", STATUS_SUCCESS, 10, { 0, 1, 2, 3 }, strict_diff_4,
1177 STATUS_INVALID_PARAMETER, 2, { -1 } },
1178 { "0X00010203", STATUS_SUCCESS, 10, { 0, 1, 2, 3 }, strict_diff_4,
1179 STATUS_INVALID_PARAMETER, 2, { -1 } },
1180 { "0x1234", STATUS_SUCCESS, 6, { 0, 0, 18, 52 }, strict_diff_4,
1181 STATUS_INVALID_PARAMETER, 2, { -1 } },
1182 { "0x123456789", STATUS_SUCCESS, 11, { 35, 69, 103, 137 }, strict_diff_4,
1183 STATUS_INVALID_PARAMETER, 2, { -1 } },
1184 { "0x00010Q03", STATUS_SUCCESS, 7, { 0, 0, 0, 16 }, strict_diff_4 | ex_fail_4,
1185 STATUS_INVALID_PARAMETER, 2, { -1 } },
1186 { "x00010203", STATUS_INVALID_PARAMETER, 0, { -1 } },
1187 { "1234BEEF", STATUS_SUCCESS, 4, { 0, 0, 4, 210 }, strict_diff_4 | ex_fail_4,
1188 STATUS_INVALID_PARAMETER, 4, { -1 } },
1189 { "017700000001", STATUS_SUCCESS, 12, { 127, 0, 0, 1 }, strict_diff_4,
1190 STATUS_INVALID_PARAMETER, 1, { -1 } },
1191 { "0777", STATUS_SUCCESS, 4, { 0, 0, 1, 255 }, strict_diff_4,
1192 STATUS_INVALID_PARAMETER, 1, { -1 } },
1193 { "::1", STATUS_INVALID_PARAMETER, 0, { -1 } },
1194 { ":1", STATUS_INVALID_PARAMETER, 0, { -1 } },
1197 static void init_ip4(IN_ADDR* addr, const int src[4])
1199 if (!src || src[0] == -1)
1201 addr->S_un.S_addr = 0xabababab;
1203 else
1205 addr->S_un.S_un_b.s_b1 = src[0];
1206 addr->S_un.S_un_b.s_b2 = src[1];
1207 addr->S_un.S_un_b.s_b3 = src[2];
1208 addr->S_un.S_un_b.s_b4 = src[3];
1212 static void test_RtlIpv4StringToAddress(void)
1214 NTSTATUS res;
1215 IN_ADDR ip, expected_ip;
1216 PCSTR terminator;
1217 CHAR dummy;
1218 int i;
1220 if (0)
1222 /* leaving either parameter NULL crashes on Windows */
1223 res = RtlIpv4StringToAddressA(NULL, FALSE, &terminator, &ip);
1224 res = RtlIpv4StringToAddressA("1.1.1.1", FALSE, NULL, &ip);
1225 res = RtlIpv4StringToAddressA("1.1.1.1", FALSE, &terminator, NULL);
1226 /* same for the wide char version */
1228 res = RtlIpv4StringToAddressW(NULL, FALSE, &terminatorW, &ip);
1229 res = RtlIpv4StringToAddressW(L"1.1.1.1", FALSE, NULL, &ip);
1230 res = RtlIpv4StringToAddressW(L"1.1.1.1", FALSE, &terminatorW, NULL);
1234 for (i = 0; i < ARRAY_SIZE(ipv4_tests); i++)
1236 /* non-strict */
1237 terminator = &dummy;
1238 ip.S_un.S_addr = 0xabababab;
1239 res = RtlIpv4StringToAddressA(ipv4_tests[i].address, FALSE, &terminator, &ip);
1240 ok(res == ipv4_tests[i].res,
1241 "[%s] res = 0x%08lx, expected 0x%08lx\n",
1242 ipv4_tests[i].address, res, ipv4_tests[i].res);
1243 ok(terminator == ipv4_tests[i].address + ipv4_tests[i].terminator_offset,
1244 "[%s] terminator = %p, expected %p\n",
1245 ipv4_tests[i].address, terminator, ipv4_tests[i].address + ipv4_tests[i].terminator_offset);
1247 init_ip4(&expected_ip, ipv4_tests[i].ip);
1248 ok(ip.S_un.S_addr == expected_ip.S_un.S_addr,
1249 "[%s] ip = %08lx, expected %08lx\n",
1250 ipv4_tests[i].address, ip.S_un.S_addr, expected_ip.S_un.S_addr);
1252 if (!(ipv4_tests[i].flags & strict_diff_4))
1254 ipv4_tests[i].res_strict = ipv4_tests[i].res;
1255 ipv4_tests[i].terminator_offset_strict = ipv4_tests[i].terminator_offset;
1256 ipv4_tests[i].ip_strict[0] = ipv4_tests[i].ip[0];
1257 ipv4_tests[i].ip_strict[1] = ipv4_tests[i].ip[1];
1258 ipv4_tests[i].ip_strict[2] = ipv4_tests[i].ip[2];
1259 ipv4_tests[i].ip_strict[3] = ipv4_tests[i].ip[3];
1261 /* strict */
1262 terminator = &dummy;
1263 ip.S_un.S_addr = 0xabababab;
1264 res = RtlIpv4StringToAddressA(ipv4_tests[i].address, TRUE, &terminator, &ip);
1265 ok(res == ipv4_tests[i].res_strict,
1266 "[%s] res = 0x%08lx, expected 0x%08lx\n",
1267 ipv4_tests[i].address, res, ipv4_tests[i].res_strict);
1268 ok(terminator == ipv4_tests[i].address + ipv4_tests[i].terminator_offset_strict,
1269 "[%s] terminator = %p, expected %p\n",
1270 ipv4_tests[i].address, terminator, ipv4_tests[i].address + ipv4_tests[i].terminator_offset_strict);
1272 init_ip4(&expected_ip, ipv4_tests[i].ip_strict);
1273 ok(ip.S_un.S_addr == expected_ip.S_un.S_addr,
1274 "[%s] ip = %08lx, expected %08lx\n",
1275 ipv4_tests[i].address, ip.S_un.S_addr, expected_ip.S_un.S_addr);
1279 static void test_RtlIpv4StringToAddressEx(void)
1281 NTSTATUS res;
1282 IN_ADDR ip, expected_ip;
1283 USHORT port;
1284 static const struct
1286 PCSTR address;
1287 NTSTATUS res;
1288 int ip[4];
1289 USHORT port;
1290 } ipv4_ex_tests[] =
1292 { "", STATUS_INVALID_PARAMETER, { -1 }, 0xdead },
1293 { " ", STATUS_INVALID_PARAMETER, { -1 }, 0xdead },
1294 { "1.1.1.1:", STATUS_INVALID_PARAMETER, { 1, 1, 1, 1 }, 0xdead },
1295 { "1.1.1.1+", STATUS_INVALID_PARAMETER, { 1, 1, 1, 1 }, 0xdead },
1296 { "1.1.1.1:1", STATUS_SUCCESS, { 1, 1, 1, 1 }, 0x100 },
1297 { "256.1.1.1:1", STATUS_INVALID_PARAMETER, { -1 }, 0xdead },
1298 { "-1.1.1.1:1", STATUS_INVALID_PARAMETER, { -1 }, 0xdead },
1299 { "0.0.0.0:0", STATUS_INVALID_PARAMETER, { 0, 0, 0, 0 }, 0xdead },
1300 { "0.0.0.0:1", STATUS_SUCCESS, { 0, 0, 0, 0 }, 0x100 },
1301 { "1.2.3.4:65535", STATUS_SUCCESS, { 1, 2, 3, 4 }, 65535 },
1302 { "1.2.3.4:65536", STATUS_INVALID_PARAMETER, { 1, 2, 3, 4 }, 0xdead },
1303 { "1.2.3.4:0xffff", STATUS_SUCCESS, { 1, 2, 3, 4 }, 65535 },
1304 { "1.2.3.4:0XfFfF", STATUS_SUCCESS, { 1, 2, 3, 4 }, 65535 },
1305 { "1.2.3.4:011064", STATUS_SUCCESS, { 1, 2, 3, 4 }, 0x3412 },
1306 { "1.2.3.4:1234a", STATUS_INVALID_PARAMETER, { 1, 2, 3, 4 }, 0xdead },
1307 { "1.2.3.4:1234+", STATUS_INVALID_PARAMETER, { 1, 2, 3, 4 }, 0xdead },
1308 { "1.2.3.4: 1234", STATUS_INVALID_PARAMETER, { 1, 2, 3, 4 }, 0xdead },
1309 { "1.2.3.4:\t1234", STATUS_INVALID_PARAMETER, { 1, 2, 3, 4 }, 0xdead },
1311 unsigned int i;
1312 BOOLEAN strict;
1314 if (!pRtlIpv4StringToAddressExA)
1316 skip("RtlIpv4StringToAddressEx not available\n");
1317 return;
1320 /* do not crash, and do not touch the ip / port. */
1321 ip.S_un.S_addr = 0xabababab;
1322 port = 0xdead;
1323 res = pRtlIpv4StringToAddressExA(NULL, FALSE, &ip, &port);
1324 ok(res == STATUS_INVALID_PARAMETER, "[null address] res = 0x%08lx, expected 0x%08lx\n",
1325 res, STATUS_INVALID_PARAMETER);
1326 ok(ip.S_un.S_addr == 0xabababab, "RtlIpv4StringToAddressExA should not touch the ip!, ip == %lx\n", ip.S_un.S_addr);
1327 ok(port == 0xdead, "RtlIpv4StringToAddressExA should not touch the port!, port == %x\n", port);
1329 port = 0xdead;
1330 res = pRtlIpv4StringToAddressExA("1.1.1.1", FALSE, NULL, &port);
1331 ok(res == STATUS_INVALID_PARAMETER, "[null ip] res = 0x%08lx, expected 0x%08lx\n",
1332 res, STATUS_INVALID_PARAMETER);
1333 ok(port == 0xdead, "RtlIpv4StringToAddressExA should not touch the port!, port == %x\n", port);
1335 ip.S_un.S_addr = 0xabababab;
1336 port = 0xdead;
1337 res = pRtlIpv4StringToAddressExA("1.1.1.1", FALSE, &ip, NULL);
1338 ok(res == STATUS_INVALID_PARAMETER, "[null port] res = 0x%08lx, expected 0x%08lx\n",
1339 res, STATUS_INVALID_PARAMETER);
1340 ok(ip.S_un.S_addr == 0xabababab, "RtlIpv4StringToAddressExA should not touch the ip!, ip == %lx\n", ip.S_un.S_addr);
1341 ok(port == 0xdead, "RtlIpv4StringToAddressExA should not touch the port!, port == %x\n", port);
1343 /* first we run the non-ex testcases on the ex function */
1344 for (i = 0; i < ARRAY_SIZE(ipv4_tests); i++)
1346 NTSTATUS expect_res = (ipv4_tests[i].flags & ex_fail_4) ? STATUS_INVALID_PARAMETER : ipv4_tests[i].res;
1348 /* non-strict */
1349 port = 0xdead;
1350 ip.S_un.S_addr = 0xabababab;
1351 res = pRtlIpv4StringToAddressExA(ipv4_tests[i].address, FALSE, &ip, &port);
1352 ok(res == expect_res, "[%s] res = 0x%08lx, expected 0x%08lx\n",
1353 ipv4_tests[i].address, res, expect_res);
1355 init_ip4(&expected_ip, ipv4_tests[i].ip);
1356 ok(ip.S_un.S_addr == expected_ip.S_un.S_addr, "[%s] ip = %08lx, expected %08lx\n",
1357 ipv4_tests[i].address, ip.S_un.S_addr, expected_ip.S_un.S_addr);
1359 if (!(ipv4_tests[i].flags & strict_diff_4))
1361 ipv4_tests[i].res_strict = ipv4_tests[i].res;
1362 ipv4_tests[i].terminator_offset_strict = ipv4_tests[i].terminator_offset;
1363 ipv4_tests[i].ip_strict[0] = ipv4_tests[i].ip[0];
1364 ipv4_tests[i].ip_strict[1] = ipv4_tests[i].ip[1];
1365 ipv4_tests[i].ip_strict[2] = ipv4_tests[i].ip[2];
1366 ipv4_tests[i].ip_strict[3] = ipv4_tests[i].ip[3];
1368 /* strict */
1369 expect_res = (ipv4_tests[i].flags & ex_fail_4) ? STATUS_INVALID_PARAMETER : ipv4_tests[i].res_strict;
1370 port = 0xdead;
1371 ip.S_un.S_addr = 0xabababab;
1372 res = pRtlIpv4StringToAddressExA(ipv4_tests[i].address, TRUE, &ip, &port);
1373 ok(res == expect_res, "[%s] res = 0x%08lx, expected 0x%08lx\n",
1374 ipv4_tests[i].address, res, expect_res);
1376 init_ip4(&expected_ip, ipv4_tests[i].ip_strict);
1377 ok(ip.S_un.S_addr == expected_ip.S_un.S_addr, "[%s] ip = %08lx, expected %08lx\n",
1378 ipv4_tests[i].address, ip.S_un.S_addr, expected_ip.S_un.S_addr);
1382 for (i = 0; i < ARRAY_SIZE(ipv4_ex_tests); i++)
1384 /* Strict is only relevant for the ip address, so make sure that it does not influence the port */
1385 for (strict = 0; strict < 2; strict++)
1387 ip.S_un.S_addr = 0xabababab;
1388 port = 0xdead;
1389 res = pRtlIpv4StringToAddressExA(ipv4_ex_tests[i].address, strict, &ip, &port);
1390 ok(res == ipv4_ex_tests[i].res, "[%s] res = 0x%08lx, expected 0x%08lx\n",
1391 ipv4_ex_tests[i].address, res, ipv4_ex_tests[i].res);
1393 init_ip4(&expected_ip, ipv4_ex_tests[i].ip);
1394 ok(ip.S_un.S_addr == expected_ip.S_un.S_addr, "[%s] ip = %08lx, expected %08lx\n",
1395 ipv4_ex_tests[i].address, ip.S_un.S_addr, expected_ip.S_un.S_addr);
1396 ok(port == ipv4_ex_tests[i].port, "[%s] port = %u, expected %u\n",
1397 ipv4_ex_tests[i].address, port, ipv4_ex_tests[i].port);
1402 /* ipv6 addresses based on the set from https://github.com/beaugunderson/javascript-ipv6/tree/master/test/data */
1403 static const struct
1405 PCSTR address;
1406 NTSTATUS res;
1407 int terminator_offset;
1408 int ip[8];
1409 /* win_broken: XP and Vista do not handle this correctly
1410 ex_fail: Ex function does need the string to be terminated, non-Ex does not.
1411 ex_skip: test doesn't make sense for Ex (f.e. it's invalid for non-Ex but valid for Ex) */
1412 enum { normal_6, win_broken_6 = 1, ex_fail_6 = 2, ex_skip_6 = 4 } flags;
1413 } ipv6_tests[] =
1415 { "0000:0000:0000:0000:0000:0000:0000:0000", STATUS_SUCCESS, 39,
1416 { 0, 0, 0, 0, 0, 0, 0, 0 } },
1417 { "0000:0000:0000:0000:0000:0000:0000:0001", STATUS_SUCCESS, 39,
1418 { 0, 0, 0, 0, 0, 0, 0, 0x100 } },
1419 { "0:0:0:0:0:0:0:0", STATUS_SUCCESS, 15,
1420 { 0, 0, 0, 0, 0, 0, 0, 0 } },
1421 { "0:0:0:0:0:0:0:1", STATUS_SUCCESS, 15,
1422 { 0, 0, 0, 0, 0, 0, 0, 0x100 } },
1423 { "0:0:0:0:0:0:0::", STATUS_SUCCESS, 15,
1424 { 0, 0, 0, 0, 0, 0, 0, 0 }, win_broken_6 },
1425 { "0:0:0:0:0:0:13.1.68.3", STATUS_SUCCESS, 21,
1426 { 0, 0, 0, 0, 0, 0, 0x10d, 0x344 } },
1427 { "0:0:0:0:0:0::", STATUS_SUCCESS, 13,
1428 { 0, 0, 0, 0, 0, 0, 0, 0 } },
1429 { "0:0:0:0:0::", STATUS_SUCCESS, 11,
1430 { 0, 0, 0, 0, 0, 0, 0, 0 } },
1431 { "0:0:0:0:0:FFFF:129.144.52.38", STATUS_SUCCESS, 28,
1432 { 0, 0, 0, 0, 0, 0xffff, 0x9081, 0x2634 } },
1433 { "0::", STATUS_SUCCESS, 3,
1434 { 0, 0, 0, 0, 0, 0, 0, 0 } },
1435 { "0:1:2:3:4:5:6:7", STATUS_SUCCESS, 15,
1436 { 0, 0x100, 0x200, 0x300, 0x400, 0x500, 0x600, 0x700 } },
1437 { "1080:0:0:0:8:800:200c:417a", STATUS_SUCCESS, 26,
1438 { 0x8010, 0, 0, 0, 0x800, 0x8, 0x0c20, 0x7a41 } },
1439 { "0:a:b:c:d:e:f::", STATUS_SUCCESS, 15,
1440 { 0, 0xa00, 0xb00, 0xc00, 0xd00, 0xe00, 0xf00, 0 }, win_broken_6 },
1441 { "1111:2222:3333:4444:5555:6666:123.123.123.123", STATUS_SUCCESS, 45,
1442 { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7b7b, 0x7b7b } },
1443 { "1111:2222:3333:4444:5555:6666:7777:8888", STATUS_SUCCESS, 39,
1444 { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0x8888 } },
1445 { "1111:2222:3333:4444:0x5555:6666:7777:8888", STATUS_INVALID_PARAMETER, 21,
1446 { 0x1111, 0x2222, 0x3333, 0x4444, 0xabab, 0xabab, 0xabab, 0xabab } },
1447 { "1111:2222:3333:4444:x555:6666:7777:8888", STATUS_INVALID_PARAMETER, 20,
1448 { 0x1111, 0x2222, 0x3333, 0x4444, 0xabab, 0xabab, 0xabab, 0xabab } },
1449 { "1111:2222:3333:4444:0r5555:6666:7777:8888", STATUS_INVALID_PARAMETER, 21,
1450 { 0x1111, 0x2222, 0x3333, 0x4444, 0xabab, 0xabab, 0xabab, 0xabab } },
1451 { "1111:2222:3333:4444:r5555:6666:7777:8888", STATUS_INVALID_PARAMETER, 20,
1452 { 0x1111, 0x2222, 0x3333, 0x4444, 0xabab, 0xabab, 0xabab, 0xabab } },
1453 { "1111:2222:3333:4444:5555:6666:7777::", STATUS_SUCCESS, 36,
1454 { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0 }, win_broken_6 },
1455 { "1111:2222:3333:4444:5555:6666::", STATUS_SUCCESS, 31,
1456 { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0, 0 } },
1457 { "1111:2222:3333:4444:5555:6666::8888", STATUS_SUCCESS, 35,
1458 { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0, 0x8888 } },
1459 { "1111:2222:3333:4444:5555:6666::7777:8888", STATUS_SUCCESS, 35,
1460 { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0, 0x7777 }, ex_fail_6 },
1461 { "1111:2222:3333:4444:5555:6666:7777::8888", STATUS_SUCCESS, 36,
1462 { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0 }, ex_fail_6|win_broken_6 },
1463 { "1111:2222:3333:4444:5555::", STATUS_SUCCESS, 26,
1464 { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0, 0, 0 } },
1465 { "1111:2222:3333:4444:5555::123.123.123.123", STATUS_SUCCESS, 41,
1466 { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0, 0x7b7b, 0x7b7b } },
1467 { "1111:2222:3333:4444:5555::0x1.123.123.123", STATUS_SUCCESS, 27,
1468 { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0, 0, 0x100 }, ex_fail_6 },
1469 { "1111:2222:3333:4444:5555::0x88", STATUS_SUCCESS, 27,
1470 { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0, 0, 0x8800 }, ex_fail_6 },
1471 { "1111:2222:3333:4444:5555::0X88", STATUS_SUCCESS, 27,
1472 { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0, 0, 0x8800 }, ex_fail_6 },
1473 { "1111:2222:3333:4444:5555::0X", STATUS_SUCCESS, 27,
1474 { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0, 0, 0 }, ex_fail_6 },
1475 { "1111:2222:3333:4444:5555::0X88:7777", STATUS_SUCCESS, 27,
1476 { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0, 0, 0x8800 }, ex_fail_6 },
1477 { "1111:2222:3333:4444:5555::0x8888", STATUS_SUCCESS, 27,
1478 { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0, 0, 0x8888 }, ex_fail_6 },
1479 { "1111:2222:3333:4444:5555::0x80000000", STATUS_SUCCESS, 27,
1480 { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0, 0, 0xffff }, ex_fail_6 },
1481 { "1111:2222:3333:4444::5555:0x012345678", STATUS_SUCCESS, 27,
1482 { 0x1111, 0x2222, 0x3333, 0x4444, 0, 0, 0x5555, 0x7856 }, ex_fail_6 },
1483 { "1111:2222:3333:4444::5555:0x123456789", STATUS_SUCCESS, 27,
1484 { 0x1111, 0x2222, 0x3333, 0x4444, 0, 0, 0x5555, 0xffff }, ex_fail_6 },
1485 { "1111:2222:3333:4444:5555:6666:0x12345678", STATUS_INVALID_PARAMETER, 31,
1486 { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0xabab, 0xabab }, ex_fail_6 },
1487 { "1111:2222:3333:4444:5555:6666:7777:0x80000000", STATUS_SUCCESS, 36,
1488 { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0xffff }, ex_fail_6 },
1489 { "1111:2222:3333:4444:5555:6666:7777:0x012345678", STATUS_SUCCESS, 36,
1490 { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0x7856 }, ex_fail_6 },
1491 { "1111:2222:3333:4444:5555:6666:7777:0x123456789", STATUS_SUCCESS, 36,
1492 { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0xffff }, ex_fail_6 },
1493 { "111:222:333:444:555:666:777:0x123456789abcdef0", STATUS_SUCCESS, 29,
1494 { 0x1101, 0x2202, 0x3303, 0x4404, 0x5505, 0x6606, 0x7707, 0xffff }, ex_fail_6 },
1495 { "1111:2222:3333:4444:5555::08888", STATUS_INVALID_PARAMETER, 31,
1496 { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0xabab, 0xabab, 0xabab } },
1497 { "1111:2222:3333:4444:5555::08888::", STATUS_INVALID_PARAMETER, 31,
1498 { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0xabab, 0xabab, 0xabab } },
1499 { "1111:2222:3333:4444:5555:6666:7777:fffff:", STATUS_INVALID_PARAMETER, 40,
1500 { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0xabab } },
1501 { "1111:2222:3333:4444:5555:6666::fffff:", STATUS_INVALID_PARAMETER, 36,
1502 { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0xabab, 0xabab } },
1503 { "1111:2222:3333:4444:5555::fffff", STATUS_INVALID_PARAMETER, 31,
1504 { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0xabab, 0xabab, 0xabab } },
1505 { "1111:2222:3333:4444::fffff", STATUS_INVALID_PARAMETER, 26,
1506 { 0x1111, 0x2222, 0x3333, 0x4444, 0xabab, 0xabab, 0xabab, 0xabab } },
1507 { "1111:2222:3333::fffff", STATUS_INVALID_PARAMETER, 21,
1508 { 0x1111, 0x2222, 0x3333, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1509 { "1111:2222:3333:4444:5555::7777:8888", STATUS_SUCCESS, 35,
1510 { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0, 0x7777, 0x8888 } },
1511 { "1111:2222:3333:4444:5555::8888", STATUS_SUCCESS, 30,
1512 { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0, 0, 0x8888 } },
1513 { "1111::", STATUS_SUCCESS, 6,
1514 { 0x1111, 0, 0, 0, 0, 0, 0, 0 } },
1515 { "1111::123.123.123.123", STATUS_SUCCESS, 21,
1516 { 0x1111, 0, 0, 0, 0, 0, 0x7b7b, 0x7b7b } },
1517 { "1111::3333:4444:5555:6666:123.123.123.123", STATUS_SUCCESS, 41,
1518 { 0x1111, 0, 0x3333, 0x4444, 0x5555, 0x6666, 0x7b7b, 0x7b7b } },
1519 { "1111::3333:4444:5555:6666:7777:8888", STATUS_SUCCESS, 35,
1520 { 0x1111, 0, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0x8888 } },
1521 { "1111::4444:5555:6666:123.123.123.123", STATUS_SUCCESS, 36,
1522 { 0x1111, 0, 0, 0x4444, 0x5555, 0x6666, 0x7b7b, 0x7b7b } },
1523 { "1111::4444:5555:6666:7777:8888", STATUS_SUCCESS, 30,
1524 { 0x1111, 0, 0, 0x4444, 0x5555, 0x6666, 0x7777, 0x8888 } },
1525 { "1111::5555:6666:123.123.123.123", STATUS_SUCCESS, 31,
1526 { 0x1111, 0, 0, 0, 0x5555, 0x6666, 0x7b7b, 0x7b7b } },
1527 { "1111::5555:6666:7777:8888", STATUS_SUCCESS, 25,
1528 { 0x1111, 0, 0, 0, 0x5555, 0x6666, 0x7777, 0x8888 } },
1529 { "1111::6666:123.123.123.123", STATUS_SUCCESS, 26,
1530 { 0x1111, 0, 0, 0, 0, 0x6666, 0x7b7b, 0x7b7b } },
1531 { "1111::6666:7777:8888", STATUS_SUCCESS, 20,
1532 { 0x1111, 0, 0, 0, 0, 0x6666, 0x7777, 0x8888 } },
1533 { "1111::7777:8888", STATUS_SUCCESS, 15,
1534 { 0x1111, 0, 0, 0, 0, 0, 0x7777, 0x8888 } },
1535 { "1111::8888", STATUS_SUCCESS, 10,
1536 { 0x1111, 0, 0, 0, 0, 0, 0, 0x8888 } },
1537 { "1:2:3:4:5:6:1.2.3.4", STATUS_SUCCESS, 19,
1538 { 0x100, 0x200, 0x300, 0x400, 0x500, 0x600, 0x201, 0x403 } },
1539 { "1:2:3:4:5:6:7:8", STATUS_SUCCESS, 15,
1540 { 0x100, 0x200, 0x300, 0x400, 0x500, 0x600, 0x700, 0x800 } },
1541 { "1:2:3:4:5:6::", STATUS_SUCCESS, 13,
1542 { 0x100, 0x200, 0x300, 0x400, 0x500, 0x600, 0, 0 } },
1543 { "1:2:3:4:5:6::8", STATUS_SUCCESS, 14,
1544 { 0x100, 0x200, 0x300, 0x400, 0x500, 0x600, 0, 0x800 } },
1545 { "2001:0000:1234:0000:0000:C1C0:ABCD:0876", STATUS_SUCCESS, 39,
1546 { 0x120, 0, 0x3412, 0, 0, 0xc0c1, 0xcdab, 0x7608 } },
1547 { "2001:0000:4136:e378:8000:63bf:3fff:fdd2", STATUS_SUCCESS, 39,
1548 { 0x120, 0, 0x3641, 0x78e3, 0x80, 0xbf63, 0xff3f, 0xd2fd } },
1549 { "2001:0db8:0:0:0:0:1428:57ab", STATUS_SUCCESS, 27,
1550 { 0x120, 0xb80d, 0, 0, 0, 0, 0x2814, 0xab57 } },
1551 { "2001:0db8:1234:ffff:ffff:ffff:ffff:ffff", STATUS_SUCCESS, 39,
1552 { 0x120, 0xb80d, 0x3412, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff } },
1553 { "2001::CE49:7601:2CAD:DFFF:7C94:FFFE", STATUS_SUCCESS, 35,
1554 { 0x120, 0, 0x49ce, 0x176, 0xad2c, 0xffdf, 0x947c, 0xfeff } },
1555 { "2001:db8:85a3::8a2e:370:7334", STATUS_SUCCESS, 28,
1556 { 0x120, 0xb80d, 0xa385, 0, 0, 0x2e8a, 0x7003, 0x3473 } },
1557 { "3ffe:0b00:0000:0000:0001:0000:0000:000a", STATUS_SUCCESS, 39,
1558 { 0xfe3f, 0xb, 0, 0, 0x100, 0, 0, 0xa00 } },
1559 { "::", STATUS_SUCCESS, 2,
1560 { 0, 0, 0, 0, 0, 0, 0, 0 } },
1561 { "::%16", STATUS_SUCCESS, 2,
1562 { 0, 0, 0, 0, 0, 0, 0, 0 } },
1563 { "::/16", STATUS_SUCCESS, 2,
1564 { 0, 0, 0, 0, 0, 0, 0, 0 }, ex_fail_6 },
1565 { "::01234", STATUS_INVALID_PARAMETER, 7,
1566 { 0, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1567 { "::0", STATUS_SUCCESS, 3,
1568 { 0, 0, 0, 0, 0, 0, 0, 0 } },
1569 { "::0:0", STATUS_SUCCESS, 5,
1570 { 0, 0, 0, 0, 0, 0, 0, 0 } },
1571 { "::0:0:0", STATUS_SUCCESS, 7,
1572 { 0, 0, 0, 0, 0, 0, 0, 0 } },
1573 { "::0:0:0:0", STATUS_SUCCESS, 9,
1574 { 0, 0, 0, 0, 0, 0, 0, 0 } },
1575 { "::0:0:0:0:0", STATUS_SUCCESS, 11,
1576 { 0, 0, 0, 0, 0, 0, 0, 0 } },
1577 { "::0:0:0:0:0:0", STATUS_SUCCESS, 13,
1578 { 0, 0, 0, 0, 0, 0, 0, 0 } },
1579 /* this one and the next one are incorrectly parsed by windows,
1580 it adds one zero too many in front, cutting off the last digit. */
1581 { "::0:0:0:0:0:0:0", STATUS_SUCCESS, 13,
1582 { 0, 0, 0, 0, 0, 0, 0, 0 }, ex_fail_6 },
1583 { "::0:a:b:c:d:e:f", STATUS_SUCCESS, 13,
1584 { 0, 0, 0, 0xa00, 0xb00, 0xc00, 0xd00, 0xe00 }, ex_fail_6 },
1585 { "::123.123.123.123", STATUS_SUCCESS, 17,
1586 { 0, 0, 0, 0, 0, 0, 0x7b7b, 0x7b7b } },
1587 { "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", STATUS_SUCCESS, 39,
1588 { 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff } },
1590 { "':10.0.0.1", STATUS_INVALID_PARAMETER, 0,
1591 { -1 } },
1592 { "-1", STATUS_INVALID_PARAMETER, 0,
1593 { -1 } },
1594 { "02001:0000:1234:0000:0000:C1C0:ABCD:0876", STATUS_INVALID_PARAMETER, -1,
1595 { -1 } },
1596 { "2001:00000:1234:0000:0000:C1C0:ABCD:0876", STATUS_INVALID_PARAMETER, -1,
1597 { 0x120, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1598 { "2001:0000:01234:0000:0000:C1C0:ABCD:0876", STATUS_INVALID_PARAMETER, -1,
1599 { 0x120, 0, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1600 { "2001:0000::01234.0", STATUS_INVALID_PARAMETER, -1,
1601 { 0x120, 0, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1602 { "2001:0::b.0", STATUS_SUCCESS, 9,
1603 { 0x120, 0, 0, 0, 0, 0, 0, 0xb00 }, ex_fail_6 },
1604 { "2001::0:b.0", STATUS_SUCCESS, 9,
1605 { 0x120, 0, 0, 0, 0, 0, 0, 0xb00 }, ex_fail_6 },
1606 { "1.2.3.4", STATUS_INVALID_PARAMETER, 7,
1607 { 0x201, 0xab03, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1608 { "1.2.3.4:1111::5555", STATUS_INVALID_PARAMETER, 7,
1609 { 0x201, 0xab03, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1610 { "1.2.3.4::5555", STATUS_INVALID_PARAMETER, 7,
1611 { 0x201, 0xab03, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1612 { "11112222:3333:4444:5555:6666:1.2.3.4", STATUS_INVALID_PARAMETER, -1,
1613 { -1 } },
1614 { "11112222:3333:4444:5555:6666:7777:8888", STATUS_INVALID_PARAMETER, -1,
1615 { -1 } },
1616 { "1111", STATUS_INVALID_PARAMETER, 4,
1617 { -1 } },
1618 { "0x1111", STATUS_INVALID_PARAMETER, 1,
1619 { -1 } },
1620 { "1111:22223333:4444:5555:6666:1.2.3.4", STATUS_INVALID_PARAMETER, -1,
1621 { 0x1111, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1622 { "1111:22223333:4444:5555:6666:7777:8888", STATUS_INVALID_PARAMETER, -1,
1623 { 0x1111, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1624 { "1111:123456789:4444:5555:6666:7777:8888", STATUS_INVALID_PARAMETER, -1,
1625 { 0x1111, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1626 { "1111:1234567890abcdef0:4444:5555:6666:7777:888", STATUS_INVALID_PARAMETER, -1,
1627 { 0x1111, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1628 { "1111:2222:", STATUS_INVALID_PARAMETER, 10,
1629 { 0x1111, 0x2222, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1630 { "1111:2222:1.2.3.4", STATUS_INVALID_PARAMETER, 17,
1631 { 0x1111, 0x2222, 0x201, 0xab03, 0xabab, 0xabab, 0xabab, 0xabab } },
1632 { "1111:2222:3333", STATUS_INVALID_PARAMETER, 14,
1633 { 0x1111, 0x2222, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1634 { "1111:2222:3333:4444:5555:6666::1.2.3.4", STATUS_SUCCESS, 32,
1635 { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0, 0x100 }, ex_fail_6 },
1636 { "1111:2222:3333:4444:5555:6666:7777:1.2.3.4", STATUS_SUCCESS, 36,
1637 { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0x100 }, ex_fail_6 },
1638 { "1111:2222:3333:4444:5555:6666:7777:8888:", STATUS_SUCCESS, 39,
1639 { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0x8888 }, ex_fail_6 },
1640 { "1111:2222:3333:4444:5555:6666:7777:8888:1.2.3.4",STATUS_SUCCESS, 39,
1641 { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0x8888 }, ex_fail_6 },
1642 { "1111:2222:3333:4444:5555:6666:7777:8888:9999", STATUS_SUCCESS, 39,
1643 { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0x8888 }, ex_fail_6 },
1644 { "1111:2222:::", STATUS_SUCCESS, 11,
1645 { 0x1111, 0x2222, 0, 0, 0, 0, 0, 0 }, ex_fail_6 },
1646 { "1111::5555:", STATUS_INVALID_PARAMETER, 11,
1647 { 0x1111, 0x5555, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1648 { "1111::3333:4444:5555:6666:7777::", STATUS_SUCCESS, 30,
1649 { 0x1111, 0, 0, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777 }, ex_fail_6 },
1650 { "1111:2222:::4444:5555:6666:1.2.3.4", STATUS_SUCCESS, 11,
1651 { 0x1111, 0x2222, 0, 0, 0, 0, 0, 0 }, ex_fail_6 },
1652 { "1111::3333::5555:6666:1.2.3.4", STATUS_SUCCESS, 10,
1653 { 0x1111, 0, 0, 0, 0, 0, 0, 0x3333 }, ex_fail_6 },
1654 { "12345::6:7:8", STATUS_INVALID_PARAMETER, -1,
1655 { -1 } },
1656 { "1::001.2.3.4", STATUS_SUCCESS, 12,
1657 { 0x100, 0, 0, 0, 0, 0, 0x201, 0x403 } },
1658 { "1::1.002.3.4", STATUS_SUCCESS, 12,
1659 { 0x100, 0, 0, 0, 0, 0, 0x201, 0x403 } },
1660 { "1::0001.2.3.4", STATUS_INVALID_PARAMETER, -1,
1661 { 0x100, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1662 { "1::1.0002.3.4", STATUS_INVALID_PARAMETER, -1,
1663 { 0x100, 0xab01, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1664 { "1::1.2.256.4", STATUS_INVALID_PARAMETER, -1,
1665 { 0x100, 0x201, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1666 { "1::1.2.4294967296.4", STATUS_INVALID_PARAMETER, -1,
1667 { 0x100, 0x201, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1668 { "1::1.2.18446744073709551616.4", STATUS_INVALID_PARAMETER, -1,
1669 { 0x100, 0x201, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1670 { "1::1.2.3.256", STATUS_INVALID_PARAMETER, 12,
1671 { 0x100, 0x201, 0xab03, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1672 { "1::1.2.3.4294967296", STATUS_INVALID_PARAMETER, 19,
1673 { 0x100, 0x201, 0xab03, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1674 { "1::1.2.3.18446744073709551616", STATUS_INVALID_PARAMETER, 29,
1675 { 0x100, 0x201, 0xab03, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1676 { "1::1.2.3.300", STATUS_INVALID_PARAMETER, 12,
1677 { 0x100, 0x201, 0xab03, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1678 { "1::1.2.3.300.", STATUS_INVALID_PARAMETER, 12,
1679 { 0x100, 0x201, 0xab03, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1680 { "1::1.2::1", STATUS_INVALID_PARAMETER, 6,
1681 { 0x100, 0xab01, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1682 { "1::1.2.3.4::1", STATUS_SUCCESS, 10,
1683 { 0x100, 0, 0, 0, 0, 0, 0x201, 0x403 }, ex_fail_6 },
1684 { "1::1.", STATUS_INVALID_PARAMETER, 5,
1685 { 0x100, 0xab01, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1686 { "1::1.2", STATUS_INVALID_PARAMETER, 6,
1687 { 0x100, 0xab01, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1688 { "1::1.2.", STATUS_INVALID_PARAMETER, 7,
1689 { 0x100, 0x201, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1690 { "1::1.2.3", STATUS_INVALID_PARAMETER, 8,
1691 { 0x100, 0x201, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1692 { "1::1.2.3.", STATUS_INVALID_PARAMETER, 9,
1693 { 0x100, 0x201, 0xab03, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1694 { "1::1.2.3.4", STATUS_SUCCESS, 10,
1695 { 0x100, 0, 0, 0, 0, 0, 0x201, 0x403 } },
1696 { "1::1.2.3.900", STATUS_INVALID_PARAMETER, 12,
1697 { 0x100, 0x201, 0xab03, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1698 { "1::1.2.300.4", STATUS_INVALID_PARAMETER, -1,
1699 { 0x100, 0x201, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1700 { "1::1.256.3.4", STATUS_INVALID_PARAMETER, -1,
1701 { 0x100, 0xab01, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1702 { "1::1.256:3.4", STATUS_INVALID_PARAMETER, 8,
1703 { 0x100, 0xab01, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1704 { "1::1.2a.3.4", STATUS_INVALID_PARAMETER, 6,
1705 { 0x100, 0xab01, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1706 { "1::256.2.3.4", STATUS_INVALID_PARAMETER, -1,
1707 { 0x100, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1708 { "1::1a.2.3.4", STATUS_SUCCESS, 5,
1709 { 0x100, 0, 0, 0, 0, 0, 0, 0x1a00 }, ex_fail_6 },
1710 { "1::2::3", STATUS_SUCCESS, 4,
1711 { 0x100, 0, 0, 0, 0, 0, 0, 0x200 }, ex_fail_6 },
1712 { "2001:0000:1234: 0000:0000:C1C0:ABCD:0876", STATUS_INVALID_PARAMETER, 15,
1713 { 0x120, 0, 0x3412, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1714 { "2001:0000:1234:0000:0000:C1C0:ABCD:0876 0", STATUS_SUCCESS, 39,
1715 { 0x120, 0, 0x3412, 0, 0, 0xc0c1, 0xcdab, 0x7608 }, ex_fail_6 },
1716 { "2001:1:1:1:1:1:255Z255X255Y255", STATUS_INVALID_PARAMETER, 18,
1717 { 0x120, 0x100, 0x100, 0x100, 0x100, 0x100, 0xabab, 0xabab } },
1718 { "2001::FFD3::57ab", STATUS_SUCCESS, 10,
1719 { 0x120, 0, 0, 0, 0, 0, 0, 0xd3ff }, ex_fail_6 },
1720 { ":", STATUS_INVALID_PARAMETER, 0,
1721 { -1 } },
1722 { ":1111:2222:3333:4444:5555:6666:1.2.3.4", STATUS_INVALID_PARAMETER, 0,
1723 { -1 } },
1724 { ":1111:2222:3333:4444:5555:6666:7777:8888", STATUS_INVALID_PARAMETER, 0,
1725 { -1 } },
1726 { ":1111::", STATUS_INVALID_PARAMETER, 0,
1727 { -1 } },
1728 { "::-1", STATUS_SUCCESS, 2,
1729 { 0, 0, 0, 0, 0, 0, 0, 0 }, ex_fail_6 },
1730 { "::12345678", STATUS_INVALID_PARAMETER, 10,
1731 { 0, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1732 { "::123456789", STATUS_INVALID_PARAMETER, 11,
1733 { 0, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1734 { "::1234567890abcdef0", STATUS_INVALID_PARAMETER, 19,
1735 { 0, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1736 { "::0x80000000", STATUS_SUCCESS, 3,
1737 { 0, 0, 0, 0, 0, 0, 0, 0xffff }, ex_fail_6 },
1738 { "::0x012345678", STATUS_SUCCESS, 3,
1739 { 0, 0, 0, 0, 0, 0, 0, 0x7856 }, ex_fail_6 },
1740 { "::0x123456789", STATUS_SUCCESS, 3,
1741 { 0, 0, 0, 0, 0, 0, 0, 0xffff }, ex_fail_6 },
1742 { "::0x1234567890abcdef0", STATUS_SUCCESS, 3,
1743 { 0, 0, 0, 0, 0, 0, 0, 0xffff }, ex_fail_6 },
1744 { "::.", STATUS_SUCCESS, 2,
1745 { 0, 0, 0, 0, 0, 0, 0, 0 }, ex_fail_6 },
1746 { "::..", STATUS_SUCCESS, 2,
1747 { 0, 0, 0, 0, 0, 0, 0, 0 }, ex_fail_6 },
1748 { "::...", STATUS_SUCCESS, 2,
1749 { 0, 0, 0, 0, 0, 0, 0, 0 }, ex_fail_6 },
1750 { "XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:1.2.3.4", STATUS_INVALID_PARAMETER, 0,
1751 { -1 } },
1752 { "[::]", STATUS_INVALID_PARAMETER, 0,
1753 { -1 }, ex_skip_6 },
1756 static void init_ip6(IN6_ADDR* addr, const int src[8])
1758 unsigned int j;
1759 if (!src || src[0] == -1)
1761 for (j = 0; j < 8; ++j)
1762 addr->s6_words[j] = 0xabab;
1764 else
1766 for (j = 0; j < 8; ++j)
1767 addr->s6_words[j] = src[j];
1771 static void test_RtlIpv6AddressToString(void)
1773 CHAR buffer[50];
1774 LPCSTR result;
1775 IN6_ADDR ip;
1776 DWORD_PTR len;
1777 static const struct
1779 PCSTR address;
1780 int ip[8];
1781 } tests[] =
1783 /* ipv4 addresses & ISATAP addresses */
1784 { "::13.1.68.3", { 0, 0, 0, 0, 0, 0, 0x10d, 0x344 } },
1785 { "::123.123.123.123", { 0, 0, 0, 0, 0, 0, 0x7b7b, 0x7b7b } },
1786 { "::ffff", { 0, 0, 0, 0, 0, 0, 0, 0xffff } },
1787 { "::0.1.0.0", { 0, 0, 0, 0, 0, 0, 0x100, 0 } },
1788 { "::ffff:13.1.68.3", { 0, 0, 0, 0, 0, 0xffff, 0x10d, 0x344 } },
1789 { "::feff:d01:4403", { 0, 0, 0, 0, 0, 0xfffe, 0x10d, 0x344 } },
1790 { "::fffe:d01:4403", { 0, 0, 0, 0, 0, 0xfeff, 0x10d, 0x344 } },
1791 { "::100:d01:4403", { 0, 0, 0, 0, 0, 1, 0x10d, 0x344 } },
1792 { "::1:d01:4403", { 0, 0, 0, 0, 0, 0x100, 0x10d, 0x344 } },
1793 { "::1:0:d01:4403", { 0, 0, 0, 0, 0x100, 0, 0x10d, 0x344 } },
1794 { "::fffe:d01:4403", { 0, 0, 0, 0, 0, 0xfeff, 0x10d, 0x344 } },
1795 { "::fffe:0:d01:4403", { 0, 0, 0, 0, 0xfeff, 0, 0x10d, 0x344 } },
1796 { "::ffff:0:4403", { 0, 0, 0, 0, 0, 0xffff, 0, 0x344 } },
1797 { "::ffff:0.1.0.0", { 0, 0, 0, 0, 0, 0xffff, 0x100, 0 } },
1798 { "::ffff:13.1.0.0", { 0, 0, 0, 0, 0, 0xffff, 0x10d, 0 } },
1799 { "::ffff:0:0", { 0, 0, 0, 0, 0, 0xffff, 0, 0 } },
1800 { "::ffff:0:ffff", { 0, 0, 0, 0, 0, 0xffff, 0, 0xffff } },
1801 { "::ffff:0:0.1.0.0", { 0, 0, 0, 0, 0xffff, 0, 0x100, 0 } },
1802 { "::ffff:0:13.1.68.3", { 0, 0, 0, 0, 0xffff, 0, 0x10d, 0x344 } },
1803 { "::ffff:ffff:d01:4403", { 0, 0, 0, 0, 0xffff, 0xffff, 0x10d, 0x344 } },
1804 { "::ffff:0:0:d01:4403", { 0, 0, 0, 0xffff, 0, 0, 0x10d, 0x344 } },
1805 { "::ffff:255.255.255.255", { 0, 0, 0, 0, 0, 0xffff, 0xffff, 0xffff } },
1806 { "::ffff:129.144.52.38", { 0, 0, 0, 0, 0, 0xffff, 0x9081, 0x2634 } },
1807 { "::5efe:0.0.0.0", { 0, 0, 0, 0, 0, 0xfe5e, 0, 0 } },
1808 { "::5efe:129.144.52.38", { 0, 0, 0, 0, 0, 0xfe5e, 0x9081, 0x2634 } },
1809 { "1111:2222:3333:4444:0:5efe:129.144.52.38", { 0x1111, 0x2222, 0x3333, 0x4444, 0, 0xfe5e, 0x9081, 0x2634 } },
1810 { "1111:2222:3333::5efe:129.144.52.38", { 0x1111, 0x2222, 0x3333, 0, 0, 0xfe5e, 0x9081, 0x2634 } },
1811 { "1111:2222::5efe:129.144.52.38", { 0x1111, 0x2222, 0, 0, 0, 0xfe5e, 0x9081, 0x2634 } },
1812 { "1111::5efe:129.144.52.38", { 0x1111, 0, 0, 0, 0, 0xfe5e, 0x9081, 0x2634 } },
1813 { "::300:5efe:8190:3426", { 0, 0, 0, 0, 3, 0xfe5e, 0x9081, 0x2634 } },
1814 { "::200:5efe:129.144.52.38", { 0, 0, 0, 0, 2, 0xfe5e, 0x9081, 0x2634 } },
1815 { "::100:5efe:8190:3426", { 0, 0, 0, 0, 1, 0xfe5e, 0x9081, 0x2634 } },
1816 /* 'normal' addresses */
1817 { "::1", { 0, 0, 0, 0, 0, 0, 0, 0x100 } },
1818 { "::2", { 0, 0, 0, 0, 0, 0, 0, 0x200 } },
1819 { "0:1:2:3:4:5:6:7", { 0, 0x100, 0x200, 0x300, 0x400, 0x500, 0x600, 0x700 } },
1820 { "1080::8:800:200c:417a", { 0x8010, 0, 0, 0, 0x800, 0x8, 0x0c20, 0x7a41 } },
1821 { "1111:2222:3333:4444:5555:6666:7b7b:7b7b", { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7b7b, 0x7b7b } },
1822 { "1111:2222:3333:4444:5555:6666:7777:8888", { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0x8888 } },
1823 { "1111:2222:3333:4444:5555:6666::", { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0, 0 } },
1824 { "1111:2222:3333:4444:5555:6666:0:8888", { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0, 0x8888 } },
1825 { "1111:2222:3333:4444:5555::", { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0, 0, 0 } },
1826 { "1111:2222:3333:4444:5555:0:7b7b:7b7b", { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0, 0x7b7b, 0x7b7b } },
1827 { "1111:2222:3333:4444:5555:0:7777:8888", { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0, 0x7777, 0x8888 } },
1828 { "1111:2222:3333:4444:5555::8888", { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0, 0, 0x8888 } },
1829 { "1111::", { 0x1111, 0, 0, 0, 0, 0, 0, 0 } },
1830 { "1111::7b7b:7b7b", { 0x1111, 0, 0, 0, 0, 0, 0x7b7b, 0x7b7b } },
1831 { "1111:0:3333:4444:5555:6666:7b7b:7b7b", { 0x1111, 0, 0x3333, 0x4444, 0x5555, 0x6666, 0x7b7b, 0x7b7b } },
1832 { "1111:0:3333:4444:5555:6666:7777:8888", { 0x1111, 0, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0x8888 } },
1833 { "1111::4444:5555:6666:7b7b:7b7b", { 0x1111, 0, 0, 0x4444, 0x5555, 0x6666, 0x7b7b, 0x7b7b } },
1834 { "1111::4444:5555:6666:7777:8888", { 0x1111, 0, 0, 0x4444, 0x5555, 0x6666, 0x7777, 0x8888 } },
1835 { "1111::5555:6666:7b7b:7b7b", { 0x1111, 0, 0, 0, 0x5555, 0x6666, 0x7b7b, 0x7b7b } },
1836 { "1111::5555:6666:7777:8888", { 0x1111, 0, 0, 0, 0x5555, 0x6666, 0x7777, 0x8888 } },
1837 { "1111::6666:7b7b:7b7b", { 0x1111, 0, 0, 0, 0, 0x6666, 0x7b7b, 0x7b7b } },
1838 { "1111::6666:7777:8888", { 0x1111, 0, 0, 0, 0, 0x6666, 0x7777, 0x8888 } },
1839 { "1111::7777:8888", { 0x1111, 0, 0, 0, 0, 0, 0x7777, 0x8888 } },
1840 { "1111::8888", { 0x1111, 0, 0, 0, 0, 0, 0, 0x8888 } },
1841 { "1:2:3:4:5:6:102:304", { 0x100, 0x200, 0x300, 0x400, 0x500, 0x600, 0x201, 0x403 } },
1842 { "1:2:3:4:5:6:7:8", { 0x100, 0x200, 0x300, 0x400, 0x500, 0x600, 0x700, 0x800 } },
1843 { "1:2:3:4:5:6::", { 0x100, 0x200, 0x300, 0x400, 0x500, 0x600, 0, 0 } },
1844 { "1:2:3:4:5:6:0:8", { 0x100, 0x200, 0x300, 0x400, 0x500, 0x600, 0, 0x800 } },
1845 { "2001:0:1234::c1c0:abcd:876", { 0x120, 0, 0x3412, 0, 0, 0xc0c1, 0xcdab, 0x7608 } },
1846 { "2001:0:4136:e378:8000:63bf:3fff:fdd2", { 0x120, 0, 0x3641, 0x78e3, 0x80, 0xbf63, 0xff3f, 0xd2fd } },
1847 { "2001:db8::1428:57ab", { 0x120, 0xb80d, 0, 0, 0, 0, 0x2814, 0xab57 } },
1848 { "2001:db8:1234:ffff:ffff:ffff:ffff:ffff", { 0x120, 0xb80d, 0x3412, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff } },
1849 { "2001:0:ce49:7601:2cad:dfff:7c94:fffe", { 0x120, 0, 0x49ce, 0x176, 0xad2c, 0xffdf, 0x947c, 0xfeff } },
1850 { "2001:db8:85a3::8a2e:370:7334", { 0x120, 0xb80d, 0xa385, 0, 0, 0x2e8a, 0x7003, 0x3473 } },
1851 { "3ffe:b00::1:0:0:a", { 0xfe3f, 0xb, 0, 0, 0x100, 0, 0, 0xa00 } },
1852 { "::a:b:c:d:e", { 0, 0, 0, 0xa00, 0xb00, 0xc00, 0xd00, 0xe00 } },
1853 { "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", { 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff } },
1854 { "1111:2222:3333:4444:5555:6666:7777:1", { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0x100 } },
1855 { "1111:2222:3333:4444:5555:6666:7777:8888", { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0x8888 } },
1856 { "1111:2222::", { 0x1111, 0x2222, 0, 0, 0, 0, 0, 0 } },
1857 { "1111::3333:4444:5555:6666:7777", { 0x1111, 0, 0, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777 } },
1858 { "1111:2222::", { 0x1111, 0x2222, 0, 0, 0, 0, 0, 0 } },
1859 { "1111::3333", { 0x1111, 0, 0, 0, 0, 0, 0, 0x3333 } },
1860 { "2001:0:1234::c1c0:abcd:876", { 0x120, 0, 0x3412, 0, 0, 0xc0c1, 0xcdab, 0x7608 } },
1861 { "2001::ffd3", { 0x120, 0, 0, 0, 0, 0, 0, 0xd3ff } },
1863 unsigned int i;
1865 memset(buffer, '#', sizeof(buffer));
1866 buffer[sizeof(buffer)-1] = 0;
1867 memset(&ip, 0, sizeof(ip));
1868 result = RtlIpv6AddressToStringA(&ip, buffer);
1870 len = strlen(buffer);
1871 ok(result == (buffer + len) && !strcmp(buffer, "::"),
1872 "got %p with '%s' (expected %p with '::')\n", result, buffer, buffer + len);
1874 result = RtlIpv6AddressToStringA(&ip, NULL);
1875 ok(result == (LPCSTR)~0 || broken(result == (LPCSTR)len) /* WinXP / Win2k3 */,
1876 "got %p, expected %p\n", result, (LPCSTR)~0);
1878 for (i = 0; i < ARRAY_SIZE(tests); i++)
1880 init_ip6(&ip, tests[i].ip);
1881 memset(buffer, '#', sizeof(buffer));
1882 buffer[sizeof(buffer)-1] = 0;
1884 result = RtlIpv6AddressToStringA(&ip, buffer);
1885 len = strlen(buffer);
1886 ok(result == (buffer + len) && !strcmp(buffer, tests[i].address),
1887 "got %p with '%s' (expected %p with '%s')\n", result, buffer, buffer + len, tests[i].address);
1889 ok(buffer[45] == 0 || broken(buffer[45] != 0) /* WinXP / Win2k3 */,
1890 "expected data at buffer[45] to always be NULL\n");
1891 ok(buffer[46] == '#', "expected data at buffer[46] not to change\n");
1895 static void test_RtlIpv6AddressToStringEx(void)
1897 CHAR buffer[70];
1898 NTSTATUS res;
1899 IN6_ADDR ip;
1900 ULONG len;
1901 static const struct
1903 PCSTR address;
1904 ULONG scopeid;
1905 USHORT port;
1906 int ip[8];
1907 } tests[] =
1909 /* ipv4 addresses & ISATAP addresses */
1910 { "::13.1.68.3", 0, 0, { 0, 0, 0, 0, 0, 0, 0x10d, 0x344 } },
1911 { "::13.1.68.3%1", 1, 0, { 0, 0, 0, 0, 0, 0, 0x10d, 0x344 } },
1912 { "::13.1.68.3%4294949819", 0xffffbbbb, 0, { 0, 0, 0, 0, 0, 0, 0x10d, 0x344 } },
1913 { "[::13.1.68.3%4294949819]:65518", 0xffffbbbb, 0xeeff, { 0, 0, 0, 0, 0, 0, 0x10d, 0x344 } },
1914 { "[::13.1.68.3%4294949819]:256", 0xffffbbbb, 1, { 0, 0, 0, 0, 0, 0, 0x10d, 0x344 } },
1915 { "[::13.1.68.3]:256", 0, 1, { 0, 0, 0, 0, 0, 0, 0x10d, 0x344 } },
1917 { "::1:d01:4403", 0, 0, { 0, 0, 0, 0, 0, 0x100, 0x10d, 0x344 } },
1918 { "::1:d01:4403%1", 1, 0, { 0, 0, 0, 0, 0, 0x100, 0x10d, 0x344 } },
1919 { "::1:d01:4403%4294949819", 0xffffbbbb, 0, { 0, 0, 0, 0, 0, 0x100, 0x10d, 0x344 } },
1920 { "[::1:d01:4403%4294949819]:65518", 0xffffbbbb, 0xeeff, { 0, 0, 0, 0, 0, 0x100, 0x10d, 0x344 } },
1921 { "[::1:d01:4403%4294949819]:256", 0xffffbbbb, 1, { 0, 0, 0, 0, 0, 0x100, 0x10d, 0x344 } },
1922 { "[::1:d01:4403]:256", 0, 1, { 0, 0, 0, 0, 0, 0x100, 0x10d, 0x344 } },
1924 { "1111:2222:3333:4444:0:5efe:129.144.52.38", 0, 0, { 0x1111, 0x2222, 0x3333, 0x4444, 0, 0xfe5e, 0x9081, 0x2634 } },
1925 { "1111:2222:3333:4444:0:5efe:129.144.52.38%1", 1, 0, { 0x1111, 0x2222, 0x3333, 0x4444, 0, 0xfe5e, 0x9081, 0x2634 } },
1926 { "1111:2222:3333:4444:0:5efe:129.144.52.38%4294949819", 0xffffbbbb, 0, { 0x1111, 0x2222, 0x3333, 0x4444, 0, 0xfe5e, 0x9081, 0x2634 } },
1927 { "[1111:2222:3333:4444:0:5efe:129.144.52.38%4294949819]:65518",0xffffbbbb, 0xeeff, { 0x1111, 0x2222, 0x3333, 0x4444, 0, 0xfe5e, 0x9081, 0x2634 } },
1928 { "[1111:2222:3333:4444:0:5efe:129.144.52.38%4294949819]:256", 0xffffbbbb, 1, { 0x1111, 0x2222, 0x3333, 0x4444, 0, 0xfe5e, 0x9081, 0x2634 } },
1929 { "[1111:2222:3333:4444:0:5efe:129.144.52.38]:256", 0, 1, { 0x1111, 0x2222, 0x3333, 0x4444, 0, 0xfe5e, 0x9081, 0x2634 } },
1931 { "::1", 0, 0, { 0, 0, 0, 0, 0, 0, 0, 0x100 } },
1932 { "::1%1", 1, 0, { 0, 0, 0, 0, 0, 0, 0, 0x100 } },
1933 { "::1%4294949819", 0xffffbbbb, 0, { 0, 0, 0, 0, 0, 0, 0, 0x100 } },
1934 { "[::1%4294949819]:65518", 0xffffbbbb, 0xeeff, { 0, 0, 0, 0, 0, 0, 0, 0x100 } },
1935 { "[::1%4294949819]:256", 0xffffbbbb, 1, { 0, 0, 0, 0, 0, 0, 0, 0x100 } },
1936 { "[::1]:256", 0, 1, { 0, 0, 0, 0, 0, 0, 0, 0x100 } },
1938 { "1111:2222:3333:4444:5555:6666:7b7b:7b7b", 0, 0, { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7b7b, 0x7b7b } },
1939 { "1111:2222:3333:4444:5555:6666:7b7b:7b7b%1", 1, 0, { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7b7b, 0x7b7b } },
1940 { "1111:2222:3333:4444:5555:6666:7b7b:7b7b%4294949819", 0xffffbbbb, 0, { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7b7b, 0x7b7b } },
1941 { "[1111:2222:3333:4444:5555:6666:7b7b:7b7b%4294949819]:65518", 0xffffbbbb, 0xeeff, { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7b7b, 0x7b7b } },
1942 { "[1111:2222:3333:4444:5555:6666:7b7b:7b7b%4294949819]:256", 0xffffbbbb, 1, { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7b7b, 0x7b7b } },
1943 { "[1111:2222:3333:4444:5555:6666:7b7b:7b7b]:256", 0, 1, { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7b7b, 0x7b7b } },
1945 { "1111::", 0, 0, { 0x1111, 0, 0, 0, 0, 0, 0, 0 } },
1946 { "1111::%1", 1, 0, { 0x1111, 0, 0, 0, 0, 0, 0, 0 } },
1947 { "1111::%4294949819", 0xffffbbbb, 0, { 0x1111, 0, 0, 0, 0, 0, 0, 0 } },
1948 { "[1111::%4294949819]:65518", 0xffffbbbb, 0xeeff, { 0x1111, 0, 0, 0, 0, 0, 0, 0 } },
1949 { "[1111::%4294949819]:256", 0xffffbbbb, 1, { 0x1111, 0, 0, 0, 0, 0, 0, 0 } },
1950 { "[1111::]:256", 0, 1, { 0x1111, 0, 0, 0, 0, 0, 0, 0 } },
1952 { "2001::ffd3", 0, 0, { 0x120, 0, 0, 0, 0, 0, 0, 0xd3ff } },
1953 { "2001::ffd3%1", 1, 0, { 0x120, 0, 0, 0, 0, 0, 0, 0xd3ff } },
1954 { "2001::ffd3%4294949819", 0xffffbbbb, 0, { 0x120, 0, 0, 0, 0, 0, 0, 0xd3ff } },
1955 { "[2001::ffd3%4294949819]:65518", 0xffffbbbb, 0xeeff, { 0x120, 0, 0, 0, 0, 0, 0, 0xd3ff } },
1956 { "[2001::ffd3%4294949819]:256", 0xffffbbbb, 1, { 0x120, 0, 0, 0, 0, 0, 0, 0xd3ff } },
1957 { "[2001::ffd3]:256", 0, 1, { 0x120, 0, 0, 0, 0, 0, 0, 0xd3ff } },
1959 unsigned int i;
1961 if (!pRtlIpv6AddressToStringExA)
1963 skip("RtlIpv6AddressToStringExA not available\n");
1964 return;
1967 memset(buffer, '#', sizeof(buffer));
1968 buffer[sizeof(buffer)-1] = 0;
1969 memset(&ip, 0, sizeof(ip));
1970 len = sizeof(buffer);
1971 res = pRtlIpv6AddressToStringExA(&ip, 0, 0, buffer, &len);
1973 ok(res == STATUS_SUCCESS, "[validate] res = 0x%08lx, expected STATUS_SUCCESS\n", res);
1974 ok(len == 3 && !strcmp(buffer, "::"),
1975 "got len %ld with '%s' (expected 3 with '::')\n", len, buffer);
1977 memset(buffer, '#', sizeof(buffer));
1978 buffer[sizeof(buffer)-1] = 0;
1980 len = sizeof(buffer);
1981 res = pRtlIpv6AddressToStringExA(NULL, 0, 0, buffer, &len);
1982 ok(res == STATUS_INVALID_PARAMETER, "[null ip] res = 0x%08lx, expected STATUS_INVALID_PARAMETER\n", res);
1984 len = sizeof(buffer);
1985 res = pRtlIpv6AddressToStringExA(&ip, 0, 0, NULL, &len);
1986 ok(res == STATUS_INVALID_PARAMETER, "[null buffer] res = 0x%08lx, expected STATUS_INVALID_PARAMETER\n", res);
1988 res = pRtlIpv6AddressToStringExA(&ip, 0, 0, buffer, NULL);
1989 ok(res == STATUS_INVALID_PARAMETER, "[null length] res = 0x%08lx, expected STATUS_INVALID_PARAMETER\n", res);
1991 len = 2;
1992 memset(buffer, '#', sizeof(buffer));
1993 buffer[sizeof(buffer)-1] = 0;
1994 res = pRtlIpv6AddressToStringExA(&ip, 0, 0, buffer, &len);
1995 ok(res == STATUS_INVALID_PARAMETER, "[null length] res = 0x%08lx, expected STATUS_INVALID_PARAMETER\n", res);
1996 ok(buffer[0] == '#', "got first char %c (expected '#')\n", buffer[0]);
1997 ok(len == 3, "got len %ld (expected len 3)\n", len);
1999 for (i = 0; i < ARRAY_SIZE(tests); i++)
2001 init_ip6(&ip, tests[i].ip);
2002 len = sizeof(buffer);
2003 memset(buffer, '#', sizeof(buffer));
2004 buffer[sizeof(buffer)-1] = 0;
2006 res = pRtlIpv6AddressToStringExA(&ip, tests[i].scopeid, tests[i].port, buffer, &len);
2008 ok(res == STATUS_SUCCESS, "[validate] res = 0x%08lx, expected STATUS_SUCCESS\n", res);
2009 ok(len == (strlen(tests[i].address) + 1) && !strcmp(buffer, tests[i].address),
2010 "got len %ld with '%s' (expected %d with '%s')\n", len, buffer, (int)strlen(tests[i].address), tests[i].address);
2014 static void compare_RtlIpv6StringToAddressW(PCSTR name_a, int terminator_offset_a,
2015 const struct in6_addr *addr_a, NTSTATUS res_a)
2017 WCHAR name[512];
2018 NTSTATUS res;
2019 IN6_ADDR ip;
2020 PCWSTR terminator;
2022 RtlMultiByteToUnicodeN(name, sizeof(name), NULL, name_a, strlen(name_a) + 1);
2024 init_ip6(&ip, NULL);
2025 terminator = (void *)0xdeadbeef;
2026 res = RtlIpv6StringToAddressW(name, &terminator, &ip);
2027 ok(res == res_a, "[W:%s] res = 0x%08lx, expected 0x%08lx\n", name_a, res, res_a);
2029 if (terminator_offset_a < 0)
2031 ok(terminator == (void *)0xdeadbeef,
2032 "[W:%s] terminator = %p, expected it not to change\n",
2033 name_a, terminator);
2035 else
2037 ok(terminator == name + terminator_offset_a,
2038 "[W:%s] terminator = %p, expected %p\n",
2039 name_a, terminator, name + terminator_offset_a);
2042 ok(!memcmp(&ip, addr_a, sizeof(ip)),
2043 "[W:%s] ip = %x:%x:%x:%x:%x:%x:%x:%x, expected %x:%x:%x:%x:%x:%x:%x:%x\n",
2044 name_a,
2045 ip.s6_words[0], ip.s6_words[1], ip.s6_words[2], ip.s6_words[3],
2046 ip.s6_words[4], ip.s6_words[5], ip.s6_words[6], ip.s6_words[7],
2047 addr_a->s6_words[0], addr_a->s6_words[1], addr_a->s6_words[2], addr_a->s6_words[3],
2048 addr_a->s6_words[4], addr_a->s6_words[5], addr_a->s6_words[6], addr_a->s6_words[7]);
2051 static void test_RtlIpv6StringToAddress(void)
2053 NTSTATUS res;
2054 IN6_ADDR ip, expected_ip;
2055 PCSTR terminator;
2056 unsigned int i;
2058 res = RtlIpv6StringToAddressA("::", &terminator, &ip);
2059 ok(res == STATUS_SUCCESS, "[validate] res = 0x%08lx, expected STATUS_SUCCESS\n", res);
2060 if (0)
2062 /* any of these crash */
2063 res = RtlIpv6StringToAddressA(NULL, &terminator, &ip);
2064 ok(res == STATUS_INVALID_PARAMETER, "[null string] res = 0x%08lx, expected STATUS_INVALID_PARAMETER\n", res);
2065 res = RtlIpv6StringToAddressA("::", NULL, &ip);
2066 ok(res == STATUS_INVALID_PARAMETER, "[null terminator] res = 0x%08lx, expected STATUS_INVALID_PARAMETER\n", res);
2067 res = RtlIpv6StringToAddressA("::", &terminator, NULL);
2068 ok(res == STATUS_INVALID_PARAMETER, "[null result] res = 0x%08lx, expected STATUS_INVALID_PARAMETER\n", res);
2071 /* sanity check */
2072 ok(sizeof(ip) == sizeof(USHORT)* 8, "sizeof(ip)\n");
2074 for (i = 0; i < ARRAY_SIZE(ipv6_tests); i++)
2076 init_ip6(&ip, NULL);
2077 terminator = (void *)0xdeadbeef;
2078 res = RtlIpv6StringToAddressA(ipv6_tests[i].address, &terminator, &ip);
2079 compare_RtlIpv6StringToAddressW(ipv6_tests[i].address, (terminator != (void *)0xdeadbeef) ?
2080 (terminator - ipv6_tests[i].address) : -1, &ip, res);
2082 if (ipv6_tests[i].flags & win_broken_6)
2084 ok(res == ipv6_tests[i].res || broken(res == STATUS_INVALID_PARAMETER),
2085 "[%s] res = 0x%08lx, expected 0x%08lx\n",
2086 ipv6_tests[i].address, res, ipv6_tests[i].res);
2088 if (res == STATUS_INVALID_PARAMETER)
2089 continue;
2091 else
2093 ok(res == ipv6_tests[i].res,
2094 "[%s] res = 0x%08lx, expected 0x%08lx\n",
2095 ipv6_tests[i].address, res, ipv6_tests[i].res);
2098 if (ipv6_tests[i].terminator_offset < 0)
2100 ok(terminator == (void *)0xdeadbeef,
2101 "[%s] terminator = %p, expected it not to change\n",
2102 ipv6_tests[i].address, terminator);
2104 else
2106 ok(terminator == ipv6_tests[i].address + ipv6_tests[i].terminator_offset,
2107 "[%s] terminator = %p, expected %p\n",
2108 ipv6_tests[i].address, terminator, ipv6_tests[i].address + ipv6_tests[i].terminator_offset);
2111 init_ip6(&expected_ip, ipv6_tests[i].ip);
2112 ok(!memcmp(&ip, &expected_ip, sizeof(ip)),
2113 "[%s] ip = %x:%x:%x:%x:%x:%x:%x:%x, expected %x:%x:%x:%x:%x:%x:%x:%x\n",
2114 ipv6_tests[i].address,
2115 ip.s6_words[0], ip.s6_words[1], ip.s6_words[2], ip.s6_words[3],
2116 ip.s6_words[4], ip.s6_words[5], ip.s6_words[6], ip.s6_words[7],
2117 expected_ip.s6_words[0], expected_ip.s6_words[1], expected_ip.s6_words[2], expected_ip.s6_words[3],
2118 expected_ip.s6_words[4], expected_ip.s6_words[5], expected_ip.s6_words[6], expected_ip.s6_words[7]);
2122 static void compare_RtlIpv6StringToAddressExW(PCSTR name_a, const struct in6_addr *addr_a, HRESULT res_a, ULONG scope_a, USHORT port_a)
2124 WCHAR name[512];
2125 NTSTATUS res;
2126 IN6_ADDR ip;
2127 ULONG scope = 0xbadf00d;
2128 USHORT port = 0xbeef;
2130 if (!pRtlIpv6StringToAddressExW)
2131 return;
2133 RtlMultiByteToUnicodeN(name, sizeof(name), NULL, name_a, strlen(name_a) + 1);
2135 init_ip6(&ip, NULL);
2136 res = pRtlIpv6StringToAddressExW(name, &ip, &scope, &port);
2138 ok(res == res_a, "[W:%s] res = 0x%08lx, expected 0x%08lx\n", name_a, res, res_a);
2139 ok(scope == scope_a, "[W:%s] scope = 0x%08lx, expected 0x%08lx\n", name_a, scope, scope_a);
2140 ok(port == port_a, "[W:%s] port = 0x%08x, expected 0x%08x\n", name_a, port, port_a);
2142 ok(!memcmp(&ip, addr_a, sizeof(ip)),
2143 "[W:%s] ip = %x:%x:%x:%x:%x:%x:%x:%x, expected %x:%x:%x:%x:%x:%x:%x:%x\n",
2144 name_a,
2145 ip.s6_words[0], ip.s6_words[1], ip.s6_words[2], ip.s6_words[3],
2146 ip.s6_words[4], ip.s6_words[5], ip.s6_words[6], ip.s6_words[7],
2147 addr_a->s6_words[0], addr_a->s6_words[1], addr_a->s6_words[2], addr_a->s6_words[3],
2148 addr_a->s6_words[4], addr_a->s6_words[5], addr_a->s6_words[6], addr_a->s6_words[7]);
2151 static void test_RtlIpv6StringToAddressEx(void)
2153 NTSTATUS res;
2154 IN6_ADDR ip, expected_ip;
2155 ULONG scope;
2156 USHORT port;
2157 static const struct
2159 PCSTR address;
2160 NTSTATUS res;
2161 ULONG scope;
2162 USHORT port;
2163 int ip[8];
2164 } ipv6_ex_tests[] =
2166 { "[::]", STATUS_SUCCESS, 0, 0,
2167 { 0, 0, 0, 0, 0, 0, 0, 0 } },
2168 { "[::1]:8080", STATUS_SUCCESS, 0, 0x901f,
2169 { 0, 0, 0, 0, 0, 0, 0, 0x100 } },
2170 { "[::1]:0x80", STATUS_SUCCESS, 0, 0x8000,
2171 { 0, 0, 0, 0, 0, 0, 0, 0x100 } },
2172 { "[::1]:0X80", STATUS_SUCCESS, 0, 0x8000,
2173 { 0, 0, 0, 0, 0, 0, 0, 0x100 } },
2174 { "[::1]:080", STATUS_INVALID_PARAMETER, 0xbadf00d, 0xbeef,
2175 { 0, 0, 0, 0, 0, 0, 0, 0x100 } },
2176 { "[::1]:800000000080", STATUS_INVALID_PARAMETER, 0xbadf00d, 0xbeef,
2177 { 0, 0, 0, 0, 0, 0, 0, 0x100 } },
2178 { "[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80", STATUS_SUCCESS, 0, 0x5000,
2179 { 0xdcfe, 0x98ba, 0x5476, 0x1032, 0xdcfe, 0x98ba, 0x5476, 0x1032 } },
2180 { "[1080:0:0:0:8:800:200C:417A]:1234", STATUS_SUCCESS, 0, 0xd204,
2181 { 0x8010, 0, 0, 0, 0x800, 8, 0xc20, 0x7a41 } },
2182 { "[3ffe:2a00:100:7031::1]:8080", STATUS_SUCCESS, 0, 0x901f,
2183 { 0xfe3f, 0x2a, 1, 0x3170, 0, 0, 0, 0x100 } },
2184 { "[ 3ffe:2a00:100:7031::1]:8080", STATUS_INVALID_PARAMETER, 0xbadf00d, 0xbeef,
2185 { -1 } },
2186 { "[3ffe:2a00:100:7031::1 ]:8080", STATUS_INVALID_PARAMETER, 0xbadf00d, 0xbeef,
2187 { 0xfe3f, 0x2a, 1, 0x3170, 0, 0, 0, 0x100 } },
2188 { "[3ffe:2a00:100:7031::1].8080", STATUS_INVALID_PARAMETER, 0xbadf00d, 0xbeef,
2189 { 0xfe3f, 0x2a, 1, 0x3170, 0, 0, 0, 0x100 } },
2190 { "[1080::8:800:200C:417A]:8080", STATUS_SUCCESS, 0, 0x901f,
2191 { 0x8010, 0, 0, 0, 0x800, 8, 0xc20, 0x7a41 } },
2192 { "[1080::8:800:200C:417A]!8080", STATUS_INVALID_PARAMETER, 0xbadf00d, 0xbeef,
2193 { 0x8010, 0, 0, 0, 0x800, 8, 0xc20, 0x7a41 } },
2194 { "[::FFFF:129.144.52.38]:80", STATUS_SUCCESS, 0, 0x5000,
2195 { 0, 0, 0, 0, 0, 0xffff, 0x9081, 0x2634 } },
2196 { "[::FFFF:129.144.52.38]:-80", STATUS_INVALID_PARAMETER, 0xbadf00d, 0xbeef,
2197 { 0, 0, 0, 0, 0, 0xffff, 0x9081, 0x2634 } },
2198 { "[::FFFF:129.144.52.38]:999999999999", STATUS_INVALID_PARAMETER, 0xbadf00d, 0xbeef,
2199 { 0, 0, 0, 0, 0, 0xffff, 0x9081, 0x2634 } },
2200 { "[::FFFF:129.144.52.38%-8]:80", STATUS_INVALID_PARAMETER, 0xbadf00d, 0xbeef,
2201 { 0, 0, 0, 0, 0, 0xffff, 0x9081, 0x2634 } },
2202 { "[::FFFF:129.144.52.38]:80", STATUS_SUCCESS, 0, 0x5000,
2203 { 0, 0, 0, 0, 0, 0xffff, 0x9081, 0x2634 } },
2204 { "[12345::6:7:8]:80", STATUS_INVALID_PARAMETER, 0xbadf00d, 0xbeef,
2205 { -1 } },
2206 { "[ff01::8:800:200C:417A%16]:8080", STATUS_SUCCESS, 16, 0x901f,
2207 { 0x1ff, 0, 0, 0, 0x800, 8, 0xc20, 0x7a41 } },
2208 { "[ff01::8:800:200C:417A%100]:8080", STATUS_SUCCESS, 100, 0x901f,
2209 { 0x1ff, 0, 0, 0, 0x800, 8, 0xc20, 0x7a41 } },
2210 { "[ff01::8:800:200C:417A%1000]:8080", STATUS_SUCCESS, 1000, 0x901f,
2211 { 0x1ff, 0, 0, 0, 0x800, 8, 0xc20, 0x7a41 } },
2212 { "[ff01::8:800:200C:417A%10000]:8080", STATUS_SUCCESS, 10000, 0x901f,
2213 { 0x1ff, 0, 0, 0, 0x800, 8, 0xc20, 0x7a41 } },
2214 { "[ff01::8:800:200C:417A%1000000]:8080", STATUS_SUCCESS, 1000000, 0x901f,
2215 { 0x1ff, 0, 0, 0, 0x800, 8, 0xc20, 0x7a41 } },
2216 { "[ff01::8:800:200C:417A%4294967295]:8080", STATUS_SUCCESS, 0xffffffff, 0x901f,
2217 { 0x1ff, 0, 0, 0, 0x800, 8, 0xc20, 0x7a41 } },
2218 { "[ff01::8:800:200C:417A%4294967296]:8080", STATUS_INVALID_PARAMETER, 0xbadf00d, 0xbeef,
2219 { 0x1ff, 0, 0, 0, 0x800, 8, 0xc20, 0x7a41 } },
2220 { "[ff01::8:800:200C:417A%-1]:8080", STATUS_INVALID_PARAMETER, 0xbadf00d, 0xbeef,
2221 { 0x1ff, 0, 0, 0, 0x800, 8, 0xc20, 0x7a41 } },
2222 { "[ff01::8:800:200C:417A%0]:8080", STATUS_SUCCESS, 0, 0x901f,
2223 { 0x1ff, 0, 0, 0, 0x800, 8, 0xc20, 0x7a41 } },
2224 { "[ff01::8:800:200C:417A%1", STATUS_INVALID_PARAMETER, 0xbadf00d, 0xbeef,
2225 { 0x1ff, 0, 0, 0, 0x800, 8, 0xc20, 0x7a41 } },
2226 { "[ff01::8:800:200C:417A%0x1000]:8080", STATUS_INVALID_PARAMETER, 0xbadf00d, 0xbeef,
2227 { 0x1ff, 0, 0, 0, 0x800, 8, 0xc20, 0x7a41 } },
2228 { "[ff01::8:800:200C:417A/16]:8080", STATUS_INVALID_PARAMETER, 0xbadf00d, 0xbeef,
2229 { 0x1ff, 0, 0, 0, 0x800, 8, 0xc20, 0x7a41 } },
2231 const char *simple_ip = "::";
2232 unsigned int i;
2234 if (!pRtlIpv6StringToAddressExW)
2236 skip("RtlIpv6StringToAddressExW not available\n");
2237 /* we can continue, just not test W */
2240 if (!pRtlIpv6StringToAddressExA)
2242 skip("RtlIpv6StringToAddressExA not available\n");
2243 return;
2246 res = pRtlIpv6StringToAddressExA(simple_ip, &ip, &scope, &port);
2247 ok(res == STATUS_SUCCESS, "[validate] res = 0x%08lx, expected STATUS_SUCCESS\n", res);
2249 init_ip6(&ip, NULL);
2250 init_ip6(&expected_ip, NULL);
2251 scope = 0xbadf00d;
2252 port = 0xbeef;
2253 res = pRtlIpv6StringToAddressExA(NULL, &ip, &scope, &port);
2254 ok(res == STATUS_INVALID_PARAMETER,
2255 "[null string] res = 0x%08lx, expected STATUS_INVALID_PARAMETER\n", res);
2256 ok(scope == 0xbadf00d, "[null string] scope = 0x%08lx, expected 0xbadf00d\n", scope);
2257 ok(port == 0xbeef, "[null string] port = 0x%08x, expected 0xbeef\n", port);
2258 ok(!memcmp(&ip, &expected_ip, sizeof(ip)),
2259 "[null string] ip is changed, expected it not to change\n");
2262 init_ip6(&ip, NULL);
2263 scope = 0xbadf00d;
2264 port = 0xbeef;
2265 res = pRtlIpv6StringToAddressExA(simple_ip, NULL, &scope, &port);
2266 ok(res == STATUS_INVALID_PARAMETER,
2267 "[null result] res = 0x%08lx, expected STATUS_INVALID_PARAMETER\n", res);
2268 ok(scope == 0xbadf00d, "[null result] scope = 0x%08lx, expected 0xbadf00d\n", scope);
2269 ok(port == 0xbeef, "[null result] port = 0x%08x, expected 0xbeef\n", port);
2270 ok(!memcmp(&ip, &expected_ip, sizeof(ip)),
2271 "[null result] ip is changed, expected it not to change\n");
2273 init_ip6(&ip, NULL);
2274 scope = 0xbadf00d;
2275 port = 0xbeef;
2276 res = pRtlIpv6StringToAddressExA(simple_ip, &ip, NULL, &port);
2277 ok(res == STATUS_INVALID_PARAMETER,
2278 "[null scope] res = 0x%08lx, expected STATUS_INVALID_PARAMETER\n", res);
2279 ok(scope == 0xbadf00d, "[null scope] scope = 0x%08lx, expected 0xbadf00d\n", scope);
2280 ok(port == 0xbeef, "[null scope] port = 0x%08x, expected 0xbeef\n", port);
2281 ok(!memcmp(&ip, &expected_ip, sizeof(ip)),
2282 "[null scope] ip is changed, expected it not to change\n");
2284 init_ip6(&ip, NULL);
2285 scope = 0xbadf00d;
2286 port = 0xbeef;
2287 res = pRtlIpv6StringToAddressExA(simple_ip, &ip, &scope, NULL);
2288 ok(res == STATUS_INVALID_PARAMETER,
2289 "[null port] res = 0x%08lx, expected STATUS_INVALID_PARAMETER\n", res);
2290 ok(scope == 0xbadf00d, "[null port] scope = 0x%08lx, expected 0xbadf00d\n", scope);
2291 ok(port == 0xbeef, "[null port] port = 0x%08x, expected 0xbeef\n", port);
2292 ok(!memcmp(&ip, &expected_ip, sizeof(ip)),
2293 "[null port] ip is changed, expected it not to change\n");
2295 /* sanity check */
2296 ok(sizeof(ip) == sizeof(USHORT)* 8, "sizeof(ip)\n");
2298 /* first we run all ip related tests, to make sure someone didn't accidentally reimplement instead of re-use. */
2299 for (i = 0; i < ARRAY_SIZE(ipv6_tests); i++)
2301 ULONG scope = 0xbadf00d;
2302 USHORT port = 0xbeef;
2303 NTSTATUS expect_ret = (ipv6_tests[i].flags & ex_fail_6) ? STATUS_INVALID_PARAMETER : ipv6_tests[i].res;
2305 if (ipv6_tests[i].flags & ex_skip_6)
2306 continue;
2308 init_ip6(&ip, NULL);
2309 res = pRtlIpv6StringToAddressExA(ipv6_tests[i].address, &ip, &scope, &port);
2310 compare_RtlIpv6StringToAddressExW(ipv6_tests[i].address, &ip, res, scope, port);
2312 /* make sure nothing was changed if this function fails. */
2313 if (res == STATUS_INVALID_PARAMETER)
2315 ok(scope == 0xbadf00d, "[%s] scope = 0x%08lx, expected 0xbadf00d\n",
2316 ipv6_tests[i].address, scope);
2317 ok(port == 0xbeef, "[%s] port = 0x%08x, expected 0xbeef\n",
2318 ipv6_tests[i].address, port);
2320 else
2322 ok(scope != 0xbadf00d, "[%s] scope = 0x%08lx, not expected 0xbadf00d\n",
2323 ipv6_tests[i].address, scope);
2324 ok(port != 0xbeef, "[%s] port = 0x%08x, not expected 0xbeef\n",
2325 ipv6_tests[i].address, port);
2328 if (ipv6_tests[i].flags & win_broken_6)
2330 ok(res == expect_ret || broken(res == STATUS_INVALID_PARAMETER),
2331 "[%s] res = 0x%08lx, expected 0x%08lx\n", ipv6_tests[i].address, res, expect_ret);
2333 if (res == STATUS_INVALID_PARAMETER)
2334 continue;
2336 else
2338 ok(res == expect_ret, "[%s] res = 0x%08lx, expected 0x%08lx\n",
2339 ipv6_tests[i].address, res, expect_ret);
2342 /* If ex fails but non-ex does not we cannot check if the part that is converted
2343 before it failed was correct, since there is no data for it in the table. */
2344 if (res == expect_ret)
2346 init_ip6(&expected_ip, ipv6_tests[i].ip);
2347 ok(!memcmp(&ip, &expected_ip, sizeof(ip)),
2348 "[%s] ip = %x:%x:%x:%x:%x:%x:%x:%x, expected %x:%x:%x:%x:%x:%x:%x:%x\n",
2349 ipv6_tests[i].address,
2350 ip.s6_words[0], ip.s6_words[1], ip.s6_words[2], ip.s6_words[3],
2351 ip.s6_words[4], ip.s6_words[5], ip.s6_words[6], ip.s6_words[7],
2352 expected_ip.s6_words[0], expected_ip.s6_words[1], expected_ip.s6_words[2], expected_ip.s6_words[3],
2353 expected_ip.s6_words[4], expected_ip.s6_words[5], expected_ip.s6_words[6], expected_ip.s6_words[7]);
2357 /* now we run scope / port related tests */
2358 for (i = 0; i < ARRAY_SIZE(ipv6_ex_tests); i++)
2360 scope = 0xbadf00d;
2361 port = 0xbeef;
2362 init_ip6(&ip, NULL);
2363 res = pRtlIpv6StringToAddressExA(ipv6_ex_tests[i].address, &ip, &scope, &port);
2364 compare_RtlIpv6StringToAddressExW(ipv6_ex_tests[i].address, &ip, res, scope, port);
2366 ok(res == ipv6_ex_tests[i].res, "[%s] res = 0x%08lx, expected 0x%08lx\n",
2367 ipv6_ex_tests[i].address, res, ipv6_ex_tests[i].res);
2368 ok(scope == ipv6_ex_tests[i].scope, "[%s] scope = 0x%08lx, expected 0x%08lx\n",
2369 ipv6_ex_tests[i].address, scope, ipv6_ex_tests[i].scope);
2370 ok(port == ipv6_ex_tests[i].port, "[%s] port = 0x%08x, expected 0x%08x\n",
2371 ipv6_ex_tests[i].address, port, ipv6_ex_tests[i].port);
2373 init_ip6(&expected_ip, ipv6_ex_tests[i].ip);
2374 ok(!memcmp(&ip, &expected_ip, sizeof(ip)),
2375 "[%s] ip = %x:%x:%x:%x:%x:%x:%x:%x, expected %x:%x:%x:%x:%x:%x:%x:%x\n",
2376 ipv6_ex_tests[i].address,
2377 ip.s6_words[0], ip.s6_words[1], ip.s6_words[2], ip.s6_words[3],
2378 ip.s6_words[4], ip.s6_words[5], ip.s6_words[6], ip.s6_words[7],
2379 expected_ip.s6_words[0], expected_ip.s6_words[1], expected_ip.s6_words[2], expected_ip.s6_words[3],
2380 expected_ip.s6_words[4], expected_ip.s6_words[5], expected_ip.s6_words[6], expected_ip.s6_words[7]);
2384 static void test_LdrAddRefDll(void)
2386 HMODULE mod, mod2;
2387 NTSTATUS status;
2388 BOOL ret;
2390 mod = LoadLibraryA("comctl32.dll");
2391 ok(mod != NULL, "got %p\n", mod);
2392 ret = FreeLibrary(mod);
2393 ok(ret, "got %d\n", ret);
2395 mod2 = GetModuleHandleA("comctl32.dll");
2396 ok(mod2 == NULL, "got %p\n", mod2);
2398 /* load, addref and release 2 times */
2399 mod = LoadLibraryA("comctl32.dll");
2400 ok(mod != NULL, "got %p\n", mod);
2401 status = LdrAddRefDll(0, mod);
2402 ok(status == STATUS_SUCCESS, "got 0x%08lx\n", status);
2403 ret = FreeLibrary(mod);
2404 ok(ret, "got %d\n", ret);
2406 mod2 = GetModuleHandleA("comctl32.dll");
2407 ok(mod2 != NULL, "got %p\n", mod2);
2408 ret = FreeLibrary(mod);
2409 ok(ret, "got %d\n", ret);
2411 mod2 = GetModuleHandleA("comctl32.dll");
2412 ok(mod2 == NULL, "got %p\n", mod2);
2414 /* pin refcount */
2415 mod = LoadLibraryA("comctl32.dll");
2416 ok(mod != NULL, "got %p\n", mod);
2417 status = LdrAddRefDll(LDR_ADDREF_DLL_PIN, mod);
2418 ok(status == STATUS_SUCCESS, "got 0x%08lx\n", status);
2420 ret = FreeLibrary(mod);
2421 ok(ret, "got %d\n", ret);
2422 ret = FreeLibrary(mod);
2423 ok(ret, "got %d\n", ret);
2424 ret = FreeLibrary(mod);
2425 ok(ret, "got %d\n", ret);
2426 ret = FreeLibrary(mod);
2427 ok(ret, "got %d\n", ret);
2429 mod2 = GetModuleHandleA("comctl32.dll");
2430 ok(mod2 != NULL, "got %p\n", mod2);
2433 static void test_LdrLockLoaderLock(void)
2435 ULONG_PTR magic;
2436 ULONG result;
2437 NTSTATUS status;
2439 /* invalid flags */
2440 result = 10;
2441 magic = 0xdeadbeef;
2442 status = LdrLockLoaderLock(0x10, &result, &magic);
2443 ok(status == STATUS_INVALID_PARAMETER_1, "got 0x%08lx\n", status);
2444 ok(result == 0, "got %ld\n", result);
2445 ok(magic == 0, "got %Ix\n", magic);
2447 magic = 0xdeadbeef;
2448 status = LdrLockLoaderLock(0x10, NULL, &magic);
2449 ok(status == STATUS_INVALID_PARAMETER_1, "got 0x%08lx\n", status);
2450 ok(magic == 0, "got %Ix\n", magic);
2452 result = 10;
2453 status = LdrLockLoaderLock(0x10, &result, NULL);
2454 ok(status == STATUS_INVALID_PARAMETER_1, "got 0x%08lx\n", status);
2455 ok(result == 0, "got %ld\n", result);
2457 /* non-blocking mode, result is null */
2458 magic = 0xdeadbeef;
2459 status = LdrLockLoaderLock(0x2, NULL, &magic);
2460 ok(status == STATUS_INVALID_PARAMETER_2, "got 0x%08lx\n", status);
2461 ok(magic == 0, "got %Ix\n", magic);
2463 /* magic pointer is null */
2464 result = 10;
2465 status = LdrLockLoaderLock(0, &result, NULL);
2466 ok(status == STATUS_INVALID_PARAMETER_3, "got 0x%08lx\n", status);
2467 ok(result == 0, "got %ld\n", result);
2469 /* lock in non-blocking mode */
2470 result = 0;
2471 magic = 0;
2472 status = LdrLockLoaderLock(0x2, &result, &magic);
2473 ok(status == STATUS_SUCCESS, "got 0x%08lx\n", status);
2474 ok(result == 1, "got %ld\n", result);
2475 ok(magic != 0, "got %Ix\n", magic);
2476 LdrUnlockLoaderLock(0, magic);
2479 static void test_RtlCompressBuffer(void)
2481 ULONG compress_workspace, decompress_workspace;
2482 static UCHAR test_buffer[] = "WineWineWine";
2483 static UCHAR buf1[0x1000], buf2[0x1000];
2484 ULONG final_size, buf_size;
2485 UCHAR *workspace = NULL;
2486 NTSTATUS status;
2488 compress_workspace = decompress_workspace = 0xdeadbeef;
2489 status = RtlGetCompressionWorkSpaceSize(COMPRESSION_FORMAT_LZNT1, &compress_workspace,
2490 &decompress_workspace);
2491 ok(status == STATUS_SUCCESS, "got wrong status 0x%08lx\n", status);
2492 ok(compress_workspace != 0, "got wrong compress_workspace %lu\n", compress_workspace);
2493 workspace = HeapAlloc(GetProcessHeap(), 0, compress_workspace);
2494 ok(workspace != NULL, "HeapAlloc failed %ld\n", GetLastError());
2496 /* test compression format / engine */
2497 final_size = 0xdeadbeef;
2498 status = RtlCompressBuffer(COMPRESSION_FORMAT_NONE, test_buffer, sizeof(test_buffer),
2499 buf1, sizeof(buf1) - 1, 4096, &final_size, workspace);
2500 ok(status == STATUS_INVALID_PARAMETER, "got wrong status 0x%08lx\n", status);
2501 ok(final_size == 0xdeadbeef, "got wrong final_size %lu\n", final_size);
2503 final_size = 0xdeadbeef;
2504 status = RtlCompressBuffer(COMPRESSION_FORMAT_DEFAULT, test_buffer, sizeof(test_buffer),
2505 buf1, sizeof(buf1) - 1, 4096, &final_size, workspace);
2506 ok(status == STATUS_INVALID_PARAMETER, "got wrong status 0x%08lx\n", status);
2507 ok(final_size == 0xdeadbeef, "got wrong final_size %lu\n", final_size);
2509 final_size = 0xdeadbeef;
2510 status = RtlCompressBuffer(0xFF, test_buffer, sizeof(test_buffer),
2511 buf1, sizeof(buf1) - 1, 4096, &final_size, workspace);
2512 ok(status == STATUS_UNSUPPORTED_COMPRESSION, "got wrong status 0x%08lx\n", status);
2513 ok(final_size == 0xdeadbeef, "got wrong final_size %lu\n", final_size);
2515 /* test compression */
2516 final_size = 0xdeadbeef;
2517 memset(buf1, 0x11, sizeof(buf1));
2518 status = RtlCompressBuffer(COMPRESSION_FORMAT_LZNT1, test_buffer, sizeof(test_buffer),
2519 buf1, sizeof(buf1), 4096, &final_size, workspace);
2520 ok(status == STATUS_SUCCESS, "got wrong status 0x%08lx\n", status);
2521 ok((*(WORD *)buf1 & 0x7000) == 0x3000, "no chunk signature found %04x\n", *(WORD *)buf1);
2522 todo_wine
2523 ok(final_size < sizeof(test_buffer), "got wrong final_size %lu\n", final_size);
2525 /* test decompression */
2526 buf_size = final_size;
2527 final_size = 0xdeadbeef;
2528 memset(buf2, 0x11, sizeof(buf2));
2529 status = RtlDecompressBuffer(COMPRESSION_FORMAT_LZNT1, buf2, sizeof(buf2),
2530 buf1, buf_size, &final_size);
2531 ok(status == STATUS_SUCCESS, "got wrong status 0x%08lx\n", status);
2532 ok(final_size == sizeof(test_buffer), "got wrong final_size %lu\n", final_size);
2533 ok(!memcmp(buf2, test_buffer, sizeof(test_buffer)), "got wrong decoded data\n");
2534 ok(buf2[sizeof(test_buffer)] == 0x11, "too many bytes written\n");
2536 /* buffer too small */
2537 final_size = 0xdeadbeef;
2538 memset(buf1, 0x11, sizeof(buf1));
2539 status = RtlCompressBuffer(COMPRESSION_FORMAT_LZNT1, test_buffer, sizeof(test_buffer),
2540 buf1, 4, 4096, &final_size, workspace);
2541 ok(status == STATUS_BUFFER_TOO_SMALL, "got wrong status 0x%08lx\n", status);
2543 HeapFree(GetProcessHeap(), 0, workspace);
2546 static void test_RtlGetCompressionWorkSpaceSize(void)
2548 ULONG compress_workspace, decompress_workspace;
2549 NTSTATUS status;
2551 /* test invalid format / engine */
2552 status = RtlGetCompressionWorkSpaceSize(COMPRESSION_FORMAT_NONE, &compress_workspace,
2553 &decompress_workspace);
2554 ok(status == STATUS_INVALID_PARAMETER, "got wrong status 0x%08lx\n", status);
2556 status = RtlGetCompressionWorkSpaceSize(COMPRESSION_FORMAT_DEFAULT, &compress_workspace,
2557 &decompress_workspace);
2558 ok(status == STATUS_INVALID_PARAMETER, "got wrong status 0x%08lx\n", status);
2560 status = RtlGetCompressionWorkSpaceSize(0xFF, &compress_workspace, &decompress_workspace);
2561 ok(status == STATUS_UNSUPPORTED_COMPRESSION, "got wrong status 0x%08lx\n", status);
2563 /* test LZNT1 with normal and maximum compression */
2564 compress_workspace = decompress_workspace = 0xdeadbeef;
2565 status = RtlGetCompressionWorkSpaceSize(COMPRESSION_FORMAT_LZNT1, &compress_workspace,
2566 &decompress_workspace);
2567 ok(status == STATUS_SUCCESS, "got wrong status 0x%08lx\n", status);
2568 ok(compress_workspace != 0, "got wrong compress_workspace %lu\n", compress_workspace);
2569 ok(decompress_workspace == 0x1000, "got wrong decompress_workspace %lu\n", decompress_workspace);
2571 compress_workspace = decompress_workspace = 0xdeadbeef;
2572 status = RtlGetCompressionWorkSpaceSize(COMPRESSION_FORMAT_LZNT1 | COMPRESSION_ENGINE_MAXIMUM,
2573 &compress_workspace, &decompress_workspace);
2574 ok(status == STATUS_SUCCESS, "got wrong status 0x%08lx\n", status);
2575 ok(compress_workspace != 0, "got wrong compress_workspace %lu\n", compress_workspace);
2576 ok(decompress_workspace == 0x1000, "got wrong decompress_workspace %lu\n", decompress_workspace);
2579 /* helper for test_RtlDecompressBuffer, checks if a chunk is incomplete */
2580 static BOOL is_incomplete_chunk(const UCHAR *compressed, ULONG compressed_size, BOOL check_all)
2582 ULONG chunk_size;
2584 if (compressed_size <= sizeof(WORD))
2585 return TRUE;
2587 while (compressed_size >= sizeof(WORD))
2589 chunk_size = (*(WORD *)compressed & 0xFFF) + 1;
2590 if (compressed_size < sizeof(WORD) + chunk_size)
2591 return TRUE;
2592 if (!check_all)
2593 break;
2594 compressed += sizeof(WORD) + chunk_size;
2595 compressed_size -= sizeof(WORD) + chunk_size;
2598 return FALSE;
2601 #define DECOMPRESS_BROKEN_FRAGMENT 1 /* < Win 7 */
2602 #define DECOMPRESS_BROKEN_TRUNCATED 2 /* broken on all machines */
2604 static void test_RtlDecompressBuffer(void)
2606 static struct
2608 UCHAR compressed[32];
2609 ULONG compressed_size;
2610 NTSTATUS status;
2611 UCHAR uncompressed[32];
2612 ULONG uncompressed_size;
2613 DWORD broken_flags;
2615 test_lznt[] =
2617 /* 4 byte uncompressed chunk */
2619 {0x03, 0x30, 'W', 'i', 'n', 'e'},
2621 STATUS_SUCCESS,
2622 "Wine",
2624 DECOMPRESS_BROKEN_FRAGMENT
2626 /* 8 byte uncompressed chunk */
2628 {0x07, 0x30, 'W', 'i', 'n', 'e', 'W', 'i', 'n', 'e'},
2630 STATUS_SUCCESS,
2631 "WineWine",
2633 DECOMPRESS_BROKEN_FRAGMENT
2635 /* 4 byte compressed chunk */
2637 {0x04, 0xB0, 0x00, 'W', 'i', 'n', 'e'},
2639 STATUS_SUCCESS,
2640 "Wine",
2643 /* 8 byte compressed chunk */
2645 {0x08, 0xB0, 0x00, 'W', 'i', 'n', 'e', 'W', 'i', 'n', 'e'},
2647 STATUS_SUCCESS,
2648 "WineWine",
2651 /* compressed chunk using backwards reference */
2653 {0x06, 0xB0, 0x10, 'W', 'i', 'n', 'e', 0x01, 0x30},
2655 STATUS_SUCCESS,
2656 "WineWine",
2658 DECOMPRESS_BROKEN_TRUNCATED
2660 /* compressed chunk using backwards reference with length > bytes_read */
2662 {0x06, 0xB0, 0x10, 'W', 'i', 'n', 'e', 0x05, 0x30},
2664 STATUS_SUCCESS,
2665 "WineWineWine",
2667 DECOMPRESS_BROKEN_TRUNCATED
2669 /* same as above, but unused bits != 0 */
2671 {0x06, 0xB0, 0x30, 'W', 'i', 'n', 'e', 0x01, 0x30},
2673 STATUS_SUCCESS,
2674 "WineWine",
2676 DECOMPRESS_BROKEN_TRUNCATED
2678 /* compressed chunk without backwards reference and unused bits != 0 */
2680 {0x01, 0xB0, 0x02, 'W'},
2682 STATUS_SUCCESS,
2683 "W",
2686 /* termination sequence after first chunk */
2688 {0x03, 0x30, 'W', 'i', 'n', 'e', 0x00, 0x00, 0x03, 0x30, 'W', 'i', 'n', 'e'},
2690 STATUS_SUCCESS,
2691 "Wine",
2693 DECOMPRESS_BROKEN_FRAGMENT
2695 /* compressed chunk using backwards reference with 4 bit offset, 12 bit length */
2697 {0x14, 0xB0, 0x00, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
2698 0x00, 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
2699 0x01, 0x01, 0xF0},
2701 STATUS_SUCCESS,
2702 "ABCDEFGHIJKLMNOPABCD",
2704 DECOMPRESS_BROKEN_TRUNCATED
2706 /* compressed chunk using backwards reference with 5 bit offset, 11 bit length */
2708 {0x15, 0xB0, 0x00, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
2709 0x00, 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
2710 0x02, 'A', 0x00, 0x78},
2712 STATUS_SUCCESS,
2713 "ABCDEFGHIJKLMNOPABCD",
2715 DECOMPRESS_BROKEN_TRUNCATED
2717 /* uncompressed chunk with invalid magic */
2719 {0x03, 0x20, 'W', 'i', 'n', 'e'},
2721 STATUS_SUCCESS,
2722 "Wine",
2724 DECOMPRESS_BROKEN_FRAGMENT
2726 /* compressed chunk with invalid magic */
2728 {0x04, 0xA0, 0x00, 'W', 'i', 'n', 'e'},
2730 STATUS_SUCCESS,
2731 "Wine",
2734 /* garbage byte after end of buffer */
2736 {0x00, 0xB0, 0x02, 0x01},
2738 STATUS_SUCCESS,
2742 /* empty compressed chunk */
2744 {0x00, 0xB0, 0x00},
2746 STATUS_SUCCESS,
2750 /* empty compressed chunk with unused bits != 0 */
2752 {0x00, 0xB0, 0x01},
2754 STATUS_SUCCESS,
2758 /* empty input buffer */
2762 STATUS_BAD_COMPRESSION_BUFFER,
2764 /* incomplete chunk header */
2766 {0x01},
2768 STATUS_BAD_COMPRESSION_BUFFER
2770 /* incomplete chunk header */
2772 {0x00, 0x30},
2774 STATUS_BAD_COMPRESSION_BUFFER
2776 /* compressed chunk with invalid backwards reference */
2778 {0x06, 0xB0, 0x10, 'W', 'i', 'n', 'e', 0x05, 0x40},
2780 STATUS_BAD_COMPRESSION_BUFFER
2782 /* compressed chunk with incomplete backwards reference */
2784 {0x05, 0xB0, 0x10, 'W', 'i', 'n', 'e', 0x05},
2786 STATUS_BAD_COMPRESSION_BUFFER
2788 /* incomplete uncompressed chunk */
2790 {0x07, 0x30, 'W', 'i', 'n', 'e'},
2792 STATUS_BAD_COMPRESSION_BUFFER
2794 /* incomplete compressed chunk */
2796 {0x08, 0xB0, 0x00, 'W', 'i', 'n', 'e'},
2798 STATUS_BAD_COMPRESSION_BUFFER
2800 /* two compressed chunks, the second one incomplete */
2802 {0x00, 0xB0, 0x02, 0x00, 0xB0},
2804 STATUS_BAD_COMPRESSION_BUFFER,
2808 static UCHAR buf[0x2000], workspace[0x1000];
2809 NTSTATUS status, expected_status;
2810 ULONG final_size;
2811 int i;
2813 /* test compression format / engine */
2814 final_size = 0xdeadbeef;
2815 status = RtlDecompressBuffer(COMPRESSION_FORMAT_NONE, buf, sizeof(buf), test_lznt[0].compressed,
2816 test_lznt[0].compressed_size, &final_size);
2817 ok(status == STATUS_INVALID_PARAMETER, "got wrong status 0x%08lx\n", status);
2818 ok(final_size == 0xdeadbeef, "got wrong final_size %lu\n", final_size);
2820 final_size = 0xdeadbeef;
2821 status = RtlDecompressBuffer(COMPRESSION_FORMAT_DEFAULT, buf, sizeof(buf), test_lznt[0].compressed,
2822 test_lznt[0].compressed_size, &final_size);
2823 ok(status == STATUS_INVALID_PARAMETER, "got wrong status 0x%08lx\n", status);
2824 ok(final_size == 0xdeadbeef, "got wrong final_size %lu\n", final_size);
2826 final_size = 0xdeadbeef;
2827 status = RtlDecompressBuffer(0xFF, buf, sizeof(buf), test_lznt[0].compressed,
2828 test_lznt[0].compressed_size, &final_size);
2829 ok(status == STATUS_UNSUPPORTED_COMPRESSION, "got wrong status 0x%08lx\n", status);
2830 ok(final_size == 0xdeadbeef, "got wrong final_size %lu\n", final_size);
2832 /* regular tests for RtlDecompressBuffer */
2833 for (i = 0; i < ARRAY_SIZE(test_lznt); i++)
2835 trace("Running test %d (compressed_size=%lu, uncompressed_size=%lu, status=0x%08lx)\n",
2836 i, test_lznt[i].compressed_size, test_lznt[i].uncompressed_size, test_lznt[i].status);
2838 /* test with very big buffer */
2839 final_size = 0xdeadbeef;
2840 memset(buf, 0x11, sizeof(buf));
2841 status = RtlDecompressBuffer(COMPRESSION_FORMAT_LZNT1, buf, sizeof(buf), test_lznt[i].compressed,
2842 test_lznt[i].compressed_size, &final_size);
2843 ok(status == test_lznt[i].status || broken(status == STATUS_BAD_COMPRESSION_BUFFER &&
2844 (test_lznt[i].broken_flags & DECOMPRESS_BROKEN_FRAGMENT)), "%d: got wrong status 0x%08lx\n", i, status);
2845 if (!status)
2847 ok(final_size == test_lznt[i].uncompressed_size,
2848 "%d: got wrong final_size %lu\n", i, final_size);
2849 ok(!memcmp(buf, test_lznt[i].uncompressed, test_lznt[i].uncompressed_size),
2850 "%d: got wrong decoded data\n", i);
2851 ok(buf[test_lznt[i].uncompressed_size] == 0x11,
2852 "%d: buf[%lu] was modified\n", i, test_lznt[i].uncompressed_size);
2855 /* test that modifier for compression engine is ignored */
2856 final_size = 0xdeadbeef;
2857 memset(buf, 0x11, sizeof(buf));
2858 status = RtlDecompressBuffer(COMPRESSION_FORMAT_LZNT1 | COMPRESSION_ENGINE_MAXIMUM, buf, sizeof(buf),
2859 test_lznt[i].compressed, test_lznt[i].compressed_size, &final_size);
2860 ok(status == test_lznt[i].status || broken(status == STATUS_BAD_COMPRESSION_BUFFER &&
2861 (test_lznt[i].broken_flags & DECOMPRESS_BROKEN_FRAGMENT)), "%d: got wrong status 0x%08lx\n", i, status);
2862 if (!status)
2864 ok(final_size == test_lznt[i].uncompressed_size,
2865 "%d: got wrong final_size %lu\n", i, final_size);
2866 ok(!memcmp(buf, test_lznt[i].uncompressed, test_lznt[i].uncompressed_size),
2867 "%d: got wrong decoded data\n", i);
2868 ok(buf[test_lznt[i].uncompressed_size] == 0x11,
2869 "%d: buf[%lu] was modified\n", i, test_lznt[i].uncompressed_size);
2872 /* test with expected output size */
2873 if (test_lznt[i].uncompressed_size > 0)
2875 final_size = 0xdeadbeef;
2876 memset(buf, 0x11, sizeof(buf));
2877 status = RtlDecompressBuffer(COMPRESSION_FORMAT_LZNT1, buf, test_lznt[i].uncompressed_size,
2878 test_lznt[i].compressed, test_lznt[i].compressed_size, &final_size);
2879 ok(status == test_lznt[i].status, "%d: got wrong status 0x%08lx\n", i, status);
2880 if (!status)
2882 ok(final_size == test_lznt[i].uncompressed_size,
2883 "%d: got wrong final_size %lu\n", i, final_size);
2884 ok(!memcmp(buf, test_lznt[i].uncompressed, test_lznt[i].uncompressed_size),
2885 "%d: got wrong decoded data\n", i);
2886 ok(buf[test_lznt[i].uncompressed_size] == 0x11,
2887 "%d: buf[%lu] was modified\n", i, test_lznt[i].uncompressed_size);
2891 /* test with smaller output size */
2892 if (test_lznt[i].uncompressed_size > 1)
2894 final_size = 0xdeadbeef;
2895 memset(buf, 0x11, sizeof(buf));
2896 status = RtlDecompressBuffer(COMPRESSION_FORMAT_LZNT1, buf, test_lznt[i].uncompressed_size - 1,
2897 test_lznt[i].compressed, test_lznt[i].compressed_size, &final_size);
2898 if (test_lznt[i].broken_flags & DECOMPRESS_BROKEN_TRUNCATED)
2899 todo_wine
2900 ok(status == STATUS_BAD_COMPRESSION_BUFFER, "%d: got wrong status 0x%08lx\n", i, status);
2901 else
2902 ok(status == test_lznt[i].status, "%d: got wrong status 0x%08lx\n", i, status);
2903 if (!status)
2905 ok(final_size == test_lznt[i].uncompressed_size - 1,
2906 "%d: got wrong final_size %lu\n", i, final_size);
2907 ok(!memcmp(buf, test_lznt[i].uncompressed, test_lznt[i].uncompressed_size - 1),
2908 "%d: got wrong decoded data\n", i);
2909 ok(buf[test_lznt[i].uncompressed_size - 1] == 0x11,
2910 "%d: buf[%lu] was modified\n", i, test_lznt[i].uncompressed_size - 1);
2914 /* test with zero output size */
2915 final_size = 0xdeadbeef;
2916 memset(buf, 0x11, sizeof(buf));
2917 status = RtlDecompressBuffer(COMPRESSION_FORMAT_LZNT1, buf, 0, test_lznt[i].compressed,
2918 test_lznt[i].compressed_size, &final_size);
2919 if (is_incomplete_chunk(test_lznt[i].compressed, test_lznt[i].compressed_size, FALSE))
2920 ok(status == STATUS_BAD_COMPRESSION_BUFFER, "%d: got wrong status 0x%08lx\n", i, status);
2921 else
2923 ok(status == STATUS_SUCCESS, "%d: got wrong status 0x%08lx\n", i, status);
2924 ok(final_size == 0, "%d: got wrong final_size %lu\n", i, final_size);
2925 ok(buf[0] == 0x11, "%d: buf[0] was modified\n", i);
2928 /* test RtlDecompressFragment with offset = 0 */
2929 final_size = 0xdeadbeef;
2930 memset(buf, 0x11, sizeof(buf));
2931 status = RtlDecompressFragment(COMPRESSION_FORMAT_LZNT1, buf, sizeof(buf), test_lznt[i].compressed,
2932 test_lznt[i].compressed_size, 0, &final_size, workspace);
2933 if (test_lznt[i].broken_flags & DECOMPRESS_BROKEN_FRAGMENT)
2934 todo_wine
2935 ok(status == STATUS_BAD_COMPRESSION_BUFFER, "%d: got wrong status 0x%08lx\n", i, status);
2936 else
2937 ok(status == test_lznt[i].status, "%d: got wrong status 0x%08lx\n", i, status);
2938 if (!status)
2940 ok(final_size == test_lznt[i].uncompressed_size,
2941 "%d: got wrong final_size %lu\n", i, final_size);
2942 ok(!memcmp(buf, test_lznt[i].uncompressed, test_lznt[i].uncompressed_size),
2943 "%d: got wrong decoded data\n", i);
2944 ok(buf[test_lznt[i].uncompressed_size] == 0x11,
2945 "%d: buf[%lu] was modified\n", i, test_lznt[i].uncompressed_size);
2948 /* test RtlDecompressFragment with offset = 1 */
2949 final_size = 0xdeadbeef;
2950 memset(buf, 0x11, sizeof(buf));
2951 status = RtlDecompressFragment(COMPRESSION_FORMAT_LZNT1, buf, sizeof(buf), test_lznt[i].compressed,
2952 test_lznt[i].compressed_size, 1, &final_size, workspace);
2953 if (test_lznt[i].broken_flags & DECOMPRESS_BROKEN_FRAGMENT)
2954 todo_wine
2955 ok(status == STATUS_BAD_COMPRESSION_BUFFER, "%d: got wrong status 0x%08lx\n", i, status);
2956 else
2957 ok(status == test_lznt[i].status, "%d: got wrong status 0x%08lx\n", i, status);
2958 if (!status)
2960 if (test_lznt[i].uncompressed_size == 0)
2962 todo_wine
2963 ok(final_size == 4095, "%d: got wrong final_size %lu\n", i, final_size);
2964 /* Buffer doesn't contain any useful value on Windows */
2965 ok(buf[4095] == 0x11, "%d: buf[4095] was modified\n", i);
2967 else
2969 ok(final_size == test_lznt[i].uncompressed_size - 1,
2970 "%d: got wrong final_size %lu\n", i, final_size);
2971 ok(!memcmp(buf, test_lznt[i].uncompressed + 1, test_lznt[i].uncompressed_size - 1),
2972 "%d: got wrong decoded data\n", i);
2973 ok(buf[test_lznt[i].uncompressed_size - 1] == 0x11,
2974 "%d: buf[%lu] was modified\n", i, test_lznt[i].uncompressed_size - 1);
2978 /* test RtlDecompressFragment with offset = 4095 */
2979 final_size = 0xdeadbeef;
2980 memset(buf, 0x11, sizeof(buf));
2981 status = RtlDecompressFragment(COMPRESSION_FORMAT_LZNT1, buf, sizeof(buf), test_lznt[i].compressed,
2982 test_lznt[i].compressed_size, 4095, &final_size, workspace);
2983 if (test_lznt[i].broken_flags & DECOMPRESS_BROKEN_FRAGMENT)
2984 todo_wine
2985 ok(status == STATUS_BAD_COMPRESSION_BUFFER, "%d: got wrong status 0x%08lx\n", i, status);
2986 else
2987 ok(status == test_lznt[i].status, "%d: got wrong status 0x%08lx\n", i, status);
2988 if (!status)
2990 todo_wine
2991 ok(final_size == 1, "%d: got wrong final_size %lu\n", i, final_size);
2992 todo_wine
2993 ok(buf[0] == 0, "%d: padding is not zero\n", i);
2994 ok(buf[1] == 0x11, "%d: buf[1] was modified\n", i);
2997 /* test RtlDecompressFragment with offset = 4096 */
2998 final_size = 0xdeadbeef;
2999 memset(buf, 0x11, sizeof(buf));
3000 status = RtlDecompressFragment(COMPRESSION_FORMAT_LZNT1, buf, sizeof(buf), test_lznt[i].compressed,
3001 test_lznt[i].compressed_size, 4096, &final_size, workspace);
3002 expected_status = is_incomplete_chunk(test_lznt[i].compressed, test_lznt[i].compressed_size, TRUE) ?
3003 test_lznt[i].status : STATUS_SUCCESS;
3004 ok(status == expected_status, "%d: got wrong status 0x%08lx, expected 0x%08lx\n", i, status, expected_status);
3005 if (!status)
3007 ok(final_size == 0, "%d: got wrong final_size %lu\n", i, final_size);
3008 ok(buf[0] == 0x11, "%d: buf[4096] was modified\n", i);
3013 #undef DECOMPRESS_BROKEN_FRAGMENT
3014 #undef DECOMPRESS_BROKEN_TRUNCATED
3016 struct critsect_locked_info
3018 CRITICAL_SECTION crit;
3019 HANDLE semaphores[2];
3022 static DWORD WINAPI critsect_locked_thread(void *param)
3024 struct critsect_locked_info *info = param;
3025 DWORD ret;
3027 ret = pRtlIsCriticalSectionLocked(&info->crit);
3028 ok(ret == TRUE, "expected TRUE, got %lu\n", ret);
3029 ret = pRtlIsCriticalSectionLockedByThread(&info->crit);
3030 ok(ret == FALSE, "expected FALSE, got %lu\n", ret);
3032 ReleaseSemaphore(info->semaphores[0], 1, NULL);
3033 ret = WaitForSingleObject(info->semaphores[1], 1000);
3034 ok(ret == WAIT_OBJECT_0, "expected WAIT_OBJECT_0, got %lu\n", ret);
3036 ret = pRtlIsCriticalSectionLocked(&info->crit);
3037 ok(ret == FALSE, "expected FALSE, got %lu\n", ret);
3038 ret = pRtlIsCriticalSectionLockedByThread(&info->crit);
3039 ok(ret == FALSE, "expected FALSE, got %lu\n", ret);
3041 EnterCriticalSection(&info->crit);
3043 ret = pRtlIsCriticalSectionLocked(&info->crit);
3044 ok(ret == TRUE, "expected TRUE, got %lu\n", ret);
3045 ret = pRtlIsCriticalSectionLockedByThread(&info->crit);
3046 ok(ret == TRUE, "expected TRUE, got %lu\n", ret);
3048 ReleaseSemaphore(info->semaphores[0], 1, NULL);
3049 ret = WaitForSingleObject(info->semaphores[1], 1000);
3050 ok(ret == WAIT_OBJECT_0, "expected WAIT_OBJECT_0, got %lu\n", ret);
3052 LeaveCriticalSection(&info->crit);
3053 return 0;
3056 static void test_RtlIsCriticalSectionLocked(void)
3058 struct critsect_locked_info info;
3059 HANDLE thread;
3060 BOOL ret;
3062 if (!pRtlIsCriticalSectionLocked || !pRtlIsCriticalSectionLockedByThread)
3064 win_skip("skipping RtlIsCriticalSectionLocked tests, required functions not available\n");
3065 return;
3068 InitializeCriticalSection(&info.crit);
3069 info.semaphores[0] = CreateSemaphoreW(NULL, 0, 1, NULL);
3070 ok(info.semaphores[0] != NULL, "CreateSemaphore failed with %lu\n", GetLastError());
3071 info.semaphores[1] = CreateSemaphoreW(NULL, 0, 1, NULL);
3072 ok(info.semaphores[1] != NULL, "CreateSemaphore failed with %lu\n", GetLastError());
3074 ret = pRtlIsCriticalSectionLocked(&info.crit);
3075 ok(ret == FALSE, "expected FALSE, got %u\n", ret);
3076 ret = pRtlIsCriticalSectionLockedByThread(&info.crit);
3077 ok(ret == FALSE, "expected FALSE, got %u\n", ret);
3079 EnterCriticalSection(&info.crit);
3081 ret = pRtlIsCriticalSectionLocked(&info.crit);
3082 ok(ret == TRUE, "expected TRUE, got %u\n", ret);
3083 ret = pRtlIsCriticalSectionLockedByThread(&info.crit);
3084 ok(ret == TRUE, "expected TRUE, got %u\n", ret);
3086 thread = CreateThread(NULL, 0, critsect_locked_thread, &info, 0, NULL);
3087 ok(thread != NULL, "CreateThread failed with %lu\n", GetLastError());
3088 ret = WaitForSingleObject(info.semaphores[0], 1000);
3089 ok(ret == WAIT_OBJECT_0, "expected WAIT_OBJECT_0, got %u\n", ret);
3091 LeaveCriticalSection(&info.crit);
3093 ReleaseSemaphore(info.semaphores[1], 1, NULL);
3094 ret = WaitForSingleObject(info.semaphores[0], 1000);
3095 ok(ret == WAIT_OBJECT_0, "expected WAIT_OBJECT_0, got %u\n", ret);
3097 ret = pRtlIsCriticalSectionLocked(&info.crit);
3098 ok(ret == TRUE, "expected TRUE, got %u\n", ret);
3099 ret = pRtlIsCriticalSectionLockedByThread(&info.crit);
3100 ok(ret == FALSE, "expected FALSE, got %u\n", ret);
3102 ReleaseSemaphore(info.semaphores[1], 1, NULL);
3103 ret = WaitForSingleObject(thread, 1000);
3104 ok(ret == WAIT_OBJECT_0, "expected WAIT_OBJECT_0, got %u\n", ret);
3106 CloseHandle(thread);
3107 CloseHandle(info.semaphores[0]);
3108 CloseHandle(info.semaphores[1]);
3109 DeleteCriticalSection(&info.crit);
3112 static void test_RtlInitializeCriticalSectionEx(void)
3114 static const CRITICAL_SECTION_DEBUG *no_debug = (void *)~(ULONG_PTR)0;
3115 CRITICAL_SECTION cs;
3117 if (!pRtlInitializeCriticalSectionEx)
3119 win_skip("RtlInitializeCriticalSectionEx is not available\n");
3120 return;
3123 memset(&cs, 0x11, sizeof(cs));
3124 pRtlInitializeCriticalSectionEx(&cs, 0, 0);
3125 ok((cs.DebugInfo != NULL && cs.DebugInfo != no_debug) || broken(cs.DebugInfo == no_debug) /* >= Win 8 */,
3126 "expected DebugInfo != NULL and DebugInfo != ~0, got %p\n", cs.DebugInfo);
3127 ok(cs.LockCount == -1, "expected LockCount == -1, got %ld\n", cs.LockCount);
3128 ok(cs.RecursionCount == 0, "expected RecursionCount == 0, got %ld\n", cs.RecursionCount);
3129 ok(cs.LockSemaphore == NULL, "expected LockSemaphore == NULL, got %p\n", cs.LockSemaphore);
3130 ok(cs.SpinCount == 0 || broken(cs.SpinCount != 0) /* >= Win 8 */,
3131 "expected SpinCount == 0, got %Id\n", cs.SpinCount);
3132 RtlDeleteCriticalSection(&cs);
3134 memset(&cs, 0x11, sizeof(cs));
3135 pRtlInitializeCriticalSectionEx(&cs, 0, RTL_CRITICAL_SECTION_FLAG_NO_DEBUG_INFO);
3136 ok(cs.DebugInfo == no_debug, "expected DebugInfo == ~0, got %p\n", cs.DebugInfo);
3137 ok(cs.LockCount == -1, "expected LockCount == -1, got %ld\n", cs.LockCount);
3138 ok(cs.RecursionCount == 0, "expected RecursionCount == 0, got %ld\n", cs.RecursionCount);
3139 ok(cs.LockSemaphore == NULL, "expected LockSemaphore == NULL, got %p\n", cs.LockSemaphore);
3140 ok(cs.SpinCount == 0 || broken(cs.SpinCount != 0) /* >= Win 8 */,
3141 "expected SpinCount == 0, got %Id\n", cs.SpinCount);
3142 RtlDeleteCriticalSection(&cs);
3145 static void test_RtlLeaveCriticalSection(void)
3147 RTL_CRITICAL_SECTION cs;
3148 NTSTATUS status;
3150 if (!pRtlInitializeCriticalSectionEx)
3151 return; /* Skip winxp */
3153 status = RtlInitializeCriticalSection(&cs);
3154 ok(!status, "RtlInitializeCriticalSection failed: %lx\n", status);
3156 status = RtlEnterCriticalSection(&cs);
3157 ok(!status, "RtlEnterCriticalSection failed: %lx\n", status);
3158 todo_wine
3159 ok(cs.LockCount == -2, "expected LockCount == -2, got %ld\n", cs.LockCount);
3160 ok(cs.RecursionCount == 1, "expected RecursionCount == 1, got %ld\n", cs.RecursionCount);
3161 ok(cs.OwningThread == ULongToHandle(GetCurrentThreadId()), "unexpected OwningThread\n");
3163 status = RtlLeaveCriticalSection(&cs);
3164 ok(!status, "RtlLeaveCriticalSection failed: %lx\n", status);
3165 ok(cs.LockCount == -1, "expected LockCount == -1, got %ld\n", cs.LockCount);
3166 ok(cs.RecursionCount == 0, "expected RecursionCount == 0, got %ld\n", cs.RecursionCount);
3167 ok(!cs.OwningThread, "unexpected OwningThread %p\n", cs.OwningThread);
3170 * Trying to leave a section that wasn't acquired modifies RecursionCount to an invalid value,
3171 * but doesn't modify LockCount so that an attempt to enter the section later will work.
3173 status = RtlLeaveCriticalSection(&cs);
3174 ok(!status, "RtlLeaveCriticalSection failed: %lx\n", status);
3175 ok(cs.LockCount == -1, "expected LockCount == -1, got %ld\n", cs.LockCount);
3176 ok(cs.RecursionCount == -1, "expected RecursionCount == -1, got %ld\n", cs.RecursionCount);
3177 ok(!cs.OwningThread, "unexpected OwningThread %p\n", cs.OwningThread);
3179 /* and again */
3180 status = RtlLeaveCriticalSection(&cs);
3181 ok(!status, "RtlLeaveCriticalSection failed: %lx\n", status);
3182 ok(cs.LockCount == -1, "expected LockCount == -1, got %ld\n", cs.LockCount);
3183 ok(cs.RecursionCount == -2, "expected RecursionCount == -2, got %ld\n", cs.RecursionCount);
3184 ok(!cs.OwningThread, "unexpected OwningThread %p\n", cs.OwningThread);
3186 /* entering section fixes RecursionCount */
3187 status = RtlEnterCriticalSection(&cs);
3188 ok(!status, "RtlEnterCriticalSection failed: %lx\n", status);
3189 todo_wine
3190 ok(cs.LockCount == -2, "expected LockCount == -2, got %ld\n", cs.LockCount);
3191 ok(cs.RecursionCount == 1, "expected RecursionCount == 1, got %ld\n", cs.RecursionCount);
3192 ok(cs.OwningThread == ULongToHandle(GetCurrentThreadId()), "unexpected OwningThread\n");
3194 status = RtlLeaveCriticalSection(&cs);
3195 ok(!status, "RtlLeaveCriticalSection failed: %lx\n", status);
3196 ok(cs.LockCount == -1, "expected LockCount == -1, got %ld\n", cs.LockCount);
3197 ok(cs.RecursionCount == 0, "expected RecursionCount == 0, got %ld\n", cs.RecursionCount);
3198 ok(!cs.OwningThread, "unexpected OwningThread %p\n", cs.OwningThread);
3200 status = RtlDeleteCriticalSection(&cs);
3201 ok(!status, "RtlDeleteCriticalSection failed: %lx\n", status);
3204 struct ldr_enum_context
3206 BOOL abort;
3207 BOOL found;
3208 int count;
3211 static void WINAPI ldr_enum_callback(LDR_DATA_TABLE_ENTRY *module, void *context, BOOLEAN *stop)
3213 static const WCHAR ntdllW[] = {'n','t','d','l','l','.','d','l','l',0};
3214 struct ldr_enum_context *ctx = context;
3216 if (!lstrcmpiW(module->BaseDllName.Buffer, ntdllW))
3217 ctx->found = TRUE;
3219 ctx->count++;
3220 *stop = ctx->abort;
3223 static void test_LdrEnumerateLoadedModules(void)
3225 struct ldr_enum_context ctx;
3226 NTSTATUS status;
3228 if (!pLdrEnumerateLoadedModules)
3230 win_skip("LdrEnumerateLoadedModules not available\n");
3231 return;
3234 ctx.abort = FALSE;
3235 ctx.found = FALSE;
3236 ctx.count = 0;
3237 status = pLdrEnumerateLoadedModules(NULL, ldr_enum_callback, &ctx);
3238 ok(status == STATUS_SUCCESS, "LdrEnumerateLoadedModules failed with %08lx\n", status);
3239 ok(ctx.count > 1, "Expected more than one module, got %d\n", ctx.count);
3240 ok(ctx.found, "Could not find ntdll in list of modules\n");
3242 ctx.abort = TRUE;
3243 ctx.count = 0;
3244 status = pLdrEnumerateLoadedModules(NULL, ldr_enum_callback, &ctx);
3245 ok(status == STATUS_SUCCESS, "LdrEnumerateLoadedModules failed with %08lx\n", status);
3246 ok(ctx.count == 1, "Expected exactly one module, got %d\n", ctx.count);
3248 status = pLdrEnumerateLoadedModules((void *)0x1, ldr_enum_callback, (void *)0xdeadbeef);
3249 ok(status == STATUS_INVALID_PARAMETER, "expected STATUS_INVALID_PARAMETER, got 0x%08lx\n", status);
3251 status = pLdrEnumerateLoadedModules((void *)0xdeadbeef, ldr_enum_callback, (void *)0xdeadbeef);
3252 ok(status == STATUS_INVALID_PARAMETER, "expected STATUS_INVALID_PARAMETER, got 0x%08lx\n", status);
3254 status = pLdrEnumerateLoadedModules(NULL, NULL, (void *)0xdeadbeef);
3255 ok(status == STATUS_INVALID_PARAMETER, "expected STATUS_INVALID_PARAMETER, got 0x%08lx\n", status);
3258 static void test_RtlMakeSelfRelativeSD(void)
3260 char buf[sizeof(SECURITY_DESCRIPTOR_RELATIVE) + 4];
3261 SECURITY_DESCRIPTOR_RELATIVE *sd_rel = (SECURITY_DESCRIPTOR_RELATIVE *)buf;
3262 SECURITY_DESCRIPTOR sd;
3263 NTSTATUS status;
3264 DWORD len;
3266 memset( &sd, 0, sizeof(sd) );
3267 sd.Revision = SECURITY_DESCRIPTOR_REVISION;
3269 len = 0;
3270 status = RtlMakeSelfRelativeSD( &sd, NULL, &len );
3271 ok( status == STATUS_BUFFER_TOO_SMALL, "got %08lx\n", status );
3272 ok( len == sizeof(*sd_rel), "got %lu\n", len );
3274 len += 4;
3275 status = RtlMakeSelfRelativeSD( &sd, sd_rel, &len );
3276 ok( status == STATUS_SUCCESS, "got %08lx\n", status );
3277 ok( len == sizeof(*sd_rel) + 4, "got %lu\n", len );
3279 len = 0;
3280 status = RtlAbsoluteToSelfRelativeSD( &sd, NULL, &len );
3281 ok( status == STATUS_BUFFER_TOO_SMALL, "got %08lx\n", status );
3282 ok( len == sizeof(*sd_rel), "got %lu\n", len );
3284 len += 4;
3285 status = RtlAbsoluteToSelfRelativeSD( &sd, sd_rel, &len );
3286 ok( status == STATUS_SUCCESS, "got %08lx\n", status );
3287 ok( len == sizeof(*sd_rel) + 4, "got %lu\n", len );
3289 sd.Control = SE_SELF_RELATIVE;
3290 status = RtlMakeSelfRelativeSD( &sd, sd_rel, &len );
3291 ok( status == STATUS_SUCCESS, "got %08lx\n", status );
3292 ok( len == sizeof(*sd_rel) + 4, "got %lu\n", len );
3294 status = RtlAbsoluteToSelfRelativeSD( &sd, sd_rel, &len );
3295 ok( status == STATUS_BAD_DESCRIPTOR_FORMAT, "got %08lx\n", status );
3298 static DWORD (CALLBACK *orig_entry)(HMODULE,DWORD,LPVOID);
3299 static DWORD *dll_main_data;
3301 static inline void *get_rva( HMODULE module, DWORD va )
3303 return (void *)((char *)module + va);
3306 static void CALLBACK ldr_notify_callback1(ULONG reason, LDR_DLL_NOTIFICATION_DATA *data, void *context)
3308 const IMAGE_IMPORT_DESCRIPTOR *imports;
3309 const IMAGE_THUNK_DATA *import_list;
3310 IMAGE_THUNK_DATA *thunk_list;
3311 LDR_DATA_TABLE_ENTRY *mod;
3312 DWORD *calls = context;
3313 LIST_ENTRY *mark;
3314 ULONG size;
3315 int i, j;
3317 *calls <<= 4;
3318 *calls |= reason;
3320 if (!lstrcmpiW(data->Loaded.BaseDllName->Buffer, expected_dll))
3321 return;
3323 ok(data->Loaded.Flags == 0, "Expected flags 0, got %lx\n", data->Loaded.Flags);
3324 ok(!lstrcmpiW(data->Loaded.BaseDllName->Buffer, expected_dll), "Expected %s, got %s\n",
3325 wine_dbgstr_w(expected_dll), wine_dbgstr_w(data->Loaded.BaseDllName->Buffer));
3326 ok(!!data->Loaded.DllBase, "Expected non zero base address\n");
3327 ok(data->Loaded.SizeOfImage, "Expected non zero image size\n");
3329 /* expect module to be last module listed in LdrData load order list */
3330 mark = &NtCurrentTeb()->Peb->LdrData->InMemoryOrderModuleList;
3331 mod = CONTAINING_RECORD(mark->Blink, LDR_DATA_TABLE_ENTRY, InMemoryOrderLinks);
3332 ok(mod->DllBase == data->Loaded.DllBase, "Expected base address %p, got %p\n",
3333 data->Loaded.DllBase, mod->DllBase);
3334 ok(!lstrcmpiW(mod->BaseDllName.Buffer, expected_dll), "Expected %s, got %s\n",
3335 wine_dbgstr_w(expected_dll), wine_dbgstr_w(mod->BaseDllName.Buffer));
3337 /* show that imports have already been resolved */
3338 imports = RtlImageDirectoryEntryToData(data->Loaded.DllBase, TRUE, IMAGE_DIRECTORY_ENTRY_IMPORT, &size);
3339 ok(!!imports, "Expected dll to have imports\n");
3341 for (i = 0; imports[i].Name; i++)
3343 thunk_list = get_rva(data->Loaded.DllBase, (DWORD)imports[i].FirstThunk);
3344 if (imports[i].OriginalFirstThunk)
3345 import_list = get_rva(data->Loaded.DllBase, (DWORD)imports[i].OriginalFirstThunk);
3346 else
3347 import_list = thunk_list;
3349 for (j = 0; import_list[j].u1.Ordinal; j++)
3351 ok(thunk_list[j].u1.AddressOfData > data->Loaded.SizeOfImage,
3352 "Import has not been resolved: %p\n", (void*)thunk_list[j].u1.Function);
3357 static void CALLBACK ldr_notify_callback2(ULONG reason, LDR_DLL_NOTIFICATION_DATA *data, void *context)
3359 DWORD *calls = context;
3360 *calls <<= 4;
3361 *calls |= reason + 2;
3364 static BOOL WINAPI fake_dll_main(HINSTANCE instance, DWORD reason, void* reserved)
3366 if (reason == DLL_PROCESS_ATTACH)
3368 *dll_main_data <<= 4;
3369 *dll_main_data |= 3;
3371 else if (reason == DLL_PROCESS_DETACH)
3373 *dll_main_data <<= 4;
3374 *dll_main_data |= 4;
3376 return orig_entry(instance, reason, reserved);
3379 static void CALLBACK ldr_notify_callback_dll_main(ULONG reason, LDR_DLL_NOTIFICATION_DATA *data, void *context)
3381 DWORD *calls = context;
3382 LIST_ENTRY *mark;
3383 LDR_DATA_TABLE_ENTRY *mod;
3385 *calls <<= 4;
3386 *calls |= reason;
3388 if (reason != LDR_DLL_NOTIFICATION_REASON_LOADED)
3389 return;
3391 mark = &NtCurrentTeb()->Peb->LdrData->InMemoryOrderModuleList;
3392 mod = CONTAINING_RECORD(mark->Blink, LDR_DATA_TABLE_ENTRY, InMemoryOrderLinks);
3393 ok(mod->DllBase == data->Loaded.DllBase, "Expected base address %p, got %p\n",
3394 data->Loaded.DllBase, mod->DllBase);
3395 if (mod->DllBase != data->Loaded.DllBase)
3396 return;
3398 orig_entry = mod->EntryPoint;
3399 mod->EntryPoint = fake_dll_main;
3400 dll_main_data = calls;
3403 static BOOL WINAPI fake_dll_main_fail(HINSTANCE instance, DWORD reason, void* reserved)
3405 if (reason == DLL_PROCESS_ATTACH)
3407 *dll_main_data <<= 4;
3408 *dll_main_data |= 3;
3410 else if (reason == DLL_PROCESS_DETACH)
3412 *dll_main_data <<= 4;
3413 *dll_main_data |= 4;
3415 return FALSE;
3418 static void CALLBACK ldr_notify_callback_fail(ULONG reason, LDR_DLL_NOTIFICATION_DATA *data, void *context)
3420 DWORD *calls = context;
3421 LIST_ENTRY *mark;
3422 LDR_DATA_TABLE_ENTRY *mod;
3424 *calls <<= 4;
3425 *calls |= reason;
3427 if (reason != LDR_DLL_NOTIFICATION_REASON_LOADED)
3428 return;
3430 mark = &NtCurrentTeb()->Peb->LdrData->InMemoryOrderModuleList;
3431 mod = CONTAINING_RECORD(mark->Blink, LDR_DATA_TABLE_ENTRY, InMemoryOrderLinks);
3432 ok(mod->DllBase == data->Loaded.DllBase, "Expected base address %p, got %p\n",
3433 data->Loaded.DllBase, mod->DllBase);
3434 if (mod->DllBase != data->Loaded.DllBase)
3435 return;
3437 orig_entry = mod->EntryPoint;
3438 mod->EntryPoint = fake_dll_main_fail;
3439 dll_main_data = calls;
3442 static void CALLBACK ldr_notify_callback_imports(ULONG reason, LDR_DLL_NOTIFICATION_DATA *data, void *context)
3444 DWORD *calls = context;
3446 if (reason != LDR_DLL_NOTIFICATION_REASON_LOADED)
3447 return;
3449 if (!lstrcmpiW(data->Loaded.BaseDllName->Buffer, crypt32dllW))
3451 *calls <<= 4;
3452 *calls |= 1;
3455 if (!lstrcmpiW(data->Loaded.BaseDllName->Buffer, wintrustdllW))
3457 *calls <<= 4;
3458 *calls |= 2;
3462 static void test_LdrRegisterDllNotification(void)
3464 void *cookie, *cookie2;
3465 NTSTATUS status;
3466 HMODULE mod;
3467 DWORD calls;
3469 if (!pLdrRegisterDllNotification || !pLdrUnregisterDllNotification)
3471 win_skip("Ldr(Un)RegisterDllNotification not available\n");
3472 return;
3475 mod = LoadLibraryW(expected_dll);
3476 if(mod)
3477 FreeLibrary(mod);
3478 else
3479 expected_dll = ws2_32dllW; /* XP Default */
3481 /* generic test */
3482 status = pLdrRegisterDllNotification(0, ldr_notify_callback1, &calls, &cookie);
3483 ok(!status, "Expected STATUS_SUCCESS, got %08lx\n", status);
3485 calls = 0;
3486 mod = LoadLibraryW(expected_dll);
3487 ok(!!mod, "Failed to load library: %ld\n", GetLastError());
3488 ok(calls == LDR_DLL_NOTIFICATION_REASON_LOADED, "Expected LDR_DLL_NOTIFICATION_REASON_LOADED, got %lx\n", calls);
3490 calls = 0;
3491 FreeLibrary(mod);
3492 ok(calls == LDR_DLL_NOTIFICATION_REASON_UNLOADED, "Expected LDR_DLL_NOTIFICATION_REASON_UNLOADED, got %lx\n", calls);
3494 /* test order of callbacks */
3495 status = pLdrRegisterDllNotification(0, ldr_notify_callback2, &calls, &cookie2);
3496 ok(!status, "Expected STATUS_SUCCESS, got %08lx\n", status);
3498 calls = 0;
3499 mod = LoadLibraryW(expected_dll);
3500 ok(!!mod, "Failed to load library: %ld\n", GetLastError());
3501 ok(calls == 0x13, "Expected order 0x13, got %lx\n", calls);
3503 calls = 0;
3504 FreeLibrary(mod);
3505 ok(calls == 0x24, "Expected order 0x24, got %lx\n", calls);
3507 pLdrUnregisterDllNotification(cookie2);
3508 pLdrUnregisterDllNotification(cookie);
3510 /* test dll main order */
3511 status = pLdrRegisterDllNotification(0, ldr_notify_callback_dll_main, &calls, &cookie);
3512 ok(!status, "Expected STATUS_SUCCESS, got %08lx\n", status);
3514 calls = 0;
3515 mod = LoadLibraryW(expected_dll);
3516 ok(!!mod, "Failed to load library: %ld\n", GetLastError());
3517 ok(calls == 0x13, "Expected order 0x13, got %lx\n", calls);
3519 calls = 0;
3520 FreeLibrary(mod);
3521 ok(calls == 0x42, "Expected order 0x42, got %lx\n", calls);
3523 pLdrUnregisterDllNotification(cookie);
3525 /* test dll main order */
3526 status = pLdrRegisterDllNotification(0, ldr_notify_callback_fail, &calls, &cookie);
3527 ok(!status, "Expected STATUS_SUCCESS, got %08lx\n", status);
3529 calls = 0;
3530 mod = LoadLibraryW(expected_dll);
3531 ok(!mod, "Expected library to fail loading\n");
3532 ok(calls == 0x1342, "Expected order 0x1342, got %lx\n", calls);
3534 pLdrUnregisterDllNotification(cookie);
3536 /* test dll with dependencies */
3537 status = pLdrRegisterDllNotification(0, ldr_notify_callback_imports, &calls, &cookie);
3538 ok(!status, "Expected STATUS_SUCCESS, got %08lx\n", status);
3540 calls = 0;
3541 mod = LoadLibraryW(wintrustdllW);
3542 ok(!!mod, "Failed to load library: %ld\n", GetLastError());
3543 ok(calls == 0x12 || calls == 0x21, "got %lx\n", calls);
3545 FreeLibrary(mod);
3546 pLdrUnregisterDllNotification(cookie);
3549 static BOOL test_dbg_print_except;
3550 static LONG test_dbg_print_except_ret;
3552 static LONG CALLBACK test_dbg_print_except_handler( EXCEPTION_POINTERS *eptrs )
3554 if (eptrs->ExceptionRecord->ExceptionCode == DBG_PRINTEXCEPTION_C)
3556 ok( eptrs->ExceptionRecord->NumberParameters == 2,
3557 "Unexpected NumberParameters: %ld\n", eptrs->ExceptionRecord->NumberParameters );
3558 ok( eptrs->ExceptionRecord->ExceptionInformation[0] == strlen("test_DbgPrint: Hello World") + 1,
3559 "Unexpected ExceptionInformation[0]: %d\n", (int)eptrs->ExceptionRecord->ExceptionInformation[0] );
3560 ok( !strcmp((char *)eptrs->ExceptionRecord->ExceptionInformation[1], "test_DbgPrint: Hello World"),
3561 "Unexpected ExceptionInformation[1]: %s\n", wine_dbgstr_a((char *)eptrs->ExceptionRecord->ExceptionInformation[1]) );
3562 test_dbg_print_except = TRUE;
3563 return test_dbg_print_except_ret;
3566 return (LONG)EXCEPTION_CONTINUE_SEARCH;
3569 static NTSTATUS WINAPIV test_vDbgPrintEx( ULONG id, ULONG level, const char *fmt, ... )
3571 NTSTATUS status;
3572 va_list args;
3573 va_start( args, fmt );
3574 status = vDbgPrintEx( id, level, fmt, args );
3575 va_end( args );
3576 return status;
3579 static NTSTATUS WINAPIV test_vDbgPrintExWithPrefix( const char *prefix, ULONG id, ULONG level, const char *fmt, ... )
3581 NTSTATUS status;
3582 va_list args;
3583 va_start( args, fmt );
3584 status = vDbgPrintExWithPrefix( prefix, id, level, fmt, args );
3585 va_end( args );
3586 return status;
3589 static void test_DbgPrint(void)
3591 NTSTATUS status;
3592 void *handler = RtlAddVectoredExceptionHandler( TRUE, test_dbg_print_except_handler );
3593 PEB *Peb = NtCurrentTeb()->Peb;
3594 BOOL debugged = Peb->BeingDebugged;
3596 test_dbg_print_except = FALSE;
3597 test_dbg_print_except_ret = (LONG)EXCEPTION_EXECUTE_HANDLER;
3598 status = DbgPrint( "test_DbgPrint: %s", "Hello World" );
3599 ok( !status, "DbgPrint returned %lx\n", status );
3600 ok( !test_dbg_print_except, "DBG_PRINTEXCEPTION_C received\n" );
3602 Peb->BeingDebugged = TRUE;
3603 test_dbg_print_except = FALSE;
3604 test_dbg_print_except_ret = (LONG)EXCEPTION_EXECUTE_HANDLER;
3605 status = DbgPrint( "test_DbgPrint: %s", "Hello World" );
3606 ok( !status, "DbgPrint returned %lx\n", status );
3607 ok( test_dbg_print_except, "DBG_PRINTEXCEPTION_C not received\n" );
3609 test_dbg_print_except = FALSE;
3610 test_dbg_print_except_ret = (LONG)EXCEPTION_CONTINUE_EXECUTION;
3611 status = DbgPrint( "test_DbgPrint: %s", "Hello World" );
3612 ok( !status, "DbgPrint returned %lx\n", status );
3613 ok( test_dbg_print_except, "DBG_PRINTEXCEPTION_C not received\n" );
3615 test_dbg_print_except = FALSE;
3616 test_dbg_print_except_ret = (LONG)EXCEPTION_CONTINUE_SEARCH;
3617 status = DbgPrint( "test_DbgPrint: %s", "Hello World" );
3618 ok( !status, "DbgPrint returned %lx\n", status );
3619 ok( test_dbg_print_except, "DBG_PRINTEXCEPTION_C not received\n" );
3622 /* FIXME: NtSetDebugFilterState / DbgSetDebugFilterState are probably what's controlling these */
3624 test_dbg_print_except = FALSE;
3625 test_dbg_print_except_ret = (LONG)EXCEPTION_EXECUTE_HANDLER;
3626 status = DbgPrintEx( 0, DPFLTR_ERROR_LEVEL, "test_DbgPrint: %s", "Hello World" );
3627 ok( !status, "DbgPrintEx returned %lx\n", status );
3628 ok( test_dbg_print_except, "DBG_PRINTEXCEPTION_C not received\n" );
3630 test_dbg_print_except = FALSE;
3631 test_dbg_print_except_ret = (LONG)EXCEPTION_EXECUTE_HANDLER;
3632 status = DbgPrintEx( 0, DPFLTR_WARNING_LEVEL, "test_DbgPrint: %s", "Hello World" );
3633 ok( !status, "DbgPrintEx returned %lx\n", status );
3634 ok( !test_dbg_print_except, "DBG_PRINTEXCEPTION_C not received\n" );
3636 test_dbg_print_except = FALSE;
3637 test_dbg_print_except_ret = (LONG)EXCEPTION_EXECUTE_HANDLER;
3638 status = DbgPrintEx( 0, DPFLTR_MASK|(1 << DPFLTR_ERROR_LEVEL), "test_DbgPrint: %s", "Hello World" );
3639 ok( !status, "DbgPrintEx returned %lx\n", status );
3640 ok( test_dbg_print_except, "DBG_PRINTEXCEPTION_C not received\n" );
3642 test_dbg_print_except = FALSE;
3643 test_dbg_print_except_ret = (LONG)EXCEPTION_EXECUTE_HANDLER;
3644 status = DbgPrintEx( 0, DPFLTR_MASK|(1 << DPFLTR_WARNING_LEVEL), "test_DbgPrint: %s", "Hello World" );
3645 ok( !status, "DbgPrintEx returned %lx\n", status );
3646 ok( !test_dbg_print_except, "DBG_PRINTEXCEPTION_C not received\n" );
3649 test_dbg_print_except = FALSE;
3650 test_dbg_print_except_ret = (LONG)EXCEPTION_EXECUTE_HANDLER;
3651 status = test_vDbgPrintEx( 0, 0xFFFFFFFF, "test_DbgPrint: %s", "Hello World" );
3652 ok( !status, "vDbgPrintEx returned %lx\n", status );
3653 ok( test_dbg_print_except, "DBG_PRINTEXCEPTION_C not received\n" );
3655 test_dbg_print_except = FALSE;
3656 test_dbg_print_except_ret = (LONG)EXCEPTION_EXECUTE_HANDLER;
3657 status = test_vDbgPrintExWithPrefix( "test_", 0, 0xFFFFFFFF, "DbgPrint: %s", "Hello World" );
3658 ok( !status, "vDbgPrintExWithPrefix returned %lx\n", status );
3659 ok( test_dbg_print_except, "DBG_PRINTEXCEPTION_C not received\n" );
3661 Peb->BeingDebugged = debugged;
3662 RtlRemoveVectoredExceptionHandler( handler );
3665 static BOOL test_heap_destroy_dbgstr = FALSE;
3666 static BOOL test_heap_destroy_break = FALSE;
3668 static LONG CALLBACK test_heap_destroy_except_handler( EXCEPTION_POINTERS *eptrs )
3670 if (eptrs->ExceptionRecord->ExceptionCode == STATUS_BREAKPOINT)
3672 #if defined( __i386__ )
3673 eptrs->ContextRecord->Eip += 1;
3674 test_heap_destroy_break = TRUE;
3675 return (LONG)EXCEPTION_CONTINUE_EXECUTION;
3676 #elif defined( __x86_64__ )
3677 eptrs->ContextRecord->Rip += 1;
3678 test_heap_destroy_break = TRUE;
3679 return (LONG)EXCEPTION_CONTINUE_EXECUTION;
3680 #endif
3683 if (eptrs->ExceptionRecord->ExceptionCode == DBG_PRINTEXCEPTION_C)
3685 test_heap_destroy_dbgstr = TRUE;
3686 return (LONG)EXCEPTION_CONTINUE_EXECUTION;
3689 return (LONG)EXCEPTION_CONTINUE_SEARCH;
3692 /* partially copied from ntdll/heap.c */
3693 #define HEAP_VALIDATE_PARAMS 0x40000000
3695 struct heap
3697 DWORD_PTR unknown1[2];
3698 DWORD unknown2[2];
3699 DWORD_PTR unknown3[4];
3700 DWORD unknown4;
3701 DWORD_PTR unknown5[2];
3702 DWORD unknown6[3];
3703 DWORD_PTR unknown7[2];
3704 DWORD flags;
3705 DWORD force_flags;
3706 DWORD_PTR unknown8[6];
3709 static void test_RtlDestroyHeap(void)
3711 const struct heap invalid = {{0, 0}, {0, HEAP_VALIDATE_PARAMS}, {0, 0, 0, 0}, 0, {0, 0}, {0, 0, 0}, {0, 0}, HEAP_VALIDATE_PARAMS, 0, {0}};
3712 HANDLE heap = (HANDLE)&invalid, ret;
3713 PEB *Peb = NtCurrentTeb()->Peb;
3714 BOOL debugged;
3715 void *handler = RtlAddVectoredExceptionHandler( TRUE, test_heap_destroy_except_handler );
3717 test_heap_destroy_dbgstr = FALSE;
3718 test_heap_destroy_break = FALSE;
3719 debugged = Peb->BeingDebugged;
3720 Peb->BeingDebugged = TRUE;
3721 ret = RtlDestroyHeap( heap );
3722 ok( ret == heap, "RtlDestroyHeap(%p) returned %p\n", heap, ret );
3723 ok( test_heap_destroy_dbgstr, "HeapDestroy didn't call OutputDebugStrA\n" );
3724 ok( test_heap_destroy_break, "HeapDestroy didn't call DbgBreakPoint\n" );
3725 Peb->BeingDebugged = debugged;
3727 RtlRemoveVectoredExceptionHandler( handler );
3730 static void test_RtlFirstFreeAce(void)
3732 PACL acl;
3733 PACE_HEADER first;
3734 BOOL ret;
3735 DWORD size;
3736 BOOLEAN found;
3738 size = sizeof(ACL) + (sizeof(ACCESS_ALLOWED_ACE));
3739 acl = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
3740 ret = InitializeAcl(acl, sizeof(ACL), ACL_REVISION);
3741 ok(ret, "InitializeAcl failed with error %ld\n", GetLastError());
3743 /* AceCount = 0 */
3744 first = (ACE_HEADER *)0xdeadbeef;
3745 found = RtlFirstFreeAce(acl, &first);
3746 ok(found, "RtlFirstFreeAce failed\n");
3747 ok(first == (PACE_HEADER)(acl + 1), "Failed to find ACL\n");
3749 acl->AclSize = sizeof(ACL) - 1;
3750 first = (ACE_HEADER *)0xdeadbeef;
3751 found = RtlFirstFreeAce(acl, &first);
3752 ok(found, "RtlFirstFreeAce failed\n");
3753 ok(first == NULL, "Found FirstAce = %p\n", first);
3755 /* AceCount = 1 */
3756 acl->AceCount = 1;
3757 acl->AclSize = size;
3758 first = (ACE_HEADER *)0xdeadbeef;
3759 found = RtlFirstFreeAce(acl, &first);
3760 ok(found, "RtlFirstFreeAce failed\n");
3761 ok(first == (PACE_HEADER)(acl + 1), "Failed to find ACL %p, %p\n", first, (PACE_HEADER)(acl + 1));
3763 acl->AclSize = sizeof(ACL) - 1;
3764 first = (ACE_HEADER *)0xdeadbeef;
3765 found = RtlFirstFreeAce(acl, &first);
3766 ok(!found, "RtlFirstFreeAce failed\n");
3767 ok(first == NULL, "Found FirstAce = %p\n", first);
3769 acl->AclSize = sizeof(ACL);
3770 first = (ACE_HEADER *)0xdeadbeef;
3771 found = RtlFirstFreeAce(acl, &first);
3772 ok(!found, "RtlFirstFreeAce failed\n");
3773 ok(first == NULL, "Found FirstAce = %p\n", first);
3775 HeapFree(GetProcessHeap(), 0, acl);
3778 START_TEST(rtl)
3780 InitFunctionPtrs();
3782 test_RtlQueryProcessDebugInformation();
3783 test_RtlCompareMemory();
3784 test_RtlCompareMemoryUlong();
3785 test_RtlMoveMemory();
3786 test_RtlFillMemory();
3787 test_RtlFillMemoryUlong();
3788 test_RtlZeroMemory();
3789 test_RtlByteSwap();
3790 test_RtlUniform();
3791 test_RtlRandom();
3792 test_RtlAreAllAccessesGranted();
3793 test_RtlAreAnyAccessesGranted();
3794 test_RtlComputeCrc32();
3795 test_HandleTables();
3796 test_RtlAllocateAndInitializeSid();
3797 test_RtlDeleteTimer();
3798 test_RtlThreadErrorMode();
3799 test_LdrProcessRelocationBlock();
3800 test_RtlIpv4AddressToString();
3801 test_RtlIpv4AddressToStringEx();
3802 test_RtlIpv4StringToAddress();
3803 test_RtlIpv4StringToAddressEx();
3804 test_RtlIpv6AddressToString();
3805 test_RtlIpv6AddressToStringEx();
3806 test_RtlIpv6StringToAddress();
3807 test_RtlIpv6StringToAddressEx();
3808 test_LdrAddRefDll();
3809 test_LdrLockLoaderLock();
3810 test_RtlCompressBuffer();
3811 test_RtlGetCompressionWorkSpaceSize();
3812 test_RtlDecompressBuffer();
3813 test_RtlIsCriticalSectionLocked();
3814 test_RtlInitializeCriticalSectionEx();
3815 test_RtlLeaveCriticalSection();
3816 test_LdrEnumerateLoadedModules();
3817 test_RtlMakeSelfRelativeSD();
3818 test_LdrRegisterDllNotification();
3819 test_DbgPrint();
3820 test_RtlDestroyHeap();
3821 test_RtlFirstFreeAce();