ReactOS  0.4.14-dev-55-g2da92ac
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 #define WMPAINT_COUNT_THRESHOLD 10
13 
14 /* Global variables to trigger exit from loop */
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  */
25  HWND hwnd,
26  UINT msg,
27  WPARAM wparam,
28  LPARAM lparam,
29  DWORD ExtraData,
30  DWORD ExtraData1,
31  DWORD ExtraData2,
32  DWORD ExtraData3)
33 {
34  switch (msg)
35  {
36  case WM_PAINT:
37  WMPAINT_count++;
38  trace("Doing WM_PAINT %d/%d\n", WMPAINT_count, WMPAINT_COUNT_THRESHOLD);
39 
41  {
42  PAINTSTRUCT ps;
43 
44  trace("Calling *Paint()\n");
45  BeginPaint(hwnd, &ps);
46  EndPaint(hwnd, &ps);
47  return 1;
48  }
49 
50  // This will force one stack corruption "ret" fault with normal window
51  // procedure callback.
52 #ifdef __MINGW32__
53  trace("Executing __MINGW32__ stack corruption code\n");
54  asm ("movl $0, %eax\n\t"
55  "leave\n\t"
56  "ret");
57 #elif defined(_M_IX86)
58 //#ifdef _MSC_VER
59  trace("Executing MSVC x86 stack corruption code\n");
60  __asm
61  {
62  mov eax, 0
63  leave
64  ret
65  }
66 #else
67  ok(FALSE, "FIXME: stack corruption code is unimplemented\n");
68 #endif
69 
70  break;
71  default:
72  trace("Doing empty default: msg = %u\n", msg);
73  }
74 
75  trace("Calling DefWindowProc()\n");
76  return DefWindowProc(hwnd, msg, wparam, lparam);
77 }
78 
79 static void test_wndproc(void)
80 {
81  WNDCLASSA cls;
82  ATOM clsAtom;
83  HWND hwndMain;
84 
85  cls.style = CS_DBLCLKS;
87  cls.cbClsExtra = 0;
88  cls.cbWndExtra = 0;
90  cls.hIcon = NULL;
93  cls.lpszMenuName = NULL;
94  cls.lpszClassName = "RedrawWindowClass";
95 
96  clsAtom = RegisterClassA(&cls);
97  ok(clsAtom != 0, "RegisterClassA() failed: LastError = %lu\n", GetLastError());
98 
99  if (clsAtom == 0)
100  {
101  skip("No Class atom\n");
102  return;
103  }
104 
106  CW_USEDEFAULT, 0, 100, 100, NULL, NULL, NULL, NULL);
107  ok(hwndMain != NULL, "CreateWindowA() failed: LastError = %lu\n", GetLastError());
108 
109  ok(WMPAINT_count == 0,
110  "Multiple unexpected WM_PAINT calls = %d\n", WMPAINT_count);
111 
112  if (hwndMain == NULL)
113  {
114  skip("No Window\n");
116  "UnregisterClassA() failed: LastError = %lu\n", GetLastError());
117  return;
118  }
119 
121  ok(WMPAINT_count == 0,
122  "Multiple unexpected WM_PAINT calls = %d\n", WMPAINT_count);
123 
125  ok(WMPAINT_count == 1 || broken(WMPAINT_count == 0), /* sometimes on win9x */
126  "Multiple unexpected WM_PAINT calls = %d\n", WMPAINT_count);
127 
130  "RedrawWindow (RDW_UPDATENOW) never completed (%d/%d)\n",
132 
133  ok(DestroyWindow(hwndMain) != 0,
134  "DestroyWindow() failed: LastError = %lu\n", GetLastError());
135 
137  "UnregisterClassA() failed: LastError = %lu\n", GetLastError());
138 }
139 
141 {
142 #ifdef __RUNTIME_CHECKS__
143  skip("This test breaks MSVC runtime checks!\n");
144  return;
145 #endif /* __RUNTIME_CHECKS__ */
146 
147  test_wndproc();
148 }
HGDIOBJ WINAPI GetStockObject(_In_ int)
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
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:15
HWND hwndMain
Definition: solitaire.cpp:12
WORD ATOM
Definition: dimm.idl:113
static int redrawComplete
Definition: WndProc.c:15
int cbClsExtra
Definition: winuser.h:3139
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
LPCSTR lpszMenuName
Definition: winuser.h:3145
#define WHITE_BRUSH
Definition: wingdi.h:901
UINT_PTR WPARAM
Definition: windef.h:207
HBRUSH hbrBackground
Definition: winuser.h:3144
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:3140
HDC WINAPI BeginPaint(_In_ HWND, _Out_ LPPAINTSTRUCT)
static UINT WPARAM LPARAM lparam
Definition: combo.c:716
#define CreateWindowA(a, b, c, d, e, f, g, h, i, j, k)
Definition: winuser.h:4216
HCURSOR hCursor
Definition: winuser.h:3143
#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:140
#define trace
Definition: atltest.h:70
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:24
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:821
#define CS_DBLCLKS
Definition: winuser.h:646
LPCSTR lpszClassName
Definition: winuser.h:3146
HCURSOR WINAPI LoadCursorA(_In_opt_ HINSTANCE, _In_ LPCSTR)
Definition: cursoricon.c:2059
#define broken(x)
Definition: _sntprintf.h:21
UINT style
Definition: winuser.h:3137
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:2880
HINSTANCE hInstance
Definition: winuser.h:3141
#define RDW_ALLCHILDREN
Definition: winuser.h:1207
#define ok(value,...)
Definition: atltest.h:57
unsigned int UINT
Definition: ndis.h:50
WNDPROC lpfnWndProc
Definition: winuser.h:3138
#define skip(...)
Definition: atltest.h:64
#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:79
BOOL WINAPI UnregisterClassA(_In_ LPCSTR, HINSTANCE)
LONG_PTR LRESULT
Definition: windef.h:209
#define WMPAINT_COUNT_THRESHOLD
Definition: WndProc.c:12
ATOM WINAPI RegisterClassA(_In_ CONST WNDCLASSA *)
static UINT WPARAM wparam
Definition: combo.c:716
HICON hIcon
Definition: winuser.h:3142