oledb32: Add conversions to DBTYPE_I2.

This commit is contained in:
Huw Davies 2009-09-23 13:42:53 +01:00 committed by Alexandre Julliard
parent 0443f2c7d1
commit 12037aa441
2 changed files with 297 additions and 0 deletions

View File

@ -198,6 +198,32 @@ static HRESULT WINAPI convert_DataConvert(IDataConvert* iface,
switch(dst_type)
{
case DBTYPE_I2:
{
signed short *d = dst;
switch(src_type)
{
case DBTYPE_EMPTY: *d = 0; hr = S_OK; break;
case DBTYPE_I2: *d = *(signed short*)src; hr = S_OK; break;
case DBTYPE_I4: hr = VarI2FromI4(*(signed int*)src, d); break;
case DBTYPE_R4: hr = VarI2FromR4(*(FLOAT*)src, d); break;
case DBTYPE_R8: hr = VarI2FromR8(*(double*)src, d); break;
case DBTYPE_CY: hr = VarI2FromCy(*(CY*)src, d); break;
case DBTYPE_DATE: hr = VarI2FromDate(*(DATE*)src, d); break;
case DBTYPE_BSTR: hr = VarI2FromStr(*(WCHAR**)src, LOCALE_USER_DEFAULT, 0, d); break;
case DBTYPE_BOOL: hr = VarI2FromBool(*(VARIANT_BOOL*)src, d); break;
case DBTYPE_DECIMAL: hr = VarI2FromDec((DECIMAL*)src, d); break;
case DBTYPE_I1: hr = VarI2FromI1(*(signed char*)src, d); break;
case DBTYPE_UI1: hr = VarI2FromUI1(*(BYTE*)src, d); break;
case DBTYPE_UI2: hr = VarI2FromUI2(*(WORD*)src, d); break;
case DBTYPE_UI4: hr = VarI2FromUI4(*(DWORD*)src, d); break;
case DBTYPE_I8: hr = VarI2FromI8(*(LONGLONG*)src, d); break;
case DBTYPE_UI8: hr = VarI2FromUI8(*(ULONGLONG*)src, d); break;
default: FIXME("Unimplemented conversion %04x -> I2\n", src_type); return E_NOTIMPL;
}
break;
}
case DBTYPE_I4:
{
signed int *d = dst;

View File

@ -338,6 +338,276 @@ static void test_canconvert(void)
IDataConvert_Release(convert);
}
static void test_converttoi2(void)
{
IDataConvert *convert;
HRESULT hr;
signed short dst;
BYTE src[20];
DBSTATUS dst_status;
DBLENGTH dst_len;
static const WCHAR ten[] = {'1','0',0};
BSTR b;
hr = CoCreateInstance(&CLSID_OLEDB_CONVERSIONLIBRARY, NULL, CLSCTX_INPROC_SERVER, &IID_IDataConvert, (void**)&convert);
if(FAILED(hr))
{
win_skip("Unable to load oledb conversion library\n");
return;
}
dst = 0x1234;
hr = IDataConvert_DataConvert(convert, DBTYPE_EMPTY, DBTYPE_I2, 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 %d\n", dst_len);
ok(dst == 0, "got %08x\n", dst);
dst = 0x1234;
hr = IDataConvert_DataConvert(convert, DBTYPE_NULL, DBTYPE_I2, 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 == sizeof(dst), "got %d\n", dst_len);
ok(dst == 0x1234, "got %08x\n", dst);
dst = 0x1234;
*(short *)src = 0x4321;
hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_I2, 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 %d\n", dst_len);
ok(dst == 0x4321, "got %08x\n", dst);
dst = 0x1234;
*(int *)src = 0x4321cafe;
hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
todo_wine
ok(hr == DB_E_DATAOVERFLOW, "got %08x\n", hr);
ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
ok(dst_len == sizeof(dst), "got %d\n", dst_len);
ok(dst == 0x1234, "got %08x\n", dst);
dst = 0x1234;
*(int *)src = 0x4321;
hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_I2, 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 %d\n", dst_len);
ok(dst == 0x4321, "got %08x\n", dst);
dst = 0x1234;
*(FLOAT *)src = 10.75;
hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_I2, 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 %d\n", dst_len);
ok(dst == 11, "got %08x\n", dst);
dst = 0x1234;
*(FLOAT *)src = -10.75;
hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_I2, 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 %d\n", dst_len);
ok(dst == -11, "got %08x\n", dst);
dst = 0x1234;
*(double *)src = 10.75;
hr = IDataConvert_DataConvert(convert, DBTYPE_R8, DBTYPE_I2, 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 %d\n", dst_len);
ok(dst == 11, "got %08x\n", dst);
dst = 0x1234;
((LARGE_INTEGER *)src)->QuadPart = 107500;
hr = IDataConvert_DataConvert(convert, DBTYPE_CY, DBTYPE_I2, 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 %d\n", dst_len);
ok(dst == 11, "got %08x\n", dst);
dst = 0x1234;
*(DATE *)src = 10.7500;
hr = IDataConvert_DataConvert(convert, DBTYPE_DATE, DBTYPE_I2, 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 %d\n", dst_len);
ok(dst == 11, "got %08x\n", dst);
dst = 0x1234;
b = SysAllocString(ten);
*(BSTR *)src = b;
hr = IDataConvert_DataConvert(convert, DBTYPE_BSTR, DBTYPE_I2, 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 %d\n", dst_len);
ok(dst == 10, "got %08x\n", dst);
SysFreeString(b);
dst = 0x1234;
*(SCODE *)src = 0x4321cafe;
hr = IDataConvert_DataConvert(convert, DBTYPE_ERROR, DBTYPE_I2, 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 == sizeof(dst), "got %d\n", dst_len);
ok(dst == 0x1234, "got %08x\n", dst);
dst = 0x1234;
*(VARIANT_BOOL *)src = VARIANT_TRUE;
hr = IDataConvert_DataConvert(convert, DBTYPE_BOOL, DBTYPE_I2, 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 %d\n", dst_len);
ok(dst == -1, "got %08x\n", dst);
dst = 0x1234;
*(VARIANT_BOOL *)src = VARIANT_FALSE;
hr = IDataConvert_DataConvert(convert, DBTYPE_BOOL, DBTYPE_I2, 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 %d\n", dst_len);
ok(dst == 0, "got %08x\n", dst);
dst = 0x1234;
V_VT((VARIANT*)src) = VT_I2;
V_I2((VARIANT*)src) = 0x4321;
hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
todo_wine
{
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 %d\n", dst_len);
todo_wine
ok(dst == 0x4321, "got %08x\n", dst);
dst = 0x1234;
memset(src, 0, sizeof(DECIMAL));
((DECIMAL*)src)->u1.Lo64 = 0x4321;
hr = IDataConvert_DataConvert(convert, DBTYPE_DECIMAL, DBTYPE_I2, 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 %d\n", dst_len);
ok(dst == 0x4321, "got %08x\n", dst);
dst = 0x1234;
*(signed char*)src = 0xab;
hr = IDataConvert_DataConvert(convert, DBTYPE_I1, DBTYPE_I2, 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 %d\n", dst_len);
ok(dst == (signed short)0xffab, "got %08x\n", dst);
dst = 0x1234;
*(BYTE*)src = 0xab;
hr = IDataConvert_DataConvert(convert, DBTYPE_UI1, DBTYPE_I2, 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 %d\n", dst_len);
ok(dst == 0xab, "got %08x\n", dst);
dst = 0x1234;
*(WORD*)src = 0x4321;
hr = IDataConvert_DataConvert(convert, DBTYPE_UI2, DBTYPE_I2, 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 %d\n", dst_len);
ok(dst == 0x4321, "got %08x\n", dst);
dst = 0x1234;
*(WORD*)src = 0xabcd;
hr = IDataConvert_DataConvert(convert, DBTYPE_UI2, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
ok(hr == DB_E_ERRORSOCCURRED, "got %08x\n", hr);
ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
ok(dst_len == sizeof(dst), "got %d\n", dst_len);
ok(dst == 0x1234, "got %08x\n", dst);
dst = 0x1234;
*(DWORD*)src = 0xabcd1234;
hr = IDataConvert_DataConvert(convert, DBTYPE_UI4, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
todo_wine
ok(hr == DB_E_DATAOVERFLOW, "got %08x\n", hr);
ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
ok(dst_len == sizeof(dst), "got %d\n", dst_len);
ok(dst == 0x1234, "got %08x\n", dst);
dst = 0x1234;
*(DWORD*)src = 0x1234abcd;
hr = IDataConvert_DataConvert(convert, DBTYPE_UI4, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
todo_wine
ok(hr == DB_E_DATAOVERFLOW, "got %08x\n", hr);
ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
ok(dst_len == sizeof(dst), "got %d\n", dst_len);
ok(dst == 0x1234, "got %08x\n", dst);
dst = 0x1234;
*(DWORD*)src = 0x4321;
hr = IDataConvert_DataConvert(convert, DBTYPE_UI4, DBTYPE_I2, 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 %d\n", dst_len);
ok(dst == 0x4321, "got %08x\n", dst);
dst = 0x1234;
((LARGE_INTEGER*)src)->QuadPart = 0x1234abcd;
hr = IDataConvert_DataConvert(convert, DBTYPE_I8, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
ok(hr == DB_E_ERRORSOCCURRED, "got %08x\n", hr);
ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
ok(dst_len == sizeof(dst), "got %d\n", dst_len);
ok(dst == 0x1234, "got %08x\n", dst);
dst = 0x1234;
((LARGE_INTEGER*)src)->QuadPart = 0x4321;
hr = IDataConvert_DataConvert(convert, DBTYPE_I8, DBTYPE_I2, 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 %d\n", dst_len);
ok(dst == 0x4321, "got %08x\n", dst);
dst = 0x1234;
((ULARGE_INTEGER*)src)->QuadPart = 0x4321;
hr = IDataConvert_DataConvert(convert, DBTYPE_UI8, DBTYPE_I2, 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 %d\n", dst_len);
ok(dst == 0x4321, "got %08x\n", dst);
dst = 0x1234;
strcpy((char *)src, "10");
hr = IDataConvert_DataConvert(convert, DBTYPE_STR, DBTYPE_I2, 2, &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 %d\n", dst_len);
ok(dst == 10, "got %08x\n", dst);
dst = 0x1234;
strcpy((char *)src, "10");
hr = IDataConvert_DataConvert(convert, DBTYPE_STR, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, DBDATACONVERT_LENGTHFROMNTS);
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 %d\n", dst_len);
ok(dst == 10, "got %08x\n", dst);
dst = 0x1234;
memcpy(src, ten, sizeof(ten));
hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_I2, 4, &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 %d\n", dst_len);
ok(dst == 10, "got %08x\n", dst);
dst = 0x1234;
memcpy(src, ten, sizeof(ten));
hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, DBDATACONVERT_LENGTHFROMNTS);
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 %d\n", dst_len);
ok(dst == 10, "got %08x\n", dst);
IDataConvert_Release(convert);
}
static void test_converttoi4(void)
{
IDataConvert *convert;
@ -579,6 +849,7 @@ START_TEST(convert)
OleInitialize(NULL);
test_dcinfo();
test_canconvert();
test_converttoi2();
test_converttoi4();
OleUninitialize();
}