[PATCH 2/2] Added ui64tow_s tests for msvcrt (The function was moved from msvcr90 to msvcrt so that msvcr80, 90 and 100 all would benefit).

Arno Teigseth arnotixe at gmail.com
Tue Dec 28 21:53:48 CST 2010


---
 dlls/msvcrt/tests/string.c |  129 +++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 127 insertions(+), 2 deletions(-)

diff --git a/dlls/msvcrt/tests/string.c b/dlls/msvcrt/tests/string.c
index 2a5d4fc..cde94c0 100644
--- a/dlls/msvcrt/tests/string.c
+++ b/dlls/msvcrt/tests/string.c
@@ -29,6 +29,11 @@
 #include <errno.h>
 #include <limits.h>
 
+
+/* copied from msvcr90 tests */
+DEFINE_EXPECT(invalid_parameter_handler);
+static _invalid_parameter_handler (__cdecl *p_set_invalid_parameter_handler)(_invalid_parameter_handler);
+
 static char *buf_to_string(const unsigned char *bin, int len, int nr)
 {
     static char buf[2][1024];
@@ -47,9 +52,16 @@ static void __cdecl test_invalid_parameter_handler(const wchar_t *expression,
         const wchar_t *function, const wchar_t *file,
         unsigned line, uintptr_t arg)
 {
-    /* we just ignore handler calls */
+    /* we USED TO just ignore handler calls */
+    CHECK_EXPECT(invalid_parameter_handler);
+    ok(expression == NULL, "expression is not NULL\n");
+    ok(function == NULL, "function is not NULL\n");
+    ok(file == NULL, "file is not NULL\n");
+    ok(line == 0, "line = %u\n", line);
+    ok(arg == 0, "arg = %lx\n", (UINT_PTR)arg);
 }
 
+
 #define expect_eq(expr, value, type, format) { type ret = (expr); ok((value) == ret, #expr " expected " format " got " format "\n", value, ret); }
 #define expect_bin(buf, value, len) { ok(memcmp((buf), value, len) == 0, "Binary buffer mismatch - expected %s, got %s\n", buf_to_string((unsigned char *)value, len, 1), buf_to_string((buf), len, 0)); }
 
@@ -69,6 +81,7 @@ static int (__cdecl *pwcstombs_s)(size_t*,char*,size_t,const wchar_t*,size_t);
 static int (__cdecl *pmbstowcs_s)(size_t*,wchar_t*,size_t,const char*,size_t);
 static errno_t (__cdecl *p_gcvt_s)(char*,size_t,double,int);
 static errno_t (__cdecl *p_itoa_s)(int,char*,size_t,int);
+static errno_t (__cdecl *p_ui64tow_s)(int,char*,size_t,int);
 static errno_t (__cdecl *p_strlwr_s)(char*,size_t);
 static errno_t (__cdecl *p_ultoa_s)(__msvcrt_ulong,char*,size_t,int);
 static int *p__mb_cur_max;
@@ -1389,6 +1402,111 @@ static void test__itoa_s(void)
                 "Cannot reset invalid parameter handler\n");
 }
 
