2011-09-23 12:05:40 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS api tests
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
|
|
|
* PURPOSE: helper functions
|
|
|
|
* PROGRAMMERS: Giannis Adamopoulos
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <wine/test.h>
|
2013-02-05 17:54:22 +00:00
|
|
|
#include <winuser.h>
|
2011-09-23 12:05:40 +00:00
|
|
|
#include "helper.h"
|
2011-09-24 11:55:19 +00:00
|
|
|
#include <undocuser.h>
|
2011-09-23 12:05:40 +00:00
|
|
|
|
2012-08-13 18:04:04 +00:00
|
|
|
MSG_CACHE default_cache = {
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
0
|
|
|
|
#endif
|
|
|
|
};
|
2011-09-30 15:37:13 +00:00
|
|
|
MSG_ENTRY empty_chain[]= {{0,0}};
|
|
|
|
|
2011-09-23 12:05:40 +00:00
|
|
|
static char* get_msg_name(UINT msg)
|
|
|
|
{
|
|
|
|
switch(msg)
|
|
|
|
{
|
|
|
|
case WM_NCACTIVATE: return "WM_NCACTIVATE";
|
|
|
|
case WM_ACTIVATE: return "WM_ACTIVATE";
|
|
|
|
case WM_ACTIVATEAPP: return "WM_ACTIVATEAPP";
|
|
|
|
case WM_WINDOWPOSCHANGING: return "WM_WINDOWPOSCHANGING";
|
|
|
|
case WM_WINDOWPOSCHANGED: return "WM_WINDOWPOSCHANGED";
|
|
|
|
case WM_SETFOCUS: return "WM_SETFOCUS";
|
|
|
|
case WM_KILLFOCUS: return "WM_KILLFOCUS";
|
|
|
|
case WM_NCPAINT: return "WM_NCPAINT";
|
|
|
|
case WM_PAINT: return "WM_PAINT";
|
|
|
|
case WM_ERASEBKGND: return "WM_ERASEBKGND";
|
|
|
|
case WM_SIZE: return "WM_SIZE";
|
|
|
|
case WM_MOVE: return "WM_MOVE";
|
|
|
|
case WM_SHOWWINDOW: return "WM_SHOWWINDOW";
|
|
|
|
case WM_QUERYNEWPALETTE: return "WM_QUERYNEWPALETTE";
|
|
|
|
case WM_MOUSELEAVE: return "WM_MOUSELEAVE";
|
|
|
|
case WM_MOUSEHOVER: return "WM_MOUSEHOVER";
|
|
|
|
case WM_NCMOUSELEAVE: return "WM_NCMOUSELEAVE";
|
|
|
|
case WM_NCMOUSEHOVER: return "WM_NCMOUSEHOVER";
|
|
|
|
case WM_NCHITTEST: return "WM_NCHITTEST";
|
|
|
|
case WM_SETCURSOR: return "WM_SETCURSOR";
|
|
|
|
case WM_MOUSEMOVE: return "WM_MOUSEMOVE";
|
2011-09-24 11:55:19 +00:00
|
|
|
case WM_SYSTIMER: return "WM_SYSTIMER";
|
2011-09-30 15:37:13 +00:00
|
|
|
case WM_GETMINMAXINFO: return "WM_GETMINMAXINFO";
|
|
|
|
case WM_NCCALCSIZE: return "WM_NCCALCSIZE";
|
2011-10-17 16:35:22 +00:00
|
|
|
case WM_SETTINGCHANGE: return "WM_SETTINGCHANGE";
|
|
|
|
case WM_GETICON: return "WM_GETICON";
|
|
|
|
case WM_SETICON: return "WM_SETICON";
|
2012-08-13 18:04:04 +00:00
|
|
|
case WM_KEYDOWN: return "WM_KEYDOWN";
|
|
|
|
case WM_KEYUP: return "WM_KEYUP";
|
2011-09-23 12:05:40 +00:00
|
|
|
default: return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-23 14:09:30 +00:00
|
|
|
static char* get_hook_name(UINT id)
|
|
|
|
{
|
|
|
|
switch (id)
|
|
|
|
{
|
|
|
|
case WH_KEYBOARD: return "WH_KEYBOARD";
|
|
|
|
case WH_KEYBOARD_LL: return "WH_KEYBOARD_LL";
|
|
|
|
case WH_MOUSE: return "WH_MOUSE";
|
|
|
|
case WH_MOUSE_LL: return "WH_MOUSE_LL";
|
|
|
|
default: return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-13 18:04:04 +00:00
|
|
|
void empty_message_cache(MSG_CACHE* cache)
|
2011-09-23 12:05:40 +00:00
|
|
|
{
|
2012-08-13 18:04:04 +00:00
|
|
|
memset(cache, 0, sizeof(MSG_CACHE));
|
2011-09-23 12:05:40 +00:00
|
|
|
}
|
|
|
|
|
2011-09-23 14:09:30 +00:00
|
|
|
void sprintf_msg_entry(char* buffer, MSG_ENTRY* msg)
|
|
|
|
{
|
|
|
|
if(!msg->iwnd && !msg->msg)
|
|
|
|
{
|
|
|
|
sprintf(buffer, "nothing");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-09-24 11:55:19 +00:00
|
|
|
char* msgName;
|
|
|
|
char* msgType;
|
|
|
|
|
|
|
|
switch (msg->type)
|
|
|
|
{
|
|
|
|
case POST:
|
|
|
|
msgName = get_msg_name(msg->msg);
|
|
|
|
msgType = "post msg";
|
|
|
|
break;
|
|
|
|
case SENT:
|
|
|
|
msgName = get_msg_name(msg->msg);
|
|
|
|
msgType = "sent msg";
|
|
|
|
break;
|
|
|
|
case HOOK:
|
|
|
|
msgName = get_hook_name(msg->msg);
|
|
|
|
msgType = "hook";
|
|
|
|
break;
|
|
|
|
case EVENT:
|
|
|
|
msgName = NULL;
|
|
|
|
msgType = "event";
|
|
|
|
break;
|
2011-09-24 12:05:14 +00:00
|
|
|
default:
|
|
|
|
return;
|
2011-09-24 11:55:19 +00:00
|
|
|
}
|
|
|
|
|
2011-09-23 14:09:30 +00:00
|
|
|
if(msgName)
|
|
|
|
sprintf(buffer, "hwnd%d %s %s %d %d", msg->iwnd, msgType, msgName, msg->param1, msg->param2);
|
|
|
|
else
|
|
|
|
sprintf(buffer, "hwnd%d %s %d %d %d", msg->iwnd, msgType, msg->msg, msg->param1, msg->param2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-13 18:04:04 +00:00
|
|
|
void trace_cache(MSG_CACHE* cache, const char* file, int line)
|
2011-09-23 12:05:40 +00:00
|
|
|
{
|
|
|
|
int i;
|
2011-09-23 14:09:30 +00:00
|
|
|
char buff[100];
|
2011-09-23 12:05:40 +00:00
|
|
|
|
2012-08-13 18:04:04 +00:00
|
|
|
for (i=0; i < cache->count; i++)
|
2011-09-23 12:05:40 +00:00
|
|
|
{
|
2012-08-13 18:04:04 +00:00
|
|
|
sprintf_msg_entry(buff, &cache->message_cache[i]);
|
2011-09-23 16:04:17 +00:00
|
|
|
trace_(file,line)("%d: %s\n", i, buff);
|
2011-09-23 12:05:40 +00:00
|
|
|
}
|
2011-09-23 14:09:30 +00:00
|
|
|
trace_(file,line)("\n");
|
2011-09-23 12:05:40 +00:00
|
|
|
}
|
|
|
|
|
2012-08-13 18:04:04 +00:00
|
|
|
void compare_cache(MSG_CACHE* cache, const char* file, int line, MSG_ENTRY *msg_chain)
|
2011-09-23 12:05:40 +00:00
|
|
|
{
|
|
|
|
int i = 0;
|
2011-09-23 14:09:30 +00:00
|
|
|
char buffGot[100], buffExp[100];
|
2011-09-23 12:05:40 +00:00
|
|
|
BOOL got_error = FALSE;
|
|
|
|
|
|
|
|
while(1)
|
|
|
|
{
|
2012-08-13 18:04:04 +00:00
|
|
|
BOOL same = !memcmp(&cache->message_cache[i],msg_chain, sizeof(MSG_ENTRY));
|
2011-09-23 12:05:40 +00:00
|
|
|
|
2012-08-13 18:04:04 +00:00
|
|
|
sprintf_msg_entry(buffGot, &cache->message_cache[i]);
|
2011-09-23 14:09:30 +00:00
|
|
|
sprintf_msg_entry(buffExp, msg_chain);
|
2011-09-23 16:04:17 +00:00
|
|
|
ok_(file,line)(same,"%d: got %s, expected %s\n",i, buffGot, buffExp);
|
2011-09-23 12:05:40 +00:00
|
|
|
|
|
|
|
if(!got_error && !same)
|
|
|
|
got_error = TRUE;
|
|
|
|
|
2011-09-25 16:05:09 +00:00
|
|
|
if(msg_chain->msg !=0 || msg_chain->iwnd != 0)
|
2011-09-23 12:05:40 +00:00
|
|
|
msg_chain++;
|
|
|
|
else
|
|
|
|
{
|
2012-08-13 18:04:04 +00:00
|
|
|
if(i > cache->count)
|
2011-09-23 12:05:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(got_error )
|
|
|
|
{
|
|
|
|
trace_(file,line)("The complete list of messages got is:\n");
|
2012-08-13 18:04:04 +00:00
|
|
|
trace_cache(cache, file,line);
|
2011-09-23 12:05:40 +00:00
|
|
|
}
|
|
|
|
|
2012-08-13 18:04:04 +00:00
|
|
|
empty_message_cache(cache);
|
2011-09-23 12:05:40 +00:00
|
|
|
}
|
|
|
|
|
2012-08-13 18:04:04 +00:00
|
|
|
void record_message(MSG_CACHE* cache, int iwnd, UINT message, MSG_TYPE type, int param1,int param2)
|
2011-09-23 12:05:40 +00:00
|
|
|
{
|
2012-08-13 18:04:04 +00:00
|
|
|
if(cache->count >= 100)
|
2011-09-23 12:05:40 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-09-24 11:55:19 +00:00
|
|
|
/* do not report a post message a second time */
|
|
|
|
if(type == SENT &&
|
2012-08-13 18:04:04 +00:00
|
|
|
cache->last_post_message.iwnd == iwnd &&
|
|
|
|
cache->last_post_message.msg == message &&
|
|
|
|
cache->last_post_message.param1 == param1 &&
|
|
|
|
cache->last_post_message.param2 == param2)
|
2011-09-24 11:55:19 +00:00
|
|
|
{
|
2012-08-13 18:04:04 +00:00
|
|
|
memset(&cache->last_post_message, 0, sizeof(MSG_ENTRY));
|
2011-09-24 11:55:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-08-13 18:04:04 +00:00
|
|
|
cache->message_cache[cache->count].iwnd = iwnd;
|
|
|
|
cache->message_cache[cache->count].msg = message;
|
|
|
|
cache->message_cache[cache->count].type = type;
|
|
|
|
cache->message_cache[cache->count].param1 = param1;
|
|
|
|
cache->message_cache[cache->count].param2 = param2;
|
2011-09-24 11:55:19 +00:00
|
|
|
|
2012-08-13 18:04:04 +00:00
|
|
|
if(cache->message_cache[cache->count].type == POST)
|
2011-09-24 11:55:19 +00:00
|
|
|
{
|
2012-08-13 18:04:04 +00:00
|
|
|
cache->last_post_message = cache->message_cache[cache->count];
|
2011-09-24 11:55:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-08-13 18:04:04 +00:00
|
|
|
memset(&cache->last_post_message, 0, sizeof(MSG_ENTRY));
|
2011-09-24 11:55:19 +00:00
|
|
|
}
|
|
|
|
|
2012-08-13 18:04:04 +00:00
|
|
|
cache->count++;
|
2011-09-23 12:05:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ATOM RegisterSimpleClass(WNDPROC lpfnWndProc, LPCWSTR lpszClassName)
|
|
|
|
{
|
|
|
|
WNDCLASSEXW wcex;
|
|
|
|
|
|
|
|
memset(&wcex, 0, sizeof(wcex));
|
|
|
|
wcex.cbSize = sizeof(WNDCLASSEX);
|
|
|
|
wcex.lpfnWndProc = lpfnWndProc;
|
|
|
|
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
|
|
|
|
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
|
|
|
|
wcex.lpszClassName = lpszClassName;
|
|
|
|
return RegisterClassExW(&wcex);
|
2011-10-17 16:35:22 +00:00
|
|
|
}
|