Author: tkreuzer
Date: Mon Dec 28 15:24:47 2015
New Revision: 70455

URL: http://svn.reactos.org/svn/reactos?rev=70455&view=rev
Log:
[CRT_APITEST]
Add tests for _snprintf, _snwprintf, strtoul, wcstoul
Patch by Thomas Faber (slightly modified by me)
CORE-6510

Added:
    trunk/rostests/apitests/crt/_snprintf.c   (with props)
    trunk/rostests/apitests/crt/_sntprintf.h   (with props)
    trunk/rostests/apitests/crt/_snwprintf.c   (with props)
    trunk/rostests/apitests/crt/strtoul.c   (with props)
    trunk/rostests/apitests/crt/tcstoul.h   (with props)
    trunk/rostests/apitests/crt/wcstoul.c   (with props)
Modified:
    trunk/rostests/apitests/crt/crtdll_crt_apitest.cmake
    trunk/rostests/apitests/crt/msvcrt_crt_apitest.cmake
    trunk/rostests/apitests/crt/ntdll_crt_apitest.cmake
    trunk/rostests/apitests/crt/testlist.c

Added: trunk/rostests/apitests/crt/_snprintf.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/crt/_snprintf.c?rev=70455
==============================================================================
--- trunk/rostests/apitests/crt/_snprintf.c     (added)
+++ trunk/rostests/apitests/crt/_snprintf.c     [iso-8859-1] Mon Dec 28 
15:24:47 2015
@@ -0,0 +1,2 @@
+#define func__sntprintf func__snprintf
+#include "_sntprintf.h"

Propchange: trunk/rostests/apitests/crt/_snprintf.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: trunk/rostests/apitests/crt/_sntprintf.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/crt/_sntprintf.h?rev=70455
==============================================================================
--- trunk/rostests/apitests/crt/_sntprintf.h    (added)
+++ trunk/rostests/apitests/crt/_sntprintf.h    [iso-8859-1] Mon Dec 28 
15:24:47 2015
@@ -0,0 +1,88 @@
+/*
+ * PROJECT:         ReactOS api tests
+ * LICENSE:         GPLv2+ - See COPYING in the top level directory
+ * PURPOSE:         Test for _sntprintf
+ * PROGRAMMER:      Thomas Faber <[email protected]>
+ */
+
+#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);
+}

Propchange: trunk/rostests/apitests/crt/_sntprintf.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: trunk/rostests/apitests/crt/_snwprintf.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/crt/_snwprintf.c?rev=70455
==============================================================================
--- trunk/rostests/apitests/crt/_snwprintf.c    (added)
+++ trunk/rostests/apitests/crt/_snwprintf.c    [iso-8859-1] Mon Dec 28 
15:24:47 2015
@@ -0,0 +1,3 @@
+#define _UNICODE
+#define func__sntprintf func__snwprintf
+#include "_sntprintf.h"

Propchange: trunk/rostests/apitests/crt/_snwprintf.c
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: trunk/rostests/apitests/crt/crtdll_crt_apitest.cmake
URL: 
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/crt/crtdll_crt_apitest.cmake?rev=70455&r1=70454&r2=70455&view=diff
==============================================================================
--- trunk/rostests/apitests/crt/crtdll_crt_apitest.cmake        [iso-8859-1] 
(original)
+++ trunk/rostests/apitests/crt/crtdll_crt_apitest.cmake        [iso-8859-1] 
Mon Dec 28 15:24:47 2015
@@ -264,9 +264,8 @@
 #    _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 @@
 #    strtod.c
 #    strtok.c
 #    strtol.c
-#    strtoul.c
+    strtoul.c
 #    strxfrm.c
 #    swprintf.c
 #    swscanf.c
@@ -518,7 +517,7 @@
 #    wcstok.c
 #    wcstol.c
     wcstombs.c
-#    wcstoul.c
+    wcstoul.c
 #    wcsxfrm.c
 #    wctomb.c
 #    wprintf.c

Modified: trunk/rostests/apitests/crt/msvcrt_crt_apitest.cmake
URL: 
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/crt/msvcrt_crt_apitest.cmake?rev=70455&r1=70454&r2=70455&view=diff
==============================================================================
--- trunk/rostests/apitests/crt/msvcrt_crt_apitest.cmake        [iso-8859-1] 
(original)
+++ trunk/rostests/apitests/crt/msvcrt_crt_apitest.cmake        [iso-8859-1] 
Mon Dec 28 15:24:47 2015
@@ -679,7 +679,7 @@
 #    _setmode.c
 #    _setsystime.c
 #    _sleep.c
