sync msvcrt winetest with wine 1.1.31
[reactos.git] / rostests / winetests / msvcrt / string.c
index 3286e91..fc2ad3c 100644 (file)
@@ -45,12 +45,12 @@ static char *buf_to_string(const unsigned char *bin, int len, int nr)
 #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)); }
 
-static void* (*pmemcpy)(void *, const void *, size_t n);
-static int* (*pmemcmp)(void *, const void *, size_t n);
-static int (*pstrcpy_s)(char *dst, size_t len, const char *src);
-static int (*pstrcat_s)(char *dst, size_t len, const char *src);
-static int (*p_mbsnbcpy_s)(unsigned char * dst, size_t size, const unsigned char * src, size_t count);
-static int (*p_wcscpy_s)(wchar_t *wcDest, size_t size, const wchar_t *wcSrc);
+static void* (__cdecl *pmemcpy)(void *, const void *, size_t n);
+static int* (__cdecl *pmemcmp)(void *, const void *, size_t n);
+static int (__cdecl *pstrcpy_s)(char *dst, size_t len, const char *src);
+static int (__cdecl *pstrcat_s)(char *dst, size_t len, const char *src);
+static int (__cdecl *p_mbsnbcpy_s)(unsigned char * dst, size_t size, const unsigned char * src, size_t count);
+static int (__cdecl *p_wcscpy_s)(wchar_t *wcDest, size_t size, const wchar_t *wcSrc);
 static int *p__mb_cur_max;
 static unsigned char *p_mbctype;
 
@@ -663,6 +663,46 @@ static void test_strtok(void)
     }
 }
 
+static void test_strtol(void)
+{
+    char* e;
+    LONG l;
+    ULONG ul;
+
+    /* errno is only set in case of error, so reset errno to EBADF to check for errno modification */
+    /* errno is modified on W2K8+ */
+    errno = EBADF;
+    l = strtol("-1234", &e, 0);
+    ok(l==-1234, "wrong value %d\n", l);
+    ok(errno == EBADF || broken(errno == 0), "wrong errno %d\n", errno);
+    errno = EBADF;
+    ul = strtoul("1234", &e, 0);
+    ok(ul==1234, "wrong value %u\n", ul);
+    ok(errno == EBADF || broken(errno == 0), "wrong errno %d\n", errno);
+
+    errno = EBADF;
+    l = strtol("2147483647L", &e, 0);
+    ok(l==2147483647, "wrong value %d\n", l);
+    ok(errno == EBADF || broken(errno == 0), "wrong errno %d\n", errno);
+    errno = EBADF;
+    l = strtol("-2147483648L", &e, 0);
+    ok(l==-2147483647L - 1, "wrong value %d\n", l);
+    ok(errno == EBADF || broken(errno == 0), "wrong errno %d\n", errno);
+    errno = EBADF;
+    ul = strtoul("4294967295UL", &e, 0);
+    ok(ul==4294967295ul, "wrong value %u\n", ul);
+    ok(errno == EBADF || broken(errno == 0), "wrong errno %d\n", errno);
+
+    errno = 0;
+    l = strtol("9223372036854775807L", &e, 0);
+    ok(l==2147483647, "wrong value %d\n", l);
+    ok(errno == ERANGE, "wrong errno %d\n", errno);
+    errno = 0;
+    ul = strtoul("9223372036854775807L", &e, 0);
+    ok(ul==4294967295ul, "wrong value %u\n", ul);
+    ok(errno == ERANGE, "wrong errno %d\n", errno);
+}
+
 START_TEST(string)
 {
     char mem[100];
@@ -706,4 +746,5 @@ START_TEST(string)
     test_mbcjisjms();
     test_strtok();
     test_wcscpy_s();
+    test_strtol();
 }