5288104c27d3fb20d6e4574cb9e099866d29dea8
[reactos.git] / rostests / apitests / user32 / WndProc.c
1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for mismatch with function prototype in window procedure callback.
5 * PROGRAMMERS:
6 */
7
8 #include <wine/test.h>
9 #include <wingdi.h>
10 #include <winuser.h>
11
12 /* Used wine Redraw test for proof in principle. */
13
14 /* Global variables to trigger exit from loop */
15 static int redrawComplete, WMPAINT_count;
16
17 /*
18 Force stack corruption when calling from assumed window procedure callback.
19 Adding (6 and) more will force exception faults and terminate the test program.
20 The test is with five and this is safe for windows.
21
22 But,,,, ReactOS compiled with GCC can handle this,,,,,,
23 */
24 static LRESULT WINAPI redraw_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam, DWORD ExtraData,DWORD ExtraData1,DWORD ExtraData2,DWORD ExtraData3)
25 {
26 switch (msg)
27 {
28 case WM_PAINT:
29 trace("doing WM_PAINT %d\n", WMPAINT_count);
30 WMPAINT_count++;
31 if (WMPAINT_count > 10 && redrawComplete == 0)
32 {
33 PAINTSTRUCT ps;
34 BeginPaint(hwnd, &ps);
35 EndPaint(hwnd, &ps);
36 return 1;
37 }
38 /*
39 This will force one stack corruption "ret" fault with normal window
40 procedure callback.
41 */
42 #ifdef __MINGW32__
43 asm ("movl $0, %eax\n\t"
44 "leave\n\t"
45 "ret");
46 #elif defined(_M_IX86)
47 //#ifdef _MSC_VER
48 __asm
49 {
50 mov eax, 0
51 leave
52 ret
53 }
54 #else
55 trace("unimplemented\n");
56 #endif
57 }
58 return DefWindowProc(hwnd, msg, wparam, lparam);
59 }
60
61 static void test_wndproc(void)
62 {
63 WNDCLASSA cls;
64 HWND hwndMain;
65
66 cls.style = CS_DBLCLKS;
67 cls.lpfnWndProc = (WNDPROC)redraw_window_procA;
68 cls.cbClsExtra = 0;
69 cls.cbWndExtra = 0;
70 cls.hInstance = GetModuleHandleA(0);
71 cls.hIcon = 0;
72 cls.hCursor = LoadCursorA(0, IDC_ARROW);
73 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
74 cls.lpszMenuName = NULL;
75 cls.lpszClassName = "RedrawWindowClass";
76
77 if (!RegisterClassA(&cls))
78 {
79 trace("Register failed %d\n", (int)GetLastError());
80 return;
81 }
82
83 hwndMain = CreateWindowA("RedrawWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
84 CW_USEDEFAULT, 0, 100, 100, NULL, NULL, 0, NULL);
85
86 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
87 ShowWindow(hwndMain, SW_SHOW);
88 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
89 RedrawWindow(hwndMain, NULL,NULL,RDW_UPDATENOW | RDW_ALLCHILDREN);
90 ok( WMPAINT_count == 1 || broken(WMPAINT_count == 0), /* sometimes on win9x */
91 "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
92 redrawComplete = TRUE;
93 ok( WMPAINT_count < 10, "RedrawWindow (RDW_UPDATENOW) never completed (%d)\n", WMPAINT_count);
94
95 /* clean up */
96 DestroyWindow( hwndMain);
97 }
98
99 START_TEST(WndProc)
100 {
101 test_wndproc();
102 }