[CRT_APITEST]
authorTimo Kreuzer <timo.kreuzer@reactos.org>
Mon, 28 Dec 2015 15:24:47 +0000 (15:24 +0000)
committerTimo Kreuzer <timo.kreuzer@reactos.org>
Mon, 28 Dec 2015 15:24:47 +0000 (15:24 +0000)
Add tests for _snprintf, _snwprintf, strtoul, wcstoul
Patch by Thomas Faber (slightly modified by me)
CORE-6510

svn path=/trunk/; revision=70455

rostests/apitests/crt/_snprintf.c [new file with mode: 0644]
rostests/apitests/crt/_sntprintf.h [new file with mode: 0644]
rostests/apitests/crt/_snwprintf.c [new file with mode: 0644]
rostests/apitests/crt/crtdll_crt_apitest.cmake
rostests/apitests/crt/msvcrt_crt_apitest.cmake
rostests/apitests/crt/ntdll_crt_apitest.cmake
rostests/apitests/crt/strtoul.c [new file with mode: 0644]
rostests/apitests/crt/tcstoul.h [new file with mode: 0644]
rostests/apitests/crt/testlist.c
rostests/apitests/crt/wcstoul.c [new file with mode: 0644]

diff --git a/rostests/apitests/crt/_snprintf.c b/rostests/apitests/crt/_snprintf.c
new file mode 100644 (file)
index 0000000..29580d6
--- /dev/null
@@ -0,0 +1,2 @@
+#define func__sntprintf func__snprintf
+#include "_sntprintf.h"
diff --git a/rostests/apitests/crt/_sntprintf.h b/rostests/apitests/crt/_sntprintf.h
new file mode 100644 (file)
index 0000000..6b59620
--- /dev/null
@@ -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);
+}
diff --git a/rostests/apitests/crt/_snwprintf.c b/rostests/apitests/crt/_snwprintf.c
new file mode 100644 (file)
index 0000000..0f89198
--- /dev/null
@@ -0,0 +1,3 @@
+#define _UNICODE
+#define func__sntprintf func__snwprintf
+#include "_sntprintf.h"
index a1a3395..3178636 100644 (file)
@@ -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
index ae02f6a..04021e3 100644 (file)
@@ -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
index 5d172b1..b401801 100644 (file)
@@ -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")
diff --git a/rostests/apitests/crt/strtoul.c b/rostests/apitests/crt/strtoul.c
new file mode 100644 (file)
index 0000000..41386b1
--- /dev/null
@@ -0,0 +1,2 @@
+#define func_tcstoul func_strtoul
+#include "tcstoul.h"
diff --git a/rostests/apitests/crt/tcstoul.h b/rostests/apitests/crt/tcstoul.h
new file mode 100644 (file)
index 0000000..6ded8d4
--- /dev/null
@@ -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);
+    }
+}
index dc00da5..cf9da52 100644 (file)
@@ -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)
     // ...
diff --git a/rostests/apitests/crt/wcstoul.c b/rostests/apitests/crt/wcstoul.c
new file mode 100644 (file)
index 0000000..5e2c7c3
--- /dev/null
@@ -0,0 +1,3 @@
+#define _UNICODE
+#define func_tcstoul func_wcstoul
+#include "tcstoul.h"