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, 0x63bfd9ff},
154 {DBTYPE_NULL, 0x40001002},
155 {DBTYPE_I2, 0x3b9fd9ff},
156 {DBTYPE_I4, 0x3bdfd9ff},
158 {DBTYPE_R4, 0x3b9fd9ff},
159 {DBTYPE_R8, 0x3b9fd9ff},
160 {DBTYPE_CY, 0x039fd97f},
161 {DBTYPE_DATE, 0x799f99bf},
163 {DBTYPE_BSTR, 0x7bffd9ff},
164 {DBTYPE_IDISPATCH, 0x7bffffff},
165 {DBTYPE_ERROR, 0x01001500},
166 {DBTYPE_BOOL, 0x039fd9ff},
168 {DBTYPE_VARIANT, 0x7bffffff},
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, 0x43dfd97f},
178 {DBTYPE_UI8, 0x43dfd97f},
179 {DBTYPE_GUID, 0x01e01103},
180 {DBTYPE_BYTES, 0x01fc110b},
181 {DBTYPE_STR, 0x7bffd9ff},
183 {DBTYPE_WSTR, 0x7bffd9ff},
184 {DBTYPE_NUMERIC, 0x039fd97f},
185 {DBTYPE_UDT, 0x00000000},
186 {DBTYPE_DBDATE, 0x79801183},
188 {DBTYPE_DBTIME, 0x79801183},
189 {DBTYPE_DBTIMESTAMP, 0x79801183},
190 {DBTYPE_FILETIME, 0x79981183}
194 static inline BOOL array_type(DBTYPE type)
196 return (type >= DBTYPE_I2 && type <= DBTYPE_UI4);
199 static void test_canconvert(void)
201 IDataConvert *convert;
203 int src_idx, dst_idx;
205 hr = CoCreateInstance(&CLSID_OLEDB_CONVERSIONLIBRARY, NULL, CLSCTX_INPROC_SERVER, &IID_IDataConvert, (void**)&convert);
208 win_skip("Unable to load oledb conversion library\n");
212 /* Some older versions of the library don't support several conversions, we'll skip
213 if we have such a library */
214 hr = IDataConvert_CanConvert(convert, DBTYPE_EMPTY, DBTYPE_DBTIMESTAMP);
217 win_skip("Doesn't handle DBTYPE_EMPTY -> DBTYPE_DBTIMESTAMP conversion so skipping\n");
218 IDataConvert_Release(convert);
222 /* Some older versions of the library don't support several conversions, we'll skip
223 if we have such a library */
224 hr = IDataConvert_CanConvert(convert, DBTYPE_EMPTY, DBTYPE_DBTIMESTAMP);
227 win_skip("Doesn't handle DBTYPE_EMPTY -> DBTYPE_DBTIMESTAMP conversion so skipping\n");
228 IDataConvert_Release(convert);
232 for(src_idx = 0; src_idx < sizeof(simple_convert) / sizeof(simple_convert[0]); src_idx++)
233 for(dst_idx = 0; dst_idx < sizeof(simple_convert) / sizeof(simple_convert[0]); dst_idx++)
235 BOOL expect, simple_expect;
236 simple_expect = (simple_convert[src_idx].can_convert_to >> dst_idx) & 1;
238 hr = IDataConvert_CanConvert(convert, simple_convert[src_idx].type, simple_convert[dst_idx].type);
239 expect = simple_expect;
240 ok((hr == S_OK && expect == TRUE) ||
241 (hr == S_FALSE && expect == FALSE),
242 "%04x -> %04x: got %08x expect conversion to be %spossible\n", simple_convert[src_idx].type,
243 simple_convert[dst_idx].type, hr, expect ? "" : "not ");
245 /* src DBTYPE_BYREF */
246 hr = IDataConvert_CanConvert(convert, simple_convert[src_idx].type | DBTYPE_BYREF, simple_convert[dst_idx].type);
247 expect = simple_expect;
248 ok((hr == S_OK && expect == TRUE) ||
249 (hr == S_FALSE && expect == FALSE),
250 "%04x -> %04x: got %08x expect conversion to be %spossible\n", simple_convert[src_idx].type | DBTYPE_BYREF,
251 simple_convert[dst_idx].type, hr, expect ? "" : "not ");
253 /* dst DBTYPE_BYREF */
254 hr = IDataConvert_CanConvert(convert, simple_convert[src_idx].type, simple_convert[dst_idx].type | DBTYPE_BYREF);
257 (simple_convert[dst_idx].type == DBTYPE_BYTES ||
258 simple_convert[dst_idx].type == DBTYPE_STR ||
259 simple_convert[dst_idx].type == DBTYPE_WSTR))
261 ok((hr == S_OK && expect == TRUE) ||
262 (hr == S_FALSE && expect == FALSE),
263 "%04x -> %04x: got %08x expect conversion to be %spossible\n", simple_convert[src_idx].type,
264 simple_convert[dst_idx].type | DBTYPE_BYREF, hr, expect ? "" : "not ");
266 /* src & dst DBTYPE_BYREF */
267 hr = IDataConvert_CanConvert(convert, simple_convert[src_idx].type | DBTYPE_BYREF, simple_convert[dst_idx].type | DBTYPE_BYREF);
270 (simple_convert[dst_idx].type == DBTYPE_BYTES ||
271 simple_convert[dst_idx].type == DBTYPE_STR ||
272 simple_convert[dst_idx].type == DBTYPE_WSTR))
274 ok((hr == S_OK && expect == TRUE) ||
275 (hr == S_FALSE && expect == FALSE),
276 "%04x -> %04x: got %08x expect conversion to be %spossible\n", simple_convert[src_idx].type | DBTYPE_BYREF,
277 simple_convert[dst_idx].type | DBTYPE_BYREF, hr, expect ? "" : "not ");
279 /* src DBTYPE_ARRAY */
280 hr = IDataConvert_CanConvert(convert, simple_convert[src_idx].type | DBTYPE_ARRAY, simple_convert[dst_idx].type);
282 if(array_type(simple_convert[src_idx].type) && simple_convert[dst_idx].type == DBTYPE_VARIANT)
284 ok((hr == S_OK && expect == TRUE) ||
285 (hr == S_FALSE && expect == FALSE),
286 "%04x -> %04x: got %08x expect conversion to be %spossible\n", simple_convert[src_idx].type | DBTYPE_ARRAY,
287 simple_convert[dst_idx].type, hr, expect ? "" : "not ");
289 /* dst DBTYPE_ARRAY */
290 hr = IDataConvert_CanConvert(convert, simple_convert[src_idx].type, simple_convert[dst_idx].type | DBTYPE_ARRAY);
292 if(array_type(simple_convert[dst_idx].type) &&
293 (simple_convert[src_idx].type == DBTYPE_IDISPATCH ||
294 simple_convert[src_idx].type == DBTYPE_VARIANT))
296 ok((hr == S_OK && expect == TRUE) ||
297 (hr == S_FALSE && expect == FALSE),
298 "%04x -> %04x: got %08x expect conversion to be %spossible\n", simple_convert[src_idx].type,
299 simple_convert[dst_idx].type | DBTYPE_ARRAY, hr, expect ? "" : "not ");
301 /* src & dst DBTYPE_ARRAY */
302 hr = IDataConvert_CanConvert(convert, simple_convert[src_idx].type | DBTYPE_ARRAY, simple_convert[dst_idx].type | DBTYPE_ARRAY);
304 if(array_type(simple_convert[src_idx].type) &&
305 simple_convert[src_idx].type == simple_convert[dst_idx].type)
307 ok((hr == S_OK && expect == TRUE) ||
308 (hr == S_FALSE && expect == FALSE),
309 "%04x -> %04x: got %08x expect conversion to be %spossible\n", simple_convert[src_idx].type | DBTYPE_ARRAY,
310 simple_convert[dst_idx].type | DBTYPE_ARRAY, hr, expect ? "" : "not ");
312 /* src DBTYPE_VECTOR */
313 hr = IDataConvert_CanConvert(convert, simple_convert[src_idx].type | DBTYPE_VECTOR, simple_convert[dst_idx].type);
315 ok((hr == S_OK && expect == TRUE) ||
316 (hr == S_FALSE && expect == FALSE),
317 "%04x -> %04x: got %08x expect conversion to be %spossible\n", simple_convert[src_idx].type | DBTYPE_VECTOR,
318 simple_convert[dst_idx].type, hr, expect ? "" : "not ");
320 /* dst DBTYPE_VECTOR */
321 hr = IDataConvert_CanConvert(convert, simple_convert[src_idx].type, simple_convert[dst_idx].type | DBTYPE_VECTOR);
323 ok((hr == S_OK && expect == TRUE) ||
324 (hr == S_FALSE && expect == FALSE),
325 "%04x -> %04x: got %08x expect conversion to be %spossible\n", simple_convert[src_idx].type,
326 simple_convert[dst_idx].type | DBTYPE_VECTOR, hr, expect ? "" : "not ");
328 /* src & dst DBTYPE_VECTOR */
329 hr = IDataConvert_CanConvert(convert, simple_convert[src_idx].type | DBTYPE_VECTOR, simple_convert[dst_idx].type | DBTYPE_VECTOR);
331 ok((hr == S_OK && expect == TRUE) ||
332 (hr == S_FALSE && expect == FALSE),
333 "%04x -> %04x: got %08x expect conversion to be %spossible\n", simple_convert[src_idx].type | DBTYPE_VECTOR,
334 simple_convert[dst_idx].type | DBTYPE_VECTOR, hr, expect ? "" : "not ");
339 IDataConvert_Release(convert);
342 static void test_converttoi2(void)
344 IDataConvert *convert;
350 static const WCHAR ten[] = {'1','0',0};
353 hr = CoCreateInstance(&CLSID_OLEDB_CONVERSIONLIBRARY, NULL, CLSCTX_INPROC_SERVER, &IID_IDataConvert, (void**)&convert);
356 win_skip("Unable to load oledb conversion library\n");
361 hr = IDataConvert_DataConvert(convert, DBTYPE_EMPTY, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
362 ok(hr == S_OK, "got %08x\n", hr);
363 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
364 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
365 ok(dst == 0, "got %08x\n", dst);
368 hr = IDataConvert_DataConvert(convert, DBTYPE_NULL, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
369 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr);
370 ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status);
371 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
372 ok(dst == 0x1234, "got %08x\n", dst);
375 *(short *)src = 0x4321;
376 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
377 ok(hr == S_OK, "got %08x\n", hr);
378 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
379 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
380 ok(dst == 0x4321, "got %08x\n", dst);
383 *(int *)src = 0x4321cafe;
384 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
386 ok(hr == DB_E_DATAOVERFLOW, "got %08x\n", hr);
387 ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
388 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
389 ok(dst == 0x1234, "got %08x\n", dst);
392 *(int *)src = 0x4321;
393 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
394 ok(hr == S_OK, "got %08x\n", hr);
395 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
396 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
397 ok(dst == 0x4321, "got %08x\n", dst);
400 *(FLOAT *)src = 10.75;
401 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
402 ok(hr == S_OK, "got %08x\n", hr);
403 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
404 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
405 ok(dst == 11, "got %08x\n", dst);
408 *(FLOAT *)src = -10.75;
409 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
410 ok(hr == S_OK, "got %08x\n", hr);
411 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
412 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
413 ok(dst == -11, "got %08x\n", dst);
416 *(double *)src = 10.75;
417 hr = IDataConvert_DataConvert(convert, DBTYPE_R8, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
418 ok(hr == S_OK, "got %08x\n", hr);
419 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
420 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
421 ok(dst == 11, "got %08x\n", dst);
424 ((LARGE_INTEGER *)src)->QuadPart = 107500;
425 hr = IDataConvert_DataConvert(convert, DBTYPE_CY, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
426 ok(hr == S_OK, "got %08x\n", hr);
427 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
428 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
429 ok(dst == 11, "got %08x\n", dst);
432 *(DATE *)src = 10.7500;
433 hr = IDataConvert_DataConvert(convert, DBTYPE_DATE, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
434 ok(hr == S_OK, "got %08x\n", hr);
435 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
436 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
437 ok(dst == 11, "got %08x\n", dst);
440 b = SysAllocString(ten);
442 hr = IDataConvert_DataConvert(convert, DBTYPE_BSTR, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
443 ok(hr == S_OK, "got %08x\n", hr);
444 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
445 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
446 ok(dst == 10, "got %08x\n", dst);
450 *(SCODE *)src = 0x4321cafe;
451 hr = IDataConvert_DataConvert(convert, DBTYPE_ERROR, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
452 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr);
453 ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status);
454 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
455 ok(dst == 0x1234, "got %08x\n", dst);
458 *(VARIANT_BOOL *)src = VARIANT_TRUE;
459 hr = IDataConvert_DataConvert(convert, DBTYPE_BOOL, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
460 ok(hr == S_OK, "got %08x\n", hr);
461 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
462 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
463 ok(dst == -1, "got %08x\n", dst);
466 *(VARIANT_BOOL *)src = VARIANT_FALSE;
467 hr = IDataConvert_DataConvert(convert, DBTYPE_BOOL, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
468 ok(hr == S_OK, "got %08x\n", hr);
469 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
470 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
471 ok(dst == 0, "got %08x\n", dst);
474 V_VT((VARIANT*)src) = VT_I2;
475 V_I2((VARIANT*)src) = 0x4321;
476 hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
479 ok(hr == S_OK, "got %08x\n", hr);
480 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
482 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
484 ok(dst == 0x4321, "got %08x\n", dst);
487 memset(src, 0, sizeof(DECIMAL));
488 ((DECIMAL*)src)->u1.Lo64 = 0x4321;
489 hr = IDataConvert_DataConvert(convert, DBTYPE_DECIMAL, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
490 ok(hr == S_OK, "got %08x\n", hr);
491 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
492 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
493 ok(dst == 0x4321, "got %08x\n", dst);
496 *(signed char*)src = 0xab;
497 hr = IDataConvert_DataConvert(convert, DBTYPE_I1, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
498 ok(hr == S_OK, "got %08x\n", hr);
499 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
500 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
501 ok(dst == (signed short)0xffab, "got %08x\n", dst);
505 hr = IDataConvert_DataConvert(convert, DBTYPE_UI1, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
506 ok(hr == S_OK, "got %08x\n", hr);
507 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
508 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
509 ok(dst == 0xab, "got %08x\n", dst);
512 *(WORD*)src = 0x4321;
513 hr = IDataConvert_DataConvert(convert, DBTYPE_UI2, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
514 ok(hr == S_OK, "got %08x\n", hr);
515 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
516 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
517 ok(dst == 0x4321, "got %08x\n", dst);
520 *(WORD*)src = 0xabcd;
521 hr = IDataConvert_DataConvert(convert, DBTYPE_UI2, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
522 ok(hr == DB_E_ERRORSOCCURRED, "got %08x\n", hr);
523 ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
524 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
525 ok(dst == 0x1234, "got %08x\n", dst);
528 *(DWORD*)src = 0xabcd1234;
529 hr = IDataConvert_DataConvert(convert, DBTYPE_UI4, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
531 ok(hr == DB_E_DATAOVERFLOW, "got %08x\n", hr);
532 ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
533 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
534 ok(dst == 0x1234, "got %08x\n", dst);
537 *(DWORD*)src = 0x1234abcd;
538 hr = IDataConvert_DataConvert(convert, DBTYPE_UI4, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
540 ok(hr == DB_E_DATAOVERFLOW, "got %08x\n", hr);
541 ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
542 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
543 ok(dst == 0x1234, "got %08x\n", dst);
546 *(DWORD*)src = 0x4321;
547 hr = IDataConvert_DataConvert(convert, DBTYPE_UI4, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
548 ok(hr == S_OK, "got %08x\n", hr);
549 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
550 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
551 ok(dst == 0x4321, "got %08x\n", dst);
554 ((LARGE_INTEGER*)src)->QuadPart = 0x1234abcd;
555 hr = IDataConvert_DataConvert(convert, DBTYPE_I8, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
556 ok(hr == DB_E_ERRORSOCCURRED, "got %08x\n", hr);
557 ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
558 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
559 ok(dst == 0x1234, "got %08x\n", dst);
562 ((LARGE_INTEGER*)src)->QuadPart = 0x4321;
563 hr = IDataConvert_DataConvert(convert, DBTYPE_I8, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
564 ok(hr == S_OK, "got %08x\n", hr);
565 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
566 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
567 ok(dst == 0x4321, "got %08x\n", dst);
570 ((ULARGE_INTEGER*)src)->QuadPart = 0x4321;
571 hr = IDataConvert_DataConvert(convert, DBTYPE_UI8, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
572 ok(hr == S_OK, "got %08x\n", hr);
573 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
574 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
575 ok(dst == 0x4321, "got %08x\n", dst);
578 strcpy((char *)src, "10");
579 hr = IDataConvert_DataConvert(convert, DBTYPE_STR, DBTYPE_I2, 2, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
580 ok(hr == S_OK, "got %08x\n", hr);
581 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
582 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
583 ok(dst == 10, "got %08x\n", dst);
586 strcpy((char *)src, "10");
587 hr = IDataConvert_DataConvert(convert, DBTYPE_STR, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, DBDATACONVERT_LENGTHFROMNTS);
588 ok(hr == S_OK, "got %08x\n", hr);
589 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
590 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
591 ok(dst == 10, "got %08x\n", dst);
594 memcpy(src, ten, sizeof(ten));
595 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_I2, 4, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
596 ok(hr == S_OK, "got %08x\n", hr);
597 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
598 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
599 ok(dst == 10, "got %08x\n", dst);
602 memcpy(src, ten, sizeof(ten));
603 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, DBDATACONVERT_LENGTHFROMNTS);
604 ok(hr == S_OK, "got %08x\n", hr);
605 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
606 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
607 ok(dst == 10, "got %08x\n", dst);
609 IDataConvert_Release(convert);
612 static void test_converttoi4(void)
614 IDataConvert *convert;
620 static const WCHAR ten[] = {'1','0',0};
623 hr = CoCreateInstance(&CLSID_OLEDB_CONVERSIONLIBRARY, NULL, CLSCTX_INPROC_SERVER, &IID_IDataConvert, (void**)&convert);
626 win_skip("Unable to load oledb conversion library\n");
631 hr = IDataConvert_DataConvert(convert, DBTYPE_EMPTY, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
632 ok(hr == S_OK, "got %08x\n", hr);
633 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
634 ok(dst_len == sizeof(i4), "got %d\n", dst_len);
635 ok(i4 == 0, "got %08x\n", i4);
638 hr = IDataConvert_DataConvert(convert, DBTYPE_NULL, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
639 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr);
640 ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status);
641 ok(dst_len == sizeof(i4), "got %d\n", dst_len);
642 ok(i4 == 0x12345678, "got %08x\n", i4);
645 *(short *)src = 0x4321;
646 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
647 ok(hr == S_OK, "got %08x\n", hr);
648 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
649 ok(dst_len == sizeof(i4), "got %d\n", dst_len);
650 ok(i4 == 0x4321, "got %08x\n", i4);
653 *(int *)src = 0x4321cafe;
654 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
655 ok(hr == S_OK, "got %08x\n", hr);
656 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
657 ok(dst_len == sizeof(i4), "got %d\n", dst_len);
658 ok(i4 == 0x4321cafe, "got %08x\n", i4);
661 *(FLOAT *)src = 10.75;
662 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
663 ok(hr == S_OK, "got %08x\n", hr);
664 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
665 ok(dst_len == sizeof(i4), "got %d\n", dst_len);
666 ok(i4 == 11, "got %08x\n", i4);
669 *(FLOAT *)src = -10.75;
670 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
671 ok(hr == S_OK, "got %08x\n", hr);
672 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
673 ok(dst_len == sizeof(i4), "got %d\n", dst_len);
674 ok(i4 == -11, "got %08x\n", i4);
677 *(double *)src = 10.75;
678 hr = IDataConvert_DataConvert(convert, DBTYPE_R8, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
679 ok(hr == S_OK, "got %08x\n", hr);
680 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
681 ok(dst_len == sizeof(i4), "got %d\n", dst_len);
682 ok(i4 == 11, "got %08x\n", i4);
685 ((LARGE_INTEGER *)src)->QuadPart = 107500;
686 hr = IDataConvert_DataConvert(convert, DBTYPE_CY, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
687 ok(hr == S_OK, "got %08x\n", hr);
688 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
689 ok(dst_len == sizeof(i4), "got %d\n", dst_len);
690 ok(i4 == 11, "got %08x\n", i4);
693 *(DATE *)src = 10.7500;
694 hr = IDataConvert_DataConvert(convert, DBTYPE_DATE, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
695 ok(hr == S_OK, "got %08x\n", hr);
696 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
697 ok(dst_len == sizeof(i4), "got %d\n", dst_len);
698 ok(i4 == 11, "got %08x\n", i4);
701 b = SysAllocString(ten);
703 hr = IDataConvert_DataConvert(convert, DBTYPE_BSTR, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
704 ok(hr == S_OK, "got %08x\n", hr);
705 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
706 ok(dst_len == sizeof(i4), "got %d\n", dst_len);
707 ok(i4 == 10, "got %08x\n", i4);
711 *(SCODE *)src = 0x4321cafe;
712 hr = IDataConvert_DataConvert(convert, DBTYPE_ERROR, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
713 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr);
714 ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status);
715 ok(dst_len == sizeof(i4), "got %d\n", dst_len);
716 ok(i4 == 0x12345678, "got %08x\n", i4);
719 *(VARIANT_BOOL *)src = VARIANT_TRUE;
720 hr = IDataConvert_DataConvert(convert, DBTYPE_BOOL, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
721 ok(hr == S_OK, "got %08x\n", hr);
722 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
723 ok(dst_len == sizeof(i4), "got %d\n", dst_len);
724 ok(i4 == 0xffffffff, "got %08x\n", i4);
727 *(VARIANT_BOOL *)src = VARIANT_FALSE;
728 hr = IDataConvert_DataConvert(convert, DBTYPE_BOOL, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
729 ok(hr == S_OK, "got %08x\n", hr);
730 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
731 ok(dst_len == sizeof(i4), "got %d\n", dst_len);
732 ok(i4 == 0, "got %08x\n", i4);
735 V_VT((VARIANT*)src) = VT_I2;
736 V_I2((VARIANT*)src) = 0x1234;
737 hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
740 ok(hr == S_OK, "got %08x\n", hr);
741 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
743 ok(dst_len == sizeof(i4), "got %d\n", dst_len);
745 ok(i4 == 0x1234, "got %08x\n", i4);
748 memset(src, 0, sizeof(DECIMAL));
749 ((DECIMAL*)src)->u1.Lo64 = 0x1234;
750 hr = IDataConvert_DataConvert(convert, DBTYPE_DECIMAL, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
751 ok(hr == S_OK, "got %08x\n", hr);
752 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
753 ok(dst_len == sizeof(i4), "got %d\n", dst_len);
754 ok(i4 == 0x1234, "got %08x\n", i4);
757 *(signed char*)src = 0xab;
758 hr = IDataConvert_DataConvert(convert, DBTYPE_I1, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
759 ok(hr == S_OK, "got %08x\n", hr);
760 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
761 ok(dst_len == sizeof(i4), "got %d\n", dst_len);
762 ok(i4 == 0xffffffab, "got %08x\n", i4);
766 hr = IDataConvert_DataConvert(convert, DBTYPE_UI1, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
767 ok(hr == S_OK, "got %08x\n", hr);
768 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
769 ok(dst_len == sizeof(i4), "got %d\n", dst_len);
770 ok(i4 == 0xab, "got %08x\n", i4);
773 *(WORD*)src = 0xabcd;
774 hr = IDataConvert_DataConvert(convert, DBTYPE_UI2, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
775 ok(hr == S_OK, "got %08x\n", hr);
776 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
777 ok(dst_len == sizeof(i4), "got %d\n", dst_len);
778 ok(i4 == 0xabcd, "got %08x\n", i4);
781 *(DWORD*)src = 0xabcd1234;
782 hr = IDataConvert_DataConvert(convert, DBTYPE_UI4, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
783 ok(hr == DB_E_ERRORSOCCURRED, "got %08x\n", hr);
784 ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
785 ok(dst_len == sizeof(i4), "got %d\n", dst_len);
786 ok(i4 == 0x12345678, "got %08x\n", i4);
789 *(DWORD*)src = 0x1234abcd;
790 hr = IDataConvert_DataConvert(convert, DBTYPE_UI4, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
791 ok(hr == S_OK, "got %08x\n", hr);
792 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
793 ok(dst_len == sizeof(i4), "got %d\n", dst_len);
794 ok(i4 == 0x1234abcd, "got %08x\n", i4);
797 ((LARGE_INTEGER*)src)->QuadPart = 0x1234abcd;
798 hr = IDataConvert_DataConvert(convert, DBTYPE_I8, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
799 ok(hr == S_OK, "got %08x\n", hr);
800 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
801 ok(dst_len == sizeof(i4), "got %d\n", dst_len);
802 ok(i4 == 0x1234abcd, "got %08x\n", i4);
805 ((ULARGE_INTEGER*)src)->QuadPart = 0x1234abcd;
806 hr = IDataConvert_DataConvert(convert, DBTYPE_UI8, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
807 ok(hr == S_OK, "got %08x\n", hr);
808 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
809 ok(dst_len == sizeof(i4), "got %d\n", dst_len);
810 ok(i4 == 0x1234abcd, "got %08x\n", i4);
813 strcpy((char *)src, "10");
814 hr = IDataConvert_DataConvert(convert, DBTYPE_STR, DBTYPE_I4, 2, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
815 ok(hr == S_OK, "got %08x\n", hr);
816 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
817 ok(dst_len == sizeof(i4), "got %d\n", dst_len);
818 ok(i4 == 10, "got %08x\n", i4);
821 strcpy((char *)src, "10");
822 hr = IDataConvert_DataConvert(convert, DBTYPE_STR, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, DBDATACONVERT_LENGTHFROMNTS);
823 ok(hr == S_OK, "got %08x\n", hr);
824 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
825 ok(dst_len == sizeof(i4), "got %d\n", dst_len);
826 ok(i4 == 10, "got %08x\n", i4);
829 memcpy(src, ten, sizeof(ten));
830 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_I4, 4, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
831 ok(hr == S_OK, "got %08x\n", hr);
832 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
833 ok(dst_len == sizeof(i4), "got %d\n", dst_len);
834 ok(i4 == 10, "got %08x\n", i4);
837 memcpy(src, ten, sizeof(ten));
838 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, DBDATACONVERT_LENGTHFROMNTS);
839 ok(hr == S_OK, "got %08x\n", hr);
840 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
841 ok(dst_len == sizeof(i4), "got %d\n", dst_len);
842 ok(i4 == 10, "got %08x\n", i4);
844 IDataConvert_Release(convert);
847 static void test_converttobstr(void)
849 IDataConvert *convert;
855 static const WCHAR ten[] = {'1','0',0};
858 hr = CoCreateInstance(&CLSID_OLEDB_CONVERSIONLIBRARY, NULL, CLSCTX_INPROC_SERVER, &IID_IDataConvert, (void**)&convert);
861 win_skip("Unable to load oledb conversion library\n");
865 hr = IDataConvert_DataConvert(convert, DBTYPE_EMPTY, DBTYPE_BSTR, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
866 ok(hr == S_OK, "got %08x\n", hr);
867 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
868 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
869 ok(dst != NULL, "got %p\n", dst);
870 ok(SysStringLen(dst) == 0, "got %d\n", SysStringLen(dst));
874 hr = IDataConvert_DataConvert(convert, DBTYPE_NULL, DBTYPE_BSTR, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
875 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr);
876 ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status);
877 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
878 ok(dst == (void*)0x1234, "got %p\n", dst);
880 *(short *)src = 4321;
881 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_BSTR, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
882 ok(hr == S_OK, "got %08x\n", hr);
883 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
884 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
885 ok(dst != NULL, "got %p\n", dst);
886 ok(SysStringLen(dst) == 4, "got %d\n", SysStringLen(dst));
889 b = SysAllocString(ten);
891 hr = IDataConvert_DataConvert(convert, DBTYPE_BSTR, DBTYPE_BSTR, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
892 ok(hr == S_OK, "got %08x\n", hr);
893 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
894 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
895 ok(dst != NULL, "got %p\n", dst);
896 ok(dst != b, "got %p src %p\n", dst, b);
897 ok(!lstrcmpW(b, dst), "got %s\n", wine_dbgstr_w(dst));
901 IDataConvert_Release(convert);
904 static void test_converttowstr(void)
906 IDataConvert *convert;
912 static const WCHAR ten[] = {'1','0',0};
913 static const WCHAR fourthreetwoone[] = {'4','3','2','1',0};
916 hr = CoCreateInstance(&CLSID_OLEDB_CONVERSIONLIBRARY, NULL, CLSCTX_INPROC_SERVER, &IID_IDataConvert, (void**)&convert);
919 win_skip("Unable to load oledb conversion library\n");
924 memset(dst, 0xcc, sizeof(dst));
925 hr = IDataConvert_DataConvert(convert, DBTYPE_EMPTY, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
926 ok(hr == S_OK, "got %08x\n", hr);
927 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
928 ok(dst_len == 0, "got %d\n", dst_len);
929 ok(dst[0] == 0, "got %02x\n", dst[0]);
930 ok(dst[1] == 0xcccc, "got %02x\n", dst[1]);
932 memset(dst, 0xcc, sizeof(dst));
933 hr = IDataConvert_DataConvert(convert, DBTYPE_NULL, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
934 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr);
935 ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status);
936 ok(dst_len == 0, "got %d\n", dst_len);
937 ok(dst[0] == 0xcccc, "got %02x\n", dst[0]);
939 *(short *)src = 4321;
940 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
941 ok(hr == S_OK, "got %08x\n", hr);
942 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
943 ok(dst_len == 8, "got %d\n", dst_len);
944 ok(!lstrcmpW(dst, fourthreetwoone), "got %s\n", wine_dbgstr_w(dst));
946 *(short *)src = 4321;
947 memset(dst, 0xcc, sizeof(dst));
948 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_WSTR, 0, &dst_len, src, dst, 0, 0, &dst_status, 0, 0, 0);
949 ok(hr == DB_E_ERRORSOCCURRED, "got %08x\n", hr);
950 ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
951 ok(dst_len == 8, "got %d\n", dst_len);
952 ok(dst[0] == 0xcccc, "got %02x\n", dst[0]);
954 *(short *)src = 4321;
955 memset(dst, 0xcc, sizeof(dst));
956 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_WSTR, 0, &dst_len, src, NULL, 0, 0, &dst_status, 0, 0, 0);
957 ok(hr == S_OK, "got %08x\n", hr);
958 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
959 ok(dst_len == 8, "got %d\n", dst_len);
960 ok(dst[0] == 0xcccc, "got %02x\n", dst[0]);
962 *(short *)src = 4321;
963 memset(dst, 0xcc, sizeof(dst));
964 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_WSTR, 0, &dst_len, src, dst, 4, 0, &dst_status, 0, 0, 0);
965 ok(hr == S_OK, "got %08x\n", hr);
966 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
967 ok(dst_len == 8, "got %d\n", dst_len);
968 ok(dst[0] == '4', "got %02x\n", dst[0]);
969 ok(dst[1] == 0, "got %02x\n", dst[1]);
970 ok(dst[2] == 0xcccc, "got %02x\n", dst[2]);
972 *(short *)src = 4321;
973 memset(dst, 0xcc, sizeof(dst));
974 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_WSTR, 0, &dst_len, src, dst, 2, 0, &dst_status, 0, 0, 0);
975 ok(hr == S_OK, "got %08x\n", hr);
976 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
977 ok(dst_len == 8, "got %d\n", dst_len);
978 ok(dst[0] == 0, "got %02x\n", dst[0]);
979 ok(dst[1] == 0xcccc, "got %02x\n", dst[1]);
981 *(short *)src = 4321;
982 memset(dst, 0xcc, sizeof(dst));
983 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_WSTR, 0, &dst_len, src, dst, 8, 0, &dst_status, 0, 0, 0);
984 ok(hr == S_OK, "got %08x\n", hr);
985 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
986 ok(dst_len == 8, "got %d\n", dst_len);
987 ok(dst[0] == '4', "got %02x\n", dst[0]);
988 ok(dst[1] == '3', "got %02x\n", dst[1]);
989 ok(dst[2] == '2', "got %02x\n", dst[2]);
990 ok(dst[3] == 0, "got %02x\n", dst[3]);
991 ok(dst[4] == 0xcccc, "got %02x\n", dst[4]);
993 b = SysAllocString(ten);
995 hr = IDataConvert_DataConvert(convert, DBTYPE_BSTR, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
996 ok(hr == S_OK, "got %08x\n", hr);
997 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
998 ok(dst_len == 4, "got %d\n", dst_len);
999 ok(!lstrcmpW(b, dst), "got %s\n", wine_dbgstr_w(dst));
1002 memcpy(src, ten, sizeof(ten));
1003 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_WSTR, 2, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1004 ok(hr == S_OK, "got %08x\n", hr);
1005 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1006 ok(dst_len == 2, "got %d\n", dst_len);
1007 ok(dst[0] == '1', "got %02x\n", dst[0]);
1008 ok(dst[1] == 0, "got %02x\n", dst[1]);
1010 memcpy(src, ten, sizeof(ten));
1011 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_WSTR, 4, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1012 ok(hr == S_OK, "got %08x\n", hr);
1013 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1014 ok(dst_len == 4, "got %d\n", dst_len);
1015 ok(!lstrcmpW(ten, dst), "got %s\n", wine_dbgstr_w(dst));
1017 memcpy(src, ten, sizeof(ten));
1018 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, DBDATACONVERT_LENGTHFROMNTS);
1019 ok(hr == S_OK, "got %08x\n", hr);
1020 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1021 ok(dst_len == 4, "got %d\n", dst_len);
1022 ok(!lstrcmpW(ten, dst), "got %s\n", wine_dbgstr_w(dst));
1024 IDataConvert_Release(convert);
1027 static void test_converttobyrefwstr(void)
1029 IDataConvert *convert;
1033 DBSTATUS dst_status;
1035 static const WCHAR ten[] = {'1','0',0};
1036 static const WCHAR fourthreetwoone[] = {'4','3','2','1',0};
1039 hr = CoCreateInstance(&CLSID_OLEDB_CONVERSIONLIBRARY, NULL, CLSCTX_INPROC_SERVER, &IID_IDataConvert, (void**)&convert);
1042 win_skip("Unable to load oledb conversion library\n");
1046 hr = IDataConvert_DataConvert(convert, DBTYPE_EMPTY, DBTYPE_BYREF | DBTYPE_WSTR, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1047 ok(hr == S_OK, "got %08x\n", hr);
1048 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1049 ok(dst_len == 0, "got %d\n", dst_len);
1050 ok(dst[0] == 0, "got %04x\n", dst[0]);
1053 dst = (void*)0x12345678;
1054 hr = IDataConvert_DataConvert(convert, DBTYPE_NULL, DBTYPE_BYREF | DBTYPE_WSTR, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1055 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr);
1056 ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status);
1057 ok(dst_len == 0, "got %d\n", dst_len);
1058 ok(dst == (void*)0x12345678, "got %p\n", dst);
1060 *(short *)src = 4321;
1061 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_BYREF | DBTYPE_WSTR, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1062 ok(hr == S_OK, "got %08x\n", hr);
1063 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1064 ok(dst_len == 8, "got %d\n", dst_len);
1065 ok(!lstrcmpW(dst, fourthreetwoone), "got %s\n", wine_dbgstr_w(dst));
1068 *(short *)src = 4321;
1069 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_BYREF | DBTYPE_WSTR, 0, &dst_len, src, &dst, 0, 0, &dst_status, 0, 0, 0);
1070 ok(hr == S_OK, "got %08x\n", hr);
1071 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1072 ok(dst_len == 8, "got %d\n", dst_len);
1073 ok(!lstrcmpW(dst, fourthreetwoone), "got %s\n", wine_dbgstr_w(dst));
1076 b = SysAllocString(ten);
1078 hr = IDataConvert_DataConvert(convert, DBTYPE_BSTR, DBTYPE_BYREF | DBTYPE_WSTR, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1079 ok(hr == S_OK, "got %08x\n", hr);
1080 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1081 ok(dst_len == 4, "got %d\n", dst_len);
1082 ok(!lstrcmpW(b, dst), "got %s\n", wine_dbgstr_w(dst));
1086 memcpy(src, ten, sizeof(ten));
1087 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_BYREF | DBTYPE_WSTR, 2, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1088 ok(hr == S_OK, "got %08x\n", hr);
1089 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1090 ok(dst_len == 2, "got %d\n", dst_len);
1091 ok(dst[0] == '1', "got %02x\n", dst[0]);
1092 ok(dst[1] == 0, "got %02x\n", dst[1]);
1095 memcpy(src, ten, sizeof(ten));
1096 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_BYREF | DBTYPE_WSTR, 4, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1097 ok(hr == S_OK, "got %08x\n", hr);
1098 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1099 ok(dst_len == 4, "got %d\n", dst_len);
1100 ok(!lstrcmpW(ten, dst), "got %s\n", wine_dbgstr_w(dst));
1103 memcpy(src, ten, sizeof(ten));
1104 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_BYREF | DBTYPE_WSTR, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, DBDATACONVERT_LENGTHFROMNTS);
1105 ok(hr == S_OK, "got %08x\n", hr);
1106 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1107 ok(dst_len == 4, "got %d\n", dst_len);
1108 ok(!lstrcmpW(ten, dst), "got %s\n", wine_dbgstr_w(dst));
1111 IDataConvert_Release(convert);
1114 static void test_converttofiletime(void)
1116 IDataConvert *convert;
1120 DBSTATUS dst_status;
1123 hr = CoCreateInstance(&CLSID_OLEDB_CONVERSIONLIBRARY, NULL, CLSCTX_INPROC_SERVER, &IID_IDataConvert, (void**)&convert);
1126 win_skip("Unable to load oledb conversion library\n");
1130 memset(&dst, 0xcc, sizeof(dst));
1131 ((FILETIME *)src)->dwLowDateTime = 0x12345678;
1132 ((FILETIME *)src)->dwHighDateTime = 0x9abcdef0;
1133 hr = IDataConvert_DataConvert(convert, DBTYPE_FILETIME, DBTYPE_FILETIME, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1134 ok(hr == S_OK, "got %08x\n", hr);
1135 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1136 ok(dst_len == sizeof(dst), "got %d\n", dst_len);
1137 ok(dst.dwLowDateTime == 0x12345678, "got %08x\n", dst.dwLowDateTime);
1138 ok(dst.dwHighDateTime == 0x9abcdef0, "got %08x\n", dst.dwHighDateTime);
1140 IDataConvert_Release(convert);
1145 OleInitialize(NULL);
1150 test_converttobstr();
1151 test_converttowstr();
1152 test_converttobyrefwstr();
1153 test_converttofiletime();