2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: helper functions
5 * PROGRAMMERS: Giannis Adamopoulos
13 #include <undocuser.h>
15 MSG_CACHE default_cache
= {
20 MSG_ENTRY empty_chain
[]= {{0,0}};
22 static char* get_msg_name(UINT msg
)
26 case WM_NCACTIVATE
: return "WM_NCACTIVATE";
27 case WM_ACTIVATE
: return "WM_ACTIVATE";
28 case WM_ACTIVATEAPP
: return "WM_ACTIVATEAPP";
29 case WM_WINDOWPOSCHANGING
: return "WM_WINDOWPOSCHANGING";
30 case WM_WINDOWPOSCHANGED
: return "WM_WINDOWPOSCHANGED";
31 case WM_SETFOCUS
: return "WM_SETFOCUS";
32 case WM_KILLFOCUS
: return "WM_KILLFOCUS";
33 case WM_NCPAINT
: return "WM_NCPAINT";
34 case WM_PAINT
: return "WM_PAINT";
35 case WM_ERASEBKGND
: return "WM_ERASEBKGND";
36 case WM_SIZE
: return "WM_SIZE";
37 case WM_MOVE
: return "WM_MOVE";
38 case WM_SHOWWINDOW
: return "WM_SHOWWINDOW";
39 case WM_QUERYNEWPALETTE
: return "WM_QUERYNEWPALETTE";
40 case WM_MOUSELEAVE
: return "WM_MOUSELEAVE";
41 case WM_MOUSEHOVER
: return "WM_MOUSEHOVER";
42 case WM_NCMOUSELEAVE
: return "WM_NCMOUSELEAVE";
43 case WM_NCMOUSEHOVER
: return "WM_NCMOUSEHOVER";
44 case WM_NCHITTEST
: return "WM_NCHITTEST";
45 case WM_SETCURSOR
: return "WM_SETCURSOR";
46 case WM_MOUSEMOVE
: return "WM_MOUSEMOVE";
47 case WM_SYSTIMER
: return "WM_SYSTIMER";
48 case WM_GETMINMAXINFO
: return "WM_GETMINMAXINFO";
49 case WM_NCCALCSIZE
: return "WM_NCCALCSIZE";
50 case WM_SETTINGCHANGE
: return "WM_SETTINGCHANGE";
51 case WM_GETICON
: return "WM_GETICON";
52 case WM_SETICON
: return "WM_SETICON";
53 case WM_KEYDOWN
: return "WM_KEYDOWN";
54 case WM_KEYUP
: return "WM_KEYUP";
59 static char* get_hook_name(UINT id
)
63 case WH_KEYBOARD
: return "WH_KEYBOARD";
64 case WH_KEYBOARD_LL
: return "WH_KEYBOARD_LL";
65 case WH_MOUSE
: return "WH_MOUSE";
66 case WH_MOUSE_LL
: return "WH_MOUSE_LL";
71 void empty_message_cache(MSG_CACHE
* cache
)
73 memset(cache
, 0, sizeof(MSG_CACHE
));
76 void sprintf_msg_entry(char* buffer
, MSG_ENTRY
* msg
)
78 if(!msg
->iwnd
&& !msg
->msg
)
80 sprintf(buffer
, "nothing");
90 msgName
= get_msg_name(msg
->msg
);
94 msgName
= get_msg_name(msg
->msg
);
98 msgName
= get_hook_name(msg
->msg
);
110 sprintf(buffer
, "hwnd%d %s %s %d %d", msg
->iwnd
, msgType
, msgName
, msg
->param1
, msg
->param2
);
112 sprintf(buffer
, "hwnd%d %s %d %d %d", msg
->iwnd
, msgType
, msg
->msg
, msg
->param1
, msg
->param2
);
116 void trace_cache(MSG_CACHE
* cache
, const char* file
, int line
)
121 for (i
=0; i
< cache
->count
; i
++)
123 sprintf_msg_entry(buff
, &cache
->message_cache
[i
]);
124 trace_(file
,line
)("%d: %s\n", i
, buff
);
126 trace_(file
,line
)("\n");
129 void compare_cache(MSG_CACHE
* cache
, const char* file
, int line
, MSG_ENTRY
*msg_chain
)
132 char buffGot
[100], buffExp
[100];
133 BOOL got_error
= FALSE
;
137 BOOL same
= !memcmp(&cache
->message_cache
[i
],msg_chain
, sizeof(MSG_ENTRY
));
139 sprintf_msg_entry(buffGot
, &cache
->message_cache
[i
]);
140 sprintf_msg_entry(buffExp
, msg_chain
);
141 ok_(file
,line
)(same
,"%d: got %s, expected %s\n",i
, buffGot
, buffExp
);
143 if(!got_error
&& !same
)
146 if(msg_chain
->msg
!=0 || msg_chain
->iwnd
!= 0)
158 trace_(file
,line
)("The complete list of messages got is:\n");
159 trace_cache(cache
, file
,line
);
162 empty_message_cache(cache
);
165 void record_message(MSG_CACHE
* cache
, int iwnd
, UINT message
, MSG_TYPE type
, int param1
,int param2
)
167 if(cache
->count
>= 100)
172 /* do not report a post message a second time */
174 cache
->last_post_message
.iwnd
== iwnd
&&
175 cache
->last_post_message
.msg
== message
&&
176 cache
->last_post_message
.param1
== param1
&&
177 cache
->last_post_message
.param2
== param2
)
179 memset(&cache
->last_post_message
, 0, sizeof(MSG_ENTRY
));
183 cache
->message_cache
[cache
->count
].iwnd
= iwnd
;
184 cache
->message_cache
[cache
->count
].msg
= message
;
185 cache
->message_cache
[cache
->count
].type
= type
;
186 cache
->message_cache
[cache
->count
].param1
= param1
;
187 cache
->message_cache
[cache
->count
].param2
= param2
;
189 if(cache
->message_cache
[cache
->count
].type
== POST
)
191 cache
->last_post_message
= cache
->message_cache
[cache
->count
];
195 memset(&cache
->last_post_message
, 0, sizeof(MSG_ENTRY
));
201 ATOM
RegisterSimpleClass(WNDPROC lpfnWndProc
, LPCWSTR lpszClassName
)
205 memset(&wcex
, 0, sizeof(wcex
));
206 wcex
.cbSize
= sizeof(WNDCLASSEX
);
207 wcex
.lpfnWndProc
= lpfnWndProc
;
208 wcex
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
209 wcex
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+1);
210 wcex
.lpszClassName
= lpszClassName
;
211 return RegisterClassExW(&wcex
);