ReactOS  0.4.13-dev-961-g238ea69
_vsnprintf.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS api tests
3  * LICENSE: GPL - See COPYING in the top level directory
4  * PURPOSE: Test for _vsnprintf
5  */
6 
7 #include <apitest.h>
8 
9 #define WIN32_NO_STATUS
10 #include <stdio.h>
11 #include <tchar.h>
12 #include <pseh/pseh2.h>
13 #include <ndk/mmfuncs.h>
14 #include <ndk/rtlfuncs.h>
15 
16 static void call_varargs(char* buf, size_t buf_size, int expected_ret, LPCSTR formatString, ...)
17 {
18  va_list args;
19  int ret;
20  /* Test the basic functionality */
21  va_start(args, formatString);
22  ret = _vsnprintf(buf, buf_size, formatString, args);
23  va_end(args);
24  ok(expected_ret == ret, "Test failed: expected %i, got %i.\n", expected_ret, ret);
25 }
26 
28 {
29  char buffer[255];
30 
31  /* Here you can mix wide and ANSI strings */
32  call_varargs(buffer, 255, 12, "%S world!", L"hello");
33  call_varargs(buffer, 255, 12, "%s world!", "hello");
34  call_varargs(buffer, 255, 11, "%u cookies", 100);
35 
36  StartSeh()
37 #if defined(TEST_CRTDLL)||defined(TEST_USER32)
38  call_varargs(NULL, INT_MAX, -1, "%s it really work?", "does");
39 #else
40  call_varargs(NULL, INT_MAX, 20, "%s it really work?", "does");
41 #endif
42 
43 #if defined(TEST_CRTDLL)||defined(TEST_USER32)
45 #else
47 #endif
48 
49 #if defined(TEST_USER32) /* NTDLL doesn't use/set errno */
50  ok(errno == EINVAL, "Expected EINVAL, got %u\n", errno);
51 #else
52  ok(errno == 0, "Expected 0, got %u \n", errno);
53 #endif
54 
55  /* This one is no better */
56  StartSeh()
57 #if defined(TEST_CRTDLL)||defined(TEST_USER32)
58  call_varargs(NULL, 0, -1, "%s it really work?", "does");
59 #else
60  call_varargs(NULL, 0, 20, "%s it really work?", "does");
61 #endif
62 
63 #if defined(TEST_USER32)
65 #else
67 #endif
68 
69 #if defined(TEST_USER32) /* NTDLL doesn't use/set errno */
70  ok(errno == EINVAL, "Expected EINVAL, got %u\n", errno);
71 #else
72  ok(errno == 0, "Expected 0, got %u \n", errno);
73 #endif
74 
75  /* One more NULL checks */
76  StartSeh()
77  call_varargs(buffer, 255, -1, NULL);
79 
80 #if defined(TEST_USER32) /* NTDLL doesn't use/set errno */
81  ok(errno == EINVAL, "Expected EINVAL, got %u\n", errno);
82 #else
83  ok(errno == 0, "Expected 0, got %u \n", errno);
84 #endif
85 }
START_TEST(_vsnprintf)
Definition: _vsnprintf.c:27
#define INT_MAX
Definition: limits.h:40
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
Definition: arc.h:39
static void call_varargs(char *buf, size_t buf_size, int expected_ret, LPCSTR formatString,...)
Definition: _vsnprintf.c:16
GLuint buffer
Definition: glext.h:5915
int errno
#define StartSeh()
Definition: _sntprintf.h:16
Definition: match.c:390
#define va_end(ap)
Definition: acmsvcex.h:90
smooth NULL
Definition: ftsmooth.c:416
char * va_list
Definition: acmsvcex.h:78
const char * LPCSTR
Definition: xmlstorage.h:183
int ret
static const WCHAR L[]
Definition: oid.c:1250
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:228
#define ok(value,...)
Definition: atltest.h:57
#define va_start(ap, A)
Definition: acmsvcex.h:91
#define _vsnprintf
Definition: xmlstorage.h:202
return STATUS_SUCCESS
Definition: btrfs.c:2777
#define args
Definition: format.c:66
#define EndSeh(ExpectedStatus)
Definition: _sntprintf.h:17