oledb32: DataConvert only variant length types can have a null dst.
[wine/multimedia.git] / dlls / oledb32 / tests / convert.c
blobee2a39b0c76bf87e85779a627a214e905fab407d
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 expect = FALSE;
307 ok((hr == S_OK && expect == TRUE) ||
308 (hr == S_FALSE && expect == FALSE),
309 "%04x -> %04x: got %08x expect conversion to be %spossible\n", simple_convert[src_idx].type | DBTYPE_VECTOR,
310 simple_convert[dst_idx].type, hr, expect ? "" : "not ");
312 /* dst DBTYPE_VECTOR */
313 hr = IDataConvert_CanConvert(convert, simple_convert[src_idx].type, simple_convert[dst_idx].type | DBTYPE_VECTOR);
314 expect = FALSE;
315 ok((hr == S_OK && expect == TRUE) ||
316 (hr == S_FALSE && expect == FALSE),
317 "%04x -> %04x: got %08x expect conversion to be %spossible\n", simple_convert[src_idx].type,
318 simple_convert[dst_idx].type | DBTYPE_VECTOR, hr, expect ? "" : "not ");
320 /* src & dst DBTYPE_VECTOR */
321 hr = IDataConvert_CanConvert(convert, simple_convert[src_idx].type | DBTYPE_VECTOR, simple_convert[dst_idx].type | DBTYPE_VECTOR);
322 expect = FALSE;
323 ok((hr == S_OK && expect == TRUE) ||
324 (hr == S_FALSE && expect == FALSE),
325 "%04x -> %04x: got %08x expect conversion to be %spossible\n", simple_convert[src_idx].type | DBTYPE_VECTOR,
326 simple_convert[dst_idx].type | DBTYPE_VECTOR, hr, expect ? "" : "not ");
332 static void test_converttoi2(void)
334 HRESULT hr;
335 signed short dst;
336 BYTE src[20];
337 DBSTATUS dst_status;
338 DBLENGTH dst_len;
339 static const WCHAR ten[] = {'1','0',0};
340 BSTR b;
342 dst_len = dst = 0x1234;
343 hr = IDataConvert_DataConvert(convert, DBTYPE_EMPTY, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
344 ok(hr == S_OK, "got %08x\n", hr);
345 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
346 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
347 ok(dst == 0, "got %08x\n", dst);
349 dst_len = dst = 0x1234;
350 hr = IDataConvert_DataConvert(convert, DBTYPE_NULL, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
351 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr);
352 ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status);
353 ok(dst_len == 0x1234, "got %ld\n", dst_len);
354 ok(dst == 0x1234, "got %08x\n", dst);
356 dst_len = dst = 0x1234;
357 *(short *)src = 0x4321;
358 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
359 ok(hr == S_OK, "got %08x\n", hr);
360 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
361 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
362 ok(dst == 0x4321, "got %08x\n", dst);
364 dst_len = dst = 0x1234;
365 *(int *)src = 0x4321cafe;
366 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
367 todo_wine
368 ok(hr == DB_E_DATAOVERFLOW, "got %08x\n", hr);
369 ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
370 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
371 ok(dst == 0x1234, "got %08x\n", dst);
373 dst_len = dst = 0x1234;
374 *(int *)src = 0x4321;
375 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
376 ok(hr == S_OK, "got %08x\n", hr);
377 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
378 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
379 ok(dst == 0x4321, "got %08x\n", dst);
381 dst_len = dst = 0x1234;
382 *(FLOAT *)src = 10.75;
383 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
384 ok(hr == S_OK, "got %08x\n", hr);
385 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
386 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
387 ok(dst == 11, "got %08x\n", dst);
389 dst_len = dst = 0x1234;
390 *(FLOAT *)src = -10.75;
391 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
392 ok(hr == S_OK, "got %08x\n", hr);
393 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
394 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
395 ok(dst == -11, "got %08x\n", dst);
397 dst_len = dst = 0x1234;
398 *(double *)src = 10.75;
399 hr = IDataConvert_DataConvert(convert, DBTYPE_R8, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
400 ok(hr == S_OK, "got %08x\n", hr);
401 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
402 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
403 ok(dst == 11, "got %08x\n", dst);
405 dst_len = dst = 0x1234;
406 ((LARGE_INTEGER *)src)->QuadPart = 107500;
407 hr = IDataConvert_DataConvert(convert, DBTYPE_CY, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
408 ok(hr == S_OK, "got %08x\n", hr);
409 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
410 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
411 ok(dst == 11, "got %08x\n", dst);
413 dst_len = dst = 0x1234;
414 *(DATE *)src = 10.7500;
415 hr = IDataConvert_DataConvert(convert, DBTYPE_DATE, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
416 ok(hr == S_OK, "got %08x\n", hr);
417 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
418 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
419 ok(dst == 11, "got %08x\n", dst);
421 dst_len = dst = 0x1234;
422 b = SysAllocString(ten);
423 *(BSTR *)src = b;
424 hr = IDataConvert_DataConvert(convert, DBTYPE_BSTR, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
425 ok(hr == S_OK, "got %08x\n", hr);
426 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
427 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
428 ok(dst == 10, "got %08x\n", dst);
429 SysFreeString(b);
431 dst_len = dst = 0x1234;
432 *(SCODE *)src = 0x4321cafe;
433 hr = IDataConvert_DataConvert(convert, DBTYPE_ERROR, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
434 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr);
435 ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status);
436 ok(dst_len == 0x1234, "got %ld\n", dst_len);
437 ok(dst == 0x1234, "got %08x\n", dst);
439 dst_len = dst = 0x1234;
440 *(VARIANT_BOOL *)src = VARIANT_TRUE;
441 hr = IDataConvert_DataConvert(convert, DBTYPE_BOOL, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
442 ok(hr == S_OK, "got %08x\n", hr);
443 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
444 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
445 ok(dst == -1, "got %08x\n", dst);
447 dst_len = dst = 0x1234;
448 *(VARIANT_BOOL *)src = VARIANT_FALSE;
449 hr = IDataConvert_DataConvert(convert, DBTYPE_BOOL, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
450 ok(hr == S_OK, "got %08x\n", hr);
451 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
452 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
453 ok(dst == 0, "got %08x\n", dst);
455 dst_len = dst = 0x1234;
456 V_VT((VARIANT*)src) = VT_I2;
457 V_I2((VARIANT*)src) = 0x4321;
458 hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
459 ok(hr == S_OK, "got %08x\n", hr);
460 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
461 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
462 ok(dst == 0x4321, "got %08x\n", dst);
464 dst_len = dst = 0x1234;
465 memset(src, 0, sizeof(DECIMAL));
466 ((DECIMAL*)src)->u1.Lo64 = 0x4321;
467 hr = IDataConvert_DataConvert(convert, DBTYPE_DECIMAL, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
468 ok(hr == S_OK, "got %08x\n", hr);
469 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
470 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
471 ok(dst == 0x4321, "got %08x\n", dst);
473 dst_len = dst = 0x1234;
474 *(signed char*)src = 0xab;
475 hr = IDataConvert_DataConvert(convert, DBTYPE_I1, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
476 ok(hr == S_OK, "got %08x\n", hr);
477 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
478 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
479 ok(dst == (signed short)0xffab, "got %08x\n", dst);
481 dst_len = dst = 0x1234;
482 *(BYTE*)src = 0xab;
483 hr = IDataConvert_DataConvert(convert, DBTYPE_UI1, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
484 ok(hr == S_OK, "got %08x\n", hr);
485 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
486 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
487 ok(dst == 0xab, "got %08x\n", dst);
489 dst_len = dst = 0x1234;
490 *(WORD*)src = 0x4321;
491 hr = IDataConvert_DataConvert(convert, DBTYPE_UI2, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
492 ok(hr == S_OK, "got %08x\n", hr);
493 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
494 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
495 ok(dst == 0x4321, "got %08x\n", dst);
497 dst_len = dst = 0x1234;
498 *(WORD*)src = 0xabcd;
499 hr = IDataConvert_DataConvert(convert, DBTYPE_UI2, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
500 ok(hr == DB_E_ERRORSOCCURRED, "got %08x\n", hr);
501 ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
502 todo_wine
503 ok(broken(dst_len == sizeof(dst)) || dst_len == 0x1234 /* W2K+ */, "got %ld\n", dst_len);
504 ok(dst == 0x1234, "got %08x\n", dst);
506 dst_len = dst = 0x1234;
507 *(DWORD*)src = 0xabcd1234;
508 hr = IDataConvert_DataConvert(convert, DBTYPE_UI4, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
509 todo_wine
510 ok(hr == DB_E_DATAOVERFLOW, "got %08x\n", hr);
511 ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
512 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
513 ok(dst == 0x1234, "got %08x\n", dst);
515 dst_len = dst = 0x1234;
516 *(DWORD*)src = 0x1234abcd;
517 hr = IDataConvert_DataConvert(convert, DBTYPE_UI4, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
518 todo_wine
519 ok(hr == DB_E_DATAOVERFLOW, "got %08x\n", hr);
520 ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
521 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
522 ok(dst == 0x1234, "got %08x\n", dst);
524 dst_len = dst = 0x1234;
525 *(DWORD*)src = 0x4321;
526 hr = IDataConvert_DataConvert(convert, DBTYPE_UI4, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
527 ok(hr == S_OK, "got %08x\n", hr);
528 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
529 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
530 ok(dst == 0x4321, "got %08x\n", dst);
532 dst_len = dst = 0x1234;
533 ((LARGE_INTEGER*)src)->QuadPart = 0x1234abcd;
534 hr = IDataConvert_DataConvert(convert, DBTYPE_I8, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
535 ok(hr == DB_E_ERRORSOCCURRED ||
536 broken(hr == DB_E_UNSUPPORTEDCONVERSION), /* win98 */
537 "got %08x\n", hr);
538 if(hr != DB_E_UNSUPPORTEDCONVERSION) /* win98 doesn't support I8/UI8 */
540 ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
541 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
542 ok(dst == 0x1234, "got %08x\n", dst);
544 dst_len = dst = 0x1234;
545 ((LARGE_INTEGER*)src)->QuadPart = 0x4321;
546 hr = IDataConvert_DataConvert(convert, DBTYPE_I8, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
547 ok(hr == S_OK, "got %08x\n", hr);
548 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
549 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
550 ok(dst == 0x4321, "got %08x\n", dst);
552 dst_len = dst = 0x1234;
553 ((ULARGE_INTEGER*)src)->QuadPart = 0x4321;
554 hr = IDataConvert_DataConvert(convert, DBTYPE_UI8, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
555 ok(hr == S_OK, "got %08x\n", hr);
556 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
557 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
558 ok(dst == 0x4321, "got %08x\n", dst);
561 dst_len = dst = 0x1234;
562 strcpy((char *)src, "10");
563 hr = IDataConvert_DataConvert(convert, DBTYPE_STR, DBTYPE_I2, 2, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
564 ok(hr == S_OK, "got %08x\n", hr);
565 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
566 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
567 ok(dst == 10, "got %08x\n", dst);
569 dst_len = dst = 0x1234;
570 strcpy((char *)src, "10");
571 hr = IDataConvert_DataConvert(convert, DBTYPE_STR, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, DBDATACONVERT_LENGTHFROMNTS);
572 ok(hr == S_OK, "got %08x\n", hr);
573 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
574 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
575 ok(dst == 10, "got %08x\n", dst);
577 dst_len = dst = 0x1234;
578 memcpy(src, ten, sizeof(ten));
579 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_I2, 4, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
580 ok(hr == S_OK, "got %08x\n", hr);
581 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
582 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
583 ok(dst == 10, "got %08x\n", dst);
585 dst_len = dst = 0x1234;
586 memcpy(src, ten, sizeof(ten));
587 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_I2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, DBDATACONVERT_LENGTHFROMNTS);
588 ok(hr == S_OK, "got %08x\n", hr);
589 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
590 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
591 ok(dst == 10, "got %08x\n", dst);
593 /* */
594 dst_len = dst = 0x1234;
595 *(WORD*)src = 0x4321;
596 hr = IDataConvert_DataConvert(convert, DBTYPE_UI2, DBTYPE_UI2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
597 ok(hr == S_OK, "got %08x\n", hr);
598 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
599 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
600 ok(dst == 0x4321, "got %08x\n", dst);
602 dst_len = dst = 0x1234;
603 *(DWORD*)src = 0xabcd1234;
604 hr = IDataConvert_DataConvert(convert, DBTYPE_UI4, DBTYPE_UI2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
605 todo_wine
606 ok(hr == DB_E_DATAOVERFLOW, "got %08x\n", hr);
607 ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
608 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
609 ok(dst == 0x1234, "got %08x\n", dst);
611 dst_len = dst = 0x1234;
612 *(DWORD*)src = 0x1234abcd;
613 hr = IDataConvert_DataConvert(convert, DBTYPE_UI4, DBTYPE_UI2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
614 todo_wine
615 ok(hr == DB_E_DATAOVERFLOW, "got %08x\n", hr);
616 ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
617 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
618 ok(dst == 0x1234, "got %08x\n", dst);
620 dst_len = dst = 0x1234;
621 *(DWORD*)src = 0x4321;
622 hr = IDataConvert_DataConvert(convert, DBTYPE_UI4, DBTYPE_UI2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
623 ok(hr == S_OK, "got %08x\n", hr);
624 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
625 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
626 ok(dst == 0x4321, "got %08x\n", dst);
628 dst_len = dst = 0x1234;
629 memcpy(src, ten, sizeof(ten));
630 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_UI2, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, DBDATACONVERT_LENGTHFROMNTS);
631 ok(hr == S_OK, "got %08x\n", hr);
632 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
633 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
634 ok(dst == 10, "got %08x\n", dst);
637 static void test_converttoi4(void)
639 HRESULT hr;
640 INT i4;
641 BYTE src[20];
642 DBSTATUS dst_status;
643 DBLENGTH dst_len;
644 static const WCHAR ten[] = {'1','0',0};
645 BSTR b;
647 i4 = 0x12345678;
648 dst_len = 0x1234;
649 hr = IDataConvert_DataConvert(convert, DBTYPE_EMPTY, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
650 ok(hr == S_OK, "got %08x\n", hr);
651 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
652 ok(dst_len == sizeof(i4), "got %ld\n", dst_len);
653 ok(i4 == 0, "got %08x\n", i4);
655 i4 = 0x12345678;
656 dst_len = 0x1234;
657 hr = IDataConvert_DataConvert(convert, DBTYPE_NULL, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
658 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr);
659 ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status);
660 ok(dst_len == 0x1234, "got %ld\n", dst_len);
661 ok(i4 == 0x12345678, "got %08x\n", i4);
663 i4 = 0x12345678;
664 *(short *)src = 0x4321;
665 dst_len = 0x1234;
666 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
667 ok(hr == S_OK, "got %08x\n", hr);
668 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
669 ok(dst_len == sizeof(i4), "got %ld\n", dst_len);
670 ok(i4 == 0x4321, "got %08x\n", i4);
672 i4 = 0x12345678;
673 *(int *)src = 0x4321cafe;
674 dst_len = 0x1234;
675 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
676 ok(hr == S_OK, "got %08x\n", hr);
677 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
678 ok(dst_len == sizeof(i4), "got %ld\n", dst_len);
679 ok(i4 == 0x4321cafe, "got %08x\n", i4);
681 i4 = 0x12345678;
682 *(FLOAT *)src = 10.75;
683 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
684 ok(hr == S_OK, "got %08x\n", hr);
685 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
686 ok(dst_len == sizeof(i4), "got %ld\n", dst_len);
687 ok(i4 == 11, "got %08x\n", i4);
689 i4 = 0x12345678;
690 *(FLOAT *)src = -10.75;
691 dst_len = 0x1234;
692 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
693 ok(hr == S_OK, "got %08x\n", hr);
694 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
695 ok(dst_len == sizeof(i4), "got %ld\n", dst_len);
696 ok(i4 == -11, "got %08x\n", i4);
698 i4 = 0x12345678;
699 *(double *)src = 10.75;
700 dst_len = 0x1234;
701 hr = IDataConvert_DataConvert(convert, DBTYPE_R8, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
702 ok(hr == S_OK, "got %08x\n", hr);
703 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
704 ok(dst_len == sizeof(i4), "got %ld\n", dst_len);
705 ok(i4 == 11, "got %08x\n", i4);
707 i4 = 0x12345678;
708 ((LARGE_INTEGER *)src)->QuadPart = 107500;
709 dst_len = 0x1234;
710 hr = IDataConvert_DataConvert(convert, DBTYPE_CY, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
711 ok(hr == S_OK, "got %08x\n", hr);
712 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
713 ok(dst_len == sizeof(i4), "got %ld\n", dst_len);
714 ok(i4 == 11, "got %08x\n", i4);
716 i4 = 0x12345678;
717 *(DATE *)src = 10.7500;
718 dst_len = 0x1234;
719 hr = IDataConvert_DataConvert(convert, DBTYPE_DATE, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
720 ok(hr == S_OK, "got %08x\n", hr);
721 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
722 ok(dst_len == sizeof(i4), "got %ld\n", dst_len);
723 ok(i4 == 11, "got %08x\n", i4);
725 i4 = 0x12345678;
726 b = SysAllocString(ten);
727 *(BSTR *)src = b;
728 dst_len = 0x1234;
729 hr = IDataConvert_DataConvert(convert, DBTYPE_BSTR, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
730 ok(hr == S_OK, "got %08x\n", hr);
731 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
732 ok(dst_len == sizeof(i4), "got %ld\n", dst_len);
733 ok(i4 == 10, "got %08x\n", i4);
734 SysFreeString(b);
736 i4 = 0x12345678;
737 *(SCODE *)src = 0x4321cafe;
738 dst_len = 0x1234;
739 hr = IDataConvert_DataConvert(convert, DBTYPE_ERROR, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
740 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr);
741 ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status);
742 ok(dst_len == 0x1234, "got %ld\n", dst_len);
743 ok(i4 == 0x12345678, "got %08x\n", i4);
745 i4 = 0x12345678;
746 *(VARIANT_BOOL *)src = VARIANT_TRUE;
747 dst_len = 0x1234;
748 hr = IDataConvert_DataConvert(convert, DBTYPE_BOOL, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
749 ok(hr == S_OK, "got %08x\n", hr);
750 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
751 ok(dst_len == sizeof(i4), "got %ld\n", dst_len);
752 ok(i4 == 0xffffffff, "got %08x\n", i4);
754 i4 = 0x12345678;
755 *(VARIANT_BOOL *)src = VARIANT_FALSE;
756 dst_len = 0x1234;
757 hr = IDataConvert_DataConvert(convert, DBTYPE_BOOL, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
758 ok(hr == S_OK, "got %08x\n", hr);
759 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
760 ok(dst_len == sizeof(i4), "got %ld\n", dst_len);
761 ok(i4 == 0, "got %08x\n", i4);
763 i4 = 0x12345678;
764 V_VT((VARIANT*)src) = VT_I2;
765 V_I2((VARIANT*)src) = 0x1234;
766 dst_len = 0x1234;
767 hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
768 ok(hr == S_OK, "got %08x\n", hr);
769 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
770 ok(dst_len == sizeof(i4), "got %ld\n", dst_len);
771 ok(i4 == 0x1234, "got %08x\n", i4);
773 i4 = 0x12345678;
774 memset(src, 0, sizeof(DECIMAL));
775 ((DECIMAL*)src)->u1.Lo64 = 0x1234;
776 dst_len = 0x1234;
777 hr = IDataConvert_DataConvert(convert, DBTYPE_DECIMAL, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
778 ok(hr == S_OK, "got %08x\n", hr);
779 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
780 ok(dst_len == sizeof(i4), "got %ld\n", dst_len);
781 ok(i4 == 0x1234, "got %08x\n", i4);
783 i4 = 0x12345678;
784 *(signed char*)src = 0xab;
785 dst_len = 0x1234;
786 hr = IDataConvert_DataConvert(convert, DBTYPE_I1, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
787 ok(hr == S_OK, "got %08x\n", hr);
788 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
789 ok(dst_len == sizeof(i4), "got %ld\n", dst_len);
790 ok(i4 == 0xffffffab, "got %08x\n", i4);
792 i4 = 0x12345678;
793 *(BYTE*)src = 0xab;
794 dst_len = 0x1234;
795 hr = IDataConvert_DataConvert(convert, DBTYPE_UI1, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
796 ok(hr == S_OK, "got %08x\n", hr);
797 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
798 ok(dst_len == sizeof(i4), "got %ld\n", dst_len);
799 ok(i4 == 0xab, "got %08x\n", i4);
801 i4 = 0x12345678;
802 *(WORD*)src = 0xabcd;
803 dst_len = 0x1234;
804 hr = IDataConvert_DataConvert(convert, DBTYPE_UI2, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
805 ok(hr == S_OK, "got %08x\n", hr);
806 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
807 ok(dst_len == sizeof(i4), "got %ld\n", dst_len);
808 ok(i4 == 0xabcd, "got %08x\n", i4);
810 i4 = 0x12345678;
811 *(DWORD*)src = 0xabcd1234;
812 dst_len = 0x1234;
813 hr = IDataConvert_DataConvert(convert, DBTYPE_UI4, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
814 ok(hr == DB_E_ERRORSOCCURRED, "got %08x\n", hr);
815 ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
816 todo_wine
817 ok(broken(dst_len == sizeof(i4)) || dst_len == 0x1234 /* W2K+ */, "got %ld\n", dst_len);
818 ok(i4 == 0x12345678, "got %08x\n", i4);
820 i4 = 0x12345678;
821 *(DWORD*)src = 0x1234abcd;
822 dst_len = 0x1234;
823 hr = IDataConvert_DataConvert(convert, DBTYPE_UI4, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
824 ok(hr == S_OK, "got %08x\n", hr);
825 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
826 ok(dst_len == sizeof(i4), "got %ld\n", dst_len);
827 ok(i4 == 0x1234abcd, "got %08x\n", i4);
829 i4 = 0x12345678;
830 ((LARGE_INTEGER*)src)->QuadPart = 0x1234abcd;
831 dst_len = 0x1234;
832 hr = IDataConvert_DataConvert(convert, DBTYPE_I8, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
833 ok(hr == S_OK ||
834 broken(hr == DB_E_UNSUPPORTEDCONVERSION), /* win98 */
835 "got %08x\n", hr);
836 if(hr != DB_E_UNSUPPORTEDCONVERSION) /* win98 doesn't support I8/UI8 */
838 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
839 ok(dst_len == sizeof(i4), "got %ld\n", dst_len);
840 ok(i4 == 0x1234abcd, "got %08x\n", i4);
842 i4 = 0x12345678;
843 ((ULARGE_INTEGER*)src)->QuadPart = 0x1234abcd;
844 dst_len = 0x1234;
845 hr = IDataConvert_DataConvert(convert, DBTYPE_UI8, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
846 ok(hr == S_OK, "got %08x\n", hr);
847 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
848 ok(dst_len == sizeof(i4), "got %ld\n", dst_len);
849 ok(i4 == 0x1234abcd, "got %08x\n", i4);
852 i4 = 0x12345678;
853 strcpy((char *)src, "10");
854 dst_len = 0x1234;
855 hr = IDataConvert_DataConvert(convert, DBTYPE_STR, DBTYPE_I4, 2, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
856 ok(hr == S_OK, "got %08x\n", hr);
857 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
858 ok(dst_len == sizeof(i4), "got %ld\n", dst_len);
859 ok(i4 == 10, "got %08x\n", i4);
861 i4 = 0x12345678;
862 strcpy((char *)src, "10");
863 dst_len = 0x1234;
864 hr = IDataConvert_DataConvert(convert, DBTYPE_STR, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, DBDATACONVERT_LENGTHFROMNTS);
865 ok(hr == S_OK, "got %08x\n", hr);
866 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
867 ok(dst_len == sizeof(i4), "got %ld\n", dst_len);
868 ok(i4 == 10, "got %08x\n", i4);
870 i4 = 0x12345678;
871 memcpy(src, ten, sizeof(ten));
872 dst_len = 0x1234;
873 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_I4, 4, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
874 ok(hr == S_OK, "got %08x\n", hr);
875 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
876 ok(dst_len == sizeof(i4), "got %ld\n", dst_len);
877 ok(i4 == 10, "got %08x\n", i4);
879 i4 = 0x12345678;
880 memcpy(src, ten, sizeof(ten));
881 dst_len = 0x1234;
882 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, DBDATACONVERT_LENGTHFROMNTS);
883 ok(hr == S_OK, "got %08x\n", hr);
884 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
885 ok(dst_len == sizeof(i4), "got %ld\n", dst_len);
886 ok(i4 == 10, "got %08x\n", i4);
888 /* src_status = DBSTATUS_S_ISNULL */
889 i4 = 0x12345678;
890 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), DBSTATUS_S_ISNULL, &dst_status, 0, 0, 0);
891 ok(hr == S_OK, "got %08x\n", hr);
892 ok(dst_status == DBSTATUS_S_ISNULL, "got %08x\n", dst_status);
893 ok(dst_len == 0, "got %ld\n", dst_len);
895 /* dst = NULL */
896 *(int *)src = 0x4321cafe;
897 dst_len = 0x1234;
898 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_I4, 0, &dst_len, src, NULL, 0, 0, NULL, 0, 0, 0);
899 ok(hr == S_OK, "got %08x\n", hr);
900 ok(dst_len == sizeof(i4), "got %ld\n", dst_len);
904 static void test_converttoi8(void)
906 HRESULT hr;
907 LARGE_INTEGER dst;
908 BYTE src[20];
909 DBSTATUS dst_status;
910 DBLENGTH dst_len;
911 static const WCHAR ten[] = {'1','0',0};
912 BSTR b;
914 dst.QuadPart = 0xcc;
915 ((ULARGE_INTEGER*)src)->QuadPart = 1234;
916 dst_len = 0x1234;
917 hr = IDataConvert_DataConvert(convert, DBTYPE_I8, DBTYPE_I8, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
918 ok(hr == S_OK, "got %08x\n", hr);
919 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
920 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
921 ok(dst.QuadPart == 1234, "got %d\n", (int)dst.QuadPart);
923 dst.QuadPart = 0xcc;
924 ((ULARGE_INTEGER*)src)->QuadPart = 1234;
925 b = SysAllocString(ten);
926 *(BSTR *)src = b;
927 hr = IDataConvert_DataConvert(convert, DBTYPE_BSTR, DBTYPE_I8, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
928 ok(hr == S_OK, "got %08x\n", hr);
929 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
930 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
931 ok(dst.QuadPart == 10, "got %d\n", (int)dst.QuadPart);
932 SysFreeString(b);
935 static void test_converttobstr(void)
937 HRESULT hr;
938 BSTR dst;
939 BYTE src[20];
940 DBSTATUS dst_status;
941 DBLENGTH dst_len;
942 static const WCHAR ten[] = {'1','0',0};
943 VARIANT v;
944 BSTR b;
946 dst_len = 0x1234;
947 hr = IDataConvert_DataConvert(convert, DBTYPE_EMPTY, DBTYPE_BSTR, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
948 ok(hr == S_OK, "got %08x\n", hr);
949 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
950 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
951 ok(dst != NULL, "got %p\n", dst);
952 ok(SysStringLen(dst) == 0, "got %d\n", SysStringLen(dst));
953 SysFreeString(dst);
955 dst = (void*)0x1234;
956 hr = IDataConvert_DataConvert(convert, DBTYPE_NULL, DBTYPE_BSTR, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
957 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr);
958 ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status);
959 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
960 ok(dst == (void*)0x1234, "got %p\n", dst);
962 *(short *)src = 4321;
963 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_BSTR, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
964 ok(hr == S_OK, "got %08x\n", hr);
965 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
966 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
967 ok(dst != NULL, "got %p\n", dst);
968 ok(SysStringLen(dst) == 4, "got %d\n", SysStringLen(dst));
969 SysFreeString(dst);
971 b = SysAllocString(ten);
972 *(BSTR *)src = b;
973 hr = IDataConvert_DataConvert(convert, DBTYPE_BSTR, DBTYPE_BSTR, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
974 ok(hr == S_OK, "got %08x\n", hr);
975 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
976 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
977 ok(dst != NULL, "got %p\n", dst);
978 ok(dst != b, "got %p src %p\n", dst, b);
979 ok(!lstrcmpW(b, dst), "got %s\n", wine_dbgstr_w(dst));
980 SysFreeString(dst);
981 SysFreeString(b);
983 b = SysAllocString(ten);
984 V_VT(&v) = VT_BSTR;
985 V_BSTR(&v) = b;
986 hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_BSTR, 0, &dst_len, &v, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
987 ok(hr == S_OK, "got %08x\n", hr);
988 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
989 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
990 ok(dst != NULL, "got %p\n", dst);
991 ok(dst != b, "got %p src %p\n", dst, b);
992 ok(!lstrcmpW(b, dst), "got %s\n", wine_dbgstr_w(dst));
993 SysFreeString(dst);
994 SysFreeString(b);
996 V_VT(&v) = VT_NULL;
997 dst = (void*)0x1234;
998 hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_BSTR, 0, &dst_len, &v, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
999 ok(hr == S_OK, "got %08x\n", hr);
1000 ok(dst_status == DBSTATUS_S_ISNULL, "got %08x\n", dst_status);
1001 ok(dst_len == sizeof(BSTR), "got %ld\n", dst_len);
1002 ok(dst == (void*)0x1234, "got %p\n", dst);
1005 static void test_converttowstr(void)
1007 HRESULT hr;
1008 WCHAR dst[100];
1009 BYTE src[20];
1010 DBSTATUS dst_status;
1011 DBLENGTH dst_len;
1012 static const WCHAR ten[] = {'1','0',0};
1013 static const WCHAR fourthreetwoone[] = {'4','3','2','1',0};
1014 static const WCHAR guid_str[] = {
1015 '{','0','C','7','3','3','A','8','D','-','2','A','1','C','-','1','1','C','E','-',
1016 'A','D','E','5','-','0','0','A','A','0','0','4','4','7','7','3','D','}',0};
1017 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 };
1018 static const WCHAR hexpacked_w[] = {'W','i','n','e', 0 };
1019 BSTR b;
1021 memset(dst, 0xcc, sizeof(dst));
1022 dst_len = 0x1234;
1023 hr = IDataConvert_DataConvert(convert, DBTYPE_EMPTY, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1024 ok(hr == S_OK, "got %08x\n", hr);
1025 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1026 ok(dst_len == 0, "got %ld\n", dst_len);
1027 ok(dst[0] == 0, "got %02x\n", dst[0]);
1028 ok(dst[1] == 0xcccc, "got %02x\n", dst[1]);
1030 memset(dst, 0xcc, sizeof(dst));
1031 dst_len = 0x1234;
1032 hr = IDataConvert_DataConvert(convert, DBTYPE_NULL, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1033 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr);
1034 ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status);
1035 ok(dst_len == 0x1234, "got %ld\n", dst_len);
1036 ok(dst[0] == 0xcccc, "got %02x\n", dst[0]);
1038 *(short *)src = 4321;
1039 dst_len = 0x1234;
1040 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1041 ok(hr == S_OK, "got %08x\n", hr);
1042 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1043 ok(dst_len == 8, "got %ld\n", dst_len);
1044 ok(!lstrcmpW(dst, fourthreetwoone), "got %s\n", wine_dbgstr_w(dst));
1046 *(short *)src = 4321;
1047 memset(dst, 0xcc, sizeof(dst));
1048 dst_len = 0x1234;
1049 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_WSTR, 0, &dst_len, src, dst, 0, 0, &dst_status, 0, 0, 0);
1050 ok(hr == DB_E_ERRORSOCCURRED, "got %08x\n", hr);
1051 ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
1052 ok(dst_len == 8, "got %ld\n", dst_len);
1053 ok(dst[0] == 0xcccc, "got %02x\n", dst[0]);
1055 *(short *)src = 4321;
1056 memset(dst, 0xcc, sizeof(dst));
1057 dst_len = 0x1234;
1058 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_WSTR, 0, &dst_len, src, NULL, 0, 0, &dst_status, 0, 0, 0);
1059 ok(hr == S_OK, "got %08x\n", hr);
1060 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1061 ok(dst_len == 8, "got %ld\n", dst_len);
1062 ok(dst[0] == 0xcccc, "got %02x\n", dst[0]);
1064 *(short *)src = 4321;
1065 memset(dst, 0xcc, sizeof(dst));
1066 dst_len = 0x1234;
1067 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_WSTR, 0, &dst_len, src, dst, 4, 0, &dst_status, 0, 0, 0);
1068 ok(hr == S_OK, "got %08x\n", hr);
1069 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1070 ok(dst_len == 8, "got %ld\n", dst_len);
1071 ok(dst[0] == '4', "got %02x\n", dst[0]);
1072 ok(dst[1] == 0, "got %02x\n", dst[1]);
1073 ok(dst[2] == 0xcccc, "got %02x\n", dst[2]);
1075 *(short *)src = 4321;
1076 memset(dst, 0xcc, sizeof(dst));
1077 dst_len = 0x1234;
1078 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_WSTR, 0, &dst_len, src, dst, 2, 0, &dst_status, 0, 0, 0);
1079 ok(hr == S_OK, "got %08x\n", hr);
1080 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1081 ok(dst_len == 8, "got %ld\n", dst_len);
1082 ok(dst[0] == 0, "got %02x\n", dst[0]);
1083 ok(dst[1] == 0xcccc, "got %02x\n", dst[1]);
1085 *(short *)src = 4321;
1086 memset(dst, 0xcc, sizeof(dst));
1087 dst_len = 0x1234;
1088 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_WSTR, 0, &dst_len, src, dst, 8, 0, &dst_status, 0, 0, 0);
1089 ok(hr == S_OK, "got %08x\n", hr);
1090 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1091 ok(dst_len == 8, "got %ld\n", dst_len);
1092 ok(dst[0] == '4', "got %02x\n", dst[0]);
1093 ok(dst[1] == '3', "got %02x\n", dst[1]);
1094 ok(dst[2] == '2', "got %02x\n", dst[2]);
1095 ok(dst[3] == 0, "got %02x\n", dst[3]);
1096 ok(dst[4] == 0xcccc, "got %02x\n", dst[4]);
1100 *(int *)src = 4321;
1101 dst_len = 0x1234;
1102 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1103 ok(hr == S_OK, "got %08x\n", hr);
1104 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1105 ok(dst_len == 8, "got %ld\n", dst_len);
1106 ok(!lstrcmpW(dst, fourthreetwoone), "got %s\n", wine_dbgstr_w(dst));
1108 *(int *)src = 4321;
1109 memset(dst, 0xcc, sizeof(dst));
1110 dst_len = 0x1234;
1111 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_WSTR, 0, &dst_len, src, dst, 0, 0, &dst_status, 0, 0, 0);
1112 ok(hr == DB_E_ERRORSOCCURRED, "got %08x\n", hr);
1113 ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "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 *(int *)src = 4321;
1118 memset(dst, 0xcc, sizeof(dst));
1119 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_WSTR, 0, &dst_len, src, NULL, 0, 0, &dst_status, 0, 0, 0);
1120 ok(hr == S_OK, "got %08x\n", hr);
1121 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1122 ok(dst_len == 8, "got %ld\n", dst_len);
1123 ok(dst[0] == 0xcccc, "got %02x\n", dst[0]);
1125 *(int *)src = 4321;
1126 memset(dst, 0xcc, sizeof(dst));
1127 dst_len = 0x1234;
1128 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_WSTR, 0, &dst_len, src, dst, 4, 0, &dst_status, 0, 0, 0);
1129 ok(hr == S_OK, "got %08x\n", hr);
1130 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1131 ok(dst_len == 8, "got %ld\n", dst_len);
1132 ok(dst[0] == '4', "got %02x\n", dst[0]);
1133 ok(dst[1] == 0, "got %02x\n", dst[1]);
1134 ok(dst[2] == 0xcccc, "got %02x\n", dst[2]);
1136 *(int *)src = 4321;
1137 memset(dst, 0xcc, sizeof(dst));
1138 dst_len = 0x1234;
1139 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_WSTR, 0, &dst_len, src, dst, 2, 0, &dst_status, 0, 0, 0);
1140 ok(hr == S_OK, "got %08x\n", hr);
1141 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1142 ok(dst_len == 8, "got %ld\n", dst_len);
1143 ok(dst[0] == 0, "got %02x\n", dst[0]);
1144 ok(dst[1] == 0xcccc, "got %02x\n", dst[1]);
1146 *(int *)src = 4321;
1147 memset(dst, 0xcc, sizeof(dst));
1148 dst_len = 0x1234;
1149 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_WSTR, 0, &dst_len, src, dst, 8, 0, &dst_status, 0, 0, 0);
1150 ok(hr == S_OK, "got %08x\n", hr);
1151 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1152 ok(dst_len == 8, "got %ld\n", dst_len);
1153 ok(dst[0] == '4', "got %02x\n", dst[0]);
1154 ok(dst[1] == '3', "got %02x\n", dst[1]);
1155 ok(dst[2] == '2', "got %02x\n", dst[2]);
1156 ok(dst[3] == 0, "got %02x\n", dst[3]);
1157 ok(dst[4] == 0xcccc, "got %02x\n", dst[4]);
1161 *(float *)src = 4321;
1162 dst_len = 0x1234;
1163 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1164 ok(hr == S_OK, "got %08x\n", hr);
1165 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1166 ok(dst_len == 8, "got %ld\n", dst_len);
1167 ok(!lstrcmpW(dst, fourthreetwoone), "got %s\n", wine_dbgstr_w(dst));
1169 *(float *)src = 4321;
1170 memset(dst, 0xcc, sizeof(dst));
1171 dst_len = 0x1234;
1172 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_WSTR, 0, &dst_len, src, dst, 0, 0, &dst_status, 0, 0, 0);
1173 ok(hr == DB_E_ERRORSOCCURRED, "got %08x\n", hr);
1174 ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "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 *(float *)src = 4321;
1179 memset(dst, 0xcc, sizeof(dst));
1180 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_WSTR, 0, &dst_len, src, NULL, 0, 0, &dst_status, 0, 0, 0);
1181 ok(hr == S_OK, "got %08x\n", hr);
1182 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1183 ok(dst_len == 8, "got %ld\n", dst_len);
1184 ok(dst[0] == 0xcccc, "got %02x\n", dst[0]);
1186 *(float *)src = 4321;
1187 memset(dst, 0xcc, sizeof(dst));
1188 dst_len = 0x1234;
1189 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_WSTR, 0, &dst_len, src, dst, 4, 0, &dst_status, 0, 0, 0);
1190 ok(hr == S_OK, "got %08x\n", hr);
1191 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1192 ok(dst_len == 8, "got %ld\n", dst_len);
1193 ok(dst[0] == '4', "got %02x\n", dst[0]);
1194 ok(dst[1] == 0, "got %02x\n", dst[1]);
1195 ok(dst[2] == 0xcccc, "got %02x\n", dst[2]);
1197 *(float *)src = 4321;
1198 memset(dst, 0xcc, sizeof(dst));
1199 dst_len = 0x1234;
1200 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_WSTR, 0, &dst_len, src, dst, 2, 0, &dst_status, 0, 0, 0);
1201 ok(hr == S_OK, "got %08x\n", hr);
1202 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1203 ok(dst_len == 8, "got %ld\n", dst_len);
1204 ok(dst[0] == 0, "got %02x\n", dst[0]);
1205 ok(dst[1] == 0xcccc, "got %02x\n", dst[1]);
1207 *(float *)src = 4321;
1208 memset(dst, 0xcc, sizeof(dst));
1209 dst_len = 0x1234;
1210 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_WSTR, 0, &dst_len, src, dst, 8, 0, &dst_status, 0, 0, 0);
1211 ok(hr == S_OK, "got %08x\n", hr);
1212 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1213 ok(dst_len == 8, "got %ld\n", dst_len);
1214 ok(dst[0] == '4', "got %02x\n", dst[0]);
1215 ok(dst[1] == '3', "got %02x\n", dst[1]);
1216 ok(dst[2] == '2', "got %02x\n", dst[2]);
1217 ok(dst[3] == 0, "got %02x\n", dst[3]);
1218 ok(dst[4] == 0xcccc, "got %02x\n", dst[4]);
1222 *(double *)src = 4321;
1223 dst_len = 0x1234;
1224 hr = IDataConvert_DataConvert(convert, DBTYPE_R8, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1225 ok(hr == S_OK, "got %08x\n", hr);
1226 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1227 ok(dst_len == 8, "got %ld\n", dst_len);
1228 ok(!lstrcmpW(dst, fourthreetwoone), "got %s\n", wine_dbgstr_w(dst));
1230 *(double *)src = 4321;
1231 memset(dst, 0xcc, sizeof(dst));
1232 hr = IDataConvert_DataConvert(convert, DBTYPE_R8, DBTYPE_WSTR, 0, &dst_len, src, dst, 0, 0, &dst_status, 0, 0, 0);
1233 ok(hr == DB_E_ERRORSOCCURRED, "got %08x\n", hr);
1234 ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
1235 ok(dst_len == 8, "got %ld\n", dst_len);
1236 ok(dst[0] == 0xcccc, "got %02x\n", dst[0]);
1238 *(double *)src = 4321;
1239 memset(dst, 0xcc, sizeof(dst));
1240 dst_len = 0x1234;
1241 hr = IDataConvert_DataConvert(convert, DBTYPE_R8, DBTYPE_WSTR, 0, &dst_len, src, NULL, 0, 0, &dst_status, 0, 0, 0);
1242 ok(hr == S_OK, "got %08x\n", hr);
1243 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1244 ok(dst_len == 8, "got %ld\n", dst_len);
1245 ok(dst[0] == 0xcccc, "got %02x\n", dst[0]);
1247 *(double *)src = 4321;
1248 memset(dst, 0xcc, sizeof(dst));
1249 dst_len = 0x1234;
1250 hr = IDataConvert_DataConvert(convert, DBTYPE_R8, DBTYPE_WSTR, 0, &dst_len, src, dst, 4, 0, &dst_status, 0, 0, 0);
1251 ok(hr == S_OK, "got %08x\n", hr);
1252 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1253 ok(dst_len == 8, "got %ld\n", dst_len);
1254 ok(dst[0] == '4', "got %02x\n", dst[0]);
1255 ok(dst[1] == 0, "got %02x\n", dst[1]);
1256 ok(dst[2] == 0xcccc, "got %02x\n", dst[2]);
1258 *(double *)src = 4321;
1259 memset(dst, 0xcc, sizeof(dst));
1260 dst_len = 0x1234;
1261 hr = IDataConvert_DataConvert(convert, DBTYPE_R8, DBTYPE_WSTR, 0, &dst_len, src, dst, 2, 0, &dst_status, 0, 0, 0);
1262 ok(hr == S_OK, "got %08x\n", hr);
1263 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1264 ok(dst_len == 8, "got %ld\n", dst_len);
1265 ok(dst[0] == 0, "got %02x\n", dst[0]);
1266 ok(dst[1] == 0xcccc, "got %02x\n", dst[1]);
1268 *(double *)src = 4321;
1269 memset(dst, 0xcc, sizeof(dst));
1270 dst_len = 0x1234;
1271 hr = IDataConvert_DataConvert(convert, DBTYPE_R8, DBTYPE_WSTR, 0, &dst_len, src, dst, 8, 0, &dst_status, 0, 0, 0);
1272 ok(hr == S_OK, "got %08x\n", hr);
1273 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1274 ok(dst_len == 8, "got %ld\n", dst_len);
1275 ok(dst[0] == '4', "got %02x\n", dst[0]);
1276 ok(dst[1] == '3', "got %02x\n", dst[1]);
1277 ok(dst[2] == '2', "got %02x\n", dst[2]);
1278 ok(dst[3] == 0, "got %02x\n", dst[3]);
1279 ok(dst[4] == 0xcccc, "got %02x\n", dst[4]);
1283 memset(src, 0, sizeof(src));
1284 ((CY*)src)->int64 = 43210000;
1285 memset(dst, 0xcc, sizeof(dst));
1286 dst_len = 0x1234;
1287 hr = IDataConvert_DataConvert(convert, DBTYPE_CY, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1288 ok(hr == S_OK, "got %08x\n", hr);
1289 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1290 ok(dst_len == 8, "got %ld\n", dst_len);
1291 ok(!lstrcmpW(dst, fourthreetwoone), "got %s\n", wine_dbgstr_w(dst));
1295 memset(src, 0, sizeof(src));
1296 *(signed char *)src = 10;
1297 dst_len = 0x1234;
1298 hr = IDataConvert_DataConvert(convert, DBTYPE_I1, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1299 ok(hr == S_OK, "got %08x\n", hr);
1300 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1301 ok(dst_len == 4, "got %ld\n", dst_len);
1302 ok(!lstrcmpW(dst, ten), "got %s\n", wine_dbgstr_w(dst));
1304 memset(src, 0, sizeof(src));
1305 *(unsigned char *)src = 10;
1306 dst_len = 0x1234;
1307 hr = IDataConvert_DataConvert(convert, DBTYPE_UI1, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1308 ok(hr == S_OK, "got %08x\n", hr);
1309 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1310 ok(dst_len == 4, "got %ld\n", dst_len);
1311 ok(!lstrcmpW(dst, ten), "got %s\n", wine_dbgstr_w(dst));
1313 memset(src, 0, sizeof(src));
1314 *(unsigned short *)src = 4321;
1315 dst_len = 0x1234;
1316 hr = IDataConvert_DataConvert(convert, DBTYPE_UI2, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1317 ok(hr == S_OK, "got %08x\n", hr);
1318 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1319 ok(dst_len == 8, "got %ld\n", dst_len);
1320 ok(!lstrcmpW(dst, fourthreetwoone), "got %s\n", wine_dbgstr_w(dst));
1322 memset(src, 0, sizeof(src));
1323 *(unsigned int *)src = 4321;
1324 dst_len = 0x1234;
1325 hr = IDataConvert_DataConvert(convert, DBTYPE_UI4, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1326 ok(hr == S_OK, "got %08x\n", hr);
1327 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1328 ok(dst_len == 8, "got %ld\n", dst_len);
1329 ok(!lstrcmpW(dst, fourthreetwoone), "got %s\n", wine_dbgstr_w(dst));
1331 memset(src, 0, sizeof(src));
1332 ((LARGE_INTEGER*)src)->QuadPart = 4321;
1333 dst_len = 0x1234;
1334 hr = IDataConvert_DataConvert(convert, DBTYPE_I8, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1335 ok(broken(DB_E_UNSUPPORTEDCONVERSION) || hr == S_OK /* W2K+ */, "got %08x\n", hr);
1336 ok(broken(dst_status == DBSTATUS_E_BADACCESSOR) || dst_status == DBSTATUS_S_OK /* W2K+ */, "got %08x\n", dst_status);
1337 ok(broken(dst_len == 0x1234) || dst_len == 8 /* W2K+ */, "got %ld\n", dst_len);
1338 ok(!lstrcmpW(dst, fourthreetwoone), "got %s\n", wine_dbgstr_w(dst));
1340 memset(src, 0, sizeof(src));
1341 ((ULARGE_INTEGER*)src)->QuadPart = 4321;
1342 hr = IDataConvert_DataConvert(convert, DBTYPE_UI8, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1343 ok(broken(DB_E_UNSUPPORTEDCONVERSION) || hr == S_OK /* W2K+ */, "got %08x\n", hr);
1344 ok(broken(dst_status == DBSTATUS_E_BADACCESSOR) || dst_status == DBSTATUS_S_OK /* W2K+ */, "got %08x\n", dst_status);
1345 ok(broken(dst_len == 0x1234) || dst_len == 8 /* W2K+ */, "got %ld\n", dst_len);
1346 ok(!lstrcmpW(dst, fourthreetwoone), "got %s\n", wine_dbgstr_w(dst));
1350 memset(src, 0, sizeof(src));
1351 memcpy(src, &IID_IDataConvert, sizeof(GUID));
1352 memset(dst, 0xcc, sizeof(dst));
1353 dst_len = 0x1234;
1354 hr = IDataConvert_DataConvert(convert, DBTYPE_GUID, DBTYPE_WSTR, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1355 ok(hr == S_OK, "got %08x\n", hr);
1356 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1357 ok(dst_len == 76, "got %ld\n", dst_len);
1358 ok(!lstrcmpW(dst, guid_str), "got %s\n", wine_dbgstr_w(dst));
1362 b = SysAllocString(ten);
1363 *(BSTR *)src = b;
1364 dst_len = 0x1234;
1365 hr = IDataConvert_DataConvert(convert, DBTYPE_BSTR, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1366 ok(hr == S_OK, "got %08x\n", hr);
1367 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1368 ok(dst_len == 4, "got %ld\n", dst_len);
1369 ok(!lstrcmpW(b, dst), "got %s\n", wine_dbgstr_w(dst));
1370 SysFreeString(b);
1372 memcpy(src, ten, sizeof(ten));
1373 dst_len = 0x1234;
1374 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_WSTR, 2, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1375 ok(hr == S_OK, "got %08x\n", hr);
1376 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1377 ok(dst_len == 2, "got %ld\n", dst_len);
1378 ok(dst[0] == '1', "got %02x\n", dst[0]);
1379 ok(dst[1] == 0, "got %02x\n", dst[1]);
1381 memcpy(src, ten, sizeof(ten));
1382 dst_len = 0x1234;
1383 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_WSTR, 4, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1384 ok(hr == S_OK, "got %08x\n", hr);
1385 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1386 ok(dst_len == 4, "got %ld\n", dst_len);
1387 ok(!lstrcmpW(ten, dst), "got %s\n", wine_dbgstr_w(dst));
1389 memcpy(src, ten, sizeof(ten));
1390 dst_len = 0x1234;
1391 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, DBDATACONVERT_LENGTHFROMNTS);
1392 ok(hr == S_OK, "got %08x\n", hr);
1393 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1394 ok(dst_len == 4, "got %ld\n", dst_len);
1395 ok(!lstrcmpW(ten, dst), "got %s\n", wine_dbgstr_w(dst));
1399 /* DBTYPE_BYTES to DBTYPE_*STR unpacks binary data into a hex string */
1400 memcpy(src, hexpacked_w, sizeof(hexpacked_w));
1401 memset(dst, 0xcc, sizeof(dst));
1402 dst_len = 0x1234;
1403 hr = IDataConvert_DataConvert(convert, DBTYPE_BYTES, DBTYPE_WSTR, sizeof(hexpacked_w), &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1404 ok(hr == S_OK, "got %08x\n", hr);
1405 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1406 ok(dst_len == sizeof(hexpacked_w) * 4, "got %ld\n", dst_len);
1407 ok(!lstrcmpW(hexunpacked_w, dst), "got %s\n", wine_dbgstr_w(dst));
1408 ok(dst[sizeof(hexpacked_w)/sizeof(WCHAR) * 4 + 1] == 0xcccc, "clobbered buffer\n");
1410 memcpy(src, hexpacked_w, sizeof(hexpacked_w));
1411 memset(dst, 0xcc, sizeof(dst));
1412 dst_len = 0x1234;
1413 hr = IDataConvert_DataConvert(convert, DBTYPE_BYTES, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1414 ok(hr == S_OK, "got %08x\n", hr);
1415 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1416 ok(dst_len == 0, "got %ld\n", dst_len);
1417 ok(dst[0] == 0, "not null terminated\n");
1418 ok(dst[1] == 0xcccc, "clobbered buffer\n");
1420 memcpy(src, hexpacked_w, sizeof(hexpacked_w));
1421 memset(dst, 0xcc, sizeof(dst));
1422 dst_len = 0x1234;
1423 hr = IDataConvert_DataConvert(convert, DBTYPE_BYTES, DBTYPE_WSTR, 4, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1424 ok(hr == S_OK, "got %08x\n", hr);
1425 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1426 ok(dst_len == 2 * sizeof(WCHAR) * 4, "got %ld\n", dst_len);
1427 ok(!memcmp(hexunpacked_w, dst, 2 * sizeof(WCHAR) * 4 ), "got %s\n", wine_dbgstr_w(dst));
1428 ok(dst[2 * 4] == 0, "not null terminated\n");
1429 ok(dst[2 * 4 + 1] == 0xcccc, "clobbered buffer\n");
1431 memcpy(src, hexpacked_w, sizeof(hexpacked_w));
1432 memset(dst, 0xcc, sizeof(dst));
1433 dst_len = 0x1234;
1434 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);
1435 ok(hr == S_OK, "got %08x\n", hr);
1436 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1437 ok(dst_len == sizeof(hexpacked_w) * 4, "got %ld\n", dst_len);
1438 ok(!memcmp(hexunpacked_w, dst, 2 * sizeof(WCHAR) * 4 ), "got %s\n", wine_dbgstr_w(dst));
1439 ok(dst[2 * 4] == 0, "not null terminated\n");
1440 ok(dst[2 * 4 + 1] == 0xcccc, "clobbered buffer\n");
1442 memcpy(src, hexpacked_w, sizeof(hexpacked_w));
1443 memset(dst, 0xcc, sizeof(dst));
1444 dst_len = 0x1234;
1445 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);
1446 ok(hr == S_OK, "got %08x\n", hr);
1447 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1448 ok(dst_len == sizeof(hexpacked_w) * 4, "got %ld\n", dst_len);
1449 ok(!memcmp(hexunpacked_w, dst, 2 * sizeof(WCHAR) * 4 - 2 ), "got %s\n", wine_dbgstr_w(dst));
1450 ok(dst[2 * 4 - 1] == 0, "not null terminated\n");
1451 ok(dst[2 * 4] == 0xcccc, "clobbered buffer\n");
1453 memcpy(src, hexpacked_w, sizeof(hexpacked_w));
1454 memset(dst, 0xcc, sizeof(dst));
1455 dst_len = 0x1234;
1456 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);
1457 ok(hr == S_OK, "got %08x\n", hr);
1458 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1459 ok(dst_len == sizeof(hexpacked_w) * 4, "got %ld\n", dst_len);
1460 ok(!memcmp(hexunpacked_w, dst, 2 * sizeof(WCHAR) * 4 - 2 ), "got %s\n", wine_dbgstr_w(dst));
1461 ok(dst[2 * 4 - 1] == 0, "not null terminated\n");
1462 ok(dst[2 * 4] == 0xcccc, "clobbered buffer\n");
1464 memcpy(src, hexpacked_w, sizeof(hexpacked_w));
1465 memset(dst, 0xcc, sizeof(dst));
1466 dst_len = 0x1234;
1467 hr = IDataConvert_DataConvert(convert, DBTYPE_BYTES, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, DBDATACONVERT_LENGTHFROMNTS);
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 == 0, "got %ld\n", dst_len);
1471 ok(dst[0] == 0, "not null terminated\n");
1472 ok(dst[1] == 0xcccc, "clobbered buffer\n");
1475 static void test_converttostr(void)
1477 HRESULT hr;
1478 char dst[100];
1479 BYTE src[64];
1480 DBSTATUS dst_status;
1481 DBLENGTH dst_len;
1482 static const WCHAR ten[] = {'1','0',0};
1483 static const char ten_a[] = "10";
1484 static const char fourthreetwoone[] = "4321";
1485 static const char guid_str[] = "{0C733A8D-2A1C-11CE-ADE5-00AA0044773D}";
1486 static const char hexunpacked_a[] = "57696E6500";
1487 static const char hexpacked_a[] = "Wine";
1488 BSTR b;
1490 memset(dst, 0xcc, sizeof(dst));
1491 dst_len = 0x1234;
1492 hr = IDataConvert_DataConvert(convert, DBTYPE_EMPTY, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1493 ok(hr == S_OK, "got %08x\n", hr);
1494 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1495 ok(dst_len == 0, "got %ld\n", dst_len);
1496 ok(dst[0] == 0, "got %02x\n", dst[0]);
1497 ok(dst[1] == (char)0xcc, "got %02x\n", dst[1]);
1499 memset(dst, 0xcc, sizeof(dst));
1500 dst_len = 0x1234;
1501 hr = IDataConvert_DataConvert(convert, DBTYPE_NULL, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1502 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr);
1503 ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status);
1504 ok(dst_len == 0x1234, "got %ld\n", dst_len);
1505 ok(dst[0] == (char)0xcc, "got %02x\n", dst[0]);
1507 *(short *)src = 4321;
1508 dst_len = 0x1234;
1509 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1510 ok(hr == S_OK, "got %08x\n", hr);
1511 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1512 ok(dst_len == 4, "got %ld\n", dst_len);
1513 ok(!lstrcmpA(dst, fourthreetwoone), "got %s\n", dst);
1515 *(short *)src = 4321;
1516 memset(dst, 0xcc, sizeof(dst));
1517 dst_len = 0x1234;
1518 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_STR, 0, &dst_len, src, dst, 0, 0, &dst_status, 0, 0, 0);
1519 ok(hr == DB_E_ERRORSOCCURRED, "got %08x\n", hr);
1520 ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
1521 ok(dst_len == 4, "got %ld\n", dst_len);
1522 ok(dst[0] == (char)0xcc, "got %02x\n", dst[0]);
1524 *(short *)src = 4321;
1525 memset(dst, 0xcc, sizeof(dst));
1526 dst_len = 0x1234;
1527 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_STR, 0, &dst_len, src, NULL, 0, 0, &dst_status, 0, 0, 0);
1528 ok(hr == S_OK, "got %08x\n", hr);
1529 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1530 ok(dst_len == 4, "got %ld\n", dst_len);
1531 ok(dst[0] == (char)0xcc, "got %02x\n", dst[0]);
1533 *(short *)src = 4321;
1534 memset(dst, 0xcc, sizeof(dst));
1535 dst_len = 0x1234;
1536 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_STR, 0, &dst_len, src, dst, 2, 0, &dst_status, 0, 0, 0);
1537 ok(hr == S_OK, "got %08x\n", hr);
1538 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1539 ok(dst_len == 4, "got %ld\n", dst_len);
1540 ok(dst[0] == '4', "got %02x\n", dst[0]);
1541 ok(dst[1] == 0, "got %02x\n", dst[1]);
1542 ok(dst[2] == (char)0xcc, "got %02x\n", dst[2]);
1544 *(short *)src = 4321;
1545 memset(dst, 0xcc, sizeof(dst));
1546 dst_len = 0x1234;
1547 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_STR, 0, &dst_len, src, dst, 1, 0, &dst_status, 0, 0, 0);
1548 ok(hr == S_OK, "got %08x\n", hr);
1549 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1550 ok(dst_len == 4, "got %ld\n", dst_len);
1551 ok(dst[0] == 0, "got %02x\n", dst[0]);
1552 ok(dst[1] == (char)0xcc, "got %02x\n", dst[1]);
1554 *(short *)src = 4321;
1555 memset(dst, 0xcc, sizeof(dst));
1556 dst_len = 0x1234;
1557 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_STR, 0, &dst_len, src, dst, 4, 0, &dst_status, 0, 0, 0);
1558 ok(hr == S_OK, "got %08x\n", hr);
1559 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1560 ok(dst_len == 4, "got %ld\n", dst_len);
1561 ok(dst[0] == '4', "got %02x\n", dst[0]);
1562 ok(dst[1] == '3', "got %02x\n", dst[1]);
1563 ok(dst[2] == '2', "got %02x\n", dst[2]);
1564 ok(dst[3] == 0, "got %02x\n", dst[3]);
1565 ok(dst[4] == (char)0xcc, "got %02x\n", dst[4]);
1568 *(int *)src = 4321;
1569 dst_len = 0x1234;
1570 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1571 ok(hr == S_OK, "got %08x\n", hr);
1572 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1573 ok(dst_len == 4, "got %ld\n", dst_len);
1574 ok(!lstrcmpA(dst, fourthreetwoone), "got %s\n", dst);
1576 *(int *)src = 4321;
1577 memset(dst, 0xcc, sizeof(dst));
1578 dst_len = 0x1234;
1579 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_STR, 0, &dst_len, src, dst, 0, 0, &dst_status, 0, 0, 0);
1580 ok(hr == DB_E_ERRORSOCCURRED, "got %08x\n", hr);
1581 ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
1582 ok(dst_len == 4, "got %ld\n", dst_len);
1583 ok(dst[0] == (char)0xcc, "got %02x\n", dst[0]);
1585 *(int *)src = 4321;
1586 memset(dst, 0xcc, sizeof(dst));
1587 dst_len = 0x1234;
1588 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_STR, 0, &dst_len, src, NULL, 0, 0, &dst_status, 0, 0, 0);
1589 ok(hr == S_OK, "got %08x\n", hr);
1590 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1591 ok(dst_len == 4, "got %ld\n", dst_len);
1592 ok(dst[0] == (char)0xcc, "got %02x\n", dst[0]);
1594 *(int *)src = 4321;
1595 memset(dst, 0xcc, sizeof(dst));
1596 dst_len = 0x1234;
1597 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_STR, 0, &dst_len, src, dst, 2, 0, &dst_status, 0, 0, 0);
1598 ok(hr == S_OK, "got %08x\n", hr);
1599 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1600 ok(dst_len == 4, "got %ld\n", dst_len);
1601 ok(dst[0] == '4', "got %02x\n", dst[0]);
1602 ok(dst[1] == 0, "got %02x\n", dst[1]);
1603 ok(dst[2] == (char)0xcc, "got %02x\n", dst[2]);
1605 *(int *)src = 4321;
1606 memset(dst, 0xcc, sizeof(dst));
1607 dst_len = 0x1234;
1608 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_STR, 0, &dst_len, src, dst, 1, 0, &dst_status, 0, 0, 0);
1609 ok(hr == S_OK, "got %08x\n", hr);
1610 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1611 ok(dst_len == 4, "got %ld\n", dst_len);
1612 ok(dst[0] == 0, "got %02x\n", dst[0]);
1613 ok(dst[1] == (char)0xcc, "got %02x\n", dst[1]);
1615 *(int *)src = 4321;
1616 memset(dst, 0xcc, sizeof(dst));
1617 dst_len = 0x1234;
1618 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_STR, 0, &dst_len, src, dst, 4, 0, &dst_status, 0, 0, 0);
1619 ok(hr == S_OK, "got %08x\n", hr);
1620 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1621 ok(dst_len == 4, "got %ld\n", dst_len);
1622 ok(dst[0] == '4', "got %02x\n", dst[0]);
1623 ok(dst[1] == '3', "got %02x\n", dst[1]);
1624 ok(dst[2] == '2', "got %02x\n", dst[2]);
1625 ok(dst[3] == 0, "got %02x\n", dst[3]);
1626 ok(dst[4] == (char)0xcc, "got %02x\n", dst[4]);
1629 *(float *)src = 4321;
1630 dst_len = 0x1234;
1631 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1632 ok(hr == S_OK, "got %08x\n", hr);
1633 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1634 ok(dst_len == 4, "got %ld\n", dst_len);
1635 ok(!lstrcmpA(dst, fourthreetwoone), "got %s\n", dst);
1637 *(float *)src = 4321;
1638 memset(dst, 0xcc, sizeof(dst));
1639 dst_len = 0x1234;
1640 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_STR, 0, &dst_len, src, dst, 0, 0, &dst_status, 0, 0, 0);
1641 ok(hr == DB_E_ERRORSOCCURRED, "got %08x\n", hr);
1642 ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
1643 ok(dst_len == 4, "got %ld\n", dst_len);
1644 ok(dst[0] == (char)0xcc, "got %02x\n", dst[0]);
1646 *(float *)src = 4321;
1647 memset(dst, 0xcc, sizeof(dst));
1648 dst_len = 0x1234;
1649 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_STR, 0, &dst_len, src, NULL, 0, 0, &dst_status, 0, 0, 0);
1650 ok(hr == S_OK, "got %08x\n", hr);
1651 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1652 ok(dst_len == 4, "got %ld\n", dst_len);
1653 ok(dst[0] == (char)0xcc, "got %02x\n", dst[0]);
1655 *(float *)src = 4321;
1656 memset(dst, 0xcc, sizeof(dst));
1657 dst_len = 0x1234;
1658 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_STR, 0, &dst_len, src, dst, 2, 0, &dst_status, 0, 0, 0);
1659 ok(hr == S_OK, "got %08x\n", hr);
1660 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1661 ok(dst_len == 4, "got %ld\n", dst_len);
1662 ok(dst[0] == '4', "got %02x\n", dst[0]);
1663 ok(dst[1] == 0, "got %02x\n", dst[1]);
1664 ok(dst[2] == (char)0xcc, "got %02x\n", dst[2]);
1666 *(float *)src = 4321;
1667 memset(dst, 0xcc, sizeof(dst));
1668 dst_len = 0x1234;
1669 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_STR, 0, &dst_len, src, dst, 1, 0, &dst_status, 0, 0, 0);
1670 ok(hr == S_OK, "got %08x\n", hr);
1671 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1672 ok(dst_len == 4, "got %ld\n", dst_len);
1673 ok(dst[0] == 0, "got %02x\n", dst[0]);
1674 ok(dst[1] == (char)0xcc, "got %02x\n", dst[1]);
1676 *(float *)src = 4321;
1677 memset(dst, 0xcc, sizeof(dst));
1678 dst_len = 0x1234;
1679 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_STR, 0, &dst_len, src, dst, 4, 0, &dst_status, 0, 0, 0);
1680 ok(hr == S_OK, "got %08x\n", hr);
1681 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1682 ok(dst_len == 4, "got %ld\n", dst_len);
1683 ok(dst[0] == '4', "got %02x\n", dst[0]);
1684 ok(dst[1] == '3', "got %02x\n", dst[1]);
1685 ok(dst[2] == '2', "got %02x\n", dst[2]);
1686 ok(dst[3] == 0, "got %02x\n", dst[3]);
1687 ok(dst[4] == (char)0xcc, "got %02x\n", dst[4]);
1690 *(double *)src = 4321;
1691 dst_len = 0x1234;
1692 hr = IDataConvert_DataConvert(convert, DBTYPE_R8, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1693 ok(hr == S_OK, "got %08x\n", hr);
1694 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1695 ok(dst_len == 4, "got %ld\n", dst_len);
1696 ok(!lstrcmpA(dst, fourthreetwoone), "got %s\n", dst);
1698 *(double *)src = 4321;
1699 memset(dst, 0xcc, sizeof(dst));
1700 dst_len = 0x1234;
1701 hr = IDataConvert_DataConvert(convert, DBTYPE_R8, DBTYPE_STR, 0, &dst_len, src, dst, 0, 0, &dst_status, 0, 0, 0);
1702 ok(hr == DB_E_ERRORSOCCURRED, "got %08x\n", hr);
1703 ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
1704 ok(dst_len == 4, "got %ld\n", dst_len);
1705 ok(dst[0] == (char)0xcc, "got %02x\n", dst[0]);
1707 *(double *)src = 4321;
1708 memset(dst, 0xcc, sizeof(dst));
1709 dst_len = 0x1234;
1710 hr = IDataConvert_DataConvert(convert, DBTYPE_R8, DBTYPE_STR, 0, &dst_len, src, NULL, 0, 0, &dst_status, 0, 0, 0);
1711 ok(hr == S_OK, "got %08x\n", hr);
1712 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1713 ok(dst_len == 4, "got %ld\n", dst_len);
1714 ok(dst[0] == (char)0xcc, "got %02x\n", dst[0]);
1716 *(double *)src = 4321;
1717 memset(dst, 0xcc, sizeof(dst));
1718 dst_len = 0x1234;
1719 hr = IDataConvert_DataConvert(convert, DBTYPE_R8, DBTYPE_STR, 0, &dst_len, src, dst, 2, 0, &dst_status, 0, 0, 0);
1720 ok(hr == S_OK, "got %08x\n", hr);
1721 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1722 ok(dst_len == 4, "got %ld\n", dst_len);
1723 ok(dst[0] == '4', "got %02x\n", dst[0]);
1724 ok(dst[1] == 0, "got %02x\n", dst[1]);
1725 ok(dst[2] == (char)0xcc, "got %02x\n", dst[2]);
1727 *(double *)src = 4321;
1728 memset(dst, 0xcc, sizeof(dst));
1729 dst_len = 0x1234;
1730 hr = IDataConvert_DataConvert(convert, DBTYPE_R8, DBTYPE_STR, 0, &dst_len, src, dst, 1, 0, &dst_status, 0, 0, 0);
1731 ok(hr == S_OK, "got %08x\n", hr);
1732 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1733 ok(dst_len == 4, "got %ld\n", dst_len);
1734 ok(dst[0] == 0, "got %02x\n", dst[0]);
1735 ok(dst[1] == (char)0xcc, "got %02x\n", dst[1]);
1737 *(double *)src = 4321;
1738 memset(dst, 0xcc, sizeof(dst));
1739 dst_len = 0x1234;
1740 hr = IDataConvert_DataConvert(convert, DBTYPE_R8, DBTYPE_STR, 0, &dst_len, src, dst, 4, 0, &dst_status, 0, 0, 0);
1741 ok(hr == S_OK, "got %08x\n", hr);
1742 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1743 ok(dst_len == 4, "got %ld\n", dst_len);
1744 ok(dst[0] == '4', "got %02x\n", dst[0]);
1745 ok(dst[1] == '3', "got %02x\n", dst[1]);
1746 ok(dst[2] == '2', "got %02x\n", dst[2]);
1747 ok(dst[3] == 0, "got %02x\n", dst[3]);
1748 ok(dst[4] == (char)0xcc, "got %02x\n", dst[4]);
1752 memset(src, 0, sizeof(src));
1753 ((CY*)src)->int64 = 43210000;
1754 memset(dst, 0xcc, sizeof(dst));
1755 dst_len = 0x1234;
1756 hr = IDataConvert_DataConvert(convert, DBTYPE_CY, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1757 ok(hr == S_OK, "got %08x\n", hr);
1758 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1759 ok(dst_len == 4, "got %ld\n", dst_len);
1760 ok(!lstrcmpA(dst, fourthreetwoone), "got %s\n", dst);
1764 memset(src, 0, sizeof(src));
1765 *(signed char *)src = 10;
1766 dst_len = 0x1234;
1767 hr = IDataConvert_DataConvert(convert, DBTYPE_I1, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1768 ok(hr == S_OK, "got %08x\n", hr);
1769 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1770 ok(dst_len == 2, "got %ld\n", dst_len);
1771 ok(!lstrcmpA(dst, ten_a), "got %s\n", dst);
1773 memset(src, 0, sizeof(src));
1774 *(unsigned char *)src = 10;
1775 dst_len = 0x1234;
1776 hr = IDataConvert_DataConvert(convert, DBTYPE_UI1, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1777 ok(hr == S_OK, "got %08x\n", hr);
1778 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1779 ok(dst_len == 2, "got %ld\n", dst_len);
1780 ok(!lstrcmpA(dst, ten_a), "got %s\n", dst);
1782 memset(src, 0, sizeof(src));
1783 *(unsigned short *)src = 4321;
1784 dst_len = 0x1234;
1785 hr = IDataConvert_DataConvert(convert, DBTYPE_UI2, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1786 ok(hr == S_OK, "got %08x\n", hr);
1787 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1788 ok(dst_len == 4, "got %ld\n", dst_len);
1789 ok(!lstrcmpA(dst, fourthreetwoone), "got %s\n", dst);
1791 memset(src, 0, sizeof(src));
1792 *(unsigned int *)src = 4321;
1793 dst_len = 0x1234;
1794 hr = IDataConvert_DataConvert(convert, DBTYPE_UI4, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1795 ok(hr == S_OK, "got %08x\n", hr);
1796 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1797 ok(dst_len == 4, "got %ld\n", dst_len);
1798 ok(!lstrcmpA(dst, fourthreetwoone), "got %s\n", dst);
1800 memset(src, 0, sizeof(src));
1801 ((LARGE_INTEGER*)src)->QuadPart = 4321;
1802 dst_len = 0x1234;
1803 hr = IDataConvert_DataConvert(convert, DBTYPE_I8, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1804 ok(broken(DB_E_UNSUPPORTEDCONVERSION) || hr == S_OK /* W2K+ */, "got %08x\n", hr);
1805 ok(broken(dst_status == DBSTATUS_E_BADACCESSOR) || dst_status == DBSTATUS_S_OK /* W2K+ */, "got %08x\n", dst_status);
1806 ok(broken(dst_len == 0x1234) || dst_len == 4 /* W2K+ */, "got %ld\n", dst_len);
1807 ok(!lstrcmpA(dst, fourthreetwoone), "got %s\n", dst);
1809 memset(src, 0, sizeof(src));
1810 ((ULARGE_INTEGER*)src)->QuadPart = 4321;
1811 dst_len = 0x1234;
1812 hr = IDataConvert_DataConvert(convert, DBTYPE_UI8, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1813 ok(broken(DB_E_UNSUPPORTEDCONVERSION) || hr == S_OK /* W2K+ */, "got %08x\n", hr);
1814 ok(broken(dst_status == DBSTATUS_E_BADACCESSOR) || dst_status == DBSTATUS_S_OK /* W2K+ */, "got %08x\n", dst_status);
1815 ok(broken(dst_len == 0x1234) || dst_len == 4 /* W2K+ */, "got %ld\n", dst_len);
1816 ok(!lstrcmpA(dst, fourthreetwoone), "got %s\n", dst);
1820 memset(src, 0, sizeof(src));
1821 memcpy(src, &IID_IDataConvert, sizeof(GUID));
1822 memset(dst, 0xcc, sizeof(dst));
1823 dst_len = 0x1234;
1824 hr = IDataConvert_DataConvert(convert, DBTYPE_GUID, DBTYPE_STR, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1825 ok(hr == S_OK, "got %08x\n", hr);
1826 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1827 ok(dst_len == 38, "got %ld\n", dst_len);
1828 ok(!lstrcmpA(dst, guid_str), "got %s\n", dst);
1832 b = SysAllocString(ten);
1833 *(BSTR *)src = b;
1834 memset(dst, 0xcc, sizeof(dst));
1835 dst_len = 0x1234;
1836 hr = IDataConvert_DataConvert(convert, DBTYPE_BSTR, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1837 ok(hr == S_OK, "got %08x\n", hr);
1838 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1839 ok(dst_len == 2, "got %ld\n", dst_len);
1840 ok(!lstrcmpA(ten_a, dst), "got %s\n", dst);
1841 SysFreeString(b);
1843 memcpy(src, ten, sizeof(ten));
1844 memset(dst, 0xcc, sizeof(dst));
1845 dst_len = 0x1234;
1846 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_STR, 2, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1847 ok(hr == S_OK, "got %08x\n", hr);
1848 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1849 ok(dst_len == 1, "got %ld\n", dst_len);
1850 ok(dst[0] == '1', "got %02x\n", dst[0]);
1851 ok(dst[1] == 0, "got %02x\n", dst[1]);
1853 memcpy(src, ten, sizeof(ten));
1854 memset(dst, 0xcc, sizeof(dst));
1855 dst_len = 0x1234;
1856 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_STR, 4, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1857 ok(hr == S_OK, "got %08x\n", hr);
1858 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1859 ok(dst_len == 2, "got %ld\n", dst_len);
1860 ok(!lstrcmpA(ten_a, dst), "got %s\n", dst);
1862 memcpy(src, ten, sizeof(ten));
1863 memset(dst, 0xcc, sizeof(dst));
1864 dst_len = 0x1234;
1865 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, DBDATACONVERT_LENGTHFROMNTS);
1866 ok(hr == S_OK, "got %08x\n", hr);
1867 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1868 ok(dst_len == 2, "got %ld\n", dst_len);
1869 ok(!lstrcmpA(ten_a, dst), "got %s\n", dst);
1871 memcpy(src, ten_a, sizeof(ten_a));
1872 memset(dst, 0xcc, sizeof(dst));
1873 dst_len = 0x1234;
1874 hr = IDataConvert_DataConvert(convert, DBTYPE_STR, DBTYPE_STR, 2, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1875 ok(hr == S_OK, "got %08x\n", hr);
1876 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1877 ok(dst_len == 2, "got %ld\n", dst_len);
1878 ok(dst[0] == '1', "got %02x\n", dst[0]);
1879 ok(dst[1] == '0', "got %02x\n", dst[1]);
1880 ok(dst[2] == 0, "got %02x\n", dst[2]);
1881 ok(dst[3] == (char)0xcc, "got %02x\n", dst[3]);
1883 memcpy(src, ten_a, sizeof(ten_a));
1884 memset(dst, 0xcc, sizeof(dst));
1885 dst_len = 0x1234;
1886 hr = IDataConvert_DataConvert(convert, DBTYPE_STR, DBTYPE_STR, 4, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1887 ok(hr == S_OK, "got %08x\n", hr);
1888 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1889 ok(dst_len == 4, "got %ld\n", dst_len);
1890 ok(!lstrcmpA(ten_a, dst), "got %s\n", dst);
1892 memcpy(src, ten_a, sizeof(ten_a));
1893 memset(dst, 0xcc, sizeof(dst));
1894 dst_len = 0x1234;
1895 hr = IDataConvert_DataConvert(convert, DBTYPE_STR, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, DBDATACONVERT_LENGTHFROMNTS);
1896 ok(hr == S_OK, "got %08x\n", hr);
1897 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1898 ok(dst_len == 2, "got %ld\n", dst_len);
1899 ok(!lstrcmpA(ten_a, dst), "got %s\n", dst);
1903 /* DBTYPE_BYTES to DBTYPE_*STR unpacks binary data into a hex string */
1904 memcpy(src, hexpacked_a, sizeof(hexpacked_a));
1905 memset(dst, 0xcc, sizeof(dst));
1906 dst_len = 0x1234;
1907 hr = IDataConvert_DataConvert(convert, DBTYPE_BYTES, DBTYPE_STR, sizeof(hexpacked_a), &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1908 ok(hr == S_OK, "got %08x\n", hr);
1909 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1910 ok(dst_len == sizeof(hexpacked_a) * 2, "got %ld\n", dst_len);
1911 ok(!lstrcmpA(hexunpacked_a, dst), "got %s\n", dst);
1912 ok(dst[sizeof(hexpacked_a)/sizeof(char) * 4 + 1] == (char)0xcc, "clobbered buffer\n");
1914 memcpy(src, hexpacked_a, sizeof(hexpacked_a));
1915 memset(dst, 0xcc, sizeof(dst));
1916 dst_len = 0x1234;
1917 hr = IDataConvert_DataConvert(convert, DBTYPE_BYTES, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1918 ok(hr == S_OK, "got %08x\n", hr);
1919 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1920 ok(dst_len == 0, "got %ld\n", dst_len);
1921 ok(dst[0] == 0, "not null terminated\n");
1922 ok(dst[1] == (char)0xcc, "clobbered buffer\n");
1924 memcpy(src, hexpacked_a, sizeof(hexpacked_a));
1925 memset(dst, 0xcc, sizeof(dst));
1926 dst_len = 0x1234;
1927 hr = IDataConvert_DataConvert(convert, DBTYPE_BYTES, DBTYPE_STR, 4, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1928 ok(hr == S_OK, "got %08x\n", hr);
1929 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1930 ok(dst_len == 2 * sizeof(char) * 4, "got %ld\n", dst_len);
1931 ok(!memcmp(hexunpacked_a, dst, 2 * sizeof(char) * 4 ), "got %s\n", dst);
1932 ok(dst[2 * 4] == 0, "not null terminated\n");
1933 ok(dst[2 * 4 + 1] == (char)0xcc, "clobbered buffer\n");
1935 memcpy(src, hexpacked_a, sizeof(hexpacked_a));
1936 memset(dst, 0xcc, sizeof(dst));
1937 dst_len = 0x1234;
1938 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);
1939 ok(hr == S_OK, "got %08x\n", hr);
1940 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1941 ok(dst_len == sizeof(hexpacked_a) * 2, "got %ld\n", dst_len);
1942 ok(!memcmp(hexunpacked_a, dst, 2 * sizeof(char) * 4 ), "got %s\n", dst);
1943 ok(dst[2 * 4] == 0, "not null terminated\n");
1944 ok(dst[2 * 4 + 1] == (char)0xcc, "clobbered buffer\n");
1946 memcpy(src, hexpacked_a, sizeof(hexpacked_a));
1947 memset(dst, 0xcc, sizeof(dst));
1948 dst_len = 0x1234;
1949 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);
1950 ok(hr == S_OK, "got %08x\n", hr);
1951 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1952 ok(dst_len == sizeof(hexpacked_a) * 2, "got %ld\n", dst_len);
1953 ok(!memcmp(hexunpacked_a, dst, 2 * sizeof(char) * 4 - 2 ), "got %s\n", dst);
1954 ok(dst[2 * 4 - 1] == 0, "not null terminated\n");
1955 ok(dst[2 * 4] == (char)0xcc, "clobbered buffer\n");
1957 memcpy(src, hexpacked_a, sizeof(hexpacked_a));
1958 memset(dst, 0xcc, sizeof(dst));
1959 dst_len = 0x1234;
1960 hr = IDataConvert_DataConvert(convert, DBTYPE_BYTES, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, DBDATACONVERT_LENGTHFROMNTS);
1961 ok(hr == S_OK, "got %08x\n", hr);
1962 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1963 ok(dst_len == 0, "got %ld\n", dst_len);
1964 ok(dst[0] == 0, "not null terminated\n");
1965 ok(dst[1] == (char)0xcc, "clobbered buffer\n");
1968 static void test_converttobyrefwstr(void)
1970 HRESULT hr;
1971 WCHAR *dst;
1972 BYTE src[20];
1973 DBSTATUS dst_status;
1974 DBLENGTH dst_len;
1975 static const WCHAR ten[] = {'1','0',0};
1976 static const WCHAR fourthreetwoone[] = {'4','3','2','1',0};
1977 BSTR b;
1979 hr = IDataConvert_DataConvert(convert, DBTYPE_EMPTY, DBTYPE_BYREF | DBTYPE_WSTR, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1980 ok(hr == S_OK, "got %08x\n", hr);
1981 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1982 ok(dst_len == 0, "got %ld\n", dst_len);
1983 ok(dst[0] == 0, "got %04x\n", dst[0]);
1984 CoTaskMemFree(dst);
1986 dst = (void*)0x12345678;
1987 dst_len = 0x1234;
1988 hr = IDataConvert_DataConvert(convert, DBTYPE_NULL, DBTYPE_BYREF | DBTYPE_WSTR, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1989 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr);
1990 ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status);
1991 ok(dst_len == 0x1234, "got %ld\n", dst_len);
1992 ok(dst == (void*)0x12345678, "got %p\n", dst);
1994 *(short *)src = 4321;
1995 dst_len = 0x1234;
1996 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_BYREF | DBTYPE_WSTR, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1997 ok(hr == S_OK, "got %08x\n", hr);
1998 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1999 ok(dst_len == 8, "got %ld\n", dst_len);
2000 ok(!lstrcmpW(dst, fourthreetwoone), "got %s\n", wine_dbgstr_w(dst));
2001 CoTaskMemFree(dst);
2003 *(short *)src = 4321;
2004 dst_len = 0x1234;
2005 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_BYREF | DBTYPE_WSTR, 0, &dst_len, src, &dst, 0, 0, &dst_status, 0, 0, 0);
2006 ok(hr == S_OK, "got %08x\n", hr);
2007 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2008 ok(dst_len == 8, "got %ld\n", dst_len);
2009 ok(!lstrcmpW(dst, fourthreetwoone), "got %s\n", wine_dbgstr_w(dst));
2010 CoTaskMemFree(dst);
2012 b = SysAllocString(ten);
2013 *(BSTR *)src = b;
2014 dst_len = 0x1234;
2015 hr = IDataConvert_DataConvert(convert, DBTYPE_BSTR, DBTYPE_BYREF | DBTYPE_WSTR, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2016 ok(hr == S_OK, "got %08x\n", hr);
2017 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2018 ok(dst_len == 4, "got %ld\n", dst_len);
2019 ok(!lstrcmpW(b, dst), "got %s\n", wine_dbgstr_w(dst));
2020 CoTaskMemFree(dst);
2021 SysFreeString(b);
2023 memcpy(src, ten, sizeof(ten));
2024 dst_len = 0x1234;
2025 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_BYREF | DBTYPE_WSTR, 2, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2026 ok(hr == S_OK, "got %08x\n", hr);
2027 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2028 ok(dst_len == 2, "got %ld\n", dst_len);
2029 ok(dst[0] == '1', "got %02x\n", dst[0]);
2030 ok(dst[1] == 0, "got %02x\n", dst[1]);
2031 CoTaskMemFree(dst);
2033 memcpy(src, ten, sizeof(ten));
2034 dst_len = 0x1234;
2035 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_BYREF | DBTYPE_WSTR, 4, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2036 ok(hr == S_OK, "got %08x\n", hr);
2037 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2038 ok(dst_len == 4, "got %ld\n", dst_len);
2039 ok(!lstrcmpW(ten, dst), "got %s\n", wine_dbgstr_w(dst));
2040 CoTaskMemFree(dst);
2042 memcpy(src, ten, sizeof(ten));
2043 dst_len = 0x1234;
2044 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_BYREF | DBTYPE_WSTR, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, DBDATACONVERT_LENGTHFROMNTS);
2045 ok(hr == S_OK, "got %08x\n", hr);
2046 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2047 ok(dst_len == 4, "got %ld\n", dst_len);
2048 ok(!lstrcmpW(ten, dst), "got %s\n", wine_dbgstr_w(dst));
2049 CoTaskMemFree(dst);
2052 static void test_converttoguid(void)
2054 HRESULT hr;
2055 GUID dst;
2056 BYTE src[20];
2057 DBSTATUS dst_status;
2058 DBLENGTH dst_len;
2060 dst = IID_IDCInfo;
2061 dst_len = 0x1234;
2062 hr = IDataConvert_DataConvert(convert, DBTYPE_EMPTY, DBTYPE_GUID, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2063 ok(hr == S_OK, "got %08x\n", hr);
2064 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2065 ok(dst_len == sizeof(GUID), "got %ld\n", dst_len);
2066 ok(IsEqualGUID(&dst, &GUID_NULL), "didn't get GUID_NULL\n");
2068 dst = IID_IDCInfo;
2069 dst_len = 0x1234;
2070 hr = IDataConvert_DataConvert(convert, DBTYPE_NULL, DBTYPE_GUID, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2071 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr);
2072 ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status);
2073 ok(dst_len == 0x1234, "got %ld\n", dst_len);
2074 ok(IsEqualGUID(&dst, &IID_IDCInfo), "dst has changed\n");
2076 dst = IID_IDCInfo;
2077 memcpy(src, &IID_IDataConvert, sizeof(GUID));
2078 dst_len = 0x1234;
2079 hr = IDataConvert_DataConvert(convert, DBTYPE_GUID, DBTYPE_GUID, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2080 ok(hr == S_OK, "got %08x\n", hr);
2081 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2082 ok(dst_len == sizeof(GUID), "got %ld\n", dst_len);
2083 ok(IsEqualGUID(&dst, &IID_IDataConvert), "didn't get IID_IDataConvert\n");
2086 static void test_converttofiletime(void)
2088 HRESULT hr;
2089 FILETIME dst;
2090 BYTE src[20];
2091 DBSTATUS dst_status;
2092 DBLENGTH dst_len;
2094 memset(&dst, 0xcc, sizeof(dst));
2095 ((FILETIME *)src)->dwLowDateTime = 0x12345678;
2096 ((FILETIME *)src)->dwHighDateTime = 0x9abcdef0;
2097 dst_len = 0x1234;
2098 hr = IDataConvert_DataConvert(convert, DBTYPE_FILETIME, DBTYPE_FILETIME, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2099 ok(hr == S_OK ||
2100 broken(hr == DB_E_BADBINDINFO), /* win98 */
2101 "got %08x\n", hr);
2102 if(SUCCEEDED(hr))
2104 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2105 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2106 ok(dst.dwLowDateTime == 0x12345678, "got %08x\n", dst.dwLowDateTime);
2107 ok(dst.dwHighDateTime == 0x9abcdef0, "got %08x\n", dst.dwHighDateTime);
2111 static void test_converttoui1(void)
2113 HRESULT hr;
2114 BYTE dst;
2115 BYTE src[20];
2116 DBSTATUS dst_status;
2117 DBLENGTH dst_len;
2119 dst = 0x12;
2120 dst_len = 0x1234;
2121 hr = IDataConvert_DataConvert(convert, DBTYPE_EMPTY, DBTYPE_UI1, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2122 ok(hr == S_OK, "got %08x\n", hr);
2123 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2124 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2125 ok(dst == 0, "got %08x\n", dst);
2127 dst = 0x12;
2128 dst_len = 0x1234;
2129 hr = IDataConvert_DataConvert(convert, DBTYPE_NULL, DBTYPE_UI1, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2130 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr);
2131 ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status);
2132 ok(dst_len == 0x1234, "got %ld\n", dst_len);
2133 ok(dst == 0x12, "got %08x\n", dst);
2135 dst = 0x12;
2136 src[0] = 0x43;
2137 dst_len = 0x1234;
2138 hr = IDataConvert_DataConvert(convert, DBTYPE_UI1, DBTYPE_UI1, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2139 ok(hr == S_OK, "got %08x\n", hr);
2140 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2141 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2142 ok(dst == 0x43, "got %08x\n", dst);
2144 dst = 0x12;
2145 src[0] = 0xfe;
2146 dst_len = 0x1234;
2147 hr = IDataConvert_DataConvert(convert, DBTYPE_UI1, DBTYPE_UI1, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2148 ok(hr == S_OK, "got %08x\n", hr);
2149 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2150 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2151 ok(dst == 0xfe, "got %08x\n", dst);
2154 static void test_converttoui4(void)
2156 HRESULT hr;
2157 DWORD dst;
2158 BYTE src[20];
2159 DBSTATUS dst_status;
2160 DBLENGTH dst_len;
2162 dst = 0x12345678;
2163 dst_len = 0x1234;
2164 hr = IDataConvert_DataConvert(convert, DBTYPE_EMPTY, DBTYPE_UI4, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2165 ok(hr == S_OK, "got %08x\n", hr);
2166 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2167 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2168 ok(dst == 0, "got %08x\n", dst);
2170 dst = 0x12345678;
2171 dst_len = 0x1234;
2172 hr = IDataConvert_DataConvert(convert, DBTYPE_NULL, DBTYPE_UI4, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2173 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr);
2174 ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status);
2175 ok(dst_len == 0x1234, "got %ld\n", dst_len);
2176 ok(dst == 0x12345678, "got %08x\n", dst);
2178 dst = 0x12345678;
2179 *(DWORD*)src = 0x87654321;
2180 dst_len = 0x1234;
2181 hr = IDataConvert_DataConvert(convert, DBTYPE_UI4, DBTYPE_UI4, 0, &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 == sizeof(dst), "got %ld\n", dst_len);
2185 ok(dst == 0x87654321, "got %08x\n", dst);
2187 dst = 0x12345678;
2188 *(signed short *)src = 0x4321;
2189 dst_len = 0x1234;
2190 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_UI4, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
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 == sizeof(dst), "got %ld\n", dst_len);
2194 ok(dst == 0x4321, "got %08x\n", dst);
2196 dst = 0x12345678;
2197 *(signed short *)src = -1;
2198 dst_len = 0x1234;
2199 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_UI4, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2200 ok(hr == DB_E_ERRORSOCCURRED, "got %08x\n", hr);
2201 todo_wine
2202 ok(dst_status == DBSTATUS_E_SIGNMISMATCH, "got %08x\n", dst_status);
2203 todo_wine
2204 ok(broken(dst_len == sizeof(dst)) || dst_len == 0x1234 /* W2K+ */, "got %ld\n", dst_len);
2205 ok(dst == 0x12345678, "got %08x\n", dst);
2207 dst_len = dst = 0x1234;
2208 V_VT((VARIANT*)src) = VT_I2;
2209 V_I2((VARIANT*)src) = 0x4321;
2210 hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_UI4, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2211 ok(hr == S_OK, "got %08x\n", hr);
2212 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2213 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2214 ok(dst == 0x4321, "got %08x\n", dst);
2217 static void test_converttor4(void)
2219 HRESULT hr;
2220 FLOAT dst;
2221 BYTE src[20];
2222 DBSTATUS dst_status;
2223 DBLENGTH dst_len;
2225 dst = 1.0;
2226 dst_len = 0x1234;
2227 hr = IDataConvert_DataConvert(convert, DBTYPE_EMPTY, DBTYPE_R4, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2228 ok(hr == S_OK, "got %08x\n", hr);
2229 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2230 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2231 ok(dst == 0.0, "got %f\n", dst);
2233 dst = 1.0;
2234 dst_len = 0x1234;
2235 hr = IDataConvert_DataConvert(convert, DBTYPE_NULL, DBTYPE_R4, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2236 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr);
2237 ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status);
2238 ok(dst_len == 0x1234, "got %ld\n", dst_len);
2239 ok(dst == 1.0, "got %f\n", dst);
2241 dst = 1.0;
2242 *(signed int*)src = 12345678;
2243 dst_len = 0x1234;
2244 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_R4, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2245 ok(hr == S_OK, "got %08x\n", hr);
2246 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2247 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2248 ok(dst == 12345678.0, "got %f\n", dst);
2250 dst = 1.0;
2251 *(FLOAT *)src = 10.0;
2252 dst_len = 0x1234;
2253 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_R4, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2254 ok(hr == S_OK, "got %08x\n", hr);
2255 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2256 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2257 ok(dst == 10.0, "got %f\n", dst);
2260 static void test_converttocy(void)
2262 HRESULT hr;
2263 CY dst;
2264 BYTE src[20];
2265 DBSTATUS dst_status;
2266 DBLENGTH dst_len;
2268 dst.int64 = 0xcc;
2269 dst_len = 0x1234;
2270 hr = IDataConvert_DataConvert(convert, DBTYPE_EMPTY, DBTYPE_CY, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2271 ok(hr == S_OK, "got %08x\n", hr);
2272 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2273 ok(dst_len == sizeof(CY), "got %ld\n", dst_len);
2274 ok(dst.int64 == 0, "didn't get 0\n");
2276 dst.int64 = 0xcc;
2277 dst_len = 0x1234;
2278 hr = IDataConvert_DataConvert(convert, DBTYPE_NULL, DBTYPE_CY, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2279 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr);
2280 ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status);
2281 ok(dst_len == 0x1234, "got %ld\n", dst_len);
2282 ok(dst.int64 == 0xcc, "dst changed\n");
2284 dst.int64 = 0xcc;
2285 *(int*)src = 1234;
2286 dst_len = 0x1234;
2287 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_CY, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2288 ok(hr == S_OK, "got %08x\n", hr);
2289 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2290 ok(dst_len == sizeof(CY), "got %ld\n", dst_len);
2291 ok(dst.int64 == 12340000, "got %d\n", dst.s.Lo);
2293 dst.int64 = 0xcc;
2294 ((CY*)src)->int64 = 1234;
2295 dst_len = 0x1234;
2296 hr = IDataConvert_DataConvert(convert, DBTYPE_CY, DBTYPE_CY, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2297 ok(hr == S_OK, "got %08x\n", hr);
2298 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2299 ok(dst_len == sizeof(CY), "got %ld\n", dst_len);
2300 ok(dst.int64 == 1234, "got %d\n", dst.s.Lo);
2303 static void test_converttoui8(void)
2305 HRESULT hr;
2306 ULARGE_INTEGER dst;
2307 BYTE src[20];
2308 DBSTATUS dst_status;
2309 DBLENGTH dst_len;
2311 dst.QuadPart = 0xcc;
2312 dst_len = 0x1234;
2313 hr = IDataConvert_DataConvert(convert, DBTYPE_EMPTY, DBTYPE_UI8, 0, &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 == sizeof(dst), "got %ld\n", dst_len);
2317 ok(dst.QuadPart == 0, "got %d\n", (int)dst.QuadPart);
2319 dst.QuadPart = 0xcc;
2320 dst_len = 0x1234;
2321 hr = IDataConvert_DataConvert(convert, DBTYPE_NULL, DBTYPE_UI8, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2322 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr);
2323 ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status);
2324 ok(dst_len == 0x1234, "got %ld\n", dst_len);
2325 ok(dst.QuadPart == 0xcc, "dst changed\n");
2327 dst.QuadPart = 0xcc;
2328 *(int*)src = 1234;
2329 dst_len = 0x1234;
2330 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_UI8, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2331 ok(hr == S_OK, "got %08x\n", hr);
2332 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2333 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2334 ok(dst.QuadPart == 1234, "got %d\n", (int)dst.QuadPart);
2336 dst.QuadPart = 0xcc;
2337 *(int*)src = -1234;
2338 dst_len = 0x1234;
2339 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_UI8, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2340 ok(hr == DB_E_ERRORSOCCURRED, "got %08x\n", hr);
2341 todo_wine
2342 ok(dst_status == DBSTATUS_E_SIGNMISMATCH, "got %08x\n", dst_status);
2343 todo_wine
2344 ok(dst_len == 0x1234, "got %ld\n", dst_len);
2345 ok(dst.QuadPart == 0xcc, "got %d\n", (int)dst.QuadPart);
2347 dst.QuadPart = 0xcc;
2348 ((ULARGE_INTEGER*)src)->QuadPart = 1234;
2349 dst_len = 0x1234;
2350 hr = IDataConvert_DataConvert(convert, DBTYPE_UI8, DBTYPE_UI8, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2351 ok(hr == S_OK, "got %08x\n", hr);
2352 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2353 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2354 ok(dst.QuadPart == 1234, "got %d\n", (int)dst.QuadPart);
2357 static void test_getconversionsize(void)
2359 DBLENGTH dst_len;
2360 DBLENGTH src_len;
2361 HRESULT hr;
2362 BSTR str;
2363 static WCHAR strW[] = {'t','e','s','t',0};
2364 static char strTest[] = "test";
2365 VARIANT var;
2367 /* same way as CanConvert fails here */
2368 dst_len = 0;
2369 hr = IDataConvert_GetConversionSize(convert, DBTYPE_NULL, DBTYPE_BSTR, NULL, &dst_len, NULL);
2370 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got 0x%08x\n", hr);
2372 dst_len = 0;
2373 hr = IDataConvert_GetConversionSize(convert, DBTYPE_I2, DBTYPE_I4, NULL, &dst_len, NULL);
2374 ok(hr == S_OK, "got 0x%08x\n", hr);
2375 ok(dst_len == 4, "got %ld\n", dst_len);
2377 hr = IDataConvert_GetConversionSize(convert, DBTYPE_I2, DBTYPE_I4, NULL, NULL, NULL);
2378 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
2380 /* size doesn't include string size */
2381 str = SysAllocStringLen(NULL, 10);
2382 dst_len = 0;
2383 hr = IDataConvert_GetConversionSize(convert, DBTYPE_BSTR, DBTYPE_VARIANT, NULL, &dst_len, str);
2384 ok(hr == S_OK, "got 0x%08x\n", hr);
2385 ok(dst_len == sizeof(VARIANT), "%ld\n", dst_len);
2386 SysFreeString(str);
2388 dst_len = 0;
2389 hr = IDataConvert_GetConversionSize(convert, DBTYPE_WSTR, DBTYPE_WSTR, NULL, &dst_len, strW);
2390 ok(hr == S_OK, "got 0x%08x\n", hr);
2391 ok(dst_len == 10, "%ld\n", dst_len);
2393 dst_len = 0;
2394 src_len = 2;
2395 hr = IDataConvert_GetConversionSize(convert, DBTYPE_WSTR, DBTYPE_WSTR, &src_len, &dst_len, strW);
2396 ok(hr == S_OK, "got 0x%08x\n", hr);
2397 ok(dst_len == 4, "%ld\n", dst_len);
2399 dst_len = 0;
2400 src_len = 20;
2401 hr = IDataConvert_GetConversionSize(convert, DBTYPE_WSTR, DBTYPE_WSTR, &src_len, &dst_len, strW);
2402 ok(hr == S_OK, "got 0x%08x\n", hr);
2403 ok(dst_len == 22, "%ld\n", dst_len);
2405 dst_len = 0;
2406 hr = IDataConvert_GetConversionSize(convert, DBTYPE_STR, DBTYPE_WSTR, NULL, &dst_len, strTest);
2407 ok(hr == S_OK, "got 0x%08x\n", hr);
2408 ok(dst_len == 10 || broken(dst_len == 12), "%ld\n", dst_len);
2410 dst_len = 0;
2411 src_len = 2;
2412 hr = IDataConvert_GetConversionSize(convert, DBTYPE_STR, DBTYPE_WSTR, &src_len, &dst_len, strTest);
2413 ok(hr == S_OK, "got 0x%08x\n", hr);
2414 ok(dst_len == 6, "%ld\n", dst_len);
2416 dst_len = 0;
2417 src_len = 20;
2418 hr = IDataConvert_GetConversionSize(convert, DBTYPE_STR, DBTYPE_WSTR, &src_len, &dst_len, strTest);
2419 ok(hr == S_OK, "got 0x%08x\n", hr);
2420 ok(dst_len == 42, "%ld\n", dst_len);
2422 dst_len = 0;
2423 V_VT(&var) = VT_BSTR;
2424 V_BSTR(&var) = SysAllocString(strW);
2425 hr = IDataConvert_GetConversionSize(convert, DBTYPE_VARIANT, DBTYPE_WSTR, NULL, &dst_len, &var);
2426 ok(hr == S_OK, "got 0x%08x\n", hr);
2427 ok(dst_len == 10, "%ld\n", dst_len);
2428 VariantClear(&var);
2430 dst_len = 0;
2431 src_len = 20;
2432 V_VT(&var) = VT_BSTR;
2433 V_BSTR(&var) = SysAllocString(strW);
2434 hr = IDataConvert_GetConversionSize(convert, DBTYPE_VARIANT, DBTYPE_WSTR, &src_len, &dst_len, &var);
2435 ok(hr == S_OK, "got 0x%08x\n", hr);
2436 ok(dst_len == 10, "%ld\n", dst_len);
2437 VariantClear(&var);
2439 dst_len = 0;
2440 src_len = 20;
2441 V_VT(&var) = VT_I4;
2442 V_I4(&var) = 4;
2443 hr = IDataConvert_GetConversionSize(convert, DBTYPE_VARIANT, DBTYPE_WSTR, &src_len, &dst_len, &var);
2444 ok(hr == S_OK, "got 0x%08x\n", hr);
2445 todo_wine ok(dst_len == 110, "%ld\n", dst_len);
2446 VariantClear(&var);
2450 static void test_converttobytes(void)
2452 DBLENGTH dst_len;
2453 HRESULT hr;
2454 BYTE byte_src[] = {0, 1, 2, 4, 5};
2455 BYTE dst[10] = {0};
2456 DBSTATUS dst_status;
2458 dst_len = 0;
2459 hr = IDataConvert_DataConvert(convert, DBTYPE_BYTES, DBTYPE_BYTES, sizeof(byte_src), &dst_len, byte_src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2460 ok(hr == S_OK, "got %08x\n", hr);
2461 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2462 ok(dst_len == sizeof(byte_src), "got %ld\n", dst_len);
2463 ok(!memcmp(byte_src, dst, dst_len ), "bytes differ\n");
2465 dst_len = 0;
2466 hr = IDataConvert_DataConvert(convert, DBTYPE_BYTES, DBTYPE_BYTES, sizeof(byte_src), &dst_len, byte_src, &dst, 2, 0, &dst_status, 0, 0, 0);
2467 ok(hr == S_OK, "got %08x\n", hr);
2468 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
2469 ok(dst_len == sizeof(byte_src), "got %ld\n", dst_len);
2470 ok(!memcmp(byte_src, dst, 2 ), "bytes differ\n");
2473 static void test_converttobytesbyref(void)
2475 DBLENGTH dst_len;
2476 HRESULT hr;
2477 BYTE byte_src[] = {0, 1, 2, 4, 5};
2478 BYTE *dst;
2479 DBSTATUS dst_status;
2481 dst_len = 0;
2482 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);
2483 ok(hr == S_OK, "got %08x\n", hr);
2484 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2485 ok(dst_len == sizeof(byte_src), "got %ld\n", dst_len);
2486 ok(!memcmp(byte_src, dst, dst_len ), "bytes differ\n");
2487 CoTaskMemFree(dst);
2490 static void test_converttodbdate(void)
2492 DBLENGTH dst_len;
2493 HRESULT hr;
2494 static WCHAR strW[] = {'2','0','1','3','-','0','5','-','1','4',0};
2495 DBDATE ts = {2013, 5, 14};
2496 DBDATE dst;
2497 DBSTATUS dst_status;
2498 VARIANT var;
2499 BSTR bstr;
2501 dst_len = 0;
2502 hr = IDataConvert_DataConvert(convert, DBTYPE_DBDATE, DBTYPE_DBDATE, sizeof(ts), &dst_len, &ts, &dst, 2, 0, &dst_status, 0, 0, 0);
2503 ok(hr == S_OK, "got %08x\n", hr);
2504 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2505 ok(dst_len == sizeof(DBDATE), "got %ld\n", dst_len);
2506 ok(!memcmp(&ts, &dst, sizeof(DBDATE) ), "bytes differ\n");
2508 VariantInit(&var);
2509 V_VT(&var) = VT_DATE;
2510 V_DATE(&var) = 41408.086250;
2511 dst_len = 0;
2512 hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_DBDATE, sizeof(var), &dst_len, &var, &dst, 2, 0, &dst_status, 0, 0, 0);
2513 ok(hr == S_OK, "got %08x\n", hr);
2514 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2515 ok(dst_len == sizeof(DBDATE), "got %ld\n", dst_len);
2516 ok(!memcmp(&ts, &dst, sizeof(DBDATE) ), "bytes differ\n");
2518 dst_len = 0;
2519 bstr = SysAllocString(strW);
2520 hr = IDataConvert_DataConvert(convert, DBTYPE_BSTR, DBTYPE_DBDATE, 0, &dst_len, &bstr, &dst, 2, 0, &dst_status, 0, 0, 0);
2521 ok(hr == S_OK, "got %08x\n", hr);
2522 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2523 ok(dst_len == sizeof(DBDATE), "got %ld\n", dst_len);
2524 ok(!memcmp(&ts, &dst, sizeof(DBDATE) ), "bytes differ\n");
2525 SysFreeString(bstr);
2529 static void test_converttovar(void)
2531 static WCHAR strW[] = {'t','e','s','t',0};
2532 BYTE byte_src[5] = {1, 2, 3, 4, 5};
2533 DBTIMESTAMP ts = {2013, 5, 14, 2, 4, 12, 0};
2534 DBDATE dbdate = {2013, 5, 15};
2535 double dvalue = 123.56;
2536 DBSTATUS dst_status;
2537 DBLENGTH dst_len;
2538 VARIANT dst;
2539 HRESULT hr;
2540 CY cy, cy2;
2541 DATE date;
2542 INT i4;
2543 LARGE_INTEGER i8;
2544 VARIANT_BOOL boolean = VARIANT_TRUE;
2546 V_VT(&dst) = VT_EMPTY;
2547 dst_len = 0;
2548 dst_status = DBSTATUS_S_DEFAULT;
2549 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_VARIANT, sizeof(strW), &dst_len, strW, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2550 ok(hr == S_OK, "got %08x\n", hr);
2551 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2552 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2553 ok(V_VT(&dst) == VT_BSTR, "got %d\n", V_VT(&dst));
2554 ok(!lstrcmpW(V_BSTR(&dst), strW), "got %s\n", wine_dbgstr_w(V_BSTR(&dst)));
2555 VariantClear(&dst);
2557 /* with null dest length and status */
2558 V_VT(&dst) = VT_EMPTY;
2559 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_VARIANT, sizeof(strW), NULL, strW, &dst, sizeof(dst), 0, NULL, 0, 0, 0);
2560 ok(hr == S_OK, "got %08x\n", hr);
2561 ok(V_VT(&dst) == VT_BSTR, "got %d\n", V_VT(&dst));
2562 ok(!lstrcmpW(V_BSTR(&dst), strW), "got %s\n", wine_dbgstr_w(V_BSTR(&dst)));
2563 VariantClear(&dst);
2565 V_VT(&dst) = VT_EMPTY;
2566 dst_len = 0;
2567 dst_status = DBSTATUS_S_DEFAULT;
2568 i8.QuadPart = 12345;
2569 dst_len = 0x1234;
2570 hr = IDataConvert_DataConvert(convert, DBTYPE_I8, DBTYPE_VARIANT, sizeof(i8), &dst_len, &i8, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2571 ok(hr == S_OK, "got %08x\n", hr);
2572 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2573 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2574 ok(V_VT(&dst) == VT_DECIMAL, "got %d\n", V_VT(&dst));
2575 ok(S(U(V_DECIMAL(&dst))).scale == 0 && S(U(V_DECIMAL(&dst))).sign == 0 &&
2576 V_DECIMAL(&dst).Hi32 == 0 && U1(V_DECIMAL(&dst)).Lo64 == 12345, "Not Equal\n");
2578 V_VT(&dst) = VT_EMPTY;
2579 dst_len = 0;
2580 dst_status = DBSTATUS_S_DEFAULT;
2581 hr = IDataConvert_DataConvert(convert, DBTYPE_R8, DBTYPE_VARIANT, sizeof(dvalue), &dst_len, &dvalue, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2582 ok(hr == S_OK, "got %08x\n", hr);
2583 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2584 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2585 ok(V_VT(&dst) == VT_R8, "got %d\n", V_VT(&dst));
2586 ok(V_R8(&dst) == 123.56, "got %f\n", V_R8(&dst));
2588 V_VT(&dst) = VT_EMPTY;
2589 dst_len = 0;
2590 dst_status = DBSTATUS_S_DEFAULT;
2591 hr = IDataConvert_DataConvert(convert, DBTYPE_BOOL, DBTYPE_VARIANT, sizeof(boolean), &dst_len, &boolean, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2592 ok(hr == S_OK, "got %08x\n", hr);
2593 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2594 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2595 ok(V_VT(&dst) == VT_BOOL, "got %d\n", V_VT(&dst));
2596 ok(V_BOOL(&dst) == VARIANT_TRUE, "got %d\n", V_BOOL(&dst));
2598 V_VT(&dst) = VT_EMPTY;
2599 dst_len = 0;
2600 dst_status = DBSTATUS_S_DEFAULT;
2601 i4 = 123;
2602 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_VARIANT, sizeof(i4), &dst_len, &i4, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2603 ok(hr == S_OK, "got %08x\n", hr);
2604 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2605 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2606 ok(V_VT(&dst) == VT_I4, "got %d\n", V_VT(&dst));
2607 ok(V_I4(&dst) == 123, "got %d\n", V_I4(&dst));
2609 V_VT(&dst) = VT_EMPTY;
2610 dst_len = 0;
2611 dst_status = DBSTATUS_S_DEFAULT;
2612 date = 123.123;
2613 hr = IDataConvert_DataConvert(convert, DBTYPE_DATE, DBTYPE_VARIANT, sizeof(date), &dst_len, &date, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2614 ok(hr == S_OK, "got %08x\n", hr);
2615 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2616 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2617 ok(V_VT(&dst) == VT_DATE, "got %d\n", V_VT(&dst));
2618 ok(V_DATE(&dst) == 123.123, "got %f\n", V_DATE(&dst));
2620 V_VT(&dst) = VT_EMPTY;
2621 dst_len = 0;
2622 dst_status = DBSTATUS_S_DEFAULT;
2623 S(cy).Lo = 1;
2624 S(cy).Hi = 2;
2625 hr = IDataConvert_DataConvert(convert, DBTYPE_CY, DBTYPE_VARIANT, sizeof(cy), &dst_len, &cy, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2626 ok(hr == S_OK, "got %08x\n", hr);
2627 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2628 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2629 ok(V_VT(&dst) == VT_CY, "got %d\n", V_VT(&dst));
2631 cy2 = V_CY(&dst);
2632 ok(S(cy2).Lo == S(cy).Lo && S(cy2).Hi == S(cy).Hi, "got %d,%d\n", S(cy2).Lo, S(cy2).Hi);
2634 dst_len = 0x1234;
2635 hr = IDataConvert_DataConvert(convert, DBTYPE_BYTES, DBTYPE_VARIANT, 0, &dst_len, &byte_src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2636 ok(hr == S_OK, "got %08x\n", hr);
2637 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2638 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2639 ok(V_VT(&dst) == (VT_ARRAY|VT_UI1), "got %d\n", V_VT(&dst));
2640 VariantClear(&dst);
2642 dst_len = 0x1234;
2643 hr = IDataConvert_DataConvert(convert, DBTYPE_DBTIMESTAMP, DBTYPE_VARIANT, 0, &dst_len, &ts, &dst, sizeof(ts), 0, &dst_status, 0, 0, 0);
2644 ok(hr == S_OK, "got %08x\n", hr);
2645 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2646 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2647 ok(V_VT(&dst) == VT_DATE, "got %d\n", V_VT(&dst));
2648 ok( (float)V_DATE(&dst) == 41408.086250f, "got %f\n", V_DATE(&dst));
2650 dst_len = 0x1234;
2651 hr = IDataConvert_DataConvert(convert, DBTYPE_DBDATE, DBTYPE_VARIANT, 0, &dst_len, &dbdate, &dst, sizeof(dbdate), 0, &dst_status, 0, 0, 0);
2652 ok(hr == S_OK, "got %08x\n", hr);
2653 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2654 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2655 ok(V_VT(&dst) == VT_DATE, "got %d\n", V_VT(&dst));
2656 ok( (float)V_DATE(&dst) == 41409.0, "got %f\n", V_DATE(&dst));
2658 /* src_status = DBSTATUS_S_ISNULL */
2659 i4 = 123;
2660 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_VARIANT, sizeof(i4), &dst_len, &i4, &dst, sizeof(dst), DBSTATUS_S_ISNULL, &dst_status, 0, 0, 0);
2661 ok(hr == S_OK, "got %08x\n", hr);
2662 ok(dst_status == DBSTATUS_S_ISNULL, "got %08x\n", dst_status);
2663 ok(dst_len == 0, "got %ld\n", dst_len);
2667 static void test_converttotimestamp(void)
2669 DBTIMESTAMP ts = {2013, 5, 14, 2, 4, 12, 0};
2670 DBTIMESTAMP dst;
2671 DBSTATUS dst_status;
2672 DBLENGTH dst_len;
2673 VARIANT var;
2674 HRESULT hr;
2676 VariantInit(&var);
2677 V_VT(&var) = VT_DATE;
2678 V_DATE(&var) = 41408.086250;
2679 dst_len = 0x1234;
2680 hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_DBTIMESTAMP, 0, &dst_len, &var, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2681 ok(hr == S_OK, "got %08x\n", hr);
2682 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2683 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2684 ok(!memcmp(&ts, &dst, sizeof(ts)), "Wrong timestamp\n");
2687 START_TEST(convert)
2689 HRESULT hr;
2691 OleInitialize(NULL);
2693 test_dcinfo();
2695 hr = CoCreateInstance(&CLSID_OLEDB_CONVERSIONLIBRARY, NULL, CLSCTX_INPROC_SERVER, &IID_IDataConvert, (void**)&convert);
2696 if(FAILED(hr))
2698 win_skip("Unable to create IDataConvert instance, 0x%08x\n", hr);
2699 OleUninitialize();
2700 return;
2703 test_canconvert();
2704 test_converttoi2();
2705 test_converttoi4();
2706 test_converttoi8();
2707 test_converttostr();
2708 test_converttobstr();
2709 test_converttowstr();
2710 test_converttobyrefwstr();
2711 test_converttoguid();
2712 test_converttoui1();
2713 test_converttoui4();
2714 test_converttor4();
2715 test_converttofiletime();
2716 test_converttocy();
2717 test_converttoui8();
2718 test_converttovar();
2719 test_converttobytes();
2720 test_converttobytesbyref();
2721 test_converttodbdate();
2722 test_getconversionsize();
2723 test_converttotimestamp();
2725 IDataConvert_Release(convert);
2727 OleUninitialize();