[6/7] msvcrt/test: Add some simple _vsnwprintf_s tests.

Alexander Scott-Johns alexander.scott.johns at googlemail.com
Sun Jun 6 11:56:07 CDT 2010


-------------- next part --------------
From 7748a91200bcb9f2a63038e104e6066bebb52cd2 Mon Sep 17 00:00:00 2001
From: Alexander Scott-Johns <alexander.scott.johns at googlemail.com>
Date: Sun, 6 Jun 2010 16:33:48 +0100
Subject: msvcrt/test: Add some simple _vsnwprintf_s tests.

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

diff --git a/dlls/msvcrt/tests/printf.c b/dlls/msvcrt/tests/printf.c
index eaf248b..d27a04e 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,62 @@ 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));
+
+  todo_wine {
+    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);
+  todo_wine
+    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);
+  todo_wine
+    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 +922,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 +933,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");
 }
-- 
1.6.0.4


More information about the wine-patches mailing list