Commit d68c13a8 authored by Dmitry Timoshkov's avatar Dmitry Timoshkov Committed by Alexandre Julliard

ole32/tests: Add some tests for PropVariantCopy.

parent 5e7251b9
...@@ -3062,21 +3062,28 @@ HRESULT WINAPI PropVariantCopy(PROPVARIANT *pvarDest, /* [out] */ ...@@ -3062,21 +3062,28 @@ HRESULT WINAPI PropVariantCopy(PROPVARIANT *pvarDest, /* [out] */
case VT_STREAMED_OBJECT: case VT_STREAMED_OBJECT:
case VT_STORAGE: case VT_STORAGE:
case VT_STORED_OBJECT: case VT_STORED_OBJECT:
IUnknown_AddRef((LPUNKNOWN)pvarDest->u.pStream); if (pvarDest->u.pStream)
IStream_AddRef(pvarDest->u.pStream);
break; break;
case VT_CLSID: case VT_CLSID:
pvarDest->u.puuid = CoTaskMemAlloc(sizeof(CLSID)); pvarDest->u.puuid = CoTaskMemAlloc(sizeof(CLSID));
*pvarDest->u.puuid = *pvarSrc->u.puuid; *pvarDest->u.puuid = *pvarSrc->u.puuid;
break; break;
case VT_LPSTR: case VT_LPSTR:
if (pvarSrc->u.pszVal)
{
len = strlen(pvarSrc->u.pszVal); len = strlen(pvarSrc->u.pszVal);
pvarDest->u.pszVal = CoTaskMemAlloc((len+1)*sizeof(CHAR)); pvarDest->u.pszVal = CoTaskMemAlloc((len+1)*sizeof(CHAR));
CopyMemory(pvarDest->u.pszVal, pvarSrc->u.pszVal, (len+1)*sizeof(CHAR)); CopyMemory(pvarDest->u.pszVal, pvarSrc->u.pszVal, (len+1)*sizeof(CHAR));
}
break; break;
case VT_LPWSTR: case VT_LPWSTR:
if (pvarSrc->u.pwszVal)
{
len = lstrlenW(pvarSrc->u.pwszVal); len = lstrlenW(pvarSrc->u.pwszVal);
pvarDest->u.pwszVal = CoTaskMemAlloc((len+1)*sizeof(WCHAR)); pvarDest->u.pwszVal = CoTaskMemAlloc((len+1)*sizeof(WCHAR));
CopyMemory(pvarDest->u.pwszVal, pvarSrc->u.pwszVal, (len+1)*sizeof(WCHAR)); CopyMemory(pvarDest->u.pwszVal, pvarSrc->u.pwszVal, (len+1)*sizeof(WCHAR));
}
break; break;
case VT_BLOB: case VT_BLOB:
case VT_BLOB_OBJECT: case VT_BLOB_OBJECT:
......
...@@ -130,7 +130,7 @@ static const char* wine_vtypes[VT_CLSID+1] = ...@@ -130,7 +130,7 @@ static const char* wine_vtypes[VT_CLSID+1] =
}; };
static void expect(HRESULT hr, VARTYPE vt) static void expect(HRESULT hr, VARTYPE vt, BOOL copy)
{ {
int idx = vt & VT_TYPEMASK; int idx = vt & VT_TYPEMASK;
BYTE flags; BYTE flags;
...@@ -158,7 +158,7 @@ static void expect(HRESULT hr, VARTYPE vt) ...@@ -158,7 +158,7 @@ static void expect(HRESULT hr, VARTYPE vt)
} }
if(flags == PROP_INV) if(flags == PROP_INV)
ok(hr == STG_E_INVALIDPARAMETER, "%s (%s): got %08x\n", wine_vtypes[idx], modifier, hr); ok(hr == copy ? DISP_E_BADVARTYPE : STG_E_INVALIDPARAMETER, "%s (%s): got %08x\n", wine_vtypes[idx], modifier, hr);
else if(flags == PROP_V0) else if(flags == PROP_V0)
ok(hr == S_OK, "%s (%s): got %08x\n", wine_vtypes[idx], modifier, hr); ok(hr == S_OK, "%s (%s): got %08x\n", wine_vtypes[idx], modifier, hr);
else if(flags & PROP_TODO) else if(flags & PROP_TODO)
...@@ -180,9 +180,11 @@ static void expect(HRESULT hr, VARTYPE vt) ...@@ -180,9 +180,11 @@ static void expect(HRESULT hr, VARTYPE vt)
static void test_validtypes(void) static void test_validtypes(void)
{ {
PROPVARIANT propvar; PROPVARIANT propvar, copy, uninit;
HRESULT hr; HRESULT hr;
unsigned int i; unsigned int i, ret;
memset(&uninit, 0x77, sizeof(uninit));
memset(&propvar, 0x55, sizeof(propvar)); memset(&propvar, 0x55, sizeof(propvar));
hr = PropVariantClear(&propvar); hr = PropVariantClear(&propvar);
...@@ -206,8 +208,23 @@ static void test_validtypes(void) ...@@ -206,8 +208,23 @@ static void test_validtypes(void)
else else
U(propvar).pszVal = NULL; U(propvar).pszVal = NULL;
vt = propvar.vt = i; vt = propvar.vt = i;
memset(&copy, 0x77, sizeof(copy));
hr = PropVariantCopy(&copy, &propvar);
expect(hr, vt, TRUE);
if (hr == S_OK)
{
ok(copy.vt == propvar.vt, "expected %d, got %d\n", propvar.vt, copy.vt);
ok(U(copy).uhVal.QuadPart == U(propvar).uhVal.QuadPart, "%u: expected %#x/%#x, got %#x/%#x\n",
i, U(propvar).uhVal.u.LowPart, U(propvar).uhVal.u.HighPart,
U(copy).uhVal.u.LowPart, U(copy).uhVal.u.HighPart);
}
else
{
ret = memcmp(&copy, &uninit, sizeof(copy));
ok(!ret || broken(ret) /* win2000 */, "%d: copy should stay unchanged\n", i);
}
hr = PropVariantClear(&propvar); hr = PropVariantClear(&propvar);
expect(hr, vt); expect(hr, vt, FALSE);
ok(propvar.vt == 0, "expected 0, got %d\n", propvar.vt); ok(propvar.vt == 0, "expected 0, got %d\n", propvar.vt);
ok(U(propvar).uhVal.QuadPart == 0, "%u: expected 0, got %#x/%#x\n", ok(U(propvar).uhVal.QuadPart == 0, "%u: expected 0, got %#x/%#x\n",
i, U(propvar).uhVal.u.LowPart, U(propvar).uhVal.u.HighPart); i, U(propvar).uhVal.u.LowPart, U(propvar).uhVal.u.HighPart);
...@@ -215,8 +232,22 @@ static void test_validtypes(void) ...@@ -215,8 +232,22 @@ static void test_validtypes(void)
memset(&propvar, 0x55, sizeof(propvar)); memset(&propvar, 0x55, sizeof(propvar));
U(propvar).pszVal = NULL; U(propvar).pszVal = NULL;
vt = propvar.vt = i | VT_ARRAY; vt = propvar.vt = i | VT_ARRAY;
memset(&copy, 0x77, sizeof(copy));
hr = PropVariantCopy(&copy, &propvar);
expect(hr, vt, TRUE);
if (hr == S_OK)
{
ok(copy.vt == propvar.vt, "expected %d, got %d\n", propvar.vt, copy.vt);
ok(U(copy).uhVal.QuadPart == 0, "%u: expected 0, got %#x/%#x\n",
i, U(copy).uhVal.u.LowPart, U(copy).uhVal.u.HighPart);
}
else
{
ret = memcmp(&copy, &uninit, sizeof(copy));
ok(!ret || broken(ret) /* win2000 */, "%d: copy should stay unchanged\n", i);
}
hr = PropVariantClear(&propvar); hr = PropVariantClear(&propvar);
expect(hr, vt); expect(hr, vt, FALSE);
ok(propvar.vt == 0, "expected 0, got %d\n", propvar.vt); ok(propvar.vt == 0, "expected 0, got %d\n", propvar.vt);
ok(U(propvar).uhVal.QuadPart == 0, "%u: expected 0, got %#x/%#x\n", ok(U(propvar).uhVal.QuadPart == 0, "%u: expected 0, got %#x/%#x\n",
i, U(propvar).uhVal.u.LowPart, U(propvar).uhVal.u.HighPart); i, U(propvar).uhVal.u.LowPart, U(propvar).uhVal.u.HighPart);
...@@ -225,8 +256,23 @@ static void test_validtypes(void) ...@@ -225,8 +256,23 @@ static void test_validtypes(void)
U(propvar).caub.cElems = 0; U(propvar).caub.cElems = 0;
U(propvar).caub.pElems = NULL; U(propvar).caub.pElems = NULL;
vt = propvar.vt = i | VT_VECTOR; vt = propvar.vt = i | VT_VECTOR;
memset(&copy, 0x77, sizeof(copy));
hr = PropVariantCopy(&copy, &propvar);
expect(hr, vt, TRUE);
if (hr == S_OK)
{
ok(copy.vt == propvar.vt, "expected %d, got %d\n", propvar.vt, copy.vt);
ok(!U(copy).caub.cElems, "%u: expected 0, got %d\n", i, U(copy).caub.cElems);
todo_wine
ok(!U(copy).caub.pElems, "%u: expected NULL, got %p\n", i, U(copy).caub.pElems);
}
else
{
ret = memcmp(&copy, &uninit, sizeof(copy));
ok(!ret || broken(ret) /* win2000 */, "%d: copy should stay unchanged\n", i);
}
hr = PropVariantClear(&propvar); hr = PropVariantClear(&propvar);
expect(hr, vt); expect(hr, vt, FALSE);
ok(propvar.vt == 0, "expected 0, got %d\n", propvar.vt); ok(propvar.vt == 0, "expected 0, got %d\n", propvar.vt);
ok(U(propvar).uhVal.QuadPart == 0, "%u: expected 0, got %#x/%#x\n", ok(U(propvar).uhVal.QuadPart == 0, "%u: expected 0, got %#x/%#x\n",
i, U(propvar).uhVal.u.LowPart, U(propvar).uhVal.u.HighPart); i, U(propvar).uhVal.u.LowPart, U(propvar).uhVal.u.HighPart);
...@@ -234,8 +280,23 @@ static void test_validtypes(void) ...@@ -234,8 +280,23 @@ static void test_validtypes(void)
memset(&propvar, 0x55, sizeof(propvar)); memset(&propvar, 0x55, sizeof(propvar));
U(propvar).pszVal = NULL; U(propvar).pszVal = NULL;
vt = propvar.vt = i | VT_BYREF; vt = propvar.vt = i | VT_BYREF;
memset(&copy, 0x77, sizeof(copy));
hr = PropVariantCopy(&copy, &propvar);
expect(hr, vt, TRUE);
if (hr == S_OK)
{
ok(copy.vt == propvar.vt, "expected %d, got %d\n", propvar.vt, copy.vt);
ok(U(copy).uhVal.QuadPart == U(propvar).uhVal.QuadPart, "%u: expected %#x/%#x, got %#x/%#x\n",
i, U(propvar).uhVal.u.LowPart, U(propvar).uhVal.u.HighPart,
U(copy).uhVal.u.LowPart, U(copy).uhVal.u.HighPart);
}
else
{
ret = memcmp(&copy, &uninit, sizeof(copy));
ok(!ret || broken(ret) /* win2000 */, "%d: copy should stay unchanged\n", i);
}
hr = PropVariantClear(&propvar); hr = PropVariantClear(&propvar);
expect(hr, vt); expect(hr, vt, FALSE);
ok(propvar.vt == 0, "expected 0, got %d\n", propvar.vt); ok(propvar.vt == 0, "expected 0, got %d\n", propvar.vt);
ok(U(propvar).uhVal.QuadPart == 0, "%u: expected 0, got %#x/%#x\n", ok(U(propvar).uhVal.QuadPart == 0, "%u: expected 0, got %#x/%#x\n",
i, U(propvar).uhVal.u.LowPart, U(propvar).uhVal.u.HighPart); i, U(propvar).uhVal.u.LowPart, U(propvar).uhVal.u.HighPart);
......
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