mfplat: Read queue subscriber within the critical section.
[wine/zf.git] / dlls / wmp / tests / media.c
blobfa6cb6490f1fa401d1822d1dcc13299b75bc8009
1 /*
2 * This library is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU Lesser General Public
4 * License as published by the Free Software Foundation; either
5 * version 2.1 of the License, or (at your option) any later version.
7 * This library is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * Lesser General Public License for more details.
12 * You should have received a copy of the GNU Lesser General Public
13 * License along with this library; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 #define WIN32_LEAN_AND_MEAN
18 #define COBJMACROS
19 #include <wmp.h>
20 #include <olectl.h>
21 #include <nserror.h>
22 #include <wmpids.h>
23 #include <math.h>
24 #include <assert.h>
26 #include "wine/test.h"
28 #define DEFINE_EXPECT(kind) \
29 static DWORD expect_ ## kind = 0, called_ ## kind = 0
31 #define SET_EXPECT(kind, index) \
32 do { \
33 assert(index < 8 * sizeof(expect_ ## kind)); \
34 expect_ ## kind |= (1 << index); \
35 }while(0)
37 #define CHECK_EXPECT(kind, index) \
38 do { \
39 ok(expect_ ##kind & (1 << index), "unexpected event for " #kind ", index:%d\n", index); \
40 called_ ## kind |= (1 << index); \
41 }while(0)
43 #define CLEAR_CALLED(kind, index) \
44 do { \
45 expect_ ## kind &= ~(1 << index); \
46 called_ ## kind &= ~(1 << index); \
47 }while(0)
49 #define CHECK_CALLED(kind, index) \
50 do { \
51 ok(called_ ## kind & (1 << index), "expected " #kind ", %d\n", index); \
52 expect_ ## kind &= ~(1 << index); \
53 called_ ## kind &= ~(1 << index); \
54 }while(0)
56 #define CHECK_NOT_CALLED(kind, index) \
57 do { \
58 ok(!(called_ ## kind & (1 << index)), "not expected " #kind ", %d\n", index); \
59 expect_ ## kind &= ~(1 << index); \
60 called_ ## kind &= ~(1 << index); \
61 }while(0)
63 DEFINE_EXPECT(PLAYSTATE);
64 DEFINE_EXPECT(OPENSTATE);
66 static HANDLE playing_event;
67 static HANDLE completed_event;
68 static DWORD main_thread_id;
70 static const WCHAR mp3file[] = L"test.mp3";
71 static const WCHAR mp3file1s[] = L"test1s.mp3";
72 static inline WCHAR *load_resource(const WCHAR *name)
74 static WCHAR pathW[MAX_PATH];
75 DWORD written;
76 HANDLE file;
77 HRSRC res;
78 void *ptr;
80 GetTempPathW(ARRAY_SIZE(pathW), pathW);
81 lstrcatW(pathW, name);
83 file = CreateFileW(pathW, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
84 ok(file != INVALID_HANDLE_VALUE, "file creation failed, at %s, error %d\n", wine_dbgstr_w(pathW),
85 GetLastError());
87 res = FindResourceW(NULL, name, (LPCWSTR)RT_RCDATA);
88 ok( res != 0, "couldn't find resource\n" );
89 ptr = LockResource( LoadResource( GetModuleHandleA(NULL), res ));
90 WriteFile( file, ptr, SizeofResource( GetModuleHandleA(NULL), res ), &written, NULL );
91 ok( written == SizeofResource( GetModuleHandleA(NULL), res ), "couldn't write resource\n" );
92 CloseHandle( file );
94 return pathW;
97 static ULONG WINAPI Dispatch_AddRef(IDispatch *iface)
99 return 2;
102 static ULONG WINAPI Dispatch_Release(IDispatch *iface)
104 return 1;
107 static HRESULT WINAPI Dispatch_GetTypeInfoCount(IDispatch *iface, UINT *pctinfo)
109 ok(0, "unexpected call\n");
110 return E_NOTIMPL;
113 static HRESULT WINAPI Dispatch_GetTypeInfo(IDispatch *iface, UINT iTInfo, LCID lcid,
114 ITypeInfo **ppTInfo)
116 ok(0, "unexpected call\n");
117 return E_NOTIMPL;
120 static HRESULT WINAPI Dispatch_GetIDsOfNames(IDispatch *iface, REFIID riid, LPOLESTR *rgszNames,
121 UINT cNames, LCID lcid, DISPID *rgDispId)
123 ok(0, "unexpected call\n");
124 return E_NOTIMPL;
127 static HRESULT WINAPI WMPOCXEvents_QueryInterface(IDispatch *iface, REFIID riid, void **ppv)
129 *ppv = NULL;
131 if(IsEqualGUID(&IID__WMPOCXEvents, riid) || IsEqualGUID(&IID_IDispatch, riid)) {
132 *ppv = iface;
133 return S_OK;
136 ok(0, "unexpected riid %s\n", wine_dbgstr_guid(riid));
137 return E_NOINTERFACE;
140 static HRESULT WINAPI WMPOCXEvents_Invoke(IDispatch *iface, DISPID dispIdMember, REFIID riid,
141 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult,
142 EXCEPINFO *pExcepInfo, UINT *puArgErr)
144 ok(main_thread_id == GetCurrentThreadId(), "Got notification outside of main thread!\n");
145 switch(dispIdMember) {
146 case DISPID_WMPCOREEVENT_OPENSTATECHANGE:
147 CHECK_EXPECT(OPENSTATE, V_UI4(pDispParams->rgvarg));
148 if (winetest_debug > 1)
149 trace("DISPID_WMPCOREEVENT_OPENSTATECHANGE, %d\n", V_UI4(pDispParams->rgvarg));
150 break;
151 case DISPID_WMPCOREEVENT_PLAYSTATECHANGE:
152 CHECK_EXPECT(PLAYSTATE, V_UI4(pDispParams->rgvarg));
153 if (V_UI4(pDispParams->rgvarg) == wmppsPlaying) {
154 SetEvent(playing_event);
155 } else if (V_UI4(pDispParams->rgvarg) == wmppsMediaEnded) {
156 SetEvent(completed_event);
158 if (winetest_debug > 1)
159 trace("DISPID_WMPCOREEVENT_PLAYSTATECHANGE, %d\n", V_UI4(pDispParams->rgvarg));
160 break;
161 case DISPID_WMPCOREEVENT_MEDIACHANGE:
162 if (winetest_debug > 1)
163 trace("DISPID_WMPCOREEVENT_MEDIACHANGE\n");
164 break;
165 case DISPID_WMPCOREEVENT_CURRENTITEMCHANGE:
166 if (winetest_debug > 1)
167 trace("DISPID_WMPCOREEVENT_CURRENTITEMCHANGE\n");
168 break;
169 case DISPID_WMPCOREEVENT_STATUSCHANGE:
170 if (winetest_debug > 1)
171 trace("DISPID_WMPCOREEVENT_STATUSCHANGE\n");
172 break;
173 default:
174 if (winetest_debug > 1)
175 trace("event: %d\n", dispIdMember);
176 break;
179 return E_NOTIMPL;
182 static IDispatchVtbl WMPOcxEventsVtbl = {
183 WMPOCXEvents_QueryInterface,
184 Dispatch_AddRef,
185 Dispatch_Release,
186 Dispatch_GetTypeInfoCount,
187 Dispatch_GetTypeInfo,
188 Dispatch_GetIDsOfNames,
189 WMPOCXEvents_Invoke,
192 static IDispatch WMPOCXEvents = { &WMPOcxEventsVtbl };
194 static HRESULT pump_messages(DWORD timeout, DWORD count, const HANDLE *handles) {
195 MSG msg;
196 HRESULT res;
197 DWORD start_time = GetTickCount();
198 do {
199 DWORD now = GetTickCount();
200 res = MsgWaitForMultipleObjectsEx(count, handles, start_time + timeout - now,
201 QS_ALLINPUT ,MWMO_ALERTABLE | MWMO_INPUTAVAILABLE);
202 if (res == WAIT_OBJECT_0 + 1) {
203 GetMessageW(&msg, 0, 0, 0);
204 if (winetest_debug > 1)
205 trace("Dispatching %d\n", msg.message);
206 TranslateMessage(&msg);
207 DispatchMessageW(&msg);
210 while (res == WAIT_OBJECT_0 + 1);
211 return res;
214 static void test_completion_event(void)
216 DWORD res = 0;
217 IWMPPlayer4 *player4;
218 HRESULT hres;
219 BSTR filename;
220 IConnectionPointContainer *container;
221 IConnectionPoint *point;
222 IOleObject *oleobj;
223 static DWORD dw = 100;
225 hres = CoCreateInstance(&CLSID_WindowsMediaPlayer, NULL, CLSCTX_INPROC_SERVER, &IID_IOleObject, (void**)&oleobj);
226 if(hres == REGDB_E_CLASSNOTREG) {
227 win_skip("CLSID_WindowsMediaPlayer not registered\n");
228 return;
230 ok(hres == S_OK, "Could not create CLSID_WindowsMediaPlayer instance: %08x\n", hres);
232 hres = IOleObject_QueryInterface(oleobj, &IID_IConnectionPointContainer, (void**)&container);
233 ok(hres == S_OK, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres);
234 if(FAILED(hres))
235 return;
237 hres = IConnectionPointContainer_FindConnectionPoint(container, &IID__WMPOCXEvents, &point);
238 IConnectionPointContainer_Release(container);
239 ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
241 hres = IConnectionPoint_Advise(point, (IUnknown*)&WMPOCXEvents, &dw);
242 ok(hres == S_OK, "Advise failed: %08x\n", hres);
244 hres = IOleObject_QueryInterface(oleobj, &IID_IWMPPlayer4, (void**)&player4);
245 ok(hres == S_OK, "Could not get IWMPPlayer4 iface: %08x\n", hres);
247 filename = SysAllocString(load_resource(mp3file1s));
249 SET_EXPECT(OPENSTATE, wmposPlaylistChanging);
250 SET_EXPECT(OPENSTATE, wmposPlaylistOpenNoMedia);
251 SET_EXPECT(OPENSTATE, wmposPlaylistChanged);
252 SET_EXPECT(OPENSTATE, wmposOpeningUnknownURL);
253 SET_EXPECT(OPENSTATE, wmposMediaOpen);
254 SET_EXPECT(OPENSTATE, wmposMediaOpening);
255 SET_EXPECT(PLAYSTATE, wmppsPlaying);
256 SET_EXPECT(PLAYSTATE, wmppsMediaEnded);
257 SET_EXPECT(PLAYSTATE, wmppsStopped);
258 SET_EXPECT(PLAYSTATE, wmppsTransitioning);
259 /* following two are sent on vistau64 vms only */
260 SET_EXPECT(OPENSTATE, wmposMediaChanging);
261 SET_EXPECT(PLAYSTATE, wmppsReady);
262 hres = IWMPPlayer4_put_URL(player4, filename);
263 ok(hres == S_OK, "IWMPPlayer4_put_URL failed: %08x\n", hres);
264 res = pump_messages(3000, 1, &completed_event);
265 ok(res == WAIT_OBJECT_0, "Timed out while waiting for media to complete\n");
267 /* following two are sent on vistau64 vms only */
268 CLEAR_CALLED(OPENSTATE, wmposMediaChanging);
269 CLEAR_CALLED(PLAYSTATE, wmppsReady);
271 CHECK_CALLED(OPENSTATE, wmposPlaylistChanging);
272 CHECK_CALLED(OPENSTATE, wmposPlaylistChanged);
273 CHECK_CALLED(OPENSTATE, wmposPlaylistOpenNoMedia);
274 CHECK_CALLED(PLAYSTATE, wmppsTransitioning);
275 CHECK_CALLED(OPENSTATE, wmposOpeningUnknownURL);
276 CHECK_CALLED(OPENSTATE, wmposMediaOpen);
277 CHECK_CALLED(PLAYSTATE, wmppsPlaying);
278 CHECK_CALLED(PLAYSTATE, wmppsMediaEnded);
279 CHECK_CALLED(PLAYSTATE, wmppsStopped);
280 /* MediaOpening happens only on xp, 2003 */
281 CLEAR_CALLED(OPENSTATE, wmposMediaOpening);
283 hres = IConnectionPoint_Unadvise(point, dw);
284 ok(hres == S_OK, "Unadvise failed: %08x\n", hres);
286 IConnectionPoint_Release(point);
287 IWMPPlayer4_Release(player4);
288 IOleObject_Release(oleobj);
289 DeleteFileW(filename);
290 SysFreeString(filename);
293 static BOOL test_wmp(void)
295 DWORD res = 0;
296 IWMPPlayer4 *player4;
297 IWMPControls *controls;
298 HRESULT hres;
299 BSTR filename;
300 IConnectionPointContainer *container;
301 IConnectionPoint *point;
302 IOleObject *oleobj;
303 static DWORD dw = 100;
304 IWMPSettings *settings;
305 BOOL test_ran = TRUE;
306 IWMPNetwork *network;
307 DOUBLE duration;
308 VARIANT_BOOL vbool;
309 LONG progress;
310 IWMPMedia *media;
311 BSTR bstrcurrentPosition;
313 hres = CoCreateInstance(&CLSID_WindowsMediaPlayer, NULL, CLSCTX_INPROC_SERVER, &IID_IOleObject, (void**)&oleobj);
314 if(hres == REGDB_E_CLASSNOTREG) {
315 win_skip("CLSID_WindowsMediaPlayer not registered\n");
316 return FALSE;
318 ok(hres == S_OK, "Could not create CLSID_WindowsMediaPlayer instance: %08x\n", hres);
320 hres = IOleObject_QueryInterface(oleobj, &IID_IConnectionPointContainer, (void**)&container);
321 ok(hres == S_OK, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres);
323 hres = IConnectionPointContainer_FindConnectionPoint(container, &IID__WMPOCXEvents, &point);
324 IConnectionPointContainer_Release(container);
325 ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
327 hres = IConnectionPoint_Advise(point, (IUnknown*)&WMPOCXEvents, &dw);
328 ok(hres == S_OK, "Advise failed: %08x\n", hres);
330 hres = IOleObject_QueryInterface(oleobj, &IID_IWMPPlayer4, (void**)&player4);
331 ok(hres == S_OK, "Could not get IWMPPlayer4 iface: %08x\n", hres);
333 settings = NULL;
334 hres = IWMPPlayer4_get_settings(player4, &settings);
335 ok(hres == S_OK, "get_settings failed: %08x\n", hres);
336 ok(settings != NULL, "settings = NULL\n");
338 hres = IWMPSettings_put_autoStart(settings, VARIANT_FALSE);
339 ok(hres == S_OK, "Could not put autoStart in IWMPSettings: %08x\n", hres);
341 controls = NULL;
342 hres = IWMPPlayer4_get_controls(player4, &controls);
343 ok(hres == S_OK, "get_controls failed: %08x\n", hres);
344 ok(controls != NULL, "controls = NULL\n");
346 bstrcurrentPosition = SysAllocString(L"currentPosition");
347 hres = IWMPControls_get_isAvailable(controls, bstrcurrentPosition, &vbool);
348 ok(hres == S_OK, "IWMPControls_get_isAvailable failed: %08x\n", hres);
349 ok(vbool == VARIANT_FALSE, "unexpected value\n");
351 hres = IWMPControls_play(controls);
352 ok(hres == NS_S_WMPCORE_COMMAND_NOT_AVAILABLE, "IWMPControls_play is available: %08x\n", hres);
354 hres = IWMPSettings_put_volume(settings, 36);
355 ok(hres == S_OK, "IWMPSettings_put_volume failed: %08x\n", hres);
356 hres = IWMPSettings_get_volume(settings, &progress);
357 ok(hres == S_OK, "IWMPSettings_get_volume failed: %08x\n", hres);
358 ok(progress == 36, "unexpected value: %d\n", progress);
360 filename = SysAllocString(load_resource(mp3file));
362 SET_EXPECT(OPENSTATE, wmposPlaylistChanging);
363 SET_EXPECT(OPENSTATE, wmposPlaylistOpenNoMedia);
364 SET_EXPECT(OPENSTATE, wmposPlaylistChanged);
365 SET_EXPECT(PLAYSTATE, wmppsTransitioning);
366 SET_EXPECT(PLAYSTATE, wmppsReady);
367 hres = IWMPPlayer4_put_URL(player4, filename);
368 ok(hres == S_OK, "IWMPPlayer4_put_URL failed: %08x\n", hres);
369 CHECK_CALLED(OPENSTATE, wmposPlaylistChanging);
370 CHECK_CALLED(OPENSTATE, wmposPlaylistChanged);
371 CHECK_CALLED(OPENSTATE, wmposPlaylistOpenNoMedia);
372 CHECK_CALLED(PLAYSTATE, wmppsTransitioning);
373 CHECK_CALLED(PLAYSTATE, wmppsReady);
375 SET_EXPECT(OPENSTATE, wmposOpeningUnknownURL);
376 SET_EXPECT(OPENSTATE, wmposMediaOpen);
377 SET_EXPECT(PLAYSTATE, wmppsPlaying);
378 SET_EXPECT(PLAYSTATE, wmppsTransitioning);
379 /* MediaOpening happens only on xp, 2003 */
380 SET_EXPECT(OPENSTATE, wmposMediaOpening);
381 hres = IWMPControls_play(controls);
382 ok(hres == S_OK, "IWMPControls_play failed: %08x\n", hres);
383 res = pump_messages(1000, 1, &playing_event);
384 ok(res == WAIT_OBJECT_0 || broken(res == WAIT_TIMEOUT), "Timed out while waiting for media to become ready\n");
385 if (res == WAIT_TIMEOUT) {
386 /* This happens on Vista Ultimate 64 vms
387 * I have been unable to find out source of this behaviour */
388 win_skip("Failed to transition media to playing state.\n");
389 test_ran = FALSE;
390 goto playback_skip;
392 CHECK_CALLED(OPENSTATE, wmposOpeningUnknownURL);
393 CHECK_CALLED(OPENSTATE, wmposMediaOpen);
394 CHECK_CALLED(PLAYSTATE, wmppsPlaying);
395 CHECK_CALLED(PLAYSTATE, wmppsTransitioning);
396 /* MediaOpening happens only on xp, 2003 */
397 CLEAR_CALLED(OPENSTATE, wmposMediaOpening);
399 hres = IWMPControls_get_isAvailable(controls, bstrcurrentPosition, &vbool);
400 ok(hres == S_OK, "IWMPControls_get_isAvailable failed: %08x\n", hres);
401 ok(vbool == VARIANT_TRUE, "unexpected value\n");
403 duration = 0.0;
404 hres = IWMPControls_get_currentPosition(controls, &duration);
405 ok(hres == S_OK, "IWMPControls_get_currentPosition failed: %08x\n", hres);
406 ok((int)duration == 0, "unexpected value %f\n", duration);
408 duration = 1.1;
409 hres = IWMPControls_put_currentPosition(controls, duration);
410 ok(hres == S_OK, "IWMPControls_put_currentPosition failed: %08x\n", hres);
412 duration = 0.0;
413 hres = IWMPControls_get_currentPosition(controls, &duration);
414 ok(hres == S_OK, "IWMPControls_get_currentPosition failed: %08x\n", hres);
415 ok(duration >= 1.05 /* save some fp errors */, "unexpected value %f\n", duration);
417 hres = IWMPPlayer4_get_currentMedia(player4, &media);
418 ok(hres == S_OK, "IWMPPlayer4_get_currentMedia failed: %08x\n", hres);
419 hres = IWMPMedia_get_duration(media, &duration);
420 ok(hres == S_OK, "IWMPMedia_get_duration failed: %08x\n", hres);
421 ok(floor(duration + 0.5) == 3, "unexpected value: %f\n", duration);
422 IWMPMedia_Release(media);
424 network = NULL;
425 hres = IWMPPlayer4_get_network(player4, &network);
426 ok(hres == S_OK, "get_network failed: %08x\n", hres);
427 ok(network != NULL, "network = NULL\n");
428 progress = 0;
429 hres = IWMPNetwork_get_bufferingProgress(network, &progress);
430 ok(hres == S_OK || broken(hres == S_FALSE), "IWMPNetwork_get_bufferingProgress failed: %08x\n", hres);
431 ok(progress == 100, "unexpected value: %d\n", progress);
432 progress = 0;
433 hres = IWMPNetwork_get_downloadProgress(network, &progress);
434 ok(hres == S_OK, "IWMPNetwork_get_downloadProgress failed: %08x\n", hres);
435 ok(progress == 100, "unexpected value: %d\n", progress);
436 IWMPNetwork_Release(network);
438 SET_EXPECT(PLAYSTATE, wmppsStopped);
439 /* The following happens on wine only since we close media on stop */
440 SET_EXPECT(OPENSTATE, wmposPlaylistOpenNoMedia);
441 hres = IWMPControls_stop(controls);
442 ok(hres == S_OK, "IWMPControls_stop failed: %08x\n", hres);
443 CHECK_CALLED(PLAYSTATE, wmppsStopped);
444 todo_wine CHECK_NOT_CALLED(OPENSTATE, wmposPlaylistOpenNoMedia);
446 /* Already Stopped */
447 hres = IWMPControls_stop(controls);
448 ok(hres == NS_S_WMPCORE_COMMAND_NOT_AVAILABLE, "IWMPControls_stop is available: %08x\n", hres);
450 SET_EXPECT(PLAYSTATE, wmppsPlaying);
451 /* The following happens on wine only since we close media on stop */
452 SET_EXPECT(OPENSTATE, wmposOpeningUnknownURL);
453 SET_EXPECT(OPENSTATE, wmposMediaOpen);
454 SET_EXPECT(PLAYSTATE, wmppsTransitioning);
455 hres = IWMPControls_play(controls);
456 ok(hres == S_OK, "IWMPControls_play failed: %08x\n", hres);
457 CHECK_CALLED(PLAYSTATE, wmppsPlaying);
458 todo_wine CHECK_NOT_CALLED(OPENSTATE, wmposOpeningUnknownURL);
459 todo_wine CHECK_NOT_CALLED(OPENSTATE, wmposMediaOpen);
460 todo_wine CHECK_NOT_CALLED(PLAYSTATE, wmppsTransitioning);
462 playback_skip:
463 hres = IConnectionPoint_Unadvise(point, dw);
464 ok(hres == S_OK, "Unadvise failed: %08x\n", hres);
466 hres = IWMPSettings_get_volume(settings, &progress);
467 ok(hres == S_OK, "IWMPSettings_get_volume failed: %08x\n", hres);
468 ok(progress == 36, "unexpected value: %d\n", progress);
469 hres = IWMPSettings_put_volume(settings, 99);
470 ok(hres == S_OK, "IWMPSettings_put_volume failed: %08x\n", hres);
471 hres = IWMPSettings_get_volume(settings, &progress);
472 ok(hres == S_OK, "IWMPSettings_get_volume failed: %08x\n", hres);
473 ok(progress == 99, "unexpected value: %d\n", progress);
475 IConnectionPoint_Release(point);
476 IWMPSettings_Release(settings);
477 IWMPControls_Release(controls);
478 IWMPPlayer4_Release(player4);
479 IOleObject_Release(oleobj);
480 DeleteFileW(filename);
481 SysFreeString(filename);
482 SysFreeString(bstrcurrentPosition);
484 return test_ran;
487 static void test_media_item(void)
489 static WCHAR pathW[MAX_PATH];
490 static WCHAR currentdirW[MAX_PATH];
491 struct {
492 const WCHAR *prefix;
493 const WCHAR *filename;
494 const WCHAR *expected;
495 } tests[] = {
496 { NULL, L"invalid_url.mp3", L"invalid_url" },
497 { currentdirW, mp3file, L"test" },
498 { currentdirW, L"invalid_url.mp3", L"invalid_url" },
499 { L"http://", L"test.winehq.org/tests/test.mp3", L"test" },
500 { L"http://", L"invalid_url.mp3", L"invalid_url.mp3" },
501 { L"https://", L"test.winehq.org/tests/test.mp3", L"test" },
502 { L"https://", L"invalid_url.mp3", L"invalid_url.mp3" },
503 { L"file:///", mp3file, L"test" },
504 { L"file:///", L"invalid_url.mp3", L"invalid_url" },
505 { L"foo://", mp3file, mp3file },
506 { L"foo://", L"invalid_url.mp3", L"invalid_url.mp3" }
508 IWMPMedia *media, *media2;
509 IWMPPlayer4 *player;
510 HRESULT hr;
511 BSTR str;
512 int i;
514 hr = CoCreateInstance(&CLSID_WindowsMediaPlayer, NULL, CLSCTX_INPROC_SERVER, &IID_IWMPPlayer4, (void **)&player);
515 if (hr == REGDB_E_CLASSNOTREG)
517 win_skip("CLSID_WindowsMediaPlayer is not registered.\n");
518 return;
520 ok(hr == S_OK, "Failed to create media player instance, hr %#x.\n", hr);
522 hr = IWMPPlayer4_newMedia(player, NULL, &media);
523 ok(hr == S_OK, "Failed to create a media item, hr %#x.\n", hr);
524 hr = IWMPMedia_get_name(media, NULL);
525 ok(hr == E_POINTER, "Unexpected hr %#x.\n", hr);
526 hr = IWMPMedia_get_name(media, &str);
527 ok(hr == S_OK, "Failed to get item name, hr %#x.\n", hr);
528 ok(*str == 0, "Unexpected name %s.\n", wine_dbgstr_w(str));
529 SysFreeString(str);
531 media2 = (void *)0xdeadbeef;
532 hr = IWMPPlayer4_get_currentMedia(player, &media2);
533 ok(hr == S_FALSE, "Failed to get current media, hr %#x.\n", hr);
534 ok(media2 == NULL, "Unexpected media instance.\n");
536 hr = IWMPPlayer4_put_currentMedia(player, media);
537 ok(hr == S_OK, "Failed to set current media, hr %#x.\n", hr);
539 hr = IWMPPlayer4_get_currentMedia(player, &media2);
540 ok(hr == S_OK, "Failed to get current media, hr %#x.\n", hr);
541 ok(media2 != NULL && media != media2, "Unexpected media instance.\n");
542 IWMPMedia_Release(media2);
544 IWMPMedia_Release(media);
546 str = SysAllocStringLen(NULL, 0);
547 hr = IWMPPlayer4_newMedia(player, str, &media);
548 ok(hr == S_OK, "Failed to create a media item, hr %#x.\n", hr);
549 SysFreeString(str);
550 hr = IWMPMedia_get_name(media, &str);
551 ok(hr == S_OK, "Failed to get item name, hr %#x.\n", hr);
552 ok(*str == 0, "Unexpected name %s.\n", wine_dbgstr_w(str));
553 SysFreeString(str);
554 IWMPMedia_Release(media);
556 str = SysAllocString(mp3file);
557 hr = IWMPPlayer4_newMedia(player, str, &media);
558 ok(hr == S_OK, "Failed to create a media item, hr %#x.\n", hr);
559 SysFreeString(str);
560 hr = IWMPMedia_get_name(media, &str);
561 ok(hr == S_OK, "Failed to get item name, hr %#x.\n", hr);
562 ok(!lstrcmpW(str, L"test"), "Expected %s, got %s\n", wine_dbgstr_w(L"test"), wine_dbgstr_w(str));
563 SysFreeString(str);
564 hr = IWMPMedia_put_name(media, NULL);
565 ok(hr == E_POINTER, "Unexpected hr %#x.\n", hr);
566 hr = IWMPMedia_get_name(media, &str);
567 ok(hr == S_OK, "Failed to get item name, hr %#x.\n", hr);
568 ok(!lstrcmpW(str, L"test"), "Expected %s, got %s\n", wine_dbgstr_w(L"test"), wine_dbgstr_w(str));
569 SysFreeString(str);
571 hr = IWMPPlayer4_put_currentMedia(player, media);
572 ok(hr == S_OK, "Failed to set current media, hr %#x.\n", hr);
573 IWMPMedia_Release(media);
575 hr = IWMPPlayer4_get_currentMedia(player, &media2);
576 ok(hr == S_OK, "Failed to get current media, hr %#x.\n", hr);
577 ok(media2 != NULL, "Unexpected media instance.\n");
578 hr = IWMPMedia_get_name(media2, &str);
579 ok(hr == S_OK, "Failed to get item name, hr %#x.\n", hr);
580 ok(!lstrcmpW(str, L"test"), "Expected %s, got %s\n", wine_dbgstr_w(L"test"), wine_dbgstr_w(str));
581 SysFreeString(str);
582 IWMPMedia_Release(media2);
584 GetCurrentDirectoryW(ARRAY_SIZE(currentdirW), currentdirW);
585 lstrcatW(currentdirW, L"\\");
587 for (i=0; i<ARRAY_SIZE(tests); i++)
590 pathW[0] = '\0';
591 if(tests[i].prefix) lstrcatW(pathW, tests[i].prefix);
592 lstrcatW(pathW, tests[i].filename);
594 str = SysAllocString(pathW);
595 hr = IWMPPlayer4_newMedia(player, str, &media);
596 ok(hr == S_OK, "Failed to create a media item, hr %#x.\n", hr);
597 SysFreeString(str);
598 hr = IWMPMedia_get_name(media, &str);
599 ok(hr == S_OK, "Failed to get item name, hr %#x.\n", hr);
600 ok(!lstrcmpW(str, tests[i].expected), "Expected %s, got %s\n", wine_dbgstr_w(tests[i].expected), wine_dbgstr_w(str));
601 SysFreeString(str);
602 IWMPMedia_Release(media);
605 IWMPPlayer4_Release(player);
608 static void test_player_url(void)
610 IWMPPlayer4 *player;
611 BSTR str, str2;
612 HRESULT hr;
614 hr = CoCreateInstance(&CLSID_WindowsMediaPlayer, NULL, CLSCTX_INPROC_SERVER, &IID_IWMPPlayer4, (void **)&player);
615 if (hr == REGDB_E_CLASSNOTREG)
617 win_skip("CLSID_WindowsMediaPlayer is not registered.\n");
618 return;
620 ok(hr == S_OK, "Failed to create media player instance, hr %#x.\n", hr);
622 hr = IWMPPlayer4_get_URL(player, &str);
623 ok(hr == S_OK, "Failed to get url, hr %#x.\n", hr);
624 ok(*str == 0, "Unexpected url %s.\n", wine_dbgstr_w(str));
625 SysFreeString(str);
627 str2 = SysAllocString(mp3file);
628 hr = IWMPPlayer4_put_URL(player, str2);
629 ok(hr == S_OK, "Failed to set url, hr %#x.\n", hr);
631 hr = IWMPPlayer4_put_URL(player, NULL);
632 ok(hr == S_OK, "Failed to set url, hr %#x.\n", hr);
633 hr = IWMPPlayer4_get_URL(player, &str);
634 ok(hr == S_OK, "Failed to set url, hr %#x.\n", hr);
635 ok(*str == 0, "Unexpected url, %s.\n", wine_dbgstr_w(str));
636 SysFreeString(str);
638 /* Empty url */
639 hr = IWMPPlayer4_put_URL(player, str2);
640 ok(hr == S_OK, "Failed to set url, hr %#x.\n", hr);
642 str = SysAllocStringLen(NULL, 0);
643 hr = IWMPPlayer4_put_URL(player, str);
644 ok(hr == S_OK, "Failed to set url, hr %#x.\n", hr);
645 SysFreeString(str);
647 hr = IWMPPlayer4_get_URL(player, &str);
648 ok(hr == S_OK, "Failed to set url, hr %#x.\n", hr);
649 ok(*str == 0, "Unexpected url, %s.\n", wine_dbgstr_w(str));
650 SysFreeString(str);
652 SysFreeString(str2);
653 IWMPPlayer4_Release(player);
656 static void test_playlist(void)
658 IWMPPlayer4 *player;
659 IWMPPlaylist *playlist, *playlist2;
660 HRESULT hr;
661 BSTR str, str2;
662 LONG count;
663 static const WCHAR nameW[] = L"Playlist1";
665 hr = CoCreateInstance(&CLSID_WindowsMediaPlayer, NULL, CLSCTX_INPROC_SERVER, &IID_IWMPPlayer4, (void **)&player);
666 if (hr == REGDB_E_CLASSNOTREG)
668 win_skip("CLSID_WindowsMediaPlayer is not registered.\n");
669 return;
671 ok(hr == S_OK, "Failed to create media player instance, hr %#x.\n", hr);
673 playlist = NULL;
674 hr = IWMPPlayer4_get_currentPlaylist(player, &playlist);
675 ok(hr == S_OK, "IWMPPlayer4_get_currentPlaylist failed: %08x\n", hr);
676 ok(playlist != NULL, "playlist == NULL\n");
678 if (0) /* fails on non-English locales */
680 hr = IWMPPlaylist_get_name(playlist, &str);
681 ok(hr == S_OK, "Failed to get playlist name, hr %#x.\n", hr);
682 ok(!lstrcmpW(str, nameW), "Expected %s, got %s\n", wine_dbgstr_w(nameW), wine_dbgstr_w(str));
683 SysFreeString(str);
686 hr = IWMPPlaylist_get_count(playlist, NULL);
687 ok(hr == E_POINTER, "Failed to get count, hr %#x.\n", hr);
689 count = -1;
690 hr = IWMPPlaylist_get_count(playlist, &count);
691 ok(hr == S_OK, "Failed to get count, hr %#x.\n", hr);
692 ok(count == 0, "Expected 0, got %d\n", count);
694 IWMPPlaylist_Release(playlist);
696 /* newPlaylist doesn't change current playlist */
697 hr = IWMPPlayer4_newPlaylist(player, NULL, NULL, &playlist);
698 ok(hr == S_OK, "Failed to create a playlist, hr %#x.\n", hr);
700 playlist2 = NULL;
701 hr = IWMPPlayer4_get_currentPlaylist(player, &playlist2);
702 ok(hr == S_OK, "IWMPPlayer4_get_currentPlaylist failed: %08x\n", hr);
703 ok(playlist2 != NULL && playlist2 != playlist, "Unexpected playlist instance\n");
705 IWMPPlaylist_Release(playlist2);
707 /* different playlists can have the same name */
708 str = SysAllocString(nameW);
709 hr = IWMPPlaylist_put_name(playlist, str);
710 ok(hr == S_OK, "Failed to get playlist name, hr %#x.\n", hr);
712 playlist2 = NULL;
713 hr = IWMPPlayer4_newPlaylist(player, str, NULL, &playlist2);
714 ok(hr == S_OK, "Failed to create a playlist, hr %#x.\n", hr);
715 hr = IWMPPlaylist_get_name(playlist2, &str2);
716 ok(hr == S_OK, "Failed to get playlist name, hr %#x.\n", hr);
717 ok(playlist != playlist2, "Expected playlists to be different");
718 ok(!lstrcmpW(str, str2), "Expected names to be the same\n");
719 SysFreeString(str);
720 SysFreeString(str2);
722 IWMPPlaylist_Release(playlist2);
724 IWMPPlaylist_Release(playlist);
725 IWMPPlayer4_Release(player);
728 START_TEST(media)
730 CoInitialize(NULL);
732 main_thread_id = GetCurrentThreadId();
733 playing_event = CreateEventW(NULL, FALSE, FALSE, NULL);
734 completed_event = CreateEventW(NULL, FALSE, FALSE, NULL);
736 test_playlist();
737 test_media_item();
738 test_player_url();
739 if (test_wmp()) {
740 test_completion_event();
741 } else {
742 win_skip("Failed to play media\n");
745 CloseHandle(playing_event);
746 CloseHandle(completed_event);
748 CoUninitialize();