[1/5] kernel32/tests: Add test to show that CompareStringW aborts on first non-matching character.

Sebastian Lackner sebastian at fds-team.de
Sat Feb 13 15:24:06 CST 2016


Signed-off-by: Sebastian Lackner <sebastian at fds-team.de>
---

The issue is already fixed, but it probably doesn't hurt to have a test
somewhere in the Wine source tree.

 dlls/kernel32/tests/locale.c |   31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/dlls/kernel32/tests/locale.c b/dlls/kernel32/tests/locale.c
index 4a9e540..6726fb9 100644
--- a/dlls/kernel32/tests/locale.c
+++ b/dlls/kernel32/tests/locale.c
@@ -1798,6 +1798,36 @@ static void test_CompareStringA(void)
         "ret %d, error %d, expected value %d\n", ret, GetLastError(), CSTR_EQUAL);
 }
 
+static void test_CompareStringW(void)
+{
+    WCHAR *str1, *str2;
+    SYSTEM_INFO si;
+    DWORD old_prot;
+    BOOL success;
+    char *buf;
+    int ret;
+
+    GetSystemInfo(&si);
+    buf = VirtualAlloc(NULL, si.dwPageSize * 4, MEM_COMMIT, PAGE_READWRITE);
+    ok(buf != NULL, "VirtualAlloc failed with %u\n", GetLastError());
+    success = VirtualProtect(buf + si.dwPageSize, si.dwPageSize, PAGE_NOACCESS, &old_prot);
+    ok(success, "VirtualProtect failed with %u\n", GetLastError());
+    success = VirtualProtect(buf + 3 * si.dwPageSize, si.dwPageSize, PAGE_NOACCESS, &old_prot);
+    ok(success, "VirtualProtect failed with %u\n", GetLastError());
+
+    str1 = (WCHAR *)(buf + si.dwPageSize - sizeof(WCHAR));
+    str2 = (WCHAR *)(buf + 3 * si.dwPageSize - sizeof(WCHAR));
+    *str1 = 'A';
+    *str2 = 'B';
+
+    /* CompareStringW should abort on the first non-matching character */
+    ret = CompareStringW(CP_ACP, 0, str1, 100, str2, 100);
+    ok(ret == CSTR_LESS_THAN, "expected CSTR_LESS_THAN, got %d\n", ret);
+
+    success = VirtualFree(buf, 0, MEM_RELEASE);
+    ok(success, "VirtualFree failed with %u\n", GetLastError());
+}
+
 struct comparestringex_test {
     const char *locale;
     DWORD flags;
@@ -4791,6 +4821,7 @@ START_TEST(locale)
   test_GetCurrencyFormatA(); /* Also tests the W version */
   test_GetNumberFormatA();   /* Also tests the W version */
   test_CompareStringA();
+  test_CompareStringW();
   test_CompareStringEx();
   test_LCMapStringA();
   test_LCMapStringW();
-- 
2.7.1



More information about the wine-patches mailing list