[CRT_APITEST]
authorTimo Kreuzer <timo.kreuzer@reactos.org>
Thu, 27 Sep 2012 21:46:39 +0000 (21:46 +0000)
committerTimo Kreuzer <timo.kreuzer@reactos.org>
Thu, 27 Sep 2012 21:46:39 +0000 (21:46 +0000)
- Add tests for wcstombs_s
- Improve tests for mbstowcs_s

svn path=/trunk/; revision=57403

rostests/apitests/crt/mbstowcs_s.c
rostests/apitests/crt/msvcrt_crt_apitest.cmake
rostests/apitests/crt/testlist.c
rostests/apitests/crt/wcstombs_s.c [new file with mode: 0644]

index 8037c84..e78ac10 100644 (file)
 #include <specstrings.h>
 
 #define ok_errno(x) ok_hex(errno, (x))
+#define ok_wchar(x,y) ok_int(x,y)
 
 errno_t
 mbstowcs_s(
-    size_t *returnval,
+    size_t *cchConverted,
     wchar_t *widechar,
     size_t charoutct,
     const char *multibyte,
     size_t count);
 
-void
-_invalid_parameter(
-   const wchar_t * expression,
-   const wchar_t * function,
-   const wchar_t * file,
-   unsigned int line,
-   uintptr_t pReserved);
-
-void
-_invalid_parameterA(
-   const char * expression,
-   const char * function,
-   const char * file,
-   unsigned int line,
-   uintptr_t pReserved)
-{
-    // call _invalid_parameter
-}
-
 #define MSVCRT_INVALID_PMT(x) _invalid_parameterA(#x, __FUNCTION__, __FILE__, __LINE__, 0)
 #define MSVCRT_CHECK_PMT(x)   ((x) || (MSVCRT_INVALID_PMT(x),0))
 
-#define _mbsnlen strnlen
-
-errno_t
-mbstowcs_s(
-   _Out_opt_ size_t *pReturnValue,
-   _Out_ wchar_t *pwcstr,
-   _In_ size_t sizeInWords,
-   _In_ const char *pmbstr,
-   _In_ size_t count)
-{
-    size_t cchMax, cwcWritten;
-    errno_t retval = 0;
-
-    if (!MSVCRT_CHECK_PMT( ((sizeInWords != 0) && (pwcstr != 0)) ||
-                           ((sizeInWords == 0) && (pwcstr == 0)) ))
-    {
-        _set_errno(EINVAL);
-        return EINVAL;
-    }
-
-    /* Check if we have a return value pointer */
-    if (pReturnValue)
-    {
-        /* Default to 0 bytes written */
-        *pReturnValue = 0;
-    }
-
-    if (!MSVCRT_CHECK_PMT((count == 0) || (pmbstr != 0)))
-    {
-        _set_errno(EINVAL);
-        return EINVAL;
-    }
-
-    /* Check if there is anything to do */
-    if ((pwcstr == 0) && (pmbstr == 0))
-    {
-        _set_errno(EINVAL);
-        return EINVAL;
-    }
-
-    /* Check if we have a source string */
-    if (pmbstr)
-    {
-        /* Check if we also have a wchar buffer */
-        if (pwcstr)
-        {
-            /* Calculate the maximum the we can write */
-            cchMax = (count < sizeInWords) ? count + 1 : sizeInWords;
-
-            /* Now do the conversion */
-            cwcWritten = mbstowcs(pwcstr, pmbstr, cchMax);
-
-            /* Check if the buffer was not zero terminated */
-            if (cwcWritten == cchMax)
-            {
-                /* Check if we reached the max size of the dest buffer */
-                if (cwcWritten == sizeInWords)
-                {
-                    /* Does the caller allow this? */
-                    if (count != _TRUNCATE)
-                    {
-                        /* Not allowed, truncate to 0 length */
-                        pwcstr[0] = L'\0';
-
-                        /* Return error */
-                        _set_errno(ERANGE);
-                        return ERANGE;
-                    }
-
-                    /* Inform the caller about truncation */
-                    retval = STRUNCATE;
-                }
-
-                /* zero teminate the buffer */
-                pwcstr[cwcWritten - 1] = L'\0';
-            }
-            else
-            {
-                /* The buffer is zero terminated, count the terminating char */
-                cwcWritten++;
-            }
-        }
-        else
-        {
-            /* Get the length of the string, plus 0 terminator */
-            cwcWritten = _mbsnlen(pmbstr, count) + 1;
-        }
-    }
-    else
-    {
-        cwcWritten = count + 1;
-    }
-
-    /* Check if we have a return value pointer */
-    if (pReturnValue)
-    {
-        /* Default to 0 bytes written */
-        *pReturnValue = cwcWritten;
-    }
-
-    return retval;
-}
-
-
-
 wchar_t g_expression[64];
 wchar_t g_function[64];
 wchar_t g_file[128];
@@ -173,64 +50,64 @@ START_TEST(mbstowcs_s)
 //    _set_invalid_parameter_handler(_test_invalid_parameter);
 
     errno_t ret;
-    size_t returnval;
+    size_t cchConverted;
     wchar_t widechar[10];
-#if 1
+
     _set_errno(0);
-    returnval = 0xf00bac;
+    cchConverted = 0xf00bac;
     widechar[5] = 0xFF;
-    ret = mbstowcs_s(&returnval, widechar, 6, "hallo", 5);
+    ret = mbstowcs_s(&cchConverted, widechar, 6, "hallo", 5);
     ok_long(ret, 0);
-    ok_size_t(returnval, 6);
-    ok_char(widechar[5], 0);
+    ok_size_t(cchConverted, 6);
+    ok_wchar(widechar[5], 0);
     ok_wstr(widechar, L"hallo");
     ok_errno(0);
 
     _set_errno(0);
-    returnval = 0xf00bac;
+    cchConverted = 0xf00bac;
     widechar[0] = 0xFF;
-    ret = mbstowcs_s(&returnval, widechar, 1, "", 0);
+    ret = mbstowcs_s(&cchConverted, widechar, 1, "", 0);
     ok_long(ret, 0);
-    ok_size_t(returnval, 1);
-    ok_char(widechar[0], 0);
+    ok_size_t(cchConverted, 1);
+    ok_wchar(widechar[0], 0);
     ok_errno(0);
 
     _set_errno(0);
-    returnval = 0xf00bac;
+    cchConverted = 0xf00bac;
     widechar[0] = 0xFF;
     widechar[1] = 0xFF;
     widechar[2] = 0xFF;
     widechar[3] = 0xFF;
     widechar[4] = 0xFF;
     widechar[5] = 0xFF;
-    ret = mbstowcs_s(&returnval, widechar, 5, "hallo", 5);
+    ret = mbstowcs_s(&cchConverted, widechar, 5, "hallo", 5);
     ok_long(ret, ERANGE);
-    ok_size_t(returnval, 0);
-    ok_char(widechar[5], 0xFF);
-    ok_char(widechar[4], L'o');
-    ok_char(widechar[3], L'l');
-    ok_char(widechar[2], L'l');
-    ok_char(widechar[1], L'a');
-    ok_char(widechar[0], 0);
+    ok_size_t(cchConverted, 0);
+    ok_wchar(widechar[5], 0xFF);
+    ok_wchar(widechar[4], L'o');
+    ok_wchar(widechar[3], L'l');
+    ok_wchar(widechar[2], L'l');
+    ok_wchar(widechar[1], L'a');
+    ok_wchar(widechar[0], 0);
     ok_errno(ERANGE);
 
     _set_errno(0);
-    returnval = 0xf00bac;
+    cchConverted = 0xf00bac;
     widechar[0] = 0xFF;
     widechar[1] = 0xFF;
     widechar[2] = 0xFF;
     widechar[3] = 0xFF;
     widechar[4] = 0xFF;
     widechar[5] = 0xFF;
-    ret = mbstowcs_s(&returnval, widechar, 3, "hallo", 5);
+    ret = mbstowcs_s(&cchConverted, widechar, 3, "hallo", 5);
     ok_long(ret, ERANGE);
-    ok_size_t(returnval, 0);
-    ok_char(widechar[5], 0xFF);
-    ok_char(widechar[4], 0xFF);
-    ok_char(widechar[3], 0xFF);
-    ok_char(widechar[2], L'l');
-    ok_char(widechar[1], L'a');
-    ok_char(widechar[0], 0);
+    ok_size_t(cchConverted, 0);
+    ok_wchar(widechar[5], 0xFF);
+    ok_wchar(widechar[4], 0xFF);
+    ok_wchar(widechar[3], 0xFF);
+    ok_wchar(widechar[2], L'l');
+    ok_wchar(widechar[1], L'a');
+    ok_wchar(widechar[0], 0);
     ok_errno(ERANGE);
 
     _set_errno(0);
@@ -239,17 +116,17 @@ START_TEST(mbstowcs_s)
     ok_errno(EINVAL);
 
     _set_errno(0);
-    returnval = 0xf00bac;
-    ret = mbstowcs_s(&returnval, 0, 0, 0, 0);
+    cchConverted = 0xf00bac;
+    ret = mbstowcs_s(&cchConverted, 0, 0, 0, 0);
     ok_long(ret, EINVAL);
-    ok_size_t(returnval, 0);
+    ok_size_t(cchConverted, 0);
     ok_errno(EINVAL);
 
     _set_errno(0);
     widechar[0] = L'x';
     ret = mbstowcs_s(0, widechar, 0, 0, 0);
     ok_long(ret, EINVAL);
-    ok_char(widechar[0], L'x');
+    ok_wchar(widechar[0], L'x');
     ok_errno(EINVAL);
 
     _set_errno(0);
@@ -263,98 +140,96 @@ START_TEST(mbstowcs_s)
     ok_errno(EINVAL);
 
     _set_errno(0);
-    returnval = 0xf00bac;
-    ret = mbstowcs_s(&returnval, 0, 10, "hallo", 5);
+    cchConverted = 0xf00bac;
+    ret = mbstowcs_s(&cchConverted, 0, 10, "hallo", 5);
     ok_long(ret, EINVAL);
-    ok_size_t(returnval, 0xf00bac);
+    ok_size_t(cchConverted, 0xf00bac);
     ok_errno(EINVAL);
 
     _set_errno(0);
-    returnval = 0xf00bac;
-    ret = mbstowcs_s(&returnval, 0, 0, "hallo", 5);
+    cchConverted = 0xf00bac;
+    ret = mbstowcs_s(&cchConverted, 0, 0, "hallo", 5);
     ok_long(ret, 0);
-    ok_size_t(returnval, 6);
+    ok_size_t(cchConverted, 6);
     ok_errno(0);
 
     _set_errno(0);
-    returnval = 0xf00bac;
-    ret = mbstowcs_s(&returnval, widechar, 10, 0, 5);
+    cchConverted = 0xf00bac;
+    ret = mbstowcs_s(&cchConverted, widechar, 10, 0, 5);
     ok_long(ret, EINVAL);
-    ok_size_t(returnval, 0);
+    ok_size_t(cchConverted, 0);
     ok_errno(EINVAL);
 
     _set_errno(0);
-    returnval = 0xf00bac;
-    ret = mbstowcs_s(&returnval, widechar, 10, "hallo", 0);
+    cchConverted = 0xf00bac;
+    ret = mbstowcs_s(&cchConverted, widechar, 10, "hallo", 0);
     ok_long(ret, 0);
-    ok_size_t(returnval, 1);
+    ok_size_t(cchConverted, 1);
     ok_errno(0);
-#endif
+
     _set_errno(0);
-    returnval = 0xf00bac;
+    cchConverted = 0xf00bac;
     widechar[0] = 0xABCD;
     widechar[1] = 0xABCD;
     widechar[2] = 0xABCD;
     widechar[3] = 0xABCD;
     widechar[4] = 0xABCD;
     widechar[5] = 0xABCD;
-    ret = mbstowcs_s(&returnval, widechar, 10, "hallo", 2);
+    ret = mbstowcs_s(&cchConverted, widechar, 10, "hallo", 2);
     ok_long(ret, 0);
-    ok_size_t(returnval, 3);
-    ok_char(widechar[5], 0xABCD);
-    ok_char(widechar[4], 0xABCD);
-    ok_char(widechar[3], 0xABCD);
-    ok_char(widechar[2], 0);
-    ok_char(widechar[1], L'a');
-    ok_char(widechar[0], L'h');
+    ok_size_t(cchConverted, 3);
+    ok_wchar(widechar[5], 0xABCD);
+    ok_wchar(widechar[4], 0xABCD);
+    ok_wchar(widechar[3], 0xABCD);
+    ok_wchar(widechar[2], 0);
+    ok_wchar(widechar[1], L'a');
+    ok_wchar(widechar[0], L'h');
     ok_errno(0);
-#if 1
+
     _set_errno(0);
-    returnval = 0xf00bac;
-    ret = mbstowcs_s(&returnval, widechar, 10, 0, 0);
+    cchConverted = 0xf00bac;
+    ret = mbstowcs_s(&cchConverted, widechar, 10, 0, 0);
     ok_long(ret, 0);
-    ok_size_t(returnval, 1);
+    ok_size_t(cchConverted, 1);
     ok_errno(0);
 
     _set_errno(0);
-    returnval = 0xf00bac;
-    ret = mbstowcs_s(&returnval, widechar, 10, "hallo", 7);
+    cchConverted = 0xf00bac;
+    ret = mbstowcs_s(&cchConverted, widechar, 10, "hallo", 7);
     ok_long(ret, 0);
-    ok_size_t(returnval, 6);
+    ok_size_t(cchConverted, 6);
     ok_errno(0);
 
     _set_errno(0);
-    returnval = 0xf00bac;
-    ret = mbstowcs_s(&returnval, 0, 0, "hallo", 7);
+    cchConverted = 0xf00bac;
+    ret = mbstowcs_s(&cchConverted, 0, 0, "hallo", 7);
     ok_long(ret, 0);
-    ok_size_t(returnval, 6);
+    ok_size_t(cchConverted, 6);
     ok_errno(0);
 
     _set_errno(0);
-    returnval = 0xf00bac;
+    cchConverted = 0xf00bac;
     widechar[0] = 0xABCD;
     widechar[1] = 0xABCD;
     widechar[2] = 0xABCD;
     widechar[3] = 0xABCD;
     widechar[4] = 0xABCD;
     widechar[5] = 0xABCD;
-    ret = mbstowcs_s(&returnval, widechar, 5, "hallo", _TRUNCATE);
+    ret = mbstowcs_s(&cchConverted, widechar, 5, "hallo", _TRUNCATE);
     ok_long(ret, STRUNCATE);
-    ok_size_t(returnval, 5);
-    ok_char(widechar[5], 0xABCD);
-    ok_char(widechar[4], 0);
-    ok_char(widechar[3], L'l');
-    ok_char(widechar[2], L'l');
-    ok_char(widechar[1], L'a');
-    ok_char(widechar[0], L'h');
+    ok_size_t(cchConverted, 5);
+    ok_wchar(widechar[5], 0xABCD);
+    ok_wchar(widechar[4], 0);
+    ok_wchar(widechar[3], L'l');
+    ok_wchar(widechar[2], L'l');
+    ok_wchar(widechar[1], L'a');
+    ok_wchar(widechar[0], L'h');
     ok_errno(0);
 
     _set_errno(0);
-    returnval = 0xf00bac;
-    ret = mbstowcs_s(&returnval, widechar, 10, "hallo", -1);
+    cchConverted = 0xf00bac;
+    ret = mbstowcs_s(&cchConverted, widechar, 10, "hallo", -1);
     ok_long(ret, 0);
-    ok_size_t(returnval, 6);
+    ok_size_t(cchConverted, 6);
     ok_errno(0);
-#endif
-
 }
index 9ce4ec2..b9ec8eb 100644 (file)
@@ -1251,7 +1251,7 @@ list(APPEND SOURCE_MSVCRT
 #    wcstok_s.c
 #    wcstol.c
 #    wcstombs.c
-#    wcstombs_s.c
+    wcstombs_s.c
 #    wcstoul.c
 #    wcsxfrm.c
 #    wctob
index c97b02c..31db207 100644 (file)
@@ -7,6 +7,7 @@
 
 #if defined(TEST_MSVCRT)
 extern void func_mbstowcs_s(void);
+extern void func_wcstombs_s(void);
 extern void func__vscprintf(void);
 extern void func__vscwprintf(void);
 #endif
@@ -33,6 +34,7 @@ const struct test winetest_testlist[] =
 #if defined(TEST_STATIC_CRT)
 #elif defined(TEST_MSVCRT)
     { "mbstowcs_s", func_mbstowcs_s },
+    { "wcstombs_s", func_wcstombs_s },
     { "_vscprintf", func__vscprintf },
     { "_vscwprintf", func__vscwprintf },
 #elif defined(TEST_NTDLL)
diff --git a/rostests/apitests/crt/wcstombs_s.c b/rostests/apitests/crt/wcstombs_s.c
new file mode 100644 (file)
index 0000000..1710561
--- /dev/null
@@ -0,0 +1,218 @@
+/*
+ * PROJECT:         ReactOS api tests
+ * LICENSE:         GPL - See COPYING in the top level directory
+ * PURPOSE:         Test for wcstombs_s
+ */
+
+#define WIN32_NO_STATUS
+#include <stdio.h>
+#include <stdlib.h>
+#include <wine/test.h>
+#include <specstrings.h>
+
+#define ok_errno(x) ok_hex(errno, (x))
+
+#undef ok_char
+#define ok_char(x,y) ok_int((unsigned)(unsigned char)(x),(unsigned)(unsigned char)(y))
+#define ok_wchar(x,y) ok_int((unsigned)(unsigned short)(x),(unsigned)(unsigned short)(y))
+
+_Check_return_wat_
+_CRTIMP
+errno_t
+__cdecl
+wcstombs_s(
+    _Out_opt_ size_t * pcchConverted,
+    _Out_writes_bytes_to_opt_(cjDstSize, *pcchConverted)
+        char * pmbsDst,
+    _In_ size_t cjDstSize,
+    _In_z_ const wchar_t * pwszSrc,
+    _In_ size_t cjMaxCount);
+
+
+START_TEST(wcstombs_s)
+{
+    errno_t ret;
+    size_t cchConverted;
+    char mbsbuffer[10];
+
+    _set_errno(0);
+    cchConverted = 0xf00bac;
+    mbsbuffer[5] = 0xFF;
+    ret = wcstombs_s(&cchConverted, mbsbuffer, 6, L"hallo", 5);
+    ok_long(ret, 0);
+    ok_size_t(cchConverted, 6);
+    ok_char(mbsbuffer[5], 0);
+    ok_str(mbsbuffer, "hallo");
+    ok_errno(0);
+
+    _set_errno(0);
+    cchConverted = 0xf00bac;
+    mbsbuffer[0] = 0xFF;
+    ret = wcstombs_s(&cchConverted, mbsbuffer, 1, L"", 0);
+    ok_long(ret, 0);
+    ok_size_t(cchConverted, 1);
+    ok_wchar(mbsbuffer[0], 0);
+    ok_errno(0);
+
+    _set_errno(0);
+    cchConverted = 0xf00bac;
+    mbsbuffer[0] = 0xFF;
+    mbsbuffer[1] = 0xFF;
+    mbsbuffer[2] = 0xFF;
+    mbsbuffer[3] = 0xFF;
+    mbsbuffer[4] = 0xFF;
+    mbsbuffer[5] = 0xFF;
+    ret = wcstombs_s(&cchConverted, mbsbuffer, 5, L"hallo", 5);
+    ok_long(ret, ERANGE);
+    ok_size_t(cchConverted, 0);
+    ok_char(mbsbuffer[5], 0xFF);
+    ok_char(mbsbuffer[4], L'o');
+    ok_char(mbsbuffer[3], L'l');
+    ok_char(mbsbuffer[2], L'l');
+    ok_char(mbsbuffer[1], L'a');
+    ok_char(mbsbuffer[0], 0);
+    ok_errno(ERANGE);
+
+    _set_errno(0);
+    cchConverted = 0xf00bac;
+    mbsbuffer[0] = 0xFF;
+    mbsbuffer[1] = 0xFF;
+    mbsbuffer[2] = 0xFF;
+    mbsbuffer[3] = 0xFF;
+    mbsbuffer[4] = 0xFF;
+    mbsbuffer[5] = 0xFF;
+    ret = wcstombs_s(&cchConverted, mbsbuffer, 3, L"hallo", 5);
+    ok_long(ret, ERANGE);
+    ok_size_t(cchConverted, 0);
+    ok_char(mbsbuffer[5], 0xFF);
+    ok_char(mbsbuffer[4], 0xFF);
+    ok_char(mbsbuffer[3], 0xFF);
+    ok_char(mbsbuffer[2], L'l');
+    ok_char(mbsbuffer[1], L'a');
+    ok_char(mbsbuffer[0], 0);
+    ok_errno(ERANGE);
+
+    _set_errno(0);
+    ret = wcstombs_s(0, 0, 0, 0, 0);
+    ok_long(ret, EINVAL);
+    ok_errno(EINVAL);
+
+    _set_errno(0);
+    cchConverted = 0xf00bac;
+    ret = wcstombs_s(&cchConverted, 0, 0, 0, 0);
+    ok_long(ret, EINVAL);
+    ok_size_t(cchConverted, 0);
+    ok_errno(EINVAL);
+
+    _set_errno(0);
+    mbsbuffer[0] = L'x';
+    ret = wcstombs_s(0, mbsbuffer, 0, 0, 0);
+    ok_long(ret, EINVAL);
+    ok_char(mbsbuffer[0], L'x');
+    ok_errno(EINVAL);
+
+    _set_errno(0);
+    ret = wcstombs_s(0, mbsbuffer, 10, L"hallo", 5);
+    ok_long(ret, 0);
+    ok_errno(0);
+
+    _set_errno(0);
+    ret = wcstombs_s(0, mbsbuffer, 0, L"hallo", 5);
+    ok_long(ret, EINVAL);
+    ok_errno(EINVAL);
+
+    _set_errno(0);
+    cchConverted = 0xf00bac;
+    ret = wcstombs_s(&cchConverted, 0, 10, L"hallo", 5);
+    ok_long(ret, EINVAL);
+    ok_size_t(cchConverted, 0xf00bac);
+    ok_errno(EINVAL);
+
+    _set_errno(0);
+    cchConverted = 0xf00bac;
+    ret = wcstombs_s(&cchConverted, 0, 0, L"hallo", 5);
+    ok_long(ret, 0);
+    ok_size_t(cchConverted, 6);
+    ok_errno(0);
+
+    _set_errno(0);
+    cchConverted = 0xf00bac;
+    ret = wcstombs_s(&cchConverted, mbsbuffer, 10, 0, 5);
+    ok_long(ret, EINVAL);
+    ok_size_t(cchConverted, 0);
+    ok_errno(EINVAL);
+
+    _set_errno(0);
+    cchConverted = 0xf00bac;
+    ret = wcstombs_s(&cchConverted, mbsbuffer, 10, L"hallo", 0);
+    ok_long(ret, 0);
+    ok_size_t(cchConverted, 1);
+    ok_errno(0);
+
+    _set_errno(0);
+    cchConverted = 0xf00bac;
+    mbsbuffer[0] = 0xAB;
+    mbsbuffer[1] = 0xCD;
+    mbsbuffer[2] = 0xAB;
+    mbsbuffer[3] = 0xCD;
+    mbsbuffer[4] = 0xAB;
+    mbsbuffer[5] = 0xCD;
+    ret = wcstombs_s(&cchConverted, mbsbuffer, 10, L"hallo", 2);
+    ok_long(ret, 0);
+    ok_size_t(cchConverted, 3);
+    ok_char(mbsbuffer[5], 0xCD);
+    ok_char(mbsbuffer[4], 0xAB);
+    ok_char(mbsbuffer[3], 0xCD);
+    ok_char(mbsbuffer[2], 0);
+    ok_char(mbsbuffer[1], L'a');
+    ok_char(mbsbuffer[0], L'h');
+    ok_errno(0);
+
+    _set_errno(0);
+    cchConverted = 0xf00bac;
+    ret = wcstombs_s(&cchConverted, mbsbuffer, 10, 0, 0);
+    ok_long(ret, 0);
+    ok_size_t(cchConverted, 1);
+    ok_errno(0);
+
+    _set_errno(0);
+    cchConverted = 0xf00bac;
+    ret = wcstombs_s(&cchConverted, mbsbuffer, 10, L"hallo", 7);
+    ok_long(ret, 0);
+    ok_size_t(cchConverted, 6);
+    ok_errno(0);
+
+    _set_errno(0);
+    cchConverted = 0xf00bac;
+    ret = wcstombs_s(&cchConverted, 0, 0, L"hallo", 7);
+    ok_long(ret, 0);
+    ok_size_t(cchConverted, 6);
+    ok_errno(0);
+
+    _set_errno(0);
+    cchConverted = 0xf00bac;
+    mbsbuffer[0] = 0xAB;
+    mbsbuffer[1] = 0xCD;
+    mbsbuffer[2] = 0xAB;
+    mbsbuffer[3] = 0xCD;
+    mbsbuffer[4] = 0xAB;
+    mbsbuffer[5] = 0xCD;
+    ret = wcstombs_s(&cchConverted, mbsbuffer, 5, L"hallo", _TRUNCATE);
+    ok_long(ret, STRUNCATE);
+    ok_size_t(cchConverted, 5);
+    ok_char(mbsbuffer[5], 0xCD);
+    ok_char(mbsbuffer[4], 0);
+    ok_char(mbsbuffer[3], L'l');
+    ok_char(mbsbuffer[2], L'l');
+    ok_char(mbsbuffer[1], L'a');
+    ok_char(mbsbuffer[0], L'h');
+    ok_errno(0);
+
+    _set_errno(0);
+    cchConverted = 0xf00bac;
+    ret = wcstombs_s(&cchConverted, mbsbuffer, 10, L"hallo", -1);
+    ok_long(ret, 0);
+    ok_size_t(cchConverted, 6);
+    ok_errno(0);
+
+}