Added regedit unit test, a couple minor changes to regedit.
[wine] / dlls / user / tests / class.c
1 /* Unit test suite for window classes.
2  *
3  * Copyright 2002 Mike McCormack
4  *
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.
9  *
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.
14  *
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
18  */
19
20 #include <assert.h>
21 #include <stdlib.h>
22 #include <stdio.h>
23
24 #include "wine/test.h"
25 #include "winbase.h"
26 #include "winreg.h"
27 #include "wingdi.h"
28 #include "winuser.h"
29
30 #define NUMCLASSWORDS 4
31
32 LRESULT WINAPI ClassTest_WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
33 {
34     return DefWindowProcW (hWnd, msg, wParam, lParam);
35 }
36
37 /***********************************************************************
38  *
39  *           WinMain
40  */
41 BOOL ClassTest(HINSTANCE hInstance, BOOL global)
42 {
43     WNDCLASSW cls, wc;
44     WCHAR className[] = {'T','e','s','t','C','l','a','s','s',0};
45     WCHAR winName[]   = {'W','i','n','C','l','a','s','s','T','e','s','t',0};
46     HWND hTestWnd;
47     DWORD i;
48     WCHAR str[20];
49
50     cls.style         = CS_HREDRAW | CS_VREDRAW | (global?CS_GLOBALCLASS:0);
51     cls.lpfnWndProc   = ClassTest_WndProc;
52     cls.cbClsExtra    = NUMCLASSWORDS*sizeof(DWORD);
53     cls.cbWndExtra    = 12;
54     cls.hInstance     = hInstance;
55     cls.hIcon         = LoadIconW (0, IDI_APPLICATIONW);
56     cls.hCursor       = LoadCursorW (0, IDC_ARROWW);
57     cls.hbrBackground = GetStockObject (WHITE_BRUSH);
58     cls.lpszMenuName  = 0;
59     cls.lpszClassName = className;
60
61     ok(RegisterClassW (&cls) ,
62         "failed to register class");
63
64     ok(!RegisterClassW (&cls),
65         "RegisterClass of the same class should fail for the second time");
66
67 #if 0
68     /* these succeeds on Wine, but shouldn't cause any trouble ... */
69     ok(!GlobalFindAtomW(className),
70         "Found class as global atom");
71
72     ok(!FindAtomW(className),
73         "Found class as global atom");
74 #endif
75
76     /* Setup windows */
77     hTestWnd = CreateWindowW (className, winName,
78        WS_OVERLAPPEDWINDOW + WS_HSCROLL + WS_VSCROLL,
79        CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, 0,
80        0, hInstance, 0);
81
82     ok(hTestWnd,
83         "Failed to create window");
84
85     /* test initial values of valid classwords */
86     for(i=0; i<NUMCLASSWORDS; i++)
87     {
88         SetLastError(0);
89         ok(!GetClassLongW(hTestWnd,i*sizeof (DWORD)),
90             "GetClassLongW initial value nonzero!");
91         ok(!GetLastError(),
92             "GetClassLongW failed!");
93     }
94
95 #if 0
96     /*
97      *  GetClassLongW(hTestWnd, NUMCLASSWORDS*sizeof(DWORD))
98      *  does not fail on Win 98, though MSDN says it should
99      */
100     SetLastError(0);
101     GetClassLongW(hTestWnd, NUMCLASSWORDS*sizeof(DWORD));
102     ok(GetLastError(),
103         "GetClassLongW() with invalid offset did not fail");
104 #endif
105
106     /* set values of valid class words */
107     for(i=0; i<NUMCLASSWORDS; i++)
108     {
109         SetLastError(0);
110         ok(!SetClassLongW(hTestWnd,i*sizeof(DWORD),i+1),
111             "GetClassLongW(%d) initial value nonzero!");
112         ok(!GetLastError(),
113             "SetClassLongW(%d) failed!");
114     }
115
116     /* test values of valid classwords that we set */
117     for(i=0; i<NUMCLASSWORDS; i++)
118     {
119         SetLastError(0);
120         ok( (i+1) == GetClassLongW(hTestWnd,i*sizeof (DWORD)),
121             "GetClassLongW value doesn't match what was set!");
122         ok(!GetLastError(),
123             "GetClassLongW failed!");
124     }
125
126     /* check GetClassName */
127     i = GetClassNameW(hTestWnd, str, sizeof str);
128     ok(i == lstrlenW(className),
129         "GetClassName returned incorrect length");
130     ok(!lstrcmpW(className,str),
131         "GetClassName returned incorrect name for this window's class");
132
133     /* check GetClassInfo with our hInstance */
134     if(GetClassInfoW(hInstance, str, &wc))
135     {
136         ok(wc.cbClsExtra == cls.cbClsExtra,
137             "cbClsExtra did not match");
138         ok(wc.cbWndExtra == cls.cbWndExtra,
139             "cbWndExtra did not match");
140         ok(wc.hbrBackground == cls.hbrBackground,
141             "hbrBackground did not match");
142         ok(wc.hCursor== cls.hCursor,
143             "hCursor did not match");
144         ok(wc.hInstance== cls.hInstance,
145             "hInstance did not match");
146     }
147     else
148         ok(FALSE,"GetClassInfo (hinstance) failed!");
149
150     /* check GetClassInfo with zero hInstance */
151     if(global)
152     {
153         if(GetClassInfoW(0, str, &wc))
154         {
155             ok(wc.cbClsExtra == cls.cbClsExtra,
156                 "cbClsExtra did not match %x!=%x");
157             ok(wc.cbWndExtra == cls.cbWndExtra,
158                 "cbWndExtra did not match %x!=%x");
159             ok(wc.hbrBackground == cls.hbrBackground,
160                 "hbrBackground did not match %x!=%x");
161             ok(wc.hCursor== cls.hCursor,
162                 "hCursor did not match %x!=%x");
163             ok(!wc.hInstance,
164                 "hInstance not zero for global class %x");
165         }
166         else
167             ok(FALSE,"GetClassInfo (0) failed for global class!");
168     }
169     else
170     {
171         ok(!GetClassInfoW(0, str, &wc),
172             "GetClassInfo (0) succeeded for local class!");
173     }
174
175     ok(!UnregisterClassW(className, hInstance),
176         "Unregister class succeeded with window existing");
177
178     ok(DestroyWindow(hTestWnd),
179         "DestroyWindow() failed!");
180
181     ok(UnregisterClassW(className, hInstance),
182         "UnregisterClass() failed");
183
184     return TRUE;
185 }
186
187 START_TEST(class)
188 {
189     HANDLE hInstance = GetModuleHandleA( NULL );
190
191     ClassTest(hInstance,FALSE);
192     ClassTest(hInstance,TRUE);
193 }