[USER32_APITEST] RedrawWindow: Add a DestroyWindow() call (#423)
[reactos.git] / modules / rostests / apitests / user32 / RedrawWindow.c
1 /*
2 * PROJECT: ReactOS API tests
3 * LICENSE: LGPL-2.1+ (https://spdx.org/licenses/LGPL-2.1+)
4 * PURPOSE: Test for RedrawWindow
5 * COPYRIGHT: Copyright 2018 Thomas Faber <thomas.faber@reactos.org>
6 */
7
8 #include "precomp.h"
9
10 static DWORD dwThreadId;
11 static BOOL got_paint;
12
13 static
14 LRESULT
15 CALLBACK
16 WndProc(
17 _In_ HWND hWnd,
18 _In_ UINT message,
19 _In_ WPARAM wParam,
20 _In_ LPARAM lParam)
21 {
22 ok(GetCurrentThreadId() == dwThreadId, "Thread 0x%lx instead of 0x%lx\n", GetCurrentThreadId(), dwThreadId);
23 if (message == WM_PAINT)
24 {
25 got_paint = TRUE;
26 }
27 return DefWindowProcW(hWnd, message, wParam, lParam);
28 }
29
30
31 START_TEST(RedrawWindow)
32 {
33 HWND hWnd;
34 MSG msg;
35 HRGN hRgn;
36 BOOL ret;
37 int i;
38
39 SetCursorPos(0,0);
40
41 dwThreadId = GetCurrentThreadId();
42 RegisterSimpleClass(WndProc, L"CreateTest");
43
44 hWnd = CreateWindowExW(0, L"CreateTest", NULL, 0, 10, 10, 20, 20, NULL, NULL, 0, NULL);
45 ok(hWnd != NULL, "CreateWindow failed\n");
46
47 ShowWindow(hWnd, SW_SHOW);
48
49 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
50 {
51 DispatchMessageA( &msg );
52 }
53
54 ok(got_paint == TRUE, "Did not process WM_PAINT message\n");
55 got_paint = FALSE;
56
57 hRgn = CreateRectRgn(0, 0, 1, 1);
58 ok(hRgn != NULL, "CreateRectRgn failed\n");
59 ret = RedrawWindow(hWnd, NULL, hRgn, RDW_INTERNALPAINT | RDW_INVALIDATE);
60 ok(ret == TRUE, "RedrawWindow failed\n");
61
62 i = 0;
63 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
64 {
65 RECORD_MESSAGE(1, msg.message, POST, 0, 0);
66 if (msg.message == WM_PAINT)
67 {
68 i++;
69 if (i == 10)
70 {
71 ok(got_paint == FALSE, "Received unexpected WM_PAINT message\n");
72 }
73 }
74 if (msg.message != WM_PAINT || i >= 10)
75 {
76 DispatchMessageA( &msg );
77 }
78 }
79
80 ok(i == 10, "Received %d WM_PAINT messages\n", i);
81 ok(got_paint == TRUE, "Did not process WM_PAINT message\n");
82
83 TRACE_CACHE();
84
85 DeleteObject(hRgn);
86 DestroyWindow(hWnd);
87 }