oledb32: Implement conversions to DBTYPE_BYREF | DBTYPE_WSTR.

This commit is contained in:
Huw Davies 2009-10-02 12:36:05 +01:00 committed by Alexandre Julliard
parent 8349b13453
commit a94e8088c8
2 changed files with 110 additions and 0 deletions

View File

@ -129,6 +129,7 @@ static int get_length(DBTYPE type)
case DBTYPE_BSTR:
return sizeof(BSTR);
case DBTYPE_WSTR:
case DBTYPE_BYREF | DBTYPE_WSTR:
return 0;
default:
FIXME("Unhandled type %04x\n", type);
@ -312,6 +313,26 @@ static HRESULT WINAPI convert_DataConvert(IDataConvert* iface,
return hr;
}
case DBTYPE_BYREF | DBTYPE_WSTR:
{
BSTR b;
WCHAR **d = dst;
DBLENGTH bstr_len;
hr = IDataConvert_DataConvert(iface, src_type, DBTYPE_BSTR, src_len, &bstr_len,
src, &b, sizeof(BSTR), src_status, dst_status,
precision, scale, flags);
if(hr != S_OK) return hr;
bstr_len = SysStringLen(b) * sizeof(WCHAR);
*dst_len = bstr_len; /* Doesn't include size for '\0' */
*d = CoTaskMemAlloc(bstr_len + sizeof(WCHAR));
if(*d) memcpy(*d, b, bstr_len + sizeof(WCHAR));
else hr = E_OUTOFMEMORY;
SysFreeString(b);
return hr;
}
default:
FIXME("Unimplemented conversion %04x -> %04x\n", src_type, dst_type);
return E_NOTIMPL;

View File

@ -1023,6 +1023,94 @@ static void test_converttowstr(void)
IDataConvert_Release(convert);
}
static void test_converttobyrefwstr(void)
{
IDataConvert *convert;
HRESULT hr;
WCHAR *dst;
BYTE src[20];
DBSTATUS dst_status;
DBLENGTH dst_len;
static const WCHAR ten[] = {'1','0',0};
static const WCHAR fourthreetwoone[] = {'4','3','2','1',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;
}
hr = IDataConvert_DataConvert(convert, DBTYPE_EMPTY, DBTYPE_BYREF | DBTYPE_WSTR, 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 == 0, "got %d\n", dst_len);
ok(dst[0] == 0, "got %04x\n", dst[0]);
CoTaskMemFree(dst);
dst = (void*)0x12345678;
hr = IDataConvert_DataConvert(convert, DBTYPE_NULL, DBTYPE_BYREF | DBTYPE_WSTR, 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 == 0, "got %d\n", dst_len);
ok(dst == (void*)0x12345678, "got %p\n", dst);
*(short *)src = 4321;
hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_BYREF | DBTYPE_WSTR, 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 == 8, "got %d\n", dst_len);
ok(!lstrcmpW(dst, fourthreetwoone), "got %s\n", wine_dbgstr_w(dst));
CoTaskMemFree(dst);
*(short *)src = 4321;
hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_BYREF | DBTYPE_WSTR, 0, &dst_len, src, &dst, 0, 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 == 8, "got %d\n", dst_len);
ok(!lstrcmpW(dst, fourthreetwoone), "got %s\n", wine_dbgstr_w(dst));
CoTaskMemFree(dst);
b = SysAllocString(ten);
*(BSTR *)src = b;
hr = IDataConvert_DataConvert(convert, DBTYPE_BSTR, DBTYPE_BYREF | DBTYPE_WSTR, 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 == 4, "got %d\n", dst_len);
ok(!lstrcmpW(b, dst), "got %s\n", wine_dbgstr_w(dst));
CoTaskMemFree(dst);
SysFreeString(b);
memcpy(src, ten, sizeof(ten));
hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_BYREF | DBTYPE_WSTR, 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 == 2, "got %d\n", dst_len);
ok(dst[0] == '1', "got %02x\n", dst[0]);
ok(dst[1] == 0, "got %02x\n", dst[1]);
CoTaskMemFree(dst);
memcpy(src, ten, sizeof(ten));
hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_BYREF | DBTYPE_WSTR, 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 == 4, "got %d\n", dst_len);
ok(!lstrcmpW(ten, dst), "got %s\n", wine_dbgstr_w(dst));
CoTaskMemFree(dst);
memcpy(src, ten, sizeof(ten));
hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_BYREF | DBTYPE_WSTR, 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 == 4, "got %d\n", dst_len);
ok(!lstrcmpW(ten, dst), "got %s\n", wine_dbgstr_w(dst));
CoTaskMemFree(dst);
IDataConvert_Release(convert);
}
START_TEST(convert)
{
OleInitialize(NULL);
@ -1032,5 +1120,6 @@ START_TEST(convert)
test_converttoi4();
test_converttobstr();
test_converttowstr();
test_converttobyrefwstr();
OleUninitialize();
}