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 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
&& todo
)
137 ok_(file
, line
) (FALSE
,
138 "%s: in msg 0x%04x expecting id 0x%x got 0x%x\n",
139 context
, expected
->message
, expected
->id
, actual
->id
);
144 ok_(file
, line
) (expected
->id
== actual
->id
,
145 "%s: in msg 0x%04x expecting id 0x%x got 0x%x\n",
146 context
, expected
->message
, expected
->id
, actual
->id
);
150 if ((expected
->flags
& defwinproc
) != (actual
->flags
& defwinproc
) && todo
)
155 ok_(file
, line
) (FALSE
,
156 "%s: the msg 0x%04x should %shave been sent by DefWindowProc\n",
157 context
, expected
->message
, (expected
->flags
& defwinproc
) ? "" : "NOT ");
162 ok_(file
, line
) ((expected
->flags
& defwinproc
) == (actual
->flags
& defwinproc
),
163 "%s: the msg 0x%04x should %shave been sent by DefWindowProc\n",
164 context
, expected
->message
, (expected
->flags
& defwinproc
) ? "" : "NOT ");
167 ok_(file
, line
) ((expected
->flags
& beginpaint
) == (actual
->flags
& beginpaint
),
168 "%s: the msg 0x%04x should %shave been sent by BeginPaint\n",
169 context
, expected
->message
, (expected
->flags
& beginpaint
) ? "" : "NOT ");
170 ok_(file
, line
) ((expected
->flags
& (sent
|posted
)) == (actual
->flags
& (sent
|posted
)),
171 "%s: the msg 0x%04x should have been %s\n",
172 context
, expected
->message
, (expected
->flags
& posted
) ? "posted" : "sent");
173 ok_(file
, line
) ((expected
->flags
& parent
) == (actual
->flags
& parent
),
174 "%s: the msg 0x%04x was expected in %s\n",
175 context
, expected
->message
, (expected
->flags
& parent
) ? "parent" : "child");
176 ok_(file
, line
) ((expected
->flags
& hook
) == (actual
->flags
& hook
),
177 "%s: the msg 0x%04x should have been sent by a hook\n",
178 context
, expected
->message
);
179 ok_(file
, line
) ((expected
->flags
& winevent_hook
) == (actual
->flags
& winevent_hook
),
180 "%s: the msg 0x%04x should have been sent by a winevent hook\n",
181 context
, expected
->message
);
185 else if (expected
->flags
& optional
)
192 ok_(file
, line
) (FALSE
, "%s: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
193 context
, expected
->message
, actual
->message
);
196 flush_sequence(seq
, sequence_index
);
201 ok_(file
, line
) (FALSE
, "%s: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
202 context
, expected
->message
, actual
->message
);
208 /* skip all optional trailing messages */
209 while (expected
->message
&& ((expected
->flags
& optional
)))
216 if (expected
->message
|| actual
->message
)
219 ok_(file
, line
) (FALSE
, "%s: the msg sequence is not complete: expected %04x - actual %04x\n",
220 context
, expected
->message
, actual
->message
);
224 else if (expected
->message
|| actual
->message
)
226 ok_(file
, line
) (FALSE
, "%s: the msg sequence is not complete: expected %04x - actual %04x\n",
227 context
, expected
->message
, actual
->message
);
230 if(todo
&& !failcount
) /* succeeded yet marked todo */
234 ok_(file
, line
)(TRUE
, "%s: marked \"todo_wine\" but succeeds\n", context
);
238 flush_sequence(seq
, sequence_index
);
241 void init_msg_sequences(struct msg_sequence
**seq
, int n
)
245 for (i
= 0; i
< n
; i
++)
246 seq
[i
] = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(struct msg_sequence
));