1 /* Unit test suite for window classes.
3 * Copyright 2002 Mike McCormack
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "wine/test.h"
32 #define NUMCLASSWORDS 4
34 LRESULT WINAPI
ClassTest_WndProc (HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
36 return DefWindowProcW (hWnd
, msg
, wParam
, lParam
);
39 /***********************************************************************
43 void ClassTest(HINSTANCE hInstance
, BOOL global
)
46 WCHAR className
[] = {'T','e','s','t','C','l','a','s','s',0};
47 WCHAR winName
[] = {'W','i','n','C','l','a','s','s','T','e','s','t',0};
54 cls
.style
= CS_HREDRAW
| CS_VREDRAW
| (global
?CS_GLOBALCLASS
:0);
55 cls
.lpfnWndProc
= ClassTest_WndProc
;
56 cls
.cbClsExtra
= NUMCLASSWORDS
*sizeof(DWORD
);
58 cls
.hInstance
= hInstance
;
59 cls
.hIcon
= LoadIconW (0, (LPWSTR
)IDI_APPLICATION
);
60 cls
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
61 cls
.hbrBackground
= GetStockObject (WHITE_BRUSH
);
63 cls
.lpszClassName
= className
;
65 classatom
=RegisterClassW(&cls
);
66 if (!classatom
&& GetLastError()==ERROR_CALL_NOT_IMPLEMENTED
)
68 ok(classatom
, "failed to register class");
70 ok(!RegisterClassW (&cls
),
71 "RegisterClass of the same class should fail for the second time");
74 /* these succeeds on Wine, but shouldn't cause any trouble ... */
75 ok(!GlobalFindAtomW(className
),
76 "Found class as global atom");
78 ok(!FindAtomW(className
),
79 "Found class as global atom");
83 hTestWnd
= CreateWindowW (className
, winName
,
84 WS_OVERLAPPEDWINDOW
+ WS_HSCROLL
+ WS_VSCROLL
,
85 CW_USEDEFAULT
, 0, CW_USEDEFAULT
, 0, 0,
88 ok(hTestWnd
!=0, "Failed to create window");
90 /* test initial values of valid classwords */
91 for(i
=0; i
<NUMCLASSWORDS
; i
++)
94 ok(!GetClassLongW(hTestWnd
,i
*sizeof (DWORD
)),
95 "GetClassLongW initial value nonzero!");
97 "GetClassLongW failed!");
102 * GetClassLongW(hTestWnd, NUMCLASSWORDS*sizeof(DWORD))
103 * does not fail on Win 98, though MSDN says it should
106 GetClassLongW(hTestWnd
, NUMCLASSWORDS
*sizeof(DWORD
));
108 "GetClassLongW() with invalid offset did not fail");
111 /* set values of valid class words */
112 for(i
=0; i
<NUMCLASSWORDS
; i
++)
115 ok(!SetClassLongW(hTestWnd
,i
*sizeof(DWORD
),i
+1),
116 "GetClassLongW(%ld) initial value nonzero!",i
*sizeof(DWORD
));
118 "SetClassLongW(%ld) failed!",i
*sizeof(DWORD
));
121 /* test values of valid classwords that we set */
122 for(i
=0; i
<NUMCLASSWORDS
; i
++)
125 ok( (i
+1) == GetClassLongW(hTestWnd
,i
*sizeof (DWORD
)),
126 "GetClassLongW value doesn't match what was set!");
128 "GetClassLongW failed!");
131 /* check GetClassName */
132 i
= GetClassNameW(hTestWnd
, str
, sizeof(str
));
133 ok(i
== lstrlenW(className
),
134 "GetClassName returned incorrect length");
135 ok(!lstrcmpW(className
,str
),
136 "GetClassName returned incorrect name for this window's class");
138 /* check GetClassInfo with our hInstance */
139 if((test_atom
= GetClassInfoW(hInstance
, str
, &wc
)))
141 ok(test_atom
== classatom
,
142 "class atom did not match");
143 ok(wc
.cbClsExtra
== cls
.cbClsExtra
,
144 "cbClsExtra did not match");
145 ok(wc
.cbWndExtra
== cls
.cbWndExtra
,
146 "cbWndExtra did not match");
147 ok(wc
.hbrBackground
== cls
.hbrBackground
,
148 "hbrBackground did not match");
149 ok(wc
.hCursor
== cls
.hCursor
,
150 "hCursor did not match");
151 ok(wc
.hInstance
== cls
.hInstance
,
152 "hInstance did not match");
155 ok(FALSE
,"GetClassInfo (hinstance) failed!");
157 /* check GetClassInfo with zero hInstance */
160 if((test_atom
= GetClassInfoW(0, str
, &wc
)))
162 ok(test_atom
== classatom
,
163 "class atom did not match %x != %x", test_atom
, classatom
);
164 ok(wc
.cbClsExtra
== cls
.cbClsExtra
,
165 "cbClsExtra did not match %x!=%x",wc
.cbClsExtra
,cls
.cbClsExtra
);
166 ok(wc
.cbWndExtra
== cls
.cbWndExtra
,
167 "cbWndExtra did not match %x!=%x",wc
.cbWndExtra
,cls
.cbWndExtra
);
168 ok(wc
.hbrBackground
== cls
.hbrBackground
,
169 "hbrBackground did not match %p!=%p",wc
.hbrBackground
,cls
.hbrBackground
);
170 ok(wc
.hCursor
== cls
.hCursor
,
171 "hCursor did not match %p!=%p",wc
.hCursor
,cls
.hCursor
);
173 "hInstance not zero for global class %p",wc
.hInstance
);
176 ok(FALSE
,"GetClassInfo (0) failed for global class!");
180 ok(!GetClassInfoW(0, str
, &wc
),
181 "GetClassInfo (0) succeeded for local class!");
184 ok(!UnregisterClassW(className
, hInstance
),
185 "Unregister class succeeded with window existing");
187 ok(DestroyWindow(hTestWnd
),
188 "DestroyWindow() failed!");
190 ok(UnregisterClassW(className
, hInstance
),
191 "UnregisterClass() failed");
198 HANDLE hInstance
= GetModuleHandleA( NULL
);
200 ClassTest(hInstance
,FALSE
);
201 ClassTest(hInstance
,TRUE
);