1 /* 2 * PROJECT: ReactOS api tests 3 * LICENSE: GPL - See COPYING in the top level directory 4 * PURPOSE: Test for _vsnwprintf 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(wchar_t* buf, size_t buf_size, int expected_ret, LPCWSTR formatString, ...) 17 { 18 va_list args; 19 int ret; 20 /* Test the basic functionality */ 21 va_start(args, formatString); 22 ret = _vsnwprintf(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 27 START_TEST(_vsnwprintf) 28 { 29 wchar_t buffer[255]; 30 31 /* Test basic functionality */ 32 //call_varargs(buffer, 255, 10, L"%s world!", "hello"); // this test is broken 33 call_varargs(buffer, 255, 12, L"%s world!", L"hello"); 34 call_varargs(buffer, 255, 11, L"%u cookies", 100); 35 /* This is how WINE implements _vcsprintf, and they are obviously wrong */ 36 StartSeh() 37 #if defined(TEST_CRTDLL) 38 call_varargs(NULL, INT_MAX, -1, L"%s it really work?", L"does"); 39 #else 40 call_varargs(NULL, INT_MAX, 20, L"%s it really work?", L"does"); 41 #endif 42 43 #if defined(TEST_USER32) 44 EndSeh(STATUS_ACCESS_VIOLATION); 45 #else 46 EndSeh(STATUS_SUCCESS); 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) 58 call_varargs(NULL, 0, -1, L"%s it really work?", L"does"); 59 #else 60 call_varargs(NULL, 0, 20, L"%s it really work?", L"does"); 61 #endif 62 EndSeh(STATUS_SUCCESS); 63 ok(errno == 0, "Expected 0, got %u\n", errno); 64 65 66 /* One more NULL checks */ 67 StartSeh() 68 call_varargs(buffer, 255, -1, NULL); 69 EndSeh(STATUS_ACCESS_VIOLATION); 70 ok(errno == 0, "Expected 0, got %u\n", errno); 71 } 72