mlang: Implement IMLangFontLink_GetStrCodePages.

Dmitry Timoshkov dmitry at codeweavers.com
Wed Feb 25 06:32:05 CST 2009


---
 dlls/mlang/mlang.c       |   45 ++++++++++++++++-----
 dlls/mlang/tests/mlang.c |   96 +++++++++++++++++++++++++++++++++++++++------
 include/mlang.idl        |    4 +-
 3 files changed, 119 insertions(+), 26 deletions(-)

diff --git a/dlls/mlang/mlang.c b/dlls/mlang/mlang.c
index 11fa366..0987083 100644
--- a/dlls/mlang/mlang.c
+++ b/dlls/mlang/mlang.c
@@ -1907,14 +1907,39 @@ static HRESULT WINAPI fnIMLangFontLink_GetCharCodePages(
 static HRESULT WINAPI fnIMLangFontLink_GetStrCodePages(
         IMLangFontLink* iface,
         const WCHAR* pszSrc,
-        long cchSrc,
+        LONG cchSrc,
         DWORD dwPriorityCodePages,
         DWORD* pdwCodePages,
-        long* pcchCodePages)
+        LONG* pcchCodePages)
 {
-    FIXME("(pszSrc=%s, cchSrc=%ld, dwPriorityCodePages=%d) stub\n", debugstr_w(pszSrc), cchSrc, dwPriorityCodePages);
-    *pdwCodePages = 0;
-    *pcchCodePages = 1;
+    LONG i;
+    DWORD cps = 0;
+
+    TRACE("(%p)->%s %d %x %p %p\n", iface, debugstr_wn(pszSrc,cchSrc),cchSrc,dwPriorityCodePages,pdwCodePages,pcchCodePages);
+
+    if (pdwCodePages) *pdwCodePages = 0;
+    if (pcchCodePages) *pcchCodePages = 0;
+
+    if (!pszSrc || !cchSrc || cchSrc < 0)
+        return E_INVALIDARG;
+
+    for (i = 0; i < cchSrc; i++)
+    {
+        DWORD cp;
+        HRESULT ret;
+
+        ret = fnIMLangFontLink_GetCharCodePages(iface, pszSrc[i], &cp);
+        if (ret != S_OK) return E_FAIL;
+
+        if (!cps) cps = cp;
+        else cps &= cp;
+
+        /* FIXME: is this correct? */
+        if (dwPriorityCodePages & cps) break;
+    }
+
+    if (pdwCodePages) *pdwCodePages = cps;
+    if (pcchCodePages) *pcchCodePages = i;
     return S_OK;
 }
 
@@ -3176,13 +3201,11 @@ static HRESULT WINAPI fnIMLangFontLink2_GetCharCodePages( IMLangFontLink2* This,
 }
 
 static HRESULT WINAPI fnIMLangFontLink2_GetStrCodePages( IMLangFontLink2* This,
-        const WCHAR *pszSrc, long cchSrc, DWORD dwPriorityCodePages,
-        DWORD *pdwCodePages, long *pcchCodePages)
+        const WCHAR *pszSrc, LONG cchSrc, DWORD dwPriorityCodePages,
+        DWORD *pdwCodePages, LONG *pcchCodePages)
 {
-    FIXME("(%p)->%s %li %x %p %p\n",This, debugstr_wn(pszSrc,cchSrc),cchSrc,dwPriorityCodePages,pdwCodePages,pcchCodePages);
-    *pdwCodePages = 0;
-    *pcchCodePages = 1;
-    return S_OK;
+    return fnIMLangFontLink_GetStrCodePages((IMLangFontLink *)This,
+            pszSrc, cchSrc, dwPriorityCodePages, pdwCodePages, pcchCodePages);
 }
 
 static HRESULT WINAPI fnIMLangFontLink2_CodePageToCodePages(IMLangFontLink2* This,
diff --git a/dlls/mlang/tests/mlang.c b/dlls/mlang/tests/mlang.c
index ae5060a..0f51df0 100644
--- a/dlls/mlang/tests/mlang.c
+++ b/dlls/mlang/tests/mlang.c
@@ -211,7 +211,7 @@ static void test_multibyte_to_unicode_translations(IMultiLanguage2 *iML2)
     ok(lenA == expected_len, "expected lenA %u, got %u\n", expected_len, lenA);
 }
 
-static inline void cpinfo_cmp(MIMECPINFO *cpinfo1, MIMECPINFO *cpinfo2)
+static void cpinfo_cmp(MIMECPINFO *cpinfo1, MIMECPINFO *cpinfo2)
 {
     ok(cpinfo1->dwFlags == cpinfo2->dwFlags, "dwFlags mismatch: %08x != %08x\n", cpinfo1->dwFlags, cpinfo2->dwFlags);
     ok(cpinfo1->uiCodePage == cpinfo2->uiCodePage, "uiCodePage mismatch: %u != %u\n", cpinfo1->uiCodePage, cpinfo2->uiCodePage);
@@ -538,7 +538,7 @@ static void test_EnumCodePages(IMultiLanguage2 *iML2, DWORD flags)
     IEnumCodePage_Release(iEnumCP);
 }
 
