Set/WindowLong problem in user/win test

Francois Gouget fgouget at free.fr
Tue Dec 24 15:23:51 CST 2002


This test uses {Get,Set}WindowLongW which of course does not work on
Win9x, thus causing the test to fail. I guess part of the goal is to
check that mixing Ansi calls (CreatewindowExA) with Unicode calls works.

So I wrote a function test_set_window_long function that calls
SetWindowLongW and then SetWindowLongA and checks that their results
match but that causes the test to fail (at least on NT4 and Wine).
More precisely even if all this function does is the following, then the
test fails:

{
    LONG rc=SetWindowLongA(hwnd,nIndex,dwNewLong);
    SetWindowLongA(hwnd,nIndex,dwNewLong);
    return rc;
}

Comment out the second SetWindowLongA and it works. Why would calling
SetWindowLong a second time make any difference?


Here's the full patch, just change '#if 0' into '#if 1' to make the test
fail.


Index: dlls/user/tests/win.c
===================================================================
RCS file: /home/wine/wine/dlls/user/tests/win.c,v
retrieving revision 1.5
diff -u -r1.5 win.c
--- dlls/user/tests/win.c	15 Nov 2002 00:02:51 -0000	1.5
+++ dlls/user/tests/win.c	24 Dec 2002 03:16:36 -0000
@@ -45,6 +45,47 @@

 static HWND hwndMain, hwndMain2;

+static LONG test_set_window_long(HWND hwnd, int nIndex, LONG dwNewLong)
+{
+    LONG rc;
+
+    SetLastError(0);
+    rc=SetWindowLongW(hwnd,nIndex,dwNewLong);
+    if (rc==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED) {
+        rc=SetWindowLongA(hwnd,nIndex,dwNewLong);
+    }
+#if 0
+    else {
+        LONG set,get;
+        get=GetWindowLongW(hwnd,nIndex);
+        set=SetWindowLongA(hwnd,nIndex,dwNewLong);
+        ok(set==get,
+           "SetWindowLongA/W(%ld) failed: got %ld, expected %ld\n",
+           dwNewLong,set,get);
+    }
+#endif
+    return rc;
+}
+
+static LONG test_get_window_long(HWND hwnd, int nIndex)
+{
+    LONG rc;
+
+    SetLastError(0);
+    rc=GetWindowLongW(hwnd,nIndex);
+    if (rc==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED) {
+        rc=GetWindowLongA(hwnd,nIndex);
+    } else {
+        LONG rcA;
+        SetLastError(0);
+        rcA=GetWindowLongA(hwnd,nIndex);
+        ok(rc==rcA,
+           "GetWindowLongW failed: got %ld, expected %ld\n",
+           rc,rcA);
+    }
+    return rc;
+}
+
 /* check the values returned by the various parent/owner functions on a given window */
 static void check_parents( HWND hwnd, HWND ga_parent, HWND gwl_parent, HWND get_parent,
                            HWND gw_owner, HWND ga_root, HWND ga_root_owner )
@@ -56,7 +97,7 @@
         res = pGetAncestor( hwnd, GA_PARENT );
         ok( res == ga_parent, "Wrong result for GA_PARENT %p expected %p", res, ga_parent );
     }
-    res = (HWND)GetWindowLongW( hwnd, GWL_HWNDPARENT );
+    res = (HWND)test_get_window_long( hwnd, GWL_HWNDPARENT );
     ok( res == gwl_parent, "Wrong result for GWL_HWNDPARENT %p expected %p", res, gwl_parent );
     res = GetParent( hwnd );
     ok( res == get_parent, "Wrong result for GetParent %p expected %p", res, get_parent );
@@ -97,31 +138,31 @@

     /* desktop window */
     check_parents( desktop, 0, 0, 0, 0, 0, 0 );
