mirror of
https://github.com/reactos/wine.git
synced 2024-11-29 14:40:56 +00:00
oledb32: Implement conversions to DBTYPE_WSTR.
This commit is contained in:
parent
a2e069b159
commit
91ef7037b7
@ -128,6 +128,8 @@ static int get_length(DBTYPE type)
|
||||
return 8;
|
||||
case DBTYPE_BSTR:
|
||||
return sizeof(BSTR);
|
||||
case DBTYPE_WSTR:
|
||||
return 0;
|
||||
default:
|
||||
FIXME("Unhandled type %04x\n", type);
|
||||
return 0;
|
||||
@ -277,6 +279,39 @@ static HRESULT WINAPI convert_DataConvert(IDataConvert* iface,
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case DBTYPE_WSTR:
|
||||
{
|
||||
BSTR b;
|
||||
DBLENGTH bstr_len;
|
||||
INT bytes_to_copy;
|
||||
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);
|
||||
*dst_len = bstr_len * sizeof(WCHAR); /* Doesn't include size for '\0' */
|
||||
*dst_status = DBSTATUS_S_OK;
|
||||
bytes_to_copy = min(*dst_len + sizeof(WCHAR), dst_max_len);
|
||||
if(dst)
|
||||
{
|
||||
if(bytes_to_copy >= sizeof(WCHAR))
|
||||
{
|
||||
memcpy(dst, b, bytes_to_copy - sizeof(WCHAR));
|
||||
*((WCHAR*)dst + bytes_to_copy / sizeof(WCHAR) - 1) = 0;
|
||||
if(bytes_to_copy < *dst_len + sizeof(WCHAR))
|
||||
*dst_status = DBSTATUS_S_TRUNCATED;
|
||||
}
|
||||
else
|
||||
{
|
||||
*dst_status = DBSTATUS_E_DATAOVERFLOW;
|
||||
hr = DB_E_ERRORSOCCURRED;
|
||||
}
|
||||
}
|
||||
SysFreeString(b);
|
||||
return hr;
|
||||
}
|
||||
|
||||
default:
|
||||
FIXME("Unimplemented conversion %04x -> %04x\n", src_type, dst_type);
|
||||
return E_NOTIMPL;
|
||||
|
@ -900,6 +900,128 @@ static void test_converttobstr(void)
|
||||
IDataConvert_Release(convert);
|
||||
}
|
||||
|
||||
static void test_converttowstr(void)
|
||||
{
|
||||
IDataConvert *convert;
|
||||
HRESULT hr;
|
||||
WCHAR dst[100];
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
memset(dst, 0xcc, sizeof(dst));
|
||||
hr = IDataConvert_DataConvert(convert, DBTYPE_EMPTY, 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 %02x\n", dst[0]);
|
||||
ok(dst[1] == 0xcccc, "got %02x\n", dst[1]);
|
||||
|
||||
memset(dst, 0xcc, sizeof(dst));
|
||||
hr = IDataConvert_DataConvert(convert, DBTYPE_NULL, 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[0] == 0xcccc, "got %02x\n", dst[0]);
|
||||
|
||||
*(short *)src = 4321;
|
||||
hr = IDataConvert_DataConvert(convert, DBTYPE_I2, 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));
|
||||
|
||||
*(short *)src = 4321;
|
||||
memset(dst, 0xcc, sizeof(dst));
|
||||
hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_WSTR, 0, &dst_len, src, dst, 0, 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 == 8, "got %d\n", dst_len);
|
||||
ok(dst[0] == 0xcccc, "got %02x\n", dst[0]);
|
||||
|
||||
*(short *)src = 4321;
|
||||
memset(dst, 0xcc, sizeof(dst));
|
||||
hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_WSTR, 0, &dst_len, src, NULL, 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(dst[0] == 0xcccc, "got %02x\n", dst[0]);
|
||||
|
||||
*(short *)src = 4321;
|
||||
memset(dst, 0xcc, sizeof(dst));
|
||||
hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_WSTR, 0, &dst_len, src, dst, 4, 0, &dst_status, 0, 0, 0);
|
||||
ok(hr == S_OK, "got %08x\n", hr);
|
||||
ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
|
||||
ok(dst_len == 8, "got %d\n", dst_len);
|
||||
ok(dst[0] == '4', "got %02x\n", dst[0]);
|
||||
ok(dst[1] == 0, "got %02x\n", dst[1]);
|
||||
ok(dst[2] == 0xcccc, "got %02x\n", dst[2]);
|
||||
|
||||
*(short *)src = 4321;
|
||||
memset(dst, 0xcc, sizeof(dst));
|
||||
hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_WSTR, 0, &dst_len, src, dst, 2, 0, &dst_status, 0, 0, 0);
|
||||
ok(hr == S_OK, "got %08x\n", hr);
|
||||
ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
|
||||
ok(dst_len == 8, "got %d\n", dst_len);
|
||||
ok(dst[0] == 0, "got %02x\n", dst[0]);
|
||||
ok(dst[1] == 0xcccc, "got %02x\n", dst[1]);
|
||||
|
||||
*(short *)src = 4321;
|
||||
memset(dst, 0xcc, sizeof(dst));
|
||||
hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_WSTR, 0, &dst_len, src, dst, 8, 0, &dst_status, 0, 0, 0);
|
||||
ok(hr == S_OK, "got %08x\n", hr);
|
||||
ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
|
||||
ok(dst_len == 8, "got %d\n", dst_len);
|
||||
ok(dst[0] == '4', "got %02x\n", dst[0]);
|
||||
ok(dst[1] == '3', "got %02x\n", dst[1]);
|
||||
ok(dst[2] == '2', "got %02x\n", dst[2]);
|
||||
ok(dst[3] == 0, "got %02x\n", dst[3]);
|
||||
ok(dst[4] == 0xcccc, "got %02x\n", dst[4]);
|
||||
|
||||
b = SysAllocString(ten);
|
||||
*(BSTR *)src = b;
|
||||
hr = IDataConvert_DataConvert(convert, DBTYPE_BSTR, 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));
|
||||
SysFreeString(b);
|
||||
|
||||
memcpy(src, ten, sizeof(ten));
|
||||
hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, 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]);
|
||||
|
||||
memcpy(src, ten, sizeof(ten));
|
||||
hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, 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));
|
||||
|
||||
memcpy(src, ten, sizeof(ten));
|
||||
hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, 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));
|
||||
|
||||
IDataConvert_Release(convert);
|
||||
}
|
||||
|
||||
START_TEST(convert)
|
||||
{
|
||||
@ -909,5 +1031,6 @@ START_TEST(convert)
|
||||
test_converttoi2();
|
||||
test_converttoi4();
|
||||
test_converttobstr();
|
||||
test_converttowstr();
|
||||
OleUninitialize();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user