ReactOS  0.4.9-dev-728-g3d012a4
large_int.c File Reference
#include <stdlib.h>
#include "ntdll_test.h"
Include dependency graph for large_int.c:

Go to the source code of this file.

Classes

struct  magic_divide_t
 
struct  largeint2str_t
 

Macros

#define ULL(a, b)   (((ULONGLONG)(a) << 32) | (b))
 
#define NB_MAGIC_DIVIDE   (sizeof(magic_divide)/sizeof(*magic_divide))
 
#define LARGE_STRI_BUFFER_LENGTH   67
 
#define NB_LARGEINT2STR   (sizeof(largeint2str)/sizeof(*largeint2str))
 

Functions

static LONGLONG (WINAPI *pRtlExtendedMagicDivide)(LONGLONG
 
static VOID (WINAPI *pRtlFreeAnsiString)(PSTRING)
 
static NTSTATUS (WINAPI *pRtlInt64ToUnicodeString)(ULONGLONG
 
static void (WINAPI *p_alldvrm)(LONGLONG
 
static void InitFunctionPtrs (void)
 
static void test_RtlExtendedMagicDivide (void)
 
static void one_RtlInt64ToUnicodeString_test (int test_num, const largeint2str_t *largeint2str)
 
static void test_RtlInt64ToUnicodeString (void)
 
static void one_RtlLargeIntegerToChar_test (int test_num, const largeint2str_t *largeint2str)
 
static void test_RtlLargeIntegerToChar (void)
 
 START_TEST (large_int)
 

Variables

static HMODULE hntdll = 0
 
static LONGLONG
 
static INT
 
static ULONG
 
static UNICODE_STRING *static PCHAR
 
static const UNICODE_STRING BOOLEAN
 
static ULONGLONG
 
static const magic_divide_t magic_divide []
 
static const largeint2str_t largeint2str []
 

Macro Definition Documentation

#define LARGE_STRI_BUFFER_LENGTH   67
#define NB_LARGEINT2STR   (sizeof(largeint2str)/sizeof(*largeint2str))

Definition at line 278 of file large_int.c.

Referenced by test_RtlInt64ToUnicodeString(), and test_RtlLargeIntegerToChar().

#define NB_MAGIC_DIVIDE   (sizeof(magic_divide)/sizeof(*magic_divide))

Definition at line 109 of file large_int.c.

Referenced by test_RtlExtendedMagicDivide().

#define ULL (   a,
  b 
)    (((ULONGLONG)(a) << 32) | (b))

Definition at line 55 of file large_int.c.

Function Documentation

static void InitFunctionPtrs ( void  )
static

Definition at line 40 of file large_int.c.

Referenced by START_TEST().

41 {
42  hntdll = LoadLibraryA("ntdll.dll");
43  ok(hntdll != 0, "LoadLibrary failed\n");
44  if (hntdll) {
45  pRtlExtendedMagicDivide = (void *)GetProcAddress(hntdll, "RtlExtendedMagicDivide");
46  pRtlFreeAnsiString = (void *)GetProcAddress(hntdll, "RtlFreeAnsiString");
47  pRtlInt64ToUnicodeString = (void *)GetProcAddress(hntdll, "RtlInt64ToUnicodeString");
48  pRtlLargeIntegerToChar = (void *)GetProcAddress(hntdll, "RtlLargeIntegerToChar");
49  pRtlUnicodeStringToAnsiString = (void *)GetProcAddress(hntdll, "RtlUnicodeStringToAnsiString");
50  p_alldvrm = (void *)GetProcAddress(hntdll, "_alldvrm");
51  p_aulldvrm = (void *)GetProcAddress(hntdll, "_aulldvrm");
52  } /* if */
53 }
static HMODULE hntdll
Definition: large_int.c:30
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
#define ok(value,...)
Definition: CComObject.cpp:34
#define GetProcAddress(x, y)
Definition: compat.h:410
static LONGLONG ( WINAPI pRtlExtendedMagicDivide)
static
static NTSTATUS ( WINAPI pRtlInt64ToUnicodeString)
static
static void one_RtlInt64ToUnicodeString_test ( int  test_num,
const largeint2str_t largeint2str 
)
static

Definition at line 281 of file large_int.c.

Referenced by test_RtlInt64ToUnicodeString().

282 {
283  int pos;
284  WCHAR expected_str_Buffer[LARGE_STRI_BUFFER_LENGTH + 1];
285  UNICODE_STRING expected_unicode_string;
286  STRING expected_ansi_str;
287  WCHAR str_Buffer[LARGE_STRI_BUFFER_LENGTH + 1];
288  UNICODE_STRING unicode_string;
289  STRING ansi_str;
291 
292 #ifdef _WIN64
293  if (largeint2str->value >> 32 == 0xffffffff) /* this crashes on 64-bit Vista */
294  {
295  skip( "Value ffffffff%08x broken on 64-bit windows\n", (DWORD)largeint2str->value );
296  return;
297  }
298 #endif
299 
300  for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) {
301  expected_str_Buffer[pos] = largeint2str->Buffer[pos];
302  } /* for */
303  expected_unicode_string.Length = largeint2str->Length * sizeof(WCHAR);
304  expected_unicode_string.MaximumLength = largeint2str->MaximumLength * sizeof(WCHAR);
305  expected_unicode_string.Buffer = expected_str_Buffer;
306  pRtlUnicodeStringToAnsiString(&expected_ansi_str, &expected_unicode_string, 1);
307 
308  for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) {
309  str_Buffer[pos] = '-';
310  } /* for */
311  unicode_string.Length = 0;
312  unicode_string.MaximumLength = largeint2str->MaximumLength * sizeof(WCHAR);
313  unicode_string.Buffer = str_Buffer;
314 
315  if (largeint2str->base == 0) {
316  result = pRtlInt64ToUnicodeString(largeint2str->value, 10, &unicode_string);
317  } else {
318  result = pRtlInt64ToUnicodeString(largeint2str->value, largeint2str->base, &unicode_string);
319  } /* if */
320  pRtlUnicodeStringToAnsiString(&ansi_str, &unicode_string, 1);
321  if (result == STATUS_BUFFER_OVERFLOW) {
322  /* On BUFFER_OVERFLOW the string Buffer should be unchanged */
323  for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) {
324  expected_str_Buffer[pos] = '-';
325  } /* for */
326  /* w2k: The native function has two reasons for BUFFER_OVERFLOW: */
327  /* If the value is too large to convert: The Length is unchanged */
328  /* If str is too small to hold the string: Set str->Length to the length */
329  /* the string would have (which can be larger than the MaximumLength). */
330  /* To allow all this in the tests we do the following: */
331  if (expected_unicode_string.Length >= 64) {
332  /* The value is too large to convert only triggered when testing native */
333  /* Length is not filled with the expected string length (garbage?) */
334  expected_unicode_string.Length = unicode_string.Length;
335  } /* if */
336  } else {
337  ok(result == largeint2str->result,
338  "(test %d): RtlInt64ToUnicodeString(0x%s, %d, [out]) has result %x, expected: %x\n",
339  test_num, wine_dbgstr_longlong(largeint2str->value), largeint2str->base, result, largeint2str->result);
340  if (result == STATUS_SUCCESS) {
341  ok(unicode_string.Buffer[unicode_string.Length/sizeof(WCHAR)] == '\0',
342  "(test %d): RtlInt64ToUnicodeString(0x%s, %d, [out]) string \"%s\" is not NULL terminated\n",
343  test_num, wine_dbgstr_longlong(largeint2str->value), largeint2str->base, ansi_str.Buffer);
344  } /* if */
345  } /* if */
346  ok(memcmp(unicode_string.Buffer, expected_unicode_string.Buffer, LARGE_STRI_BUFFER_LENGTH * sizeof(WCHAR)) == 0,
347  "(test %d): RtlInt64ToUnicodeString(0x%x%08x, %d, [out]) assigns string \"%s\", expected: \"%s\"\n",
348  test_num, (DWORD)(largeint2str->value >>32), (DWORD)largeint2str->value, largeint2str->base,
349  ansi_str.Buffer, expected_ansi_str.Buffer);
350  ok(unicode_string.Length == expected_unicode_string.Length,
351  "(test %d): RtlInt64ToUnicodeString(0x%s, %d, [out]) string has Length %d, expected: %d\n",
352  test_num, wine_dbgstr_longlong(largeint2str->value), largeint2str->base,
353  unicode_string.Length, expected_unicode_string.Length);
354  ok(unicode_string.MaximumLength == expected_unicode_string.MaximumLength,
355  "(test %d): RtlInt64ToUnicodeString(0x%s, %d, [out]) string has MaximumLength %d, expected: %d\n",
356  test_num, wine_dbgstr_longlong(largeint2str->value), largeint2str->base,
357  unicode_string.MaximumLength, expected_unicode_string.MaximumLength);
358  pRtlFreeAnsiString(&expected_ansi_str);
359  pRtlFreeAnsiString(&ansi_str);
360 }
const char * Buffer
Definition: large_int.c:134
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
USHORT MaximumLength
Definition: env_spec_w32.h:370
__wchar_t WCHAR
Definition: xmlstorage.h:180
return STATUS_SUCCESS
Definition: btrfs.c:2690
ULONGLONG value
Definition: large_int.c:131
USHORT MaximumLength
Definition: large_int.c:133
#define WCHAR
Definition: msvc.h:43
DWORD DWORD
Definition: winlogon.h:75
#define ok(value,...)
Definition: CComObject.cpp:34
NTSTATUS result
Definition: large_int.c:135
LONG NTSTATUS
Definition: precomp.h:26
std::wstring STRING
Definition: fontsub.cpp:33
USHORT Length
Definition: large_int.c:132
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:49
#define LARGE_STRI_BUFFER_LENGTH
Definition: large_int.c:127
#define skip(...)
Definition: CString.cpp:57
static __inline const char * wine_dbgstr_longlong(ULONGLONG ll)
Definition: compat.h:41
GLuint64EXT * result
Definition: glext.h:11304
static void one_RtlLargeIntegerToChar_test ( int  test_num,
const largeint2str_t largeint2str 
)
static

