[NTFS]
[reactos.git] / rostests / apitests / crt / _vsnprintf.c
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 ok(expected_ret == ret, "Test failed: expected %i, got %i.\n", expected_ret, ret);
24 }
25
26 START_TEST(_vsnprintf)
27 {
28 char buffer[255];
29
30 /* Here you can mix wide and ANSI strings */
31 call_varargs(buffer, 255, 12, "%S world!", L"hello");
32 call_varargs(buffer, 255, 12, "%s world!", "hello");
33 call_varargs(buffer, 255, 11, "%u cookies", 100);
34
35 StartSeh()
36 #if defined(TEST_CRTDLL)||defined(TEST_USER32)
37 call_varargs(NULL, INT_MAX, -1, "%s it really work?", "does");
38 #else
39 call_varargs(NULL, INT_MAX, 20, "%s it really work?", "does");
40 #endif
41
42 #if defined(TEST_CRTDLL)||defined(TEST_USER32)
43 EndSeh(STATUS_ACCESS_VIOLATION);
44 #else
45 EndSeh(STATUS_SUCCESS);
46 #endif
47
48 #if defined(TEST_USER32) /* NTDLL doesn't use/set errno */
49 ok(errno == EINVAL, "Expected EINVAL, got %u\n", errno);
50 #else
51 ok(errno == 0, "Expected 0, got %u \n", errno);
52 #endif
53
54 /* This one is no better */
55 StartSeh()
56 #if defined(TEST_CRTDLL)||defined(TEST_USER32)
57 call_varargs(NULL, 0, -1, "%s it really work?", "does");
58 #else
59 call_varargs(NULL, 0, 20, "%s it really work?", "does");
60 #endif
61
62 #if defined(TEST_USER32)
63 EndSeh(STATUS_ACCESS_VIOLATION);
64 #else
65 EndSeh(STATUS_SUCCESS);
66 #endif
67
68 #if defined(TEST_USER32) /* NTDLL doesn't use/set errno */
69 ok(errno == EINVAL, "Expected EINVAL, got %u\n", errno);
70 #else
71 ok(errno == 0, "Expected 0, got %u \n", errno);
72 #endif
73
74 /* One more NULL checks */
75 StartSeh()
76 call_varargs(buffer, 255, -1, NULL);
77 EndSeh(STATUS_ACCESS_VIOLATION);
78
79 #if defined(TEST_USER32) /* NTDLL doesn't use/set errno */
80 ok(errno == EINVAL, "Expected EINVAL, got %u\n", errno);
81 #else
82 ok(errno == 0, "Expected 0, got %u \n", errno);
83 #endif
84 }