Commit e0a829db authored by Jactry Zeng's avatar Jactry Zeng Committed by Alexandre Julliard

propsys: Implement PropVariantToString().

parent 8db8c941
......@@ -133,7 +133,7 @@
@ stub PropVariantToInt64VectorAlloc
@ stub PropVariantToInt64WithDefault
@ stub PropVariantToStrRet
@ stub PropVariantToString
@ stdcall PropVariantToString(ptr ptr long)
@ stdcall PropVariantToStringAlloc(ptr ptr)
@ stub PropVariantToStringVector
@ stub PropVariantToStringVectorAlloc
......
......@@ -34,6 +34,7 @@
#include "winuser.h"
#include "shlobj.h"
#include "propvarutil.h"
#include "strsafe.h"
#include "wine/debug.h"
#include "wine/unicode.h"
......@@ -305,6 +306,30 @@ HRESULT WINAPI PropVariantToBoolean(REFPROPVARIANT propvarIn, BOOL *ret)
return hr;
}
HRESULT WINAPI PropVariantToString(REFPROPVARIANT propvarIn, PWSTR ret, UINT cch)
{
HRESULT hr;
WCHAR *stringW = NULL;
TRACE("(%p, %p, %d)\n", propvarIn, ret, cch);
ret[0] = '\0';
if(!cch)
return E_INVALIDARG;
hr = PropVariantToStringAlloc(propvarIn, &stringW);
if(SUCCEEDED(hr))
{
if(lstrlenW(stringW) >= cch)
hr = STRSAFE_E_INSUFFICIENT_BUFFER;
lstrcpynW(ret, stringW, cch);
CoTaskMemFree(stringW);
}
return hr;
}
HRESULT WINAPI PropVariantToStringAlloc(REFPROPVARIANT propvarIn, WCHAR **ret)
{
WCHAR *res = NULL;
......
......@@ -32,6 +32,7 @@
#include "initguid.h"
#include "propsys.h"
#include "propvarutil.h"
#include "strsafe.h"
#include "wine/test.h"
DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
......@@ -1310,6 +1311,95 @@ static void test_PropVariantToDouble(void)
ok(value == 8.0, "Unexpected value: %f.\n", value);
}
static void test_PropVariantToString(void)
{
PROPVARIANT propvar;
static CHAR string[] = "Wine";
static WCHAR stringW[] = {'W','i','n','e',0};
WCHAR bufferW[256] = {0};
HRESULT hr;
PropVariantInit(&propvar);
propvar.vt = VT_EMPTY;
U(propvar).pwszVal = stringW;
bufferW[0] = 65;
hr = PropVariantToString(&propvar, bufferW, 0);
ok(hr == E_INVALIDARG, "PropVariantToString should fail: 0x%08x.\n", hr);
ok(!bufferW[0], "got wrong string: \"%s\".\n", wine_dbgstr_w(bufferW));
memset(bufferW, 0, sizeof(bufferW));
PropVariantClear(&propvar);
PropVariantInit(&propvar);
propvar.vt = VT_EMPTY;
U(propvar).pwszVal = stringW;
bufferW[0] = 65;
hr = PropVariantToString(&propvar, bufferW, ARRAY_SIZE(bufferW));
ok(hr == S_OK, "PropVariantToString failed: 0x%08x.\n", hr);
ok(!bufferW[0], "got wrong string: \"%s\".\n", wine_dbgstr_w(bufferW));
memset(bufferW, 0, sizeof(bufferW));
PropVariantClear(&propvar);
PropVariantInit(&propvar);
propvar.vt = VT_NULL;
U(propvar).pwszVal = stringW;
bufferW[0] = 65;
hr = PropVariantToString(&propvar, bufferW, ARRAY_SIZE(bufferW));
ok(hr == S_OK, "PropVariantToString failed: 0x%08x.\n", hr);
ok(!bufferW[0], "got wrong string: \"%s\".\n", wine_dbgstr_w(bufferW));
memset(bufferW, 0, sizeof(bufferW));
PropVariantClear(&propvar);
PropVariantInit(&propvar);
propvar.vt = VT_I4;
U(propvar).lVal = 22;
hr = PropVariantToString(&propvar, bufferW, ARRAY_SIZE(bufferW));
todo_wine ok(hr == S_OK, "PropVariantToString failed: 0x%08x.\n", hr);
todo_wine ok(!strcmp_wa(bufferW, "22"), "got wrong string: \"%s\".\n", wine_dbgstr_w(bufferW));
memset(bufferW, 0, sizeof(bufferW));
PropVariantClear(&propvar);
PropVariantInit(&propvar);
propvar.vt = VT_LPWSTR;
U(propvar).pwszVal = stringW;
hr = PropVariantToString(&propvar, bufferW, ARRAY_SIZE(bufferW));
ok(hr == S_OK, "PropVariantToString failed: 0x%08x.\n", hr);
ok(!lstrcmpW(bufferW, stringW), "got wrong string: \"%s\".\n", wine_dbgstr_w(bufferW));
memset(bufferW, 0, sizeof(bufferW));
PropVariantInit(&propvar);
propvar.vt = VT_LPSTR;
U(propvar).pszVal = string;
hr = PropVariantToString(&propvar, bufferW, ARRAY_SIZE(bufferW));
ok(hr == S_OK, "PropVariantToString failed: 0x%08x.\n", hr);
ok(!lstrcmpW(bufferW, stringW), "got wrong string: \"%s\".\n", wine_dbgstr_w(bufferW));
memset(bufferW, 0, sizeof(bufferW));
PropVariantInit(&propvar);
propvar.vt = VT_LPWSTR;
U(propvar).pwszVal = stringW;
hr = PropVariantToString(&propvar, bufferW, 4);
ok(hr == STRSAFE_E_INSUFFICIENT_BUFFER, "PropVariantToString returned: 0x%08x.\n", hr);
ok(!memcmp(bufferW, stringW, 4), "got wrong string.\n");
memset(bufferW, 0, sizeof(bufferW));
PropVariantInit(&propvar);
propvar.vt = VT_LPSTR;
U(propvar).pszVal = string;
hr = PropVariantToString(&propvar, bufferW, 4);
ok(hr == STRSAFE_E_INSUFFICIENT_BUFFER, "PropVariantToString returned: 0x%08x.\n", hr);
ok(!memcmp(bufferW, stringW, 4), "got wrong string.\n");
memset(bufferW, 0, sizeof(bufferW));
PropVariantInit(&propvar);
propvar.vt = VT_BSTR;
propvar.u.bstrVal = SysAllocString(stringW);
hr = PropVariantToString(&propvar, bufferW, ARRAY_SIZE(bufferW));
ok(hr == S_OK, "PropVariantToString failed: 0x%08x.\n", hr);
ok(!lstrcmpW(bufferW, stringW), "got wrong string: \"%s\".\n", wine_dbgstr_w(bufferW));
memset(bufferW, 0, sizeof(bufferW));
SysFreeString(propvar.u.bstrVal);
}
START_TEST(propsys)
{
test_PSStringFromPropertyKey();
......@@ -1326,4 +1416,5 @@ START_TEST(propsys)
test_PropVariantToStringWithDefault();
test_InitPropVariantFromCLSID();
test_PropVariantToDouble();
test_PropVariantToString();
}
......@@ -79,6 +79,7 @@ HRESULT WINAPI PropVariantToUInt16(REFPROPVARIANT propvarIn, USHORT *ret);
HRESULT WINAPI PropVariantToUInt32(REFPROPVARIANT propvarIn, ULONG *ret);
HRESULT WINAPI PropVariantToUInt64(REFPROPVARIANT propvarIn, ULONGLONG *ret);
HRESULT WINAPI PropVariantToBoolean(REFPROPVARIANT propvarIn, BOOL *ret);
HRESULT WINAPI PropVariantToString(REFPROPVARIANT propvarIn, PWSTR ret, UINT cch);
PCWSTR WINAPI PropVariantToStringWithDefault(REFPROPVARIANT propvarIn, LPCWSTR pszDefault);
HRESULT WINAPI PropVariantToStringAlloc(REFPROPVARIANT propvarIn, WCHAR **ret);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment