Robert Shearman : user: Ignore setting NULL window procs inside SetWindowLong.

Alexandre Julliard julliard at wine.codeweavers.com
Mon Jul 31 15:01:27 CDT 2006


Module: wine
Branch: refs/heads/master
Commit: 447721e8cb449794b8646430a692a607533f1d81
URL:    http://source.winehq.org/git/?p=wine.git;a=commit;h=447721e8cb449794b8646430a692a607533f1d81

Author: Robert Shearman <rob at codeweavers.com>
Date:   Mon Jul 31 16:43:35 2006 +0100

user: Ignore setting NULL window procs inside SetWindowLong.

Add tests for SetWindowLong error cases.

---

 dlls/user/tests/win.c |   49 +++++++++++++++++++++++++++++++++++++++++++++++++
 dlls/user/win.c       |    8 +++++---
 2 files changed, 54 insertions(+), 3 deletions(-)

diff --git a/dlls/user/tests/win.c b/dlls/user/tests/win.c
index 05a9287..35cd7fc 100644
--- a/dlls/user/tests/win.c
+++ b/dlls/user/tests/win.c
@@ -3818,6 +3818,54 @@ #undef expect_style
 #undef expect_ex_style
 }
 
+/* function that remembers whether the system the test is running on sets the
+ * last error for user32 functions to make the tests stricter */
+static int check_error(DWORD actual, DWORD expected)
+{
+    static int sets_last_error = -1;
+    if (sets_last_error == -1)
+        sets_last_error = (actual != 0xdeadbeef);
+    return (!sets_last_error && (actual == 0xdeadbeef)) || (actual == expected);
+}
+
+static void test_SetWindowLong(void)
+{
+    LONG_PTR retval;
+
+    SetLastError(0xdeadbeef);
+    retval = SetWindowLongPtr(NULL, GWLP_WNDPROC, 0);
+    ok(!retval, "SetWindowLongPtr on invalid window handle should have returned 0 instead of 0x%x\n", retval);
+    ok(check_error(GetLastError(), ERROR_INVALID_WINDOW_HANDLE),
+        "SetWindowLongPtr should have set error to ERROR_INVALID_WINDOW_HANDLE instad of %ld\n", GetLastError());
+
+    SetLastError(0xdeadbeef);
+    retval = SetWindowLongPtr(hwndMain, 0xdeadbeef, 0);
+    ok(!retval, "SetWindowLongPtr on invalid index should have returned 0 instead of 0x%x\n", retval);
+    ok(check_error(GetLastError(), ERROR_INVALID_INDEX),
+        "SetWindowLongPtr should have set error to ERROR_INVALID_INDEX instad of %ld\n", GetLastError());
+
+    SetLastError(0xdeadbeef);
+    retval = SetWindowLongPtr(hwndMain, GWLP_WNDPROC, 0);
+    ok((WNDPROC)retval == main_window_procA,
+        "SetWindowLongPtr on invalid window proc should have returned address of main_window_procA instead of 0x%x\n", retval);
+    ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %ld\n", GetLastError());
+    retval = GetWindowLongPtr(hwndMain, GWLP_WNDPROC);
+    ok((WNDPROC)retval == main_window_procA,
+        "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%x\n", retval);
+    ok(!IsWindowUnicode(hwndMain), "hwndMain shouldn't be Unicode\n");
+
+    SetLastError(0xdeadbeef);
+    retval = SetWindowLongPtrW(hwndMain, GWLP_WNDPROC, 0);
+    if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
+    {
+        ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %ld\n", GetLastError());
+        ok(IsWindowUnicode(hwndMain), "hwndMain should now be Unicode\n");
+
+        /* set it back to ANSI */
+        SetWindowLongPtr(hwndMain, GWLP_WNDPROC, 0);
+    }
+}
+
 START_TEST(win)
 {
     pGetAncestor = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetAncestor" );
@@ -3893,6 +3941,7 @@ START_TEST(win)
     test_window_styles();
     test_redrawnow();
     test_csparentdc();
+    test_SetWindowLong();
 
     /* add the tests above this line */
     UnhookWindowsHookEx(hhook);
diff --git a/dlls/user/win.c b/dlls/user/win.c
index fa2af00..16690b0 100644
--- a/dlls/user/win.c
+++ b/dlls/user/win.c
@@ -1981,11 +1981,13 @@ static LONG_PTR WIN_SetWindowLong( HWND 
         }
     case GWLP_WNDPROC:
     {
+        WNDPROC proc;
         UINT old_flags = wndPtr->flags;
         retval = (ULONG_PTR)WINPROC_GetProc( wndPtr->winproc, unicode );
-        if (unicode) wndPtr->winproc = WINPROC_AllocProc( NULL, (WNDPROC)newval );
-        else wndPtr->winproc = WINPROC_AllocProc( (WNDPROC)newval, NULL );
-        if (WINPROC_IsUnicode( wndPtr->winproc, unicode )) wndPtr->flags |= WIN_ISUNICODE;
+        if (unicode) proc = WINPROC_AllocProc( NULL, (WNDPROC)newval );
+        else proc = WINPROC_AllocProc( (WNDPROC)newval, NULL );
+        if (proc) wndPtr->winproc = proc;
+        if (WINPROC_IsUnicode( proc, unicode )) wndPtr->flags |= WIN_ISUNICODE;
         else wndPtr->flags &= ~WIN_ISUNICODE;
         if (!((old_flags ^ wndPtr->flags) & WIN_ISUNICODE))
         {




More information about the wine-cvs mailing list