ReactOS  0.4.13-dev-257-gfabbd7c
WndProc.c
Go to the documentation of this file.
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 "precomp.h"
9 
10 /* Used wine Redraw test for proof in principle. */
11 
12 /* Global variables to trigger exit from loop */
14 
15 /*
16  Force stack corruption when calling from assumed window procedure callback.
17  Adding (6 and) more will force exception faults and terminate the test program.
18  The test is with five and this is safe for windows.
19 
20  But,,,, ReactOS compiled with GCC can handle this,,,,,,
21  */
22 static LRESULT WINAPI redraw_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam, DWORD ExtraData,DWORD ExtraData1,DWORD ExtraData2,DWORD ExtraData3)
23 {
24  switch (msg)
25  {
26  case WM_PAINT:
27  trace("doing WM_PAINT %d\n", WMPAINT_count);
28  WMPAINT_count++;
29  if (WMPAINT_count > 10 && redrawComplete == 0)
30  {
31  PAINTSTRUCT ps;
32  BeginPaint(hwnd, &ps);
33  EndPaint(hwnd, &ps);
34  return 1;
35  }
36  /*
37  This will force one stack corruption "ret" fault with normal window
38  procedure callback.
39  */
40 #ifdef __MINGW32__
41  asm ("movl $0, %eax\n\t"
42  "leave\n\t"
43  "ret");
44 #elif defined(_M_IX86)
45 //#ifdef _MSC_VER
46  __asm
47  {
48  mov eax, 0
49  leave
50  ret
51  }
52 #else
53  trace("unimplemented\n");
54 #endif
55  }
56  return DefWindowProc(hwnd, msg, wparam, lparam);
57 }
58 
59 static void test_wndproc(void)
60 {
61  WNDCLASSA cls;
62  HWND hwndMain;
63 
64  cls.style = CS_DBLCLKS;
66  cls.cbClsExtra = 0;
67  cls.cbWndExtra = 0;
68  cls.hInstance = GetModuleHandleA(0);
69  cls.hIcon = 0;
70  cls.hCursor = LoadCursorA(0, IDC_ARROW);
72  cls.lpszMenuName = NULL;
73  cls.lpszClassName = "RedrawWindowClass";
74 
75  if (!RegisterClassA(&cls))
76  {
77  trace("Register failed %d\n", (int)GetLastError());
78  return;
79  }
80 
81  hwndMain = CreateWindowA("RedrawWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
82  CW_USEDEFAULT, 0, 100, 100, NULL, NULL, 0, NULL);
83 
84  ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
86  ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
88  ok( WMPAINT_count == 1 || broken(WMPAINT_count == 0), /* sometimes on win9x */
89  "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
91  ok( WMPAINT_count < 10, "RedrawWindow (RDW_UPDATENOW) never completed (%d)\n", WMPAINT_count);
92 
93  /* clean up */
95 }
96 
98 {
99 #ifdef __RUNTIME_CHECKS__
100  skip("This test breaks MSVC runtime checks!");
101  return;
102 #endif /* __RUNTIME_CHECKS__ */
103  test_wndproc();
104 }
HGDIOBJ WINAPI GetStockObject(_In_ int)
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
#define trace(...)
Definition: kmt_test.h:217
BOOL WINAPI RedrawWindow(_In_opt_ HWND, _In_opt_ LPCRECT, _In_opt_ HRGN, _In_ UINT)
#define TRUE
Definition: types.h:120
static int WMPAINT_count
Definition: WndProc.c:13
HWND hwndMain
Definition: solitaire.cpp:12
static int redrawComplete
Definition: WndProc.c:13
int cbClsExtra
Definition: winuser.h:3118
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
LPCSTR lpszMenuName
Definition: winuser.h:3124
#define WHITE_BRUSH
Definition: wingdi.h:901
UINT_PTR WPARAM
Definition: windef.h:207
HBRUSH hbrBackground
Definition: winuser.h:3123
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
BOOL WINAPI EndPaint(_In_ HWND, _In_ const PAINTSTRUCT *)
BOOL WINAPI DestroyWindow(_In_ HWND)
int cbWndExtra
Definition: winuser.h:3119
HDC WINAPI BeginPaint(_In_ HWND, _Out_ LPPAINTSTRUCT)
static UINT WPARAM LPARAM lparam
Definition: combo.c:716
#define ok(value,...)
#define CreateWindowA(a, b, c, d, e, f, g, h, i, j, k)
Definition: winuser.h:4184
HCURSOR hCursor
Definition: winuser.h:3122
#define CW_USEDEFAULT
Definition: winuser.h:225
smooth NULL
Definition: ftsmooth.c:416
LONG_PTR LPARAM
Definition: windef.h:208
#define SW_SHOW
Definition: winuser.h:769
#define DefWindowProc
Definition: ros2win.h:31
START_TEST(WndProc)
Definition: WndProc.c:97
ecx edi ebx edx edi decl ecx esi eax jecxz decl eax andl eax esi movl eax
Definition: synth_sse3d.h:85
#define WINAPI
Definition: msvc.h:8
unsigned long DWORD
Definition: ntddk_ex.h:95
#define WM_PAINT
Definition: winuser.h:1602
int ret
static LRESULT WINAPI redraw_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam, DWORD ExtraData, DWORD ExtraData1, DWORD ExtraData2, DWORD ExtraData3)
Definition: WndProc.c:22
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:819
#define CS_DBLCLKS
Definition: winuser.h:646
LPCSTR lpszClassName
Definition: winuser.h:3125
HCURSOR WINAPI LoadCursorA(_In_opt_ HINSTANCE, _In_ LPCSTR)
Definition: cursoricon.c:2059
#define broken(x)
Definition: _sntprintf.h:21
UINT style
Definition: winuser.h:3116
LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
Definition: solitaire.cpp:598
LRESULT(CALLBACK * WNDPROC)(HWND, UINT, WPARAM, LPARAM)
Definition: winuser.h:2859
HINSTANCE hInstance
Definition: winuser.h:3120
#define RDW_ALLCHILDREN
Definition: winuser.h:1207
unsigned int UINT
Definition: ndis.h:50
WNDPROC lpfnWndProc
Definition: winuser.h:3117
#define skip(...)
#define msg(x)
Definition: auth_time.c:54
#define RDW_UPDATENOW
Definition: winuser.h:1206
#define IDC_ARROW
Definition: winuser.h:682
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
static void test_wndproc(void)
Definition: WndProc.c:59
LONG_PTR LRESULT
Definition: windef.h:209
ATOM WINAPI RegisterClassA(_In_ CONST WNDCLASSA *)
static UINT WPARAM wparam
Definition: combo.c:716
HICON hIcon
Definition: winuser.h:3121