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