Better implementation of GetCalendarInfo{A,W}, not perfect.
[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 #include "winbase.h"
24 #include "winreg.h"
25 #include "wingdi.h"
26 #include "winuser.h"
27 #include "wine/test.h"
28
29 #define NUMCLASSWORDS 4
30
31 LRESULT WINAPI ClassTest_WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
32 {
33     return DefWindowProcW (hWnd, msg, wParam, lParam);
34 }
35
36 /***********************************************************************
37  *
38  *           WinMain
39  */
40 BOOL ClassTest(HINSTANCE hInstance, BOOL global)
41 {
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];
48
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;
59
60     ok(RegisterClassW (&cls) ,
61         "failed to register class");
62
63     ok(!RegisterClassW (&cls),
64         "RegisterClass of the same class should fail for the second time");
65
66 #if 0
67     /* these succeeds on Wine, but shouldn't cause any trouble ... */
68     ok(!GlobalFindAtomW(className),
69         "Found class as global atom");
70
71     ok(!FindAtomW(className),
72         "Found class as global atom");
73 #endif
74
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);
80
81     ok(hTestWnd,
82         "Failed to create window");
83
84     /* test initial values of valid classwords */
85     for(i=0; i<NUMCLASSWORDS; i++)
86     {
87         SetLastError(0);
88         ok(!GetClassLongW(hTestWnd,i*sizeof (DWORD)),
89             "GetClassLongW initial value nonzero!");
90         ok(!GetLastError(),
91             "GetClassLongW failed!");
92     }
93
94 #if 0
95     /*
96      *  GetClassLongW(hTestWnd, NUMCLASSWORDS*sizeof(DWORD))
97      *  does not fail on Win 98, though MSDN says it should
98      */
99     SetLastError(0);
100     GetClassLongW(hTestWnd, NUMCLASSWORDS*sizeof(DWORD));
101     ok(GetLastError(),
102         "GetClassLongW() with invalid offset did not fail");
103 #endif
104
105     /* set values of valid class words */
106     for(i=0; i<NUMCLASSWORDS; i++)
107     {
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!");
113     }
114
115     /* test values of valid classwords that we set */
116     for(i=0; i<NUMCLASSWORDS; i++)
117     {
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!");
123     }
124
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");
131
132     /* check GetClassInfo with our hInstance */
133     if(GetClassInfoW(hInstance, str, &wc))
134     {
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");
145     }
146     else
147         ok(FALSE,"GetClassInfo (hinstance) failed!");
148
149     /* check GetClassInfo with zero hInstance */
150     if(global)
151     {
152         if(GetClassInfoW(0, str, &wc))
153         {
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");
164         }
165         else
166             ok(FALSE,"GetClassInfo (0) failed for global class!");
167     }
168     else
169     {
170         ok(!GetClassInfoW(0, str, &wc),
171             "GetClassInfo (0) succeeded for local class!");
172     }
173
174     ok(!UnregisterClassW(className, hInstance),
175         "Unregister class succeeded with window existing");
176
177     ok(DestroyWindow(hTestWnd),
178         "DestroyWindow() failed!");
179
180     ok(UnregisterClassW(className, hInstance),
181         "UnregisterClass() failed");
182
183     return TRUE;
184 }
185
186 START_TEST(class)
187 {
188     HANDLE hInstance = GetModuleHandleA( NULL );
189
190     ClassTest(hInstance,FALSE);
191     ClassTest(hInstance,TRUE);
192 }