ReactOS 0.4.17-dev-116-ga4b6fe9
large_int.c
Go to the documentation of this file.
1/* Unit test suite for Rtl large integer functions
2 *
3 * Copyright 2003 Thomas Mertes
4 *
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.
9 *
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.
14 *
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
18 *
19 * NOTES
20 * We use function pointers here as there is no import library for NTDLL on
21 * windows.
22 */
23
24#include <stdlib.h>
25#include <stdarg.h>
26
27#include "ntstatus.h"
28#define WIN32_NO_STATUS
29#include "windef.h"
30#include "winbase.h"
31#include "winternl.h"
32#include "wine/test.h"
33
34
35/* Function ptrs for ntdll calls */
36static HMODULE hntdll = 0;
37static LONGLONG (WINAPI *pRtlExtendedMagicDivide)(LONGLONG, LONGLONG, INT);
38static VOID (WINAPI *pRtlFreeAnsiString)(PSTRING);
39static NTSTATUS (WINAPI *pRtlInt64ToUnicodeString)(ULONGLONG, ULONG, UNICODE_STRING *);
40static NTSTATUS (WINAPI *pRtlLargeIntegerToChar)(ULONGLONG *, ULONG, ULONG, PCHAR);
41static NTSTATUS (WINAPI *pRtlUnicodeStringToAnsiString)(STRING *, const UNICODE_STRING *, BOOLEAN);
42
43static LONGLONG (WINAPI *p_alldiv)( LONGLONG a, LONGLONG b );
44static LONGLONG (WINAPI *p_allrem)( LONGLONG a, LONGLONG b );
45static LONGLONG (WINAPI *p_allmul)( LONGLONG a, LONGLONG b );
46static ULONGLONG (WINAPI *p_aulldiv)( ULONGLONG a, ULONGLONG b );
47static ULONGLONG (WINAPI *p_aullrem)( ULONGLONG a, ULONGLONG b );
48static void *p_allshl, *p_allshr, *p_aullshr;
49
50static void InitFunctionPtrs(void)
51{
52 hntdll = LoadLibraryA("ntdll.dll");
53 ok(hntdll != 0, "LoadLibrary failed\n");
54 if (hntdll) {
55 pRtlExtendedMagicDivide = (void *)GetProcAddress(hntdll, "RtlExtendedMagicDivide");
56 pRtlFreeAnsiString = (void *)GetProcAddress(hntdll, "RtlFreeAnsiString");
57 pRtlInt64ToUnicodeString = (void *)GetProcAddress(hntdll, "RtlInt64ToUnicodeString");
58 pRtlLargeIntegerToChar = (void *)GetProcAddress(hntdll, "RtlLargeIntegerToChar");
59 pRtlUnicodeStringToAnsiString = (void *)GetProcAddress(hntdll, "RtlUnicodeStringToAnsiString");
60
61 p_alldiv = (void *)GetProcAddress(hntdll, "_alldiv");
62 p_allrem = (void *)GetProcAddress(hntdll, "_allrem");
63 p_allmul = (void *)GetProcAddress(hntdll, "_allmul");
64 p_allshl = (void *)GetProcAddress(hntdll, "_allshl");
65 p_allshr = (void *)GetProcAddress(hntdll, "_allshr");
66 p_aulldiv = (void *)GetProcAddress(hntdll, "_aulldiv");
67 p_aullrem = (void *)GetProcAddress(hntdll, "_aullrem");
68 p_aullshr = (void *)GetProcAddress(hntdll, "_aullshr");
69 } /* if */
70}
71
72#define ULL(a,b) (((ULONGLONG)(a) << 32) | (b))
73
74typedef struct {
80
81static const magic_divide_t magic_divide[] = {
82 { 3, ULL(0x55555555,0x55555555), 0, 0}, /* 1 */
83 { 333333333, ULL(0x55555555,0x55555555), 0, 111111110}, /* 111111111 */
84 { ULL(0x7fffffff,0xffffffff), ULL(0x55555555,0x55555555), 0, ULL(0x2aaaaaaa,0xaaaaaaaa)},
85 { 3, ULL(0xaaaaaaaa,0xaaaaaaaa), 1, 0}, /* 1 */
86 { 333333333, ULL(0xaaaaaaaa,0xaaaaaaaa), 1, 111111110}, /* 111111111 */
87 { ULL(0x7fffffff,0xffffffff), ULL(0xaaaaaaaa,0xaaaaaaaa), 1, ULL(0x2aaaaaaa,0xaaaaaaaa)},
88 { -3, ULL(0x55555555,0x55555555), 0, 0}, /* -1 */
89 { -333333333, ULL(0x55555555,0x55555555), 0, -111111110}, /* -111111111 */
90 {-ULL(0x7fffffff,0xffffffff), ULL(0x55555555,0x55555555), 0, -ULL(0x2aaaaaaa,0xaaaaaaaa)},
91 { -3, ULL(0xaaaaaaaa,0xaaaaaaaa), 1, 0}, /* -1 */
92 { -333333333, ULL(0xaaaaaaaa,0xaaaaaaaa), 1, -111111110}, /* -111111111 */
93 {-ULL(0x7fffffff,0xffffffff), ULL(0xaaaaaaaa,0xaaaaaaaa), 1, -ULL(0x2aaaaaaa,0xaaaaaaaa)},
94 { -3, -ULL(0x55555555,0x55555555), 0, -2}, /* -1 */
95 { -333333333, -ULL(0x55555555,0x55555555), 0, -222222222}, /* -111111111 */
96 {-ULL(0x7fffffff,0xffffffff), -ULL(0x55555555,0x55555555), 0, -ULL(0x55555555,0x55555554)},
97 { -3, -ULL(0xaaaaaaaa,0xaaaaaaaa), 1, 0}, /* -1 */
98 { -333333333, -ULL(0xaaaaaaaa,0xaaaaaaaa), 1, -55555555}, /* -111111111 */
99 {-ULL(0x7fffffff,0xffffffff), -ULL(0xaaaaaaaa,0xaaaaaaaa), 1, -ULL(0x15555555,0x55555555)},
100 { 3, -ULL(0x55555555,0x55555555), 0, 2}, /* -1 */
101 { 333333333, -ULL(0x55555555,0x55555555), 0, 222222222}, /* -111111111 */
102 { ULL(0x7fffffff,0xffffffff), -ULL(0x55555555,0x55555555), 0, ULL(0x55555555,0x55555554)},
103 { 3, -ULL(0xaaaaaaaa,0xaaaaaaaa), 1, 0}, /* -1 */
104 { 333333333, -ULL(0xaaaaaaaa,0xaaaaaaaa), 1, 55555555}, /* -111111111 */
105 { ULL(0x7fffffff,0xffffffff), -ULL(0xaaaaaaaa,0xaaaaaaaa), 1, ULL(0x15555555,0x55555555)},
106 { 3, ULL(0xaaaaaaaa,0xaaaaa800), 1, 0}, /* 1 */
107 { 333333333, ULL(0xaaaaaaaa,0xaaaaa800), 1, 111111110}, /* 111111111 */
108 { ULL(0x7fffffff,0xffffffff), ULL(0xaaaaaaaa,0xaaaaa800), 1, ULL(0x2aaaaaaa,0xaaaaa9ff)}, /* 0x2aaaaaaaaaaaaaaa */
109 { 5, ULL(0x33333333,0x333333ff), 0, 1},
110 { 555555555, ULL(0x33333333,0x333333ff), 0, 111111111},
111 { ULL(0x7fffffff,0xffffffff), ULL(0x33333333,0x333333ff), 0, ULL(0x19999999,0x999999ff)}, /* 0x199999999999999a */
112 { 5, ULL(0x66666666,0x666667fe), 1, 1},
113 { 555555555, ULL(0x66666666,0x666667fe), 1, 111111111},
114 { ULL(0x7fffffff,0xffffffff), ULL(0x66666666,0x666667fe), 1, ULL(0x19999999,0x999999ff)}, /* 0x199999999999999a */
115 { 5, ULL(0xcccccccc,0xcccccffd), 2, 1},
116 { 555555555, ULL(0xcccccccc,0xcccccffd), 2, 111111111},
117 { ULL(0x7fffffff,0xffffffff), ULL(0xcccccccc,0xcccccffd), 2, ULL(0x19999999,0x999999ff)}, /* 0x199999999999999a */
118 { ULL(0x00000add,0xcafeface), ULL(0x002f1e28,0xfd1b5cca), 33, 1},
119 { ULL(0x081ac1b9,0xc2310a80), ULL(0x002f1e28,0xfd1b5cca), 33, 0xbeef},
120 { ULL(0x74ae3b5f,0x1558c800), ULL(0x002f1e28,0xfd1b5cca), 33, 0xabcde},
121 { ULL(0x00000add,0xcafeface), ULL(0x2f1e28fd,0x1b5cca00), 41, 1},
122 { ULL(0x081ac1b9,0xc2310a80), ULL(0x2f1e28fd,0x1b5cca00), 41, 0xbeef},
123 { ULL(0x74ae3b5f,0x1558c800), ULL(0x2f1e28fd,0x1b5cca00), 41, 0xabcde},
124
125};
126
127
129{
130 int i;
132
133 for (i = 0; i < ARRAY_SIZE(magic_divide); i++) {
134 result = pRtlExtendedMagicDivide(magic_divide[i].a, magic_divide[i].b, magic_divide[i].shift);
136 "call failed: RtlExtendedMagicDivide(0x%s, 0x%s, %d) has result 0x%s, expected 0x%s\n",
139 }
140}
141
142
143#define LARGE_STRI_BUFFER_LENGTH 67
144
145typedef struct {
146 int base;
150 const char *Buffer;
154
155/*
156 * The native DLL does produce garbage or STATUS_BUFFER_OVERFLOW for
157 * base 2, 8 and 16 when the value is larger than 0xFFFFFFFF.
158 * Therefore these testcases are commented out.
159 */
160
161static const largeint2str_t largeint2str[] = {
162 {10, 123, 3, 11, "123\0---------------------------------------------------------------", STATUS_SUCCESS},
163
164 { 0, 0x80000000U, 10, 11, "2147483648\0--------------------------------------------------------", STATUS_SUCCESS},
165 { 0, -2147483647, 20, 21, "18446744071562067969\0----------------------------------------------", STATUS_SUCCESS},
166 { 0, -2, 20, 21, "18446744073709551614\0----------------------------------------------", STATUS_SUCCESS},
167 { 0, -1, 20, 21, "18446744073709551615\0----------------------------------------------", STATUS_SUCCESS},
168 { 0, 0, 1, 11, "0\0-----------------------------------------------------------------", STATUS_SUCCESS},
169 { 0, 1, 1, 11, "1\0-----------------------------------------------------------------", STATUS_SUCCESS},
170 { 0, 12, 2, 11, "12\0----------------------------------------------------------------", STATUS_SUCCESS},
171 { 0, 123, 3, 11, "123\0---------------------------------------------------------------", STATUS_SUCCESS},
172 { 0, 1234, 4, 11, "1234\0--------------------------------------------------------------", STATUS_SUCCESS},
173 { 0, 12345, 5, 11, "12345\0-------------------------------------------------------------", STATUS_SUCCESS},
174 { 0, 123456, 6, 11, "123456\0------------------------------------------------------------", STATUS_SUCCESS},
175 { 0, 1234567, 7, 11, "1234567\0-----------------------------------------------------------", STATUS_SUCCESS},
176 { 0, 12345678, 8, 11, "12345678\0----------------------------------------------------------", STATUS_SUCCESS},
177 { 0, 123456789, 9, 11, "123456789\0---------------------------------------------------------", STATUS_SUCCESS},
178 { 0, 2147483646, 10, 11, "2147483646\0--------------------------------------------------------", STATUS_SUCCESS},
179 { 0, 2147483647, 10, 11, "2147483647\0--------------------------------------------------------", STATUS_SUCCESS},
180 { 0, 2147483648U, 10, 11, "2147483648\0--------------------------------------------------------", STATUS_SUCCESS},
181 { 0, 2147483649U, 10, 11, "2147483649\0--------------------------------------------------------", STATUS_SUCCESS},
182 { 0, 4294967294U, 10, 11, "4294967294\0--------------------------------------------------------", STATUS_SUCCESS},
183 { 0, 4294967295U, 10, 11, "4294967295\0--------------------------------------------------------", STATUS_SUCCESS},
184 { 0, ULL(0x2,0xdfdc1c35), 11, 12, "12345678901\0-------------------------------------------------------", STATUS_SUCCESS},
185 { 0, ULL(0xe5,0xf4c8f374), 12, 13, "987654321012\0------------------------------------------------------", STATUS_SUCCESS},
186 { 0, ULL(0x1c0,0xfc161e3e), 13, 14, "1928374656574\0-----------------------------------------------------", STATUS_SUCCESS},
187 { 0, ULL(0xbad,0xcafeface), 14, 15, "12841062955726\0----------------------------------------------------", STATUS_SUCCESS},
188 { 0, ULL(0x5bad,0xcafeface), 15, 16, "100801993177806\0---------------------------------------------------", STATUS_SUCCESS},
189 { 0, ULL(0xaface,0xbeefcafe), 16, 20, "3090515640699646\0--------------------------------------------------", STATUS_SUCCESS},
190 { 0, ULL(0xa5beef,0xabcdcafe), 17, 20, "46653307746110206\0-------------------------------------------------", STATUS_SUCCESS},
191 { 0, ULL(0x1f8cf9b,0xf2df3af1), 18, 20, "142091656963767025\0------------------------------------------------", STATUS_SUCCESS},
192 { 0, ULL(0x0fffffff,0xffffffff), 19, 20, "1152921504606846975\0-----------------------------------------------", STATUS_SUCCESS},
193 { 0, ULL(0xffffffff,0xfffffffe), 20, 21, "18446744073709551614\0----------------------------------------------", STATUS_SUCCESS},
194 { 0, ULL(0xffffffff,0xffffffff), 20, 21, "18446744073709551615\0----------------------------------------------", STATUS_SUCCESS},
195
196 { 2, 0x80000000U, 32, 33, "10000000000000000000000000000000\0----------------------------------", STATUS_SUCCESS},
197/*
198 * { 2, -2147483647, 64, 65, "1111111111111111111111111111111110000000000000000000000000000001\0--", STATUS_SUCCESS},
199 * { 2, -2, 64, 65, "1111111111111111111111111111111111111111111111111111111111111110\0--", STATUS_SUCCESS},
200 * { 2, -1, 64, 65, "1111111111111111111111111111111111111111111111111111111111111111\0--", STATUS_SUCCESS},
201 */
202 { 2, 0, 1, 33, "0\0-----------------------------------------------------------------", STATUS_SUCCESS},
203 { 2, 1, 1, 33, "1\0-----------------------------------------------------------------", STATUS_SUCCESS},
204 { 2, 10, 4, 33, "1010\0--------------------------------------------------------------", STATUS_SUCCESS},
205 { 2, 100, 7, 33, "1100100\0-----------------------------------------------------------", STATUS_SUCCESS},
206 { 2, 1000, 10, 33, "1111101000\0--------------------------------------------------------", STATUS_SUCCESS},
207 { 2, 10000, 14, 33, "10011100010000\0----------------------------------------------------", STATUS_SUCCESS},
208 { 2, 32767, 15, 33, "111111111111111\0---------------------------------------------------", STATUS_SUCCESS},
209 { 2, 32768, 16, 33, "1000000000000000\0--------------------------------------------------", STATUS_SUCCESS},
210 { 2, 65535, 16, 33, "1111111111111111\0--------------------------------------------------", STATUS_SUCCESS},
211 { 2, 100000, 17, 33, "11000011010100000\0-------------------------------------------------", STATUS_SUCCESS},
212 { 2, 1000000, 20, 33, "11110100001001000000\0----------------------------------------------", STATUS_SUCCESS},
213 { 2, 10000000, 24, 33, "100110001001011010000000\0------------------------------------------", STATUS_SUCCESS},
214 { 2, 100000000, 27, 33, "101111101011110000100000000\0---------------------------------------", STATUS_SUCCESS},
215 { 2, 1000000000, 30, 33, "111011100110101100101000000000\0------------------------------------", STATUS_SUCCESS},
216 { 2, 1073741823, 30, 33, "111111111111111111111111111111\0------------------------------------", STATUS_SUCCESS},
217 { 2, 2147483646, 31, 33, "1111111111111111111111111111110\0-----------------------------------", STATUS_SUCCESS},
218 { 2, 2147483647, 31, 33, "1111111111111111111111111111111\0-----------------------------------", STATUS_SUCCESS},
219 { 2, 2147483648U, 32, 33, "10000000000000000000000000000000\0----------------------------------", STATUS_SUCCESS},
220 { 2, 2147483649U, 32, 33, "10000000000000000000000000000001\0----------------------------------", STATUS_SUCCESS},
221 { 2, 4294967294U, 32, 33, "11111111111111111111111111111110\0----------------------------------", STATUS_SUCCESS},
222 { 2, 0xFFFFFFFF, 32, 33, "11111111111111111111111111111111\0----------------------------------", STATUS_SUCCESS},
223/*
224 * { 2, 0x1FFFFFFFF, 33, 34, "111111111111111111111111111111111\0---------------------------------", STATUS_SUCCESS},
225 * { 2, 0x3FFFFFFFF, 34, 35, "1111111111111111111111111111111111\0--------------------------------", STATUS_SUCCESS},
226 * { 2, 0x7FFFFFFFF, 35, 36, "11111111111111111111111111111111111\0-------------------------------", STATUS_SUCCESS},
227 * { 2, 0xFFFFFFFFF, 36, 37, "111111111111111111111111111111111111\0------------------------------", STATUS_SUCCESS},
228 * { 2, 0x1FFFFFFFFF, 37, 38, "1111111111111111111111111111111111111\0-----------------------------", STATUS_SUCCESS},
229 * { 2, 0x3FFFFFFFFF, 38, 39, "11111111111111111111111111111111111111\0----------------------------", STATUS_SUCCESS},
230 * { 2, 0x7FFFFFFFFF, 39, 40, "111111111111111111111111111111111111111\0---------------------------", STATUS_SUCCESS},
231 * { 2, 0xFFFFFFFFFF, 40, 41, "1111111111111111111111111111111111111111\0--------------------------", STATUS_SUCCESS},
232 */
233
234 { 8, 0x80000000U, 11, 12, "20000000000\0-------------------------------------------------------", STATUS_SUCCESS},
235/*
236 * { 8, -2147483647, 22, 23, "1777777777760000000001\0--------------------------------------------", STATUS_SUCCESS},
237 * { 8, -2, 22, 23, "1777777777777777777776\0--------------------------------------------", STATUS_SUCCESS},
238 * { 8, -1, 22, 23, "1777777777777777777777\0--------------------------------------------", STATUS_SUCCESS},
239 */
240 { 8, 0, 1, 12, "0\0-----------------------------------------------------------------", STATUS_SUCCESS},
241 { 8, 1, 1, 12, "1\0-----------------------------------------------------------------", STATUS_SUCCESS},
242 { 8, 2147483646, 11, 12, "17777777776\0-------------------------------------------------------", STATUS_SUCCESS},
243 { 8, 2147483647, 11, 12, "17777777777\0-------------------------------------------------------", STATUS_SUCCESS},
244 { 8, 2147483648U, 11, 12, "20000000000\0-------------------------------------------------------", STATUS_SUCCESS},
245 { 8, 2147483649U, 11, 12, "20000000001\0-------------------------------------------------------", STATUS_SUCCESS},
246 { 8, 4294967294U, 11, 12, "37777777776\0-------------------------------------------------------", STATUS_SUCCESS},
247 { 8, 4294967295U, 11, 12, "37777777777\0-------------------------------------------------------", STATUS_SUCCESS},
248
249 {10, 0x80000000U, 10, 11, "2147483648\0--------------------------------------------------------", STATUS_SUCCESS},
250 {10, -2147483647, 20, 21, "18446744071562067969\0----------------------------------------------", STATUS_SUCCESS},
251 {10, -2, 20, 21, "18446744073709551614\0----------------------------------------------", STATUS_SUCCESS},
252 {10, -1, 20, 21, "18446744073709551615\0----------------------------------------------", STATUS_SUCCESS},
253 {10, 0, 1, 11, "0\0-----------------------------------------------------------------", STATUS_SUCCESS},
254 {10, 1, 1, 11, "1\0-----------------------------------------------------------------", STATUS_SUCCESS},
255 {10, 2147483646, 10, 11, "2147483646\0--------------------------------------------------------", STATUS_SUCCESS},
256 {10, 2147483647, 10, 11, "2147483647\0--------------------------------------------------------", STATUS_SUCCESS},
257 {10, 2147483648U, 10, 11, "2147483648\0--------------------------------------------------------", STATUS_SUCCESS},
258 {10, 2147483649U, 10, 11, "2147483649\0--------------------------------------------------------", STATUS_SUCCESS},
259 {10, 4294967294U, 10, 11, "4294967294\0--------------------------------------------------------", STATUS_SUCCESS},
260 {10, 4294967295U, 10, 11, "4294967295\0--------------------------------------------------------", STATUS_SUCCESS},
261
262 {16, 0, 1, 9, "0\0-----------------------------------------------------------------", STATUS_SUCCESS},
263 {16, 1, 1, 9, "1\0-----------------------------------------------------------------", STATUS_SUCCESS},
264 {16, 2147483646, 8, 9, "7FFFFFFE\0----------------------------------------------------------", STATUS_SUCCESS},
265 {16, 2147483647, 8, 9, "7FFFFFFF\0----------------------------------------------------------", STATUS_SUCCESS},
266 {16, 0x80000000, 8, 9, "80000000\0----------------------------------------------------------", STATUS_SUCCESS},
267 {16, 0x80000001, 8, 9, "80000001\0----------------------------------------------------------", STATUS_SUCCESS},
268 {16, 0xFFFFFFFE, 8, 9, "FFFFFFFE\0----------------------------------------------------------", STATUS_SUCCESS},
269 {16, 0xFFFFFFFF, 8, 9, "FFFFFFFF\0----------------------------------------------------------", STATUS_SUCCESS},
270/*
271 * {16, 0x100000000, 9, 10, "100000000\0---------------------------------------------------------", STATUS_SUCCESS},
272 * {16, 0xBADDEADBEEF, 11, 12, "BADDEADBEEF\0-------------------------------------------------------", STATUS_SUCCESS},
273 * {16, 0x8000000000000000, 16, 17, "8000000000000000\0--------------------------------------------------", STATUS_SUCCESS},
274 * {16, 0xFEDCBA9876543210, 16, 17, "FEDCBA9876543210\0--------------------------------------------------", STATUS_SUCCESS},
275 * {16, 0xFFFFFFFF80000001, 16, 17, "FFFFFFFF80000001\0--------------------------------------------------", STATUS_SUCCESS},
276 * {16, 0xFFFFFFFFFFFFFFFE, 16, 17, "FFFFFFFFFFFFFFFE\0--------------------------------------------------", STATUS_SUCCESS},
277 * {16, 0xFFFFFFFFFFFFFFFF, 16, 17, "FFFFFFFFFFFFFFFF\0--------------------------------------------------", STATUS_SUCCESS},
278 */
279
280 { 2, 32768, 16, 17, "1000000000000000\0--------------------------------------------------", STATUS_SUCCESS},
281 { 2, 32768, 16, 16, "1000000000000000---------------------------------------------------", STATUS_SUCCESS, 1},
282 { 2, 65536, 17, 18, "10000000000000000\0-------------------------------------------------", STATUS_SUCCESS},
283 { 2, 65536, 17, 17, "10000000000000000--------------------------------------------------", STATUS_SUCCESS, 1},
284 { 2, 131072, 18, 19, "100000000000000000\0------------------------------------------------", STATUS_SUCCESS},
285 { 2, 131072, 18, 18, "100000000000000000-------------------------------------------------", STATUS_SUCCESS, 1},
286 {16, 0xffffffff, 8, 9, "FFFFFFFF\0----------------------------------------------------------", STATUS_SUCCESS},
287 {16, 0xffffffff, 8, 8, "FFFFFFFF-----------------------------------------------------------", STATUS_SUCCESS, 1},
288 {16, 0xffffffff, 8, 7, "-------------------------------------------------------------------", STATUS_BUFFER_OVERFLOW, 1},
289 {16, 0xa, 1, 2, "A\0-----------------------------------------------------------------", STATUS_SUCCESS},
290 {16, 0xa, 1, 1, "A------------------------------------------------------------------", STATUS_SUCCESS, 1},
291 {16, 0, 1, 0, "-------------------------------------------------------------------", STATUS_BUFFER_OVERFLOW, 1},
292 {20, 0xdeadbeef, 0, 9, "-------------------------------------------------------------------", STATUS_INVALID_PARAMETER},
293 {-8, 07654321, 0, 12, "-------------------------------------------------------------------", STATUS_INVALID_PARAMETER},
294};
295
296
298{
299 int pos;
300 WCHAR expected_str_Buffer[LARGE_STRI_BUFFER_LENGTH + 1];
301 UNICODE_STRING expected_unicode_string;
302 STRING expected_ansi_str;
303 WCHAR str_Buffer[LARGE_STRI_BUFFER_LENGTH + 1];
304 UNICODE_STRING unicode_string;
305 STRING ansi_str;
307
308#ifdef _WIN64
309 if (largeint2str->value >> 32 == 0xffffffff) /* this crashes on 64-bit Vista */
310 {
311 skip( "Value ffffffff%08lx broken on 64-bit windows\n", (DWORD)largeint2str->value );
312 return;
313 }
314#endif
315
316 for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) {
317 expected_str_Buffer[pos] = largeint2str->Buffer[pos];
318 } /* for */
319 expected_unicode_string.Length = largeint2str->Length * sizeof(WCHAR);
320 expected_unicode_string.MaximumLength = largeint2str->MaximumLength * sizeof(WCHAR);
321 expected_unicode_string.Buffer = expected_str_Buffer;
322 pRtlUnicodeStringToAnsiString(&expected_ansi_str, &expected_unicode_string, 1);
323
324 for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) {
325 str_Buffer[pos] = '-';
326 } /* for */
327 unicode_string.Length = 0;
328 unicode_string.MaximumLength = largeint2str->MaximumLength * sizeof(WCHAR);
329 unicode_string.Buffer = str_Buffer;
330
331 if (largeint2str->base == 0) {
332 result = pRtlInt64ToUnicodeString(largeint2str->value, 10, &unicode_string);
333 } else {
334 result = pRtlInt64ToUnicodeString(largeint2str->value, largeint2str->base, &unicode_string);
335 } /* if */
336 pRtlUnicodeStringToAnsiString(&ansi_str, &unicode_string, 1);
338 /* On BUFFER_OVERFLOW the string Buffer should be unchanged */
339 for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) {
340 expected_str_Buffer[pos] = '-';
341 } /* for */
342 /* w2k: The native function has two reasons for BUFFER_OVERFLOW: */
343 /* If the value is too large to convert: The Length is unchanged */
344 /* If str is too small to hold the string: Set str->Length to the length */
345 /* the string would have (which can be larger than the MaximumLength). */
346 /* To allow all this in the tests we do the following: */
347 if (expected_unicode_string.Length >= 64) {
348 /* The value is too large to convert only triggered when testing native */
349 /* Length is not filled with the expected string length (garbage?) */
350 expected_unicode_string.Length = unicode_string.Length;
351 } /* if */
352 } else {
354 "(test %d): RtlInt64ToUnicodeString(0x%s, %d, [out]) has result %lx, expected: %lx\n",
356 if (result == STATUS_SUCCESS) {
357 ok(unicode_string.Buffer[unicode_string.Length/sizeof(WCHAR)] == '\0',
358 "(test %d): RtlInt64ToUnicodeString(0x%s, %d, [out]) string \"%s\" is not NULL terminated\n",
359 test_num, wine_dbgstr_longlong(largeint2str->value), largeint2str->base, ansi_str.Buffer);
360 } /* if */
361 } /* if */
362 ok(memcmp(unicode_string.Buffer, expected_unicode_string.Buffer, LARGE_STRI_BUFFER_LENGTH * sizeof(WCHAR)) == 0,
363 "(test %d): RtlInt64ToUnicodeString(0x%I64x, %d, [out]) assigns string \"%s\", expected: \"%s\"\n",
364 test_num, largeint2str->value, largeint2str->base, ansi_str.Buffer, expected_ansi_str.Buffer);
365 ok(unicode_string.Length == expected_unicode_string.Length ||
366 broken(largeint2str->broken_len && !unicode_string.Length) /* win11 */,
367 "(test %d): RtlInt64ToUnicodeString(0x%s, %d, [out]) string has Length %d, expected: %d\n",
369 unicode_string.Length, expected_unicode_string.Length);
370 ok(unicode_string.MaximumLength == expected_unicode_string.MaximumLength,
371 "(test %d): RtlInt64ToUnicodeString(0x%s, %d, [out]) string has MaximumLength %d, expected: %d\n",
373 unicode_string.MaximumLength, expected_unicode_string.MaximumLength);
374 pRtlFreeAnsiString(&expected_ansi_str);
375 pRtlFreeAnsiString(&ansi_str);
376}
377
378
380{
381 int test_num;
382
383 for (test_num = 0; test_num < ARRAY_SIZE(largeint2str); test_num++) {
385 } /* for */
386}
387
388
390{
392 char dest_str[LARGE_STRI_BUFFER_LENGTH + 1];
394
395#ifdef _WIN64
396 if (largeint2str->value >> 32 == 0xffffffff) /* this crashes on 64-bit Vista */
397 {
398 skip( "Value ffffffff%08lx broken on 64-bit windows\n", (DWORD)largeint2str->value );
399 return;
400 }
401#endif
402
403 memset(dest_str, '-', LARGE_STRI_BUFFER_LENGTH);
404 dest_str[LARGE_STRI_BUFFER_LENGTH] = '\0';
406 if (largeint2str->base == 0) {
407 result = pRtlLargeIntegerToChar(&value, 10, largeint2str->MaximumLength, dest_str);
408 } else {
409 result = pRtlLargeIntegerToChar(&value, largeint2str->base, largeint2str->MaximumLength, dest_str);
410 } /* if */
412 "(test %d): RtlLargeIntegerToChar(0x%s, %d, %d, [out]) has result %lx, expected: %lx\n",
416 "(test %d): RtlLargeIntegerToChar(0x%s, %d, %d, [out]) assigns string \"%s\", expected: \"%s\"\n",
419}
420
421
423{
425 int test_num;
427
428 for (test_num = 0; test_num < ARRAY_SIZE(largeint2str); test_num++) {
429 one_RtlLargeIntegerToChar_test(test_num, &largeint2str[test_num]);
430 } /* for */
431
433 result = pRtlLargeIntegerToChar(&value, 20, largeint2str[0].MaximumLength, NULL);
435 "(test a): RtlLargeIntegerToChar(0x%s, %d, %d, NULL) has result %lx, expected: %lx\n",
438
439 result = pRtlLargeIntegerToChar(&value, 20, 0, NULL);
441 "(test b): RtlLargeIntegerToChar(0x%s, %d, %d, NULL) has result %lx, expected: %lx\n",
444
445 result = pRtlLargeIntegerToChar(&value, largeint2str[0].base, 0, NULL);
447 "(test c): RtlLargeIntegerToChar(0x%s, %d, %d, NULL) has result %lx, expected: %lx\n",
449
450 result = pRtlLargeIntegerToChar(&value, largeint2str[0].base, largeint2str[0].MaximumLength, NULL);
452 "(test d): RtlLargeIntegerToChar(0x%s, %d, %d, NULL) has result %lx, expected: %lx\n",
455}
456
457static void test_builtins(void)
458{
459#ifdef __i386__
460 void *code_mem;
461 ULONGLONG u;
462 LONGLONG l;
463
464 static const BYTE call_shift_code[] =
465 {
466 0x55, /* pushl %ebp */
467 0x89, 0xe5, /* movl %esp,%ebp */
468 0x31, 0xc0, /* xorl %eax,%eax */
469 0x31, 0xd2, /* xorl %edx,%edx */
470 0x31, 0xc9, /* xorl %ecx,%ecx */
471 0x87, 0x45, 0x0c, /* xchgl 12(%ebp),%eax */
472 0x87, 0x55, 0x10, /* xchgl 16(%ebp),%edx */
473 0x87, 0x4d, 0x14, /* xchgl 20(%ebp),%ecx */
474 0xff, 0x55, 0x08, /* call *8(%ebp) */
475 0x39, 0xe5, /* cmpl %esp,%ebp */
476 0x74, 0x05, /* je 1f */
477 0xb8, 0xef, 0xbe, 0xad, 0xde, /* movl $0xdeadbeef,%eax */
478 0xc9, /* leave */
479 0xc3, /* ret */
480 };
481 LONGLONG (__cdecl *call_shift_func)(void *func, LONGLONG a, LONG b);
482
484
485 l = p_alldiv(100, 7);
486 ok(l == 14, "_alldiv returned %s\n", wine_dbgstr_longlong(l));
487
488 l = p_alldiv(-100, 7);
489 ok(l == -14, "_alldiv returned %s\n", wine_dbgstr_longlong(l));
490
491 l = p_alldiv(0x2000000040ll, 0x100000007ll);
492 ok(l == 0x1f, "_alldiv returned %s\n", wine_dbgstr_longlong(l));
493
494 u = p_aulldiv(100, 7);
495 ok(u == 14, "_aulldiv returned %s\n", wine_dbgstr_longlong(u));
496
497 u = p_aulldiv(-100, 7);
498 ok(u == 0x2492492492492484ull, "_alldiv returned %s\n", wine_dbgstr_longlong(u));
499
500 u = p_aulldiv(0x2000000040ull, 0x100000007ull);
501 ok(u == 0x1f, "_aulldiv returned %s\n", wine_dbgstr_longlong(u));
502
503 l = p_allrem(100, 7);
504 ok(l == 2, "_allrem returned %s\n", wine_dbgstr_longlong(l));
505
506 l = p_allrem(-100, 7);
507 ok(l == -2, "_allrem returned %s\n", wine_dbgstr_longlong(l));
508
509 l = p_allrem(0x2000000040ll, 0x100000007ll);
510 ok(l == 0xffffff67, "_allrem returned %s\n", wine_dbgstr_longlong(l));
511
512 u = p_aullrem(100, 7);
513 ok(u == 2, "_aullrem returned %s\n", wine_dbgstr_longlong(u));
514
515 u = p_aullrem(-100, 7);
516 ok(u == 0, "_allrem returned %s\n", wine_dbgstr_longlong(u));
517
518 u = p_aullrem(0x2000000040ull, 0x100000007ull);
519 ok(u == 0xffffff67, "_aullrem returned %s\n", wine_dbgstr_longlong(u));
520
521 l = p_allmul(3, 4);
522 ok(l == 12, "_allmul = %s\n", wine_dbgstr_longlong(l));
523
524 l = p_allmul(0x300000001ll, 4);
525 ok(l == 0xc00000004, "_allmul = %s\n", wine_dbgstr_longlong(l));
526
527 memcpy(code_mem, call_shift_code, sizeof(call_shift_code));
528 call_shift_func = code_mem;
529
530 l = call_shift_func(p_allshl, 0x0123456789abcdefll, 12);
531 ok(l == 0x3456789abcdef000ll, "got %#I64x\n", l);
532
533 l = call_shift_func(p_allshl, 0x0123456789abcdefll, 44);
534 ok(l == 0xbcdef00000000000ll, "got %#I64x\n", l);
535
536 l = call_shift_func(p_allshl, 0x0123456789abcdefll, 88);
537 ok(!l, "got %#I64x\n", l);
538
539 l = call_shift_func(p_allshl, 0x0123456789abcdefll, 0x88);
540 ok(!l, "got %#I64x\n", l);
541
542 l = call_shift_func(p_allshl, 0x0123456789abcdefll, 0x108);
543 ok(l == 0x23456789abcdef00ll, "got %#I64x\n", l);
544
545 l = call_shift_func(p_allshr, 0x0123456789abcdefll, 12);
546 ok(l == 0x0123456789abcll, "got %#I64x\n", l);
547
548 l = call_shift_func(p_allshr, 0x0123456789abcdefll, 44);
549 ok(l == 0x01234ll, "got %#I64x\n", l);
550
551 l = call_shift_func(p_allshr, 0x0123456789abcdefll, 88);
552 ok(!l, "got %#I64x\n", l);
553
554 l = call_shift_func(p_allshr, 0x8123456789abcdefll, 12);
555 ok(l == 0xfff8123456789abcll, "got %#I64x\n", l);
556
557 l = call_shift_func(p_allshr, 0x8123456789abcdefll, 44);
558 ok(l == 0xfffffffffff81234ll, "got %#I64x\n", l);
559
560 l = call_shift_func(p_allshr, 0x8123456789abcdefll, 88);
561 ok(l == -1ll, "got %#I64x\n", l);
562
563 l = call_shift_func(p_allshr, 0x8123456789abcdefll, 0x108);
564 ok(l == 0xff8123456789abcdll, "got %#I64x\n", l);
565
566 l = call_shift_func(p_aullshr, 0x8123456789abcdefll, 12);
567 ok(l == 0x8123456789abcll, "got %#I64x\n", l);
568
569 l = call_shift_func(p_aullshr, 0x8123456789abcdefll, 44);
570 ok(l == 0x81234ll, "got %#I64x\n", l);
571
572 l = call_shift_func(p_aullshr, 0x8123456789abcdefll, 88);
573 ok(!l, "got %#I64x\n", l);
574
575 l = call_shift_func(p_aullshr, 0x8123456789abcdefll, 0x108);
576 ok(l == 0x8123456789abcdll, "got %#I64x\n", l);
577
579#endif /* __i386__ */
580}
581
582START_TEST(large_int)
583{
585
586 if (pRtlExtendedMagicDivide)
588 if (pRtlInt64ToUnicodeString)
590 if (pRtlLargeIntegerToChar)
593}
#define VOID
Definition: acefi.h:82
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define broken(x)
Definition: atltest.h:178
#define START_TEST(x)
Definition: atltest.h:75
LONG NTSTATUS
Definition: precomp.h:26
#define ARRAY_SIZE(A)
Definition: main.h:20
r l[0]
Definition: byte_order.h:168
#define NULL
Definition: types.h:112
#define NTSTATUS
Definition: precomp.h:19
#define GetProcAddress(x, y)
Definition: compat.h:753
static __inline const char * wine_dbgstr_longlong(ULONGLONG ll)
Definition: compat.h:49
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
#define __cdecl
Definition: corecrt.h:121
_ACRTIMP int __cdecl memcmp(const void *, const void *, size_t)
Definition: string.c:2802
unsigned long DWORD
Definition: ntddk_ex.h:95
std::wstring STRING
Definition: fontsub.cpp:33
#define STATUS_ACCESS_VIOLATION
GLenum func
Definition: glext.h:6028
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLuint64EXT * result
Definition: glext.h:11304
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble * u
Definition: glfuncs.h:240
#define a
Definition: ke_i.h:78
static HMODULE hntdll
Definition: large_int.c:36
static ULONG
Definition: large_int.c:39
static LONGLONG b
Definition: large_int.c:43
static void one_RtlLargeIntegerToChar_test(int test_num, const largeint2str_t *largeint2str)
Definition: large_int.c:389
#define ULL(a, b)
Definition: large_int.c:72
static INT
Definition: large_int.c:37
static void * p_allshl
Definition: large_int.c:48
static const magic_divide_t magic_divide[]
Definition: large_int.c:81
static void test_RtlInt64ToUnicodeString(void)
Definition: large_int.c:379
static UNICODE_STRING *static PCHAR
Definition: large_int.c:40
static void InitFunctionPtrs(void)
Definition: large_int.c:50
static void test_RtlExtendedMagicDivide(void)
Definition: large_int.c:128
static void * p_aullshr
Definition: large_int.c:48
static const largeint2str_t largeint2str[]
Definition: large_int.c:161
static void * p_allshr
Definition: large_int.c:48
static void test_RtlLargeIntegerToChar(void)
Definition: large_int.c:422
#define LARGE_STRI_BUFFER_LENGTH
Definition: large_int.c:143
static void one_RtlInt64ToUnicodeString_test(int test_num, const largeint2str_t *largeint2str)
Definition: large_int.c:297
static const UNICODE_STRING BOOLEAN
Definition: large_int.c:41
static LONGLONG
Definition: large_int.c:37
static void test_builtins(void)
Definition: large_int.c:457
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static void * code_mem
Definition: exception.c:51
#define shift
Definition: input.c:3280
#define MEM_RESERVE
Definition: nt_native.h:1317
#define MEM_RELEASE
Definition: nt_native.h:1319
#define MEM_COMMIT
Definition: nt_native.h:1316
#define PAGE_EXECUTE_READWRITE
Definition: nt_native.h:1311
short WCHAR
Definition: pedump.c:58
long LONG
Definition: pedump.c:60
unsigned short USHORT
Definition: pedump.c:61
#define memset(x, y, z)
Definition: compat.h:39
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
USHORT MaximumLength
Definition: env_spec_w32.h:370
USHORT Length
Definition: large_int.c:148
USHORT MaximumLength
Definition: large_int.c:149
NTSTATUS result
Definition: large_int.c:151
const char * Buffer
Definition: large_int.c:150
ULONGLONG value
Definition: large_int.c:147
LONGLONG b
Definition: large_int.c:76
LONGLONG a
Definition: large_int.c:75
LONGLONG result
Definition: large_int.c:78
int64_t LONGLONG
Definition: typedefs.h:68
int32_t INT
Definition: typedefs.h:58
uint64_t ULONGLONG
Definition: typedefs.h:67
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
struct _STRING * PSTRING
Definition: pdh_main.c:96
_In_ WDFDMATRANSACTION _In_ size_t MaximumLength
LPVOID NTAPI VirtualAlloc(IN LPVOID lpAddress, IN SIZE_T dwSize, IN DWORD flAllocationType, IN DWORD flProtect)
Definition: virtmem.c:65
BOOL NTAPI VirtualFree(IN LPVOID lpAddress, IN SIZE_T dwSize, IN DWORD dwFreeType)
Definition: virtmem.c:119
#define WINAPI
Definition: msvc.h:6
unsigned char BYTE
Definition: xxhash.c:193