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"
29 #ifndef __WINE_WINTERNL_H
31 typedef struct _RTL_HANDLE
33 struct _RTL_HANDLE
* Next
;
36 typedef struct _RTL_HANDLE_TABLE
49 /* avoid #include <winsock2.h> */
51 #ifdef WORDS_BIGENDIAN
52 #define htons(s) ((USHORT)(s))
53 #else /* WORDS_BIGENDIAN */
54 static inline USHORT
__my_ushort_swap(USHORT s
)
56 return (s
>> 8) | (s
<< 8);
58 #define htons(s) __my_ushort_swap(s)
59 #endif /* WORDS_BIGENDIAN */
63 /* Function ptrs for ntdll calls */
64 static HMODULE hntdll
= 0;
65 static SIZE_T (WINAPI
*pRtlCompareMemory
)(LPCVOID
,LPCVOID
,SIZE_T
);
66 static SIZE_T (WINAPI
*pRtlCompareMemoryUlong
)(PULONG
, SIZE_T
, ULONG
);
67 static NTSTATUS (WINAPI
*pRtlDeleteTimer
)(HANDLE
, HANDLE
, HANDLE
);
68 static VOID (WINAPI
*pRtlMoveMemory
)(LPVOID
,LPCVOID
,SIZE_T
);
69 static VOID (WINAPI
*pRtlFillMemory
)(LPVOID
,SIZE_T
,BYTE
);
70 static VOID (WINAPI
*pRtlFillMemoryUlong
)(LPVOID
,SIZE_T
,ULONG
);
71 static VOID (WINAPI
*pRtlZeroMemory
)(LPVOID
,SIZE_T
);
72 static ULONGLONG (WINAPIV
*pRtlUlonglongByteSwap
)(ULONGLONG source
);
73 static ULONG (WINAPI
*pRtlUniform
)(PULONG
);
74 static ULONG (WINAPI
*pRtlRandom
)(PULONG
);
75 static BOOLEAN (WINAPI
*pRtlAreAllAccessesGranted
)(ACCESS_MASK
, ACCESS_MASK
);
76 static BOOLEAN (WINAPI
*pRtlAreAnyAccessesGranted
)(ACCESS_MASK
, ACCESS_MASK
);
77 static DWORD (WINAPI
*pRtlComputeCrc32
)(DWORD
,const BYTE
*,INT
);
78 static void (WINAPI
* pRtlInitializeHandleTable
)(ULONG
, ULONG
, RTL_HANDLE_TABLE
*);
79 static BOOLEAN (WINAPI
* pRtlIsValidIndexHandle
)(const RTL_HANDLE_TABLE
*, ULONG
, RTL_HANDLE
**);
80 static NTSTATUS (WINAPI
* pRtlDestroyHandleTable
)(RTL_HANDLE_TABLE
*);
81 static RTL_HANDLE
* (WINAPI
* pRtlAllocateHandle
)(RTL_HANDLE_TABLE
*, ULONG
*);
82 static BOOLEAN (WINAPI
* pRtlFreeHandle
)(RTL_HANDLE_TABLE
*, RTL_HANDLE
*);
83 static NTSTATUS (WINAPI
*pRtlAllocateAndInitializeSid
)(PSID_IDENTIFIER_AUTHORITY
,BYTE
,DWORD
,DWORD
,DWORD
,DWORD
,DWORD
,DWORD
,DWORD
,DWORD
,PSID
*);
84 static NTSTATUS (WINAPI
*pRtlFreeSid
)(PSID
);
85 static struct _TEB
* (WINAPI
*pNtCurrentTeb
)(void);
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
*pLdrAddRefDll
)(ULONG
, HMODULE
);
93 static NTSTATUS (WINAPI
*pLdrLockLoaderLock
)(ULONG
, ULONG
*, ULONG_PTR
*);
94 static NTSTATUS (WINAPI
*pLdrUnlockLoaderLock
)(ULONG
, ULONG_PTR
);
95 static NTSTATUS (WINAPI
*pRtlGetCompressionWorkSpaceSize
)(USHORT
, PULONG
, PULONG
);
96 static NTSTATUS (WINAPI
*pRtlDecompressBuffer
)(USHORT
, PUCHAR
, ULONG
, const UCHAR
*, ULONG
, PULONG
);
97 static NTSTATUS (WINAPI
*pRtlDecompressFragment
)(USHORT
, PUCHAR
, ULONG
, const UCHAR
*, ULONG
, ULONG
, PULONG
, PVOID
);
98 static NTSTATUS (WINAPI
*pRtlCompressBuffer
)(USHORT
, const UCHAR
*, ULONG
, PUCHAR
, ULONG
, ULONG
, PULONG
, PVOID
);
99 static BOOL (WINAPI
*pRtlIsCriticalSectionLocked
)(CRITICAL_SECTION
*);
100 static BOOL (WINAPI
*pRtlIsCriticalSectionLockedByThread
)(CRITICAL_SECTION
*);
101 static NTSTATUS (WINAPI
*pRtlInitializeCriticalSectionEx
)(CRITICAL_SECTION
*, ULONG
, ULONG
);
103 static HMODULE hkernel32
= 0;
104 static BOOL (WINAPI
*pIsWow64Process
)(HANDLE
, PBOOL
);
108 static const char* src_src
= "This is a test!"; /* 16 bytes long, incl NUL */
109 static ULONG src_aligned_block
[4];
110 static ULONG dest_aligned_block
[32];
111 static const char *src
= (const char*)src_aligned_block
;
112 static char* dest
= (char*)dest_aligned_block
;
114 static void InitFunctionPtrs(void)
116 hntdll
= LoadLibraryA("ntdll.dll");
117 ok(hntdll
!= 0, "LoadLibrary failed\n");
119 pRtlCompareMemory
= (void *)GetProcAddress(hntdll
, "RtlCompareMemory");
120 pRtlCompareMemoryUlong
= (void *)GetProcAddress(hntdll
, "RtlCompareMemoryUlong");
121 pRtlDeleteTimer
= (void *)GetProcAddress(hntdll
, "RtlDeleteTimer");
122 pRtlMoveMemory
= (void *)GetProcAddress(hntdll
, "RtlMoveMemory");
123 pRtlFillMemory
= (void *)GetProcAddress(hntdll
, "RtlFillMemory");
124 pRtlFillMemoryUlong
= (void *)GetProcAddress(hntdll
, "RtlFillMemoryUlong");
125 pRtlZeroMemory
= (void *)GetProcAddress(hntdll
, "RtlZeroMemory");
126 pRtlUlonglongByteSwap
= (void *)GetProcAddress(hntdll
, "RtlUlonglongByteSwap");
127 pRtlUniform
= (void *)GetProcAddress(hntdll
, "RtlUniform");
128 pRtlRandom
= (void *)GetProcAddress(hntdll
, "RtlRandom");
129 pRtlAreAllAccessesGranted
= (void *)GetProcAddress(hntdll
, "RtlAreAllAccessesGranted");
130 pRtlAreAnyAccessesGranted
= (void *)GetProcAddress(hntdll
, "RtlAreAnyAccessesGranted");
131 pRtlComputeCrc32
= (void *)GetProcAddress(hntdll
, "RtlComputeCrc32");
132 pRtlInitializeHandleTable
= (void *)GetProcAddress(hntdll
, "RtlInitializeHandleTable");
133 pRtlIsValidIndexHandle
= (void *)GetProcAddress(hntdll
, "RtlIsValidIndexHandle");
134 pRtlDestroyHandleTable
= (void *)GetProcAddress(hntdll
, "RtlDestroyHandleTable");
135 pRtlAllocateHandle
= (void *)GetProcAddress(hntdll
, "RtlAllocateHandle");
136 pRtlFreeHandle
= (void *)GetProcAddress(hntdll
, "RtlFreeHandle");
137 pRtlAllocateAndInitializeSid
= (void *)GetProcAddress(hntdll
, "RtlAllocateAndInitializeSid");
138 pRtlFreeSid
= (void *)GetProcAddress(hntdll
, "RtlFreeSid");
139 pNtCurrentTeb
= (void *)GetProcAddress(hntdll
, "NtCurrentTeb");
140 pRtlGetThreadErrorMode
= (void *)GetProcAddress(hntdll
, "RtlGetThreadErrorMode");
141 pRtlSetThreadErrorMode
= (void *)GetProcAddress(hntdll
, "RtlSetThreadErrorMode");
142 pLdrProcessRelocationBlock
= (void *)GetProcAddress(hntdll
, "LdrProcessRelocationBlock");
143 pRtlIpv4AddressToStringA
= (void *)GetProcAddress(hntdll
, "RtlIpv4AddressToStringA");
144 pRtlIpv4AddressToStringExA
= (void *)GetProcAddress(hntdll
, "RtlIpv4AddressToStringExA");
145 pRtlIpv4StringToAddressA
= (void *)GetProcAddress(hntdll
, "RtlIpv4StringToAddressA");
146 pLdrAddRefDll
= (void *)GetProcAddress(hntdll
, "LdrAddRefDll");
147 pLdrLockLoaderLock
= (void *)GetProcAddress(hntdll
, "LdrLockLoaderLock");
148 pLdrUnlockLoaderLock
= (void *)GetProcAddress(hntdll
, "LdrUnlockLoaderLock");
149 pRtlGetCompressionWorkSpaceSize
= (void *)GetProcAddress(hntdll
, "RtlGetCompressionWorkSpaceSize");
150 pRtlDecompressBuffer
= (void *)GetProcAddress(hntdll
, "RtlDecompressBuffer");
151 pRtlDecompressFragment
= (void *)GetProcAddress(hntdll
, "RtlDecompressFragment");
152 pRtlCompressBuffer
= (void *)GetProcAddress(hntdll
, "RtlCompressBuffer");
153 pRtlIsCriticalSectionLocked
= (void *)GetProcAddress(hntdll
, "RtlIsCriticalSectionLocked");
154 pRtlIsCriticalSectionLockedByThread
= (void *)GetProcAddress(hntdll
, "RtlIsCriticalSectionLockedByThread");
155 pRtlInitializeCriticalSectionEx
= (void *)GetProcAddress(hntdll
, "RtlInitializeCriticalSectionEx");
157 hkernel32
= LoadLibraryA("kernel32.dll");
158 ok(hkernel32
!= 0, "LoadLibrary failed\n");
160 pIsWow64Process
= (void *)GetProcAddress(hkernel32
, "IsWow64Process");
162 strcpy((char*)src_aligned_block
, src_src
);
163 ok(strlen(src
) == 15, "Source must be 16 bytes long!\n");
166 #define COMP(str1,str2,cmplen,len) size = pRtlCompareMemory(str1, str2, cmplen); \
167 ok(size == len, "Expected %ld, got %ld\n", size, (SIZE_T)len)
169 static void test_RtlCompareMemory(void)
173 if (!pRtlCompareMemory
)
175 win_skip("RtlCompareMemory is not available\n");
182 COMP(src
,src
,LEN
,LEN
);
184 COMP(src
,dest
,LEN
,0);
187 static void test_RtlCompareMemoryUlong(void)
192 if (!pRtlCompareMemoryUlong
)
194 win_skip("RtlCompareMemoryUlong is not available\n");
202 result
= pRtlCompareMemoryUlong(a
, 0, 0x0123);
203 ok(result
== 0, "RtlCompareMemoryUlong(%p, 0, 0x0123) returns %u, expected 0\n", a
, result
);
204 result
= pRtlCompareMemoryUlong(a
, 3, 0x0123);
205 ok(result
== 0, "RtlCompareMemoryUlong(%p, 3, 0x0123) returns %u, expected 0\n", a
, result
);
206 result
= pRtlCompareMemoryUlong(a
, 4, 0x0123);
207 ok(result
== 4, "RtlCompareMemoryUlong(%p, 4, 0x0123) returns %u, expected 4\n", a
, result
);
208 result
= pRtlCompareMemoryUlong(a
, 5, 0x0123);
209 ok(result
== 4, "RtlCompareMemoryUlong(%p, 5, 0x0123) returns %u, expected 4\n", a
, result
);
210 result
= pRtlCompareMemoryUlong(a
, 7, 0x0123);
211 ok(result
== 4, "RtlCompareMemoryUlong(%p, 7, 0x0123) returns %u, expected 4\n", a
, result
);
212 result
= pRtlCompareMemoryUlong(a
, 8, 0x0123);
213 ok(result
== 4, "RtlCompareMemoryUlong(%p, 8, 0x0123) returns %u, expected 4\n", a
, result
);
214 result
= pRtlCompareMemoryUlong(a
, 9, 0x0123);
215 ok(result
== 4, "RtlCompareMemoryUlong(%p, 9, 0x0123) returns %u, expected 4\n", a
, result
);
216 result
= pRtlCompareMemoryUlong(a
, 4, 0x0127);
217 ok(result
== 0, "RtlCompareMemoryUlong(%p, 4, 0x0127) returns %u, expected 0\n", a
, result
);
218 result
= pRtlCompareMemoryUlong(a
, 4, 0x7123);
219 ok(result
== 0, "RtlCompareMemoryUlong(%p, 4, 0x7123) returns %u, expected 0\n", a
, result
);
220 result
= pRtlCompareMemoryUlong(a
, 16, 0x4567);
221 ok(result
== 0, "RtlCompareMemoryUlong(%p, 16, 0x4567) returns %u, expected 0\n", a
, result
);
224 result
= pRtlCompareMemoryUlong(a
, 3, 0x0123);
225 ok(result
== 0, "RtlCompareMemoryUlong(%p, 3, 0x0123) returns %u, expected 0\n", a
, result
);
226 result
= pRtlCompareMemoryUlong(a
, 4, 0x0123);
227 ok(result
== 4, "RtlCompareMemoryUlong(%p, 4, 0x0123) returns %u, expected 4\n", a
, result
);
228 result
= pRtlCompareMemoryUlong(a
, 5, 0x0123);
229 ok(result
== 4, "RtlCompareMemoryUlong(%p, 5, 0x0123) returns %u, expected 4\n", a
, result
);
230 result
= pRtlCompareMemoryUlong(a
, 7, 0x0123);
231 ok(result
== 4, "RtlCompareMemoryUlong(%p, 7, 0x0123) returns %u, expected 4\n", a
, result
);
232 result
= pRtlCompareMemoryUlong(a
, 8, 0x0123);
233 ok(result
== 8, "RtlCompareMemoryUlong(%p, 8, 0x0123) returns %u, expected 8\n", a
, result
);
234 result
= pRtlCompareMemoryUlong(a
, 9, 0x0123);
235 ok(result
== 8, "RtlCompareMemoryUlong(%p, 9, 0x0123) returns %u, expected 8\n", a
, result
);
238 #define COPY(len) memset(dest,0,sizeof(dest_aligned_block)); pRtlMoveMemory(dest, src, len)
239 #define CMP(str) ok(strcmp(dest,str) == 0, "Expected '%s', got '%s'\n", str, dest)
241 static void test_RtlMoveMemory(void)
245 win_skip("RtlMoveMemory is not available\n");
249 /* Length should be in bytes and not rounded. Use strcmp to ensure we
250 * didn't write past the end (it checks for the final NUL left by memset)
256 COPY(4); CMP("This");
257 COPY(5); CMP("This ");
258 COPY(6); CMP("This i");
259 COPY(7); CMP("This is");
260 COPY(8); CMP("This is ");
261 COPY(9); CMP("This is a");
264 strcpy(dest
, src
); pRtlMoveMemory(dest
, dest
+ 1, strlen(src
) - 1);
265 CMP("his is a test!!");
266 strcpy(dest
, src
); pRtlMoveMemory(dest
+ 1, dest
, strlen(src
));
267 CMP("TThis is a test!");
270 #define FILL(len) memset(dest,0,sizeof(dest_aligned_block)); strcpy(dest, src); pRtlFillMemory(dest,len,'x')
272 static void test_RtlFillMemory(void)
276 win_skip("RtlFillMemory is not available\n");
280 /* Length should be in bytes and not rounded. Use strcmp to ensure we
281 * didn't write past the end (the remainder of the string should match)
283 FILL(0); CMP("This is a test!");
284 FILL(1); CMP("xhis is a test!");
285 FILL(2); CMP("xxis is a test!");
286 FILL(3); CMP("xxxs is a test!");
287 FILL(4); CMP("xxxx is a test!");
288 FILL(5); CMP("xxxxxis a test!");
289 FILL(6); CMP("xxxxxxs a test!");
290 FILL(7); CMP("xxxxxxx a test!");
291 FILL(8); CMP("xxxxxxxxa test!");
292 FILL(9); CMP("xxxxxxxxx test!");
295 #define LFILL(len) memset(dest,0,sizeof(dest_aligned_block)); strcpy(dest, src); pRtlFillMemoryUlong(dest,len,val)
297 static void test_RtlFillMemoryUlong(void)
299 ULONG val
= ('x' << 24) | ('x' << 16) | ('x' << 8) | 'x';
300 if (!pRtlFillMemoryUlong
)
302 win_skip("RtlFillMemoryUlong is not available\n");
306 /* Length should be in bytes and not rounded. Use strcmp to ensure we
307 * didn't write past the end (the remainder of the string should match)
309 LFILL(0); CMP("This is a test!");
310 LFILL(1); CMP("This is a test!");
311 LFILL(2); CMP("This is a test!");
312 LFILL(3); CMP("This is a test!");
313 LFILL(4); CMP("xxxx is a test!");
314 LFILL(5); CMP("xxxx is a test!");
315 LFILL(6); CMP("xxxx is a test!");
316 LFILL(7); CMP("xxxx is a test!");
317 LFILL(8); CMP("xxxxxxxxa test!");
318 LFILL(9); CMP("xxxxxxxxa test!");
321 #define ZERO(len) memset(dest,0,sizeof(dest_aligned_block)); strcpy(dest, src); pRtlZeroMemory(dest,len)
322 #define MCMP(str) ok(memcmp(dest,str,LEN) == 0, "Memcmp failed\n")
324 static void test_RtlZeroMemory(void)
328 win_skip("RtlZeroMemory is not available\n");
332 /* Length should be in bytes and not rounded. */
333 ZERO(0); MCMP("This is a test!");
334 ZERO(1); MCMP("\0his is a test!");
335 ZERO(2); MCMP("\0\0is is a test!");
336 ZERO(3); MCMP("\0\0\0s is a test!");
337 ZERO(4); MCMP("\0\0\0\0 is a test!");
338 ZERO(5); MCMP("\0\0\0\0\0is a test!");
339 ZERO(6); MCMP("\0\0\0\0\0\0s a test!");
340 ZERO(7); MCMP("\0\0\0\0\0\0\0 a test!");
341 ZERO(8); MCMP("\0\0\0\0\0\0\0\0a test!");
342 ZERO(9); MCMP("\0\0\0\0\0\0\0\0\0 test!");
345 static void test_RtlUlonglongByteSwap(void)
349 if ( !pRtlUlonglongByteSwap
)
351 win_skip("RtlUlonglongByteSwap is not available\n");
355 if ( pRtlUlonglongByteSwap( 0 ) != 0 )
357 win_skip("Broken RtlUlonglongByteSwap in win2k\n");
361 result
= pRtlUlonglongByteSwap( ((ULONGLONG
)0x76543210 << 32) | 0x87654321 );
362 ok( (((ULONGLONG
)0x21436587 << 32) | 0x10325476) == result
,
363 "RtlUlonglongByteSwap(0x7654321087654321) returns 0x%x%08x, expected 0x2143658710325476\n",
364 (DWORD
)(result
>> 32), (DWORD
)result
);
368 static void test_RtlUniform(void)
378 win_skip("RtlUniform is not available\n");
383 * According to the documentation RtlUniform is using D.H. Lehmer's 1948
384 * algorithm. This algorithm is:
386 * seed = (seed * const_1 + const_2) % const_3;
388 * According to the documentation the random number is distributed over
389 * [0..MAXLONG]. Therefore const_3 is MAXLONG + 1:
391 * seed = (seed * const_1 + const_2) % (MAXLONG + 1);
393 * Because MAXLONG is 0x7fffffff (and MAXLONG + 1 is 0x80000000) the
394 * algorithm can be expressed without division as:
396 * seed = (seed * const_1 + const_2) & MAXLONG;
398 * To find out const_2 we just call RtlUniform with seed set to 0:
401 expected
= 0x7fffffc3;
402 result
= pRtlUniform(&seed
);
403 ok(result
== expected
,
404 "RtlUniform(&seed (seed == 0)) returns %x, expected %x\n",
407 * The algorithm is now:
409 * seed = (seed * const_1 + 0x7fffffc3) & MAXLONG;
411 * To find out const_1 we can use:
413 * const_1 = RtlUniform(1) - 0x7fffffc3;
415 * If that does not work a search loop can try all possible values of
416 * const_1 and compare to the result to RtlUniform(1).
417 * This way we find out that const_1 is 0xffffffed.
419 * For seed = 1 the const_2 is 0x7fffffc4:
422 expected
= seed
* 0xffffffed + 0x7fffffc3 + 1;
423 result
= pRtlUniform(&seed
);
424 ok(result
== expected
,
425 "RtlUniform(&seed (seed == 1)) returns %x, expected %x\n",
428 * For seed = 2 the const_2 is 0x7fffffc3:
431 expected
= seed
* 0xffffffed + 0x7fffffc3;
432 result
= pRtlUniform(&seed
);
435 * Windows Vista uses different algorithms, so skip the rest of the tests
436 * until that is figured out. Trace output for the failures is about 10.5 MB!
439 if (result
== 0x7fffff9f) {
440 skip("Most likely running on Windows Vista which uses a different algorithm\n");
444 ok(result
== expected
,
445 "RtlUniform(&seed (seed == 2)) returns %x, expected %x\n",
449 * More tests show that if seed is odd the result must be incremented by 1:
452 expected
= seed
* 0xffffffed + 0x7fffffc3 + (seed
& 1);
453 result
= pRtlUniform(&seed
);
454 ok(result
== expected
,
455 "RtlUniform(&seed (seed == 3)) returns %x, expected %x\n",
459 expected
= seed
* 0xffffffed + 0x7fffffc3;
460 result
= pRtlUniform(&seed
);
461 ok(result
== expected
,
462 "RtlUniform(&seed (seed == 0x6bca1aa)) returns %x, expected %x\n",
466 expected
= seed
* 0xffffffed + 0x7fffffc3 + 1;
467 result
= pRtlUniform(&seed
);
468 ok(result
== expected
,
469 "RtlUniform(&seed (seed == 0x6bca1ab)) returns %x, expected %x\n",
472 * When seed is 0x6bca1ac there is an exception:
475 expected
= seed
* 0xffffffed + 0x7fffffc3 + 2;
476 result
= pRtlUniform(&seed
);
477 ok(result
== expected
,
478 "RtlUniform(&seed (seed == 0x6bca1ac)) returns %x, expected %x\n",
481 * Note that up to here const_3 is not used
482 * (the highest bit of the result is not set).
484 * Starting with 0x6bca1ad: If seed is even the result must be incremented by 1:
487 expected
= (seed
* 0xffffffed + 0x7fffffc3) & MAXLONG
;
488 result
= pRtlUniform(&seed
);
489 ok(result
== expected
,
490 "RtlUniform(&seed (seed == 0x6bca1ad)) returns %x, expected %x\n",
494 expected
= (seed
* 0xffffffed + 0x7fffffc3 + 1) & MAXLONG
;
495 result
= pRtlUniform(&seed
);
496 ok(result
== expected
,
497 "RtlUniform(&seed (seed == 0x6bca1ae)) returns %x, expected %x\n",
500 * There are several ranges where for odd or even seed the result must be
501 * incremented by 1. You can see this ranges in the following test.
503 * For a full test use one of the following loop heads:
505 * for (num = 0; num <= 0xffffffff; num++) {
510 * for (num = 0; num <= 0xffffffff; num++) {
514 for (num
= 0; num
<= 100000; num
++) {
516 expected
= seed
* 0xffffffed + 0x7fffffc3;
517 if (seed
< 0x6bca1ac) {
518 expected
= expected
+ (seed
& 1);
519 } else if (seed
== 0x6bca1ac) {
520 expected
= (expected
+ 2) & MAXLONG
;
521 } else if (seed
< 0xd79435c) {
522 expected
= (expected
+ (~seed
& 1)) & MAXLONG
;
523 } else if (seed
< 0x1435e50b) {
524 expected
= expected
+ (seed
& 1);
525 } else if (seed
< 0x1af286ba) {
526 expected
= (expected
+ (~seed
& 1)) & MAXLONG
;
527 } else if (seed
< 0x21af2869) {
528 expected
= expected
+ (seed
& 1);
529 } else if (seed
< 0x286bca18) {
530 expected
= (expected
+ (~seed
& 1)) & MAXLONG
;
531 } else if (seed
< 0x2f286bc7) {
532 expected
= expected
+ (seed
& 1);
533 } else if (seed
< 0x35e50d77) {
534 expected
= (expected
+ (~seed
& 1)) & MAXLONG
;
535 } else if (seed
< 0x3ca1af26) {
536 expected
= expected
+ (seed
& 1);
537 } else if (seed
< 0x435e50d5) {
538 expected
= (expected
+ (~seed
& 1)) & MAXLONG
;
539 } else if (seed
< 0x4a1af284) {
540 expected
= expected
+ (seed
& 1);
541 } else if (seed
< 0x50d79433) {
542 expected
= (expected
+ (~seed
& 1)) & MAXLONG
;
543 } else if (seed
< 0x579435e2) {
544 expected
= expected
+ (seed
& 1);
545 } else if (seed
< 0x5e50d792) {
546 expected
= (expected
+ (~seed
& 1)) & MAXLONG
;
547 } else if (seed
< 0x650d7941) {
548 expected
= expected
+ (seed
& 1);
549 } else if (seed
< 0x6bca1af0) {
550 expected
= (expected
+ (~seed
& 1)) & MAXLONG
;
551 } else if (seed
< 0x7286bc9f) {
552 expected
= expected
+ (seed
& 1);
553 } else if (seed
< 0x79435e4e) {
554 expected
= (expected
+ (~seed
& 1)) & MAXLONG
;
555 } else if (seed
< 0x7ffffffd) {
556 expected
= expected
+ (seed
& 1);
557 } else if (seed
< 0x86bca1ac) {
558 expected
= (expected
+ (~seed
& 1)) & MAXLONG
;
559 } else if (seed
== 0x86bca1ac) {
560 expected
= (expected
+ 1) & MAXLONG
;
561 } else if (seed
< 0x8d79435c) {
562 expected
= expected
+ (seed
& 1);
563 } else if (seed
< 0x9435e50b) {
564 expected
= (expected
+ (~seed
& 1)) & MAXLONG
;
565 } else if (seed
< 0x9af286ba) {
566 expected
= expected
+ (seed
& 1);
567 } else if (seed
< 0xa1af2869) {
568 expected
= (expected
+ (~seed
& 1)) & MAXLONG
;
569 } else if (seed
< 0xa86bca18) {
570 expected
= expected
+ (seed
& 1);
571 } else if (seed
< 0xaf286bc7) {
572 expected
= (expected
+ (~seed
& 1)) & MAXLONG
;
573 } else if (seed
== 0xaf286bc7) {
574 expected
= (expected
+ 2) & MAXLONG
;
575 } else if (seed
< 0xb5e50d77) {
576 expected
= expected
+ (seed
& 1);
577 } else if (seed
< 0xbca1af26) {
578 expected
= (expected
+ (~seed
& 1)) & MAXLONG
;
579 } else if (seed
< 0xc35e50d5) {
580 expected
= expected
+ (seed
& 1);
581 } else if (seed
< 0xca1af284) {
582 expected
= (expected
+ (~seed
& 1)) & MAXLONG
;
583 } else if (seed
< 0xd0d79433) {
584 expected
= expected
+ (seed
& 1);
585 } else if (seed
< 0xd79435e2) {
586 expected
= (expected
+ (~seed
& 1)) & MAXLONG
;
587 } else if (seed
< 0xde50d792) {
588 expected
= expected
+ (seed
& 1);
589 } else if (seed
< 0xe50d7941) {
590 expected
= (expected
+ (~seed
& 1)) & MAXLONG
;
591 } else if (seed
< 0xebca1af0) {
592 expected
= expected
+ (seed
& 1);
593 } else if (seed
< 0xf286bc9f) {
594 expected
= (expected
+ (~seed
& 1)) & MAXLONG
;
595 } else if (seed
< 0xf9435e4e) {
596 expected
= expected
+ (seed
& 1);
597 } else if (seed
< 0xfffffffd) {
598 expected
= (expected
+ (~seed
& 1)) & MAXLONG
;
600 expected
= expected
+ (seed
& 1);
603 result
= pRtlUniform(&seed
);
604 ok(result
== expected
,
605 "test: 0x%x%08x RtlUniform(&seed (seed == %x)) returns %x, expected %x\n",
606 (DWORD
)(num
>> 32), (DWORD
)num
, seed_bak
, result
, expected
);
608 "test: 0x%x%08x RtlUniform(&seed (seed == %x)) sets seed to %x, expected %x\n",
609 (DWORD
)(num
>> 32), (DWORD
)num
, seed_bak
, result
, expected
);
612 * Further investigation shows: In the different regions the highest bit
613 * is set or cleared when even or odd seeds need an increment by 1.
614 * This leads to a simplified algorithm:
616 * seed = seed * 0xffffffed + 0x7fffffc3;
617 * if (seed == 0xffffffff || seed == 0x7ffffffe) {
618 * seed = (seed + 2) & MAXLONG;
619 * } else if (seed == 0x7fffffff) {
621 * } else if ((seed & 0x80000000) == 0) {
622 * seed = seed + (~seed & 1);
624 * seed = (seed + (seed & 1)) & MAXLONG;
627 * This is also the algorithm used for RtlUniform of wine (see dlls/ntdll/rtl.c).
629 * Now comes the funny part:
630 * It took me one weekend, to find the complicated algorithm and one day more,
631 * to find the simplified algorithm. Several weeks later I found out: The value
632 * MAXLONG (=0x7fffffff) is never returned, neither with the native function
633 * nor with the simplified algorithm. In reality the native function and our
634 * function return a random number distributed over [0..MAXLONG-1]. Note
635 * that this is different from what native documentation states [0..MAXLONG].
636 * Expressed with D.H. Lehmer's 1948 algorithm it looks like:
638 * seed = (seed * const_1 + const_2) % MAXLONG;
640 * Further investigations show that the real algorithm is:
642 * seed = (seed * 0x7fffffed + 0x7fffffc3) % MAXLONG;
644 * This is checked with the test below:
647 for (num
= 0; num
<= 100000; num
++) {
648 expected
= (seed
* 0x7fffffed + 0x7fffffc3) % 0x7fffffff;
650 result
= pRtlUniform(&seed
);
651 ok(result
== expected
,
652 "test: 0x%x%08x RtlUniform(&seed (seed == %x)) returns %x, expected %x\n",
653 (DWORD
)(num
>> 32), (DWORD
)num
, seed_bak
, result
, expected
);
655 "test: 0x%x%08x RtlUniform(&seed (seed == %x)) sets seed to %x, expected %x\n",
656 (DWORD
)(num
>> 32), (DWORD
)num
, seed_bak
, result
, expected
);
659 * More tests show that RtlUniform does not return 0x7ffffffd for seed values
660 * in the range [0..MAXLONG-1]. Additionally 2 is returned twice. This shows
661 * that there is more than one cycle of generated randon numbers ...
666 static void test_RtlRandom(void)
674 win_skip("RtlRandom is not available\n");
679 for (i
= 0; i
< sizeof(res
) / sizeof(res
[0]); i
++)
681 res
[i
] = pRtlRandom(&seed
);
682 ok(seed
!= res
[i
], "%i: seed is same as res %x\n", i
, seed
);
683 for (j
= 0; j
< i
; j
++)
684 ok(res
[i
] != res
[j
], "res[%i] (%x) is same as res[%i] (%x)\n", j
, res
[j
], i
, res
[i
]);
690 ACCESS_MASK GrantedAccess
;
691 ACCESS_MASK DesiredAccess
;
695 static const all_accesses_t all_accesses
[] = {
696 {0xFEDCBA76, 0xFEDCBA76, 1},
697 {0x00000000, 0xFEDCBA76, 0},
698 {0xFEDCBA76, 0x00000000, 1},
699 {0x00000000, 0x00000000, 1},
700 {0xFEDCBA76, 0xFEDCBA70, 1},
701 {0xFEDCBA70, 0xFEDCBA76, 0},
702 {0xFEDCBA76, 0xFEDC8A76, 1},
703 {0xFEDC8A76, 0xFEDCBA76, 0},
704 {0xFEDCBA76, 0xC8C4B242, 1},
705 {0xC8C4B242, 0xFEDCBA76, 0},
707 #define NB_ALL_ACCESSES (sizeof(all_accesses)/sizeof(*all_accesses))
710 static void test_RtlAreAllAccessesGranted(void)
712 unsigned int test_num
;
715 if (!pRtlAreAllAccessesGranted
)
717 win_skip("RtlAreAllAccessesGranted is not available\n");
721 for (test_num
= 0; test_num
< NB_ALL_ACCESSES
; test_num
++) {
722 result
= pRtlAreAllAccessesGranted(all_accesses
[test_num
].GrantedAccess
,
723 all_accesses
[test_num
].DesiredAccess
);
724 ok(all_accesses
[test_num
].result
== result
,
725 "(test %d): RtlAreAllAccessesGranted(%08x, %08x) returns %d, expected %d\n",
726 test_num
, all_accesses
[test_num
].GrantedAccess
,
727 all_accesses
[test_num
].DesiredAccess
,
728 result
, all_accesses
[test_num
].result
);
734 ACCESS_MASK GrantedAccess
;
735 ACCESS_MASK DesiredAccess
;
739 static const any_accesses_t any_accesses
[] = {
740 {0xFEDCBA76, 0xFEDCBA76, 1},
741 {0x00000000, 0xFEDCBA76, 0},
742 {0xFEDCBA76, 0x00000000, 0},
743 {0x00000000, 0x00000000, 0},
744 {0xFEDCBA76, 0x01234589, 0},
745 {0x00040000, 0xFEDCBA76, 1},
746 {0x00040000, 0xFED8BA76, 0},
747 {0xFEDCBA76, 0x00040000, 1},
748 {0xFED8BA76, 0x00040000, 0},
750 #define NB_ANY_ACCESSES (sizeof(any_accesses)/sizeof(*any_accesses))
753 static void test_RtlAreAnyAccessesGranted(void)
755 unsigned int test_num
;
758 if (!pRtlAreAnyAccessesGranted
)
760 win_skip("RtlAreAnyAccessesGranted is not available\n");
764 for (test_num
= 0; test_num
< NB_ANY_ACCESSES
; test_num
++) {
765 result
= pRtlAreAnyAccessesGranted(any_accesses
[test_num
].GrantedAccess
,
766 any_accesses
[test_num
].DesiredAccess
);
767 ok(any_accesses
[test_num
].result
== result
,
768 "(test %d): RtlAreAnyAccessesGranted(%08x, %08x) returns %d, expected %d\n",
769 test_num
, any_accesses
[test_num
].GrantedAccess
,
770 any_accesses
[test_num
].DesiredAccess
,
771 result
, any_accesses
[test_num
].result
);
775 static void test_RtlComputeCrc32(void)
779 if (!pRtlComputeCrc32
)
781 win_skip("RtlComputeCrc32 is not available\n");
785 crc
= pRtlComputeCrc32(crc
, (const BYTE
*)src
, LEN
);
786 ok(crc
== 0x40861dc2,"Expected 0x40861dc2, got %8x\n", crc
);
790 typedef struct MY_HANDLE
792 RTL_HANDLE RtlHandle
;
796 static inline void RtlpMakeHandleAllocated(RTL_HANDLE
* Handle
)
798 ULONG_PTR
*AllocatedBit
= (ULONG_PTR
*)(&Handle
->Next
);
799 *AllocatedBit
= *AllocatedBit
| 1;
802 static void test_HandleTables(void)
807 MY_HANDLE
* MyHandle
;
808 RTL_HANDLE_TABLE HandleTable
;
810 if (!pRtlInitializeHandleTable
)
812 win_skip("RtlInitializeHandleTable is not available\n");
816 pRtlInitializeHandleTable(0x3FFF, sizeof(MY_HANDLE
), &HandleTable
);
817 MyHandle
= (MY_HANDLE
*)pRtlAllocateHandle(&HandleTable
, &Index
);
818 ok(MyHandle
!= NULL
, "RtlAllocateHandle failed\n");
819 RtlpMakeHandleAllocated(&MyHandle
->RtlHandle
);
821 result
= pRtlIsValidIndexHandle(&HandleTable
, Index
, (RTL_HANDLE
**)&MyHandle
);
822 ok(result
, "Handle %p wasn't valid\n", MyHandle
);
823 result
= pRtlFreeHandle(&HandleTable
, &MyHandle
->RtlHandle
);
824 ok(result
, "Couldn't free handle %p\n", MyHandle
);
825 status
= pRtlDestroyHandleTable(&HandleTable
);
826 ok(status
== STATUS_SUCCESS
, "RtlDestroyHandleTable failed with error 0x%08x\n", status
);
829 static void test_RtlAllocateAndInitializeSid(void)
832 SID_IDENTIFIER_AUTHORITY sia
= {{ 1, 2, 3, 4, 5, 6 }};
835 if (!pRtlAllocateAndInitializeSid
)
837 win_skip("RtlAllocateAndInitializeSid is not available\n");
841 ret
= pRtlAllocateAndInitializeSid(&sia
, 0, 1, 2, 3, 4, 5, 6, 7, 8, &psid
);
842 ok(!ret
, "RtlAllocateAndInitializeSid error %08x\n", ret
);
843 ret
= pRtlFreeSid(psid
);
844 ok(!ret
, "RtlFreeSid error %08x\n", ret
);
846 /* these tests crash on XP */
849 pRtlAllocateAndInitializeSid(NULL
, 0, 1, 2, 3, 4, 5, 6, 7, 8, &psid
);
850 pRtlAllocateAndInitializeSid(&sia
, 0, 1, 2, 3, 4, 5, 6, 7, 8, NULL
);
853 ret
= pRtlAllocateAndInitializeSid(&sia
, 9, 1, 2, 3, 4, 5, 6, 7, 8, &psid
);
854 ok(ret
== STATUS_INVALID_SID
, "wrong error %08x\n", ret
);
857 static void test_RtlDeleteTimer(void)
861 if (!pRtlDeleteTimer
)
863 win_skip("RtlDeleteTimer is not available\n");
867 ret
= pRtlDeleteTimer(NULL
, NULL
, NULL
);
868 ok(ret
== STATUS_INVALID_PARAMETER_1
||
869 ret
== STATUS_INVALID_PARAMETER
, /* W2K */
870 "expected STATUS_INVALID_PARAMETER_1 or STATUS_INVALID_PARAMETER, got %x\n", ret
);
873 static void test_RtlThreadErrorMode(void)
880 if (!pRtlGetThreadErrorMode
|| !pRtlSetThreadErrorMode
)
882 win_skip("RtlGetThreadErrorMode and/or RtlSetThreadErrorMode not available\n");
886 if (!pIsWow64Process
|| !pIsWow64Process(GetCurrentProcess(), &is_wow64
))
889 oldmode
= pRtlGetThreadErrorMode();
891 status
= pRtlSetThreadErrorMode(0x70, &mode
);
892 ok(status
== STATUS_SUCCESS
||
893 status
== STATUS_WAIT_1
, /* Vista */
894 "RtlSetThreadErrorMode failed with error 0x%08x\n", status
);
896 "RtlSetThreadErrorMode returned mode 0x%x, expected 0x%x\n",
898 ok(pRtlGetThreadErrorMode() == 0x70,
899 "RtlGetThreadErrorMode returned 0x%x, expected 0x%x\n", mode
, 0x70);
900 if (!is_wow64
&& pNtCurrentTeb
)
901 ok(pNtCurrentTeb()->HardErrorDisabled
== 0x70,
902 "The TEB contains 0x%x, expected 0x%x\n",
903 pNtCurrentTeb()->HardErrorDisabled
, 0x70);
905 status
= pRtlSetThreadErrorMode(0, &mode
);
906 ok(status
== STATUS_SUCCESS
||
907 status
== STATUS_WAIT_1
, /* Vista */
908 "RtlSetThreadErrorMode failed with error 0x%08x\n", status
);
910 "RtlSetThreadErrorMode returned mode 0x%x, expected 0x%x\n",
912 ok(pRtlGetThreadErrorMode() == 0,
913 "RtlGetThreadErrorMode returned 0x%x, expected 0x%x\n", mode
, 0);
914 if (!is_wow64
&& pNtCurrentTeb
)
915 ok(pNtCurrentTeb()->HardErrorDisabled
== 0,
916 "The TEB contains 0x%x, expected 0x%x\n",
917 pNtCurrentTeb()->HardErrorDisabled
, 0);
919 for (mode
= 1; mode
; mode
<<= 1)
921 status
= pRtlSetThreadErrorMode(mode
, NULL
);
923 ok(status
== STATUS_SUCCESS
||
924 status
== STATUS_WAIT_1
, /* Vista */
925 "RtlSetThreadErrorMode(%x,NULL) failed with error 0x%08x\n",
928 ok(status
== STATUS_INVALID_PARAMETER_1
,
929 "RtlSetThreadErrorMode(%x,NULL) returns 0x%08x, "
930 "expected STATUS_INVALID_PARAMETER_1\n",
934 pRtlSetThreadErrorMode(oldmode
, NULL
);
937 static void test_LdrProcessRelocationBlock(void)
939 IMAGE_BASE_RELOCATION
*ret
;
944 if(!pLdrProcessRelocationBlock
) {
945 win_skip("LdrProcessRelocationBlock not available\n");
950 reloc
= IMAGE_REL_BASED_HIGHLOW
<<12;
951 ret
= pLdrProcessRelocationBlock(&addr32
, 1, &reloc
, 0x500050);
952 ok((USHORT
*)ret
== &reloc
+1, "ret = %p, expected %p\n", ret
, &reloc
+1);
953 ok(addr32
== 0x550055, "addr32 = %x, expected 0x550055\n", addr32
);
956 reloc
= IMAGE_REL_BASED_HIGH
<<12;
957 ret
= pLdrProcessRelocationBlock(&addr16
, 1, &reloc
, 0x500060);
958 ok((USHORT
*)ret
== &reloc
+1, "ret = %p, expected %p\n", ret
, &reloc
+1);
959 ok(addr16
== 0x555, "addr16 = %x, expected 0x555\n", addr16
);
962 reloc
= IMAGE_REL_BASED_LOW
<<12;
963 ret
= pLdrProcessRelocationBlock(&addr16
, 1, &reloc
, 0x500060);
964 ok((USHORT
*)ret
== &reloc
+1, "ret = %p, expected %p\n", ret
, &reloc
+1);
965 ok(addr16
== 0x565, "addr16 = %x, expected 0x565\n", addr16
);
968 static void test_RtlIpv4AddressToString(void)
975 if (!pRtlIpv4AddressToStringA
)
977 win_skip("RtlIpv4AddressToStringA not available\n");
981 ip
.S_un
.S_un_b
.s_b1
= 1;
982 ip
.S_un
.S_un_b
.s_b2
= 2;
983 ip
.S_un
.S_un_b
.s_b3
= 3;
984 ip
.S_un
.S_un_b
.s_b4
= 4;
986 memset(buffer
, '#', sizeof(buffer
) - 1);
987 buffer
[sizeof(buffer
) -1] = 0;
988 res
= pRtlIpv4AddressToStringA(&ip
, buffer
);
989 len
= strlen(buffer
);
990 ok(res
== (buffer
+ len
), "got %p with '%s' (expected %p)\n", res
, buffer
, buffer
+ len
);
992 res
= pRtlIpv4AddressToStringA(&ip
, NULL
);
993 ok( (res
== (char *)~0) ||
994 broken(res
== (char *)len
), /* XP and w2003 */
995 "got %p (expected ~0)\n", res
);
998 /* this crashes in windows */
999 memset(buffer
, '#', sizeof(buffer
) - 1);
1000 buffer
[sizeof(buffer
) -1] = 0;
1001 res
= pRtlIpv4AddressToStringA(NULL
, buffer
);
1002 trace("got %p with '%s'\n", res
, buffer
);
1006 /* this crashes in windows */
1007 res
= pRtlIpv4AddressToStringA(NULL
, NULL
);
1008 trace("got %p\n", res
);
1012 static void test_RtlIpv4AddressToStringEx(void)
1014 CHAR ip_1234
[] = "1.2.3.4";
1015 CHAR ip_1234_80
[] = "1.2.3.4:80";
1024 if (!pRtlIpv4AddressToStringExA
)
1026 win_skip("RtlIpv4AddressToStringExA not available\n");
1030 ip
.S_un
.S_un_b
.s_b1
= 1;
1031 ip
.S_un
.S_un_b
.s_b2
= 2;
1032 ip
.S_un
.S_un_b
.s_b3
= 3;
1033 ip
.S_un
.S_un_b
.s_b4
= 4;
1036 expect
= ip_1234_80
;
1038 size
= sizeof(buffer
);
1039 memset(buffer
, '#', sizeof(buffer
) - 1);
1040 buffer
[sizeof(buffer
) -1] = 0;
1041 res
= pRtlIpv4AddressToStringExA(&ip
, port
, buffer
, &size
);
1042 used
= strlen(buffer
);
1043 ok( (res
== STATUS_SUCCESS
) &&
1044 (size
== strlen(expect
) + 1) && !strcmp(buffer
, expect
),
1045 "got 0x%x and size %d with '%s'\n", res
, size
, buffer
);
1048 memset(buffer
, '#', sizeof(buffer
) - 1);
1049 buffer
[sizeof(buffer
) -1] = 0;
1050 res
= pRtlIpv4AddressToStringExA(&ip
, port
, buffer
, &size
);
1051 ok( (res
== STATUS_SUCCESS
) &&
1052 (size
== strlen(expect
) + 1) && !strcmp(buffer
, expect
),
1053 "got 0x%x and size %d with '%s'\n", res
, size
, buffer
);
1056 memset(buffer
, '#', sizeof(buffer
) - 1);
1057 buffer
[sizeof(buffer
) -1] = 0;
1058 res
= pRtlIpv4AddressToStringExA(&ip
, port
, buffer
, &size
);
1059 ok( (res
== STATUS_INVALID_PARAMETER
) && (size
== used
+ 1),
1060 "got 0x%x and %d with '%s' (expected STATUS_INVALID_PARAMETER and %d)\n",
1061 res
, size
, buffer
, used
+ 1);
1064 memset(buffer
, '#', sizeof(buffer
) - 1);
1065 buffer
[sizeof(buffer
) -1] = 0;
1066 res
= pRtlIpv4AddressToStringExA(&ip
, port
, buffer
, &size
);
1067 ok( (res
== STATUS_INVALID_PARAMETER
) && (size
== used
+ 1),
1068 "got 0x%x and %d with '%s' (expected STATUS_INVALID_PARAMETER and %d)\n",
1069 res
, size
, buffer
, used
+ 1);
1072 /* to get only the ip, use 0 as port */
1076 size
= sizeof(buffer
);
1077 memset(buffer
, '#', sizeof(buffer
) - 1);
1078 buffer
[sizeof(buffer
) -1] = 0;
1079 res
= pRtlIpv4AddressToStringExA(&ip
, port
, buffer
, &size
);
1080 used
= strlen(buffer
);
1081 ok( (res
== STATUS_SUCCESS
) &&
1082 (size
== strlen(expect
) + 1) && !strcmp(buffer
, expect
),
1083 "got 0x%x and size %d with '%s'\n", res
, size
, buffer
);
1086 memset(buffer
, '#', sizeof(buffer
) - 1);
1087 buffer
[sizeof(buffer
) -1] = 0;
1088 res
= pRtlIpv4AddressToStringExA(&ip
, port
, buffer
, &size
);
1089 ok( (res
== STATUS_SUCCESS
) &&
1090 (size
== strlen(expect
) + 1) && !strcmp(buffer
, expect
),
1091 "got 0x%x and size %d with '%s'\n", res
, size
, buffer
);
1094 memset(buffer
, '#', sizeof(buffer
) - 1);
1095 buffer
[sizeof(buffer
) -1] = 0;
1096 res
= pRtlIpv4AddressToStringExA(&ip
, port
, buffer
, &size
);
1097 ok( (res
== STATUS_INVALID_PARAMETER
) && (size
== used
+ 1),
1098 "got 0x%x and %d with '%s' (expected STATUS_INVALID_PARAMETER and %d)\n",
1099 res
, size
, buffer
, used
+ 1);
1102 memset(buffer
, '#', sizeof(buffer
) - 1);
1103 buffer
[sizeof(buffer
) -1] = 0;
1104 res
= pRtlIpv4AddressToStringExA(&ip
, port
, buffer
, &size
);
1105 ok( (res
== STATUS_INVALID_PARAMETER
) && (size
== used
+ 1),
1106 "got 0x%x and %d with '%s' (expected STATUS_INVALID_PARAMETER and %d)\n",
1107 res
, size
, buffer
, used
+ 1);
1110 /* parameters are checked */
1111 memset(buffer
, '#', sizeof(buffer
) - 1);
1112 buffer
[sizeof(buffer
) -1] = 0;
1113 res
= pRtlIpv4AddressToStringExA(&ip
, 0, buffer
, NULL
);
1114 ok(res
== STATUS_INVALID_PARAMETER
,
1115 "got 0x%x with '%s' (expected STATUS_INVALID_PARAMETER)\n", res
, buffer
);
1117 size
= sizeof(buffer
);
1118 res
= pRtlIpv4AddressToStringExA(&ip
, 0, NULL
, &size
);
1119 ok( res
== STATUS_INVALID_PARAMETER
,
1120 "got 0x%x and size %d (expected STATUS_INVALID_PARAMETER)\n", res
, size
);
1122 size
= sizeof(buffer
);
1123 memset(buffer
, '#', sizeof(buffer
) - 1);
1124 buffer
[sizeof(buffer
) -1] = 0;
1125 res
= pRtlIpv4AddressToStringExA(NULL
, 0, buffer
, &size
);
1126 ok( res
== STATUS_INVALID_PARAMETER
,
1127 "got 0x%x and size %d with '%s' (expected STATUS_INVALID_PARAMETER)\n",
1131 static void test_RtlIpv4StringToAddress(void)
1134 IN_ADDR ip
, expected_ip
;
1141 int terminator_offset
;
1143 BOOL strict_is_different
;
1144 NTSTATUS res_strict
;
1145 int terminator_offset_strict
;
1149 { "", STATUS_INVALID_PARAMETER
, 0, { -1 } },
1150 { " ", STATUS_INVALID_PARAMETER
, 0, { -1 } },
1151 { "1.1.1.1", STATUS_SUCCESS
, 7, { 1, 1, 1, 1 } },
1152 { "0.0.0.0", STATUS_SUCCESS
, 7, { 0, 0, 0, 0 } },
1153 { "255.255.255.255", STATUS_SUCCESS
, 15, { 255, 255, 255, 255 } },
1154 { "255.255.255.255:123",
1155 STATUS_SUCCESS
, 15, { 255, 255, 255, 255 } },
1156 { "255.255.255.256", STATUS_INVALID_PARAMETER
, 15, { -1 } },
1157 { "255.255.255.4294967295",
1158 STATUS_INVALID_PARAMETER
, 22, { -1 } },
1159 { "255.255.255.4294967296",
1160 STATUS_INVALID_PARAMETER
, 21, { -1 } },
1161 { "255.255.255.4294967297",
1162 STATUS_INVALID_PARAMETER
, 21, { -1 } },
1163 { "a", STATUS_INVALID_PARAMETER
, 0, { -1 } },
1164 { "1.1.1.0xaA", STATUS_SUCCESS
, 10, { 1, 1, 1, 170 },
1165 TRUE
, STATUS_INVALID_PARAMETER
, 8, { -1 } },
1166 { "1.1.1.0XaA", STATUS_SUCCESS
, 10, { 1, 1, 1, 170 },
1167 TRUE
, STATUS_INVALID_PARAMETER
, 8, { -1 } },
1168 { "1.1.1.0x", STATUS_INVALID_PARAMETER
, 8, { -1 } },
1169 { "1.1.1.0xff", STATUS_SUCCESS
, 10, { 1, 1, 1, 255 },
1170 TRUE
, STATUS_INVALID_PARAMETER
, 8, { -1 } },
1171 { "1.1.1.0x100", STATUS_INVALID_PARAMETER
, 11, { -1 },
1172 TRUE
, STATUS_INVALID_PARAMETER
, 8, { -1 } },
1173 { "1.1.1.0xffffffff",STATUS_INVALID_PARAMETER
, 16, { -1 },
1174 TRUE
, STATUS_INVALID_PARAMETER
, 8, { -1 } },
1175 { "1.1.1.0x100000000",
1176 STATUS_INVALID_PARAMETER
, 16, { -1, 0, 0, 0 },
1177 TRUE
, STATUS_INVALID_PARAMETER
, 8, { -1 } },
1178 { "1.1.1.010", STATUS_SUCCESS
, 9, { 1, 1, 1, 8 },
1179 TRUE
, STATUS_INVALID_PARAMETER
, 7, { -1 } },
1180 { "1.1.1.00", STATUS_SUCCESS
, 8, { 1, 1, 1, 0 },
1181 TRUE
, STATUS_INVALID_PARAMETER
, 7, { -1 } },
1182 { "1.1.1.007", STATUS_SUCCESS
, 9, { 1, 1, 1, 7 },
1183 TRUE
, STATUS_INVALID_PARAMETER
, 7, { -1 } },
1184 { "1.1.1.08", STATUS_INVALID_PARAMETER
, 7, { -1 } },
1185 { "1.1.1.008", STATUS_SUCCESS
, 8, { 1, 1, 1, 0 },
1186 TRUE
, STATUS_INVALID_PARAMETER
, 7, { -1 } },
1187 { "1.1.1.0a", STATUS_SUCCESS
, 7, { 1, 1, 1, 0 } },
1188 { "1.1.1.0o10", STATUS_SUCCESS
, 7, { 1, 1, 1, 0 } },
1189 { "1.1.1.0b10", STATUS_SUCCESS
, 7, { 1, 1, 1, 0 } },
1190 { "1.1.1.-2", STATUS_INVALID_PARAMETER
, 6, { -1 } },
1191 { "1", STATUS_SUCCESS
, 1, { 0, 0, 0, 1 },
1192 TRUE
, STATUS_INVALID_PARAMETER
, 1, { -1 } },
1193 { "-1", STATUS_INVALID_PARAMETER
, 0, { -1 } },
1194 { "203569230", STATUS_SUCCESS
, 9, { 12, 34, 56, 78 },
1195 TRUE
, STATUS_INVALID_PARAMETER
, 9, { -1 } },
1196 { "1.223756", STATUS_SUCCESS
, 8, { 1, 3, 106, 12 },
1197 TRUE
, STATUS_INVALID_PARAMETER
, 8, { -1 } },
1198 { "3.4.756", STATUS_SUCCESS
, 7, { 3, 4, 2, 244 },
1199 TRUE
, STATUS_INVALID_PARAMETER
, 7, { -1 } },
1200 { "3.4.756.1", STATUS_INVALID_PARAMETER
, 9, { -1 } },
1201 { "3.4.65536", STATUS_INVALID_PARAMETER
, 9, { -1 } },
1202 { "3.4.5.6.7", STATUS_INVALID_PARAMETER
, 7, { -1 } },
1203 { "3.4.5.+6", STATUS_INVALID_PARAMETER
, 6, { -1 } },
1204 { " 3.4.5.6", STATUS_INVALID_PARAMETER
, 0, { -1 } },
1205 { "\t3.4.5.6", STATUS_INVALID_PARAMETER
, 0, { -1 } },
1206 { "3.4.5.6 ", STATUS_SUCCESS
, 7, { 3, 4, 5, 6 } },
1207 { "3. 4.5.6", STATUS_INVALID_PARAMETER
, 2, { -1 } },
1208 { ".", STATUS_INVALID_PARAMETER
, 1, { -1 } },
1209 { "..", STATUS_INVALID_PARAMETER
, 1, { -1 } },
1210 { "1.", STATUS_INVALID_PARAMETER
, 2, { -1 } },
1211 { "1..", STATUS_INVALID_PARAMETER
, 3, { -1 } },
1212 { ".1", STATUS_INVALID_PARAMETER
, 1, { -1 } },
1213 { ".1.", STATUS_INVALID_PARAMETER
, 1, { -1 } },
1214 { ".1.2.3", STATUS_INVALID_PARAMETER
, 1, { -1 } },
1215 { "0.1.2.3", STATUS_SUCCESS
, 7, { 0, 1, 2, 3 } },
1216 { "0.1.2.3.", STATUS_INVALID_PARAMETER
, 7, { -1 } },
1217 { "[0.1.2.3]", STATUS_INVALID_PARAMETER
, 0, { -1 } },
1218 { "::1", STATUS_INVALID_PARAMETER
, 0, { -1 } },
1219 { ":1", STATUS_INVALID_PARAMETER
, 0, { -1 } },
1221 const int testcount
= sizeof(tests
) / sizeof(tests
[0]);
1224 if (!pRtlIpv4StringToAddressA
)
1226 skip("RtlIpv4StringToAddress not available\n");
1232 /* leaving either parameter NULL crashes on Windows */
1233 res
= pRtlIpv4StringToAddressA(NULL
, FALSE
, &terminator
, &ip
);
1234 res
= pRtlIpv4StringToAddressA("1.1.1.1", FALSE
, NULL
, &ip
);
1235 res
= pRtlIpv4StringToAddressA("1.1.1.1", FALSE
, &terminator
, NULL
);
1236 /* same for the wide char version */
1238 res = pRtlIpv4StringToAddressW(NULL, FALSE, &terminatorW, &ip);
1239 res = pRtlIpv4StringToAddressW(L"1.1.1.1", FALSE, NULL, &ip);
1240 res = pRtlIpv4StringToAddressW(L"1.1.1.1", FALSE, &terminatorW, NULL);
1244 for (i
= 0; i
< testcount
; i
++)
1247 terminator
= &dummy
;
1248 ip
.S_un
.S_addr
= 0xabababab;
1249 res
= pRtlIpv4StringToAddressA(tests
[i
].address
, FALSE
, &terminator
, &ip
);
1250 ok(res
== tests
[i
].res
,
1251 "[%s] res = 0x%08x, expected 0x%08x\n",
1252 tests
[i
].address
, res
, tests
[i
].res
);
1253 ok(terminator
== tests
[i
].address
+ tests
[i
].terminator_offset
,
1254 "[%s] terminator = %p, expected %p\n",
1255 tests
[i
].address
, terminator
, tests
[i
].address
+ tests
[i
].terminator_offset
);
1256 if (tests
[i
].ip
[0] == -1)
1257 expected_ip
.S_un
.S_addr
= 0xabababab;
1260 expected_ip
.S_un
.S_un_b
.s_b1
= tests
[i
].ip
[0];
1261 expected_ip
.S_un
.S_un_b
.s_b2
= tests
[i
].ip
[1];
1262 expected_ip
.S_un
.S_un_b
.s_b3
= tests
[i
].ip
[2];
1263 expected_ip
.S_un
.S_un_b
.s_b4
= tests
[i
].ip
[3];
1265 ok(ip
.S_un
.S_addr
== expected_ip
.S_un
.S_addr
,
1266 "[%s] ip = %08x, expected %08x\n",
1267 tests
[i
].address
, ip
.S_un
.S_addr
, expected_ip
.S_un
.S_addr
);
1269 if (!tests
[i
].strict_is_different
)
1271 tests
[i
].res_strict
= tests
[i
].res
;
1272 tests
[i
].terminator_offset_strict
= tests
[i
].terminator_offset
;
1273 tests
[i
].ip_strict
[0] = tests
[i
].ip
[0];
1274 tests
[i
].ip_strict
[1] = tests
[i
].ip
[1];
1275 tests
[i
].ip_strict
[2] = tests
[i
].ip
[2];
1276 tests
[i
].ip_strict
[3] = tests
[i
].ip
[3];
1279 terminator
= &dummy
;
1280 ip
.S_un
.S_addr
= 0xabababab;
1281 res
= pRtlIpv4StringToAddressA(tests
[i
].address
, TRUE
, &terminator
, &ip
);
1282 ok(res
== tests
[i
].res_strict
,
1283 "[%s] res = 0x%08x, expected 0x%08x\n",
1284 tests
[i
].address
, res
, tests
[i
].res_strict
);
1285 ok(terminator
== tests
[i
].address
+ tests
[i
].terminator_offset_strict
,
1286 "[%s] terminator = %p, expected %p\n",
1287 tests
[i
].address
, terminator
, tests
[i
].address
+ tests
[i
].terminator_offset_strict
);
1288 if (tests
[i
].ip_strict
[0] == -1)
1289 expected_ip
.S_un
.S_addr
= 0xabababab;
1292 expected_ip
.S_un
.S_un_b
.s_b1
= tests
[i
].ip_strict
[0];
1293 expected_ip
.S_un
.S_un_b
.s_b2
= tests
[i
].ip_strict
[1];
1294 expected_ip
.S_un
.S_un_b
.s_b3
= tests
[i
].ip_strict
[2];
1295 expected_ip
.S_un
.S_un_b
.s_b4
= tests
[i
].ip_strict
[3];
1297 ok(ip
.S_un
.S_addr
== expected_ip
.S_un
.S_addr
,
1298 "[%s] ip = %08x, expected %08x\n",
1299 tests
[i
].address
, ip
.S_un
.S_addr
, expected_ip
.S_un
.S_addr
);
1303 static void test_LdrAddRefDll(void)
1311 win_skip( "LdrAddRefDll not supported\n" );
1315 mod
= LoadLibraryA("comctl32.dll");
1316 ok(mod
!= NULL
, "got %p\n", mod
);
1317 ret
= FreeLibrary(mod
);
1318 ok(ret
, "got %d\n", ret
);
1320 mod2
= GetModuleHandleA("comctl32.dll");
1321 ok(mod2
== NULL
, "got %p\n", mod2
);
1323 /* load, addref and release 2 times */
1324 mod
= LoadLibraryA("comctl32.dll");
1325 ok(mod
!= NULL
, "got %p\n", mod
);
1326 status
= pLdrAddRefDll(0, mod
);
1327 ok(status
== STATUS_SUCCESS
, "got 0x%08x\n", status
);
1328 ret
= FreeLibrary(mod
);
1329 ok(ret
, "got %d\n", ret
);
1331 mod2
= GetModuleHandleA("comctl32.dll");
1332 ok(mod2
!= NULL
, "got %p\n", mod2
);
1333 ret
= FreeLibrary(mod
);
1334 ok(ret
, "got %d\n", ret
);
1336 mod2
= GetModuleHandleA("comctl32.dll");
1337 ok(mod2
== NULL
, "got %p\n", mod2
);
1340 mod
= LoadLibraryA("comctl32.dll");
1341 ok(mod
!= NULL
, "got %p\n", mod
);
1342 status
= pLdrAddRefDll(LDR_ADDREF_DLL_PIN
, mod
);
1343 ok(status
== STATUS_SUCCESS
, "got 0x%08x\n", status
);
1345 ret
= FreeLibrary(mod
);
1346 ok(ret
, "got %d\n", ret
);
1347 ret
= FreeLibrary(mod
);
1348 ok(ret
, "got %d\n", ret
);
1349 ret
= FreeLibrary(mod
);
1350 ok(ret
, "got %d\n", ret
);
1351 ret
= FreeLibrary(mod
);
1352 ok(ret
, "got %d\n", ret
);
1354 mod2
= GetModuleHandleA("comctl32.dll");
1355 ok(mod2
!= NULL
, "got %p\n", mod2
);
1358 static void test_LdrLockLoaderLock(void)
1364 if (!pLdrLockLoaderLock
)
1366 win_skip("LdrLockLoaderLock() is not available\n");
1373 status
= pLdrLockLoaderLock(0x10, &result
, &magic
);
1374 ok(status
== STATUS_INVALID_PARAMETER_1
, "got 0x%08x\n", status
);
1375 ok(result
== 0, "got %d\n", result
);
1376 ok(magic
== 0, "got %lx\n", magic
);
1379 status
= pLdrLockLoaderLock(0x10, NULL
, &magic
);
1380 ok(status
== STATUS_INVALID_PARAMETER_1
, "got 0x%08x\n", status
);
1381 ok(magic
== 0, "got %lx\n", magic
);
1384 status
= pLdrLockLoaderLock(0x10, &result
, NULL
);
1385 ok(status
== STATUS_INVALID_PARAMETER_1
, "got 0x%08x\n", status
);
1386 ok(result
== 0, "got %d\n", result
);
1388 /* non-blocking mode, result is null */
1390 status
= pLdrLockLoaderLock(0x2, NULL
, &magic
);
1391 ok(status
== STATUS_INVALID_PARAMETER_2
, "got 0x%08x\n", status
);
1392 ok(magic
== 0, "got %lx\n", magic
);
1394 /* magic pointer is null */
1396 status
= pLdrLockLoaderLock(0, &result
, NULL
);
1397 ok(status
== STATUS_INVALID_PARAMETER_3
, "got 0x%08x\n", status
);
1398 ok(result
== 0, "got %d\n", result
);
1400 /* lock in non-blocking mode */
1403 status
= pLdrLockLoaderLock(0x2, &result
, &magic
);
1404 ok(status
== STATUS_SUCCESS
, "got 0x%08x\n", status
);
1405 ok(result
== 1, "got %d\n", result
);
1406 ok(magic
!= 0, "got %lx\n", magic
);
1407 pLdrUnlockLoaderLock(0, magic
);
1410 static void test_RtlCompressBuffer(void)
1412 ULONG compress_workspace
, decompress_workspace
;
1413 static const UCHAR test_buffer
[] = "WineWineWine";
1414 static UCHAR buf1
[0x1000], buf2
[0x1000];
1415 ULONG final_size
, buf_size
;
1416 UCHAR
*workspace
= NULL
;
1419 if (!pRtlCompressBuffer
|| !pRtlDecompressBuffer
|| !pRtlGetCompressionWorkSpaceSize
)
1421 win_skip("skipping RtlCompressBuffer tests, required functions not available\n");
1425 compress_workspace
= decompress_workspace
= 0xdeadbeef;
1426 status
= pRtlGetCompressionWorkSpaceSize(COMPRESSION_FORMAT_LZNT1
, &compress_workspace
,
1427 &decompress_workspace
);
1428 ok(status
== STATUS_SUCCESS
, "got wrong status 0x%08x\n", status
);
1429 ok(compress_workspace
!= 0, "got wrong compress_workspace %u\n", compress_workspace
);
1430 workspace
= HeapAlloc(GetProcessHeap(), 0, compress_workspace
);
1431 ok(workspace
!= NULL
, "HeapAlloc failed %d\n", GetLastError());
1433 /* test compression format / engine */
1434 final_size
= 0xdeadbeef;
1435 status
= pRtlCompressBuffer(COMPRESSION_FORMAT_NONE
, test_buffer
, sizeof(test_buffer
),
1436 buf1
, sizeof(buf1
) - 1, 4096, &final_size
, workspace
);
1437 ok(status
== STATUS_INVALID_PARAMETER
, "got wrong status 0x%08x\n", status
);
1438 ok(final_size
== 0xdeadbeef, "got wrong final_size %u\n", final_size
);
1440 final_size
= 0xdeadbeef;
1441 status
= pRtlCompressBuffer(COMPRESSION_FORMAT_DEFAULT
, test_buffer
, sizeof(test_buffer
),
1442 buf1
, sizeof(buf1
) - 1, 4096, &final_size
, workspace
);
1443 ok(status
== STATUS_INVALID_PARAMETER
, "got wrong status 0x%08x\n", status
);
1444 ok(final_size
== 0xdeadbeef, "got wrong final_size %u\n", final_size
);
1446 final_size
= 0xdeadbeef;
1447 status
= pRtlCompressBuffer(0xFF, test_buffer
, sizeof(test_buffer
),
1448 buf1
, sizeof(buf1
) - 1, 4096, &final_size
, workspace
);
1449 ok(status
== STATUS_UNSUPPORTED_COMPRESSION
, "got wrong status 0x%08x\n", status
);
1450 ok(final_size
== 0xdeadbeef, "got wrong final_size %u\n", final_size
);
1452 /* test compression */
1453 final_size
= 0xdeadbeef;
1454 memset(buf1
, 0x11, sizeof(buf1
));
1455 status
= pRtlCompressBuffer(COMPRESSION_FORMAT_LZNT1
, test_buffer
, sizeof(test_buffer
),
1456 buf1
, sizeof(buf1
), 4096, &final_size
, workspace
);
1457 ok(status
== STATUS_SUCCESS
, "got wrong status 0x%08x\n", status
);
1458 ok((*(WORD
*)buf1
& 0x7000) == 0x3000, "no chunk signature found %04x\n", *(WORD
*)buf1
);
1460 ok(final_size
< sizeof(test_buffer
), "got wrong final_size %u\n", final_size
);
1462 /* test decompression */
1463 buf_size
= final_size
;
1464 final_size
= 0xdeadbeef;
1465 memset(buf2
, 0x11, sizeof(buf2
));
1466 status
= pRtlDecompressBuffer(COMPRESSION_FORMAT_LZNT1
, buf2
, sizeof(buf2
),
1467 buf1
, buf_size
, &final_size
);
1468 ok(status
== STATUS_SUCCESS
, "got wrong status 0x%08x\n", status
);
1469 ok(final_size
== sizeof(test_buffer
), "got wrong final_size %u\n", final_size
);
1470 ok(!memcmp(buf2
, test_buffer
, sizeof(test_buffer
)), "got wrong decoded data\n");
1471 ok(buf2
[sizeof(test_buffer
)] == 0x11, "too many bytes written\n");
1473 /* buffer too small */
1474 final_size
= 0xdeadbeef;
1475 memset(buf1
, 0x11, sizeof(buf1
));
1476 status
= pRtlCompressBuffer(COMPRESSION_FORMAT_LZNT1
, test_buffer
, sizeof(test_buffer
),
1477 buf1
, 4, 4096, &final_size
, workspace
);
1478 ok(status
== STATUS_BUFFER_TOO_SMALL
, "got wrong status 0x%08x\n", status
);
1480 HeapFree(GetProcessHeap(), 0, workspace
);
1483 static void test_RtlGetCompressionWorkSpaceSize(void)
1485 ULONG compress_workspace
, decompress_workspace
;
1488 if (!pRtlGetCompressionWorkSpaceSize
)
1490 win_skip("RtlGetCompressionWorkSpaceSize is not available\n");
1494 /* test invalid format / engine */
1495 status
= pRtlGetCompressionWorkSpaceSize(COMPRESSION_FORMAT_NONE
, &compress_workspace
,
1496 &decompress_workspace
);
1497 ok(status
== STATUS_INVALID_PARAMETER
, "got wrong status 0x%08x\n", status
);
1499 status
= pRtlGetCompressionWorkSpaceSize(COMPRESSION_FORMAT_DEFAULT
, &compress_workspace
,
1500 &decompress_workspace
);
1501 ok(status
== STATUS_INVALID_PARAMETER
, "got wrong status 0x%08x\n", status
);
1503 status
= pRtlGetCompressionWorkSpaceSize(0xFF, &compress_workspace
, &decompress_workspace
);
1504 ok(status
== STATUS_UNSUPPORTED_COMPRESSION
, "got wrong status 0x%08x\n", status
);
1506 /* test LZNT1 with normal and maximum compression */
1507 compress_workspace
= decompress_workspace
= 0xdeadbeef;
1508 status
= pRtlGetCompressionWorkSpaceSize(COMPRESSION_FORMAT_LZNT1
, &compress_workspace
,
1509 &decompress_workspace
);
1510 ok(status
== STATUS_SUCCESS
, "got wrong status 0x%08x\n", status
);
1511 ok(compress_workspace
!= 0, "got wrong compress_workspace %u\n", compress_workspace
);
1512 ok(decompress_workspace
== 0x1000, "got wrong decompress_workspace %u\n", decompress_workspace
);
1514 compress_workspace
= decompress_workspace
= 0xdeadbeef;
1515 status
= pRtlGetCompressionWorkSpaceSize(COMPRESSION_FORMAT_LZNT1
| COMPRESSION_ENGINE_MAXIMUM
,
1516 &compress_workspace
, &decompress_workspace
);
1517 ok(status
== STATUS_SUCCESS
, "got wrong status 0x%08x\n", status
);
1518 ok(compress_workspace
!= 0, "got wrong compress_workspace %u\n", compress_workspace
);
1519 ok(decompress_workspace
== 0x1000, "got wrong decompress_workspace %u\n", decompress_workspace
);
1522 /* helper for test_RtlDecompressBuffer, checks if a chunk is incomplete */
1523 static BOOL
is_incomplete_chunk(const UCHAR
*compressed
, ULONG compressed_size
, BOOL check_all
)
1527 if (compressed_size
<= sizeof(WORD
))
1530 while (compressed_size
>= sizeof(WORD
))
1532 chunk_size
= (*(WORD
*)compressed
& 0xFFF) + 1;
1533 if (compressed_size
< sizeof(WORD
) + chunk_size
)
1537 compressed
+= sizeof(WORD
) + chunk_size
;
1538 compressed_size
-= sizeof(WORD
) + chunk_size
;
1544 #define DECOMPRESS_BROKEN_FRAGMENT 1 /* < Win 7 */
1545 #define DECOMPRESS_BROKEN_TRUNCATED 2 /* broken on all machines */
1547 static void test_RtlDecompressBuffer(void)
1551 UCHAR compressed
[32];
1552 ULONG compressed_size
;
1554 UCHAR uncompressed
[32];
1555 ULONG uncompressed_size
;
1560 /* 4 byte uncompressed chunk */
1562 {0x03, 0x30, 'W', 'i', 'n', 'e'},
1567 DECOMPRESS_BROKEN_FRAGMENT
1569 /* 8 byte uncompressed chunk */
1571 {0x07, 0x30, 'W', 'i', 'n', 'e', 'W', 'i', 'n', 'e'},
1576 DECOMPRESS_BROKEN_FRAGMENT
1578 /* 4 byte compressed chunk */
1580 {0x04, 0xB0, 0x00, 'W', 'i', 'n', 'e'},
1586 /* 8 byte compressed chunk */
1588 {0x08, 0xB0, 0x00, 'W', 'i', 'n', 'e', 'W', 'i', 'n', 'e'},
1594 /* compressed chunk using backwards reference */
1596 {0x06, 0xB0, 0x10, 'W', 'i', 'n', 'e', 0x01, 0x30},
1601 DECOMPRESS_BROKEN_TRUNCATED
1603 /* compressed chunk using backwards reference with length > bytes_read */
1605 {0x06, 0xB0, 0x10, 'W', 'i', 'n', 'e', 0x05, 0x30},
1610 DECOMPRESS_BROKEN_TRUNCATED
1612 /* same as above, but unused bits != 0 */
1614 {0x06, 0xB0, 0x30, 'W', 'i', 'n', 'e', 0x01, 0x30},
1619 DECOMPRESS_BROKEN_TRUNCATED
1621 /* compressed chunk without backwards reference and unused bits != 0 */
1623 {0x01, 0xB0, 0x02, 'W'},
1629 /* termination sequence after first chunk */
1631 {0x03, 0x30, 'W', 'i', 'n', 'e', 0x00, 0x00, 0x03, 0x30, 'W', 'i', 'n', 'e'},
1636 DECOMPRESS_BROKEN_FRAGMENT
1638 /* compressed chunk using backwards reference with 4 bit offset, 12 bit length */
1640 {0x14, 0xB0, 0x00, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
1641 0x00, 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
1645 "ABCDEFGHIJKLMNOPABCD",
1647 DECOMPRESS_BROKEN_TRUNCATED
1649 /* compressed chunk using backwards reference with 5 bit offset, 11 bit length */
1651 {0x15, 0xB0, 0x00, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
1652 0x00, 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
1653 0x02, 'A', 0x00, 0x78},
1656 "ABCDEFGHIJKLMNOPABCD",
1658 DECOMPRESS_BROKEN_TRUNCATED
1660 /* uncompressed chunk with invalid magic */
1662 {0x03, 0x20, 'W', 'i', 'n', 'e'},
1667 DECOMPRESS_BROKEN_FRAGMENT
1669 /* compressed chunk with invalid magic */
1671 {0x04, 0xA0, 0x00, 'W', 'i', 'n', 'e'},
1677 /* garbage byte after end of buffer */
1679 {0x00, 0xB0, 0x02, 0x01},
1685 /* empty compressed chunk */
1693 /* empty compressed chunk with unused bits != 0 */
1701 /* empty input buffer */
1705 STATUS_BAD_COMPRESSION_BUFFER
,
1707 /* incomplete chunk header */
1711 STATUS_BAD_COMPRESSION_BUFFER
1713 /* incomplete chunk header */
1717 STATUS_BAD_COMPRESSION_BUFFER
1719 /* compressed chunk with invalid backwards reference */
1721 {0x06, 0xB0, 0x10, 'W', 'i', 'n', 'e', 0x05, 0x40},
1723 STATUS_BAD_COMPRESSION_BUFFER
1725 /* compressed chunk with incomplete backwards reference */
1727 {0x05, 0xB0, 0x10, 'W', 'i', 'n', 'e', 0x05},
1729 STATUS_BAD_COMPRESSION_BUFFER
1731 /* incomplete uncompressed chunk */
1733 {0x07, 0x30, 'W', 'i', 'n', 'e'},
1735 STATUS_BAD_COMPRESSION_BUFFER
1737 /* incomplete compressed chunk */
1739 {0x08, 0xB0, 0x00, 'W', 'i', 'n', 'e'},
1741 STATUS_BAD_COMPRESSION_BUFFER
1743 /* two compressed chunks, the second one incomplete */
1745 {0x00, 0xB0, 0x02, 0x00, 0xB0},
1747 STATUS_BAD_COMPRESSION_BUFFER
,
1751 static UCHAR buf
[0x2000], workspace
[0x1000];
1752 NTSTATUS status
, expected_status
;
1756 if (!pRtlDecompressBuffer
|| !pRtlDecompressFragment
)
1758 win_skip("RtlDecompressBuffer or RtlDecompressFragment is not available\n");
1762 /* test compression format / engine */
1763 final_size
= 0xdeadbeef;
1764 status
= pRtlDecompressBuffer(COMPRESSION_FORMAT_NONE
, buf
, sizeof(buf
), test_lznt
[0].compressed
,
1765 test_lznt
[0].compressed_size
, &final_size
);
1766 ok(status
== STATUS_INVALID_PARAMETER
, "got wrong status 0x%08x\n", status
);
1767 ok(final_size
== 0xdeadbeef, "got wrong final_size %u\n", final_size
);
1769 final_size
= 0xdeadbeef;
1770 status
= pRtlDecompressBuffer(COMPRESSION_FORMAT_DEFAULT
, buf
, sizeof(buf
), test_lznt
[0].compressed
,
1771 test_lznt
[0].compressed_size
, &final_size
);
1772 ok(status
== STATUS_INVALID_PARAMETER
, "got wrong status 0x%08x\n", status
);
1773 ok(final_size
== 0xdeadbeef, "got wrong final_size %u\n", final_size
);
1775 final_size
= 0xdeadbeef;
1776 status
= pRtlDecompressBuffer(0xFF, buf
, sizeof(buf
), test_lznt
[0].compressed
,
1777 test_lznt
[0].compressed_size
, &final_size
);
1778 ok(status
== STATUS_UNSUPPORTED_COMPRESSION
, "got wrong status 0x%08x\n", status
);
1779 ok(final_size
== 0xdeadbeef, "got wrong final_size %u\n", final_size
);
1781 /* regular tests for RtlDecompressBuffer */
1782 for (i
= 0; i
< sizeof(test_lznt
) / sizeof(test_lznt
[0]); i
++)
1784 trace("Running test %d (compressed_size=%u, uncompressed_size=%u, status=0x%08x)\n",
1785 i
, test_lznt
[i
].compressed_size
, test_lznt
[i
].uncompressed_size
, test_lznt
[i
].status
);
1787 /* test with very big buffer */
1788 final_size
= 0xdeadbeef;
1789 memset(buf
, 0x11, sizeof(buf
));
1790 status
= pRtlDecompressBuffer(COMPRESSION_FORMAT_LZNT1
, buf
, sizeof(buf
), test_lznt
[i
].compressed
,
1791 test_lznt
[i
].compressed_size
, &final_size
);
1792 ok(status
== test_lznt
[i
].status
|| broken(status
== STATUS_BAD_COMPRESSION_BUFFER
&&
1793 (test_lznt
[i
].broken_flags
& DECOMPRESS_BROKEN_FRAGMENT
)), "%d: got wrong status 0x%08x\n", i
, status
);
1796 ok(final_size
== test_lznt
[i
].uncompressed_size
,
1797 "%d: got wrong final_size %u\n", i
, final_size
);
1798 ok(!memcmp(buf
, test_lznt
[i
].uncompressed
, test_lznt
[i
].uncompressed_size
),
1799 "%d: got wrong decoded data\n", i
);
1800 ok(buf
[test_lznt
[i
].uncompressed_size
] == 0x11,
1801 "%d: buf[%u] was modified\n", i
, test_lznt
[i
].uncompressed_size
);
1804 /* test that modifier for compression engine is ignored */
1805 final_size
= 0xdeadbeef;
1806 memset(buf
, 0x11, sizeof(buf
));
1807 status
= pRtlDecompressBuffer(COMPRESSION_FORMAT_LZNT1
| COMPRESSION_ENGINE_MAXIMUM
, buf
, sizeof(buf
),
1808 test_lznt
[i
].compressed
, test_lznt
[i
].compressed_size
, &final_size
);
1809 ok(status
== test_lznt
[i
].status
|| broken(status
== STATUS_BAD_COMPRESSION_BUFFER
&&
1810 (test_lznt
[i
].broken_flags
& DECOMPRESS_BROKEN_FRAGMENT
)), "%d: got wrong status 0x%08x\n", i
, status
);
1813 ok(final_size
== test_lznt
[i
].uncompressed_size
,
1814 "%d: got wrong final_size %u\n", i
, final_size
);
1815 ok(!memcmp(buf
, test_lznt
[i
].uncompressed
, test_lznt
[i
].uncompressed_size
),
1816 "%d: got wrong decoded data\n", i
);
1817 ok(buf
[test_lznt
[i
].uncompressed_size
] == 0x11,
1818 "%d: buf[%u] was modified\n", i
, test_lznt
[i
].uncompressed_size
);
1821 /* test with expected output size */
1822 if (test_lznt
[i
].uncompressed_size
> 0)
1824 final_size
= 0xdeadbeef;
1825 memset(buf
, 0x11, sizeof(buf
));
1826 status
= pRtlDecompressBuffer(COMPRESSION_FORMAT_LZNT1
, buf
, test_lznt
[i
].uncompressed_size
,
1827 test_lznt
[i
].compressed
, test_lznt
[i
].compressed_size
, &final_size
);
1828 ok(status
== test_lznt
[i
].status
, "%d: got wrong status 0x%08x\n", i
, status
);
1831 ok(final_size
== test_lznt
[i
].uncompressed_size
,
1832 "%d: got wrong final_size %u\n", i
, final_size
);
1833 ok(!memcmp(buf
, test_lznt
[i
].uncompressed
, test_lznt
[i
].uncompressed_size
),
1834 "%d: got wrong decoded data\n", i
);
1835 ok(buf
[test_lznt
[i
].uncompressed_size
] == 0x11,
1836 "%d: buf[%u] was modified\n", i
, test_lznt
[i
].uncompressed_size
);
1840 /* test with smaller output size */
1841 if (test_lznt
[i
].uncompressed_size
> 1)
1843 final_size
= 0xdeadbeef;
1844 memset(buf
, 0x11, sizeof(buf
));
1845 status
= pRtlDecompressBuffer(COMPRESSION_FORMAT_LZNT1
, buf
, test_lznt
[i
].uncompressed_size
- 1,
1846 test_lznt
[i
].compressed
, test_lznt
[i
].compressed_size
, &final_size
);
1847 if (test_lznt
[i
].broken_flags
& DECOMPRESS_BROKEN_TRUNCATED
)
1849 ok(status
== STATUS_BAD_COMPRESSION_BUFFER
, "%d: got wrong status 0x%08x\n", i
, status
);
1851 ok(status
== test_lznt
[i
].status
, "%d: got wrong status 0x%08x\n", i
, status
);
1854 ok(final_size
== test_lznt
[i
].uncompressed_size
- 1,
1855 "%d: got wrong final_size %u\n", i
, final_size
);
1856 ok(!memcmp(buf
, test_lznt
[i
].uncompressed
, test_lznt
[i
].uncompressed_size
- 1),
1857 "%d: got wrong decoded data\n", i
);
1858 ok(buf
[test_lznt
[i
].uncompressed_size
- 1] == 0x11,
1859 "%d: buf[%u] was modified\n", i
, test_lznt
[i
].uncompressed_size
- 1);
1863 /* test with zero output size */
1864 final_size
= 0xdeadbeef;
1865 memset(buf
, 0x11, sizeof(buf
));
1866 status
= pRtlDecompressBuffer(COMPRESSION_FORMAT_LZNT1
, buf
, 0, test_lznt
[i
].compressed
,
1867 test_lznt
[i
].compressed_size
, &final_size
);
1868 if (is_incomplete_chunk(test_lznt
[i
].compressed
, test_lznt
[i
].compressed_size
, FALSE
))
1869 ok(status
== STATUS_BAD_COMPRESSION_BUFFER
, "%d: got wrong status 0x%08x\n", i
, status
);
1872 ok(status
== STATUS_SUCCESS
, "%d: got wrong status 0x%08x\n", i
, status
);
1873 ok(final_size
== 0, "%d: got wrong final_size %u\n", i
, final_size
);
1874 ok(buf
[0] == 0x11, "%d: buf[0] was modified\n", i
);
1877 /* test RtlDecompressFragment with offset = 0 */
1878 final_size
= 0xdeadbeef;
1879 memset(buf
, 0x11, sizeof(buf
));
1880 status
= pRtlDecompressFragment(COMPRESSION_FORMAT_LZNT1
, buf
, sizeof(buf
), test_lznt
[i
].compressed
,
1881 test_lznt
[i
].compressed_size
, 0, &final_size
, workspace
);
1882 if (test_lznt
[i
].broken_flags
& DECOMPRESS_BROKEN_FRAGMENT
)
1884 ok(status
== STATUS_BAD_COMPRESSION_BUFFER
, "%d: got wrong status 0x%08x\n", i
, status
);
1886 ok(status
== test_lznt
[i
].status
, "%d: got wrong status 0x%08x\n", i
, status
);
1889 ok(final_size
== test_lznt
[i
].uncompressed_size
,
1890 "%d: got wrong final_size %u\n", i
, final_size
);
1891 ok(!memcmp(buf
, test_lznt
[i
].uncompressed
, test_lznt
[i
].uncompressed_size
),
1892 "%d: got wrong decoded data\n", i
);
1893 ok(buf
[test_lznt
[i
].uncompressed_size
] == 0x11,
1894 "%d: buf[%u] was modified\n", i
, test_lznt
[i
].uncompressed_size
);
1897 /* test RtlDecompressFragment with offset = 1 */
1898 final_size
= 0xdeadbeef;
1899 memset(buf
, 0x11, sizeof(buf
));
1900 status
= pRtlDecompressFragment(COMPRESSION_FORMAT_LZNT1
, buf
, sizeof(buf
), test_lznt
[i
].compressed
,
1901 test_lznt
[i
].compressed_size
, 1, &final_size
, workspace
);
1902 if (test_lznt
[i
].broken_flags
& DECOMPRESS_BROKEN_FRAGMENT
)
1904 ok(status
== STATUS_BAD_COMPRESSION_BUFFER
, "%d: got wrong status 0x%08x\n", i
, status
);
1906 ok(status
== test_lznt
[i
].status
, "%d: got wrong status 0x%08x\n", i
, status
);
1909 if (test_lznt
[i
].uncompressed_size
== 0)
1912 ok(final_size
== 4095, "%d: got wrong final_size %u\n", i
, final_size
);
1913 /* Buffer doesn't contain any useful value on Windows */
1914 ok(buf
[4095] == 0x11, "%d: buf[4095] was modified\n", i
);
1918 ok(final_size
== test_lznt
[i
].uncompressed_size
- 1,
1919 "%d: got wrong final_size %u\n", i
, final_size
);
1920 ok(!memcmp(buf
, test_lznt
[i
].uncompressed
+ 1, test_lznt
[i
].uncompressed_size
- 1),
1921 "%d: got wrong decoded data\n", i
);
1922 ok(buf
[test_lznt
[i
].uncompressed_size
- 1] == 0x11,
1923 "%d: buf[%u] was modified\n", i
, test_lznt
[i
].uncompressed_size
- 1);
1927 /* test RtlDecompressFragment with offset = 4095 */
1928 final_size
= 0xdeadbeef;
1929 memset(buf
, 0x11, sizeof(buf
));
1930 status
= pRtlDecompressFragment(COMPRESSION_FORMAT_LZNT1
, buf
, sizeof(buf
), test_lznt
[i
].compressed
,
1931 test_lznt
[i
].compressed_size
, 4095, &final_size
, workspace
);
1932 if (test_lznt
[i
].broken_flags
& DECOMPRESS_BROKEN_FRAGMENT
)
1934 ok(status
== STATUS_BAD_COMPRESSION_BUFFER
, "%d: got wrong status 0x%08x\n", i
, status
);
1936 ok(status
== test_lznt
[i
].status
, "%d: got wrong status 0x%08x\n", i
, status
);
1940 ok(final_size
== 1, "%d: got wrong final_size %u\n", i
, final_size
);
1942 ok(buf
[0] == 0, "%d: padding is not zero\n", i
);
1943 ok(buf
[1] == 0x11, "%d: buf[1] was modified\n", i
);
1946 /* test RtlDecompressFragment with offset = 4096 */
1947 final_size
= 0xdeadbeef;
1948 memset(buf
, 0x11, sizeof(buf
));
1949 status
= pRtlDecompressFragment(COMPRESSION_FORMAT_LZNT1
, buf
, sizeof(buf
), test_lznt
[i
].compressed
,
1950 test_lznt
[i
].compressed_size
, 4096, &final_size
, workspace
);
1951 expected_status
= is_incomplete_chunk(test_lznt
[i
].compressed
, test_lznt
[i
].compressed_size
, TRUE
) ?
1952 test_lznt
[i
].status
: STATUS_SUCCESS
;
1953 ok(status
== expected_status
, "%d: got wrong status 0x%08x, expected 0x%08x\n", i
, status
, expected_status
);
1956 ok(final_size
== 0, "%d: got wrong final_size %u\n", i
, final_size
);
1957 ok(buf
[0] == 0x11, "%d: buf[4096] was modified\n", i
);
1962 #undef DECOMPRESS_BROKEN_FRAGMENT
1963 #undef DECOMPRESS_BROKEN_TRUNCATED
1965 struct critsect_locked_info
1967 CRITICAL_SECTION crit
;
1968 HANDLE semaphores
[2];
1971 static DWORD WINAPI
critsect_locked_thread(void *param
)
1973 struct critsect_locked_info
*info
= param
;
1976 ret
= pRtlIsCriticalSectionLocked(&info
->crit
);
1977 ok(ret
== TRUE
, "expected TRUE, got %u\n", ret
);
1978 ret
= pRtlIsCriticalSectionLockedByThread(&info
->crit
);
1979 ok(ret
== FALSE
, "expected FALSE, got %u\n", ret
);
1981 ReleaseSemaphore(info
->semaphores
[0], 1, NULL
);
1982 ret
= WaitForSingleObject(info
->semaphores
[1], 1000);
1983 ok(ret
== WAIT_OBJECT_0
, "expected WAIT_OBJECT_0, got %u\n", ret
);
1985 ret
= pRtlIsCriticalSectionLocked(&info
->crit
);
1986 ok(ret
== FALSE
, "expected FALSE, got %u\n", ret
);
1987 ret
= pRtlIsCriticalSectionLockedByThread(&info
->crit
);
1988 ok(ret
== FALSE
, "expected FALSE, got %u\n", ret
);
1990 EnterCriticalSection(&info
->crit
);
1992 ret
= pRtlIsCriticalSectionLocked(&info
->crit
);
1993 ok(ret
== TRUE
, "expected TRUE, got %u\n", ret
);
1994 ret
= pRtlIsCriticalSectionLockedByThread(&info
->crit
);
1995 ok(ret
== TRUE
, "expected TRUE, got %u\n", ret
);
1997 ReleaseSemaphore(info
->semaphores
[0], 1, NULL
);
1998 ret
= WaitForSingleObject(info
->semaphores
[1], 1000);
1999 ok(ret
== WAIT_OBJECT_0
, "expected WAIT_OBJECT_0, got %u\n", ret
);
2001 LeaveCriticalSection(&info
->crit
);
2005 static void test_RtlIsCriticalSectionLocked(void)
2007 struct critsect_locked_info info
;
2011 if (!pRtlIsCriticalSectionLocked
|| !pRtlIsCriticalSectionLockedByThread
)
2013 win_skip("skipping RtlIsCriticalSectionLocked tests, required functions not available\n");
2017 InitializeCriticalSection(&info
.crit
);
2018 info
.semaphores
[0] = CreateSemaphoreW(NULL
, 0, 1, NULL
);
2019 ok(info
.semaphores
[0] != NULL
, "CreateSemaphore failed with %u\n", GetLastError());
2020 info
.semaphores
[1] = CreateSemaphoreW(NULL
, 0, 1, NULL
);
2021 ok(info
.semaphores
[1] != NULL
, "CreateSemaphore failed with %u\n", GetLastError());
2023 ret
= pRtlIsCriticalSectionLocked(&info
.crit
);
2024 ok(ret
== FALSE
, "expected FALSE, got %u\n", ret
);
2025 ret
= pRtlIsCriticalSectionLockedByThread(&info
.crit
);
2026 ok(ret
== FALSE
, "expected FALSE, got %u\n", ret
);
2028 EnterCriticalSection(&info
.crit
);
2030 ret
= pRtlIsCriticalSectionLocked(&info
.crit
);
2031 ok(ret
== TRUE
, "expected TRUE, got %u\n", ret
);
2032 ret
= pRtlIsCriticalSectionLockedByThread(&info
.crit
);
2033 ok(ret
== TRUE
, "expected TRUE, got %u\n", ret
);
2035 thread
= CreateThread(NULL
, 0, critsect_locked_thread
, &info
, 0, NULL
);
2036 ok(thread
!= NULL
, "CreateThread failed with %u\n", GetLastError());
2037 ret
= WaitForSingleObject(info
.semaphores
[0], 1000);
2038 ok(ret
== WAIT_OBJECT_0
, "expected WAIT_OBJECT_0, got %u\n", ret
);
2040 LeaveCriticalSection(&info
.crit
);
2042 ReleaseSemaphore(info
.semaphores
[1], 1, NULL
);
2043 ret
= WaitForSingleObject(info
.semaphores
[0], 1000);
2044 ok(ret
== WAIT_OBJECT_0
, "expected WAIT_OBJECT_0, got %u\n", ret
);
2046 ret
= pRtlIsCriticalSectionLocked(&info
.crit
);
2047 ok(ret
== TRUE
, "expected TRUE, got %u\n", ret
);
2048 ret
= pRtlIsCriticalSectionLockedByThread(&info
.crit
);
2049 ok(ret
== FALSE
, "expected FALSE, got %u\n", ret
);
2051 ReleaseSemaphore(info
.semaphores
[1], 1, NULL
);
2052 ret
= WaitForSingleObject(thread
, 1000);
2053 ok(ret
== WAIT_OBJECT_0
, "expected WAIT_OBJECT_0, got %u\n", ret
);
2055 CloseHandle(thread
);
2056 CloseHandle(info
.semaphores
[0]);
2057 CloseHandle(info
.semaphores
[1]);
2058 DeleteCriticalSection(&info
.crit
);
2061 static void test_RtlInitializeCriticalSectionEx(void)
2063 static const CRITICAL_SECTION_DEBUG
*no_debug
= (void *)~(ULONG_PTR
)0;
2064 CRITICAL_SECTION cs
;
2066 if (!pRtlInitializeCriticalSectionEx
)
2068 win_skip("RtlInitializeCriticalSectionEx is not available\n");
2072 memset(&cs
, 0x11, sizeof(cs
));
2073 pRtlInitializeCriticalSectionEx(&cs
, 0, 0);
2074 ok((cs
.DebugInfo
!= NULL
&& cs
.DebugInfo
!= no_debug
) || broken(cs
.DebugInfo
== no_debug
) /* >= Win 8 */,
2075 "expected DebugInfo != NULL and DebugInfo != ~0, got %p\n", cs
.DebugInfo
);
2076 ok(cs
.LockCount
== -1, "expected LockCount == -1, got %d\n", cs
.LockCount
);
2077 ok(cs
.RecursionCount
== 0, "expected RecursionCount == 0, got %d\n", cs
.RecursionCount
);
2078 ok(cs
.LockSemaphore
== NULL
, "expected LockSemaphore == NULL, got %p\n", cs
.LockSemaphore
);
2079 ok(cs
.SpinCount
== 0 || broken(cs
.SpinCount
!= 0) /* >= Win 8 */,
2080 "expected SpinCount == 0, got %ld\n", cs
.SpinCount
);
2081 RtlDeleteCriticalSection(&cs
);
2083 memset(&cs
, 0x11, sizeof(cs
));
2084 pRtlInitializeCriticalSectionEx(&cs
, 0, RTL_CRITICAL_SECTION_FLAG_NO_DEBUG_INFO
);
2086 ok(cs
.DebugInfo
== no_debug
, "expected DebugInfo == ~0, got %p\n", cs
.DebugInfo
);
2087 ok(cs
.LockCount
== -1, "expected LockCount == -1, got %d\n", cs
.LockCount
);
2088 ok(cs
.RecursionCount
== 0, "expected RecursionCount == 0, got %d\n", cs
.RecursionCount
);
2089 ok(cs
.LockSemaphore
== NULL
, "expected LockSemaphore == NULL, got %p\n", cs
.LockSemaphore
);
2090 ok(cs
.SpinCount
== 0 || broken(cs
.SpinCount
!= 0) /* >= Win 8 */,
2091 "expected SpinCount == 0, got %ld\n", cs
.SpinCount
);
2092 RtlDeleteCriticalSection(&cs
);
2099 test_RtlCompareMemory();
2100 test_RtlCompareMemoryUlong();
2101 test_RtlMoveMemory();
2102 test_RtlFillMemory();
2103 test_RtlFillMemoryUlong();
2104 test_RtlZeroMemory();
2105 test_RtlUlonglongByteSwap();
2108 test_RtlAreAllAccessesGranted();
2109 test_RtlAreAnyAccessesGranted();
2110 test_RtlComputeCrc32();
2111 test_HandleTables();
2112 test_RtlAllocateAndInitializeSid();
2113 test_RtlDeleteTimer();
2114 test_RtlThreadErrorMode();
2115 test_LdrProcessRelocationBlock();
2116 test_RtlIpv4AddressToString();
2117 test_RtlIpv4AddressToStringEx();
2118 test_RtlIpv4StringToAddress();
2119 test_LdrAddRefDll();
2120 test_LdrLockLoaderLock();
2121 test_RtlCompressBuffer();
2122 test_RtlGetCompressionWorkSpaceSize();
2123 test_RtlDecompressBuffer();
2124 test_RtlIsCriticalSectionLocked();
2125 test_RtlInitializeCriticalSectionEx();