-#    _snprintf.c
+    _snprintf.c
 #    _snprintf_c
 #    _snprintf_c_l
 #    _snprintf_l
@@ -689,7 +689,7 @@
 #    _snscanf_l
 #    _snscanf_s
 #    _snscanf_s_l
-#    _snwprintf.c
+    _snwprintf.c
 #    _snwprintf_l
 #    _snwprintf_s
 #    _snwprintf_s_l
@@ -1188,7 +1188,7 @@
 #    strtok.c
 #    strtok_s.c
 #    strtol.c
-#    strtoul.c
+    strtoul.c
 #    strxfrm.c
 #    swprintf.c
 #    swprintf_s.c
@@ -1252,7 +1252,7 @@
 #    wcstol.c
     wcstombs.c
 #    wcstombs_s.c Not exported in 2k3 Sp1
-#    wcstoul.c
+    wcstoul.c
 #    wcsxfrm.c
 #    wctob
 #    wctomb.c

Modified: trunk/rostests/apitests/crt/ntdll_crt_apitest.cmake
URL: 
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/crt/ntdll_crt_apitest.cmake?rev=70455&r1=70454&r2=70455&view=diff
==============================================================================
--- trunk/rostests/apitests/crt/ntdll_crt_apitest.cmake [iso-8859-1] (original)
+++ trunk/rostests/apitests/crt/ntdll_crt_apitest.cmake [iso-8859-1] Mon Dec 28 
15:24:47 2015
@@ -19,8 +19,8 @@
 #    _ltow.c
 #    _memccpy.c
 #    _memicmp.c
-#    _snprintf.c
-#    _snwprintf.c
+    _snprintf.c
+    _snwprintf.c
 #    _splitpath.c
     # _strcmpi == _stricmp
 #    _stricmp.c
@@ -97,7 +97,7 @@
 #    strspn.c
 #    strstr.c
 #    strtol.c
-#    strtoul.c
+    strtoul.c
 #    swprintf.c
 #    tan.c
 #    tolower.c
@@ -121,7 +121,7 @@
 #    wcstok.c
 #    wcstol.c
     wcstombs.c
-#    wcstoul.c
+    wcstoul.c
 )
 
 if(ARCH STREQUAL "i386")

Added: trunk/rostests/apitests/crt/strtoul.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/crt/strtoul.c?rev=70455
==============================================================================
--- trunk/rostests/apitests/crt/strtoul.c       (added)
+++ trunk/rostests/apitests/crt/strtoul.c       [iso-8859-1] Mon Dec 28 
15:24:47 2015
@@ -0,0 +1,2 @@
+#define func_tcstoul func_strtoul
+#include "tcstoul.h"

Propchange: trunk/rostests/apitests/crt/strtoul.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: trunk/rostests/apitests/crt/tcstoul.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/crt/tcstoul.h?rev=70455
==============================================================================
--- trunk/rostests/apitests/crt/tcstoul.h       (added)
+++ trunk/rostests/apitests/crt/tcstoul.h       [iso-8859-1] Mon Dec 28 
15:24:47 2015
@@ -0,0 +1,102 @@
+/*
+ * PROJECT:         ReactOS api tests
+ * LICENSE:         GPLv2+ - See COPYING in the top level directory
+ * PURPOSE:         Test for _tcstoul
+ * PROGRAMMER:      Thomas Faber <[email protected]>
+ */
+
+#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);
+    }
+}

Propchange: trunk/rostests/apitests/crt/tcstoul.h
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: trunk/rostests/apitests/crt/testlist.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/crt/testlist.c?rev=70455&r1=70454&r2=70455&view=diff
==============================================================================
--- trunk/rostests/apitests/crt/testlist.c      [iso-8859-1] (original)
+++ trunk/rostests/apitests/crt/testlist.c      [iso-8859-1] Mon Dec 28 
15:24:47 2015
@@ -10,13 +10,21 @@
 #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 @@
     { "_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)
     // ...

Added: trunk/rostests/apitests/crt/wcstoul.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/crt/wcstoul.c?rev=70455
==============================================================================
--- trunk/rostests/apitests/crt/wcstoul.c       (added)
+++ trunk/rostests/apitests/crt/wcstoul.c       [iso-8859-1] Mon Dec 28 
15:24:47 2015
@@ -0,0 +1,3 @@
+#define _UNICODE
+#define func_tcstoul func_wcstoul
+#include "tcstoul.h"

Propchange: trunk/rostests/apitests/crt/wcstoul.c
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to