From: Mohamad Al-Jaf mohamadaljaf@gmail.com
Signed-off-by: Mohamad Al-Jaf mohamadaljaf@gmail.com Signed-off-by: Nikolay Sivov nsivov@codeweavers.com ---
v6: removed unrelated inline helper, this is guarded differently in SDK.
dlls/propsys/propsys.spec | 2 +- dlls/propsys/propvar.c | 16 ++++++++++++++++ include/propvarutil.h | 1 + 3 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/dlls/propsys/propsys.spec b/dlls/propsys/propsys.spec index 15749952e95..7391cf4aaa2 100644 --- a/dlls/propsys/propsys.spec +++ b/dlls/propsys/propsys.spec @@ -194,7 +194,7 @@ @ stub VariantToStringAlloc @ stub VariantToStringArray @ stub VariantToStringArrayAlloc -@ stub VariantToStringWithDefault +@ stdcall VariantToStringWithDefault(ptr wstr) @ stub VariantToUInt16 @ stub VariantToUInt16Array @ stub VariantToUInt16ArrayAlloc diff --git a/dlls/propsys/propvar.c b/dlls/propsys/propvar.c index 8f6c52f7aa7..cd92912fde5 100644 --- a/dlls/propsys/propvar.c +++ b/dlls/propsys/propvar.c @@ -416,6 +416,22 @@ PCWSTR WINAPI PropVariantToStringWithDefault(REFPROPVARIANT propvarIn, LPCWSTR p return pszDefault; }
+/****************************************************************** + * VariantToStringWithDefault (PROPSYS.@) + */ +PCWSTR WINAPI VariantToStringWithDefault(const VARIANT *pvar, const WCHAR *default_value) +{ + TRACE("%s, %s.\n", debugstr_variant(pvar), debugstr_w(default_value)); + + if (V_VT(pvar) == (VT_BYREF | VT_VARIANT)) pvar = V_VARIANTREF(pvar); + if (V_VT(pvar) == (VT_BYREF | VT_BSTR) || V_VT(pvar) == VT_BSTR) + { + BSTR ret = V_ISBYREF(pvar) ? *V_BSTRREF(pvar) : V_BSTR(pvar); + return ret ? ret : L""; + } + + return default_value; +}
/****************************************************************** * PropVariantChangeType (PROPSYS.@) diff --git a/include/propvarutil.h b/include/propvarutil.h index 36a670f56e6..fcc532fd623 100644 --- a/include/propvarutil.h +++ b/include/propvarutil.h @@ -93,6 +93,7 @@ HRESULT WINAPI PropVariantToBoolean(REFPROPVARIANT propvarIn, BOOL *ret); HRESULT WINAPI PropVariantToBuffer(REFPROPVARIANT propvarIn, void *ret, UINT cb); HRESULT WINAPI PropVariantToString(REFPROPVARIANT propvarIn, PWSTR ret, UINT cch); PCWSTR WINAPI PropVariantToStringWithDefault(REFPROPVARIANT propvarIn, LPCWSTR pszDefault); +PCWSTR WINAPI VariantToStringWithDefault(const VARIANT *pvar, LPCWSTR pszDefault);
HRESULT WINAPI PropVariantToStringAlloc(REFPROPVARIANT propvarIn, WCHAR **ret);
From: Mohamad Al-Jaf mohamadaljaf@gmail.com
Signed-off-by: Mohamad Al-Jaf mohamadaljaf@gmail.com Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/propsys/tests/propsys.c | 187 +++++++++++++++++++++++++++++++++++ 1 file changed, 187 insertions(+)
diff --git a/dlls/propsys/tests/propsys.c b/dlls/propsys/tests/propsys.c index 124b3405bcb..47a7930a18b 100644 --- a/dlls/propsys/tests/propsys.c +++ b/dlls/propsys/tests/propsys.c @@ -2064,6 +2064,192 @@ static void test_InitVariantFromFileTime(void) ok(V_DATE(&var) == d, "got wrong value: %f, expected %f\n", V_DATE(&var), d); }
+static void test_VariantToStringWithDefault(void) +{ + static WCHAR default_value[] = L"test"; + VARIANT var, var2; + PCWSTR result; + BSTR b; + + V_VT(&var) = VT_EMPTY; + result = VariantToStringWithDefault(&var, NULL); + ok(result == NULL, "Unexpected value %s\n", wine_dbgstr_w(result)); + result = VariantToStringWithDefault(&var, default_value); + ok(result == default_value, "Unexpected value %s\n", wine_dbgstr_w(result)); + + V_VT(&var) = VT_NULL; + result = VariantToStringWithDefault(&var, NULL); + ok(result == NULL, "Unexpected value %s\n", wine_dbgstr_w(result)); + result = VariantToStringWithDefault(&var, default_value); + ok(result == default_value, "Unexpected value %s\n", wine_dbgstr_w(result)); + + V_VT(&var) = VT_BOOL; + result = VariantToStringWithDefault(&var, NULL); + ok(result == NULL, "Unexpected value %s\n", wine_dbgstr_w(result)); + V_BOOL(&var) = VARIANT_TRUE; + result = VariantToStringWithDefault(&var, default_value); + ok(result == default_value, "Unexpected value %s\n", wine_dbgstr_w(result)); + + V_VT(&var) = VT_CY; + V_CY(&var).int64 = 100000; + result = VariantToStringWithDefault(&var, NULL); + ok(result == NULL, "Unexpected value %s\n", wine_dbgstr_w(result)); + result = VariantToStringWithDefault(&var, default_value); + ok(result == default_value, "Unexpected value %s\n", wine_dbgstr_w(result)); + + V_VT(&var) = VT_DATE; + V_DATE(&var) = 42.0; + result = VariantToStringWithDefault(&var, NULL); + ok(result == NULL, "Unexpected value %s\n", wine_dbgstr_w(result)); + result = VariantToStringWithDefault(&var, default_value); + ok(result == default_value, "Unexpected value %s\n", wine_dbgstr_w(result)); + + V_VT(&var) = VT_ERROR; + V_ERROR(&var) = DISP_E_PARAMNOTFOUND; + result = VariantToStringWithDefault(&var, NULL); + ok(result == NULL, "Unexpected value %s\n", wine_dbgstr_w(result)); + result = VariantToStringWithDefault(&var, default_value); + ok(result == default_value, "Unexpected value %s\n", wine_dbgstr_w(result)); + + V_VT(&var) = VT_I4; + V_I4(&var) = 15; + result = VariantToStringWithDefault(&var, NULL); + ok(result == NULL, "Unexpected value %s\n", wine_dbgstr_w(result)); + result = VariantToStringWithDefault(&var, default_value); + ok(result == default_value, "Unexpected value %s\n", wine_dbgstr_w(result)); + + V_VT(&var) = VT_I1; + V_I1(&var) = 1; + result = VariantToStringWithDefault(&var, NULL); + ok(result == NULL, "Unexpected value %s\n", wine_dbgstr_w(result)); + result = VariantToStringWithDefault(&var, default_value); + ok(result == default_value, "Unexpected value %s\n", wine_dbgstr_w(result)); + + /* V_BSTR */ + + V_VT(&var) = VT_BSTR; + V_BSTR(&var) = NULL; + result = VariantToStringWithDefault(&var, default_value); + ok(result[0] == '\0', "Unexpected value %s\n", wine_dbgstr_w(result)); + + V_VT(&var) = VT_BSTR; + V_BSTR(&var) = SysAllocString(L""); + result = VariantToStringWithDefault(&var, default_value); + ok(result == V_BSTR(&var), "Unexpected value %s\n", wine_dbgstr_w(result)); + VariantClear(&var); + + V_VT(&var) = VT_BSTR; + V_BSTR(&var) = SysAllocString(L" "); + result = VariantToStringWithDefault(&var, default_value); + ok(result == V_BSTR(&var), "Unexpected value %s\n", wine_dbgstr_w(result)); + VariantClear(&var); + + V_VT(&var) = VT_BSTR; + V_BSTR(&var) = SysAllocString(L"test1"); + result = VariantToStringWithDefault(&var, default_value); + ok(result == V_BSTR(&var), "Unexpected value %s\n", wine_dbgstr_w(result)); + VariantClear(&var); + + /* V_BSTRREF */ + + V_VT(&var) = VT_BYREF | VT_BSTR; + b = NULL; + V_BSTRREF(&var) = &b; + result = VariantToStringWithDefault(&var, default_value); + ok(result[0] == '\0', "Unexpected value %s\n", wine_dbgstr_w(result)); + + V_VT(&var) = VT_BYREF | VT_BSTR; + b = SysAllocString(L""); + V_BSTRREF(&var) = &b; + result = VariantToStringWithDefault(&var, default_value); + ok(result == b, "Unexpected value %s\n", wine_dbgstr_w(result)); + SysFreeString(b); + + V_VT(&var) = VT_BYREF | VT_BSTR; + b = SysAllocString(L" "); + V_BSTRREF(&var) = &b; + result = VariantToStringWithDefault(&var, default_value); + ok(result == b, "Unexpected value %s\n", wine_dbgstr_w(result)); + SysFreeString(b); + + V_VT(&var) = VT_BYREF | VT_BSTR; + b = SysAllocString(L"test1"); + V_BSTRREF(&var) = &b; + result = VariantToStringWithDefault(&var, default_value); + ok(result == b, "Unexpected value %s\n", wine_dbgstr_w(result)); + SysFreeString(b); + + /* Nested V_BSTR */ + + V_VT(&var) = VT_BYREF | VT_VARIANT; + V_VT(&var2) = VT_BSTR; + V_BSTR(&var2) = NULL; + V_VARIANTREF(&var) = &var2; + result = VariantToStringWithDefault(&var, default_value); + ok(result[0] == '\0', "Unexpected value %s\n", wine_dbgstr_w(result)); + + V_VT(&var) = VT_BYREF | VT_VARIANT; + V_VT(&var2) = VT_BSTR; + V_BSTR(&var2) = SysAllocString(L""); + V_VARIANTREF(&var) = &var2; + result = VariantToStringWithDefault(&var, default_value); + ok(result == V_BSTR(&var2), "Unexpected value %s\n", wine_dbgstr_w(result)); + VariantClear(&var2); + + V_VT(&var) = VT_BYREF | VT_VARIANT; + V_VT(&var2) = VT_BSTR; + V_BSTR(&var2) = SysAllocString(L" "); + V_VARIANTREF(&var) = &var2; + result = VariantToStringWithDefault(&var, default_value); + ok(result == V_BSTR(&var2), "Unexpected value %s\n", wine_dbgstr_w(result)); + VariantClear(&var2); + + V_VT(&var) = VT_BYREF | VT_VARIANT; + V_VT(&var2) = VT_BSTR; + V_BSTR(&var2) = SysAllocString(L"test1"); + V_VARIANTREF(&var) = &var2; + result = VariantToStringWithDefault(&var, default_value); + ok(result == V_BSTR(&var2), "Unexpected value %s\n", wine_dbgstr_w(result)); + VariantClear(&var2); + + /* Nested V_BSTRREF */ + + V_VT(&var) = VT_BYREF | VT_VARIANT; + V_VT(&var2) = VT_BYREF | VT_BSTR; + b = NULL; + V_BSTRREF(&var2) = &b; + V_VARIANTREF(&var) = &var2; + result = VariantToStringWithDefault(&var, default_value); + ok(result[0] == '\0', "Unexpected value %s\n", wine_dbgstr_w(result)); + + V_VT(&var) = VT_BYREF | VT_VARIANT; + V_VT(&var2) = VT_BYREF | VT_BSTR; + b = SysAllocString(L""); + V_BSTRREF(&var2) = &b; + V_VARIANTREF(&var) = &var2; + result = VariantToStringWithDefault(&var, default_value); + ok(result == b, "Unexpected value %s\n", wine_dbgstr_w(result)); + SysFreeString(b); + + V_VT(&var) = VT_BYREF | VT_VARIANT; + V_VT(&var2) = VT_BYREF | VT_BSTR; + b = SysAllocString(L" "); + V_BSTRREF(&var2) = &b; + V_VARIANTREF(&var) = &var2; + result = VariantToStringWithDefault(&var, default_value); + ok(result == b, "Unexpected value %s\n", wine_dbgstr_w(result)); + SysFreeString(b); + + V_VT(&var) = VT_BYREF | VT_VARIANT; + V_VT(&var2) = VT_BYREF | VT_BSTR; + b = SysAllocString(L"test1"); + V_BSTRREF(&var2) = &b; + V_VARIANTREF(&var) = &var2; + result = VariantToStringWithDefault(&var, default_value); + ok(result == b, "Unexpected value %s\n", wine_dbgstr_w(result)); + SysFreeString(b); +} + START_TEST(propsys) { test_PSStringFromPropertyKey(); @@ -2088,4 +2274,5 @@ START_TEST(propsys) test_propertystore(); test_PSCreatePropertyStoreFromObject(); test_InitVariantFromFileTime(); + test_VariantToStringWithDefault(); }