shell32/tests: Enable compilation with long types.
[wine.git] / dlls / shell32 / tests / msg.h
bloba6c16ae05e61934aec8906d5b241d3d037d6d396
1 /* Message Sequence Testing Code
3 * Copyright (C) 2007 James Hawkins
4 * Copyright (C) 2007 Lei Zhang
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.
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.
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
21 #include <assert.h>
22 #include <windows.h>
24 #include "wine/heap.h"
25 #include "wine/test.h"
27 /* undocumented SWP flags - from SDK 3.1 */
28 #define SWP_NOCLIENTSIZE 0x0800
29 #define SWP_NOCLIENTMOVE 0x1000
31 typedef enum
33 sent = 0x1,
34 posted = 0x2,
35 parent = 0x4,
36 wparam = 0x8,
37 lparam = 0x10,
38 defwinproc = 0x20,
39 beginpaint = 0x40,
40 optional = 0x80,
41 hook = 0x100,
42 winevent_hook =0x200,
43 id = 0x400
44 } msg_flags_t;
46 struct message
48 UINT message; /* the WM_* code */
49 msg_flags_t flags; /* message props */
50 WPARAM wParam; /* expected value of wParam */
51 LPARAM lParam; /* expected value of lParam */
52 UINT id; /* extra message data: id of the window,
53 notify code etc. */
56 struct msg_sequence
58 int count;
59 int size;
60 struct message *sequence;
63 static void add_message(struct msg_sequence **seq, int sequence_index,
64 const struct message *msg)
66 struct msg_sequence *msg_seq = seq[sequence_index];
68 if (!msg_seq->sequence)
70 msg_seq->size = 10;
71 msg_seq->sequence = heap_alloc(msg_seq->size * sizeof (struct message));
74 if (msg_seq->count == msg_seq->size)
76 msg_seq->size *= 2;
77 msg_seq->sequence = heap_realloc(msg_seq->sequence, msg_seq->size * sizeof (struct message));
80 assert(msg_seq->sequence);
82 msg_seq->sequence[msg_seq->count].message = msg->message;
83 msg_seq->sequence[msg_seq->count].flags = msg->flags;
84 msg_seq->sequence[msg_seq->count].wParam = msg->wParam;
85 msg_seq->sequence[msg_seq->count].lParam = msg->lParam;
86 msg_seq->sequence[msg_seq->count].id = msg->id;
88 msg_seq->count++;
91 static void flush_sequence(struct msg_sequence **seg, int sequence_index)
93 struct msg_sequence *msg_seq = seg[sequence_index];
94 heap_free(msg_seq->sequence);
95 msg_seq->sequence = NULL;
96 msg_seq->count = msg_seq->size = 0;
99 static void flush_sequences(struct msg_sequence **seq, int n)
101 int i;
103 for (i = 0; i < n; i++)
104 flush_sequence(seq, i);
107 static void ok_sequence_(struct msg_sequence **seq, int sequence_index,
108 const struct message *expected, const char *context, BOOL todo,
109 const char *file, int line)
111 struct msg_sequence *msg_seq = seq[sequence_index];
112 static const struct message end_of_sequence = {0, 0, 0, 0};
113 const struct message *actual, *sequence;
114 int failcount = 0;
116 add_message(seq, sequence_index, &end_of_sequence);
118 sequence = msg_seq->sequence;
119 actual = sequence;
121 while (expected->message && actual->message)
123 trace_( file, line)("expected %04x - actual %04x\n", expected->message, actual->message);
125 if (expected->message == actual->message)
127 if (expected->flags & wparam)
129 if (expected->wParam != actual->wParam && todo)
131 todo_wine
133 failcount++;
134 ok_(file, line) (FALSE,
135 "%s: in msg 0x%04x expecting wParam 0x%Ix got 0x%Ix\n",
136 context, expected->message, expected->wParam, actual->wParam);
139 else
141 ok_(file, line) (expected->wParam == actual->wParam,
142 "%s: in msg 0x%04x expecting wParam 0x%Ix got 0x%Ix\n",
143 context, expected->message, expected->wParam, actual->wParam);
147 if (expected->flags & lparam)
149 if (expected->lParam != actual->lParam && todo)
151 todo_wine
153 failcount++;
154 ok_(file, line) (FALSE,
155 "%s: in msg 0x%04x expecting lParam 0x%Ix got 0x%Ix\n",
156 context, expected->message, expected->lParam, actual->lParam);
159 else
161 ok_(file, line) (expected->lParam == actual->lParam,
162 "%s: in msg 0x%04x expecting lParam 0x%Ix got 0x%Ix\n",
163 context, expected->message, expected->lParam, actual->lParam);
167 if (expected->flags & id)
169 if (expected->id != actual->id && expected->flags & optional)
171 expected++;
172 continue;
174 if (expected->id != actual->id && todo)
176 todo_wine
178 failcount++;
179 ok_(file, line) (FALSE,
180 "%s: in msg 0x%04x expecting id 0x%x got 0x%x\n",
181 context, expected->message, expected->id, actual->id);
184 else
186 ok_(file, line) (expected->id == actual->id,
187 "%s: in msg 0x%04x expecting id 0x%x got 0x%x\n",
188 context, expected->message, expected->id, actual->id);
192 if ((expected->flags & defwinproc) != (actual->flags & defwinproc) && todo)
194 todo_wine
196 failcount++;
197 ok_(file, line) (FALSE,
198 "%s: the msg 0x%04x should %shave been sent by DefWindowProc\n",
199 context, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
202 else
204 ok_(file, line) ((expected->flags & defwinproc) == (actual->flags & defwinproc),
205 "%s: the msg 0x%04x should %shave been sent by DefWindowProc\n",
206 context, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
209 ok_(file, line) ((expected->flags & beginpaint) == (actual->flags & beginpaint),
210 "%s: the msg 0x%04x should %shave been sent by BeginPaint\n",
211 context, expected->message, (expected->flags & beginpaint) ? "" : "NOT ");
212 ok_(file, line) ((expected->flags & (sent|posted)) == (actual->flags & (sent|posted)),
213 "%s: the msg 0x%04x should have been %s\n",
214 context, expected->message, (expected->flags & posted) ? "posted" : "sent");
215 ok_(file, line) ((expected->flags & parent) == (actual->flags & parent),
216 "%s: the msg 0x%04x was expected in %s\n",
217 context, expected->message, (expected->flags & parent) ? "parent" : "child");
218 ok_(file, line) ((expected->flags & hook) == (actual->flags & hook),
219 "%s: the msg 0x%04x should have been sent by a hook\n",
220 context, expected->message);
221 ok_(file, line) ((expected->flags & winevent_hook) == (actual->flags & winevent_hook),
222 "%s: the msg 0x%04x should have been sent by a winevent hook\n",
223 context, expected->message);
224 expected++;
225 actual++;
227 else if (expected->flags & optional)
228 expected++;
229 else if (todo)
231 failcount++;
232 todo_wine
234 ok_(file, line) (FALSE, "%s: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
235 context, expected->message, actual->message);
238 flush_sequence(seq, sequence_index);
239 return;
241 else
243 ok_(file, line) (FALSE, "%s: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
244 context, expected->message, actual->message);
245 expected++;
246 actual++;
250 /* skip all optional trailing messages */
251 while (expected->message && ((expected->flags & optional)))
252 expected++;
254 if (todo)
256 todo_wine
258 if (expected->message || actual->message)
260 failcount++;
261 ok_(file, line) (FALSE, "%s: the msg sequence is not complete: expected %04x - actual %04x\n",
262 context, expected->message, actual->message);
266 else if (expected->message || actual->message)
268 ok_(file, line) (FALSE, "%s: the msg sequence is not complete: expected %04x - actual %04x\n",
269 context, expected->message, actual->message);
272 if(todo && !failcount) /* succeeded yet marked todo */
274 todo_wine
276 ok_(file, line)(TRUE, "%s: marked \"todo_wine\" but succeeds\n", context);
280 flush_sequence(seq, sequence_index);
283 #define ok_sequence(seq, index, exp, contx, todo) \
284 ok_sequence_(seq, index, (exp), (contx), (todo), __FILE__, __LINE__)
287 static void init_msg_sequences(struct msg_sequence **seq, int n)
289 int i;
291 for (i = 0; i < n; i++)
292 seq[i] = heap_alloc_zero(sizeof(struct msg_sequence));