-    style = GetWindowLongW( desktop, GWL_STYLE );
-    ok( !SetWindowLongW( desktop, GWL_STYLE, WS_POPUP ), "Set GWL_STYLE on desktop succeeded" );
-    ok( !SetWindowLongW( desktop, GWL_STYLE, 0 ), "Set GWL_STYLE on desktop succeeded" );
-    ok( GetWindowLongW( desktop, GWL_STYLE ) == style, "Desktop style changed" );
+    style = test_get_window_long( desktop, GWL_STYLE );
+    ok( !SetWindowLongA( desktop, GWL_STYLE, WS_POPUP ), "Set GWL_STYLE on desktop succeeded" );
+    ok( !SetWindowLongA( desktop, GWL_STYLE, 0 ), "Set GWL_STYLE on desktop succeeded" );
+    ok( test_get_window_long( desktop, GWL_STYLE ) == style, "Desktop style changed" );

     /* normal child window */
     test = create_tool_window( WS_CHILD, hwndMain );
     trace( "created child %p\n", test );
     check_parents( test, hwndMain, hwndMain, hwndMain, 0, hwndMain, hwndMain );
-    SetWindowLongW( test, GWL_STYLE, 0 );
+    test_set_window_long( test, GWL_STYLE, 0 );
     check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
-    SetWindowLongW( test, GWL_STYLE, WS_POPUP );
+    test_set_window_long( test, GWL_STYLE, WS_POPUP );
     check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
-    SetWindowLongW( test, GWL_STYLE, WS_POPUP|WS_CHILD );
+    test_set_window_long( test, GWL_STYLE, WS_POPUP|WS_CHILD );
     check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
-    SetWindowLongW( test, GWL_STYLE, WS_CHILD );
+    test_set_window_long( test, GWL_STYLE, WS_CHILD );
     DestroyWindow( test );

     /* child of desktop */
     test = create_tool_window( WS_CHILD, desktop );
     trace( "created child of desktop %p\n", test );
     check_parents( test, desktop, 0, desktop, 0, test, desktop );
-    SetWindowLongW( test, GWL_STYLE, WS_POPUP );
+    test_set_window_long( test, GWL_STYLE, WS_POPUP );
     check_parents( test, desktop, 0, 0, 0, test, test );
-    SetWindowLongW( test, GWL_STYLE, 0 );
+    test_set_window_long( test, GWL_STYLE, 0 );
     check_parents( test, desktop, 0, 0, 0, test, test );
     DestroyWindow( test );

@@ -129,9 +170,9 @@
     test = create_tool_window( WS_CHILD, child );
     trace( "created child of child %p\n", test );
     check_parents( test, child, child, child, 0, hwndMain, hwndMain );
-    SetWindowLongW( test, GWL_STYLE, 0 );
+    test_set_window_long( test, GWL_STYLE, 0 );
     check_parents( test, child, child, 0, 0, hwndMain, test );
-    SetWindowLongW( test, GWL_STYLE, WS_POPUP );
+    test_set_window_long( test, GWL_STYLE, WS_POPUP );
     check_parents( test, child, child, 0, 0, hwndMain, test );
     DestroyWindow( test );

@@ -139,9 +180,9 @@
     test = create_tool_window( 0, 0 );
     trace( "created top-level %p\n", test );
     check_parents( test, desktop, 0, 0, 0, test, test );
-    SetWindowLongW( test, GWL_STYLE, WS_POPUP );
+    test_set_window_long( test, GWL_STYLE, WS_POPUP );
     check_parents( test, desktop, 0, 0, 0, test, test );
-    SetWindowLongW( test, GWL_STYLE, WS_CHILD );
+    test_set_window_long( test, GWL_STYLE, WS_CHILD );
     check_parents( test, desktop, 0, desktop, 0, test, desktop );
     DestroyWindow( test );

@@ -149,9 +190,9 @@
     test = create_tool_window( 0, hwndMain );
     trace( "created owned top-level %p\n", test );
     check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
-    SetWindowLongW( test, GWL_STYLE, WS_POPUP );
+    test_set_window_long( test, GWL_STYLE, WS_POPUP );
     check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
-    SetWindowLongW( test, GWL_STYLE, WS_CHILD );
+    test_set_window_long( test, GWL_STYLE, WS_CHILD );
     check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
     DestroyWindow( test );

@@ -159,9 +200,9 @@
     test = create_tool_window( WS_POPUP, 0 );
     trace( "created popup %p\n", test );
     check_parents( test, desktop, 0, 0, 0, test, test );
-    SetWindowLongW( test, GWL_STYLE, WS_CHILD );
+    test_set_window_long( test, GWL_STYLE, WS_CHILD );
     check_parents( test, desktop, 0, desktop, 0, test, desktop );
-    SetWindowLongW( test, GWL_STYLE, 0 );
+    test_set_window_long( test, GWL_STYLE, 0 );
     check_parents( test, desktop, 0, 0, 0, test, test );
     DestroyWindow( test );

@@ -169,9 +210,9 @@
     test = create_tool_window( WS_POPUP, hwndMain );
     trace( "created owned popup %p\n", test );
     check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
-    SetWindowLongW( test, GWL_STYLE, WS_CHILD );
+    test_set_window_long( test, GWL_STYLE, WS_CHILD );
     check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
-    SetWindowLongW( test, GWL_STYLE, 0 );
+    test_set_window_long( test, GWL_STYLE, 0 );
     check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
     DestroyWindow( test );

@@ -210,7 +251,7 @@

     /* desktop window */
     check_parents( desktop, 0, 0, 0, 0, 0, 0 );
-    ret = (HWND)SetWindowLongW( test, GWL_HWNDPARENT, (LONG_PTR)hwndMain2 );
+    ret = (HWND)test_set_window_long( test, GWL_HWNDPARENT, (LONG_PTR)hwndMain2 );
     ok( !ret, "Set GWL_HWNDPARENT succeeded on desktop" );
     check_parents( desktop, 0, 0, 0, 0, 0, 0 );
     ok( !SetParent( desktop, hwndMain ), "SetParent succeeded on desktop" );
@@ -220,24 +261,24 @@
     test = create_tool_window( WS_CHILD, hwndMain );
     trace( "created child %p\n", test );

-    ret = (HWND)SetWindowLongW( test, GWL_HWNDPARENT, (LONG_PTR)hwndMain2 );
+    ret = (HWND)test_set_window_long( test, GWL_HWNDPARENT, (LONG_PTR)hwndMain2 );
     ok( ret == hwndMain, "GWL_HWNDPARENT return value %p expected %p", ret, hwndMain );
     check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );

-    ret = (HWND)SetWindowLongW( test, GWL_HWNDPARENT, (LONG_PTR)child );
+    ret = (HWND)test_set_window_long( test, GWL_HWNDPARENT, (LONG_PTR)child );
     ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p", ret, hwndMain2 );
     check_parents( test, child, child, child, 0, hwndMain, hwndMain );

-    ret = (HWND)SetWindowLongW( test, GWL_HWNDPARENT, (LONG_PTR)desktop );
+    ret = (HWND)test_set_window_long( test, GWL_HWNDPARENT, (LONG_PTR)desktop );
     ok( ret == child, "GWL_HWNDPARENT return value %p expected %p", ret, child );
     check_parents( test, desktop, 0, desktop, 0, test, desktop );

     /* window is now child of desktop so GWL_HWNDPARENT changes owner from now on */
-    ret = (HWND)SetWindowLongW( test, GWL_HWNDPARENT, (LONG_PTR)child );
+    ret = (HWND)test_set_window_long( test, GWL_HWNDPARENT, (LONG_PTR)child );
     ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0", ret );
     check_parents( test, desktop, child, desktop, child, test, desktop );

-    ret = (HWND)SetWindowLongW( test, GWL_HWNDPARENT, 0 );
+    ret = (HWND)test_set_window_long( test, GWL_HWNDPARENT, 0 );
     ok( ret == child, "GWL_HWNDPARENT return value %p expected %p", ret, child );
     check_parents( test, desktop, 0, desktop, 0, test, desktop );
     DestroyWindow( test );
