ReactOS  0.4.15-dev-1397-g19779b3
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

◆ LARGE_STRI_BUFFER_LENGTH

#define LARGE_STRI_BUFFER_LENGTH   67

Definition at line 127 of file large_int.c.

◆ NB_LARGEINT2STR

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

Definition at line 278 of file large_int.c.

◆ NB_MAGIC_DIVIDE

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

Definition at line 109 of file large_int.c.

◆ ULL

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

Definition at line 55 of file large_int.c.

Function Documentation

◆ InitFunctionPtrs()

static void InitFunctionPtrs ( void  )
static

Definition at line 40 of file large_int.c.

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: atltest.h:57
#define GetProcAddress(x, y)
Definition: compat.h:612

Referenced by START_TEST().

◆ LONGLONG()

static LONGLONG ( WINAPI pRtlExtendedMagicDivide)
static

◆ NTSTATUS()

static NTSTATUS ( WINAPI pRtlInt64ToUnicodeString)
static

◆ one_RtlInt64ToUnicodeString_test()

static void one_RtlInt64ToUnicodeString_test ( int  test_num,
const largeint2str_t largeint2str 
)
static

Definition at line 281 of file large_int.c.

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);
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 {
338  "(test %d): RtlInt64ToUnicodeString(0x%s, %d, [out]) has result %x, expected: %x\n",
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",
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",
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
GLuint64EXT * result
Definition: glext.h:11304
USHORT MaximumLength
Definition: env_spec_w32.h:370
LONG NTSTATUS
Definition: precomp.h:26
ULONGLONG value
Definition: large_int.c:131
USHORT MaximumLength
Definition: large_int.c:133
NTSTATUS result
Definition: large_int.c:135
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
std::wstring STRING
Definition: fontsub.cpp:33
USHORT Length
Definition: large_int.c:132
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
#define LARGE_STRI_BUFFER_LENGTH
Definition: large_int.c:127
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
static __inline const char * wine_dbgstr_longlong(ULONGLONG ll)
Definition: compat.h:49
static const largeint2str_t largeint2str[]
Definition: large_int.c:144
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by test_RtlInt64ToUnicodeString().

◆ one_RtlLargeIntegerToChar_test()

static void one_RtlLargeIntegerToChar_test ( int  test_num,
const largeint2str_t largeint2str 
)
static

Definition at line 373 of file large_int.c.

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';
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 */
396  "(test %d): RtlLargeIntegerToChar(0x%s, %d, %d, [out]) has result %x, expected: %x\n",
400  "(test %d): RtlLargeIntegerToChar(0x%s, %d, %d, [out]) assigns string \"%s\", expected: \"%s\"\n",
403 }
const char * Buffer
Definition: large_int.c:134
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
GLuint64EXT * result
Definition: glext.h:11304
LONG NTSTATUS
Definition: precomp.h:26
ULONGLONG value
Definition: large_int.c:131
USHORT MaximumLength
Definition: large_int.c:133
NTSTATUS result
Definition: large_int.c:135
uint64_t ULONGLONG
Definition: typedefs.h:67
unsigned long DWORD
Definition: ntddk_ex.h:95
GLsizei const GLfloat * value
Definition: glext.h:6069
#define LARGE_STRI_BUFFER_LENGTH
Definition: large_int.c:127
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
static __inline const char * wine_dbgstr_longlong(ULONGLONG ll)
Definition: compat.h:49
static const largeint2str_t largeint2str[]
Definition: large_int.c:144
#define memset(x, y, z)
Definition: compat.h:39

Referenced by test_RtlLargeIntegerToChar().

◆ START_TEST()

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

◆ test_RtlExtendedMagicDivide()

static void test_RtlExtendedMagicDivide ( void  )
static

Definition at line 112 of file large_int.c.

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);
120  "call failed: RtlExtendedMagicDivide(0x%s, 0x%s, %d) has result 0x%s, expected 0x%s\n",
123  }
124 }
#define shift
Definition: input.c:1756
GLuint64EXT * result
Definition: glext.h:11304
int64_t LONGLONG
Definition: typedefs.h:68
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
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
#define ok(value,...)
Definition: atltest.h:57
static __inline const char * wine_dbgstr_longlong(ULONGLONG ll)
Definition: compat.h:49
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204

Referenced by START_TEST().

◆ test_RtlInt64ToUnicodeString()

static void test_RtlInt64ToUnicodeString ( void  )
static

Definition at line 363 of file large_int.c.

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

Referenced by START_TEST().

◆ test_RtlLargeIntegerToChar()

static void test_RtlLargeIntegerToChar ( void  )
static

Definition at line 406 of file large_int.c.

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);
419  "(test a): RtlLargeIntegerToChar(0x%s, %d, %d, NULL) has result %x, expected: %x\n",
422 
423  result = pRtlLargeIntegerToChar(&value, 20, 0, NULL);
425  "(test b): RtlLargeIntegerToChar(0x%s, %d, %d, NULL) has result %x, expected: %x\n",
428 
429  result = pRtlLargeIntegerToChar(&value, largeint2str[0].base, 0, NULL);
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);
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
GLuint64EXT * result
Definition: glext.h:11304
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define NB_LARGEINT2STR
Definition: large_int.c:278
LONG NTSTATUS
Definition: precomp.h:26
ULONGLONG value
Definition: large_int.c:131
_In_ WDFDMATRANSACTION _In_ size_t MaximumLength
uint64_t ULONGLONG
Definition: typedefs.h:67
GLsizei const GLfloat * value
Definition: glext.h:6069
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
#define ok(value,...)
Definition: atltest.h:57
#define NULL
Definition: types.h:112
static __inline const char * wine_dbgstr_longlong(ULONGLONG ll)
Definition: compat.h:49
static const largeint2str_t largeint2str[]
Definition: large_int.c:144

Referenced by START_TEST().

◆ VOID()

static VOID ( WINAPI pRtlFreeAnsiString)
static

◆ void()

static void ( WINAPI p_alldvrm)
static

Variable Documentation

◆ BOOLEAN

Definition at line 35 of file large_int.c.

◆ hntdll

HMODULE hntdll = 0
static

Definition at line 30 of file large_int.c.

Referenced by InitFunctionPtrs().

◆ INT

INT

Definition at line 31 of file large_int.c.

◆ largeint2str

◆ LONGLONG

Definition at line 31 of file large_int.c.

◆ magic_divide

const magic_divide_t magic_divide[]
static

Definition at line 64 of file large_int.c.

Referenced by test_RtlExtendedMagicDivide().

◆ PCHAR

Definition at line 34 of file large_int.c.

◆ ULONG

Definition at line 33 of file large_int.c.

◆ ULONGLONG

Definition at line 37 of file large_int.c.