From 27338bc4b52da8d92fec72faa8dd47c23ebc2b41 Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Mon, 20 Aug 2018 11:58:33 +0300 Subject: [PATCH] wmp: Improve URL property handling. Signed-off-by: Nikolay Sivov Signed-off-by: Alexandre Julliard --- dlls/wmp/player.c | 17 ++++++--------- dlls/wmp/tests/media.c | 49 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 11 deletions(-) diff --git a/dlls/wmp/player.c b/dlls/wmp/player.c index fd8c17d60f9..519ffa1d18f 100644 --- a/dlls/wmp/player.c +++ b/dlls/wmp/player.c @@ -28,7 +28,7 @@ static ATOM player_msg_class; static INIT_ONCE class_init_once; static UINT WM_WMPEVENT; static const WCHAR WMPmessageW[] = {'_', 'W', 'M', 'P', 'M','e','s','s','a','g','e',0}; - +static const WCHAR emptyW[] = {0}; static void update_state(WindowsMediaPlayer *wmp, LONG type, LONG state) { @@ -135,9 +135,8 @@ static HRESULT WINAPI WMPPlayer4_get_URL(IWMPPlayer4 *iface, BSTR *url) TRACE("(%p)->(%p)\n", This, url); - if(This->media == NULL) { - return S_FALSE; - } + if (!This->media) + return return_bstr(emptyW, url); return return_bstr(This->media->url, url); } @@ -147,10 +146,8 @@ static HRESULT WINAPI WMPPlayer4_put_URL(IWMPPlayer4 *iface, BSTR url) WindowsMediaPlayer *This = impl_from_IWMPPlayer4(iface); IWMPMedia *media; HRESULT hres; + TRACE("(%p)->(%s)\n", This, debugstr_w(url)); - if(url == NULL) { - return E_POINTER; - } hres = create_media_from_url(url, 0.0, &media); @@ -161,9 +158,8 @@ static HRESULT WINAPI WMPPlayer4_put_URL(IWMPPlayer4 *iface, BSTR url) } if (SUCCEEDED(hres)) { update_state(This, DISPID_WMPCOREEVENT_PLAYSTATECHANGE, wmppsReady); - if (This->auto_start == VARIANT_TRUE) { - hres = IWMPControls_play(&This->IWMPControls_iface); - } + if (This->auto_start == VARIANT_TRUE) + IWMPControls_play(&This->IWMPControls_iface); } return hres; @@ -2025,7 +2021,6 @@ WMPMedia *unsafe_impl_from_IWMPMedia(IWMPMedia *iface) HRESULT create_media_from_url(BSTR url, double duration, IWMPMedia **ppMedia) { - static const WCHAR emptyW[] = {0}; WMPMedia *media; media = heap_alloc_zero(sizeof(*media)); diff --git a/dlls/wmp/tests/media.c b/dlls/wmp/tests/media.c index bd9aefc975f..dd6fdcbc919 100644 --- a/dlls/wmp/tests/media.c +++ b/dlls/wmp/tests/media.c @@ -562,6 +562,54 @@ todo_wine IWMPPlayer4_Release(player); } +static void test_player_url(void) +{ + IWMPPlayer4 *player; + BSTR str, str2; + HRESULT hr; + + hr = CoCreateInstance(&CLSID_WindowsMediaPlayer, NULL, CLSCTX_INPROC_SERVER, &IID_IWMPPlayer4, (void **)&player); + if (hr == REGDB_E_CLASSNOTREG) + { + win_skip("CLSID_WindowsMediaPlayer is not registered.\n"); + return; + } + ok(hr == S_OK, "Failed to create media player instance, hr %#x.\n", hr); + + hr = IWMPPlayer4_get_URL(player, &str); + ok(hr == S_OK, "Failed to get url, hr %#x.\n", hr); + ok(*str == 0, "Unexpected url %s.\n", wine_dbgstr_w(str)); + SysFreeString(str); + + str2 = SysAllocString(mp3file); + hr = IWMPPlayer4_put_URL(player, str2); + ok(hr == S_OK, "Failed to set url, hr %#x.\n", hr); + + hr = IWMPPlayer4_put_URL(player, NULL); + ok(hr == S_OK, "Failed to set url, hr %#x.\n", hr); + hr = IWMPPlayer4_get_URL(player, &str); + ok(hr == S_OK, "Failed to set url, hr %#x.\n", hr); + ok(*str == 0, "Unexpected url, %s.\n", wine_dbgstr_w(str)); + SysFreeString(str); + + /* Empty url */ + hr = IWMPPlayer4_put_URL(player, str2); + ok(hr == S_OK, "Failed to set url, hr %#x.\n", hr); + + str = SysAllocStringLen(NULL, 0); + hr = IWMPPlayer4_put_URL(player, str); + ok(hr == S_OK, "Failed to set url, hr %#x.\n", hr); + SysFreeString(str); + + hr = IWMPPlayer4_get_URL(player, &str); + ok(hr == S_OK, "Failed to set url, hr %#x.\n", hr); + ok(*str == 0, "Unexpected url, %s.\n", wine_dbgstr_w(str)); + SysFreeString(str); + + SysFreeString(str2); + IWMPPlayer4_Release(player); +} + START_TEST(media) { CoInitialize(NULL); @@ -571,6 +619,7 @@ START_TEST(media) completed_event = CreateEventW(NULL, FALSE, FALSE, NULL); test_media_item(); + test_player_url(); if (test_wmp()) { test_completion_event(); } else {