ReactOS 0.4.17-dev-966-gf06eace
mciwnd.c
Go to the documentation of this file.
1/*
2 * Unit tests for MCIWnd
3 *
4 * Copyright 2019 Sven Baars
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21#define WIN32_LEAN_AND_MEAN
22
23#include <windows.h>
24#include <vfw.h>
25
26#include "wine/test.h"
27
28static const DWORD file_header[] = /* file_header */
29{
30 FOURCC_RIFF, 0x8c0 /* file size */,
32 FOURCC_LIST, 0xc0 /* list length */,
34};
35
37{
38 0x0001046b, /* dwMicroSecPerFrame */
39 0x00000000, /* dwMaxBytesPerSec */
40 0x00000000, /* dwPaddingGranularity */
41 0x00000810, /* dwFlags */
42 2, /* dwTotalFrames */
43 0, /* dwInitialFrames */
44 1, /* dwStreams */
45 0x48, /* dwSuggestedBufferSize*/
46 5, /* dwWidth */
47 5, /* dwHeight */
48 { 0, 0, 0, 0 } /* dwReserved[4] */
49};
50
51static const DWORD stream_list[] =
52{
53 FOURCC_LIST, 0x74 /* length */,
54 listtypeSTREAMHEADER, ckidSTREAMHEADER, 0x38 /* length */,
55};
56
58{
59 streamtypeVIDEO, /* fccType */
60 0, /* fccHandler */
61 0, /* dwFlags */
62 0, /* wPriority */
63 0, /* wLanguage */
64 0, /* dwInitialFrames */
65 1, /* dwScale */
66 0xf, /* dwRate */
67 0, /* dwStart */
68 2, /* dwLength */
69 0x48, /* dwSuggestedBufferSize*/
70 0, /* dwQuality */
71 0, /* dwSampleSize */
72 { 0, 0, 0, 0 } /* short left right top bottom */
73};
74
75static const DWORD video_stream_format[] =
76{
78 0x28 /* length */,
79 0x28 /* length */,
80 5 /* width */,
81 5 /* height */,
82 0x00180001 ,
83 mmioFOURCC('c', 'v', 'i', 'd'),
84 0x245a,
85 0, 0, 0, 0,
86};
87
88static const DWORD padding[] =
89{
90 ckidAVIPADDING, 0x718 /* length */,
91};
92
93static const DWORD data[] =
94{
95 FOURCC_LIST, 0xa4 /* length */, listtypeAVIMOVIE,
96 mmioFOURCC('0', '0', 'd', 'b'), 0x48, 0x48000000, 0x08000800,
97 0x00100100, 0x00003e00, 0x08000000, 0x00200800,
98 0x00001600, 0x00000000, 0x00003a00, 0x22e306f9,
99 0xfc120000, 0x0a000022, 0x00000000, 0x00300000,
100 0x00c01200, 0x00000000, 0x02010000, 0x00000000,
101 mmioFOURCC('0', '0', 'd', 'b'), 0x48, 0x48000000, 0x08000800,
102 0x00100100, 0x00003e00, 0x08000000, 0x00200800,
103 0x00001600, 0x00000000, 0x00003a00, 0x22e306f9,
104 0xfc120000, 0x0a000022, 0x00000000, 0x00300000,
105 0x00c01200, 0x00000000, 0x02010000, 0x00000000,
106 mmioFOURCC('i', 'd', 'x', '1'), 0x20, mmioFOURCC('0', '0', 'd', 'b'), 0x10,
107 0x04, 0x48, mmioFOURCC('0', '0', 'd', 'b'), 0x10,
108 0x54, 0x48,
109};
110
111static BOOL create_avi_file(char *fname)
112{
114 DWORD written;
115 char temp_path[MAX_PATH];
116 BOOL ret;
117 BYTE *buffer;
118 ULONG buffer_length;
119
121 ok(ret, "Failed to get a temp path, err %ld\n", GetLastError());
122 if (!ret)
123 return FALSE;
124
125 ret = GetTempFileNameA(temp_path, "mci", 0, fname);
126 ok(ret, "Failed to get a temp name, err %ld\n", GetLastError());
127 if (!ret)
128 return FALSE;
129 DeleteFileA(fname);
130
131 lstrcatA(fname, ".avi");
132
134 ok(hFile != INVALID_HANDLE_VALUE, "Failed to create a file, err %ld\n", GetLastError());
135 if (hFile == INVALID_HANDLE_VALUE) return FALSE;
136
137 buffer_length = padding[1];
138 buffer = calloc(1, buffer_length);
139
140 WriteFile(hFile, file_header, sizeof(file_header), &written, NULL);
141 WriteFile(hFile, &main_avi_header, sizeof(MainAVIHeader), &written, NULL);
142 WriteFile(hFile, stream_list, sizeof(stream_list), &written, NULL);
145 WriteFile(hFile, padding, sizeof(padding), &written, NULL);
146 WriteFile(hFile, buffer, buffer_length, &written, NULL);
147 WriteFile(hFile, data, sizeof(data), &written, NULL);
148
149 free(buffer);
150
152 return ret;
153}
154
155/* expected information for window creation */
156static struct {
157 /* input */
158 const char* expectedA;
160 /* output */
161 unsigned open_msg;
162 enum {NO_MATCH, PTR_ANSI_MATCH, PTR_UNICODE_MATCH, ANSI_MATCH, UNICODE_MATCH } match;
164
167{
168 switch (wMsg)
169 {
170 case WM_CREATE:
171 {
173 if (cs->lpCreateParams)
174 {
175 if (cs->lpCreateParams == wnd_creation.expectedA)
176 wnd_creation.match = PTR_ANSI_MATCH;
177 else if (cs->lpCreateParams == wnd_creation.expectedW)
178 wnd_creation.match = PTR_UNICODE_MATCH;
179 else if (!strcmp(cs->lpCreateParams, wnd_creation.expectedA))
180 wnd_creation.match = ANSI_MATCH;
181 else if (!wcscmp(cs->lpCreateParams, wnd_creation.expectedW))
182 wnd_creation.match = UNICODE_MATCH;
183 }
184 }
185 break;
186 case MCIWNDM_OPENA:
187 case MCIWNDM_OPENW:
188 wnd_creation.open_msg = wMsg;
189 break;
190 default:
191 break;
192 }
193 return old_MCIWndProc(hWnd, wMsg, wParam, lParam);
194}
195
197{
198 if (code == HCBT_CREATEWND && lp)
199 {
200 CREATESTRUCTW* cs = ((CBT_CREATEWNDW *)lp)->lpcs;
201 if (cs && ((ULONG_PTR)cs->lpszClass >> 16) && !wcsicmp(cs->lpszClass, L"MCIWndClass"))
202 {
204 ok(old_MCIWndProc != NULL, "No wnd proc\n");
205 }
206 }
207
208 return CallNextHookEx( NULL, code, wp, lp );
209}
210
211static void test_window_create(unsigned line, const char* fname, HWND parent,
212 BOOL with_mci, BOOL call_ansi, unsigned match)
213{
215 WCHAR fnameW[MAX_PATH];
216 HWND window;
217 char error[200];
218 LRESULT ret;
219 BOOL expect_ansi = match == PTR_ANSI_MATCH || match == ANSI_MATCH;
220
221 MultiByteToWideChar(CP_ACP, 0, fname, -1, fnameW, ARRAY_SIZE(fnameW));
222
223 wnd_creation.expectedA = fname;
224 wnd_creation.expectedW = fnameW;
225 wnd_creation.open_msg = 0;
226 wnd_creation.match = NO_MATCH;
227
228 if (call_ansi)
229 {
230 if (with_mci)
232 else
233 window = CreateWindowExA(0, "MCIWndClass", NULL,
235 0, 0, 300, 0,
236 parent, 0, hinst, expect_ansi ? (LPVOID)fname : (LPVOID)fnameW);
237 }
238 else
239 {
240 if (with_mci)
242 else
243 window = CreateWindowExW(0, L"MCIWndClass", NULL,
245 0, 0, 300, 0,
246 parent, 0, hinst, expect_ansi ? (LPVOID)fname : (LPVOID)fnameW);
247 }
248 ok_(__FILE__, line)(window != NULL, "Failed to create an MCIWnd window\n");
249 ok_(__FILE__, line)(wnd_creation.match == match, "unexpected match %u\n", wnd_creation.match);
250 ok_(__FILE__, line)((expect_ansi && wnd_creation.open_msg == MCIWNDM_OPENA) ||
251 (!expect_ansi && wnd_creation.open_msg == MCIWNDM_OPENW),
252 "bad open message %u %s%u\n", match,
253 wnd_creation.open_msg >= WM_USER ? "WM_USER+" : "",
254 wnd_creation.open_msg >= WM_USER ? wnd_creation.open_msg - WM_USER : wnd_creation.open_msg);
256 ok_(__FILE__, line)(!ret || broken(ret == ERROR_INVALID_HANDLE) /* w2003std, w2008s64 */,
257 "Unexpected error %Id\n", ret);
259}
260
261static void test_MCIWndCreate(void)
262{
265 char fname[MAX_PATH];
266 char invalid_fname[] = "invalid.avi";
267 char error[200];
268 HHOOK hook;
269 LRESULT ret;
270
271 create_avi_file(fname);
272
274
275 test_window_create( __LINE__, fname, NULL, TRUE, TRUE, UNICODE_MATCH );
276 test_window_create( __LINE__, fname, NULL, TRUE, FALSE, PTR_UNICODE_MATCH );
277 test_window_create( __LINE__, fname, NULL, FALSE, TRUE, PTR_ANSI_MATCH );
278 test_window_create( __LINE__, fname, NULL, FALSE, FALSE, PTR_ANSI_MATCH );
279
280 parent = CreateWindowExA(0, "static", "msvfw32 test",
281 WS_POPUP, 0, 0, 100, 100,
282 0, 0, 0, NULL);
283 ok(parent != NULL, "Failed to create a window\n");
284 ok(!IsWindowUnicode(parent), "Expecting ansi parent window\n");
285
286 test_window_create( __LINE__, fname, parent, TRUE, TRUE, UNICODE_MATCH );
287 test_window_create( __LINE__, fname, parent, TRUE, FALSE, PTR_UNICODE_MATCH );
288 test_window_create( __LINE__, fname, parent, FALSE, TRUE, PTR_ANSI_MATCH );
289 test_window_create( __LINE__, fname, parent, FALSE, FALSE, PTR_ANSI_MATCH );
290
292
293 parent = CreateWindowExW(0, L"static", L"msvfw32 test",
294 WS_POPUP, 0, 0, 100, 100,
295 0, 0, 0, NULL);
296 ok(parent != NULL, "Failed to create a window\n");
297 ok(IsWindowUnicode(parent), "Expecting unicode parent window\n");
298
299 test_window_create( __LINE__, fname, parent, TRUE, TRUE, UNICODE_MATCH );
300 test_window_create( __LINE__, fname, parent, TRUE, FALSE, PTR_UNICODE_MATCH );
301 test_window_create( __LINE__, fname, parent, FALSE, TRUE, PTR_UNICODE_MATCH );
302 test_window_create( __LINE__, fname, parent, FALSE, FALSE, PTR_UNICODE_MATCH );
303
305
307
309 ok(window != NULL, "Failed to create an MCIWnd window\n");
310
312 todo_wine ok(ret == MCIERR_FILE_NOT_FOUND, "Unexpected error %Id\n", ret);
313
315
316 DeleteFileA(fname);
317}
318
320{
322}
@ hook
Definition: SystemMenu.c:35
#define ok(value,...)
Definition: atltest.h:57
#define broken(x)
Definition: atltest.h:178
#define START_TEST(x)
Definition: atltest.h:75
#define ok_(x1, x2)
Definition: atltest.h:61
#define streamtypeVIDEO
Definition: aviriff.h:92
#define ckidSTREAMHEADER
Definition: aviriff.h:88
#define ckidSTREAMFORMAT
Definition: aviriff.h:125
HWND hWnd
Definition: settings.c:17
#define ARRAY_SIZE(A)
Definition: main.h:20
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define free
Definition: debug_ros.c:5
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
#define CP_ACP
Definition: compat.h:109
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:740
#define MAX_PATH
Definition: compat.h:34
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define CALLBACK
Definition: compat.h:35
#define MultiByteToWideChar
Definition: compat.h:110
#define wcsicmp
Definition: compat.h:15
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
BOOL WINAPI WriteFile(_In_ HANDLE hFile, _In_reads_bytes_opt_(nNumberOfBytesToWrite) LPCVOID lpBuffer, _In_ DWORD nNumberOfBytesToWrite, _Out_opt_ LPDWORD lpNumberOfBytesWritten, _Inout_opt_ LPOVERLAPPED lpOverlapped)
Definition: rw.c:25
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
DWORD WINAPI GetTempPathA(IN DWORD nBufferLength, OUT LPSTR lpBuffer)
Definition: path.c:2072
_ACRTIMP int __cdecl wcscmp(const wchar_t *, const wchar_t *)
Definition: wcs.c:1977
_ACRTIMP int __cdecl strcmp(const char *, const char *)
Definition: string.c:3324
HWND VFWAPIV MCIWndCreateA(HWND hwndParent, HINSTANCE hInstance, DWORD dwStyle, LPCSTR szFile)
Definition: mciwnd.c:128
HWND VFWAPIV MCIWndCreateW(HWND hwndParent, HINSTANCE hInstance, DWORD dwStyle, LPCWSTR szFile)
Definition: mciwnd.c:104
return ret
Definition: mutex.c:147
#define L(x)
Definition: resources.c:13
r parent
Definition: btrfs.c:3010
UINT WINAPI GetTempFileNameA(IN LPCSTR lpPathName, IN LPCSTR lpPrefixString, IN UINT uUnique, OUT LPSTR lpTempFileName)
Definition: filename.c:26
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLuint buffer
Definition: glext.h:5915
unsigned int UINT
Definition: sysinfo.c:13
#define cs
Definition: i386-dis.c:442
if(dx< 0)
Definition: linetemp.h:194
LPSTR WINAPI lstrcatA(LPSTR lpString1, LPCSTR lpString2)
Definition: lstring.c:123
#define todo_wine
Definition: minitest.h:80
LONG_PTR LPARAM
Definition: minwindef.h:175
LONG_PTR LRESULT
Definition: minwindef.h:176
UINT_PTR WPARAM
Definition: minwindef.h:174
#define error(str)
Definition: mkdosfs.c:1605
#define FOURCC_RIFF
Definition: mmsystem.h:564
#define MCIERR_FILE_NOT_FOUND
Definition: mmsystem.h:585
#define FOURCC_LIST
Definition: mmsystem.h:565
#define mmioFOURCC(c0, c1, c2, c3)
Definition: mmsystem.h:38
#define CREATE_ALWAYS
Definition: disk.h:72
static HINSTANCE hinst
Definition: edit.c:551
static IHTMLWindow2 * window
Definition: events.c:77
enum @1952::@1953 match
static WNDPROC old_MCIWndProc
Definition: mciwnd.c:165
static const DWORD stream_list[]
Definition: mciwnd.c:51
static void test_MCIWndCreate(void)
Definition: mciwnd.c:261
static LRESULT CALLBACK hook_proc(int code, WPARAM wp, LPARAM lp)
Definition: mciwnd.c:196
unsigned open_msg
Definition: mciwnd.c:161
static const DWORD video_stream_format[]
Definition: mciwnd.c:75
const char * expectedA
Definition: mciwnd.c:158
static const DWORD padding[]
Definition: mciwnd.c:88
static LRESULT WINAPI proxy_MCIWndProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
Definition: mciwnd.c:166
static struct @1952 wnd_creation
static const AVIStreamHeader avi_stream_header
Definition: mciwnd.c:57
static BOOL create_avi_file(char *fname)
Definition: mciwnd.c:111
const WCHAR * expectedW
Definition: mciwnd.c:159
static void test_window_create(unsigned line, const char *fname, HWND parent, BOOL with_mci, BOOL call_ansi, unsigned match)
Definition: mciwnd.c:211
static const MainAVIHeader main_avi_header
Definition: mciwnd.c:36
static const DWORD file_header[]
Definition: mciwnd.c:28
char temp_path[MAX_PATH]
Definition: mspatcha.c:123
_In_ HANDLE hFile
Definition: mswsock.h:90
#define GENERIC_WRITE
Definition: nt_native.h:90
short WCHAR
Definition: pedump.c:58
#define WS_POPUP
Definition: pedump.c:616
#define WS_CLIPSIBLINGS
Definition: pedump.c:618
#define WS_CLIPCHILDREN
Definition: pedump.c:619
HWND WINAPI CreateWindowExA(_In_ DWORD dwExStyle, _In_opt_ LPCSTR lpClassName, _In_opt_ LPCSTR lpWindowName, _In_ DWORD dwStyle, _In_ int X, _In_ int Y, _In_ int nWidth, _In_ int nHeight, _In_opt_ HWND hWndParent, _In_opt_ HMENU hMenu, _In_opt_ HINSTANCE hInstance, _In_opt_ LPVOID lpParam)
#define WM_CREATE
Definition: winuser.h:1636
HHOOK WINAPI SetWindowsHookExW(_In_ int, _In_ HOOKPROC, _In_opt_ HINSTANCE, _In_ DWORD)
LRESULT WINAPI SendMessageA(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define WH_CBT
Definition: winuser.h:35
#define HCBT_CREATEWND
Definition: winuser.h:58
BOOL WINAPI IsWindowUnicode(_In_ HWND)
BOOL WINAPI UnhookWindowsHookEx(_In_ HHOOK)
HWND WINAPI CreateWindowExW(_In_ DWORD dwExStyle, _In_opt_ LPCWSTR lpClassName, _In_opt_ LPCWSTR lpWindowName, _In_ DWORD dwStyle, _In_ int X, _In_ int Y, _In_ int nWidth, _In_ int nHeight, _In_opt_ HWND hWndParent, _In_opt_ HMENU hMenu, _In_opt_ HINSTANCE hInstance, _In_opt_ LPVOID lpParam)
LRESULT WINAPI CallNextHookEx(_In_opt_ HHOOK, _In_ int, _In_ WPARAM, _In_ LPARAM)
#define WM_USER
Definition: winuser.h:1923
LRESULT(CALLBACK * WNDPROC)(HWND, UINT, WPARAM, LPARAM)
Definition: winuser.h:3014
#define SetWindowLongPtrW
Definition: winuser.h:5512
BOOL WINAPI DestroyWindow(_In_ HWND)
#define calloc
Definition: rosglue.h:14
Definition: inflate.c:139
Definition: parser.c:49
Definition: match.c:28
#define GWLP_WNDPROC
Definition: treelist.c:66
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint32_t ULONG
Definition: typedefs.h:59
struct _MainAVIHeader MainAVIHeader
#define listtypeAVIMOVIE
Definition: vfw.h:898
#define MCIWNDM_GETERRORA
Definition: vfw.h:1964
#define listtypeSTREAMHEADER
Definition: vfw.h:892
#define listtypeAVIHEADER
Definition: vfw.h:890
#define MCIWNDF_NOERRORDLG
Definition: vfw.h:1807
#define ckidAVIPADDING
Definition: vfw.h:916
#define ckidAVIMAINHDR
Definition: vfw.h:891
#define MCIWNDM_OPENW
Definition: vfw.h:1979
#define formtypeAVI
Definition: vfw.h:889
#define MCIWNDM_OPENA
Definition: vfw.h:1967
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
DWORD WINAPI GetCurrentThreadId(void)
Definition: thread.c:459
#define WINAPI
Definition: msvc.h:6
unsigned char BYTE
Definition: xxhash.c:193