ReactOS 0.4.15-dev-7712-gbbbcd8e
msg.h
Go to the documentation of this file.
1/* Message Sequence Testing Code
2 *
3 * Copyright (C) 2007 James Hawkins
4 * Copyright (C) 2007 Lei Zhang
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21#pragma once
22
23#include <assert.h>
24#include <windows.h>
25
26#include "wine/heap.h"
27#include "wine/test.h"
28
29/* undocumented SWP flags - from SDK 3.1 */
30#define SWP_NOCLIENTSIZE 0x0800
31#define SWP_NOCLIENTMOVE 0x1000
32
33typedef enum
34{
35 sent = 0x1,
36 posted = 0x2,
37 parent = 0x4,
38 wparam = 0x8,
39 lparam = 0x10,
40 defwinproc = 0x20,
41 beginpaint = 0x40,
42 optional = 0x80,
43 hook = 0x100,
45 id = 0x400
47
48struct message
49{
50 UINT message; /* the WM_* code */
51 msg_flags_t flags; /* message props */
52 WPARAM wParam; /* expected value of wParam */
53 LPARAM lParam; /* expected value of lParam */
54 UINT id; /* extra message data: id of the window,
55 notify code etc. */
56};
57
58struct msg_sequence
59{
60 int count;
61 int size;
62 struct message *sequence;
63};
64
65static void add_message(struct msg_sequence **seq, int sequence_index,
66 const struct message *msg)
67{
68 struct msg_sequence *msg_seq = seq[sequence_index];
69
70 if (!msg_seq->sequence)
71 {
72 msg_seq->size = 10;
73 msg_seq->sequence = heap_alloc(msg_seq->size * sizeof (struct message));
74 }
75
76 if (msg_seq->count == msg_seq->size)
77 {
78 msg_seq->size *= 2;
79 msg_seq->sequence = heap_realloc(msg_seq->sequence, msg_seq->size * sizeof (struct message));
80 }
81
82 assert(msg_seq->sequence);
83
84 msg_seq->sequence[msg_seq->count].message = msg->message;
85 msg_seq->sequence[msg_seq->count].flags = msg->flags;
86 msg_seq->sequence[msg_seq->count].wParam = msg->wParam;
87 msg_seq->sequence[msg_seq->count].lParam = msg->lParam;
88 msg_seq->sequence[msg_seq->count].id = msg->id;
89
90 msg_seq->count++;
91}
92
93static void flush_sequence(struct msg_sequence **seg, int sequence_index)
94{
95 struct msg_sequence *msg_seq = seg[sequence_index];
96 heap_free(msg_seq->sequence);
97 msg_seq->sequence = NULL;
98 msg_seq->count = msg_seq->size = 0;
99}
100
101static void flush_sequences(struct msg_sequence **seq, int n)
102{
103 int i;
104
105 for (i = 0; i < n; i++)
106 flush_sequence(seq, i);
107}
108
109static void ok_sequence_(struct msg_sequence **seq, int sequence_index,
110 const struct message *expected, const char *context, BOOL todo,
111 const char *file, int line)
112{
113 struct msg_sequence *msg_seq = seq[sequence_index];
114 static const struct message end_of_sequence = {0, 0, 0, 0};
115 const struct message *actual, *sequence;
116 int failcount = 0;
117
118 add_message(seq, sequence_index, &end_of_sequence);
119
120 sequence = msg_seq->sequence;
121 actual = sequence;
122
123 while (expected->message && actual->message)
124 {
125 trace_( file, line)("expected %04x - actual %04x\n", expected->message, actual->message);
126
127 if (expected->message == actual->message)
128 {
129 if (expected->flags & wparam)
130 {
131 if (expected->wParam != actual->wParam && todo)
132 {
134 {
135 failcount++;
136 ok_(file, line) (FALSE,
137 "%s: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
138 context, expected->message, expected->wParam, actual->wParam);
139 }
140 }
141 else
142 {
143 ok_(file, line) (expected->wParam == actual->wParam,
144 "%s: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
145 context, expected->message, expected->wParam, actual->wParam);
146 }
147 }
148
149 if (expected->flags & lparam)
150 {
151 if (expected->lParam != actual->lParam && todo)
152 {
154 {
155 failcount++;
156 ok_(file, line) (FALSE,
157 "%s: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
158 context, expected->message, expected->lParam, actual->lParam);
159 }
160 }
161 else
162 {
163 ok_(file, line) (expected->lParam == actual->lParam,
164 "%s: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
165 context, expected->message, expected->lParam, actual->lParam);
166 }
167 }
168
169 if (expected->flags & id)
170 {
171 if (expected->id != actual->id && expected->flags & optional)
172 {
173 expected++;
174 continue;
175 }
176 if (expected->id != actual->id && todo)
177 {
179 {
180 failcount++;
181 ok_(file, line) (FALSE,
182 "%s: in msg 0x%04x expecting id 0x%x got 0x%x\n",
183 context, expected->message, expected->id, actual->id);
184 }
185 }
186 else
187 {
188 ok_(file, line) (expected->id == actual->id,
189 "%s: in msg 0x%04x expecting id 0x%x got 0x%x\n",
190 context, expected->message, expected->id, actual->id);
191 }
192 }
193
194 if ((expected->flags & defwinproc) != (actual->flags & defwinproc) && todo)
195 {
197 {
198 failcount++;
199 ok_(file, line) (FALSE,
200 "%s: the msg 0x%04x should %shave been sent by DefWindowProc\n",
201 context, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
202 }
203 }
204 else
205 {
206 ok_(file, line) ((expected->flags & defwinproc) == (actual->flags & defwinproc),
207 "%s: the msg 0x%04x should %shave been sent by DefWindowProc\n",
208 context, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
209 }
210
211 ok_(file, line) ((expected->flags & beginpaint) == (actual->flags & beginpaint),
212 "%s: the msg 0x%04x should %shave been sent by BeginPaint\n",
213 context, expected->message, (expected->flags & beginpaint) ? "" : "NOT ");
214 ok_(file, line) ((expected->flags & (sent|posted)) == (actual->flags & (sent|posted)),
215 "%s: the msg 0x%04x should have been %s\n",
216 context, expected->message, (expected->flags & posted) ? "posted" : "sent");
217 ok_(file, line) ((expected->flags & parent) == (actual->flags & parent),
218 "%s: the msg 0x%04x was expected in %s\n",
219 context, expected->message, (expected->flags & parent) ? "parent" : "child");
220 ok_(file, line) ((expected->flags & hook) == (actual->flags & hook),
221 "%s: the msg 0x%04x should have been sent by a hook\n",
222 context, expected->message);
223 ok_(file, line) ((expected->flags & winevent_hook) == (actual->flags & winevent_hook),
224 "%s: the msg 0x%04x should have been sent by a winevent hook\n",
225 context, expected->message);
226 expected++;
227 actual++;
228 }
229 else if (expected->flags & optional)
230 expected++;
231 else if (todo)
232 {
233 failcount++;
235 {
236 ok_(file, line) (FALSE, "%s: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
237 context, expected->message, actual->message);
238 }
239
240 flush_sequence(seq, sequence_index);
241 return;
242 }
243 else
244 {
245 ok_(file, line) (FALSE, "%s: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
246 context, expected->message, actual->message);
247 expected++;
248 actual++;
249 }
250 }
251
252 /* skip all optional trailing messages */
253 while (expected->message && ((expected->flags & optional)))
254 expected++;
255
256 if (todo)
257 {
259 {
260 if (expected->message || actual->message)
261 {
262 failcount++;
263 ok_(file, line) (FALSE, "%s: the msg sequence is not complete: expected %04x - actual %04x\n",
264 context, expected->message, actual->message);
265 }
266 }
267 }
268 else if (expected->message || actual->message)
269 {
270 ok_(file, line) (FALSE, "%s: the msg sequence is not complete: expected %04x - actual %04x\n",
271 context, expected->message, actual->message);
272 }
273
274 if(todo && !failcount) /* succeeded yet marked todo */
275 {
277 {
278 ok_(file, line)(TRUE, "%s: marked \"todo_wine\" but succeeds\n", context);
279 }
280 }
281
282 flush_sequence(seq, sequence_index);
283}
284
285#define ok_sequence(seq, index, exp, contx, todo) \
286 ok_sequence_(seq, index, (exp), (contx), (todo), __FILE__, __LINE__)
287
288
289static void init_msg_sequences(struct msg_sequence **seq, int n)
290{
291 int i;
292
293 for (i = 0; i < n; i++)
294 seq[i] = heap_alloc_zero(sizeof(struct msg_sequence));
295}
msg_flags_t
Definition: SystemMenu.c:26
#define add_message(msg)
Definition: SystemMenu.c:98
static void flush_sequence(void)
Definition: SystemMenu.c:184
static struct recvd_message * sequence
Definition: SystemMenu.c:63
static void * heap_alloc(size_t len)
Definition: appwiz.h:66
static BOOL heap_free(void *mem)
Definition: appwiz.h:76
static void * heap_realloc(void *mem, size_t len)
Definition: appwiz.h:71
#define ok_(x1, x2)
Definition: atltest.h:61
#define msg(x)
Definition: auth_time.c:54
msg_flags_t
Definition: msg.h:33
@ sent
Definition: msg.h:34
@ beginpaint
Definition: msg.h:40
@ defwinproc
Definition: msg.h:39
@ parent
Definition: msg.h:36
@ posted
Definition: msg.h:35
@ lparam
Definition: msg.h:38
@ hook
Definition: msg.h:42
@ winevent_hook
Definition: msg.h:43
@ wparam
Definition: msg.h:37
@ optional
Definition: msg.h:41
static void init_msg_sequences(struct msg_sequence **seq, int n)
Definition: msg.h:391
static void ok_sequence_(struct msg_sequence **seq, int sequence_index, const struct message *expected_list, const char *context, BOOL todo, const char *file, int line)
Definition: msg.h:167
static void flush_sequences(struct msg_sequence **seq, int n)
Definition: msg.h:97
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define assert(x)
Definition: debug.h:53
unsigned int BOOL
Definition: ntddk_ex.h:94
GLdouble n
Definition: glext.h:7729
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define trace_(file, line,...)
Definition: kmt_test.h:223
BOOL todo
Definition: filedlg.c:313
BOOL expected
Definition: store.c:2063
#define todo_wine
Definition: custom.c:79
unsigned int UINT
Definition: ndis.h:50
Definition: http.c:7252
Definition: fci.c:127
Definition: parser.c:49
Definition: tftpd.h:60
UINT id
Definition: msg.h:54
UINT message
Definition: SystemMenu.c:42
msg_flags_t flags
Definition: SystemMenu.c:43
struct message * sequence
Definition: msg.h:63
int count
Definition: msg.h:61
int size
Definition: msg.h:62
LONG_PTR LPARAM
Definition: windef.h:208
UINT_PTR WPARAM
Definition: windef.h:207
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList