[PATCH] shlwapi/tests: Add tests for SHUnicodeToAnsiCP
Detlef Riekenberg
wine.dev at web.de
Tue Jun 30 15:33:24 CDT 2009
---
dlls/shlwapi/tests/string.c | 114 +++++++++++++++++++++++++++++++++++++++++++
1 files changed, 114 insertions(+), 0 deletions(-)
diff --git a/dlls/shlwapi/tests/string.c b/dlls/shlwapi/tests/string.c
index fa50626..4f5754b 100644
--- a/dlls/shlwapi/tests/string.c
+++ b/dlls/shlwapi/tests/string.c
@@ -42,6 +42,7 @@
static BOOL (WINAPI *pIntlStrEqWorkerA)(BOOL,LPCSTR,LPCSTR,int);
static BOOL (WINAPI *pIntlStrEqWorkerW)(BOOL,LPCWSTR,LPCWSTR,int);
+static DWORD (WINAPI *pSHUnicodeToAnsiCP)(UINT,LPCWSTR,LPSTR,int);
static DWORD (WINAPI *pSHAnsiToAnsi)(LPCSTR,LPSTR,int);
static DWORD (WINAPI *pSHUnicodeToUnicode)(LPCWSTR,LPWSTR,int);
static LPSTR (WINAPI *pStrCatBuffA)(LPSTR,LPCSTR,INT);
@@ -188,6 +189,43 @@ static const StrFromTimeIntervalResult StrFromTimeInterval_results[] = {
{ 0, 0, NULL }
};
+typedef struct unucodetoansicp_entry_tag {
+ UINT cp;
+ LPCWSTR strW;
+ LPCSTR strA;
+ DWORD needed;
+} unucodetoansicp_entry;
+
+static const WCHAR winehqW[] = {'h','t','t','p',':','/','/',
+ 'w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
+static const CHAR winehqA[] = {'h','t','t','p',':','/','/',
+ 'w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
+static const WCHAR spassW[] = {'s','p','a',0xdf,0};
+static const CHAR spassA[] = {'s','p','a',0xdf,0};
+static const CHAR spass8[] = {'s','p','a',0xc3,0x9f,0};
+static const CHAR spass7[] = {'s','p','a','+','A','N','8','-',0};
+static const WCHAR tenohmW[] = {'1','0',0x2126,0};
+static const CHAR tenohm8[] = {'1','0',0xe2,0x84,0xa6,0};
+static const CHAR tenohm7[] = {'1','0','+','I','S','Y','-',0};
+static const WCHAR pluszW[] = {'+','z',0};
+static const CHAR plusz8[] = {'+','z',0};
+static const CHAR plusz7[] = {'+','-','z',0};
+
+static const unucodetoansicp_entry utoa_table[] = {
+ {1252, winehqW, winehqA, 22},
+ {CP_UTF8, winehqW, winehqA, 22},
+ {1252, spassW, spassA, 5},
+ {CP_UTF8, spassW, spass8, 6},
+ {CP_UTF7, spassW, spass7, 9},
+
+ {CP_UTF8, tenohmW, tenohm8, 6},
+ {CP_UTF7, tenohmW, tenohm7, 8},
+
+ {CP_UTF8, pluszW, plusz8, 3},
+ {CP_UTF7, pluszW, plusz7, 4}
+};
+
+
static void test_StrChrA(void)
{
char string[129];
@@ -779,6 +817,80 @@ static void test_SHAnsiToAnsi(void)
dwRet, dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
}
+static void test_SHUnicodeToAnsiCP(void)
+{
+ CHAR dst[32];
+ BOOL have_utf8;
+ BOOL have_utf7;
+ DWORD res;
+ INT i;
+
+ if (!pSHUnicodeToAnsiCP)
+ {
+ win_skip("SHUnicodeToAnsiCP() is not available\n");
+ return;
+ }
+
+ /* Not all systems support CP_UTF7 and CP_UTF8 */
+ res = WideCharToMultiByte(CP_UTF7, 0, winehqW, -1, dst, sizeof(dst), NULL, NULL);
+ have_utf7 = (res > 0);
+
+ res = WideCharToMultiByte(CP_UTF8, 0, winehqW, -1, dst, sizeof(dst), NULL, NULL);
+ have_utf8 = (res > 0);
+
+ /* SHUnicodeToAnsiCP does not change lasterror with UTF7 / UTF8 */
+ for(i = 0; i < sizeof(utoa_table) / sizeof(utoa_table[0]); i++) {
+
+ if ((utoa_table[i].cp == CP_UTF8 && !have_utf8) ||
+ (utoa_table[i].cp == CP_UTF7 && !have_utf7)) {
+ continue;
+ }
+
+ /* a large buffer for the result */
+ memset(dst, 'x', sizeof(dst));
+ dst[sizeof(dst)-1] = '\0';
+ res = pSHUnicodeToAnsiCP(utoa_table[i].cp, utoa_table[i].strW, dst, sizeof(dst));
+ ok( (res == utoa_table[i].needed) && (!lstrcmpA(dst, utoa_table[i].strA)),
+ "#%02d (max) got %d and '%s' (expected %d with '%s')\n",
+ i, res, dst, utoa_table[i].needed, utoa_table[i].strA);
+
+ /* exact size */
+ memset(dst, 'x', sizeof(dst));
+ dst[sizeof(dst)-1] = '\0';
+ res = pSHUnicodeToAnsiCP(utoa_table[i].cp, utoa_table[i].strW, dst, utoa_table[i].needed);
+ ok( (res == utoa_table[i].needed) && (!lstrcmpA(dst, utoa_table[i].strA)),
+ "#%02d (len + 1) got %d and '%s' (expected %d with '%s')\n",
+ i, res, dst, utoa_table[i].needed, utoa_table[i].strA);
+
+ /* no space for terminating zero */
+ memset(dst, 'x', sizeof(dst));
+ dst[sizeof(dst)-1] = '\0';
+ res = pSHUnicodeToAnsiCP(utoa_table[i].cp, utoa_table[i].strW, dst, utoa_table[i].needed - 1);
+ ok( (res < utoa_table[i].needed) && (lstrcmpA(dst, utoa_table[i].strA)),
+ "#%02d (len) got %d and '%s' (expected '< %d' and != '%s')\n",
+ i, res, dst, utoa_table[i].needed, utoa_table[i].strA);
+
+ /* no space for the full result */
+ memset(dst, 'x', sizeof(dst));
+ dst[sizeof(dst)-1] = '\0';
+ res = pSHUnicodeToAnsiCP(utoa_table[i].cp, utoa_table[i].strW, dst, utoa_table[i].needed- 2);
+ ok( lstrcmpA(dst, utoa_table[i].strA),
+ "#%02d (len - 1) got %d and '%s' (expected != '%s')\n",
+ i, res, dst, utoa_table[i].strA);
+
+ /* negativ len */
+ memset(dst, 'x', sizeof(dst));
+ dst[sizeof(dst)-1] = '\0';
+ res = pSHUnicodeToAnsiCP(utoa_table[i].cp, utoa_table[i].strW, dst, -1);
+ ok(res == 0, "got %d (expected 0)\n", res);
+
+ /* NULL (no dst buffer) */
+ res = pSHUnicodeToAnsiCP(utoa_table[i].cp, utoa_table[i].strW, NULL, sizeof(dst));
+ ok(res == 0, "got %d (expected 0)\n", res);
+
+ }
+}
+
static void test_SHUnicodeToUnicode(void)
{
static const WCHAR lpInit[] = { '\n','\n','\n','\n','\n','\n','\n','\n' };
@@ -905,6 +1017,7 @@ START_TEST(string)
hShlwapi = GetModuleHandleA("shlwapi");
pIntlStrEqWorkerA = (void *)GetProcAddress(hShlwapi, "IntlStrEqWorkerA");
pIntlStrEqWorkerW = (void *)GetProcAddress(hShlwapi, "IntlStrEqWorkerW");
+ pSHUnicodeToAnsiCP = (void *)GetProcAddress(hShlwapi, (LPSTR)218);
pSHAnsiToAnsi = (void *)GetProcAddress(hShlwapi, (LPSTR)345);
pSHUnicodeToUnicode = (void *)GetProcAddress(hShlwapi, (LPSTR)346);
pStrCatBuffA = (void *)GetProcAddress(hShlwapi, "StrCatBuffA");
@@ -955,6 +1068,7 @@ START_TEST(string)
test_StrCpyNXW();
test_StrRStrI();
test_SHAnsiToAnsi();
+ test_SHUnicodeToAnsiCP();
test_SHUnicodeToUnicode();
test_StrXXX_overflows();
--
1.5.4.3
--=-S4XkiNZus1ywWHTkLlRK--
More information about the wine-patches
mailing list