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     11,
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_WP | MSGLST_CMP_RES }, // FIXME: LPARAM doesn't match on win 10
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         {  TRUE,   WM_CHANGEUISTATE,       3,         0,     0, MSGLST_CMP_LP | MSGLST_CMP_RES },
52         {  FALSE,  WM_CHANGEUISTATE,       3,         0,     0, MSGLST_CMP_LP | MSGLST_CMP_RES },
53     }
54 };
55 
56 void DumpMsgList(const char* lstName, const tagMsgList *ml)
57 {
58     const char *dlgProcName;
59     int i1;
60 
61     printf("%s\n", lstName);
62     for (i1 = 0; i1 < ml->msgCount; i1++)
63     {
64         dlgProcName = (ml->msgList[i1].DlgProc)  ? "DlgProc" : "WndProc";
65         printf("#%.3d %s, msg 0x%x, wParam 0x%Ix, lParam 0x%Ix, result %d\n",
66                i1,
67                dlgProcName,
68                ml->msgList[i1].msg,
69                ml->msgList[i1].wParam,
70                ml->msgList[i1].lParam,
71                ml->msgList[i1].result);
72     }
73 }
74 
75 BOOL CmpMsgList(const tagMsgList *recvd,
76                 const tagMsgList *expect)
77 {
78     int i1;
79     BOOL isOk;
80 
81     isOk = TRUE;
82     if (recvd->msgCount != expect->msgCount)
83     {
84         ok(FALSE, "%d messages expected, %d messages received!\n",
85            expect->msgCount, recvd->msgCount);
86         isOk = FALSE;
87     }
88     else
89     {
90         for (i1 = 0; i1 < recvd->msgCount; i1++)
91         {
92             if (expect->msgList[i1].DlgProc != recvd->msgList[i1].DlgProc)
93                 isOk = FALSE;
94             if (expect->msgList[i1].msg != recvd->msgList[i1].msg)
95                 isOk = FALSE;
96             if ((expect->msgList[i1].cmpflag & MSGLST_CMP_WP) &&
97                 (expect->msgList[i1].wParam != recvd->msgList[i1].wParam))
98                 isOk = FALSE;
99             if ((expect->msgList[i1].cmpflag & MSGLST_CMP_LP) &&
100                 (expect->msgList[i1].lParam != recvd->msgList[i1].lParam))
101                 isOk = FALSE;
102             if ((expect->msgList[i1].cmpflag & MSGLST_CMP_RES) &&
103                 (expect->msgList[i1].result != recvd->msgList[i1].result))
104                 isOk = FALSE;
105             if (!isOk)
106             {
107                 ok(FALSE, "Message #%.3d not equal\n", i1);
108                 break;
109             }
110         }
111     }
112 
113     if (!isOk)
114     {
115         DumpMsgList("RECEIVED", recvd);
116         DumpMsgList("EXPECTED", expect);
117         return FALSE;
118     }
119 
120     ok(TRUE, "\n");
121     return TRUE;
122 }
123 
124 INT_PTR CALLBACK Test_CreateDialogW_DLGPROC(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
125 {
126     if (msglist.msgCount < TEST_MAX_MSG)
127     {
128         msglist.msgList[msglist.msgCount].DlgProc = TRUE;
129         msglist.msgList[msglist.msgCount].msg     = msg;
130         msglist.msgList[msglist.msgCount].wParam  = wParam;
131         msglist.msgList[msglist.msgCount].lParam  = lParam;
132         msglist.msgList[msglist.msgCount].result  = 0;
133         msglist.msgCount++;
134     }
135     trace("DlgProc: msg 0x%x, wParam 0x%x, lParam 0x%Ix\n",
136            msg, wParam, lParam);
137     return FALSE;
138 }
139 
140 LRESULT CALLBACK Test_CreateDialogW_WNDPROC(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
141 {
142     LRESULT res;
143     res = DefDlgProcW(hWnd, msg, wParam, lParam);
144 
145     if (msglist.msgCount < TEST_MAX_MSG)
146     {
147         msglist.msgList[msglist.msgCount].DlgProc = FALSE;
148         msglist.msgList[msglist.msgCount].msg     = msg;
149         msglist.msgList[msglist.msgCount].wParam  = wParam;
150         msglist.msgList[msglist.msgCount].lParam  = lParam;
151         msglist.msgList[msglist.msgCount].result  = res;
152         msglist.msgCount++;
153     }
154     trace("WndProc: msg 0x%x, wParam 0x%x, lParam 0x%Ix, result %Id\n",
155           msg, wParam, lParam, res);
156     return res;
157 }
158 
159 void Test_CreateDialogW()
160 {
161     HWND hWnd;
162     HMODULE hMod;
163     DWORD exstyle;
164     WNDCLASSW wc;
165 
166     hMod = GetModuleHandle(NULL);
167     ok(hMod != NULL, "\n");
168 
169     msglist.msgCount = 0;
170     wc.style         = CS_HREDRAW | CS_VREDRAW;
171     wc.lpfnWndProc   = Test_CreateDialogW_WNDPROC;
172     wc.cbClsExtra    = 0;
173     wc.cbWndExtra    = DLGWINDOWEXTRA;
174     wc.hInstance     = hMod;
175     wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
176     wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
177     wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
178     wc.lpszMenuName  = NULL;
179     wc.lpszClassName = L"TestDialogClass";
180 
181     if (!RegisterClassW(&wc))
182     {
183          ok(FALSE, "Error registering Window-Class\n");
184          return;
185     }
186     hWnd = CreateDialogW(hMod, L"TESTDIALOG", 0, Test_CreateDialogW_DLGPROC);
187     ok(hWnd != NULL, "Error: %lu\n", GetLastError());
188     if (hWnd != NULL)
189     {
190         /* Check the exstyle */
191         exstyle = GetWindowLongW(hWnd, GWL_EXSTYLE);
192         ok(exstyle != 0x50010, "ExStyle wrong, got %#08lX, expected 0x50010.\n", exstyle);
193         /* Check the messages we received during creation */
194         CmpMsgList(&msglist, &t1msgList);
195     }
196 }
197 
198 START_TEST(CreateDialog)
199 {
200     //Test_CreateDialogA();//TODO
201     Test_CreateDialogW();
202 }
203