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
27 #include "wine/test.h"
29 #define NUMCLASSWORDS 4
31 LRESULT WINAPI ClassTest_WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
33 return DefWindowProcW (hWnd, msg, wParam, lParam);
36 /***********************************************************************
40 BOOL ClassTest(HINSTANCE hInstance, BOOL global)
43 WCHAR className[] = {'T','e','s','t','C','l','a','s','s',0};
44 WCHAR winName[] = {'W','i','n','C','l','a','s','s','T','e','s','t',0};
49 cls.style = CS_HREDRAW | CS_VREDRAW | (global?CS_GLOBALCLASS:0);
50 cls.lpfnWndProc = ClassTest_WndProc;
51 cls.cbClsExtra = NUMCLASSWORDS*sizeof(DWORD);
53 cls.hInstance = hInstance;
54 cls.hIcon = LoadIconW (0, IDI_APPLICATIONW);
55 cls.hCursor = LoadCursorW (0, IDC_ARROWW);
56 cls.hbrBackground = GetStockObject (WHITE_BRUSH);
58 cls.lpszClassName = className;
60 ok(RegisterClassW (&cls) ,
61 "failed to register class");
63 ok(!RegisterClassW (&cls),
64 "RegisterClass of the same class should fail for the second time");
67 /* these succeeds on Wine, but shouldn't cause any trouble ... */
68 ok(!GlobalFindAtomW(className),
69 "Found class as global atom");
71 ok(!FindAtomW(className),
72 "Found class as global atom");
76 hTestWnd = CreateWindowW (className, winName,
77 WS_OVERLAPPEDWINDOW + WS_HSCROLL + WS_VSCROLL,
78 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, 0,
82 "Failed to create window");
84 /* test initial values of valid classwords */
85 for(i=0; i<NUMCLASSWORDS; i++)
88 ok(!GetClassLongW(hTestWnd,i*sizeof (DWORD)),
89 "GetClassLongW initial value nonzero!");
91 "GetClassLongW failed!");
96 * GetClassLongW(hTestWnd, NUMCLASSWORDS*sizeof(DWORD))
97 * does not fail on Win 98, though MSDN says it should
100 GetClassLongW(hTestWnd, NUMCLASSWORDS*sizeof(DWORD));
102 "GetClassLongW() with invalid offset did not fail");
105 /* set values of valid class words */
106 for(i=0; i<NUMCLASSWORDS; i++)
109 ok(!SetClassLongW(hTestWnd,i*sizeof(DWORD),i+1),
110 "GetClassLongW(%d) initial value nonzero!");
112 "SetClassLongW(%d) failed!");
115 /* test values of valid classwords that we set */
116 for(i=0; i<NUMCLASSWORDS; i++)
119 ok( (i+1) == GetClassLongW(hTestWnd,i*sizeof (DWORD)),
120 "GetClassLongW value doesn't match what was set!");
122 "GetClassLongW failed!");
125 /* check GetClassName */
126 i = GetClassNameW(hTestWnd, str, sizeof str);
127 ok(i == lstrlenW(className),
128 "GetClassName returned incorrect length");
129 ok(!lstrcmpW(className,str),
130 "GetClassName returned incorrect name for this window's class");
132 /* check GetClassInfo with our hInstance */
133 if(GetClassInfoW(hInstance, str, &wc))
135 ok(wc.cbClsExtra == cls.cbClsExtra,
136 "cbClsExtra did not match");
137 ok(wc.cbWndExtra == cls.cbWndExtra,
138 "cbWndExtra did not match");
139 ok(wc.hbrBackground == cls.hbrBackground,
140 "hbrBackground did not match");
141 ok(wc.hCursor== cls.hCursor,
142 "hCursor did not match");
143 ok(wc.hInstance== cls.hInstance,
144 "hInstance did not match");
147 ok(FALSE,"GetClassInfo (hinstance) failed!");
149 /* check GetClassInfo with zero hInstance */
152 if(GetClassInfoW(0, str, &wc))
154 ok(wc.cbClsExtra == cls.cbClsExtra,
155 "cbClsExtra did not match %x!=%x");
156 ok(wc.cbWndExtra == cls.cbWndExtra,
157 "cbWndExtra did not match %x!=%x");
158 ok(wc.hbrBackground == cls.hbrBackground,
159 "hbrBackground did not match %x!=%x");
160 ok(wc.hCursor== cls.hCursor,
161 "hCursor did not match %x!=%x");
163 "hInstance not zero for global class %x");
166 ok(FALSE,"GetClassInfo (0) failed for global class!");
170 ok(!GetClassInfoW(0, str, &wc),
171 "GetClassInfo (0) succeeded for local class!");
174 ok(!UnregisterClassW(className, hInstance),
175 "Unregister class succeeded with window existing");
177 ok(DestroyWindow(hTestWnd),
178 "DestroyWindow() failed!");
180 ok(UnregisterClassW(className, hInstance),
181 "UnregisterClass() failed");
188 HANDLE hInstance = GetModuleHandleA( NULL );
190 ClassTest(hInstance,FALSE);
191 ClassTest(hInstance,TRUE);