Signed-off-by: Myah Caron qsniyg@protonmail.com --- v2: - Skip test if AudioOutput key doesn't exist (fixes Marvin test failures, but shouldn't happen on updated prefixes that have applied the first patch). - Improve wording for SPERR_NOT_FOUND skip.
Original notes below:
This patchset is a first step towards fixing https://bugs.winehq.org/show_bug.cgi?id=49641
My previous attempt (https://www.winehq.org/pipermail/wine-devel/2020-August/171124.html) was a rather large patch and had tests that I believe were much too invasive (deleting and restoring system registry keys).
Since my previous attempt was dropped (fair enough), in order to reduce the patch review burden, this patch is much smaller and is only meant to cover the bug's use case.
dlls/sapi/tests/token.c | 64 +++++++++++++++++++++++++++++++++++++++++ dlls/sapi/token.c | 34 ++++++++++++++++++++-- 2 files changed, 96 insertions(+), 2 deletions(-)
diff --git a/dlls/sapi/tests/token.c b/dlls/sapi/tests/token.c index 9f6689b83f8..afa159f4f6f 100644 --- a/dlls/sapi/tests/token.c +++ b/dlls/sapi/tests/token.c @@ -116,11 +116,75 @@ static void test_token_enum(void) ISpObjectTokenEnumBuilder_Release( token_enum ); }
+static void test_default_token_id(void) +{ + ISpObjectTokenCategory *cat; + HRESULT hr; + LPWSTR token_id = NULL; + LONG res; + WCHAR regvalue[512]; + DWORD regvalue_size; + + hr = CoCreateInstance( &CLSID_SpObjectTokenCategory, NULL, CLSCTX_INPROC_SERVER, + &IID_ISpObjectTokenCategory, (void **)&cat ); + ok( hr == S_OK, "got %08x\n", hr ); + + token_id = (LPWSTR)0xdeadbeef; + hr = ISpObjectTokenCategory_GetDefaultTokenId( cat, &token_id ); + ok( hr == SPERR_UNINITIALIZED, "got %08x\n", hr ); + ok( token_id == (LPWSTR)0xdeadbeef, "got %p\n", token_id ); + + hr = ISpObjectTokenCategory_GetDefaultTokenId( cat, NULL ); + ok( hr == SPERR_UNINITIALIZED, "got %08x\n", hr ); + + hr = ISpObjectTokenCategory_SetId( cat, SPCAT_AUDIOOUT, FALSE ); + if (hr == SPERR_INVALID_REGISTRY_KEY) { + skip( "AudioOutput category not found\n" ); + return; + } else { + ok( hr == S_OK, "got %08x\n", hr ); + } + + hr = ISpObjectTokenCategory_GetDefaultTokenId( cat, NULL ); + ok( hr == E_POINTER, "got %08x\n", hr ); + + token_id = (LPWSTR)0xdeadbeef; + hr = ISpObjectTokenCategory_GetDefaultTokenId( cat, &token_id ); + + /* AudioOutput under windows server returns this error */ + if (hr == SPERR_NOT_FOUND) { + /* also happens if TokenEnums/Tokens is empty or doesn't exist */ + skip( "AudioOutput category not found for GetDefaultTokenId\n" ); + return; + } + + ok( hr == S_OK, "got %08x\n", hr ); + ok( token_id != (LPWSTR)0xdeadbeef && token_id != NULL, "got %p\n", token_id ); + + regvalue_size = sizeof( regvalue ); + res = RegGetValueW( HKEY_LOCAL_MACHINE, L"SOFTWARE\Microsoft\Speech\AudioOutput", + L"DefaultDefaultTokenId", RRF_RT_REG_SZ, NULL, + (LPVOID)®value, ®value_size); + if (res == ERROR_FILE_NOT_FOUND) { + skip( "DefaultDefaultTokenId not found for AudioOutput category (%s)\n", + wine_dbgstr_w(token_id) ); + } else { + ok( res == ERROR_SUCCESS, "got %08x\n", res ); + ok( !wcscmp(regvalue, token_id), + "GetDefaultTokenId (%s) should be equal to the DefaultDefaultTokenId key (%s)\n", + wine_dbgstr_w(token_id), wine_dbgstr_w(regvalue) ); + } + + CoTaskMemFree( token_id ); + ISpObjectTokenCategory_Release( cat ); +} + START_TEST(token) { CoInitialize( NULL ); test_data_key(); test_token_category(); test_token_enum(); + test_default_token_id(); CoUninitialize(); } diff --git a/dlls/sapi/token.c b/dlls/sapi/token.c index d2b70c95cfc..21cd958282f 100644 --- a/dlls/sapi/token.c +++ b/dlls/sapi/token.c @@ -489,8 +489,38 @@ static HRESULT WINAPI token_category_SetDefaultTokenId( ISpObjectTokenCategory * static HRESULT WINAPI token_category_GetDefaultTokenId( ISpObjectTokenCategory *iface, LPWSTR *id ) { - FIXME( "stub\n" ); - return E_NOTIMPL; + struct token_category *This = impl_from_ISpObjectTokenCategory( iface ); + struct data_key *this_data_key; + LONG res; + WCHAR regvalue[512]; + DWORD regvalue_size = sizeof( regvalue ); + + FIXME( "(%p)->(%p): semi-stub\n", iface, id ); + + if (!This->data_key) + return SPERR_UNINITIALIZED; + + if (!id) + return E_POINTER; + + /* todo: check HKCU's DefaultTokenId before */ + + this_data_key = impl_from_ISpRegDataKey( This->data_key ); + + res = RegGetValueW( this_data_key->key, NULL, L"DefaultDefaultTokenId", RRF_RT_REG_SZ, + NULL, ®value, ®value_size); + if (res == ERROR_FILE_NOT_FOUND) { + return SPERR_NOT_FOUND; + } else if (res != ERROR_SUCCESS) { + /* probably not the correct return value */ + FIXME( "returning %08x\n", res ); + return res; + } + + *id = CoTaskMemAlloc( regvalue_size ); + wcscpy( *id, regvalue ); + + return S_OK; }
const struct ISpObjectTokenCategoryVtbl token_category_vtbl = -- 2.28.0