Release 1.6-rc2.
[wine/testsucceed.git] / dlls / oledb32 / tests / convert.c
blob5c6694fd3f3a031ab9fc6e669b9394388b69939a
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;
1020 VARIANT v;
1022 memset(dst, 0xcc, sizeof(dst));
1023 dst_len = 0x1234;
1024 hr = IDataConvert_DataConvert(convert, DBTYPE_EMPTY, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1025 ok(hr == S_OK, "got %08x\n", hr);
1026 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1027 ok(dst_len == 0, "got %ld\n", dst_len);
1028 ok(dst[0] == 0, "got %02x\n", dst[0]);
1029 ok(dst[1] == 0xcccc, "got %02x\n", dst[1]);
1031 memset(dst, 0xcc, sizeof(dst));
1032 dst_len = 0x1234;
1033 hr = IDataConvert_DataConvert(convert, DBTYPE_NULL, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1034 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr);
1035 ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status);
1036 ok(dst_len == 0x1234, "got %ld\n", dst_len);
1037 ok(dst[0] == 0xcccc, "got %02x\n", dst[0]);
1039 *(short *)src = 4321;
1040 dst_len = 0x1234;
1041 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1042 ok(hr == S_OK, "got %08x\n", hr);
1043 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1044 ok(dst_len == 8, "got %ld\n", dst_len);
1045 ok(!lstrcmpW(dst, fourthreetwoone), "got %s\n", wine_dbgstr_w(dst));
1047 *(short *)src = 4321;
1048 memset(dst, 0xcc, sizeof(dst));
1049 dst_len = 0x1234;
1050 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_WSTR, 0, &dst_len, src, dst, 0, 0, &dst_status, 0, 0, 0);
1051 ok(hr == DB_E_ERRORSOCCURRED, "got %08x\n", hr);
1052 ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
1053 ok(dst_len == 8, "got %ld\n", dst_len);
1054 ok(dst[0] == 0xcccc, "got %02x\n", dst[0]);
1056 *(short *)src = 4321;
1057 memset(dst, 0xcc, sizeof(dst));
1058 dst_len = 0x1234;
1059 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_WSTR, 0, &dst_len, src, NULL, 0, 0, &dst_status, 0, 0, 0);
1060 ok(hr == S_OK, "got %08x\n", hr);
1061 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1062 ok(dst_len == 8, "got %ld\n", dst_len);
1063 ok(dst[0] == 0xcccc, "got %02x\n", dst[0]);
1065 *(short *)src = 4321;
1066 memset(dst, 0xcc, sizeof(dst));
1067 dst_len = 0x1234;
1068 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_WSTR, 0, &dst_len, src, dst, 4, 0, &dst_status, 0, 0, 0);
1069 ok(hr == S_OK, "got %08x\n", hr);
1070 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1071 ok(dst_len == 8, "got %ld\n", dst_len);
1072 ok(dst[0] == '4', "got %02x\n", dst[0]);
1073 ok(dst[1] == 0, "got %02x\n", dst[1]);
1074 ok(dst[2] == 0xcccc, "got %02x\n", dst[2]);
1076 *(short *)src = 4321;
1077 memset(dst, 0xcc, sizeof(dst));
1078 dst_len = 0x1234;
1079 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_WSTR, 0, &dst_len, src, dst, 2, 0, &dst_status, 0, 0, 0);
1080 ok(hr == S_OK, "got %08x\n", hr);
1081 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1082 ok(dst_len == 8, "got %ld\n", dst_len);
1083 ok(dst[0] == 0, "got %02x\n", dst[0]);
1084 ok(dst[1] == 0xcccc, "got %02x\n", dst[1]);
1086 *(short *)src = 4321;
1087 memset(dst, 0xcc, sizeof(dst));
1088 dst_len = 0x1234;
1089 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_WSTR, 0, &dst_len, src, dst, 8, 0, &dst_status, 0, 0, 0);
1090 ok(hr == S_OK, "got %08x\n", hr);
1091 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1092 ok(dst_len == 8, "got %ld\n", dst_len);
1093 ok(dst[0] == '4', "got %02x\n", dst[0]);
1094 ok(dst[1] == '3', "got %02x\n", dst[1]);
1095 ok(dst[2] == '2', "got %02x\n", dst[2]);
1096 ok(dst[3] == 0, "got %02x\n", dst[3]);
1097 ok(dst[4] == 0xcccc, "got %02x\n", dst[4]);
1101 *(int *)src = 4321;
1102 dst_len = 0x1234;
1103 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1104 ok(hr == S_OK, "got %08x\n", hr);
1105 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1106 ok(dst_len == 8, "got %ld\n", dst_len);
1107 ok(!lstrcmpW(dst, fourthreetwoone), "got %s\n", wine_dbgstr_w(dst));
1109 *(int *)src = 4321;
1110 memset(dst, 0xcc, sizeof(dst));
1111 dst_len = 0x1234;
1112 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_WSTR, 0, &dst_len, src, dst, 0, 0, &dst_status, 0, 0, 0);
1113 ok(hr == DB_E_ERRORSOCCURRED, "got %08x\n", hr);
1114 ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
1115 ok(dst_len == 8, "got %ld\n", dst_len);
1116 ok(dst[0] == 0xcccc, "got %02x\n", dst[0]);
1118 *(int *)src = 4321;
1119 memset(dst, 0xcc, sizeof(dst));
1120 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_WSTR, 0, &dst_len, src, NULL, 0, 0, &dst_status, 0, 0, 0);
1121 ok(hr == S_OK, "got %08x\n", hr);
1122 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1123 ok(dst_len == 8, "got %ld\n", dst_len);
1124 ok(dst[0] == 0xcccc, "got %02x\n", dst[0]);
1126 *(int *)src = 4321;
1127 memset(dst, 0xcc, sizeof(dst));
1128 dst_len = 0x1234;
1129 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_WSTR, 0, &dst_len, src, dst, 4, 0, &dst_status, 0, 0, 0);
1130 ok(hr == S_OK, "got %08x\n", hr);
1131 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1132 ok(dst_len == 8, "got %ld\n", dst_len);
1133 ok(dst[0] == '4', "got %02x\n", dst[0]);
1134 ok(dst[1] == 0, "got %02x\n", dst[1]);
1135 ok(dst[2] == 0xcccc, "got %02x\n", dst[2]);
1137 *(int *)src = 4321;
1138 memset(dst, 0xcc, sizeof(dst));
1139 dst_len = 0x1234;
1140 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_WSTR, 0, &dst_len, src, dst, 2, 0, &dst_status, 0, 0, 0);
1141 ok(hr == S_OK, "got %08x\n", hr);
1142 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1143 ok(dst_len == 8, "got %ld\n", dst_len);
1144 ok(dst[0] == 0, "got %02x\n", dst[0]);
1145 ok(dst[1] == 0xcccc, "got %02x\n", dst[1]);
1147 *(int *)src = 4321;
1148 memset(dst, 0xcc, sizeof(dst));
1149 dst_len = 0x1234;
1150 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_WSTR, 0, &dst_len, src, dst, 8, 0, &dst_status, 0, 0, 0);
1151 ok(hr == S_OK, "got %08x\n", hr);
1152 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1153 ok(dst_len == 8, "got %ld\n", dst_len);
1154 ok(dst[0] == '4', "got %02x\n", dst[0]);
1155 ok(dst[1] == '3', "got %02x\n", dst[1]);
1156 ok(dst[2] == '2', "got %02x\n", dst[2]);
1157 ok(dst[3] == 0, "got %02x\n", dst[3]);
1158 ok(dst[4] == 0xcccc, "got %02x\n", dst[4]);
1162 *(float *)src = 4321;
1163 dst_len = 0x1234;
1164 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1165 ok(hr == S_OK, "got %08x\n", hr);
1166 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1167 ok(dst_len == 8, "got %ld\n", dst_len);
1168 ok(!lstrcmpW(dst, fourthreetwoone), "got %s\n", wine_dbgstr_w(dst));
1170 *(float *)src = 4321;
1171 memset(dst, 0xcc, sizeof(dst));
1172 dst_len = 0x1234;
1173 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_WSTR, 0, &dst_len, src, dst, 0, 0, &dst_status, 0, 0, 0);
1174 ok(hr == DB_E_ERRORSOCCURRED, "got %08x\n", hr);
1175 ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
1176 ok(dst_len == 8, "got %ld\n", dst_len);
1177 ok(dst[0] == 0xcccc, "got %02x\n", dst[0]);
1179 *(float *)src = 4321;
1180 memset(dst, 0xcc, sizeof(dst));
1181 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_WSTR, 0, &dst_len, src, NULL, 0, 0, &dst_status, 0, 0, 0);
1182 ok(hr == S_OK, "got %08x\n", hr);
1183 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1184 ok(dst_len == 8, "got %ld\n", dst_len);
1185 ok(dst[0] == 0xcccc, "got %02x\n", dst[0]);
1187 *(float *)src = 4321;
1188 memset(dst, 0xcc, sizeof(dst));
1189 dst_len = 0x1234;
1190 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_WSTR, 0, &dst_len, src, dst, 4, 0, &dst_status, 0, 0, 0);
1191 ok(hr == S_OK, "got %08x\n", hr);
1192 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1193 ok(dst_len == 8, "got %ld\n", dst_len);
1194 ok(dst[0] == '4', "got %02x\n", dst[0]);
1195 ok(dst[1] == 0, "got %02x\n", dst[1]);
1196 ok(dst[2] == 0xcccc, "got %02x\n", dst[2]);
1198 *(float *)src = 4321;
1199 memset(dst, 0xcc, sizeof(dst));
1200 dst_len = 0x1234;
1201 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_WSTR, 0, &dst_len, src, dst, 2, 0, &dst_status, 0, 0, 0);
1202 ok(hr == S_OK, "got %08x\n", hr);
1203 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1204 ok(dst_len == 8, "got %ld\n", dst_len);
1205 ok(dst[0] == 0, "got %02x\n", dst[0]);
1206 ok(dst[1] == 0xcccc, "got %02x\n", dst[1]);
1208 *(float *)src = 4321;
1209 memset(dst, 0xcc, sizeof(dst));
1210 dst_len = 0x1234;
1211 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_WSTR, 0, &dst_len, src, dst, 8, 0, &dst_status, 0, 0, 0);
1212 ok(hr == S_OK, "got %08x\n", hr);
1213 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1214 ok(dst_len == 8, "got %ld\n", dst_len);
1215 ok(dst[0] == '4', "got %02x\n", dst[0]);
1216 ok(dst[1] == '3', "got %02x\n", dst[1]);
1217 ok(dst[2] == '2', "got %02x\n", dst[2]);
1218 ok(dst[3] == 0, "got %02x\n", dst[3]);
1219 ok(dst[4] == 0xcccc, "got %02x\n", dst[4]);
1223 *(double *)src = 4321;
1224 dst_len = 0x1234;
1225 hr = IDataConvert_DataConvert(convert, DBTYPE_R8, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1226 ok(hr == S_OK, "got %08x\n", hr);
1227 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1228 ok(dst_len == 8, "got %ld\n", dst_len);
1229 ok(!lstrcmpW(dst, fourthreetwoone), "got %s\n", wine_dbgstr_w(dst));
1231 *(double *)src = 4321;
1232 memset(dst, 0xcc, sizeof(dst));
1233 hr = IDataConvert_DataConvert(convert, DBTYPE_R8, DBTYPE_WSTR, 0, &dst_len, src, dst, 0, 0, &dst_status, 0, 0, 0);
1234 ok(hr == DB_E_ERRORSOCCURRED, "got %08x\n", hr);
1235 ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
1236 ok(dst_len == 8, "got %ld\n", dst_len);
1237 ok(dst[0] == 0xcccc, "got %02x\n", dst[0]);
1239 *(double *)src = 4321;
1240 memset(dst, 0xcc, sizeof(dst));
1241 dst_len = 0x1234;
1242 hr = IDataConvert_DataConvert(convert, DBTYPE_R8, DBTYPE_WSTR, 0, &dst_len, src, NULL, 0, 0, &dst_status, 0, 0, 0);
1243 ok(hr == S_OK, "got %08x\n", hr);
1244 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1245 ok(dst_len == 8, "got %ld\n", dst_len);
1246 ok(dst[0] == 0xcccc, "got %02x\n", dst[0]);
1248 *(double *)src = 4321;
1249 memset(dst, 0xcc, sizeof(dst));
1250 dst_len = 0x1234;
1251 hr = IDataConvert_DataConvert(convert, DBTYPE_R8, DBTYPE_WSTR, 0, &dst_len, src, dst, 4, 0, &dst_status, 0, 0, 0);
1252 ok(hr == S_OK, "got %08x\n", hr);
1253 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1254 ok(dst_len == 8, "got %ld\n", dst_len);
1255 ok(dst[0] == '4', "got %02x\n", dst[0]);
1256 ok(dst[1] == 0, "got %02x\n", dst[1]);
1257 ok(dst[2] == 0xcccc, "got %02x\n", dst[2]);
1259 *(double *)src = 4321;
1260 memset(dst, 0xcc, sizeof(dst));
1261 dst_len = 0x1234;
1262 hr = IDataConvert_DataConvert(convert, DBTYPE_R8, DBTYPE_WSTR, 0, &dst_len, src, dst, 2, 0, &dst_status, 0, 0, 0);
1263 ok(hr == S_OK, "got %08x\n", hr);
1264 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1265 ok(dst_len == 8, "got %ld\n", dst_len);
1266 ok(dst[0] == 0, "got %02x\n", dst[0]);
1267 ok(dst[1] == 0xcccc, "got %02x\n", dst[1]);
1269 *(double *)src = 4321;
1270 memset(dst, 0xcc, sizeof(dst));
1271 dst_len = 0x1234;
1272 hr = IDataConvert_DataConvert(convert, DBTYPE_R8, DBTYPE_WSTR, 0, &dst_len, src, dst, 8, 0, &dst_status, 0, 0, 0);
1273 ok(hr == S_OK, "got %08x\n", hr);
1274 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1275 ok(dst_len == 8, "got %ld\n", dst_len);
1276 ok(dst[0] == '4', "got %02x\n", dst[0]);
1277 ok(dst[1] == '3', "got %02x\n", dst[1]);
1278 ok(dst[2] == '2', "got %02x\n", dst[2]);
1279 ok(dst[3] == 0, "got %02x\n", dst[3]);
1280 ok(dst[4] == 0xcccc, "got %02x\n", dst[4]);
1284 memset(src, 0, sizeof(src));
1285 ((CY*)src)->int64 = 43210000;
1286 memset(dst, 0xcc, sizeof(dst));
1287 dst_len = 0x1234;
1288 hr = IDataConvert_DataConvert(convert, DBTYPE_CY, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1289 ok(hr == S_OK, "got %08x\n", hr);
1290 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1291 ok(dst_len == 8, "got %ld\n", dst_len);
1292 ok(!lstrcmpW(dst, fourthreetwoone), "got %s\n", wine_dbgstr_w(dst));
1296 memset(src, 0, sizeof(src));
1297 *(signed char *)src = 10;
1298 dst_len = 0x1234;
1299 hr = IDataConvert_DataConvert(convert, DBTYPE_I1, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1300 ok(hr == S_OK, "got %08x\n", hr);
1301 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1302 ok(dst_len == 4, "got %ld\n", dst_len);
1303 ok(!lstrcmpW(dst, ten), "got %s\n", wine_dbgstr_w(dst));
1305 memset(src, 0, sizeof(src));
1306 *(unsigned char *)src = 10;
1307 dst_len = 0x1234;
1308 hr = IDataConvert_DataConvert(convert, DBTYPE_UI1, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1309 ok(hr == S_OK, "got %08x\n", hr);
1310 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1311 ok(dst_len == 4, "got %ld\n", dst_len);
1312 ok(!lstrcmpW(dst, ten), "got %s\n", wine_dbgstr_w(dst));
1314 memset(src, 0, sizeof(src));
1315 *(unsigned short *)src = 4321;
1316 dst_len = 0x1234;
1317 hr = IDataConvert_DataConvert(convert, DBTYPE_UI2, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1318 ok(hr == S_OK, "got %08x\n", hr);
1319 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1320 ok(dst_len == 8, "got %ld\n", dst_len);
1321 ok(!lstrcmpW(dst, fourthreetwoone), "got %s\n", wine_dbgstr_w(dst));
1323 memset(src, 0, sizeof(src));
1324 *(unsigned int *)src = 4321;
1325 dst_len = 0x1234;
1326 hr = IDataConvert_DataConvert(convert, DBTYPE_UI4, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1327 ok(hr == S_OK, "got %08x\n", hr);
1328 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1329 ok(dst_len == 8, "got %ld\n", dst_len);
1330 ok(!lstrcmpW(dst, fourthreetwoone), "got %s\n", wine_dbgstr_w(dst));
1332 memset(src, 0, sizeof(src));
1333 ((LARGE_INTEGER*)src)->QuadPart = 4321;
1334 dst_len = 0x1234;
1335 hr = IDataConvert_DataConvert(convert, DBTYPE_I8, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1336 ok(broken(DB_E_UNSUPPORTEDCONVERSION) || hr == S_OK /* W2K+ */, "got %08x\n", hr);
1337 ok(broken(dst_status == DBSTATUS_E_BADACCESSOR) || dst_status == DBSTATUS_S_OK /* W2K+ */, "got %08x\n", dst_status);
1338 ok(broken(dst_len == 0x1234) || dst_len == 8 /* W2K+ */, "got %ld\n", dst_len);
1339 ok(!lstrcmpW(dst, fourthreetwoone), "got %s\n", wine_dbgstr_w(dst));
1341 memset(src, 0, sizeof(src));
1342 ((ULARGE_INTEGER*)src)->QuadPart = 4321;
1343 hr = IDataConvert_DataConvert(convert, DBTYPE_UI8, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1344 ok(broken(DB_E_UNSUPPORTEDCONVERSION) || hr == S_OK /* W2K+ */, "got %08x\n", hr);
1345 ok(broken(dst_status == DBSTATUS_E_BADACCESSOR) || dst_status == DBSTATUS_S_OK /* W2K+ */, "got %08x\n", dst_status);
1346 ok(broken(dst_len == 0x1234) || dst_len == 8 /* W2K+ */, "got %ld\n", dst_len);
1347 ok(!lstrcmpW(dst, fourthreetwoone), "got %s\n", wine_dbgstr_w(dst));
1351 memset(src, 0, sizeof(src));
1352 memcpy(src, &IID_IDataConvert, sizeof(GUID));
1353 memset(dst, 0xcc, sizeof(dst));
1354 dst_len = 0x1234;
1355 hr = IDataConvert_DataConvert(convert, DBTYPE_GUID, DBTYPE_WSTR, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1356 ok(hr == S_OK, "got %08x\n", hr);
1357 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1358 ok(dst_len == 76, "got %ld\n", dst_len);
1359 ok(!lstrcmpW(dst, guid_str), "got %s\n", wine_dbgstr_w(dst));
1363 b = SysAllocString(ten);
1364 *(BSTR *)src = b;
1365 dst_len = 0x1234;
1366 hr = IDataConvert_DataConvert(convert, DBTYPE_BSTR, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1367 ok(hr == S_OK, "got %08x\n", hr);
1368 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1369 ok(dst_len == 4, "got %ld\n", dst_len);
1370 ok(!lstrcmpW(b, dst), "got %s\n", wine_dbgstr_w(dst));
1371 SysFreeString(b);
1373 memcpy(src, ten, sizeof(ten));
1374 dst_len = 0x1234;
1375 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_WSTR, 2, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1376 ok(hr == S_OK, "got %08x\n", hr);
1377 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1378 ok(dst_len == 2, "got %ld\n", dst_len);
1379 ok(dst[0] == '1', "got %02x\n", dst[0]);
1380 ok(dst[1] == 0, "got %02x\n", dst[1]);
1382 memcpy(src, ten, sizeof(ten));
1383 dst_len = 0x1234;
1384 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_WSTR, 4, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1385 ok(hr == S_OK, "got %08x\n", hr);
1386 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1387 ok(dst_len == 4, "got %ld\n", dst_len);
1388 ok(!lstrcmpW(ten, dst), "got %s\n", wine_dbgstr_w(dst));
1390 memcpy(src, ten, sizeof(ten));
1391 dst_len = 0x1234;
1392 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, DBDATACONVERT_LENGTHFROMNTS);
1393 ok(hr == S_OK, "got %08x\n", hr);
1394 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1395 ok(dst_len == 4, "got %ld\n", dst_len);
1396 ok(!lstrcmpW(ten, dst), "got %s\n", wine_dbgstr_w(dst));
1400 /* DBTYPE_BYTES to DBTYPE_*STR unpacks binary data into a hex string */
1401 memcpy(src, hexpacked_w, sizeof(hexpacked_w));
1402 memset(dst, 0xcc, sizeof(dst));
1403 dst_len = 0x1234;
1404 hr = IDataConvert_DataConvert(convert, DBTYPE_BYTES, DBTYPE_WSTR, sizeof(hexpacked_w), &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1405 ok(hr == S_OK, "got %08x\n", hr);
1406 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1407 ok(dst_len == sizeof(hexpacked_w) * 4, "got %ld\n", dst_len);
1408 ok(!lstrcmpW(hexunpacked_w, dst), "got %s\n", wine_dbgstr_w(dst));
1409 ok(dst[sizeof(hexpacked_w)/sizeof(WCHAR) * 4 + 1] == 0xcccc, "clobbered buffer\n");
1411 memcpy(src, hexpacked_w, sizeof(hexpacked_w));
1412 memset(dst, 0xcc, sizeof(dst));
1413 dst_len = 0x1234;
1414 hr = IDataConvert_DataConvert(convert, DBTYPE_BYTES, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1415 ok(hr == S_OK, "got %08x\n", hr);
1416 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1417 ok(dst_len == 0, "got %ld\n", dst_len);
1418 ok(dst[0] == 0, "not null terminated\n");
1419 ok(dst[1] == 0xcccc, "clobbered buffer\n");
1421 memcpy(src, hexpacked_w, sizeof(hexpacked_w));
1422 memset(dst, 0xcc, sizeof(dst));
1423 dst_len = 0x1234;
1424 hr = IDataConvert_DataConvert(convert, DBTYPE_BYTES, DBTYPE_WSTR, 4, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1425 ok(hr == S_OK, "got %08x\n", hr);
1426 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1427 ok(dst_len == 2 * sizeof(WCHAR) * 4, "got %ld\n", dst_len);
1428 ok(!memcmp(hexunpacked_w, dst, 2 * sizeof(WCHAR) * 4 ), "got %s\n", wine_dbgstr_w(dst));
1429 ok(dst[2 * 4] == 0, "not null terminated\n");
1430 ok(dst[2 * 4 + 1] == 0xcccc, "clobbered buffer\n");
1432 memcpy(src, hexpacked_w, sizeof(hexpacked_w));
1433 memset(dst, 0xcc, sizeof(dst));
1434 dst_len = 0x1234;
1435 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);
1436 ok(hr == S_OK, "got %08x\n", hr);
1437 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1438 ok(dst_len == sizeof(hexpacked_w) * 4, "got %ld\n", dst_len);
1439 ok(!memcmp(hexunpacked_w, dst, 2 * sizeof(WCHAR) * 4 ), "got %s\n", wine_dbgstr_w(dst));
1440 ok(dst[2 * 4] == 0, "not null terminated\n");
1441 ok(dst[2 * 4 + 1] == 0xcccc, "clobbered buffer\n");
1443 memcpy(src, hexpacked_w, sizeof(hexpacked_w));
1444 memset(dst, 0xcc, sizeof(dst));
1445 dst_len = 0x1234;
1446 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);
1447 ok(hr == S_OK, "got %08x\n", hr);
1448 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1449 ok(dst_len == sizeof(hexpacked_w) * 4, "got %ld\n", dst_len);
1450 ok(!memcmp(hexunpacked_w, dst, 2 * sizeof(WCHAR) * 4 - 2 ), "got %s\n", wine_dbgstr_w(dst));
1451 ok(dst[2 * 4 - 1] == 0, "not null terminated\n");
1452 ok(dst[2 * 4] == 0xcccc, "clobbered buffer\n");
1454 memcpy(src, hexpacked_w, sizeof(hexpacked_w));
1455 memset(dst, 0xcc, sizeof(dst));
1456 dst_len = 0x1234;
1457 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);
1458 ok(hr == S_OK, "got %08x\n", hr);
1459 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1460 ok(dst_len == sizeof(hexpacked_w) * 4, "got %ld\n", dst_len);
1461 ok(!memcmp(hexunpacked_w, dst, 2 * sizeof(WCHAR) * 4 - 2 ), "got %s\n", wine_dbgstr_w(dst));
1462 ok(dst[2 * 4 - 1] == 0, "not null terminated\n");
1463 ok(dst[2 * 4] == 0xcccc, "clobbered buffer\n");
1465 memcpy(src, hexpacked_w, sizeof(hexpacked_w));
1466 memset(dst, 0xcc, sizeof(dst));
1467 dst_len = 0x1234;
1468 hr = IDataConvert_DataConvert(convert, DBTYPE_BYTES, DBTYPE_WSTR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, DBDATACONVERT_LENGTHFROMNTS);
1469 ok(hr == S_OK, "got %08x\n", hr);
1470 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1471 ok(dst_len == 0, "got %ld\n", dst_len);
1472 ok(dst[0] == 0, "not null terminated\n");
1473 ok(dst[1] == 0xcccc, "clobbered buffer\n");
1475 b = SysAllocStringLen(NULL, 0);
1476 V_VT(&v) = VT_BSTR;
1477 V_BSTR(&v) = b;
1478 hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_WSTR, 0, &dst_len, &v, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1479 ok(hr == S_OK, "got %08x\n", hr);
1480 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1481 ok(dst_len == 0, "got %ld\n", dst_len);
1482 ok(dst != NULL, "got %p\n", dst);
1483 ok(dst != b, "got %p src %p\n", dst, b);
1484 ok(!lstrcmpW(b, dst), "got %s\n", wine_dbgstr_w(dst));
1485 VariantClear(&v);
1487 V_VT(&v) = VT_NULL;
1488 hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_WSTR, 0, &dst_len, &v, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1489 ok(hr == S_OK, "got %08x\n", hr);
1490 ok(dst_status == DBSTATUS_S_ISNULL, "got %08x\n", dst_status);
1491 ok(dst_len == 0, "got %ld\n", dst_len);
1494 static void test_converttostr(void)
1496 HRESULT hr;
1497 char dst[100];
1498 BYTE src[64];
1499 DBSTATUS dst_status;
1500 DBLENGTH dst_len;
1501 static const WCHAR ten[] = {'1','0',0};
1502 static const char ten_a[] = "10";
1503 static const char fourthreetwoone[] = "4321";
1504 static const char guid_str[] = "{0C733A8D-2A1C-11CE-ADE5-00AA0044773D}";
1505 static const char hexunpacked_a[] = "57696E6500";
1506 static const char hexpacked_a[] = "Wine";
1507 BSTR b;
1509 memset(dst, 0xcc, sizeof(dst));
1510 dst_len = 0x1234;
1511 hr = IDataConvert_DataConvert(convert, DBTYPE_EMPTY, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1512 ok(hr == S_OK, "got %08x\n", hr);
1513 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1514 ok(dst_len == 0, "got %ld\n", dst_len);
1515 ok(dst[0] == 0, "got %02x\n", dst[0]);
1516 ok(dst[1] == (char)0xcc, "got %02x\n", dst[1]);
1518 memset(dst, 0xcc, sizeof(dst));
1519 dst_len = 0x1234;
1520 hr = IDataConvert_DataConvert(convert, DBTYPE_NULL, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1521 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr);
1522 ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status);
1523 ok(dst_len == 0x1234, "got %ld\n", dst_len);
1524 ok(dst[0] == (char)0xcc, "got %02x\n", dst[0]);
1526 *(short *)src = 4321;
1527 dst_len = 0x1234;
1528 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1529 ok(hr == S_OK, "got %08x\n", hr);
1530 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1531 ok(dst_len == 4, "got %ld\n", dst_len);
1532 ok(!lstrcmpA(dst, fourthreetwoone), "got %s\n", dst);
1534 *(short *)src = 4321;
1535 memset(dst, 0xcc, sizeof(dst));
1536 dst_len = 0x1234;
1537 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_STR, 0, &dst_len, src, dst, 0, 0, &dst_status, 0, 0, 0);
1538 ok(hr == DB_E_ERRORSOCCURRED, "got %08x\n", hr);
1539 ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
1540 ok(dst_len == 4, "got %ld\n", dst_len);
1541 ok(dst[0] == (char)0xcc, "got %02x\n", dst[0]);
1543 *(short *)src = 4321;
1544 memset(dst, 0xcc, sizeof(dst));
1545 dst_len = 0x1234;
1546 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_STR, 0, &dst_len, src, NULL, 0, 0, &dst_status, 0, 0, 0);
1547 ok(hr == S_OK, "got %08x\n", hr);
1548 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1549 ok(dst_len == 4, "got %ld\n", dst_len);
1550 ok(dst[0] == (char)0xcc, "got %02x\n", dst[0]);
1552 *(short *)src = 4321;
1553 memset(dst, 0xcc, sizeof(dst));
1554 dst_len = 0x1234;
1555 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_STR, 0, &dst_len, src, dst, 2, 0, &dst_status, 0, 0, 0);
1556 ok(hr == S_OK, "got %08x\n", hr);
1557 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1558 ok(dst_len == 4, "got %ld\n", dst_len);
1559 ok(dst[0] == '4', "got %02x\n", dst[0]);
1560 ok(dst[1] == 0, "got %02x\n", dst[1]);
1561 ok(dst[2] == (char)0xcc, "got %02x\n", dst[2]);
1563 *(short *)src = 4321;
1564 memset(dst, 0xcc, sizeof(dst));
1565 dst_len = 0x1234;
1566 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_STR, 0, &dst_len, src, dst, 1, 0, &dst_status, 0, 0, 0);
1567 ok(hr == S_OK, "got %08x\n", hr);
1568 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1569 ok(dst_len == 4, "got %ld\n", dst_len);
1570 ok(dst[0] == 0, "got %02x\n", dst[0]);
1571 ok(dst[1] == (char)0xcc, "got %02x\n", dst[1]);
1573 *(short *)src = 4321;
1574 memset(dst, 0xcc, sizeof(dst));
1575 dst_len = 0x1234;
1576 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_STR, 0, &dst_len, src, dst, 4, 0, &dst_status, 0, 0, 0);
1577 ok(hr == S_OK, "got %08x\n", hr);
1578 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1579 ok(dst_len == 4, "got %ld\n", dst_len);
1580 ok(dst[0] == '4', "got %02x\n", dst[0]);
1581 ok(dst[1] == '3', "got %02x\n", dst[1]);
1582 ok(dst[2] == '2', "got %02x\n", dst[2]);
1583 ok(dst[3] == 0, "got %02x\n", dst[3]);
1584 ok(dst[4] == (char)0xcc, "got %02x\n", dst[4]);
1587 *(int *)src = 4321;
1588 dst_len = 0x1234;
1589 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1590 ok(hr == S_OK, "got %08x\n", hr);
1591 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1592 ok(dst_len == 4, "got %ld\n", dst_len);
1593 ok(!lstrcmpA(dst, fourthreetwoone), "got %s\n", dst);
1595 *(int *)src = 4321;
1596 memset(dst, 0xcc, sizeof(dst));
1597 dst_len = 0x1234;
1598 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_STR, 0, &dst_len, src, dst, 0, 0, &dst_status, 0, 0, 0);
1599 ok(hr == DB_E_ERRORSOCCURRED, "got %08x\n", hr);
1600 ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
1601 ok(dst_len == 4, "got %ld\n", dst_len);
1602 ok(dst[0] == (char)0xcc, "got %02x\n", dst[0]);
1604 *(int *)src = 4321;
1605 memset(dst, 0xcc, sizeof(dst));
1606 dst_len = 0x1234;
1607 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_STR, 0, &dst_len, src, NULL, 0, 0, &dst_status, 0, 0, 0);
1608 ok(hr == S_OK, "got %08x\n", hr);
1609 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1610 ok(dst_len == 4, "got %ld\n", dst_len);
1611 ok(dst[0] == (char)0xcc, "got %02x\n", dst[0]);
1613 *(int *)src = 4321;
1614 memset(dst, 0xcc, sizeof(dst));
1615 dst_len = 0x1234;
1616 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_STR, 0, &dst_len, src, dst, 2, 0, &dst_status, 0, 0, 0);
1617 ok(hr == S_OK, "got %08x\n", hr);
1618 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1619 ok(dst_len == 4, "got %ld\n", dst_len);
1620 ok(dst[0] == '4', "got %02x\n", dst[0]);
1621 ok(dst[1] == 0, "got %02x\n", dst[1]);
1622 ok(dst[2] == (char)0xcc, "got %02x\n", dst[2]);
1624 *(int *)src = 4321;
1625 memset(dst, 0xcc, sizeof(dst));
1626 dst_len = 0x1234;
1627 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_STR, 0, &dst_len, src, dst, 1, 0, &dst_status, 0, 0, 0);
1628 ok(hr == S_OK, "got %08x\n", hr);
1629 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1630 ok(dst_len == 4, "got %ld\n", dst_len);
1631 ok(dst[0] == 0, "got %02x\n", dst[0]);
1632 ok(dst[1] == (char)0xcc, "got %02x\n", dst[1]);
1634 *(int *)src = 4321;
1635 memset(dst, 0xcc, sizeof(dst));
1636 dst_len = 0x1234;
1637 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_STR, 0, &dst_len, src, dst, 4, 0, &dst_status, 0, 0, 0);
1638 ok(hr == S_OK, "got %08x\n", hr);
1639 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1640 ok(dst_len == 4, "got %ld\n", dst_len);
1641 ok(dst[0] == '4', "got %02x\n", dst[0]);
1642 ok(dst[1] == '3', "got %02x\n", dst[1]);
1643 ok(dst[2] == '2', "got %02x\n", dst[2]);
1644 ok(dst[3] == 0, "got %02x\n", dst[3]);
1645 ok(dst[4] == (char)0xcc, "got %02x\n", dst[4]);
1648 *(float *)src = 4321;
1649 dst_len = 0x1234;
1650 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1651 ok(hr == S_OK, "got %08x\n", hr);
1652 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1653 ok(dst_len == 4, "got %ld\n", dst_len);
1654 ok(!lstrcmpA(dst, fourthreetwoone), "got %s\n", dst);
1656 *(float *)src = 4321;
1657 memset(dst, 0xcc, sizeof(dst));
1658 dst_len = 0x1234;
1659 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_STR, 0, &dst_len, src, dst, 0, 0, &dst_status, 0, 0, 0);
1660 ok(hr == DB_E_ERRORSOCCURRED, "got %08x\n", hr);
1661 ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
1662 ok(dst_len == 4, "got %ld\n", dst_len);
1663 ok(dst[0] == (char)0xcc, "got %02x\n", dst[0]);
1665 *(float *)src = 4321;
1666 memset(dst, 0xcc, sizeof(dst));
1667 dst_len = 0x1234;
1668 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_STR, 0, &dst_len, src, NULL, 0, 0, &dst_status, 0, 0, 0);
1669 ok(hr == S_OK, "got %08x\n", hr);
1670 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1671 ok(dst_len == 4, "got %ld\n", dst_len);
1672 ok(dst[0] == (char)0xcc, "got %02x\n", dst[0]);
1674 *(float *)src = 4321;
1675 memset(dst, 0xcc, sizeof(dst));
1676 dst_len = 0x1234;
1677 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_STR, 0, &dst_len, src, dst, 2, 0, &dst_status, 0, 0, 0);
1678 ok(hr == S_OK, "got %08x\n", hr);
1679 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1680 ok(dst_len == 4, "got %ld\n", dst_len);
1681 ok(dst[0] == '4', "got %02x\n", dst[0]);
1682 ok(dst[1] == 0, "got %02x\n", dst[1]);
1683 ok(dst[2] == (char)0xcc, "got %02x\n", dst[2]);
1685 *(float *)src = 4321;
1686 memset(dst, 0xcc, sizeof(dst));
1687 dst_len = 0x1234;
1688 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_STR, 0, &dst_len, src, dst, 1, 0, &dst_status, 0, 0, 0);
1689 ok(hr == S_OK, "got %08x\n", hr);
1690 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1691 ok(dst_len == 4, "got %ld\n", dst_len);
1692 ok(dst[0] == 0, "got %02x\n", dst[0]);
1693 ok(dst[1] == (char)0xcc, "got %02x\n", dst[1]);
1695 *(float *)src = 4321;
1696 memset(dst, 0xcc, sizeof(dst));
1697 dst_len = 0x1234;
1698 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_STR, 0, &dst_len, src, dst, 4, 0, &dst_status, 0, 0, 0);
1699 ok(hr == S_OK, "got %08x\n", hr);
1700 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1701 ok(dst_len == 4, "got %ld\n", dst_len);
1702 ok(dst[0] == '4', "got %02x\n", dst[0]);
1703 ok(dst[1] == '3', "got %02x\n", dst[1]);
1704 ok(dst[2] == '2', "got %02x\n", dst[2]);
1705 ok(dst[3] == 0, "got %02x\n", dst[3]);
1706 ok(dst[4] == (char)0xcc, "got %02x\n", dst[4]);
1709 *(double *)src = 4321;
1710 dst_len = 0x1234;
1711 hr = IDataConvert_DataConvert(convert, DBTYPE_R8, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1712 ok(hr == S_OK, "got %08x\n", hr);
1713 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1714 ok(dst_len == 4, "got %ld\n", dst_len);
1715 ok(!lstrcmpA(dst, fourthreetwoone), "got %s\n", dst);
1717 *(double *)src = 4321;
1718 memset(dst, 0xcc, sizeof(dst));
1719 dst_len = 0x1234;
1720 hr = IDataConvert_DataConvert(convert, DBTYPE_R8, DBTYPE_STR, 0, &dst_len, src, dst, 0, 0, &dst_status, 0, 0, 0);
1721 ok(hr == DB_E_ERRORSOCCURRED, "got %08x\n", hr);
1722 ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
1723 ok(dst_len == 4, "got %ld\n", dst_len);
1724 ok(dst[0] == (char)0xcc, "got %02x\n", dst[0]);
1726 *(double *)src = 4321;
1727 memset(dst, 0xcc, sizeof(dst));
1728 dst_len = 0x1234;
1729 hr = IDataConvert_DataConvert(convert, DBTYPE_R8, DBTYPE_STR, 0, &dst_len, src, NULL, 0, 0, &dst_status, 0, 0, 0);
1730 ok(hr == S_OK, "got %08x\n", hr);
1731 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1732 ok(dst_len == 4, "got %ld\n", dst_len);
1733 ok(dst[0] == (char)0xcc, "got %02x\n", dst[0]);
1735 *(double *)src = 4321;
1736 memset(dst, 0xcc, sizeof(dst));
1737 dst_len = 0x1234;
1738 hr = IDataConvert_DataConvert(convert, DBTYPE_R8, DBTYPE_STR, 0, &dst_len, src, dst, 2, 0, &dst_status, 0, 0, 0);
1739 ok(hr == S_OK, "got %08x\n", hr);
1740 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1741 ok(dst_len == 4, "got %ld\n", dst_len);
1742 ok(dst[0] == '4', "got %02x\n", dst[0]);
1743 ok(dst[1] == 0, "got %02x\n", dst[1]);
1744 ok(dst[2] == (char)0xcc, "got %02x\n", dst[2]);
1746 *(double *)src = 4321;
1747 memset(dst, 0xcc, sizeof(dst));
1748 dst_len = 0x1234;
1749 hr = IDataConvert_DataConvert(convert, DBTYPE_R8, DBTYPE_STR, 0, &dst_len, src, dst, 1, 0, &dst_status, 0, 0, 0);
1750 ok(hr == S_OK, "got %08x\n", hr);
1751 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1752 ok(dst_len == 4, "got %ld\n", dst_len);
1753 ok(dst[0] == 0, "got %02x\n", dst[0]);
1754 ok(dst[1] == (char)0xcc, "got %02x\n", dst[1]);
1756 *(double *)src = 4321;
1757 memset(dst, 0xcc, sizeof(dst));
1758 dst_len = 0x1234;
1759 hr = IDataConvert_DataConvert(convert, DBTYPE_R8, DBTYPE_STR, 0, &dst_len, src, dst, 4, 0, &dst_status, 0, 0, 0);
1760 ok(hr == S_OK, "got %08x\n", hr);
1761 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1762 ok(dst_len == 4, "got %ld\n", dst_len);
1763 ok(dst[0] == '4', "got %02x\n", dst[0]);
1764 ok(dst[1] == '3', "got %02x\n", dst[1]);
1765 ok(dst[2] == '2', "got %02x\n", dst[2]);
1766 ok(dst[3] == 0, "got %02x\n", dst[3]);
1767 ok(dst[4] == (char)0xcc, "got %02x\n", dst[4]);
1771 memset(src, 0, sizeof(src));
1772 ((CY*)src)->int64 = 43210000;
1773 memset(dst, 0xcc, sizeof(dst));
1774 dst_len = 0x1234;
1775 hr = IDataConvert_DataConvert(convert, DBTYPE_CY, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1776 ok(hr == S_OK, "got %08x\n", hr);
1777 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1778 ok(dst_len == 4, "got %ld\n", dst_len);
1779 ok(!lstrcmpA(dst, fourthreetwoone), "got %s\n", dst);
1783 memset(src, 0, sizeof(src));
1784 *(signed char *)src = 10;
1785 dst_len = 0x1234;
1786 hr = IDataConvert_DataConvert(convert, DBTYPE_I1, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1787 ok(hr == S_OK, "got %08x\n", hr);
1788 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1789 ok(dst_len == 2, "got %ld\n", dst_len);
1790 ok(!lstrcmpA(dst, ten_a), "got %s\n", dst);
1792 memset(src, 0, sizeof(src));
1793 *(unsigned char *)src = 10;
1794 dst_len = 0x1234;
1795 hr = IDataConvert_DataConvert(convert, DBTYPE_UI1, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1796 ok(hr == S_OK, "got %08x\n", hr);
1797 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1798 ok(dst_len == 2, "got %ld\n", dst_len);
1799 ok(!lstrcmpA(dst, ten_a), "got %s\n", dst);
1801 memset(src, 0, sizeof(src));
1802 *(unsigned short *)src = 4321;
1803 dst_len = 0x1234;
1804 hr = IDataConvert_DataConvert(convert, DBTYPE_UI2, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1805 ok(hr == S_OK, "got %08x\n", hr);
1806 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1807 ok(dst_len == 4, "got %ld\n", dst_len);
1808 ok(!lstrcmpA(dst, fourthreetwoone), "got %s\n", dst);
1810 memset(src, 0, sizeof(src));
1811 *(unsigned int *)src = 4321;
1812 dst_len = 0x1234;
1813 hr = IDataConvert_DataConvert(convert, DBTYPE_UI4, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1814 ok(hr == S_OK, "got %08x\n", hr);
1815 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1816 ok(dst_len == 4, "got %ld\n", dst_len);
1817 ok(!lstrcmpA(dst, fourthreetwoone), "got %s\n", dst);
1819 memset(src, 0, sizeof(src));
1820 ((LARGE_INTEGER*)src)->QuadPart = 4321;
1821 dst_len = 0x1234;
1822 hr = IDataConvert_DataConvert(convert, DBTYPE_I8, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1823 ok(broken(DB_E_UNSUPPORTEDCONVERSION) || hr == S_OK /* W2K+ */, "got %08x\n", hr);
1824 ok(broken(dst_status == DBSTATUS_E_BADACCESSOR) || dst_status == DBSTATUS_S_OK /* W2K+ */, "got %08x\n", dst_status);
1825 ok(broken(dst_len == 0x1234) || dst_len == 4 /* W2K+ */, "got %ld\n", dst_len);
1826 ok(!lstrcmpA(dst, fourthreetwoone), "got %s\n", dst);
1828 memset(src, 0, sizeof(src));
1829 ((ULARGE_INTEGER*)src)->QuadPart = 4321;
1830 dst_len = 0x1234;
1831 hr = IDataConvert_DataConvert(convert, DBTYPE_UI8, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1832 ok(broken(DB_E_UNSUPPORTEDCONVERSION) || hr == S_OK /* W2K+ */, "got %08x\n", hr);
1833 ok(broken(dst_status == DBSTATUS_E_BADACCESSOR) || dst_status == DBSTATUS_S_OK /* W2K+ */, "got %08x\n", dst_status);
1834 ok(broken(dst_len == 0x1234) || dst_len == 4 /* W2K+ */, "got %ld\n", dst_len);
1835 ok(!lstrcmpA(dst, fourthreetwoone), "got %s\n", dst);
1839 memset(src, 0, sizeof(src));
1840 memcpy(src, &IID_IDataConvert, sizeof(GUID));
1841 memset(dst, 0xcc, sizeof(dst));
1842 dst_len = 0x1234;
1843 hr = IDataConvert_DataConvert(convert, DBTYPE_GUID, DBTYPE_STR, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1844 ok(hr == S_OK, "got %08x\n", hr);
1845 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1846 ok(dst_len == 38, "got %ld\n", dst_len);
1847 ok(!lstrcmpA(dst, guid_str), "got %s\n", dst);
1851 b = SysAllocString(ten);
1852 *(BSTR *)src = b;
1853 memset(dst, 0xcc, sizeof(dst));
1854 dst_len = 0x1234;
1855 hr = IDataConvert_DataConvert(convert, DBTYPE_BSTR, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1856 ok(hr == S_OK, "got %08x\n", hr);
1857 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1858 ok(dst_len == 2, "got %ld\n", dst_len);
1859 ok(!lstrcmpA(ten_a, dst), "got %s\n", dst);
1860 SysFreeString(b);
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, 2, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
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 == 1, "got %ld\n", dst_len);
1869 ok(dst[0] == '1', "got %02x\n", dst[0]);
1870 ok(dst[1] == 0, "got %02x\n", dst[1]);
1872 memcpy(src, ten, sizeof(ten));
1873 memset(dst, 0xcc, sizeof(dst));
1874 dst_len = 0x1234;
1875 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_STR, 4, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1876 ok(hr == S_OK, "got %08x\n", hr);
1877 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1878 ok(dst_len == 2, "got %ld\n", dst_len);
1879 ok(!lstrcmpA(ten_a, dst), "got %s\n", dst);
1881 memcpy(src, ten, sizeof(ten));
1882 memset(dst, 0xcc, sizeof(dst));
1883 dst_len = 0x1234;
1884 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, DBDATACONVERT_LENGTHFROMNTS);
1885 ok(hr == S_OK, "got %08x\n", hr);
1886 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1887 ok(dst_len == 2, "got %ld\n", dst_len);
1888 ok(!lstrcmpA(ten_a, dst), "got %s\n", dst);
1890 memcpy(src, ten_a, sizeof(ten_a));
1891 memset(dst, 0xcc, sizeof(dst));
1892 dst_len = 0x1234;
1893 hr = IDataConvert_DataConvert(convert, DBTYPE_STR, DBTYPE_STR, 2, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1894 ok(hr == S_OK, "got %08x\n", hr);
1895 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1896 ok(dst_len == 2, "got %ld\n", dst_len);
1897 ok(dst[0] == '1', "got %02x\n", dst[0]);
1898 ok(dst[1] == '0', "got %02x\n", dst[1]);
1899 ok(dst[2] == 0, "got %02x\n", dst[2]);
1900 ok(dst[3] == (char)0xcc, "got %02x\n", dst[3]);
1902 memcpy(src, ten_a, sizeof(ten_a));
1903 memset(dst, 0xcc, sizeof(dst));
1904 dst_len = 0x1234;
1905 hr = IDataConvert_DataConvert(convert, DBTYPE_STR, DBTYPE_STR, 4, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1906 ok(hr == S_OK, "got %08x\n", hr);
1907 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1908 ok(dst_len == 4, "got %ld\n", dst_len);
1909 ok(!lstrcmpA(ten_a, dst), "got %s\n", dst);
1911 memcpy(src, ten_a, sizeof(ten_a));
1912 memset(dst, 0xcc, sizeof(dst));
1913 dst_len = 0x1234;
1914 hr = IDataConvert_DataConvert(convert, DBTYPE_STR, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, DBDATACONVERT_LENGTHFROMNTS);
1915 ok(hr == S_OK, "got %08x\n", hr);
1916 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1917 ok(dst_len == 2, "got %ld\n", dst_len);
1918 ok(!lstrcmpA(ten_a, dst), "got %s\n", dst);
1922 /* DBTYPE_BYTES to DBTYPE_*STR unpacks binary data into a hex string */
1923 memcpy(src, hexpacked_a, sizeof(hexpacked_a));
1924 memset(dst, 0xcc, sizeof(dst));
1925 dst_len = 0x1234;
1926 hr = IDataConvert_DataConvert(convert, DBTYPE_BYTES, DBTYPE_STR, sizeof(hexpacked_a), &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1927 ok(hr == S_OK, "got %08x\n", hr);
1928 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1929 ok(dst_len == sizeof(hexpacked_a) * 2, "got %ld\n", dst_len);
1930 ok(!lstrcmpA(hexunpacked_a, dst), "got %s\n", dst);
1931 ok(dst[sizeof(hexpacked_a)/sizeof(char) * 4 + 1] == (char)0xcc, "clobbered buffer\n");
1933 memcpy(src, hexpacked_a, sizeof(hexpacked_a));
1934 memset(dst, 0xcc, sizeof(dst));
1935 dst_len = 0x1234;
1936 hr = IDataConvert_DataConvert(convert, DBTYPE_BYTES, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1937 ok(hr == S_OK, "got %08x\n", hr);
1938 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1939 ok(dst_len == 0, "got %ld\n", dst_len);
1940 ok(dst[0] == 0, "not null terminated\n");
1941 ok(dst[1] == (char)0xcc, "clobbered buffer\n");
1943 memcpy(src, hexpacked_a, sizeof(hexpacked_a));
1944 memset(dst, 0xcc, sizeof(dst));
1945 dst_len = 0x1234;
1946 hr = IDataConvert_DataConvert(convert, DBTYPE_BYTES, DBTYPE_STR, 4, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1947 ok(hr == S_OK, "got %08x\n", hr);
1948 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
1949 ok(dst_len == 2 * sizeof(char) * 4, "got %ld\n", dst_len);
1950 ok(!memcmp(hexunpacked_a, dst, 2 * sizeof(char) * 4 ), "got %s\n", dst);
1951 ok(dst[2 * 4] == 0, "not null terminated\n");
1952 ok(dst[2 * 4 + 1] == (char)0xcc, "clobbered buffer\n");
1954 memcpy(src, hexpacked_a, sizeof(hexpacked_a));
1955 memset(dst, 0xcc, sizeof(dst));
1956 dst_len = 0x1234;
1957 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);
1958 ok(hr == S_OK, "got %08x\n", hr);
1959 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1960 ok(dst_len == sizeof(hexpacked_a) * 2, "got %ld\n", dst_len);
1961 ok(!memcmp(hexunpacked_a, dst, 2 * sizeof(char) * 4 ), "got %s\n", dst);
1962 ok(dst[2 * 4] == 0, "not null terminated\n");
1963 ok(dst[2 * 4 + 1] == (char)0xcc, "clobbered buffer\n");
1965 memcpy(src, hexpacked_a, sizeof(hexpacked_a));
1966 memset(dst, 0xcc, sizeof(dst));
1967 dst_len = 0x1234;
1968 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);
1969 ok(hr == S_OK, "got %08x\n", hr);
1970 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
1971 ok(dst_len == sizeof(hexpacked_a) * 2, "got %ld\n", dst_len);
1972 ok(!memcmp(hexunpacked_a, dst, 2 * sizeof(char) * 4 - 2 ), "got %s\n", dst);
1973 ok(dst[2 * 4 - 1] == 0, "not null terminated\n");
1974 ok(dst[2 * 4] == (char)0xcc, "clobbered buffer\n");
1976 memcpy(src, hexpacked_a, sizeof(hexpacked_a));
1977 memset(dst, 0xcc, sizeof(dst));
1978 dst_len = 0x1234;
1979 hr = IDataConvert_DataConvert(convert, DBTYPE_BYTES, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, DBDATACONVERT_LENGTHFROMNTS);
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, "not null terminated\n");
1984 ok(dst[1] == (char)0xcc, "clobbered buffer\n");
1987 static void test_converttobyrefwstr(void)
1989 HRESULT hr;
1990 WCHAR *dst;
1991 BYTE src[20];
1992 DBSTATUS dst_status;
1993 DBLENGTH dst_len;
1994 static const WCHAR ten[] = {'1','0',0};
1995 static const WCHAR fourthreetwoone[] = {'4','3','2','1',0};
1996 BSTR b;
1998 hr = IDataConvert_DataConvert(convert, DBTYPE_EMPTY, DBTYPE_BYREF | DBTYPE_WSTR, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
1999 ok(hr == S_OK, "got %08x\n", hr);
2000 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2001 ok(dst_len == 0, "got %ld\n", dst_len);
2002 ok(dst[0] == 0, "got %04x\n", dst[0]);
2003 CoTaskMemFree(dst);
2005 dst = (void*)0x12345678;
2006 dst_len = 0x1234;
2007 hr = IDataConvert_DataConvert(convert, DBTYPE_NULL, DBTYPE_BYREF | DBTYPE_WSTR, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2008 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr);
2009 ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status);
2010 ok(dst_len == 0x1234, "got %ld\n", dst_len);
2011 ok(dst == (void*)0x12345678, "got %p\n", dst);
2013 *(short *)src = 4321;
2014 dst_len = 0x1234;
2015 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, 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 == 8, "got %ld\n", dst_len);
2019 ok(!lstrcmpW(dst, fourthreetwoone), "got %s\n", wine_dbgstr_w(dst));
2020 CoTaskMemFree(dst);
2022 *(short *)src = 4321;
2023 dst_len = 0x1234;
2024 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_BYREF | DBTYPE_WSTR, 0, &dst_len, src, &dst, 0, 0, &dst_status, 0, 0, 0);
2025 ok(hr == S_OK, "got %08x\n", hr);
2026 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2027 ok(dst_len == 8, "got %ld\n", dst_len);
2028 ok(!lstrcmpW(dst, fourthreetwoone), "got %s\n", wine_dbgstr_w(dst));
2029 CoTaskMemFree(dst);
2031 b = SysAllocString(ten);
2032 *(BSTR *)src = b;
2033 dst_len = 0x1234;
2034 hr = IDataConvert_DataConvert(convert, DBTYPE_BSTR, DBTYPE_BYREF | DBTYPE_WSTR, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2035 ok(hr == S_OK, "got %08x\n", hr);
2036 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2037 ok(dst_len == 4, "got %ld\n", dst_len);
2038 ok(!lstrcmpW(b, dst), "got %s\n", wine_dbgstr_w(dst));
2039 CoTaskMemFree(dst);
2040 SysFreeString(b);
2042 memcpy(src, ten, sizeof(ten));
2043 dst_len = 0x1234;
2044 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_BYREF | DBTYPE_WSTR, 2, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
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 == 2, "got %ld\n", dst_len);
2048 ok(dst[0] == '1', "got %02x\n", dst[0]);
2049 ok(dst[1] == 0, "got %02x\n", dst[1]);
2050 CoTaskMemFree(dst);
2052 memcpy(src, ten, sizeof(ten));
2053 dst_len = 0x1234;
2054 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_BYREF | DBTYPE_WSTR, 4, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2055 ok(hr == S_OK, "got %08x\n", hr);
2056 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2057 ok(dst_len == 4, "got %ld\n", dst_len);
2058 ok(!lstrcmpW(ten, dst), "got %s\n", wine_dbgstr_w(dst));
2059 CoTaskMemFree(dst);
2061 memcpy(src, ten, sizeof(ten));
2062 dst_len = 0x1234;
2063 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_BYREF | DBTYPE_WSTR, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, DBDATACONVERT_LENGTHFROMNTS);
2064 ok(hr == S_OK, "got %08x\n", hr);
2065 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2066 ok(dst_len == 4, "got %ld\n", dst_len);
2067 ok(!lstrcmpW(ten, dst), "got %s\n", wine_dbgstr_w(dst));
2068 CoTaskMemFree(dst);
2071 static void test_converttoguid(void)
2073 HRESULT hr;
2074 GUID dst;
2075 BYTE src[20];
2076 DBSTATUS dst_status;
2077 DBLENGTH dst_len;
2079 dst = IID_IDCInfo;
2080 dst_len = 0x1234;
2081 hr = IDataConvert_DataConvert(convert, DBTYPE_EMPTY, DBTYPE_GUID, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2082 ok(hr == S_OK, "got %08x\n", hr);
2083 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2084 ok(dst_len == sizeof(GUID), "got %ld\n", dst_len);
2085 ok(IsEqualGUID(&dst, &GUID_NULL), "didn't get GUID_NULL\n");
2087 dst = IID_IDCInfo;
2088 dst_len = 0x1234;
2089 hr = IDataConvert_DataConvert(convert, DBTYPE_NULL, DBTYPE_GUID, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2090 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr);
2091 ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status);
2092 ok(dst_len == 0x1234, "got %ld\n", dst_len);
2093 ok(IsEqualGUID(&dst, &IID_IDCInfo), "dst has changed\n");
2095 dst = IID_IDCInfo;
2096 memcpy(src, &IID_IDataConvert, sizeof(GUID));
2097 dst_len = 0x1234;
2098 hr = IDataConvert_DataConvert(convert, DBTYPE_GUID, DBTYPE_GUID, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2099 ok(hr == S_OK, "got %08x\n", hr);
2100 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2101 ok(dst_len == sizeof(GUID), "got %ld\n", dst_len);
2102 ok(IsEqualGUID(&dst, &IID_IDataConvert), "didn't get IID_IDataConvert\n");
2105 static void test_converttofiletime(void)
2107 HRESULT hr;
2108 FILETIME dst;
2109 BYTE src[20];
2110 DBSTATUS dst_status;
2111 DBLENGTH dst_len;
2113 memset(&dst, 0xcc, sizeof(dst));
2114 ((FILETIME *)src)->dwLowDateTime = 0x12345678;
2115 ((FILETIME *)src)->dwHighDateTime = 0x9abcdef0;
2116 dst_len = 0x1234;
2117 hr = IDataConvert_DataConvert(convert, DBTYPE_FILETIME, DBTYPE_FILETIME, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2118 ok(hr == S_OK ||
2119 broken(hr == DB_E_BADBINDINFO), /* win98 */
2120 "got %08x\n", hr);
2121 if(SUCCEEDED(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.dwLowDateTime == 0x12345678, "got %08x\n", dst.dwLowDateTime);
2126 ok(dst.dwHighDateTime == 0x9abcdef0, "got %08x\n", dst.dwHighDateTime);
2130 static void test_converttoui1(void)
2132 HRESULT hr;
2133 BYTE dst;
2134 BYTE src[20];
2135 DBSTATUS dst_status;
2136 DBLENGTH dst_len;
2138 dst = 0x12;
2139 dst_len = 0x1234;
2140 hr = IDataConvert_DataConvert(convert, DBTYPE_EMPTY, DBTYPE_UI1, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2141 ok(hr == S_OK, "got %08x\n", hr);
2142 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2143 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2144 ok(dst == 0, "got %08x\n", dst);
2146 dst = 0x12;
2147 dst_len = 0x1234;
2148 hr = IDataConvert_DataConvert(convert, DBTYPE_NULL, DBTYPE_UI1, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2149 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr);
2150 ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status);
2151 ok(dst_len == 0x1234, "got %ld\n", dst_len);
2152 ok(dst == 0x12, "got %08x\n", dst);
2154 dst = 0x12;
2155 src[0] = 0x43;
2156 dst_len = 0x1234;
2157 hr = IDataConvert_DataConvert(convert, DBTYPE_UI1, DBTYPE_UI1, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2158 ok(hr == S_OK, "got %08x\n", hr);
2159 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2160 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2161 ok(dst == 0x43, "got %08x\n", dst);
2163 dst = 0x12;
2164 src[0] = 0xfe;
2165 dst_len = 0x1234;
2166 hr = IDataConvert_DataConvert(convert, DBTYPE_UI1, DBTYPE_UI1, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2167 ok(hr == S_OK, "got %08x\n", hr);
2168 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2169 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2170 ok(dst == 0xfe, "got %08x\n", dst);
2173 static void test_converttoui4(void)
2175 HRESULT hr;
2176 DWORD dst;
2177 BYTE src[20];
2178 DBSTATUS dst_status;
2179 DBLENGTH dst_len;
2181 dst = 0x12345678;
2182 dst_len = 0x1234;
2183 hr = IDataConvert_DataConvert(convert, DBTYPE_EMPTY, DBTYPE_UI4, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2184 ok(hr == S_OK, "got %08x\n", hr);
2185 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2186 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2187 ok(dst == 0, "got %08x\n", dst);
2189 dst = 0x12345678;
2190 dst_len = 0x1234;
2191 hr = IDataConvert_DataConvert(convert, DBTYPE_NULL, DBTYPE_UI4, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2192 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr);
2193 ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status);
2194 ok(dst_len == 0x1234, "got %ld\n", dst_len);
2195 ok(dst == 0x12345678, "got %08x\n", dst);
2197 dst = 0x12345678;
2198 *(DWORD*)src = 0x87654321;
2199 dst_len = 0x1234;
2200 hr = IDataConvert_DataConvert(convert, DBTYPE_UI4, DBTYPE_UI4, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2201 ok(hr == S_OK, "got %08x\n", hr);
2202 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2203 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2204 ok(dst == 0x87654321, "got %08x\n", dst);
2206 dst = 0x12345678;
2207 *(signed short *)src = 0x4321;
2208 dst_len = 0x1234;
2209 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_UI4, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2210 ok(hr == S_OK, "got %08x\n", hr);
2211 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2212 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2213 ok(dst == 0x4321, "got %08x\n", dst);
2215 dst = 0x12345678;
2216 *(signed short *)src = -1;
2217 dst_len = 0x1234;
2218 hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_UI4, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2219 ok(hr == DB_E_ERRORSOCCURRED, "got %08x\n", hr);
2220 todo_wine
2221 ok(dst_status == DBSTATUS_E_SIGNMISMATCH, "got %08x\n", dst_status);
2222 todo_wine
2223 ok(broken(dst_len == sizeof(dst)) || dst_len == 0x1234 /* W2K+ */, "got %ld\n", dst_len);
2224 ok(dst == 0x12345678, "got %08x\n", dst);
2226 dst_len = dst = 0x1234;
2227 V_VT((VARIANT*)src) = VT_I2;
2228 V_I2((VARIANT*)src) = 0x4321;
2229 hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_UI4, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2230 ok(hr == S_OK, "got %08x\n", hr);
2231 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2232 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2233 ok(dst == 0x4321, "got %08x\n", dst);
2236 static void test_converttor4(void)
2238 HRESULT hr;
2239 FLOAT dst;
2240 BYTE src[20];
2241 DBSTATUS dst_status;
2242 DBLENGTH dst_len;
2244 dst = 1.0;
2245 dst_len = 0x1234;
2246 hr = IDataConvert_DataConvert(convert, DBTYPE_EMPTY, DBTYPE_R4, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2247 ok(hr == S_OK, "got %08x\n", hr);
2248 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2249 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2250 ok(dst == 0.0, "got %f\n", dst);
2252 dst = 1.0;
2253 dst_len = 0x1234;
2254 hr = IDataConvert_DataConvert(convert, DBTYPE_NULL, DBTYPE_R4, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2255 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr);
2256 ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status);
2257 ok(dst_len == 0x1234, "got %ld\n", dst_len);
2258 ok(dst == 1.0, "got %f\n", dst);
2260 dst = 1.0;
2261 *(signed int*)src = 12345678;
2262 dst_len = 0x1234;
2263 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_R4, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2264 ok(hr == S_OK, "got %08x\n", hr);
2265 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2266 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2267 ok(dst == 12345678.0, "got %f\n", dst);
2269 dst = 1.0;
2270 *(FLOAT *)src = 10.0;
2271 dst_len = 0x1234;
2272 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_R4, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2273 ok(hr == S_OK, "got %08x\n", hr);
2274 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2275 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2276 ok(dst == 10.0, "got %f\n", dst);
2279 static void test_converttocy(void)
2281 HRESULT hr;
2282 CY dst;
2283 BYTE src[20];
2284 DBSTATUS dst_status;
2285 DBLENGTH dst_len;
2287 dst.int64 = 0xcc;
2288 dst_len = 0x1234;
2289 hr = IDataConvert_DataConvert(convert, DBTYPE_EMPTY, DBTYPE_CY, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2290 ok(hr == S_OK, "got %08x\n", hr);
2291 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2292 ok(dst_len == sizeof(CY), "got %ld\n", dst_len);
2293 ok(dst.int64 == 0, "didn't get 0\n");
2295 dst.int64 = 0xcc;
2296 dst_len = 0x1234;
2297 hr = IDataConvert_DataConvert(convert, DBTYPE_NULL, DBTYPE_CY, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2298 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr);
2299 ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status);
2300 ok(dst_len == 0x1234, "got %ld\n", dst_len);
2301 ok(dst.int64 == 0xcc, "dst changed\n");
2303 dst.int64 = 0xcc;
2304 *(int*)src = 1234;
2305 dst_len = 0x1234;
2306 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_CY, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2307 ok(hr == S_OK, "got %08x\n", hr);
2308 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2309 ok(dst_len == sizeof(CY), "got %ld\n", dst_len);
2310 ok(dst.int64 == 12340000, "got %d\n", dst.s.Lo);
2312 dst.int64 = 0xcc;
2313 ((CY*)src)->int64 = 1234;
2314 dst_len = 0x1234;
2315 hr = IDataConvert_DataConvert(convert, DBTYPE_CY, DBTYPE_CY, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2316 ok(hr == S_OK, "got %08x\n", hr);
2317 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2318 ok(dst_len == sizeof(CY), "got %ld\n", dst_len);
2319 ok(dst.int64 == 1234, "got %d\n", dst.s.Lo);
2322 static void test_converttoui8(void)
2324 HRESULT hr;
2325 ULARGE_INTEGER dst;
2326 BYTE src[20];
2327 DBSTATUS dst_status;
2328 DBLENGTH dst_len;
2330 dst.QuadPart = 0xcc;
2331 dst_len = 0x1234;
2332 hr = IDataConvert_DataConvert(convert, DBTYPE_EMPTY, DBTYPE_UI8, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2333 ok(hr == S_OK, "got %08x\n", hr);
2334 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2335 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2336 ok(dst.QuadPart == 0, "got %d\n", (int)dst.QuadPart);
2338 dst.QuadPart = 0xcc;
2339 dst_len = 0x1234;
2340 hr = IDataConvert_DataConvert(convert, DBTYPE_NULL, DBTYPE_UI8, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2341 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr);
2342 ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status);
2343 ok(dst_len == 0x1234, "got %ld\n", dst_len);
2344 ok(dst.QuadPart == 0xcc, "dst changed\n");
2346 dst.QuadPart = 0xcc;
2347 *(int*)src = 1234;
2348 dst_len = 0x1234;
2349 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_UI8, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2350 ok(hr == S_OK, "got %08x\n", hr);
2351 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2352 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2353 ok(dst.QuadPart == 1234, "got %d\n", (int)dst.QuadPart);
2355 dst.QuadPart = 0xcc;
2356 *(int*)src = -1234;
2357 dst_len = 0x1234;
2358 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_UI8, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2359 ok(hr == DB_E_ERRORSOCCURRED, "got %08x\n", hr);
2360 todo_wine
2361 ok(dst_status == DBSTATUS_E_SIGNMISMATCH, "got %08x\n", dst_status);
2362 todo_wine
2363 ok(dst_len == 0x1234, "got %ld\n", dst_len);
2364 ok(dst.QuadPart == 0xcc, "got %d\n", (int)dst.QuadPart);
2366 dst.QuadPart = 0xcc;
2367 ((ULARGE_INTEGER*)src)->QuadPart = 1234;
2368 dst_len = 0x1234;
2369 hr = IDataConvert_DataConvert(convert, DBTYPE_UI8, DBTYPE_UI8, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2370 ok(hr == S_OK, "got %08x\n", hr);
2371 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2372 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2373 ok(dst.QuadPart == 1234, "got %d\n", (int)dst.QuadPart);
2376 static void test_getconversionsize(void)
2378 DBLENGTH dst_len;
2379 DBLENGTH src_len;
2380 HRESULT hr;
2381 BSTR str;
2382 static WCHAR strW[] = {'t','e','s','t',0};
2383 static char strTest[] = "test";
2384 VARIANT var;
2385 SAFEARRAY *psa = NULL;
2386 SAFEARRAYBOUND rgsabound[1];
2388 /* same way as CanConvert fails here */
2389 dst_len = 0;
2390 hr = IDataConvert_GetConversionSize(convert, DBTYPE_NULL, DBTYPE_BSTR, NULL, &dst_len, NULL);
2391 ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got 0x%08x\n", hr);
2393 dst_len = 0;
2394 hr = IDataConvert_GetConversionSize(convert, DBTYPE_I2, DBTYPE_I4, NULL, &dst_len, NULL);
2395 ok(hr == S_OK, "got 0x%08x\n", hr);
2396 ok(dst_len == 4, "got %ld\n", dst_len);
2398 hr = IDataConvert_GetConversionSize(convert, DBTYPE_I2, DBTYPE_I4, NULL, NULL, NULL);
2399 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
2401 /* size doesn't include string size */
2402 str = SysAllocStringLen(NULL, 10);
2403 dst_len = 0;
2404 hr = IDataConvert_GetConversionSize(convert, DBTYPE_BSTR, DBTYPE_VARIANT, NULL, &dst_len, str);
2405 ok(hr == S_OK, "got 0x%08x\n", hr);
2406 ok(dst_len == sizeof(VARIANT), "%ld\n", dst_len);
2407 SysFreeString(str);
2409 dst_len = 0;
2410 hr = IDataConvert_GetConversionSize(convert, DBTYPE_WSTR, DBTYPE_WSTR, NULL, &dst_len, strW);
2411 ok(hr == S_OK, "got 0x%08x\n", hr);
2412 ok(dst_len == 10, "%ld\n", dst_len);
2414 dst_len = 0;
2415 src_len = 2;
2416 hr = IDataConvert_GetConversionSize(convert, DBTYPE_WSTR, DBTYPE_WSTR, &src_len, &dst_len, strW);
2417 ok(hr == S_OK, "got 0x%08x\n", hr);
2418 ok(dst_len == 4, "%ld\n", dst_len);
2420 dst_len = 0;
2421 src_len = 20;
2422 hr = IDataConvert_GetConversionSize(convert, DBTYPE_WSTR, DBTYPE_WSTR, &src_len, &dst_len, strW);
2423 ok(hr == S_OK, "got 0x%08x\n", hr);
2424 ok(dst_len == 22, "%ld\n", dst_len);
2426 dst_len = 0;
2427 hr = IDataConvert_GetConversionSize(convert, DBTYPE_STR, DBTYPE_WSTR, NULL, &dst_len, strTest);
2428 ok(hr == S_OK, "got 0x%08x\n", hr);
2429 ok(dst_len == 10 || broken(dst_len == 12), "%ld\n", dst_len);
2431 dst_len = 0;
2432 src_len = 2;
2433 hr = IDataConvert_GetConversionSize(convert, DBTYPE_STR, DBTYPE_WSTR, &src_len, &dst_len, strTest);
2434 ok(hr == S_OK, "got 0x%08x\n", hr);
2435 ok(dst_len == 6, "%ld\n", dst_len);
2437 dst_len = 0;
2438 src_len = 20;
2439 hr = IDataConvert_GetConversionSize(convert, DBTYPE_STR, DBTYPE_WSTR, &src_len, &dst_len, strTest);
2440 ok(hr == S_OK, "got 0x%08x\n", hr);
2441 ok(dst_len == 42, "%ld\n", dst_len);
2443 dst_len = 0;
2444 V_VT(&var) = VT_BSTR;
2445 V_BSTR(&var) = SysAllocString(strW);
2446 hr = IDataConvert_GetConversionSize(convert, DBTYPE_VARIANT, DBTYPE_WSTR, NULL, &dst_len, &var);
2447 ok(hr == S_OK, "got 0x%08x\n", hr);
2448 ok(dst_len == 10, "%ld\n", dst_len);
2449 VariantClear(&var);
2451 dst_len = 0;
2452 src_len = 20;
2453 V_VT(&var) = VT_BSTR;
2454 V_BSTR(&var) = SysAllocString(strW);
2455 hr = IDataConvert_GetConversionSize(convert, DBTYPE_VARIANT, DBTYPE_WSTR, &src_len, &dst_len, &var);
2456 ok(hr == S_OK, "got 0x%08x\n", hr);
2457 ok(dst_len == 10, "%ld\n", dst_len);
2458 VariantClear(&var);
2460 dst_len = 0;
2461 src_len = 20;
2462 V_VT(&var) = VT_I4;
2463 V_I4(&var) = 4;
2464 hr = IDataConvert_GetConversionSize(convert, DBTYPE_VARIANT, DBTYPE_WSTR, &src_len, &dst_len, &var);
2465 ok(hr == S_OK, "got 0x%08x\n", hr);
2466 VariantClear(&var);
2468 dst_len = 0;
2469 src_len = 20;
2470 V_VT(&var) = VT_BSTR;
2471 V_BSTR(&var) = SysAllocString(strW);
2472 hr = IDataConvert_GetConversionSize(convert, DBTYPE_VARIANT, DBTYPE_BYTES, &src_len, &dst_len, &var);
2473 ok(hr == S_OK, "got 0x%08x\n", hr);
2474 ok(dst_len == 2, "%ld\n", dst_len);
2475 VariantClear(&var);
2477 dst_len = 0;
2478 src_len = 20;
2479 V_VT(&var) = VT_NULL;
2480 hr = IDataConvert_GetConversionSize(convert, DBTYPE_VARIANT, DBTYPE_BYTES, &src_len, &dst_len, &var);
2481 ok(hr == S_OK, "got 0x%08x\n", hr);
2482 VariantClear(&var);
2484 dst_len = 0;
2485 src_len = 20;
2486 rgsabound[0].lLbound = 0;
2487 rgsabound[0].cElements = 1802;
2488 psa = SafeArrayCreate(VT_UI1,1,rgsabound);
2490 V_VT(&var) = VT_ARRAY|VT_UI1;
2491 V_ARRAY(&var) = psa;
2492 hr = IDataConvert_GetConversionSize(convert, DBTYPE_VARIANT, DBTYPE_BYTES, &src_len, &dst_len, &var);
2493 ok(hr == S_OK, "got 0x%08x\n", hr);
2494 ok(dst_len == 1802, "%ld\n", dst_len);
2495 VariantClear(&var);
2498 static void test_converttobytes(void)
2500 DBLENGTH dst_len;
2501 HRESULT hr;
2502 BYTE byte_src[] = {0, 1, 2, 4, 5};
2503 BYTE byte_dst[] = {0, 0, 0, 0, 0};
2504 BYTE dst[10] = {0};
2505 DBSTATUS dst_status;
2506 VARIANT v;
2507 SAFEARRAY *psa = NULL;
2508 SAFEARRAYBOUND rgsabound[1];
2510 dst_len = 0;
2511 hr = IDataConvert_DataConvert(convert, DBTYPE_BYTES, DBTYPE_BYTES, sizeof(byte_src), &dst_len, byte_src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2512 ok(hr == S_OK, "got %08x\n", hr);
2513 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2514 ok(dst_len == sizeof(byte_src), "got %ld\n", dst_len);
2515 ok(!memcmp(byte_src, dst, dst_len ), "bytes differ\n");
2517 dst_len = 0;
2518 hr = IDataConvert_DataConvert(convert, DBTYPE_BYTES, DBTYPE_BYTES, sizeof(byte_src), &dst_len, byte_src, &dst, 2, 0, &dst_status, 0, 0, 0);
2519 ok(hr == S_OK, "got %08x\n", hr);
2520 ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status);
2521 ok(dst_len == sizeof(byte_src), "got %ld\n", dst_len);
2522 ok(!memcmp(byte_src, dst, 2 ), "bytes differ\n");
2524 V_VT(&v) = VT_NULL;
2525 dst_len = 0;
2526 hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_BYTES, sizeof(v), &dst_len, &v, &dst, 2, 0, &dst_status, 0, 0, 0);
2527 ok(hr == S_OK, "got %08x\n", hr);
2528 ok(dst_status == DBSTATUS_S_ISNULL, "got %08x\n", dst_status);
2529 ok(dst_len == 0, "got %ld\n", dst_len);
2531 dst_len = 0;
2532 rgsabound[0].lLbound = 0;
2533 rgsabound[0].cElements = 4;
2534 psa = SafeArrayCreate(VT_UI1,1,rgsabound);
2536 V_VT(&v) = VT_ARRAY|VT_UI1;
2537 V_ARRAY(&v) = psa;
2538 hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_BYTES, sizeof(v), &dst_len, &v, &dst, 10, 0, &dst_status, 0, 0, 0);
2539 ok(hr == S_OK, "got 0x%08x\n", hr);
2540 ok(dst_len == 4, "%ld\n", dst_len);
2541 ok(!memcmp(byte_dst, dst, dst_len), "bytes differ\n");
2542 VariantClear(&v);
2546 static void test_converttobytesbyref(void)
2548 DBLENGTH dst_len;
2549 HRESULT hr;
2550 BYTE byte_src[] = {0, 1, 2, 4, 5};
2551 BYTE *dst;
2552 DBSTATUS dst_status;
2554 dst_len = 0;
2555 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);
2556 ok(hr == S_OK, "got %08x\n", hr);
2557 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2558 ok(dst_len == sizeof(byte_src), "got %ld\n", dst_len);
2559 ok(!memcmp(byte_src, dst, dst_len ), "bytes differ\n");
2560 CoTaskMemFree(dst);
2563 static void test_converttodbdate(void)
2565 DBLENGTH dst_len;
2566 HRESULT hr;
2567 static WCHAR strW[] = {'2','0','1','3','-','0','5','-','1','4',0};
2568 DBDATE ts = {2013, 5, 14};
2569 DBDATE dst;
2570 DBSTATUS dst_status;
2571 VARIANT var;
2572 BSTR bstr;
2574 dst_len = 0;
2575 hr = IDataConvert_DataConvert(convert, DBTYPE_DBDATE, DBTYPE_DBDATE, sizeof(ts), &dst_len, &ts, &dst, 2, 0, &dst_status, 0, 0, 0);
2576 ok(hr == S_OK, "got %08x\n", hr);
2577 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2578 ok(dst_len == sizeof(DBDATE), "got %ld\n", dst_len);
2579 ok(!memcmp(&ts, &dst, sizeof(DBDATE) ), "bytes differ\n");
2581 VariantInit(&var);
2582 V_VT(&var) = VT_DATE;
2583 V_DATE(&var) = 41408.086250;
2584 dst_len = 0;
2585 hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_DBDATE, sizeof(var), &dst_len, &var, &dst, 2, 0, &dst_status, 0, 0, 0);
2586 ok(hr == S_OK, "got %08x\n", hr);
2587 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2588 ok(dst_len == sizeof(DBDATE), "got %ld\n", dst_len);
2589 ok(!memcmp(&ts, &dst, sizeof(DBDATE) ), "bytes differ\n");
2591 dst_len = 0;
2592 bstr = SysAllocString(strW);
2593 hr = IDataConvert_DataConvert(convert, DBTYPE_BSTR, DBTYPE_DBDATE, 0, &dst_len, &bstr, &dst, 2, 0, &dst_status, 0, 0, 0);
2594 ok(hr == S_OK, "got %08x\n", hr);
2595 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2596 ok(dst_len == sizeof(DBDATE), "got %ld\n", dst_len);
2597 ok(!memcmp(&ts, &dst, sizeof(DBDATE) ), "bytes differ\n");
2598 SysFreeString(bstr);
2602 static void test_converttovar(void)
2604 static WCHAR strW[] = {'t','e','s','t',0};
2605 BYTE byte_src[5] = {1, 2, 3, 4, 5};
2606 DBTIMESTAMP ts = {2013, 5, 14, 2, 4, 12, 0};
2607 DBDATE dbdate = {2013, 5, 15};
2608 double dvalue = 123.56;
2609 DBSTATUS dst_status;
2610 DBLENGTH dst_len;
2611 VARIANT dst;
2612 HRESULT hr;
2613 CY cy, cy2;
2614 DATE date;
2615 INT i4;
2616 LARGE_INTEGER i8;
2617 VARIANT_BOOL boolean = VARIANT_TRUE;
2618 FLOAT fvalue = 543.21f;
2620 V_VT(&dst) = VT_EMPTY;
2621 dst_len = 0;
2622 dst_status = DBSTATUS_S_DEFAULT;
2623 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_VARIANT, sizeof(strW), &dst_len, strW, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2624 ok(hr == S_OK, "got %08x\n", hr);
2625 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2626 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2627 ok(V_VT(&dst) == VT_BSTR, "got %d\n", V_VT(&dst));
2628 ok(!lstrcmpW(V_BSTR(&dst), strW), "got %s\n", wine_dbgstr_w(V_BSTR(&dst)));
2629 VariantClear(&dst);
2631 /* with null dest length and status */
2632 V_VT(&dst) = VT_EMPTY;
2633 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_VARIANT, sizeof(strW), NULL, strW, &dst, sizeof(dst), 0, NULL, 0, 0, 0);
2634 ok(hr == S_OK, "got %08x\n", hr);
2635 ok(V_VT(&dst) == VT_BSTR, "got %d\n", V_VT(&dst));
2636 ok(!lstrcmpW(V_BSTR(&dst), strW), "got %s\n", wine_dbgstr_w(V_BSTR(&dst)));
2637 VariantClear(&dst);
2639 V_VT(&dst) = VT_EMPTY;
2640 dst_len = 0;
2641 dst_status = DBSTATUS_S_DEFAULT;
2642 i8.QuadPart = 12345;
2643 dst_len = 0x1234;
2644 hr = IDataConvert_DataConvert(convert, DBTYPE_I8, DBTYPE_VARIANT, sizeof(i8), &dst_len, &i8, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2645 ok(hr == S_OK, "got %08x\n", hr);
2646 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2647 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2648 ok(V_VT(&dst) == VT_DECIMAL, "got %d\n", V_VT(&dst));
2649 ok(S(U(V_DECIMAL(&dst))).scale == 0 && S(U(V_DECIMAL(&dst))).sign == 0 &&
2650 V_DECIMAL(&dst).Hi32 == 0 && U1(V_DECIMAL(&dst)).Lo64 == 12345, "Not Equal\n");
2652 V_VT(&dst) = VT_EMPTY;
2653 dst_len = 0;
2654 dst_status = DBSTATUS_S_DEFAULT;
2655 hr = IDataConvert_DataConvert(convert, DBTYPE_R4, DBTYPE_VARIANT, sizeof(fvalue), &dst_len, &fvalue, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2656 ok(hr == S_OK, "got %08x\n", hr);
2657 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2658 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2659 ok(V_VT(&dst) == VT_R4, "got %d\n", V_VT(&dst));
2660 ok(V_R4(&dst) == 543.21f, "got %f\n", V_R4(&dst));
2662 V_VT(&dst) = VT_EMPTY;
2663 dst_len = 0;
2664 dst_status = DBSTATUS_S_DEFAULT;
2665 hr = IDataConvert_DataConvert(convert, DBTYPE_R8, DBTYPE_VARIANT, sizeof(dvalue), &dst_len, &dvalue, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2666 ok(hr == S_OK, "got %08x\n", hr);
2667 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2668 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2669 ok(V_VT(&dst) == VT_R8, "got %d\n", V_VT(&dst));
2670 ok(V_R8(&dst) == 123.56, "got %f\n", V_R8(&dst));
2672 V_VT(&dst) = VT_EMPTY;
2673 dst_len = 0;
2674 dst_status = DBSTATUS_S_DEFAULT;
2675 hr = IDataConvert_DataConvert(convert, DBTYPE_BOOL, DBTYPE_VARIANT, sizeof(boolean), &dst_len, &boolean, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2676 ok(hr == S_OK, "got %08x\n", hr);
2677 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2678 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2679 ok(V_VT(&dst) == VT_BOOL, "got %d\n", V_VT(&dst));
2680 ok(V_BOOL(&dst) == VARIANT_TRUE, "got %d\n", V_BOOL(&dst));
2682 V_VT(&dst) = VT_EMPTY;
2683 dst_len = 0;
2684 dst_status = DBSTATUS_S_DEFAULT;
2685 i4 = 123;
2686 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_VARIANT, sizeof(i4), &dst_len, &i4, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2687 ok(hr == S_OK, "got %08x\n", hr);
2688 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2689 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2690 ok(V_VT(&dst) == VT_I4, "got %d\n", V_VT(&dst));
2691 ok(V_I4(&dst) == 123, "got %d\n", V_I4(&dst));
2693 V_VT(&dst) = VT_EMPTY;
2694 dst_len = 0;
2695 dst_status = DBSTATUS_S_DEFAULT;
2696 date = 123.123;
2697 hr = IDataConvert_DataConvert(convert, DBTYPE_DATE, DBTYPE_VARIANT, sizeof(date), &dst_len, &date, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2698 ok(hr == S_OK, "got %08x\n", hr);
2699 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2700 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2701 ok(V_VT(&dst) == VT_DATE, "got %d\n", V_VT(&dst));
2702 ok(V_DATE(&dst) == 123.123, "got %f\n", V_DATE(&dst));
2704 V_VT(&dst) = VT_EMPTY;
2705 dst_len = 0;
2706 dst_status = DBSTATUS_S_DEFAULT;
2707 S(cy).Lo = 1;
2708 S(cy).Hi = 2;
2709 hr = IDataConvert_DataConvert(convert, DBTYPE_CY, DBTYPE_VARIANT, sizeof(cy), &dst_len, &cy, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2710 ok(hr == S_OK, "got %08x\n", hr);
2711 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2712 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2713 ok(V_VT(&dst) == VT_CY, "got %d\n", V_VT(&dst));
2715 cy2 = V_CY(&dst);
2716 ok(S(cy2).Lo == S(cy).Lo && S(cy2).Hi == S(cy).Hi, "got %d,%d\n", S(cy2).Lo, S(cy2).Hi);
2718 dst_len = 0x1234;
2719 hr = IDataConvert_DataConvert(convert, DBTYPE_BYTES, DBTYPE_VARIANT, sizeof(byte_src), &dst_len, &byte_src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2720 ok(hr == S_OK, "got %08x\n", hr);
2721 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2722 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2723 ok(V_VT(&dst) == (VT_ARRAY|VT_UI1), "got %d\n", V_VT(&dst));
2724 if(V_VT(&dst) == (VT_ARRAY|VT_UI1))
2726 LONG l;
2728 hr = SafeArrayGetUBound(V_ARRAY(&dst), 1, &l);
2729 ok(hr == S_OK, "got %08x\n", hr);
2730 ok(l == 4, "got %d\n", l); /* 5 elements */
2732 VariantClear(&dst);
2734 dst_len = 0x1234;
2735 hr = IDataConvert_DataConvert(convert, DBTYPE_BYTES, DBTYPE_VARIANT, 0, &dst_len, &byte_src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2736 ok(hr == S_OK, "got %08x\n", hr);
2737 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2738 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2739 ok(V_VT(&dst) == (VT_ARRAY|VT_UI1), "got %d\n", V_VT(&dst));
2740 if(V_VT(&dst) == (VT_ARRAY|VT_UI1))
2742 LONG l;
2744 hr = SafeArrayGetUBound(V_ARRAY(&dst), 1, &l);
2745 ok(hr == S_OK, "got %08x\n", hr);
2746 ok(l == -1, "got %d\n", l); /* 0 elements */
2748 VariantClear(&dst);
2750 dst_len = 0x1234;
2751 hr = IDataConvert_DataConvert(convert, DBTYPE_BYTES, DBTYPE_VARIANT, 2, &dst_len, &byte_src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2752 ok(hr == S_OK, "got %08x\n", hr);
2753 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2754 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2755 ok(V_VT(&dst) == (VT_ARRAY|VT_UI1), "got %d\n", V_VT(&dst));
2756 if(V_VT(&dst) == (VT_ARRAY|VT_UI1))
2758 LONG l;
2760 hr = SafeArrayGetUBound(V_ARRAY(&dst), 1, &l);
2761 ok(hr == S_OK, "got %08x\n", hr);
2762 ok(l == 1, "got %d\n", l); /* 2 elements */
2764 VariantClear(&dst);
2766 dst_len = 0x1234;
2767 hr = IDataConvert_DataConvert(convert, DBTYPE_DBTIMESTAMP, DBTYPE_VARIANT, 0, &dst_len, &ts, &dst, sizeof(ts), 0, &dst_status, 0, 0, 0);
2768 ok(hr == S_OK, "got %08x\n", hr);
2769 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2770 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2771 ok(V_VT(&dst) == VT_DATE, "got %d\n", V_VT(&dst));
2772 ok( (float)V_DATE(&dst) == 41408.086250f, "got %f\n", V_DATE(&dst));
2774 dst_len = 0x1234;
2775 hr = IDataConvert_DataConvert(convert, DBTYPE_DBDATE, DBTYPE_VARIANT, 0, &dst_len, &dbdate, &dst, sizeof(dbdate), 0, &dst_status, 0, 0, 0);
2776 ok(hr == S_OK, "got %08x\n", hr);
2777 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2778 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2779 ok(V_VT(&dst) == VT_DATE, "got %d\n", V_VT(&dst));
2780 ok( (float)V_DATE(&dst) == 41409.0, "got %f\n", V_DATE(&dst));
2782 /* src_status = DBSTATUS_S_ISNULL */
2783 i4 = 123;
2784 hr = IDataConvert_DataConvert(convert, DBTYPE_I4, DBTYPE_VARIANT, sizeof(i4), &dst_len, &i4, &dst, sizeof(dst), DBSTATUS_S_ISNULL, &dst_status, 0, 0, 0);
2785 ok(hr == S_OK, "got %08x\n", hr);
2786 ok(dst_status == DBSTATUS_S_ISNULL, "got %08x\n", dst_status);
2787 ok(dst_len == 0, "got %ld\n", dst_len);
2791 static void test_converttotimestamp(void)
2793 static const WCHAR strW[] = {'2','0','1','3','-','0','5','-','1','4',' ','0','2',':','0','4',':','1','2',0};
2794 DBTIMESTAMP ts = {2013, 5, 14, 2, 4, 12, 0};
2795 DBTIMESTAMP dst;
2796 DBSTATUS dst_status;
2797 DBLENGTH dst_len;
2798 VARIANT var;
2799 HRESULT hr;
2800 BSTR bstr;
2802 VariantInit(&var);
2803 V_VT(&var) = VT_DATE;
2804 V_DATE(&var) = 41408.086250;
2805 dst_len = 0x1234;
2806 hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_DBTIMESTAMP, 0, &dst_len, &var, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2807 ok(hr == S_OK, "got %08x\n", hr);
2808 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2809 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2810 ok(!memcmp(&ts, &dst, sizeof(ts)), "Wrong timestamp\n");
2812 bstr = SysAllocString(strW);
2813 dst_len = 0x1234;
2814 hr = IDataConvert_DataConvert(convert, DBTYPE_BSTR, DBTYPE_DBTIMESTAMP, 0, &dst_len, &bstr, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
2815 ok(hr == S_OK, "got %08x\n", hr);
2816 ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
2817 ok(dst_len == sizeof(dst), "got %ld\n", dst_len);
2818 ok(!memcmp(&ts, &dst, sizeof(ts)), "Wrong timestamp\n");
2819 SysFreeString(bstr);
2822 static void test_converttoiunknown(void)
2824 HRESULT hr;
2825 DBSTATUS dst_status;
2826 DBLENGTH dst_len;
2827 IUnknown *dst = NULL;
2828 static WCHAR strW[] = {'t','e','s','t',0};
2830 dst_len = 0x1234;
2831 hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_IUNKNOWN, sizeof(strW), &dst_len, strW, dst, sizeof(dst), DBSTATUS_S_ISNULL, &dst_status, 0, 0, 0);
2832 ok(hr == S_OK, "got %08x\n", hr);
2833 ok(dst_status == DBSTATUS_S_ISNULL, "got %08x\n", dst_status);
2834 ok(dst_len == 0, "got %ld\n", dst_len);
2837 START_TEST(convert)
2839 HRESULT hr;
2841 OleInitialize(NULL);
2843 test_dcinfo();
2845 hr = CoCreateInstance(&CLSID_OLEDB_CONVERSIONLIBRARY, NULL, CLSCTX_INPROC_SERVER, &IID_IDataConvert, (void**)&convert);
2846 if(FAILED(hr))
2848 win_skip("Unable to create IDataConvert instance, 0x%08x\n", hr);
2849 OleUninitialize();
2850 return;
2853 test_canconvert();
2854 test_converttoi2();
2855 test_converttoi4();
2856 test_converttoi8();
2857 test_converttostr();
2858 test_converttobstr();
2859 test_converttowstr();
2860 test_converttobyrefwstr();
2861 test_converttoguid();
2862 test_converttoui1();
2863 test_converttoui4();
2864 test_converttor4();
2865 test_converttofiletime();
2866 test_converttocy();
2867 test_converttoui8();
2868 test_converttovar();
2869 test_converttobytes();
2870 test_converttobytesbyref();
2871 test_converttodbdate();
2872 test_getconversionsize();
2873 test_converttotimestamp();
2874 test_converttoiunknown();
2876 IDataConvert_Release(convert);
2878 OleUninitialize();