Alexander Scott-Johns : msvcrt/test: Add some simple _vsnwprintf_s tests.

Alexandre Julliard julliard at winehq.org
Mon Jun 7 10:02:28 CDT 2010


Module: wine
Branch: master
Commit: d313c0b98285fa43fd679dc4d6f9d3d1ab60eafd
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=d313c0b98285fa43fd679dc4d6f9d3d1ab60eafd

Author: Alexander Scott-Johns <alexander.scott.johns at googlemail.com>
Date:   Mon Jun  7 03:04:53 2010 +0100

msvcrt/test: Add some simple _vsnwprintf_s tests.

---

 dlls/msvcrt/tests/printf.c |   61 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 61 insertions(+), 0 deletions(-)

diff --git a/dlls/msvcrt/tests/printf.c b/dlls/msvcrt/tests/printf.c
index eaf248b..b48db51 100644
--- a/dlls/msvcrt/tests/printf.c
+++ b/dlls/msvcrt/tests/printf.c
@@ -812,6 +812,9 @@ static void test_vsnwprintf(void)
 
 static int (__cdecl *p__vscprintf)(const char *format, __ms_va_list valist);
 static int (__cdecl *p__vscwprintf)(const wchar_t *format, __ms_va_list valist);
+static int (__cdecl *p__vsnwprintf_s)(wchar_t *str, size_t sizeOfBuffer,
+                                      size_t count, const wchar_t *format,
+                                      __ms_va_list valist);
 
 static int __cdecl _vscprintf_wrapper(const char *format, ...)
 {
@@ -852,6 +855,58 @@ static void test_vscwprintf(void)
     ok( ret == 8, "got %d expected 8\n", ret );
 }
 
+static int __cdecl _vsnwprintf_s_wrapper(wchar_t *str, size_t sizeOfBuffer,
+                                 size_t count, const wchar_t *format, ...)
+{
+    int ret;
+    __ms_va_list valist;
+    __ms_va_start(valist, format);
+    ret = p__vsnwprintf_s(str, sizeOfBuffer, count, format, valist);
+    __ms_va_end(valist);
+    return ret;
+}
+
+static void test_vsnwprintf_s(void)
+{
+    const wchar_t format[] = { 'A','B','%','u','C',0 };
+    const wchar_t out7[] = { 'A','B','1','2','3','C',0 };
+    const wchar_t out6[] = { 'A','B','1','2','3',0 };
+    const wchar_t out2[] = { 'A',0 };
+    const wchar_t out1[] = { 0 };
+    wchar_t buffer[14] = { 0 };
+    int exp, got;
+
+    /* Enough room. */
+    exp = wcslen(out7);
+
+    got = _vsnwprintf_s_wrapper(buffer, 14, _TRUNCATE, format, 123);
+    ok( exp == got, "length wrong, expect=%d, got=%d\n", exp, got);
+    ok( !wcscmp(out7, buffer), "buffer wrong, got=%s\n", wine_dbgstr_w(buffer));
+
+    got = _vsnwprintf_s_wrapper(buffer, 12, _TRUNCATE, format, 123);
+    ok( exp == got, "length wrong, expect=%d, got=%d\n", exp, got);
+    ok( !wcscmp(out7, buffer), "buffer wrong, got=%s\n", wine_dbgstr_w(buffer));
+
+    got = _vsnwprintf_s_wrapper(buffer, 7, _TRUNCATE, format, 123);
+    ok( exp == got, "length wrong, expect=%d, got=%d\n", exp, got);
+    ok( !wcscmp(out7, buffer), "buffer wrong, got=%s\n", wine_dbgstr_w(buffer));
+
+    /* Not enough room. */
+    exp = -1;
+
+    got = _vsnwprintf_s_wrapper(buffer, 6, _TRUNCATE, format, 123);
+    ok( exp == got, "length wrong, expect=%d, got=%d\n", exp, got);
+    ok( !wcscmp(out6, buffer), "buffer wrong, got=%s\n", wine_dbgstr_w(buffer));
+
+    got = _vsnwprintf_s_wrapper(buffer, 2, _TRUNCATE, format, 123);
+    ok( exp == got, "length wrong, expect=%d, got=%d\n", exp, got);
+    ok( !wcscmp(out2, buffer), "buffer wrong, got=%s\n", wine_dbgstr_w(buffer));
+
+    got = _vsnwprintf_s_wrapper(buffer, 1, _TRUNCATE, format, 123);
+    ok( exp == got, "length wrong, expect=%d, got=%d\n", exp, got);
+    ok( !wcscmp(out1, buffer), "buffer wrong, got=%s\n", wine_dbgstr_w(buffer));
+}
+
 START_TEST(printf)
 {
     test_sprintf();
@@ -863,6 +918,7 @@ START_TEST(printf)
 
     p__vscprintf = (void *)GetProcAddress(GetModuleHandle("msvcrt.dll"), "_vscprintf");
     p__vscwprintf = (void *)GetProcAddress(GetModuleHandle("msvcrt.dll"), "_vscwprintf");
+    p__vsnwprintf_s = (void *)GetProcAddress(GetModuleHandle("msvcrt.dll"), "_vsnwprintf_s");
 
     if (p__vscprintf)
         test_vscprintf();
@@ -873,4 +929,9 @@ START_TEST(printf)
         test_vscwprintf();
     else
         win_skip("_vscwprintf not available\n");
+
+    if (p__vsnwprintf_s)
+        test_vsnwprintf_s();
+    else
+        win_skip("_vsnwprintf_s not available\n");
 }




More information about the wine-cvs mailing list