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