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
24 #include "wine/heap.h"
25 #include "wine/test.h"
27 /* undocumented SWP flags - from SDK 3.1 */
28 #define SWP_NOCLIENTSIZE 0x0800
29 #define SWP_NOCLIENTMOVE 0x1000
48 UINT message
; /* the WM_* code */
49 msg_flags_t flags
; /* message props */
50 WPARAM wParam
; /* expected value of wParam */
51 LPARAM lParam
; /* expected value of lParam */
52 UINT id
; /* extra message data: id of the window,
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
= heap_alloc(msg_seq
->size
* sizeof (struct message
));
74 if (msg_seq
->count
== msg_seq
->size
)
77 msg_seq
->sequence
= heap_realloc(msg_seq
->sequence
, msg_seq
->size
* sizeof (struct message
));
80 assert(msg_seq
->sequence
);
82 msg_seq
->sequence
[msg_seq
->count
].message
= msg
->message
;
83 msg_seq
->sequence
[msg_seq
->count
].flags
= msg
->flags
;
84 msg_seq
->sequence
[msg_seq
->count
].wParam
= msg
->wParam
;
85 msg_seq
->sequence
[msg_seq
->count
].lParam
= msg
->lParam
;
86 msg_seq
->sequence
[msg_seq
->count
].id
= msg
->id
;
91 static void flush_sequence(struct msg_sequence
**seg
, int sequence_index
)
93 struct msg_sequence
*msg_seq
= seg
[sequence_index
];
94 heap_free(msg_seq
->sequence
);
95 msg_seq
->sequence
= NULL
;
96 msg_seq
->count
= msg_seq
->size
= 0;
99 static void flush_sequences(struct msg_sequence
**seq
, int n
)
103 for (i
= 0; i
< n
; i
++)
104 flush_sequence(seq
, i
);
107 static void ok_sequence_(struct msg_sequence
**seq
, int sequence_index
,
108 const struct message
*expected
, const char *context
, BOOL todo
,
109 const char *file
, int line
)
111 struct msg_sequence
*msg_seq
= seq
[sequence_index
];
112 static const struct message end_of_sequence
= {0, 0, 0, 0};
113 const struct message
*actual
, *sequence
;
116 add_message(seq
, sequence_index
, &end_of_sequence
);
118 sequence
= msg_seq
->sequence
;
121 while (expected
->message
&& actual
->message
)
123 trace_( file
, line
)("expected %04x - actual %04x\n", expected
->message
, actual
->message
);
125 if (expected
->message
== actual
->message
)
127 if (expected
->flags
& wparam
)
129 if (expected
->wParam
!= actual
->wParam
&& todo
)
134 ok_(file
, line
) (FALSE
,
135 "%s: in msg 0x%04x expecting wParam 0x%Ix got 0x%Ix\n",
136 context
, expected
->message
, expected
->wParam
, actual
->wParam
);
141 ok_(file
, line
) (expected
->wParam
== actual
->wParam
,
142 "%s: in msg 0x%04x expecting wParam 0x%Ix got 0x%Ix\n",
143 context
, expected
->message
, expected
->wParam
, actual
->wParam
);
147 if (expected
->flags
& lparam
)
149 if (expected
->lParam
!= actual
->lParam
&& todo
)
154 ok_(file
, line
) (FALSE
,
155 "%s: in msg 0x%04x expecting lParam 0x%Ix got 0x%Ix\n",
156 context
, expected
->message
, expected
->lParam
, actual
->lParam
);
161 ok_(file
, line
) (expected
->lParam
== actual
->lParam
,
162 "%s: in msg 0x%04x expecting lParam 0x%Ix got 0x%Ix\n",
163 context
, expected
->message
, expected
->lParam
, actual
->lParam
);
167 if (expected
->flags
& id
)
169 if (expected
->id
!= actual
->id
&& expected
->flags
& optional
)
174 if (expected
->id
!= actual
->id
&& todo
)
179 ok_(file
, line
) (FALSE
,
180 "%s: in msg 0x%04x expecting id 0x%x got 0x%x\n",
181 context
, expected
->message
, expected
->id
, actual
->id
);
186 ok_(file
, line
) (expected
->id
== actual
->id
,
187 "%s: in msg 0x%04x expecting id 0x%x got 0x%x\n",
188 context
, expected
->message
, expected
->id
, actual
->id
);
192 if ((expected
->flags
& defwinproc
) != (actual
->flags
& defwinproc
) && todo
)
197 ok_(file
, line
) (FALSE
,
198 "%s: the msg 0x%04x should %shave been sent by DefWindowProc\n",
199 context
, expected
->message
, (expected
->flags
& defwinproc
) ? "" : "NOT ");
204 ok_(file
, line
) ((expected
->flags
& defwinproc
) == (actual
->flags
& defwinproc
),
205 "%s: the msg 0x%04x should %shave been sent by DefWindowProc\n",
206 context
, expected
->message
, (expected
->flags
& defwinproc
) ? "" : "NOT ");
209 ok_(file
, line
) ((expected
->flags
& beginpaint
) == (actual
->flags
& beginpaint
),
210 "%s: the msg 0x%04x should %shave been sent by BeginPaint\n",
211 context
, expected
->message
, (expected
->flags
& beginpaint
) ? "" : "NOT ");
212 ok_(file
, line
) ((expected
->flags
& (sent
|posted
)) == (actual
->flags
& (sent
|posted
)),
213 "%s: the msg 0x%04x should have been %s\n",
214 context
, expected
->message
, (expected
->flags
& posted
) ? "posted" : "sent");
215 ok_(file
, line
) ((expected
->flags
& parent
) == (actual
->flags
& parent
),
216 "%s: the msg 0x%04x was expected in %s\n",
217 context
, expected
->message
, (expected
->flags
& parent
) ? "parent" : "child");
218 ok_(file
, line
) ((expected
->flags
& hook
) == (actual
->flags
& hook
),
219 "%s: the msg 0x%04x should have been sent by a hook\n",
220 context
, expected
->message
);
221 ok_(file
, line
) ((expected
->flags
& winevent_hook
) == (actual
->flags
& winevent_hook
),
222 "%s: the msg 0x%04x should have been sent by a winevent hook\n",
223 context
, expected
->message
);
227 else if (expected
->flags
& optional
)
234 ok_(file
, line
) (FALSE
, "%s: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
235 context
, expected
->message
, actual
->message
);
238 flush_sequence(seq
, sequence_index
);
243 ok_(file
, line
) (FALSE
, "%s: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
244 context
, expected
->message
, actual
->message
);
250 /* skip all optional trailing messages */
251 while (expected
->message
&& ((expected
->flags
& optional
)))
258 if (expected
->message
|| actual
->message
)
261 ok_(file
, line
) (FALSE
, "%s: the msg sequence is not complete: expected %04x - actual %04x\n",
262 context
, expected
->message
, actual
->message
);
266 else if (expected
->message
|| actual
->message
)
268 ok_(file
, line
) (FALSE
, "%s: the msg sequence is not complete: expected %04x - actual %04x\n",
269 context
, expected
->message
, actual
->message
);
272 if(todo
&& !failcount
) /* succeeded yet marked todo */
276 ok_(file
, line
)(TRUE
, "%s: marked \"todo_wine\" but succeeds\n", context
);
280 flush_sequence(seq
, sequence_index
);
283 #define ok_sequence(seq, index, exp, contx, todo) \
284 ok_sequence_(seq, index, (exp), (contx), (todo), __FILE__, __LINE__)
287 static void init_msg_sequences(struct msg_sequence
**seq
, int n
)
291 for (i
= 0; i
< n
; i
++)
292 seq
[i
] = heap_alloc_zero(sizeof(struct msg_sequence
));