msi: Call execute_script directly in InstallFinalize.
[wine.git] / dlls / comctl32 / tests / msg.h
blob3fa0fae311c5e255f165e3284a8fffbb4a2e2b66
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>
23 #include "wine/test.h"
25 /* undocumented SWP flags - from SDK 3.1 */
26 #define SWP_NOCLIENTSIZE 0x0800
27 #define SWP_NOCLIENTMOVE 0x1000
29 typedef enum
31 sent = 0x1,
32 posted = 0x2,
33 parent = 0x4,
34 wparam = 0x8,
35 lparam = 0x10,
36 defwinproc = 0x20,
37 beginpaint = 0x40,
38 optional = 0x80,
39 hook = 0x100,
40 winevent_hook =0x200,
41 id = 0x400,
42 custdraw = 0x800
43 } msg_flags_t;
45 struct message
47 UINT message; /* the WM_* code */
48 msg_flags_t flags; /* message props */
49 WPARAM wParam; /* expected value of wParam */
50 LPARAM lParam; /* expected value of lParam */
51 UINT id; /* extra message data: id of the window,
52 notify code etc. */
53 DWORD stage; /* custom draw stage */
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 = HeapAlloc(GetProcessHeap(), 0,
72 msg_seq->size * sizeof (struct message));
75 if (msg_seq->count == msg_seq->size)
77 msg_seq->size *= 2;
78 msg_seq->sequence = HeapReAlloc(GetProcessHeap(), 0,
79 msg_seq->sequence,
80 msg_seq->size * sizeof (struct message));
83 assert(msg_seq->sequence);
85 msg_seq->sequence[msg_seq->count] = *msg;
86 msg_seq->count++;
89 static inline void flush_sequence(struct msg_sequence **seg, int sequence_index)
91 struct msg_sequence *msg_seq = seg[sequence_index];
92 HeapFree(GetProcessHeap(), 0, msg_seq->sequence);
93 msg_seq->sequence = NULL;
94 msg_seq->count = msg_seq->size = 0;
97 static inline void flush_sequences(struct msg_sequence **seq, int n)
99 int i;
101 for (i = 0; i < n; i++)
102 flush_sequence(seq, i);
105 static void dump_sequence( struct msg_sequence **seq, int sequence_index,
106 const struct message *expected, const char *context,
107 const char *file, int line )
109 struct msg_sequence *msg_seq = seq[sequence_index];
110 const struct message *actual, *sequence;
111 unsigned int count = 0;
113 sequence = msg_seq->sequence;
114 actual = sequence;
116 trace_(file, line)("Failed sequence %s:\n", context );
117 while (expected->message && actual->message)
119 trace_(file, line)( " %u: expected: %04x - actual: %04x wp %08lx lp %08lx\n",
120 count, expected->message, actual->message, actual->wParam, actual->lParam );
122 if (expected->message == actual->message)
124 if ((expected->flags & defwinproc) != (actual->flags & defwinproc) &&
125 (expected->flags & optional))
127 /* don't match messages if their defwinproc status differs */
128 expected++;
130 else
132 expected++;
133 actual++;
136 else
138 expected++;
139 actual++;
141 count++;
144 /* optional trailing messages */
145 while (expected->message && expected->flags & optional)
147 trace_(file, line)( " %u: expected: msg %04x - actual: nothing\n", count, expected->message );
148 expected++;
149 count++;
152 if (expected->message)
154 trace_(file, line)( " %u: expected: msg %04x - actual: nothing\n", count, expected->message );
155 return;
158 while (actual->message)
160 trace_(file, line)( " %u: expected: nothing - actual: %04x wp %08lx lp %08lx\n",
161 count, actual->message, actual->wParam, actual->lParam );
162 actual++;
163 count++;
167 static void ok_sequence_(struct msg_sequence **seq, int sequence_index,
168 const struct message *expected, const char *context, BOOL todo,
169 const char *file, int line)
171 struct msg_sequence *msg_seq = seq[sequence_index];
172 static const struct message end_of_sequence = {0, 0, 0, 0};
173 const struct message *actual, *sequence;
174 int failcount = 0, dump = 0;
176 add_message(seq, sequence_index, &end_of_sequence);
178 sequence = msg_seq->sequence;
179 actual = sequence;
181 while (expected->message && actual->message)
183 if (expected->message == actual->message)
185 if (expected->flags & wparam)
187 if (expected->wParam != actual->wParam && todo)
189 todo_wine
191 failcount++;
192 dump++;
193 ok_(file, line) (FALSE,
194 "%s: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
195 context, expected->message, expected->wParam, actual->wParam);
198 else
200 ok_(file, line) (expected->wParam == actual->wParam,
201 "%s: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
202 context, expected->message, expected->wParam, actual->wParam);
203 if (expected->wParam != actual->wParam) dump++;
207 if (expected->flags & lparam)
209 if (expected->lParam != actual->lParam && todo)
211 todo_wine
213 failcount++;
214 dump++;
215 ok_(file, line) (FALSE,
216 "%s: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
217 context, expected->message, expected->lParam, actual->lParam);
220 else
222 ok_(file, line) (expected->lParam == actual->lParam,
223 "%s: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
224 context, expected->message, expected->lParam, actual->lParam);
225 if (expected->lParam != actual->lParam) dump++;
229 if (expected->flags & custdraw)
231 if (expected->stage != actual->stage && todo)
233 todo_wine
235 failcount++;
236 dump++;
237 ok_(file, line) (FALSE,
238 "%s: in msg 0x%04x expecting cd stage 0x%08x got 0x%08x\n",
239 context, expected->message, expected->stage, actual->stage);
242 else
244 ok_(file, line) (expected->stage == actual->stage,
245 "%s: in msg 0x%04x expecting cd stage 0x%08x got 0x%08x\n",
246 context, expected->message, expected->stage, actual->stage);
247 if (expected->stage != actual->stage) dump++;
251 if (expected->flags & id)
253 if (expected->id != actual->id && expected->flags & optional)
255 expected++;
256 continue;
258 if (expected->id != actual->id && todo)
260 todo_wine
262 failcount++;
263 dump++;
264 ok_(file, line) (FALSE,
265 "%s: in msg 0x%04x expecting id 0x%x got 0x%x\n",
266 context, expected->message, expected->id, actual->id);
269 else
271 ok_(file, line) (expected->id == actual->id,
272 "%s: in msg 0x%04x expecting id 0x%x got 0x%x\n",
273 context, expected->message, expected->id, actual->id);
274 if (expected->id != actual->id) dump++;
278 if ((expected->flags & defwinproc) != (actual->flags & defwinproc) && todo)
280 todo_wine
282 failcount++;
283 dump++;
284 ok_(file, line) (FALSE,
285 "%s: the msg 0x%04x should %shave been sent by DefWindowProc\n",
286 context, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
289 else
291 ok_(file, line) ((expected->flags & defwinproc) == (actual->flags & defwinproc),
292 "%s: the msg 0x%04x should %shave been sent by DefWindowProc\n",
293 context, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
294 if ((expected->flags & defwinproc) != (actual->flags & defwinproc)) dump++;
297 ok_(file, line) ((expected->flags & beginpaint) == (actual->flags & beginpaint),
298 "%s: the msg 0x%04x should %shave been sent by BeginPaint\n",
299 context, expected->message, (expected->flags & beginpaint) ? "" : "NOT ");
300 if ((expected->flags & beginpaint) != (actual->flags & beginpaint)) dump++;
302 ok_(file, line) ((expected->flags & (sent|posted)) == (actual->flags & (sent|posted)),
303 "%s: the msg 0x%04x should have been %s\n",
304 context, expected->message, (expected->flags & posted) ? "posted" : "sent");
305 if ((expected->flags & (sent|posted)) != (actual->flags & (sent|posted))) dump++;
307 ok_(file, line) ((expected->flags & parent) == (actual->flags & parent),
308 "%s: the msg 0x%04x was expected in %s\n",
309 context, expected->message, (expected->flags & parent) ? "parent" : "child");
310 if ((expected->flags & parent) != (actual->flags & parent)) dump++;
312 ok_(file, line) ((expected->flags & hook) == (actual->flags & hook),
313 "%s: the msg 0x%04x should have been sent by a hook\n",
314 context, expected->message);
315 if ((expected->flags & hook) != (actual->flags & hook)) dump++;
317 ok_(file, line) ((expected->flags & winevent_hook) == (actual->flags & winevent_hook),
318 "%s: the msg 0x%04x should have been sent by a winevent hook\n",
319 context, expected->message);
320 if ((expected->flags & winevent_hook) != (actual->flags & winevent_hook)) dump++;
322 expected++;
323 actual++;
325 else if (expected->flags & optional)
326 expected++;
327 else if (todo)
329 failcount++;
330 dump++;
331 todo_wine
333 ok_(file, line) (FALSE, "%s: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
334 context, expected->message, actual->message);
336 goto done;
338 else
340 ok_(file, line) (FALSE, "%s: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
341 context, expected->message, actual->message);
342 dump++;
343 expected++;
344 actual++;
348 /* skip all optional trailing messages */
349 while (expected->message && ((expected->flags & optional)))
350 expected++;
352 if (todo)
354 todo_wine
356 if (expected->message || actual->message)
358 failcount++;
359 dump++;
360 ok_(file, line) (FALSE, "%s: the msg sequence is not complete: expected %04x - actual %04x\n",
361 context, expected->message, actual->message);
365 else if (expected->message || actual->message)
367 dump++;
368 ok_(file, line) (FALSE, "%s: the msg sequence is not complete: expected %04x - actual %04x\n",
369 context, expected->message, actual->message);
372 if(todo && !failcount) /* succeeded yet marked todo */
374 dump++;
375 todo_wine
377 ok_(file, line)(TRUE, "%s: marked \"todo_wine\" but succeeds\n", context);
381 done:
382 if (dump) dump_sequence( seq, sequence_index, expected, context, file, line );
383 flush_sequence(seq, sequence_index);
386 #define ok_sequence(seq, index, exp, contx, todo) \
387 ok_sequence_(seq, index, (exp), (contx), (todo), __FILE__, __LINE__)
390 static void init_msg_sequences(struct msg_sequence **seq, int n)
392 int i;
394 for (i = 0; i < n; i++)
395 seq[i] = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct msg_sequence));