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
;
49 msg_seq
->sequence
[msg_seq
->count
].id
= msg
->id
;
54 static void flush_sequence(struct msg_sequence
**seg
, int sequence_index
)
56 struct msg_sequence
*msg_seq
= seg
[sequence_index
];
57 HeapFree(GetProcessHeap(), 0, msg_seq
->sequence
);
58 msg_seq
->sequence
= NULL
;
59 msg_seq
->count
= msg_seq
->size
= 0;
62 void flush_sequences(struct msg_sequence
**seq
, int n
)
66 for (i
= 0; i
< n
; i
++)
67 flush_sequence(seq
, i
);
70 void ok_sequence_(struct msg_sequence
**seq
, int sequence_index
,
71 const struct message
*expected
, const char *context
, int todo
,
72 const char *file
, int line
)
74 struct msg_sequence
*msg_seq
= seq
[sequence_index
];
75 static const struct message end_of_sequence
= {0, 0, 0, 0};
76 const struct message
*actual
, *sequence
;
79 add_message(seq
, sequence_index
, &end_of_sequence
);
81 sequence
= msg_seq
->sequence
;
84 while (expected
->message
&& actual
->message
)
86 trace_( file
, line
)("expected %04x - actual %04x\n", expected
->message
, actual
->message
);
88 if (expected
->message
== actual
->message
)
90 if (expected
->flags
& wparam
)
92 if (expected
->wParam
!= actual
->wParam
&& todo
)
97 ok_(file
, line
) (FALSE
,
98 "%s: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
99 context
, expected
->message
, expected
->wParam
, actual
->wParam
);
104 ok_(file
, line
) (expected
->wParam
== actual
->wParam
,
105 "%s: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
106 context
, expected
->message
, expected
->wParam
, actual
->wParam
);
110 if (expected
->flags
& lparam
)
112 if (expected
->lParam
!= actual
->lParam
&& todo
)
117 ok_(file
, line
) (FALSE
,
118 "%s: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
119 context
, expected
->message
, expected
->lParam
, actual
->lParam
);
124 ok_(file
, line
) (expected
->lParam
== actual
->lParam
,
125 "%s: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
126 context
, expected
->message
, expected
->lParam
, actual
->lParam
);
130 if (expected
->flags
& id
)
132 if (expected
->id
!= actual
->id
&& expected
->flags
& optional
)
137 if (expected
->id
!= actual
->id
&& todo
)
142 ok_(file
, line
) (FALSE
,
143 "%s: in msg 0x%04x expecting id 0x%x got 0x%x\n",
144 context
, expected
->message
, expected
->id
, actual
->id
);
149 ok_(file
, line
) (expected
->id
== actual
->id
,
150 "%s: in msg 0x%04x expecting id 0x%x got 0x%x\n",
151 context
, expected
->message
, expected
->id
, actual
->id
);
155 if ((expected
->flags
& defwinproc
) != (actual
->flags
& defwinproc
) && todo
)
160 ok_(file
, line
) (FALSE
,
161 "%s: the msg 0x%04x should %shave been sent by DefWindowProc\n",
162 context
, expected
->message
, (expected
->flags
& defwinproc
) ? "" : "NOT ");
167 ok_(file
, line
) ((expected
->flags
& defwinproc
) == (actual
->flags
& defwinproc
),
168 "%s: the msg 0x%04x should %shave been sent by DefWindowProc\n",
169 context
, expected
->message
, (expected
->flags
& defwinproc
) ? "" : "NOT ");
172 ok_(file
, line
) ((expected
->flags
& beginpaint
) == (actual
->flags
& beginpaint
),
173 "%s: the msg 0x%04x should %shave been sent by BeginPaint\n",
174 context
, expected
->message
, (expected
->flags
& beginpaint
) ? "" : "NOT ");
175 ok_(file
, line
) ((expected
->flags
& (sent
|posted
)) == (actual
->flags
& (sent
|posted
)),
176 "%s: the msg 0x%04x should have been %s\n",
177 context
, expected
->message
, (expected
->flags
& posted
) ? "posted" : "sent");
178 ok_(file
, line
) ((expected
->flags
& parent
) == (actual
->flags
& parent
),
179 "%s: the msg 0x%04x was expected in %s\n",
180 context
, expected
->message
, (expected
->flags
& parent
) ? "parent" : "child");
181 ok_(file
, line
) ((expected
->flags
& hook
) == (actual
->flags
& hook
),
182 "%s: the msg 0x%04x should have been sent by a hook\n",
183 context
, expected
->message
);
184 ok_(file
, line
) ((expected
->flags
& winevent_hook
) == (actual
->flags
& winevent_hook
),
185 "%s: the msg 0x%04x should have been sent by a winevent hook\n",
186 context
, expected
->message
);
190 else if (expected
->flags
& optional
)
197 ok_(file
, line
) (FALSE
, "%s: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
198 context
, expected
->message
, actual
->message
);
201 flush_sequence(seq
, sequence_index
);
206 ok_(file
, line
) (FALSE
, "%s: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
207 context
, expected
->message
, actual
->message
);
213 /* skip all optional trailing messages */
214 while (expected
->message
&& ((expected
->flags
& optional
)))
221 if (expected
->message
|| actual
->message
)
224 ok_(file
, line
) (FALSE
, "%s: the msg sequence is not complete: expected %04x - actual %04x\n",
225 context
, expected
->message
, actual
->message
);
229 else if (expected
->message
|| actual
->message
)
231 ok_(file
, line
) (FALSE
, "%s: the msg sequence is not complete: expected %04x - actual %04x\n",
232 context
, expected
->message
, actual
->message
);
235 if(todo
&& !failcount
) /* succeeded yet marked todo */
239 ok_(file
, line
)(TRUE
, "%s: marked \"todo_wine\" but succeeds\n", context
);
243 flush_sequence(seq
, sequence_index
);
246 void init_msg_sequences(struct msg_sequence
**seq
, int n
)
250 for (i
= 0; i
< n
; i
++)
251 seq
[i
] = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(struct msg_sequence
));