msvcrt[5/5]: test that some functions depends on locale codepage, not the one set by _setmbcp

Mikolaj Zalewski mikolajz at google.com
Mon Aug 20 12:23:04 CDT 2007


mblen and _mbstrlen depends on the locale codepage - I've moved them
down and added a comment. The test works only if the default locale
charset is single-byte but there should be enough testers with this
configuration to notice regressions.
-------------- next part --------------
From 8b85b10ec3ffdc14f989ff966ef6abd759c32b41 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Miko=C5=82aj_Zalewski?= <mikolaj at zalewski.pl>
Date: Sun, 19 Aug 2007 22:59:52 -0700
Subject: [PATCH] msvcrt: test that some functions depends on locale codepage, not the one set by _setmbcp

---
 dlls/msvcrt/mbcs.c         |   83 +++++++++++++++++++++++++-------------------
 dlls/msvcrt/tests/string.c |   13 +++++++
 2 files changed, 60 insertions(+), 36 deletions(-)

diff --git a/dlls/msvcrt/mbcs.c b/dlls/msvcrt/mbcs.c
index f49323d..aa1c7b9 100644
--- a/dlls/msvcrt/mbcs.c
+++ b/dlls/msvcrt/mbcs.c
@@ -360,21 +360,6 @@ unsigned int CDECL _mbclen(const unsigned char* str)
 }
 
 /*********************************************************************
- *		mblen(MSVCRT.@)
- */
-int CDECL MSVCRT_mblen(const char* str, MSVCRT_size_t size)
-{
-  if (str && *str && size)
-  {
-    if(MSVCRT___mb_cur_max == 1)
-      return 1; /* ASCII CP */
-
-    return !MSVCRT_isleadbyte(*str) ? 1 : (size>1 ? 2 : -1);
-  }
-  return 0;
-}
-
-/*********************************************************************
  *		_mbslen(MSVCRT.@)
  */
 MSVCRT_size_t CDECL _mbslen(const unsigned char* str)
@@ -395,27 +380,6 @@ MSVCRT_size_t CDECL _mbslen(const unsigned char* str)
 }
 
 /*********************************************************************
- *		_mbstrlen(MSVCRT.@)
- */
-MSVCRT_size_t CDECL _mbstrlen(const char* str)
-{
-  if(MSVCRT___mb_cur_max > 1)
-  {
-    MSVCRT_size_t len = 0;
-    while(*str)
-    {
-      /* FIXME: According to the documentation we are supposed to test for
-       * multi-byte character validity. Whatever that means
-       */
-      str += MSVCRT_isleadbyte(*str) ? 2 : 1;
-      len++;
-    }
-    return len;
-  }
-  return strlen(str); /* ASCII CP */
-}
-
-/*********************************************************************
  *		_mbccpy(MSVCRT.@)
  */
 void CDECL _mbccpy(unsigned char* dest, const unsigned char* src)
@@ -1477,3 +1441,50 @@ unsigned char* CDECL _mbspbrk(const unsigned char* str, const unsigned char* acc
     }
     return NULL;
 }
+
+
+/*
+ * Functions depending on locale codepage
+ */
+
+/*********************************************************************
+ *		mblen(MSVCRT.@)
+ * REMARKS
+ *  Unlike most of the multibyte string functions this function uses
+ *  the locale codepage, not the codepage set by _setmbcp
+ */
+int CDECL MSVCRT_mblen(const char* str, MSVCRT_size_t size)
+{
+  if (str && *str && size)
+  {
+    if(MSVCRT___mb_cur_max == 1)
+      return 1; /* ASCII CP */
+
+    return !MSVCRT_isleadbyte(*str) ? 1 : (size>1 ? 2 : -1);
+  }
+  return 0;
+}
+
+/*********************************************************************
+ *		_mbstrlen(MSVCRT.@)
+ * REMARKS
+ *  Unlike most of the multibyte string functions this function uses
+ *  the locale codepage, not the codepage set by _setmbcp
+ */
+MSVCRT_size_t CDECL _mbstrlen(const char* str)
+{
+  if(MSVCRT___mb_cur_max > 1)
+  {
+    MSVCRT_size_t len = 0;
+    while(*str)
+    {
+      /* FIXME: According to the documentation we are supposed to test for
+       * multi-byte character validity. Whatever that means
+       */
+      str += MSVCRT_isleadbyte(*str) ? 2 : 1;
+      len++;
+    }
+    return len;
+  }
+  return strlen(str); /* ASCII CP */
+}
diff --git a/dlls/msvcrt/tests/string.c b/dlls/msvcrt/tests/string.c
index 209f1fa..4f82652 100644
--- a/dlls/msvcrt/tests/string.c
+++ b/dlls/msvcrt/tests/string.c
@@ -201,6 +201,19 @@ static void test_mbcp(void)
     expect_eq(_mbslen(mbsonlylead), 0, int, "%d");          /* lead + NUL not counted as character */
     expect_eq(_mbslen(mbstring), 4, int, "%d");             /* lead + invalid trail counted */
 
+
+    /* functions that depend on locale codepage, not mbcp.
+     * 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)
+    {
+        expect_eq(mblen((char *)mbstring, 3), 1, int, "%x");
+        expect_eq(_mbstrlen((char *)mbstring2), 7, int, "%d");
+    }
+    else
+        skip("Current locale has double-byte charset - could leave to false positives\n");
+
     _setmbcp(curr_mbcp);
 }
 
-- 
1.4.4.2


More information about the wine-patches mailing list