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
[] = {'t','e','s','t','.','m','p','3',0};
71 static const WCHAR mp3file1s
[] = {'t','e','s','t','1','s','.','m','p','3',0};
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 static const WCHAR currentPosition
[] = {'c','u','r','r','e','n','t','P','o','s','i','t','i','o','n',0};
312 BSTR bstrcurrentPosition
;
314 hres
= CoCreateInstance(&CLSID_WindowsMediaPlayer
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IOleObject
, (void**)&oleobj
);
315 if(hres
== REGDB_E_CLASSNOTREG
) {
316 win_skip("CLSID_WindowsMediaPlayer not registered\n");
319 ok(hres
== S_OK
, "Could not create CLSID_WindowsMediaPlayer instance: %08x\n", hres
);
321 hres
= IOleObject_QueryInterface(oleobj
, &IID_IConnectionPointContainer
, (void**)&container
);
322 ok(hres
== S_OK
, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres
);
324 hres
= IConnectionPointContainer_FindConnectionPoint(container
, &IID__WMPOCXEvents
, &point
);
325 IConnectionPointContainer_Release(container
);
326 ok(hres
== S_OK
, "FindConnectionPoint failed: %08x\n", hres
);
328 hres
= IConnectionPoint_Advise(point
, (IUnknown
*)&WMPOCXEvents
, &dw
);
329 ok(hres
== S_OK
, "Advise failed: %08x\n", hres
);
331 hres
= IOleObject_QueryInterface(oleobj
, &IID_IWMPPlayer4
, (void**)&player4
);
332 ok(hres
== S_OK
, "Could not get IWMPPlayer4 iface: %08x\n", hres
);
335 hres
= IWMPPlayer4_get_settings(player4
, &settings
);
336 ok(hres
== S_OK
, "get_settings failed: %08x\n", hres
);
337 ok(settings
!= NULL
, "settings = NULL\n");
339 hres
= IWMPSettings_put_autoStart(settings
, VARIANT_FALSE
);
340 ok(hres
== S_OK
, "Could not put autoStart in IWMPSettings: %08x\n", hres
);
343 hres
= IWMPPlayer4_get_controls(player4
, &controls
);
344 ok(hres
== S_OK
, "get_controls failed: %08x\n", hres
);
345 ok(controls
!= NULL
, "controls = NULL\n");
347 bstrcurrentPosition
= SysAllocString(currentPosition
);
348 hres
= IWMPControls_get_isAvailable(controls
, bstrcurrentPosition
, &vbool
);
349 ok(hres
== S_OK
, "IWMPControls_get_isAvailable failed: %08x\n", hres
);
350 ok(vbool
== VARIANT_FALSE
, "unexpected value\n");
352 hres
= IWMPControls_play(controls
);
353 ok(hres
== NS_S_WMPCORE_COMMAND_NOT_AVAILABLE
, "IWMPControls_play is available: %08x\n", hres
);
355 hres
= IWMPSettings_put_volume(settings
, 36);
356 ok(hres
== S_OK
, "IWMPSettings_put_volume failed: %08x\n", hres
);
357 hres
= IWMPSettings_get_volume(settings
, &progress
);
358 ok(hres
== S_OK
, "IWMPSettings_get_volume failed: %08x\n", hres
);
359 ok(progress
== 36, "unexpected value: %d\n", progress
);
361 filename
= SysAllocString(load_resource(mp3file
));
363 SET_EXPECT(OPENSTATE
, wmposPlaylistChanging
);
364 SET_EXPECT(OPENSTATE
, wmposPlaylistOpenNoMedia
);
365 SET_EXPECT(OPENSTATE
, wmposPlaylistChanged
);
366 SET_EXPECT(PLAYSTATE
, wmppsTransitioning
);
367 SET_EXPECT(PLAYSTATE
, wmppsReady
);
368 hres
= IWMPPlayer4_put_URL(player4
, filename
);
369 ok(hres
== S_OK
, "IWMPPlayer4_put_URL failed: %08x\n", hres
);
370 CHECK_CALLED(OPENSTATE
, wmposPlaylistChanging
);
371 CHECK_CALLED(OPENSTATE
, wmposPlaylistChanged
);
372 CHECK_CALLED(OPENSTATE
, wmposPlaylistOpenNoMedia
);
373 CHECK_CALLED(PLAYSTATE
, wmppsTransitioning
);
374 CHECK_CALLED(PLAYSTATE
, wmppsReady
);
376 SET_EXPECT(OPENSTATE
, wmposOpeningUnknownURL
);
377 SET_EXPECT(OPENSTATE
, wmposMediaOpen
);
378 SET_EXPECT(PLAYSTATE
, wmppsPlaying
);
379 SET_EXPECT(PLAYSTATE
, wmppsTransitioning
);
380 /* MediaOpening happens only on xp, 2003 */
381 SET_EXPECT(OPENSTATE
, wmposMediaOpening
);
382 hres
= IWMPControls_play(controls
);
383 ok(hres
== S_OK
, "IWMPControls_play failed: %08x\n", hres
);
384 res
= pump_messages(1000, 1, &playing_event
);
385 ok(res
== WAIT_OBJECT_0
|| broken(res
== WAIT_TIMEOUT
), "Timed out while waiting for media to become ready\n");
386 if (res
== WAIT_TIMEOUT
) {
387 /* This happens on Vista Ultimate 64 vms
388 * I have been unable to find out source of this behaviour */
389 win_skip("Failed to transition media to playing state.\n");
393 CHECK_CALLED(OPENSTATE
, wmposOpeningUnknownURL
);
394 CHECK_CALLED(OPENSTATE
, wmposMediaOpen
);
395 CHECK_CALLED(PLAYSTATE
, wmppsPlaying
);
396 CHECK_CALLED(PLAYSTATE
, wmppsTransitioning
);
397 /* MediaOpening happens only on xp, 2003 */
398 CLEAR_CALLED(OPENSTATE
, wmposMediaOpening
);
400 hres
= IWMPControls_get_isAvailable(controls
, bstrcurrentPosition
, &vbool
);
401 ok(hres
== S_OK
, "IWMPControls_get_isAvailable failed: %08x\n", hres
);
402 ok(vbool
== VARIANT_TRUE
, "unexpected value\n");
405 hres
= IWMPControls_get_currentPosition(controls
, &duration
);
406 ok(hres
== S_OK
, "IWMPControls_get_currentPosition failed: %08x\n", hres
);
407 ok((int)duration
== 0, "unexpected value %f\n", duration
);
410 hres
= IWMPControls_put_currentPosition(controls
, duration
);
411 ok(hres
== S_OK
, "IWMPControls_put_currentPosition failed: %08x\n", hres
);
414 hres
= IWMPControls_get_currentPosition(controls
, &duration
);
415 ok(hres
== S_OK
, "IWMPControls_get_currentPosition failed: %08x\n", hres
);
416 ok(duration
>= 1.05 /* save some fp errors */, "unexpected value %f\n", duration
);
418 hres
= IWMPPlayer4_get_currentMedia(player4
, &media
);
419 ok(hres
== S_OK
, "IWMPPlayer4_get_currentMedia failed: %08x\n", hres
);
420 hres
= IWMPMedia_get_duration(media
, &duration
);
421 ok(hres
== S_OK
, "IWMPMedia_get_duration failed: %08x\n", hres
);
422 ok(floor(duration
+ 0.5) == 3, "unexpected value: %f\n", duration
);
423 IWMPMedia_Release(media
);
426 hres
= IWMPPlayer4_get_network(player4
, &network
);
427 ok(hres
== S_OK
, "get_network failed: %08x\n", hres
);
428 ok(network
!= NULL
, "network = NULL\n");
430 hres
= IWMPNetwork_get_bufferingProgress(network
, &progress
);
431 ok(hres
== S_OK
|| broken(hres
== S_FALSE
), "IWMPNetwork_get_bufferingProgress failed: %08x\n", hres
);
432 ok(progress
== 100, "unexpected value: %d\n", progress
);
434 hres
= IWMPNetwork_get_downloadProgress(network
, &progress
);
435 ok(hres
== S_OK
, "IWMPNetwork_get_downloadProgress failed: %08x\n", hres
);
436 ok(progress
== 100, "unexpected value: %d\n", progress
);
437 IWMPNetwork_Release(network
);
439 SET_EXPECT(PLAYSTATE
, wmppsStopped
);
440 /* The following happens on wine only since we close media on stop */
441 SET_EXPECT(OPENSTATE
, wmposPlaylistOpenNoMedia
);
442 hres
= IWMPControls_stop(controls
);
443 ok(hres
== S_OK
, "IWMPControls_stop failed: %08x\n", hres
);
444 CHECK_CALLED(PLAYSTATE
, wmppsStopped
);
445 todo_wine
CHECK_NOT_CALLED(OPENSTATE
, wmposPlaylistOpenNoMedia
);
447 /* Already Stopped */
448 hres
= IWMPControls_stop(controls
);
449 ok(hres
== NS_S_WMPCORE_COMMAND_NOT_AVAILABLE
, "IWMPControls_stop is available: %08x\n", hres
);
451 SET_EXPECT(PLAYSTATE
, wmppsPlaying
);
452 /* The following happens on wine only since we close media on stop */
453 SET_EXPECT(OPENSTATE
, wmposOpeningUnknownURL
);
454 SET_EXPECT(OPENSTATE
, wmposMediaOpen
);
455 SET_EXPECT(PLAYSTATE
, wmppsTransitioning
);
456 hres
= IWMPControls_play(controls
);
457 ok(hres
== S_OK
, "IWMPControls_play failed: %08x\n", hres
);
458 CHECK_CALLED(PLAYSTATE
, wmppsPlaying
);
459 todo_wine
CHECK_NOT_CALLED(OPENSTATE
, wmposOpeningUnknownURL
);
460 todo_wine
CHECK_NOT_CALLED(OPENSTATE
, wmposMediaOpen
);
461 todo_wine
CHECK_NOT_CALLED(PLAYSTATE
, wmppsTransitioning
);
464 hres
= IConnectionPoint_Unadvise(point
, dw
);
465 ok(hres
== S_OK
, "Unadvise failed: %08x\n", hres
);
467 hres
= IWMPSettings_get_volume(settings
, &progress
);
468 ok(hres
== S_OK
, "IWMPSettings_get_volume failed: %08x\n", hres
);
469 ok(progress
== 36, "unexpected value: %d\n", progress
);
470 hres
= IWMPSettings_put_volume(settings
, 99);
471 ok(hres
== S_OK
, "IWMPSettings_put_volume failed: %08x\n", hres
);
472 hres
= IWMPSettings_get_volume(settings
, &progress
);
473 ok(hres
== S_OK
, "IWMPSettings_get_volume failed: %08x\n", hres
);
474 ok(progress
== 99, "unexpected value: %d\n", progress
);
476 IConnectionPoint_Release(point
);
477 IWMPSettings_Release(settings
);
478 IWMPControls_Release(controls
);
479 IWMPPlayer4_Release(player4
);
480 IOleObject_Release(oleobj
);
481 DeleteFileW(filename
);
482 SysFreeString(filename
);
483 SysFreeString(bstrcurrentPosition
);
488 static void test_media_item(void)
490 static const WCHAR slashW
[] = {'\\',0};
491 static const WCHAR testW
[] = {'t','e','s','t',0};
492 static const WCHAR fooW
[] = {'f','o','o',':','/','/',0};
493 static const WCHAR fileW
[] = {'f','i','l','e',':','/','/','/',0};
494 static const WCHAR httpW
[] = {'h','t','t','p',':','/','/',0};
495 static const WCHAR httpsW
[] = {'h','t','t','p','s',':','/','/',0};
496 static const WCHAR invalidurlW
[] = {'i','n','v','a','l','i','d','_','u','r','l',0};
497 static const WCHAR invalidurlmp3W
[] = {'i','n','v','a','l','i','d','_','u','r','l','.','m','p','3',0};
498 static const WCHAR winehqurlW
[] = {'t','e','s','t','.','w','i','n','e','h','q','.','o','r','g',
499 '/','t','e','s','t','s','/','t','e','s','t','.','m','p','3',0};
500 static WCHAR pathW
[MAX_PATH
];
501 static WCHAR currentdirW
[MAX_PATH
];
504 const WCHAR
*filename
;
505 const WCHAR
*expected
;
507 { NULL
, invalidurlmp3W
, invalidurlW
},
508 { currentdirW
, mp3file
, testW
},
509 { currentdirW
, invalidurlmp3W
, invalidurlW
},
510 { httpW
, winehqurlW
, testW
},
511 { httpW
, invalidurlmp3W
, invalidurlmp3W
},
512 { httpsW
, winehqurlW
, testW
},
513 { httpsW
, invalidurlmp3W
, invalidurlmp3W
},
514 { fileW
, mp3file
, testW
},
515 { fileW
, invalidurlmp3W
, invalidurlW
},
516 { fooW
, mp3file
, mp3file
},
517 { fooW
, invalidurlmp3W
, invalidurlmp3W
}
519 IWMPMedia
*media
, *media2
;
525 hr
= CoCreateInstance(&CLSID_WindowsMediaPlayer
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IWMPPlayer4
, (void **)&player
);
526 if (hr
== REGDB_E_CLASSNOTREG
)
528 win_skip("CLSID_WindowsMediaPlayer is not registered.\n");
531 ok(hr
== S_OK
, "Failed to create media player instance, hr %#x.\n", hr
);
533 hr
= IWMPPlayer4_newMedia(player
, NULL
, &media
);
534 ok(hr
== S_OK
, "Failed to create a media item, hr %#x.\n", hr
);
535 hr
= IWMPMedia_get_name(media
, NULL
);
536 ok(hr
== E_POINTER
, "Unexpected hr %#x.\n", hr
);
537 hr
= IWMPMedia_get_name(media
, &str
);
538 ok(hr
== S_OK
, "Failed to get item name, hr %#x.\n", hr
);
539 ok(*str
== 0, "Unexpected name %s.\n", wine_dbgstr_w(str
));
542 media2
= (void *)0xdeadbeef;
543 hr
= IWMPPlayer4_get_currentMedia(player
, &media2
);
544 ok(hr
== S_FALSE
, "Failed to get current media, hr %#x.\n", hr
);
545 ok(media2
== NULL
, "Unexpected media instance.\n");
547 hr
= IWMPPlayer4_put_currentMedia(player
, media
);
548 ok(hr
== S_OK
, "Failed to set current media, hr %#x.\n", hr
);
550 hr
= IWMPPlayer4_get_currentMedia(player
, &media2
);
551 ok(hr
== S_OK
, "Failed to get current media, hr %#x.\n", hr
);
552 ok(media2
!= NULL
&& media
!= media2
, "Unexpected media instance.\n");
553 IWMPMedia_Release(media2
);
555 IWMPMedia_Release(media
);
557 str
= SysAllocStringLen(NULL
, 0);
558 hr
= IWMPPlayer4_newMedia(player
, str
, &media
);
559 ok(hr
== S_OK
, "Failed to create a media item, hr %#x.\n", hr
);
561 hr
= IWMPMedia_get_name(media
, &str
);
562 ok(hr
== S_OK
, "Failed to get item name, hr %#x.\n", hr
);
563 ok(*str
== 0, "Unexpected name %s.\n", wine_dbgstr_w(str
));
565 IWMPMedia_Release(media
);
567 str
= SysAllocString(mp3file
);
568 hr
= IWMPPlayer4_newMedia(player
, str
, &media
);
569 ok(hr
== S_OK
, "Failed to create a media item, hr %#x.\n", hr
);
571 hr
= IWMPMedia_get_name(media
, &str
);
572 ok(hr
== S_OK
, "Failed to get item name, hr %#x.\n", hr
);
573 ok(!lstrcmpW(str
, testW
), "Expected %s, got %s\n", wine_dbgstr_w(testW
), wine_dbgstr_w(str
));
575 hr
= IWMPMedia_put_name(media
, NULL
);
576 ok(hr
== E_POINTER
, "Unexpected hr %#x.\n", hr
);
577 hr
= IWMPMedia_get_name(media
, &str
);
578 ok(hr
== S_OK
, "Failed to get item name, hr %#x.\n", hr
);
579 ok(!lstrcmpW(str
, testW
), "Expected %s, got %s\n", wine_dbgstr_w(testW
), wine_dbgstr_w(str
));
582 hr
= IWMPPlayer4_put_currentMedia(player
, media
);
583 ok(hr
== S_OK
, "Failed to set current media, hr %#x.\n", hr
);
584 IWMPMedia_Release(media
);
586 hr
= IWMPPlayer4_get_currentMedia(player
, &media2
);
587 ok(hr
== S_OK
, "Failed to get current media, hr %#x.\n", hr
);
588 ok(media2
!= NULL
, "Unexpected media instance.\n");
589 hr
= IWMPMedia_get_name(media2
, &str
);
590 ok(hr
== S_OK
, "Failed to get item name, hr %#x.\n", hr
);
591 ok(!lstrcmpW(str
, testW
), "Expected %s, got %s\n", wine_dbgstr_w(testW
), wine_dbgstr_w(str
));
593 IWMPMedia_Release(media2
);
595 GetCurrentDirectoryW(ARRAY_SIZE(currentdirW
), currentdirW
);
596 lstrcatW(currentdirW
, slashW
);
598 for (i
=0; i
<ARRAY_SIZE(tests
); i
++)
602 if(tests
[i
].prefix
) lstrcatW(pathW
, tests
[i
].prefix
);
603 lstrcatW(pathW
, tests
[i
].filename
);
605 str
= SysAllocString(pathW
);
606 hr
= IWMPPlayer4_newMedia(player
, str
, &media
);
607 ok(hr
== S_OK
, "Failed to create a media item, hr %#x.\n", hr
);
609 hr
= IWMPMedia_get_name(media
, &str
);
610 ok(hr
== S_OK
, "Failed to get item name, hr %#x.\n", hr
);
611 ok(!lstrcmpW(str
, tests
[i
].expected
), "Expected %s, got %s\n", wine_dbgstr_w(tests
[i
].expected
), wine_dbgstr_w(str
));
613 IWMPMedia_Release(media
);
616 IWMPPlayer4_Release(player
);
619 static void test_player_url(void)
625 hr
= CoCreateInstance(&CLSID_WindowsMediaPlayer
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IWMPPlayer4
, (void **)&player
);
626 if (hr
== REGDB_E_CLASSNOTREG
)
628 win_skip("CLSID_WindowsMediaPlayer is not registered.\n");
631 ok(hr
== S_OK
, "Failed to create media player instance, hr %#x.\n", hr
);
633 hr
= IWMPPlayer4_get_URL(player
, &str
);
634 ok(hr
== S_OK
, "Failed to get url, hr %#x.\n", hr
);
635 ok(*str
== 0, "Unexpected url %s.\n", wine_dbgstr_w(str
));
638 str2
= SysAllocString(mp3file
);
639 hr
= IWMPPlayer4_put_URL(player
, str2
);
640 ok(hr
== S_OK
, "Failed to set url, hr %#x.\n", hr
);
642 hr
= IWMPPlayer4_put_URL(player
, NULL
);
643 ok(hr
== S_OK
, "Failed to set url, hr %#x.\n", hr
);
644 hr
= IWMPPlayer4_get_URL(player
, &str
);
645 ok(hr
== S_OK
, "Failed to set url, hr %#x.\n", hr
);
646 ok(*str
== 0, "Unexpected url, %s.\n", wine_dbgstr_w(str
));
650 hr
= IWMPPlayer4_put_URL(player
, str2
);
651 ok(hr
== S_OK
, "Failed to set url, hr %#x.\n", hr
);
653 str
= SysAllocStringLen(NULL
, 0);
654 hr
= IWMPPlayer4_put_URL(player
, str
);
655 ok(hr
== S_OK
, "Failed to set url, hr %#x.\n", hr
);
658 hr
= IWMPPlayer4_get_URL(player
, &str
);
659 ok(hr
== S_OK
, "Failed to set url, hr %#x.\n", hr
);
660 ok(*str
== 0, "Unexpected url, %s.\n", wine_dbgstr_w(str
));
664 IWMPPlayer4_Release(player
);
667 static void test_playlist(void)
670 IWMPPlaylist
*playlist
, *playlist2
;
674 static const WCHAR nameW
[] = {'P','l','a','y','l','i','s','t','1',0};
676 hr
= CoCreateInstance(&CLSID_WindowsMediaPlayer
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IWMPPlayer4
, (void **)&player
);
677 if (hr
== REGDB_E_CLASSNOTREG
)
679 win_skip("CLSID_WindowsMediaPlayer is not registered.\n");
682 ok(hr
== S_OK
, "Failed to create media player instance, hr %#x.\n", hr
);
685 hr
= IWMPPlayer4_get_currentPlaylist(player
, &playlist
);
686 ok(hr
== S_OK
, "IWMPPlayer4_get_currentPlaylist failed: %08x\n", hr
);
687 ok(playlist
!= NULL
, "playlist == NULL\n");
689 if (0) /* fails on non-English locales */
691 hr
= IWMPPlaylist_get_name(playlist
, &str
);
692 ok(hr
== S_OK
, "Failed to get playlist name, hr %#x.\n", hr
);
693 ok(!lstrcmpW(str
, nameW
), "Expected %s, got %s\n", wine_dbgstr_w(nameW
), wine_dbgstr_w(str
));
697 hr
= IWMPPlaylist_get_count(playlist
, NULL
);
698 ok(hr
== E_POINTER
, "Failed to get count, hr %#x.\n", hr
);
701 hr
= IWMPPlaylist_get_count(playlist
, &count
);
702 ok(hr
== S_OK
, "Failed to get count, hr %#x.\n", hr
);
703 ok(count
== 0, "Expected 0, got %d\n", count
);
705 IWMPPlaylist_Release(playlist
);
707 /* newPlaylist doesn't change current playlist */
708 hr
= IWMPPlayer4_newPlaylist(player
, NULL
, NULL
, &playlist
);
709 ok(hr
== S_OK
, "Failed to create a playlist, hr %#x.\n", hr
);
712 hr
= IWMPPlayer4_get_currentPlaylist(player
, &playlist2
);
713 ok(hr
== S_OK
, "IWMPPlayer4_get_currentPlaylist failed: %08x\n", hr
);
714 ok(playlist2
!= NULL
&& playlist2
!= playlist
, "Unexpected playlist instance\n");
716 IWMPPlaylist_Release(playlist2
);
718 /* different playlists can have the same name */
719 str
= SysAllocString(nameW
);
720 hr
= IWMPPlaylist_put_name(playlist
, str
);
721 ok(hr
== S_OK
, "Failed to get playlist name, hr %#x.\n", hr
);
724 hr
= IWMPPlayer4_newPlaylist(player
, str
, NULL
, &playlist2
);
725 ok(hr
== S_OK
, "Failed to create a playlist, hr %#x.\n", hr
);
726 hr
= IWMPPlaylist_get_name(playlist2
, &str2
);
727 ok(hr
== S_OK
, "Failed to get playlist name, hr %#x.\n", hr
);
728 ok(playlist
!= playlist2
, "Expected playlists to be different");
729 ok(!lstrcmpW(str
, str2
), "Expected names to be the same\n");
733 IWMPPlaylist_Release(playlist2
);
735 IWMPPlaylist_Release(playlist
);
736 IWMPPlayer4_Release(player
);
743 main_thread_id
= GetCurrentThreadId();
744 playing_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
745 completed_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
751 test_completion_event();
753 win_skip("Failed to play media\n");
756 CloseHandle(playing_event
);
757 CloseHandle(completed_event
);