1*c2c66affSColin Finck /*
2*c2c66affSColin Finck * PROJECT: ReactOS api tests
3*c2c66affSColin Finck * LICENSE: GPLv2+ - See COPYING in the top level directory
4*c2c66affSColin Finck * PURPOSE: Test for _sntprintf
5*c2c66affSColin Finck * PROGRAMMER: Thomas Faber <thfabba@gmx.de>
6*c2c66affSColin Finck */
7*c2c66affSColin Finck
8*c2c66affSColin Finck #define WIN32_NO_STATUS
9*c2c66affSColin Finck #include <wine/test.h>
10*c2c66affSColin Finck #include <stdio.h>
11*c2c66affSColin Finck #include <tchar.h>
12*c2c66affSColin Finck #include <pseh/pseh2.h>
13*c2c66affSColin Finck #include <ndk/mmfuncs.h>
14*c2c66affSColin Finck #include <ndk/rtlfuncs.h>
15*c2c66affSColin Finck
16*c2c66affSColin Finck #define StartSeh() ExceptionStatus = STATUS_SUCCESS; _SEH2_TRY {
17*c2c66affSColin Finck #define EndSeh(ExpectedStatus) } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { ExceptionStatus = _SEH2_GetExceptionCode(); } _SEH2_END; ok(ExceptionStatus == ExpectedStatus, "Exception %lx, expected %lx\n", ExceptionStatus, ExpectedStatus)
18*c2c66affSColin Finck
19*c2c66affSColin Finck /* winetest_platform is "windows" for us, so broken() doesn't do what it should :( */
20*c2c66affSColin Finck #undef broken
21*c2c66affSColin Finck #define broken(x) 0
22*c2c66affSColin Finck
START_TEST(_sntprintf)23*c2c66affSColin Finck START_TEST(_sntprintf)
24*c2c66affSColin Finck {
25*c2c66affSColin Finck NTSTATUS ExceptionStatus;
26*c2c66affSColin Finck _TCHAR Buffer[128];
27*c2c66affSColin Finck size_t BufferSize = sizeof(Buffer) / sizeof(Buffer[0]);
28*c2c66affSColin Finck int Result;
29*c2c66affSColin Finck
30*c2c66affSColin Finck StartSeh()
31*c2c66affSColin Finck Result = _sntprintf(NULL, 0, _T("Hello"));
32*c2c66affSColin Finck #ifdef TEST_CRTDLL
33*c2c66affSColin Finck ok_int(Result, -1);
34*c2c66affSColin Finck #else
35*c2c66affSColin Finck ok_int(Result, 5);
36*c2c66affSColin Finck #endif
37*c2c66affSColin Finck EndSeh(STATUS_SUCCESS);
38*c2c66affSColin Finck
39*c2c66affSColin Finck StartSeh()
40*c2c66affSColin Finck Result = _sntprintf(NULL, 1, _T("Hello"));
41*c2c66affSColin Finck ok(Result == 5 ||
42*c2c66affSColin Finck broken(Result == -1) /* Win7 */, "Result = %d\n", Result);
43*c2c66affSColin Finck #if defined(_UNICODE) || defined(TEST_CRTDLL)
44*c2c66affSColin Finck EndSeh(STATUS_ACCESS_VIOLATION);
45*c2c66affSColin Finck #else
46*c2c66affSColin Finck EndSeh(STATUS_SUCCESS);
47*c2c66affSColin Finck #endif
48*c2c66affSColin Finck
49*c2c66affSColin Finck StartSeh()
50*c2c66affSColin Finck FillMemory(Buffer, sizeof(Buffer), 0x55);
51*c2c66affSColin Finck Result = _sntprintf(Buffer, BufferSize, _T("Hello"));
52*c2c66affSColin Finck ok_int(Result, 5);
53*c2c66affSColin Finck ok(Buffer[0] == _T('H'), "\n");
54*c2c66affSColin Finck ok(Buffer[1] == _T('e'), "\n");
55*c2c66affSColin Finck ok(Buffer[2] == _T('l'), "\n");
56*c2c66affSColin Finck ok(Buffer[3] == _T('l'), "\n");
57*c2c66affSColin Finck ok(Buffer[4] == _T('o'), "\n");
58*c2c66affSColin Finck ok(Buffer[5] == _T('\0'), "\n");
59*c2c66affSColin Finck ok(Buffer[6] == (_TCHAR)0x5555, "\n");
60*c2c66affSColin Finck EndSeh(STATUS_SUCCESS);
61*c2c66affSColin Finck
62*c2c66affSColin Finck StartSeh()
63*c2c66affSColin Finck FillMemory(Buffer, sizeof(Buffer), 0x55);
64*c2c66affSColin Finck Result = _sntprintf(Buffer, 5, _T("Hello"));
65*c2c66affSColin Finck ok_int(Result, 5);
66*c2c66affSColin Finck ok(Buffer[0] == _T('H'), "\n");
67*c2c66affSColin Finck ok(Buffer[1] == _T('e'), "\n");
68*c2c66affSColin Finck ok(Buffer[2] == _T('l'), "\n");
69*c2c66affSColin Finck ok(Buffer[3] == _T('l'), "\n");
70*c2c66affSColin Finck ok(Buffer[4] == _T('o'), "\n");
71*c2c66affSColin Finck ok(Buffer[5] == (_TCHAR)0x5555, "\n");
72*c2c66affSColin Finck EndSeh(STATUS_SUCCESS);
73*c2c66affSColin Finck
74*c2c66affSColin Finck StartSeh()
75*c2c66affSColin Finck FillMemory(Buffer, sizeof(Buffer), 0x55);
76*c2c66affSColin Finck Result = _sntprintf(Buffer, 1, _T("Hello"));
77*c2c66affSColin Finck ok_int(Result, -1);
78*c2c66affSColin Finck ok(Buffer[0] == _T('H'), "\n");
79*c2c66affSColin Finck ok(Buffer[1] == (_TCHAR)0x5555, "\n");
80*c2c66affSColin Finck EndSeh(STATUS_SUCCESS);
81*c2c66affSColin Finck
82*c2c66affSColin Finck StartSeh()
83*c2c66affSColin Finck FillMemory(Buffer, sizeof(Buffer), 0x55);
84*c2c66affSColin Finck Result = _sntprintf(Buffer, 0, _T("Hello"));
85*c2c66affSColin Finck ok_int(Result, -1);
86*c2c66affSColin Finck ok(Buffer[0] == (_TCHAR)0x5555, "\n");
87*c2c66affSColin Finck EndSeh(STATUS_SUCCESS);
88*c2c66affSColin Finck }
89