[2/2] ntdll/tests: Add test for _snprintf

Sebastian Lackner sebastian at fds-team.de
Tue Dec 17 15:00:48 CST 2013


---
 dlls/ntdll/tests/string.c |   34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

-------------- next part --------------
From 4a6e1cfa7f725eab71cda044d2ae388cd872f428 Mon Sep 17 00:00:00 2001
From: Sebastian Lackner <sebastian at fds-team.de>
Date: Mon, 16 Dec 2013 04:12:18 +0100
Subject: ntdll/tests: Add test for _snprintf

---
 dlls/ntdll/tests/string.c |   34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/dlls/ntdll/tests/string.c b/dlls/ntdll/tests/string.c
index 9349f5d..6620a3b 100644
--- a/dlls/ntdll/tests/string.c
+++ b/dlls/ntdll/tests/string.c
@@ -60,6 +60,7 @@ static LPWSTR   (WINAPIV *p_wcsrchr)(LPCWSTR, WCHAR);
 static void     (__cdecl *p_qsort)(void *,size_t,size_t, int(__cdecl *compar)(const void *, const void *) );
 static void*    (__cdecl *p_bsearch)(void *,void*,size_t,size_t, int(__cdecl *compar)(const void *, const void *) );
 
+static int      (__cdecl *p__snprintf)(char *, size_t, const char *, ...);
 
 static void InitFunctionPtrs(void)
 {
@@ -96,6 +97,9 @@ static void InitFunctionPtrs(void)
 	p_wcsrchr= (void *)GetProcAddress(hntdll, "wcsrchr");
 	p_qsort= (void *)GetProcAddress(hntdll, "qsort");
 	p_bsearch= (void *)GetProcAddress(hntdll, "bsearch");
+
+        p__snprintf = (void *)GetProcAddress(hntdll, "_snprintf");
+
     } /* if */
 }
 
@@ -1270,6 +1274,34 @@ static void test_bsearch(void)
     }
 }
 
+static void test__snprintf(void)
+{
+    const char *origstring = "XXXXXXXXXXXX";
+    const char *teststring = "hello world";
+    char buffer[32];
+    int res;
+
+    res = p__snprintf(NULL, 0, teststring);
+    ok(res == strlen(teststring), "_snprintf returned %d, expected %d.\n", res, strlen(teststring));
+
+    res = p__snprintf(NULL, 1, teststring);
+    ok(res == strlen(teststring) /* WinXP */ || res < 0 /* Vista and greater */,
+            "_snprintf returned %d, expected %d or < 0.\n", res, strlen(teststring));
+
+    res = p__snprintf(buffer, strlen(teststring) - 1, teststring);
+    ok(res < 0, "_snprintf returned %d, expected < 0.\n", res);
+
+    strcpy(buffer,  origstring);
+    res = p__snprintf(buffer, strlen(teststring), teststring);
+    ok(res == strlen(teststring), "_snprintf returned %d, expected %d.\n", res, strlen(teststring));
+    ok(!strcmp(buffer, "hello worldX"), "_snprintf returned buffer '%s', expected 'hello worldX'.\n", buffer);
+
+    strcpy(buffer, origstring);
+    res = p__snprintf(buffer, strlen(teststring) + 1, teststring);
+    ok(res == strlen(teststring), "_snprintf returned %d, expected %d.\n", res, strlen(teststring));
+    ok(!strcmp(buffer, teststring), "_snprintf returned buffer '%s', expected '%s'.\n", buffer, teststring);
+}
+
 START_TEST(string)
 {
     InitFunctionPtrs();
@@ -1304,4 +1336,6 @@ START_TEST(string)
         test_qsort();
     if (p_bsearch)
         test_bsearch();
+    if (p__snprintf)
+        test__snprintf();
 }
-- 
1.7.9.5


More information about the wine-patches mailing list