Commit 58ea6bdd authored by Fabian Maurer's avatar Fabian Maurer Committed by Alexandre Julliard

propsys: Added PropVariantToBoolean with some tests.

parent 02641e33
...@@ -107,7 +107,7 @@ ...@@ -107,7 +107,7 @@
@ stub PropVariantGetUInt32Elem @ stub PropVariantGetUInt32Elem
@ stub PropVariantGetUInt64Elem @ stub PropVariantGetUInt64Elem
@ stub PropVariantToBSTR @ stub PropVariantToBSTR
@ stub PropVariantToBoolean @ stdcall PropVariantToBoolean(ptr ptr)
@ stub PropVariantToBooleanVector @ stub PropVariantToBooleanVector
@ stub PropVariantToBooleanVectorAlloc @ stub PropVariantToBooleanVectorAlloc
@ stub PropVariantToBooleanWithDefault @ stub PropVariantToBooleanWithDefault
......
...@@ -227,6 +227,66 @@ HRESULT WINAPI PropVariantToUInt64(REFPROPVARIANT propvarIn, ULONGLONG *ret) ...@@ -227,6 +227,66 @@ HRESULT WINAPI PropVariantToUInt64(REFPROPVARIANT propvarIn, ULONGLONG *ret)
return hr; return hr;
} }
HRESULT WINAPI PropVariantToBoolean(REFPROPVARIANT propvarIn, BOOL *ret)
{
static const WCHAR trueW[] = {'t','r','u','e',0};
static const WCHAR falseW[] = {'f','a','l','s','e',0};
static const WCHAR true2W[] = {'#','T','R','U','E','#',0};
static const WCHAR false2W[] = {'#','F','A','L','S','E','#',0};
LONGLONG res;
HRESULT hr;
TRACE("%p,%p\n", propvarIn, ret);
*ret = FALSE;
switch (propvarIn->vt)
{
case VT_BOOL:
*ret = propvarIn->u.boolVal == VARIANT_TRUE;
return S_OK;
case VT_LPWSTR:
case VT_BSTR:
if (!propvarIn->u.pwszVal)
return DISP_E_TYPEMISMATCH;
if (!lstrcmpiW(propvarIn->u.pwszVal, trueW) || !lstrcmpW(propvarIn->u.pwszVal, true2W))
{
*ret = TRUE;
return S_OK;
}
if (!lstrcmpiW(propvarIn->u.pwszVal, falseW) || !lstrcmpW(propvarIn->u.pwszVal, false2W))
{
*ret = FALSE;
return S_OK;
}
break;
case VT_LPSTR:
if (!propvarIn->u.pszVal)
return DISP_E_TYPEMISMATCH;
if (!lstrcmpiA(propvarIn->u.pszVal, "true") || !lstrcmpA(propvarIn->u.pszVal, "#TRUE#"))
{
*ret = TRUE;
return S_OK;
}
if (!lstrcmpiA(propvarIn->u.pszVal, "false") || !lstrcmpA(propvarIn->u.pszVal, "#FALSE#"))
{
*ret = FALSE;
return S_OK;
}
break;
}
hr = PROPVAR_ConvertNumber(propvarIn, 64, FALSE, &res);
*ret = !!res;
return hr;
}
HRESULT WINAPI PropVariantToStringAlloc(REFPROPVARIANT propvarIn, WCHAR **ret) HRESULT WINAPI PropVariantToStringAlloc(REFPROPVARIANT propvarIn, WCHAR **ret)
{ {
WCHAR *res = NULL; WCHAR *res = NULL;
......
...@@ -883,6 +883,220 @@ static void test_intconversions(void) ...@@ -883,6 +883,220 @@ static void test_intconversions(void)
ok(llval == -7, "got wrong value %s\n", wine_dbgstr_longlong(llval)); ok(llval == -7, "got wrong value %s\n", wine_dbgstr_longlong(llval));
} }
static void test_PropVariantToBoolean(void)
{
static WCHAR str_0[] = {'0',0};
static WCHAR str_1[] = {'1',0};
static WCHAR str_7[] = {'7',0};
static WCHAR str_n7[] = {'-','7',0};
static WCHAR str_true[] = {'t','r','u','e',0};
static WCHAR str_true2[] = {'#','T','R','U','E','#',0};
static WCHAR str_true_case[] = {'t','R','U','e',0};
static WCHAR str_false[] = {'f','a','l','s','e',0};
static WCHAR str_false2[] = {'#','F','A','L','S','E','#',0};
static WCHAR str_true_space[] = {'t','r','u','e',' ',0};
static WCHAR str_yes[] = {'y','e','s',0};
PROPVARIANT propvar;
HRESULT hr;
BOOL val;
/* VT_BOOL */
propvar.vt = VT_BOOL;
propvar.u.boolVal = VARIANT_FALSE;
val = TRUE;
hr = PropVariantToBoolean(&propvar, &val);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
ok(val == FALSE, "Unexpected value %d\n", val);
propvar.vt = VT_BOOL;
propvar.u.boolVal = 1;
val = TRUE;
hr = PropVariantToBoolean(&propvar, &val);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
ok(val == FALSE, "Unexpected value %d\n", val);
propvar.vt = VT_BOOL;
propvar.u.boolVal = VARIANT_TRUE;
val = FALSE;
hr = PropVariantToBoolean(&propvar, &val);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
ok(val == TRUE, "Unexpected value %d\n", val);
/* VT_EMPTY */
propvar.vt = VT_EMPTY;
propvar.u.boolVal = VARIANT_TRUE;
val = TRUE;
hr = PropVariantToBoolean(&propvar, &val);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
ok(val == FALSE, "Unexpected value %d\n", val);
/* test integer conversion */
propvar.vt = VT_I4;
propvar.u.lVal = 0;
val = TRUE;
hr = PropVariantToBoolean(&propvar, &val);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
ok(val == FALSE, "Unexpected value %d\n", val);
propvar.vt = VT_I4;
propvar.u.lVal = 1;
val = FALSE;
hr = PropVariantToBoolean(&propvar, &val);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
ok(val == TRUE, "Unexpected value %d\n", val);
propvar.vt = VT_I4;
propvar.u.lVal = 67;
val = FALSE;
hr = PropVariantToBoolean(&propvar, &val);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
ok(val == TRUE, "Unexpected value %d\n", val);
propvar.vt = VT_I4;
propvar.u.lVal = -67;
val = FALSE;
hr = PropVariantToBoolean(&propvar, &val);
todo_wine
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
ok(val == TRUE, "Unexpected value %d\n", val);
/* test string conversion */
propvar.vt = VT_LPWSTR;
propvar.u.pwszVal = str_0;
val = TRUE;
hr = PropVariantToBoolean(&propvar, &val);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
ok(val == FALSE, "Unexpected value %d\n", val);
propvar.vt = VT_LPWSTR;
propvar.u.pwszVal = str_1;
val = FALSE;
hr = PropVariantToBoolean(&propvar, &val);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
ok(val == TRUE, "Unexpected value %d\n", val);
propvar.vt = VT_LPWSTR;
propvar.u.pwszVal = str_7;
val = FALSE;
hr = PropVariantToBoolean(&propvar, &val);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
ok(val == TRUE, "Unexpected value %d\n", val);
propvar.vt = VT_LPWSTR;
propvar.u.pwszVal = str_n7;
val = FALSE;
hr = PropVariantToBoolean(&propvar, &val);
todo_wine
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
ok(val == TRUE, "Unexpected value %d\n", val);
propvar.vt = VT_LPWSTR;
propvar.u.pwszVal = str_true;
val = FALSE;
hr = PropVariantToBoolean(&propvar, &val);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
ok(val == TRUE, "Unexpected value %d\n", val);
propvar.vt = VT_LPWSTR;
propvar.u.pwszVal = str_true_case;
val = FALSE;
hr = PropVariantToBoolean(&propvar, &val);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
ok(val == TRUE, "Unexpected value %d\n", val);
propvar.vt = VT_LPWSTR;
propvar.u.pwszVal = str_true2;
val = FALSE;
hr = PropVariantToBoolean(&propvar, &val);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
ok(val == TRUE, "Unexpected value %d\n", val);
propvar.vt = VT_LPWSTR;
propvar.u.pwszVal = str_false;
val = TRUE;
hr = PropVariantToBoolean(&propvar, &val);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
ok(val == FALSE, "Unexpected value %d\n", val);
propvar.vt = VT_LPWSTR;
propvar.u.pwszVal = str_false2;
val = TRUE;
hr = PropVariantToBoolean(&propvar, &val);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
ok(val == FALSE, "Unexpected value %d\n", val);
propvar.vt = VT_LPWSTR;
propvar.u.pwszVal = str_true_space;
val = TRUE;
hr = PropVariantToBoolean(&propvar, &val);
ok(hr == DISP_E_TYPEMISMATCH, "Unexpected hr %#x.\n", hr);
ok(val == FALSE, "Unexpected value %d\n", val);
propvar.vt = VT_LPWSTR;
propvar.u.pwszVal = str_yes;
val = TRUE;
hr = PropVariantToBoolean(&propvar, &val);
ok(hr == DISP_E_TYPEMISMATCH, "Unexpected hr %#x.\n", hr);
ok(val == FALSE, "Unexpected value %d\n", val);
propvar.vt = VT_LPWSTR;
propvar.u.pwszVal = NULL;
val = TRUE;
hr = PropVariantToBoolean(&propvar, &val);
ok(hr == DISP_E_TYPEMISMATCH, "Unexpected hr %#x.\n", hr);
ok(val == FALSE, "Unexpected value %d\n", val);
/* VT_LPSTR */
propvar.vt = VT_LPSTR;
propvar.u.pszVal = (char *)"#TruE#";
val = TRUE;
hr = PropVariantToBoolean(&propvar, &val);
ok(hr == DISP_E_TYPEMISMATCH, "Unexpected hr %#x.\n", hr);
ok(val == FALSE, "Unexpected value %d\n", val);
propvar.vt = VT_LPSTR;
propvar.u.pszVal = (char *)"#TRUE#";
val = FALSE;
hr = PropVariantToBoolean(&propvar, &val);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
ok(val == TRUE, "Unexpected value %d\n", val);
propvar.vt = VT_LPSTR;
propvar.u.pszVal = (char *)"tRUe";
val = FALSE;
hr = PropVariantToBoolean(&propvar, &val);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
ok(val == TRUE, "Unexpected value %d\n", val);
propvar.vt = VT_LPSTR;
propvar.u.pszVal = (char *)"#FALSE#";
val = TRUE;
hr = PropVariantToBoolean(&propvar, &val);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
ok(val == FALSE, "Unexpected value %d\n", val);
propvar.vt = VT_LPSTR;
propvar.u.pszVal = (char *)"fALSe";
val = TRUE;
hr = PropVariantToBoolean(&propvar, &val);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
ok(val == FALSE, "Unexpected value %d\n", val);
propvar.vt = VT_LPSTR;
propvar.u.pszVal = (char *)"1";
val = FALSE;
hr = PropVariantToBoolean(&propvar, &val);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
ok(val == TRUE, "Unexpected value %d\n", val);
propvar.vt = VT_LPSTR;
propvar.u.pszVal = (char *)"-1";
hr = PropVariantToBoolean(&propvar, &val);
todo_wine
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
ok(val == TRUE, "Unexpected value %d\n", val);
}
static void test_PropVariantChangeType_LPWSTR(void) static void test_PropVariantChangeType_LPWSTR(void)
{ {
PROPVARIANT dest, src; PROPVARIANT dest, src;
...@@ -931,4 +1145,5 @@ START_TEST(propsys) ...@@ -931,4 +1145,5 @@ START_TEST(propsys)
test_PropVariantCompare(); test_PropVariantCompare();
test_intconversions(); test_intconversions();
test_PropVariantChangeType_LPWSTR(); test_PropVariantChangeType_LPWSTR();
test_PropVariantToBoolean();
} }
...@@ -76,6 +76,7 @@ HRESULT WINAPI PropVariantToInt64(REFPROPVARIANT propvarIn, LONGLONG *ret); ...@@ -76,6 +76,7 @@ HRESULT WINAPI PropVariantToInt64(REFPROPVARIANT propvarIn, LONGLONG *ret);
HRESULT WINAPI PropVariantToUInt16(REFPROPVARIANT propvarIn, USHORT *ret); HRESULT WINAPI PropVariantToUInt16(REFPROPVARIANT propvarIn, USHORT *ret);
HRESULT WINAPI PropVariantToUInt32(REFPROPVARIANT propvarIn, ULONG *ret); HRESULT WINAPI PropVariantToUInt32(REFPROPVARIANT propvarIn, ULONG *ret);
HRESULT WINAPI PropVariantToUInt64(REFPROPVARIANT propvarIn, ULONGLONG *ret); HRESULT WINAPI PropVariantToUInt64(REFPROPVARIANT propvarIn, ULONGLONG *ret);
HRESULT WINAPI PropVariantToBoolean(REFPROPVARIANT propvarIn, BOOL *ret);
HRESULT WINAPI PropVariantToStringAlloc(REFPROPVARIANT propvarIn, WCHAR **ret); 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