ReactOS  0.4.14-dev-1112-g2b067d6
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 {
30  switch (msg)
31  {
32  case WM_PAINT:
33  break;
34  WMPAINT_count++;
35  trace("Doing WM_PAINT %d/%d\n", WMPAINT_count, WMPAINT_COUNT_THRESHOLD);
36 
38  {
39  PAINTSTRUCT ps;
40 
41  trace("Calling *Paint()\n");
42  BeginPaint(hwnd, &ps);
43  EndPaint(hwnd, &ps);
44  return 1;
45  }
46 
47  // This will force one stack corruption "ret" fault with normal window
48  // procedure callback.
49 #ifdef __MINGW32__
50  trace("Executing __MINGW32__ stack corruption code\n");
51  asm ("movl $0, %eax\n\t"
52  "leave\n\t"
53  "ret");
54 #elif defined(_M_IX86)
55 //#ifdef _MSC_VER
56  trace("Executing MSVC x86 stack corruption code\n");
57  __asm
58  {
59  mov eax, 0
60  leave
61  ret
62  }
63 #else
64  ok(FALSE, "FIXME: stack corruption code is unimplemented\n");
65 #endif
66 
67  break;
68  default:
69  trace("Doing empty default: msg = %u\n", msg);
70  }
71 
72  trace("Calling DefWindowProc()\n");
73  return DefWindowProc(hwnd, msg, wparam, lparam);
74 }
75 
76 static void test_wndproc(void)
77 {
78  WNDCLASSA cls;
79  ATOM clsAtom;
80  HWND hwndMain;
81 
82  cls.style = CS_DBLCLKS;
84  cls.cbClsExtra = 0;
85  cls.cbWndExtra = 0;
87  cls.hIcon = NULL;
90  cls.lpszMenuName = NULL;
91  cls.lpszClassName = "RedrawWindowClass";
92 
93  clsAtom = RegisterClassA(&cls);
94  ok(clsAtom != 0, "RegisterClassA() failed: LastError = %lu\n", GetLastError());
95 
96  if (clsAtom == 0)
97  {
98  skip("No Class atom\n");
99  return;
100  }
101 
103  CW_USEDEFAULT, 0, 100, 100, NULL, NULL, NULL, NULL);
104 
105  ok(hwndMain != NULL, "CreateWindowA() failed: LastError = %lu\n", GetLastError());
106 
107  ok(WMPAINT_count == 0,
108  "Multiple unexpected WM_PAINT calls = %d\n", WMPAINT_count);
109 
110  if (hwndMain == NULL)
111  {
112  skip("No Window\n");
114  "UnregisterClassA() failed: LastError = %lu\n", GetLastError());
115  return;
116  }
117 
119  ok(WMPAINT_count == 0,
120  "Multiple unexpected WM_PAINT calls = %d\n", WMPAINT_count);
121 
123  ok(WMPAINT_count == 1 || broken(WMPAINT_count == 0), /* sometimes on win9x */
124  "Multiple unexpected WM_PAINT calls = %d\n", WMPAINT_count);
125 
128  "RedrawWindow (RDW_UPDATENOW) never completed (%d/%d)\n",
130 
131  ok(DestroyWindow(hwndMain) != 0,
132  "DestroyWindow() failed: LastError = %lu\n", GetLastError());
133 
135  "UnregisterClassA() failed: LastError = %lu\n", GetLastError());
136 }
137 
139 {
140 #ifdef __RUNTIME_CHECKS__
141  skip("This test breaks MSVC runtime checks!\n");
142  return;
143 #endif /* __RUNTIME_CHECKS__ */
144 
145  test_wndproc();
146 }
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:3140
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
LPCSTR lpszMenuName
Definition: winuser.h:3146
#define WHITE_BRUSH
Definition: wingdi.h:901
UINT_PTR WPARAM
Definition: windef.h:207
HBRUSH hbrBackground
Definition: winuser.h:3145
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:3141
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:4290
HCURSOR hCursor
Definition: winuser.h:3144
#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:138
#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:6
#define WM_PAINT
Definition: winuser.h:1602
int ret
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:821
#define CS_DBLCLKS
Definition: winuser.h:646
LPCSTR lpszClassName
Definition: winuser.h:3147
HCURSOR WINAPI LoadCursorA(_In_opt_ HINSTANCE, _In_ LPCSTR)
Definition: cursoricon.c:2059
#define broken(x)
Definition: _sntprintf.h:21
UINT style
Definition: winuser.h:3138
LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
Definition: solitaire.cpp:598
static LRESULT WINAPI redraw_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
Definition: WndProc.c:24
HINSTANCE hInstance
Definition: winuser.h:3142
#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:3139
#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:76
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:3143