msvcrt/tests: Move function pointer initialization code in printf.c into separate init function.

Alexander Scott-Johns alexander.scott.johns at googlemail.com
Tue Jun 8 22:00:44 CDT 2010


Makes the file more consistent with other tests.

This *might* fix the weird win_skip failure bug
(http://bugs.winehq.org/show_bug.cgi?id=23095), but only if there's a
bug in the compiler or something like that.
-------------- next part --------------
From 53c1204b9cddc5fc3680dc630efe13544f8015c2 Mon Sep 17 00:00:00 2001
From: Alexander Scott-Johns <alexander.scott.johns at googlemail.com>
Date: Tue, 8 Jun 2010 19:20:15 +0100
Subject: msvcrt/tests: Move function pointer initialization code in printf.c into separate init function.

---
 dlls/msvcrt/tests/printf.c |   63 ++++++++++++++++++++++++++-----------------
 1 files changed, 38 insertions(+), 25 deletions(-)

diff --git a/dlls/msvcrt/tests/printf.c b/dlls/msvcrt/tests/printf.c
index b48db51..19e21f9 100644
--- a/dlls/msvcrt/tests/printf.c
+++ b/dlls/msvcrt/tests/printf.c
@@ -33,6 +33,21 @@
 
 #include "wine/test.h"
 
+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 void init( void )
+{
+    HMODULE hmod = GetModuleHandleA("msvcrt.dll");
+
+    p__vscprintf = (void *)GetProcAddress(hmod, "_vscprintf");
+    p__vscwprintf = (void *)GetProcAddress(hmod, "_vscwprintf");
+    p__vsnwprintf_s = (void *)GetProcAddress(hmod, "_vsnwprintf_s");
+}
+
 static void test_sprintf( void )
 {
     char buffer[100];
@@ -810,12 +825,6 @@ static void test_vsnwprintf(void)
     ok( !strcmp(buf, "onetwothree"), "got %s expected 'onetwothree'\n", buf );
 }
 
-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, ...)
 {
     int ret;
@@ -830,6 +839,12 @@ static void test_vscprintf(void)
 {
     int ret;
 
+    if (!p__vscprintf)
+    {
+       win_skip("_vscprintf not available\n");
+       return;
+    }
+
     ret = _vscprintf_wrapper( "%s %d", "number", 1 );
     ok( ret == 8, "got %d expected 8\n", ret );
 }
@@ -851,6 +866,12 @@ static void test_vscwprintf(void)
 
     int ret;
 
+    if (!p__vscwprintf)
+    {
+        win_skip("_vscwprintf not available\n");
+        return;
+    }
+
     ret = _vscwprintf_wrapper( format, number, 1 );
     ok( ret == 8, "got %d expected 8\n", ret );
 }
@@ -876,6 +897,12 @@ static void test_vsnwprintf_s(void)
     wchar_t buffer[14] = { 0 };
     int exp, got;
 
+    if (!p__vsnwprintf_s)
+    {
+        win_skip("_vsnwprintf_s not available\n");
+        return;
+    }
+
     /* Enough room. */
     exp = wcslen(out7);
 
@@ -909,29 +936,15 @@ static void test_vsnwprintf_s(void)
 
 START_TEST(printf)
 {
+    init();
+
     test_sprintf();
     test_swprintf();
     test_snprintf();
     test_fcvt();
     test_xcvt();
     test_vsnwprintf();
-
-    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();
-    else
-        win_skip("_vscprintf not available\n");
-
-    if (p__vscwprintf)
-        test_vscwprintf();
-    else
-        win_skip("_vscwprintf not available\n");
-
-    if (p__vsnwprintf_s)
-        test_vsnwprintf_s();
-    else
-        win_skip("_vsnwprintf_s not available\n");
+    test_vscprintf();
+    test_vscwprintf();
+    test_vsnwprintf_s();
 }
-- 
1.6.0.4


More information about the wine-patches mailing list