dfb33a5c008e3f91294dfeb6eb531d669f6ceb33
[reactos.git] / modules / rostests / apitests / user32 / CreateDialog.c
1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for CreateDialog
5 * PROGRAMMERS: Andreas Maier
6 */
7
8 #include <stdarg.h>
9 #include <stdio.h>
10 #include <apitest.h>
11
12 #include <wingdi.h>
13 #include <winuser.h>
14
15 #define TEST_MAX_MSG 50
16
17 // cmpflag
18 #define MSGLST_CMP_WP 0x1
19 #define MSGLST_CMP_LP 0x2
20 #define MSGLST_CMP_RES 0x4
21 #define MSGLST_CMP_ALL (MSGLST_CMP_WP | MSGLST_CMP_LP | MSGLST_CMP_RES)
22
23 typedef struct
24 {
25 BOOL DlgProc; // true = DlgProg, false WndProc
26 UINT msg;
27 WPARAM wParam;
28 LPARAM lParam;
29 int result;
30 int cmpflag;
31 } tagMsgInfo;
32
33 typedef struct
34 {
35 int msgCount;
36 tagMsgInfo msgList[TEST_MAX_MSG];
37 } tagMsgList;
38
39 tagMsgList msglist;
40
41 /* the expected message-list */
42 const tagMsgList t1msgList =
43 {
44 9,
45 {
46 // DlgProc, msg, wParam, lParam, result, cmpflag
47 { FALSE, WM_NCCREATE, 0, 0, 1, MSGLST_CMP_WP | MSGLST_CMP_RES },
48 { FALSE, WM_NCCALCSIZE, 0, 0, 0, MSGLST_CMP_WP | MSGLST_CMP_RES },
49 { FALSE, WM_CREATE, 0, 0, 0, MSGLST_CMP_WP | MSGLST_CMP_RES },
50 { FALSE, WM_SIZE, 0, 0x145012c, 0, MSGLST_CMP_ALL }, // FIXME: size is 400x400 on Win7?
51 { FALSE, WM_MOVE, 0, 0x0160003, 0, MSGLST_CMP_ALL },
52 { TRUE, WM_SETFONT, 0, 0, 0, MSGLST_CMP_LP | MSGLST_CMP_RES },
53 { FALSE, WM_SETFONT, 0, 0, 0, MSGLST_CMP_LP | MSGLST_CMP_RES },
54 { TRUE, WM_INITDIALOG, 0, 0, 0, MSGLST_CMP_LP | MSGLST_CMP_RES },
55 { FALSE, WM_INITDIALOG, 0, 0, 0, MSGLST_CMP_LP | MSGLST_CMP_RES },
56 }
57 };
58
59 void DumpMsgList(const char* lstName, const tagMsgList *ml)
60 {
61 const char *dlgProcName;
62 int i1;
63
64 printf("%s\n", lstName);
65 for (i1 = 0; i1 < ml->msgCount; i1++)
66 {
67 dlgProcName = (ml->msgList[i1].DlgProc) ? "DlgProc" : "WndProc";
68 printf("#%.3d %s, msg 0x%x, wParam 0x%x, lParam 0x%Ix, result %d\n",
69 i1,
70 dlgProcName,
71 ml->msgList[i1].msg,
72 ml->msgList[i1].wParam,
73 ml->msgList[i1].lParam,
74 ml->msgList[i1].result);
75 }
76 }
77
78 BOOL CmpMsgList(const tagMsgList *recvd,
79 const tagMsgList *expect)
80 {
81 int i1;
82 BOOL isOk;
83
84 isOk = TRUE;
85 if (recvd->msgCount != expect->msgCount)
86 {
87 ok(FALSE, "%d messages expected, %d messages received!\n",
88 expect->msgCount, recvd->msgCount);
89 isOk = FALSE;
90 }
91 else
92 {
93 for (i1 = 0; i1 < recvd->msgCount; i1++)
94 {
95 if (expect->msgList[i1].DlgProc != recvd->msgList[i1].DlgProc)
96 isOk = FALSE;
97 if (expect->msgList[i1].msg != recvd->msgList[i1].msg)
98 isOk = FALSE;
99 if ((expect->msgList[i1].cmpflag & MSGLST_CMP_WP) &&
100 (expect->msgList[i1].wParam != recvd->msgList[i1].wParam))
101 isOk = FALSE;
102 if ((expect->msgList[i1].cmpflag & MSGLST_CMP_LP) &&
103 (expect->msgList[i1].lParam != recvd->msgList[i1].lParam))
104 isOk = FALSE;
105 if ((expect->msgList[i1].cmpflag & MSGLST_CMP_RES) &&
106 (expect->msgList[i1].result != recvd->msgList[i1].result))
107 isOk = FALSE;
108 if (!isOk)
109 {
110 ok(FALSE, "Message #%.3d not equal\n", i1);
111 break;
112 }
113 }
114 }
115
116 if (!isOk)
117 {
118 DumpMsgList("RECEIVED", recvd);
119 DumpMsgList("EXPECTED", expect);
120 return FALSE;
121 }
122
123 ok(TRUE, "\n");
124 return TRUE;
125 }
126
127 INT_PTR CALLBACK Test_CreateDialogW_DLGPROC(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
128 {
129 if (msglist.msgCount < TEST_MAX_MSG)
130 {
131 msglist.msgList[msglist.msgCount].DlgProc = TRUE;
132 msglist.msgList[msglist.msgCount].msg = msg;
133 msglist.msgList[msglist.msgCount].wParam = wParam;
134 msglist.msgList[msglist.msgCount].lParam = lParam;
135 msglist.msgList[msglist.msgCount].result = 0;
136 msglist.msgCount++;
137 }
138 trace("DlgProc: msg 0x%x, wParam 0x%x, lParam 0x%Ix\n",
139 msg, wParam, lParam);
140 return FALSE;
141 }
142
143 LRESULT CALLBACK Test_CreateDialogW_WNDPROC(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
144 {
145 LRESULT res;
146 res = DefDlgProcW(hWnd, msg, wParam, lParam);
147
148 if (msglist.msgCount < TEST_MAX_MSG)
149 {
150 msglist.msgList[msglist.msgCount].DlgProc = FALSE;
151 msglist.msgList[msglist.msgCount].msg = msg;
152 msglist.msgList[msglist.msgCount].wParam = wParam;
153 msglist.msgList[msglist.msgCount].lParam = lParam;
154 msglist.msgList[msglist.msgCount].result = res;
155 msglist.msgCount++;
156 }
157 trace("WndProc: msg 0x%x, wParam 0x%x, lParam 0x%Ix, result %Id\n",
158 msg, wParam, lParam, res);
159 return res;
160 }
161
162 void Test_CreateDialogW()
163 {
164 HWND hWnd;
165 HMODULE hMod;
166 DWORD exstyle;
167 WNDCLASSW wc;
168
169 hMod = GetModuleHandle(NULL);
170 ok(hMod != NULL, "\n");
171
172 msglist.msgCount = 0;
173 wc.style = CS_HREDRAW | CS_VREDRAW;
174 wc.lpfnWndProc = Test_CreateDialogW_WNDPROC;
175 wc.cbClsExtra = 0;
176 wc.cbWndExtra = DLGWINDOWEXTRA;
177 wc.hInstance = hMod;
178 wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
179 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
180 wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
181 wc.lpszMenuName = NULL;
182 wc.lpszClassName = L"TestDialogClass";
183
184 if (!RegisterClassW(&wc))
185 {
186 ok(FALSE, "Error registering Window-Class\n");
187 return;
188 }
189 hWnd = CreateDialogW(hMod, L"TESTDIALOG", 0, Test_CreateDialogW_DLGPROC);
190 ok(hWnd != NULL, "Error: %lu\n", GetLastError());
191 if (hWnd != NULL)
192 {
193 /* Check the exstyle */
194 exstyle = GetWindowLongW(hWnd, GWL_EXSTYLE);
195 ok(exstyle != 0x50010, "ExStyle wrong, got %#08lX, expected 0x50010.\n", exstyle);
196 /* Check the messages we received during creation */
197 CmpMsgList(&msglist, &t1msgList);
198 }
199 }
200
201 START_TEST(CreateDialog)
202 {
203 //Test_CreateDialogA();//TODO
204 Test_CreateDialogW();
205 }