include/mscvpdb.h: Use flexible array members for the rest of structures.
[wine.git] / dlls / shell32 / tests / msg.h
bloba2b723cfb892ab3dc59b3222698b9639800729f8
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/test.h"
26 /* undocumented SWP flags - from SDK 3.1 */
27 #define SWP_NOCLIENTSIZE 0x0800
28 #define SWP_NOCLIENTMOVE 0x1000
30 typedef enum
32 sent = 0x1,
33 posted = 0x2,
34 parent = 0x4,
35 wparam = 0x8,
36 lparam = 0x10,
37 defwinproc = 0x20,
38 beginpaint = 0x40,
39 optional = 0x80,
40 hook = 0x100,
41 winevent_hook =0x200,
42 id = 0x400
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. */
55 struct msg_sequence
57 int count;
58 int size;
59 struct message *sequence;
62 static void add_message(struct msg_sequence **seq, int sequence_index,
63 const struct message *msg)
65 struct msg_sequence *msg_seq = seq[sequence_index];
67 if (!msg_seq->sequence)
69 msg_seq->size = 10;
70 msg_seq->sequence = malloc(msg_seq->size * sizeof (struct message));
73 if (msg_seq->count == msg_seq->size)
75 msg_seq->size *= 2;
76 msg_seq->sequence = realloc(msg_seq->sequence, msg_seq->size * sizeof (struct message));
79 assert(msg_seq->sequence);
81 msg_seq->sequence[msg_seq->count].message = msg->message;
82 msg_seq->sequence[msg_seq->count].flags = msg->flags;
83 msg_seq->sequence[msg_seq->count].wParam = msg->wParam;
84 msg_seq->sequence[msg_seq->count].lParam = msg->lParam;
85 msg_seq->sequence[msg_seq->count].id = msg->id;
87 msg_seq->count++;
90 static void flush_sequence(struct msg_sequence **seg, int sequence_index)
92 struct msg_sequence *msg_seq = seg[sequence_index];
93 free(msg_seq->sequence);
94 msg_seq->sequence = NULL;
95 msg_seq->count = msg_seq->size = 0;
98 static void flush_sequences(struct msg_sequence **seq, int n)
100 int i;
102 for (i = 0; i < n; i++)
103 flush_sequence(seq, i);
106 static void ok_sequence_(struct msg_sequence **seq, int sequence_index,
107 const struct message *expected, const char *context, BOOL todo,
108 const char *file, int line)
110 struct msg_sequence *msg_seq = seq[sequence_index];
111 static const struct message end_of_sequence = {0, 0, 0, 0};
112 const struct message *actual, *sequence;
113 int failcount = 0;
115 add_message(seq, sequence_index, &end_of_sequence);
117 sequence = msg_seq->sequence;
118 actual = sequence;
120 while (expected->message && actual->message)
122 trace_( file, line)("expected %04x - actual %04x\n", expected->message, actual->message);
124 if (expected->message == actual->message)
126 if (expected->flags & wparam)
128 if (expected->wParam != actual->wParam && todo)
130 todo_wine
132 failcount++;
133 ok_(file, line) (FALSE,
134 "%s: in msg 0x%04x expecting wParam 0x%Ix got 0x%Ix\n",
135 context, expected->message, expected->wParam, actual->wParam);
138 else
140 ok_(file, line) (expected->wParam == actual->wParam,
141 "%s: in msg 0x%04x expecting wParam 0x%Ix got 0x%Ix\n",
142 context, expected->message, expected->wParam, actual->wParam);
146 if (expected->flags & lparam)
148 if (expected->lParam != actual->lParam && todo)
150 todo_wine
152 failcount++;
153 ok_(file, line) (FALSE,
154 "%s: in msg 0x%04x expecting lParam 0x%Ix got 0x%Ix\n",
155 context, expected->message, expected->lParam, actual->lParam);
158 else
160 ok_(file, line) (expected->lParam == actual->lParam,
161 "%s: in msg 0x%04x expecting lParam 0x%Ix got 0x%Ix\n",
162 context, expected->message, expected->lParam, actual->lParam);
166 if (expected->flags & id)
168 if (expected->id != actual->id && expected->flags & optional)
170 expected++;
171 continue;
173 if (expected->id != actual->id && todo)
175 todo_wine
177 failcount++;
178 ok_(file, line) (FALSE,
179 "%s: in msg 0x%04x expecting id 0x%x got 0x%x\n",
180 context, expected->message, expected->id, actual->id);
183 else
185 ok_(file, line) (expected->id == actual->id,
186 "%s: in msg 0x%04x expecting id 0x%x got 0x%x\n",
187 context, expected->message, expected->id, actual->id);
191 if ((expected->flags & defwinproc) != (actual->flags & defwinproc) && todo)
193 todo_wine
195 failcount++;
196 ok_(file, line) (FALSE,
197 "%s: the msg 0x%04x should %shave been sent by DefWindowProc\n",
198 context, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
201 else
203 ok_(file, line) ((expected->flags & defwinproc) == (actual->flags & defwinproc),
204 "%s: the msg 0x%04x should %shave been sent by DefWindowProc\n",
205 context, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
208 ok_(file, line) ((expected->flags & beginpaint) == (actual->flags & beginpaint),
209 "%s: the msg 0x%04x should %shave been sent by BeginPaint\n",
210 context, expected->message, (expected->flags & beginpaint) ? "" : "NOT ");
211 ok_(file, line) ((expected->flags & (sent|posted)) == (actual->flags & (sent|posted)),
212 "%s: the msg 0x%04x should have been %s\n",
213 context, expected->message, (expected->flags & posted) ? "posted" : "sent");
214 ok_(file, line) ((expected->flags & parent) == (actual->flags & parent),
215 "%s: the msg 0x%04x was expected in %s\n",
216 context, expected->message, (expected->flags & parent) ? "parent" : "child");
217 ok_(file, line) ((expected->flags & hook) == (actual->flags & hook),
218 "%s: the msg 0x%04x should have been sent by a hook\n",
219 context, expected->message);
220 ok_(file, line) ((expected->flags & winevent_hook) == (actual->flags & winevent_hook),
221 "%s: the msg 0x%04x should have been sent by a winevent hook\n",
222 context, expected->message);
223 expected++;
224 actual++;
226 else if (expected->flags & optional)
227 expected++;
228 else if (todo)
230 failcount++;
231 todo_wine
233 ok_(file, line) (FALSE, "%s: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
234 context, expected->message, actual->message);
237 flush_sequence(seq, sequence_index);
238 return;
240 else
242 ok_(file, line) (FALSE, "%s: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
243 context, expected->message, actual->message);
244 expected++;
245 actual++;
249 /* skip all optional trailing messages */
250 while (expected->message && ((expected->flags & optional)))
251 expected++;
253 if (todo)
255 todo_wine
257 if (expected->message || actual->message)
259 failcount++;
260 ok_(file, line) (FALSE, "%s: the msg sequence is not complete: expected %04x - actual %04x\n",
261 context, expected->message, actual->message);
265 else if (expected->message || actual->message)
267 ok_(file, line) (FALSE, "%s: the msg sequence is not complete: expected %04x - actual %04x\n",
268 context, expected->message, actual->message);
271 if(todo && !failcount) /* succeeded yet marked todo */
273 todo_wine
275 ok_(file, line)(TRUE, "%s: marked \"todo_wine\" but succeeds\n", context);
279 flush_sequence(seq, sequence_index);
282 #define ok_sequence(seq, index, exp, contx, todo) \
283 ok_sequence_(seq, index, (exp), (contx), (todo), __FILE__, __LINE__)
286 static void init_msg_sequences(struct msg_sequence **seq, int n)
288 int i;
290 for (i = 0; i < n; i++)
291 seq[i] = calloc(1, sizeof(struct msg_sequence));