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 void add_message(struct msg_sequence **seq, int sequence_index,
24 const struct message *msg)
26 struct msg_sequence *msg_seq = seq[sequence_index];
28 if (!msg_seq->sequence)
31 msg_seq->sequence = HeapAlloc(GetProcessHeap(), 0,
32 msg_seq->size * sizeof (struct message));
35 if (msg_seq->count == msg_seq->size)
38 msg_seq->sequence = HeapReAlloc(GetProcessHeap(), 0,
40 msg_seq->size * sizeof (struct message));
43 assert(msg_seq->sequence);
45 msg_seq->sequence[msg_seq->count].message = msg->message;
46 msg_seq->sequence[msg_seq->count].flags = msg->flags;
47 msg_seq->sequence[msg_seq->count].wParam = msg->wParam;
48 msg_seq->sequence[msg_seq->count].lParam = msg->lParam;
53 void flush_sequence(struct msg_sequence **seg, int sequence_index)
55 struct msg_sequence *msg_seq = seg[sequence_index];
56 HeapFree(GetProcessHeap(), 0, msg_seq->sequence);
57 msg_seq->sequence = NULL;
58 msg_seq->count = msg_seq->size = 0;
61 void flush_sequences(struct msg_sequence **seq, int n)
65 for (i = 0; i < n; i++)
66 flush_sequence(seq, i);
69 void ok_sequence_(struct msg_sequence **seq, int sequence_index,
70 const struct message *expected, const char *context, int todo,
71 const char *file, int line)
73 struct msg_sequence *msg_seq = seq[sequence_index];
74 static const struct message end_of_sequence = {0, 0, 0, 0};
75 const struct message *actual, *sequence;
78 add_message(seq, sequence_index, &end_of_sequence);
80 sequence = msg_seq->sequence;
83 while (expected->message && actual->message)
85 trace_( file, line)("expected %04x - actual %04x\n", expected->message, actual->message);
87 if (expected->message == actual->message)
89 if (expected->flags & wparam)
91 if (expected->wParam != actual->wParam && todo)
96 ok_(file, line) (FALSE,
97 "%s: in msg 0x%04x expecting wParam 0x%x got 0x%x\n",
98 context, expected->message, expected->wParam, actual->wParam);
103 ok_(file, line) (expected->wParam == actual->wParam,
104 "%s: in msg 0x%04x expecting wParam 0x%x got 0x%x\n",
105 context, expected->message, expected->wParam, actual->wParam);
109 if (expected->flags & lparam)
111 if (expected->lParam != actual->lParam && todo)
116 ok_(file, line) (FALSE,
117 "%s: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
118 context, expected->message, expected->lParam, actual->lParam);
123 ok_(file, line) (expected->lParam == actual->lParam,
124 "%s: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
125 context, expected->message, expected->lParam, actual->lParam);
129 if ((expected->flags & defwinproc) != (actual->flags & defwinproc) && todo)
134 ok_(file, line) (FALSE,
135 "%s: the msg 0x%04x should %shave been sent by DefWindowProc\n",
136 context, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
141 ok_(file, line) ((expected->flags & defwinproc) == (actual->flags & defwinproc),
142 "%s: the msg 0x%04x should %shave been sent by DefWindowProc\n",
143 context, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
146 ok_(file, line) ((expected->flags & beginpaint) == (actual->flags & beginpaint),
147 "%s: the msg 0x%04x should %shave been sent by BeginPaint\n",
148 context, expected->message, (expected->flags & beginpaint) ? "" : "NOT ");
149 ok_(file, line) ((expected->flags & (sent|posted)) == (actual->flags & (sent|posted)),
150 "%s: the msg 0x%04x should have been %s\n",
151 context, expected->message, (expected->flags & posted) ? "posted" : "sent");
152 ok_(file, line) ((expected->flags & parent) == (actual->flags & parent),
153 "%s: the msg 0x%04x was expected in %s\n",
154 context, expected->message, (expected->flags & parent) ? "parent" : "child");
155 ok_(file, line) ((expected->flags & hook) == (actual->flags & hook),
156 "%s: the msg 0x%04x should have been sent by a hook\n",
157 context, expected->message);
158 ok_(file, line) ((expected->flags & winevent_hook) == (actual->flags & winevent_hook),
159 "%s: the msg 0x%04x should have been sent by a winevent hook\n",
160 context, expected->message);
164 else if (expected->flags & optional)
171 ok_(file, line) (FALSE, "%s: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
172 context, expected->message, actual->message);
175 flush_sequence(seq, sequence_index);
180 ok_(file, line) (FALSE, "%s: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
181 context, expected->message, actual->message);
187 /* skip all optional trailing messages */
188 while (expected->message && ((expected->flags & optional)))
195 if (expected->message || actual->message)
198 ok_(file, line) (FALSE, "%s: the msg sequence is not complete: expected %04x - actual %04x\n",
199 context, expected->message, actual->message);
203 else if (expected->message || actual->message)
205 ok_(file, line) (FALSE, "%s: the msg sequence is not complete: expected %04x - actual %04x\n",
206 context, expected->message, actual->message);
209 if(todo && !failcount) /* succeeded yet marked todo */
213 ok_(file, line)(TRUE, "%s: marked \"todo_wine\" but succeeds\n", context);
217 flush_sequence(seq, sequence_index);
220 void init_msg_sequences(struct msg_sequence **seq, int n)
224 for (i = 0; i < n; i++)
225 seq[i] = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct msg_sequence));