hhctrl.ocx: Added hhc parser.
[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
50     msg_seq->count++;
51 }
52
53 void flush_sequence(struct msg_sequence **seg, int sequence_index)
54 {
55     struct msg_sequence *msg_seq = seg[sequence_index];
56     HeapFree(GetProcessHeap(), 0, msg_seq->sequence);
57     msg_seq->sequence = NULL;
58     msg_seq->count = msg_seq->size = 0;
59 }
60
61 void flush_sequences(struct msg_sequence **seq, int n)
62 {
63     int i;
64
65     for (i = 0; i < n; i++)
66         flush_sequence(seq, i);
67 }
68
69 void ok_sequence_(struct msg_sequence **seq, int sequence_index,
70     const struct message *expected, const char *context, int todo,
71     const char *file, int line)
72 {
73     struct msg_sequence *msg_seq = seq[sequence_index];
74     static const struct message end_of_sequence = {0, 0, 0, 0};
75     const struct message *actual, *sequence;
76     int failcount = 0;
77
78     add_message(seq, sequence_index, &end_of_sequence);
79
80     sequence = msg_seq->sequence;
81     actual = sequence;
82
83     while (expected->message && actual->message)
84     {
85         trace_( file, line)("expected %04x - actual %04x\n", expected->message, actual->message);
86
87         if (expected->message == actual->message)
88         {
89             if (expected->flags & wparam)
90             {
91                 if (expected->wParam != actual->wParam && todo)
92                 {
93                     todo_wine
94                     {
95                         failcount++;
96                         ok_(file, line) (FALSE,
97                             "%s: in msg 0x%04x expecting wParam 0x%x got 0x%x\n",
98                             context, expected->message, expected->wParam, actual->wParam);
99                     }
100                 }
101                 else
102                 {
103                     ok_(file, line) (expected->wParam == actual->wParam,
104                         "%s: in msg 0x%04x expecting wParam 0x%x got 0x%x\n",
105                         context, expected->message, expected->wParam, actual->wParam);
106                 }
107             }
108
109             if (expected->flags & lparam)
110             {
111                 if (expected->lParam != actual->lParam && todo)
112                 {
113                     todo_wine
114                     {
115                         failcount++;
116                         ok_(file, line) (FALSE,
117                             "%s: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
118                             context, expected->message, expected->lParam, actual->lParam);
119                     }
120                 }
121                 else
122                 {
123                     ok_(file, line) (expected->lParam == actual->lParam,
124                         "%s: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
125                         context, expected->message, expected->lParam, actual->lParam);
126                 }
127             }
128
129             if ((expected->flags & defwinproc) != (actual->flags & defwinproc) && todo)
130             {
131                 todo_wine
132                 {
133                     failcount++;
134                     ok_(file, line) (FALSE,
135                         "%s: the msg 0x%04x should %shave been sent by DefWindowProc\n",
136                         context, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
137                 }
138             }
139             else
140             {
141                 ok_(file, line) ((expected->flags & defwinproc) == (actual->flags & defwinproc),
142                     "%s: the msg 0x%04x should %shave been sent by DefWindowProc\n",
143                     context, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
144             }
145
146             ok_(file, line) ((expected->flags & beginpaint) == (actual->flags & beginpaint),
147                 "%s: the msg 0x%04x should %shave been sent by BeginPaint\n",
148                 context, expected->message, (expected->flags & beginpaint) ? "" : "NOT ");
149             ok_(file, line) ((expected->flags & (sent|posted)) == (actual->flags & (sent|posted)),
150                 "%s: the msg 0x%04x should have been %s\n",
151                 context, expected->message, (expected->flags & posted) ? "posted" : "sent");
152             ok_(file, line) ((expected->flags & parent) == (actual->flags & parent),
153                 "%s: the msg 0x%04x was expected in %s\n",
154                 context, expected->message, (expected->flags & parent) ? "parent" : "child");
155             ok_(file, line) ((expected->flags & hook) == (actual->flags & hook),
156                 "%s: the msg 0x%04x should have been sent by a hook\n",
157                 context, expected->message);
158             ok_(file, line) ((expected->flags & winevent_hook) == (actual->flags & winevent_hook),
159                 "%s: the msg 0x%04x should have been sent by a winevent hook\n",
160                 context, expected->message);
161             expected++;
162             actual++;
163         }
164         else if (expected->flags & optional)
165             expected++;
166         else if (todo)
167         {
168             failcount++;
169             todo_wine
170             {
171                 ok_(file, line) (FALSE, "%s: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
172                     context, expected->message, actual->message);
173             }
174
175             flush_sequence(seq, sequence_index);
176             return;
177         }
178         else
179         {
180             ok_(file, line) (FALSE, "%s: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
181                 context, expected->message, actual->message);
182             expected++;
183             actual++;
184         }
185     }
186
187     /* skip all optional trailing messages */
188     while (expected->message && ((expected->flags & optional)))
189         expected++;
190
191     if (todo)
192     {
193         todo_wine
194         {
195             if (expected->message || actual->message)
196             {
197                 failcount++;
198                 ok_(file, line) (FALSE, "%s: the msg sequence is not complete: expected %04x - actual %04x\n",
199                     context, expected->message, actual->message);
200             }
201         }
202     }
203     else if (expected->message || actual->message)
204     {
205         ok_(file, line) (FALSE, "%s: the msg sequence is not complete: expected %04x - actual %04x\n",
206             context, expected->message, actual->message);
207     }
208
209     if(todo && !failcount) /* succeeded yet marked todo */
210     {
211         todo_wine
212         {
213             ok_(file, line)(TRUE, "%s: marked \"todo_wine\" but succeeds\n", context);
214         }
215     }
216
217     flush_sequence(seq, sequence_index);
218 }
219
220 void init_msg_sequences(struct msg_sequence **seq, int n)
221 {
222     int i;
223
224     for (i = 0; i < n; i++)
225         seq[i] = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct msg_sequence));
226 }
227
228 START_TEST(msg)
229 {
230 }