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
46 UINT message
; /* the WM_* code */
47 msg_flags_t flags
; /* message props */
48 WPARAM wParam
; /* expected value of wParam */
49 LPARAM lParam
; /* expected value of lParam */
50 UINT id
; /* extra message data: id of the window,
58 struct message
*sequence
;
61 static void add_message(struct msg_sequence
**seq
, int sequence_index
,
62 const struct message
*msg
)
64 struct msg_sequence
*msg_seq
= seq
[sequence_index
];
66 if (!msg_seq
->sequence
)
69 msg_seq
->sequence
= HeapAlloc(GetProcessHeap(), 0,
70 msg_seq
->size
* sizeof (struct message
));
73 if (msg_seq
->count
== msg_seq
->size
)
76 msg_seq
->sequence
= HeapReAlloc(GetProcessHeap(), 0,
78 msg_seq
->size
* sizeof (struct message
));
81 assert(msg_seq
->sequence
);
83 msg_seq
->sequence
[msg_seq
->count
].message
= msg
->message
;
84 msg_seq
->sequence
[msg_seq
->count
].flags
= msg
->flags
;
85 msg_seq
->sequence
[msg_seq
->count
].wParam
= msg
->wParam
;
86 msg_seq
->sequence
[msg_seq
->count
].lParam
= msg
->lParam
;
87 msg_seq
->sequence
[msg_seq
->count
].id
= msg
->id
;
92 static void flush_sequence(struct msg_sequence
**seg
, int sequence_index
)
94 struct msg_sequence
*msg_seq
= seg
[sequence_index
];
95 HeapFree(GetProcessHeap(), 0, msg_seq
->sequence
);
96 msg_seq
->sequence
= NULL
;
97 msg_seq
->count
= msg_seq
->size
= 0;
100 static void flush_sequences(struct msg_sequence
**seq
, int n
)
104 for (i
= 0; i
< n
; i
++)
105 flush_sequence(seq
, i
);
108 static void ok_sequence_(struct msg_sequence
**seq
, int sequence_index
,
109 const struct message
*expected
, const char *context
, int todo
,
110 const char *file
, int line
)
112 struct msg_sequence
*msg_seq
= seq
[sequence_index
];
113 static const struct message end_of_sequence
= {0, 0, 0, 0};
114 const struct message
*actual
, *sequence
;
117 add_message(seq
, sequence_index
, &end_of_sequence
);
119 sequence
= msg_seq
->sequence
;
122 while (expected
->message
&& actual
->message
)
124 trace_( file
, line
)("expected %04x - actual %04x\n", expected
->message
, actual
->message
);
126 if (expected
->message
== actual
->message
)
128 if (expected
->flags
& wparam
)
130 if (expected
->wParam
!= actual
->wParam
&& todo
)
135 ok_(file
, line
) (FALSE
,
136 "%s: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
137 context
, expected
->message
, expected
->wParam
, actual
->wParam
);
142 ok_(file
, line
) (expected
->wParam
== actual
->wParam
,
143 "%s: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
144 context
, expected
->message
, expected
->wParam
, actual
->wParam
);
148 if (expected
->flags
& lparam
)
150 if (expected
->lParam
!= actual
->lParam
&& todo
)
155 ok_(file
, line
) (FALSE
,
156 "%s: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
157 context
, expected
->message
, expected
->lParam
, actual
->lParam
);
162 ok_(file
, line
) (expected
->lParam
== actual
->lParam
,
163 "%s: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
164 context
, expected
->message
, expected
->lParam
, actual
->lParam
);
168 if (expected
->flags
& id
)
170 if (expected
->id
!= actual
->id
&& expected
->flags
& optional
)
175 if (expected
->id
!= actual
->id
&& todo
)
180 ok_(file
, line
) (FALSE
,
181 "%s: in msg 0x%04x expecting id 0x%x got 0x%x\n",
182 context
, expected
->message
, expected
->id
, actual
->id
);
187 ok_(file
, line
) (expected
->id
== actual
->id
,
188 "%s: in msg 0x%04x expecting id 0x%x got 0x%x\n",
189 context
, expected
->message
, expected
->id
, actual
->id
);
193 if ((expected
->flags
& defwinproc
) != (actual
->flags
& defwinproc
) && todo
)
198 ok_(file
, line
) (FALSE
,
199 "%s: the msg 0x%04x should %shave been sent by DefWindowProc\n",
200 context
, expected
->message
, (expected
->flags
& defwinproc
) ? "" : "NOT ");
205 ok_(file
, line
) ((expected
->flags
& defwinproc
) == (actual
->flags
& defwinproc
),
206 "%s: the msg 0x%04x should %shave been sent by DefWindowProc\n",
207 context
, expected
->message
, (expected
->flags
& defwinproc
) ? "" : "NOT ");
210 ok_(file
, line
) ((expected
->flags
& beginpaint
) == (actual
->flags
& beginpaint
),
211 "%s: the msg 0x%04x should %shave been sent by BeginPaint\n",
212 context
, expected
->message
, (expected
->flags
& beginpaint
) ? "" : "NOT ");
213 ok_(file
, line
) ((expected
->flags
& (sent
|posted
)) == (actual
->flags
& (sent
|posted
)),
214 "%s: the msg 0x%04x should have been %s\n",
215 context
, expected
->message
, (expected
->flags
& posted
) ? "posted" : "sent");
216 ok_(file
, line
) ((expected
->flags
& parent
) == (actual
->flags
& parent
),
217 "%s: the msg 0x%04x was expected in %s\n",
218 context
, expected
->message
, (expected
->flags
& parent
) ? "parent" : "child");
219 ok_(file
, line
) ((expected
->flags
& hook
) == (actual
->flags
& hook
),
220 "%s: the msg 0x%04x should have been sent by a hook\n",
221 context
, expected
->message
);
222 ok_(file
, line
) ((expected
->flags
& winevent_hook
) == (actual
->flags
& winevent_hook
),
223 "%s: the msg 0x%04x should have been sent by a winevent hook\n",
224 context
, expected
->message
);
228 else if (expected
->flags
& optional
)
235 ok_(file
, line
) (FALSE
, "%s: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
236 context
, expected
->message
, actual
->message
);
239 flush_sequence(seq
, sequence_index
);
244 ok_(file
, line
) (FALSE
, "%s: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
245 context
, expected
->message
, actual
->message
);
251 /* skip all optional trailing messages */
252 while (expected
->message
&& ((expected
->flags
& optional
)))
259 if (expected
->message
|| actual
->message
)
262 ok_(file
, line
) (FALSE
, "%s: the msg sequence is not complete: expected %04x - actual %04x\n",
263 context
, expected
->message
, actual
->message
);
267 else if (expected
->message
|| actual
->message
)
269 ok_(file
, line
) (FALSE
, "%s: the msg sequence is not complete: expected %04x - actual %04x\n",
270 context
, expected
->message
, actual
->message
);
273 if(todo
&& !failcount
) /* succeeded yet marked todo */
277 ok_(file
, line
)(TRUE
, "%s: marked \"todo_wine\" but succeeds\n", context
);
281 flush_sequence(seq
, sequence_index
);
284 #define ok_sequence(seq, index, exp, contx, todo) \
285 ok_sequence_(seq, index, (exp), (contx), (todo), __FILE__, __LINE__)
288 static void init_msg_sequences(struct msg_sequence
**seq
, int n
)
292 for (i
= 0; i
< n
; i
++)
293 seq
[i
] = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(struct msg_sequence
));