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
23 #include "wine/test.h"
25 /* undocumented SWP flags - from SDK 3.1 */
26 #define SWP_NOCLIENTSIZE 0x0800
27 #define SWP_NOCLIENTMOVE 0x1000
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,
53 DWORD stage
; /* custom draw stage */
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
)
71 msg_seq
->sequence
= HeapAlloc(GetProcessHeap(), 0,
72 msg_seq
->size
* sizeof (struct message
));
75 if (msg_seq
->count
== msg_seq
->size
)
78 msg_seq
->sequence
= HeapReAlloc(GetProcessHeap(), 0,
80 msg_seq
->size
* sizeof (struct message
));
83 assert(msg_seq
->sequence
);
85 msg_seq
->sequence
[msg_seq
->count
] = *msg
;
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
)
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
;
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 */
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
);
152 if (expected
->message
)
154 trace_(file
, line
)( " %u: expected: msg %04x - actual: nothing\n", count
, expected
->message
);
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
);
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
;
181 while (expected
->message
&& actual
->message
)
183 if (expected
->message
== actual
->message
)
185 if (expected
->flags
& wparam
)
187 if (expected
->wParam
!= actual
->wParam
&& todo
)
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
);
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
)
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
);
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
)
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
);
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
)
258 if (expected
->id
!= actual
->id
&& todo
)
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
);
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
)
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 ");
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
++;
325 else if (expected
->flags
& optional
)
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
);
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
);
348 /* skip all optional trailing messages */
349 while (expected
->message
&& ((expected
->flags
& optional
)))
356 if (expected
->message
|| actual
->message
)
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
)
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 */
377 ok_(file
, line
)(TRUE
, "%s: marked \"todo_wine\" but succeeds\n", context
);
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
)
394 for (i
= 0; i
< n
; i
++)
395 seq
[i
] = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(struct msg_sequence
));