Added a simple test set for window classes.
[wine/testsucceed.git] / dlls / user / tests / class.c
blobd964750080ab08a8b872ca97c65281fb24221c5f
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
20 #include <assert.h>
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include "winbase.h"
24 #include "winreg.h"
25 #include "wingdi.h"
26 #include "winuser.h"
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 /***********************************************************************
38 * WinMain
40 BOOL ClassTest(HINSTANCE hInstance, BOOL global)
42 WNDCLASSW cls, wc;
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};
45 HWND hTestWnd;
46 DWORD i;
47 WCHAR str[20];
49 cls.style = CS_HREDRAW | CS_VREDRAW | (global?CS_GLOBALCLASS:0);
50 cls.lpfnWndProc = ClassTest_WndProc;
51 cls.cbClsExtra = NUMCLASSWORDS*sizeof(DWORD);
52 cls.cbWndExtra = 12;
53 cls.hInstance = hInstance;
54 cls.hIcon = LoadIconW (0, IDI_APPLICATIONW);
55 cls.hCursor = LoadCursorW (0, IDC_ARROWW);
56 cls.hbrBackground = GetStockObject (WHITE_BRUSH);
57 cls.lpszMenuName = 0;
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");
66 #if 0
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");
73 #endif
75 /* Setup windows */
76 hTestWnd = CreateWindowW (className, winName,
77 WS_OVERLAPPEDWINDOW + WS_HSCROLL + WS_VSCROLL,
78 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, 0,
79 0, hInstance, 0);
81 ok(hTestWnd,
82 "Failed to create window");
84 /* test initial values of valid classwords */
85 for(i=0; i<NUMCLASSWORDS; i++)
87 SetLastError(0);
88 ok(!GetClassLongW(hTestWnd,i*sizeof (DWORD)),
89 "GetClassLongW initial value nonzero!");
90 ok(!GetLastError(),
91 "GetClassLongW failed!");
94 #if 0
96 * GetClassLongW(hTestWnd, NUMCLASSWORDS*sizeof(DWORD))
97 * does not fail on Win 98, though MSDN says it should
99 SetLastError(0);
100 GetClassLongW(hTestWnd, NUMCLASSWORDS*sizeof(DWORD));
101 ok(GetLastError(),
102 "GetClassLongW() with invalid offset did not fail");
103 #endif
105 /* set values of valid class words */
106 for(i=0; i<NUMCLASSWORDS; i++)
108 SetLastError(0);
109 ok(!SetClassLongW(hTestWnd,i*sizeof(DWORD),i+1),
110 "GetClassLongW(%d) initial value nonzero!");
111 ok(!GetLastError(),
112 "SetClassLongW(%d) failed!");
115 /* test values of valid classwords that we set */
116 for(i=0; i<NUMCLASSWORDS; i++)
118 SetLastError(0);
119 ok( (i+1) == GetClassLongW(hTestWnd,i*sizeof (DWORD)),
120 "GetClassLongW value doesn't match what was set!");
121 ok(!GetLastError(),
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");
146 else
147 ok(FALSE,"GetClassInfo (hinstance) failed!");
149 /* check GetClassInfo with zero hInstance */
150 if(global)
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");
162 ok(!wc.hInstance,
163 "hInstance not zero for global class %x");
165 else
166 ok(FALSE,"GetClassInfo (0) failed for global class!");
168 else
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");
183 return TRUE;
186 START_TEST(class)
188 HANDLE hInstance = GetModuleHandleA( NULL );
190 ClassTest(hInstance,FALSE);
191 ClassTest(hInstance,TRUE);