@@ -246,15 +287,15 @@
     test = create_tool_window( 0, 0 );
     trace( "created top-level %p\n", test );

-    ret = (HWND)SetWindowLongW( test, GWL_HWNDPARENT, (LONG_PTR)hwndMain2 );
+    ret = (HWND)test_set_window_long( test, GWL_HWNDPARENT, (LONG_PTR)hwndMain2 );
     ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0", ret );
     check_parents( test, desktop, hwndMain2, 0, hwndMain2, test, test );

-    ret = (HWND)SetWindowLongW( test, GWL_HWNDPARENT, (LONG_PTR)child );
+    ret = (HWND)test_set_window_long( test, GWL_HWNDPARENT, (LONG_PTR)child );
     ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p", ret, hwndMain2 );
     check_parents( test, desktop, child, 0, child, test, test );

-    ret = (HWND)SetWindowLongW( test, GWL_HWNDPARENT, 0 );
+    ret = (HWND)test_set_window_long( test, GWL_HWNDPARENT, 0 );
     ok( ret == child, "GWL_HWNDPARENT return value %p expected %p", ret, child );
     check_parents( test, desktop, 0, 0, 0, test, test );
     DestroyWindow( test );
@@ -263,15 +304,15 @@
     test = create_tool_window( WS_POPUP, 0 );
     trace( "created popup %p\n", test );

-    ret = (HWND)SetWindowLongW( test, GWL_HWNDPARENT, (LONG_PTR)hwndMain2 );
+    ret = (HWND)test_set_window_long( test, GWL_HWNDPARENT, (LONG_PTR)hwndMain2 );
     ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0", ret );
     check_parents( test, desktop, hwndMain2, hwndMain2, hwndMain2, test, hwndMain2 );

-    ret = (HWND)SetWindowLongW( test, GWL_HWNDPARENT, (LONG_PTR)child );
+    ret = (HWND)test_set_window_long( test, GWL_HWNDPARENT, (LONG_PTR)child );
     ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p", ret, hwndMain2 );
     check_parents( test, desktop, child, child, child, test, hwndMain );

-    ret = (HWND)SetWindowLongW( test, GWL_HWNDPARENT, 0 );
+    ret = (HWND)test_set_window_long( test, GWL_HWNDPARENT, 0 );
     ok( ret == child, "GWL_HWNDPARENT return value %p expected %p", ret, child );
     check_parents( test, desktop, 0, 0, 0, test, test );
     DestroyWindow( test );
@@ -310,7 +351,7 @@
     ok( ret == desktop, "SetParent return value %p expected %p", ret, desktop );
     check_parents( test, child, child, hwndMain2, hwndMain2, hwndMain, hwndMain2 );

-    ret = (HWND)SetWindowLongW( test, GWL_HWNDPARENT, (ULONG_PTR)hwndMain );
+    ret = (HWND)test_set_window_long( test, GWL_HWNDPARENT, (ULONG_PTR)hwndMain );
     ok( ret == child, "GWL_HWNDPARENT return value %p expected %p", ret, child );
     check_parents( test, hwndMain, hwndMain, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
     DestroyWindow( test );
@@ -343,7 +384,7 @@
     owner = create_tool_window( WS_CHILD, hwndMain2 );
     test = create_tool_window( WS_POPUP, 0 );
     trace( "created owner %p and popup %p\n", owner, test );
-    ret = (HWND)SetWindowLongW( test, GWL_HWNDPARENT, (ULONG_PTR)owner );
+    ret = (HWND)test_set_window_long( test, GWL_HWNDPARENT, (ULONG_PTR)owner );
     ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0", ret );
     check_parents( test, desktop, owner, owner, owner, test, hwndMain2 );
     DestroyWindow( owner );



-- 
Francois Gouget         fgouget at free.fr        http://fgouget.free.fr/
            Before you criticize someone, walk a mile in his shoes.
       That way, if he gets angry, he'll be a mile away - and barefoot.




More information about the wine-devel mailing list