ReactOS  r75636
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 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 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 275 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 105 of file large_int.c.

Referenced by test_RtlExtendedMagicDivide().

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

Definition at line 51 of file large_int.c.

Function Documentation

static void InitFunctionPtrs ( void  )
static

Definition at line 38 of file large_int.c.

Referenced by START_TEST().

39 {
40  hntdll = LoadLibraryA("ntdll.dll");
41  ok(hntdll != 0, "LoadLibrary failed\n");
42  if (hntdll) {
43  pRtlExtendedMagicDivide = (void *)GetProcAddress(hntdll, "RtlExtendedMagicDivide");
44  pRtlFreeAnsiString = (void *)GetProcAddress(hntdll, "RtlFreeAnsiString");
45  pRtlInt64ToUnicodeString = (void *)GetProcAddress(hntdll, "RtlInt64ToUnicodeString");
46  pRtlLargeIntegerToChar = (void *)GetProcAddress(hntdll, "RtlLargeIntegerToChar");
47  pRtlUnicodeStringToAnsiString = (void *)GetProcAddress(hntdll, "RtlUnicodeStringToAnsiString");
48  } /* if */
49 }
static HMODULE hntdll
Definition: large_int.c:30
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
#define GetProcAddress(x, y)
Definition: compat.h:410
#define ok(value,...)
Definition: CImage.cpp:33
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 278 of file large_int.c.

Referenced by test_RtlInt64ToUnicodeString().

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

Definition at line 372 of file large_int.c.

Referenced by test_RtlLargeIntegerToChar().

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

Definition at line 442 of file large_int.c.

443 {
445 
446  if (pRtlExtendedMagicDivide)
448  if (pRtlInt64ToUnicodeString)
450  if (pRtlLargeIntegerToChar)
452 }
static void InitFunctionPtrs(void)
Definition: large_int.c:38
static void test_RtlInt64ToUnicodeString(void)
Definition: large_int.c:362
static void test_RtlExtendedMagicDivide(void)
Definition: large_int.c:108
static void test_RtlLargeIntegerToChar(void)
Definition: large_int.c:405
static void test_RtlExtendedMagicDivide ( void  )
static

Definition at line 108 of file large_int.c.

Referenced by START_TEST().

109 {
110  int i;
112 
113  for (i = 0; i < NB_MAGIC_DIVIDE; i++) {
114  result = pRtlExtendedMagicDivide(magic_divide[i].a, magic_divide[i].b, magic_divide[i].shift);
115  ok(result == magic_divide[i].result,
116  "call failed: RtlExtendedMagicDivide(0x%x%08x, 0x%x%08x, %d) has result 0x%x%08x, expected 0x%x%08x\n",
117  (DWORD)(magic_divide[i].a >> 32), (DWORD)magic_divide[i].a, (DWORD)(magic_divide[i].b >> 32),
118  (DWORD)magic_divide[i].b, magic_divide[i].shift, (DWORD)(result >> 32), (DWORD)result,
119  (DWORD)(magic_divide[i].result >> 32), (DWORD)magic_divide[i].result);
120  }
121 }
#define shift
Definition: input.c:1594
DWORD DWORD
Definition: winlogon.h:75
GLenum GLclampf GLint i
Definition: glfuncs.h:14
int64_t LONGLONG
Definition: typedefs.h:67
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
#define NB_MAGIC_DIVIDE
Definition: large_int.c:105
static const magic_divide_t magic_divide[]
Definition: large_int.c:60
#define ok(value,...)
Definition: CImage.cpp:33
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
GLuint64EXT * result
Definition: glext.h:11304
static void test_RtlInt64ToUnicodeString ( void  )
static

Definition at line 362 of file large_int.c.

Referenced by START_TEST().

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

Definition at line 405 of file large_int.c.

Referenced by START_TEST().

406 {
408  int test_num;
410 
411  for (test_num = 0; test_num < NB_LARGEINT2STR; test_num++) {
412  one_RtlLargeIntegerToChar_test(test_num, &largeint2str[test_num]);
413  } /* for */
414 
415  value = largeint2str[0].value;
416  result = pRtlLargeIntegerToChar(&value, 20, largeint2str[0].MaximumLength, NULL);
417  ok(result == STATUS_INVALID_PARAMETER,
418  "(test a): RtlLargeIntegerToChar(0x%x%08x, %d, %d, NULL) has result %x, expected: %x\n",
419  (DWORD)(largeint2str[0].value >> 32), (DWORD)largeint2str[0].value, 20,
421 
422  result = pRtlLargeIntegerToChar(&value, 20, 0, NULL);
423  ok(result == STATUS_INVALID_PARAMETER,
424  "(test b): RtlLargeIntegerToChar(0x%x%08x, %d, %d, NULL) has result %x, expected: %x\n",
425  (DWORD)(largeint2str[0].value >> 32), (DWORD)largeint2str[0].value, 20,
427 
428  result = pRtlLargeIntegerToChar(&value, largeint2str[0].base, 0, NULL);
429  ok(result == STATUS_BUFFER_OVERFLOW,
430  "(test c): RtlLargeIntegerToChar(0x%x%08x, %d, %d, NULL) has result %x, expected: %x\n",
431  (DWORD)(largeint2str[0].value >> 32), (DWORD)largeint2str[0].value,
432  largeint2str[0].base, 0, result, STATUS_BUFFER_OVERFLOW);
433 
434  result = pRtlLargeIntegerToChar(&value, largeint2str[0].base, largeint2str[0].MaximumLength, NULL);
435  ok(result == STATUS_ACCESS_VIOLATION,
436  "(test d): RtlLargeIntegerToChar(0x%x%08x, %d, %d, NULL) has result %x, expected: %x\n",
437  (DWORD)(largeint2str[0].value >> 32), (DWORD)largeint2str[0].value,
439 }
static void one_RtlLargeIntegerToChar_test(int test_num, const largeint2str_t *largeint2str)
Definition: large_int.c:372
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define NB_LARGEINT2STR
Definition: large_int.c:275
ULONGLONG value
Definition: large_int.c:128
DWORD DWORD
Definition: winlogon.h:75
smooth NULL
Definition: ftsmooth.c:513
uint64_t ULONGLONG
Definition: typedefs.h:66
GLsizei const GLfloat * value
Definition: glext.h:6069
UnicodeString MaximumLength
Definition: rtlfuncs.h:2982
LONG NTSTATUS
Definition: DriverTester.h:11
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:228
#define ok(value,...)
Definition: CImage.cpp:33
static const largeint2str_t largeint2str[]
Definition: large_int.c:141
GLuint64EXT * result
Definition: glext.h:11304
#define STATUS_BUFFER_OVERFLOW
Definition: udferr_usr.h:127
static VOID ( WINAPI pRtlFreeAnsiString)
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 141 of file large_int.c.

Definition at line 31 of file large_int.c.

const magic_divide_t magic_divide[]
static

Definition at line 60 of file large_int.c.

Definition at line 34 of file large_int.c.

Definition at line 33 of file large_int.c.