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
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) \
33 assert(index < 8 * sizeof(expect_ ## kind)); \
34 expect_ ## kind |= (1 << index); \
37 #define CHECK_EXPECT(kind, index) \
39 ok(expect_ ##kind & (1 << index), "unexpected event for " #kind ", index:%d\n", index); \
40 called_ ## kind |= (1 << index); \
43 #define CLEAR_CALLED(kind, index) \
45 expect_ ## kind &= ~(1 << index); \
46 called_ ## kind &= ~(1 << index); \
49 #define CHECK_CALLED(kind, index) \
51 ok(called_ ## kind & (1 << index), "expected " #kind ", %d\n", index); \
52 expect_ ## kind &= ~(1 << index); \
53 called_ ## kind &= ~(1 << index); \
56 #define CHECK_NOT_CALLED(kind, index) \
58 ok(!(called_ ## kind & (1 << index)), "not expected " #kind ", %d\n", index); \
59 expect_ ## kind &= ~(1 << index); \
60 called_ ## kind &= ~(1 << index); \
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
];
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
),
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" );
97 static ULONG WINAPI
Dispatch_AddRef(IDispatch
*iface
)
102 static ULONG WINAPI
Dispatch_Release(IDispatch
*iface
)
107 static HRESULT WINAPI
Dispatch_GetTypeInfoCount(IDispatch
*iface
, UINT
*pctinfo
)
109 ok(0, "unexpected call\n");
113 static HRESULT WINAPI
Dispatch_GetTypeInfo(IDispatch
*iface
, UINT iTInfo
, LCID lcid
,
116 ok(0, "unexpected call\n");
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");
127 static HRESULT WINAPI
WMPOCXEvents_QueryInterface(IDispatch
*iface
, REFIID riid
, void **ppv
)
131 if(IsEqualGUID(&IID__WMPOCXEvents
, riid
) || IsEqualGUID(&IID_IDispatch
, riid
)) {
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
));
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
));
161 case DISPID_WMPCOREEVENT_MEDIACHANGE
:
162 if (winetest_debug
> 1)
163 trace("DISPID_WMPCOREEVENT_MEDIACHANGE\n");
165 case DISPID_WMPCOREEVENT_CURRENTITEMCHANGE
:
166 if (winetest_debug
> 1)
167 trace("DISPID_WMPCOREEVENT_CURRENTITEMCHANGE\n");
169 case DISPID_WMPCOREEVENT_STATUSCHANGE
:
170 if (winetest_debug
> 1)
171 trace("DISPID_WMPCOREEVENT_STATUSCHANGE\n");
174 if (winetest_debug
> 1)
175 trace("event: %d\n", dispIdMember
);
182 static IDispatchVtbl WMPOcxEventsVtbl
= {
183 WMPOCXEvents_QueryInterface
,
186 Dispatch_GetTypeInfoCount
,
187 Dispatch_GetTypeInfo
,
188 Dispatch_GetIDsOfNames
,
192 static IDispatch WMPOCXEvents
= { &WMPOcxEventsVtbl
};
194 static HRESULT
pump_messages(DWORD timeout
, DWORD count
, const HANDLE
*handles
) {
197 DWORD start_time
= GetTickCount();
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);
214 static void test_completion_event(void)
217 IWMPPlayer4
*player4
;
220 IConnectionPointContainer
*container
;
221 IConnectionPoint
*point
;
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");
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
);
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)
296 IWMPPlayer4
*player4
;
297 IWMPControls
*controls
;
300 IConnectionPointContainer
*container
;
301 IConnectionPoint
*point
;
303 static DWORD dw
= 100;
304 IWMPSettings
*settings
;
305 BOOL test_ran
= TRUE
;
306 IWMPNetwork
*network
;
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");
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
);
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
);
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");
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");
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
);
409 hres
= IWMPControls_put_currentPosition(controls
, duration
);
410 ok(hres
== S_OK
, "IWMPControls_put_currentPosition failed: %08x\n", hres
);
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
);
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");
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
);
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
);
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
);
487 static void test_media_item(void)
489 static WCHAR pathW
[MAX_PATH
];
490 static WCHAR currentdirW
[MAX_PATH
];
493 const WCHAR
*filename
;
494 const WCHAR
*expected
;
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
;
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");
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
));
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
);
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
));
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
);
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
));
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
));
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
));
582 IWMPMedia_Release(media2
);
584 GetCurrentDirectoryW(ARRAY_SIZE(currentdirW
), currentdirW
);
585 lstrcatW(currentdirW
, L
"\\");
587 for (i
=0; i
<ARRAY_SIZE(tests
); i
++)
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
);
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
));
602 IWMPMedia_Release(media
);
605 IWMPPlayer4_Release(player
);
608 static void test_player_url(void)
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");
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
));
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
));
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
);
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
));
653 IWMPPlayer4_Release(player
);
656 static void test_playlist(void)
659 IWMPPlaylist
*playlist
, *playlist2
;
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");
671 ok(hr
== S_OK
, "Failed to create media player instance, hr %#x.\n", hr
);
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
));
686 hr
= IWMPPlaylist_get_count(playlist
, NULL
);
687 ok(hr
== E_POINTER
, "Failed to get count, hr %#x.\n", hr
);
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
);
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
);
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");
722 IWMPPlaylist_Release(playlist2
);
724 IWMPPlaylist_Release(playlist
);
725 IWMPPlayer4_Release(player
);
732 main_thread_id
= GetCurrentThreadId();
733 playing_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
734 completed_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
740 test_completion_event();
742 win_skip("Failed to play media\n");
745 CloseHandle(playing_event
);
746 CloseHandle(completed_event
);