Module: wine Branch: master Commit: 09bb38d12bbbe5fbeede2e29c8893877d853d792 URL: http://source.winehq.org/git/wine.git/?a=commit;h=09bb38d12bbbe5fbeede2e29c8...
Author: Sebastian Lackner sebastian@fds-team.de Date: Mon Dec 16 04:12:18 2013 +0100
ntdll/tests: Add test for _snprintf.
---
dlls/ntdll/tests/string.c | 33 +++++++++++++++++++++++++++++++++ 1 files changed, 33 insertions(+), 0 deletions(-)
diff --git a/dlls/ntdll/tests/string.c b/dlls/ntdll/tests/string.c index 9349f5d..7b56691 100644 --- a/dlls/ntdll/tests/string.c +++ b/dlls/ntdll/tests/string.c @@ -59,6 +59,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,8 @@ 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 +1273,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 == lstrlenA(teststring), "_snprintf returned %d, expected %d.\n", res, lstrlenA(teststring)); + + res = p__snprintf(NULL, 1, teststring); + ok(res == lstrlenA(teststring) /* WinXP */ || res < 0 /* Vista and greater */, + "_snprintf returned %d, expected %d or < 0.\n", res, lstrlenA(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 == lstrlenA(teststring), "_snprintf returned %d, expected %d.\n", res, lstrlenA(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 == lstrlenA(teststring), "_snprintf returned %d, expected %d.\n", res, lstrlenA(teststring)); + ok(!strcmp(buffer, teststring), "_snprintf returned buffer '%s', expected '%s'.\n", buffer, teststring); +} + START_TEST(string) { InitFunctionPtrs(); @@ -1304,4 +1335,6 @@ START_TEST(string) test_qsort(); if (p_bsearch) test_bsearch(); + if (p__snprintf) + test__snprintf(); }