+static void test__ui64tow_s(void)
+{
+
+    /* mostly copied from _itoa_s tests:
+       _itoa_s (on msvcr90) doesn't set errno (in case of errors) while msvcrt does
+     * as we always set errno in our msvcrt implementation, don't test here that errno
+     * isn't changed
+     */
+
+    errno_t ret;
+    char buffer[33];
+
+    if (!p_ui64tow_s)
+    {
+        win_skip("Skipping _ui64tow_s tests\n");
+        return;
+    }
+
+    if(!p_set_invalid_parameter_handler) {
+        win_skip("_set_invalid_parameter_handler not found\n");
+        return;
+    }
+
+    SET_EXPECT(invalid_parameter_handler);
+    ret = p_ui64tow_s(0, NULL, 0, 0);
+    ok(ret == EINVAL, "Expected _ui64tow_s to return EINVAL, got %d\n", ret);
+    CHECK_CALLED(invalid_parameter_handler);
+
+    memset(buffer, 'X', sizeof(buffer));
+    SET_EXPECT(invalid_parameter_handler);
+    ret = p_ui64tow_s(0, buffer, 0, 0);
+    ok(ret == EINVAL, "Expected _ui64tow_s to return EINVAL, got %d\n", ret);
+    ok(buffer[0] == 'X', "Expected the output buffer to be untouched\n");
+    CHECK_CALLED(invalid_parameter_handler);
+
+    memset(buffer, 'X', sizeof(buffer));
+    SET_EXPECT(invalid_parameter_handler);
+    ret = p_ui64tow_s(0, buffer, sizeof(buffer), 0);
+    ok(ret == EINVAL, "Expected _ui64tow_s to return EINVAL, got %d\n", ret);
+    ok(buffer[0] == '\0', "Expected the output buffer to be null terminated\n");
+    CHECK_CALLED(invalid_parameter_handler);
+
+    memset(buffer, 'X', sizeof(buffer));
+    SET_EXPECT(invalid_parameter_handler);
+    ret = p_ui64tow_s(0, buffer, sizeof(buffer), 64);
+    ok(ret == EINVAL, "Expected _ui64tow_s to return EINVAL, got %d\n", ret);
+    ok(buffer[0] == '\0', "Expected the output buffer to be null terminated\n");
+    CHECK_CALLED(invalid_parameter_handler);
+
+    memset(buffer, 'X', sizeof(buffer));
+    SET_EXPECT(invalid_parameter_handler);
+    ret = p_ui64tow_s(12345678, buffer, 4, 10);
+    ok(ret == ERANGE, "Expected _ui64tow_s to return ERANGE, got %d\n", ret);
+    ok(!memcmp(buffer, "\000765", 4),
+       "Expected the output buffer to be null terminated with truncated output\n");
+    CHECK_CALLED(invalid_parameter_handler);
+
+    memset(buffer, 'X', sizeof(buffer));
+    SET_EXPECT(invalid_parameter_handler);
+    ret = p_ui64tow_s(12345678, buffer, 8, 10);
+    ok(ret == ERANGE, "Expected _ui64tow_s to return ERANGE, got %d\n", ret);
+    ok(!memcmp(buffer, "\0007654321", 8),
+       "Expected the output buffer to be null terminated with truncated output\n");
+    CHECK_CALLED(invalid_parameter_handler);
+
+    memset(buffer, 'X', sizeof(buffer));
+    SET_EXPECT(invalid_parameter_handler);
+    ret = p_ui64tow_s(-12345678, buffer, 9, 10);
+    ok(ret == ERANGE, "Expected _ui64tow_s to return ERANGE, got %d\n", ret);
+    ok(!memcmp(buffer, "\00087654321", 9),
+       "Expected the output buffer to be null terminated with truncated output\n");
+    CHECK_CALLED(invalid_parameter_handler);
+
+    ret = p_ui64tow_s(12345678, buffer, 9, 10);
+    ok(ret == 0, "Expected _ui64tow_s to return 0, got %d\n", ret);
+    ok(!strcmp(buffer, "12345678"),
+       "Expected output buffer string to be \"12345678\", got \"%s\"\n",
+       buffer);
+
+    ret = p_ui64tow_s(43690, buffer, sizeof(buffer), 2);
+    ok(ret == 0, "Expected _ui64tow_s to return 0, got %d\n", ret);
+    ok(!strcmp(buffer, "1010101010101010"),
+       "Expected output buffer string to be \"1010101010101010\", got \"%s\"\n",
+       buffer);
+
+    ret = p_ui64tow_s(1092009, buffer, sizeof(buffer), 36);
+    ok(ret == 0, "Expected _ui64tow_s to return 0, got %d\n", ret);
+    ok(!strcmp(buffer, "nell"),
+       "Expected output buffer string to be \"nell\", got \"%s\"\n",
+       buffer);
+
+    ret = p_ui64tow_s(5704, buffer, sizeof(buffer), 18);
+    ok(ret == 0, "Expected _ui64tow_s to return 0, got %d\n", ret);
+    ok(!strcmp(buffer, "hag"),
+       "Expected output buffer string to be \"hag\", got \"%s\"\n",
+       buffer);
+
+    ret = p_ui64tow_s(-12345678, buffer, sizeof(buffer), 10);
+    ok(ret == 0, "Expected _ui64tow_s to return 0, got %d\n", ret);
+    ok(!strcmp(buffer, "-12345678"),
+       "Expected output buffer string to be \"-12345678\", got \"%s\"\n",
+       buffer);
+}
+
+
 static void test__strlwr_s(void)
 {
     errno_t ret;
@@ -1726,9 +1844,15 @@ START_TEST(string)
     pwcstombs_s = (void *)GetProcAddress(hMsvcrt, "wcstombs_s");
     p_gcvt_s = (void *)GetProcAddress(hMsvcrt, "_gcvt_s");
     p_itoa_s = (void *)GetProcAddress(hMsvcrt, "_itoa_s");
+    p_ui64tow_s = (void *)GetProcAddress(hcrt, "_ui64tow_s");
     p_strlwr_s = (void *)GetProcAddress(hMsvcrt, "_strlwr_s");
     p_ultoa_s = (void *)GetProcAddress(hMsvcrt, "_ultoa_s");
-    p_set_invalid_parameter_handler = (void *) GetProcAddress(hMsvcrt, "_set_invalid_parameter_handler");
+/*  used to be
+    p_set_invalid_parameter_handler = (void *) GetProcAddress(hMsvcrt, "_set_invalid_parameter_handler"); */
+    p_set_invalid_parameter_handler = (void *) GetProcAddress(hcrt, "_set_invalid_parameter_handler");
+    if(p_set_invalid_parameter_handler)
+        ok(p_set_invalid_parameter_handler(test_invalid_parameter_handler) == NULL,
+                "Invalid parameter handler was already set\n");
 
     /* MSVCRT memcpy behaves like memmove for overlapping moves,
        MFC42 CString::Insert seems to rely on that behaviour */
@@ -1764,6 +1888,7 @@ START_TEST(string)
     test_mbstowcs();
     test_gcvt();
     test__itoa_s();
+    test__ui64tow_s();
     test__strlwr_s();
     test_wcsncat_s();
     test__mbsnbcat_s();
-- 
1.6.3.3

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
URL: <http://www.winehq.org/pipermail/wine-patches/attachments/20101228/07d130e3/attachment-0001.pgp>


More information about the wine-patches mailing list