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
20 * We use function pointers here as there is no import library for NTDLL on
26 #include "ntdll_test.h"
30 #ifndef __WINE_WINTERNL_H
32 typedef struct _RTL_HANDLE
34 struct _RTL_HANDLE
* Next
;
37 typedef struct _RTL_HANDLE_TABLE
50 /* avoid #include <winsock2.h> */
52 #ifdef WORDS_BIGENDIAN
53 #define htons(s) ((USHORT)(s))
54 #else /* WORDS_BIGENDIAN */
55 static inline USHORT
__my_ushort_swap(USHORT s
)
57 return (s
>> 8) | (s
<< 8);
59 #define htons(s) __my_ushort_swap(s)
60 #endif /* WORDS_BIGENDIAN */
64 /* Function ptrs for ntdll calls */
65 static HMODULE hntdll
= 0;
66 static SIZE_T (WINAPI
*pRtlCompareMemory
)(LPCVOID
,LPCVOID
,SIZE_T
);
67 static SIZE_T (WINAPI
*pRtlCompareMemoryUlong
)(PULONG
, SIZE_T
, ULONG
);
68 static NTSTATUS (WINAPI
*pRtlDeleteTimer
)(HANDLE
, HANDLE
, HANDLE
);
69 static VOID (WINAPI
*pRtlMoveMemory
)(LPVOID
,LPCVOID
,SIZE_T
);
70 static VOID (WINAPI
*pRtlFillMemory
)(LPVOID
,SIZE_T
,BYTE
);
71 static VOID (WINAPI
*pRtlFillMemoryUlong
)(LPVOID
,SIZE_T
,ULONG
);
72 static VOID (WINAPI
*pRtlZeroMemory
)(LPVOID
,SIZE_T
);
73 static ULONGLONG (WINAPIV
*pRtlUlonglongByteSwap
)(ULONGLONG source
);
74 static ULONG (WINAPI
*pRtlUniform
)(PULONG
);
75 static ULONG (WINAPI
*pRtlRandom
)(PULONG
);
76 static BOOLEAN (WINAPI
*pRtlAreAllAccessesGranted
)(ACCESS_MASK
, ACCESS_MASK
);
77 static BOOLEAN (WINAPI
*pRtlAreAnyAccessesGranted
)(ACCESS_MASK
, ACCESS_MASK
);
78 static DWORD (WINAPI
*pRtlComputeCrc32
)(DWORD
,const BYTE
*,INT
);
79 static void (WINAPI
* pRtlInitializeHandleTable
)(ULONG
, ULONG
, RTL_HANDLE_TABLE
*);
80 static BOOLEAN (WINAPI
* pRtlIsValidIndexHandle
)(const RTL_HANDLE_TABLE
*, ULONG
, RTL_HANDLE
**);
81 static NTSTATUS (WINAPI
* pRtlDestroyHandleTable
)(RTL_HANDLE_TABLE
*);
82 static RTL_HANDLE
* (WINAPI
* pRtlAllocateHandle
)(RTL_HANDLE_TABLE
*, ULONG
*);
83 static BOOLEAN (WINAPI
* pRtlFreeHandle
)(RTL_HANDLE_TABLE
*, RTL_HANDLE
*);
84 static NTSTATUS (WINAPI
*pRtlAllocateAndInitializeSid
)(PSID_IDENTIFIER_AUTHORITY
,BYTE
,DWORD
,DWORD
,DWORD
,DWORD
,DWORD
,DWORD
,DWORD
,DWORD
,PSID
*);
85 static NTSTATUS (WINAPI
*pRtlFreeSid
)(PSID
);
86 static DWORD (WINAPI
*pRtlGetThreadErrorMode
)(void);
87 static NTSTATUS (WINAPI
*pRtlSetThreadErrorMode
)(DWORD
, LPDWORD
);
88 static IMAGE_BASE_RELOCATION
*(WINAPI
*pLdrProcessRelocationBlock
)(void*,UINT
,USHORT
*,INT_PTR
);
89 static CHAR
* (WINAPI
*pRtlIpv4AddressToStringA
)(const IN_ADDR
*, LPSTR
);
90 static NTSTATUS (WINAPI
*pRtlIpv4AddressToStringExA
)(const IN_ADDR
*, USHORT
, LPSTR
, PULONG
);
91 static NTSTATUS (WINAPI
*pRtlIpv4StringToAddressA
)(PCSTR
, BOOLEAN
, PCSTR
*, IN_ADDR
*);
92 static NTSTATUS (WINAPI
*pRtlIpv4StringToAddressExA
)(PCSTR
, BOOLEAN
, IN_ADDR
*, PUSHORT
);
93 static CHAR
* (WINAPI
*pRtlIpv6AddressToStringA
)(struct in6_addr
*, PSTR
);
94 static NTSTATUS (WINAPI
*pRtlIpv6AddressToStringExA
)(struct in6_addr
*, ULONG
, USHORT
, PCHAR
, PULONG
);
95 static NTSTATUS (WINAPI
*pRtlIpv6StringToAddressA
)(PCSTR
, PCSTR
*, struct in6_addr
*);
96 static NTSTATUS (WINAPI
*pRtlIpv6StringToAddressW
)(PCWSTR
, PCWSTR
*, struct in6_addr
*);
97 static NTSTATUS (WINAPI
*pRtlIpv6StringToAddressExA
)(PCSTR
, struct in6_addr
*, PULONG
, PUSHORT
);
98 static NTSTATUS (WINAPI
*pRtlIpv6StringToAddressExW
)(PCWSTR
, struct in6_addr
*, PULONG
, PUSHORT
);
99 static NTSTATUS (WINAPI
*pLdrAddRefDll
)(ULONG
, HMODULE
);
100 static NTSTATUS (WINAPI
*pLdrLockLoaderLock
)(ULONG
, ULONG
*, ULONG_PTR
*);
101 static NTSTATUS (WINAPI
*pLdrUnlockLoaderLock
)(ULONG
, ULONG_PTR
);
102 static NTSTATUS (WINAPI
*pRtlMultiByteToUnicodeN
)(LPWSTR
, DWORD
, LPDWORD
, LPCSTR
, DWORD
);
103 static NTSTATUS (WINAPI
*pRtlGetCompressionWorkSpaceSize
)(USHORT
, PULONG
, PULONG
);
104 static NTSTATUS (WINAPI
*pRtlDecompressBuffer
)(USHORT
, PUCHAR
, ULONG
, const UCHAR
*, ULONG
, PULONG
);
105 static NTSTATUS (WINAPI
*pRtlDecompressFragment
)(USHORT
, PUCHAR
, ULONG
, const UCHAR
*, ULONG
, ULONG
, PULONG
, PVOID
);
106 static NTSTATUS (WINAPI
*pRtlCompressBuffer
)(USHORT
, const UCHAR
*, ULONG
, PUCHAR
, ULONG
, ULONG
, PULONG
, PVOID
);
107 static BOOL (WINAPI
*pRtlIsCriticalSectionLocked
)(CRITICAL_SECTION
*);
108 static BOOL (WINAPI
*pRtlIsCriticalSectionLockedByThread
)(CRITICAL_SECTION
*);
109 static NTSTATUS (WINAPI
*pRtlInitializeCriticalSectionEx
)(CRITICAL_SECTION
*, ULONG
, ULONG
);
110 static NTSTATUS (WINAPI
*pLdrEnumerateLoadedModules
)(void *, void *, void *);
111 static NTSTATUS (WINAPI
*pRtlMakeSelfRelativeSD
)(PSECURITY_DESCRIPTOR
,PSECURITY_DESCRIPTOR
,LPDWORD
);
112 static NTSTATUS (WINAPI
*pRtlAbsoluteToSelfRelativeSD
)(PSECURITY_DESCRIPTOR
,PSECURITY_DESCRIPTOR
,PULONG
);
113 static NTSTATUS (WINAPI
*pLdrRegisterDllNotification
)(ULONG
, PLDR_DLL_NOTIFICATION_FUNCTION
, void *, void **);
114 static NTSTATUS (WINAPI
*pLdrUnregisterDllNotification
)(void *);
116 static HMODULE hkernel32
= 0;
117 static BOOL (WINAPI
*pIsWow64Process
)(HANDLE
, PBOOL
);
121 static const char* src_src
= "This is a test!"; /* 16 bytes long, incl NUL */
122 static WCHAR ws2_32dllW
[] = {'w','s','2','_','3','2','.','d','l','l',0};
123 static WCHAR nsidllW
[] = {'n','s','i','.','d','l','l',0};
124 static WCHAR wintrustdllW
[] = {'w','i','n','t','r','u','s','t','.','d','l','l',0};
125 static WCHAR crypt32dllW
[] = {'c','r','y','p','t','3','2','.','d','l','l',0};
126 static ULONG src_aligned_block
[4];
127 static ULONG dest_aligned_block
[32];
128 static const char *src
= (const char*)src_aligned_block
;
129 static char* dest
= (char*)dest_aligned_block
;
130 const WCHAR
*expected_dll
= nsidllW
;
132 static void InitFunctionPtrs(void)
134 hntdll
= LoadLibraryA("ntdll.dll");
135 ok(hntdll
!= 0, "LoadLibrary failed\n");
137 pRtlCompareMemory
= (void *)GetProcAddress(hntdll
, "RtlCompareMemory");
138 pRtlCompareMemoryUlong
= (void *)GetProcAddress(hntdll
, "RtlCompareMemoryUlong");
139 pRtlDeleteTimer
= (void *)GetProcAddress(hntdll
, "RtlDeleteTimer");
140 pRtlMoveMemory
= (void *)GetProcAddress(hntdll
, "RtlMoveMemory");
141 pRtlFillMemory
= (void *)GetProcAddress(hntdll
, "RtlFillMemory");
142 pRtlFillMemoryUlong
= (void *)GetProcAddress(hntdll
, "RtlFillMemoryUlong");
143 pRtlZeroMemory
= (void *)GetProcAddress(hntdll
, "RtlZeroMemory");
144 pRtlUlonglongByteSwap
= (void *)GetProcAddress(hntdll
, "RtlUlonglongByteSwap");
145 pRtlUniform
= (void *)GetProcAddress(hntdll
, "RtlUniform");
146 pRtlRandom
= (void *)GetProcAddress(hntdll
, "RtlRandom");
147 pRtlAreAllAccessesGranted
= (void *)GetProcAddress(hntdll
, "RtlAreAllAccessesGranted");
148 pRtlAreAnyAccessesGranted
= (void *)GetProcAddress(hntdll
, "RtlAreAnyAccessesGranted");
149 pRtlComputeCrc32
= (void *)GetProcAddress(hntdll
, "RtlComputeCrc32");
150 pRtlInitializeHandleTable
= (void *)GetProcAddress(hntdll
, "RtlInitializeHandleTable");
151 pRtlIsValidIndexHandle
= (void *)GetProcAddress(hntdll
, "RtlIsValidIndexHandle");
152 pRtlDestroyHandleTable
= (void *)GetProcAddress(hntdll
, "RtlDestroyHandleTable");
153 pRtlAllocateHandle
= (void *)GetProcAddress(hntdll
, "RtlAllocateHandle");
154 pRtlFreeHandle
= (void *)GetProcAddress(hntdll
, "RtlFreeHandle");
155 pRtlAllocateAndInitializeSid
= (void *)GetProcAddress(hntdll
, "RtlAllocateAndInitializeSid");
156 pRtlFreeSid
= (void *)GetProcAddress(hntdll
, "RtlFreeSid");
157 pRtlGetThreadErrorMode
= (void *)GetProcAddress(hntdll
, "RtlGetThreadErrorMode");
158 pRtlSetThreadErrorMode
= (void *)GetProcAddress(hntdll
, "RtlSetThreadErrorMode");
159 pLdrProcessRelocationBlock
= (void *)GetProcAddress(hntdll
, "LdrProcessRelocationBlock");
160 pRtlIpv4AddressToStringA
= (void *)GetProcAddress(hntdll
, "RtlIpv4AddressToStringA");
161 pRtlIpv4AddressToStringExA
= (void *)GetProcAddress(hntdll
, "RtlIpv4AddressToStringExA");
162 pRtlIpv4StringToAddressA
= (void *)GetProcAddress(hntdll
, "RtlIpv4StringToAddressA");
163 pRtlIpv4StringToAddressExA
= (void *)GetProcAddress(hntdll
, "RtlIpv4StringToAddressExA");
164 pRtlIpv6AddressToStringA
= (void *)GetProcAddress(hntdll
, "RtlIpv6AddressToStringA");
165 pRtlIpv6AddressToStringExA
= (void *)GetProcAddress(hntdll
, "RtlIpv6AddressToStringExA");
166 pRtlIpv6StringToAddressA
= (void *)GetProcAddress(hntdll
, "RtlIpv6StringToAddressA");
167 pRtlIpv6StringToAddressW
= (void *)GetProcAddress(hntdll
, "RtlIpv6StringToAddressW");
168 pRtlIpv6StringToAddressExA
= (void *)GetProcAddress(hntdll
, "RtlIpv6StringToAddressExA");
169 pRtlIpv6StringToAddressExW
= (void *)GetProcAddress(hntdll
, "RtlIpv6StringToAddressExW");
170 pLdrAddRefDll
= (void *)GetProcAddress(hntdll
, "LdrAddRefDll");
171 pLdrLockLoaderLock
= (void *)GetProcAddress(hntdll
, "LdrLockLoaderLock");
172 pLdrUnlockLoaderLock
= (void *)GetProcAddress(hntdll
, "LdrUnlockLoaderLock");
173 pRtlMultiByteToUnicodeN
= (void *)GetProcAddress(hntdll
, "RtlMultiByteToUnicodeN");
174 pRtlGetCompressionWorkSpaceSize
= (void *)GetProcAddress(hntdll
, "RtlGetCompressionWorkSpaceSize");
175 pRtlDecompressBuffer
= (void *)GetProcAddress(hntdll
, "RtlDecompressBuffer");
176 pRtlDecompressFragment
= (void *)GetProcAddress(hntdll
, "RtlDecompressFragment");
177 pRtlCompressBuffer
= (void *)GetProcAddress(hntdll
, "RtlCompressBuffer");
178 pRtlIsCriticalSectionLocked
= (void *)GetProcAddress(hntdll
, "RtlIsCriticalSectionLocked");
179 pRtlIsCriticalSectionLockedByThread
= (void *)GetProcAddress(hntdll
, "RtlIsCriticalSectionLockedByThread");
180 pRtlInitializeCriticalSectionEx
= (void *)GetProcAddress(hntdll
, "RtlInitializeCriticalSectionEx");
181 pLdrEnumerateLoadedModules
= (void *)GetProcAddress(hntdll
, "LdrEnumerateLoadedModules");
182 pRtlMakeSelfRelativeSD
= (void *)GetProcAddress(hntdll
, "RtlMakeSelfRelativeSD");
183 pRtlAbsoluteToSelfRelativeSD
= (void *)GetProcAddress(hntdll
, "RtlAbsoluteToSelfRelativeSD");
184 pLdrRegisterDllNotification
= (void *)GetProcAddress(hntdll
, "LdrRegisterDllNotification");
185 pLdrUnregisterDllNotification
= (void *)GetProcAddress(hntdll
, "LdrUnregisterDllNotification");
187 hkernel32
= LoadLibraryA("kernel32.dll");
188 ok(hkernel32
!= 0, "LoadLibrary failed\n");
190 pIsWow64Process
= (void *)GetProcAddress(hkernel32
, "IsWow64Process");
192 strcpy((char*)src_aligned_block
, src_src
);
193 ok(strlen(src
) == 15, "Source must be 16 bytes long!\n");
196 #define COMP(str1,str2,cmplen,len) size = pRtlCompareMemory(str1, str2, cmplen); \
197 ok(size == len, "Expected %ld, got %ld\n", size, (SIZE_T)len)
199 static void test_RtlCompareMemory(void)
203 if (!pRtlCompareMemory
)
205 win_skip("RtlCompareMemory is not available\n");
212 COMP(src
,src
,LEN
,LEN
);
214 COMP(src
,dest
,LEN
,0);
217 static void test_RtlCompareMemoryUlong(void)
222 if (!pRtlCompareMemoryUlong
)
224 win_skip("RtlCompareMemoryUlong is not available\n");
232 result
= pRtlCompareMemoryUlong(a
, 0, 0x0123);
233 ok(result
== 0, "RtlCompareMemoryUlong(%p, 0, 0x0123) returns %u, expected 0\n", a
, result
);
234 result
= pRtlCompareMemoryUlong(a
, 3, 0x0123);
235 ok(result
== 0, "RtlCompareMemoryUlong(%p, 3, 0x0123) returns %u, expected 0\n", a
, result
);
236 result
= pRtlCompareMemoryUlong(a
, 4, 0x0123);
237 ok(result
== 4, "RtlCompareMemoryUlong(%p, 4, 0x0123) returns %u, expected 4\n", a
, result
);
238 result
= pRtlCompareMemoryUlong(a
, 5, 0x0123);
239 ok(result
== 4, "RtlCompareMemoryUlong(%p, 5, 0x0123) returns %u, expected 4\n", a
, result
);
240 result
= pRtlCompareMemoryUlong(a
, 7, 0x0123);
241 ok(result
== 4, "RtlCompareMemoryUlong(%p, 7, 0x0123) returns %u, expected 4\n", a
, result
);
242 result
= pRtlCompareMemoryUlong(a
, 8, 0x0123);
243 ok(result
== 4, "RtlCompareMemoryUlong(%p, 8, 0x0123) returns %u, expected 4\n", a
, result
);
244 result
= pRtlCompareMemoryUlong(a
, 9, 0x0123);
245 ok(result
== 4, "RtlCompareMemoryUlong(%p, 9, 0x0123) returns %u, expected 4\n", a
, result
);
246 result
= pRtlCompareMemoryUlong(a
, 4, 0x0127);
247 ok(result
== 0, "RtlCompareMemoryUlong(%p, 4, 0x0127) returns %u, expected 0\n", a
, result
);
248 result
= pRtlCompareMemoryUlong(a
, 4, 0x7123);
249 ok(result
== 0, "RtlCompareMemoryUlong(%p, 4, 0x7123) returns %u, expected 0\n", a
, result
);
250 result
= pRtlCompareMemoryUlong(a
, 16, 0x4567);
251 ok(result
== 0, "RtlCompareMemoryUlong(%p, 16, 0x4567) returns %u, expected 0\n", a
, result
);
254 result
= pRtlCompareMemoryUlong(a
, 3, 0x0123);
255 ok(result
== 0, "RtlCompareMemoryUlong(%p, 3, 0x0123) returns %u, expected 0\n", a
, result
);
256 result
= pRtlCompareMemoryUlong(a
, 4, 0x0123);
257 ok(result
== 4, "RtlCompareMemoryUlong(%p, 4, 0x0123) returns %u, expected 4\n", a
, result
);
258 result
= pRtlCompareMemoryUlong(a
, 5, 0x0123);
259 ok(result
== 4, "RtlCompareMemoryUlong(%p, 5, 0x0123) returns %u, expected 4\n", a
, result
);
260 result
= pRtlCompareMemoryUlong(a
, 7, 0x0123);
261 ok(result
== 4, "RtlCompareMemoryUlong(%p, 7, 0x0123) returns %u, expected 4\n", a
, result
);
262 result
= pRtlCompareMemoryUlong(a
, 8, 0x0123);
263 ok(result
== 8, "RtlCompareMemoryUlong(%p, 8, 0x0123) returns %u, expected 8\n", a
, result
);
264 result
= pRtlCompareMemoryUlong(a
, 9, 0x0123);
265 ok(result
== 8, "RtlCompareMemoryUlong(%p, 9, 0x0123) returns %u, expected 8\n", a
, result
);
268 #define COPY(len) memset(dest,0,sizeof(dest_aligned_block)); pRtlMoveMemory(dest, src, len)
269 #define CMP(str) ok(strcmp(dest,str) == 0, "Expected '%s', got '%s'\n", str, dest)
271 static void test_RtlMoveMemory(void)
275 win_skip("RtlMoveMemory is not available\n");
279 /* Length should be in bytes and not rounded. Use strcmp to ensure we
280 * didn't write past the end (it checks for the final NUL left by memset)
286 COPY(4); CMP("This");
287 COPY(5); CMP("This ");
288 COPY(6); CMP("This i");
289 COPY(7); CMP("This is");
290 COPY(8); CMP("This is ");
291 COPY(9); CMP("This is a");
294 strcpy(dest
, src
); pRtlMoveMemory(dest
, dest
+ 1, strlen(src
) - 1);
295 CMP("his is a test!!");
296 strcpy(dest
, src
); pRtlMoveMemory(dest
+ 1, dest
, strlen(src
));
297 CMP("TThis is a test!");
300 #define FILL(len) memset(dest,0,sizeof(dest_aligned_block)); strcpy(dest, src); pRtlFillMemory(dest,len,'x')
302 static void test_RtlFillMemory(void)
306 win_skip("RtlFillMemory is not available\n");
310 /* Length should be in bytes and not rounded. Use strcmp to ensure we
311 * didn't write past the end (the remainder of the string should match)
313 FILL(0); CMP("This is a test!");
314 FILL(1); CMP("xhis is a test!");
315 FILL(2); CMP("xxis is a test!");
316 FILL(3); CMP("xxxs is a test!");
317 FILL(4); CMP("xxxx is a test!");
318 FILL(5); CMP("xxxxxis a test!");
319 FILL(6); CMP("xxxxxxs a test!");
320 FILL(7); CMP("xxxxxxx a test!");
321 FILL(8); CMP("xxxxxxxxa test!");
322 FILL(9); CMP("xxxxxxxxx test!");
325 #define LFILL(len) memset(dest,0,sizeof(dest_aligned_block)); strcpy(dest, src); pRtlFillMemoryUlong(dest,len,val)
327 static void test_RtlFillMemoryUlong(void)
329 ULONG val
= ('x' << 24) | ('x' << 16) | ('x' << 8) | 'x';
330 if (!pRtlFillMemoryUlong
)
332 win_skip("RtlFillMemoryUlong is not available\n");
336 /* Length should be in bytes and not rounded. Use strcmp to ensure we
337 * didn't write past the end (the remainder of the string should match)
339 LFILL(0); CMP("This is a test!");
340 LFILL(1); CMP("This is a test!");
341 LFILL(2); CMP("This is a test!");
342 LFILL(3); CMP("This is a test!");
343 LFILL(4); CMP("xxxx is a test!");
344 LFILL(5); CMP("xxxx is a test!");
345 LFILL(6); CMP("xxxx is a test!");
346 LFILL(7); CMP("xxxx is a test!");
347 LFILL(8); CMP("xxxxxxxxa test!");
348 LFILL(9); CMP("xxxxxxxxa test!");
351 #define ZERO(len) memset(dest,0,sizeof(dest_aligned_block)); strcpy(dest, src); pRtlZeroMemory(dest,len)
352 #define MCMP(str) ok(memcmp(dest,str,LEN) == 0, "Memcmp failed\n")
354 static void test_RtlZeroMemory(void)
358 win_skip("RtlZeroMemory is not available\n");
362 /* Length should be in bytes and not rounded. */
363 ZERO(0); MCMP("This is a test!");
364 ZERO(1); MCMP("\0his is a test!");
365 ZERO(2); MCMP("\0\0is is a test!");
366 ZERO(3); MCMP("\0\0\0s is a test!");
367 ZERO(4); MCMP("\0\0\0\0 is a test!");
368 ZERO(5); MCMP("\0\0\0\0\0is a test!");
369 ZERO(6); MCMP("\0\0\0\0\0\0s a test!");
370 ZERO(7); MCMP("\0\0\0\0\0\0\0 a test!");
371 ZERO(8); MCMP("\0\0\0\0\0\0\0\0a test!");
372 ZERO(9); MCMP("\0\0\0\0\0\0\0\0\0 test!");
375 static void test_RtlUlonglongByteSwap(void)
379 if ( !pRtlUlonglongByteSwap
)
381 win_skip("RtlUlonglongByteSwap is not available\n");
385 if ( pRtlUlonglongByteSwap( 0 ) != 0 )
387 win_skip("Broken RtlUlonglongByteSwap in win2k\n");
391 result
= pRtlUlonglongByteSwap( ((ULONGLONG
)0x76543210 << 32) | 0x87654321 );
392 ok( (((ULONGLONG
)0x21436587 << 32) | 0x10325476) == result
,
393 "RtlUlonglongByteSwap(0x7654321087654321) returns 0x%s, expected 0x2143658710325476\n",
394 wine_dbgstr_longlong(result
));
398 static void test_RtlUniform(void)
408 win_skip("RtlUniform is not available\n");
413 * According to the documentation RtlUniform is using D.H. Lehmer's 1948
414 * algorithm. This algorithm is:
416 * seed = (seed * const_1 + const_2) % const_3;
418 * According to the documentation the random number is distributed over
419 * [0..MAXLONG]. Therefore const_3 is MAXLONG + 1:
421 * seed = (seed * const_1 + const_2) % (MAXLONG + 1);
423 * Because MAXLONG is 0x7fffffff (and MAXLONG + 1 is 0x80000000) the
424 * algorithm can be expressed without division as:
426 * seed = (seed * const_1 + const_2) & MAXLONG;
428 * To find out const_2 we just call RtlUniform with seed set to 0:
431 expected
= 0x7fffffc3;
432 result
= pRtlUniform(&seed
);
433 ok(result
== expected
,
434 "RtlUniform(&seed (seed == 0)) returns %x, expected %x\n",
437 * The algorithm is now:
439 * seed = (seed * const_1 + 0x7fffffc3) & MAXLONG;
441 * To find out const_1 we can use:
443 * const_1 = RtlUniform(1) - 0x7fffffc3;
445 * If that does not work a search loop can try all possible values of
446 * const_1 and compare to the result to RtlUniform(1).
447 * This way we find out that const_1 is 0xffffffed.
449 * For seed = 1 the const_2 is 0x7fffffc4:
452 expected
= seed
* 0xffffffed + 0x7fffffc3 + 1;
453 result
= pRtlUniform(&seed
);
454 ok(result
== expected
,
455 "RtlUniform(&seed (seed == 1)) returns %x, expected %x\n",
458 * For seed = 2 the const_2 is 0x7fffffc3:
461 expected
= seed
* 0xffffffed + 0x7fffffc3;
462 result
= pRtlUniform(&seed
);
465 * Windows Vista uses different algorithms, so skip the rest of the tests
466 * until that is figured out. Trace output for the failures is about 10.5 MB!
469 if (result
== 0x7fffff9f) {
470 skip("Most likely running on Windows Vista which uses a different algorithm\n");
474 ok(result
== expected
,
475 "RtlUniform(&seed (seed == 2)) returns %x, expected %x\n",
479 * More tests show that if seed is odd the result must be incremented by 1:
482 expected
= seed
* 0xffffffed + 0x7fffffc3 + (seed
& 1);
483 result
= pRtlUniform(&seed
);
484 ok(result
== expected
,
485 "RtlUniform(&seed (seed == 3)) returns %x, expected %x\n",
489 expected
= seed
* 0xffffffed + 0x7fffffc3;
490 result
= pRtlUniform(&seed
);
491 ok(result
== expected
,
492 "RtlUniform(&seed (seed == 0x6bca1aa)) returns %x, expected %x\n",
496 expected
= seed
* 0xffffffed + 0x7fffffc3 + 1;
497 result
= pRtlUniform(&seed
);
498 ok(result
== expected
,
499 "RtlUniform(&seed (seed == 0x6bca1ab)) returns %x, expected %x\n",
502 * When seed is 0x6bca1ac there is an exception:
505 expected
= seed
* 0xffffffed + 0x7fffffc3 + 2;
506 result
= pRtlUniform(&seed
);
507 ok(result
== expected
,
508 "RtlUniform(&seed (seed == 0x6bca1ac)) returns %x, expected %x\n",
511 * Note that up to here const_3 is not used
512 * (the highest bit of the result is not set).
514 * Starting with 0x6bca1ad: If seed is even the result must be incremented by 1:
517 expected
= (seed
* 0xffffffed + 0x7fffffc3) & MAXLONG
;
518 result
= pRtlUniform(&seed
);
519 ok(result
== expected
,
520 "RtlUniform(&seed (seed == 0x6bca1ad)) returns %x, expected %x\n",
524 expected
= (seed
* 0xffffffed + 0x7fffffc3 + 1) & MAXLONG
;
525 result
= pRtlUniform(&seed
);
526 ok(result
== expected
,
527 "RtlUniform(&seed (seed == 0x6bca1ae)) returns %x, expected %x\n",
530 * There are several ranges where for odd or even seed the result must be
531 * incremented by 1. You can see this ranges in the following test.
533 * For a full test use one of the following loop heads:
535 * for (num = 0; num <= 0xffffffff; num++) {
540 * for (num = 0; num <= 0xffffffff; num++) {
544 for (num
= 0; num
<= 100000; num
++) {
546 expected
= seed
* 0xffffffed + 0x7fffffc3;
547 if (seed
< 0x6bca1ac) {
548 expected
= expected
+ (seed
& 1);
549 } else if (seed
== 0x6bca1ac) {
550 expected
= (expected
+ 2) & MAXLONG
;
551 } else if (seed
< 0xd79435c) {
552 expected
= (expected
+ (~seed
& 1)) & MAXLONG
;
553 } else if (seed
< 0x1435e50b) {
554 expected
= expected
+ (seed
& 1);
555 } else if (seed
< 0x1af286ba) {
556 expected
= (expected
+ (~seed
& 1)) & MAXLONG
;
557 } else if (seed
< 0x21af2869) {
558 expected
= expected
+ (seed
& 1);
559 } else if (seed
< 0x286bca18) {
560 expected
= (expected
+ (~seed
& 1)) & MAXLONG
;
561 } else if (seed
< 0x2f286bc7) {
562 expected
= expected
+ (seed
& 1);
563 } else if (seed
< 0x35e50d77) {
564 expected
= (expected
+ (~seed
& 1)) & MAXLONG
;
565 } else if (seed
< 0x3ca1af26) {
566 expected
= expected
+ (seed
& 1);
567 } else if (seed
< 0x435e50d5) {
568 expected
= (expected
+ (~seed
& 1)) & MAXLONG
;
569 } else if (seed
< 0x4a1af284) {
570 expected
= expected
+ (seed
& 1);
571 } else if (seed
< 0x50d79433) {
572 expected
= (expected
+ (~seed
& 1)) & MAXLONG
;
573 } else if (seed
< 0x579435e2) {
574 expected
= expected
+ (seed
& 1);
575 } else if (seed
< 0x5e50d792) {
576 expected
= (expected
+ (~seed
& 1)) & MAXLONG
;
577 } else if (seed
< 0x650d7941) {
578 expected
= expected
+ (seed
& 1);
579 } else if (seed
< 0x6bca1af0) {
580 expected
= (expected
+ (~seed
& 1)) & MAXLONG
;
581 } else if (seed
< 0x7286bc9f) {
582 expected
= expected
+ (seed
& 1);
583 } else if (seed
< 0x79435e4e) {
584 expected
= (expected
+ (~seed
& 1)) & MAXLONG
;
585 } else if (seed
< 0x7ffffffd) {
586 expected
= expected
+ (seed
& 1);
587 } else if (seed
< 0x86bca1ac) {
588 expected
= (expected
+ (~seed
& 1)) & MAXLONG
;
589 } else if (seed
== 0x86bca1ac) {
590 expected
= (expected
+ 1) & MAXLONG
;
591 } else if (seed
< 0x8d79435c) {
592 expected
= expected
+ (seed
& 1);
593 } else if (seed
< 0x9435e50b) {
594 expected
= (expected
+ (~seed
& 1)) & MAXLONG
;
595 } else if (seed
< 0x9af286ba) {
596 expected
= expected
+ (seed
& 1);
597 } else if (seed
< 0xa1af2869) {
598 expected
= (expected
+ (~seed
& 1)) & MAXLONG
;
599 } else if (seed
< 0xa86bca18) {
600 expected
= expected
+ (seed
& 1);
601 } else if (seed
< 0xaf286bc7) {
602 expected
= (expected
+ (~seed
& 1)) & MAXLONG
;
603 } else if (seed
== 0xaf286bc7) {
604 expected
= (expected
+ 2) & MAXLONG
;
605 } else if (seed
< 0xb5e50d77) {
606 expected
= expected
+ (seed
& 1);
607 } else if (seed
< 0xbca1af26) {
608 expected
= (expected
+ (~seed
& 1)) & MAXLONG
;
609 } else if (seed
< 0xc35e50d5) {
610 expected
= expected
+ (seed
& 1);
611 } else if (seed
< 0xca1af284) {
612 expected
= (expected
+ (~seed
& 1)) & MAXLONG
;
613 } else if (seed
< 0xd0d79433) {
614 expected
= expected
+ (seed
& 1);
615 } else if (seed
< 0xd79435e2) {
616 expected
= (expected
+ (~seed
& 1)) & MAXLONG
;
617 } else if (seed
< 0xde50d792) {
618 expected
= expected
+ (seed
& 1);
619 } else if (seed
< 0xe50d7941) {
620 expected
= (expected
+ (~seed
& 1)) & MAXLONG
;
621 } else if (seed
< 0xebca1af0) {
622 expected
= expected
+ (seed
& 1);
623 } else if (seed
< 0xf286bc9f) {
624 expected
= (expected
+ (~seed
& 1)) & MAXLONG
;
625 } else if (seed
< 0xf9435e4e) {
626 expected
= expected
+ (seed
& 1);
627 } else if (seed
< 0xfffffffd) {
628 expected
= (expected
+ (~seed
& 1)) & MAXLONG
;
630 expected
= expected
+ (seed
& 1);
633 result
= pRtlUniform(&seed
);
634 ok(result
== expected
,
635 "test: 0x%s RtlUniform(&seed (seed == %x)) returns %x, expected %x\n",
636 wine_dbgstr_longlong(num
), seed_bak
, result
, expected
);
638 "test: 0x%s RtlUniform(&seed (seed == %x)) sets seed to %x, expected %x\n",
639 wine_dbgstr_longlong(num
), seed_bak
, result
, expected
);
642 * Further investigation shows: In the different regions the highest bit
643 * is set or cleared when even or odd seeds need an increment by 1.
644 * This leads to a simplified algorithm:
646 * seed = seed * 0xffffffed + 0x7fffffc3;
647 * if (seed == 0xffffffff || seed == 0x7ffffffe) {
648 * seed = (seed + 2) & MAXLONG;
649 * } else if (seed == 0x7fffffff) {
651 * } else if ((seed & 0x80000000) == 0) {
652 * seed = seed + (~seed & 1);
654 * seed = (seed + (seed & 1)) & MAXLONG;
657 * This is also the algorithm used for RtlUniform of wine (see dlls/ntdll/rtl.c).
659 * Now comes the funny part:
660 * It took me one weekend, to find the complicated algorithm and one day more,
661 * to find the simplified algorithm. Several weeks later I found out: The value
662 * MAXLONG (=0x7fffffff) is never returned, neither with the native function
663 * nor with the simplified algorithm. In reality the native function and our
664 * function return a random number distributed over [0..MAXLONG-1]. Note
665 * that this is different from what native documentation states [0..MAXLONG].
666 * Expressed with D.H. Lehmer's 1948 algorithm it looks like:
668 * seed = (seed * const_1 + const_2) % MAXLONG;
670 * Further investigations show that the real algorithm is:
672 * seed = (seed * 0x7fffffed + 0x7fffffc3) % MAXLONG;
674 * This is checked with the test below:
677 for (num
= 0; num
<= 100000; num
++) {
678 expected
= (seed
* 0x7fffffed + 0x7fffffc3) % 0x7fffffff;
680 result
= pRtlUniform(&seed
);
681 ok(result
== expected
,
682 "test: 0x%s RtlUniform(&seed (seed == %x)) returns %x, expected %x\n",
683 wine_dbgstr_longlong(num
), seed_bak
, result
, expected
);
685 "test: 0x%s RtlUniform(&seed (seed == %x)) sets seed to %x, expected %x\n",
686 wine_dbgstr_longlong(num
), seed_bak
, result
, expected
);
689 * More tests show that RtlUniform does not return 0x7ffffffd for seed values
690 * in the range [0..MAXLONG-1]. Additionally 2 is returned twice. This shows
691 * that there is more than one cycle of generated randon numbers ...
696 static void test_RtlRandom(void)
704 win_skip("RtlRandom is not available\n");
709 for (i
= 0; i
< ARRAY_SIZE(res
); i
++)
711 res
[i
] = pRtlRandom(&seed
);
712 ok(seed
!= res
[i
], "%i: seed is same as res %x\n", i
, seed
);
713 for (j
= 0; j
< i
; j
++)
714 ok(res
[i
] != res
[j
], "res[%i] (%x) is same as res[%i] (%x)\n", j
, res
[j
], i
, res
[i
]);
720 ACCESS_MASK GrantedAccess
;
721 ACCESS_MASK DesiredAccess
;
725 static const all_accesses_t all_accesses
[] = {
726 {0xFEDCBA76, 0xFEDCBA76, 1},
727 {0x00000000, 0xFEDCBA76, 0},
728 {0xFEDCBA76, 0x00000000, 1},
729 {0x00000000, 0x00000000, 1},
730 {0xFEDCBA76, 0xFEDCBA70, 1},
731 {0xFEDCBA70, 0xFEDCBA76, 0},
732 {0xFEDCBA76, 0xFEDC8A76, 1},
733 {0xFEDC8A76, 0xFEDCBA76, 0},
734 {0xFEDCBA76, 0xC8C4B242, 1},
735 {0xC8C4B242, 0xFEDCBA76, 0},
739 static void test_RtlAreAllAccessesGranted(void)
741 unsigned int test_num
;
744 if (!pRtlAreAllAccessesGranted
)
746 win_skip("RtlAreAllAccessesGranted is not available\n");
750 for (test_num
= 0; test_num
< ARRAY_SIZE(all_accesses
); test_num
++) {
751 result
= pRtlAreAllAccessesGranted(all_accesses
[test_num
].GrantedAccess
,
752 all_accesses
[test_num
].DesiredAccess
);
753 ok(all_accesses
[test_num
].result
== result
,
754 "(test %d): RtlAreAllAccessesGranted(%08x, %08x) returns %d, expected %d\n",
755 test_num
, all_accesses
[test_num
].GrantedAccess
,
756 all_accesses
[test_num
].DesiredAccess
,
757 result
, all_accesses
[test_num
].result
);
763 ACCESS_MASK GrantedAccess
;
764 ACCESS_MASK DesiredAccess
;
768 static const any_accesses_t any_accesses
[] = {
769 {0xFEDCBA76, 0xFEDCBA76, 1},
770 {0x00000000, 0xFEDCBA76, 0},
771 {0xFEDCBA76, 0x00000000, 0},
772 {0x00000000, 0x00000000, 0},
773 {0xFEDCBA76, 0x01234589, 0},
774 {0x00040000, 0xFEDCBA76, 1},
775 {0x00040000, 0xFED8BA76, 0},
776 {0xFEDCBA76, 0x00040000, 1},
777 {0xFED8BA76, 0x00040000, 0},
781 static void test_RtlAreAnyAccessesGranted(void)
783 unsigned int test_num
;
786 if (!pRtlAreAnyAccessesGranted
)
788 win_skip("RtlAreAnyAccessesGranted is not available\n");
792 for (test_num
= 0; test_num
< ARRAY_SIZE(any_accesses
); test_num
++) {
793 result
= pRtlAreAnyAccessesGranted(any_accesses
[test_num
].GrantedAccess
,
794 any_accesses
[test_num
].DesiredAccess
);
795 ok(any_accesses
[test_num
].result
== result
,
796 "(test %d): RtlAreAnyAccessesGranted(%08x, %08x) returns %d, expected %d\n",
797 test_num
, any_accesses
[test_num
].GrantedAccess
,
798 any_accesses
[test_num
].DesiredAccess
,
799 result
, any_accesses
[test_num
].result
);
803 static void test_RtlComputeCrc32(void)
807 if (!pRtlComputeCrc32
)
809 win_skip("RtlComputeCrc32 is not available\n");
813 crc
= pRtlComputeCrc32(crc
, (const BYTE
*)src
, LEN
);
814 ok(crc
== 0x40861dc2,"Expected 0x40861dc2, got %8x\n", crc
);
818 typedef struct MY_HANDLE
820 RTL_HANDLE RtlHandle
;
824 static inline void RtlpMakeHandleAllocated(RTL_HANDLE
* Handle
)
826 ULONG_PTR
*AllocatedBit
= (ULONG_PTR
*)(&Handle
->Next
);
827 *AllocatedBit
= *AllocatedBit
| 1;
830 static void test_HandleTables(void)
835 MY_HANDLE
* MyHandle
;
836 RTL_HANDLE_TABLE HandleTable
;
838 if (!pRtlInitializeHandleTable
)
840 win_skip("RtlInitializeHandleTable is not available\n");
844 pRtlInitializeHandleTable(0x3FFF, sizeof(MY_HANDLE
), &HandleTable
);
845 MyHandle
= (MY_HANDLE
*)pRtlAllocateHandle(&HandleTable
, &Index
);
846 ok(MyHandle
!= NULL
, "RtlAllocateHandle failed\n");
847 RtlpMakeHandleAllocated(&MyHandle
->RtlHandle
);
849 result
= pRtlIsValidIndexHandle(&HandleTable
, Index
, (RTL_HANDLE
**)&MyHandle
);
850 ok(result
, "Handle %p wasn't valid\n", MyHandle
);
851 result
= pRtlFreeHandle(&HandleTable
, &MyHandle
->RtlHandle
);
852 ok(result
, "Couldn't free handle %p\n", MyHandle
);
853 status
= pRtlDestroyHandleTable(&HandleTable
);
854 ok(status
== STATUS_SUCCESS
, "RtlDestroyHandleTable failed with error 0x%08x\n", status
);
857 static void test_RtlAllocateAndInitializeSid(void)
860 SID_IDENTIFIER_AUTHORITY sia
= {{ 1, 2, 3, 4, 5, 6 }};
863 if (!pRtlAllocateAndInitializeSid
)
865 win_skip("RtlAllocateAndInitializeSid is not available\n");
869 ret
= pRtlAllocateAndInitializeSid(&sia
, 0, 1, 2, 3, 4, 5, 6, 7, 8, &psid
);
870 ok(!ret
, "RtlAllocateAndInitializeSid error %08x\n", ret
);
871 ret
= pRtlFreeSid(psid
);
872 ok(!ret
, "RtlFreeSid error %08x\n", ret
);
874 /* these tests crash on XP */
877 pRtlAllocateAndInitializeSid(NULL
, 0, 1, 2, 3, 4, 5, 6, 7, 8, &psid
);
878 pRtlAllocateAndInitializeSid(&sia
, 0, 1, 2, 3, 4, 5, 6, 7, 8, NULL
);
881 ret
= pRtlAllocateAndInitializeSid(&sia
, 9, 1, 2, 3, 4, 5, 6, 7, 8, &psid
);
882 ok(ret
== STATUS_INVALID_SID
, "wrong error %08x\n", ret
);
885 static void test_RtlDeleteTimer(void)
889 if (!pRtlDeleteTimer
)
891 win_skip("RtlDeleteTimer is not available\n");
895 ret
= pRtlDeleteTimer(NULL
, NULL
, NULL
);
896 ok(ret
== STATUS_INVALID_PARAMETER_1
||
897 ret
== STATUS_INVALID_PARAMETER
, /* W2K */
898 "expected STATUS_INVALID_PARAMETER_1 or STATUS_INVALID_PARAMETER, got %x\n", ret
);
901 static void test_RtlThreadErrorMode(void)
908 if (!pRtlGetThreadErrorMode
|| !pRtlSetThreadErrorMode
)
910 win_skip("RtlGetThreadErrorMode and/or RtlSetThreadErrorMode not available\n");
914 if (!pIsWow64Process
|| !pIsWow64Process(GetCurrentProcess(), &is_wow64
))
917 oldmode
= pRtlGetThreadErrorMode();
919 status
= pRtlSetThreadErrorMode(0x70, &mode
);
920 ok(status
== STATUS_SUCCESS
||
921 status
== STATUS_WAIT_1
, /* Vista */
922 "RtlSetThreadErrorMode failed with error 0x%08x\n", status
);
924 "RtlSetThreadErrorMode returned mode 0x%x, expected 0x%x\n",
926 ok(pRtlGetThreadErrorMode() == 0x70,
927 "RtlGetThreadErrorMode returned 0x%x, expected 0x%x\n", mode
, 0x70);
930 ok(NtCurrentTeb()->HardErrorDisabled
== 0x70,
931 "The TEB contains 0x%x, expected 0x%x\n",
932 NtCurrentTeb()->HardErrorDisabled
, 0x70);
935 status
= pRtlSetThreadErrorMode(0, &mode
);
936 ok(status
== STATUS_SUCCESS
||
937 status
== STATUS_WAIT_1
, /* Vista */
938 "RtlSetThreadErrorMode failed with error 0x%08x\n", status
);
940 "RtlSetThreadErrorMode returned mode 0x%x, expected 0x%x\n",
942 ok(pRtlGetThreadErrorMode() == 0,
943 "RtlGetThreadErrorMode returned 0x%x, expected 0x%x\n", mode
, 0);
946 ok(NtCurrentTeb()->HardErrorDisabled
== 0,
947 "The TEB contains 0x%x, expected 0x%x\n",
948 NtCurrentTeb()->HardErrorDisabled
, 0);
951 for (mode
= 1; mode
; mode
<<= 1)
953 status
= pRtlSetThreadErrorMode(mode
, NULL
);
955 ok(status
== STATUS_SUCCESS
||
956 status
== STATUS_WAIT_1
, /* Vista */
957 "RtlSetThreadErrorMode(%x,NULL) failed with error 0x%08x\n",
960 ok(status
== STATUS_INVALID_PARAMETER_1
,
961 "RtlSetThreadErrorMode(%x,NULL) returns 0x%08x, "
962 "expected STATUS_INVALID_PARAMETER_1\n",
966 pRtlSetThreadErrorMode(oldmode
, NULL
);
969 static void test_LdrProcessRelocationBlock(void)
971 IMAGE_BASE_RELOCATION
*ret
;
976 if(!pLdrProcessRelocationBlock
) {
977 win_skip("LdrProcessRelocationBlock not available\n");
982 reloc
= IMAGE_REL_BASED_HIGHLOW
<<12;
983 ret
= pLdrProcessRelocationBlock(&addr32
, 1, &reloc
, 0x500050);
984 ok((USHORT
*)ret
== &reloc
+1, "ret = %p, expected %p\n", ret
, &reloc
+1);
985 ok(addr32
== 0x550055, "addr32 = %x, expected 0x550055\n", addr32
);
988 reloc
= IMAGE_REL_BASED_HIGH
<<12;
989 ret
= pLdrProcessRelocationBlock(&addr16
, 1, &reloc
, 0x500060);
990 ok((USHORT
*)ret
== &reloc
+1, "ret = %p, expected %p\n", ret
, &reloc
+1);
991 ok(addr16
== 0x555, "addr16 = %x, expected 0x555\n", addr16
);
994 reloc
= IMAGE_REL_BASED_LOW
<<12;
995 ret
= pLdrProcessRelocationBlock(&addr16
, 1, &reloc
, 0x500060);
996 ok((USHORT
*)ret
== &reloc
+1, "ret = %p, expected %p\n", ret
, &reloc
+1);
997 ok(addr16
== 0x565, "addr16 = %x, expected 0x565\n", addr16
);
1000 static void test_RtlIpv4AddressToString(void)
1007 if (!pRtlIpv4AddressToStringA
)
1009 win_skip("RtlIpv4AddressToStringA not available\n");
1013 ip
.S_un
.S_un_b
.s_b1
= 1;
1014 ip
.S_un
.S_un_b
.s_b2
= 2;
1015 ip
.S_un
.S_un_b
.s_b3
= 3;
1016 ip
.S_un
.S_un_b
.s_b4
= 4;
1018 memset(buffer
, '#', sizeof(buffer
) - 1);
1019 buffer
[sizeof(buffer
) -1] = 0;
1020 res
= pRtlIpv4AddressToStringA(&ip
, buffer
);
1021 len
= strlen(buffer
);
1022 ok(res
== (buffer
+ len
), "got %p with '%s' (expected %p)\n", res
, buffer
, buffer
+ len
);
1024 res
= pRtlIpv4AddressToStringA(&ip
, NULL
);
1025 ok( (res
== (char *)~0) ||
1026 broken(res
== (char *)len
), /* XP and w2003 */
1027 "got %p (expected ~0)\n", res
);
1030 /* this crashes in windows */
1031 memset(buffer
, '#', sizeof(buffer
) - 1);
1032 buffer
[sizeof(buffer
) -1] = 0;
1033 res
= pRtlIpv4AddressToStringA(NULL
, buffer
);
1034 trace("got %p with '%s'\n", res
, buffer
);
1038 /* this crashes in windows */
1039 res
= pRtlIpv4AddressToStringA(NULL
, NULL
);
1040 trace("got %p\n", res
);
1044 static void test_RtlIpv4AddressToStringEx(void)
1046 CHAR ip_1234
[] = "1.2.3.4";
1047 CHAR ip_1234_80
[] = "1.2.3.4:80";
1056 if (!pRtlIpv4AddressToStringExA
)
1058 win_skip("RtlIpv4AddressToStringExA not available\n");
1062 ip
.S_un
.S_un_b
.s_b1
= 1;
1063 ip
.S_un
.S_un_b
.s_b2
= 2;
1064 ip
.S_un
.S_un_b
.s_b3
= 3;
1065 ip
.S_un
.S_un_b
.s_b4
= 4;
1068 expect
= ip_1234_80
;
1070 size
= sizeof(buffer
);
1071 memset(buffer
, '#', sizeof(buffer
) - 1);
1072 buffer
[sizeof(buffer
) -1] = 0;
1073 res
= pRtlIpv4AddressToStringExA(&ip
, port
, buffer
, &size
);
1074 used
= strlen(buffer
);
1075 ok( (res
== STATUS_SUCCESS
) &&
1076 (size
== strlen(expect
) + 1) && !strcmp(buffer
, expect
),
1077 "got 0x%x and size %d with '%s'\n", res
, size
, buffer
);
1080 memset(buffer
, '#', sizeof(buffer
) - 1);
1081 buffer
[sizeof(buffer
) -1] = 0;
1082 res
= pRtlIpv4AddressToStringExA(&ip
, port
, buffer
, &size
);
1083 ok( (res
== STATUS_SUCCESS
) &&
1084 (size
== strlen(expect
) + 1) && !strcmp(buffer
, expect
),
1085 "got 0x%x and size %d with '%s'\n", res
, size
, buffer
);
1088 memset(buffer
, '#', sizeof(buffer
) - 1);
1089 buffer
[sizeof(buffer
) -1] = 0;
1090 res
= pRtlIpv4AddressToStringExA(&ip
, port
, buffer
, &size
);
1091 ok( (res
== STATUS_INVALID_PARAMETER
) && (size
== used
+ 1),
1092 "got 0x%x and %d with '%s' (expected STATUS_INVALID_PARAMETER and %d)\n",
1093 res
, size
, buffer
, used
+ 1);
1096 memset(buffer
, '#', sizeof(buffer
) - 1);
1097 buffer
[sizeof(buffer
) -1] = 0;
1098 res
= pRtlIpv4AddressToStringExA(&ip
, port
, buffer
, &size
);
1099 ok( (res
== STATUS_INVALID_PARAMETER
) && (size
== used
+ 1),
1100 "got 0x%x and %d with '%s' (expected STATUS_INVALID_PARAMETER and %d)\n",
1101 res
, size
, buffer
, used
+ 1);
1104 /* to get only the ip, use 0 as port */
1108 size
= sizeof(buffer
);
1109 memset(buffer
, '#', sizeof(buffer
) - 1);
1110 buffer
[sizeof(buffer
) -1] = 0;
1111 res
= pRtlIpv4AddressToStringExA(&ip
, port
, buffer
, &size
);
1112 used
= strlen(buffer
);
1113 ok( (res
== STATUS_SUCCESS
) &&
1114 (size
== strlen(expect
) + 1) && !strcmp(buffer
, expect
),
1115 "got 0x%x and size %d with '%s'\n", res
, size
, buffer
);
1118 memset(buffer
, '#', sizeof(buffer
) - 1);
1119 buffer
[sizeof(buffer
) -1] = 0;
1120 res
= pRtlIpv4AddressToStringExA(&ip
, port
, buffer
, &size
);
1121 ok( (res
== STATUS_SUCCESS
) &&
1122 (size
== strlen(expect
) + 1) && !strcmp(buffer
, expect
),
1123 "got 0x%x and size %d with '%s'\n", res
, size
, buffer
);
1126 memset(buffer
, '#', sizeof(buffer
) - 1);
1127 buffer
[sizeof(buffer
) -1] = 0;
1128 res
= pRtlIpv4AddressToStringExA(&ip
, port
, buffer
, &size
);
1129 ok( (res
== STATUS_INVALID_PARAMETER
) && (size
== used
+ 1),
1130 "got 0x%x and %d with '%s' (expected STATUS_INVALID_PARAMETER and %d)\n",
1131 res
, size
, buffer
, used
+ 1);
1134 memset(buffer
, '#', sizeof(buffer
) - 1);
1135 buffer
[sizeof(buffer
) -1] = 0;
1136 res
= pRtlIpv4AddressToStringExA(&ip
, port
, buffer
, &size
);
1137 ok( (res
== STATUS_INVALID_PARAMETER
) && (size
== used
+ 1),
1138 "got 0x%x and %d with '%s' (expected STATUS_INVALID_PARAMETER and %d)\n",
1139 res
, size
, buffer
, used
+ 1);
1142 /* parameters are checked */
1143 memset(buffer
, '#', sizeof(buffer
) - 1);
1144 buffer
[sizeof(buffer
) -1] = 0;
1145 res
= pRtlIpv4AddressToStringExA(&ip
, 0, buffer
, NULL
);
1146 ok(res
== STATUS_INVALID_PARAMETER
,
1147 "got 0x%x with '%s' (expected STATUS_INVALID_PARAMETER)\n", res
, buffer
);
1149 size
= sizeof(buffer
);
1150 res
= pRtlIpv4AddressToStringExA(&ip
, 0, NULL
, &size
);
1151 ok( res
== STATUS_INVALID_PARAMETER
,
1152 "got 0x%x and size %d (expected STATUS_INVALID_PARAMETER)\n", res
, size
);
1154 size
= sizeof(buffer
);
1155 memset(buffer
, '#', sizeof(buffer
) - 1);
1156 buffer
[sizeof(buffer
) -1] = 0;
1157 res
= pRtlIpv4AddressToStringExA(NULL
, 0, buffer
, &size
);
1158 ok( res
== STATUS_INVALID_PARAMETER
,
1159 "got 0x%x and size %d with '%s' (expected STATUS_INVALID_PARAMETER)\n",
1167 int terminator_offset
;
1169 enum { normal_4
, strict_diff_4
= 1, ex_fail_4
= 2 } flags
;
1170 NTSTATUS res_strict
;
1171 int terminator_offset_strict
;
1175 { "", STATUS_INVALID_PARAMETER
, 0, { -1 } },
1176 { " ", STATUS_INVALID_PARAMETER
, 0, { -1 } },
1177 { "1.1.1.1", STATUS_SUCCESS
, 7, { 1, 1, 1, 1 } },
1178 { "0.0.0.0", STATUS_SUCCESS
, 7, { 0, 0, 0, 0 } },
1179 { "255.255.255.255", STATUS_SUCCESS
, 15, { 255, 255, 255, 255 } },
1180 { "255.255.255.255:123", STATUS_SUCCESS
, 15, { 255, 255, 255, 255 } },
1181 { "255.255.255.256", STATUS_INVALID_PARAMETER
, 15, { -1 } },
1182 { "255.255.255.4294967295", STATUS_INVALID_PARAMETER
, 22, { -1 } },
1183 { "255.255.255.4294967296", STATUS_INVALID_PARAMETER
, 21, { -1 } },
1184 { "255.255.255.4294967297", STATUS_INVALID_PARAMETER
, 21, { -1 } },
1185 { "a", STATUS_INVALID_PARAMETER
, 0, { -1 } },
1186 { "1.1.1.0xaA", STATUS_SUCCESS
, 10, { 1, 1, 1, 170 }, strict_diff_4
,
1187 STATUS_INVALID_PARAMETER
, 8, { -1 } },
1188 { "1.1.1.0XaA", STATUS_SUCCESS
, 10, { 1, 1, 1, 170 }, strict_diff_4
,
1189 STATUS_INVALID_PARAMETER
, 8, { -1 } },
1190 { "1.1.1.0x", STATUS_INVALID_PARAMETER
, 8, { -1 } },
1191 { "1.1.1.0xff", STATUS_SUCCESS
, 10, { 1, 1, 1, 255 }, strict_diff_4
,
1192 STATUS_INVALID_PARAMETER
, 8, { -1 } },
1193 { "1.1.1.0x100", STATUS_INVALID_PARAMETER
, 11, { -1 }, strict_diff_4
,
1194 STATUS_INVALID_PARAMETER
, 8, { -1 } },
1195 { "1.1.1.0xffffffff", STATUS_INVALID_PARAMETER
, 16, { -1 }, strict_diff_4
,
1196 STATUS_INVALID_PARAMETER
, 8, { -1 } },
1197 { "1.1.1.0x100000000", STATUS_INVALID_PARAMETER
, 16, { -1, 0, 0, 0 }, strict_diff_4
,
1198 STATUS_INVALID_PARAMETER
, 8, { -1 } },
1199 { "1.1.1.010", STATUS_SUCCESS
, 9, { 1, 1, 1, 8 }, strict_diff_4
,
1200 STATUS_INVALID_PARAMETER
, 7, { -1 } },
1201 { "1.1.1.00", STATUS_SUCCESS
, 8, { 1, 1, 1, 0 }, strict_diff_4
,
1202 STATUS_INVALID_PARAMETER
, 7, { -1 } },
1203 { "1.1.1.007", STATUS_SUCCESS
, 9, { 1, 1, 1, 7 }, strict_diff_4
,
1204 STATUS_INVALID_PARAMETER
, 7, { -1 } },
1205 { "1.1.1.08", STATUS_INVALID_PARAMETER
, 7, { -1 } },
1206 { "1.1.1.008", STATUS_SUCCESS
, 8, { 1, 1, 1, 0 }, strict_diff_4
| ex_fail_4
,
1207 STATUS_INVALID_PARAMETER
, 7, { -1 } },
1208 { "1.1.1.0a", STATUS_SUCCESS
, 7, { 1, 1, 1, 0 }, ex_fail_4
},
1209 { "1.1.1.0o10", STATUS_SUCCESS
, 7, { 1, 1, 1, 0 }, ex_fail_4
},
1210 { "1.1.1.0b10", STATUS_SUCCESS
, 7, { 1, 1, 1, 0 }, ex_fail_4
},
1211 { "1.1.1.-2", STATUS_INVALID_PARAMETER
, 6, { -1 } },
1212 { "1", STATUS_SUCCESS
, 1, { 0, 0, 0, 1 }, strict_diff_4
,
1213 STATUS_INVALID_PARAMETER
, 1, { -1 } },
1214 { "-1", STATUS_INVALID_PARAMETER
, 0, { -1 } },
1215 { "1.2", STATUS_SUCCESS
, 3, { 1, 0, 0, 2 }, strict_diff_4
,
1216 STATUS_INVALID_PARAMETER
, 3, { -1 } },
1217 { "1000.2000", STATUS_INVALID_PARAMETER
, 9, { -1 } },
1218 { "1.2.", STATUS_INVALID_PARAMETER
, 4, { -1 } },
1219 { "1..2", STATUS_INVALID_PARAMETER
, 3, { -1 } },
1220 { "1...2", STATUS_INVALID_PARAMETER
, 3, { -1 } },
1221 { "1.2.3", STATUS_SUCCESS
, 5, { 1, 2, 0, 3 }, strict_diff_4
,
1222 STATUS_INVALID_PARAMETER
, 5, { -1 } },
1223 { "1.2.3.", STATUS_INVALID_PARAMETER
, 6, { -1 } },
1224 { "203569230", STATUS_SUCCESS
, 9, { 12, 34, 56, 78 }, strict_diff_4
,
1225 STATUS_INVALID_PARAMETER
, 9, { -1 } },
1226 { "1.223756", STATUS_SUCCESS
, 8, { 1, 3, 106, 12 }, strict_diff_4
,
1227 STATUS_INVALID_PARAMETER
, 8, { -1 } },
1228 { "3.4.756", STATUS_SUCCESS
, 7, { 3, 4, 2, 244 }, strict_diff_4
,
1229 STATUS_INVALID_PARAMETER
, 7, { -1 } },
1230 { "756.3.4", STATUS_INVALID_PARAMETER
, 7, { -1 } },
1231 { "3.756.4", STATUS_INVALID_PARAMETER
, 7, { -1 } },
1232 { "3.4.756.1", STATUS_INVALID_PARAMETER
, 9, { -1 } },
1233 { "3.4.65536", STATUS_INVALID_PARAMETER
, 9, { -1 } },
1234 { "3.4.5.6.7", STATUS_INVALID_PARAMETER
, 7, { -1 } },
1235 { "3.4.5.+6", STATUS_INVALID_PARAMETER
, 6, { -1 } },
1236 { " 3.4.5.6", STATUS_INVALID_PARAMETER
, 0, { -1 } },
1237 { "\t3.4.5.6", STATUS_INVALID_PARAMETER
, 0, { -1 } },
1238 { "3.4.5.6 ", STATUS_SUCCESS
, 7, { 3, 4, 5, 6 }, ex_fail_4
},
1239 { "3. 4.5.6", STATUS_INVALID_PARAMETER
, 2, { -1 } },
1240 { ".", STATUS_INVALID_PARAMETER
, 1, { -1 } },
1241 { "..", STATUS_INVALID_PARAMETER
, 1, { -1 } },
1242 { "1.", STATUS_INVALID_PARAMETER
, 2, { -1 } },
1243 { "1..", STATUS_INVALID_PARAMETER
, 3, { -1 } },
1244 { ".1", STATUS_INVALID_PARAMETER
, 1, { -1 } },
1245 { ".1.", STATUS_INVALID_PARAMETER
, 1, { -1 } },
1246 { ".1.2.3", STATUS_INVALID_PARAMETER
, 1, { -1 } },
1247 { ".1.2.3.4", STATUS_INVALID_PARAMETER
, 1, { -1 } },
1248 { "0.1.2.3", STATUS_SUCCESS
, 7, { 0, 1, 2, 3 } },
1249 { "0.1.2.3.", STATUS_INVALID_PARAMETER
, 7, { -1 } },
1250 { "[0.1.2.3]", STATUS_INVALID_PARAMETER
, 0, { -1 } },
1251 { "0x00010203", STATUS_SUCCESS
, 10, { 0, 1, 2, 3 }, strict_diff_4
,
1252 STATUS_INVALID_PARAMETER
, 2, { -1 } },
1253 { "0X00010203", STATUS_SUCCESS
, 10, { 0, 1, 2, 3 }, strict_diff_4
,
1254 STATUS_INVALID_PARAMETER
, 2, { -1 } },
1255 { "0x1234", STATUS_SUCCESS
, 6, { 0, 0, 18, 52 }, strict_diff_4
,
1256 STATUS_INVALID_PARAMETER
, 2, { -1 } },
1257 { "0x123456789", STATUS_SUCCESS
, 11, { 35, 69, 103, 137 }, strict_diff_4
,
1258 STATUS_INVALID_PARAMETER
, 2, { -1 } },
1259 { "0x00010Q03", STATUS_SUCCESS
, 7, { 0, 0, 0, 16 }, strict_diff_4
| ex_fail_4
,
1260 STATUS_INVALID_PARAMETER
, 2, { -1 } },
1261 { "x00010203", STATUS_INVALID_PARAMETER
, 0, { -1 } },
1262 { "1234BEEF", STATUS_SUCCESS
, 4, { 0, 0, 4, 210 }, strict_diff_4
| ex_fail_4
,
1263 STATUS_INVALID_PARAMETER
, 4, { -1 } },
1264 { "017700000001", STATUS_SUCCESS
, 12, { 127, 0, 0, 1 }, strict_diff_4
,
1265 STATUS_INVALID_PARAMETER
, 1, { -1 } },
1266 { "0777", STATUS_SUCCESS
, 4, { 0, 0, 1, 255 }, strict_diff_4
,
1267 STATUS_INVALID_PARAMETER
, 1, { -1 } },
1268 { "::1", STATUS_INVALID_PARAMETER
, 0, { -1 } },
1269 { ":1", STATUS_INVALID_PARAMETER
, 0, { -1 } },
1272 static void init_ip4(IN_ADDR
* addr
, const int src
[4])
1274 if (!src
|| src
[0] == -1)
1276 addr
->S_un
.S_addr
= 0xabababab;
1280 addr
->S_un
.S_un_b
.s_b1
= src
[0];
1281 addr
->S_un
.S_un_b
.s_b2
= src
[1];
1282 addr
->S_un
.S_un_b
.s_b3
= src
[2];
1283 addr
->S_un
.S_un_b
.s_b4
= src
[3];
1287 static void test_RtlIpv4StringToAddress(void)
1290 IN_ADDR ip
, expected_ip
;
1295 if (!pRtlIpv4StringToAddressA
)
1297 skip("RtlIpv4StringToAddress not available\n");
1303 /* leaving either parameter NULL crashes on Windows */
1304 res
= pRtlIpv4StringToAddressA(NULL
, FALSE
, &terminator
, &ip
);
1305 res
= pRtlIpv4StringToAddressA("1.1.1.1", FALSE
, NULL
, &ip
);
1306 res
= pRtlIpv4StringToAddressA("1.1.1.1", FALSE
, &terminator
, NULL
);
1307 /* same for the wide char version */
1309 res = pRtlIpv4StringToAddressW(NULL, FALSE, &terminatorW, &ip);
1310 res = pRtlIpv4StringToAddressW(L"1.1.1.1", FALSE, NULL, &ip);
1311 res = pRtlIpv4StringToAddressW(L"1.1.1.1", FALSE, &terminatorW, NULL);
1315 for (i
= 0; i
< ARRAY_SIZE(ipv4_tests
); i
++)
1318 terminator
= &dummy
;
1319 ip
.S_un
.S_addr
= 0xabababab;
1320 res
= pRtlIpv4StringToAddressA(ipv4_tests
[i
].address
, FALSE
, &terminator
, &ip
);
1321 ok(res
== ipv4_tests
[i
].res
,
1322 "[%s] res = 0x%08x, expected 0x%08x\n",
1323 ipv4_tests
[i
].address
, res
, ipv4_tests
[i
].res
);
1324 ok(terminator
== ipv4_tests
[i
].address
+ ipv4_tests
[i
].terminator_offset
,
1325 "[%s] terminator = %p, expected %p\n",
1326 ipv4_tests
[i
].address
, terminator
, ipv4_tests
[i
].address
+ ipv4_tests
[i
].terminator_offset
);
1328 init_ip4(&expected_ip
, ipv4_tests
[i
].ip
);
1329 ok(ip
.S_un
.S_addr
== expected_ip
.S_un
.S_addr
,
1330 "[%s] ip = %08x, expected %08x\n",
1331 ipv4_tests
[i
].address
, ip
.S_un
.S_addr
, expected_ip
.S_un
.S_addr
);
1333 if (!(ipv4_tests
[i
].flags
& strict_diff_4
))
1335 ipv4_tests
[i
].res_strict
= ipv4_tests
[i
].res
;
1336 ipv4_tests
[i
].terminator_offset_strict
= ipv4_tests
[i
].terminator_offset
;
1337 ipv4_tests
[i
].ip_strict
[0] = ipv4_tests
[i
].ip
[0];
1338 ipv4_tests
[i
].ip_strict
[1] = ipv4_tests
[i
].ip
[1];
1339 ipv4_tests
[i
].ip_strict
[2] = ipv4_tests
[i
].ip
[2];
1340 ipv4_tests
[i
].ip_strict
[3] = ipv4_tests
[i
].ip
[3];
1343 terminator
= &dummy
;
1344 ip
.S_un
.S_addr
= 0xabababab;
1345 res
= pRtlIpv4StringToAddressA(ipv4_tests
[i
].address
, TRUE
, &terminator
, &ip
);
1346 ok(res
== ipv4_tests
[i
].res_strict
,
1347 "[%s] res = 0x%08x, expected 0x%08x\n",
1348 ipv4_tests
[i
].address
, res
, ipv4_tests
[i
].res_strict
);
1349 ok(terminator
== ipv4_tests
[i
].address
+ ipv4_tests
[i
].terminator_offset_strict
,
1350 "[%s] terminator = %p, expected %p\n",
1351 ipv4_tests
[i
].address
, terminator
, ipv4_tests
[i
].address
+ ipv4_tests
[i
].terminator_offset_strict
);
1353 init_ip4(&expected_ip
, ipv4_tests
[i
].ip_strict
);
1354 ok(ip
.S_un
.S_addr
== expected_ip
.S_un
.S_addr
,
1355 "[%s] ip = %08x, expected %08x\n",
1356 ipv4_tests
[i
].address
, ip
.S_un
.S_addr
, expected_ip
.S_un
.S_addr
);
1360 static void test_RtlIpv4StringToAddressEx(void)
1363 IN_ADDR ip
, expected_ip
;
1373 { "", STATUS_INVALID_PARAMETER
, { -1 }, 0xdead },
1374 { " ", STATUS_INVALID_PARAMETER
, { -1 }, 0xdead },
1375 { "1.1.1.1:", STATUS_INVALID_PARAMETER
, { 1, 1, 1, 1 }, 0xdead },
1376 { "1.1.1.1+", STATUS_INVALID_PARAMETER
, { 1, 1, 1, 1 }, 0xdead },
1377 { "1.1.1.1:1", STATUS_SUCCESS
, { 1, 1, 1, 1 }, 0x100 },
1378 { "256.1.1.1:1", STATUS_INVALID_PARAMETER
, { -1 }, 0xdead },
1379 { "-1.1.1.1:1", STATUS_INVALID_PARAMETER
, { -1 }, 0xdead },
1380 { "0.0.0.0:0", STATUS_INVALID_PARAMETER
, { 0, 0, 0, 0 }, 0xdead },
1381 { "0.0.0.0:1", STATUS_SUCCESS
, { 0, 0, 0, 0 }, 0x100 },
1382 { "1.2.3.4:65535", STATUS_SUCCESS
, { 1, 2, 3, 4 }, 65535 },
1383 { "1.2.3.4:65536", STATUS_INVALID_PARAMETER
, { 1, 2, 3, 4 }, 0xdead },
1384 { "1.2.3.4:0xffff", STATUS_SUCCESS
, { 1, 2, 3, 4 }, 65535 },
1385 { "1.2.3.4:0XfFfF", STATUS_SUCCESS
, { 1, 2, 3, 4 }, 65535 },
1386 { "1.2.3.4:011064", STATUS_SUCCESS
, { 1, 2, 3, 4 }, 0x3412 },
1387 { "1.2.3.4:1234a", STATUS_INVALID_PARAMETER
, { 1, 2, 3, 4 }, 0xdead },
1388 { "1.2.3.4:1234+", STATUS_INVALID_PARAMETER
, { 1, 2, 3, 4 }, 0xdead },
1389 { "1.2.3.4: 1234", STATUS_INVALID_PARAMETER
, { 1, 2, 3, 4 }, 0xdead },
1390 { "1.2.3.4:\t1234", STATUS_INVALID_PARAMETER
, { 1, 2, 3, 4 }, 0xdead },
1395 if (!pRtlIpv4StringToAddressExA
)
1397 skip("RtlIpv4StringToAddressEx not available\n");
1401 /* do not crash, and do not touch the ip / port. */
1402 ip
.S_un
.S_addr
= 0xabababab;
1404 res
= pRtlIpv4StringToAddressExA(NULL
, FALSE
, &ip
, &port
);
1405 ok(res
== STATUS_INVALID_PARAMETER
, "[null address] res = 0x%08x, expected 0x%08x\n",
1406 res
, STATUS_INVALID_PARAMETER
);
1407 ok(ip
.S_un
.S_addr
== 0xabababab, "RtlIpv4StringToAddressExA should not touch the ip!, ip == %x\n", ip
.S_un
.S_addr
);
1408 ok(port
== 0xdead, "RtlIpv4StringToAddressExA should not touch the port!, port == %x\n", port
);
1411 res
= pRtlIpv4StringToAddressExA("1.1.1.1", FALSE
, NULL
, &port
);
1412 ok(res
== STATUS_INVALID_PARAMETER
, "[null ip] res = 0x%08x, expected 0x%08x\n",
1413 res
, STATUS_INVALID_PARAMETER
);
1414 ok(port
== 0xdead, "RtlIpv4StringToAddressExA should not touch the port!, port == %x\n", port
);
1416 ip
.S_un
.S_addr
= 0xabababab;
1418 res
= pRtlIpv4StringToAddressExA("1.1.1.1", FALSE
, &ip
, NULL
);
1419 ok(res
== STATUS_INVALID_PARAMETER
, "[null port] res = 0x%08x, expected 0x%08x\n",
1420 res
, STATUS_INVALID_PARAMETER
);
1421 ok(ip
.S_un
.S_addr
== 0xabababab, "RtlIpv4StringToAddressExA should not touch the ip!, ip == %x\n", ip
.S_un
.S_addr
);
1422 ok(port
== 0xdead, "RtlIpv4StringToAddressExA should not touch the port!, port == %x\n", port
);
1424 /* first we run the non-ex testcases on the ex function */
1425 for (i
= 0; i
< ARRAY_SIZE(ipv4_tests
); i
++)
1427 NTSTATUS expect_res
= (ipv4_tests
[i
].flags
& ex_fail_4
) ? STATUS_INVALID_PARAMETER
: ipv4_tests
[i
].res
;
1431 ip
.S_un
.S_addr
= 0xabababab;
1432 res
= pRtlIpv4StringToAddressExA(ipv4_tests
[i
].address
, FALSE
, &ip
, &port
);
1433 ok(res
== expect_res
, "[%s] res = 0x%08x, expected 0x%08x\n",
1434 ipv4_tests
[i
].address
, res
, expect_res
);
1436 init_ip4(&expected_ip
, ipv4_tests
[i
].ip
);
1437 ok(ip
.S_un
.S_addr
== expected_ip
.S_un
.S_addr
, "[%s] ip = %08x, expected %08x\n",
1438 ipv4_tests
[i
].address
, ip
.S_un
.S_addr
, expected_ip
.S_un
.S_addr
);
1440 if (!(ipv4_tests
[i
].flags
& strict_diff_4
))
1442 ipv4_tests
[i
].res_strict
= ipv4_tests
[i
].res
;
1443 ipv4_tests
[i
].terminator_offset_strict
= ipv4_tests
[i
].terminator_offset
;
1444 ipv4_tests
[i
].ip_strict
[0] = ipv4_tests
[i
].ip
[0];
1445 ipv4_tests
[i
].ip_strict
[1] = ipv4_tests
[i
].ip
[1];
1446 ipv4_tests
[i
].ip_strict
[2] = ipv4_tests
[i
].ip
[2];
1447 ipv4_tests
[i
].ip_strict
[3] = ipv4_tests
[i
].ip
[3];
1450 expect_res
= (ipv4_tests
[i
].flags
& ex_fail_4
) ? STATUS_INVALID_PARAMETER
: ipv4_tests
[i
].res_strict
;
1452 ip
.S_un
.S_addr
= 0xabababab;
1453 res
= pRtlIpv4StringToAddressExA(ipv4_tests
[i
].address
, TRUE
, &ip
, &port
);
1454 ok(res
== expect_res
, "[%s] res = 0x%08x, expected 0x%08x\n",
1455 ipv4_tests
[i
].address
, res
, expect_res
);
1457 init_ip4(&expected_ip
, ipv4_tests
[i
].ip_strict
);
1458 ok(ip
.S_un
.S_addr
== expected_ip
.S_un
.S_addr
, "[%s] ip = %08x, expected %08x\n",
1459 ipv4_tests
[i
].address
, ip
.S_un
.S_addr
, expected_ip
.S_un
.S_addr
);
1463 for (i
= 0; i
< ARRAY_SIZE(ipv4_ex_tests
); i
++)
1465 /* Strict is only relevant for the ip address, so make sure that it does not influence the port */
1466 for (strict
= 0; strict
< 2; strict
++)
1468 ip
.S_un
.S_addr
= 0xabababab;
1470 res
= pRtlIpv4StringToAddressExA(ipv4_ex_tests
[i
].address
, strict
, &ip
, &port
);
1471 ok(res
== ipv4_ex_tests
[i
].res
, "[%s] res = 0x%08x, expected 0x%08x\n",
1472 ipv4_ex_tests
[i
].address
, res
, ipv4_ex_tests
[i
].res
);
1474 init_ip4(&expected_ip
, ipv4_ex_tests
[i
].ip
);
1475 ok(ip
.S_un
.S_addr
== expected_ip
.S_un
.S_addr
, "[%s] ip = %08x, expected %08x\n",
1476 ipv4_ex_tests
[i
].address
, ip
.S_un
.S_addr
, expected_ip
.S_un
.S_addr
);
1477 ok(port
== ipv4_ex_tests
[i
].port
, "[%s] port = %u, expected %u\n",
1478 ipv4_ex_tests
[i
].address
, port
, ipv4_ex_tests
[i
].port
);
1483 /* ipv6 addresses based on the set from https://github.com/beaugunderson/javascript-ipv6/tree/master/test/data */
1488 int terminator_offset
;
1490 /* win_broken: XP and Vista do not handle this correctly
1491 ex_fail: Ex function does need the string to be terminated, non-Ex does not.
1492 ex_skip: test doesn't make sense for Ex (f.e. it's invalid for non-Ex but valid for Ex) */
1493 enum { normal_6
, win_broken_6
= 1, ex_fail_6
= 2, ex_skip_6
= 4 } flags
;
1496 { "0000:0000:0000:0000:0000:0000:0000:0000", STATUS_SUCCESS
, 39,
1497 { 0, 0, 0, 0, 0, 0, 0, 0 } },
1498 { "0000:0000:0000:0000:0000:0000:0000:0001", STATUS_SUCCESS
, 39,
1499 { 0, 0, 0, 0, 0, 0, 0, 0x100 } },
1500 { "0:0:0:0:0:0:0:0", STATUS_SUCCESS
, 15,
1501 { 0, 0, 0, 0, 0, 0, 0, 0 } },
1502 { "0:0:0:0:0:0:0:1", STATUS_SUCCESS
, 15,
1503 { 0, 0, 0, 0, 0, 0, 0, 0x100 } },
1504 { "0:0:0:0:0:0:0::", STATUS_SUCCESS
, 15,
1505 { 0, 0, 0, 0, 0, 0, 0, 0 }, win_broken_6
},
1506 { "0:0:0:0:0:0:13.1.68.3", STATUS_SUCCESS
, 21,
1507 { 0, 0, 0, 0, 0, 0, 0x10d, 0x344 } },
1508 { "0:0:0:0:0:0::", STATUS_SUCCESS
, 13,
1509 { 0, 0, 0, 0, 0, 0, 0, 0 } },
1510 { "0:0:0:0:0::", STATUS_SUCCESS
, 11,
1511 { 0, 0, 0, 0, 0, 0, 0, 0 } },
1512 { "0:0:0:0:0:FFFF:129.144.52.38", STATUS_SUCCESS
, 28,
1513 { 0, 0, 0, 0, 0, 0xffff, 0x9081, 0x2634 } },
1514 { "0::", STATUS_SUCCESS
, 3,
1515 { 0, 0, 0, 0, 0, 0, 0, 0 } },
1516 { "0:1:2:3:4:5:6:7", STATUS_SUCCESS
, 15,
1517 { 0, 0x100, 0x200, 0x300, 0x400, 0x500, 0x600, 0x700 } },
1518 { "1080:0:0:0:8:800:200c:417a", STATUS_SUCCESS
, 26,
1519 { 0x8010, 0, 0, 0, 0x800, 0x8, 0x0c20, 0x7a41 } },
1520 { "0:a:b:c:d:e:f::", STATUS_SUCCESS
, 15,
1521 { 0, 0xa00, 0xb00, 0xc00, 0xd00, 0xe00, 0xf00, 0 }, win_broken_6
},
1522 { "1111:2222:3333:4444:5555:6666:123.123.123.123", STATUS_SUCCESS
, 45,
1523 { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7b7b, 0x7b7b } },
1524 { "1111:2222:3333:4444:5555:6666:7777:8888", STATUS_SUCCESS
, 39,
1525 { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0x8888 } },
1526 { "1111:2222:3333:4444:0x5555:6666:7777:8888", STATUS_INVALID_PARAMETER
, 21,
1527 { 0x1111, 0x2222, 0x3333, 0x4444, 0xabab, 0xabab, 0xabab, 0xabab } },
1528 { "1111:2222:3333:4444:x555:6666:7777:8888", STATUS_INVALID_PARAMETER
, 20,
1529 { 0x1111, 0x2222, 0x3333, 0x4444, 0xabab, 0xabab, 0xabab, 0xabab } },
1530 { "1111:2222:3333:4444:0r5555:6666:7777:8888", STATUS_INVALID_PARAMETER
, 21,
1531 { 0x1111, 0x2222, 0x3333, 0x4444, 0xabab, 0xabab, 0xabab, 0xabab } },
1532 { "1111:2222:3333:4444:r5555:6666:7777:8888", STATUS_INVALID_PARAMETER
, 20,
1533 { 0x1111, 0x2222, 0x3333, 0x4444, 0xabab, 0xabab, 0xabab, 0xabab } },
1534 { "1111:2222:3333:4444:5555:6666:7777::", STATUS_SUCCESS
, 36,
1535 { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0 }, win_broken_6
},
1536 { "1111:2222:3333:4444:5555:6666::", STATUS_SUCCESS
, 31,
1537 { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0, 0 } },
1538 { "1111:2222:3333:4444:5555:6666::8888", STATUS_SUCCESS
, 35,
1539 { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0, 0x8888 } },
1540 { "1111:2222:3333:4444:5555:6666::7777:8888", STATUS_SUCCESS
, 35,
1541 { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0, 0x7777 }, ex_fail_6
},
1542 { "1111:2222:3333:4444:5555::", STATUS_SUCCESS
, 26,
1543 { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0, 0, 0 } },
1544 { "1111:2222:3333:4444:5555::123.123.123.123", STATUS_SUCCESS
, 41,
1545 { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0, 0x7b7b, 0x7b7b } },
1546 { "1111:2222:3333:4444:5555::0x1.123.123.123", STATUS_SUCCESS
, 27,
1547 { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0, 0, 0x100 }, ex_fail_6
},
1548 { "1111:2222:3333:4444:5555::0x88", STATUS_SUCCESS
, 27,
1549 { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0, 0, 0x8800 }, ex_fail_6
},
1550 { "1111:2222:3333:4444:5555::0X88", STATUS_SUCCESS
, 27,
1551 { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0, 0, 0x8800 }, ex_fail_6
},
1552 { "1111:2222:3333:4444:5555::0X", STATUS_SUCCESS
, 27,
1553 { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0, 0, 0 }, ex_fail_6
},
1554 { "1111:2222:3333:4444:5555::0X88:7777", STATUS_SUCCESS
, 27,
1555 { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0, 0, 0x8800 }, ex_fail_6
},
1556 { "1111:2222:3333:4444:5555::0x8888", STATUS_SUCCESS
, 27,
1557 { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0, 0, 0x8888 }, ex_fail_6
},
1558 { "1111:2222:3333:4444:5555::08888", STATUS_INVALID_PARAMETER
, 31,
1559 { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0xabab, 0xabab, 0xabab } },
1560 { "1111:2222:3333:4444:5555::fffff", STATUS_INVALID_PARAMETER
, 31,
1561 { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0xabab, 0xabab, 0xabab } },
1562 { "1111:2222:3333:4444::fffff", STATUS_INVALID_PARAMETER
, 26,
1563 { 0x1111, 0x2222, 0x3333, 0x4444, 0xabab, 0xabab, 0xabab, 0xabab } },
1564 { "1111:2222:3333::fffff", STATUS_INVALID_PARAMETER
, 21,
1565 { 0x1111, 0x2222, 0x3333, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1566 { "1111:2222:3333:4444:5555::7777:8888", STATUS_SUCCESS
, 35,
1567 { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0, 0x7777, 0x8888 } },
1568 { "1111:2222:3333:4444:5555::8888", STATUS_SUCCESS
, 30,
1569 { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0, 0, 0x8888 } },
1570 { "1111::", STATUS_SUCCESS
, 6,
1571 { 0x1111, 0, 0, 0, 0, 0, 0, 0 } },
1572 { "1111::123.123.123.123", STATUS_SUCCESS
, 21,
1573 { 0x1111, 0, 0, 0, 0, 0, 0x7b7b, 0x7b7b } },
1574 { "1111::3333:4444:5555:6666:123.123.123.123", STATUS_SUCCESS
, 41,
1575 { 0x1111, 0, 0x3333, 0x4444, 0x5555, 0x6666, 0x7b7b, 0x7b7b } },
1576 { "1111::3333:4444:5555:6666:7777:8888", STATUS_SUCCESS
, 35,
1577 { 0x1111, 0, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0x8888 } },
1578 { "1111::4444:5555:6666:123.123.123.123", STATUS_SUCCESS
, 36,
1579 { 0x1111, 0, 0, 0x4444, 0x5555, 0x6666, 0x7b7b, 0x7b7b } },
1580 { "1111::4444:5555:6666:7777:8888", STATUS_SUCCESS
, 30,
1581 { 0x1111, 0, 0, 0x4444, 0x5555, 0x6666, 0x7777, 0x8888 } },
1582 { "1111::5555:6666:123.123.123.123", STATUS_SUCCESS
, 31,
1583 { 0x1111, 0, 0, 0, 0x5555, 0x6666, 0x7b7b, 0x7b7b } },
1584 { "1111::5555:6666:7777:8888", STATUS_SUCCESS
, 25,
1585 { 0x1111, 0, 0, 0, 0x5555, 0x6666, 0x7777, 0x8888 } },
1586 { "1111::6666:123.123.123.123", STATUS_SUCCESS
, 26,
1587 { 0x1111, 0, 0, 0, 0, 0x6666, 0x7b7b, 0x7b7b } },
1588 { "1111::6666:7777:8888", STATUS_SUCCESS
, 20,
1589 { 0x1111, 0, 0, 0, 0, 0x6666, 0x7777, 0x8888 } },
1590 { "1111::7777:8888", STATUS_SUCCESS
, 15,
1591 { 0x1111, 0, 0, 0, 0, 0, 0x7777, 0x8888 } },
1592 { "1111::8888", STATUS_SUCCESS
, 10,
1593 { 0x1111, 0, 0, 0, 0, 0, 0, 0x8888 } },
1594 { "1:2:3:4:5:6:1.2.3.4", STATUS_SUCCESS
, 19,
1595 { 0x100, 0x200, 0x300, 0x400, 0x500, 0x600, 0x201, 0x403 } },
1596 { "1:2:3:4:5:6:7:8", STATUS_SUCCESS
, 15,
1597 { 0x100, 0x200, 0x300, 0x400, 0x500, 0x600, 0x700, 0x800 } },
1598 { "1:2:3:4:5:6::", STATUS_SUCCESS
, 13,
1599 { 0x100, 0x200, 0x300, 0x400, 0x500, 0x600, 0, 0 } },
1600 { "1:2:3:4:5:6::8", STATUS_SUCCESS
, 14,
1601 { 0x100, 0x200, 0x300, 0x400, 0x500, 0x600, 0, 0x800 } },
1602 { "2001:0000:1234:0000:0000:C1C0:ABCD:0876", STATUS_SUCCESS
, 39,
1603 { 0x120, 0, 0x3412, 0, 0, 0xc0c1, 0xcdab, 0x7608 } },
1604 { "2001:0000:4136:e378:8000:63bf:3fff:fdd2", STATUS_SUCCESS
, 39,
1605 { 0x120, 0, 0x3641, 0x78e3, 0x80, 0xbf63, 0xff3f, 0xd2fd } },
1606 { "2001:0db8:0:0:0:0:1428:57ab", STATUS_SUCCESS
, 27,
1607 { 0x120, 0xb80d, 0, 0, 0, 0, 0x2814, 0xab57 } },
1608 { "2001:0db8:1234:ffff:ffff:ffff:ffff:ffff", STATUS_SUCCESS
, 39,
1609 { 0x120, 0xb80d, 0x3412, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff } },
1610 { "2001::CE49:7601:2CAD:DFFF:7C94:FFFE", STATUS_SUCCESS
, 35,
1611 { 0x120, 0, 0x49ce, 0x176, 0xad2c, 0xffdf, 0x947c, 0xfeff } },
1612 { "2001:db8:85a3::8a2e:370:7334", STATUS_SUCCESS
, 28,
1613 { 0x120, 0xb80d, 0xa385, 0, 0, 0x2e8a, 0x7003, 0x3473 } },
1614 { "3ffe:0b00:0000:0000:0001:0000:0000:000a", STATUS_SUCCESS
, 39,
1615 { 0xfe3f, 0xb, 0, 0, 0x100, 0, 0, 0xa00 } },
1616 { "::", STATUS_SUCCESS
, 2,
1617 { 0, 0, 0, 0, 0, 0, 0, 0 } },
1618 { "::%16", STATUS_SUCCESS
, 2,
1619 { 0, 0, 0, 0, 0, 0, 0, 0 } },
1620 { "::/16", STATUS_SUCCESS
, 2,
1621 { 0, 0, 0, 0, 0, 0, 0, 0 }, ex_fail_6
},
1622 { "::01234", STATUS_INVALID_PARAMETER
, 7,
1623 { 0, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1624 { "::0", STATUS_SUCCESS
, 3,
1625 { 0, 0, 0, 0, 0, 0, 0, 0 } },
1626 { "::0:0", STATUS_SUCCESS
, 5,
1627 { 0, 0, 0, 0, 0, 0, 0, 0 } },
1628 { "::0:0:0", STATUS_SUCCESS
, 7,
1629 { 0, 0, 0, 0, 0, 0, 0, 0 } },
1630 { "::0:0:0:0", STATUS_SUCCESS
, 9,
1631 { 0, 0, 0, 0, 0, 0, 0, 0 } },
1632 { "::0:0:0:0:0", STATUS_SUCCESS
, 11,
1633 { 0, 0, 0, 0, 0, 0, 0, 0 } },
1634 { "::0:0:0:0:0:0", STATUS_SUCCESS
, 13,
1635 { 0, 0, 0, 0, 0, 0, 0, 0 } },
1636 /* this one and the next one are incorrectly parsed by windows,
1637 it adds one zero too many in front, cutting off the last digit. */
1638 { "::0:0:0:0:0:0:0", STATUS_SUCCESS
, 13,
1639 { 0, 0, 0, 0, 0, 0, 0, 0 }, ex_fail_6
},
1640 { "::0:a:b:c:d:e:f", STATUS_SUCCESS
, 13,
1641 { 0, 0, 0, 0xa00, 0xb00, 0xc00, 0xd00, 0xe00 }, ex_fail_6
},
1642 { "::123.123.123.123", STATUS_SUCCESS
, 17,
1643 { 0, 0, 0, 0, 0, 0, 0x7b7b, 0x7b7b } },
1644 { "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", STATUS_SUCCESS
, 39,
1645 { 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff } },
1647 { "':10.0.0.1", STATUS_INVALID_PARAMETER
, 0,
1649 { "-1", STATUS_INVALID_PARAMETER
, 0,
1651 { "02001:0000:1234:0000:0000:C1C0:ABCD:0876", STATUS_INVALID_PARAMETER
, -1,
1653 { "2001:00000:1234:0000:0000:C1C0:ABCD:0876", STATUS_INVALID_PARAMETER
, -1,
1654 { 0x120, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1655 { "2001:0000:01234:0000:0000:C1C0:ABCD:0876", STATUS_INVALID_PARAMETER
, -1,
1656 { 0x120, 0, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1657 { "2001:0000::01234.0", STATUS_INVALID_PARAMETER
, -1,
1658 { 0x120, 0, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1659 { "2001:0::b.0", STATUS_SUCCESS
, 9,
1660 { 0x120, 0, 0, 0, 0, 0, 0, 0xb00 }, ex_fail_6
},
1661 { "2001::0:b.0", STATUS_SUCCESS
, 9,
1662 { 0x120, 0, 0, 0, 0, 0, 0, 0xb00 }, ex_fail_6
},
1663 { "1.2.3.4", STATUS_INVALID_PARAMETER
, 7,
1664 { 0x201, 0xab03, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1665 { "1.2.3.4:1111::5555", STATUS_INVALID_PARAMETER
, 7,
1666 { 0x201, 0xab03, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1667 { "1.2.3.4::5555", STATUS_INVALID_PARAMETER
, 7,
1668 { 0x201, 0xab03, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1669 { "11112222:3333:4444:5555:6666:1.2.3.4", STATUS_INVALID_PARAMETER
, -1,
1671 { "11112222:3333:4444:5555:6666:7777:8888", STATUS_INVALID_PARAMETER
, -1,
1673 { "1111", STATUS_INVALID_PARAMETER
, 4,
1675 { "1111:22223333:4444:5555:6666:1.2.3.4", STATUS_INVALID_PARAMETER
, -1,
1676 { 0x1111, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1677 { "1111:22223333:4444:5555:6666:7777:8888", STATUS_INVALID_PARAMETER
, -1,
1678 { 0x1111, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1679 { "1111:2222:", STATUS_INVALID_PARAMETER
, 10,
1680 { 0x1111, 0x2222, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1681 { "1111:2222:1.2.3.4", STATUS_INVALID_PARAMETER
, 17,
1682 { 0x1111, 0x2222, 0x201, 0xab03, 0xabab, 0xabab, 0xabab, 0xabab } },
1683 { "1111:2222:3333", STATUS_INVALID_PARAMETER
, 14,
1684 { 0x1111, 0x2222, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1685 { "1111:2222:3333:4444:5555:6666:7777:1.2.3.4", STATUS_SUCCESS
, 36,
1686 { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0x100 }, ex_fail_6
},
1687 { "1111:2222:3333:4444:5555:6666:7777:8888:", STATUS_SUCCESS
, 39,
1688 { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0x8888 }, ex_fail_6
},
1689 { "1111:2222:3333:4444:5555:6666:7777:8888:1.2.3.4",STATUS_SUCCESS
, 39,
1690 { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0x8888 }, ex_fail_6
},
1691 { "1111:2222:3333:4444:5555:6666:7777:8888:9999", STATUS_SUCCESS
, 39,
1692 { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0x8888 }, ex_fail_6
},
1693 { "1111:2222:::", STATUS_SUCCESS
, 11,
1694 { 0x1111, 0x2222, 0, 0, 0, 0, 0, 0 }, ex_fail_6
},
1695 { "1111::5555:", STATUS_INVALID_PARAMETER
, 11,
1696 { 0x1111, 0x5555, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1697 { "1111::3333:4444:5555:6666:7777::", STATUS_SUCCESS
, 30,
1698 { 0x1111, 0, 0, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777 }, ex_fail_6
},
1699 { "1111:2222:::4444:5555:6666:1.2.3.4", STATUS_SUCCESS
, 11,
1700 { 0x1111, 0x2222, 0, 0, 0, 0, 0, 0 }, ex_fail_6
},
1701 { "1111::3333::5555:6666:1.2.3.4", STATUS_SUCCESS
, 10,
1702 { 0x1111, 0, 0, 0, 0, 0, 0, 0x3333 }, ex_fail_6
},
1703 { "12345::6:7:8", STATUS_INVALID_PARAMETER
, -1,
1705 { "1::1.2.256.4", STATUS_INVALID_PARAMETER
, -1,
1706 { 0x100, 0x201, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1707 { "1::1.2.3.256", STATUS_INVALID_PARAMETER
, 12,
1708 { 0x100, 0x201, 0xab03, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1709 { "1::1.2.3.300", STATUS_INVALID_PARAMETER
, 12,
1710 { 0x100, 0x201, 0xab03, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1711 { "1::1.2::1", STATUS_INVALID_PARAMETER
, 6,
1712 { 0x100, 0xab01, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1713 { "1::1.2.3.4::1", STATUS_SUCCESS
, 10,
1714 { 0x100, 0, 0, 0, 0, 0, 0x201, 0x403 }, ex_fail_6
},
1715 { "1::1.", STATUS_INVALID_PARAMETER
, 5,
1716 { 0x100, 0xab01, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1717 { "1::1.2", STATUS_INVALID_PARAMETER
, 6,
1718 { 0x100, 0xab01, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1719 { "1::1.2.", STATUS_INVALID_PARAMETER
, 7,
1720 { 0x100, 0x201, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1721 { "1::1.2.3", STATUS_INVALID_PARAMETER
, 8,
1722 { 0x100, 0x201, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1723 { "1::1.2.3.", STATUS_INVALID_PARAMETER
, 9,
1724 { 0x100, 0x201, 0xab03, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1725 { "1::1.2.3.4", STATUS_SUCCESS
, 10,
1726 { 0x100, 0, 0, 0, 0, 0, 0x201, 0x403 } },
1727 { "1::1.2.3.900", STATUS_INVALID_PARAMETER
, 12,
1728 { 0x100, 0x201, 0xab03, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1729 { "1::1.2.300.4", STATUS_INVALID_PARAMETER
, -1,
1730 { 0x100, 0x201, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1731 { "1::1.256.3.4", STATUS_INVALID_PARAMETER
, -1,
1732 { 0x100, 0xab01, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1733 { "1::1.256:3.4", STATUS_INVALID_PARAMETER
, 8,
1734 { 0x100, 0xab01, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1735 { "1::1.2a.3.4", STATUS_INVALID_PARAMETER
, 6,
1736 { 0x100, 0xab01, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1737 { "1::256.2.3.4", STATUS_INVALID_PARAMETER
, -1,
1738 { 0x100, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1739 { "1::1a.2.3.4", STATUS_SUCCESS
, 5,
1740 { 0x100, 0, 0, 0, 0, 0, 0, 0x1a00 }, ex_fail_6
},
1741 { "1::2::3", STATUS_SUCCESS
, 4,
1742 { 0x100, 0, 0, 0, 0, 0, 0, 0x200 }, ex_fail_6
},
1743 { "2001:0000:1234: 0000:0000:C1C0:ABCD:0876", STATUS_INVALID_PARAMETER
, 15,
1744 { 0x120, 0, 0x3412, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
1745 { "2001:0000:1234:0000:0000:C1C0:ABCD:0876 0", STATUS_SUCCESS
, 39,
1746 { 0x120, 0, 0x3412, 0, 0, 0xc0c1, 0xcdab, 0x7608 }, ex_fail_6
},
1747 { "2001:1:1:1:1:1:255Z255X255Y255", STATUS_INVALID_PARAMETER
, 18,
1748 { 0x120, 0x100, 0x100, 0x100, 0x100, 0x100, 0xabab, 0xabab } },
1749 { "2001::FFD3::57ab", STATUS_SUCCESS
, 10,
1750 { 0x120, 0, 0, 0, 0, 0, 0, 0xd3ff }, ex_fail_6
},
1751 { ":", STATUS_INVALID_PARAMETER
, 0,
1753 { ":1111:2222:3333:4444:5555:6666:1.2.3.4", STATUS_INVALID_PARAMETER
, 0,
1755 { ":1111:2222:3333:4444:5555:6666:7777:8888", STATUS_INVALID_PARAMETER
, 0,
1757 { ":1111::", STATUS_INVALID_PARAMETER
, 0,
1759 { "::-1", STATUS_SUCCESS
, 2,
1760 { 0, 0, 0, 0, 0, 0, 0, 0 }, ex_fail_6
},
1761 { "::.", STATUS_SUCCESS
, 2,
1762 { 0, 0, 0, 0, 0, 0, 0, 0 }, ex_fail_6
},
1763 { "::..", STATUS_SUCCESS
, 2,
1764 { 0, 0, 0, 0, 0, 0, 0, 0 }, ex_fail_6
},
1765 { "::...", STATUS_SUCCESS
, 2,
1766 { 0, 0, 0, 0, 0, 0, 0, 0 }, ex_fail_6
},
1767 { "XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:1.2.3.4", STATUS_INVALID_PARAMETER
, 0,
1769 { "[::]", STATUS_INVALID_PARAMETER
, 0,
1770 { -1 }, ex_skip_6
},
1773 static void init_ip6(IN6_ADDR
* addr
, const int src
[8])
1776 if (!src
|| src
[0] == -1)
1778 for (j
= 0; j
< 8; ++j
)
1779 addr
->s6_words
[j
] = 0xabab;
1783 for (j
= 0; j
< 8; ++j
)
1784 addr
->s6_words
[j
] = src
[j
];
1788 static void test_RtlIpv6AddressToString(void)
1800 /* ipv4 addresses & ISATAP addresses */
1801 { "::13.1.68.3", { 0, 0, 0, 0, 0, 0, 0x10d, 0x344 } },
1802 { "::ffff:13.1.68.3", { 0, 0, 0, 0, 0, 0xffff, 0x10d, 0x344 } },
1803 { "::feff:d01:4403", { 0, 0, 0, 0, 0, 0xfffe, 0x10d, 0x344 } },
1804 { "::fffe:d01:4403", { 0, 0, 0, 0, 0, 0xfeff, 0x10d, 0x344 } },
1805 { "::100:d01:4403", { 0, 0, 0, 0, 0, 1, 0x10d, 0x344 } },
1806 { "::1:d01:4403", { 0, 0, 0, 0, 0, 0x100, 0x10d, 0x344 } },
1807 { "::ffff:0:4403", { 0, 0, 0, 0, 0, 0xffff, 0, 0x344 } },
1808 { "::ffff:13.1.0.0", { 0, 0, 0, 0, 0, 0xffff, 0x10d, 0 } },
1809 { "::ffff:0:0", { 0, 0, 0, 0, 0, 0xffff, 0, 0 } },
1810 { "::ffff:0:13.1.68.3", { 0, 0, 0, 0, 0xffff, 0, 0x10d, 0x344 } },
1811 { "::ffff:ffff:d01:4403", { 0, 0, 0, 0, 0xffff, 0xffff, 0x10d, 0x344 } },
1812 { "::ffff:0:0:d01:4403", { 0, 0, 0, 0xffff, 0, 0, 0x10d, 0x344 } },
1813 { "::ffff:255.255.255.255", { 0, 0, 0, 0, 0, 0xffff, 0xffff, 0xffff } },
1814 { "::ffff:129.144.52.38", { 0, 0, 0, 0, 0, 0xffff, 0x9081, 0x2634 } },
1815 { "::5efe:129.144.52.38", { 0, 0, 0, 0, 0, 0xfe5e, 0x9081, 0x2634 } },
1816 { "1111:2222:3333:4444:0:5efe:129.144.52.38", { 0x1111, 0x2222, 0x3333, 0x4444, 0, 0xfe5e, 0x9081, 0x2634 } },
1817 { "1111:2222:3333::5efe:129.144.52.38", { 0x1111, 0x2222, 0x3333, 0, 0, 0xfe5e, 0x9081, 0x2634 } },
1818 { "1111:2222::5efe:129.144.52.38", { 0x1111, 0x2222, 0, 0, 0, 0xfe5e, 0x9081, 0x2634 } },
1819 { "1111::5efe:129.144.52.38", { 0x1111, 0, 0, 0, 0, 0xfe5e, 0x9081, 0x2634 } },
1820 { "::200:5efe:129.144.52.38", { 0, 0, 0, 0, 2, 0xfe5e, 0x9081, 0x2634 } },
1821 { "::100:5efe:8190:3426", { 0, 0, 0, 0, 1, 0xfe5e, 0x9081, 0x2634 } },
1822 /* 'normal' addresses */
1823 { "::1", { 0, 0, 0, 0, 0, 0, 0, 0x100 } },
1824 { "0:1:2:3:4:5:6:7", { 0, 0x100, 0x200, 0x300, 0x400, 0x500, 0x600, 0x700 } },
1825 { "1080::8:800:200c:417a", { 0x8010, 0, 0, 0, 0x800, 0x8, 0x0c20, 0x7a41 } },
1826 { "1111:2222:3333:4444:5555:6666:7b7b:7b7b", { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7b7b, 0x7b7b } },
1827 { "1111:2222:3333:4444:5555:6666:7777:8888", { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0x8888 } },
1828 { "1111:2222:3333:4444:5555:6666::", { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0, 0 } },
1829 { "1111:2222:3333:4444:5555:6666:0:8888", { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0, 0x8888 } },
1830 { "1111:2222:3333:4444:5555::", { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0, 0, 0 } },
1831 { "1111:2222:3333:4444:5555:0:7b7b:7b7b", { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0, 0x7b7b, 0x7b7b } },
1832 { "1111:2222:3333:4444:5555:0:7777:8888", { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0, 0x7777, 0x8888 } },
1833 { "1111:2222:3333:4444:5555::8888", { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0, 0, 0x8888 } },
1834 { "1111::", { 0x1111, 0, 0, 0, 0, 0, 0, 0 } },
1835 { "1111::7b7b:7b7b", { 0x1111, 0, 0, 0, 0, 0, 0x7b7b, 0x7b7b } },
1836 { "1111:0:3333:4444:5555:6666:7b7b:7b7b", { 0x1111, 0, 0x3333, 0x4444, 0x5555, 0x6666, 0x7b7b, 0x7b7b } },
1837 { "1111:0:3333:4444:5555:6666:7777:8888", { 0x1111, 0, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0x8888 } },
1838 { "1111::4444:5555:6666:7b7b:7b7b", { 0x1111, 0, 0, 0x4444, 0x5555, 0x6666, 0x7b7b, 0x7b7b } },
1839 { "1111::4444:5555:6666:7777:8888", { 0x1111, 0, 0, 0x4444, 0x5555, 0x6666, 0x7777, 0x8888 } },
1840 { "1111::5555:6666:7b7b:7b7b", { 0x1111, 0, 0, 0, 0x5555, 0x6666, 0x7b7b, 0x7b7b } },
1841 { "1111::5555:6666:7777:8888", { 0x1111, 0, 0, 0, 0x5555, 0x6666, 0x7777, 0x8888 } },
1842 { "1111::6666:7b7b:7b7b", { 0x1111, 0, 0, 0, 0, 0x6666, 0x7b7b, 0x7b7b } },
1843 { "1111::6666:7777:8888", { 0x1111, 0, 0, 0, 0, 0x6666, 0x7777, 0x8888 } },
1844 { "1111::7777:8888", { 0x1111, 0, 0, 0, 0, 0, 0x7777, 0x8888 } },
1845 { "1111::8888", { 0x1111, 0, 0, 0, 0, 0, 0, 0x8888 } },
1846 { "1:2:3:4:5:6:102:304", { 0x100, 0x200, 0x300, 0x400, 0x500, 0x600, 0x201, 0x403 } },
1847 { "1:2:3:4:5:6:7:8", { 0x100, 0x200, 0x300, 0x400, 0x500, 0x600, 0x700, 0x800 } },
1848 { "1:2:3:4:5:6::", { 0x100, 0x200, 0x300, 0x400, 0x500, 0x600, 0, 0 } },
1849 { "1:2:3:4:5:6:0:8", { 0x100, 0x200, 0x300, 0x400, 0x500, 0x600, 0, 0x800 } },
1850 { "2001:0:1234::c1c0:abcd:876", { 0x120, 0, 0x3412, 0, 0, 0xc0c1, 0xcdab, 0x7608 } },
1851 { "2001:0:4136:e378:8000:63bf:3fff:fdd2", { 0x120, 0, 0x3641, 0x78e3, 0x80, 0xbf63, 0xff3f, 0xd2fd } },
1852 { "2001:db8::1428:57ab", { 0x120, 0xb80d, 0, 0, 0, 0, 0x2814, 0xab57 } },
1853 { "2001:db8:1234:ffff:ffff:ffff:ffff:ffff", { 0x120, 0xb80d, 0x3412, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff } },
1854 { "2001:0:ce49:7601:2cad:dfff:7c94:fffe", { 0x120, 0, 0x49ce, 0x176, 0xad2c, 0xffdf, 0x947c, 0xfeff } },
1855 { "2001:db8:85a3::8a2e:370:7334", { 0x120, 0xb80d, 0xa385, 0, 0, 0x2e8a, 0x7003, 0x3473 } },
1856 { "3ffe:b00::1:0:0:a", { 0xfe3f, 0xb, 0, 0, 0x100, 0, 0, 0xa00 } },
1857 { "::a:b:c:d:e", { 0, 0, 0, 0xa00, 0xb00, 0xc00, 0xd00, 0xe00 } },
1858 { "::123.123.123.123", { 0, 0, 0, 0, 0, 0, 0x7b7b, 0x7b7b } },
1859 { "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", { 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff } },
1860 { "1111:2222:3333:4444:5555:6666:7777:1", { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0x100 } },
1861 { "1111:2222:3333:4444:5555:6666:7777:8888", { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0x8888 } },
1862 { "1111:2222::", { 0x1111, 0x2222, 0, 0, 0, 0, 0, 0 } },
1863 { "1111::3333:4444:5555:6666:7777", { 0x1111, 0, 0, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777 } },
1864 { "1111:2222::", { 0x1111, 0x2222, 0, 0, 0, 0, 0, 0 } },
1865 { "1111::3333", { 0x1111, 0, 0, 0, 0, 0, 0, 0x3333 } },
1866 { "2001:0:1234::c1c0:abcd:876", { 0x120, 0, 0x3412, 0, 0, 0xc0c1, 0xcdab, 0x7608 } },
1867 { "2001::ffd3", { 0x120, 0, 0, 0, 0, 0, 0, 0xd3ff } },
1871 if (!pRtlIpv6AddressToStringA
)
1873 skip("RtlIpv6AddressToStringA not available\n");
1877 memset(buffer
, '#', sizeof(buffer
));
1878 buffer
[sizeof(buffer
)-1] = 0;
1879 memset(&ip
, 0, sizeof(ip
));
1880 result
= pRtlIpv6AddressToStringA(&ip
, buffer
);
1882 len
= strlen(buffer
);
1883 ok(result
== (buffer
+ len
) && !strcmp(buffer
, "::"),
1884 "got %p with '%s' (expected %p with '::')\n", result
, buffer
, buffer
+ len
);
1886 result
= pRtlIpv6AddressToStringA(&ip
, NULL
);
1887 ok(result
== (LPCSTR
)~0 || broken(result
== (LPCSTR
)len
) /* WinXP / Win2k3 */,
1888 "got %p, expected %p\n", result
, (LPCSTR
)~0);
1890 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++)
1892 init_ip6(&ip
, tests
[i
].ip
);
1893 memset(buffer
, '#', sizeof(buffer
));
1894 buffer
[sizeof(buffer
)-1] = 0;
1896 result
= pRtlIpv6AddressToStringA(&ip
, buffer
);
1897 len
= strlen(buffer
);
1898 ok(result
== (buffer
+ len
) && !strcmp(buffer
, tests
[i
].address
),
1899 "got %p with '%s' (expected %p with '%s')\n", result
, buffer
, buffer
+ len
, tests
[i
].address
);
1901 ok(buffer
[45] == 0 || broken(buffer
[45] != 0) /* WinXP / Win2k3 */,
1902 "expected data at buffer[45] to always be NULL\n");
1903 ok(buffer
[46] == '#', "expected data at buffer[46] not to change\n");
1907 static void test_RtlIpv6AddressToStringEx(void)
1921 /* ipv4 addresses & ISATAP addresses */
1922 { "::13.1.68.3", 0, 0, { 0, 0, 0, 0, 0, 0, 0x10d, 0x344 } },
1923 { "::13.1.68.3%1", 1, 0, { 0, 0, 0, 0, 0, 0, 0x10d, 0x344 } },
1924 { "::13.1.68.3%4294949819", 0xffffbbbb, 0, { 0, 0, 0, 0, 0, 0, 0x10d, 0x344 } },
1925 { "[::13.1.68.3%4294949819]:65518", 0xffffbbbb, 0xeeff, { 0, 0, 0, 0, 0, 0, 0x10d, 0x344 } },
1926 { "[::13.1.68.3%4294949819]:256", 0xffffbbbb, 1, { 0, 0, 0, 0, 0, 0, 0x10d, 0x344 } },
1927 { "[::13.1.68.3]:256", 0, 1, { 0, 0, 0, 0, 0, 0, 0x10d, 0x344 } },
1929 { "::1:d01:4403", 0, 0, { 0, 0, 0, 0, 0, 0x100, 0x10d, 0x344 } },
1930 { "::1:d01:4403%1", 1, 0, { 0, 0, 0, 0, 0, 0x100, 0x10d, 0x344 } },
1931 { "::1:d01:4403%4294949819", 0xffffbbbb, 0, { 0, 0, 0, 0, 0, 0x100, 0x10d, 0x344 } },
1932 { "[::1:d01:4403%4294949819]:65518", 0xffffbbbb, 0xeeff, { 0, 0, 0, 0, 0, 0x100, 0x10d, 0x344 } },
1933 { "[::1:d01:4403%4294949819]:256", 0xffffbbbb, 1, { 0, 0, 0, 0, 0, 0x100, 0x10d, 0x344 } },
1934 { "[::1:d01:4403]:256", 0, 1, { 0, 0, 0, 0, 0, 0x100, 0x10d, 0x344 } },
1936 { "1111:2222:3333:4444:0:5efe:129.144.52.38", 0, 0, { 0x1111, 0x2222, 0x3333, 0x4444, 0, 0xfe5e, 0x9081, 0x2634 } },
1937 { "1111:2222:3333:4444:0:5efe:129.144.52.38%1", 1, 0, { 0x1111, 0x2222, 0x3333, 0x4444, 0, 0xfe5e, 0x9081, 0x2634 } },
1938 { "1111:2222:3333:4444:0:5efe:129.144.52.38%4294949819", 0xffffbbbb, 0, { 0x1111, 0x2222, 0x3333, 0x4444, 0, 0xfe5e, 0x9081, 0x2634 } },
1939 { "[1111:2222:3333:4444:0:5efe:129.144.52.38%4294949819]:65518",0xffffbbbb, 0xeeff, { 0x1111, 0x2222, 0x3333, 0x4444, 0, 0xfe5e, 0x9081, 0x2634 } },
1940 { "[1111:2222:3333:4444:0:5efe:129.144.52.38%4294949819]:256", 0xffffbbbb, 1, { 0x1111, 0x2222, 0x3333, 0x4444, 0, 0xfe5e, 0x9081, 0x2634 } },
1941 { "[1111:2222:3333:4444:0:5efe:129.144.52.38]:256", 0, 1, { 0x1111, 0x2222, 0x3333, 0x4444, 0, 0xfe5e, 0x9081, 0x2634 } },
1943 { "::1", 0, 0, { 0, 0, 0, 0, 0, 0, 0, 0x100 } },
1944 { "::1%1", 1, 0, { 0, 0, 0, 0, 0, 0, 0, 0x100 } },
1945 { "::1%4294949819", 0xffffbbbb, 0, { 0, 0, 0, 0, 0, 0, 0, 0x100 } },
1946 { "[::1%4294949819]:65518", 0xffffbbbb, 0xeeff, { 0, 0, 0, 0, 0, 0, 0, 0x100 } },
1947 { "[::1%4294949819]:256", 0xffffbbbb, 1, { 0, 0, 0, 0, 0, 0, 0, 0x100 } },
1948 { "[::1]:256", 0, 1, { 0, 0, 0, 0, 0, 0, 0, 0x100 } },
1950 { "1111:2222:3333:4444:5555:6666:7b7b:7b7b", 0, 0, { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7b7b, 0x7b7b } },
1951 { "1111:2222:3333:4444:5555:6666:7b7b:7b7b%1", 1, 0, { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7b7b, 0x7b7b } },
1952 { "1111:2222:3333:4444:5555:6666:7b7b:7b7b%4294949819", 0xffffbbbb, 0, { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7b7b, 0x7b7b } },
1953 { "[1111:2222:3333:4444:5555:6666:7b7b:7b7b%4294949819]:65518", 0xffffbbbb, 0xeeff, { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7b7b, 0x7b7b } },
1954 { "[1111:2222:3333:4444:5555:6666:7b7b:7b7b%4294949819]:256", 0xffffbbbb, 1, { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7b7b, 0x7b7b } },
1955 { "[1111:2222:3333:4444:5555:6666:7b7b:7b7b]:256", 0, 1, { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7b7b, 0x7b7b } },
1957 { "1111::", 0, 0, { 0x1111, 0, 0, 0, 0, 0, 0, 0 } },
1958 { "1111::%1", 1, 0, { 0x1111, 0, 0, 0, 0, 0, 0, 0 } },
1959 { "1111::%4294949819", 0xffffbbbb, 0, { 0x1111, 0, 0, 0, 0, 0, 0, 0 } },
1960 { "[1111::%4294949819]:65518", 0xffffbbbb, 0xeeff, { 0x1111, 0, 0, 0, 0, 0, 0, 0 } },
1961 { "[1111::%4294949819]:256", 0xffffbbbb, 1, { 0x1111, 0, 0, 0, 0, 0, 0, 0 } },
1962 { "[1111::]:256", 0, 1, { 0x1111, 0, 0, 0, 0, 0, 0, 0 } },
1964 { "2001::ffd3", 0, 0, { 0x120, 0, 0, 0, 0, 0, 0, 0xd3ff } },
1965 { "2001::ffd3%1", 1, 0, { 0x120, 0, 0, 0, 0, 0, 0, 0xd3ff } },
1966 { "2001::ffd3%4294949819", 0xffffbbbb, 0, { 0x120, 0, 0, 0, 0, 0, 0, 0xd3ff } },
1967 { "[2001::ffd3%4294949819]:65518", 0xffffbbbb, 0xeeff, { 0x120, 0, 0, 0, 0, 0, 0, 0xd3ff } },
1968 { "[2001::ffd3%4294949819]:256", 0xffffbbbb, 1, { 0x120, 0, 0, 0, 0, 0, 0, 0xd3ff } },
1969 { "[2001::ffd3]:256", 0, 1, { 0x120, 0, 0, 0, 0, 0, 0, 0xd3ff } },
1973 if (!pRtlIpv6AddressToStringExA
)
1975 skip("RtlIpv6AddressToStringExA not available\n");
1979 memset(buffer
, '#', sizeof(buffer
));
1980 buffer
[sizeof(buffer
)-1] = 0;
1981 memset(&ip
, 0, sizeof(ip
));
1982 len
= sizeof(buffer
);
1983 res
= pRtlIpv6AddressToStringExA(&ip
, 0, 0, buffer
, &len
);
1985 ok(res
== STATUS_SUCCESS
, "[validate] res = 0x%08x, expected STATUS_SUCCESS\n", res
);
1986 ok(len
== 3 && !strcmp(buffer
, "::"),
1987 "got len %d with '%s' (expected 3 with '::')\n", len
, buffer
);
1989 memset(buffer
, '#', sizeof(buffer
));
1990 buffer
[sizeof(buffer
)-1] = 0;
1992 len
= sizeof(buffer
);
1993 res
= pRtlIpv6AddressToStringExA(NULL
, 0, 0, buffer
, &len
);
1994 ok(res
== STATUS_INVALID_PARAMETER
, "[null ip] res = 0x%08x, expected STATUS_INVALID_PARAMETER\n", res
);
1996 len
= sizeof(buffer
);
1997 res
= pRtlIpv6AddressToStringExA(&ip
, 0, 0, NULL
, &len
);
1998 ok(res
== STATUS_INVALID_PARAMETER
, "[null buffer] res = 0x%08x, expected STATUS_INVALID_PARAMETER\n", res
);
2000 res
= pRtlIpv6AddressToStringExA(&ip
, 0, 0, buffer
, NULL
);
2001 ok(res
== STATUS_INVALID_PARAMETER
, "[null length] res = 0x%08x, expected STATUS_INVALID_PARAMETER\n", res
);
2004 memset(buffer
, '#', sizeof(buffer
));
2005 buffer
[sizeof(buffer
)-1] = 0;
2006 res
= pRtlIpv6AddressToStringExA(&ip
, 0, 0, buffer
, &len
);
2007 ok(res
== STATUS_INVALID_PARAMETER
, "[null length] res = 0x%08x, expected STATUS_INVALID_PARAMETER\n", res
);
2008 ok(buffer
[0] == '#', "got first char %c (expected '#')\n", buffer
[0]);
2009 ok(len
== 3, "got len %d (expected len 3)\n", len
);
2011 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++)
2013 init_ip6(&ip
, tests
[i
].ip
);
2014 len
= sizeof(buffer
);
2015 memset(buffer
, '#', sizeof(buffer
));
2016 buffer
[sizeof(buffer
)-1] = 0;
2018 res
= pRtlIpv6AddressToStringExA(&ip
, tests
[i
].scopeid
, tests
[i
].port
, buffer
, &len
);
2020 ok(res
== STATUS_SUCCESS
, "[validate] res = 0x%08x, expected STATUS_SUCCESS\n", res
);
2021 ok(len
== (strlen(tests
[i
].address
) + 1) && !strcmp(buffer
, tests
[i
].address
),
2022 "got len %d with '%s' (expected %d with '%s')\n", len
, buffer
, (int)strlen(tests
[i
].address
), tests
[i
].address
);
2026 static void compare_RtlIpv6StringToAddressW(PCSTR name_a
, int terminator_offset_a
,
2027 const struct in6_addr
*addr_a
, NTSTATUS res_a
)
2034 if (!pRtlIpv6StringToAddressW
)
2037 pRtlMultiByteToUnicodeN(name
, sizeof(name
), NULL
, name_a
, strlen(name_a
) + 1);
2039 init_ip6(&ip
, NULL
);
2040 terminator
= (void *)0xdeadbeef;
2041 res
= pRtlIpv6StringToAddressW(name
, &terminator
, &ip
);
2042 ok(res
== res_a
, "[W:%s] res = 0x%08x, expected 0x%08x\n", name_a
, res
, res_a
);
2044 if (terminator_offset_a
< 0)
2046 ok(terminator
== (void *)0xdeadbeef,
2047 "[W:%s] terminator = %p, expected it not to change\n",
2048 name_a
, terminator
);
2052 ok(terminator
== name
+ terminator_offset_a
,
2053 "[W:%s] terminator = %p, expected %p\n",
2054 name_a
, terminator
, name
+ terminator_offset_a
);
2057 ok(!memcmp(&ip
, addr_a
, sizeof(ip
)),
2058 "[W:%s] ip = %x:%x:%x:%x:%x:%x:%x:%x, expected %x:%x:%x:%x:%x:%x:%x:%x\n",
2060 ip
.s6_words
[0], ip
.s6_words
[1], ip
.s6_words
[2], ip
.s6_words
[3],
2061 ip
.s6_words
[4], ip
.s6_words
[5], ip
.s6_words
[6], ip
.s6_words
[7],
2062 addr_a
->s6_words
[0], addr_a
->s6_words
[1], addr_a
->s6_words
[2], addr_a
->s6_words
[3],
2063 addr_a
->s6_words
[4], addr_a
->s6_words
[5], addr_a
->s6_words
[6], addr_a
->s6_words
[7]);
2066 static void test_RtlIpv6StringToAddress(void)
2069 IN6_ADDR ip
, expected_ip
;
2073 if (!pRtlIpv6StringToAddressW
)
2075 skip("RtlIpv6StringToAddressW not available\n");
2076 /* we can continue, just not test W */
2079 if (!pRtlIpv6StringToAddressA
)
2081 skip("RtlIpv6StringToAddressA not available\n");
2082 return; /* all tests are centered around A, we cannot continue */
2085 res
= pRtlIpv6StringToAddressA("::", &terminator
, &ip
);
2086 ok(res
== STATUS_SUCCESS
, "[validate] res = 0x%08x, expected STATUS_SUCCESS\n", res
);
2089 /* any of these crash */
2090 res
= pRtlIpv6StringToAddressA(NULL
, &terminator
, &ip
);
2091 ok(res
== STATUS_INVALID_PARAMETER
, "[null string] res = 0x%08x, expected STATUS_INVALID_PARAMETER\n", res
);
2092 res
= pRtlIpv6StringToAddressA("::", NULL
, &ip
);
2093 ok(res
== STATUS_INVALID_PARAMETER
, "[null terminator] res = 0x%08x, expected STATUS_INVALID_PARAMETER\n", res
);
2094 res
= pRtlIpv6StringToAddressA("::", &terminator
, NULL
);
2095 ok(res
== STATUS_INVALID_PARAMETER
, "[null result] res = 0x%08x, expected STATUS_INVALID_PARAMETER\n", res
);
2099 ok(sizeof(ip
) == sizeof(USHORT
)* 8, "sizeof(ip)\n");
2101 for (i
= 0; i
< ARRAY_SIZE(ipv6_tests
); i
++)
2103 init_ip6(&ip
, NULL
);
2104 terminator
= (void *)0xdeadbeef;
2105 res
= pRtlIpv6StringToAddressA(ipv6_tests
[i
].address
, &terminator
, &ip
);
2106 compare_RtlIpv6StringToAddressW(ipv6_tests
[i
].address
, (terminator
!= (void *)0xdeadbeef) ?
2107 (terminator
- ipv6_tests
[i
].address
) : -1, &ip
, res
);
2109 if (ipv6_tests
[i
].flags
& win_broken_6
)
2111 ok(res
== ipv6_tests
[i
].res
|| broken(res
== STATUS_INVALID_PARAMETER
),
2112 "[%s] res = 0x%08x, expected 0x%08x\n",
2113 ipv6_tests
[i
].address
, res
, ipv6_tests
[i
].res
);
2115 if (res
== STATUS_INVALID_PARAMETER
)
2120 ok(res
== ipv6_tests
[i
].res
,
2121 "[%s] res = 0x%08x, expected 0x%08x\n",
2122 ipv6_tests
[i
].address
, res
, ipv6_tests
[i
].res
);
2125 if (ipv6_tests
[i
].terminator_offset
< 0)
2127 ok(terminator
== (void *)0xdeadbeef,
2128 "[%s] terminator = %p, expected it not to change\n",
2129 ipv6_tests
[i
].address
, terminator
);
2133 ok(terminator
== ipv6_tests
[i
].address
+ ipv6_tests
[i
].terminator_offset
,
2134 "[%s] terminator = %p, expected %p\n",
2135 ipv6_tests
[i
].address
, terminator
, ipv6_tests
[i
].address
+ ipv6_tests
[i
].terminator_offset
);
2138 init_ip6(&expected_ip
, ipv6_tests
[i
].ip
);
2139 ok(!memcmp(&ip
, &expected_ip
, sizeof(ip
)),
2140 "[%s] ip = %x:%x:%x:%x:%x:%x:%x:%x, expected %x:%x:%x:%x:%x:%x:%x:%x\n",
2141 ipv6_tests
[i
].address
,
2142 ip
.s6_words
[0], ip
.s6_words
[1], ip
.s6_words
[2], ip
.s6_words
[3],
2143 ip
.s6_words
[4], ip
.s6_words
[5], ip
.s6_words
[6], ip
.s6_words
[7],
2144 expected_ip
.s6_words
[0], expected_ip
.s6_words
[1], expected_ip
.s6_words
[2], expected_ip
.s6_words
[3],
2145 expected_ip
.s6_words
[4], expected_ip
.s6_words
[5], expected_ip
.s6_words
[6], expected_ip
.s6_words
[7]);
2149 static void compare_RtlIpv6StringToAddressExW(PCSTR name_a
, const struct in6_addr
*addr_a
, HRESULT res_a
, ULONG scope_a
, USHORT port_a
)
2154 ULONG scope
= 0xbadf00d;
2155 USHORT port
= 0xbeef;
2157 if (!pRtlIpv6StringToAddressExW
)
2160 pRtlMultiByteToUnicodeN(name
, sizeof(name
), NULL
, name_a
, strlen(name_a
) + 1);
2162 init_ip6(&ip
, NULL
);
2163 res
= pRtlIpv6StringToAddressExW(name
, &ip
, &scope
, &port
);
2165 ok(res
== res_a
, "[W:%s] res = 0x%08x, expected 0x%08x\n", name_a
, res
, res_a
);
2166 ok(scope
== scope_a
, "[W:%s] scope = 0x%08x, expected 0x%08x\n", name_a
, scope
, scope_a
);
2167 ok(port
== port_a
, "[W:%s] port = 0x%08x, expected 0x%08x\n", name_a
, port
, port_a
);
2169 ok(!memcmp(&ip
, addr_a
, sizeof(ip
)),
2170 "[W:%s] ip = %x:%x:%x:%x:%x:%x:%x:%x, expected %x:%x:%x:%x:%x:%x:%x:%x\n",
2172 ip
.s6_words
[0], ip
.s6_words
[1], ip
.s6_words
[2], ip
.s6_words
[3],
2173 ip
.s6_words
[4], ip
.s6_words
[5], ip
.s6_words
[6], ip
.s6_words
[7],
2174 addr_a
->s6_words
[0], addr_a
->s6_words
[1], addr_a
->s6_words
[2], addr_a
->s6_words
[3],
2175 addr_a
->s6_words
[4], addr_a
->s6_words
[5], addr_a
->s6_words
[6], addr_a
->s6_words
[7]);
2178 static void test_RtlIpv6StringToAddressEx(void)
2181 IN6_ADDR ip
, expected_ip
;
2193 { "[::]", STATUS_SUCCESS
, 0, 0,
2194 { 0, 0, 0, 0, 0, 0, 0, 0 } },
2195 { "[::1]:8080", STATUS_SUCCESS
, 0, 0x901f,
2196 { 0, 0, 0, 0, 0, 0, 0, 0x100 } },
2197 { "[::1]:0x80", STATUS_SUCCESS
, 0, 0x8000,
2198 { 0, 0, 0, 0, 0, 0, 0, 0x100 } },
2199 { "[::1]:0X80", STATUS_SUCCESS
, 0, 0x8000,
2200 { 0, 0, 0, 0, 0, 0, 0, 0x100 } },
2201 { "[::1]:080", STATUS_INVALID_PARAMETER
, 0xbadf00d, 0xbeef,
2202 { 0, 0, 0, 0, 0, 0, 0, 0x100 } },
2203 { "[::1]:800000000080", STATUS_INVALID_PARAMETER
, 0xbadf00d, 0xbeef,
2204 { 0, 0, 0, 0, 0, 0, 0, 0x100 } },
2205 { "[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80", STATUS_SUCCESS
, 0, 0x5000,
2206 { 0xdcfe, 0x98ba, 0x5476, 0x1032, 0xdcfe, 0x98ba, 0x5476, 0x1032 } },
2207 { "[1080:0:0:0:8:800:200C:417A]:1234", STATUS_SUCCESS
, 0, 0xd204,
2208 { 0x8010, 0, 0, 0, 0x800, 8, 0xc20, 0x7a41 } },
2209 { "[3ffe:2a00:100:7031::1]:8080", STATUS_SUCCESS
, 0, 0x901f,
2210 { 0xfe3f, 0x2a, 1, 0x3170, 0, 0, 0, 0x100 } },
2211 { "[ 3ffe:2a00:100:7031::1]:8080", STATUS_INVALID_PARAMETER
, 0xbadf00d, 0xbeef,
2213 { "[3ffe:2a00:100:7031::1 ]:8080", STATUS_INVALID_PARAMETER
, 0xbadf00d, 0xbeef,
2214 { 0xfe3f, 0x2a, 1, 0x3170, 0, 0, 0, 0x100 } },
2215 { "[3ffe:2a00:100:7031::1].8080", STATUS_INVALID_PARAMETER
, 0xbadf00d, 0xbeef,
2216 { 0xfe3f, 0x2a, 1, 0x3170, 0, 0, 0, 0x100 } },
2217 { "[1080::8:800:200C:417A]:8080", STATUS_SUCCESS
, 0, 0x901f,
2218 { 0x8010, 0, 0, 0, 0x800, 8, 0xc20, 0x7a41 } },
2219 { "[1080::8:800:200C:417A]!8080", STATUS_INVALID_PARAMETER
, 0xbadf00d, 0xbeef,
2220 { 0x8010, 0, 0, 0, 0x800, 8, 0xc20, 0x7a41 } },
2221 { "[::FFFF:129.144.52.38]:80", STATUS_SUCCESS
, 0, 0x5000,
2222 { 0, 0, 0, 0, 0, 0xffff, 0x9081, 0x2634 } },
2223 { "[::FFFF:129.144.52.38]:-80", STATUS_INVALID_PARAMETER
, 0xbadf00d, 0xbeef,
2224 { 0, 0, 0, 0, 0, 0xffff, 0x9081, 0x2634 } },
2225 { "[::FFFF:129.144.52.38]:999999999999", STATUS_INVALID_PARAMETER
, 0xbadf00d, 0xbeef,
2226 { 0, 0, 0, 0, 0, 0xffff, 0x9081, 0x2634 } },
2227 { "[::FFFF:129.144.52.38%-8]:80", STATUS_INVALID_PARAMETER
, 0xbadf00d, 0xbeef,
2228 { 0, 0, 0, 0, 0, 0xffff, 0x9081, 0x2634 } },
2229 { "[::FFFF:129.144.52.38]:80", STATUS_SUCCESS
, 0, 0x5000,
2230 { 0, 0, 0, 0, 0, 0xffff, 0x9081, 0x2634 } },
2231 { "[12345::6:7:8]:80", STATUS_INVALID_PARAMETER
, 0xbadf00d, 0xbeef,
2233 { "[ff01::8:800:200C:417A%16]:8080", STATUS_SUCCESS
, 16, 0x901f,
2234 { 0x1ff, 0, 0, 0, 0x800, 8, 0xc20, 0x7a41 } },
2235 { "[ff01::8:800:200C:417A%100]:8080", STATUS_SUCCESS
, 100, 0x901f,
2236 { 0x1ff, 0, 0, 0, 0x800, 8, 0xc20, 0x7a41 } },
2237 { "[ff01::8:800:200C:417A%1000]:8080", STATUS_SUCCESS
, 1000, 0x901f,
2238 { 0x1ff, 0, 0, 0, 0x800, 8, 0xc20, 0x7a41 } },
2239 { "[ff01::8:800:200C:417A%10000]:8080", STATUS_SUCCESS
, 10000, 0x901f,
2240 { 0x1ff, 0, 0, 0, 0x800, 8, 0xc20, 0x7a41 } },
2241 { "[ff01::8:800:200C:417A%1000000]:8080", STATUS_SUCCESS
, 1000000, 0x901f,
2242 { 0x1ff, 0, 0, 0, 0x800, 8, 0xc20, 0x7a41 } },
2243 { "[ff01::8:800:200C:417A%4294967295]:8080", STATUS_SUCCESS
, 0xffffffff, 0x901f,
2244 { 0x1ff, 0, 0, 0, 0x800, 8, 0xc20, 0x7a41 } },
2245 { "[ff01::8:800:200C:417A%4294967296]:8080", STATUS_INVALID_PARAMETER
, 0xbadf00d, 0xbeef,
2246 { 0x1ff, 0, 0, 0, 0x800, 8, 0xc20, 0x7a41 } },
2247 { "[ff01::8:800:200C:417A%-1]:8080", STATUS_INVALID_PARAMETER
, 0xbadf00d, 0xbeef,
2248 { 0x1ff, 0, 0, 0, 0x800, 8, 0xc20, 0x7a41 } },
2249 { "[ff01::8:800:200C:417A%0]:8080", STATUS_SUCCESS
, 0, 0x901f,
2250 { 0x1ff, 0, 0, 0, 0x800, 8, 0xc20, 0x7a41 } },
2251 { "[ff01::8:800:200C:417A%1", STATUS_INVALID_PARAMETER
, 0xbadf00d, 0xbeef,
2252 { 0x1ff, 0, 0, 0, 0x800, 8, 0xc20, 0x7a41 } },
2253 { "[ff01::8:800:200C:417A%0x1000]:8080", STATUS_INVALID_PARAMETER
, 0xbadf00d, 0xbeef,
2254 { 0x1ff, 0, 0, 0, 0x800, 8, 0xc20, 0x7a41 } },
2255 { "[ff01::8:800:200C:417A/16]:8080", STATUS_INVALID_PARAMETER
, 0xbadf00d, 0xbeef,
2256 { 0x1ff, 0, 0, 0, 0x800, 8, 0xc20, 0x7a41 } },
2258 const char *simple_ip
= "::";
2261 if (!pRtlIpv6StringToAddressExW
)
2263 skip("RtlIpv6StringToAddressExW not available\n");
2264 /* we can continue, just not test W */
2267 if (!pRtlIpv6StringToAddressExA
)
2269 skip("RtlIpv6StringToAddressExA not available\n");
2273 res
= pRtlIpv6StringToAddressExA(simple_ip
, &ip
, &scope
, &port
);
2274 ok(res
== STATUS_SUCCESS
, "[validate] res = 0x%08x, expected STATUS_SUCCESS\n", res
);
2276 init_ip6(&ip
, NULL
);
2277 init_ip6(&expected_ip
, NULL
);
2280 res
= pRtlIpv6StringToAddressExA(NULL
, &ip
, &scope
, &port
);
2281 ok(res
== STATUS_INVALID_PARAMETER
,
2282 "[null string] res = 0x%08x, expected STATUS_INVALID_PARAMETER\n", res
);
2283 ok(scope
== 0xbadf00d, "[null string] scope = 0x%08x, expected 0xbadf00d\n", scope
);
2284 ok(port
== 0xbeef, "[null string] port = 0x%08x, expected 0xbeef\n", port
);
2285 ok(!memcmp(&ip
, &expected_ip
, sizeof(ip
)),
2286 "[null string] ip is changed, expected it not to change\n");
2289 init_ip6(&ip
, NULL
);
2292 res
= pRtlIpv6StringToAddressExA(simple_ip
, NULL
, &scope
, &port
);
2293 ok(res
== STATUS_INVALID_PARAMETER
,
2294 "[null result] res = 0x%08x, expected STATUS_INVALID_PARAMETER\n", res
);
2295 ok(scope
== 0xbadf00d, "[null result] scope = 0x%08x, expected 0xbadf00d\n", scope
);
2296 ok(port
== 0xbeef, "[null result] port = 0x%08x, expected 0xbeef\n", port
);
2297 ok(!memcmp(&ip
, &expected_ip
, sizeof(ip
)),
2298 "[null result] ip is changed, expected it not to change\n");
2300 init_ip6(&ip
, NULL
);
2303 res
= pRtlIpv6StringToAddressExA(simple_ip
, &ip
, NULL
, &port
);
2304 ok(res
== STATUS_INVALID_PARAMETER
,
2305 "[null scope] res = 0x%08x, expected STATUS_INVALID_PARAMETER\n", res
);
2306 ok(scope
== 0xbadf00d, "[null scope] scope = 0x%08x, expected 0xbadf00d\n", scope
);
2307 ok(port
== 0xbeef, "[null scope] port = 0x%08x, expected 0xbeef\n", port
);
2308 ok(!memcmp(&ip
, &expected_ip
, sizeof(ip
)),
2309 "[null scope] ip is changed, expected it not to change\n");
2311 init_ip6(&ip
, NULL
);
2314 res
= pRtlIpv6StringToAddressExA(simple_ip
, &ip
, &scope
, NULL
);
2315 ok(res
== STATUS_INVALID_PARAMETER
,
2316 "[null port] res = 0x%08x, expected STATUS_INVALID_PARAMETER\n", res
);
2317 ok(scope
== 0xbadf00d, "[null port] scope = 0x%08x, expected 0xbadf00d\n", scope
);
2318 ok(port
== 0xbeef, "[null port] port = 0x%08x, expected 0xbeef\n", port
);
2319 ok(!memcmp(&ip
, &expected_ip
, sizeof(ip
)),
2320 "[null port] ip is changed, expected it not to change\n");
2323 ok(sizeof(ip
) == sizeof(USHORT
)* 8, "sizeof(ip)\n");
2325 /* first we run all ip related tests, to make sure someone didn't accidentally reimplement instead of re-use. */
2326 for (i
= 0; i
< ARRAY_SIZE(ipv6_tests
); i
++)
2328 ULONG scope
= 0xbadf00d;
2329 USHORT port
= 0xbeef;
2330 NTSTATUS expect_ret
= (ipv6_tests
[i
].flags
& ex_fail_6
) ? STATUS_INVALID_PARAMETER
: ipv6_tests
[i
].res
;
2332 if (ipv6_tests
[i
].flags
& ex_skip_6
)
2335 init_ip6(&ip
, NULL
);
2336 res
= pRtlIpv6StringToAddressExA(ipv6_tests
[i
].address
, &ip
, &scope
, &port
);
2337 compare_RtlIpv6StringToAddressExW(ipv6_tests
[i
].address
, &ip
, res
, scope
, port
);
2339 /* make sure nothing was changed if this function fails. */
2340 if (res
== STATUS_INVALID_PARAMETER
)
2342 ok(scope
== 0xbadf00d, "[%s] scope = 0x%08x, expected 0xbadf00d\n",
2343 ipv6_tests
[i
].address
, scope
);
2344 ok(port
== 0xbeef, "[%s] port = 0x%08x, expected 0xbeef\n",
2345 ipv6_tests
[i
].address
, port
);
2349 ok(scope
!= 0xbadf00d, "[%s] scope = 0x%08x, not expected 0xbadf00d\n",
2350 ipv6_tests
[i
].address
, scope
);
2351 ok(port
!= 0xbeef, "[%s] port = 0x%08x, not expected 0xbeef\n",
2352 ipv6_tests
[i
].address
, port
);
2355 if (ipv6_tests
[i
].flags
& win_broken_6
)
2357 ok(res
== expect_ret
|| broken(res
== STATUS_INVALID_PARAMETER
),
2358 "[%s] res = 0x%08x, expected 0x%08x\n", ipv6_tests
[i
].address
, res
, expect_ret
);
2360 if (res
== STATUS_INVALID_PARAMETER
)
2365 ok(res
== expect_ret
, "[%s] res = 0x%08x, expected 0x%08x\n",
2366 ipv6_tests
[i
].address
, res
, expect_ret
);
2369 /* If ex fails but non-ex does not we cannot check if the part that is converted
2370 before it failed was correct, since there is no data for it in the table. */
2371 if (res
== expect_ret
)
2373 init_ip6(&expected_ip
, ipv6_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_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 /* now we run scope / port related tests */
2385 for (i
= 0; i
< ARRAY_SIZE(ipv6_ex_tests
); i
++)
2389 init_ip6(&ip
, NULL
);
2390 res
= pRtlIpv6StringToAddressExA(ipv6_ex_tests
[i
].address
, &ip
, &scope
, &port
);
2391 compare_RtlIpv6StringToAddressExW(ipv6_ex_tests
[i
].address
, &ip
, res
, scope
, port
);
2393 ok(res
== ipv6_ex_tests
[i
].res
, "[%s] res = 0x%08x, expected 0x%08x\n",
2394 ipv6_ex_tests
[i
].address
, res
, ipv6_ex_tests
[i
].res
);
2395 ok(scope
== ipv6_ex_tests
[i
].scope
, "[%s] scope = 0x%08x, expected 0x%08x\n",
2396 ipv6_ex_tests
[i
].address
, scope
, ipv6_ex_tests
[i
].scope
);
2397 ok(port
== ipv6_ex_tests
[i
].port
, "[%s] port = 0x%08x, expected 0x%08x\n",
2398 ipv6_ex_tests
[i
].address
, port
, ipv6_ex_tests
[i
].port
);
2400 init_ip6(&expected_ip
, ipv6_ex_tests
[i
].ip
);
2401 ok(!memcmp(&ip
, &expected_ip
, sizeof(ip
)),
2402 "[%s] ip = %x:%x:%x:%x:%x:%x:%x:%x, expected %x:%x:%x:%x:%x:%x:%x:%x\n",
2403 ipv6_ex_tests
[i
].address
,
2404 ip
.s6_words
[0], ip
.s6_words
[1], ip
.s6_words
[2], ip
.s6_words
[3],
2405 ip
.s6_words
[4], ip
.s6_words
[5], ip
.s6_words
[6], ip
.s6_words
[7],
2406 expected_ip
.s6_words
[0], expected_ip
.s6_words
[1], expected_ip
.s6_words
[2], expected_ip
.s6_words
[3],
2407 expected_ip
.s6_words
[4], expected_ip
.s6_words
[5], expected_ip
.s6_words
[6], expected_ip
.s6_words
[7]);
2411 static void test_LdrAddRefDll(void)
2419 win_skip( "LdrAddRefDll not supported\n" );
2423 mod
= LoadLibraryA("comctl32.dll");
2424 ok(mod
!= NULL
, "got %p\n", mod
);
2425 ret
= FreeLibrary(mod
);
2426 ok(ret
, "got %d\n", ret
);
2428 mod2
= GetModuleHandleA("comctl32.dll");
2429 ok(mod2
== NULL
, "got %p\n", mod2
);
2431 /* load, addref and release 2 times */
2432 mod
= LoadLibraryA("comctl32.dll");
2433 ok(mod
!= NULL
, "got %p\n", mod
);
2434 status
= pLdrAddRefDll(0, mod
);
2435 ok(status
== STATUS_SUCCESS
, "got 0x%08x\n", status
);
2436 ret
= FreeLibrary(mod
);
2437 ok(ret
, "got %d\n", ret
);
2439 mod2
= GetModuleHandleA("comctl32.dll");
2440 ok(mod2
!= NULL
, "got %p\n", mod2
);
2441 ret
= FreeLibrary(mod
);
2442 ok(ret
, "got %d\n", ret
);
2444 mod2
= GetModuleHandleA("comctl32.dll");
2445 ok(mod2
== NULL
, "got %p\n", mod2
);
2448 mod
= LoadLibraryA("comctl32.dll");
2449 ok(mod
!= NULL
, "got %p\n", mod
);
2450 status
= pLdrAddRefDll(LDR_ADDREF_DLL_PIN
, mod
);
2451 ok(status
== STATUS_SUCCESS
, "got 0x%08x\n", status
);
2453 ret
= FreeLibrary(mod
);
2454 ok(ret
, "got %d\n", ret
);
2455 ret
= FreeLibrary(mod
);
2456 ok(ret
, "got %d\n", ret
);
2457 ret
= FreeLibrary(mod
);
2458 ok(ret
, "got %d\n", ret
);
2459 ret
= FreeLibrary(mod
);
2460 ok(ret
, "got %d\n", ret
);
2462 mod2
= GetModuleHandleA("comctl32.dll");
2463 ok(mod2
!= NULL
, "got %p\n", mod2
);
2466 static void test_LdrLockLoaderLock(void)
2472 if (!pLdrLockLoaderLock
)
2474 win_skip("LdrLockLoaderLock() is not available\n");
2481 status
= pLdrLockLoaderLock(0x10, &result
, &magic
);
2482 ok(status
== STATUS_INVALID_PARAMETER_1
, "got 0x%08x\n", status
);
2483 ok(result
== 0, "got %d\n", result
);
2484 ok(magic
== 0, "got %lx\n", magic
);
2487 status
= pLdrLockLoaderLock(0x10, NULL
, &magic
);
2488 ok(status
== STATUS_INVALID_PARAMETER_1
, "got 0x%08x\n", status
);
2489 ok(magic
== 0, "got %lx\n", magic
);
2492 status
= pLdrLockLoaderLock(0x10, &result
, NULL
);
2493 ok(status
== STATUS_INVALID_PARAMETER_1
, "got 0x%08x\n", status
);
2494 ok(result
== 0, "got %d\n", result
);
2496 /* non-blocking mode, result is null */
2498 status
= pLdrLockLoaderLock(0x2, NULL
, &magic
);
2499 ok(status
== STATUS_INVALID_PARAMETER_2
, "got 0x%08x\n", status
);
2500 ok(magic
== 0, "got %lx\n", magic
);
2502 /* magic pointer is null */
2504 status
= pLdrLockLoaderLock(0, &result
, NULL
);
2505 ok(status
== STATUS_INVALID_PARAMETER_3
, "got 0x%08x\n", status
);
2506 ok(result
== 0, "got %d\n", result
);
2508 /* lock in non-blocking mode */
2511 status
= pLdrLockLoaderLock(0x2, &result
, &magic
);
2512 ok(status
== STATUS_SUCCESS
, "got 0x%08x\n", status
);
2513 ok(result
== 1, "got %d\n", result
);
2514 ok(magic
!= 0, "got %lx\n", magic
);
2515 pLdrUnlockLoaderLock(0, magic
);
2518 static void test_RtlCompressBuffer(void)
2520 ULONG compress_workspace
, decompress_workspace
;
2521 static const UCHAR test_buffer
[] = "WineWineWine";
2522 static UCHAR buf1
[0x1000], buf2
[0x1000];
2523 ULONG final_size
, buf_size
;
2524 UCHAR
*workspace
= NULL
;
2527 if (!pRtlCompressBuffer
|| !pRtlDecompressBuffer
|| !pRtlGetCompressionWorkSpaceSize
)
2529 win_skip("skipping RtlCompressBuffer tests, required functions not available\n");
2533 compress_workspace
= decompress_workspace
= 0xdeadbeef;
2534 status
= pRtlGetCompressionWorkSpaceSize(COMPRESSION_FORMAT_LZNT1
, &compress_workspace
,
2535 &decompress_workspace
);
2536 ok(status
== STATUS_SUCCESS
, "got wrong status 0x%08x\n", status
);
2537 ok(compress_workspace
!= 0, "got wrong compress_workspace %u\n", compress_workspace
);
2538 workspace
= HeapAlloc(GetProcessHeap(), 0, compress_workspace
);
2539 ok(workspace
!= NULL
, "HeapAlloc failed %d\n", GetLastError());
2541 /* test compression format / engine */
2542 final_size
= 0xdeadbeef;
2543 status
= pRtlCompressBuffer(COMPRESSION_FORMAT_NONE
, test_buffer
, sizeof(test_buffer
),
2544 buf1
, sizeof(buf1
) - 1, 4096, &final_size
, workspace
);
2545 ok(status
== STATUS_INVALID_PARAMETER
, "got wrong status 0x%08x\n", status
);
2546 ok(final_size
== 0xdeadbeef, "got wrong final_size %u\n", final_size
);
2548 final_size
= 0xdeadbeef;
2549 status
= pRtlCompressBuffer(COMPRESSION_FORMAT_DEFAULT
, test_buffer
, sizeof(test_buffer
),
2550 buf1
, sizeof(buf1
) - 1, 4096, &final_size
, workspace
);
2551 ok(status
== STATUS_INVALID_PARAMETER
, "got wrong status 0x%08x\n", status
);
2552 ok(final_size
== 0xdeadbeef, "got wrong final_size %u\n", final_size
);
2554 final_size
= 0xdeadbeef;
2555 status
= pRtlCompressBuffer(0xFF, test_buffer
, sizeof(test_buffer
),
2556 buf1
, sizeof(buf1
) - 1, 4096, &final_size
, workspace
);
2557 ok(status
== STATUS_UNSUPPORTED_COMPRESSION
, "got wrong status 0x%08x\n", status
);
2558 ok(final_size
== 0xdeadbeef, "got wrong final_size %u\n", final_size
);
2560 /* test compression */
2561 final_size
= 0xdeadbeef;
2562 memset(buf1
, 0x11, sizeof(buf1
));
2563 status
= pRtlCompressBuffer(COMPRESSION_FORMAT_LZNT1
, test_buffer
, sizeof(test_buffer
),
2564 buf1
, sizeof(buf1
), 4096, &final_size
, workspace
);
2565 ok(status
== STATUS_SUCCESS
, "got wrong status 0x%08x\n", status
);
2566 ok((*(WORD
*)buf1
& 0x7000) == 0x3000, "no chunk signature found %04x\n", *(WORD
*)buf1
);
2568 ok(final_size
< sizeof(test_buffer
), "got wrong final_size %u\n", final_size
);
2570 /* test decompression */
2571 buf_size
= final_size
;
2572 final_size
= 0xdeadbeef;
2573 memset(buf2
, 0x11, sizeof(buf2
));
2574 status
= pRtlDecompressBuffer(COMPRESSION_FORMAT_LZNT1
, buf2
, sizeof(buf2
),
2575 buf1
, buf_size
, &final_size
);
2576 ok(status
== STATUS_SUCCESS
, "got wrong status 0x%08x\n", status
);
2577 ok(final_size
== sizeof(test_buffer
), "got wrong final_size %u\n", final_size
);
2578 ok(!memcmp(buf2
, test_buffer
, sizeof(test_buffer
)), "got wrong decoded data\n");
2579 ok(buf2
[sizeof(test_buffer
)] == 0x11, "too many bytes written\n");
2581 /* buffer too small */
2582 final_size
= 0xdeadbeef;
2583 memset(buf1
, 0x11, sizeof(buf1
));
2584 status
= pRtlCompressBuffer(COMPRESSION_FORMAT_LZNT1
, test_buffer
, sizeof(test_buffer
),
2585 buf1
, 4, 4096, &final_size
, workspace
);
2586 ok(status
== STATUS_BUFFER_TOO_SMALL
, "got wrong status 0x%08x\n", status
);
2588 HeapFree(GetProcessHeap(), 0, workspace
);
2591 static void test_RtlGetCompressionWorkSpaceSize(void)
2593 ULONG compress_workspace
, decompress_workspace
;
2596 if (!pRtlGetCompressionWorkSpaceSize
)
2598 win_skip("RtlGetCompressionWorkSpaceSize is not available\n");
2602 /* test invalid format / engine */
2603 status
= pRtlGetCompressionWorkSpaceSize(COMPRESSION_FORMAT_NONE
, &compress_workspace
,
2604 &decompress_workspace
);
2605 ok(status
== STATUS_INVALID_PARAMETER
, "got wrong status 0x%08x\n", status
);
2607 status
= pRtlGetCompressionWorkSpaceSize(COMPRESSION_FORMAT_DEFAULT
, &compress_workspace
,
2608 &decompress_workspace
);
2609 ok(status
== STATUS_INVALID_PARAMETER
, "got wrong status 0x%08x\n", status
);
2611 status
= pRtlGetCompressionWorkSpaceSize(0xFF, &compress_workspace
, &decompress_workspace
);
2612 ok(status
== STATUS_UNSUPPORTED_COMPRESSION
, "got wrong status 0x%08x\n", status
);
2614 /* test LZNT1 with normal and maximum compression */
2615 compress_workspace
= decompress_workspace
= 0xdeadbeef;
2616 status
= pRtlGetCompressionWorkSpaceSize(COMPRESSION_FORMAT_LZNT1
, &compress_workspace
,
2617 &decompress_workspace
);
2618 ok(status
== STATUS_SUCCESS
, "got wrong status 0x%08x\n", status
);
2619 ok(compress_workspace
!= 0, "got wrong compress_workspace %u\n", compress_workspace
);
2620 ok(decompress_workspace
== 0x1000, "got wrong decompress_workspace %u\n", decompress_workspace
);
2622 compress_workspace
= decompress_workspace
= 0xdeadbeef;
2623 status
= pRtlGetCompressionWorkSpaceSize(COMPRESSION_FORMAT_LZNT1
| COMPRESSION_ENGINE_MAXIMUM
,
2624 &compress_workspace
, &decompress_workspace
);
2625 ok(status
== STATUS_SUCCESS
, "got wrong status 0x%08x\n", status
);
2626 ok(compress_workspace
!= 0, "got wrong compress_workspace %u\n", compress_workspace
);
2627 ok(decompress_workspace
== 0x1000, "got wrong decompress_workspace %u\n", decompress_workspace
);
2630 /* helper for test_RtlDecompressBuffer, checks if a chunk is incomplete */
2631 static BOOL
is_incomplete_chunk(const UCHAR
*compressed
, ULONG compressed_size
, BOOL check_all
)
2635 if (compressed_size
<= sizeof(WORD
))
2638 while (compressed_size
>= sizeof(WORD
))
2640 chunk_size
= (*(WORD
*)compressed
& 0xFFF) + 1;
2641 if (compressed_size
< sizeof(WORD
) + chunk_size
)
2645 compressed
+= sizeof(WORD
) + chunk_size
;
2646 compressed_size
-= sizeof(WORD
) + chunk_size
;
2652 #define DECOMPRESS_BROKEN_FRAGMENT 1 /* < Win 7 */
2653 #define DECOMPRESS_BROKEN_TRUNCATED 2 /* broken on all machines */
2655 static void test_RtlDecompressBuffer(void)
2659 UCHAR compressed
[32];
2660 ULONG compressed_size
;
2662 UCHAR uncompressed
[32];
2663 ULONG uncompressed_size
;
2668 /* 4 byte uncompressed chunk */
2670 {0x03, 0x30, 'W', 'i', 'n', 'e'},
2675 DECOMPRESS_BROKEN_FRAGMENT
2677 /* 8 byte uncompressed chunk */
2679 {0x07, 0x30, 'W', 'i', 'n', 'e', 'W', 'i', 'n', 'e'},
2684 DECOMPRESS_BROKEN_FRAGMENT
2686 /* 4 byte compressed chunk */
2688 {0x04, 0xB0, 0x00, 'W', 'i', 'n', 'e'},
2694 /* 8 byte compressed chunk */
2696 {0x08, 0xB0, 0x00, 'W', 'i', 'n', 'e', 'W', 'i', 'n', 'e'},
2702 /* compressed chunk using backwards reference */
2704 {0x06, 0xB0, 0x10, 'W', 'i', 'n', 'e', 0x01, 0x30},
2709 DECOMPRESS_BROKEN_TRUNCATED
2711 /* compressed chunk using backwards reference with length > bytes_read */
2713 {0x06, 0xB0, 0x10, 'W', 'i', 'n', 'e', 0x05, 0x30},
2718 DECOMPRESS_BROKEN_TRUNCATED
2720 /* same as above, but unused bits != 0 */
2722 {0x06, 0xB0, 0x30, 'W', 'i', 'n', 'e', 0x01, 0x30},
2727 DECOMPRESS_BROKEN_TRUNCATED
2729 /* compressed chunk without backwards reference and unused bits != 0 */
2731 {0x01, 0xB0, 0x02, 'W'},
2737 /* termination sequence after first chunk */
2739 {0x03, 0x30, 'W', 'i', 'n', 'e', 0x00, 0x00, 0x03, 0x30, 'W', 'i', 'n', 'e'},
2744 DECOMPRESS_BROKEN_FRAGMENT
2746 /* compressed chunk using backwards reference with 4 bit offset, 12 bit length */
2748 {0x14, 0xB0, 0x00, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
2749 0x00, 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
2753 "ABCDEFGHIJKLMNOPABCD",
2755 DECOMPRESS_BROKEN_TRUNCATED
2757 /* compressed chunk using backwards reference with 5 bit offset, 11 bit length */
2759 {0x15, 0xB0, 0x00, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
2760 0x00, 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
2761 0x02, 'A', 0x00, 0x78},
2764 "ABCDEFGHIJKLMNOPABCD",
2766 DECOMPRESS_BROKEN_TRUNCATED
2768 /* uncompressed chunk with invalid magic */
2770 {0x03, 0x20, 'W', 'i', 'n', 'e'},
2775 DECOMPRESS_BROKEN_FRAGMENT
2777 /* compressed chunk with invalid magic */
2779 {0x04, 0xA0, 0x00, 'W', 'i', 'n', 'e'},
2785 /* garbage byte after end of buffer */
2787 {0x00, 0xB0, 0x02, 0x01},
2793 /* empty compressed chunk */
2801 /* empty compressed chunk with unused bits != 0 */
2809 /* empty input buffer */
2813 STATUS_BAD_COMPRESSION_BUFFER
,
2815 /* incomplete chunk header */
2819 STATUS_BAD_COMPRESSION_BUFFER
2821 /* incomplete chunk header */
2825 STATUS_BAD_COMPRESSION_BUFFER
2827 /* compressed chunk with invalid backwards reference */
2829 {0x06, 0xB0, 0x10, 'W', 'i', 'n', 'e', 0x05, 0x40},
2831 STATUS_BAD_COMPRESSION_BUFFER
2833 /* compressed chunk with incomplete backwards reference */
2835 {0x05, 0xB0, 0x10, 'W', 'i', 'n', 'e', 0x05},
2837 STATUS_BAD_COMPRESSION_BUFFER
2839 /* incomplete uncompressed chunk */
2841 {0x07, 0x30, 'W', 'i', 'n', 'e'},
2843 STATUS_BAD_COMPRESSION_BUFFER
2845 /* incomplete compressed chunk */
2847 {0x08, 0xB0, 0x00, 'W', 'i', 'n', 'e'},
2849 STATUS_BAD_COMPRESSION_BUFFER
2851 /* two compressed chunks, the second one incomplete */
2853 {0x00, 0xB0, 0x02, 0x00, 0xB0},
2855 STATUS_BAD_COMPRESSION_BUFFER
,
2859 static UCHAR buf
[0x2000], workspace
[0x1000];
2860 NTSTATUS status
, expected_status
;
2864 if (!pRtlDecompressBuffer
|| !pRtlDecompressFragment
)
2866 win_skip("RtlDecompressBuffer or RtlDecompressFragment is not available\n");
2870 /* test compression format / engine */
2871 final_size
= 0xdeadbeef;
2872 status
= pRtlDecompressBuffer(COMPRESSION_FORMAT_NONE
, buf
, sizeof(buf
), test_lznt
[0].compressed
,
2873 test_lznt
[0].compressed_size
, &final_size
);
2874 ok(status
== STATUS_INVALID_PARAMETER
, "got wrong status 0x%08x\n", status
);
2875 ok(final_size
== 0xdeadbeef, "got wrong final_size %u\n", final_size
);
2877 final_size
= 0xdeadbeef;
2878 status
= pRtlDecompressBuffer(COMPRESSION_FORMAT_DEFAULT
, buf
, sizeof(buf
), test_lznt
[0].compressed
,
2879 test_lznt
[0].compressed_size
, &final_size
);
2880 ok(status
== STATUS_INVALID_PARAMETER
, "got wrong status 0x%08x\n", status
);
2881 ok(final_size
== 0xdeadbeef, "got wrong final_size %u\n", final_size
);
2883 final_size
= 0xdeadbeef;
2884 status
= pRtlDecompressBuffer(0xFF, buf
, sizeof(buf
), test_lznt
[0].compressed
,
2885 test_lznt
[0].compressed_size
, &final_size
);
2886 ok(status
== STATUS_UNSUPPORTED_COMPRESSION
, "got wrong status 0x%08x\n", status
);
2887 ok(final_size
== 0xdeadbeef, "got wrong final_size %u\n", final_size
);
2889 /* regular tests for RtlDecompressBuffer */
2890 for (i
= 0; i
< ARRAY_SIZE(test_lznt
); i
++)
2892 trace("Running test %d (compressed_size=%u, uncompressed_size=%u, status=0x%08x)\n",
2893 i
, test_lznt
[i
].compressed_size
, test_lznt
[i
].uncompressed_size
, test_lznt
[i
].status
);
2895 /* test with very big buffer */
2896 final_size
= 0xdeadbeef;
2897 memset(buf
, 0x11, sizeof(buf
));
2898 status
= pRtlDecompressBuffer(COMPRESSION_FORMAT_LZNT1
, buf
, sizeof(buf
), test_lznt
[i
].compressed
,
2899 test_lznt
[i
].compressed_size
, &final_size
);
2900 ok(status
== test_lznt
[i
].status
|| broken(status
== STATUS_BAD_COMPRESSION_BUFFER
&&
2901 (test_lznt
[i
].broken_flags
& DECOMPRESS_BROKEN_FRAGMENT
)), "%d: got wrong status 0x%08x\n", i
, status
);
2904 ok(final_size
== test_lznt
[i
].uncompressed_size
,
2905 "%d: got wrong final_size %u\n", i
, final_size
);
2906 ok(!memcmp(buf
, test_lznt
[i
].uncompressed
, test_lznt
[i
].uncompressed_size
),
2907 "%d: got wrong decoded data\n", i
);
2908 ok(buf
[test_lznt
[i
].uncompressed_size
] == 0x11,
2909 "%d: buf[%u] was modified\n", i
, test_lznt
[i
].uncompressed_size
);
2912 /* test that modifier for compression engine is ignored */
2913 final_size
= 0xdeadbeef;
2914 memset(buf
, 0x11, sizeof(buf
));
2915 status
= pRtlDecompressBuffer(COMPRESSION_FORMAT_LZNT1
| COMPRESSION_ENGINE_MAXIMUM
, buf
, sizeof(buf
),
2916 test_lznt
[i
].compressed
, test_lznt
[i
].compressed_size
, &final_size
);
2917 ok(status
== test_lznt
[i
].status
|| broken(status
== STATUS_BAD_COMPRESSION_BUFFER
&&
2918 (test_lznt
[i
].broken_flags
& DECOMPRESS_BROKEN_FRAGMENT
)), "%d: got wrong status 0x%08x\n", i
, status
);
2921 ok(final_size
== test_lznt
[i
].uncompressed_size
,
2922 "%d: got wrong final_size %u\n", i
, final_size
);
2923 ok(!memcmp(buf
, test_lznt
[i
].uncompressed
, test_lznt
[i
].uncompressed_size
),
2924 "%d: got wrong decoded data\n", i
);
2925 ok(buf
[test_lznt
[i
].uncompressed_size
] == 0x11,
2926 "%d: buf[%u] was modified\n", i
, test_lznt
[i
].uncompressed_size
);
2929 /* test with expected output size */
2930 if (test_lznt
[i
].uncompressed_size
> 0)
2932 final_size
= 0xdeadbeef;
2933 memset(buf
, 0x11, sizeof(buf
));
2934 status
= pRtlDecompressBuffer(COMPRESSION_FORMAT_LZNT1
, buf
, test_lznt
[i
].uncompressed_size
,
2935 test_lznt
[i
].compressed
, test_lznt
[i
].compressed_size
, &final_size
);
2936 ok(status
== test_lznt
[i
].status
, "%d: got wrong status 0x%08x\n", i
, status
);
2939 ok(final_size
== test_lznt
[i
].uncompressed_size
,
2940 "%d: got wrong final_size %u\n", i
, final_size
);
2941 ok(!memcmp(buf
, test_lznt
[i
].uncompressed
, test_lznt
[i
].uncompressed_size
),
2942 "%d: got wrong decoded data\n", i
);
2943 ok(buf
[test_lznt
[i
].uncompressed_size
] == 0x11,
2944 "%d: buf[%u] was modified\n", i
, test_lznt
[i
].uncompressed_size
);
2948 /* test with smaller output size */
2949 if (test_lznt
[i
].uncompressed_size
> 1)
2951 final_size
= 0xdeadbeef;
2952 memset(buf
, 0x11, sizeof(buf
));
2953 status
= pRtlDecompressBuffer(COMPRESSION_FORMAT_LZNT1
, buf
, test_lznt
[i
].uncompressed_size
- 1,
2954 test_lznt
[i
].compressed
, test_lznt
[i
].compressed_size
, &final_size
);
2955 if (test_lznt
[i
].broken_flags
& DECOMPRESS_BROKEN_TRUNCATED
)
2957 ok(status
== STATUS_BAD_COMPRESSION_BUFFER
, "%d: got wrong status 0x%08x\n", i
, status
);
2959 ok(status
== test_lznt
[i
].status
, "%d: got wrong status 0x%08x\n", i
, status
);
2962 ok(final_size
== test_lznt
[i
].uncompressed_size
- 1,
2963 "%d: got wrong final_size %u\n", i
, final_size
);
2964 ok(!memcmp(buf
, test_lznt
[i
].uncompressed
, test_lznt
[i
].uncompressed_size
- 1),
2965 "%d: got wrong decoded data\n", i
);
2966 ok(buf
[test_lznt
[i
].uncompressed_size
- 1] == 0x11,
2967 "%d: buf[%u] was modified\n", i
, test_lznt
[i
].uncompressed_size
- 1);
2971 /* test with zero output size */
2972 final_size
= 0xdeadbeef;
2973 memset(buf
, 0x11, sizeof(buf
));
2974 status
= pRtlDecompressBuffer(COMPRESSION_FORMAT_LZNT1
, buf
, 0, test_lznt
[i
].compressed
,
2975 test_lznt
[i
].compressed_size
, &final_size
);
2976 if (is_incomplete_chunk(test_lznt
[i
].compressed
, test_lznt
[i
].compressed_size
, FALSE
))
2977 ok(status
== STATUS_BAD_COMPRESSION_BUFFER
, "%d: got wrong status 0x%08x\n", i
, status
);
2980 ok(status
== STATUS_SUCCESS
, "%d: got wrong status 0x%08x\n", i
, status
);
2981 ok(final_size
== 0, "%d: got wrong final_size %u\n", i
, final_size
);
2982 ok(buf
[0] == 0x11, "%d: buf[0] was modified\n", i
);
2985 /* test RtlDecompressFragment with offset = 0 */
2986 final_size
= 0xdeadbeef;
2987 memset(buf
, 0x11, sizeof(buf
));
2988 status
= pRtlDecompressFragment(COMPRESSION_FORMAT_LZNT1
, buf
, sizeof(buf
), test_lznt
[i
].compressed
,
2989 test_lznt
[i
].compressed_size
, 0, &final_size
, workspace
);
2990 if (test_lznt
[i
].broken_flags
& DECOMPRESS_BROKEN_FRAGMENT
)
2992 ok(status
== STATUS_BAD_COMPRESSION_BUFFER
, "%d: got wrong status 0x%08x\n", i
, status
);
2994 ok(status
== test_lznt
[i
].status
, "%d: got wrong status 0x%08x\n", i
, status
);
2997 ok(final_size
== test_lznt
[i
].uncompressed_size
,
2998 "%d: got wrong final_size %u\n", i
, final_size
);
2999 ok(!memcmp(buf
, test_lznt
[i
].uncompressed
, test_lznt
[i
].uncompressed_size
),
3000 "%d: got wrong decoded data\n", i
);
3001 ok(buf
[test_lznt
[i
].uncompressed_size
] == 0x11,
3002 "%d: buf[%u] was modified\n", i
, test_lznt
[i
].uncompressed_size
);
3005 /* test RtlDecompressFragment with offset = 1 */
3006 final_size
= 0xdeadbeef;
3007 memset(buf
, 0x11, sizeof(buf
));
3008 status
= pRtlDecompressFragment(COMPRESSION_FORMAT_LZNT1
, buf
, sizeof(buf
), test_lznt
[i
].compressed
,
3009 test_lznt
[i
].compressed_size
, 1, &final_size
, workspace
);
3010 if (test_lznt
[i
].broken_flags
& DECOMPRESS_BROKEN_FRAGMENT
)
3012 ok(status
== STATUS_BAD_COMPRESSION_BUFFER
, "%d: got wrong status 0x%08x\n", i
, status
);
3014 ok(status
== test_lznt
[i
].status
, "%d: got wrong status 0x%08x\n", i
, status
);
3017 if (test_lznt
[i
].uncompressed_size
== 0)
3020 ok(final_size
== 4095, "%d: got wrong final_size %u\n", i
, final_size
);
3021 /* Buffer doesn't contain any useful value on Windows */
3022 ok(buf
[4095] == 0x11, "%d: buf[4095] was modified\n", i
);
3026 ok(final_size
== test_lznt
[i
].uncompressed_size
- 1,
3027 "%d: got wrong final_size %u\n", i
, final_size
);
3028 ok(!memcmp(buf
, test_lznt
[i
].uncompressed
+ 1, test_lznt
[i
].uncompressed_size
- 1),
3029 "%d: got wrong decoded data\n", i
);
3030 ok(buf
[test_lznt
[i
].uncompressed_size
- 1] == 0x11,
3031 "%d: buf[%u] was modified\n", i
, test_lznt
[i
].uncompressed_size
- 1);
3035 /* test RtlDecompressFragment with offset = 4095 */
3036 final_size
= 0xdeadbeef;
3037 memset(buf
, 0x11, sizeof(buf
));
3038 status
= pRtlDecompressFragment(COMPRESSION_FORMAT_LZNT1
, buf
, sizeof(buf
), test_lznt
[i
].compressed
,
3039 test_lznt
[i
].compressed_size
, 4095, &final_size
, workspace
);
3040 if (test_lznt
[i
].broken_flags
& DECOMPRESS_BROKEN_FRAGMENT
)
3042 ok(status
== STATUS_BAD_COMPRESSION_BUFFER
, "%d: got wrong status 0x%08x\n", i
, status
);
3044 ok(status
== test_lznt
[i
].status
, "%d: got wrong status 0x%08x\n", i
, status
);
3048 ok(final_size
== 1, "%d: got wrong final_size %u\n", i
, final_size
);
3050 ok(buf
[0] == 0, "%d: padding is not zero\n", i
);
3051 ok(buf
[1] == 0x11, "%d: buf[1] was modified\n", i
);
3054 /* test RtlDecompressFragment with offset = 4096 */
3055 final_size
= 0xdeadbeef;
3056 memset(buf
, 0x11, sizeof(buf
));
3057 status
= pRtlDecompressFragment(COMPRESSION_FORMAT_LZNT1
, buf
, sizeof(buf
), test_lznt
[i
].compressed
,
3058 test_lznt
[i
].compressed_size
, 4096, &final_size
, workspace
);
3059 expected_status
= is_incomplete_chunk(test_lznt
[i
].compressed
, test_lznt
[i
].compressed_size
, TRUE
) ?
3060 test_lznt
[i
].status
: STATUS_SUCCESS
;
3061 ok(status
== expected_status
, "%d: got wrong status 0x%08x, expected 0x%08x\n", i
, status
, expected_status
);
3064 ok(final_size
== 0, "%d: got wrong final_size %u\n", i
, final_size
);
3065 ok(buf
[0] == 0x11, "%d: buf[4096] was modified\n", i
);
3070 #undef DECOMPRESS_BROKEN_FRAGMENT
3071 #undef DECOMPRESS_BROKEN_TRUNCATED
3073 struct critsect_locked_info
3075 CRITICAL_SECTION crit
;
3076 HANDLE semaphores
[2];
3079 static DWORD WINAPI
critsect_locked_thread(void *param
)
3081 struct critsect_locked_info
*info
= param
;
3084 ret
= pRtlIsCriticalSectionLocked(&info
->crit
);
3085 ok(ret
== TRUE
, "expected TRUE, got %u\n", ret
);
3086 ret
= pRtlIsCriticalSectionLockedByThread(&info
->crit
);
3087 ok(ret
== FALSE
, "expected FALSE, got %u\n", ret
);
3089 ReleaseSemaphore(info
->semaphores
[0], 1, NULL
);
3090 ret
= WaitForSingleObject(info
->semaphores
[1], 1000);
3091 ok(ret
== WAIT_OBJECT_0
, "expected WAIT_OBJECT_0, got %u\n", ret
);
3093 ret
= pRtlIsCriticalSectionLocked(&info
->crit
);
3094 ok(ret
== FALSE
, "expected FALSE, got %u\n", ret
);
3095 ret
= pRtlIsCriticalSectionLockedByThread(&info
->crit
);
3096 ok(ret
== FALSE
, "expected FALSE, got %u\n", ret
);
3098 EnterCriticalSection(&info
->crit
);
3100 ret
= pRtlIsCriticalSectionLocked(&info
->crit
);
3101 ok(ret
== TRUE
, "expected TRUE, got %u\n", ret
);
3102 ret
= pRtlIsCriticalSectionLockedByThread(&info
->crit
);
3103 ok(ret
== TRUE
, "expected TRUE, got %u\n", ret
);
3105 ReleaseSemaphore(info
->semaphores
[0], 1, NULL
);
3106 ret
= WaitForSingleObject(info
->semaphores
[1], 1000);
3107 ok(ret
== WAIT_OBJECT_0
, "expected WAIT_OBJECT_0, got %u\n", ret
);
3109 LeaveCriticalSection(&info
->crit
);
3113 static void test_RtlIsCriticalSectionLocked(void)
3115 struct critsect_locked_info info
;
3119 if (!pRtlIsCriticalSectionLocked
|| !pRtlIsCriticalSectionLockedByThread
)
3121 win_skip("skipping RtlIsCriticalSectionLocked tests, required functions not available\n");
3125 InitializeCriticalSection(&info
.crit
);
3126 info
.semaphores
[0] = CreateSemaphoreW(NULL
, 0, 1, NULL
);
3127 ok(info
.semaphores
[0] != NULL
, "CreateSemaphore failed with %u\n", GetLastError());
3128 info
.semaphores
[1] = CreateSemaphoreW(NULL
, 0, 1, NULL
);
3129 ok(info
.semaphores
[1] != NULL
, "CreateSemaphore failed with %u\n", GetLastError());
3131 ret
= pRtlIsCriticalSectionLocked(&info
.crit
);
3132 ok(ret
== FALSE
, "expected FALSE, got %u\n", ret
);
3133 ret
= pRtlIsCriticalSectionLockedByThread(&info
.crit
);
3134 ok(ret
== FALSE
, "expected FALSE, got %u\n", ret
);
3136 EnterCriticalSection(&info
.crit
);
3138 ret
= pRtlIsCriticalSectionLocked(&info
.crit
);
3139 ok(ret
== TRUE
, "expected TRUE, got %u\n", ret
);
3140 ret
= pRtlIsCriticalSectionLockedByThread(&info
.crit
);
3141 ok(ret
== TRUE
, "expected TRUE, got %u\n", ret
);
3143 thread
= CreateThread(NULL
, 0, critsect_locked_thread
, &info
, 0, NULL
);
3144 ok(thread
!= NULL
, "CreateThread failed with %u\n", GetLastError());
3145 ret
= WaitForSingleObject(info
.semaphores
[0], 1000);
3146 ok(ret
== WAIT_OBJECT_0
, "expected WAIT_OBJECT_0, got %u\n", ret
);
3148 LeaveCriticalSection(&info
.crit
);
3150 ReleaseSemaphore(info
.semaphores
[1], 1, NULL
);
3151 ret
= WaitForSingleObject(info
.semaphores
[0], 1000);
3152 ok(ret
== WAIT_OBJECT_0
, "expected WAIT_OBJECT_0, got %u\n", ret
);
3154 ret
= pRtlIsCriticalSectionLocked(&info
.crit
);
3155 ok(ret
== TRUE
, "expected TRUE, got %u\n", ret
);
3156 ret
= pRtlIsCriticalSectionLockedByThread(&info
.crit
);
3157 ok(ret
== FALSE
, "expected FALSE, got %u\n", ret
);
3159 ReleaseSemaphore(info
.semaphores
[1], 1, NULL
);
3160 ret
= WaitForSingleObject(thread
, 1000);
3161 ok(ret
== WAIT_OBJECT_0
, "expected WAIT_OBJECT_0, got %u\n", ret
);
3163 CloseHandle(thread
);
3164 CloseHandle(info
.semaphores
[0]);
3165 CloseHandle(info
.semaphores
[1]);
3166 DeleteCriticalSection(&info
.crit
);
3169 static void test_RtlInitializeCriticalSectionEx(void)
3171 static const CRITICAL_SECTION_DEBUG
*no_debug
= (void *)~(ULONG_PTR
)0;
3172 CRITICAL_SECTION cs
;
3174 if (!pRtlInitializeCriticalSectionEx
)
3176 win_skip("RtlInitializeCriticalSectionEx is not available\n");
3180 memset(&cs
, 0x11, sizeof(cs
));
3181 pRtlInitializeCriticalSectionEx(&cs
, 0, 0);
3182 ok((cs
.DebugInfo
!= NULL
&& cs
.DebugInfo
!= no_debug
) || broken(cs
.DebugInfo
== no_debug
) /* >= Win 8 */,
3183 "expected DebugInfo != NULL and DebugInfo != ~0, got %p\n", cs
.DebugInfo
);
3184 ok(cs
.LockCount
== -1, "expected LockCount == -1, got %d\n", cs
.LockCount
);
3185 ok(cs
.RecursionCount
== 0, "expected RecursionCount == 0, got %d\n", cs
.RecursionCount
);
3186 ok(cs
.LockSemaphore
== NULL
, "expected LockSemaphore == NULL, got %p\n", cs
.LockSemaphore
);
3187 ok(cs
.SpinCount
== 0 || broken(cs
.SpinCount
!= 0) /* >= Win 8 */,
3188 "expected SpinCount == 0, got %ld\n", cs
.SpinCount
);
3189 RtlDeleteCriticalSection(&cs
);
3191 memset(&cs
, 0x11, sizeof(cs
));
3192 pRtlInitializeCriticalSectionEx(&cs
, 0, RTL_CRITICAL_SECTION_FLAG_NO_DEBUG_INFO
);
3193 ok(cs
.DebugInfo
== no_debug
, "expected DebugInfo == ~0, got %p\n", cs
.DebugInfo
);
3194 ok(cs
.LockCount
== -1, "expected LockCount == -1, got %d\n", cs
.LockCount
);
3195 ok(cs
.RecursionCount
== 0, "expected RecursionCount == 0, got %d\n", cs
.RecursionCount
);
3196 ok(cs
.LockSemaphore
== NULL
, "expected LockSemaphore == NULL, got %p\n", cs
.LockSemaphore
);
3197 ok(cs
.SpinCount
== 0 || broken(cs
.SpinCount
!= 0) /* >= Win 8 */,
3198 "expected SpinCount == 0, got %ld\n", cs
.SpinCount
);
3199 RtlDeleteCriticalSection(&cs
);
3202 static void test_RtlLeaveCriticalSection(void)
3204 RTL_CRITICAL_SECTION cs
;
3207 if (!pRtlInitializeCriticalSectionEx
)
3208 return; /* Skip winxp */
3210 status
= RtlInitializeCriticalSection(&cs
);
3211 ok(!status
, "RtlInitializeCriticalSection failed: %x\n", status
);
3213 status
= RtlEnterCriticalSection(&cs
);
3214 ok(!status
, "RtlEnterCriticalSection failed: %x\n", status
);
3216 ok(cs
.LockCount
== -2, "expected LockCount == -2, got %d\n", cs
.LockCount
);
3217 ok(cs
.RecursionCount
== 1, "expected RecursionCount == 1, got %d\n", cs
.RecursionCount
);
3218 ok(cs
.OwningThread
== ULongToHandle(GetCurrentThreadId()), "unexpected OwningThread\n");
3220 status
= RtlLeaveCriticalSection(&cs
);
3221 ok(!status
, "RtlLeaveCriticalSection failed: %x\n", status
);
3222 ok(cs
.LockCount
== -1, "expected LockCount == -1, got %d\n", cs
.LockCount
);
3223 ok(cs
.RecursionCount
== 0, "expected RecursionCount == 0, got %d\n", cs
.RecursionCount
);
3224 ok(!cs
.OwningThread
, "unexpected OwningThread %p\n", cs
.OwningThread
);
3227 * Trying to leave a section that wasn't acquired modifies RecursionCount to an invalid value,
3228 * but doesn't modify LockCount so that an attempt to enter the section later will work.
3230 status
= RtlLeaveCriticalSection(&cs
);
3231 ok(!status
, "RtlLeaveCriticalSection failed: %x\n", status
);
3232 ok(cs
.LockCount
== -1, "expected LockCount == -1, got %d\n", cs
.LockCount
);
3233 ok(cs
.RecursionCount
== -1, "expected RecursionCount == -1, got %d\n", cs
.RecursionCount
);
3234 ok(!cs
.OwningThread
, "unexpected OwningThread %p\n", cs
.OwningThread
);
3237 status
= RtlLeaveCriticalSection(&cs
);
3238 ok(!status
, "RtlLeaveCriticalSection failed: %x\n", status
);
3239 ok(cs
.LockCount
== -1, "expected LockCount == -1, got %d\n", cs
.LockCount
);
3240 ok(cs
.RecursionCount
== -2, "expected RecursionCount == -2, got %d\n", cs
.RecursionCount
);
3241 ok(!cs
.OwningThread
, "unexpected OwningThread %p\n", cs
.OwningThread
);
3243 /* entering section fixes RecursionCount */
3244 status
= RtlEnterCriticalSection(&cs
);
3245 ok(!status
, "RtlEnterCriticalSection failed: %x\n", status
);
3247 ok(cs
.LockCount
== -2, "expected LockCount == -2, got %d\n", cs
.LockCount
);
3248 ok(cs
.RecursionCount
== 1, "expected RecursionCount == 1, got %d\n", cs
.RecursionCount
);
3249 ok(cs
.OwningThread
== ULongToHandle(GetCurrentThreadId()), "unexpected OwningThread\n");
3251 status
= RtlLeaveCriticalSection(&cs
);
3252 ok(!status
, "RtlLeaveCriticalSection failed: %x\n", status
);
3253 ok(cs
.LockCount
== -1, "expected LockCount == -1, got %d\n", cs
.LockCount
);
3254 ok(cs
.RecursionCount
== 0, "expected RecursionCount == 0, got %d\n", cs
.RecursionCount
);
3255 ok(!cs
.OwningThread
, "unexpected OwningThread %p\n", cs
.OwningThread
);
3257 status
= RtlDeleteCriticalSection(&cs
);
3258 ok(!status
, "RtlDeleteCriticalSection failed: %x\n", status
);
3261 struct ldr_enum_context
3268 static void WINAPI
ldr_enum_callback(LDR_MODULE
*module
, void *context
, BOOLEAN
*stop
)
3270 static const WCHAR ntdllW
[] = {'n','t','d','l','l','.','d','l','l',0};
3271 struct ldr_enum_context
*ctx
= context
;
3273 if (!lstrcmpiW(module
->BaseDllName
.Buffer
, ntdllW
))
3280 static void test_LdrEnumerateLoadedModules(void)
3282 struct ldr_enum_context ctx
;
3285 if (!pLdrEnumerateLoadedModules
)
3287 win_skip("LdrEnumerateLoadedModules not available\n");
3294 status
= pLdrEnumerateLoadedModules(NULL
, ldr_enum_callback
, &ctx
);
3295 ok(status
== STATUS_SUCCESS
, "LdrEnumerateLoadedModules failed with %08x\n", status
);
3296 ok(ctx
.count
> 1, "Expected more than one module, got %d\n", ctx
.count
);
3297 ok(ctx
.found
, "Could not find ntdll in list of modules\n");
3301 status
= pLdrEnumerateLoadedModules(NULL
, ldr_enum_callback
, &ctx
);
3302 ok(status
== STATUS_SUCCESS
, "LdrEnumerateLoadedModules failed with %08x\n", status
);
3303 ok(ctx
.count
== 1, "Expected exactly one module, got %d\n", ctx
.count
);
3305 status
= pLdrEnumerateLoadedModules((void *)0x1, ldr_enum_callback
, (void *)0xdeadbeef);
3306 ok(status
== STATUS_INVALID_PARAMETER
, "expected STATUS_INVALID_PARAMETER, got 0x%08x\n", status
);
3308 status
= pLdrEnumerateLoadedModules((void *)0xdeadbeef, ldr_enum_callback
, (void *)0xdeadbeef);
3309 ok(status
== STATUS_INVALID_PARAMETER
, "expected STATUS_INVALID_PARAMETER, got 0x%08x\n", status
);
3311 status
= pLdrEnumerateLoadedModules(NULL
, NULL
, (void *)0xdeadbeef);
3312 ok(status
== STATUS_INVALID_PARAMETER
, "expected STATUS_INVALID_PARAMETER, got 0x%08x\n", status
);
3315 static void test_RtlMakeSelfRelativeSD(void)
3317 char buf
[sizeof(SECURITY_DESCRIPTOR_RELATIVE
) + 4];
3318 SECURITY_DESCRIPTOR_RELATIVE
*sd_rel
= (SECURITY_DESCRIPTOR_RELATIVE
*)buf
;
3319 SECURITY_DESCRIPTOR sd
;
3323 if (!pRtlMakeSelfRelativeSD
|| !pRtlAbsoluteToSelfRelativeSD
)
3325 win_skip( "RtlMakeSelfRelativeSD/RtlAbsoluteToSelfRelativeSD not available\n" );
3329 memset( &sd
, 0, sizeof(sd
) );
3330 sd
.Revision
= SECURITY_DESCRIPTOR_REVISION
;
3333 status
= pRtlMakeSelfRelativeSD( &sd
, NULL
, &len
);
3334 ok( status
== STATUS_BUFFER_TOO_SMALL
, "got %08x\n", status
);
3335 ok( len
== sizeof(*sd_rel
), "got %u\n", len
);
3338 status
= pRtlMakeSelfRelativeSD( &sd
, sd_rel
, &len
);
3339 ok( status
== STATUS_SUCCESS
, "got %08x\n", status
);
3340 ok( len
== sizeof(*sd_rel
) + 4, "got %u\n", len
);
3343 status
= pRtlAbsoluteToSelfRelativeSD( &sd
, NULL
, &len
);
3344 ok( status
== STATUS_BUFFER_TOO_SMALL
, "got %08x\n", status
);
3345 ok( len
== sizeof(*sd_rel
), "got %u\n", len
);
3348 status
= pRtlAbsoluteToSelfRelativeSD( &sd
, sd_rel
, &len
);
3349 ok( status
== STATUS_SUCCESS
, "got %08x\n", status
);
3350 ok( len
== sizeof(*sd_rel
) + 4, "got %u\n", len
);
3352 sd
.Control
= SE_SELF_RELATIVE
;
3353 status
= pRtlMakeSelfRelativeSD( &sd
, sd_rel
, &len
);
3354 ok( status
== STATUS_SUCCESS
, "got %08x\n", status
);
3355 ok( len
== sizeof(*sd_rel
) + 4, "got %u\n", len
);
3357 status
= pRtlAbsoluteToSelfRelativeSD( &sd
, sd_rel
, &len
);
3358 ok( status
== STATUS_BAD_DESCRIPTOR_FORMAT
, "got %08x\n", status
);
3361 static DWORD (CALLBACK
*orig_entry
)(HMODULE
,DWORD
,LPVOID
);
3362 static DWORD
*dll_main_data
;
3364 static inline void *get_rva( HMODULE module
, DWORD va
)
3366 return (void *)((char *)module
+ va
);
3369 static void CALLBACK
ldr_notify_callback1(ULONG reason
, LDR_DLL_NOTIFICATION_DATA
*data
, void *context
)
3371 const IMAGE_IMPORT_DESCRIPTOR
*imports
;
3372 const IMAGE_THUNK_DATA
*import_list
;
3373 IMAGE_THUNK_DATA
*thunk_list
;
3374 DWORD
*calls
= context
;
3383 if (!lstrcmpiW(data
->Loaded
.BaseDllName
->Buffer
, expected_dll
))
3386 ok(data
->Loaded
.Flags
== 0, "Expected flags 0, got %x\n", data
->Loaded
.Flags
);
3387 ok(!lstrcmpiW(data
->Loaded
.BaseDllName
->Buffer
, expected_dll
), "Expected %s, got %s\n",
3388 wine_dbgstr_w(expected_dll
), wine_dbgstr_w(data
->Loaded
.BaseDllName
->Buffer
));
3389 ok(!!data
->Loaded
.DllBase
, "Expected non zero base address\n");
3390 ok(data
->Loaded
.SizeOfImage
, "Expected non zero image size\n");
3392 /* expect module to be last module listed in LdrData load order list */
3393 mark
= &NtCurrentTeb()->Peb
->LdrData
->InMemoryOrderModuleList
;
3394 mod
= CONTAINING_RECORD(mark
->Blink
, LDR_MODULE
, InMemoryOrderModuleList
);
3395 ok(mod
->BaseAddress
== data
->Loaded
.DllBase
, "Expected base address %p, got %p\n",
3396 data
->Loaded
.DllBase
, mod
->BaseAddress
);
3397 ok(!lstrcmpiW(mod
->BaseDllName
.Buffer
, expected_dll
), "Expected %s, got %s\n",
3398 wine_dbgstr_w(expected_dll
), wine_dbgstr_w(mod
->BaseDllName
.Buffer
));
3400 /* show that imports have already been resolved */
3401 imports
= RtlImageDirectoryEntryToData(data
->Loaded
.DllBase
, TRUE
, IMAGE_DIRECTORY_ENTRY_IMPORT
, &size
);
3402 ok(!!imports
, "Expected dll to have imports\n");
3404 for (i
= 0; imports
[i
].Name
; i
++)
3406 thunk_list
= get_rva(data
->Loaded
.DllBase
, (DWORD
)imports
[i
].FirstThunk
);
3407 if (imports
[i
].OriginalFirstThunk
)
3408 import_list
= get_rva(data
->Loaded
.DllBase
, (DWORD
)imports
[i
].OriginalFirstThunk
);
3410 import_list
= thunk_list
;
3412 for (j
= 0; import_list
[j
].u1
.Ordinal
; j
++)
3414 ok(thunk_list
[j
].u1
.AddressOfData
> data
->Loaded
.SizeOfImage
,
3415 "Import has not been resolved: %p\n", (void*)thunk_list
[j
].u1
.Function
);
3420 static void CALLBACK
ldr_notify_callback2(ULONG reason
, LDR_DLL_NOTIFICATION_DATA
*data
, void *context
)
3422 DWORD
*calls
= context
;
3424 *calls
|= reason
+ 2;
3427 static BOOL WINAPI
fake_dll_main(HINSTANCE instance
, DWORD reason
, void* reserved
)
3429 if (reason
== DLL_PROCESS_ATTACH
)
3431 *dll_main_data
<<= 4;
3432 *dll_main_data
|= 3;
3434 else if (reason
== DLL_PROCESS_DETACH
)
3436 *dll_main_data
<<= 4;
3437 *dll_main_data
|= 4;
3439 return orig_entry(instance
, reason
, reserved
);
3442 static void CALLBACK
ldr_notify_callback_dll_main(ULONG reason
, LDR_DLL_NOTIFICATION_DATA
*data
, void *context
)
3444 DWORD
*calls
= context
;
3451 if (reason
!= LDR_DLL_NOTIFICATION_REASON_LOADED
)
3454 mark
= &NtCurrentTeb()->Peb
->LdrData
->InMemoryOrderModuleList
;
3455 mod
= CONTAINING_RECORD(mark
->Blink
, LDR_MODULE
, InMemoryOrderModuleList
);
3456 ok(mod
->BaseAddress
== data
->Loaded
.DllBase
, "Expected base address %p, got %p\n",
3457 data
->Loaded
.DllBase
, mod
->BaseAddress
);
3458 if (mod
->BaseAddress
!= data
->Loaded
.DllBase
)
3461 orig_entry
= mod
->EntryPoint
;
3462 mod
->EntryPoint
= fake_dll_main
;
3463 dll_main_data
= calls
;
3466 static BOOL WINAPI
fake_dll_main_fail(HINSTANCE instance
, DWORD reason
, void* reserved
)
3468 if (reason
== DLL_PROCESS_ATTACH
)
3470 *dll_main_data
<<= 4;
3471 *dll_main_data
|= 3;
3473 else if (reason
== DLL_PROCESS_DETACH
)
3475 *dll_main_data
<<= 4;
3476 *dll_main_data
|= 4;
3481 static void CALLBACK
ldr_notify_callback_fail(ULONG reason
, LDR_DLL_NOTIFICATION_DATA
*data
, void *context
)
3483 DWORD
*calls
= context
;
3490 if (reason
!= LDR_DLL_NOTIFICATION_REASON_LOADED
)
3493 mark
= &NtCurrentTeb()->Peb
->LdrData
->InMemoryOrderModuleList
;
3494 mod
= CONTAINING_RECORD(mark
->Blink
, LDR_MODULE
, InMemoryOrderModuleList
);
3495 ok(mod
->BaseAddress
== data
->Loaded
.DllBase
, "Expected base address %p, got %p\n",
3496 data
->Loaded
.DllBase
, mod
->BaseAddress
);
3497 if (mod
->BaseAddress
!= data
->Loaded
.DllBase
)
3500 orig_entry
= mod
->EntryPoint
;
3501 mod
->EntryPoint
= fake_dll_main_fail
;
3502 dll_main_data
= calls
;
3505 static void CALLBACK
ldr_notify_callback_imports(ULONG reason
, LDR_DLL_NOTIFICATION_DATA
*data
, void *context
)
3507 DWORD
*calls
= context
;
3509 if (reason
!= LDR_DLL_NOTIFICATION_REASON_LOADED
)
3512 if (!lstrcmpiW(data
->Loaded
.BaseDllName
->Buffer
, crypt32dllW
))
3518 if (!lstrcmpiW(data
->Loaded
.BaseDllName
->Buffer
, wintrustdllW
))
3525 static void test_LdrRegisterDllNotification(void)
3527 void *cookie
, *cookie2
;
3532 if (!pLdrRegisterDllNotification
|| !pLdrUnregisterDllNotification
)
3534 win_skip("Ldr(Un)RegisterDllNotification not available\n");
3538 mod
= LoadLibraryW(expected_dll
);
3542 expected_dll
= ws2_32dllW
; /* XP Default */
3545 status
= pLdrRegisterDllNotification(0, ldr_notify_callback1
, &calls
, &cookie
);
3546 ok(!status
, "Expected STATUS_SUCCESS, got %08x\n", status
);
3549 mod
= LoadLibraryW(expected_dll
);
3550 ok(!!mod
, "Failed to load library: %d\n", GetLastError());
3551 ok(calls
== LDR_DLL_NOTIFICATION_REASON_LOADED
, "Expected LDR_DLL_NOTIFICATION_REASON_LOADED, got %x\n", calls
);
3555 ok(calls
== LDR_DLL_NOTIFICATION_REASON_UNLOADED
, "Expected LDR_DLL_NOTIFICATION_REASON_UNLOADED, got %x\n", calls
);
3557 /* test order of callbacks */
3558 status
= pLdrRegisterDllNotification(0, ldr_notify_callback2
, &calls
, &cookie2
);
3559 ok(!status
, "Expected STATUS_SUCCESS, got %08x\n", status
);
3562 mod
= LoadLibraryW(expected_dll
);
3563 ok(!!mod
, "Failed to load library: %d\n", GetLastError());
3564 ok(calls
== 0x13, "Expected order 0x13, got %x\n", calls
);
3568 ok(calls
== 0x24, "Expected order 0x24, got %x\n", calls
);
3570 pLdrUnregisterDllNotification(cookie2
);
3571 pLdrUnregisterDllNotification(cookie
);
3573 /* test dll main order */
3574 status
= pLdrRegisterDllNotification(0, ldr_notify_callback_dll_main
, &calls
, &cookie
);
3575 ok(!status
, "Expected STATUS_SUCCESS, got %08x\n", status
);
3578 mod
= LoadLibraryW(expected_dll
);
3579 ok(!!mod
, "Failed to load library: %d\n", GetLastError());
3580 ok(calls
== 0x13, "Expected order 0x13, got %x\n", calls
);
3584 ok(calls
== 0x42, "Expected order 0x42, got %x\n", calls
);
3586 pLdrUnregisterDllNotification(cookie
);
3588 /* test dll main order */
3589 status
= pLdrRegisterDllNotification(0, ldr_notify_callback_fail
, &calls
, &cookie
);
3590 ok(!status
, "Expected STATUS_SUCCESS, got %08x\n", status
);
3593 mod
= LoadLibraryW(expected_dll
);
3594 ok(!mod
, "Expected library to fail loading\n");
3595 ok(calls
== 0x1342, "Expected order 0x1342, got %x\n", calls
);
3597 pLdrUnregisterDllNotification(cookie
);
3599 /* test dll with dependencies */
3600 status
= pLdrRegisterDllNotification(0, ldr_notify_callback_imports
, &calls
, &cookie
);
3601 ok(!status
, "Expected STATUS_SUCCESS, got %08x\n", status
);
3604 mod
= LoadLibraryW(wintrustdllW
);
3605 ok(!!mod
, "Failed to load library: %d\n", GetLastError());
3606 ok(calls
== 0x12 || calls
== 0x21, "got %x\n", calls
);
3609 pLdrUnregisterDllNotification(cookie
);
3616 test_RtlCompareMemory();
3617 test_RtlCompareMemoryUlong();
3618 test_RtlMoveMemory();
3619 test_RtlFillMemory();
3620 test_RtlFillMemoryUlong();
3621 test_RtlZeroMemory();
3622 test_RtlUlonglongByteSwap();
3625 test_RtlAreAllAccessesGranted();
3626 test_RtlAreAnyAccessesGranted();
3627 test_RtlComputeCrc32();
3628 test_HandleTables();
3629 test_RtlAllocateAndInitializeSid();
3630 test_RtlDeleteTimer();
3631 test_RtlThreadErrorMode();
3632 test_LdrProcessRelocationBlock();
3633 test_RtlIpv4AddressToString();
3634 test_RtlIpv4AddressToStringEx();
3635 test_RtlIpv4StringToAddress();
3636 test_RtlIpv4StringToAddressEx();
3637 test_RtlIpv6AddressToString();
3638 test_RtlIpv6AddressToStringEx();
3639 test_RtlIpv6StringToAddress();
3640 test_RtlIpv6StringToAddressEx();
3641 test_LdrAddRefDll();
3642 test_LdrLockLoaderLock();
3643 test_RtlCompressBuffer();
3644 test_RtlGetCompressionWorkSpaceSize();
3645 test_RtlDecompressBuffer();
3646 test_RtlIsCriticalSectionLocked();
3647 test_RtlInitializeCriticalSectionEx();
3648 test_RtlLeaveCriticalSection();
3649 test_LdrEnumerateLoadedModules();
3650 test_RtlMakeSelfRelativeSD();
3651 test_LdrRegisterDllNotification();