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