-static inline void scriptinfo_cmp(SCRIPTINFO *sinfo1, SCRIPTINFO *sinfo2)
+static void scriptinfo_cmp(SCRIPTINFO *sinfo1, SCRIPTINFO *sinfo2)
 {
     ok(sinfo1->ScriptId == sinfo2->ScriptId, "ScriptId mismatch: %d != %d\n", sinfo1->ScriptId, sinfo2->ScriptId);
     ok(sinfo1->uiCodePage == sinfo2->uiCodePage, "uiCodePage mismatch: %u != %u\n", sinfo1->uiCodePage, sinfo2->uiCodePage);
@@ -649,6 +649,8 @@ static void IMLangFontLink_Test(IMLangFontLink* iMLFL)
     DWORD dwCodePages, dwManyCodePages;
     DWORD dwCmpCodePages;
     UINT CodePage;
+    static const WCHAR str[3] = { 'd', 0x0436, 0xff90 };
+    LONG processed;
     HRESULT ret;
 
     dwCodePages = ~0u;
@@ -693,21 +695,89 @@ static void IMLangFontLink_Test(IMLangFontLink* iMLFL)
     dwCmpCodePages = FS_LATIN1 | FS_LATIN2 | FS_CYRILLIC | FS_GREEK | FS_TURKISH
         | FS_HEBREW | FS_ARABIC | FS_BALTIC | FS_VIETNAMESE | FS_THAI
         | FS_JISJAPAN | FS_CHINESESIMP | FS_WANSUNG | FS_CHINESETRAD;
-    ok(IMLangFontLink_GetCharCodePages(iMLFL, 'd', &dwCodePages) == S_OK,
-        "IMLangFontLink_GetCharCodePages failed\n");
-    ok(dwCodePages == dwCmpCodePages, "Incorrect CodePages returned (%i)\n", dwCodePages);
+    ret = IMLangFontLink_GetCharCodePages(iMLFL, 'd', &dwCodePages);
+    ok(ret == S_OK, "IMLangFontLink_GetCharCodePages error %x\n", ret);
+    ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
+
+    dwCodePages = 0;
+    processed = 0;
+    ret = IMLangFontLink_GetStrCodePages(iMLFL, &str[0], 1, 0, &dwCodePages, &processed);
+    ok(ret == S_OK, "IMLangFontLink_GetStrCodePages error %x\n", ret);
+    ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
+    ok(processed == 1, "expected 1, got %d\n", processed);
 
     /* Cyrillic */
     dwCmpCodePages = FS_CYRILLIC | FS_JISJAPAN | FS_CHINESESIMP | FS_WANSUNG;
-    ok(IMLangFontLink_GetCharCodePages(iMLFL, 0x0436, &dwCodePages) == S_OK,
-        "IMLangFontLink_GetCharCodePages failed\n");
-    ok(dwCodePages == dwCmpCodePages, "Incorrect CodePages returned (%i)\n", dwCodePages);
+    ret = IMLangFontLink_GetCharCodePages(iMLFL, 0x0436, &dwCodePages);
+    ok(ret == S_OK, "IMLangFontLink_GetCharCodePages error %x\n", ret);
+    ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
+
+    dwCodePages = 0;
+    processed = 0;
+    ret = IMLangFontLink_GetStrCodePages(iMLFL, &str[1], 1, 0, &dwCodePages, &processed);
+    ok(ret == S_OK, "IMLangFontLink_GetStrCodePages error %x\n", ret);
+    ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
+    ok(processed == 1, "expected 1, got %d\n", processed);
 
     /* Japanese */
     dwCmpCodePages =  FS_JISJAPAN;
-    ok(IMLangFontLink_GetCharCodePages(iMLFL, 0xff90, &dwCodePages) == S_OK,
-        "IMLangFontLink_GetCharCodePages failed\n");
-    ok(dwCodePages == dwCmpCodePages, "Incorrect CodePages returned (%i)\n", dwCodePages);
+    ret = IMLangFontLink_GetCharCodePages(iMLFL, 0xff90, &dwCodePages);
+    ok(ret == S_OK, "IMLangFontLink_GetCharCodePages error %x\n", ret);
+    ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
+
+    dwCodePages = 0;
+    processed = 0;
+    ret = IMLangFontLink_GetStrCodePages(iMLFL, &str[2], 1, 0, &dwCodePages, &processed);
+    ok(ret == S_OK, "IMLangFontLink_GetStrCodePages error %x\n", ret);
+    ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
+    ok(processed == 1, "expected 1, got %d\n", processed);
+
+    dwCmpCodePages = FS_CYRILLIC | FS_JISJAPAN | FS_CHINESESIMP | FS_WANSUNG;
+    dwCodePages = 0;
+    processed = 0;
+    ret = IMLangFontLink_GetStrCodePages(iMLFL, str, 2, 0, &dwCodePages, &processed);
+    ok(ret == S_OK, "IMLangFontLink_GetStrCodePages error %x\n", ret);
+    ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
+    ok(processed == 2, "expected 2, got %d\n", processed);
+
+    dwCmpCodePages = FS_JISJAPAN;
+    dwCodePages = 0;
+    processed = 0;
+    ret = IMLangFontLink_GetStrCodePages(iMLFL, str, 3, 0, &dwCodePages, &processed);
+    ok(ret == S_OK, "IMLangFontLink_GetStrCodePages error %x\n", ret);
+    ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
+    ok(processed == 3, "expected 3, got %d\n", processed);
+
+    dwCodePages = 0xffff;
+    processed = -1;
+    ret = IMLangFontLink_GetStrCodePages(iMLFL, &str[2], 1, 0, &dwCodePages, &processed);
+    ok(ret == S_OK, "IMLangFontLink_GetStrCodePages error %x\n", ret);
+    ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
+    ok(processed == 1, "expected 0, got %d\n", processed);
+
+    ret = IMLangFontLink_GetStrCodePages(iMLFL, &str[2], 1, 0, NULL, NULL);
+    ok(ret == S_OK, "IMLangFontLink_GetStrCodePages error %x\n", ret);
+
+    dwCodePages = 0xffff;
+    processed = -1;
+    ret = IMLangFontLink_GetStrCodePages(iMLFL, str, -1, 0, &dwCodePages, &processed);
+    ok(ret == E_INVALIDARG, "IMLangFontLink_GetStrCodePages should fail: %x\n", ret);
+    ok(dwCodePages == 0, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
+    ok(processed == 0, "expected 0, got %d\n", processed);
+
+    dwCodePages = 0xffff;
+    processed = -1;
+    ret = IMLangFontLink_GetStrCodePages(iMLFL, NULL, 1, 0, &dwCodePages, &processed);
+    ok(ret == E_INVALIDARG, "IMLangFontLink_GetStrCodePages should fail: %x\n", ret);
+    ok(dwCodePages == 0, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
+    ok(processed == 0, "expected 0, got %d\n", processed);
+
+    dwCodePages = 0xffff;
+    processed = -1;
+    ret = IMLangFontLink_GetStrCodePages(iMLFL, str, 0, 0, &dwCodePages, &processed);
+    ok(ret == E_INVALIDARG, "IMLangFontLink_GetStrCodePages should fail: %x\n", ret);
+    ok(dwCodePages == 0, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
+    ok(processed == 0, "expected 0, got %d\n", processed);
 }
 
 /* copied from libs/wine/string.c */
@@ -1395,7 +1465,7 @@ static void test_GetScriptFontInfo(IMLangFontLink2 *font_link)
     hr = IMLangFontLink2_GetScriptFontInfo(font_link, sidLatin, SCRIPTCONTF_FIXED_FONT, &nfonts, sfi);
     ok(hr == S_OK, "GetScriptFontInfo failed %u\n", GetLastError());
     ok(nfonts == 1, "got %u, expected 1\n", nfonts);
-    ok(sfi[0].scripts, "unexpected result\n");
+    ok(sfi[0].scripts != 0, "unexpected result\n");
     ok(sfi[0].wszFont[0], "unexpected result\n");
 
     nfonts = 1;
@@ -1403,7 +1473,7 @@ static void test_GetScriptFontInfo(IMLangFontLink2 *font_link)
     hr = IMLangFontLink2_GetScriptFontInfo(font_link, sidLatin, SCRIPTCONTF_PROPORTIONAL_FONT, &nfonts, sfi);
     ok(hr == S_OK, "GetScriptFontInfo failed %u\n", GetLastError());
     ok(nfonts == 1, "got %u, expected 1\n", nfonts);
-    ok(sfi[0].scripts, "unexpected result\n");
+    ok(sfi[0].scripts != 0, "unexpected result\n");
     ok(sfi[0].wszFont[0], "unexpected result\n");
 }
 
diff --git a/include/mlang.idl b/include/mlang.idl
index ca89711..d6a7f3a 100644
--- a/include/mlang.idl
+++ b/include/mlang.idl
@@ -37,10 +37,10 @@ interface IMLangCodePages : IUnknown
         [out] DWORD *pdwCodePages);
     HRESULT GetStrCodePages(      
         [in, size_is(cchSrc)] const WCHAR *pszSrc,
-        [in] long cchSrc,
+        [in] LONG cchSrc,
         [in] DWORD dwPriorityCodePages,
         [out] DWORD *pdwCodePages,
-        [out] long *pcchCodePages);
+        [out] LONG *pcchCodePages);
     HRESULT CodePageToCodePages(      
         [in] UINT uCodePage,
         [out] DWORD *pdwCodePages);
-- 
1.6.1.3




More information about the wine-patches mailing list