Definition at line 373 of file large_int.c.

Referenced by test_RtlLargeIntegerToChar().

374 {
376  char dest_str[LARGE_STRI_BUFFER_LENGTH + 1];
378 
379 #ifdef _WIN64
380  if (largeint2str->value >> 32 == 0xffffffff) /* this crashes on 64-bit Vista */
381  {
382  skip( "Value ffffffff%08x broken on 64-bit windows\n", (DWORD)largeint2str->value );
383  return;
384  }
385 #endif
386 
387  memset(dest_str, '-', LARGE_STRI_BUFFER_LENGTH);
388  dest_str[LARGE_STRI_BUFFER_LENGTH] = '\0';
389  value = largeint2str->value;
390  if (largeint2str->base == 0) {
391  result = pRtlLargeIntegerToChar(&value, 10, largeint2str->MaximumLength, dest_str);
392  } else {
393  result = pRtlLargeIntegerToChar(&value, largeint2str->base, largeint2str->MaximumLength, dest_str);
394  } /* if */
395  ok(result == largeint2str->result,
396  "(test %d): RtlLargeIntegerToChar(0x%s, %d, %d, [out]) has result %x, expected: %x\n",
397  test_num, wine_dbgstr_longlong(largeint2str->value), largeint2str->base,
398  largeint2str->MaximumLength, result, largeint2str->result);
399  ok(memcmp(dest_str, largeint2str->Buffer, LARGE_STRI_BUFFER_LENGTH) == 0,
400  "(test %d): RtlLargeIntegerToChar(0x%s, %d, %d, [out]) assigns string \"%s\", expected: \"%s\"\n",
401  test_num, wine_dbgstr_longlong(largeint2str->value), largeint2str->base,
402  largeint2str->MaximumLength, dest_str, largeint2str->Buffer);
403 }
const char * Buffer
Definition: large_int.c:134
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
ULONGLONG value
Definition: large_int.c:131
USHORT MaximumLength
Definition: large_int.c:133
DWORD DWORD
Definition: winlogon.h:75
#define ok(value,...)
Definition: CComObject.cpp:34
NTSTATUS result
Definition: large_int.c:135
LONG NTSTATUS
Definition: precomp.h:26
uint64_t ULONGLONG
Definition: typedefs.h:65
GLsizei const GLfloat * value
Definition: glext.h:6069
#define LARGE_STRI_BUFFER_LENGTH
Definition: large_int.c:127
#define skip(...)
Definition: CString.cpp:57
static __inline const char * wine_dbgstr_longlong(ULONGLONG ll)
Definition: compat.h:41
GLuint64EXT * result
Definition: glext.h:11304
#define memset(x, y, z)
Definition: compat.h:39
START_TEST ( large_int  )

