mirror of
https://github.com/reactos/reactos.git
synced 2024-07-01 02:10:07 +00:00
[CRT_APITEST]
Add tests for _snprintf, _snwprintf, strtoul, wcstoul Patch by Thomas Faber (slightly modified by me) CORE-6510 svn path=/trunk/; revision=70455
This commit is contained in:
parent
ec916c445e
commit
42a833ef22
2
rostests/apitests/crt/_snprintf.c
Normal file
2
rostests/apitests/crt/_snprintf.c
Normal file
|
@ -0,0 +1,2 @@
|
|||
#define func__sntprintf func__snprintf
|
||||
#include "_sntprintf.h"
|
88
rostests/apitests/crt/_sntprintf.h
Normal file
88
rostests/apitests/crt/_sntprintf.h
Normal file
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* PROJECT: ReactOS api tests
|
||||
* LICENSE: GPLv2+ - See COPYING in the top level directory
|
||||
* PURPOSE: Test for _sntprintf
|
||||
* PROGRAMMER: Thomas Faber <thfabba@gmx.de>
|
||||
*/
|
||||
|
||||
#define WIN32_NO_STATUS
|
||||
#include <wine/test.h>
|
||||
#include <stdio.h>
|
||||
#include <tchar.h>
|
||||
#include <pseh/pseh2.h>
|
||||
#include <ndk/mmfuncs.h>
|
||||
#include <ndk/rtlfuncs.h>
|
||||
|
||||
#define StartSeh() ExceptionStatus = STATUS_SUCCESS; _SEH2_TRY {
|
||||
#define EndSeh(ExpectedStatus) } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { ExceptionStatus = _SEH2_GetExceptionCode(); } _SEH2_END; ok(ExceptionStatus == ExpectedStatus, "Exception %lx, expected %lx\n", ExceptionStatus, ExpectedStatus)
|
||||
|
||||
/* winetest_platform is "windows" for us, so broken() doesn't do what it should :( */
|
||||
#undef broken
|
||||
#define broken(x) 0
|
||||
|
||||
START_TEST(_sntprintf)
|
||||
{
|
||||
NTSTATUS ExceptionStatus;
|
||||
_TCHAR Buffer[128];
|
||||
size_t BufferSize = sizeof(Buffer) / sizeof(Buffer[0]);
|
||||
int Result;
|
||||
|
||||
StartSeh()
|
||||
Result = _sntprintf(NULL, 0, _T("Hello"));
|
||||
#ifdef TEST_CRTDLL
|
||||
ok_int(Result, -1);
|
||||
#else
|
||||
ok_int(Result, 5);
|
||||
#endif
|
||||
EndSeh(STATUS_SUCCESS);
|
||||
|
||||
StartSeh()
|
||||
Result = _sntprintf(NULL, 1, _T("Hello"));
|
||||
ok(Result == 5 ||
|
||||
broken(Result == -1) /* Win7 */, "Result = %d\n", Result);
|
||||
#if defined(_UNICODE) || defined(TEST_CRTDLL)
|
||||
EndSeh(STATUS_ACCESS_VIOLATION);
|
||||
#else
|
||||
EndSeh(STATUS_SUCCESS);
|
||||
#endif
|
||||
|
||||
StartSeh()
|
||||
FillMemory(Buffer, sizeof(Buffer), 0x55);
|
||||
Result = _sntprintf(Buffer, BufferSize, _T("Hello"));
|
||||
ok_int(Result, 5);
|
||||
ok(Buffer[0] == _T('H'), "\n");
|
||||
ok(Buffer[1] == _T('e'), "\n");
|
||||
ok(Buffer[2] == _T('l'), "\n");
|
||||
ok(Buffer[3] == _T('l'), "\n");
|
||||
ok(Buffer[4] == _T('o'), "\n");
|
||||
ok(Buffer[5] == _T('\0'), "\n");
|
||||
ok(Buffer[6] == (_TCHAR)0x5555, "\n");
|
||||
EndSeh(STATUS_SUCCESS);
|
||||
|
||||
StartSeh()
|
||||
FillMemory(Buffer, sizeof(Buffer), 0x55);
|
||||
Result = _sntprintf(Buffer, 5, _T("Hello"));
|
||||
ok_int(Result, 5);
|
||||
ok(Buffer[0] == _T('H'), "\n");
|
||||
ok(Buffer[1] == _T('e'), "\n");
|
||||
ok(Buffer[2] == _T('l'), "\n");
|
||||
ok(Buffer[3] == _T('l'), "\n");
|
||||
ok(Buffer[4] == _T('o'), "\n");
|
||||
ok(Buffer[5] == (_TCHAR)0x5555, "\n");
|
||||
EndSeh(STATUS_SUCCESS);
|
||||
|
||||
StartSeh()
|
||||
FillMemory(Buffer, sizeof(Buffer), 0x55);
|
||||
Result = _sntprintf(Buffer, 1, _T("Hello"));
|
||||
ok_int(Result, -1);
|
||||
ok(Buffer[0] == _T('H'), "\n");
|
||||
ok(Buffer[1] == (_TCHAR)0x5555, "\n");
|
||||
EndSeh(STATUS_SUCCESS);
|
||||
|
||||
StartSeh()
|
||||
FillMemory(Buffer, sizeof(Buffer), 0x55);
|
||||
Result = _sntprintf(Buffer, 0, _T("Hello"));
|
||||
ok_int(Result, -1);
|
||||
ok(Buffer[0] == (_TCHAR)0x5555, "\n");
|
||||
EndSeh(STATUS_SUCCESS);
|
||||
}
|
3
rostests/apitests/crt/_snwprintf.c
Normal file
3
rostests/apitests/crt/_snwprintf.c
Normal file
|
@ -0,0 +1,3 @@
|
|||
#define _UNICODE
|
||||
#define func__sntprintf func__snwprintf
|
||||
#include "_sntprintf.h"
|
|
@ -264,9 +264,8 @@ list(APPEND SOURCE_CRTDLL
|
|||
# _setmode.c
|
||||
# _setsystime.c
|
||||
# _sleep.c
|
||||
# _snprintf.c
|
||||
# _snwprintf.c
|
||||
# _sopen.c
|
||||
_snprintf.c
|
||||
_snwprintf.c# _sopen.c
|
||||
# _spawnl.c
|
||||
# _spawnle.c
|
||||
# _spawnlp.c
|
||||
|
@ -477,7 +476,7 @@ list(APPEND SOURCE_CRTDLL
|
|||
# strtod.c
|
||||
# strtok.c
|
||||
# strtol.c
|
||||
# strtoul.c
|
||||
strtoul.c
|
||||
# strxfrm.c
|
||||
# swprintf.c
|
||||
# swscanf.c
|
||||
|
@ -518,7 +517,7 @@ list(APPEND SOURCE_CRTDLL
|
|||
# wcstok.c
|
||||
# wcstol.c
|
||||
wcstombs.c
|
||||
# wcstoul.c
|
||||
wcstoul.c
|
||||
# wcsxfrm.c
|
||||
# wctomb.c
|
||||
# wprintf.c
|
||||
|
|
|
@ -679,7 +679,7 @@ list(APPEND SOURCE_MSVCRT
|
|||
# _setmode.c
|
||||
# _setsystime.c
|
||||
# _sleep.c
|
||||
# _snprintf.c
|
||||
_snprintf.c
|
||||
# _snprintf_c
|
||||
# _snprintf_c_l
|
||||
# _snprintf_l
|
||||
|
@ -689,7 +689,7 @@ list(APPEND SOURCE_MSVCRT
|
|||
# _snscanf_l
|
||||
# _snscanf_s
|
||||
# _snscanf_s_l
|
||||
# _snwprintf.c
|
||||
_snwprintf.c
|
||||
# _snwprintf_l
|
||||
# _snwprintf_s
|
||||
# _snwprintf_s_l
|
||||
|
@ -1188,7 +1188,7 @@ list(APPEND SOURCE_MSVCRT
|
|||
# strtok.c
|
||||
# strtok_s.c
|
||||
# strtol.c
|
||||
# strtoul.c
|
||||
strtoul.c
|
||||
# strxfrm.c
|
||||
# swprintf.c
|
||||
# swprintf_s.c
|
||||
|
@ -1252,7 +1252,7 @@ list(APPEND SOURCE_MSVCRT
|
|||
# wcstol.c
|
||||
wcstombs.c
|
||||
# wcstombs_s.c Not exported in 2k3 Sp1
|
||||
# wcstoul.c
|
||||
wcstoul.c
|
||||
# wcsxfrm.c
|
||||
# wctob
|
||||
# wctomb.c
|
||||
|
|
|
@ -19,8 +19,8 @@ list(APPEND SOURCE_NTDLL
|
|||
# _ltow.c
|
||||
# _memccpy.c
|
||||
# _memicmp.c
|
||||
# _snprintf.c
|
||||
# _snwprintf.c
|
||||
_snprintf.c
|
||||
_snwprintf.c
|
||||
# _splitpath.c
|
||||
# _strcmpi == _stricmp
|
||||
# _stricmp.c
|
||||
|
@ -97,7 +97,7 @@ list(APPEND SOURCE_NTDLL
|
|||
# strspn.c
|
||||
# strstr.c
|
||||
# strtol.c
|
||||
# strtoul.c
|
||||
strtoul.c
|
||||
# swprintf.c
|
||||
# tan.c
|
||||
# tolower.c
|
||||
|
@ -121,7 +121,7 @@ list(APPEND SOURCE_NTDLL
|
|||
# wcstok.c
|
||||
# wcstol.c
|
||||
wcstombs.c
|
||||
# wcstoul.c
|
||||
wcstoul.c
|
||||
)
|
||||
|
||||
if(ARCH STREQUAL "i386")
|
||||
|
|
2
rostests/apitests/crt/strtoul.c
Normal file
2
rostests/apitests/crt/strtoul.c
Normal file
|
@ -0,0 +1,2 @@
|
|||
#define func_tcstoul func_strtoul
|
||||
#include "tcstoul.h"
|
102
rostests/apitests/crt/tcstoul.h
Normal file
102
rostests/apitests/crt/tcstoul.h
Normal file
|
@ -0,0 +1,102 @@
|
|||
/*
|
||||
* PROJECT: ReactOS api tests
|
||||
* LICENSE: GPLv2+ - See COPYING in the top level directory
|
||||
* PURPOSE: Test for _tcstoul
|
||||
* PROGRAMMER: Thomas Faber <thfabba@gmx.de>
|
||||
*/
|
||||
|
||||
#define WIN32_NO_STATUS
|
||||
#include <wine/test.h>
|
||||
#include <tchar.h>
|
||||
#include <pseh/pseh2.h>
|
||||
#include <ndk/mmfuncs.h>
|
||||
#include <ndk/rtlfuncs.h>
|
||||
|
||||
#define StartSeh() ExceptionStatus = STATUS_SUCCESS; _SEH2_TRY {
|
||||
#define EndSeh(ExpectedStatus) } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { ExceptionStatus = _SEH2_GetExceptionCode(); } _SEH2_END; ok(ExceptionStatus == ExpectedStatus, "Exception %lx, expected %lx\n", ExceptionStatus, ExpectedStatus)
|
||||
|
||||
#define ok_ulong(expression, result) \
|
||||
do { \
|
||||
unsigned long _value = (expression); \
|
||||
ok(_value == (result), "Wrong value for '%s', expected: " #result " (%lu), got: %lu\n", \
|
||||
#expression, (unsigned long)(result), _value); \
|
||||
} while (0)
|
||||
|
||||
START_TEST(tcstoul)
|
||||
{
|
||||
NTSTATUS ExceptionStatus;
|
||||
ULONG Result;
|
||||
_TCHAR Dummy;
|
||||
_TCHAR *End;
|
||||
struct
|
||||
{
|
||||
const _TCHAR *Input;
|
||||
int ExpectedLength0;
|
||||
ULONG Expected0;
|
||||
int ExpectedLength10;
|
||||
ULONG Expected10;
|
||||
} Tests[] =
|
||||
{
|
||||
{ _T(""), 0, 0, 0, 0 },
|
||||
{ _T(" "), 0, 0, 0, 0 },
|
||||
{ _T(" 0"), 2, 0, 2, 0 },
|
||||
{ _T("0 "), 1, 0, 1, 0 },
|
||||
{ _T("0"), 1, 0, 1, 0 },
|
||||
{ _T("1"), 1, 1, 1, 1 },
|
||||
{ _T("10"), 2, 10, 2, 10 },
|
||||
{ _T("01"), 2, 1, 2, 1 },
|
||||
{ _T("010"), 3, 8, 3, 10 },
|
||||
{ _T("08"), 1, 0, 2, 8 },
|
||||
{ _T("008"), 2, 0, 3, 8 },
|
||||
{ _T("-1"), 2, -1, 2, -1 },
|
||||
{ _T("+1"), 2, 1, 2, 1 },
|
||||
{ _T("--1"), 0, 0, 0, 0 },
|
||||
{ _T("++1"), 0, 0, 0, 0 },
|
||||
{ _T("0a"), 1, 0, 1, 0 },
|
||||
{ _T("0x"), 0, 0, 1, 0 },
|
||||
{ _T("0x0"), 3, 0, 1, 0 },
|
||||
{ _T("0xFFFFFFFF"), 10, -1, 1, 0 },
|
||||
{ _T("0xFFFFFFFFF"),11, -1, 1, 0 },
|
||||
{ _T("4294967295"), 10, -1, 10, -1 },
|
||||
{ _T("4294967296"), 10, -1, 10, -1 },
|
||||
{ _T("4294967297"), 10, -1, 10, -1 },
|
||||
{ _T("42949672951"),11, -1, 11, -1 },
|
||||
};
|
||||
const INT TestCount = sizeof(Tests) / sizeof(Tests[0]);
|
||||
INT i;
|
||||
|
||||
StartSeh()
|
||||
Result = _tcstoul(NULL, NULL, 0);
|
||||
EndSeh(STATUS_ACCESS_VIOLATION);
|
||||
|
||||
StartSeh()
|
||||
Result = _tcstoul(_T(""), NULL, 0);
|
||||
ok_ulong(Result, 0);
|
||||
EndSeh(STATUS_SUCCESS);
|
||||
|
||||
StartSeh()
|
||||
Result = _tcstoul(_T("1"), NULL, 0);
|
||||
ok_ulong(Result, 1);
|
||||
EndSeh(STATUS_SUCCESS);
|
||||
|
||||
Result = _tcstoul(_T("1"), &End, 0);
|
||||
ok_ulong(Result, 1);
|
||||
|
||||
for (i = 0; i < TestCount; i++)
|
||||
{
|
||||
#ifdef _UNICODE
|
||||
trace("%d: '%ls'\n", i, Tests[i].Input);
|
||||
#else
|
||||
trace("%d: '%s'\n", i, Tests[i].Input);
|
||||
#endif
|
||||
End = &Dummy;
|
||||
Result = _tcstoul(Tests[i].Input, &End, 0);
|
||||
ok_ulong(Result, Tests[i].Expected0);
|
||||
ok_ptr(End, Tests[i].Input + Tests[i].ExpectedLength0);
|
||||
|
||||
End = &Dummy;
|
||||
Result = _tcstoul(Tests[i].Input, &End, 10);
|
||||
ok_ulong(Result, Tests[i].Expected10);
|
||||
ok_ptr(End, Tests[i].Input + Tests[i].ExpectedLength10);
|
||||
}
|
||||
}
|
|
@ -10,13 +10,21 @@ extern void func__vscwprintf(void);
|
|||
#if defined(TEST_NTDLL)
|
||||
extern void func__vscwprintf(void);
|
||||
#endif
|
||||
extern void func_fputc(void);
|
||||
extern void func_fputwc(void);
|
||||
extern void func__snprintf(void);
|
||||
extern void func__snwprintf(void);
|
||||
extern void func__vsnprintf(void);
|
||||
extern void func__vsnwprintf(void);
|
||||
extern void func_mbstowcs(void);
|
||||
extern void func_sprintf(void);
|
||||
extern void func_strcpy(void);
|
||||
extern void func_strlen(void);
|
||||
extern void func_strnlen(void);
|
||||
extern void func_strtoul(void);
|
||||
extern void func_wcsnlen(void);
|
||||
extern void func_wcstombs(void);
|
||||
extern void func_wcstoul(void);
|
||||
|
||||
extern void func_static_construct(void);
|
||||
extern void func_static_init(void);
|
||||
|
@ -26,9 +34,13 @@ const struct test winetest_testlist[] =
|
|||
{ "_vsnprintf", func__vsnprintf },
|
||||
{ "_vsnwprintf", func__vsnwprintf },
|
||||
{ "mbstowcs", func_mbstowcs },
|
||||
{ "_snprintf", func__snprintf },
|
||||
{ "_snwprintf", func__snwprintf },
|
||||
{ "sprintf", func_sprintf },
|
||||
{ "strcpy", func_strcpy },
|
||||
{ "strlen", func_strlen },
|
||||
{ "strtoul", func_strtoul },
|
||||
{ "wcstoul", func_wcstoul },
|
||||
{ "wcstombs", func_wcstombs },
|
||||
#if defined(TEST_CRTDLL) || defined(TEST_MSVCRT) || defined(TEST_STATIC_CRT)
|
||||
// ...
|
||||
|
|
3
rostests/apitests/crt/wcstoul.c
Normal file
3
rostests/apitests/crt/wcstoul.c
Normal file
|
@ -0,0 +1,3 @@
|
|||
#define _UNICODE
|
||||
#define func_tcstoul func_wcstoul
|
||||
#include "tcstoul.h"
|
Loading…
Reference in a new issue