From d04d1f52309a4fa185cd303c2220ec61bd63f592 Mon Sep 17 00:00:00 2001 From: Alistair Leslie-Hughes Date: Tue, 25 Jun 2013 14:48:04 +1000 Subject: [PATCH] oledb32: Implement DataConvert Variant->R8. --- dlls/oledb32/convert.c | 5 ++++ dlls/oledb32/tests/convert.c | 54 ++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/dlls/oledb32/convert.c b/dlls/oledb32/convert.c index e68078b5241..88750578033 100644 --- a/dlls/oledb32/convert.c +++ b/dlls/oledb32/convert.c @@ -361,6 +361,11 @@ static HRESULT WINAPI convert_DataConvert(IDataConvert* iface, case DBTYPE_BSTR: hr = VarR8FromStr(*(WCHAR**)src, LOCALE_USER_DEFAULT, 0, d); break; case DBTYPE_BOOL: hr = VarR8FromBool(*(VARIANT_BOOL*)src, d); break; case DBTYPE_DECIMAL: hr = VarR8FromDec((DECIMAL*)src, d); break; + case DBTYPE_VARIANT: + VariantInit(&tmp); + if ((hr = VariantChangeType(&tmp, (VARIANT*)src, 0, VT_R8)) == S_OK) + *d = V_R8(&tmp); + break; default: FIXME("Unimplemented conversion %04x -> R8\n", src_type); return E_NOTIMPL; } break; diff --git a/dlls/oledb32/tests/convert.c b/dlls/oledb32/tests/convert.c index 5c6694fd3f3..61607a939fe 100644 --- a/dlls/oledb32/tests/convert.c +++ b/dlls/oledb32/tests/convert.c @@ -2276,6 +2276,59 @@ static void test_converttor4(void) ok(dst == 10.0, "got %f\n", dst); } +static void test_converttor8(void) +{ + HRESULT hr; + DOUBLE dst; + BYTE src[20]; + DBSTATUS dst_status; + DBLENGTH dst_len; + VARIANT var; + + dst = 1.0; + dst_len = 0x1234; + hr = IDataConvert_DataConvert(convert, DBTYPE_EMPTY, DBTYPE_R8, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0); + ok(hr == S_OK, "got %08x\n", hr); + ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status); + ok(dst_len == sizeof(dst), "got %ld\n", dst_len); + ok(dst == 0.0, "got %f\n", dst); + + dst = 1.0; + dst_len = 0x1234; + hr = IDataConvert_DataConvert(convert, DBTYPE_NULL, DBTYPE_R8, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0); + ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr); + ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status); + ok(dst_len == 0x1234, "got %ld\n", dst_len); + ok(dst == 1.0, "got %f\n", dst); + + dst = 1.0; + *(signed int*)src = 12345678; + dst_len = 0x1234; + hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_R8, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0); + ok(hr == S_OK, "got %08x\n", hr); + ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status); + ok(dst_len == sizeof(dst), "got %ld\n", dst_len); + ok(dst == 12345678.0, "got %f\n", dst); + + dst = 1.0; + *(FLOAT *)src = 10.0; + dst_len = 0x1234; + hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_R8, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0); + ok(hr == S_OK, "got %08x\n", hr); + ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status); + ok(dst_len == sizeof(dst), "got %ld\n", dst_len); + ok(dst == 10.0, "got %f\n", dst); + + dst_len = dst = 0x1234; + V_VT(&var) = VT_I2; + V_I2(&var) = 0x4321; + hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_R8, 0, &dst_len, &var, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0); + ok(hr == S_OK, "got %08x\n", hr); + ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status); + ok(dst_len == sizeof(dst), "got %ld\n", dst_len); + ok(dst == 0x4321, "got %f\n", dst); +} + static void test_converttocy(void) { HRESULT hr; @@ -2862,6 +2915,7 @@ START_TEST(convert) test_converttoui1(); test_converttoui4(); test_converttor4(); + test_converttor8(); test_converttofiletime(); test_converttocy(); test_converttoui8();