Definition at line 502 of file large_int.c.

503 {
505 
506  if (pRtlExtendedMagicDivide)
508  if (pRtlInt64ToUnicodeString)
510  if (pRtlLargeIntegerToChar)
512 
513 #ifdef __i386__
514  test__alldvrm();
515 #endif /* __i386__ */
516 }
static void InitFunctionPtrs(void)
Definition: large_int.c:40
static void test_RtlInt64ToUnicodeString(void)
Definition: large_int.c:363
static void test_RtlExtendedMagicDivide(void)
Definition: large_int.c:112
static void test_RtlLargeIntegerToChar(void)
Definition: large_int.c:406
static void test_RtlExtendedMagicDivide ( void  )
static

Definition at line 112 of file large_int.c.

Referenced by START_TEST().

113 {
114  int i;
116 
117  for (i = 0; i < NB_MAGIC_DIVIDE; i++) {
118  result = pRtlExtendedMagicDivide(magic_divide[i].a, magic_divide[i].b, magic_divide[i].shift);
119  ok(result == magic_divide[i].result,
120  "call failed: RtlExtendedMagicDivide(0x%s, 0x%s, %d) has result 0x%s, expected 0x%s\n",
123  }
124 }
#define shift
Definition: input.c:1668
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define ok(value,...)
Definition: CComObject.cpp:34
int64_t LONGLONG
Definition: typedefs.h:66
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
#define NB_MAGIC_DIVIDE
Definition: large_int.c:109
static const magic_divide_t magic_divide[]
Definition: large_int.c:64
static __inline const char * wine_dbgstr_longlong(ULONGLONG ll)
Definition: compat.h:41
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
GLuint64EXT * result
Definition: glext.h:11304
static void test_RtlInt64ToUnicodeString ( void  )
static

Definition at line 363 of file large_int.c.

Referenced by START_TEST().

364 {
365  int test_num;
366 
367  for (test_num = 0; test_num < NB_LARGEINT2STR; test_num++) {
368  one_RtlInt64ToUnicodeString_test(test_num, &largeint2str[test_num]);
369  } /* for */
370 }
#define NB_LARGEINT2STR
Definition: large_int.c:278
static void one_RtlInt64ToUnicodeString_test(int test_num, const largeint2str_t *largeint2str)
Definition: large_int.c:281
static const largeint2str_t largeint2str[]
Definition: large_int.c:144
static void test_RtlLargeIntegerToChar ( void  )
static

Definition at line 406 of file large_int.c.

Referenced by START_TEST().

407 {
409  int test_num;
411 
412  for (test_num = 0; test_num < NB_LARGEINT2STR; test_num++) {
413  one_RtlLargeIntegerToChar_test(test_num, &largeint2str[test_num]);
414  } /* for */
415 
416  value = largeint2str[0].value;
417  result = pRtlLargeIntegerToChar(&value, 20, largeint2str[0].MaximumLength, NULL);
418  ok(result == STATUS_INVALID_PARAMETER,
419  "(test a): RtlLargeIntegerToChar(0x%s, %d, %d, NULL) has result %x, expected: %x\n",
420  wine_dbgstr_longlong(largeint2str[0].value), 20,
422 
423  result = pRtlLargeIntegerToChar(&value, 20, 0, NULL);
424  ok(result == STATUS_INVALID_PARAMETER,
425  "(test b): RtlLargeIntegerToChar(0x%s, %d, %d, NULL) has result %x, expected: %x\n",
426  wine_dbgstr_longlong(largeint2str[0].value), 20,
428 
429  result = pRtlLargeIntegerToChar(&value, largeint2str[0].base, 0, NULL);
430  ok(result == STATUS_BUFFER_OVERFLOW,
431  "(test c): RtlLargeIntegerToChar(0x%s, %d, %d, NULL) has result %x, expected: %x\n",
433 
434  result = pRtlLargeIntegerToChar(&value, largeint2str[0].base, largeint2str[0].MaximumLength, NULL);
435  ok(result == STATUS_ACCESS_VIOLATION,
436  "(test d): RtlLargeIntegerToChar(0x%s, %d, %d, NULL) has result %x, expected: %x\n",
439 }
static void one_RtlLargeIntegerToChar_test(int test_num, const largeint2str_t *largeint2str)
Definition: large_int.c:373
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define NB_LARGEINT2STR
Definition: large_int.c:278
ULONGLONG value
Definition: large_int.c:131
smooth NULL
Definition: ftsmooth.c:416
#define ok(value,...)
Definition: CComObject.cpp:34
LONG NTSTATUS
Definition: precomp.h:26
uint64_t ULONGLONG
Definition: typedefs.h:65
GLsizei const GLfloat * value
Definition: glext.h:6069
UnicodeString MaximumLength
Definition: rtlfuncs.h:2982
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:49
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:228
static __inline const char * wine_dbgstr_longlong(ULONGLONG ll)
Definition: compat.h:41
static const largeint2str_t largeint2str[]
Definition: large_int.c:144
GLuint64EXT * result
Definition: glext.h:11304
static VOID ( WINAPI pRtlFreeAnsiString)
static
static void ( WINAPI p_alldvrm)
static

Variable Documentation

Definition at line 35 of file large_int.c.

HMODULE hntdll = 0
static

Definition at line 30 of file large_int.c.

Referenced by InitFunctionPtrs().

INT

Definition at line 31 of file large_int.c.

const largeint2str_t largeint2str[]
static

Definition at line 144 of file large_int.c.

Definition at line 31 of file large_int.c.

const magic_divide_t magic_divide[]
static

Definition at line 64 of file large_int.c.

Definition at line 34 of file large_int.c.

Definition at line 33 of file large_int.c.

Definition at line 37 of file large_int.c.