Commit 3a1146d8 authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

propsys: Add InitPropVariantFromStringVector().

parent de6c2f9c
......@@ -41,7 +41,7 @@
@ stub InitPropVariantFromResource
@ stub InitPropVariantFromStrRet
@ stub InitPropVariantFromStringAsVector
@ stub InitPropVariantFromStringVector
@ stdcall InitPropVariantFromStringVector(ptr long ptr)
@ stub InitPropVariantFromUInt16Vector
@ stub InitPropVariantFromUInt32Vector
@ stub InitPropVariantFromUInt64Vector
......
......@@ -657,6 +657,38 @@ HRESULT WINAPI InitPropVariantFromCLSID(REFCLSID clsid, PROPVARIANT *ppropvar)
return S_OK;
}
HRESULT WINAPI InitPropVariantFromStringVector(PCWSTR *strs, ULONG count, PROPVARIANT *ppropvar)
{
unsigned int i;
TRACE("(%p %lu %p)\n", strs, count, ppropvar);
ppropvar->calpwstr.pElems = CoTaskMemAlloc(count * sizeof(*ppropvar->calpwstr.pElems));
if(!ppropvar->calpwstr.pElems)
return E_OUTOFMEMORY;
ppropvar->vt = VT_LPWSTR | VT_VECTOR;
ppropvar->calpwstr.cElems = 0;
if (count)
memset(ppropvar->calpwstr.pElems, 0, count * sizeof(*ppropvar->calpwstr.pElems));
for (i = 0; i < count; ++i)
{
if (strs[i])
{
if (!(ppropvar->calpwstr.pElems[i] = CoTaskMemAlloc((wcslen(strs[i]) + 1)*sizeof(**strs))))
{
PropVariantClear(ppropvar);
return E_OUTOFMEMORY;
}
}
wcscpy(ppropvar->calpwstr.pElems[i], strs[i]);
ppropvar->calpwstr.cElems++;
}
return S_OK;
}
HRESULT WINAPI InitVariantFromBuffer(const VOID *pv, UINT cb, VARIANT *pvar)
{
SAFEARRAY *arr;
......
......@@ -1419,6 +1419,35 @@ static void test_InitPropVariantFromCLSID(void)
PropVariantClear(&propvar);
}
static void test_InitPropVariantFromStringVector(void)
{
static const WCHAR *strs[2] = { L"abc", L"def" };
PROPVARIANT propvar;
HRESULT hr;
memset(&propvar, 0, sizeof(propvar));
propvar.vt = VT_I4;
propvar.lVal = 15;
hr = InitPropVariantFromStringVector(NULL, 0, &propvar);
ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
ok(propvar.vt == (VT_LPWSTR|VT_VECTOR), "Unexpected type %#x.\n", propvar.vt);
ok(!propvar.calpwstr.cElems, "Unexpected number of elements.\n");
ok(!!propvar.calpwstr.pElems, "Unexpected vector pointer.\n");
PropVariantClear(&propvar);
hr = InitPropVariantFromStringVector(strs, 2, &propvar);
ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
ok(propvar.vt == (VT_LPWSTR|VT_VECTOR), "Unexpected type %#x.\n", propvar.vt);
ok(propvar.calpwstr.cElems == 2, "Unexpected number of elements.\n");
ok(!!propvar.calpwstr.pElems, "Unexpected vector pointer.\n");
ok(propvar.calpwstr.pElems[0] != strs[0], "Unexpected string pointer.\n");
ok(!wcscmp(propvar.calpwstr.pElems[0], strs[0]), "Unexpected string %s.\n", debugstr_w(propvar.calpwstr.pElems[0]));
ok(propvar.calpwstr.pElems[1] != strs[1], "Unexpected string pointer.\n");
ok(!wcscmp(propvar.calpwstr.pElems[1], strs[1]), "Unexpected string %s.\n", debugstr_w(propvar.calpwstr.pElems[1]));
PropVariantClear(&propvar);
}
static void test_PropVariantToDouble(void)
{
PROPVARIANT propvar;
......@@ -2252,11 +2281,15 @@ static void test_VariantToStringWithDefault(void)
START_TEST(propsys)
{
test_InitPropVariantFromGUIDAsString();
test_InitPropVariantFromBuffer();
test_InitPropVariantFromCLSID();
test_InitPropVariantFromStringVector();
test_InitVariantFromFileTime();
test_PSStringFromPropertyKey();
test_PSPropertyKeyFromString();
test_PSRefreshPropertySchema();
test_InitPropVariantFromGUIDAsString();
test_InitPropVariantFromBuffer();
test_PropVariantToGUID();
test_PropVariantToStringAlloc();
test_PropVariantCompareEx();
......@@ -2264,7 +2297,6 @@ START_TEST(propsys)
test_PropVariantChangeType_LPWSTR();
test_PropVariantToBoolean();
test_PropVariantToStringWithDefault();
test_InitPropVariantFromCLSID();
test_PropVariantToDouble();
test_PropVariantToString();
test_PropVariantToBuffer();
......@@ -2273,6 +2305,5 @@ START_TEST(propsys)
test_PSCreateMemoryPropertyStore();
test_propertystore();
test_PSCreatePropertyStoreFromObject();
test_InitVariantFromFileTime();
test_VariantToStringWithDefault();
}
......@@ -81,6 +81,7 @@ HRESULT WINAPI VariantToGUID(const VARIANT *pvar, GUID *guid);
INT WINAPI PropVariantCompareEx(REFPROPVARIANT propvar1, REFPROPVARIANT propvar2,
PROPVAR_COMPARE_UNIT uint, PROPVAR_COMPARE_FLAGS flags);
HRESULT WINAPI InitPropVariantFromFileTime(const FILETIME *pftIn, PROPVARIANT *ppropvar);
HRESULT WINAPI InitPropVariantFromStringVector(PCWSTR *strs, ULONG count, PROPVARIANT *ppropvar);
HRESULT WINAPI PropVariantToDouble(REFPROPVARIANT propvarIn, double *ret);
HRESULT WINAPI PropVariantToInt16(REFPROPVARIANT propvarIn, SHORT *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