Fixed header dependencies to be fully compatible with the Windows
[wine/multimedia.git] / dlls / user / tests / class.c
blob33508b2c9a92f0a60b77b57291e6dfb452cfbebd
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 <stdarg.h>
23 #include <stdio.h>
25 #include "wine/test.h"
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winreg.h"
29 #include "wingdi.h"
30 #include "winuser.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 /***********************************************************************
41 * WinMain
43 void ClassTest(HINSTANCE hInstance, BOOL global)
45 WNDCLASSW cls, wc;
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};
48 ATOM test_atom;
49 HWND hTestWnd;
50 DWORD i;
51 WCHAR str[20];
52 ATOM classatom;
54 cls.style = CS_HREDRAW | CS_VREDRAW | (global?CS_GLOBALCLASS:0);
55 cls.lpfnWndProc = ClassTest_WndProc;
56 cls.cbClsExtra = NUMCLASSWORDS*sizeof(DWORD);
57 cls.cbWndExtra = 12;
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);
62 cls.lpszMenuName = 0;
63 cls.lpszClassName = className;
65 classatom=RegisterClassW(&cls);
66 if (!classatom && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
67 return;
68 ok(classatom, "failed to register class");
70 ok(!RegisterClassW (&cls),
71 "RegisterClass of the same class should fail for the second time");
73 #if 0
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");
80 #endif
82 /* Setup windows */
83 hTestWnd = CreateWindowW (className, winName,
84 WS_OVERLAPPEDWINDOW + WS_HSCROLL + WS_VSCROLL,
85 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, 0,
86 0, hInstance, 0);
88 ok(hTestWnd!=0, "Failed to create window");
90 /* test initial values of valid classwords */
91 for(i=0; i<NUMCLASSWORDS; i++)
93 SetLastError(0);
94 ok(!GetClassLongW(hTestWnd,i*sizeof (DWORD)),
95 "GetClassLongW initial value nonzero!");
96 ok(!GetLastError(),
97 "GetClassLongW failed!");
100 #if 0
102 * GetClassLongW(hTestWnd, NUMCLASSWORDS*sizeof(DWORD))
103 * does not fail on Win 98, though MSDN says it should
105 SetLastError(0);
106 GetClassLongW(hTestWnd, NUMCLASSWORDS*sizeof(DWORD));
107 ok(GetLastError(),
108 "GetClassLongW() with invalid offset did not fail");
109 #endif
111 /* set values of valid class words */
112 for(i=0; i<NUMCLASSWORDS; i++)
114 SetLastError(0);
115 ok(!SetClassLongW(hTestWnd,i*sizeof(DWORD),i+1),
116 "GetClassLongW(%ld) initial value nonzero!",i*sizeof(DWORD));
117 ok(!GetLastError(),
118 "SetClassLongW(%ld) failed!",i*sizeof(DWORD));
121 /* test values of valid classwords that we set */
122 for(i=0; i<NUMCLASSWORDS; i++)
124 SetLastError(0);
125 ok( (i+1) == GetClassLongW(hTestWnd,i*sizeof (DWORD)),
126 "GetClassLongW value doesn't match what was set!");
127 ok(!GetLastError(),
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");
154 else
155 ok(FALSE,"GetClassInfo (hinstance) failed!");
157 /* check GetClassInfo with zero hInstance */
158 if(global)
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);
172 ok(!wc.hInstance,
173 "hInstance not zero for global class %p",wc.hInstance);
175 else
176 ok(FALSE,"GetClassInfo (0) failed for global class!");
178 else
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");
193 return;
196 START_TEST(class)
198 HANDLE hInstance = GetModuleHandleA( NULL );
200 ClassTest(hInstance,FALSE);
201 ClassTest(hInstance,TRUE);