Commit 32b6ef32 authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

oledb32: Add support for DBTYPE_VARIANT -> DBTYPE_DATE conversion.

parent 788f588f
......@@ -475,6 +475,14 @@ static HRESULT WINAPI convert_DataConvert(IDataConvert* iface,
hr = (SystemTimeToVariantTime(&st, d) ? S_OK : E_FAIL);
break;
}
case DBTYPE_VARIANT:
{
VARIANT tmp;
VariantInit(&tmp);
if ((hr = VariantChangeType(&tmp, src, 0, VT_DATE)) == S_OK)
*d = V_DATE(&tmp);
break;
}
default: FIXME("Unimplemented conversion %04x -> DATE\n", src_type); return E_NOTIMPL;
}
break;
......
......@@ -4122,6 +4122,97 @@ static void test_converttonumeric(void)
SysFreeString(bstr);
}
static void test_converttodate(void)
{
static const WCHAR strW[] = {'2','0','1','3','-','0','5','-','1','4',0};
DBLENGTH dst_len;
HRESULT hr;
DATE dst, date = 41408.086250;
DBSTATUS dst_status;
VARIANT var;
BSTR bstr;
dst = 0.0;
dst_len = 0;
hr = IDataConvert_DataConvert(convert, DBTYPE_DATE, DBTYPE_DATE, sizeof(date), &dst_len, &date, &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 == 41408.086250, "got %f\n", dst);
VariantInit(&var);
V_VT(&var) = VT_DATE;
V_DATE(&var) = 41408.086250;
dst = 0.0;
dst_len = 0;
hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_DATE, sizeof(var), &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 == 41408.086250, "got %f\n", dst);
VariantInit(&var);
V_VT(&var) = VT_R8;
V_R8(&var) = 41408.086250;
dst = 0.0;
dst_len = 0;
hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_DATE, sizeof(var), &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 == 41408.086250, "got %f\n", dst);
VariantInit(&var);
V_VT(&var) = VT_I4;
V_I4(&var) = 41408;
dst = 0.0;
dst_len = 0;
hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_DATE, sizeof(var), &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 == 41408.000000, "got %f\n", dst);
V_VT(&var) = VT_BSTR;
V_BSTR(&var) = SysAllocString(strW);
dst = 0.0;
dst_len = 0;
hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_DATE, sizeof(var), &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 == 41408.000000, "got %f\n", dst);
VariantClear(&var);
dst = 0.0;
dst_len = 0;
bstr = SysAllocString(strW);
hr = IDataConvert_DataConvert(convert, DBTYPE_BSTR, DBTYPE_DATE, 0, &dst_len, &bstr, &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 == 41408.000000, "got %f\n", dst);
SysFreeString(bstr);
V_VT(&var) = VT_EMPTY;
dst = 1.0;
dst_len = 0;
hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_DATE, sizeof(var), &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 == 0.0, "got %f\n", dst);
V_VT(&var) = VT_NULL;
dst = 1.0;
dst_len = 0xdeadbeef;
hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_DATE, sizeof(var), &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_ISNULL, "got %08x\n", dst_status);
ok(dst_len == 0xdeadbeef, "got %ld\n", dst_len);
ok(dst == 1.0, "got %f\n", dst);
}
START_TEST(convert)
{
HRESULT hr;
......@@ -4164,6 +4255,7 @@ START_TEST(convert)
test_converttotimestamp();
test_converttoiunknown();
test_converttonumeric();
test_converttodate();
IDataConvert_Release(convert);
......
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