[MSVCRT_WINETEST]
[reactos.git] / rostests / winetests / msvcrt / string.c
index a36d3b0..a7b3404 100644 (file)
@@ -45,12 +45,15 @@ 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 (__cdecl *p_wcsupr_s)(wchar_t *str, size_t size);
+static int *p__mb_cur_max;
+static unsigned char *p_mbctype;
 
 #define SETNOFAIL(x,y) x = (void*)GetProcAddress(hMsvcrt,y)
 #define SET(x,y) SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y)
@@ -62,13 +65,13 @@ static void test_swab( void ) {
     char expected1[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ@#";
     char expected2[] = "ABCDEFGHIJKLMNOPQRSTUVWX$";
     char expected3[] = "$";
-
+    
     char from[30];
     char to[30];
-
+    
     int testsize;
-
-    /* Test 1 - normal even case */
+    
+    /* Test 1 - normal even case */                               
     memset(to,'$', sizeof(to));
     memset(from,'@', sizeof(from));
     testsize = 26;
@@ -76,7 +79,7 @@ static void test_swab( void ) {
     _swab( from, to, testsize );
     ok(memcmp(to,expected1,testsize) == 0, "Testing even size %d returned '%*.*s'\n", testsize, testsize, testsize, to);
 
-    /* Test 2 - uneven case  */
+    /* Test 2 - uneven case  */                               
     memset(to,'$', sizeof(to));
     memset(from,'@', sizeof(from));
     testsize = 25;
@@ -84,7 +87,7 @@ static void test_swab( void ) {
     _swab( from, to, testsize );
     ok(memcmp(to,expected2,testsize) == 0, "Testing odd size %d returned '%*.*s'\n", testsize, testsize, testsize, to);
 
-    /* Test 3 - from = to */
+    /* Test 3 - from = to */                               
     memset(to,'$', sizeof(to));
     memset(from,'@', sizeof(from));
     testsize = 26;
@@ -92,7 +95,7 @@ static void test_swab( void ) {
     _swab( to, to, testsize );
     ok(memcmp(to,expected1,testsize) == 0, "Testing overlapped size %d returned '%*.*s'\n", testsize, testsize, testsize, to);
 
-    /* Test 4 - 1 bytes */
+    /* Test 4 - 1 bytes */                               
     memset(to,'$', sizeof(to));
     memset(from,'@', sizeof(from));
     testsize = 1;
@@ -111,14 +114,14 @@ static void test_codepage(int cp)
 
     ok(_setmbcp(cp) == 0, "Couldn't set mbcp\n");
 
-    prev = _mbctype[0];
+    prev = p_mbctype[0];
     printf("static int result_cp_%d_mbctype[] = { ", cp);
     for (i = 1; i < 257; i++)
     {
-        if (_mbctype[i] != prev)
+        if (p_mbctype[i] != prev)
         {
             printf("0x%x,%d, ", prev, count);
-            prev = _mbctype[i];
+            prev = p_mbctype[i];
             count = 1;
         }
         else
@@ -127,7 +130,7 @@ static void test_codepage(int cp)
     printf("0x%x,%d };\n", prev, count);
 }
 
-#define test_codepage_todo(cp, todo) test_codepage(cp)
+#else
 
 /* RLE-encoded mbctype tables for given codepages */
 static int result_cp_932_mbctype[] = { 0x0,65, 0x8,1, 0x18,26, 0x8,6, 0x28,26, 0x8,4,
@@ -139,10 +142,7 @@ static int result_cp_949_mbctype[] = { 0x0,66, 0x18,26, 0x8,6, 0x28,26, 0x8,6, 0
 static int result_cp_950_mbctype[] = { 0x0,65, 0x8,1, 0x18,26, 0x8,6, 0x28,26, 0x8,4,
   0x0,2, 0x4,32, 0xc,94, 0,1 };
 
-static int todo_none[] = { -2 };
-static int todo_cp_932[] = { 254, -2 };
-
-void test_cp_table(int cp, int *result, int *todo)
+static void test_cp_table(int cp, int *result)
 {
     int i;
     int count = 0;
@@ -156,26 +156,18 @@ void test_cp_table(int cp, int *result, int *todo)
             count = result[1];
             result += 2;
         }
-       if (i == *todo + 1)
-       {
-            todo_wine ok(_mbctype[i] == curr, "CP%d: Mismatch in ctype for character %d - %d instead of %d\n", cp, i-1, _mbctype[i], curr);
-            todo++;
-       }
-       else
-            ok(_mbctype[i] == curr, "CP%d: Mismatch in ctype for character %d - %d instead of %d\n", cp, i-1, _mbctype[i], curr);
+        ok(p_mbctype[i] == curr, "CP%d: Mismatch in ctype for character %d - %d instead of %d\n", cp, i-1, p_mbctype[i], curr);
         count--;
     }
 }
 
-#define test_codepage(num) test_cp_table(num, result_cp_##num##_mbctype, todo_none);
-#define test_codepage_todo(num, todo) test_cp_table(num, result_cp_##num##_mbctype, todo);
+#define test_codepage(num) test_cp_table(num, result_cp_##num##_mbctype);
 
 #endif
 
-
 static void test_mbcp(void)
 {
-    int mb_orig_max = __mb_cur_max;
+    int mb_orig_max = *p__mb_cur_max;
     int curr_mbcp = _getmbcp();
     unsigned char *mbstring = (unsigned char *)"\xb0\xb1\xb2 \xb3\xb4 \xb5"; /* incorrect string */
     unsigned char *mbstring2 = (unsigned char *)"\xb0\xb1\xb2\xb3Q\xb4\xb5"; /* correct string */
@@ -189,26 +181,26 @@ static void test_mbcp(void)
      * between versions of Windows. Also Windows 9x seems to ignore the codepage and always uses
      * CP1252 (or the ACP?) so we test only a few ASCII characters */
     _setmbcp(1252);
-    expect_eq(_mbctype[10], 0, char, "%x");
-    expect_eq(_mbctype[50], 0, char, "%x");
-    expect_eq(_mbctype[66], _SBUP, char, "%x");
-    expect_eq(_mbctype[100], _SBLOW, char, "%x");
-    expect_eq(_mbctype[128], 0, char, "%x");
+    expect_eq(p_mbctype[10], 0, char, "%x");
+    expect_eq(p_mbctype[50], 0, char, "%x");
+    expect_eq(p_mbctype[66], _SBUP, char, "%x");
+    expect_eq(p_mbctype[100], _SBLOW, char, "%x");
+    expect_eq(p_mbctype[128], 0, char, "%x");
     _setmbcp(1250);
-    expect_eq(_mbctype[10], 0, char, "%x");
-    expect_eq(_mbctype[50], 0, char, "%x");
-    expect_eq(_mbctype[66], _SBUP, char, "%x");
-    expect_eq(_mbctype[100], _SBLOW, char, "%x");
-    expect_eq(_mbctype[128], 0, char, "%x");
+    expect_eq(p_mbctype[10], 0, char, "%x");
+    expect_eq(p_mbctype[50], 0, char, "%x");
+    expect_eq(p_mbctype[66], _SBUP, char, "%x");
+    expect_eq(p_mbctype[100], _SBLOW, char, "%x");
+    expect_eq(p_mbctype[128], 0, char, "%x");
 
     /* double byte code pages */
-    //test_codepage_todo(932, todo_cp_932);
-    //test_codepage(936);
-    //test_codepage(949);
-    //test_codepage(950);
+    test_codepage(932);
+    test_codepage(936);
+    test_codepage(949);
+    test_codepage(950);
 
     _setmbcp(936);
-    ok(__mb_cur_max == mb_orig_max, "__mb_cur_max shouldn't be updated (is %d != %d)\n", __mb_cur_max, mb_orig_max);
+    ok(*p__mb_cur_max == mb_orig_max, "__mb_cur_max shouldn't be updated (is %d != %d)\n", *p__mb_cur_max, mb_orig_max);
     ok(_ismbblead('\354'), "\354 should be a lead byte\n");
     ok(_ismbblead(' ') == FALSE, "' ' should not be a lead byte\n");
     ok(_ismbblead(0x1234b0), "0x1234b0 should not be a lead byte\n");
@@ -345,7 +337,7 @@ static void test_mbcp(void)
      * we hope the current locale to be SBCS because setlocale(LC_ALL, ".1252") seems not to work yet
      * (as of Wine 0.9.43)
      */
-    if (__mb_cur_max == 1)
+    if (*p__mb_cur_max == 1)
     {
         expect_eq(mblen((char *)mbstring, 3), 1, int, "%x");
         expect_eq(_mbstrlen((char *)mbstring2), 7, int, "%d");
@@ -353,6 +345,29 @@ static void test_mbcp(void)
     else
         skip("Current locale has double-byte charset - could leave to false positives\n");
 
+    _setmbcp(1361);
+    expect_eq(_ismbblead(0x80), 0, int, "%d");
+    todo_wine {
+      expect_eq(_ismbblead(0x81), 1, int, "%d");
+      expect_eq(_ismbblead(0x83), 1, int, "%d");
+    }
+    expect_eq(_ismbblead(0x84), 1, int, "%d");
+    expect_eq(_ismbblead(0xd3), 1, int, "%d");
+    expect_eq(_ismbblead(0xd7), 0, int, "%d");
+    todo_wine {
+      expect_eq(_ismbblead(0xd8), 1, int, "%d");
+    }
+    expect_eq(_ismbblead(0xd9), 1, int, "%d");
+
+    expect_eq(_ismbbtrail(0x30), 0, int, "%d");
+    expect_eq(_ismbbtrail(0x31), 1, int, "%d");
+    expect_eq(_ismbbtrail(0x7e), 1, int, "%d");
+    expect_eq(_ismbbtrail(0x7f), 0, int, "%d");
+    expect_eq(_ismbbtrail(0x80), 0, int, "%d");
+    expect_eq(_ismbbtrail(0x81), 1, int, "%d");
+    expect_eq(_ismbbtrail(0xfe), 1, int, "%d");
+    expect_eq(_ismbbtrail(0xff), 0, int, "%d");
+
     _setmbcp(curr_mbcp);
 }
 
@@ -606,6 +621,296 @@ static void test_wcscpy_s(void)
     ok(szDestShort[0] == 0, "szDestShort[0] not 0\n");
 }
 
+static void test__wcsupr_s(void)
+{
+    static const WCHAR mixedString[] = {'M', 'i', 'X', 'e', 'D', 'l', 'o', 'w',
+                                        'e', 'r', 'U', 'P', 'P', 'E', 'R', 0};
+    static const WCHAR expectedString[] = {'M', 'I', 'X', 'E', 'D', 'L', 'O',
+                                           'W', 'E', 'R', 'U', 'P', 'P', 'E',
+                                           'R', 0};
+    WCHAR testBuffer[2*sizeof(mixedString)/sizeof(WCHAR)];
+    int ret;
+
+    if (!p_wcsupr_s)
+    {
+        win_skip("_wcsupr_s not found\n");
+        return;
+    }
+
+    /* Test NULL input string and invalid size. */
+    errno = EBADF;
+    ret = p_wcsupr_s(NULL, 0);
+    ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
+    ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
+
+    /* Test NULL input string and valid size. */
+    errno = EBADF;
+    ret = p_wcsupr_s(NULL, sizeof(testBuffer)/sizeof(WCHAR));
+    ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
+    ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
+
+    /* Test empty string with zero size. */
+    errno = EBADF;
+    testBuffer[0] = '\0';
+    ret = p_wcsupr_s(testBuffer, 0);
+    ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
+    ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
+    ok(testBuffer[0] == '\0', "Expected the buffer to be unchanged\n");
+
+    /* Test empty string with size of one. */
+    testBuffer[0] = '\0';
+    ret = p_wcsupr_s(testBuffer, 1);
+    ok(ret == 0, "Expected _wcsupr_s to succeed, got %d\n", ret);
+    ok(testBuffer[0] == '\0', "Expected the buffer to be unchanged\n");
+
+    /* Test one-byte buffer with zero size. */
+    errno = EBADF;
+    testBuffer[0] = 'x';
+    ret = p_wcsupr_s(testBuffer, 0);
+    ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
+    ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
+    ok(testBuffer[0] == '\0', "Expected the first buffer character to be null\n");
+
+    /* Test one-byte buffer with size of one. */
+    errno = EBADF;
+    testBuffer[0] = 'x';
+    ret = p_wcsupr_s(testBuffer, 1);
+    ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
+    ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
+    ok(testBuffer[0] == '\0', "Expected the first buffer character to be null\n");
+
+    /* Test invalid size. */
+    wcscpy(testBuffer, mixedString);
+    errno = EBADF;
+    ret = p_wcsupr_s(testBuffer, 0);
+    ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
+    ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
+    ok(testBuffer[0] == '\0', "Expected the first buffer character to be null\n");
+
+    /* Test normal string uppercasing. */
+    wcscpy(testBuffer, mixedString);
+    ret = p_wcsupr_s(testBuffer, sizeof(mixedString)/sizeof(WCHAR));
+    ok(ret == 0, "Expected _wcsupr_s to succeed, got %d\n", ret);
+    ok(!wcscmp(testBuffer, expectedString), "Expected the string to be fully upper-case\n");
+
+    /* Test uppercasing with a shorter buffer size count. */
+    wcscpy(testBuffer, mixedString);
+    errno = EBADF;
+    ret = p_wcsupr_s(testBuffer, sizeof(mixedString)/sizeof(WCHAR) - 1);
+    ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
+    ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
+    ok(testBuffer[0] == '\0', "Expected the first buffer character to be null\n");
+
+    /* Test uppercasing with a longer buffer size count. */
+    wcscpy(testBuffer, mixedString);
+    ret = p_wcsupr_s(testBuffer, sizeof(testBuffer)/sizeof(WCHAR));
+    ok(ret == 0, "Expected _wcsupr_s to succeed, got %d\n", ret);
+    ok(!wcscmp(testBuffer, expectedString), "Expected the string to be fully upper-case\n");
+}
+
+static void test_mbcjisjms(void)
+{
+    /* List of value-pairs to test. The test assumes the last pair to be {0, ..} */
+    unsigned int jisjms[][2] = { {0x2020, 0}, {0x2021, 0}, {0x2120, 0}, {0x2121, 0x8140},
+                                 {0x7f7f, 0}, {0x7f7e, 0}, {0x7e7f, 0}, {0x7e7e, 0xeffc},
+                                 {0x2121FFFF, 0}, {0x2223, 0x81a1}, {0x237e, 0x829e}, {0, 0}};
+    unsigned int ret, exp, i;
+
+    i = 0;
+    do
+    {
+        ret = _mbcjistojms(jisjms[i][0]);
+
+        if(_getmbcp() == 932)   /* Japanese codepage? */
+            exp = jisjms[i][1];
+        else
+            exp = jisjms[i][0]; /* If not, no conversion */
+
+        ok(ret == exp, "Expected 0x%x, got 0x%x\n", exp, ret);
+    } while(jisjms[i++][0] != 0);
+}
+
+static void test_mbctombb(void)
+{
+    static const unsigned int mbcmbb_932[][2] = {
+        {0x829e, 0x829e}, {0x829f, 0xa7}, {0x82f1, 0xdd}, {0x82f2, 0x82f2},
+        {0x833f, 0x833f}, {0x8340, 0xa7}, {0x837e, 0xd0}, {0x837f, 0x837f},
+        {0x8380, 0xd1}, {0x8396, 0xb9}, {0x8397, 0x8397}, {0x813f, 0x813f},
+        {0x8140, 0x20}, {0x814c, 0x814c}, {0x814f, 0x5e}, {0x8197, 0x40},
+        {0x8198, 0x8198}, {0x8258, 0x39}, {0x8259, 0x8259}, {0x825f, 0x825f},
+        {0x8260, 0x41}, {0x82f1, 0xdd}, {0x82f2, 0x82f2}, {0,0}};
+    unsigned int exp, ret, i;
+    unsigned int prev_cp = _getmbcp();
+
+    _setmbcp(932);
+    for (i = 0; mbcmbb_932[i][0] != 0; i++)
+    {
+        ret = _mbctombb(mbcmbb_932[i][0]);
+        exp = mbcmbb_932[i][1];
+        ok(ret == exp, "Expected 0x%x, got 0x%x\n", exp, ret);
+    }
+    _setmbcp(prev_cp);
+}
+
+static void test_ismbclegal(void) {
+    unsigned int prev_cp = _getmbcp();
+    int ret, exp, err;
+    unsigned int i;
+
+    _setmbcp(932); /* Japanese */
+    err = 0;
+    for(i = 0; i < 0x10000; i++) {
+        ret = _ismbclegal(i);
+        exp = ((HIBYTE(i) >= 0x81 && HIBYTE(i) <= 0x9F) ||
+               (HIBYTE(i) >= 0xE0 && HIBYTE(i) <= 0xFC)) &&
+              ((LOBYTE(i) >= 0x40 && LOBYTE(i) <= 0x7E) ||
+               (LOBYTE(i) >= 0x80 && LOBYTE(i) <= 0xFC));
+        if(ret != exp) {
+            err = 1;
+            break;
+        }
+    }
+    ok(!err, "_ismbclegal (932) : Expected 0x%x, got 0x%x (0x%x)\n", exp, ret, i);
+    _setmbcp(936); /* Chinese (GBK) */
+    err = 0;
+    for(i = 0; i < 0x10000; i++) {
+        ret = _ismbclegal(i);
+        exp = HIBYTE(i) >= 0x81 && HIBYTE(i) <= 0xFE &&
+              LOBYTE(i) >= 0x40 && LOBYTE(i) <= 0xFE;
+        if(ret != exp) {
+            err = 1;
+            break;
+        }
+    }
+    ok(!err, "_ismbclegal (936) : Expected 0x%x, got 0x%x (0x%x)\n", exp, ret, i);
+    _setmbcp(949); /* Korean */
+    err = 0;
+    for(i = 0; i < 0x10000; i++) {
+        ret = _ismbclegal(i);
+        exp = HIBYTE(i) >= 0x81 && HIBYTE(i) <= 0xFE &&
+              LOBYTE(i) >= 0x41 && LOBYTE(i) <= 0xFE;
+        if(ret != exp) {
+            err = 1;
+            break;
+        }
+    }
+    ok(!err, "_ismbclegal (949) : Expected 0x%x, got 0x%x (0x%x)\n", exp, ret, i);
+    _setmbcp(950); /* Chinese (Big5) */
+    err = 0;
+    for(i = 0; i < 0x10000; i++) {
+        ret = _ismbclegal(i);
+        exp = HIBYTE(i) >= 0x81 && HIBYTE(i) <= 0xFE &&
+            ((LOBYTE(i) >= 0x40 && LOBYTE(i) <= 0x7E) ||
+             (LOBYTE(i) >= 0xA1 && LOBYTE(i) <= 0xFE));
+        if(ret != exp) {
+            err = 1;
+            break;
+        }
+    }
+    ok(!err, "_ismbclegal (950) : Expected 0x%x, got 0x%x (0x%x)\n", exp, ret, i);
+    _setmbcp(1361); /* Korean (Johab) */
+    err = 0;
+    for(i = 0; i < 0x10000; i++) {
+        ret = _ismbclegal(i);
+        exp = ((HIBYTE(i) >= 0x81 && HIBYTE(i) <= 0xD3) ||
+               (HIBYTE(i) >= 0xD8 && HIBYTE(i) <= 0xF9)) &&
+              ((LOBYTE(i) >= 0x31 && LOBYTE(i) <= 0x7E) ||
+               (LOBYTE(i) >= 0x81 && LOBYTE(i) <= 0xFE)) &&
+                HIBYTE(i) != 0xDF;
+        if(ret != exp) {
+            err = 1;
+            break;
+        }
+    }
+    todo_wine ok(!err, "_ismbclegal (1361) : Expected 0x%x, got 0x%x (0x%x)\n", exp, ret, i);
+
+    _setmbcp(prev_cp);
+}
+
+static const struct {
+    const char* string;
+    const char* delimiter;
+    int exp_offsetret1; /* returned offset from string after first call to strtok()
+                           -1 means NULL  */
+    int exp_offsetret2; /* returned offset from string after second call to strtok()
+                           -1 means NULL  */
+    int exp_offsetret3; /* returned offset from string after third call to strtok()
+                           -1 means NULL  */
+} testcases_strtok[] = {
+    { "red cabernet", " ", 0, 4, -1 },
+    { "sparkling white riesling", " ", 0, 10, 16 },
+    { " pale cream sherry", "e ", 1, 6, 9 },
+    /* end mark */
+    { 0}
+};
+
+static void test_strtok(void)
+{
+    int i;
+    char *strret;
+    char teststr[100];
+    for( i = 0; testcases_strtok[i].string; i++){
+        strcpy( teststr, testcases_strtok[i].string);
+        strret = strtok( teststr, testcases_strtok[i].delimiter);
+        ok( (int)(strret - teststr) ==  testcases_strtok[i].exp_offsetret1 ||
+                (!strret && testcases_strtok[i].exp_offsetret1 == -1),
+                "string (%p) \'%s\' return %p\n",
+                teststr, testcases_strtok[i].string, strret);
+        if( !strret) continue;
+        strret = strtok( NULL, testcases_strtok[i].delimiter);
+        ok( (int)(strret - teststr) ==  testcases_strtok[i].exp_offsetret2 ||
+                (!strret && testcases_strtok[i].exp_offsetret2 == -1),
+                "second call string (%p) \'%s\' return %p\n",
+                teststr, testcases_strtok[i].string, strret);
+        if( !strret) continue;
+        strret = strtok( NULL, testcases_strtok[i].delimiter);
+        ok( (int)(strret - teststr) ==  testcases_strtok[i].exp_offsetret3 ||
+                (!strret && testcases_strtok[i].exp_offsetret3 == -1),
+                "third call string (%p) \'%s\' return %p\n",
+                teststr, testcases_strtok[i].string, strret);
+    }
+}
+
+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];
@@ -618,10 +923,13 @@ START_TEST(string)
     ok(hMsvcrt != 0, "GetModuleHandleA failed\n");
     SET(pmemcpy,"memcpy");
     SET(pmemcmp,"memcmp");
+    SET(p_mbctype,"_mbctype");
+    SET(p__mb_cur_max,"__mb_cur_max");
     pstrcpy_s = (void *)GetProcAddress( hMsvcrt,"strcpy_s" );
     pstrcat_s = (void *)GetProcAddress( hMsvcrt,"strcat_s" );
     p_mbsnbcpy_s = (void *)GetProcAddress( hMsvcrt,"_mbsnbcpy_s" );
     p_wcscpy_s = (void *)GetProcAddress( hMsvcrt,"wcscpy_s" );
+    p_wcsupr_s = (void *)GetProcAddress( hMsvcrt,"_wcsupr_s" );
 
     /* MSVCRT memcpy behaves like memmove for overlapping moves,
        MFC42 CString::Insert seems to rely on that behaviour */
@@ -644,6 +952,11 @@ START_TEST(string)
     test_strcpy_s();
     test_strcat_s();
     test__mbsnbcpy_s();
-
+    test_mbcjisjms();
+    test_mbctombb();
+    test_ismbclegal();
+    test_strtok();
     test_wcscpy_s();
+    test__wcsupr_s();
+    test_strtol();
 }