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