Add missing files
[reactos.git] / rostests / apitests / user32 / RealGetWindowClass.c
1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for RealGetWindowClass
5 * PROGRAMMERS: Gregor Gullwi
6 */
7
8 #include <stdio.h>
9 #include <wine/test.h>
10 #include <windows.h>
11
12 #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
13
14 typedef struct _TestData
15 {
16 BOOL OverrideWndProc; /* TRUE if lpfnWndProc should be overridden */
17 LPCSTR ClassName; /* Name of the new class to register */
18 DWORD WndExtra; /* Remove these WNDCLASS::cbWndExtra flags */
19 BOOL ExpectsHwnd; /* TRUE if a HWND should be created to run tests on */
20 LPCSTR ExpectedClassNameBefore; /* Expected class name before any dialog function is called */
21 LPCSTR ExpectedClassNameAfter; /* Expected class name after any dialog function is called */
22 } TestData;
23
24 static TestData RealClassTestData[] =
25 {
26 {
27 TRUE,
28 "OverrideWndProc_with_DLGWINDOWEXTRA_TRUE",
29 0,
30 TRUE,
31 "OverrideWndProc_with_DLGWINDOWEXTRA_TRUE",
32 "#32770",
33 },
34 {
35 TRUE,
36 "OverrideWndProc_without_DLGWINDOWEXTRA_TRUE",
37 DLGWINDOWEXTRA,
38 TRUE,
39 "OverrideWndProc_without_DLGWINDOWEXTRA_TRUE",
40 "OverrideWndProc_without_DLGWINDOWEXTRA_TRUE",
41 },
42 {
43 FALSE,
44 "DefaultWndProc_with_DLGWINDOWEXTRA_FALSE",
45 0,
46 TRUE,
47 "#32770",
48 "#32770",
49 },
50 {
51 FALSE,
52 "DefaultWndProc_without_DLGWINDOWEXTRA_FALSE",
53 DLGWINDOWEXTRA,
54 FALSE,
55 "N/A",
56 "N/A",
57 },
58 };
59
60 void Test_RealGetWindowClass()
61 {
62 int testNo;
63 UINT Result;
64 CHAR Buffer[1024];
65
66 Result = RealGetWindowClass( NULL, Buffer, ARRAY_SIZE(Buffer) );
67 ok(Result == 0, "Result = %d\n", Result);
68 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "GetLastError() = %ld\n", GetLastError());
69
70 for (testNo = 0; testNo < ARRAY_SIZE(RealClassTestData); testNo++)
71 {
72 ATOM atom;
73 WNDCLASSA cls;
74 HWND hWnd;
75
76 /* Register classes, "derived" from built-in dialog, with and without the DLGWINDOWEXTRA flag set */
77 GetClassInfoA(0, "#32770", &cls);
78 if (RealClassTestData[testNo].OverrideWndProc)
79 cls.lpfnWndProc = DefWindowProcA;
80 cls.lpszClassName = RealClassTestData[testNo].ClassName;
81 cls.cbWndExtra &= ~RealClassTestData[testNo].WndExtra;
82 atom = RegisterClassA (&cls);
83 if (atom == 0) return;
84
85 /* Create a window */
86 hWnd = CreateWindowEx( WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR |
87 WS_EX_DLGMODALFRAME | WS_EX_WINDOWEDGE | WS_EX_CONTROLPARENT | WS_EX_APPWINDOW,
88 RealClassTestData[testNo].ClassName,
89 RealClassTestData[testNo].ClassName,
90 WS_POPUPWINDOW | WS_CLIPSIBLINGS | WS_DLGFRAME | WS_OVERLAPPED |
91 WS_MINIMIZEBOX | WS_MAXIMIZEBOX | DS_3DLOOK | DS_SETFONT | DS_MODALFRAME,
92 CW_USEDEFAULT, CW_USEDEFAULT, 100, 100,
93 NULL, NULL, 0, 0);
94
95 /* Do we expect a HWND at all? */
96 if (RealClassTestData[testNo].ExpectsHwnd)
97 {
98 ok(hWnd != NULL, "\n");
99
100 if (hWnd != NULL)
101 {
102 /* Get the "real" class name */
103 Result = RealGetWindowClass( hWnd, Buffer, ARRAY_SIZE(Buffer) );
104 printf("Buffer: %s\nExpectedClassNameBefore(%d): %s\n", Buffer, testNo, RealClassTestData[testNo].ExpectedClassNameBefore);
105 ok( Result != 0, "\n" );
106 ok( strcmp( Buffer, RealClassTestData[testNo].ExpectedClassNameBefore ) == 0, "\n" );
107
108 /* Call a function that requires a dialog window */
109 DefDlgProcA( hWnd, DM_SETDEFID, IDCANCEL, 0 );
110
111 /* Get the "real" class name again */
112 Result = RealGetWindowClass( hWnd, Buffer, ARRAY_SIZE(Buffer) );
113 printf("Buffer: %s\nExpectedClassNameAfter(%d): %s\n", Buffer, testNo, RealClassTestData[testNo].ExpectedClassNameAfter);
114 ok( Result != 0, "\n" );
115 ok( strcmp( Buffer, RealClassTestData[testNo].ExpectedClassNameAfter ) == 0, "\n" );
116 }
117 }
118 else
119 {
120 ok(hWnd == NULL, "\n");
121 }
122
123 /* Cleanup */
124 DestroyWindow(hWnd);
125 UnregisterClass(RealClassTestData[testNo].ClassName, 0);
126 }
127
128 }
129
130 START_TEST(RealGetWindowClass)
131 {
132 Test_RealGetWindowClass();
133 }
134