2 * Copyright 2019 Hans Leidekker for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include <msado15_backcompat.h>
24 #include "wine/test.h"
26 #define MAKE_ADO_HRESULT( err ) MAKE_HRESULT( SEVERITY_ERROR, FACILITY_CONTROL, err )
28 static BOOL
is_bof( _Recordset
*recordset
)
30 VARIANT_BOOL bof
= VARIANT_FALSE
;
31 _Recordset_get_BOF( recordset
, &bof
);
32 return bof
== VARIANT_TRUE
;
35 static BOOL
is_eof( _Recordset
*recordset
)
37 VARIANT_BOOL eof
= VARIANT_FALSE
;
38 _Recordset_get_EOF( recordset
, &eof
);
39 return eof
== VARIANT_TRUE
;
42 static LONG
get_refs_field( Field
*field
)
44 Field_AddRef( field
);
45 return Field_Release( field
);
48 static LONG
get_refs_fields( Fields
*fields
)
50 Fields_AddRef( fields
);
51 return Fields_Release( fields
);
54 static LONG
get_refs_recordset( _Recordset
*recordset
)
56 _Recordset_AddRef( recordset
);
57 return _Recordset_Release( recordset
);
60 static void test_Recordset(void)
62 _Recordset
*recordset
;
63 ISupportErrorInfo
*errorinfo
;
64 Fields
*fields
, *fields2
;
66 LONG refs
, count
, state
;
67 VARIANT missing
, val
, index
;
71 hr
= CoCreateInstance( &CLSID_Recordset
, NULL
, CLSCTX_INPROC_SERVER
, &IID__Recordset
, (void **)&recordset
);
72 ok( hr
== S_OK
, "got %08x\n", hr
);
74 /* _Recordset object supports ISupportErrorInfo */
76 hr
= _Recordset_QueryInterface( recordset
, &IID_ISupportErrorInfo
, (void **)&errorinfo
);
77 ok( hr
== S_OK
, "got %08x\n", hr
);
78 refs
= get_refs_recordset( recordset
);
79 ok( refs
== 2, "got %d\n", refs
);
80 if (errorinfo
) ISupportErrorInfo_Release( errorinfo
);
81 refs
= get_refs_recordset( recordset
);
82 ok( refs
== 1, "got %d\n", refs
);
84 /* handing out fields object increases recordset refcount */
85 refs
= get_refs_recordset( recordset
);
86 ok( refs
== 1, "got %d\n", refs
);
87 hr
= _Recordset_get_Fields( recordset
, &fields
);
88 ok( hr
== S_OK
, "got %08x\n", hr
);
89 refs
= get_refs_recordset( recordset
);
90 ok( refs
== 2, "got %d\n", refs
);
91 refs
= get_refs_fields( fields
);
92 ok( refs
== 1, "got %d\n", refs
);
94 /* releasing fields object decreases recordset refcount, but fields refcount doesn't drop to zero */
95 Fields_Release( fields
);
96 refs
= get_refs_recordset( recordset
);
97 ok( refs
== 1, "got %d\n", refs
);
98 refs
= get_refs_fields( fields
);
99 ok( refs
== 1, "got %d\n", refs
);
101 /* calling get_Fields again returns the same object with the same refcount and increases recordset refcount */
102 hr
= _Recordset_get_Fields( recordset
, &fields2
);
103 ok( hr
== S_OK
, "got %08x\n", hr
);
104 refs
= get_refs_recordset( recordset
);
105 ok( refs
== 2, "got %d\n", refs
);
106 refs
= get_refs_fields( fields2
);
107 ok( refs
== 1, "got %d\n", refs
);
108 ok( fields2
== fields
, "expected same object\n" );
109 refs
= Fields_Release( fields2
);
110 ok( refs
== 1, "got %d\n", refs
);
113 hr
= Fields_get_Count( fields2
, &count
);
114 ok( hr
== S_OK
, "got %08x\n", hr
);
115 ok( !count
, "got %d\n", count
);
117 hr
= _Recordset_Close( recordset
);
118 ok( hr
== MAKE_ADO_HRESULT( adErrObjectClosed
), "got %08x\n", hr
);
120 refs
= _Recordset_Release( recordset
);
121 ok( !refs
, "got %d\n", refs
);
123 /* fields object still has a reference */
124 refs
= Fields_Release( fields2
);
125 ok( refs
== 1, "got %d\n", refs
);
127 hr
= CoCreateInstance( &CLSID_Recordset
, NULL
, CLSCTX_INPROC_SERVER
, &IID__Recordset
, (void **)&recordset
);
128 ok( hr
== S_OK
, "got %08x\n", hr
);
131 hr
= _Recordset_get_State( recordset
, &state
);
132 ok( hr
== S_OK
, "got %08x\n", hr
);
133 ok( state
== adStateClosed
, "got %d\n", state
);
135 VariantInit( &missing
);
136 hr
= _Recordset_AddNew( recordset
, missing
, missing
);
137 ok( hr
== MAKE_ADO_HRESULT( adErrObjectClosed
), "got %08x\n", hr
);
139 V_VT( &missing
) = VT_ERROR
;
140 V_ERROR( &missing
) = DISP_E_PARAMNOTFOUND
;
141 hr
= _Recordset_Open( recordset
, missing
, missing
, adOpenStatic
, adLockBatchOptimistic
, adCmdUnspecified
);
142 ok( hr
== MAKE_ADO_HRESULT( adErrInvalidConnection
), "got %08x\n", hr
);
144 hr
= _Recordset_get_Fields( recordset
, &fields
);
145 ok( hr
== S_OK
, "got %08x\n", hr
);
147 name
= SysAllocString( L
"field" );
148 hr
= Fields__Append( fields
, name
, adInteger
, 4, adFldUnspecified
);
149 ok( hr
== S_OK
, "got %08x\n", hr
);
151 V_VT( &index
) = VT_BSTR
;
152 V_BSTR( &index
) = name
;
153 hr
= Fields_get_Item( fields
, index
, &field
);
154 ok( hr
== S_OK
, "got %08x\n", hr
);
155 SysFreeString( name
);
157 hr
= _Recordset_Open( recordset
, missing
, missing
, adOpenStatic
, adLockBatchOptimistic
, adCmdUnspecified
);
158 ok( hr
== S_OK
, "got %08x\n", hr
);
159 ok( is_eof( recordset
), "not eof\n" );
160 ok( is_bof( recordset
), "not bof\n" );
162 hr
= _Recordset_Open( recordset
, missing
, missing
, adOpenStatic
, adLockBatchOptimistic
, adCmdUnspecified
);
163 ok( hr
== MAKE_ADO_HRESULT( adErrObjectOpen
), "got %08x\n", hr
);
166 hr
= _Recordset_get_State( recordset
, &state
);
167 ok( hr
== S_OK
, "got %08x\n", hr
);
168 ok( state
== adStateOpen
, "got %d\n", state
);
171 hr
= _Recordset_get_RecordCount( recordset
, &count
);
172 ok( hr
== S_OK
, "got %08x\n", hr
);
173 ok( !count
, "got %d\n", count
);
175 hr
= _Recordset_AddNew( recordset
, missing
, missing
);
176 ok( hr
== S_OK
, "got %08x\n", hr
);
177 ok( !is_eof( recordset
), "eof\n" );
178 ok( !is_bof( recordset
), "bof\n" );
181 hr
= _Recordset_get_RecordCount( recordset
, &count
);
182 ok( hr
== S_OK
, "got %08x\n", hr
);
183 ok( count
== 1, "got %d\n", count
);
185 /* get_Fields still returns the same object */
186 hr
= _Recordset_get_Fields( recordset
, &fields2
);
187 ok( hr
== S_OK
, "got %08x\n", hr
);
188 ok( fields2
== fields
, "expected same object\n" );
189 Fields_Release( fields2
);
192 hr
= Fields_get_Count( fields2
, &count
);
193 ok( count
== 1, "got %d\n", count
);
195 hr
= Field_get_Value( field
, &val
);
196 ok( hr
== S_OK
, "got %08x\n", hr
);
197 ok( V_VT( &val
) == VT_EMPTY
, "got %u\n", V_VT( &val
) );
199 V_VT( &val
) = VT_I4
;
201 hr
= Field_put_Value( field
, val
);
202 ok( hr
== S_OK
, "got %08x\n", hr
);
204 V_VT( &val
) = VT_ERROR
;
205 V_ERROR( &val
) = DISP_E_PARAMNOTFOUND
;
206 hr
= Field_get_Value( field
, &val
);
207 ok( hr
== S_OK
, "got %08x\n", hr
);
208 ok( V_VT( &val
) == VT_I4
, "got %u\n", V_VT( &val
) );
209 ok( V_I4( &val
) == -1, "got %d\n", V_I4( &val
) );
211 hr
= _Recordset_AddNew( recordset
, missing
, missing
);
212 ok( hr
== S_OK
, "got %08x\n", hr
);
214 /* field object returns different value after AddNew */
215 V_VT( &val
) = VT_ERROR
;
216 V_ERROR( &val
) = DISP_E_PARAMNOTFOUND
;
217 hr
= Field_get_Value( field
, &val
);
218 ok( hr
== S_OK
, "got %08x\n", hr
);
219 ok( V_VT( &val
) == VT_EMPTY
, "got %u\n", V_VT( &val
) );
221 ok( !is_eof( recordset
), "eof\n" );
222 ok( !is_bof( recordset
), "bof\n" );
223 hr
= _Recordset_MoveFirst( recordset
);
224 ok( hr
== S_OK
, "got %08x\n", hr
);
225 ok( !is_eof( recordset
), "eof\n" );
226 ok( !is_bof( recordset
), "bof\n" );
228 V_VT( &val
) = VT_ERROR
;
229 V_ERROR( &val
) = DISP_E_PARAMNOTFOUND
;
230 hr
= Field_get_Value( field
, &val
);
231 ok( hr
== S_OK
, "got %08x\n", hr
);
232 ok( V_VT( &val
) == VT_I4
, "got %u\n", V_VT( &val
) );
233 ok( V_I4( &val
) == -1, "got %d\n", V_I4( &val
) );
235 hr
= _Recordset_MoveNext( recordset
);
236 ok( hr
== S_OK
, "got %08x\n", hr
);
237 ok( !is_eof( recordset
), "eof\n" );
238 ok( !is_bof( recordset
), "not bof\n" );
240 hr
= _Recordset_MoveNext( recordset
);
241 ok( hr
== S_OK
, "got %08x\n", hr
);
242 ok( is_eof( recordset
), "not eof\n" );
243 ok( !is_bof( recordset
), "bof\n" );
245 hr
= _Recordset_MoveFirst( recordset
);
246 ok( hr
== S_OK
, "got %08x\n", hr
);
247 ok( !is_eof( recordset
), "eof\n" );
248 ok( !is_bof( recordset
), "bof\n" );
250 hr
= _Recordset_MovePrevious( recordset
);
251 ok( hr
== S_OK
, "got %08x\n", hr
);
252 ok( !is_eof( recordset
), "eof\n" );
253 ok( is_bof( recordset
), "not bof\n" );
255 /* try get value at BOF */
257 hr
= Field_get_Value( field
, &val
);
258 ok( hr
== MAKE_ADO_HRESULT( adErrNoCurrentRecord
), "got %08x\n", hr
);
260 hr
= _Recordset_Close( recordset
);
261 ok( hr
== S_OK
, "got %08x\n", hr
);
264 hr
= _Recordset_get_State( recordset
, &state
);
265 ok( hr
== S_OK
, "got %08x\n", hr
);
266 ok( state
== adStateClosed
, "got %d\n", state
);
268 Field_Release( field
);
269 Fields_Release( fields
);
270 _Recordset_Release( recordset
);
273 static void test_Fields(void)
275 _Recordset
*recordset
;
276 ISupportErrorInfo
*errorinfo
;
278 Field
*field
, *field2
;
281 LONG refs
, count
, size
;
283 FieldAttributeEnum attrs
;
286 hr
= CoCreateInstance( &CLSID_Recordset
, NULL
, CLSCTX_INPROC_SERVER
, &IID__Recordset
, (void **)&recordset
);
287 ok( hr
== S_OK
, "got %08x\n", hr
);
289 hr
= _Recordset_get_Fields( recordset
, &fields
);
290 ok( hr
== S_OK
, "got %08x\n", hr
);
292 /* Fields object supports ISupportErrorInfo */
294 hr
= Fields_QueryInterface( fields
, &IID_ISupportErrorInfo
, (void **)&errorinfo
);
295 ok( hr
== S_OK
, "got %08x\n", hr
);
296 refs
= get_refs_fields( fields
);
297 ok( refs
== 2, "got %d\n", refs
);
298 if (errorinfo
) ISupportErrorInfo_Release( errorinfo
);
299 refs
= get_refs_fields( fields
);
300 ok( refs
== 1, "got %d\n", refs
);
303 hr
= Fields_get_Count( fields
, &count
);
304 ok( !count
, "got %d\n", count
);
306 name
= SysAllocString( L
"field" );
307 V_VT( &val
) = VT_ERROR
;
308 V_ERROR( &val
) = DISP_E_PARAMNOTFOUND
;
309 hr
= Fields_Append( fields
, name
, adInteger
, 4, adFldUnspecified
, val
);
310 ok( hr
== S_OK
, "got %08x\n", hr
);
311 SysFreeString( name
);
314 hr
= Fields_get_Count( fields
, &count
);
315 ok( count
== 1, "got %d\n", count
);
317 name
= SysAllocString( L
"field2" );
318 hr
= Fields__Append( fields
, name
, adInteger
, 4, adFldUnspecified
);
319 ok( hr
== S_OK
, "got %08x\n", hr
);
320 SysFreeString( name
);
323 hr
= Fields_get_Count( fields
, &count
);
324 ok( count
== 2, "got %d\n", count
);
326 /* handing out field object doesn't add reference to fields or recordset object */
327 name
= SysAllocString( L
"field" );
328 V_VT( &index
) = VT_BSTR
;
329 V_BSTR( &index
) = name
;
330 refs
= get_refs_recordset( recordset
);
331 ok( refs
== 2, "got %d\n", refs
);
332 refs
= get_refs_fields( fields
);
333 ok( refs
== 1, "got %d\n", refs
);
334 hr
= Fields_get_Item( fields
, index
, &field
);
335 ok( hr
== S_OK
, "got %08x\n", hr
);
336 refs
= get_refs_field( field
);
337 ok( refs
== 1, "got %d\n", refs
);
338 refs
= get_refs_recordset( recordset
);
339 ok( refs
== 2, "got %d\n", refs
);
340 refs
= get_refs_fields( fields
);
341 ok( refs
== 1, "got %d\n", refs
);
343 /* calling get_Item again returns the same object and adds reference */
344 hr
= Fields_get_Item( fields
, index
, &field2
);
345 ok( hr
== S_OK
, "got %08x\n", hr
);
346 ok( field2
== field
, "expected same object\n" );
347 refs
= get_refs_field( field2
);
348 ok( refs
== 2, "got %d\n", refs
);
349 refs
= get_refs_recordset( recordset
);
350 ok( refs
== 2, "got %d\n", refs
);
351 refs
= get_refs_fields( fields
);
352 ok( refs
== 1, "got %d\n", refs
);
353 Field_Release( field2
);
354 SysFreeString( name
);
356 /* Field object supports ISupportErrorInfo */
358 hr
= Field_QueryInterface( field
, &IID_ISupportErrorInfo
, (void **)&errorinfo
);
359 ok( hr
== S_OK
, "got %08x\n", hr
);
360 refs
= get_refs_field( field
);
361 ok( refs
== 2, "got %d\n", refs
);
362 if (errorinfo
) ISupportErrorInfo_Release( errorinfo
);
363 refs
= get_refs_field( field
);
364 ok( refs
== 1, "got %d\n", refs
);
366 /* verify values set with _Append */
367 hr
= Field_get_Name( field
, &name
);
368 ok( hr
== S_OK
, "got %08x\n", hr
);
369 ok( !lstrcmpW( name
, L
"field" ), "got %s\n", wine_dbgstr_w(name
) );
370 SysFreeString( name
);
372 hr
= Field_get_Type( field
, &type
);
373 ok( hr
== S_OK
, "got %08x\n", hr
);
374 ok( type
== adInteger
, "got %d\n", type
);
376 hr
= Field_get_DefinedSize( field
, &size
);
377 ok( hr
== S_OK
, "got %08x\n", hr
);
378 ok( size
== 4, "got %d\n", size
);
380 hr
= Field_get_Attributes( field
, &attrs
);
381 ok( hr
== S_OK
, "got %08x\n", hr
);
382 ok( !attrs
, "got %d\n", attrs
);
384 Field_Release( field
);
385 Fields_Release( fields
);
386 _Recordset_Release( recordset
);
389 static HRESULT
str_to_byte_array( const char *data
, VARIANT
*ret
)
392 LONG i
, len
= strlen(data
);
395 if (!(vector
= SafeArrayCreateVector( VT_UI1
, 0, len
))) return E_OUTOFMEMORY
;
396 for (i
= 0; i
< len
; i
++)
398 if ((hr
= SafeArrayPutElement( vector
, &i
, (void *)&data
[i
] )) != S_OK
)
400 SafeArrayDestroy( vector
);
405 V_VT( ret
) = VT_ARRAY
| VT_UI1
;
406 V_ARRAY( ret
) = vector
;
410 static void test_Stream(void)
415 LineSeparatorEnum sep
;
416 LONG refs
, size
, pos
;
417 ObjectStateEnum state
;
418 ConnectModeEnum mode
;
420 VARIANT missing
, val
;
423 hr
= CoCreateInstance( &CLSID_Stream
, NULL
, CLSCTX_INPROC_SERVER
, &IID__Stream
, (void **)&stream
);
424 ok( hr
== S_OK
, "got %08x\n", hr
);
426 hr
= _Stream_get_Size( stream
, &size
);
427 ok( hr
== MAKE_ADO_HRESULT( adErrObjectClosed
), "got %08x\n", hr
);
429 hr
= _Stream_get_EOS( stream
, &eos
);
430 ok( hr
== MAKE_ADO_HRESULT( adErrObjectClosed
), "got %08x\n", hr
);
432 hr
= _Stream_get_Position( stream
, &pos
);
433 ok( hr
== MAKE_ADO_HRESULT( adErrObjectClosed
), "got %08x\n", hr
);
435 hr
= _Stream_put_Position( stream
, 0 );
436 ok( hr
== MAKE_ADO_HRESULT( adErrObjectClosed
), "got %08x\n", hr
);
438 /* check default type */
440 hr
= _Stream_get_Type( stream
, &type
);
441 ok( hr
== S_OK
, "got %08x\n", hr
);
442 ok( type
== adTypeText
, "got %u\n", type
);
444 hr
= _Stream_put_Type( stream
, adTypeBinary
);
445 ok( hr
== S_OK
, "got %08x\n", hr
);
448 hr
= _Stream_get_Type( stream
, &type
);
449 ok( hr
== S_OK
, "got %08x\n", hr
);
450 ok( type
== adTypeBinary
, "got %u\n", type
);
453 hr
= _Stream_put_Type( stream
, adTypeText
);
454 ok( hr
== S_OK
, "got %08x\n", hr
);
457 hr
= _Stream_get_LineSeparator( stream
, &sep
);
458 ok( hr
== S_OK
, "got %08x\n", hr
);
459 ok( sep
== adCRLF
, "got %d\n", sep
);
461 hr
= _Stream_put_LineSeparator( stream
, adLF
);
462 ok( hr
== S_OK
, "got %08x\n", hr
);
465 hr
= _Stream_get_State( stream
, &state
);
466 ok( hr
== S_OK
, "got %08x\n", hr
);
467 ok( state
== adStateClosed
, "got %u\n", state
);
470 hr
= _Stream_get_Mode( stream
, &mode
);
471 ok( hr
== S_OK
, "got %08x\n", hr
);
472 ok( mode
== adModeUnknown
, "got %u\n", mode
);
474 hr
= _Stream_put_Mode( stream
, adModeReadWrite
);
475 ok( hr
== S_OK
, "got %08x\n", hr
);
477 hr
= _Stream_get_Charset( stream
, &charset
);
478 ok( hr
== S_OK
, "got %08x\n", hr
);
479 ok( !lstrcmpW( charset
, L
"Unicode" ), "got %s\n", wine_dbgstr_w(charset
) );
480 SysFreeString( charset
);
482 str
= SysAllocString( L
"Unicode" );
483 hr
= _Stream_put_Charset( stream
, str
);
484 ok( hr
== S_OK
, "got %08x\n", hr
);
485 SysFreeString( str
);
487 hr
= _Stream_Read( stream
, 2, &val
);
488 ok( hr
== MAKE_ADO_HRESULT( adErrObjectClosed
), "got %08x\n", hr
);
490 V_VT( &missing
) = VT_ERROR
;
491 V_ERROR( &missing
) = DISP_E_PARAMNOTFOUND
;
492 hr
= _Stream_Open( stream
, missing
, adModeUnknown
, adOpenStreamUnspecified
, NULL
, NULL
);
493 ok( hr
== S_OK
, "got %08x\n", hr
);
495 hr
= _Stream_Open( stream
, missing
, adModeUnknown
, adOpenStreamUnspecified
, NULL
, NULL
);
496 ok( hr
== MAKE_ADO_HRESULT( adErrObjectOpen
), "got %08x\n", hr
);
499 hr
= _Stream_get_State( stream
, &state
);
500 ok( hr
== S_OK
, "got %08x\n", hr
);
501 ok( state
== adStateOpen
, "got %u\n", state
);
504 hr
= _Stream_get_Size( stream
, &size
);
505 ok( hr
== S_OK
, "got %08x\n", hr
);
506 ok( !size
, "got %d\n", size
);
509 hr
= _Stream_get_EOS( stream
, &eos
);
510 ok( hr
== S_OK
, "got %08x\n", hr
);
511 ok( eos
== VARIANT_TRUE
, "got %04x\n", eos
);
514 hr
= _Stream_get_Position( stream
, &pos
);
515 ok( hr
== S_OK
, "got %08x\n", hr
);
516 ok( !pos
, "got %d\n", pos
);
519 hr
= _Stream_get_Size( stream
, &size
);
520 ok( hr
== S_OK
, "got %08x\n", hr
);
521 ok( !size
, "got %d\n", size
);
523 hr
= _Stream_Read( stream
, 2, &val
);
524 ok( hr
== MAKE_ADO_HRESULT( adErrIllegalOperation
), "got %08x\n", hr
);
526 hr
= _Stream_ReadText( stream
, 2, &str
);
527 ok( hr
== S_OK
, "got %08x\n", hr
);
528 ok( !str
[0], "got %s\n", wine_dbgstr_w(str
) );
529 SysFreeString( str
);
532 hr
= _Stream_get_Position( stream
, &pos
);
533 ok( hr
== S_OK
, "got %08x\n", hr
);
534 ok( !pos
, "got %d\n", pos
);
536 str
= SysAllocString( L
"test" );
537 hr
= _Stream_WriteText( stream
, str
, adWriteChar
);
538 ok( hr
== S_OK
, "got %08x\n", hr
);
539 SysFreeString( str
);
541 hr
= _Stream_ReadText( stream
, adReadAll
, &str
);
542 ok( hr
== S_OK
, "got %08x\n", hr
);
543 ok( !str
[0], "got %s\n", wine_dbgstr_w(str
) );
544 SysFreeString( str
);
546 hr
= _Stream_put_Position( stream
, 0 );
547 ok( hr
== S_OK
, "got %08x\n", hr
);
548 hr
= _Stream_ReadText( stream
, adReadAll
, &str
);
549 ok( hr
== S_OK
, "got %08x\n", hr
);
550 ok( !lstrcmpW( str
, L
"test" ), "got %s\n", wine_dbgstr_w(str
) );
551 SysFreeString( str
);
554 hr
= _Stream_get_Position( stream
, &pos
);
555 ok( hr
== S_OK
, "got %08x\n", hr
);
556 ok( pos
== 10, "got %d\n", pos
);
559 hr
= _Stream_get_EOS( stream
, &eos
);
560 ok( hr
== S_OK
, "got %08x\n", hr
);
561 ok( eos
== VARIANT_TRUE
, "got %04x\n", eos
);
563 hr
= _Stream_put_Position( stream
, 6 );
564 ok( hr
== S_OK
, "got %08x\n", hr
);
567 hr
= _Stream_get_Size( stream
, &size
);
568 ok( hr
== S_OK
, "got %08x\n", hr
);
569 ok( size
== 10, "got %d\n", size
);
571 hr
= _Stream_put_Position( stream
, 2 );
572 ok( hr
== S_OK
, "got %08x\n", hr
);
574 hr
= _Stream_SetEOS( stream
);
575 ok( hr
== S_OK
, "got %08x\n", hr
);
578 hr
= _Stream_get_Position( stream
, &pos
);
579 ok( hr
== S_OK
, "got %08x\n", hr
);
580 ok( pos
== 2, "got %d\n", pos
);
583 hr
= _Stream_get_Size( stream
, &size
);
584 ok( hr
== S_OK
, "got %08x\n", hr
);
585 ok( size
== 2, "got %d\n", size
);
587 hr
= _Stream_Close( stream
);
588 ok( hr
== S_OK
, "got %08x\n", hr
);
591 hr
= _Stream_get_State( stream
, &state
);
592 ok( hr
== S_OK
, "got %08x\n", hr
);
593 ok( state
== adStateClosed
, "got %u\n", state
);
595 hr
= _Stream_Close( stream
);
596 ok( hr
== MAKE_ADO_HRESULT( adErrObjectClosed
), "got %08x\n", hr
);
598 refs
= _Stream_Release( stream
);
599 ok( !refs
, "got %d\n", refs
);
602 hr
= CoCreateInstance( &CLSID_Stream
, NULL
, CLSCTX_INPROC_SERVER
, &IID__Stream
, (void **)&stream
);
603 ok( hr
== S_OK
, "got %08x\n", hr
);
605 hr
= _Stream_put_Type( stream
, adTypeBinary
);
606 ok( hr
== S_OK
, "got %08x\n", hr
);
608 hr
= _Stream_Open( stream
, missing
, adModeUnknown
, adOpenStreamUnspecified
, NULL
, NULL
);
609 ok( hr
== S_OK
, "got %08x\n", hr
);
611 hr
= _Stream_ReadText( stream
, adReadAll
, &str
);
612 ok( hr
== MAKE_ADO_HRESULT( adErrIllegalOperation
), "got %08x\n", hr
);
614 str
= SysAllocString( L
"test" );
615 hr
= _Stream_WriteText( stream
, str
, adWriteChar
);
616 ok( hr
== MAKE_ADO_HRESULT( adErrIllegalOperation
), "got %08x\n", hr
);
617 SysFreeString( str
);
620 hr
= _Stream_Read( stream
, 1, &val
);
621 ok( hr
== S_OK
, "got %08x\n", hr
);
622 ok( V_VT( &val
) == VT_NULL
, "got %u\n", V_VT( &val
) );
625 hr
= _Stream_Write( stream
, val
);
626 ok( hr
== MAKE_ADO_HRESULT( adErrInvalidArgument
), "got %08x\n", hr
);
628 hr
= str_to_byte_array( "data", &val
);
629 ok( hr
== S_OK
, "got %08x\n", hr
);
630 hr
= _Stream_Write( stream
, val
);
631 ok( hr
== S_OK
, "got %08x\n", hr
);
632 VariantClear( &val
);
635 hr
= _Stream_get_Position( stream
, &pos
);
636 ok( hr
== S_OK
, "got %08x\n", hr
);
637 ok( pos
== 4, "got %d\n", pos
);
639 hr
= _Stream_put_Position( stream
, 0 );
640 ok( hr
== S_OK
, "got %08x\n", hr
);
643 hr
= _Stream_Read( stream
, adReadAll
, &val
);
644 ok( hr
== S_OK
, "got %08x\n", hr
);
645 ok( V_VT( &val
) == (VT_ARRAY
| VT_UI1
), "got %04x\n", V_VT( &val
) );
646 VariantClear( &val
);
649 hr
= _Stream_get_Position( stream
, &pos
);
650 ok( hr
== S_OK
, "got %08x\n", hr
);
651 ok( pos
== 4, "got %d\n", pos
);
653 refs
= _Stream_Release( stream
);
654 ok( !refs
, "got %d\n", refs
);
657 static void test_Connection(void)
660 _Connection
*connection
;
661 IRunnableObject
*runtime
;
662 ISupportErrorInfo
*errorinfo
;
665 hr
= CoCreateInstance(&CLSID_Connection
, NULL
, CLSCTX_INPROC_SERVER
, &IID__Connection
, (void**)&connection
);
666 ok( hr
== S_OK
, "got %08x\n", hr
);
668 hr
= _Connection_QueryInterface(connection
, &IID_IRunnableObject
, (void**)&runtime
);
669 ok(hr
== E_NOINTERFACE
, "Unexpected IRunnableObject interface\n");
671 hr
= _Connection_QueryInterface(connection
, &IID_ISupportErrorInfo
, (void**)&errorinfo
);
672 ok(hr
== S_OK
, "Failed to get ISupportErrorInfo interface\n");
673 ISupportErrorInfo_Release(errorinfo
);
675 if (0) /* Crashes on windows */
677 hr
= _Connection_get_State(connection
, NULL
);
678 ok(hr
== E_INVALIDARG
, "Unexpected hr 0x%08x\n", hr
);
682 hr
= _Connection_get_State(connection
, &state
);
683 ok(hr
== S_OK
, "Failed to get state, hr 0x%08x\n", hr
);
684 ok(state
== adStateClosed
, "Unexpected state value 0x%08x\n", state
);
687 hr
= _Connection_get_CommandTimeout(connection
, &timeout
);
688 ok(hr
== S_OK
, "Failed to get state, hr 0x%08x\n", hr
);
689 ok(timeout
== 30, "Unexpected timeout value %d\n", timeout
);
691 hr
= _Connection_put_CommandTimeout(connection
, 300);
692 ok(hr
== S_OK
, "Failed to get state, hr 0x%08x\n", hr
);
695 hr
= _Connection_get_CommandTimeout(connection
, &timeout
);
696 ok(hr
== S_OK
, "Failed to get state, hr 0x%08x\n", hr
);
697 ok(timeout
== 300, "Unexpected timeout value %d\n", timeout
);
699 _Connection_Release(connection
);
702 static void test_Command(void)
707 Command15
*command15
;
708 Command25
*command25
;
710 hr
= CoCreateInstance( &CLSID_Command
, NULL
, CLSCTX_INPROC_SERVER
, &IID__Command
, (void **)&command
);
711 ok( hr
== S_OK
, "got %08x\n", hr
);
713 hr
= _Command_QueryInterface( command
, &IID__ADO
, (void **)&ado
);
714 ok( hr
== S_OK
, "got %08x\n", hr
);
717 hr
= _Command_QueryInterface( command
, &IID_Command15
, (void **)&command15
);
718 ok( hr
== S_OK
, "got %08x\n", hr
);
719 Command15_Release( command15
);
721 hr
= _Command_QueryInterface( command
, &IID_Command25
, (void **)&command25
);
722 ok( hr
== S_OK
, "got %08x\n", hr
);
723 Command25_Release( command25
);
725 _Command_Release( command
);
730 CoInitialize( NULL
);