oledb32: Coerce Variant to VT_DATE when converting data.
[wine.git] / dlls / oledb32 / tests / convert.c
blob6b0dd55c7f58fa5b1813b8b5e06a04f164fdc98f
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
20 #include <stdarg.h>
22 #define COBJMACROS
23 #define NONAMELESSUNION
24 #define NONAMELESSSTRUCT
26 #include "windef.h"
27 #include "winbase.h"
28 #include "ole2.h"
29 #include "msdadc.h"
31 #include "oledberr.h"
33 #include "initguid.h"
34 #include "msdaguid.h"
36 #include "wine/test.h"
38 static IDataConvert *convert;
40 static void test_dcinfo(void)
42 IDCInfo *info;
43 HRESULT hr;
44 DCINFOTYPE types[2];
45 DCINFO *inf;
47 hr = CoCreateInstance(&CLSID_OLEDB_CONVERSIONLIBRARY, NULL, CLSCTX_INPROC_SERVER, &IID_IDCInfo, (void**)&info);
48 if(FAILED(hr))
50 win_skip("Unable to load oledb conversion library\n");
51 return;
54 types[0] = DCINFOTYPE_VERSION;
55 hr = IDCInfo_GetInfo(info, 1, types, &inf);
56 ok(hr == S_OK, "got %08x\n", hr);
58 ok(inf->eInfoType == DCINFOTYPE_VERSION, "got %08x\n", inf->eInfoType);
59 ok(V_VT(&inf->vData) == VT_UI4, "got %08x\n", V_VT(&inf->vData));
60 ok(V_UI4(&inf->vData) == 0x110, "got %08x\n", V_UI4(&inf->vData));
62 V_UI4(&inf->vData) = 0x200;
63 hr = IDCInfo_SetInfo(info, 1, inf);
64 ok(hr == S_OK, "got %08x\n", hr);
65 CoTaskMemFree(inf);
67 hr = IDCInfo_GetInfo(info, 1, types, &inf);
68 ok(hr == S_OK, "got %08x\n", hr);
69 ok(inf->eInfoType == DCINFOTYPE_VERSION, "got %08x\n", inf->eInfoType);
70 ok(V_VT(&inf->vData) == VT_UI4, "got %08x\n", V_VT(&inf->vData));
71 ok(V_UI4(&inf->vData) == 0x200, "got %08x\n", V_UI4(&inf->vData));
73 V_UI4(&inf->vData) = 0x100;
74 hr = IDCInfo_SetInfo(info, 1, inf);
75 ok(hr == S_OK, "got %08x\n", hr);
76 CoTaskMemFree(inf);
78 hr = IDCInfo_GetInfo(info, 1, types, &inf);
79 ok(hr == S_OK, "got %08x\n", hr);
80 ok(inf->eInfoType == DCINFOTYPE_VERSION, "got %08x\n", inf->eInfoType);
81 ok(V_VT(&inf->vData) == VT_UI4, "got %08x\n", V_VT(&inf->vData));
82 ok(V_UI4(&inf->vData) == 0x100, "got %08x\n", V_UI4(&inf->vData));
84 V_UI4(&inf->vData) = 0x500;
85 hr = IDCInfo_SetInfo(info, 1, inf);
86 ok(hr == S_OK, "got %08x\n", hr);
87 CoTaskMemFree(inf);
89 hr = IDCInfo_GetInfo(info, 1, types, &inf);
90 ok(hr == S_OK, "got %08x\n", hr);
91 ok(inf->eInfoType == DCINFOTYPE_VERSION, "got %08x\n", inf->eInfoType);
92 ok(V_VT(&inf->vData) == VT_UI4, "got %08x\n", V_VT(&inf->vData));
93 ok(V_UI4(&inf->vData) == 0x500, "got %08x\n", V_UI4(&inf->vData));
95 V_UI4(&inf->vData) = 0xffff;
96 hr = IDCInfo_SetInfo(info, 1, inf);
97 ok(hr == S_OK, "got %08x\n", hr);
98 CoTaskMemFree(inf);
100 hr = IDCInfo_GetInfo(info, 1, types, &inf);
101 ok(hr == S_OK, "got %08x\n", hr);
102 ok(inf->eInfoType == DCINFOTYPE_VERSION, "got %08x\n", inf->eInfoType);
103 ok(V_VT(&inf->vData) == VT_UI4, "got %08x\n", V_VT(&inf->vData));
104 ok(V_UI4(&inf->vData) == 0xffff, "got %08x\n", V_UI4(&inf->vData));
106 V_UI4(&inf->vData) = 0x12345678;
107 hr = IDCInfo_SetInfo(info, 1, inf);
108 ok(hr == S_OK, "got %08x\n", hr);
109 CoTaskMemFree(inf);
111 hr = IDCInfo_GetInfo(info, 1, types, &inf);
112 ok(hr == S_OK, "got %08x\n", hr);
113 ok(inf->eInfoType == DCINFOTYPE_VERSION, "got %08x\n", inf->eInfoType);
114 ok(V_VT(&inf->vData) == VT_UI4, "got %08x\n", V_VT(&inf->vData));
115 ok(V_UI4(&inf->vData) == 0x12345678, "got %08x\n", V_UI4(&inf->vData));
117 /* Try setting a version variant of something other than VT_UI4 */
118 V_VT(&inf->vData) = VT_I4;
119 V_I4(&inf->vData) = 0x200;
120 hr = IDCInfo_SetInfo(info, 1, inf);
121 ok(hr == DB_S_ERRORSOCCURRED, "got %08x\n", hr);
122 CoTaskMemFree(inf);
124 hr = IDCInfo_GetInfo(info, 1, types, &inf);
125 ok(hr == S_OK, "got %08x\n", hr);
126 ok(inf->eInfoType == DCINFOTYPE_VERSION, "got %08x\n", inf->eInfoType);
127 ok(V_VT(&inf->vData) == VT_UI4, "got %08x\n", V_VT(&inf->vData));
128 ok(V_UI4(&inf->vData) == 0x12345678, "got %08x\n", V_UI4(&inf->vData));
129 CoTaskMemFree(inf);
131 /* More than one type */
132 types[1] = 2;
133 hr = IDCInfo_GetInfo(info, 2, types, &inf);
134 ok(hr == S_OK, "got %08x\n", hr);
135 ok(inf[0].eInfoType == DCINFOTYPE_VERSION, "got %08x\n", inf[0].eInfoType);
136 ok(V_VT(&inf[0].vData) == VT_UI4, "got %08x\n", V_VT(&inf[0].vData));
137 ok(V_UI4(&inf[0].vData) == 0x12345678, "got %08x\n", V_UI4(&inf[0].vData));
138 ok(inf[1].eInfoType == 2, "got %08x\n", inf[1].eInfoType);
139 ok(V_VT(&inf[1].vData) == VT_EMPTY, "got %08x\n", V_VT(&inf[1].vData));
141 hr = IDCInfo_SetInfo(info, 2, inf);
142 ok(hr == S_OK, "got %08x\n", hr);
143 CoTaskMemFree(inf);
146 IDCInfo_Release(info);
149 static const struct can_convert
151 DBTYPE type;
152 DWORD can_convert_to;
153 } simple_convert[] =
155 {DBTYPE_EMPTY, 0x63bfd9ff},
156 {DBTYPE_NULL, 0x40001002},
157 {DBTYPE_I2, 0x3b9fd9ff},
158 {DBTYPE_I4, 0x3bdfd9ff},
160 {DBTYPE_R4, 0x3b9fd9ff},
161 {DBTYPE_R8, 0x3b9fd9ff},
162 {DBTYPE_CY, 0x039fd97f},
163 {DBTYPE_DATE, 0x799f99bf},
165 {DBTYPE_BSTR, 0x7bffd9ff},
166 {DBTYPE_IDISPATCH, 0x7bffffff},
167 {DBTYPE_ERROR, 0x01001500},
168 {DBTYPE_BOOL, 0x039fd9ff},
170 {DBTYPE_VARIANT, 0x7bffffff},
171 {DBTYPE_IUNKNOWN, 0x00003203},
172 {DBTYPE_DECIMAL, 0x3b9fd97f},
173 {DBTYPE_I1, 0x3b9fd9ff},
175 {DBTYPE_UI1, 0x3b9fd9ff},
176 {DBTYPE_UI2, 0x3b9fd9ff},
177 {DBTYPE_UI4, 0x3bdfd9ff},
178 {DBTYPE_I8, 0x43dfd97f},
180 {DBTYPE_UI8, 0x43dfd97f},
181 {DBTYPE_GUID, 0x01e01103},
182 {DBTYPE_BYTES, 0x01fc110b},
183 {DBTYPE_STR, 0x7bffd9ff},
185 {DBTYPE_WSTR, 0x7bffd9ff},
186 {DBTYPE_NUMERIC, 0x039fd97f},
187 {DBTYPE_UDT, 0x00000000},
188 {DBTYPE_DBDATE, 0x79801183},
190 {DBTYPE_DBTIME, 0x79801183},
191 {DBTYPE_DBTIMESTAMP, 0x79801183},
192 {DBTYPE_FILETIME, 0x79981183}
196 static inline BOOL array_type(DBTYPE type)
198 return (type >= DBTYPE_I2 && type <= DBTYPE_UI4);
201 static void test_canconvert(void)
203 HRESULT hr;
204 int src_idx, dst_idx;
206 /* Some older versions of the library don't support several conversions, we'll skip
207 if we have such a library */
208 hr = IDataConvert_CanConvert(convert, DBTYPE_EMPTY, DBTYPE_DBTIMESTAMP);
209 if(hr == S_FALSE)
211 win_skip("Doesn't handle DBTYPE_EMPTY -> DBTYPE_DBTIMESTAMP conversion so skipping\n");
212 return;
215 /* Some older versions of the library don't support several conversions, we'll skip
216 if we have such a library */
217 hr = IDataConvert_CanConvert(convert, DBTYPE_EMPTY, DBTYPE_DBTIMESTAMP);
218 if(hr == S_FALSE)
220 win_skip("Doesn't handle DBTYPE_EMPTY -> DBTYPE_DBTIMESTAMP conversion so skipping\n");
221 return;
224 for(src_idx = 0; src_idx < sizeof(simple_convert) / sizeof(simple_convert[0]); src_idx++)
225 for(dst_idx = 0; dst_idx < sizeof(simple_convert) / sizeof(simple_convert[0]); dst_idx++)
227 BOOL expect, simple_expect;
228 simple_expect = (simple_convert[src_idx].can_convert_to >> dst_idx) & 1;
230 hr = IDataConvert_CanConvert(convert, simple_convert[src_idx].type, simple_convert[dst_idx].type);
231 expect = simple_expect;
232 ok((hr == S_OK && expect == TRUE) ||
233 (hr == S_FALSE && expect == FALSE),
234 "%04x -> %04x: got %08x expect conversion to be %spossible\n", simple_convert[src_idx].type,
235 simple_convert[dst_idx].type, hr, expect ? "" : "not ");
237 /* src DBTYPE_BYREF */
238 hr = IDataConvert_CanConvert(convert, simple_convert[src_idx].type | DBTYPE_BYREF, 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 | DBTYPE_BYREF,
243 simple_convert[dst_idx].type, hr, expect ? "" : "not ");
245 /* dst DBTYPE_BYREF */
246 hr = IDataConvert_CanConvert(convert, simple_convert[src_idx].type, simple_convert[dst_idx].type | DBTYPE_BYREF);
247 expect = FALSE;
248 if(simple_expect &&
249 (simple_convert[dst_idx].type == DBTYPE_BYTES ||
250 simple_convert[dst_idx].type == DBTYPE_STR ||
251 simple_convert[dst_idx].type == DBTYPE_WSTR))
252 expect = TRUE;
253 ok((hr == S_OK && expect == TRUE) ||
254 (hr == S_FALSE && expect == FALSE),
255 "%04x -> %04x: got %08x expect conversion to be %spossible\n", simple_convert[src_idx].type,
256 simple_convert[dst_idx].type | DBTYPE_BYREF, hr, expect ? "" : "not ");
258 /* src & dst DBTYPE_BYREF */
259 hr = IDataConvert_CanConvert(convert, simple_convert[src_idx].type | DBTYPE_BYREF, simple_convert[dst_idx].type | DBTYPE_BYREF);
260 expect = FALSE;
261 if(simple_expect &&
262 (simple_convert[dst_idx].type == DBTYPE_BYTES ||
263 simple_convert[dst_idx].type == DBTYPE_STR ||
264 simple_convert[dst_idx].type == DBTYPE_WSTR))
265 expect = TRUE;
266 ok((hr == S_OK && expect == TRUE) ||
267 (hr == S_FALSE && expect == FALSE),
268 "%04x -> %04x: got %08x expect conversion to be %spossible\n", simple_convert[src_idx].type | DBTYPE_BYREF,
269 simple_convert[dst_idx].type | DBTYPE_BYREF, hr, expect ? "" : "not ");
271 /* src DBTYPE_ARRAY */
272 hr = IDataConvert_CanConvert(convert, simple_convert[src_idx].type | DBTYPE_ARRAY, simple_convert[dst_idx].type);
273 expect = FALSE;
274 if(array_type(simple_convert[src_idx].type) && simple_convert[dst_idx].type == DBTYPE_VARIANT)
275 expect = TRUE;
276 ok((hr == S_OK && expect == TRUE) ||
277 (hr == S_FALSE && expect == FALSE),
278 "%04x -> %04x: got %08x expect conversion to be %spossible\n", simple_convert[src_idx].type | DBTYPE_ARRAY,
279 simple_convert[dst_idx].type, hr, expect ? "" : "not ");
281 /* dst DBTYPE_ARRAY */
282 hr = IDataConvert_CanConvert(convert, simple_convert[src_idx].type, simple_convert[dst_idx].type | DBTYPE_ARRAY);
283 expect = FALSE;
284 if(array_type(simple_convert[dst_idx].type) &&
285 (simple_convert[src_idx].type == DBTYPE_IDISPATCH ||
286 simple_convert[src_idx].type == DBTYPE_VARIANT))
287 expect = TRUE;
288 ok((hr == S_OK && expect == TRUE) ||
289 (hr == S_FALSE && expect == FALSE),
290 "%04x -> %04x: got %08x expect conversion to be %spossible\n", simple_convert[src_idx].type,
291 simple_convert[dst_idx].type | DBTYPE_ARRAY, hr, expect ? "" : "not ");
293 /* src & dst DBTYPE_ARRAY */
294 hr = IDataConvert_CanConvert(convert, simple_convert[src_idx].type | DBTYPE_ARRAY, simple_convert[dst_idx].type | DBTYPE_ARRAY);
295 expect = FALSE;
296 if(array_type(simple_convert[src_idx].type) &&
297 simple_convert[src_idx].type == simple_convert[dst_idx].type)
298 expect = TRUE;
299 ok((hr == S_OK && expect == TRUE) ||
300 (hr == S_FALSE && expect == FALSE),
301 "%04x -> %04x: got %08x expect conversion to be %spossible\n", simple_convert[src_idx].type | DBTYPE_ARRAY,
302 simple_convert[dst_idx].type | DBTYPE_ARRAY, hr, expect ? "" : "not ");
304 /* src DBTYPE_VECTOR */
305 hr = IDataConvert_CanConvert(convert, simple_convert[src_idx].type | DBTYPE_VECTOR, simple_convert[dst_idx].type);
306 ok(hr == S_FALSE,
307 "%04x -> %04x: got %08x expect conversion to not be possible\n", simple_convert[src_idx].type | DBTYPE_VECTOR,
308 simple_convert[dst_idx].type, hr);
310 /* dst DBTYPE_VECTOR */
311 hr = IDataConvert_CanConvert(convert, simple_convert[src_idx].type, simple_convert[dst_idx].type | DBTYPE_VECTOR);
312 ok(hr == S_FALSE,
313 "%04x -> %04x: got %08x expect conversion to not be possible\n", simple_convert[src_idx].type,
314 simple_convert[dst_idx].type | DBTYPE_VECTOR, hr);
316 /* src & dst DBTYPE_VECTOR */
317 hr = IDataConvert_CanConvert(convert, simple_convert[src_idx].type | DBTYPE_VECTOR, simple_convert[dst_idx].type | DBTYPE_VECTOR);
318 ok(hr == S_FALSE,
319 "%04x -> %04x: got %08x expect conversion to not be possible\n", simple_convert[src_idx].type | DBTYPE_VECTOR,
320 simple_convert[dst_idx].type | DBTYPE_VECTOR, hr);
326 static void test_converttoi2(void)
328 HRESULT hr;
329 signed short dst;
330 BYTE src[20];
331 DBSTATUS dst_status;
332 DBLENGTH dst_len;
333 static const WCHAR ten[] = {'1','0',0};
334 BSTR b;
336 dst_len = dst = 0x1234;
337 hr = IDataConvert_DataConvert(convert, DBTYPE_EMPTY, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
338 ok(hr == S_OK, "got %08x\n", hr);
339 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
340 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
341 ok(dst == 0, "got %08x\n", dst);
343 dst_len = dst = 0x1234;
344 hr = IDataConvert_DataConvert(convert, DBTYPE_NULL, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
345 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr);
346 ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status);
347 ok(dst_len == 0x1234, "got %ld\n", dst_len);
348 ok(dst == 0x1234, "got %08x\n", dst);
350 dst_len = dst = 0x1234;
351 *(short *)src = 0x4321;
352 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
353 ok(hr == S_OK, "got %08x\n", hr);
354 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
355 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
356 ok(dst == 0x4321, "got %08x\n", dst);
358 dst_len = dst = 0x1234;
359 *(int *)src = 0x4321cafe;
360 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
361 todo_wine
362 ok(hr == DB_E_DATAOVERFLOW, "got %08x\n", hr);
363 ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
364 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
365 ok(dst == 0x1234, "got %08x\n", dst);
367 dst_len = dst = 0x1234;
368 *(int *)src = 0x4321;
369 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
370 ok(hr == S_OK, "got %08x\n", hr);
371 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
372 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
373 ok(dst == 0x4321, "got %08x\n", dst);
375 dst_len = dst = 0x1234;
376 *(FLOAT *)src = 10.75;
377 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
378 ok(hr == S_OK, "got %08x\n", hr);
379 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
380 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
381 ok(dst == 11, "got %08x\n", dst);
383 dst_len = dst = 0x1234;
384 *(FLOAT *)src = -10.75;
385 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
386 ok(hr == S_OK, "got %08x\n", hr);
387 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
388 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
389 ok(dst == -11, "got %08x\n", dst);
391 dst_len = dst = 0x1234;
392 *(double *)src = 10.75;
393 hr = IDataConvert_DataConvert(convert, DBTYPE_R8, 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 %ld\n", dst_len);
397 ok(dst == 11, "got %08x\n", dst);
399 dst_len = dst = 0x1234;
400 ((LARGE_INTEGER *)src)->QuadPart = 107500;
401 hr = IDataConvert_DataConvert(convert, DBTYPE_CY, 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 %ld\n", dst_len);
405 ok(dst == 11, "got %08x\n", dst);
407 dst_len = dst = 0x1234;
408 *(DATE *)src = 10.7500;
409 hr = IDataConvert_DataConvert(convert, DBTYPE_DATE, 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 %ld\n", dst_len);
413 ok(dst == 11, "got %08x\n", dst);
415 dst_len = dst = 0x1234;
416 b = SysAllocString(ten);
417 *(BSTR *)src = b;
418 hr = IDataConvert_DataConvert(convert, DBTYPE_BSTR, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
419 ok(hr == S_OK, "got %08x\n", hr);
420 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
421 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
422 ok(dst == 10, "got %08x\n", dst);
423 SysFreeString(b);
425 dst_len = dst = 0x1234;
426 *(SCODE *)src = 0x4321cafe;
427 hr = IDataConvert_DataConvert(convert, DBTYPE_ERROR, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
428 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr);
429 ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status);
430 ok(dst_len == 0x1234, "got %ld\n", dst_len);
431 ok(dst == 0x1234, "got %08x\n", dst);
433 dst_len = dst = 0x1234;
434 *(VARIANT_BOOL *)src = VARIANT_TRUE;
435 hr = IDataConvert_DataConvert(convert, DBTYPE_BOOL, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
436 ok(hr == S_OK, "got %08x\n", hr);
437 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
438 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
439 ok(dst == -1, "got %08x\n", dst);
441 dst_len = dst = 0x1234;
442 *(VARIANT_BOOL *)src = VARIANT_FALSE;
443 hr = IDataConvert_DataConvert(convert, DBTYPE_BOOL, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
444 ok(hr == S_OK, "got %08x\n", hr);
445 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
446 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
447 ok(dst == 0, "got %08x\n", dst);
449 dst_len = dst = 0x1234;
450 V_VT((VARIANT*)src) = VT_I2;
451 V_I2((VARIANT*)src) = 0x4321;
452 hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
453 ok(hr == S_OK, "got %08x\n", hr);
454 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
455 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
456 ok(dst == 0x4321, "got %08x\n", dst);
458 V_VT((VARIANT*)src) = VT_NULL;
459 dst_len = 0x1234;
460 hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
461 ok(hr == S_OK, "got %08x\n", hr);
462 ok(dst_status == DBSTATUS_S_ISNULL, "got %08x\n", dst_status);
463 ok(dst_len == 0x1234, "got %ld\n", dst_len);
465 dst_len = dst = 0x1234;
466 memset(src, 0, sizeof(DECIMAL));
467 ((DECIMAL*)src)->u1.Lo64 = 0x4321;
468 hr = IDataConvert_DataConvert(convert, DBTYPE_DECIMAL, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
469 ok(hr == S_OK, "got %08x\n", hr);
470 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
471 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
472 ok(dst == 0x4321, "got %08x\n", dst);
474 dst_len = dst = 0x1234;
475 *(signed char*)src = 0xab;
476 hr = IDataConvert_DataConvert(convert, DBTYPE_I1, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
477 ok(hr == S_OK, "got %08x\n", hr);
478 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
479 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
480 ok(dst == (signed short)0xffab, "got %08x\n", dst);
482 dst_len = dst = 0x1234;
483 *(BYTE*)src = 0xab;
484 hr = IDataConvert_DataConvert(convert, DBTYPE_UI1, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
485 ok(hr == S_OK, "got %08x\n", hr);
486 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
487 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
488 ok(dst == 0xab, "got %08x\n", dst);
490 dst_len = dst = 0x1234;
491 *(WORD*)src = 0x4321;
492 hr = IDataConvert_DataConvert(convert, DBTYPE_UI2, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
493 ok(hr == S_OK, "got %08x\n", hr);
494 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
495 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
496 ok(dst == 0x4321, "got %08x\n", dst);
498 dst_len = dst = 0x1234;
499 *(WORD*)src = 0xabcd;
500 hr = IDataConvert_DataConvert(convert, DBTYPE_UI2, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
501 ok(hr == DB_E_ERRORSOCCURRED, "got %08x\n", hr);
502 ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
503 todo_wine
504 ok(broken(dst_len == sizeof(dst)) || dst_len == 0x1234 /* W2K+ */, "got %ld\n", dst_len);
505 ok(dst == 0x1234, "got %08x\n", dst);
507 dst_len = dst = 0x1234;
508 *(DWORD*)src = 0xabcd1234;
509 hr = IDataConvert_DataConvert(convert, DBTYPE_UI4, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
510 todo_wine
511 ok(hr == DB_E_DATAOVERFLOW, "got %08x\n", hr);
512 ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
513 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
514 ok(dst == 0x1234, "got %08x\n", dst);
516 dst_len = dst = 0x1234;
517 *(DWORD*)src = 0x1234abcd;
518 hr = IDataConvert_DataConvert(convert, DBTYPE_UI4, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
519 todo_wine
520 ok(hr == DB_E_DATAOVERFLOW, "got %08x\n", hr);
521 ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
522 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
523 ok(dst == 0x1234, "got %08x\n", dst);
525 dst_len = dst = 0x1234;
526 *(DWORD*)src = 0x4321;
527 hr = IDataConvert_DataConvert(convert, DBTYPE_UI4, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
528 ok(hr == S_OK, "got %08x\n", hr);
529 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
530 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
531 ok(dst == 0x4321, "got %08x\n", dst);
533 dst_len = dst = 0x1234;
534 ((LARGE_INTEGER*)src)->QuadPart = 0x1234abcd;
535 hr = IDataConvert_DataConvert(convert, DBTYPE_I8, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
536 ok(hr == DB_E_ERRORSOCCURRED ||
537 broken(hr == DB_E_UNSUPPORTEDCONVERSION), /* win98 */
538 "got %08x\n", hr);
539 if(hr != DB_E_UNSUPPORTEDCONVERSION) /* win98 doesn't support I8/UI8 */
541 ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
542 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
543 ok(dst == 0x1234, "got %08x\n", dst);
545 dst_len = dst = 0x1234;
546 ((LARGE_INTEGER*)src)->QuadPart = 0x4321;
547 hr = IDataConvert_DataConvert(convert, DBTYPE_I8, 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 %ld\n", dst_len);
551 ok(dst == 0x4321, "got %08x\n", dst);
553 dst_len = dst = 0x1234;
554 ((ULARGE_INTEGER*)src)->QuadPart = 0x4321;
555 hr = IDataConvert_DataConvert(convert, DBTYPE_UI8, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
556 ok(hr == S_OK, "got %08x\n", hr);
557 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
558 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
559 ok(dst == 0x4321, "got %08x\n", dst);
562 dst_len = dst = 0x1234;
563 strcpy((char *)src, "10");
564 hr = IDataConvert_DataConvert(convert, DBTYPE_STR, DBTYPE_I2, 2, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
565 ok(hr == S_OK, "got %08x\n", hr);
566 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
567 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
568 ok(dst == 10, "got %08x\n", dst);
570 dst_len = dst = 0x1234;
571 strcpy((char *)src, "10");
572 hr = IDataConvert_DataConvert(convert, DBTYPE_STR, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, DBDATACONVERT_LENGTHFROMNTS);
573 ok(hr == S_OK, "got %08x\n", hr);
574 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
575 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
576 ok(dst == 10, "got %08x\n", dst);
578 dst_len = dst = 0x1234;
579 memcpy(src, ten, sizeof(ten));
580 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_I2, 4, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
581 ok(hr == S_OK, "got %08x\n", hr);
582 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
583 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
584 ok(dst == 10, "got %08x\n", dst);
586 dst_len = dst = 0x1234;
587 memcpy(src, ten, sizeof(ten));
588 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, DBDATACONVERT_LENGTHFROMNTS);
589 ok(hr == S_OK, "got %08x\n", hr);
590 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
591 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
592 ok(dst == 10, "got %08x\n", dst);
594 /* */
595 dst_len = dst = 0x1234;
596 *(WORD*)src = 0x4321;
597 hr = IDataConvert_DataConvert(convert, DBTYPE_UI2, DBTYPE_UI2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
598 ok(hr == S_OK, "got %08x\n", hr);
599 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
600 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
601 ok(dst == 0x4321, "got %08x\n", dst);
603 dst_len = dst = 0x1234;
604 *(DWORD*)src = 0xabcd1234;
605 hr = IDataConvert_DataConvert(convert, DBTYPE_UI4, DBTYPE_UI2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
606 todo_wine
607 ok(hr == DB_E_DATAOVERFLOW, "got %08x\n", hr);
608 ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
609 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
610 ok(dst == 0x1234, "got %08x\n", dst);
612 dst_len = dst = 0x1234;
613 *(DWORD*)src = 0x1234abcd;
614 hr = IDataConvert_DataConvert(convert, DBTYPE_UI4, DBTYPE_UI2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
615 todo_wine
616 ok(hr == DB_E_DATAOVERFLOW, "got %08x\n", hr);
617 ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
618 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
619 ok(dst == 0x1234, "got %08x\n", dst);
621 dst_len = dst = 0x1234;
622 *(DWORD*)src = 0x4321;
623 hr = IDataConvert_DataConvert(convert, DBTYPE_UI4, DBTYPE_UI2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
624 ok(hr == S_OK, "got %08x\n", hr);
625 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
626 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
627 ok(dst == 0x4321, "got %08x\n", dst);
629 dst_len = dst = 0x1234;
630 memcpy(src, ten, sizeof(ten));
631 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_UI2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, DBDATACONVERT_LENGTHFROMNTS);
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(dst), "got %ld\n", dst_len);
635 ok(dst == 10, "got %08x\n", dst);
638 static void test_converttoi4(void)
640 HRESULT hr;
641 INT i4;
642 BYTE src[20];
643 DBSTATUS dst_status;
644 DBLENGTH dst_len;
645 static const WCHAR ten[] = {'1','0',0};
646 BSTR b;
648 i4 = 0x12345678;
649 dst_len = 0x1234;
650 hr = IDataConvert_DataConvert(convert, DBTYPE_EMPTY, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
651 ok(hr == S_OK, "got %08x\n", hr);
652 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
653 ok(dst_len == sizeof(i4), "got %ld\n", dst_len);
654 ok(i4 == 0, "got %08x\n", i4);
656 i4 = 0x12345678;
657 dst_len = 0x1234;
658 hr = IDataConvert_DataConvert(convert, DBTYPE_NULL, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
659 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr);
660 ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status);
661 ok(dst_len == 0x1234, "got %ld\n", dst_len);
662 ok(i4 == 0x12345678, "got %08x\n", i4);
664 i4 = 0x12345678;
665 *(short *)src = 0x4321;
666 dst_len = 0x1234;
667 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
668 ok(hr == S_OK, "got %08x\n", hr);
669 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
670 ok(dst_len == sizeof(i4), "got %ld\n", dst_len);
671 ok(i4 == 0x4321, "got %08x\n", i4);
673 i4 = 0x12345678;
674 *(int *)src = 0x4321cafe;
675 dst_len = 0x1234;
676 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
677 ok(hr == S_OK, "got %08x\n", hr);
678 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
679 ok(dst_len == sizeof(i4), "got %ld\n", dst_len);
680 ok(i4 == 0x4321cafe, "got %08x\n", i4);
682 i4 = 0x12345678;
683 *(FLOAT *)src = 10.75;
684 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
685 ok(hr == S_OK, "got %08x\n", hr);
686 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
687 ok(dst_len == sizeof(i4), "got %ld\n", dst_len);
688 ok(i4 == 11, "got %08x\n", i4);
690 i4 = 0x12345678;
691 *(FLOAT *)src = -10.75;
692 dst_len = 0x1234;
693 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, 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 %ld\n", dst_len);
697 ok(i4 == -11, "got %08x\n", i4);
699 i4 = 0x12345678;
700 *(double *)src = 10.75;
701 dst_len = 0x1234;
702 hr = IDataConvert_DataConvert(convert, DBTYPE_R8, 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 %ld\n", dst_len);
706 ok(i4 == 11, "got %08x\n", i4);
708 i4 = 0x12345678;
709 ((LARGE_INTEGER *)src)->QuadPart = 107500;
710 dst_len = 0x1234;
711 hr = IDataConvert_DataConvert(convert, DBTYPE_CY, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
712 ok(hr == S_OK, "got %08x\n", hr);
713 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
714 ok(dst_len == sizeof(i4), "got %ld\n", dst_len);
715 ok(i4 == 11, "got %08x\n", i4);
717 i4 = 0x12345678;
718 *(DATE *)src = 10.7500;
719 dst_len = 0x1234;
720 hr = IDataConvert_DataConvert(convert, DBTYPE_DATE, 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 %ld\n", dst_len);
724 ok(i4 == 11, "got %08x\n", i4);
726 i4 = 0x12345678;
727 b = SysAllocString(ten);
728 *(BSTR *)src = b;
729 dst_len = 0x1234;
730 hr = IDataConvert_DataConvert(convert, DBTYPE_BSTR, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
731 ok(hr == S_OK, "got %08x\n", hr);
732 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
733 ok(dst_len == sizeof(i4), "got %ld\n", dst_len);
734 ok(i4 == 10, "got %08x\n", i4);
735 SysFreeString(b);
737 i4 = 0x12345678;
738 *(SCODE *)src = 0x4321cafe;
739 dst_len = 0x1234;
740 hr = IDataConvert_DataConvert(convert, DBTYPE_ERROR, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
741 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr);
742 ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status);
743 ok(dst_len == 0x1234, "got %ld\n", dst_len);
744 ok(i4 == 0x12345678, "got %08x\n", i4);
746 i4 = 0x12345678;
747 *(VARIANT_BOOL *)src = VARIANT_TRUE;
748 dst_len = 0x1234;
749 hr = IDataConvert_DataConvert(convert, DBTYPE_BOOL, 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 %ld\n", dst_len);
753 ok(i4 == 0xffffffff, "got %08x\n", i4);
755 i4 = 0x12345678;
756 *(VARIANT_BOOL *)src = VARIANT_FALSE;
757 dst_len = 0x1234;
758 hr = IDataConvert_DataConvert(convert, DBTYPE_BOOL, 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 %ld\n", dst_len);
762 ok(i4 == 0, "got %08x\n", i4);
764 i4 = 0x12345678;
765 V_VT((VARIANT*)src) = VT_I2;
766 V_I2((VARIANT*)src) = 0x1234;
767 dst_len = 0x1234;
768 hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
769 ok(hr == S_OK, "got %08x\n", hr);
770 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
771 ok(dst_len == sizeof(i4), "got %ld\n", dst_len);
772 ok(i4 == 0x1234, "got %08x\n", i4);
774 V_VT((VARIANT*)src) = VT_NULL;
775 dst_len = 0x1234;
776 hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
777 ok(hr == S_OK, "got %08x\n", hr);
778 ok(dst_status == DBSTATUS_S_ISNULL, "got %08x\n", dst_status);
779 ok(dst_len == 0x1234, "got %ld\n", dst_len);
781 i4 = 0x12345678;
782 memset(src, 0, sizeof(DECIMAL));
783 ((DECIMAL*)src)->u1.Lo64 = 0x1234;
784 dst_len = 0x1234;
785 hr = IDataConvert_DataConvert(convert, DBTYPE_DECIMAL, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
786 ok(hr == S_OK, "got %08x\n", hr);
787 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
788 ok(dst_len == sizeof(i4), "got %ld\n", dst_len);
789 ok(i4 == 0x1234, "got %08x\n", i4);
791 i4 = 0x12345678;
792 *(signed char*)src = 0xab;
793 dst_len = 0x1234;
794 hr = IDataConvert_DataConvert(convert, DBTYPE_I1, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
795 ok(hr == S_OK, "got %08x\n", hr);
796 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
797 ok(dst_len == sizeof(i4), "got %ld\n", dst_len);
798 ok(i4 == 0xffffffab, "got %08x\n", i4);
800 i4 = 0x12345678;
801 *(BYTE*)src = 0xab;
802 dst_len = 0x1234;
803 hr = IDataConvert_DataConvert(convert, DBTYPE_UI1, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
804 ok(hr == S_OK, "got %08x\n", hr);
805 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
806 ok(dst_len == sizeof(i4), "got %ld\n", dst_len);
807 ok(i4 == 0xab, "got %08x\n", i4);
809 i4 = 0x12345678;
810 *(WORD*)src = 0xabcd;
811 dst_len = 0x1234;
812 hr = IDataConvert_DataConvert(convert, DBTYPE_UI2, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
813 ok(hr == S_OK, "got %08x\n", hr);
814 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
815 ok(dst_len == sizeof(i4), "got %ld\n", dst_len);
816 ok(i4 == 0xabcd, "got %08x\n", i4);
818 i4 = 0x12345678;
819 *(DWORD*)src = 0xabcd1234;
820 dst_len = 0x1234;
821 hr = IDataConvert_DataConvert(convert, DBTYPE_UI4, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
822 ok(hr == DB_E_ERRORSOCCURRED, "got %08x\n", hr);
823 ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
824 todo_wine
825 ok(broken(dst_len == sizeof(i4)) || dst_len == 0x1234 /* W2K+ */, "got %ld\n", dst_len);
826 ok(i4 == 0x12345678, "got %08x\n", i4);
828 i4 = 0x12345678;
829 *(DWORD*)src = 0x1234abcd;
830 dst_len = 0x1234;
831 hr = IDataConvert_DataConvert(convert, DBTYPE_UI4, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
832 ok(hr == S_OK, "got %08x\n", hr);
833 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
834 ok(dst_len == sizeof(i4), "got %ld\n", dst_len);
835 ok(i4 == 0x1234abcd, "got %08x\n", i4);
837 i4 = 0x12345678;
838 ((LARGE_INTEGER*)src)->QuadPart = 0x1234abcd;
839 dst_len = 0x1234;
840 hr = IDataConvert_DataConvert(convert, DBTYPE_I8, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
841 ok(hr == S_OK ||
842 broken(hr == DB_E_UNSUPPORTEDCONVERSION), /* win98 */
843 "got %08x\n", hr);
844 if(hr != DB_E_UNSUPPORTEDCONVERSION) /* win98 doesn't support I8/UI8 */
846 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
847 ok(dst_len == sizeof(i4), "got %ld\n", dst_len);
848 ok(i4 == 0x1234abcd, "got %08x\n", i4);
850 i4 = 0x12345678;
851 ((ULARGE_INTEGER*)src)->QuadPart = 0x1234abcd;
852 dst_len = 0x1234;
853 hr = IDataConvert_DataConvert(convert, DBTYPE_UI8, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
854 ok(hr == S_OK, "got %08x\n", hr);
855 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
856 ok(dst_len == sizeof(i4), "got %ld\n", dst_len);
857 ok(i4 == 0x1234abcd, "got %08x\n", i4);
860 i4 = 0x12345678;
861 strcpy((char *)src, "10");
862 dst_len = 0x1234;
863 hr = IDataConvert_DataConvert(convert, DBTYPE_STR, DBTYPE_I4, 2, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
864 ok(hr == S_OK, "got %08x\n", hr);
865 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
866 ok(dst_len == sizeof(i4), "got %ld\n", dst_len);
867 ok(i4 == 10, "got %08x\n", i4);
869 i4 = 0x12345678;
870 strcpy((char *)src, "10");
871 dst_len = 0x1234;
872 hr = IDataConvert_DataConvert(convert, DBTYPE_STR, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, DBDATACONVERT_LENGTHFROMNTS);
873 ok(hr == S_OK, "got %08x\n", hr);
874 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
875 ok(dst_len == sizeof(i4), "got %ld\n", dst_len);
876 ok(i4 == 10, "got %08x\n", i4);
878 i4 = 0x12345678;
879 memcpy(src, ten, sizeof(ten));
880 dst_len = 0x1234;
881 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_I4, 4, &dst_len, src, &i4, sizeof(i4), 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(i4), "got %ld\n", dst_len);
885 ok(i4 == 10, "got %08x\n", i4);
887 i4 = 0x12345678;
888 memcpy(src, ten, sizeof(ten));
889 dst_len = 0x1234;
890 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, DBDATACONVERT_LENGTHFROMNTS);
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(i4), "got %ld\n", dst_len);
894 ok(i4 == 10, "got %08x\n", i4);
896 /* src_status = DBSTATUS_S_ISNULL */
897 i4 = 0x12345678;
898 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), DBSTATUS_S_ISNULL, &dst_status, 0, 0, 0);
899 ok(hr == S_OK, "got %08x\n", hr);
900 ok(dst_status == DBSTATUS_S_ISNULL, "got %08x\n", dst_status);
901 ok(dst_len == 0, "got %ld\n", dst_len);
903 /* dst = NULL */
904 *(int *)src = 0x4321cafe;
905 dst_len = 0x1234;
906 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_I4, 0, &dst_len, src, NULL, 0, 0, NULL, 0, 0, 0);
907 ok(hr == S_OK, "got %08x\n", hr);
908 ok(dst_len == sizeof(i4), "got %ld\n", dst_len);
912 static void test_converttoi8(void)
914 HRESULT hr;
915 LARGE_INTEGER dst;
916 BYTE src[20];
917 DBSTATUS dst_status;
918 DBLENGTH dst_len;
919 static const WCHAR ten[] = {'1','0',0};
920 BSTR b;
922 dst.QuadPart = 0xcc;
923 ((ULARGE_INTEGER*)src)->QuadPart = 1234;
924 dst_len = 0x1234;
925 hr = IDataConvert_DataConvert(convert, DBTYPE_I8, DBTYPE_I8, 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 == sizeof(dst), "got %ld\n", dst_len);
929 ok(dst.QuadPart == 1234, "got %d\n", (int)dst.QuadPart);
931 dst.QuadPart = 0xcc;
932 ((ULARGE_INTEGER*)src)->QuadPart = 1234;
933 b = SysAllocString(ten);
934 *(BSTR *)src = b;
935 hr = IDataConvert_DataConvert(convert, DBTYPE_BSTR, DBTYPE_I8, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
936 ok(hr == S_OK, "got %08x\n", hr);
937 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
938 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
939 ok(dst.QuadPart == 10, "got %d\n", (int)dst.QuadPart);
940 SysFreeString(b);
942 V_VT((VARIANT*)src) = VT_NULL;
943 dst_len = 0x1234;
944 hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_I8, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
945 ok(hr == S_OK, "got %08x\n", hr);
946 ok(dst_status == DBSTATUS_S_ISNULL, "got %08x\n", dst_status);
947 ok(dst_len == 0x1234, "got %ld\n", dst_len);
950 static void test_converttobstr(void)
952 HRESULT hr;
953 BSTR dst;
954 BYTE src[20];
955 DBSTATUS dst_status;
956 DBLENGTH dst_len;
957 static const WCHAR ten[] = {'1','0',0};
958 static const WCHAR tsW[] = {'2','0','1','3','-','0','5','-','1','4',' ','0','2',':','0','4',':','1','2',0};
959 static const WCHAR ts1W[] = {'2','0','1','3','-','0','5','-','1','4',' ','0','2',':','0','4',':','1','2','.','0','0','0','0','0','0','0','0','3',0};
960 static const WCHAR ts2W[] = {'2','0','1','3','-','0','5','-','1','4',' ','0','2',':','0','4',':','1','2','.','0','0','0','0','0','0','2','0','0',0};
961 DBTIMESTAMP ts = {2013, 5, 14, 2, 4, 12, 0};
962 VARIANT v;
963 BSTR b;
965 dst_len = 0x1234;
966 hr = IDataConvert_DataConvert(convert, DBTYPE_EMPTY, DBTYPE_BSTR, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
967 ok(hr == S_OK, "got %08x\n", hr);
968 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
969 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
970 ok(dst != NULL, "got %p\n", dst);
971 ok(SysStringLen(dst) == 0, "got %d\n", SysStringLen(dst));
972 SysFreeString(dst);
974 dst = (void*)0x1234;
975 hr = IDataConvert_DataConvert(convert, DBTYPE_NULL, DBTYPE_BSTR, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
976 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr);
977 ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status);
978 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
979 ok(dst == (void*)0x1234, "got %p\n", dst);
981 *(short *)src = 4321;
982 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_BSTR, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
983 ok(hr == S_OK, "got %08x\n", hr);
984 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
985 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
986 ok(dst != NULL, "got %p\n", dst);
987 ok(SysStringLen(dst) == 4, "got %d\n", SysStringLen(dst));
988 SysFreeString(dst);
990 b = SysAllocString(ten);
991 *(BSTR *)src = b;
992 hr = IDataConvert_DataConvert(convert, DBTYPE_BSTR, DBTYPE_BSTR, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
993 ok(hr == S_OK, "got %08x\n", hr);
994 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
995 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
996 ok(dst != NULL, "got %p\n", dst);
997 ok(dst != b, "got %p src %p\n", dst, b);
998 ok(!lstrcmpW(b, dst), "got %s\n", wine_dbgstr_w(dst));
999 SysFreeString(dst);
1000 SysFreeString(b);
1002 b = SysAllocString(ten);
1003 V_VT(&v) = VT_BSTR;
1004 V_BSTR(&v) = b;
1005 hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_BSTR, 0, &dst_len, &v, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1006 ok(hr == S_OK, "got %08x\n", hr);
1007 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1008 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
1009 ok(dst != NULL, "got %p\n", dst);
1010 ok(dst != b, "got %p src %p\n", dst, b);
1011 ok(!lstrcmpW(b, dst), "got %s\n", wine_dbgstr_w(dst));
1012 SysFreeString(dst);
1013 SysFreeString(b);
1015 V_VT(&v) = VT_NULL;
1016 dst = (void*)0x1234;
1017 dst_len = 33;
1018 hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_BSTR, 0, &dst_len, &v, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1019 ok(hr == S_OK, "got %08x\n", hr);
1020 ok(dst_status == DBSTATUS_S_ISNULL, "got %08x\n", dst_status);
1021 ok(dst_len == 33, "got %ld\n", dst_len);
1022 ok(dst == (void*)0x1234, "got %p\n", dst);
1024 dst_len = 0x1234;
1025 hr = IDataConvert_DataConvert(convert, DBTYPE_DBTIMESTAMP, DBTYPE_BSTR, 0, &dst_len, &ts, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1026 ok(hr == S_OK, "got %08x\n", hr);
1027 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1028 ok(dst_len == sizeof(BSTR), "got %ld\n", dst_len);
1029 ok(!lstrcmpW(tsW, dst), "got %s\n", wine_dbgstr_w(dst));
1030 SysFreeString(dst);
1032 dst_len = 0x1234;
1033 ts.fraction = 3;
1034 hr = IDataConvert_DataConvert(convert, DBTYPE_DBTIMESTAMP, DBTYPE_BSTR, 0, &dst_len, &ts, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1035 ok(hr == S_OK, "got %08x\n", hr);
1036 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1037 ok(dst_len == sizeof(BSTR), "got %ld\n", dst_len);
1038 ok(!lstrcmpW(ts1W, dst), "got %s\n", wine_dbgstr_w(dst));
1039 SysFreeString(dst);
1041 dst_len = 0x1234;
1042 ts.fraction = 200;
1043 hr = IDataConvert_DataConvert(convert, DBTYPE_DBTIMESTAMP, DBTYPE_BSTR, 0, &dst_len, &ts, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1044 ok(hr == S_OK, "got %08x\n", hr);
1045 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1046 ok(dst_len == sizeof(BSTR), "got %ld\n", dst_len);
1047 ok(!lstrcmpW(ts2W, dst), "got %s\n", wine_dbgstr_w(dst));
1048 SysFreeString(dst);
1051 static void test_converttowstr(void)
1053 HRESULT hr;
1054 WCHAR dst[100];
1055 BYTE src[20];
1056 DBSTATUS dst_status;
1057 DBLENGTH dst_len;
1058 static const WCHAR ten[] = {'1','0',0};
1059 static const WCHAR fourthreetwoone[] = {'4','3','2','1',0};
1060 static const WCHAR guid_str[] = {
1061 '{','0','C','7','3','3','A','8','D','-','2','A','1','C','-','1','1','C','E','-',
1062 'A','D','E','5','-','0','0','A','A','0','0','4','4','7','7','3','D','}',0};
1063 static const WCHAR hexunpacked_w[] = {'5','7','0','0','6','9','0','0','6','E','0','0','6','5','0','0','0','0','0','0', 0 };
1064 static const WCHAR hexpacked_w[] = {'W','i','n','e', 0 };
1065 static const WCHAR tsW[] = {'2','0','1','3','-','0','5','-','1','4',' ','0','2',':','0','4',':','1','2',0};
1066 static const WCHAR ts1W[] = {'2','0','1','3','-','0','5','-','1','4',' ','0','2',':','0','4',':','1','2','.','0','0','0','0','0','0','0','0','3',0};
1067 static const WCHAR ts2W[] = {'2','0','1','3','-','0','5','-','1','4',' ','0','2',':','0','4',':','1','2','.','0','0','0','0','0','0','2','0','0',0};
1068 DBTIMESTAMP ts = {2013, 5, 14, 2, 4, 12, 0};
1069 BSTR b;
1070 VARIANT v;
1072 VariantInit(&v);
1074 memset(dst, 0xcc, sizeof(dst));
1075 dst_len = 0x1234;
1076 hr = IDataConvert_DataConvert(convert, DBTYPE_EMPTY, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1077 ok(hr == S_OK, "got %08x\n", hr);
1078 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1079 ok(dst_len == 0, "got %ld\n", dst_len);
1080 ok(dst[0] == 0, "got %02x\n", dst[0]);
1081 ok(dst[1] == 0xcccc, "got %02x\n", dst[1]);
1083 memset(dst, 0xcc, sizeof(dst));
1084 dst_len = 0x1234;
1085 hr = IDataConvert_DataConvert(convert, DBTYPE_NULL, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1086 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr);
1087 ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status);
1088 ok(dst_len == 0x1234, "got %ld\n", dst_len);
1089 ok(dst[0] == 0xcccc, "got %02x\n", dst[0]);
1091 *(short *)src = 4321;
1092 dst_len = 0x1234;
1093 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1094 ok(hr == S_OK, "got %08x\n", hr);
1095 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1096 ok(dst_len == 8, "got %ld\n", dst_len);
1097 ok(!lstrcmpW(dst, fourthreetwoone), "got %s\n", wine_dbgstr_w(dst));
1099 *(short *)src = 4321;
1100 memset(dst, 0xcc, sizeof(dst));
1101 dst_len = 0x1234;
1102 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_WSTR, 0, &dst_len, src, dst, 0, 0, &dst_status, 0, 0, 0);
1103 ok(hr == DB_E_ERRORSOCCURRED, "got %08x\n", hr);
1104 ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
1105 ok(dst_len == 8, "got %ld\n", dst_len);
1106 ok(dst[0] == 0xcccc, "got %02x\n", dst[0]);
1108 *(short *)src = 4321;
1109 memset(dst, 0xcc, sizeof(dst));
1110 dst_len = 0x1234;
1111 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_WSTR, 0, &dst_len, src, NULL, 0, 0, &dst_status, 0, 0, 0);
1112 ok(hr == S_OK, "got %08x\n", hr);
1113 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1114 ok(dst_len == 8, "got %ld\n", dst_len);
1115 ok(dst[0] == 0xcccc, "got %02x\n", dst[0]);
1117 *(short *)src = 4321;
1118 memset(dst, 0xcc, sizeof(dst));
1119 dst_len = 0x1234;
1120 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_WSTR, 0, &dst_len, src, dst, 4, 0, &dst_status, 0, 0, 0);
1121 ok(hr == S_OK, "got %08x\n", hr);
1122 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1123 ok(dst_len == 8, "got %ld\n", dst_len);
1124 ok(dst[0] == '4', "got %02x\n", dst[0]);
1125 ok(dst[1] == 0, "got %02x\n", dst[1]);
1126 ok(dst[2] == 0xcccc, "got %02x\n", dst[2]);
1128 *(short *)src = 4321;
1129 memset(dst, 0xcc, sizeof(dst));
1130 dst_len = 0x1234;
1131 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_WSTR, 0, &dst_len, src, dst, 2, 0, &dst_status, 0, 0, 0);
1132 ok(hr == S_OK, "got %08x\n", hr);
1133 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1134 ok(dst_len == 8, "got %ld\n", dst_len);
1135 ok(dst[0] == 0, "got %02x\n", dst[0]);
1136 ok(dst[1] == 0xcccc, "got %02x\n", dst[1]);
1138 *(short *)src = 4321;
1139 memset(dst, 0xcc, sizeof(dst));
1140 dst_len = 0x1234;
1141 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_WSTR, 0, &dst_len, src, dst, 8, 0, &dst_status, 0, 0, 0);
1142 ok(hr == S_OK, "got %08x\n", hr);
1143 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1144 ok(dst_len == 8, "got %ld\n", dst_len);
1145 ok(dst[0] == '4', "got %02x\n", dst[0]);
1146 ok(dst[1] == '3', "got %02x\n", dst[1]);
1147 ok(dst[2] == '2', "got %02x\n", dst[2]);
1148 ok(dst[3] == 0, "got %02x\n", dst[3]);
1149 ok(dst[4] == 0xcccc, "got %02x\n", dst[4]);
1153 *(int *)src = 4321;
1154 dst_len = 0x1234;
1155 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1156 ok(hr == S_OK, "got %08x\n", hr);
1157 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1158 ok(dst_len == 8, "got %ld\n", dst_len);
1159 ok(!lstrcmpW(dst, fourthreetwoone), "got %s\n", wine_dbgstr_w(dst));
1161 *(int *)src = 4321;
1162 memset(dst, 0xcc, sizeof(dst));
1163 dst_len = 0x1234;
1164 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_WSTR, 0, &dst_len, src, dst, 0, 0, &dst_status, 0, 0, 0);
1165 ok(hr == DB_E_ERRORSOCCURRED, "got %08x\n", hr);
1166 ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
1167 ok(dst_len == 8, "got %ld\n", dst_len);
1168 ok(dst[0] == 0xcccc, "got %02x\n", dst[0]);
1170 *(int *)src = 4321;
1171 memset(dst, 0xcc, sizeof(dst));
1172 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_WSTR, 0, &dst_len, src, NULL, 0, 0, &dst_status, 0, 0, 0);
1173 ok(hr == S_OK, "got %08x\n", hr);
1174 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1175 ok(dst_len == 8, "got %ld\n", dst_len);
1176 ok(dst[0] == 0xcccc, "got %02x\n", dst[0]);
1178 *(int *)src = 4321;
1179 memset(dst, 0xcc, sizeof(dst));
1180 dst_len = 0x1234;
1181 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_WSTR, 0, &dst_len, src, dst, 4, 0, &dst_status, 0, 0, 0);
1182 ok(hr == S_OK, "got %08x\n", hr);
1183 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1184 ok(dst_len == 8, "got %ld\n", dst_len);
1185 ok(dst[0] == '4', "got %02x\n", dst[0]);
1186 ok(dst[1] == 0, "got %02x\n", dst[1]);
1187 ok(dst[2] == 0xcccc, "got %02x\n", dst[2]);
1189 *(int *)src = 4321;
1190 memset(dst, 0xcc, sizeof(dst));
1191 dst_len = 0x1234;
1192 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_WSTR, 0, &dst_len, src, dst, 2, 0, &dst_status, 0, 0, 0);
1193 ok(hr == S_OK, "got %08x\n", hr);
1194 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1195 ok(dst_len == 8, "got %ld\n", dst_len);
1196 ok(dst[0] == 0, "got %02x\n", dst[0]);
1197 ok(dst[1] == 0xcccc, "got %02x\n", dst[1]);
1199 *(int *)src = 4321;
1200 memset(dst, 0xcc, sizeof(dst));
1201 dst_len = 0x1234;
1202 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_WSTR, 0, &dst_len, src, dst, 8, 0, &dst_status, 0, 0, 0);
1203 ok(hr == S_OK, "got %08x\n", hr);
1204 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1205 ok(dst_len == 8, "got %ld\n", dst_len);
1206 ok(dst[0] == '4', "got %02x\n", dst[0]);
1207 ok(dst[1] == '3', "got %02x\n", dst[1]);
1208 ok(dst[2] == '2', "got %02x\n", dst[2]);
1209 ok(dst[3] == 0, "got %02x\n", dst[3]);
1210 ok(dst[4] == 0xcccc, "got %02x\n", dst[4]);
1214 *(float *)src = 4321;
1215 dst_len = 0x1234;
1216 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1217 ok(hr == S_OK, "got %08x\n", hr);
1218 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1219 ok(dst_len == 8, "got %ld\n", dst_len);
1220 ok(!lstrcmpW(dst, fourthreetwoone), "got %s\n", wine_dbgstr_w(dst));
1222 *(float *)src = 4321;
1223 memset(dst, 0xcc, sizeof(dst));
1224 dst_len = 0x1234;
1225 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_WSTR, 0, &dst_len, src, dst, 0, 0, &dst_status, 0, 0, 0);
1226 ok(hr == DB_E_ERRORSOCCURRED, "got %08x\n", hr);
1227 ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
1228 ok(dst_len == 8, "got %ld\n", dst_len);
1229 ok(dst[0] == 0xcccc, "got %02x\n", dst[0]);
1231 *(float *)src = 4321;
1232 memset(dst, 0xcc, sizeof(dst));
1233 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_WSTR, 0, &dst_len, src, NULL, 0, 0, &dst_status, 0, 0, 0);
1234 ok(hr == S_OK, "got %08x\n", hr);
1235 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1236 ok(dst_len == 8, "got %ld\n", dst_len);
1237 ok(dst[0] == 0xcccc, "got %02x\n", dst[0]);
1239 *(float *)src = 4321;
1240 memset(dst, 0xcc, sizeof(dst));
1241 dst_len = 0x1234;
1242 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_WSTR, 0, &dst_len, src, dst, 4, 0, &dst_status, 0, 0, 0);
1243 ok(hr == S_OK, "got %08x\n", hr);
1244 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1245 ok(dst_len == 8, "got %ld\n", dst_len);
1246 ok(dst[0] == '4', "got %02x\n", dst[0]);
1247 ok(dst[1] == 0, "got %02x\n", dst[1]);
1248 ok(dst[2] == 0xcccc, "got %02x\n", dst[2]);
1250 *(float *)src = 4321;
1251 memset(dst, 0xcc, sizeof(dst));
1252 dst_len = 0x1234;
1253 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_WSTR, 0, &dst_len, src, dst, 2, 0, &dst_status, 0, 0, 0);
1254 ok(hr == S_OK, "got %08x\n", hr);
1255 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1256 ok(dst_len == 8, "got %ld\n", dst_len);
1257 ok(dst[0] == 0, "got %02x\n", dst[0]);
1258 ok(dst[1] == 0xcccc, "got %02x\n", dst[1]);
1260 *(float *)src = 4321;
1261 memset(dst, 0xcc, sizeof(dst));
1262 dst_len = 0x1234;
1263 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_WSTR, 0, &dst_len, src, dst, 8, 0, &dst_status, 0, 0, 0);
1264 ok(hr == S_OK, "got %08x\n", hr);
1265 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1266 ok(dst_len == 8, "got %ld\n", dst_len);
1267 ok(dst[0] == '4', "got %02x\n", dst[0]);
1268 ok(dst[1] == '3', "got %02x\n", dst[1]);
1269 ok(dst[2] == '2', "got %02x\n", dst[2]);
1270 ok(dst[3] == 0, "got %02x\n", dst[3]);
1271 ok(dst[4] == 0xcccc, "got %02x\n", dst[4]);
1275 *(double *)src = 4321;
1276 dst_len = 0x1234;
1277 hr = IDataConvert_DataConvert(convert, DBTYPE_R8, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1278 ok(hr == S_OK, "got %08x\n", hr);
1279 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1280 ok(dst_len == 8, "got %ld\n", dst_len);
1281 ok(!lstrcmpW(dst, fourthreetwoone), "got %s\n", wine_dbgstr_w(dst));
1283 *(double *)src = 4321;
1284 memset(dst, 0xcc, sizeof(dst));
1285 hr = IDataConvert_DataConvert(convert, DBTYPE_R8, DBTYPE_WSTR, 0, &dst_len, src, dst, 0, 0, &dst_status, 0, 0, 0);
1286 ok(hr == DB_E_ERRORSOCCURRED, "got %08x\n", hr);
1287 ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
1288 ok(dst_len == 8, "got %ld\n", dst_len);
1289 ok(dst[0] == 0xcccc, "got %02x\n", dst[0]);
1291 *(double *)src = 4321;
1292 memset(dst, 0xcc, sizeof(dst));
1293 dst_len = 0x1234;
1294 hr = IDataConvert_DataConvert(convert, DBTYPE_R8, DBTYPE_WSTR, 0, &dst_len, src, NULL, 0, 0, &dst_status, 0, 0, 0);
1295 ok(hr == S_OK, "got %08x\n", hr);
1296 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1297 ok(dst_len == 8, "got %ld\n", dst_len);
1298 ok(dst[0] == 0xcccc, "got %02x\n", dst[0]);
1300 *(double *)src = 4321;
1301 memset(dst, 0xcc, sizeof(dst));
1302 dst_len = 0x1234;
1303 hr = IDataConvert_DataConvert(convert, DBTYPE_R8, DBTYPE_WSTR, 0, &dst_len, src, dst, 4, 0, &dst_status, 0, 0, 0);
1304 ok(hr == S_OK, "got %08x\n", hr);
1305 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1306 ok(dst_len == 8, "got %ld\n", dst_len);
1307 ok(dst[0] == '4', "got %02x\n", dst[0]);
1308 ok(dst[1] == 0, "got %02x\n", dst[1]);
1309 ok(dst[2] == 0xcccc, "got %02x\n", dst[2]);
1311 *(double *)src = 4321;
1312 memset(dst, 0xcc, sizeof(dst));
1313 dst_len = 0x1234;
1314 hr = IDataConvert_DataConvert(convert, DBTYPE_R8, DBTYPE_WSTR, 0, &dst_len, src, dst, 2, 0, &dst_status, 0, 0, 0);
1315 ok(hr == S_OK, "got %08x\n", hr);
1316 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1317 ok(dst_len == 8, "got %ld\n", dst_len);
1318 ok(dst[0] == 0, "got %02x\n", dst[0]);
1319 ok(dst[1] == 0xcccc, "got %02x\n", dst[1]);
1321 *(double *)src = 4321;
1322 memset(dst, 0xcc, sizeof(dst));
1323 dst_len = 0x1234;
1324 hr = IDataConvert_DataConvert(convert, DBTYPE_R8, DBTYPE_WSTR, 0, &dst_len, src, dst, 8, 0, &dst_status, 0, 0, 0);
1325 ok(hr == S_OK, "got %08x\n", hr);
1326 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1327 ok(dst_len == 8, "got %ld\n", dst_len);
1328 ok(dst[0] == '4', "got %02x\n", dst[0]);
1329 ok(dst[1] == '3', "got %02x\n", dst[1]);
1330 ok(dst[2] == '2', "got %02x\n", dst[2]);
1331 ok(dst[3] == 0, "got %02x\n", dst[3]);
1332 ok(dst[4] == 0xcccc, "got %02x\n", dst[4]);
1336 memset(src, 0, sizeof(src));
1337 ((CY*)src)->int64 = 43210000;
1338 memset(dst, 0xcc, sizeof(dst));
1339 dst_len = 0x1234;
1340 hr = IDataConvert_DataConvert(convert, DBTYPE_CY, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1341 ok(hr == S_OK, "got %08x\n", hr);
1342 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1343 ok(dst_len == 8, "got %ld\n", dst_len);
1344 ok(!lstrcmpW(dst, fourthreetwoone), "got %s\n", wine_dbgstr_w(dst));
1348 memset(src, 0, sizeof(src));
1349 *(signed char *)src = 10;
1350 dst_len = 0x1234;
1351 hr = IDataConvert_DataConvert(convert, DBTYPE_I1, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1352 ok(hr == S_OK, "got %08x\n", hr);
1353 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1354 ok(dst_len == 4, "got %ld\n", dst_len);
1355 ok(!lstrcmpW(dst, ten), "got %s\n", wine_dbgstr_w(dst));
1357 memset(src, 0, sizeof(src));
1358 *(unsigned char *)src = 10;
1359 dst_len = 0x1234;
1360 hr = IDataConvert_DataConvert(convert, DBTYPE_UI1, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1361 ok(hr == S_OK, "got %08x\n", hr);
1362 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1363 ok(dst_len == 4, "got %ld\n", dst_len);
1364 ok(!lstrcmpW(dst, ten), "got %s\n", wine_dbgstr_w(dst));
1366 memset(src, 0, sizeof(src));
1367 *(unsigned short *)src = 4321;
1368 dst_len = 0x1234;
1369 hr = IDataConvert_DataConvert(convert, DBTYPE_UI2, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1370 ok(hr == S_OK, "got %08x\n", hr);
1371 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1372 ok(dst_len == 8, "got %ld\n", dst_len);
1373 ok(!lstrcmpW(dst, fourthreetwoone), "got %s\n", wine_dbgstr_w(dst));
1375 memset(src, 0, sizeof(src));
1376 *(unsigned int *)src = 4321;
1377 dst_len = 0x1234;
1378 hr = IDataConvert_DataConvert(convert, DBTYPE_UI4, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1379 ok(hr == S_OK, "got %08x\n", hr);
1380 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1381 ok(dst_len == 8, "got %ld\n", dst_len);
1382 ok(!lstrcmpW(dst, fourthreetwoone), "got %s\n", wine_dbgstr_w(dst));
1384 memset(src, 0, sizeof(src));
1385 ((LARGE_INTEGER*)src)->QuadPart = 4321;
1386 dst_len = 0x1234;
1387 hr = IDataConvert_DataConvert(convert, DBTYPE_I8, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1388 ok(broken(hr == DB_E_UNSUPPORTEDCONVERSION) || hr == S_OK /* W2K+ */, "got %08x\n", hr);
1389 ok(broken(dst_status == DBSTATUS_E_BADACCESSOR) || dst_status == DBSTATUS_S_OK /* W2K+ */, "got %08x\n", dst_status);
1390 ok(broken(dst_len == 0x1234) || dst_len == 8 /* W2K+ */, "got %ld\n", dst_len);
1391 ok(!lstrcmpW(dst, fourthreetwoone), "got %s\n", wine_dbgstr_w(dst));
1393 memset(src, 0, sizeof(src));
1394 ((ULARGE_INTEGER*)src)->QuadPart = 4321;
1395 hr = IDataConvert_DataConvert(convert, DBTYPE_UI8, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1396 ok(broken(hr == DB_E_UNSUPPORTEDCONVERSION) || hr == S_OK /* W2K+ */, "got %08x\n", hr);
1397 ok(broken(dst_status == DBSTATUS_E_BADACCESSOR) || dst_status == DBSTATUS_S_OK /* W2K+ */, "got %08x\n", dst_status);
1398 ok(broken(dst_len == 0x1234) || dst_len == 8 /* W2K+ */, "got %ld\n", dst_len);
1399 ok(!lstrcmpW(dst, fourthreetwoone), "got %s\n", wine_dbgstr_w(dst));
1403 memset(src, 0, sizeof(src));
1404 memcpy(src, &IID_IDataConvert, sizeof(GUID));
1405 memset(dst, 0xcc, sizeof(dst));
1406 dst_len = 0x1234;
1407 hr = IDataConvert_DataConvert(convert, DBTYPE_GUID, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1408 ok(hr == S_OK, "got %08x\n", hr);
1409 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1410 ok(dst_len == 76, "got %ld\n", dst_len);
1411 ok(!lstrcmpW(dst, guid_str), "got %s\n", wine_dbgstr_w(dst));
1415 b = SysAllocString(ten);
1416 *(BSTR *)src = b;
1417 dst_len = 0x1234;
1418 hr = IDataConvert_DataConvert(convert, DBTYPE_BSTR, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1419 ok(hr == S_OK, "got %08x\n", hr);
1420 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1421 ok(dst_len == 4, "got %ld\n", dst_len);
1422 ok(!lstrcmpW(b, dst), "got %s\n", wine_dbgstr_w(dst));
1423 SysFreeString(b);
1425 memcpy(src, ten, sizeof(ten));
1426 dst_len = 0x1234;
1427 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_WSTR, 2, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1428 ok(hr == S_OK, "got %08x\n", hr);
1429 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1430 ok(dst_len == 2, "got %ld\n", dst_len);
1431 ok(dst[0] == '1', "got %02x\n", dst[0]);
1432 ok(dst[1] == 0, "got %02x\n", dst[1]);
1434 memcpy(src, ten, sizeof(ten));
1435 dst_len = 0x1234;
1436 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_WSTR, 4, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1437 ok(hr == S_OK, "got %08x\n", hr);
1438 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1439 ok(dst_len == 4, "got %ld\n", dst_len);
1440 ok(!lstrcmpW(ten, dst), "got %s\n", wine_dbgstr_w(dst));
1442 memcpy(src, ten, sizeof(ten));
1443 dst_len = 0x1234;
1444 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, DBDATACONVERT_LENGTHFROMNTS);
1445 ok(hr == S_OK, "got %08x\n", hr);
1446 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1447 ok(dst_len == 4, "got %ld\n", dst_len);
1448 ok(!lstrcmpW(ten, dst), "got %s\n", wine_dbgstr_w(dst));
1450 dst_len = 0x1234;
1451 hr = IDataConvert_DataConvert(convert, DBTYPE_DBTIMESTAMP, DBTYPE_WSTR, 0, &dst_len, &ts, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1452 ok(hr == S_OK, "got %08x\n", hr);
1453 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1454 ok(dst_len == 38, "got %ld\n", dst_len);
1455 ok(!lstrcmpW(tsW, dst), "got %s\n", wine_dbgstr_w(dst));
1457 dst_len = 0x1234;
1458 ts.fraction = 3;
1459 hr = IDataConvert_DataConvert(convert, DBTYPE_DBTIMESTAMP, DBTYPE_WSTR, 0, &dst_len, &ts, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1460 ok(hr == S_OK, "got %08x\n", hr);
1461 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1462 ok(dst_len == 58, "got %ld\n", dst_len);
1463 ok(!lstrcmpW(ts1W, dst), "got %s\n", wine_dbgstr_w(dst));
1465 dst_len = 0x1234;
1466 ts.fraction = 200;
1467 hr = IDataConvert_DataConvert(convert, DBTYPE_DBTIMESTAMP, DBTYPE_WSTR, 0, &dst_len, &ts, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1468 ok(hr == S_OK, "got %08x\n", hr);
1469 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1470 ok(dst_len == 58, "got %ld\n", dst_len);
1471 ok(!lstrcmpW(ts2W, dst), "got %s\n", wine_dbgstr_w(dst));
1473 /* DBTYPE_BYTES to DBTYPE_*STR unpacks binary data into a hex string */
1474 memcpy(src, hexpacked_w, sizeof(hexpacked_w));
1475 memset(dst, 0xcc, sizeof(dst));
1476 dst_len = 0x1234;
1477 hr = IDataConvert_DataConvert(convert, DBTYPE_BYTES, DBTYPE_WSTR, sizeof(hexpacked_w), &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1478 ok(hr == S_OK, "got %08x\n", hr);
1479 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1480 ok(dst_len == sizeof(hexpacked_w) * 4, "got %ld\n", dst_len);
1481 ok(!lstrcmpW(hexunpacked_w, dst), "got %s\n", wine_dbgstr_w(dst));
1482 ok(dst[sizeof(hexpacked_w)/sizeof(WCHAR) * 4 + 1] == 0xcccc, "clobbered buffer\n");
1484 memcpy(src, hexpacked_w, sizeof(hexpacked_w));
1485 memset(dst, 0xcc, sizeof(dst));
1486 dst_len = 0x1234;
1487 hr = IDataConvert_DataConvert(convert, DBTYPE_BYTES, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1488 ok(hr == S_OK, "got %08x\n", hr);
1489 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1490 ok(dst_len == 0, "got %ld\n", dst_len);
1491 ok(dst[0] == 0, "not null terminated\n");
1492 ok(dst[1] == 0xcccc, "clobbered buffer\n");
1494 memcpy(src, hexpacked_w, sizeof(hexpacked_w));
1495 memset(dst, 0xcc, sizeof(dst));
1496 dst_len = 0x1234;
1497 hr = IDataConvert_DataConvert(convert, DBTYPE_BYTES, DBTYPE_WSTR, 4, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1498 ok(hr == S_OK, "got %08x\n", hr);
1499 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1500 ok(dst_len == 2 * sizeof(WCHAR) * 4, "got %ld\n", dst_len);
1501 ok(!memcmp(hexunpacked_w, dst, 2 * sizeof(WCHAR) * 4 ), "got %s\n", wine_dbgstr_w(dst));
1502 ok(dst[2 * 4] == 0, "not null terminated\n");
1503 ok(dst[2 * 4 + 1] == 0xcccc, "clobbered buffer\n");
1505 memcpy(src, hexpacked_w, sizeof(hexpacked_w));
1506 memset(dst, 0xcc, sizeof(dst));
1507 dst_len = 0x1234;
1508 hr = IDataConvert_DataConvert(convert, DBTYPE_BYTES, DBTYPE_WSTR, sizeof(hexpacked_w), &dst_len, src, dst, 2 * sizeof(WCHAR) * 4 + sizeof(WCHAR), 0, &dst_status, 0, 0, 0);
1509 ok(hr == S_OK, "got %08x\n", hr);
1510 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1511 ok(dst_len == sizeof(hexpacked_w) * 4, "got %ld\n", dst_len);
1512 ok(!memcmp(hexunpacked_w, dst, 2 * sizeof(WCHAR) * 4 ), "got %s\n", wine_dbgstr_w(dst));
1513 ok(dst[2 * 4] == 0, "not null terminated\n");
1514 ok(dst[2 * 4 + 1] == 0xcccc, "clobbered buffer\n");
1516 memcpy(src, hexpacked_w, sizeof(hexpacked_w));
1517 memset(dst, 0xcc, sizeof(dst));
1518 dst_len = 0x1234;
1519 hr = IDataConvert_DataConvert(convert, DBTYPE_BYTES, DBTYPE_WSTR, sizeof(hexpacked_w), &dst_len, src, dst, 2 * sizeof(WCHAR) * 4 +1, 0, &dst_status, 0, 0, 0);
1520 ok(hr == S_OK, "got %08x\n", hr);
1521 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1522 ok(dst_len == sizeof(hexpacked_w) * 4, "got %ld\n", dst_len);
1523 ok(!memcmp(hexunpacked_w, dst, 2 * sizeof(WCHAR) * 4 - 2 ), "got %s\n", wine_dbgstr_w(dst));
1524 ok(dst[2 * 4 - 1] == 0, "not null terminated\n");
1525 ok(dst[2 * 4] == 0xcccc, "clobbered buffer\n");
1527 memcpy(src, hexpacked_w, sizeof(hexpacked_w));
1528 memset(dst, 0xcc, sizeof(dst));
1529 dst_len = 0x1234;
1530 hr = IDataConvert_DataConvert(convert, DBTYPE_BYTES, DBTYPE_WSTR, sizeof(hexpacked_w), &dst_len, src, dst, 2 * sizeof(WCHAR) * 4, 0, &dst_status, 0, 0, 0);
1531 ok(hr == S_OK, "got %08x\n", hr);
1532 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1533 ok(dst_len == sizeof(hexpacked_w) * 4, "got %ld\n", dst_len);
1534 ok(!memcmp(hexunpacked_w, dst, 2 * sizeof(WCHAR) * 4 - 2 ), "got %s\n", wine_dbgstr_w(dst));
1535 ok(dst[2 * 4 - 1] == 0, "not null terminated\n");
1536 ok(dst[2 * 4] == 0xcccc, "clobbered buffer\n");
1538 memcpy(src, hexpacked_w, sizeof(hexpacked_w));
1539 memset(dst, 0xcc, sizeof(dst));
1540 dst_len = 0x1234;
1541 hr = IDataConvert_DataConvert(convert, DBTYPE_BYTES, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, DBDATACONVERT_LENGTHFROMNTS);
1542 ok(hr == S_OK, "got %08x\n", hr);
1543 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1544 ok(dst_len == 0, "got %ld\n", dst_len);
1545 ok(dst[0] == 0, "not null terminated\n");
1546 ok(dst[1] == 0xcccc, "clobbered buffer\n");
1548 b = SysAllocStringLen(NULL, 0);
1549 V_VT(&v) = VT_BSTR;
1550 V_BSTR(&v) = b;
1551 hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_WSTR, 0, &dst_len, &v, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1552 ok(hr == S_OK, "got %08x\n", hr);
1553 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1554 ok(dst_len == 0, "got %ld\n", dst_len);
1555 ok(!lstrcmpW(b, dst), "got %s\n", wine_dbgstr_w(dst));
1556 VariantClear(&v);
1558 dst_len = 44;
1559 V_VT(&v) = VT_NULL;
1560 hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_WSTR, 0, &dst_len, &v, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1561 ok(hr == S_OK, "got %08x\n", hr);
1562 ok(dst_status == DBSTATUS_S_ISNULL, "got %08x\n", dst_status);
1563 ok(dst_len == 44, "got %ld\n", dst_len);
1566 static void test_converttostr(void)
1568 HRESULT hr;
1569 char dst[100];
1570 BYTE src[64];
1571 DBSTATUS dst_status;
1572 DBLENGTH dst_len;
1573 static const WCHAR ten[] = {'1','0',0};
1574 static const WCHAR idW[] = {'0','C','7','3','3','A','8','D','-','2','A','1','C',0 };
1575 static const char idA[] = "0C733A8D";
1576 static const char withnull[] = "test\0ed";
1577 static const char ten_a[] = "10";
1578 static const char fourthreetwoone[] = "4321";
1579 static const char guid_str[] = "{0C733A8D-2A1C-11CE-ADE5-00AA0044773D}";
1580 static const char hexunpacked_a[] = "57696E6500";
1581 static const char hexpacked_a[] = "Wine";
1582 BSTR b;
1583 VARIANT v;
1585 memset(dst, 0xcc, sizeof(dst));
1586 dst_len = 0x1234;
1587 hr = IDataConvert_DataConvert(convert, DBTYPE_EMPTY, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1588 ok(hr == S_OK, "got %08x\n", hr);
1589 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1590 ok(dst_len == 0, "got %ld\n", dst_len);
1591 ok(dst[0] == 0, "got %02x\n", dst[0]);
1592 ok(dst[1] == (char)0xcc, "got %02x\n", dst[1]);
1594 memset(dst, 0xcc, sizeof(dst));
1595 dst_len = 0x1234;
1596 hr = IDataConvert_DataConvert(convert, DBTYPE_NULL, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1597 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr);
1598 ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status);
1599 ok(dst_len == 0x1234, "got %ld\n", dst_len);
1600 ok(dst[0] == (char)0xcc, "got %02x\n", dst[0]);
1602 *(short *)src = 4321;
1603 dst_len = 0x1234;
1604 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1605 ok(hr == S_OK, "got %08x\n", hr);
1606 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1607 ok(dst_len == 4, "got %ld\n", dst_len);
1608 ok(!lstrcmpA(dst, fourthreetwoone), "got %s\n", dst);
1610 *(short *)src = 4321;
1611 memset(dst, 0xcc, sizeof(dst));
1612 dst_len = 0x1234;
1613 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_STR, 0, &dst_len, src, dst, 0, 0, &dst_status, 0, 0, 0);
1614 ok(hr == DB_E_ERRORSOCCURRED, "got %08x\n", hr);
1615 ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
1616 ok(dst_len == 4, "got %ld\n", dst_len);
1617 ok(dst[0] == (char)0xcc, "got %02x\n", dst[0]);
1619 *(short *)src = 4321;
1620 memset(dst, 0xcc, sizeof(dst));
1621 dst_len = 0x1234;
1622 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_STR, 0, &dst_len, src, NULL, 0, 0, &dst_status, 0, 0, 0);
1623 ok(hr == S_OK, "got %08x\n", hr);
1624 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1625 ok(dst_len == 4, "got %ld\n", dst_len);
1626 ok(dst[0] == (char)0xcc, "got %02x\n", dst[0]);
1628 *(short *)src = 4321;
1629 memset(dst, 0xcc, sizeof(dst));
1630 dst_len = 0x1234;
1631 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_STR, 0, &dst_len, src, dst, 2, 0, &dst_status, 0, 0, 0);
1632 ok(hr == S_OK, "got %08x\n", hr);
1633 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1634 ok(dst_len == 4, "got %ld\n", dst_len);
1635 ok(dst[0] == '4', "got %02x\n", dst[0]);
1636 ok(dst[1] == 0, "got %02x\n", dst[1]);
1637 ok(dst[2] == (char)0xcc, "got %02x\n", dst[2]);
1639 *(short *)src = 4321;
1640 memset(dst, 0xcc, sizeof(dst));
1641 dst_len = 0x1234;
1642 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_STR, 0, &dst_len, src, dst, 1, 0, &dst_status, 0, 0, 0);
1643 ok(hr == S_OK, "got %08x\n", hr);
1644 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1645 ok(dst_len == 4, "got %ld\n", dst_len);
1646 ok(dst[0] == 0, "got %02x\n", dst[0]);
1647 ok(dst[1] == (char)0xcc, "got %02x\n", dst[1]);
1649 *(short *)src = 4321;
1650 memset(dst, 0xcc, sizeof(dst));
1651 dst_len = 0x1234;
1652 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_STR, 0, &dst_len, src, dst, 4, 0, &dst_status, 0, 0, 0);
1653 ok(hr == S_OK, "got %08x\n", hr);
1654 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1655 ok(dst_len == 4, "got %ld\n", dst_len);
1656 ok(dst[0] == '4', "got %02x\n", dst[0]);
1657 ok(dst[1] == '3', "got %02x\n", dst[1]);
1658 ok(dst[2] == '2', "got %02x\n", dst[2]);
1659 ok(dst[3] == 0, "got %02x\n", dst[3]);
1660 ok(dst[4] == (char)0xcc, "got %02x\n", dst[4]);
1663 *(int *)src = 4321;
1664 dst_len = 0x1234;
1665 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1666 ok(hr == S_OK, "got %08x\n", hr);
1667 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1668 ok(dst_len == 4, "got %ld\n", dst_len);
1669 ok(!lstrcmpA(dst, fourthreetwoone), "got %s\n", dst);
1671 *(int *)src = 4321;
1672 memset(dst, 0xcc, sizeof(dst));
1673 dst_len = 0x1234;
1674 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_STR, 0, &dst_len, src, dst, 0, 0, &dst_status, 0, 0, 0);
1675 ok(hr == DB_E_ERRORSOCCURRED, "got %08x\n", hr);
1676 ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
1677 ok(dst_len == 4, "got %ld\n", dst_len);
1678 ok(dst[0] == (char)0xcc, "got %02x\n", dst[0]);
1680 *(int *)src = 4321;
1681 memset(dst, 0xcc, sizeof(dst));
1682 dst_len = 0x1234;
1683 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_STR, 0, &dst_len, src, NULL, 0, 0, &dst_status, 0, 0, 0);
1684 ok(hr == S_OK, "got %08x\n", hr);
1685 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1686 ok(dst_len == 4, "got %ld\n", dst_len);
1687 ok(dst[0] == (char)0xcc, "got %02x\n", dst[0]);
1689 *(int *)src = 4321;
1690 memset(dst, 0xcc, sizeof(dst));
1691 dst_len = 0x1234;
1692 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_STR, 0, &dst_len, src, dst, 2, 0, &dst_status, 0, 0, 0);
1693 ok(hr == S_OK, "got %08x\n", hr);
1694 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1695 ok(dst_len == 4, "got %ld\n", dst_len);
1696 ok(dst[0] == '4', "got %02x\n", dst[0]);
1697 ok(dst[1] == 0, "got %02x\n", dst[1]);
1698 ok(dst[2] == (char)0xcc, "got %02x\n", dst[2]);
1700 *(int *)src = 4321;
1701 memset(dst, 0xcc, sizeof(dst));
1702 dst_len = 0x1234;
1703 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_STR, 0, &dst_len, src, dst, 1, 0, &dst_status, 0, 0, 0);
1704 ok(hr == S_OK, "got %08x\n", hr);
1705 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1706 ok(dst_len == 4, "got %ld\n", dst_len);
1707 ok(dst[0] == 0, "got %02x\n", dst[0]);
1708 ok(dst[1] == (char)0xcc, "got %02x\n", dst[1]);
1710 *(int *)src = 4321;
1711 memset(dst, 0xcc, sizeof(dst));
1712 dst_len = 0x1234;
1713 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_STR, 0, &dst_len, src, dst, 4, 0, &dst_status, 0, 0, 0);
1714 ok(hr == S_OK, "got %08x\n", hr);
1715 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1716 ok(dst_len == 4, "got %ld\n", dst_len);
1717 ok(dst[0] == '4', "got %02x\n", dst[0]);
1718 ok(dst[1] == '3', "got %02x\n", dst[1]);
1719 ok(dst[2] == '2', "got %02x\n", dst[2]);
1720 ok(dst[3] == 0, "got %02x\n", dst[3]);
1721 ok(dst[4] == (char)0xcc, "got %02x\n", dst[4]);
1724 *(float *)src = 4321;
1725 dst_len = 0x1234;
1726 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1727 ok(hr == S_OK, "got %08x\n", hr);
1728 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1729 ok(dst_len == 4, "got %ld\n", dst_len);
1730 ok(!lstrcmpA(dst, fourthreetwoone), "got %s\n", dst);
1732 *(float *)src = 4321;
1733 memset(dst, 0xcc, sizeof(dst));
1734 dst_len = 0x1234;
1735 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_STR, 0, &dst_len, src, dst, 0, 0, &dst_status, 0, 0, 0);
1736 ok(hr == DB_E_ERRORSOCCURRED, "got %08x\n", hr);
1737 ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
1738 ok(dst_len == 4, "got %ld\n", dst_len);
1739 ok(dst[0] == (char)0xcc, "got %02x\n", dst[0]);
1741 *(float *)src = 4321;
1742 memset(dst, 0xcc, sizeof(dst));
1743 dst_len = 0x1234;
1744 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_STR, 0, &dst_len, src, NULL, 0, 0, &dst_status, 0, 0, 0);
1745 ok(hr == S_OK, "got %08x\n", hr);
1746 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1747 ok(dst_len == 4, "got %ld\n", dst_len);
1748 ok(dst[0] == (char)0xcc, "got %02x\n", dst[0]);
1750 *(float *)src = 4321;
1751 memset(dst, 0xcc, sizeof(dst));
1752 dst_len = 0x1234;
1753 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_STR, 0, &dst_len, src, dst, 2, 0, &dst_status, 0, 0, 0);
1754 ok(hr == S_OK, "got %08x\n", hr);
1755 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1756 ok(dst_len == 4, "got %ld\n", dst_len);
1757 ok(dst[0] == '4', "got %02x\n", dst[0]);
1758 ok(dst[1] == 0, "got %02x\n", dst[1]);
1759 ok(dst[2] == (char)0xcc, "got %02x\n", dst[2]);
1761 *(float *)src = 4321;
1762 memset(dst, 0xcc, sizeof(dst));
1763 dst_len = 0x1234;
1764 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_STR, 0, &dst_len, src, dst, 1, 0, &dst_status, 0, 0, 0);
1765 ok(hr == S_OK, "got %08x\n", hr);
1766 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1767 ok(dst_len == 4, "got %ld\n", dst_len);
1768 ok(dst[0] == 0, "got %02x\n", dst[0]);
1769 ok(dst[1] == (char)0xcc, "got %02x\n", dst[1]);
1771 *(float *)src = 4321;
1772 memset(dst, 0xcc, sizeof(dst));
1773 dst_len = 0x1234;
1774 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_STR, 0, &dst_len, src, dst, 4, 0, &dst_status, 0, 0, 0);
1775 ok(hr == S_OK, "got %08x\n", hr);
1776 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1777 ok(dst_len == 4, "got %ld\n", dst_len);
1778 ok(dst[0] == '4', "got %02x\n", dst[0]);
1779 ok(dst[1] == '3', "got %02x\n", dst[1]);
1780 ok(dst[2] == '2', "got %02x\n", dst[2]);
1781 ok(dst[3] == 0, "got %02x\n", dst[3]);
1782 ok(dst[4] == (char)0xcc, "got %02x\n", dst[4]);
1785 *(double *)src = 4321;
1786 dst_len = 0x1234;
1787 hr = IDataConvert_DataConvert(convert, DBTYPE_R8, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1788 ok(hr == S_OK, "got %08x\n", hr);
1789 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1790 ok(dst_len == 4, "got %ld\n", dst_len);
1791 ok(!lstrcmpA(dst, fourthreetwoone), "got %s\n", dst);
1793 *(double *)src = 4321;
1794 memset(dst, 0xcc, sizeof(dst));
1795 dst_len = 0x1234;
1796 hr = IDataConvert_DataConvert(convert, DBTYPE_R8, DBTYPE_STR, 0, &dst_len, src, dst, 0, 0, &dst_status, 0, 0, 0);
1797 ok(hr == DB_E_ERRORSOCCURRED, "got %08x\n", hr);
1798 ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
1799 ok(dst_len == 4, "got %ld\n", dst_len);
1800 ok(dst[0] == (char)0xcc, "got %02x\n", dst[0]);
1802 *(double *)src = 4321;
1803 memset(dst, 0xcc, sizeof(dst));
1804 dst_len = 0x1234;
1805 hr = IDataConvert_DataConvert(convert, DBTYPE_R8, DBTYPE_STR, 0, &dst_len, src, NULL, 0, 0, &dst_status, 0, 0, 0);
1806 ok(hr == S_OK, "got %08x\n", hr);
1807 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1808 ok(dst_len == 4, "got %ld\n", dst_len);
1809 ok(dst[0] == (char)0xcc, "got %02x\n", dst[0]);
1811 *(double *)src = 4321;
1812 memset(dst, 0xcc, sizeof(dst));
1813 dst_len = 0x1234;
1814 hr = IDataConvert_DataConvert(convert, DBTYPE_R8, DBTYPE_STR, 0, &dst_len, src, dst, 2, 0, &dst_status, 0, 0, 0);
1815 ok(hr == S_OK, "got %08x\n", hr);
1816 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1817 ok(dst_len == 4, "got %ld\n", dst_len);
1818 ok(dst[0] == '4', "got %02x\n", dst[0]);
1819 ok(dst[1] == 0, "got %02x\n", dst[1]);
1820 ok(dst[2] == (char)0xcc, "got %02x\n", dst[2]);
1822 *(double *)src = 4321;
1823 memset(dst, 0xcc, sizeof(dst));
1824 dst_len = 0x1234;
1825 hr = IDataConvert_DataConvert(convert, DBTYPE_R8, DBTYPE_STR, 0, &dst_len, src, dst, 1, 0, &dst_status, 0, 0, 0);
1826 ok(hr == S_OK, "got %08x\n", hr);
1827 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1828 ok(dst_len == 4, "got %ld\n", dst_len);
1829 ok(dst[0] == 0, "got %02x\n", dst[0]);
1830 ok(dst[1] == (char)0xcc, "got %02x\n", dst[1]);
1832 *(double *)src = 4321;
1833 memset(dst, 0xcc, sizeof(dst));
1834 dst_len = 0x1234;
1835 hr = IDataConvert_DataConvert(convert, DBTYPE_R8, DBTYPE_STR, 0, &dst_len, src, dst, 4, 0, &dst_status, 0, 0, 0);
1836 ok(hr == S_OK, "got %08x\n", hr);
1837 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1838 ok(dst_len == 4, "got %ld\n", dst_len);
1839 ok(dst[0] == '4', "got %02x\n", dst[0]);
1840 ok(dst[1] == '3', "got %02x\n", dst[1]);
1841 ok(dst[2] == '2', "got %02x\n", dst[2]);
1842 ok(dst[3] == 0, "got %02x\n", dst[3]);
1843 ok(dst[4] == (char)0xcc, "got %02x\n", dst[4]);
1847 memset(src, 0, sizeof(src));
1848 ((CY*)src)->int64 = 43210000;
1849 memset(dst, 0xcc, sizeof(dst));
1850 dst_len = 0x1234;
1851 hr = IDataConvert_DataConvert(convert, DBTYPE_CY, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1852 ok(hr == S_OK, "got %08x\n", hr);
1853 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1854 ok(dst_len == 4, "got %ld\n", dst_len);
1855 ok(!lstrcmpA(dst, fourthreetwoone), "got %s\n", dst);
1859 memset(src, 0, sizeof(src));
1860 *(signed char *)src = 10;
1861 dst_len = 0x1234;
1862 hr = IDataConvert_DataConvert(convert, DBTYPE_I1, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1863 ok(hr == S_OK, "got %08x\n", hr);
1864 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1865 ok(dst_len == 2, "got %ld\n", dst_len);
1866 ok(!lstrcmpA(dst, ten_a), "got %s\n", dst);
1868 memset(src, 0, sizeof(src));
1869 *(unsigned char *)src = 10;
1870 dst_len = 0x1234;
1871 hr = IDataConvert_DataConvert(convert, DBTYPE_UI1, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1872 ok(hr == S_OK, "got %08x\n", hr);
1873 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1874 ok(dst_len == 2, "got %ld\n", dst_len);
1875 ok(!lstrcmpA(dst, ten_a), "got %s\n", dst);
1877 memset(src, 0, sizeof(src));
1878 *(unsigned short *)src = 4321;
1879 dst_len = 0x1234;
1880 hr = IDataConvert_DataConvert(convert, DBTYPE_UI2, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1881 ok(hr == S_OK, "got %08x\n", hr);
1882 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1883 ok(dst_len == 4, "got %ld\n", dst_len);
1884 ok(!lstrcmpA(dst, fourthreetwoone), "got %s\n", dst);
1886 memset(src, 0, sizeof(src));
1887 *(unsigned int *)src = 4321;
1888 dst_len = 0x1234;
1889 hr = IDataConvert_DataConvert(convert, DBTYPE_UI4, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1890 ok(hr == S_OK, "got %08x\n", hr);
1891 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1892 ok(dst_len == 4, "got %ld\n", dst_len);
1893 ok(!lstrcmpA(dst, fourthreetwoone), "got %s\n", dst);
1895 memset(src, 0, sizeof(src));
1896 ((LARGE_INTEGER*)src)->QuadPart = 4321;
1897 dst_len = 0x1234;
1898 hr = IDataConvert_DataConvert(convert, DBTYPE_I8, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1899 ok(broken(hr == DB_E_UNSUPPORTEDCONVERSION) || hr == S_OK /* W2K+ */, "got %08x\n", hr);
1900 ok(broken(dst_status == DBSTATUS_E_BADACCESSOR) || dst_status == DBSTATUS_S_OK /* W2K+ */, "got %08x\n", dst_status);
1901 ok(broken(dst_len == 0x1234) || dst_len == 4 /* W2K+ */, "got %ld\n", dst_len);
1902 ok(!lstrcmpA(dst, fourthreetwoone), "got %s\n", dst);
1904 memset(src, 0, sizeof(src));
1905 ((ULARGE_INTEGER*)src)->QuadPart = 4321;
1906 dst_len = 0x1234;
1907 hr = IDataConvert_DataConvert(convert, DBTYPE_UI8, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1908 ok(broken(hr == DB_E_UNSUPPORTEDCONVERSION) || hr == S_OK /* W2K+ */, "got %08x\n", hr);
1909 ok(broken(dst_status == DBSTATUS_E_BADACCESSOR) || dst_status == DBSTATUS_S_OK /* W2K+ */, "got %08x\n", dst_status);
1910 ok(broken(dst_len == 0x1234) || dst_len == 4 /* W2K+ */, "got %ld\n", dst_len);
1911 ok(!lstrcmpA(dst, fourthreetwoone), "got %s\n", dst);
1915 memset(src, 0, sizeof(src));
1916 memcpy(src, &IID_IDataConvert, sizeof(GUID));
1917 memset(dst, 0xcc, sizeof(dst));
1918 dst_len = 0x1234;
1919 hr = IDataConvert_DataConvert(convert, DBTYPE_GUID, DBTYPE_STR, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1920 ok(hr == S_OK, "got %08x\n", hr);
1921 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1922 ok(dst_len == 38, "got %ld\n", dst_len);
1923 ok(!lstrcmpA(dst, guid_str), "got %s\n", dst);
1927 b = SysAllocString(ten);
1928 *(BSTR *)src = b;
1929 memset(dst, 0xcc, sizeof(dst));
1930 dst_len = 0x1234;
1931 hr = IDataConvert_DataConvert(convert, DBTYPE_BSTR, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1932 ok(hr == S_OK, "got %08x\n", hr);
1933 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1934 ok(dst_len == 2, "got %ld\n", dst_len);
1935 ok(!lstrcmpA(ten_a, dst), "got %s\n", dst);
1936 SysFreeString(b);
1938 b = SysAllocString(idW);
1939 *(BSTR *)src = b;
1940 memset(dst, 0xcc, sizeof(dst));
1941 dst_len = 0x1234;
1942 hr = IDataConvert_DataConvert(convert, DBTYPE_BSTR, DBTYPE_STR, 0, &dst_len, src, dst, 9, 0, &dst_status, 0, 0, 0);
1943 ok(hr == S_OK, "got %08x\n", hr);
1944 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1945 ok(dst_len == 13, "got %ld\n", dst_len);
1946 ok(!lstrcmpA(idA, dst), "got %s\n", dst);
1947 SysFreeString(b);
1949 memcpy(src, withnull, sizeof(withnull));
1950 memset(dst, 0xcc, sizeof(dst));
1951 dst_len = 0x1234;
1952 hr = IDataConvert_DataConvert(convert, DBTYPE_STR, DBTYPE_STR, sizeof(withnull), &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1953 ok(hr == S_OK, "got %08x\n", hr);
1954 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1955 ok(dst_len == 8, "got %ld\n", dst_len);
1956 ok(!memcmp(withnull, dst, 8), "got %s\n", dst);
1957 ok(dst[8] == 0, "got %02x\n", dst[8]);
1959 memcpy(src, withnull, sizeof(withnull));
1960 memset(dst, 0xcc, sizeof(dst));
1961 dst_len = 0x1234;
1962 hr = IDataConvert_DataConvert(convert, DBTYPE_STR, DBTYPE_STR, 7, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1963 ok(hr == S_OK, "got %08x\n", hr);
1964 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1965 ok(dst_len == 7, "got %ld\n", dst_len);
1966 ok(!memcmp(withnull, dst, 7), "got %s\n", dst);
1967 ok(dst[7] == 0, "got %02x\n", dst[7]);
1969 memcpy(src, withnull, sizeof(withnull));
1970 memset(dst, 0xcc, sizeof(dst));
1971 dst_len = 0x1234;
1972 hr = IDataConvert_DataConvert(convert, DBTYPE_STR, DBTYPE_STR, 6, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1973 ok(hr == S_OK, "got %08x\n", hr);
1974 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1975 ok(dst_len == 6, "got %ld\n", dst_len);
1976 ok(!memcmp(withnull, dst, 6), "got %s\n", dst);
1977 ok(dst[6] == 0, "got %02x\n", dst[6]);
1979 memcpy(src, ten, sizeof(ten));
1980 memset(dst, 0xcc, sizeof(dst));
1981 dst_len = 0x1234;
1982 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_STR, 2, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1983 ok(hr == S_OK, "got %08x\n", hr);
1984 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1985 ok(dst_len == 1, "got %ld\n", dst_len);
1986 ok(dst[0] == '1', "got %02x\n", dst[0]);
1987 ok(dst[1] == 0, "got %02x\n", dst[1]);
1989 memcpy(src, ten, sizeof(ten));
1990 memset(dst, 0xcc, sizeof(dst));
1991 dst_len = 0x1234;
1992 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_STR, 4, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1993 ok(hr == S_OK, "got %08x\n", hr);
1994 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1995 ok(dst_len == 2, "got %ld\n", dst_len);
1996 ok(!lstrcmpA(ten_a, dst), "got %s\n", dst);
1998 memcpy(src, ten, sizeof(ten));
1999 memset(dst, 0xcc, sizeof(dst));
2000 dst_len = 0x1234;
2001 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, DBDATACONVERT_LENGTHFROMNTS);
2002 ok(hr == S_OK, "got %08x\n", hr);
2003 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2004 ok(dst_len == 2, "got %ld\n", dst_len);
2005 ok(!lstrcmpA(ten_a, dst), "got %s\n", dst);
2007 memcpy(src, ten_a, sizeof(ten_a));
2008 memset(dst, 0xcc, sizeof(dst));
2009 dst_len = 0x1234;
2010 hr = IDataConvert_DataConvert(convert, DBTYPE_STR, DBTYPE_STR, 2, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2011 ok(hr == S_OK, "got %08x\n", hr);
2012 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2013 ok(dst_len == 2, "got %ld\n", dst_len);
2014 ok(dst[0] == '1', "got %02x\n", dst[0]);
2015 ok(dst[1] == '0', "got %02x\n", dst[1]);
2016 ok(dst[2] == 0, "got %02x\n", dst[2]);
2017 ok(dst[3] == (char)0xcc, "got %02x\n", dst[3]);
2019 memcpy(src, ten_a, sizeof(ten_a));
2020 memset(dst, 0xcc, sizeof(dst));
2021 dst_len = 0x1234;
2022 hr = IDataConvert_DataConvert(convert, DBTYPE_STR, DBTYPE_STR, 4, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2023 ok(hr == S_OK, "got %08x\n", hr);
2024 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2025 ok(dst_len == 4, "got %ld\n", dst_len);
2026 ok(!lstrcmpA(ten_a, dst), "got %s\n", dst);
2028 memcpy(src, ten_a, sizeof(ten_a));
2029 memset(dst, 0xcc, sizeof(dst));
2030 dst_len = 0x1234;
2031 hr = IDataConvert_DataConvert(convert, DBTYPE_STR, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, DBDATACONVERT_LENGTHFROMNTS);
2032 ok(hr == S_OK, "got %08x\n", hr);
2033 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2034 ok(dst_len == 2, "got %ld\n", dst_len);
2035 ok(!lstrcmpA(ten_a, dst), "got %s\n", dst);
2039 /* DBTYPE_BYTES to DBTYPE_*STR unpacks binary data into a hex string */
2040 memcpy(src, hexpacked_a, sizeof(hexpacked_a));
2041 memset(dst, 0xcc, sizeof(dst));
2042 dst_len = 0x1234;
2043 hr = IDataConvert_DataConvert(convert, DBTYPE_BYTES, DBTYPE_STR, sizeof(hexpacked_a), &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2044 ok(hr == S_OK, "got %08x\n", hr);
2045 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2046 ok(dst_len == sizeof(hexpacked_a) * 2, "got %ld\n", dst_len);
2047 ok(!lstrcmpA(hexunpacked_a, dst), "got %s\n", dst);
2048 ok(dst[sizeof(hexpacked_a)/sizeof(char) * 4 + 1] == (char)0xcc, "clobbered buffer\n");
2050 memcpy(src, hexpacked_a, sizeof(hexpacked_a));
2051 memset(dst, 0xcc, sizeof(dst));
2052 dst_len = 0x1234;
2053 hr = IDataConvert_DataConvert(convert, DBTYPE_BYTES, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2054 ok(hr == S_OK, "got %08x\n", hr);
2055 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2056 ok(dst_len == 0, "got %ld\n", dst_len);
2057 ok(dst[0] == 0, "not null terminated\n");
2058 ok(dst[1] == (char)0xcc, "clobbered buffer\n");
2060 memcpy(src, hexpacked_a, sizeof(hexpacked_a));
2061 memset(dst, 0xcc, sizeof(dst));
2062 dst_len = 0x1234;
2063 hr = IDataConvert_DataConvert(convert, DBTYPE_BYTES, DBTYPE_STR, 4, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2064 ok(hr == S_OK, "got %08x\n", hr);
2065 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2066 ok(dst_len == 2 * sizeof(char) * 4, "got %ld\n", dst_len);
2067 ok(!memcmp(hexunpacked_a, dst, 2 * sizeof(char) * 4 ), "got %s\n", dst);
2068 ok(dst[2 * 4] == 0, "not null terminated\n");
2069 ok(dst[2 * 4 + 1] == (char)0xcc, "clobbered buffer\n");
2071 memcpy(src, hexpacked_a, sizeof(hexpacked_a));
2072 memset(dst, 0xcc, sizeof(dst));
2073 dst_len = 0x1234;
2074 hr = IDataConvert_DataConvert(convert, DBTYPE_BYTES, DBTYPE_STR, sizeof(hexpacked_a), &dst_len, src, dst, 2 * sizeof(char) * 4 + sizeof(char), 0, &dst_status, 0, 0, 0);
2075 ok(hr == S_OK, "got %08x\n", hr);
2076 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
2077 ok(dst_len == sizeof(hexpacked_a) * 2, "got %ld\n", dst_len);
2078 ok(!memcmp(hexunpacked_a, dst, 2 * sizeof(char) * 4 ), "got %s\n", dst);
2079 ok(dst[2 * 4] == 0, "not null terminated\n");
2080 ok(dst[2 * 4 + 1] == (char)0xcc, "clobbered buffer\n");
2082 memcpy(src, hexpacked_a, sizeof(hexpacked_a));
2083 memset(dst, 0xcc, sizeof(dst));
2084 dst_len = 0x1234;
2085 hr = IDataConvert_DataConvert(convert, DBTYPE_BYTES, DBTYPE_STR, sizeof(hexpacked_a), &dst_len, src, dst, 2 * sizeof(char) * 4, 0, &dst_status, 0, 0, 0);
2086 ok(hr == S_OK, "got %08x\n", hr);
2087 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
2088 ok(dst_len == sizeof(hexpacked_a) * 2, "got %ld\n", dst_len);
2089 ok(!memcmp(hexunpacked_a, dst, 2 * sizeof(char) * 4 - 2 ), "got %s\n", dst);
2090 ok(dst[2 * 4 - 1] == 0, "not null terminated\n");
2091 ok(dst[2 * 4] == (char)0xcc, "clobbered buffer\n");
2093 memcpy(src, hexpacked_a, sizeof(hexpacked_a));
2094 memset(dst, 0xcc, sizeof(dst));
2095 dst_len = 0x1234;
2096 hr = IDataConvert_DataConvert(convert, DBTYPE_BYTES, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, DBDATACONVERT_LENGTHFROMNTS);
2097 ok(hr == S_OK, "got %08x\n", hr);
2098 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2099 ok(dst_len == 0, "got %ld\n", dst_len);
2100 ok(dst[0] == 0, "not null terminated\n");
2101 ok(dst[1] == (char)0xcc, "clobbered buffer\n");
2103 dst_len = 44;
2104 V_VT(&v) = VT_NULL;
2105 hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_STR, 0, &dst_len, &v, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2106 ok(hr == S_OK, "got %08x\n", hr);
2107 ok(dst_status == DBSTATUS_S_ISNULL, "got %08x\n", dst_status);
2108 ok(dst_len == 44, "got %ld\n", dst_len);
2111 static void test_converttobyrefwstr(void)
2113 HRESULT hr;
2114 WCHAR *dst;
2115 BYTE src[20];
2116 DBSTATUS dst_status;
2117 DBLENGTH dst_len;
2118 static const WCHAR ten[] = {'1','0',0};
2119 static const WCHAR fourthreetwoone[] = {'4','3','2','1',0};
2120 BSTR b;
2121 VARIANT v;
2123 VariantInit(&v);
2125 hr = IDataConvert_DataConvert(convert, DBTYPE_EMPTY, DBTYPE_BYREF | DBTYPE_WSTR, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2126 ok(hr == S_OK, "got %08x\n", hr);
2127 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2128 ok(dst_len == 0, "got %ld\n", dst_len);
2129 ok(dst[0] == 0, "got %04x\n", dst[0]);
2130 CoTaskMemFree(dst);
2132 dst = (void*)0x12345678;
2133 dst_len = 0x1234;
2134 hr = IDataConvert_DataConvert(convert, DBTYPE_NULL, DBTYPE_BYREF | DBTYPE_WSTR, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2135 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr);
2136 ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status);
2137 ok(dst_len == 0x1234, "got %ld\n", dst_len);
2138 ok(dst == (void*)0x12345678, "got %p\n", dst);
2140 *(short *)src = 4321;
2141 dst_len = 0x1234;
2142 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_BYREF | DBTYPE_WSTR, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2143 ok(hr == S_OK, "got %08x\n", hr);
2144 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2145 ok(dst_len == 8, "got %ld\n", dst_len);
2146 ok(!lstrcmpW(dst, fourthreetwoone), "got %s\n", wine_dbgstr_w(dst));
2147 CoTaskMemFree(dst);
2149 *(short *)src = 4321;
2150 dst_len = 0x1234;
2151 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_BYREF | DBTYPE_WSTR, 0, &dst_len, src, &dst, 0, 0, &dst_status, 0, 0, 0);
2152 ok(hr == S_OK, "got %08x\n", hr);
2153 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2154 ok(dst_len == 8, "got %ld\n", dst_len);
2155 ok(!lstrcmpW(dst, fourthreetwoone), "got %s\n", wine_dbgstr_w(dst));
2156 CoTaskMemFree(dst);
2158 b = SysAllocString(ten);
2159 *(BSTR *)src = b;
2160 dst_len = 0x1234;
2161 hr = IDataConvert_DataConvert(convert, DBTYPE_BSTR, DBTYPE_BYREF | DBTYPE_WSTR, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2162 ok(hr == S_OK, "got %08x\n", hr);
2163 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2164 ok(dst_len == 4, "got %ld\n", dst_len);
2165 ok(!lstrcmpW(b, dst), "got %s\n", wine_dbgstr_w(dst));
2166 CoTaskMemFree(dst);
2167 SysFreeString(b);
2169 memcpy(src, ten, sizeof(ten));
2170 dst_len = 0x1234;
2171 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_BYREF | DBTYPE_WSTR, 2, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2172 ok(hr == S_OK, "got %08x\n", hr);
2173 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2174 ok(dst_len == 2, "got %ld\n", dst_len);
2175 ok(dst[0] == '1', "got %02x\n", dst[0]);
2176 ok(dst[1] == 0, "got %02x\n", dst[1]);
2177 CoTaskMemFree(dst);
2179 memcpy(src, ten, sizeof(ten));
2180 dst_len = 0x1234;
2181 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_BYREF | DBTYPE_WSTR, 4, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2182 ok(hr == S_OK, "got %08x\n", hr);
2183 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2184 ok(dst_len == 4, "got %ld\n", dst_len);
2185 ok(!lstrcmpW(ten, dst), "got %s\n", wine_dbgstr_w(dst));
2186 CoTaskMemFree(dst);
2188 memcpy(src, ten, sizeof(ten));
2189 dst_len = 0x1234;
2190 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_BYREF | DBTYPE_WSTR, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, DBDATACONVERT_LENGTHFROMNTS);
2191 ok(hr == S_OK, "got %08x\n", hr);
2192 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2193 ok(dst_len == 4, "got %ld\n", dst_len);
2194 ok(!lstrcmpW(ten, dst), "got %s\n", wine_dbgstr_w(dst));
2195 CoTaskMemFree(dst);
2197 dst_len = 44;
2198 V_VT(&v) = VT_NULL;
2199 hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_BYREF | DBTYPE_WSTR, 0, &dst_len, &v, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2200 ok(hr == S_OK, "got %08x\n", hr);
2201 ok(dst_status == DBSTATUS_S_ISNULL, "got %08x\n", dst_status);
2202 ok(dst_len == 44, "got %ld\n", dst_len);
2205 static void test_converttobyrefstr(void)
2207 HRESULT hr;
2208 char *dst;
2209 BYTE src[20];
2210 DBSTATUS dst_status;
2211 DBLENGTH dst_len;
2212 static const WCHAR ten[] = {'1','0',0};
2213 static const char withnull[] = "test\0ed";
2214 BSTR b;
2215 VARIANT v;
2217 VariantInit(&v);
2219 hr = IDataConvert_DataConvert(convert, DBTYPE_EMPTY, DBTYPE_STR | DBTYPE_BYREF, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2220 ok(hr == S_OK, "got %08x\n", hr);
2221 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2222 ok(dst_len == 0, "got %ld\n", dst_len);
2223 ok(dst[0] == 0, "got %04x\n", dst[0]);
2224 CoTaskMemFree(dst);
2226 dst = (void*)0x12345678;
2227 dst_len = 0x1234;
2228 hr = IDataConvert_DataConvert(convert, DBTYPE_NULL, DBTYPE_STR | DBTYPE_BYREF, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2229 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr);
2230 ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status);
2231 ok(dst_len == 0x1234, "got %ld\n", dst_len);
2232 ok(dst == (void*)0x12345678, "got %p\n", dst);
2234 *(short *)src = 4321;
2235 dst_len = 0x1234;
2236 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_STR | DBTYPE_BYREF, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2237 ok(hr == S_OK, "got %08x\n", hr);
2238 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2239 ok(dst_len == 4, "got %ld\n", dst_len);
2240 ok(!lstrcmpA(dst, "4321"), "got %s\n", dst);
2241 CoTaskMemFree(dst);
2243 *(short *)src = 4321;
2244 dst_len = 0x1234;
2245 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_STR | DBTYPE_BYREF, 0, &dst_len, src, &dst, 0, 0, &dst_status, 0, 0, 0);
2246 ok(hr == S_OK, "got %08x\n", hr);
2247 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2248 ok(dst_len == 4, "got %ld\n", dst_len);
2249 ok(!lstrcmpA(dst, "4321"), "got %s\n", dst);
2250 CoTaskMemFree(dst);
2252 b = SysAllocString(ten);
2253 *(BSTR *)src = b;
2254 dst_len = 0x1234;
2255 hr = IDataConvert_DataConvert(convert, DBTYPE_BSTR, DBTYPE_STR | DBTYPE_BYREF, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2256 ok(hr == S_OK, "got %08x\n", hr);
2257 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2258 ok(dst_len == 2, "got %ld\n", dst_len);
2259 ok(!lstrcmpA("10", dst), "got %s\n", dst);
2260 CoTaskMemFree(dst);
2261 SysFreeString(b);
2263 memcpy(src, ten, sizeof(ten));
2264 dst_len = 0x1234;
2265 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_STR | DBTYPE_BYREF, 2, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2266 ok(hr == S_OK, "got %08x\n", hr);
2267 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2268 ok(dst_len == 1, "got %ld\n", dst_len);
2269 ok(dst[0] == '1', "got %02x\n", dst[0]);
2270 ok(dst[1] == 0, "got %02x\n", dst[1]);
2271 CoTaskMemFree(dst);
2273 memcpy(src, ten, sizeof(ten));
2274 dst_len = 0x1234;
2275 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_STR | DBTYPE_BYREF, 4, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2276 ok(hr == S_OK, "got %08x\n", hr);
2277 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2278 ok(dst_len == 2, "got %ld\n", dst_len);
2279 ok(!lstrcmpA("10", dst), "got %s\n", dst);
2280 CoTaskMemFree(dst);
2282 memcpy(src, ten, sizeof(ten));
2283 dst_len = 0x1234;
2284 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_STR | DBTYPE_BYREF, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, DBDATACONVERT_LENGTHFROMNTS);
2285 ok(hr == S_OK, "got %08x\n", hr);
2286 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2287 ok(dst_len == 2, "got %ld\n", dst_len);
2288 ok(!lstrcmpA("10", dst), "got %s\n", dst);
2289 CoTaskMemFree(dst);
2291 memcpy(src, withnull, sizeof(withnull));
2292 dst_len = 0x1234;
2293 hr = IDataConvert_DataConvert(convert, DBTYPE_STR, DBTYPE_STR | DBTYPE_BYREF, sizeof(withnull), &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2294 ok(hr == S_OK, "got %08x\n", hr);
2295 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2296 ok(dst_len == 8, "got %ld\n", dst_len);
2297 ok(!memcmp(withnull, dst, 8), "got %s\n", dst);
2298 ok(dst[8] == 0, "got %02x\n", dst[8]);
2299 CoTaskMemFree(dst);
2301 memcpy(src, withnull, sizeof(withnull));
2302 dst_len = 0x1234;
2303 hr = IDataConvert_DataConvert(convert, DBTYPE_STR, DBTYPE_STR | DBTYPE_BYREF, 7, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2304 ok(hr == S_OK, "got %08x\n", hr);
2305 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2306 ok(dst_len == 7, "got %ld\n", dst_len);
2307 ok(!memcmp(withnull, dst, 7), "got %s\n", dst);
2308 ok(dst[7] == 0, "got %02x\n", dst[7]);
2309 CoTaskMemFree(dst);
2311 memcpy(src, withnull, sizeof(withnull));
2312 dst_len = 0x1234;
2313 hr = IDataConvert_DataConvert(convert, DBTYPE_STR, DBTYPE_STR | DBTYPE_BYREF, 6, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2314 ok(hr == S_OK, "got %08x\n", hr);
2315 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2316 ok(dst_len == 6, "got %ld\n", dst_len);
2317 ok(!memcmp(withnull, dst, 6), "got %s\n", dst);
2318 ok(dst[6] == 0, "got %02x\n", dst[6]);
2319 CoTaskMemFree(dst);
2322 dst_len = 44;
2323 V_VT(&v) = VT_NULL;
2324 hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_STR | DBTYPE_BYREF, 0, &dst_len, &v, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2325 ok(hr == S_OK, "got %08x\n", hr);
2326 ok(dst_status == DBSTATUS_S_ISNULL, "got %08x\n", dst_status);
2327 ok(dst_len == 44, "got %ld\n", dst_len);
2330 static void test_converttoguid(void)
2332 HRESULT hr;
2333 GUID dst;
2334 BYTE src[20];
2335 DBSTATUS dst_status;
2336 DBLENGTH dst_len;
2337 VARIANT v;
2339 VariantInit(&v);
2341 dst = IID_IDCInfo;
2342 dst_len = 0x1234;
2343 hr = IDataConvert_DataConvert(convert, DBTYPE_EMPTY, DBTYPE_GUID, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2344 ok(hr == S_OK, "got %08x\n", hr);
2345 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2346 ok(dst_len == sizeof(GUID), "got %ld\n", dst_len);
2347 ok(IsEqualGUID(&dst, &GUID_NULL), "didn't get GUID_NULL\n");
2349 dst = IID_IDCInfo;
2350 dst_len = 0x1234;
2351 hr = IDataConvert_DataConvert(convert, DBTYPE_NULL, DBTYPE_GUID, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2352 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr);
2353 ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status);
2354 ok(dst_len == 0x1234, "got %ld\n", dst_len);
2355 ok(IsEqualGUID(&dst, &IID_IDCInfo), "dst has changed\n");
2357 dst = IID_IDCInfo;
2358 memcpy(src, &IID_IDataConvert, sizeof(GUID));
2359 dst_len = 0x1234;
2360 hr = IDataConvert_DataConvert(convert, DBTYPE_GUID, DBTYPE_GUID, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2361 ok(hr == S_OK, "got %08x\n", hr);
2362 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2363 ok(dst_len == sizeof(GUID), "got %ld\n", dst_len);
2364 ok(IsEqualGUID(&dst, &IID_IDataConvert), "didn't get IID_IDataConvert\n");
2366 dst_len = 44;
2367 V_VT(&v) = VT_NULL;
2368 hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_GUID, 0, &dst_len, &v, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2369 ok(hr == S_OK, "got %08x\n", hr);
2370 ok(dst_status == DBSTATUS_S_ISNULL, "got %08x\n", dst_status);
2371 ok(dst_len == 44, "got %ld\n", dst_len);
2374 static void test_converttofiletime(void)
2376 HRESULT hr;
2377 FILETIME dst;
2378 BYTE src[20];
2379 DBSTATUS dst_status;
2380 DBLENGTH dst_len;
2381 VARIANT v;
2383 VariantInit(&v);
2385 memset(&dst, 0xcc, sizeof(dst));
2386 ((FILETIME *)src)->dwLowDateTime = 0x12345678;
2387 ((FILETIME *)src)->dwHighDateTime = 0x9abcdef0;
2388 dst_len = 0x1234;
2389 hr = IDataConvert_DataConvert(convert, DBTYPE_FILETIME, DBTYPE_FILETIME, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2390 ok(hr == S_OK ||
2391 broken(hr == DB_E_BADBINDINFO), /* win98 */
2392 "got %08x\n", hr);
2393 if(SUCCEEDED(hr))
2395 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2396 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2397 ok(dst.dwLowDateTime == 0x12345678, "got %08x\n", dst.dwLowDateTime);
2398 ok(dst.dwHighDateTime == 0x9abcdef0, "got %08x\n", dst.dwHighDateTime);
2401 dst_len = 44;
2402 V_VT(&v) = VT_NULL;
2403 hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_FILETIME, 0, &dst_len, &v, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2404 ok(hr == S_OK, "got %08x\n", hr);
2405 ok(dst_status == DBSTATUS_S_ISNULL, "got %08x\n", dst_status);
2406 ok(dst_len == 44, "got %ld\n", dst_len);
2409 static void test_converttoui1(void)
2411 HRESULT hr;
2412 BYTE dst;
2413 BYTE src[20];
2414 DBSTATUS dst_status;
2415 DBLENGTH dst_len;
2416 VARIANT v;
2418 VariantInit(&v);
2420 dst = 0x12;
2421 dst_len = 0x1234;
2422 hr = IDataConvert_DataConvert(convert, DBTYPE_EMPTY, DBTYPE_UI1, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2423 ok(hr == S_OK, "got %08x\n", hr);
2424 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2425 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2426 ok(dst == 0, "got %08x\n", dst);
2428 dst = 0x12;
2429 dst_len = 0x1234;
2430 hr = IDataConvert_DataConvert(convert, DBTYPE_NULL, DBTYPE_UI1, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2431 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr);
2432 ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status);
2433 ok(dst_len == 0x1234, "got %ld\n", dst_len);
2434 ok(dst == 0x12, "got %08x\n", dst);
2436 dst = 0x12;
2437 src[0] = 0x43;
2438 dst_len = 0x1234;
2439 hr = IDataConvert_DataConvert(convert, DBTYPE_UI1, DBTYPE_UI1, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2440 ok(hr == S_OK, "got %08x\n", hr);
2441 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2442 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2443 ok(dst == 0x43, "got %08x\n", dst);
2445 dst = 0x12;
2446 src[0] = 0xfe;
2447 dst_len = 0x1234;
2448 hr = IDataConvert_DataConvert(convert, DBTYPE_UI1, DBTYPE_UI1, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2449 ok(hr == S_OK, "got %08x\n", hr);
2450 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2451 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2452 ok(dst == 0xfe, "got %08x\n", dst);
2454 dst_len = 44;
2455 V_VT(&v) = VT_NULL;
2456 hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_UI1, 0, &dst_len, &v, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2457 ok(hr == S_OK, "got %08x\n", hr);
2458 ok(dst_status == DBSTATUS_S_ISNULL, "got %08x\n", dst_status);
2459 ok(dst_len == 44, "got %ld\n", dst_len);
2462 static void test_converttoui4(void)
2464 HRESULT hr;
2465 DWORD dst;
2466 BYTE src[20];
2467 DBSTATUS dst_status;
2468 DBLENGTH dst_len;
2470 dst = 0x12345678;
2471 dst_len = 0x1234;
2472 hr = IDataConvert_DataConvert(convert, DBTYPE_EMPTY, DBTYPE_UI4, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2473 ok(hr == S_OK, "got %08x\n", hr);
2474 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2475 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2476 ok(dst == 0, "got %08x\n", dst);
2478 dst = 0x12345678;
2479 dst_len = 0x1234;
2480 hr = IDataConvert_DataConvert(convert, DBTYPE_NULL, DBTYPE_UI4, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2481 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr);
2482 ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status);
2483 ok(dst_len == 0x1234, "got %ld\n", dst_len);
2484 ok(dst == 0x12345678, "got %08x\n", dst);
2486 dst = 0x12345678;
2487 *(DWORD*)src = 0x87654321;
2488 dst_len = 0x1234;
2489 hr = IDataConvert_DataConvert(convert, DBTYPE_UI4, DBTYPE_UI4, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2490 ok(hr == S_OK, "got %08x\n", hr);
2491 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2492 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2493 ok(dst == 0x87654321, "got %08x\n", dst);
2495 dst = 0x12345678;
2496 *(signed short *)src = 0x4321;
2497 dst_len = 0x1234;
2498 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_UI4, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2499 ok(hr == S_OK, "got %08x\n", hr);
2500 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2501 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2502 ok(dst == 0x4321, "got %08x\n", dst);
2504 dst = 0x12345678;
2505 *(signed short *)src = -1;
2506 dst_len = 0x1234;
2507 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_UI4, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2508 ok(hr == DB_E_ERRORSOCCURRED, "got %08x\n", hr);
2509 todo_wine
2510 ok(dst_status == DBSTATUS_E_SIGNMISMATCH, "got %08x\n", dst_status);
2511 todo_wine
2512 ok(broken(dst_len == sizeof(dst)) || dst_len == 0x1234 /* W2K+ */, "got %ld\n", dst_len);
2513 ok(dst == 0x12345678, "got %08x\n", dst);
2515 dst_len = dst = 0x1234;
2516 V_VT((VARIANT*)src) = VT_I2;
2517 V_I2((VARIANT*)src) = 0x4321;
2518 hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_UI4, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2519 ok(hr == S_OK, "got %08x\n", hr);
2520 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2521 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2522 ok(dst == 0x4321, "got %08x\n", dst);
2524 dst_len = 44;
2525 V_VT((VARIANT*)src) = VT_NULL;
2526 hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_UI4, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2527 ok(hr == S_OK, "got %08x\n", hr);
2528 ok(dst_status == DBSTATUS_S_ISNULL, "got %08x\n", dst_status);
2529 ok(dst_len == 44, "got %ld\n", dst_len);
2532 static void test_converttor4(void)
2534 HRESULT hr;
2535 FLOAT dst;
2536 BYTE src[20];
2537 DBSTATUS dst_status;
2538 DBLENGTH dst_len;
2539 VARIANT v;
2541 VariantInit(&v);
2543 dst = 1.0;
2544 dst_len = 0x1234;
2545 hr = IDataConvert_DataConvert(convert, DBTYPE_EMPTY, DBTYPE_R4, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2546 ok(hr == S_OK, "got %08x\n", hr);
2547 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2548 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2549 ok(dst == 0.0, "got %f\n", dst);
2551 dst = 1.0;
2552 dst_len = 0x1234;
2553 hr = IDataConvert_DataConvert(convert, DBTYPE_NULL, DBTYPE_R4, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2554 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr);
2555 ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status);
2556 ok(dst_len == 0x1234, "got %ld\n", dst_len);
2557 ok(dst == 1.0, "got %f\n", dst);
2559 dst = 1.0;
2560 *(signed int*)src = 12345678;
2561 dst_len = 0x1234;
2562 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_R4, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2563 ok(hr == S_OK, "got %08x\n", hr);
2564 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2565 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2566 ok(dst == 12345678.0, "got %f\n", dst);
2568 dst = 1.0;
2569 *(FLOAT *)src = 10.0;
2570 dst_len = 0x1234;
2571 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_R4, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2572 ok(hr == S_OK, "got %08x\n", hr);
2573 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2574 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2575 ok(dst == 10.0, "got %f\n", dst);
2577 dst_len = 44;
2578 V_VT(&v) = VT_NULL;
2579 hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_R4, 0, &dst_len, &v, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2580 ok(hr == S_OK, "got %08x\n", hr);
2581 ok(dst_status == DBSTATUS_S_ISNULL, "got %08x\n", dst_status);
2582 ok(dst_len == 44, "got %ld\n", dst_len);
2584 dst_len = dst = 0x1234;
2585 V_VT(&v) = VT_I2;
2586 V_I2(&v) = 0x4321;
2587 hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_R4, 0, &dst_len, &v, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2588 ok(hr == S_OK, "got %08x\n", hr);
2589 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2590 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2591 ok(dst == 0x4321, "got %f\n", dst);
2594 static void test_converttor8(void)
2596 HRESULT hr;
2597 DOUBLE dst;
2598 BYTE src[20];
2599 DBSTATUS dst_status;
2600 DBLENGTH dst_len;
2601 VARIANT var;
2603 dst = 1.0;
2604 dst_len = 0x1234;
2605 hr = IDataConvert_DataConvert(convert, DBTYPE_EMPTY, DBTYPE_R8, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2606 ok(hr == S_OK, "got %08x\n", hr);
2607 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2608 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2609 ok(dst == 0.0, "got %f\n", dst);
2611 dst = 1.0;
2612 dst_len = 0x1234;
2613 hr = IDataConvert_DataConvert(convert, DBTYPE_NULL, DBTYPE_R8, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2614 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr);
2615 ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status);
2616 ok(dst_len == 0x1234, "got %ld\n", dst_len);
2617 ok(dst == 1.0, "got %f\n", dst);
2619 dst = 1.0;
2620 *(signed int*)src = 12345678;
2621 dst_len = 0x1234;
2622 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_R8, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2623 ok(hr == S_OK, "got %08x\n", hr);
2624 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2625 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2626 ok(dst == 12345678.0, "got %f\n", dst);
2628 dst = 1.0;
2629 *(FLOAT *)src = 10.0;
2630 dst_len = 0x1234;
2631 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_R8, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2632 ok(hr == S_OK, "got %08x\n", hr);
2633 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2634 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2635 ok(dst == 10.0, "got %f\n", dst);
2637 dst_len = dst = 0x1234;
2638 V_VT(&var) = VT_I2;
2639 V_I2(&var) = 0x4321;
2640 hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_R8, 0, &dst_len, &var, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2641 ok(hr == S_OK, "got %08x\n", hr);
2642 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2643 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2644 ok(dst == 0x4321, "got %f\n", dst);
2646 dst_len = 44;
2647 V_VT(&var) = VT_NULL;
2648 hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_R8, 0, &dst_len, &var, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2649 ok(hr == S_OK, "got %08x\n", hr);
2650 ok(dst_status == DBSTATUS_S_ISNULL, "got %08x\n", dst_status);
2651 ok(dst_len == 44, "got %ld\n", dst_len);
2654 static void test_converttocy(void)
2656 HRESULT hr;
2657 CY dst;
2658 BYTE src[20];
2659 DBSTATUS dst_status;
2660 DBLENGTH dst_len;
2661 VARIANT v;
2663 VariantInit(&v);
2665 dst.int64 = 0xcc;
2666 dst_len = 0x1234;
2667 hr = IDataConvert_DataConvert(convert, DBTYPE_EMPTY, DBTYPE_CY, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2668 ok(hr == S_OK, "got %08x\n", hr);
2669 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2670 ok(dst_len == sizeof(CY), "got %ld\n", dst_len);
2671 ok(dst.int64 == 0, "didn't get 0\n");
2673 dst.int64 = 0xcc;
2674 dst_len = 0x1234;
2675 hr = IDataConvert_DataConvert(convert, DBTYPE_NULL, DBTYPE_CY, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2676 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr);
2677 ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status);
2678 ok(dst_len == 0x1234, "got %ld\n", dst_len);
2679 ok(dst.int64 == 0xcc, "dst changed\n");
2681 dst.int64 = 0xcc;
2682 *(int*)src = 1234;
2683 dst_len = 0x1234;
2684 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_CY, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2685 ok(hr == S_OK, "got %08x\n", hr);
2686 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2687 ok(dst_len == sizeof(CY), "got %ld\n", dst_len);
2688 ok(dst.int64 == 12340000, "got %d\n", dst.s.Lo);
2690 dst.int64 = 0xcc;
2691 ((CY*)src)->int64 = 1234;
2692 dst_len = 0x1234;
2693 hr = IDataConvert_DataConvert(convert, DBTYPE_CY, DBTYPE_CY, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2694 ok(hr == S_OK, "got %08x\n", hr);
2695 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2696 ok(dst_len == sizeof(CY), "got %ld\n", dst_len);
2697 ok(dst.int64 == 1234, "got %d\n", dst.s.Lo);
2699 dst_len = 44;
2700 V_VT(&v) = VT_NULL;
2701 hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_CY, 0, &dst_len, &v, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2702 ok(hr == S_OK, "got %08x\n", hr);
2703 ok(dst_status == DBSTATUS_S_ISNULL, "got %08x\n", dst_status);
2704 ok(dst_len == 44, "got %ld\n", dst_len);
2707 static void test_converttoui8(void)
2709 HRESULT hr;
2710 ULARGE_INTEGER dst;
2711 BYTE src[20];
2712 DBSTATUS dst_status;
2713 DBLENGTH dst_len;
2714 VARIANT v;
2716 VariantInit(&v);
2718 dst.QuadPart = 0xcc;
2719 dst_len = 0x1234;
2720 hr = IDataConvert_DataConvert(convert, DBTYPE_EMPTY, DBTYPE_UI8, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2721 ok(hr == S_OK, "got %08x\n", hr);
2722 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2723 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2724 ok(dst.QuadPart == 0, "got %d\n", (int)dst.QuadPart);
2726 dst.QuadPart = 0xcc;
2727 dst_len = 0x1234;
2728 hr = IDataConvert_DataConvert(convert, DBTYPE_NULL, DBTYPE_UI8, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2729 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr);
2730 ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status);
2731 ok(dst_len == 0x1234, "got %ld\n", dst_len);
2732 ok(dst.QuadPart == 0xcc, "dst changed\n");
2734 dst.QuadPart = 0xcc;
2735 *(int*)src = 1234;
2736 dst_len = 0x1234;
2737 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_UI8, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2738 ok(hr == S_OK, "got %08x\n", hr);
2739 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2740 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2741 ok(dst.QuadPart == 1234, "got %d\n", (int)dst.QuadPart);
2743 dst.QuadPart = 0xcc;
2744 *(int*)src = -1234;
2745 dst_len = 0x1234;
2746 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_UI8, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2747 ok(hr == DB_E_ERRORSOCCURRED, "got %08x\n", hr);
2748 todo_wine
2749 ok(dst_status == DBSTATUS_E_SIGNMISMATCH, "got %08x\n", dst_status);
2750 todo_wine
2751 ok(dst_len == 0x1234, "got %ld\n", dst_len);
2752 ok(dst.QuadPart == 0xcc, "got %d\n", (int)dst.QuadPart);
2754 dst.QuadPart = 0xcc;
2755 ((ULARGE_INTEGER*)src)->QuadPart = 1234;
2756 dst_len = 0x1234;
2757 hr = IDataConvert_DataConvert(convert, DBTYPE_UI8, DBTYPE_UI8, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2758 ok(hr == S_OK, "got %08x\n", hr);
2759 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2760 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2761 ok(dst.QuadPart == 1234, "got %d\n", (int)dst.QuadPart);
2763 dst_len = 44;
2764 V_VT(&v) = VT_NULL;
2765 hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_UI8, 0, &dst_len, &v, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2766 ok(hr == S_OK, "got %08x\n", hr);
2767 ok(dst_status == DBSTATUS_S_ISNULL, "got %08x\n", dst_status);
2768 ok(dst_len == 44, "got %ld\n", dst_len);
2771 static void test_getconversionsize(void)
2773 DBLENGTH dst_len;
2774 DBLENGTH src_len;
2775 HRESULT hr;
2776 BSTR str;
2777 static WCHAR strW[] = {'t','e','s','t',0};
2778 static char strTest[] = "test";
2779 VARIANT var;
2780 SAFEARRAY *psa = NULL;
2781 SAFEARRAYBOUND rgsabound[1];
2782 int i4 = 200;
2783 WORD i2 = 201;
2784 char i1 = 203;
2785 FLOAT f4 = 1.0;
2786 LONGLONG i8 = 202;
2787 DATE dbdate;
2788 DECIMAL dec;
2789 DBTIMESTAMP ts = {2013, 5, 14, 2, 4, 12, 0};
2790 DBTIME dbtime;
2791 DBDATE dbdate1;
2793 /* same way as CanConvert fails here */
2794 dst_len = 0;
2795 hr = IDataConvert_GetConversionSize(convert, DBTYPE_NULL, DBTYPE_BSTR, NULL, &dst_len, NULL);
2796 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got 0x%08x\n", hr);
2798 dst_len = 0;
2799 hr = IDataConvert_GetConversionSize(convert, DBTYPE_I2, DBTYPE_I4, NULL, &dst_len, NULL);
2800 ok(hr == S_OK, "got 0x%08x\n", hr);
2801 ok(dst_len == 4, "got %ld\n", dst_len);
2803 hr = IDataConvert_GetConversionSize(convert, DBTYPE_I2, DBTYPE_I4, NULL, NULL, NULL);
2804 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
2806 /* size doesn't include string size */
2807 str = SysAllocStringLen(NULL, 10);
2808 dst_len = 0;
2809 hr = IDataConvert_GetConversionSize(convert, DBTYPE_BSTR, DBTYPE_VARIANT, NULL, &dst_len, str);
2810 ok(hr == S_OK, "got 0x%08x\n", hr);
2811 ok(dst_len == sizeof(VARIANT), "%ld\n", dst_len);
2812 SysFreeString(str);
2814 dst_len = 0;
2815 hr = IDataConvert_GetConversionSize(convert, DBTYPE_WSTR, DBTYPE_WSTR, NULL, &dst_len, strW);
2816 ok(hr == S_OK, "got 0x%08x\n", hr);
2817 ok(dst_len == 10, "%ld\n", dst_len);
2819 dst_len = 0;
2820 src_len = 2;
2821 hr = IDataConvert_GetConversionSize(convert, DBTYPE_WSTR, DBTYPE_WSTR, &src_len, &dst_len, strW);
2822 ok(hr == S_OK, "got 0x%08x\n", hr);
2823 ok(dst_len == 4, "%ld\n", dst_len);
2825 dst_len = 0;
2826 src_len = 20;
2827 hr = IDataConvert_GetConversionSize(convert, DBTYPE_WSTR, DBTYPE_WSTR, &src_len, &dst_len, strW);
2828 ok(hr == S_OK, "got 0x%08x\n", hr);
2829 ok(dst_len == 22, "%ld\n", dst_len);
2831 dst_len = 0;
2832 hr = IDataConvert_GetConversionSize(convert, DBTYPE_STR, DBTYPE_WSTR, NULL, &dst_len, strTest);
2833 ok(hr == S_OK, "got 0x%08x\n", hr);
2834 ok(dst_len == 10 || broken(dst_len == 12), "%ld\n", dst_len);
2836 dst_len = 0;
2837 src_len = 2;
2838 hr = IDataConvert_GetConversionSize(convert, DBTYPE_STR, DBTYPE_WSTR, &src_len, &dst_len, strTest);
2839 ok(hr == S_OK, "got 0x%08x\n", hr);
2840 ok(dst_len == 6, "%ld\n", dst_len);
2842 dst_len = 0;
2843 src_len = 20;
2844 hr = IDataConvert_GetConversionSize(convert, DBTYPE_STR, DBTYPE_WSTR, &src_len, &dst_len, strTest);
2845 ok(hr == S_OK, "got 0x%08x\n", hr);
2846 ok(dst_len == 42, "%ld\n", dst_len);
2848 dst_len = 0;
2849 V_VT(&var) = VT_BSTR;
2850 V_BSTR(&var) = SysAllocString(strW);
2851 hr = IDataConvert_GetConversionSize(convert, DBTYPE_VARIANT, DBTYPE_WSTR, NULL, &dst_len, &var);
2852 ok(hr == S_OK, "got 0x%08x\n", hr);
2853 ok(dst_len == 10, "%ld\n", dst_len);
2854 VariantClear(&var);
2856 dst_len = 0;
2857 src_len = 20;
2858 V_VT(&var) = VT_BSTR;
2859 V_BSTR(&var) = SysAllocString(strW);
2860 hr = IDataConvert_GetConversionSize(convert, DBTYPE_VARIANT, DBTYPE_WSTR, &src_len, &dst_len, &var);
2861 ok(hr == S_OK, "got 0x%08x\n", hr);
2862 ok(dst_len == 10, "%ld\n", dst_len);
2863 VariantClear(&var);
2865 dst_len = 0;
2866 src_len = 20;
2867 V_VT(&var) = VT_I4;
2868 V_I4(&var) = 4;
2869 hr = IDataConvert_GetConversionSize(convert, DBTYPE_VARIANT, DBTYPE_WSTR, &src_len, &dst_len, &var);
2870 ok(hr == S_OK, "got 0x%08x\n", hr);
2871 VariantClear(&var);
2873 dst_len = 0;
2874 src_len = 20;
2875 V_VT(&var) = VT_BSTR;
2876 V_BSTR(&var) = SysAllocString(strW);
2877 hr = IDataConvert_GetConversionSize(convert, DBTYPE_VARIANT, DBTYPE_STR, &src_len, &dst_len, &var);
2878 ok(hr == S_OK, "got 0x%08x\n", hr);
2879 ok(dst_len == 5, "%ld\n", dst_len);
2880 VariantClear(&var);
2882 src_len = 20;
2883 V_VT(&var) = VT_I4;
2884 V_I4(&var) = 4;
2885 hr = IDataConvert_GetConversionSize(convert, DBTYPE_VARIANT, DBTYPE_STR, &src_len, &dst_len, &var);
2886 ok(hr == S_OK, "got 0x%08x\n", hr);
2887 VariantClear(&var);
2889 dst_len = 0;
2890 src_len = 20;
2891 V_VT(&var) = VT_BSTR;
2892 V_BSTR(&var) = SysAllocString(strW);
2893 hr = IDataConvert_GetConversionSize(convert, DBTYPE_VARIANT, DBTYPE_BYTES, &src_len, &dst_len, &var);
2894 ok(hr == S_OK, "got 0x%08x\n", hr);
2895 ok(dst_len == 2, "%ld\n", dst_len);
2896 VariantClear(&var);
2898 dst_len = 0;
2899 src_len = 20;
2900 rgsabound[0].lLbound = 0;
2901 rgsabound[0].cElements = 1802;
2902 psa = SafeArrayCreate(VT_UI1,1,rgsabound);
2904 V_VT(&var) = VT_ARRAY|VT_UI1;
2905 V_ARRAY(&var) = psa;
2906 hr = IDataConvert_GetConversionSize(convert, DBTYPE_VARIANT, DBTYPE_BYTES, &src_len, &dst_len, &var);
2907 ok(hr == S_OK, "got 0x%08x\n", hr);
2908 ok(dst_len == 1802, "%ld\n", dst_len);
2909 VariantClear(&var);
2911 /* On Windows, NULL variants being convert to a non-fixed sized type will return a dst_len of
2912 * 110 but we aren't testing for this value.
2914 dst_len = 32;
2915 V_VT(&var) = VT_NULL;
2916 hr = IDataConvert_GetConversionSize(convert, DBTYPE_VARIANT, DBTYPE_I4, NULL, &dst_len, &var);
2917 ok(dst_len == 4, "%ld\n", dst_len);
2918 ok(hr == S_OK, "got 0x%08x\n", hr);
2920 V_VT(&var) = VT_NULL;
2921 hr = IDataConvert_GetConversionSize(convert, DBTYPE_VARIANT, DBTYPE_STR, NULL, &dst_len, &var);
2922 ok(hr == S_OK, "got 0x%08x\n", hr);
2923 ok(dst_len == 110, "%ld\n", dst_len);
2925 V_VT(&var) = VT_NULL;
2926 hr = IDataConvert_GetConversionSize(convert, DBTYPE_VARIANT, DBTYPE_WSTR, NULL, &dst_len, &var);
2927 ok(hr == S_OK, "got 0x%08x\n", hr);
2928 ok(dst_len == 110, "%ld\n", dst_len);
2930 src_len = 20;
2931 V_VT(&var) = VT_NULL;
2932 hr = IDataConvert_GetConversionSize(convert, DBTYPE_VARIANT, DBTYPE_BYTES, &src_len, &dst_len, &var);
2933 ok(hr == S_OK, "got 0x%08x\n", hr);
2934 ok(dst_len == 110, "%ld\n", dst_len);
2935 VariantClear(&var);
2937 hr = IDataConvert_GetConversionSize(convert, DBTYPE_NUMERIC, DBTYPE_NUMERIC, NULL, &dst_len, NULL);
2938 ok(hr == S_OK, "got 0x%08x\n", hr);
2939 ok(dst_len == sizeof(DB_NUMERIC), "%ld\n", dst_len);
2941 dst_len = 0;
2942 src_len = sizeof(i4);
2943 hr = IDataConvert_GetConversionSize(convert, DBTYPE_I4, DBTYPE_WSTR, &src_len, &dst_len, &i4);
2944 ok(hr == S_OK, "got 0x%08x\n", hr);
2945 ok(dst_len == 110, "%ld\n", dst_len);
2947 dst_len = 0;
2948 hr = IDataConvert_GetConversionSize(convert, DBTYPE_I4, DBTYPE_WSTR, NULL, &dst_len, NULL);
2949 ok(hr == S_OK, "got 0x%08x\n", hr);
2950 ok(dst_len == 110, "%ld\n", dst_len);
2952 dst_len = 0;
2953 src_len = sizeof(i4);
2954 hr = IDataConvert_GetConversionSize(convert, DBTYPE_UI4, DBTYPE_WSTR, &src_len, &dst_len, &i4);
2955 ok(hr == S_OK, "got 0x%08x\n", hr);
2956 ok(dst_len == 110, "%ld\n", dst_len);
2958 dst_len = 0;
2959 hr = IDataConvert_GetConversionSize(convert, DBTYPE_UI4, DBTYPE_WSTR, NULL, &dst_len, NULL);
2960 ok(hr == S_OK, "got 0x%08x\n", hr);
2961 ok(dst_len == 110, "%ld\n", dst_len);
2963 dst_len = 0;
2964 src_len = sizeof(i2);
2965 hr = IDataConvert_GetConversionSize(convert, DBTYPE_I2, DBTYPE_WSTR, &src_len, &dst_len, &i2);
2966 ok(hr == S_OK, "got 0x%08x\n", hr);
2967 ok(dst_len == 110, "%ld\n", dst_len);
2969 dst_len = 0;
2970 hr = IDataConvert_GetConversionSize(convert, DBTYPE_I2, DBTYPE_WSTR, NULL, &dst_len, NULL);
2971 ok(hr == S_OK, "got 0x%08x\n", hr);
2972 ok(dst_len == 110, "%ld\n", dst_len);
2974 dst_len = 0;
2975 src_len = sizeof(i2);
2976 hr = IDataConvert_GetConversionSize(convert, DBTYPE_UI2, DBTYPE_WSTR, &src_len, &dst_len, &i2);
2977 ok(hr == S_OK, "got 0x%08x\n", hr);
2978 ok(dst_len == 110, "%ld\n", dst_len);
2980 dst_len = 0;
2981 src_len = sizeof(i1);
2982 hr = IDataConvert_GetConversionSize(convert, DBTYPE_I1, DBTYPE_WSTR, &src_len, &dst_len, &i1);
2983 ok(hr == S_OK, "got 0x%08x\n", hr);
2984 ok(dst_len == 110, "%ld\n", dst_len);
2986 dst_len = 0;
2987 hr = IDataConvert_GetConversionSize(convert, DBTYPE_I1, DBTYPE_WSTR, NULL, &dst_len, NULL);
2988 ok(hr == S_OK, "got 0x%08x\n", hr);
2989 ok(dst_len == 110, "%ld\n", dst_len);
2991 dst_len = 0;
2992 src_len = sizeof(i2);
2993 hr = IDataConvert_GetConversionSize(convert, DBTYPE_UI2, DBTYPE_WSTR, &src_len, &dst_len, &i2);
2994 ok(hr == S_OK, "got 0x%08x\n", hr);
2995 ok(dst_len == 110, "%ld\n", dst_len);
2997 dst_len = 0;
2998 hr = IDataConvert_GetConversionSize(convert, DBTYPE_UI2, DBTYPE_WSTR, NULL, &dst_len, NULL);
2999 ok(hr == S_OK, "got 0x%08x\n", hr);
3000 ok(dst_len == 110, "%ld\n", dst_len);
3002 dst_len = 0;
3003 src_len = sizeof(f4);
3004 hr = IDataConvert_GetConversionSize(convert, DBTYPE_R4, DBTYPE_WSTR, &src_len, &dst_len, &f4);
3005 ok(hr == S_OK, "got 0x%08x\n", hr);
3006 ok(dst_len == 110, "%ld\n", dst_len);
3008 dst_len = 0;
3009 hr = IDataConvert_GetConversionSize(convert, DBTYPE_R4, DBTYPE_WSTR, NULL, &dst_len, NULL);
3010 ok(hr == S_OK, "got 0x%08x\n", hr);
3011 ok(dst_len == 110, "%ld\n", dst_len);
3013 dst_len = 0;
3014 src_len = sizeof(i8);
3015 hr = IDataConvert_GetConversionSize(convert, DBTYPE_UI8, DBTYPE_WSTR, &src_len, &dst_len, &i8);
3016 ok(hr == S_OK, "got 0x%08x\n", hr);
3017 ok(dst_len == 110, "%ld\n", dst_len);
3019 dst_len = 0;
3020 hr = IDataConvert_GetConversionSize(convert, DBTYPE_UI8, DBTYPE_WSTR, NULL, &dst_len, NULL);
3021 ok(hr == S_OK, "got 0x%08x\n", hr);
3022 ok(dst_len == 110, "%ld\n", dst_len);
3024 dst_len = 0;
3025 src_len = sizeof(i8);
3026 hr = IDataConvert_GetConversionSize(convert, DBTYPE_I8, DBTYPE_WSTR, &src_len, &dst_len, &i8);
3027 ok(hr == S_OK, "got 0x%08x\n", hr);
3028 ok(dst_len == 110, "%ld\n", dst_len);
3030 dst_len = 0;
3031 hr = IDataConvert_GetConversionSize(convert, DBTYPE_I8, DBTYPE_WSTR, NULL, &dst_len, NULL);
3032 ok(hr == S_OK, "got 0x%08x\n", hr);
3033 ok(dst_len == 110, "%ld\n", dst_len);
3035 dst_len = 0;
3036 src_len = sizeof(dbdate);
3037 hr = IDataConvert_GetConversionSize(convert, DBTYPE_DATE, DBTYPE_WSTR, &src_len, &dst_len, &dbdate);
3038 ok(hr == S_OK, "got 0x%08x\n", hr);
3039 ok(dst_len == 110, "%ld\n", dst_len);
3041 dst_len = 0;
3042 hr = IDataConvert_GetConversionSize(convert, DBTYPE_DATE, DBTYPE_WSTR, NULL, &dst_len, NULL);
3043 ok(hr == S_OK, "got 0x%08x\n", hr);
3044 ok(dst_len == 110, "%ld\n", dst_len);
3046 dst_len = 0;
3047 src_len = sizeof(dec);
3048 hr = IDataConvert_GetConversionSize(convert, DBTYPE_DECIMAL, DBTYPE_WSTR, &src_len, &dst_len, &dec);
3049 ok(hr == S_OK, "got 0x%08x\n", hr);
3050 ok(dst_len == 110, "%ld\n", dst_len);
3052 dst_len = 0;
3053 hr = IDataConvert_GetConversionSize(convert, DBTYPE_DECIMAL, DBTYPE_WSTR, NULL, &dst_len, NULL);
3054 ok(hr == S_OK, "got 0x%08x\n", hr);
3055 ok(dst_len == 110, "%ld\n", dst_len);
3057 dst_len = 0;
3058 hr = IDataConvert_GetConversionSize(convert, DBTYPE_EMPTY, DBTYPE_WSTR, NULL, &dst_len, NULL);
3059 ok(hr == S_OK, "got 0x%08x\n", hr);
3060 ok(dst_len == 110, "%ld\n", dst_len);
3062 dst_len = 0;
3063 src_len = sizeof(ts);
3064 hr = IDataConvert_GetConversionSize(convert, DBTYPE_DBTIMESTAMP, DBTYPE_WSTR, &src_len, &dst_len, &ts);
3065 ok(hr == S_OK, "got 0x%08x\n", hr);
3066 ok(dst_len == 110, "%ld\n", dst_len);
3068 dst_len = 0;
3069 hr = IDataConvert_GetConversionSize(convert, DBTYPE_DBTIMESTAMP, DBTYPE_WSTR, NULL, &dst_len, NULL);
3070 ok(hr == S_OK, "got 0x%08x\n", hr);
3071 ok(dst_len == 110, "%ld\n", dst_len);
3073 dst_len = 0;
3074 src_len = sizeof(dbtime);
3075 hr = IDataConvert_GetConversionSize(convert, DBTYPE_DBTIME, DBTYPE_WSTR, &src_len, &dst_len, &dbtime);
3076 ok(hr == S_OK, "got 0x%08x\n", hr);
3077 ok(dst_len == 110, "%ld\n", dst_len);
3079 dst_len = 0;
3080 hr = IDataConvert_GetConversionSize(convert, DBTYPE_DBTIME, DBTYPE_WSTR, NULL, &dst_len, NULL);
3081 ok(hr == S_OK, "got 0x%08x\n", hr);
3082 ok(dst_len == 110, "%ld\n", dst_len);
3084 dst_len = 0;
3085 src_len = sizeof(dbdate1);
3086 hr = IDataConvert_GetConversionSize(convert, DBTYPE_DBDATE, DBTYPE_WSTR, &src_len, &dst_len, &dbdate1);
3087 ok(hr == S_OK, "got 0x%08x\n", hr);
3088 ok(dst_len == 110, "%ld\n", dst_len);
3090 dst_len = 0;
3091 hr = IDataConvert_GetConversionSize(convert, DBTYPE_DBDATE, DBTYPE_WSTR, NULL, &dst_len, NULL);
3092 ok(hr == S_OK, "got 0x%08x\n", hr);
3093 ok(dst_len == 110, "%ld\n", dst_len);
3095 dst_len = 0;
3096 src_len = sizeof(i4);
3097 hr = IDataConvert_GetConversionSize(convert, DBTYPE_I4, DBTYPE_STR, &src_len, &dst_len, &i4);
3098 ok(hr == S_OK, "got 0x%08x\n", hr);
3099 ok(dst_len == 110, "%ld\n", dst_len);
3101 dst_len = 0;
3102 hr = IDataConvert_GetConversionSize(convert, DBTYPE_I4, DBTYPE_STR, NULL, &dst_len, NULL);
3103 ok(hr == S_OK, "got 0x%08x\n", hr);
3104 ok(dst_len == 110, "%ld\n", dst_len);
3106 dst_len = 0;
3107 src_len = sizeof(i4);
3108 hr = IDataConvert_GetConversionSize(convert, DBTYPE_UI4, DBTYPE_STR, &src_len, &dst_len, &i4);
3109 ok(hr == S_OK, "got 0x%08x\n", hr);
3110 ok(dst_len == 110, "%ld\n", dst_len);
3112 dst_len = 0;
3113 hr = IDataConvert_GetConversionSize(convert, DBTYPE_UI4, DBTYPE_STR, NULL, &dst_len, NULL);
3114 ok(hr == S_OK, "got 0x%08x\n", hr);
3115 ok(dst_len == 110, "%ld\n", dst_len);
3117 dst_len = 0;
3118 src_len = sizeof(i2);
3119 hr = IDataConvert_GetConversionSize(convert, DBTYPE_I2, DBTYPE_STR, &src_len, &dst_len, &i2);
3120 ok(hr == S_OK, "got 0x%08x\n", hr);
3121 ok(dst_len == 110, "%ld\n", dst_len);
3123 dst_len = 0;
3124 hr = IDataConvert_GetConversionSize(convert, DBTYPE_I2, DBTYPE_STR, NULL, &dst_len, NULL);
3125 ok(hr == S_OK, "got 0x%08x\n", hr);
3126 ok(dst_len == 110, "%ld\n", dst_len);
3128 dst_len = 0;
3129 src_len = sizeof(i2);
3130 hr = IDataConvert_GetConversionSize(convert, DBTYPE_UI2, DBTYPE_STR, &src_len, &dst_len, &i2);
3131 ok(hr == S_OK, "got 0x%08x\n", hr);
3132 ok(dst_len == 110, "%ld\n", dst_len);
3134 dst_len = 0;
3135 src_len = sizeof(i1);
3136 hr = IDataConvert_GetConversionSize(convert, DBTYPE_I1, DBTYPE_STR, &src_len, &dst_len, &i1);
3137 ok(hr == S_OK, "got 0x%08x\n", hr);
3138 ok(dst_len == 110, "%ld\n", dst_len);
3140 dst_len = 0;
3141 hr = IDataConvert_GetConversionSize(convert, DBTYPE_I1, DBTYPE_STR, NULL, &dst_len, NULL);
3142 ok(hr == S_OK, "got 0x%08x\n", hr);
3143 ok(dst_len == 110, "%ld\n", dst_len);
3145 dst_len = 0;
3146 src_len = sizeof(i2);
3147 hr = IDataConvert_GetConversionSize(convert, DBTYPE_UI2, DBTYPE_STR, &src_len, &dst_len, &i2);
3148 ok(hr == S_OK, "got 0x%08x\n", hr);
3149 ok(dst_len == 110, "%ld\n", dst_len);
3151 dst_len = 0;
3152 hr = IDataConvert_GetConversionSize(convert, DBTYPE_UI2, DBTYPE_STR, NULL, &dst_len, NULL);
3153 ok(hr == S_OK, "got 0x%08x\n", hr);
3154 ok(dst_len == 110, "%ld\n", dst_len);
3156 dst_len = 0;
3157 src_len = sizeof(f4);
3158 hr = IDataConvert_GetConversionSize(convert, DBTYPE_R4, DBTYPE_STR, &src_len, &dst_len, &f4);
3159 ok(hr == S_OK, "got 0x%08x\n", hr);
3160 ok(dst_len == 110, "%ld\n", dst_len);
3162 dst_len = 0;
3163 hr = IDataConvert_GetConversionSize(convert, DBTYPE_R4, DBTYPE_STR, NULL, &dst_len, NULL);
3164 ok(hr == S_OK, "got 0x%08x\n", hr);
3165 ok(dst_len == 110, "%ld\n", dst_len);
3167 dst_len = 0;
3168 src_len = sizeof(i8);
3169 hr = IDataConvert_GetConversionSize(convert, DBTYPE_UI8, DBTYPE_STR, &src_len, &dst_len, &i8);
3170 ok(hr == S_OK, "got 0x%08x\n", hr);
3171 ok(dst_len == 110, "%ld\n", dst_len);
3173 dst_len = 0;
3174 hr = IDataConvert_GetConversionSize(convert, DBTYPE_UI8, DBTYPE_STR, NULL, &dst_len, NULL);
3175 ok(hr == S_OK, "got 0x%08x\n", hr);
3176 ok(dst_len == 110, "%ld\n", dst_len);
3178 dst_len = 0;
3179 src_len = sizeof(i8);
3180 hr = IDataConvert_GetConversionSize(convert, DBTYPE_I8, DBTYPE_STR, &src_len, &dst_len, &i8);
3181 ok(hr == S_OK, "got 0x%08x\n", hr);
3182 ok(dst_len == 110, "%ld\n", dst_len);
3184 dst_len = 0;
3185 hr = IDataConvert_GetConversionSize(convert, DBTYPE_I8, DBTYPE_STR, NULL, &dst_len, NULL);
3186 ok(hr == S_OK, "got 0x%08x\n", hr);
3187 ok(dst_len == 110, "%ld\n", dst_len);
3189 dst_len = 0;
3190 src_len = sizeof(dbdate);
3191 hr = IDataConvert_GetConversionSize(convert, DBTYPE_DATE, DBTYPE_STR, &src_len, &dst_len, &dbdate);
3192 ok(hr == S_OK, "got 0x%08x\n", hr);
3193 ok(dst_len == 110, "%ld\n", dst_len);
3195 dst_len = 0;
3196 hr = IDataConvert_GetConversionSize(convert, DBTYPE_DATE, DBTYPE_STR, NULL, &dst_len, NULL);
3197 ok(hr == S_OK, "got 0x%08x\n", hr);
3198 ok(dst_len == 110, "%ld\n", dst_len);
3200 dst_len = 0;
3201 src_len = sizeof(dec);
3202 hr = IDataConvert_GetConversionSize(convert, DBTYPE_DECIMAL, DBTYPE_STR, &src_len, &dst_len, &dec);
3203 ok(hr == S_OK, "got 0x%08x\n", hr);
3204 ok(dst_len == 110, "%ld\n", dst_len);
3206 dst_len = 0;
3207 hr = IDataConvert_GetConversionSize(convert, DBTYPE_DECIMAL, DBTYPE_STR, NULL, &dst_len, NULL);
3208 ok(hr == S_OK, "got 0x%08x\n", hr);
3209 ok(dst_len == 110, "%ld\n", dst_len);
3211 dst_len = 0;
3212 hr = IDataConvert_GetConversionSize(convert, DBTYPE_EMPTY, DBTYPE_STR, NULL, &dst_len, NULL);
3213 ok(hr == S_OK, "got 0x%08x\n", hr);
3214 ok(dst_len == 110, "%ld\n", dst_len);
3216 dst_len = 0;
3217 src_len = sizeof(ts);
3218 hr = IDataConvert_GetConversionSize(convert, DBTYPE_DBTIMESTAMP, DBTYPE_STR, &src_len, &dst_len, &ts);
3219 ok(hr == S_OK, "got 0x%08x\n", hr);
3220 ok(dst_len == 110, "%ld\n", dst_len);
3222 dst_len = 0;
3223 hr = IDataConvert_GetConversionSize(convert, DBTYPE_DBTIMESTAMP, DBTYPE_STR, NULL, &dst_len, NULL);
3224 ok(hr == S_OK, "got 0x%08x\n", hr);
3225 ok(dst_len == 110, "%ld\n", dst_len);
3227 dst_len = 0;
3228 src_len = sizeof(dbtime);
3229 hr = IDataConvert_GetConversionSize(convert, DBTYPE_DBTIME, DBTYPE_STR, &src_len, &dst_len, &dbtime);
3230 ok(hr == S_OK, "got 0x%08x\n", hr);
3231 ok(dst_len == 110, "%ld\n", dst_len);
3233 dst_len = 0;
3234 hr = IDataConvert_GetConversionSize(convert, DBTYPE_DBTIME, DBTYPE_STR, NULL, &dst_len, NULL);
3235 ok(hr == S_OK, "got 0x%08x\n", hr);
3236 ok(dst_len == 110, "%ld\n", dst_len);
3238 dst_len = 0;
3239 src_len = sizeof(dbdate1);
3240 hr = IDataConvert_GetConversionSize(convert, DBTYPE_DBDATE, DBTYPE_STR, &src_len, &dst_len, &dbdate1);
3241 ok(hr == S_OK, "got 0x%08x\n", hr);
3242 ok(dst_len == 110, "%ld\n", dst_len);
3244 dst_len = 0;
3245 hr = IDataConvert_GetConversionSize(convert, DBTYPE_DBDATE, DBTYPE_STR, NULL, &dst_len, NULL);
3246 ok(hr == S_OK, "got 0x%08x\n", hr);
3247 ok(dst_len == 110, "%ld\n", dst_len);
3250 static void test_converttobytes(void)
3252 DBLENGTH dst_len;
3253 HRESULT hr;
3254 BYTE byte_src[] = {0, 1, 2, 4, 5};
3255 BYTE byte_dst[] = {0, 0, 0, 0, 0};
3256 BYTE dst[10] = {0};
3257 DBSTATUS dst_status;
3258 VARIANT v;
3259 SAFEARRAY *psa = NULL;
3260 SAFEARRAYBOUND rgsabound[1];
3262 dst_len = 0;
3263 hr = IDataConvert_DataConvert(convert, DBTYPE_BYTES, DBTYPE_BYTES, sizeof(byte_src), &dst_len, byte_src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
3264 ok(hr == S_OK, "got %08x\n", hr);
3265 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
3266 ok(dst_len == sizeof(byte_src), "got %ld\n", dst_len);
3267 ok(!memcmp(byte_src, dst, dst_len ), "bytes differ\n");
3269 dst_len = 0;
3270 hr = IDataConvert_DataConvert(convert, DBTYPE_BYTES, DBTYPE_BYTES, sizeof(byte_src), &dst_len, byte_src, &dst, 2, 0, &dst_status, 0, 0, 0);
3271 ok(hr == S_OK, "got %08x\n", hr);
3272 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
3273 ok(dst_len == sizeof(byte_src), "got %ld\n", dst_len);
3274 ok(!memcmp(byte_src, dst, 2 ), "bytes differ\n");
3276 V_VT(&v) = VT_NULL;
3277 dst_len = 77;
3278 hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_BYTES, sizeof(v), &dst_len, &v, &dst, 2, 0, &dst_status, 0, 0, 0);
3279 ok(hr == S_OK, "got %08x\n", hr);
3280 ok(dst_status == DBSTATUS_S_ISNULL, "got %08x\n", dst_status);
3281 ok(dst_len == 77, "got %ld\n", dst_len);
3283 dst_len = 0;
3284 rgsabound[0].lLbound = 0;
3285 rgsabound[0].cElements = 4;
3286 psa = SafeArrayCreate(VT_UI1,1,rgsabound);
3288 V_VT(&v) = VT_ARRAY|VT_UI1;
3289 V_ARRAY(&v) = psa;
3290 hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_BYTES, sizeof(v), &dst_len, &v, &dst, 10, 0, &dst_status, 0, 0, 0);
3291 ok(hr == S_OK, "got 0x%08x\n", hr);
3292 ok(dst_len == 4, "%ld\n", dst_len);
3293 ok(!memcmp(byte_dst, dst, dst_len), "bytes differ\n");
3294 VariantClear(&v);
3296 dst_len = 44;
3297 V_VT(&v) = VT_NULL;
3298 hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_BYTES, 0, &dst_len, &v, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
3299 ok(hr == S_OK, "got %08x\n", hr);
3300 ok(dst_status == DBSTATUS_S_ISNULL, "got %08x\n", dst_status);
3301 ok(dst_len == 44, "got %ld\n", dst_len);
3305 static void test_converttobytesbyref(void)
3307 DBLENGTH dst_len;
3308 HRESULT hr;
3309 BYTE byte_src[] = {0, 1, 2, 4, 5};
3310 BYTE *dst;
3311 DBSTATUS dst_status;
3312 VARIANT v;
3314 VariantInit(&v);
3316 dst_len = 0;
3317 hr = IDataConvert_DataConvert(convert, DBTYPE_BYTES, DBTYPE_BYTES | DBTYPE_BYREF, sizeof(byte_src), &dst_len, byte_src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
3318 ok(hr == S_OK, "got %08x\n", hr);
3319 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
3320 ok(dst_len == sizeof(byte_src), "got %ld\n", dst_len);
3321 ok(!memcmp(byte_src, dst, dst_len ), "bytes differ\n");
3322 CoTaskMemFree(dst);
3324 dst_len = 44;
3325 V_VT(&v) = VT_NULL;
3326 hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_BYTES | DBTYPE_BYREF, 0, &dst_len, &v, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
3327 ok(hr == S_OK, "got %08x\n", hr);
3328 ok(dst_status == DBSTATUS_S_ISNULL, "got %08x\n", dst_status);
3329 ok(dst_len == 44, "got %ld\n", dst_len);
3332 static void test_converttodbdate(void)
3334 DBLENGTH dst_len;
3335 HRESULT hr;
3336 static const WCHAR strW[] = {'2','0','1','3','-','0','5','-','1','4',0};
3337 DBDATE ts = {2013, 5, 14};
3338 DBDATE dst;
3339 DBSTATUS dst_status;
3340 VARIANT var;
3341 BSTR bstr;
3343 dst_len = 0;
3344 hr = IDataConvert_DataConvert(convert, DBTYPE_DBDATE, DBTYPE_DBDATE, sizeof(ts), &dst_len, &ts, &dst, 2, 0, &dst_status, 0, 0, 0);
3345 ok(hr == S_OK, "got %08x\n", hr);
3346 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
3347 ok(dst_len == sizeof(DBDATE), "got %ld\n", dst_len);
3348 ok(!memcmp(&ts, &dst, sizeof(DBDATE) ), "bytes differ\n");
3350 VariantInit(&var);
3351 V_VT(&var) = VT_DATE;
3352 V_DATE(&var) = 41408.086250;
3353 dst_len = 0;
3354 hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_DBDATE, sizeof(var), &dst_len, &var, &dst, 2, 0, &dst_status, 0, 0, 0);
3355 ok(hr == S_OK, "got %08x\n", hr);
3356 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
3357 ok(dst_len == sizeof(DBDATE), "got %ld\n", dst_len);
3358 ok(!memcmp(&ts, &dst, sizeof(DBDATE) ), "bytes differ\n");
3360 V_VT(&var) = VT_R8;
3361 V_R8(&var) = 41408.086250;
3362 dst_len = 0;
3363 hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_DBDATE, sizeof(var), &dst_len, &var, &dst, 2, 0, &dst_status, 0, 0, 0);
3364 ok(hr == S_OK, "got %08x\n", hr);
3365 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
3366 ok(dst_len == sizeof(DBDATE), "got %ld\n", dst_len);
3367 ok(!memcmp(&ts, &dst, sizeof(DBDATE) ), "bytes differ\n");
3369 V_VT(&var) = VT_BSTR;
3370 V_BSTR(&var) = SysAllocString(strW);
3371 dst_len = 0;
3372 hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_DBDATE, sizeof(var), &dst_len, &var, &dst, 2, 0, &dst_status, 0, 0, 0);
3373 ok(hr == S_OK, "got %08x\n", hr);
3374 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
3375 ok(dst_len == sizeof(DBDATE), "got %ld\n", dst_len);
3376 ok(!memcmp(&ts, &dst, sizeof(DBDATE) ), "bytes differ\n");
3377 VariantClear(&var);
3379 dst_len = 0;
3380 bstr = SysAllocString(strW);
3381 hr = IDataConvert_DataConvert(convert, DBTYPE_BSTR, DBTYPE_DBDATE, 0, &dst_len, &bstr, &dst, 2, 0, &dst_status, 0, 0, 0);
3382 ok(hr == S_OK, "got %08x\n", hr);
3383 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
3384 ok(dst_len == sizeof(DBDATE), "got %ld\n", dst_len);
3385 ok(!memcmp(&ts, &dst, sizeof(DBDATE) ), "bytes differ\n");
3386 SysFreeString(bstr);
3388 V_VT(&var) = VT_NULL;
3389 dst_len = 88;
3390 hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_DBDATE, sizeof(var), &dst_len, &var, &dst, 2, 0, &dst_status, 0, 0, 0);
3391 ok(hr == S_OK, "got %08x\n", hr);
3392 ok(dst_status == DBSTATUS_S_ISNULL, "got %08x\n", dst_status);
3393 ok(dst_len == 88, "got %ld\n", dst_len);
3397 static void test_converttovar(void)
3399 static WCHAR strW[] = {'t','e','s','t',0};
3400 BYTE byte_src[5] = {1, 2, 3, 4, 5};
3401 DBTIMESTAMP ts = {2013, 5, 14, 2, 4, 12, 0};
3402 DBDATE dbdate = {2013, 5, 15};
3403 double dvalue = 123.56;
3404 DBSTATUS dst_status;
3405 DBLENGTH dst_len;
3406 VARIANT dst;
3407 HRESULT hr;
3408 CY cy, cy2;
3409 DATE date;
3410 INT i4;
3411 signed short i2;
3412 LARGE_INTEGER i8;
3413 VARIANT_BOOL boolean = VARIANT_TRUE;
3414 FLOAT fvalue = 543.21f;
3415 VARIANT var;
3417 VariantInit(&var);
3419 V_VT(&dst) = VT_EMPTY;
3420 dst_len = 0;
3421 dst_status = DBSTATUS_S_DEFAULT;
3422 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_VARIANT, sizeof(strW), &dst_len, strW, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
3423 ok(hr == S_OK, "got %08x\n", hr);
3424 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
3425 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
3426 ok(V_VT(&dst) == VT_BSTR, "got %d\n", V_VT(&dst));
3427 ok(!lstrcmpW(V_BSTR(&dst), strW), "got %s\n", wine_dbgstr_w(V_BSTR(&dst)));
3428 VariantClear(&dst);
3430 /* with null dest length and status */
3431 V_VT(&dst) = VT_EMPTY;
3432 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_VARIANT, sizeof(strW), NULL, strW, &dst, sizeof(dst), 0, NULL, 0, 0, 0);
3433 ok(hr == S_OK, "got %08x\n", hr);
3434 ok(V_VT(&dst) == VT_BSTR, "got %d\n", V_VT(&dst));
3435 ok(!lstrcmpW(V_BSTR(&dst), strW), "got %s\n", wine_dbgstr_w(V_BSTR(&dst)));
3436 VariantClear(&dst);
3438 V_VT(&dst) = VT_EMPTY;
3439 dst_status = DBSTATUS_S_DEFAULT;
3440 i8.QuadPart = 12345;
3441 dst_len = 0x1234;
3442 hr = IDataConvert_DataConvert(convert, DBTYPE_I8, DBTYPE_VARIANT, sizeof(i8), &dst_len, &i8, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
3443 ok(hr == S_OK, "got %08x\n", hr);
3444 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
3445 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
3446 ok(V_VT(&dst) == VT_DECIMAL, "got %d\n", V_VT(&dst));
3447 ok(S(U(V_DECIMAL(&dst))).scale == 0 && S(U(V_DECIMAL(&dst))).sign == 0 &&
3448 V_DECIMAL(&dst).Hi32 == 0 && U1(V_DECIMAL(&dst)).Lo64 == 12345, "Not Equal\n");
3450 V_VT(&dst) = VT_EMPTY;
3451 dst_len = 0;
3452 dst_status = DBSTATUS_S_DEFAULT;
3453 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_VARIANT, sizeof(fvalue), &dst_len, &fvalue, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
3454 ok(hr == S_OK, "got %08x\n", hr);
3455 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
3456 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
3457 ok(V_VT(&dst) == VT_R4, "got %d\n", V_VT(&dst));
3458 ok(V_R4(&dst) == 543.21f, "got %f\n", V_R4(&dst));
3460 V_VT(&dst) = VT_EMPTY;
3461 dst_len = 0;
3462 dst_status = DBSTATUS_S_DEFAULT;
3463 hr = IDataConvert_DataConvert(convert, DBTYPE_R8, DBTYPE_VARIANT, sizeof(dvalue), &dst_len, &dvalue, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
3464 ok(hr == S_OK, "got %08x\n", hr);
3465 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
3466 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
3467 ok(V_VT(&dst) == VT_R8, "got %d\n", V_VT(&dst));
3468 ok(V_R8(&dst) == 123.56, "got %f\n", V_R8(&dst));
3470 V_VT(&dst) = VT_EMPTY;
3471 dst_len = 0;
3472 dst_status = DBSTATUS_S_DEFAULT;
3473 hr = IDataConvert_DataConvert(convert, DBTYPE_BOOL, DBTYPE_VARIANT, sizeof(boolean), &dst_len, &boolean, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
3474 ok(hr == S_OK, "got %08x\n", hr);
3475 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
3476 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
3477 ok(V_VT(&dst) == VT_BOOL, "got %d\n", V_VT(&dst));
3478 ok(V_BOOL(&dst) == VARIANT_TRUE, "got %d\n", V_BOOL(&dst));
3480 V_VT(&dst) = VT_EMPTY;
3481 dst_len = 0;
3482 dst_status = DBSTATUS_S_DEFAULT;
3483 i4 = 123;
3484 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_VARIANT, sizeof(i4), &dst_len, &i4, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
3485 ok(hr == S_OK, "got %08x\n", hr);
3486 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
3487 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
3488 ok(V_VT(&dst) == VT_I4, "got %d\n", V_VT(&dst));
3489 ok(V_I4(&dst) == 123, "got %d\n", V_I4(&dst));
3491 V_VT(&dst) = VT_EMPTY;
3492 dst_len = 0;
3493 dst_status = DBSTATUS_S_DEFAULT;
3494 i2 = 123;
3495 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_VARIANT, sizeof(i2), &dst_len, &i2, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
3496 ok(hr == S_OK, "got %08x\n", hr);
3497 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
3498 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
3499 ok(V_VT(&dst) == VT_I2, "got %d\n", V_VT(&dst));
3500 ok(V_I2(&dst) == 123, "got %d\n", V_I2(&dst));
3502 V_VT(&dst) = VT_EMPTY;
3503 dst_len = 0;
3504 dst_status = DBSTATUS_S_DEFAULT;
3505 date = 123.123;
3506 hr = IDataConvert_DataConvert(convert, DBTYPE_DATE, DBTYPE_VARIANT, sizeof(date), &dst_len, &date, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
3507 ok(hr == S_OK, "got %08x\n", hr);
3508 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
3509 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
3510 ok(V_VT(&dst) == VT_DATE, "got %d\n", V_VT(&dst));
3511 ok(V_DATE(&dst) == 123.123, "got %f\n", V_DATE(&dst));
3513 V_VT(&dst) = VT_EMPTY;
3514 dst_len = 0;
3515 dst_status = DBSTATUS_S_DEFAULT;
3516 S(cy).Lo = 1;
3517 S(cy).Hi = 2;
3518 hr = IDataConvert_DataConvert(convert, DBTYPE_CY, DBTYPE_VARIANT, sizeof(cy), &dst_len, &cy, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
3519 ok(hr == S_OK, "got %08x\n", hr);
3520 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
3521 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
3522 ok(V_VT(&dst) == VT_CY, "got %d\n", V_VT(&dst));
3524 cy2 = V_CY(&dst);
3525 ok(S(cy2).Lo == S(cy).Lo && S(cy2).Hi == S(cy).Hi, "got %d,%d\n", S(cy2).Lo, S(cy2).Hi);
3527 dst_len = 0x1234;
3528 hr = IDataConvert_DataConvert(convert, DBTYPE_BYTES, DBTYPE_VARIANT, sizeof(byte_src), &dst_len, &byte_src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
3529 ok(hr == S_OK, "got %08x\n", hr);
3530 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
3531 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
3532 ok(V_VT(&dst) == (VT_ARRAY|VT_UI1), "got %d\n", V_VT(&dst));
3533 if(V_VT(&dst) == (VT_ARRAY|VT_UI1))
3535 LONG l;
3537 hr = SafeArrayGetUBound(V_ARRAY(&dst), 1, &l);
3538 ok(hr == S_OK, "got %08x\n", hr);
3539 ok(l == 4, "got %d\n", l); /* 5 elements */
3541 VariantClear(&dst);
3543 dst_len = 0x1234;
3544 hr = IDataConvert_DataConvert(convert, DBTYPE_BYTES, DBTYPE_VARIANT, 0, &dst_len, &byte_src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
3545 ok(hr == S_OK, "got %08x\n", hr);
3546 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
3547 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
3548 ok(V_VT(&dst) == (VT_ARRAY|VT_UI1), "got %d\n", V_VT(&dst));
3549 if(V_VT(&dst) == (VT_ARRAY|VT_UI1))
3551 LONG l;
3553 hr = SafeArrayGetUBound(V_ARRAY(&dst), 1, &l);
3554 ok(hr == S_OK, "got %08x\n", hr);
3555 ok(l == -1, "got %d\n", l); /* 0 elements */
3557 VariantClear(&dst);
3559 dst_len = 0x1234;
3560 hr = IDataConvert_DataConvert(convert, DBTYPE_BYTES, DBTYPE_VARIANT, 2, &dst_len, &byte_src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
3561 ok(hr == S_OK, "got %08x\n", hr);
3562 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
3563 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
3564 ok(V_VT(&dst) == (VT_ARRAY|VT_UI1), "got %d\n", V_VT(&dst));
3565 if(V_VT(&dst) == (VT_ARRAY|VT_UI1))
3567 LONG l;
3569 hr = SafeArrayGetUBound(V_ARRAY(&dst), 1, &l);
3570 ok(hr == S_OK, "got %08x\n", hr);
3571 ok(l == 1, "got %d\n", l); /* 2 elements */
3573 VariantClear(&dst);
3575 dst_len = 0x1234;
3576 hr = IDataConvert_DataConvert(convert, DBTYPE_DBTIMESTAMP, DBTYPE_VARIANT, 0, &dst_len, &ts, &dst, sizeof(ts), 0, &dst_status, 0, 0, 0);
3577 ok(hr == S_OK, "got %08x\n", hr);
3578 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
3579 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
3580 ok(V_VT(&dst) == VT_DATE, "got %d\n", V_VT(&dst));
3581 ok( (float)V_DATE(&dst) == 41408.086250f, "got %f\n", V_DATE(&dst));
3583 dst_len = 0x1234;
3584 hr = IDataConvert_DataConvert(convert, DBTYPE_DBDATE, DBTYPE_VARIANT, 0, &dst_len, &dbdate, &dst, sizeof(dbdate), 0, &dst_status, 0, 0, 0);
3585 ok(hr == S_OK, "got %08x\n", hr);
3586 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
3587 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
3588 ok(V_VT(&dst) == VT_DATE, "got %d\n", V_VT(&dst));
3589 ok( (float)V_DATE(&dst) == 41409.0, "got %f\n", V_DATE(&dst));
3591 /* src_status = DBSTATUS_S_ISNULL */
3592 i4 = 123;
3593 dst_len = 99;
3594 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_VARIANT, sizeof(i4), &dst_len, &i4, &dst, sizeof(dst), DBSTATUS_S_ISNULL, &dst_status, 0, 0, 0);
3595 ok(hr == S_OK, "got %08x\n", hr);
3596 ok(dst_status == DBSTATUS_S_ISNULL, "got %08x\n", dst_status);
3597 ok(dst_len == 0, "got %ld\n", dst_len);
3599 dst_len = 44;
3600 V_VT(&var) = VT_NULL;
3601 hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_VARIANT, 0, &dst_len, &var, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
3602 ok(hr == S_OK, "got %08x\n", hr);
3603 ok(dst_status == DBSTATUS_S_ISNULL, "got %08x\n", dst_status);
3604 ok(dst_len == sizeof(VARIANT), "got %ld\n", dst_len);
3608 static void test_converttotimestamp(void)
3610 static const WCHAR strW[] = {'2','0','1','3','-','0','5','-','1','4',' ','0','2',':','0','4',':','1','2',0};
3611 DBTIMESTAMP ts = {2013, 5, 14, 2, 4, 12, 0};
3612 DBTIMESTAMP dst;
3613 DBSTATUS dst_status;
3614 DBLENGTH dst_len;
3615 VARIANT var;
3616 HRESULT hr;
3617 BSTR bstr;
3619 VariantInit(&var);
3620 V_VT(&var) = VT_DATE;
3621 V_DATE(&var) = 41408.086250;
3622 dst_len = 0x1234;
3623 hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_DBTIMESTAMP, 0, &dst_len, &var, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
3624 ok(hr == S_OK, "got %08x\n", hr);
3625 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
3626 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
3627 ok(!memcmp(&ts, &dst, sizeof(ts)), "Wrong timestamp\n");
3629 bstr = SysAllocString(strW);
3630 dst_len = 0x1234;
3631 hr = IDataConvert_DataConvert(convert, DBTYPE_BSTR, DBTYPE_DBTIMESTAMP, 0, &dst_len, &bstr, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
3632 ok(hr == S_OK, "got %08x\n", hr);
3633 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
3634 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
3635 ok(!memcmp(&ts, &dst, sizeof(ts)), "Wrong timestamp\n");
3636 SysFreeString(bstr);
3638 V_VT(&var) = VT_NULL;
3639 dst_len = 77;
3640 hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_DBTIMESTAMP, sizeof(var), &dst_len, &var, &dst, 2, 0, &dst_status, 0, 0, 0);
3641 ok(hr == S_OK, "got %08x\n", hr);
3642 ok(dst_status == DBSTATUS_S_ISNULL, "got %08x\n", dst_status);
3643 ok(dst_len == 77, "got %ld\n", dst_len);
3646 static void test_converttoiunknown(void)
3648 HRESULT hr;
3649 DBSTATUS dst_status;
3650 DBLENGTH dst_len;
3651 IUnknown *dst = NULL;
3652 static WCHAR strW[] = {'t','e','s','t',0};
3653 VARIANT var;
3655 VariantInit(&var);
3657 dst_len = 0x1234;
3658 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_IUNKNOWN, sizeof(strW), &dst_len, strW, dst, sizeof(dst), DBSTATUS_S_ISNULL, &dst_status, 0, 0, 0);
3659 ok(hr == S_OK, "got %08x\n", hr);
3660 ok(dst_status == DBSTATUS_S_ISNULL, "got %08x\n", dst_status);
3661 ok(dst_len == 0, "got %ld\n", dst_len);
3663 dst_len = 44;
3664 V_VT(&var) = VT_NULL;
3665 hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_IUNKNOWN, 0, &dst_len, &var, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
3666 ok(hr == S_OK, "got %08x\n", hr);
3667 ok(dst_status == DBSTATUS_S_ISNULL, "got %08x\n", dst_status);
3668 ok(dst_len == 44, "got %ld\n", dst_len);
3671 #define test_numeric_val(current, expected) _test_numeric_val(__LINE__, current, expected);
3672 static inline void _test_numeric_val(unsigned line, DB_NUMERIC *current, DB_NUMERIC *expected)
3674 int same = !memcmp(current, expected, sizeof(DB_NUMERIC));
3675 ok_(__FILE__,line) (same, "Invalid byte array\n");
3676 if(!same)
3678 int i;
3679 for(i=0; i < sizeof(current->val); i++)
3680 ok_(__FILE__,line) (current->val[i] == expected->val[i], " byte %d got 0x%02x expected 0x%02x\n", i, current->val[i], expected->val[i]);
3684 static void test_converttonumeric(void)
3686 HRESULT hr;
3687 DBSTATUS dst_status;
3688 DBLENGTH dst_len;
3689 DB_NUMERIC dst;
3690 static WCHAR strW[] = {'1','2','3','.','4','5',0};
3691 static WCHAR largeW[] = {'1','2','3','4','5','6','7','8','9','0',0};
3692 INT i;
3693 BSTR bstr;
3694 FLOAT fvalue = 543.21f;
3695 VARIANT_BOOL boolean = VARIANT_TRUE;
3696 VARIANT var;
3697 LARGE_INTEGER i8;
3698 DB_NUMERIC result1 = { 10, 0, 1, {0x02, 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }; /* 4098 */
3699 DB_NUMERIC result2 = { 10, 0, 1, {0x39, 0x30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }; /* 12345 */
3700 DB_NUMERIC result3 = { 10, 0, 0, {0x01, 0x00, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }; /* -1 */
3701 DB_NUMERIC result4 = { 10, 0, 1, {0x1f, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }; /* 543.21 */
3702 DB_NUMERIC result5 = { 10, 0, 1, {0x7b, 0x00, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }; /* 123.45 */
3703 DB_NUMERIC result6 = { 10, 0, 1, {0xd2, 0x02, 0x96, 0x49, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }; /* 123456789 */
3705 VariantInit(&var);
3707 i = 4098;
3708 dst_len = 0x1234;
3709 dst.scale = 30;
3710 memset(dst.val, 0xfe, sizeof(dst.val));
3711 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_NUMERIC, 0, &dst_len, &i, &dst, sizeof(dst), 0, &dst_status, 10, 0, 0);
3712 todo_wine ok(hr == S_OK, "got %08x\n", hr);
3713 todo_wine ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
3714 todo_wine ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
3715 todo_wine test_numeric_val(&dst, &result1);
3717 i8.QuadPart = 12345;
3718 dst_len = 0x1234;
3719 dst.scale = 30;
3720 memset(dst.val, 0xfe, sizeof(dst.val));
3721 hr = IDataConvert_DataConvert(convert, DBTYPE_I8, DBTYPE_NUMERIC, sizeof(i8), &dst_len, &i8, &dst, sizeof(dst), 0, &dst_status, 10, 0, 0);
3722 todo_wine ok(hr == S_OK, "got %08x\n", hr);
3723 todo_wine ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
3724 todo_wine ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
3725 todo_wine test_numeric_val(&dst, &result2);
3727 dst_len = 0x1234;
3728 dst.scale = 30;
3729 dst.sign = 1;
3730 memset(dst.val, 0xfe, sizeof(dst.val));
3731 hr = IDataConvert_DataConvert(convert, DBTYPE_BOOL, DBTYPE_NUMERIC, sizeof(boolean), &dst_len, &boolean, &dst, sizeof(dst), 0, &dst_status, 10, 0, 0);
3732 todo_wine ok(hr == S_OK, "got %08x\n", hr);
3733 todo_wine ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
3734 todo_wine ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
3735 todo_wine test_numeric_val(&dst, &result3);
3737 dst_len = 0x1234;
3738 dst.scale = 30;
3739 dst.sign = 0;
3740 memset(dst.val, 0xfe, sizeof(dst.val));
3741 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_NUMERIC, sizeof(fvalue), &dst_len, &fvalue, &dst, sizeof(dst), 0, &dst_status, 10, 0, 0);
3742 todo_wine ok(hr == S_OK, "got %08x\n", hr);
3743 todo_wine ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
3744 todo_wine ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
3745 todo_wine test_numeric_val(&dst, &result4);
3747 dst_len = 0x1234;
3748 dst.scale = 30;
3749 dst.sign = 0;
3750 memset(dst.val, 0xfe, sizeof(dst.val));
3751 V_VT(&var) = VT_NULL;
3752 hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_NUMERIC, sizeof(var), &dst_len, &var, &dst, sizeof(dst), 0, &dst_status, 10, 0, 0);
3753 ok(hr == S_OK, "got %08x\n", hr);
3754 ok(dst_status == DBSTATUS_S_ISNULL, "got %08x\n", dst_status);
3756 dst_len = 0x1234;
3757 dst.scale = 30;
3758 dst.sign = 0;
3759 memset(dst.val, 0xfe, sizeof(dst.val));
3760 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_NUMERIC, sizeof(strW), &dst_len, strW, &dst, sizeof(dst), 0, &dst_status, 10, 0, 0);
3761 todo_wine ok(hr == S_OK, "got %08x\n", hr);
3762 todo_wine ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
3763 todo_wine ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
3764 todo_wine test_numeric_val(&dst, &result5);
3766 bstr = SysAllocString(strW);
3767 dst_status = 0;
3768 dst.scale = 30;
3769 dst.sign = 0;
3770 dst_len = sizeof(strW);
3771 memset(dst.val, 0xfe, sizeof(dst.val));
3772 hr = IDataConvert_DataConvert(convert, DBTYPE_BSTR, DBTYPE_NUMERIC, 0, &dst_len, &bstr, &dst, sizeof(dst), 0, &dst_status, 10, 0, 0);
3773 todo_wine ok(hr == S_OK, "got %08x\n", hr);
3774 todo_wine ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
3775 todo_wine ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
3776 todo_wine test_numeric_val(&dst, &result5);
3778 bstr = SysAllocString(largeW);
3779 dst_status = 0;
3780 dst.scale = 30;
3781 dst.sign = 0;
3782 dst_len = sizeof(largeW);
3783 memset(dst.val, 0xfe, sizeof(dst.val));
3784 hr = IDataConvert_DataConvert(convert, DBTYPE_BSTR, DBTYPE_NUMERIC, 0, &dst_len, &bstr, &dst, sizeof(dst), 0, &dst_status, 10, 0, 0);
3785 todo_wine ok(hr == S_OK, "got %08x\n", hr);
3786 todo_wine ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
3787 todo_wine ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
3788 todo_wine test_numeric_val(&dst, &result6);
3791 START_TEST(convert)
3793 HRESULT hr;
3795 OleInitialize(NULL);
3797 test_dcinfo();
3799 hr = CoCreateInstance(&CLSID_OLEDB_CONVERSIONLIBRARY, NULL, CLSCTX_INPROC_SERVER, &IID_IDataConvert, (void**)&convert);
3800 if(FAILED(hr))
3802 win_skip("Unable to create IDataConvert instance, 0x%08x\n", hr);
3803 OleUninitialize();
3804 return;
3807 test_canconvert();
3808 test_converttoi2();
3809 test_converttoi4();
3810 test_converttoi8();
3811 test_converttostr();
3812 test_converttobstr();
3813 test_converttowstr();
3814 test_converttobyrefwstr();
3815 test_converttobyrefstr();
3816 test_converttoguid();
3817 test_converttoui1();
3818 test_converttoui4();
3819 test_converttor4();
3820 test_converttor8();
3821 test_converttofiletime();
3822 test_converttocy();
3823 test_converttoui8();
3824 test_converttovar();
3825 test_converttobytes();
3826 test_converttobytesbyref();
3827 test_converttodbdate();
3828 test_getconversionsize();
3829 test_converttotimestamp();
3830 test_converttoiunknown();
3831 test_converttonumeric();
3833 IDataConvert_Release(convert);
3835 OleUninitialize();