scrrun: Added support for VT_DATE keys, and BYREF float key types.

This commit is contained in:
Nikolay Sivov 2015-03-23 08:18:30 +03:00 committed by Alexandre Julliard
parent 5189dc417a
commit 94a1838b7e
2 changed files with 83 additions and 15 deletions

View File

@ -761,6 +761,22 @@ static DWORD get_num_hash(FLOAT num)
return (*((DWORD*)&num)) % DICT_HASH_MOD;
}
static HRESULT get_flt_hash(FLOAT flt, LONG *hash)
{
if (isinf(flt)) {
*hash = 0;
return S_OK;
}
else if (!isnan(flt)) {
*hash = get_num_hash(flt);
return S_OK;
}
/* NaN case */
*hash = ~0u;
return CTL_E_ILLEGALFUNCTIONCALL;
}
static DWORD get_ptr_hash(void *ptr)
{
return PtrToUlong(ptr) % DICT_HASH_MOD;
@ -810,23 +826,15 @@ static HRESULT WINAPI dictionary_get_HashVal(IDictionary *iface, VARIANT *key, V
IUnknown_Release(unk);
break;
}
case VT_DATE|VT_BYREF:
case VT_DATE:
return get_flt_hash(V_VT(key) & VT_BYREF ? *V_DATEREF(key) : V_DATE(key), &V_I4(hash));
case VT_R4|VT_BYREF:
case VT_R4:
return get_flt_hash(V_VT(key) & VT_BYREF ? *V_R4REF(key) : V_R4(key), &V_I4(hash));
case VT_R8|VT_BYREF:
case VT_R8:
{
FLOAT flt = V_VT(key) == VT_R4 ? V_R4(key) : V_R8(key);
if (isinf(flt))
{
V_I4(hash) = 0;
break;
}
else if (!isnan(flt))
{
V_I4(hash) = get_num_hash(flt);
break;
}
/* fallthrough on NAN */
}
return get_flt_hash(V_VT(key) & VT_BYREF ? *V_R8REF(key) : V_R8(key), &V_I4(hash));
case VT_INT:
case VT_UINT:
case VT_I1:

View File

@ -499,6 +499,15 @@ static void test_hash_value(void)
ok(V_I4(&hash) == ~0u || broken(V_I4(&hash) == 0 /* win2k */ ||
V_I4(&hash) == 0x1f4 /* vista, win2k8 */), "got hash 0x%08x\n", V_I4(&hash));
V_VT(&key) = VT_DATE;
V_DATE(&key) = fx8.d;
VariantInit(&hash);
hr = IDictionary_get_HashVal(dict, &key, &hash);
ok(hr == CTL_E_ILLEGALFUNCTIONCALL || broken(hr == S_OK) /* win2k, win2k3 */, "got 0x%08x\n", hr);
ok(V_VT(&hash) == VT_I4, "got %d\n", V_VT(&hash));
ok(V_I4(&hash) == ~0u || broken(V_I4(&hash) == 0 /* win2k */ ||
V_I4(&hash) == 0x1f4 /* vista, win2k8 */), "got hash 0x%08x\n", V_I4(&hash));
/* inf */
fx8.d = 10.0;
fx8.i.m_lo = 0;
@ -513,7 +522,19 @@ static void test_hash_value(void)
ok(V_VT(&hash) == VT_I4, "got %d\n", V_VT(&hash));
ok(V_I4(&hash) == 0, "got hash 0x%08x\n", V_I4(&hash));
V_VT(&key) = VT_DATE;
V_DATE(&key) = fx8.d;
V_I4(&hash) = 10;
hr = IDictionary_get_HashVal(dict, &key, &hash);
ok(hr == S_OK, "got 0x%08x\n", hr);
ok(V_VT(&hash) == VT_I4, "got %d\n", V_VT(&hash));
ok(V_I4(&hash) == 0, "got hash 0x%08x\n", V_I4(&hash));
for (i = 0; i < sizeof(float_hash_tests)/sizeof(float_hash_tests[0]); i++) {
double dbl;
FLOAT flt;
DATE date;
expected = get_num_hash(float_hash_tests[i]);
V_VT(&key) = VT_R4;
@ -525,6 +546,16 @@ static void test_hash_value(void)
ok(V_I4(&hash) == expected, "%d: got hash 0x%08x, expected 0x%08x\n", i, V_I4(&hash),
expected);
flt = float_hash_tests[i];
V_VT(&key) = VT_R4|VT_BYREF;
V_R4REF(&key) = &flt;
VariantInit(&hash);
hr = IDictionary_get_HashVal(dict, &key, &hash);
ok(hr == S_OK, "got 0x%08x\n", hr);
ok(V_VT(&hash) == VT_I4, "got %d\n", V_VT(&hash));
ok(V_I4(&hash) == expected, "%d: got hash 0x%08x, expected 0x%08x\n", i, V_I4(&hash),
expected);
V_VT(&key) = VT_R8;
V_R8(&key) = float_hash_tests[i];
VariantInit(&hash);
@ -533,6 +564,35 @@ static void test_hash_value(void)
ok(V_VT(&hash) == VT_I4, "got %d\n", V_VT(&hash));
ok(V_I4(&hash) == expected, "%d: got hash 0x%08x, expected 0x%08x\n", i, V_I4(&hash),
expected);
dbl = float_hash_tests[i];
V_VT(&key) = VT_R8|VT_BYREF;
V_R8REF(&key) = &dbl;
VariantInit(&hash);
hr = IDictionary_get_HashVal(dict, &key, &hash);
ok(hr == S_OK, "got 0x%08x\n", hr);
ok(V_VT(&hash) == VT_I4, "got %d\n", V_VT(&hash));
ok(V_I4(&hash) == expected, "%d: got hash 0x%08x, expected 0x%08x\n", i, V_I4(&hash),
expected);
V_VT(&key) = VT_DATE;
V_DATE(&key) = float_hash_tests[i];
VariantInit(&hash);
hr = IDictionary_get_HashVal(dict, &key, &hash);
ok(hr == S_OK, "got 0x%08x\n", hr);
ok(V_VT(&hash) == VT_I4, "got %d\n", V_VT(&hash));
ok(V_I4(&hash) == expected, "%d: got hash 0x%08x, expected 0x%08x\n", i, V_I4(&hash),
expected);
V_VT(&key) = VT_DATE|VT_BYREF;
date = float_hash_tests[i];
V_DATEREF(&key) = &date;
VariantInit(&hash);
hr = IDictionary_get_HashVal(dict, &key, &hash);
ok(hr == S_OK, "got 0x%08x\n", hr);
ok(V_VT(&hash) == VT_I4, "got %d\n", V_VT(&hash));
ok(V_I4(&hash) == expected, "%d: got hash 0x%08x, expected 0x%08x\n", i, V_I4(&hash),
expected);
}
/* interface pointers as keys */