comctl32/tests: Make flush_sequence() static.
[wine] / dlls / comctl32 / tests / msg.c
1 /* Message Sequence Testing Code
2  *
3  * Copyright (C) 2007 James Hawkins
4  * Copyright (C) 2007 Lei Zhang
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "msg.h"
22
23 void add_message(struct msg_sequence **seq, int sequence_index,
24     const struct message *msg)
25 {
26     struct msg_sequence *msg_seq = seq[sequence_index];
27
28     if (!msg_seq->sequence)
29     {
30         msg_seq->size = 10;
31         msg_seq->sequence = HeapAlloc(GetProcessHeap(), 0,
32                                       msg_seq->size * sizeof (struct message));
33     }
34
35     if (msg_seq->count == msg_seq->size)
36     {
37         msg_seq->size *= 2;
38         msg_seq->sequence = HeapReAlloc(GetProcessHeap(), 0,
39                                         msg_seq->sequence,
40                                         msg_seq->size * sizeof (struct message));
41     }
42
43     assert(msg_seq->sequence);
44
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;
50
51     msg_seq->count++;
52 }
53
54 static void flush_sequence(struct msg_sequence **seg, int sequence_index)
55 {
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;
60 }
61
62 void flush_sequences(struct msg_sequence **seq, int n)
63 {
64     int i;
65
66     for (i = 0; i < n; i++)
67         flush_sequence(seq, i);
68 }
69
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)
73 {
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;
77     int failcount = 0;
78
79     add_message(seq, sequence_index, &end_of_sequence);
80
81     sequence = msg_seq->sequence;
82     actual = sequence;
83
84     while (expected->message && actual->message)
85     {
86         trace_( file, line)("expected %04x - actual %04x\n", expected->message, actual->message);
87
88         if (expected->message == actual->message)
89         {
90             if (expected->flags & wparam)
91             {
92                 if (expected->wParam != actual->wParam && todo)
93                 {
94                     todo_wine
95                     {
96                         failcount++;
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);
100                     }
101                 }
102                 else
103                 {
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);
107                 }
108             }
109
110             if (expected->flags & lparam)
111             {
112                 if (expected->lParam != actual->lParam && todo)
113                 {
114                     todo_wine
115                     {
116                         failcount++;
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);
120                     }
121                 }
122                 else
123                 {
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);
127                 }
128             }
129
130             if (expected->flags & id)
131             {
132                 if (expected->id != actual->id && todo)
133                 {
134                     todo_wine
135                     {
136                         failcount++;
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);
140                     }
141                 }
142                 else
143                 {
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);
147                 }
148             }
149
150             if ((expected->flags & defwinproc) != (actual->flags & defwinproc) && todo)
151             {
152                 todo_wine
153                 {
154                     failcount++;
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 ");
158                 }
159             }
160             else
161             {
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 ");
165             }
166
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);
182             expected++;
183             actual++;
184         }
185         else if (expected->flags & optional)
186             expected++;
187         else if (todo)
188         {
189             failcount++;
190             todo_wine
191             {
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);
194             }
195
196             flush_sequence(seq, sequence_index);
197             return;
198         }
199         else
200         {
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);
203             expected++;
204             actual++;
205         }
206     }
207
208     /* skip all optional trailing messages */
209     while (expected->message && ((expected->flags & optional)))
210         expected++;
211
212     if (todo)
213     {
214         todo_wine
215         {
216             if (expected->message || actual->message)
217             {
218                 failcount++;
219                 ok_(file, line) (FALSE, "%s: the msg sequence is not complete: expected %04x - actual %04x\n",
220                     context, expected->message, actual->message);
221             }
222         }
223     }
224     else if (expected->message || actual->message)
225     {
226         ok_(file, line) (FALSE, "%s: the msg sequence is not complete: expected %04x - actual %04x\n",
227             context, expected->message, actual->message);
228     }
229
230     if(todo && !failcount) /* succeeded yet marked todo */
231     {
232         todo_wine
233         {
234             ok_(file, line)(TRUE, "%s: marked \"todo_wine\" but succeeds\n", context);
235         }
236     }
237
238     flush_sequence(seq, sequence_index);
239 }
240
241 void init_msg_sequences(struct msg_sequence **seq, int n)
242 {
243     int i;
244
245     for (i = 0; i < n; i++)
246         seq[i] = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct msg_sequence));
247 }
248
249 START_TEST(msg)
250 {
251 }