1 /* OLE DB Conversion library tests
3 * Copyright 2009 Huw Davies
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #define NONAMELESSUNION
24 #define NONAMELESSSTRUCT
36 #include "wine/test.h"
38 static void test_dcinfo(void)
45 hr = CoCreateInstance(&CLSID_OLEDB_CONVERSIONLIBRARY, NULL, CLSCTX_INPROC_SERVER, &IID_IDCInfo, (void**)&info);
48 win_skip("Unable to load oledb conversion library\n");
52 types[0] = DCINFOTYPE_VERSION;
53 hr = IDCInfo_GetInfo(info, 1, types, &inf);
54 ok(hr == S_OK, "got %08x\n", hr);
56 ok(inf->eInfoType == DCINFOTYPE_VERSION, "got %08x\n", inf->eInfoType);
57 ok(V_VT(&inf->vData) == VT_UI4, "got %08x\n", V_VT(&inf->vData));
58 ok(V_UI4(&inf->vData) == 0x110, "got %08x\n", V_UI4(&inf->vData));
60 V_UI4(&inf->vData) = 0x200;
61 hr = IDCInfo_SetInfo(info, 1, inf);
62 ok(hr == S_OK, "got %08x\n", hr);
65 hr = IDCInfo_GetInfo(info, 1, types, &inf);
66 ok(hr == S_OK, "got %08x\n", hr);
67 ok(inf->eInfoType == DCINFOTYPE_VERSION, "got %08x\n", inf->eInfoType);
68 ok(V_VT(&inf->vData) == VT_UI4, "got %08x\n", V_VT(&inf->vData));
69 ok(V_UI4(&inf->vData) == 0x200, "got %08x\n", V_UI4(&inf->vData));
71 V_UI4(&inf->vData) = 0x100;
72 hr = IDCInfo_SetInfo(info, 1, inf);
73 ok(hr == S_OK, "got %08x\n", hr);
76 hr = IDCInfo_GetInfo(info, 1, types, &inf);
77 ok(hr == S_OK, "got %08x\n", hr);
78 ok(inf->eInfoType == DCINFOTYPE_VERSION, "got %08x\n", inf->eInfoType);
79 ok(V_VT(&inf->vData) == VT_UI4, "got %08x\n", V_VT(&inf->vData));
80 ok(V_UI4(&inf->vData) == 0x100, "got %08x\n", V_UI4(&inf->vData));
82 V_UI4(&inf->vData) = 0x500;
83 hr = IDCInfo_SetInfo(info, 1, inf);
84 ok(hr == S_OK, "got %08x\n", hr);
87 hr = IDCInfo_GetInfo(info, 1, types, &inf);
88 ok(hr == S_OK, "got %08x\n", hr);
89 ok(inf->eInfoType == DCINFOTYPE_VERSION, "got %08x\n", inf->eInfoType);
90 ok(V_VT(&inf->vData) == VT_UI4, "got %08x\n", V_VT(&inf->vData));
91 ok(V_UI4(&inf->vData) == 0x500, "got %08x\n", V_UI4(&inf->vData));
93 V_UI4(&inf->vData) = 0xffff;
94 hr = IDCInfo_SetInfo(info, 1, inf);
95 ok(hr == S_OK, "got %08x\n", hr);
98 hr = IDCInfo_GetInfo(info, 1, types, &inf);
99 ok(hr == S_OK, "got %08x\n", hr);
100 ok(inf->eInfoType == DCINFOTYPE_VERSION, "got %08x\n", inf->eInfoType);
101 ok(V_VT(&inf->vData) == VT_UI4, "got %08x\n", V_VT(&inf->vData));
102 ok(V_UI4(&inf->vData) == 0xffff, "got %08x\n", V_UI4(&inf->vData));
104 V_UI4(&inf->vData) = 0x12345678;
105 hr = IDCInfo_SetInfo(info, 1, inf);
106 ok(hr == S_OK, "got %08x\n", hr);
109 hr = IDCInfo_GetInfo(info, 1, types, &inf);
110 ok(hr == S_OK, "got %08x\n", hr);
111 ok(inf->eInfoType == DCINFOTYPE_VERSION, "got %08x\n", inf->eInfoType);
112 ok(V_VT(&inf->vData) == VT_UI4, "got %08x\n", V_VT(&inf->vData));
113 ok(V_UI4(&inf->vData) == 0x12345678, "got %08x\n", V_UI4(&inf->vData));
115 /* Try setting a version variant of something other than VT_UI4 */
116 V_VT(&inf->vData) = VT_I4;
117 V_I4(&inf->vData) = 0x200;
118 hr = IDCInfo_SetInfo(info, 1, inf);
119 ok(hr == DB_S_ERRORSOCCURRED, "got %08x\n", hr);
122 hr = IDCInfo_GetInfo(info, 1, types, &inf);
123 ok(hr == S_OK, "got %08x\n", hr);
124 ok(inf->eInfoType == DCINFOTYPE_VERSION, "got %08x\n", inf->eInfoType);
125 ok(V_VT(&inf->vData) == VT_UI4, "got %08x\n", V_VT(&inf->vData));
126 ok(V_UI4(&inf->vData) == 0x12345678, "got %08x\n", V_UI4(&inf->vData));
129 /* More than one type */
131 hr = IDCInfo_GetInfo(info, 2, types, &inf);
132 ok(hr == S_OK, "got %08x\n", hr);
133 ok(inf[0].eInfoType == DCINFOTYPE_VERSION, "got %08x\n", inf[0].eInfoType);
134 ok(V_VT(&inf[0].vData) == VT_UI4, "got %08x\n", V_VT(&inf[0].vData));
135 ok(V_UI4(&inf[0].vData) == 0x12345678, "got %08x\n", V_UI4(&inf[0].vData));
136 ok(inf[1].eInfoType == 2, "got %08x\n", inf[1].eInfoType);
137 ok(V_VT(&inf[1].vData) == VT_EMPTY, "got %08x\n", V_VT(&inf[1].vData));
139 hr = IDCInfo_SetInfo(info, 2, inf);
140 ok(hr == S_OK, "got %08x\n", hr);
144 IDCInfo_Release(info);
150 DWORD can_convert_to;
153 {DBTYPE_EMPTY, 0x23bfd9ff},
154 {DBTYPE_NULL, 0x00001002},
155 {DBTYPE_I2, 0x3b9fd9ff},
156 {DBTYPE_I4, 0x3bdfd9ff},
158 {DBTYPE_R4, 0x3b9fd9ff},
159 {DBTYPE_R8, 0x3b9fd9ff},
160 {DBTYPE_CY, 0x039fd97f},
161 {DBTYPE_DATE, 0x399f99bf},
163 {DBTYPE_BSTR, 0x3bffd9ff},
164 {DBTYPE_IDISPATCH, 0x3bffffff},
165 {DBTYPE_ERROR, 0x01001500},
166 {DBTYPE_BOOL, 0x039fd9ff},
168 {DBTYPE_VARIANT, 0x3bffffff},
169 {DBTYPE_IUNKNOWN, 0x00003203},
170 {DBTYPE_DECIMAL, 0x3b9fd97f},
171 {DBTYPE_I1, 0x3b9fd9ff},
173 {DBTYPE_UI1, 0x3b9fd9ff},
174 {DBTYPE_UI2, 0x3b9fd9ff},
175 {DBTYPE_UI4, 0x3bdfd9ff},
176 {DBTYPE_I8, 0x03dfd97f},
178 {DBTYPE_UI8, 0x03dfd97f},
179 {DBTYPE_GUID, 0x01e01103},
180 {DBTYPE_BYTES, 0x01fc110b},
181 {DBTYPE_STR, 0x3bffd9ff},
183 {DBTYPE_WSTR, 0x3bffd9ff},
184 {DBTYPE_NUMERIC, 0x039fd97f},
185 {DBTYPE_UDT, 0x00000000},
186 {DBTYPE_DBDATE, 0x39801183},
188 {DBTYPE_DBTIME, 0x39801183},
189 {DBTYPE_DBTIMESTAMP, 0x39801183}
193 static inline BOOL array_type(DBTYPE type)
195 return (type >= DBTYPE_I2 && type <= DBTYPE_UI4);
198 static void test_canconvert(void)
200 IDataConvert *convert;
202 int src_idx, dst_idx;
204 hr = CoCreateInstance(&CLSID_OLEDB_CONVERSIONLIBRARY, NULL, CLSCTX_INPROC_SERVER, &IID_IDataConvert, (void**)&convert);
207 win_skip("Unable to load oledb conversion library\n");
211 /* Some older versions of the library don't support several conversions, we'll skip
212 if we have such a library */
213 hr = IDataConvert_CanConvert(convert, DBTYPE_EMPTY, DBTYPE_DBTIMESTAMP);
216 win_skip("Doesn't handle DBTYPE_EMPTY -> DBTYPE_DBTIMESTAMP conversion so skipping\n");
217 IDataConvert_Release(convert);
221 /* Some older versions of the library don't support several conversions, we'll skip
222 if we have such a library */
223 hr = IDataConvert_CanConvert(convert, DBTYPE_EMPTY, DBTYPE_DBTIMESTAMP);
226 win_skip("Doesn't handle DBTYPE_EMPTY -> DBTYPE_DBTIMESTAMP conversion so skipping\n");
227 IDataConvert_Release(convert);
231 for(src_idx = 0; src_idx < sizeof(simple_convert) / sizeof(simple_convert[0]); src_idx++)
232 for(dst_idx = 0; dst_idx < sizeof(simple_convert) / sizeof(simple_convert[0]); dst_idx++)
234 BOOL expect, simple_expect;
235 simple_expect = (simple_convert[src_idx].can_convert_to >> dst_idx) & 1;
237 hr = IDataConvert_CanConvert(convert, simple_convert[src_idx].type, simple_convert[dst_idx].type);
238 expect = simple_expect;
239 ok((hr == S_OK && expect == TRUE) ||
240 (hr == S_FALSE && expect == FALSE),
241 "%04x -> %04x: got %08x expect conversion to be %spossible\n", simple_convert[src_idx].type,
242 simple_convert[dst_idx].type, hr, expect ? "" : "not ");
244 /* src DBTYPE_BYREF */
245 hr = IDataConvert_CanConvert(convert, simple_convert[src_idx].type | DBTYPE_BYREF, simple_convert[dst_idx].type);
246 expect = simple_expect;
247 ok((hr == S_OK && expect == TRUE) ||
248 (hr == S_FALSE && expect == FALSE),
249 "%04x -> %04x: got %08x expect conversion to be %spossible\n", simple_convert[src_idx].type | DBTYPE_BYREF,
250 simple_convert[dst_idx].type, hr, expect ? "" : "not ");
252 /* dst DBTYPE_BYREF */
253 hr = IDataConvert_CanConvert(convert, simple_convert[src_idx].type, simple_convert[dst_idx].type | DBTYPE_BYREF);
256 (simple_convert[dst_idx].type == DBTYPE_BYTES ||
257 simple_convert[dst_idx].type == DBTYPE_STR ||
258 simple_convert[dst_idx].type == DBTYPE_WSTR))
260 ok((hr == S_OK && expect == TRUE) ||
261 (hr == S_FALSE && expect == FALSE),
262 "%04x -> %04x: got %08x expect conversion to be %spossible\n", simple_convert[src_idx].type,
263 simple_convert[dst_idx].type | DBTYPE_BYREF, hr, expect ? "" : "not ");
265 /* src & dst DBTYPE_BYREF */
266 hr = IDataConvert_CanConvert(convert, simple_convert[src_idx].type | DBTYPE_BYREF, simple_convert[dst_idx].type | DBTYPE_BYREF);
269 (simple_convert[dst_idx].type == DBTYPE_BYTES ||
270 simple_convert[dst_idx].type == DBTYPE_STR ||
271 simple_convert[dst_idx].type == DBTYPE_WSTR))
273 ok((hr == S_OK && expect == TRUE) ||
274 (hr == S_FALSE && expect == FALSE),
275 "%04x -> %04x: got %08x expect conversion to be %spossible\n", simple_convert[src_idx].type | DBTYPE_BYREF,
276 simple_convert[dst_idx].type | DBTYPE_BYREF, hr, expect ? "" : "not ");
278 /* src DBTYPE_ARRAY */
279 hr = IDataConvert_CanConvert(convert, simple_convert[src_idx].type | DBTYPE_ARRAY, simple_convert[dst_idx].type);
281 if(array_type(simple_convert[src_idx].type) && simple_convert[dst_idx].type == DBTYPE_VARIANT)
283 ok((hr == S_OK && expect == TRUE) ||
284 (hr == S_FALSE && expect == FALSE),
285 "%04x -> %04x: got %08x expect conversion to be %spossible\n", simple_convert[src_idx].type | DBTYPE_ARRAY,
286 simple_convert[dst_idx].type, hr, expect ? "" : "not ");
288 /* dst DBTYPE_ARRAY */
289 hr = IDataConvert_CanConvert(convert, simple_convert[src_idx].type, simple_convert[dst_idx].type | DBTYPE_ARRAY);
291 if(array_type(simple_convert[dst_idx].type) &&
292 (simple_convert[src_idx].type == DBTYPE_IDISPATCH ||
293 simple_convert[src_idx].type == DBTYPE_VARIANT))
295 ok((hr == S_OK && expect == TRUE) ||
296 (hr == S_FALSE && expect == FALSE),
297 "%04x -> %04x: got %08x expect conversion to be %spossible\n", simple_convert[src_idx].type,
298 simple_convert[dst_idx].type | DBTYPE_ARRAY, hr, expect ? "" : "not ");
300 /* src & dst DBTYPE_ARRAY */
301 hr = IDataConvert_CanConvert(convert, simple_convert[src_idx].type | DBTYPE_ARRAY, simple_convert[dst_idx].type | DBTYPE_ARRAY);
303 if(array_type(simple_convert[src_idx].type) &&
304 simple_convert[src_idx].type == simple_convert[dst_idx].type)
306 ok((hr == S_OK && expect == TRUE) ||
307 (hr == S_FALSE && expect == FALSE),
308 "%04x -> %04x: got %08x expect conversion to be %spossible\n", simple_convert[src_idx].type | DBTYPE_ARRAY,
309 simple_convert[dst_idx].type | DBTYPE_ARRAY, hr, expect ? "" : "not ");
311 /* src DBTYPE_VECTOR */
312 hr = IDataConvert_CanConvert(convert, simple_convert[src_idx].type | DBTYPE_VECTOR, simple_convert[dst_idx].type);
314 ok((hr == S_OK && expect == TRUE) ||
315 (hr == S_FALSE && expect == FALSE),
316 "%04x -> %04x: got %08x expect conversion to be %spossible\n", simple_convert[src_idx].type | DBTYPE_VECTOR,
317 simple_convert[dst_idx].type, hr, expect ? "" : "not ");
319 /* dst DBTYPE_VECTOR */
320 hr = IDataConvert_CanConvert(convert, simple_convert[src_idx].type, simple_convert[dst_idx].type | DBTYPE_VECTOR);
322 ok((hr == S_OK && expect == TRUE) ||
323 (hr == S_FALSE && expect == FALSE),
324 "%04x -> %04x: got %08x expect conversion to be %spossible\n", simple_convert[src_idx].type,
325 simple_convert[dst_idx].type | DBTYPE_VECTOR, hr, expect ? "" : "not ");
327 /* src & dst DBTYPE_VECTOR */
328 hr = IDataConvert_CanConvert(convert, simple_convert[src_idx].type | DBTYPE_VECTOR, simple_convert[dst_idx].type | DBTYPE_VECTOR);
330 ok((hr == S_OK && expect == TRUE) ||
331 (hr == S_FALSE && expect == FALSE),
332 "%04x -> %04x: got %08x expect conversion to be %spossible\n", simple_convert[src_idx].type | DBTYPE_VECTOR,
333 simple_convert[dst_idx].type | DBTYPE_VECTOR, hr, expect ? "" : "not ");
338 IDataConvert_Release(convert);
341 static void test_converttoi2(void)
343 IDataConvert *convert;
349 static const WCHAR ten[] = {'1','0',0};
352 hr = CoCreateInstance(&CLSID_OLEDB_CONVERSIONLIBRARY, NULL, CLSCTX_INPROC_SERVER, &IID_IDataConvert, (void**)&convert);
355 win_skip("Unable to load oledb conversion library\n");
360 hr = IDataConvert_DataConvert(convert, DBTYPE_EMPTY, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
361 ok(hr == S_OK, "got %08x\n", hr);
362 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
363 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
364 ok(dst == 0, "got %08x\n", dst);
367 hr = IDataConvert_DataConvert(convert, DBTYPE_NULL, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
368 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr);
369 ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status);
370 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
371 ok(dst == 0x1234, "got %08x\n", dst);
374 *(short *)src = 0x4321;
375 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
376 ok(hr == S_OK, "got %08x\n", hr);
377 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
378 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
379 ok(dst == 0x4321, "got %08x\n", dst);
382 *(int *)src = 0x4321cafe;
383 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
385 ok(hr == DB_E_DATAOVERFLOW, "got %08x\n", hr);
386 ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
387 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
388 ok(dst == 0x1234, "got %08x\n", dst);
391 *(int *)src = 0x4321;
392 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
393 ok(hr == S_OK, "got %08x\n", hr);
394 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
395 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
396 ok(dst == 0x4321, "got %08x\n", dst);
399 *(FLOAT *)src = 10.75;
400 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
401 ok(hr == S_OK, "got %08x\n", hr);
402 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
403 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
404 ok(dst == 11, "got %08x\n", dst);
407 *(FLOAT *)src = -10.75;
408 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
409 ok(hr == S_OK, "got %08x\n", hr);
410 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
411 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
412 ok(dst == -11, "got %08x\n", dst);
415 *(double *)src = 10.75;
416 hr = IDataConvert_DataConvert(convert, DBTYPE_R8, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
417 ok(hr == S_OK, "got %08x\n", hr);
418 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
419 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
420 ok(dst == 11, "got %08x\n", dst);
423 ((LARGE_INTEGER *)src)->QuadPart = 107500;
424 hr = IDataConvert_DataConvert(convert, DBTYPE_CY, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
425 ok(hr == S_OK, "got %08x\n", hr);
426 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
427 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
428 ok(dst == 11, "got %08x\n", dst);
431 *(DATE *)src = 10.7500;
432 hr = IDataConvert_DataConvert(convert, DBTYPE_DATE, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
433 ok(hr == S_OK, "got %08x\n", hr);
434 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
435 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
436 ok(dst == 11, "got %08x\n", dst);
439 b = SysAllocString(ten);
441 hr = IDataConvert_DataConvert(convert, DBTYPE_BSTR, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
442 ok(hr == S_OK, "got %08x\n", hr);
443 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
444 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
445 ok(dst == 10, "got %08x\n", dst);
449 *(SCODE *)src = 0x4321cafe;
450 hr = IDataConvert_DataConvert(convert, DBTYPE_ERROR, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
451 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr);
452 ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status);
453 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
454 ok(dst == 0x1234, "got %08x\n", dst);
457 *(VARIANT_BOOL *)src = VARIANT_TRUE;
458 hr = IDataConvert_DataConvert(convert, DBTYPE_BOOL, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
459 ok(hr == S_OK, "got %08x\n", hr);
460 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
461 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
462 ok(dst == -1, "got %08x\n", dst);
465 *(VARIANT_BOOL *)src = VARIANT_FALSE;
466 hr = IDataConvert_DataConvert(convert, DBTYPE_BOOL, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
467 ok(hr == S_OK, "got %08x\n", hr);
468 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
469 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
470 ok(dst == 0, "got %08x\n", dst);
473 V_VT((VARIANT*)src) = VT_I2;
474 V_I2((VARIANT*)src) = 0x4321;
475 hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
478 ok(hr == S_OK, "got %08x\n", hr);
479 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
481 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
483 ok(dst == 0x4321, "got %08x\n", dst);
486 memset(src, 0, sizeof(DECIMAL));
487 ((DECIMAL*)src)->u1.Lo64 = 0x4321;
488 hr = IDataConvert_DataConvert(convert, DBTYPE_DECIMAL, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
489 ok(hr == S_OK, "got %08x\n", hr);
490 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
491 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
492 ok(dst == 0x4321, "got %08x\n", dst);
495 *(signed char*)src = 0xab;
496 hr = IDataConvert_DataConvert(convert, DBTYPE_I1, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
497 ok(hr == S_OK, "got %08x\n", hr);
498 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
499 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
500 ok(dst == (signed short)0xffab, "got %08x\n", dst);
504 hr = IDataConvert_DataConvert(convert, DBTYPE_UI1, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
505 ok(hr == S_OK, "got %08x\n", hr);
506 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
507 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
508 ok(dst == 0xab, "got %08x\n", dst);
511 *(WORD*)src = 0x4321;
512 hr = IDataConvert_DataConvert(convert, DBTYPE_UI2, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
513 ok(hr == S_OK, "got %08x\n", hr);
514 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
515 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
516 ok(dst == 0x4321, "got %08x\n", dst);
519 *(WORD*)src = 0xabcd;
520 hr = IDataConvert_DataConvert(convert, DBTYPE_UI2, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
521 ok(hr == DB_E_ERRORSOCCURRED, "got %08x\n", hr);
522 ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
523 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
524 ok(dst == 0x1234, "got %08x\n", dst);
527 *(DWORD*)src = 0xabcd1234;
528 hr = IDataConvert_DataConvert(convert, DBTYPE_UI4, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
530 ok(hr == DB_E_DATAOVERFLOW, "got %08x\n", hr);
531 ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
532 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
533 ok(dst == 0x1234, "got %08x\n", dst);
536 *(DWORD*)src = 0x1234abcd;
537 hr = IDataConvert_DataConvert(convert, DBTYPE_UI4, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
539 ok(hr == DB_E_DATAOVERFLOW, "got %08x\n", hr);
540 ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
541 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
542 ok(dst == 0x1234, "got %08x\n", dst);
545 *(DWORD*)src = 0x4321;
546 hr = IDataConvert_DataConvert(convert, DBTYPE_UI4, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
547 ok(hr == S_OK, "got %08x\n", hr);
548 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
549 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
550 ok(dst == 0x4321, "got %08x\n", dst);
553 ((LARGE_INTEGER*)src)->QuadPart = 0x1234abcd;
554 hr = IDataConvert_DataConvert(convert, DBTYPE_I8, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
555 ok(hr == DB_E_ERRORSOCCURRED, "got %08x\n", hr);
556 ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
557 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
558 ok(dst == 0x1234, "got %08x\n", dst);
561 ((LARGE_INTEGER*)src)->QuadPart = 0x4321;
562 hr = IDataConvert_DataConvert(convert, DBTYPE_I8, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
563 ok(hr == S_OK, "got %08x\n", hr);
564 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
565 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
566 ok(dst == 0x4321, "got %08x\n", dst);
569 ((ULARGE_INTEGER*)src)->QuadPart = 0x4321;
570 hr = IDataConvert_DataConvert(convert, DBTYPE_UI8, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
571 ok(hr == S_OK, "got %08x\n", hr);
572 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
573 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
574 ok(dst == 0x4321, "got %08x\n", dst);
577 strcpy((char *)src, "10");
578 hr = IDataConvert_DataConvert(convert, DBTYPE_STR, DBTYPE_I2, 2, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
579 ok(hr == S_OK, "got %08x\n", hr);
580 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
581 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
582 ok(dst == 10, "got %08x\n", dst);
585 strcpy((char *)src, "10");
586 hr = IDataConvert_DataConvert(convert, DBTYPE_STR, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, DBDATACONVERT_LENGTHFROMNTS);
587 ok(hr == S_OK, "got %08x\n", hr);
588 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
589 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
590 ok(dst == 10, "got %08x\n", dst);
593 memcpy(src, ten, sizeof(ten));
594 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_I2, 4, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
595 ok(hr == S_OK, "got %08x\n", hr);
596 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
597 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
598 ok(dst == 10, "got %08x\n", dst);
601 memcpy(src, ten, sizeof(ten));
602 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, DBDATACONVERT_LENGTHFROMNTS);
603 ok(hr == S_OK, "got %08x\n", hr);
604 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
605 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
606 ok(dst == 10, "got %08x\n", dst);
608 IDataConvert_Release(convert);
611 static void test_converttoi4(void)
613 IDataConvert *convert;
619 static const WCHAR ten[] = {'1','0',0};
622 hr = CoCreateInstance(&CLSID_OLEDB_CONVERSIONLIBRARY, NULL, CLSCTX_INPROC_SERVER, &IID_IDataConvert, (void**)&convert);
625 win_skip("Unable to load oledb conversion library\n");
630 hr = IDataConvert_DataConvert(convert, DBTYPE_EMPTY, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
631 ok(hr == S_OK, "got %08x\n", hr);
632 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
633 ok(dst_len == sizeof(i4), "got %d\n", dst_len);
634 ok(i4 == 0, "got %08x\n", i4);
637 hr = IDataConvert_DataConvert(convert, DBTYPE_NULL, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
638 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr);
639 ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status);
640 ok(dst_len == sizeof(i4), "got %d\n", dst_len);
641 ok(i4 == 0x12345678, "got %08x\n", i4);
644 *(short *)src = 0x4321;
645 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
646 ok(hr == S_OK, "got %08x\n", hr);
647 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
648 ok(dst_len == sizeof(i4), "got %d\n", dst_len);
649 ok(i4 == 0x4321, "got %08x\n", i4);
652 *(int *)src = 0x4321cafe;
653 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
654 ok(hr == S_OK, "got %08x\n", hr);
655 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
656 ok(dst_len == sizeof(i4), "got %d\n", dst_len);
657 ok(i4 == 0x4321cafe, "got %08x\n", i4);
660 *(FLOAT *)src = 10.75;
661 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
662 ok(hr == S_OK, "got %08x\n", hr);
663 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
664 ok(dst_len == sizeof(i4), "got %d\n", dst_len);
665 ok(i4 == 11, "got %08x\n", i4);
668 *(FLOAT *)src = -10.75;
669 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
670 ok(hr == S_OK, "got %08x\n", hr);
671 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
672 ok(dst_len == sizeof(i4), "got %d\n", dst_len);
673 ok(i4 == -11, "got %08x\n", i4);
676 *(double *)src = 10.75;
677 hr = IDataConvert_DataConvert(convert, DBTYPE_R8, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
678 ok(hr == S_OK, "got %08x\n", hr);
679 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
680 ok(dst_len == sizeof(i4), "got %d\n", dst_len);
681 ok(i4 == 11, "got %08x\n", i4);
684 ((LARGE_INTEGER *)src)->QuadPart = 107500;
685 hr = IDataConvert_DataConvert(convert, DBTYPE_CY, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
686 ok(hr == S_OK, "got %08x\n", hr);
687 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
688 ok(dst_len == sizeof(i4), "got %d\n", dst_len);
689 ok(i4 == 11, "got %08x\n", i4);
692 *(DATE *)src = 10.7500;
693 hr = IDataConvert_DataConvert(convert, DBTYPE_DATE, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
694 ok(hr == S_OK, "got %08x\n", hr);
695 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
696 ok(dst_len == sizeof(i4), "got %d\n", dst_len);
697 ok(i4 == 11, "got %08x\n", i4);
700 b = SysAllocString(ten);
702 hr = IDataConvert_DataConvert(convert, DBTYPE_BSTR, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
703 ok(hr == S_OK, "got %08x\n", hr);
704 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
705 ok(dst_len == sizeof(i4), "got %d\n", dst_len);
706 ok(i4 == 10, "got %08x\n", i4);
710 *(SCODE *)src = 0x4321cafe;
711 hr = IDataConvert_DataConvert(convert, DBTYPE_ERROR, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
712 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr);
713 ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status);
714 ok(dst_len == sizeof(i4), "got %d\n", dst_len);
715 ok(i4 == 0x12345678, "got %08x\n", i4);
718 *(VARIANT_BOOL *)src = VARIANT_TRUE;
719 hr = IDataConvert_DataConvert(convert, DBTYPE_BOOL, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
720 ok(hr == S_OK, "got %08x\n", hr);
721 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
722 ok(dst_len == sizeof(i4), "got %d\n", dst_len);
723 ok(i4 == 0xffffffff, "got %08x\n", i4);
726 *(VARIANT_BOOL *)src = VARIANT_FALSE;
727 hr = IDataConvert_DataConvert(convert, DBTYPE_BOOL, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
728 ok(hr == S_OK, "got %08x\n", hr);
729 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
730 ok(dst_len == sizeof(i4), "got %d\n", dst_len);
731 ok(i4 == 0, "got %08x\n", i4);
734 V_VT((VARIANT*)src) = VT_I2;
735 V_I2((VARIANT*)src) = 0x1234;
736 hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
739 ok(hr == S_OK, "got %08x\n", hr);
740 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
742 ok(dst_len == sizeof(i4), "got %d\n", dst_len);
744 ok(i4 == 0x1234, "got %08x\n", i4);
747 memset(src, 0, sizeof(DECIMAL));
748 ((DECIMAL*)src)->u1.Lo64 = 0x1234;
749 hr = IDataConvert_DataConvert(convert, DBTYPE_DECIMAL, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
750 ok(hr == S_OK, "got %08x\n", hr);
751 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
752 ok(dst_len == sizeof(i4), "got %d\n", dst_len);
753 ok(i4 == 0x1234, "got %08x\n", i4);
756 *(signed char*)src = 0xab;
757 hr = IDataConvert_DataConvert(convert, DBTYPE_I1, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
758 ok(hr == S_OK, "got %08x\n", hr);
759 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
760 ok(dst_len == sizeof(i4), "got %d\n", dst_len);
761 ok(i4 == 0xffffffab, "got %08x\n", i4);
765 hr = IDataConvert_DataConvert(convert, DBTYPE_UI1, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
766 ok(hr == S_OK, "got %08x\n", hr);
767 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
768 ok(dst_len == sizeof(i4), "got %d\n", dst_len);
769 ok(i4 == 0xab, "got %08x\n", i4);
772 *(WORD*)src = 0xabcd;
773 hr = IDataConvert_DataConvert(convert, DBTYPE_UI2, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
774 ok(hr == S_OK, "got %08x\n", hr);
775 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
776 ok(dst_len == sizeof(i4), "got %d\n", dst_len);
777 ok(i4 == 0xabcd, "got %08x\n", i4);
780 *(DWORD*)src = 0xabcd1234;
781 hr = IDataConvert_DataConvert(convert, DBTYPE_UI4, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
782 ok(hr == DB_E_ERRORSOCCURRED, "got %08x\n", hr);
783 ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
784 ok(dst_len == sizeof(i4), "got %d\n", dst_len);
785 ok(i4 == 0x12345678, "got %08x\n", i4);
788 *(DWORD*)src = 0x1234abcd;
789 hr = IDataConvert_DataConvert(convert, DBTYPE_UI4, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
790 ok(hr == S_OK, "got %08x\n", hr);
791 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
792 ok(dst_len == sizeof(i4), "got %d\n", dst_len);
793 ok(i4 == 0x1234abcd, "got %08x\n", i4);
796 ((LARGE_INTEGER*)src)->QuadPart = 0x1234abcd;
797 hr = IDataConvert_DataConvert(convert, DBTYPE_I8, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
798 ok(hr == S_OK, "got %08x\n", hr);
799 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
800 ok(dst_len == sizeof(i4), "got %d\n", dst_len);
801 ok(i4 == 0x1234abcd, "got %08x\n", i4);
804 ((ULARGE_INTEGER*)src)->QuadPart = 0x1234abcd;
805 hr = IDataConvert_DataConvert(convert, DBTYPE_UI8, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
806 ok(hr == S_OK, "got %08x\n", hr);
807 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
808 ok(dst_len == sizeof(i4), "got %d\n", dst_len);
809 ok(i4 == 0x1234abcd, "got %08x\n", i4);
812 strcpy((char *)src, "10");
813 hr = IDataConvert_DataConvert(convert, DBTYPE_STR, DBTYPE_I4, 2, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
814 ok(hr == S_OK, "got %08x\n", hr);
815 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
816 ok(dst_len == sizeof(i4), "got %d\n", dst_len);
817 ok(i4 == 10, "got %08x\n", i4);
820 strcpy((char *)src, "10");
821 hr = IDataConvert_DataConvert(convert, DBTYPE_STR, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, DBDATACONVERT_LENGTHFROMNTS);
822 ok(hr == S_OK, "got %08x\n", hr);
823 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
824 ok(dst_len == sizeof(i4), "got %d\n", dst_len);
825 ok(i4 == 10, "got %08x\n", i4);
828 memcpy(src, ten, sizeof(ten));
829 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_I4, 4, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
830 ok(hr == S_OK, "got %08x\n", hr);
831 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
832 ok(dst_len == sizeof(i4), "got %d\n", dst_len);
833 ok(i4 == 10, "got %08x\n", i4);
836 memcpy(src, ten, sizeof(ten));
837 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, DBDATACONVERT_LENGTHFROMNTS);
838 ok(hr == S_OK, "got %08x\n", hr);
839 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
840 ok(dst_len == sizeof(i4), "got %d\n", dst_len);
841 ok(i4 == 10, "got %08x\n", i4);
843 IDataConvert_Release(convert);
846 static void test_converttobstr(void)
848 IDataConvert *convert;
854 static const WCHAR ten[] = {'1','0',0};
857 hr = CoCreateInstance(&CLSID_OLEDB_CONVERSIONLIBRARY, NULL, CLSCTX_INPROC_SERVER, &IID_IDataConvert, (void**)&convert);
860 win_skip("Unable to load oledb conversion library\n");
864 hr = IDataConvert_DataConvert(convert, DBTYPE_EMPTY, DBTYPE_BSTR, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
865 ok(hr == S_OK, "got %08x\n", hr);
866 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
867 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
868 ok(dst != NULL, "got %p\n", dst);
869 ok(SysStringLen(dst) == 0, "got %d\n", SysStringLen(dst));
873 hr = IDataConvert_DataConvert(convert, DBTYPE_NULL, DBTYPE_BSTR, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
874 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr);
875 ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status);
876 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
877 ok(dst == (void*)0x1234, "got %p\n", dst);
879 *(short *)src = 4321;
880 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_BSTR, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
881 ok(hr == S_OK, "got %08x\n", hr);
882 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
883 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
884 ok(dst != NULL, "got %p\n", dst);
885 ok(SysStringLen(dst) == 4, "got %d\n", SysStringLen(dst));
888 b = SysAllocString(ten);
890 hr = IDataConvert_DataConvert(convert, DBTYPE_BSTR, DBTYPE_BSTR, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
891 ok(hr == S_OK, "got %08x\n", hr);
892 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
893 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
894 ok(dst != NULL, "got %p\n", dst);
895 ok(dst != b, "got %p src %p\n", dst, b);
896 ok(!lstrcmpW(b, dst), "got %s\n", wine_dbgstr_w(dst));
900 IDataConvert_Release(convert);
903 static void test_converttowstr(void)
905 IDataConvert *convert;
911 static const WCHAR ten[] = {'1','0',0};
912 static const WCHAR fourthreetwoone[] = {'4','3','2','1',0};
915 hr = CoCreateInstance(&CLSID_OLEDB_CONVERSIONLIBRARY, NULL, CLSCTX_INPROC_SERVER, &IID_IDataConvert, (void**)&convert);
918 win_skip("Unable to load oledb conversion library\n");
923 memset(dst, 0xcc, sizeof(dst));
924 hr = IDataConvert_DataConvert(convert, DBTYPE_EMPTY, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
925 ok(hr == S_OK, "got %08x\n", hr);
926 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
927 ok(dst_len == 0, "got %d\n", dst_len);
928 ok(dst[0] == 0, "got %02x\n", dst[0]);
929 ok(dst[1] == 0xcccc, "got %02x\n", dst[1]);
931 memset(dst, 0xcc, sizeof(dst));
932 hr = IDataConvert_DataConvert(convert, DBTYPE_NULL, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
933 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr);
934 ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status);
935 ok(dst_len == 0, "got %d\n", dst_len);
936 ok(dst[0] == 0xcccc, "got %02x\n", dst[0]);
938 *(short *)src = 4321;
939 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
940 ok(hr == S_OK, "got %08x\n", hr);
941 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
942 ok(dst_len == 8, "got %d\n", dst_len);
943 ok(!lstrcmpW(dst, fourthreetwoone), "got %s\n", wine_dbgstr_w(dst));
945 *(short *)src = 4321;
946 memset(dst, 0xcc, sizeof(dst));
947 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_WSTR, 0, &dst_len, src, dst, 0, 0, &dst_status, 0, 0, 0);
948 ok(hr == DB_E_ERRORSOCCURRED, "got %08x\n", hr);
949 ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
950 ok(dst_len == 8, "got %d\n", dst_len);
951 ok(dst[0] == 0xcccc, "got %02x\n", dst[0]);
953 *(short *)src = 4321;
954 memset(dst, 0xcc, sizeof(dst));
955 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_WSTR, 0, &dst_len, src, NULL, 0, 0, &dst_status, 0, 0, 0);
956 ok(hr == S_OK, "got %08x\n", hr);
957 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
958 ok(dst_len == 8, "got %d\n", dst_len);
959 ok(dst[0] == 0xcccc, "got %02x\n", dst[0]);
961 *(short *)src = 4321;
962 memset(dst, 0xcc, sizeof(dst));
963 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_WSTR, 0, &dst_len, src, dst, 4, 0, &dst_status, 0, 0, 0);
964 ok(hr == S_OK, "got %08x\n", hr);
965 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
966 ok(dst_len == 8, "got %d\n", dst_len);
967 ok(dst[0] == '4', "got %02x\n", dst[0]);
968 ok(dst[1] == 0, "got %02x\n", dst[1]);
969 ok(dst[2] == 0xcccc, "got %02x\n", dst[2]);
971 *(short *)src = 4321;
972 memset(dst, 0xcc, sizeof(dst));
973 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_WSTR, 0, &dst_len, src, dst, 2, 0, &dst_status, 0, 0, 0);
974 ok(hr == S_OK, "got %08x\n", hr);
975 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
976 ok(dst_len == 8, "got %d\n", dst_len);
977 ok(dst[0] == 0, "got %02x\n", dst[0]);
978 ok(dst[1] == 0xcccc, "got %02x\n", dst[1]);
980 *(short *)src = 4321;
981 memset(dst, 0xcc, sizeof(dst));
982 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_WSTR, 0, &dst_len, src, dst, 8, 0, &dst_status, 0, 0, 0);
983 ok(hr == S_OK, "got %08x\n", hr);
984 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
985 ok(dst_len == 8, "got %d\n", dst_len);
986 ok(dst[0] == '4', "got %02x\n", dst[0]);
987 ok(dst[1] == '3', "got %02x\n", dst[1]);
988 ok(dst[2] == '2', "got %02x\n", dst[2]);
989 ok(dst[3] == 0, "got %02x\n", dst[3]);
990 ok(dst[4] == 0xcccc, "got %02x\n", dst[4]);
992 b = SysAllocString(ten);
994 hr = IDataConvert_DataConvert(convert, DBTYPE_BSTR, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
995 ok(hr == S_OK, "got %08x\n", hr);
996 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
997 ok(dst_len == 4, "got %d\n", dst_len);
998 ok(!lstrcmpW(b, dst), "got %s\n", wine_dbgstr_w(dst));
1001 memcpy(src, ten, sizeof(ten));
1002 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_WSTR, 2, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1003 ok(hr == S_OK, "got %08x\n", hr);
1004 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1005 ok(dst_len == 2, "got %d\n", dst_len);
1006 ok(dst[0] == '1', "got %02x\n", dst[0]);
1007 ok(dst[1] == 0, "got %02x\n", dst[1]);
1009 memcpy(src, ten, sizeof(ten));
1010 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_WSTR, 4, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1011 ok(hr == S_OK, "got %08x\n", hr);
1012 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1013 ok(dst_len == 4, "got %d\n", dst_len);
1014 ok(!lstrcmpW(ten, dst), "got %s\n", wine_dbgstr_w(dst));
1016 memcpy(src, ten, sizeof(ten));
1017 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, DBDATACONVERT_LENGTHFROMNTS);
1018 ok(hr == S_OK, "got %08x\n", hr);
1019 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1020 ok(dst_len == 4, "got %d\n", dst_len);
1021 ok(!lstrcmpW(ten, dst), "got %s\n", wine_dbgstr_w(dst));
1023 IDataConvert_Release(convert);
1026 static void test_converttobyrefwstr(void)
1028 IDataConvert *convert;
1032 DBSTATUS dst_status;
1034 static const WCHAR ten[] = {'1','0',0};
1035 static const WCHAR fourthreetwoone[] = {'4','3','2','1',0};
1038 hr = CoCreateInstance(&CLSID_OLEDB_CONVERSIONLIBRARY, NULL, CLSCTX_INPROC_SERVER, &IID_IDataConvert, (void**)&convert);
1041 win_skip("Unable to load oledb conversion library\n");
1045 hr = IDataConvert_DataConvert(convert, DBTYPE_EMPTY, DBTYPE_BYREF | DBTYPE_WSTR, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1046 ok(hr == S_OK, "got %08x\n", hr);
1047 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1048 ok(dst_len == 0, "got %d\n", dst_len);
1049 ok(dst[0] == 0, "got %04x\n", dst[0]);
1052 dst = (void*)0x12345678;
1053 hr = IDataConvert_DataConvert(convert, DBTYPE_NULL, DBTYPE_BYREF | DBTYPE_WSTR, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1054 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr);
1055 ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status);
1056 ok(dst_len == 0, "got %d\n", dst_len);
1057 ok(dst == (void*)0x12345678, "got %p\n", dst);
1059 *(short *)src = 4321;
1060 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_BYREF | DBTYPE_WSTR, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1061 ok(hr == S_OK, "got %08x\n", hr);
1062 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1063 ok(dst_len == 8, "got %d\n", dst_len);
1064 ok(!lstrcmpW(dst, fourthreetwoone), "got %s\n", wine_dbgstr_w(dst));
1067 *(short *)src = 4321;
1068 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_BYREF | DBTYPE_WSTR, 0, &dst_len, src, &dst, 0, 0, &dst_status, 0, 0, 0);
1069 ok(hr == S_OK, "got %08x\n", hr);
1070 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1071 ok(dst_len == 8, "got %d\n", dst_len);
1072 ok(!lstrcmpW(dst, fourthreetwoone), "got %s\n", wine_dbgstr_w(dst));
1075 b = SysAllocString(ten);
1077 hr = IDataConvert_DataConvert(convert, DBTYPE_BSTR, DBTYPE_BYREF | DBTYPE_WSTR, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1078 ok(hr == S_OK, "got %08x\n", hr);
1079 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1080 ok(dst_len == 4, "got %d\n", dst_len);
1081 ok(!lstrcmpW(b, dst), "got %s\n", wine_dbgstr_w(dst));
1085 memcpy(src, ten, sizeof(ten));
1086 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_BYREF | DBTYPE_WSTR, 2, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1087 ok(hr == S_OK, "got %08x\n", hr);
1088 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1089 ok(dst_len == 2, "got %d\n", dst_len);
1090 ok(dst[0] == '1', "got %02x\n", dst[0]);
1091 ok(dst[1] == 0, "got %02x\n", dst[1]);
1094 memcpy(src, ten, sizeof(ten));
1095 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_BYREF | DBTYPE_WSTR, 4, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1096 ok(hr == S_OK, "got %08x\n", hr);
1097 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1098 ok(dst_len == 4, "got %d\n", dst_len);
1099 ok(!lstrcmpW(ten, dst), "got %s\n", wine_dbgstr_w(dst));
1102 memcpy(src, ten, sizeof(ten));
1103 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_BYREF | DBTYPE_WSTR, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, DBDATACONVERT_LENGTHFROMNTS);
1104 ok(hr == S_OK, "got %08x\n", hr);
1105 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1106 ok(dst_len == 4, "got %d\n", dst_len);
1107 ok(!lstrcmpW(ten, dst), "got %s\n", wine_dbgstr_w(dst));
1110 IDataConvert_Release(convert);
1116 OleInitialize(NULL);
1121 test_converttobstr();
1122 test_converttowstr();
1123 test_converttobyrefwstr();