ReactOS 0.4.16-dev-91-g764881a
msgtrace.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: helper functions
5 * PROGRAMMERS: Giannis Adamopoulos
6 */
7
8#include <apitest.h>
9
10#include <stdio.h>
11#include <winuser.h>
12#include <msgtrace.h>
13#include <undocuser.h>
14
16#ifdef _MSC_VER
17 0
18#endif
19};
21
22static char* get_msg_name(UINT msg)
23{
24 switch(msg)
25 {
26 case WM_CREATE: return "WM_CREATE";
27 case WM_NCCREATE: return "WM_NCCREATE";
28 case WM_PARENTNOTIFY: return "WM_PARENTNOTIFY";
29 case WM_DESTROY: return "WM_DESTROY";
30 case WM_NCDESTROY: return "WM_NCDESTROY";
31 case WM_CHILDACTIVATE: return "WM_CHILDACTIVATE";
32 case WM_NCACTIVATE: return "WM_NCACTIVATE";
33 case WM_ACTIVATE: return "WM_ACTIVATE";
34 case WM_ACTIVATEAPP: return "WM_ACTIVATEAPP";
35 case WM_WINDOWPOSCHANGING: return "WM_WINDOWPOSCHANGING";
36 case WM_WINDOWPOSCHANGED: return "WM_WINDOWPOSCHANGED";
37 case WM_SETFOCUS: return "WM_SETFOCUS";
38 case WM_KILLFOCUS: return "WM_KILLFOCUS";
39 case WM_NCPAINT: return "WM_NCPAINT";
40 case WM_PAINT: return "WM_PAINT";
41 case WM_ERASEBKGND: return "WM_ERASEBKGND";
42 case WM_SIZE: return "WM_SIZE";
43 case WM_MOVE: return "WM_MOVE";
44 case WM_SHOWWINDOW: return "WM_SHOWWINDOW";
45 case WM_QUERYNEWPALETTE: return "WM_QUERYNEWPALETTE";
46 case WM_MOUSELEAVE: return "WM_MOUSELEAVE";
47 case WM_MOUSEHOVER: return "WM_MOUSEHOVER";
48 case WM_NCMOUSELEAVE: return "WM_NCMOUSELEAVE";
49 case WM_NCMOUSEHOVER: return "WM_NCMOUSEHOVER";
50 case WM_NCHITTEST: return "WM_NCHITTEST";
51 case WM_SETCURSOR: return "WM_SETCURSOR";
52 case WM_MOUSEMOVE: return "WM_MOUSEMOVE";
53 case WM_SYSTIMER: return "WM_SYSTIMER";
54 case WM_GETMINMAXINFO: return "WM_GETMINMAXINFO";
55 case WM_NCCALCSIZE: return "WM_NCCALCSIZE";
56 case WM_SETTINGCHANGE: return "WM_SETTINGCHANGE";
57 case WM_GETICON: return "WM_GETICON";
58 case WM_SETICON: return "WM_SETICON";
59 case WM_KEYDOWN: return "WM_KEYDOWN";
60 case WM_KEYUP: return "WM_KEYUP";
61 case WM_NOTIFY: return "WM_NOTIFY";
62 case WM_COMMAND: return "WM_COMMAND";
63 case WM_PRINTCLIENT: return "WM_PRINTCLIENT";
64 case WM_CTLCOLORSTATIC: return "WM_CTLCOLORSTATIC";
65 case WM_STYLECHANGING: return "WM_STYLECHANGING";
66 case WM_STYLECHANGED: return "WM_STYLECHANGED";
67 default: return NULL;
68 }
69}
70
71static char* get_hook_name(UINT id)
72{
73 switch (id)
74 {
75 case WH_KEYBOARD: return "WH_KEYBOARD";
76 case WH_KEYBOARD_LL: return "WH_KEYBOARD_LL";
77 case WH_MOUSE: return "WH_MOUSE";
78 case WH_MOUSE_LL: return "WH_MOUSE_LL";
79 default: return NULL;
80 }
81}
82
84{
85 memset(cache, 0, sizeof(MSG_CACHE));
86}
87
89{
90 if(!msg->iwnd && !msg->msg)
91 {
92 sprintf(buffer, "nothing");
93 }
94 else
95 {
96 char* msgName;
97 char* msgType;
98
99 switch (msg->type)
100 {
101 case POST:
102 case MARKER:
103 msgName = get_msg_name(msg->msg);
104 msgType = msg->type == POST ? "post msg" : "marker";
105 break;
106 case SENT:
107 case SENT_RET:
108 msgName = get_msg_name(msg->msg);
109 msgType = msg->type == SENT ? "sent msg" : "sent_ret msg";
110 break;
111 case HOOK:
112 msgName = get_hook_name(msg->msg);
113 msgType = "hook";
114 break;
115 case EVENT:
116 msgName = NULL;
117 msgType = "event";
118 break;
119 default:
120 return;
121 }
122
123 if(msgName)
124 sprintf(buffer, "hwnd%d %s %s %d %d", msg->iwnd, msgType, msgName, msg->param1, msg->param2);
125 else
126 sprintf(buffer, "hwnd%d %s %d %d %d", msg->iwnd, msgType, msg->msg, msg->param1, msg->param2);
127 }
128}
129
130void trace_cache(MSG_CACHE* cache, const char* file, int line)
131{
132 int i;
133 char buff[100];
134
135 for (i=0; i < cache->count; i++)
136 {
137 sprintf_msg_entry(buff, &cache->message_cache[i]);
138 trace_(file,line)("%d: %s\n", i, buff);
139 }
140 trace_(file,line)("\n");
141}
142
143void compare_cache(MSG_CACHE* cache, const char* file, int line, MSG_ENTRY *msg_chain)
144{
145 int i = 0;
146 char buffGot[100], buffExp[100];
147 BOOL got_error = FALSE;
148
149 while(1)
150 {
151 BOOL same = !memcmp(&cache->message_cache[i],msg_chain, sizeof(MSG_ENTRY));
152
153 sprintf_msg_entry(buffGot, &cache->message_cache[i]);
154 sprintf_msg_entry(buffExp, msg_chain);
155 ok_(file,line)(same,"%d: got %s, expected %s\n",i, buffGot, buffExp);
156
157 if(!got_error && !same)
158 got_error = TRUE;
159
160 if(msg_chain->msg !=0 || msg_chain->iwnd != 0)
161 msg_chain++;
162 else
163 {
164 if(i > cache->count)
165 break;
166 }
167 i++;
168 }
169
170 if(got_error )
171 {
172 trace_(file,line)("The complete list of messages got is:\n");
174 }
175
177}
178
179void record_message(MSG_CACHE* cache, int iwnd, UINT message, MSG_TYPE type, int param1,int param2)
180{
181 if(cache->count >= 100)
182 {
183 return;
184 }
185
186 /* do not report a post message a second time */
187 if(type == SENT &&
188 cache->last_post_message.iwnd == iwnd &&
189 cache->last_post_message.msg == message &&
190 cache->last_post_message.param1 == param1 &&
191 cache->last_post_message.param2 == param2)
192 {
193 memset(&cache->last_post_message, 0, sizeof(MSG_ENTRY));
194 return;
195 }
196
197 cache->message_cache[cache->count].iwnd = iwnd;
198 cache->message_cache[cache->count].msg = message;
199 cache->message_cache[cache->count].type = type;
200 cache->message_cache[cache->count].param1 = param1;
201 cache->message_cache[cache->count].param2 = param2;
202
203 if(cache->message_cache[cache->count].type == POST)
204 {
205 cache->last_post_message = cache->message_cache[cache->count];
206 }
207 else
208 {
209 memset(&cache->last_post_message, 0, sizeof(MSG_ENTRY));
210 }
211
212 cache->count++;
213}
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
#define ok_(x1, x2)
Definition: atltest.h:61
#define msg(x)
Definition: auth_time.c:54
#define WM_SYSTIMER
Definition: comctl32.h:125
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
static unsigned char buff[32768]
Definition: fatten.c:17
unsigned int BOOL
Definition: ntddk_ex.h:94
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLuint buffer
Definition: glext.h:5915
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
struct tagHOOK HOOK
#define trace_(file, line,...)
Definition: kmt_test.h:223
#define sprintf(buf, format,...)
Definition: sprintf.c:55
MSG_ENTRY empty_chain[]
Definition: msgtrace.c:20
void trace_cache(MSG_CACHE *cache, const char *file, int line)
Definition: msgtrace.c:130
void record_message(MSG_CACHE *cache, int iwnd, UINT message, MSG_TYPE type, int param1, int param2)
Definition: msgtrace.c:179
MSG_CACHE default_cache
Definition: msgtrace.c:15
void compare_cache(MSG_CACHE *cache, const char *file, int line, MSG_ENTRY *msg_chain)
Definition: msgtrace.c:143
void sprintf_msg_entry(char *buffer, MSG_ENTRY *msg)
Definition: msgtrace.c:88
static char * get_msg_name(UINT msg)
Definition: msgtrace.c:22
static char * get_hook_name(UINT id)
Definition: msgtrace.c:71
void empty_message_cache(MSG_CACHE *cache)
Definition: msgtrace.c:83
enum _MSG_TYPE MSG_TYPE
@ EVENT
Definition: msgtrace.h:9
@ POST
Definition: msgtrace.h:7
@ MARKER
Definition: msgtrace.h:11
@ SENT_RET
Definition: msgtrace.h:10
@ SENT
Definition: msgtrace.h:6
unsigned int UINT
Definition: ndis.h:50
#define WM_MOUSELEAVE
Definition: commctrl.h:4980
#define WM_MOUSEHOVER
Definition: commctrl.h:4979
#define WM_PRINTCLIENT
Definition: richedit.h:70
#define WM_NOTIFY
Definition: richedit.h:61
#define memset(x, y, z)
Definition: compat.h:39
Definition: msgtrace.h:15
int iwnd
Definition: msgtrace.h:16
UINT msg
Definition: msgtrace.h:17
Definition: cache.c:49
Definition: fci.c:127
Definition: parser.c:49
Definition: tftpd.h:60
#define WM_PAINT
Definition: winuser.h:1623
#define WM_ERASEBKGND
Definition: winuser.h:1628
#define WM_QUERYNEWPALETTE
Definition: winuser.h:1881
#define WH_KEYBOARD
Definition: winuser.h:32
#define WM_CTLCOLORSTATIC
Definition: winuser.h:1775
#define WM_KEYUP
Definition: winuser.h:1719
#define WM_WINDOWPOSCHANGING
Definition: winuser.h:1664
#define WM_CHILDACTIVATE
Definition: winuser.h:1641
#define WM_CREATE
Definition: winuser.h:1611
#define WM_SIZE
Definition: winuser.h:1614
#define WM_COMMAND
Definition: winuser.h:1743
#define WM_NCHITTEST
Definition: winuser.h:1689
#define WM_SETFOCUS
Definition: winuser.h:1616
#define WM_MOUSEMOVE
Definition: winuser.h:1778
#define WM_NCCREATE
Definition: winuser.h:1686
#define WM_ACTIVATE
Definition: winuser.h:1615
#define WM_SHOWWINDOW
Definition: winuser.h:1631
#define WM_SETTINGCHANGE
Definition: winuser.h:1632
#define WH_MOUSE_LL
Definition: winuser.h:44
#define WM_NCACTIVATE
Definition: winuser.h:1691
#define WM_GETMINMAXINFO
Definition: winuser.h:1643
#define WH_MOUSE
Definition: winuser.h:37
#define WH_KEYBOARD_LL
Definition: winuser.h:43
#define WM_MOVE
Definition: winuser.h:1613
#define WM_NCDESTROY
Definition: winuser.h:1687
#define WM_SETCURSOR
Definition: winuser.h:1639
#define WM_ACTIVATEAPP
Definition: winuser.h:1635
#define WM_DESTROY
Definition: winuser.h:1612
#define WM_KEYDOWN
Definition: winuser.h:1718
#define WM_PARENTNOTIFY
Definition: winuser.h:1806
#define WM_NCMOUSELEAVE
Definition: winuser.h:1845
#define WM_NCCALCSIZE
Definition: winuser.h:1688
#define WM_WINDOWPOSCHANGED
Definition: winuser.h:1665
#define WM_KILLFOCUS
Definition: winuser.h:1617
#define WM_NCMOUSEHOVER
Definition: winuser.h:1844
#define WM_NCPAINT
Definition: winuser.h:1690