2 * Unit tests for OLE storage
4 * Copyright (c) 2004 Mike McCormack
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #define NONAMELESSUNION
25 #define NONAMELESSSTRUCT
28 #include "wine/test.h"
34 DEFINE_GUID( test_stg_cls
, 0x88888888, 0x0425, 0x0000, 0,0,0,0,0,0,0,0);
36 #define ok_ole_success(hr, func) ok(hr == S_OK, func " failed with error 0x%08x\n", hr)
38 static CHAR filenameA
[MAX_PATH
];
39 static WCHAR filename
[MAX_PATH
];
41 static const char file1_nameA
[] = {'c','o','p','y','t','e','s','t','A',0};
42 static const WCHAR file1_name
[] = {'c','o','p','y','t','e','s','t','A',0};
43 static const char file2_nameA
[] = {'c','o','p','y','t','e','s','t','B',0};
44 static const WCHAR file2_name
[] = {'c','o','p','y','t','e','s','t','B',0};
45 static const WCHAR stgA_name
[] = {'S','t','o','r','a','g','e','A',0};
46 static const WCHAR stgB_name
[] = {'S','t','o','r','a','g','e','B',0};
47 static const WCHAR strmA_name
[] = {'S','t','r','e','a','m','A',0};
48 static const WCHAR strmB_name
[] = {'S','t','r','e','a','m','B',0};
49 static const WCHAR strmC_name
[] = {'S','t','r','e','a','m','C',0};
51 /* Win9x and WinMe don't have lstrcmpW */
52 static int strcmp_ww(LPCWSTR strw1
, LPCWSTR strw2
)
54 CHAR stra1
[512], stra2
[512];
55 WideCharToMultiByte(CP_ACP
, 0, strw1
, -1, stra1
, sizeof(stra1
), NULL
, NULL
);
56 WideCharToMultiByte(CP_ACP
, 0, strw2
, -1, stra2
, sizeof(stra2
), NULL
, NULL
);
57 return lstrcmpA(stra1
, stra2
);
60 typedef struct TestLockBytes
{
61 ILockBytes ILockBytes_iface
;
67 ULONG locks_supported
;
71 static inline TestLockBytes
*impl_from_ILockBytes(ILockBytes
*iface
)
73 return CONTAINING_RECORD(iface
, TestLockBytes
, ILockBytes_iface
);
76 static HRESULT WINAPI
TestLockBytes_QueryInterface(ILockBytes
*iface
, REFIID iid
,
79 TestLockBytes
*This
= impl_from_ILockBytes(iface
);
81 if (!ppv
) return E_INVALIDARG
;
83 if (IsEqualIID(&IID_IUnknown
, iid
) ||
84 IsEqualIID(&IID_ILockBytes
, iid
))
85 *ppv
= &This
->ILockBytes_iface
;
89 IUnknown_AddRef((IUnknown
*)*ppv
);
93 static ULONG WINAPI
TestLockBytes_AddRef(ILockBytes
*iface
)
95 TestLockBytes
*This
= impl_from_ILockBytes(iface
);
96 ULONG ref
= InterlockedIncrement(&This
->ref
);
100 static ULONG WINAPI
TestLockBytes_Release(ILockBytes
*iface
)
102 TestLockBytes
*This
= impl_from_ILockBytes(iface
);
103 ULONG ref
= InterlockedDecrement(&This
->ref
);
107 static HRESULT WINAPI
TestLockBytes_ReadAt(ILockBytes
*iface
,
108 ULARGE_INTEGER ulOffset
, void *pv
, ULONG cb
, ULONG
*pcbRead
)
110 TestLockBytes
*This
= impl_from_ILockBytes(iface
);
113 if (!pv
) return E_INVALIDARG
;
115 if (!pcbRead
) pcbRead
= &dummy
;
117 if (ulOffset
.QuadPart
>= This
->size
)
123 cb
= min(cb
, This
->size
- ulOffset
.QuadPart
);
126 memcpy(pv
, &This
->contents
[ulOffset
.QuadPart
], cb
);
131 static HRESULT WINAPI
TestLockBytes_WriteAt(ILockBytes
*iface
,
132 ULARGE_INTEGER ulOffset
, const void *pv
, ULONG cb
, ULONG
*pcbWritten
)
134 TestLockBytes
*This
= impl_from_ILockBytes(iface
);
138 if (!pv
) return E_INVALIDARG
;
140 if (!pcbWritten
) pcbWritten
= &dummy
;
142 if (ulOffset
.QuadPart
+ cb
> This
->size
)
144 ULARGE_INTEGER new_size
;
145 new_size
.QuadPart
= ulOffset
.QuadPart
+ cb
;
146 hr
= ILockBytes_SetSize(iface
, new_size
);
147 if (FAILED(hr
)) return hr
;
151 memcpy(&This
->contents
[ulOffset
.QuadPart
], pv
, cb
);
156 static HRESULT WINAPI
TestLockBytes_Flush(ILockBytes
*iface
)
161 static HRESULT WINAPI
TestLockBytes_SetSize(ILockBytes
*iface
,
164 TestLockBytes
*This
= impl_from_ILockBytes(iface
);
166 if (This
->buffer_size
< cb
.QuadPart
)
168 ULONG new_buffer_size
= max(This
->buffer_size
* 2, cb
.QuadPart
);
169 BYTE
* new_buffer
= HeapAlloc(GetProcessHeap(), 0, new_buffer_size
);
170 if (!new_buffer
) return E_OUTOFMEMORY
;
171 memcpy(new_buffer
, This
->contents
, This
->size
);
172 HeapFree(GetProcessHeap(), 0, This
->contents
);
173 This
->contents
= new_buffer
;
176 if (cb
.QuadPart
> This
->size
)
177 memset(&This
->contents
[This
->size
], 0, cb
.QuadPart
- This
->size
);
179 This
->size
= cb
.QuadPart
;
184 static HRESULT WINAPI
TestLockBytes_LockRegion(ILockBytes
*iface
,
185 ULARGE_INTEGER libOffset
, ULARGE_INTEGER cb
, DWORD dwLockType
)
187 TestLockBytes
*This
= impl_from_ILockBytes(iface
);
189 return This
->lock_hr
;
192 static HRESULT WINAPI
TestLockBytes_UnlockRegion(ILockBytes
*iface
,
193 ULARGE_INTEGER libOffset
, ULARGE_INTEGER cb
, DWORD dwLockType
)
195 TestLockBytes
*This
= impl_from_ILockBytes(iface
);
196 return This
->lock_hr
;
199 static HRESULT WINAPI
TestLockBytes_Stat(ILockBytes
*iface
,
200 STATSTG
*pstatstg
, DWORD grfStatFlag
)
202 TestLockBytes
*This
= impl_from_ILockBytes(iface
);
203 static const WCHAR dummy_name
[] = {'d','u','m','m','y',0};
205 if (!pstatstg
) return E_INVALIDARG
;
207 memset(pstatstg
, 0, sizeof(STATSTG
));
209 if (!(grfStatFlag
& STATFLAG_NONAME
))
211 pstatstg
->pwcsName
= CoTaskMemAlloc(sizeof(dummy_name
));
212 if (!pstatstg
->pwcsName
) return E_OUTOFMEMORY
;
213 memcpy(pstatstg
->pwcsName
, dummy_name
, sizeof(dummy_name
));
216 pstatstg
->type
= STGTY_LOCKBYTES
;
217 pstatstg
->cbSize
.QuadPart
= This
->size
;
218 pstatstg
->grfLocksSupported
= This
->locks_supported
;
223 static const ILockBytesVtbl TestLockBytes_Vtbl
= {
224 TestLockBytes_QueryInterface
,
225 TestLockBytes_AddRef
,
226 TestLockBytes_Release
,
227 TestLockBytes_ReadAt
,
228 TestLockBytes_WriteAt
,
230 TestLockBytes_SetSize
,
231 TestLockBytes_LockRegion
,
232 TestLockBytes_UnlockRegion
,
236 static void CreateTestLockBytes(TestLockBytes
**This
)
238 *This
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(**This
));
242 (*This
)->ILockBytes_iface
.lpVtbl
= &TestLockBytes_Vtbl
;
247 static void DeleteTestLockBytes(TestLockBytes
*This
)
249 ok(This
->ILockBytes_iface
.lpVtbl
== &TestLockBytes_Vtbl
, "test lock bytes %p deleted with incorrect vtable\n", This
);
250 ok(This
->ref
== 1, "test lock bytes %p deleted with %i references instead of 1\n", This
, This
->ref
);
251 HeapFree(GetProcessHeap(), 0, This
->contents
);
252 HeapFree(GetProcessHeap(), 0, This
);
255 static void test_hglobal_storage_stat(void)
257 ILockBytes
*ilb
= NULL
;
258 IStorage
*stg
= NULL
;
261 DWORD mode
, refcount
;
263 r
= CreateILockBytesOnHGlobal( NULL
, TRUE
, &ilb
);
264 ok( r
== S_OK
, "CreateILockBytesOnHGlobal failed\n");
266 r
= StgIsStorageILockBytes( ilb
);
267 ok( r
== S_FALSE
, "StgIsStorageILockBytes should have failed\n");
269 mode
= STGM_CREATE
|STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
;/*0x1012*/
270 r
= StgCreateDocfileOnILockBytes( ilb
, mode
, 0, &stg
);
271 ok( r
== S_OK
, "StgCreateDocfileOnILockBytes failed\n");
273 r
= WriteClassStg( stg
, &test_stg_cls
);
274 ok( r
== S_OK
, "WriteClassStg failed\n");
276 r
= StgIsStorageILockBytes( ilb
);
277 ok( r
== S_OK
, "StgIsStorageILockBytes failed\n");
279 memset( &stat
, 0, sizeof stat
);
280 r
= IStorage_Stat( stg
, &stat
, 0 );
282 ok( stat
.pwcsName
== NULL
, "storage name not null\n");
283 ok( stat
.type
== 1, "type is wrong\n");
284 ok( stat
.grfMode
== 0x12, "grf mode is incorrect\n");
285 ok( !memcmp(&stat
.clsid
, &test_stg_cls
, sizeof test_stg_cls
), "CLSID is wrong\n");
287 refcount
= IStorage_Release( stg
);
288 ok( refcount
== 0, "IStorage refcount is wrong\n");
289 refcount
= ILockBytes_Release( ilb
);
290 ok( refcount
== 0, "ILockBytes refcount is wrong\n");
293 static void test_create_storage_modes(void)
295 IStorage
*stg
= NULL
;
298 DeleteFileA(filenameA
);
300 /* test with some invalid parameters */
301 r
= StgCreateDocfile( NULL
, 0, 0, &stg
);
302 ok(r
==STG_E_INVALIDFLAG
, "StgCreateDocfile succeeded\n");
303 r
= StgCreateDocfile( filename
, 0, 0, &stg
);
304 ok(r
==STG_E_INVALIDFLAG
, "StgCreateDocfile succeeded\n");
305 r
= StgCreateDocfile( filename
, STGM_CREATE
, 0, &stg
);
306 ok(r
==STG_E_INVALIDFLAG
, "StgCreateDocfile succeeded\n");
307 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_READWRITE
, 0, &stg
);
308 ok(r
==STG_E_INVALIDFLAG
, "StgCreateDocfile succeeded\n");
309 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
, 0, &stg
);
310 ok(r
==STG_E_INVALIDFLAG
, "StgCreateDocfile succeeded\n");
311 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, NULL
);
312 ok(r
==STG_E_INVALIDPOINTER
, "StgCreateDocfile succeeded\n");
313 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 1, &stg
);
314 ok(r
==STG_E_INVALIDPARAMETER
, "StgCreateDocfile succeeded\n");
315 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_SHARE_DENY_WRITE
| STGM_READWRITE
, 0, &stg
);
316 ok(r
==STG_E_INVALIDFLAG
, "StgCreateDocfile succeeded\n");
317 r
= StgCreateDocfile( filename
, STGM_SHARE_EXCLUSIVE
| STGM_READ
, 0, &stg
);
318 ok(r
==STG_E_INVALIDFLAG
, "StgCreateDocfile succeeded\n");
319 r
= StgCreateDocfile( filename
, STGM_PRIORITY
, 0, &stg
);
320 ok(r
==STG_E_INVALIDFLAG
, "StgCreateDocfile succeeded\n");
322 /* StgCreateDocfile seems to be very particular about the flags it accepts */
323 r
= StgCreateDocfile( filename
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
|STGM_TRANSACTED
| STGM_WRITE
, 0, &stg
);
324 ok(r
==STG_E_INVALIDFLAG
, "StgCreateDocfile succeeded\n");
325 r
= StgCreateDocfile( filename
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
|STGM_TRANSACTED
| 8, 0, &stg
);
326 ok(r
==STG_E_INVALIDFLAG
, "StgCreateDocfile succeeded\n");
327 r
= StgCreateDocfile( filename
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
|STGM_TRANSACTED
| 0x80, 0, &stg
);
328 ok(r
==STG_E_INVALIDFLAG
, "StgCreateDocfile succeeded\n");
329 r
= StgCreateDocfile( filename
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
|STGM_TRANSACTED
| 0x800, 0, &stg
);
330 ok(r
==STG_E_INVALIDFLAG
, "StgCreateDocfile succeeded\n");
331 r
= StgCreateDocfile( filename
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
|STGM_TRANSACTED
| 0x8000, 0, &stg
);
332 ok(r
==STG_E_INVALIDFLAG
, "StgCreateDocfile succeeded\n");
333 r
= StgCreateDocfile( filename
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
|STGM_TRANSACTED
| 0x80000, 0, &stg
);
334 ok(r
==STG_E_INVALIDFLAG
, "StgCreateDocfile succeeded\n");
335 r
= StgCreateDocfile( filename
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
|STGM_TRANSACTED
| 0x800000, 0, &stg
);
336 ok(r
==STG_E_INVALIDFLAG
, "StgCreateDocfile succeeded\n");
337 ok(stg
== NULL
, "stg was set\n");
339 /* check what happens if the file already exists (which is how it's meant to be used) */
340 r
= StgCreateDocfile( filename
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, &stg
);
341 ok(r
==S_OK
, "StgCreateDocfile failed\n");
342 r
= IStorage_Release(stg
);
343 ok(r
== 0, "storage not released\n");
344 r
= StgCreateDocfile( filename
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
|STGM_TRANSACTED
, 0, &stg
);
345 ok(r
==STG_E_FILEALREADYEXISTS
, "StgCreateDocfile wrong error\n"); /* FAILIFTHERE is default */
346 r
= StgCreateDocfile( filename
, STGM_READ
, 0, &stg
);
347 ok(r
==STG_E_INVALIDFLAG
, "StgCreateDocfile succeeded\n"); /* need at least readmode and sharemode */
348 r
= StgCreateDocfile( filename
, STGM_SHARE_EXCLUSIVE
, 0, &stg
);
349 ok(r
==STG_E_INVALIDFLAG
, "StgCreateDocfile succeeded\n");
350 r
= StgCreateDocfile( filename
, STGM_SHARE_DENY_WRITE
, 0, &stg
);
351 ok(r
==STG_E_INVALIDFLAG
, "StgCreateDocfile succeeded\n");
352 r
= StgCreateDocfile( filename
, STGM_SHARE_DENY_NONE
, 0, &stg
);
353 ok(r
==STG_E_INVALIDFLAG
, "StgCreateDocfile failed\n");
354 r
= StgCreateDocfile( filename
, STGM_SHARE_DENY_NONE
| STGM_TRANSACTED
, 0, &stg
);
355 ok(r
==STG_E_INVALIDFLAG
, "StgCreateDocfile failed\n");
356 r
= StgCreateDocfile( filename
, STGM_SHARE_DENY_NONE
| STGM_READWRITE
, 0, &stg
);
357 ok(r
==STG_E_INVALIDFLAG
, "StgCreateDocfile failed\n");
358 r
= StgCreateDocfile( filename
, STGM_SHARE_DENY_NONE
| STGM_WRITE
, 0, &stg
);
359 ok(r
==STG_E_INVALIDFLAG
, "StgCreateDocfile failed\n");
360 r
= StgCreateDocfile( filename
, STGM_SHARE_DENY_WRITE
| STGM_WRITE
, 0, &stg
);
361 ok(r
==STG_E_INVALIDFLAG
, "StgCreateDocfile failed\n");
362 r
= StgCreateDocfile( filename
, STGM_SHARE_DENY_WRITE
| STGM_READ
, 0, &stg
);
363 ok(r
==STG_E_INVALIDFLAG
, "StgCreateDocfile wrong error\n");
364 r
= StgCreateDocfile( filename
, STGM_TRANSACTED
| STGM_SHARE_DENY_WRITE
| STGM_READ
, 0, &stg
);
365 ok(r
==STG_E_INVALIDFLAG
, "StgCreateDocfile wrong error\n");
366 ok(DeleteFileA(filenameA
), "failed to delete file\n");
368 r
= StgCreateDocfile( filename
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
|STGM_TRANSACTED
, 0, &stg
);
369 ok(r
==S_OK
, "StgCreateDocfile failed\n");
370 r
= IStorage_Release(stg
);
371 ok(r
== 0, "storage not released\n");
372 r
= StgCreateDocfile( filename
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
|STGM_TRANSACTED
|STGM_FAILIFTHERE
, 0, &stg
);
373 ok(r
==STG_E_FILEALREADYEXISTS
, "StgCreateDocfile wrong error\n");
374 r
= StgCreateDocfile( filename
, STGM_SHARE_EXCLUSIVE
| STGM_WRITE
, 0, &stg
);
375 ok(r
==STG_E_FILEALREADYEXISTS
, "StgCreateDocfile wrong error\n");
377 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_SHARE_DENY_WRITE
| STGM_READWRITE
, 0, &stg
);
378 ok(r
==STG_E_INVALIDFLAG
, "StgCreateDocfile succeeded\n");
379 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
|STGM_TRANSACTED
, 0, &stg
);
380 ok(r
==S_OK
, "StgCreateDocfile failed\n");
381 r
= IStorage_Release(stg
);
382 ok(r
== 0, "storage not released\n");
383 ok(DeleteFileA(filenameA
), "failed to delete file\n");
385 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_READWRITE
|STGM_TRANSACTED
, 0, &stg
);
386 ok(r
==S_OK
, "StgCreateDocfile failed\n");
387 r
= IStorage_Release(stg
);
388 ok(r
== 0, "storage not released\n");
389 ok(DeleteFileA(filenameA
), "failed to delete file\n");
391 /* test the way excel uses StgCreateDocFile */
392 r
= StgCreateDocfile( filename
, STGM_TRANSACTED
|STGM_CREATE
|STGM_SHARE_DENY_WRITE
|STGM_READWRITE
, 0, &stg
);
393 ok(r
==S_OK
, "StgCreateDocfile the excel way failed\n");
396 r
= IStorage_Release(stg
);
397 ok(r
== 0, "storage not released\n");
398 ok(DeleteFileA(filenameA
), "failed to delete file\n");
401 /* and the way windows media uses it ... */
402 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_SHARE_DENY_NONE
| STGM_READWRITE
| STGM_TRANSACTED
, 0, &stg
);
403 ok(r
==S_OK
, "StgCreateDocfile the windows media way failed\n");
406 r
= IStorage_Release(stg
);
407 ok(r
== 0, "storage not released\n");
408 ok(DeleteFileA(filenameA
), "failed to delete file\n");
411 /* looks like we need STGM_TRANSACTED or STGM_CREATE */
412 r
= StgCreateDocfile( filename
, STGM_TRANSACTED
|STGM_SHARE_DENY_WRITE
|STGM_READWRITE
, 0, &stg
);
413 ok(r
==S_OK
, "StgCreateDocfile the excel way failed\n");
416 r
= IStorage_Release(stg
);
417 ok(r
== 0, "storage not released\n");
418 ok(DeleteFileA(filenameA
), "failed to delete file\n");
421 r
= StgCreateDocfile( filename
, STGM_TRANSACTED
|STGM_CREATE
|STGM_SHARE_DENY_WRITE
|STGM_WRITE
, 0, &stg
);
422 ok(r
==S_OK
, "StgCreateDocfile the excel way failed\n");
425 r
= IStorage_Release(stg
);
426 ok(r
== 0, "storage not released\n");
427 ok(DeleteFileA(filenameA
), "failed to delete file\n");
430 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, &stg
);
431 ok(r
==S_OK
, "StgCreateDocfile the powerpoint way failed\n");
434 r
= IStorage_Release(stg
);
435 ok(r
== 0, "storage not released\n");
436 ok(DeleteFileA(filenameA
), "failed to delete file\n");
439 /* test the way msi uses StgCreateDocfile */
440 r
= StgCreateDocfile( filename
, STGM_DIRECT
| STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, &stg
);
441 ok(r
==S_OK
, "StgCreateDocFile failed\n");
442 r
= IStorage_Release(stg
);
443 ok(r
== 0, "storage not released\n");
444 ok(DeleteFileA(filenameA
), "failed to delete file\n");
447 static void test_stgcreatestorageex(void)
449 HRESULT (WINAPI
*pStgCreateStorageEx
)(const WCHAR
* pwcsName
, DWORD grfMode
, DWORD stgfmt
, DWORD grfAttrs
, STGOPTIONS
* pStgOptions
, void* reserved
, REFIID riid
, void** ppObjectOpen
);
450 HMODULE hOle32
= GetModuleHandleA("ole32");
451 IStorage
*stg
= NULL
;
452 STGOPTIONS stgoptions
= {1, 0, 4096};
455 pStgCreateStorageEx
= (void *) GetProcAddress(hOle32
, "StgCreateStorageEx");
456 if (!pStgCreateStorageEx
)
458 win_skip("skipping test on NT4\n");
462 DeleteFileA(filenameA
);
464 /* Verify that StgCreateStorageEx can accept an options param */
465 r
= pStgCreateStorageEx( filename
,
466 STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
,
473 ok(r
==S_OK
|| r
==STG_E_UNIMPLEMENTEDFUNCTION
, "StgCreateStorageEx with options failed\n");
474 if (r
==STG_E_UNIMPLEMENTEDFUNCTION
)
476 /* We're on win98 which means all bets are off. Let's get out of here. */
477 win_skip("skipping test on win9x\n");
481 r
= IStorage_Release(stg
);
482 ok(r
== 0, "storage not released\n");
483 ok(DeleteFileA(filenameA
), "failed to delete file\n");
485 /* Verify that StgCreateStorageEx can accept a NULL pStgOptions */
486 r
= pStgCreateStorageEx( filename
,
487 STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
,
494 ok(r
==S_OK
, "StgCreateStorageEx with NULL options failed\n");
495 r
= IStorage_Release(stg
);
496 ok(r
== 0, "storage not released\n");
497 ok(DeleteFileA(filenameA
), "failed to delete file\n");
500 static void test_storage_stream(void)
502 static const WCHAR stmname
[] = { 'C','O','N','T','E','N','T','S',0 };
503 static const WCHAR longname
[] = {
504 'a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a',
505 'a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a',0
507 IStorage
*stg
= NULL
;
510 IStream
*stm2
= NULL
;
514 unsigned char buffer
[0x100];
518 DeleteFileA(filenameA
);
520 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
|STGM_TRANSACTED
, 0, &stg
);
521 ok(r
==S_OK
, "StgCreateDocfile failed\n");
523 /* try create some invalid streams */
524 r
= IStorage_CreateStream(stg
, stmname
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 1, 0, &stm
);
525 ok(r
==STG_E_INVALIDPARAMETER
, "IStorage->CreateStream wrong error\n");
526 r
= IStorage_CreateStream(stg
, stmname
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 1, &stm
);
527 ok(r
==STG_E_INVALIDPARAMETER
, "IStorage->CreateStream wrong error\n");
528 r
= IStorage_CreateStream(stg
, stmname
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, NULL
);
529 ok(r
==STG_E_INVALIDPOINTER
, "IStorage->CreateStream wrong error\n");
530 r
= IStorage_CreateStream(stg
, NULL
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stm
);
531 ok(r
==STG_E_INVALIDNAME
, "IStorage->CreateStream wrong error\n");
532 r
= IStorage_CreateStream(stg
, longname
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stm
);
533 ok(r
==STG_E_INVALIDNAME
|| broken(r
==S_OK
) /* nt4 */,
534 "IStorage->CreateStream wrong error, got %d GetLastError()=%d\n", r
, GetLastError());
535 r
= IStorage_CreateStream(stg
, stmname
, STGM_READWRITE
, 0, 0, &stm
);
536 ok(r
==STG_E_INVALIDFLAG
, "IStorage->CreateStream wrong error\n");
537 r
= IStorage_CreateStream(stg
, stmname
, STGM_READ
, 0, 0, &stm
);
538 ok(r
==STG_E_INVALIDFLAG
, "IStorage->CreateStream wrong error\n");
539 r
= IStorage_CreateStream(stg
, stmname
, STGM_WRITE
, 0, 0, &stm
);
540 ok(r
==STG_E_INVALIDFLAG
, "IStorage->CreateStream wrong error\n");
541 r
= IStorage_CreateStream(stg
, stmname
, STGM_SHARE_DENY_NONE
| STGM_READWRITE
, 0, 0, &stm
);
542 ok(r
==STG_E_INVALIDFLAG
, "IStorage->CreateStream wrong error\n");
543 r
= IStorage_CreateStream(stg
, stmname
, STGM_SHARE_DENY_NONE
| STGM_READ
, 0, 0, &stm
);
544 ok(r
==STG_E_INVALIDFLAG
, "IStorage->CreateStream wrong error\n");
546 /* now really create a stream and delete it */
547 r
= IStorage_CreateStream(stg
, stmname
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stm
);
548 ok(r
==S_OK
, "IStorage->CreateStream failed\n");
550 /* test for support interfaces */
551 r
= IStream_QueryInterface(stm
, &IID_IPersist
, (void**)&unk
);
552 ok(r
==E_NOINTERFACE
, "got 0x%08x\n", r
);
553 r
= IStream_QueryInterface(stm
, &IID_IPersistStream
, (void**)&unk
);
554 ok(r
==E_NOINTERFACE
, "got 0x%08x\n", r
);
556 r
= IStream_Release(stm
);
557 ok(r
== 0, "wrong ref count\n");
558 r
= IStorage_CreateStream(stg
, stmname
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stm
);
559 ok(r
==STG_E_FILEALREADYEXISTS
, "IStorage->CreateStream failed\n");
560 r
= IStorage_DestroyElement(stg
,stmname
);
561 ok(r
==S_OK
, "IStorage->DestroyElement failed\n");
563 /* create a stream and write to it */
564 r
= IStorage_CreateStream(stg
, stmname
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stm
);
565 ok(r
==S_OK
, "IStorage->CreateStream failed\n");
567 r
= IStream_Clone(stm
, &stm2
);
568 ok(r
==S_OK
, "failed to clone stream\n");
570 r
= IStream_Write(stm
, NULL
, 0, NULL
);
571 ok(r
==STG_E_INVALIDPOINTER
, "IStream->Write wrong error\n");
572 r
= IStream_Write(stm
, "Hello\n", 0, NULL
);
573 ok(r
==S_OK
, "failed to write stream\n");
574 r
= IStream_Write(stm
, "Hello\n", 0, &count
);
575 ok(r
==S_OK
, "failed to write stream\n");
576 r
= IStream_Write(stm
, "Hello\n", 6, &count
);
577 ok(r
==S_OK
, "failed to write stream\n");
578 r
= IStream_Commit(stm
, STGC_DEFAULT
);
579 ok(r
==S_OK
, "failed to commit stream\n");
580 r
= IStream_Commit(stm
, STGC_DEFAULT
);
581 ok(r
==S_OK
, "failed to commit stream\n");
583 /* Read past the end of the stream. */
585 r
= IStream_Seek(stm
, pos
, STREAM_SEEK_SET
, &p
);
586 ok(r
==S_OK
, "failed to seek stream\n");
587 ok(p
.QuadPart
== 3, "at wrong place\n");
588 r
= IStream_Read(stm
, buffer
, sizeof buffer
, &count
);
589 ok(r
==S_OK
, "failed to read\n");
590 ok(count
== 3, "read bytes past end of stream\n");
592 r
= IStream_Seek(stm
, pos
, STREAM_SEEK_SET
, &p
);
593 ok(r
==S_OK
, "failed to seek stream\n");
594 ok(p
.QuadPart
== 10, "at wrong place\n");
595 r
= IStream_Read(stm
, buffer
, sizeof buffer
, &count
);
596 ok(r
==S_OK
, "failed to read\n");
597 ok(count
== 0, "read bytes past end of stream\n");
598 pos
.QuadPart
= 10000;
599 r
= IStream_Seek(stm
, pos
, STREAM_SEEK_SET
, &p
);
600 ok(r
==S_OK
, "failed to seek stream\n");
601 ok(p
.QuadPart
== 10000, "at wrong place\n");
602 r
= IStream_Read(stm
, buffer
, sizeof buffer
, &count
);
603 ok(r
==S_OK
, "failed to read\n");
604 ok(count
== 0, "read bytes past end of stream\n");
606 /* Convert to a big block stream, and read past the end. */
608 r
= IStream_SetSize(stm
,p
);
609 ok(r
==S_OK
, "failed to set pos\n");
611 r
= IStream_Seek(stm
, pos
, STREAM_SEEK_SET
, &p
);
612 ok(r
==S_OK
, "failed to seek stream\n");
613 ok(p
.QuadPart
== 4997, "at wrong place\n");
614 r
= IStream_Read(stm
, buffer
, sizeof buffer
, &count
);
615 ok(r
==S_OK
, "failed to read\n");
616 ok(count
== 3, "read bytes past end of stream\n");
618 r
= IStream_Seek(stm
, pos
, STREAM_SEEK_SET
, &p
);
619 ok(r
==S_OK
, "failed to seek stream\n");
620 ok(p
.QuadPart
== 5001, "at wrong place\n");
621 r
= IStream_Read(stm
, buffer
, sizeof buffer
, &count
);
622 ok(r
==S_OK
, "failed to read\n");
623 ok(count
== 0, "read bytes past end of stream\n");
624 pos
.QuadPart
= 10000;
625 r
= IStream_Seek(stm
, pos
, STREAM_SEEK_SET
, &p
);
626 ok(r
==S_OK
, "failed to seek stream\n");
627 ok(p
.QuadPart
== 10000, "at wrong place\n");
628 r
= IStream_Read(stm
, buffer
, sizeof buffer
, &count
);
629 ok(r
==S_OK
, "failed to read\n");
630 ok(count
== 0, "read bytes past end of stream\n");
632 /* seek round a bit, reset the stream size */
634 r
= IStream_Seek(stm
, pos
, 3, &p
);
635 ok(r
==STG_E_INVALIDFUNCTION
, "IStream->Seek returned wrong error\n");
636 r
= IStream_Seek(stm
, pos
, STREAM_SEEK_SET
, NULL
);
637 ok(r
==S_OK
, "failed to seek stream\n");
638 r
= IStream_Seek(stm
, pos
, STREAM_SEEK_SET
, &p
);
639 ok(r
==S_OK
, "failed to seek stream\n");
640 r
= IStream_SetSize(stm
,p
);
641 ok(r
==S_OK
, "failed to set pos\n");
643 r
= IStream_Seek(stm
, pos
, STREAM_SEEK_SET
, &p
);
644 ok(r
==S_OK
, "failed to seek stream\n");
645 ok(p
.QuadPart
== 10, "at wrong place\n");
646 r
= IStream_Read(stm
, buffer
, sizeof buffer
, &count
);
647 ok(r
==S_OK
, "failed to set pos\n");
648 ok(count
== 0, "read bytes from empty stream\n");
649 pos
.QuadPart
= 10000;
650 r
= IStream_Seek(stm
, pos
, STREAM_SEEK_SET
, &p
);
651 ok(r
==S_OK
, "failed to seek stream\n");
652 ok(p
.QuadPart
== 10000, "at wrong place\n");
653 r
= IStream_Read(stm
, buffer
, sizeof buffer
, &count
);
654 ok(r
==S_OK
, "failed to set pos\n");
655 ok(count
== 0, "read bytes from empty stream\n");
657 r
= IStream_Seek(stm
, pos
, STREAM_SEEK_END
, &p
);
658 ok(r
==S_OK
, "failed to seek stream\n");
659 ok(p
.QuadPart
== 0, "at wrong place\n");
660 r
= IStream_Read(stm
, buffer
, sizeof buffer
, &count
);
661 ok(r
==S_OK
, "failed to set pos\n");
662 ok(count
== 0, "read bytes from empty stream\n");
665 r
= IStream_Release(stm2
);
666 ok(r
== 0, "wrong ref count\n");
668 /* create a stream and write to it */
669 r
= IStorage_CreateStream(stg
, stmname
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stm2
);
670 ok(r
==S_OK
, "IStorage->CreateStream failed\n");
672 r
= IStream_Seek(stm
, pos
, STREAM_SEEK_SET
, &p
);
673 ok(r
==STG_E_REVERTED
, "overwritten stream should return STG_E_REVERTED instead of 0x%08x\n", r
);
675 r
= IStream_Release(stm2
);
676 ok(r
== 0, "wrong ref count\n");
677 r
= IStream_Release(stm
);
678 ok(r
== 0, "wrong ref count\n");
680 r
= IStorage_Release(stg
);
681 ok(r
== 0, "wrong ref count\n");
683 /* try create some invalid streams */
686 r
= StgOpenStorage(filename
, NULL
, STGM_READ
| STGM_SHARE_DENY_WRITE
, NULL
, 0, &stg
);
687 ok(r
== S_OK
, "should succeed\n");
690 r
= IStorage_OpenStream(stg
, stmname
, NULL
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, &stm
);
691 ok(r
== STG_E_INVALIDFLAG
, "IStorage->OpenStream should return STG_E_INVALIDFLAG instead of 0x%08x\n", r
);
692 IStorage_Release(stg
);
695 ret
= DeleteFileA(filenameA
);
696 ok(ret
, "file should exist\n");
699 static BOOL
touch_file(LPCSTR filename
)
703 file
= CreateFileA(filename
, GENERIC_READ
|GENERIC_WRITE
, 0, NULL
,
704 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
705 if (file
==INVALID_HANDLE_VALUE
)
711 static BOOL
is_zero_length(LPCSTR filename
)
716 file
= CreateFileA(filename
, GENERIC_READ
, 0, NULL
,
717 OPEN_EXISTING
, 0, NULL
);
718 if (file
==INVALID_HANDLE_VALUE
)
720 len
= GetFileSize(file
, NULL
);
725 static BOOL
is_existing_file(LPCSTR filename
)
729 file
= CreateFileA(filename
, GENERIC_READ
, 0, NULL
,
730 OPEN_EXISTING
, 0, NULL
);
731 if (file
==INVALID_HANDLE_VALUE
)
737 static void test_open_storage(void)
739 static const WCHAR szNonExist
[] = { 'n','o','n','e','x','i','s','t',0 };
740 IStorage
*stg
= NULL
, *stg2
= NULL
;
745 /* try opening a zero length file - it should stay zero length */
746 DeleteFileA(filenameA
);
747 touch_file(filenameA
);
748 stgm
= STGM_NOSCRATCH
| STGM_TRANSACTED
| STGM_SHARE_DENY_WRITE
| STGM_READWRITE
;
749 r
= StgOpenStorage( filename
, NULL
, stgm
, NULL
, 0, &stg
);
750 ok(r
==STG_E_FILEALREADYEXISTS
, "StgOpenStorage didn't fail\n");
752 stgm
= STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
;
753 r
= StgOpenStorage( filename
, NULL
, stgm
, NULL
, 0, &stg
);
754 ok(r
==STG_E_FILEALREADYEXISTS
, "StgOpenStorage didn't fail\n");
755 ok(is_zero_length(filenameA
), "file length changed\n");
757 DeleteFileA(filenameA
);
759 /* try opening a nonexistent file - it should not create it */
760 stgm
= STGM_DIRECT
| STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
;
761 r
= StgOpenStorage( filename
, NULL
, stgm
, NULL
, 0, &stg
);
762 ok(r
!=S_OK
, "StgOpenStorage failed: 0x%08x\n", r
);
763 if (r
==S_OK
) IStorage_Release(stg
);
764 ok(!is_existing_file(filenameA
), "StgOpenStorage should not create a file\n");
765 DeleteFileA(filenameA
);
767 /* create the file */
768 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
|STGM_TRANSACTED
, 0, &stg
);
769 ok(r
==S_OK
, "StgCreateDocfile failed\n");
770 IStorage_Release(stg
);
772 r
= StgOpenStorage( filename
, NULL
, 0, NULL
, 0, &stg
);
773 ok(r
==STG_E_INVALIDFLAG
, "StgOpenStorage wrong error\n");
774 r
= StgOpenStorage( NULL
, NULL
, STGM_SHARE_EXCLUSIVE
, NULL
, 0, &stg
);
775 ok(r
==STG_E_INVALIDNAME
, "StgOpenStorage wrong error\n");
776 r
= StgOpenStorage( filename
, NULL
, STGM_SHARE_EXCLUSIVE
| STGM_READ
, NULL
, 0, NULL
);
777 ok(r
==STG_E_INVALIDPOINTER
, "StgOpenStorage wrong error\n");
778 r
= StgOpenStorage( filename
, NULL
, STGM_SHARE_EXCLUSIVE
| STGM_READ
, NULL
, 1, &stg
);
779 ok(r
==STG_E_INVALIDPARAMETER
, "StgOpenStorage wrong error\n");
780 r
= StgOpenStorage( szNonExist
, NULL
, STGM_SHARE_EXCLUSIVE
| STGM_READ
, NULL
, 0, &stg
);
781 ok(r
==STG_E_FILENOTFOUND
, "StgOpenStorage failed\n");
782 r
= StgOpenStorage( filename
, NULL
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READ
, NULL
, 0, &stg
);
783 ok(r
==STG_E_INVALIDFLAG
, "StgOpenStorage failed\n");
784 r
= StgOpenStorage( filename
, NULL
, STGM_SHARE_DENY_NONE
| STGM_READ
, NULL
, 0, &stg
);
785 ok(r
==STG_E_INVALIDFLAG
, "StgOpenStorage failed\n");
786 r
= StgOpenStorage( filename
, NULL
, STGM_SHARE_DENY_READ
| STGM_READ
, NULL
, 0, &stg
);
787 ok(r
==STG_E_INVALIDFLAG
, "StgOpenStorage failed\n");
788 r
= StgOpenStorage( filename
, NULL
, STGM_SHARE_DENY_WRITE
| STGM_READWRITE
, NULL
, 0, &stg
);
789 ok(r
==STG_E_INVALIDFLAG
, "StgOpenStorage failed\n");
791 /* open it for real */
792 r
= StgOpenStorage( filename
, NULL
, STGM_SHARE_DENY_NONE
| STGM_READ
| STGM_TRANSACTED
, NULL
, 0, &stg
); /* XLViewer 97/2000 */
793 ok(r
==S_OK
, "StgOpenStorage failed\n");
796 r
= IStorage_Release(stg
);
797 ok(r
== 0, "wrong ref count\n");
800 r
= StgOpenStorage( filename
, NULL
, STGM_SHARE_DENY_WRITE
| STGM_READ
, NULL
, 0, &stg
);
801 ok(r
==S_OK
, "StgOpenStorage failed\n");
804 r
= IStorage_Release(stg
);
805 ok(r
== 0, "wrong ref count\n");
808 /* test the way word opens its custom dictionary */
809 r
= StgOpenStorage( filename
, NULL
, STGM_NOSCRATCH
| STGM_TRANSACTED
|
810 STGM_SHARE_DENY_WRITE
| STGM_READWRITE
, NULL
, 0, &stg
);
811 ok(r
==S_OK
, "StgOpenStorage failed\n");
814 r
= IStorage_Release(stg
);
815 ok(r
== 0, "wrong ref count\n");
818 r
= StgOpenStorage( filename
, NULL
, STGM_SHARE_EXCLUSIVE
| STGM_READ
, NULL
, 0, &stg
);
819 ok(r
==S_OK
, "StgOpenStorage failed\n");
820 r
= StgOpenStorage( filename
, NULL
, STGM_SHARE_EXCLUSIVE
| STGM_READ
, NULL
, 0, &stg2
);
821 ok(r
==STG_E_SHAREVIOLATION
, "StgOpenStorage failed\n");
824 r
= IStorage_Release(stg
);
825 ok(r
== 0, "wrong ref count\n");
828 /* now try write to a storage file we opened read-only */
829 r
= StgOpenStorage( filename
, NULL
, STGM_SHARE_EXCLUSIVE
| STGM_READ
, NULL
, 0, &stg
);
830 ok(r
==S_OK
, "StgOpenStorage failed\n");
833 static const WCHAR stmname
[] = { 'w','i','n','e','t','e','s','t',0};
835 IStorage
*stg2
= NULL
;
837 r
= IStorage_CreateStream( stg
, stmname
, STGM_WRITE
| STGM_SHARE_EXCLUSIVE
,
839 ok(r
== STG_E_ACCESSDENIED
, "CreateStream should fail\n");
840 r
= IStorage_CreateStorage( stg
, stmname
, STGM_WRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stg2
);
841 ok(r
== STG_E_ACCESSDENIED
, "CreateStream should fail\n");
843 r
= IStorage_Release(stg
);
844 ok(r
== 0, "wrong ref count\n");
847 /* open like visio 2003 */
849 r
= StgOpenStorage( filename
, NULL
, STGM_PRIORITY
| STGM_SHARE_DENY_NONE
, NULL
, 0, &stg
);
850 ok(r
== S_OK
, "should succeed\n");
852 IStorage_Release(stg
);
854 /* test other sharing modes with STGM_PRIORITY */
856 r
= StgOpenStorage( filename
, NULL
, STGM_PRIORITY
| STGM_SHARE_EXCLUSIVE
, NULL
, 0, &stg
);
857 ok(r
== S_OK
, "should succeed\n");
859 IStorage_Release(stg
);
862 r
= StgOpenStorage( filename
, NULL
, STGM_PRIORITY
| STGM_SHARE_DENY_WRITE
, NULL
, 0, &stg
);
863 ok(r
== S_OK
, "should succeed\n");
865 IStorage_Release(stg
);
868 r
= StgOpenStorage( filename
, NULL
, STGM_PRIORITY
| STGM_SHARE_DENY_READ
, NULL
, 0, &stg
);
869 ok(r
== S_OK
, "should succeed\n");
871 IStorage_Release(stg
);
873 /* open like Project 2003 */
875 r
= StgOpenStorage( filename
, NULL
, STGM_PRIORITY
, NULL
, 0, &stg
);
876 ok(r
== S_OK
, "should succeed\n");
877 r
= StgOpenStorage( filename
, NULL
, STGM_PRIORITY
, NULL
, 0, &stg2
);
878 ok(r
== S_OK
, "should succeed\n");
880 IStorage_Release(stg2
);
882 IStorage_Release(stg
);
885 r
= StgOpenStorage( filename
, NULL
, STGM_PRIORITY
| STGM_READWRITE
, NULL
, 0, &stg
);
886 ok(r
== STG_E_INVALIDFLAG
, "should fail\n");
888 r
= StgOpenStorage( filename
, NULL
, STGM_TRANSACTED
| STGM_PRIORITY
, NULL
, 0, &stg
);
889 ok(r
== STG_E_INVALIDFLAG
, "should fail\n");
891 r
= StgOpenStorage( filename
, NULL
, STGM_SIMPLE
| STGM_PRIORITY
, NULL
, 0, &stg
);
892 ok(r
== STG_E_INVALIDFLAG
, "should fail\n");
894 r
= StgOpenStorage( filename
, NULL
, STGM_DELETEONRELEASE
| STGM_PRIORITY
, NULL
, 0, &stg
);
895 ok(r
== STG_E_INVALIDFUNCTION
, "should fail\n");
897 r
= StgOpenStorage( filename
, NULL
, STGM_NOSCRATCH
| STGM_PRIORITY
, NULL
, 0, &stg
);
898 ok(r
== STG_E_INVALIDFLAG
, "should fail\n");
900 r
= StgOpenStorage( filename
, NULL
, STGM_NOSNAPSHOT
| STGM_PRIORITY
, NULL
, 0, &stg
);
901 ok(r
== STG_E_INVALIDFLAG
, "should fail\n");
903 ret
= DeleteFileA(filenameA
);
904 ok(ret
, "file didn't exist\n");
907 static void test_storage_suminfo(void)
909 IStorage
*stg
= NULL
;
910 IPropertySetStorage
*propset
= NULL
;
911 IPropertyStorage
*ps
= NULL
;
914 DeleteFileA(filenameA
);
916 /* create the file */
917 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
|
918 STGM_READWRITE
|STGM_TRANSACTED
, 0, &stg
);
919 ok(r
==S_OK
, "StgCreateDocfile failed\n");
921 r
= IStorage_QueryInterface( stg
, &IID_IPropertySetStorage
, (LPVOID
) &propset
);
922 ok(r
== S_OK
, "query interface failed\n");
925 r
= IPropertySetStorage_Delete( propset
, &FMTID_SummaryInformation
);
926 ok(r
== STG_E_FILENOTFOUND
, "deleted property set storage\n");
928 r
= IPropertySetStorage_Open( propset
, &FMTID_SummaryInformation
,
929 STGM_READ
| STGM_SHARE_EXCLUSIVE
, &ps
);
930 ok(r
== STG_E_FILENOTFOUND
, "opened property set storage\n");
932 r
= IPropertySetStorage_Create( propset
, &FMTID_SummaryInformation
, NULL
, 0,
933 STGM_READ
| STGM_SHARE_EXCLUSIVE
, &ps
);
934 ok(r
== STG_E_INVALIDFLAG
, "created property set storage\n");
936 r
= IPropertySetStorage_Create( propset
, &FMTID_SummaryInformation
, NULL
, 0,
938 ok(r
== STG_E_INVALIDFLAG
, "created property set storage\n");
940 r
= IPropertySetStorage_Create( propset
, &FMTID_SummaryInformation
, NULL
, 0, 0, &ps
);
941 ok(r
== STG_E_INVALIDFLAG
, "created property set storage\n");
943 r
= IPropertySetStorage_Create( propset
, &FMTID_SummaryInformation
, NULL
, 0,
944 STGM_WRITE
|STGM_SHARE_EXCLUSIVE
, &ps
);
945 ok(r
== STG_E_INVALIDFLAG
, "created property set storage\n");
947 r
= IPropertySetStorage_Create( propset
, &FMTID_SummaryInformation
, NULL
, 0,
948 STGM_CREATE
|STGM_WRITE
|STGM_SHARE_EXCLUSIVE
, &ps
);
949 ok(r
== STG_E_INVALIDFLAG
, "created property set storage\n");
951 /* now try really creating a property set */
952 r
= IPropertySetStorage_Create( propset
, &FMTID_SummaryInformation
, NULL
, 0,
953 STGM_CREATE
|STGM_READWRITE
|STGM_SHARE_EXCLUSIVE
, &ps
);
954 ok(r
== S_OK
, "failed to create property set storage\n");
957 IPropertyStorage_Release(ps
);
959 /* now try creating the same thing again */
960 r
= IPropertySetStorage_Create( propset
, &FMTID_SummaryInformation
, NULL
, 0,
961 STGM_CREATE
|STGM_READWRITE
|STGM_SHARE_EXCLUSIVE
, &ps
);
962 ok(r
== S_OK
, "failed to create property set storage\n");
964 IPropertyStorage_Release(ps
);
966 /* should be able to open it */
967 r
= IPropertySetStorage_Open( propset
, &FMTID_SummaryInformation
,
968 STGM_READWRITE
|STGM_SHARE_EXCLUSIVE
, &ps
);
969 ok(r
== S_OK
, "open failed\n");
971 IPropertyStorage_Release(ps
);
974 r
= IPropertySetStorage_Delete( propset
, &FMTID_SummaryInformation
);
975 ok(r
== S_OK
, "failed to delete property set storage\n");
977 /* try opening with an invalid FMTID */
978 r
= IPropertySetStorage_Open( propset
, NULL
,
979 STGM_READWRITE
|STGM_SHARE_EXCLUSIVE
, &ps
);
980 ok(r
== E_INVALIDARG
, "open succeeded\n");
982 IPropertyStorage_Release(ps
);
985 r
= IPropertySetStorage_Open( propset
, &IID_IStorage
,
986 STGM_READWRITE
|STGM_SHARE_EXCLUSIVE
, &ps
);
987 ok(r
== STG_E_FILENOTFOUND
, "open succeeded\n");
989 IPropertyStorage_Release(ps
);
992 /* try some invalid flags */
993 r
= IPropertySetStorage_Open( propset
, &FMTID_SummaryInformation
,
994 STGM_CREATE
| STGM_READWRITE
|STGM_SHARE_EXCLUSIVE
, &ps
);
995 ok(r
== STG_E_INVALIDFLAG
, "open succeeded\n");
997 IPropertyStorage_Release(ps
);
999 /* after deleting it, it should be gone */
1000 r
= IPropertySetStorage_Open( propset
, &FMTID_SummaryInformation
,
1001 STGM_READWRITE
|STGM_SHARE_EXCLUSIVE
, &ps
);
1002 ok(r
== STG_E_FILENOTFOUND
, "open failed\n");
1004 IPropertyStorage_Release(ps
);
1006 r
= IPropertySetStorage_Release( propset
);
1007 ok(r
== 1, "ref count wrong\n");
1009 r
= IStorage_Release(stg
);
1010 ok(r
== 0, "ref count wrong\n");
1012 DeleteFileA(filenameA
);
1015 static void test_storage_refcount(void)
1017 IStorage
*stg
= NULL
;
1018 IStorage
*stgprio
= NULL
;
1020 IStream
*stm
= NULL
;
1021 static const WCHAR stmname
[] = { 'C','O','N','T','E','N','T','S',0 };
1023 ULARGE_INTEGER upos
;
1027 DeleteFileA(filenameA
);
1029 /* create the file */
1030 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
|
1031 STGM_READWRITE
|STGM_TRANSACTED
, 0, &stg
);
1032 ok(r
==S_OK
, "StgCreateDocfile failed\n");
1034 r
= WriteClassStg( stg
, &test_stg_cls
);
1035 ok( r
== S_OK
, "WriteClassStg failed\n");
1037 r
= IStorage_Commit( stg
, STGC_DEFAULT
);
1038 ok( r
== S_OK
, "IStorage_Commit failed\n");
1040 /* now create a stream */
1041 r
= IStorage_CreateStream(stg
, stmname
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stm
);
1042 ok(r
==S_OK
, "IStorage->CreateStream failed\n");
1044 r
= IStorage_Release( stg
);
1045 ok (r
== 0, "storage not released\n");
1048 r
= IStream_Seek( stm
, pos
, 0, &upos
);
1049 ok (r
== STG_E_REVERTED
, "seek should fail\n");
1051 r
= IStream_Stat( stm
, &stat
, STATFLAG_DEFAULT
);
1052 ok (r
== STG_E_REVERTED
, "stat should fail\n");
1054 r
= IStream_Write( stm
, "Test string", strlen("Test string"), NULL
);
1055 ok (r
== STG_E_REVERTED
, "IStream_Write should return STG_E_REVERTED instead of 0x%08x\n", r
);
1057 r
= IStream_Read( stm
, buffer
, sizeof(buffer
), NULL
);
1058 ok (r
== STG_E_REVERTED
, "IStream_Read should return STG_E_REVERTED instead of 0x%08x\n", r
);
1060 r
= IStream_Release(stm
);
1061 ok (r
== 0, "stream not released\n");
1063 /* tests that STGM_PRIORITY doesn't prevent readwrite access from other
1064 * StgOpenStorage calls in transacted mode */
1065 r
= StgOpenStorage( filename
, NULL
, STGM_PRIORITY
, NULL
, 0, &stgprio
);
1066 ok(r
==S_OK
, "StgOpenStorage failed with error 0x%08x\n", r
);
1068 /* non-transacted mode read/write fails */
1069 r
= StgOpenStorage( filename
, NULL
, STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, NULL
, 0, &stg
);
1070 ok(r
==STG_E_LOCKVIOLATION
, "StgOpenStorage should return STG_E_LOCKVIOLATION instead of 0x%08x\n", r
);
1072 /* non-transacted mode read-only succeeds */
1073 r
= StgOpenStorage( filename
, NULL
, STGM_SHARE_DENY_WRITE
|STGM_READ
, NULL
, 0, &stg
);
1074 ok(r
==S_OK
, "StgOpenStorage failed with error 0x%08x\n", r
);
1075 IStorage_Release(stg
);
1077 r
= StgOpenStorage( filename
, NULL
, STGM_TRANSACTED
|STGM_SHARE_DENY_WRITE
|STGM_READWRITE
, NULL
, 0, &stg
);
1078 ok(r
==S_OK
, "StgOpenStorage failed with error 0x%08x\n", r
);
1081 static const WCHAR stgname
[] = { ' ',' ',' ','2','9',0 };
1082 static const WCHAR stgname2
[] = { 'C','V','_','i','e','w',0 };
1083 static const WCHAR stmname2
[] = { 'V','a','r','2','D','a','t','a',0 };
1088 r
= IStorage_Stat( stg
, &statstg
, STATFLAG_NONAME
);
1089 ok(r
== S_OK
, "Stat should have succeeded instead of returning 0x%08x\n", r
);
1090 ok(statstg
.type
== STGTY_STORAGE
, "Statstg type should have been STGTY_STORAGE instead of %d\n", statstg
.type
);
1091 ok(U(statstg
.cbSize
).LowPart
== 0, "Statstg cbSize.LowPart should have been 0 instead of %d\n", U(statstg
.cbSize
).LowPart
);
1092 ok(U(statstg
.cbSize
).HighPart
== 0, "Statstg cbSize.HighPart should have been 0 instead of %d\n", U(statstg
.cbSize
).HighPart
);
1093 ok(statstg
.grfMode
== (STGM_TRANSACTED
|STGM_SHARE_DENY_WRITE
|STGM_READWRITE
),
1094 "Statstg grfMode should have been 0x10022 instead of 0x%x\n", statstg
.grfMode
);
1095 ok(statstg
.grfLocksSupported
== 0, "Statstg grfLocksSupported should have been 0 instead of %d\n", statstg
.grfLocksSupported
);
1096 ok(IsEqualCLSID(&statstg
.clsid
, &test_stg_cls
), "Statstg clsid is not test_stg_cls\n");
1097 ok(statstg
.grfStateBits
== 0, "Statstg grfStateBits should have been 0 instead of %d\n", statstg
.grfStateBits
);
1098 ok(statstg
.reserved
== 0, "Statstg reserved should have been 0 instead of %d\n", statstg
.reserved
);
1100 r
= IStorage_CreateStorage( stg
, stgname
, STGM_SHARE_EXCLUSIVE
, 0, 0, &stg2
);
1101 ok(r
== S_OK
, "CreateStorage should have succeeded instead of returning 0x%08x\n", r
);
1103 r
= IStorage_Stat( stg2
, &statstg
, STATFLAG_DEFAULT
);
1104 ok(r
== S_OK
, "Stat should have succeeded instead of returning 0x%08x\n", r
);
1105 ok(!memcmp(statstg
.pwcsName
, stgname
, sizeof(stgname
)),
1106 "Statstg pwcsName should have been the name the storage was created with\n");
1107 ok(statstg
.type
== STGTY_STORAGE
, "Statstg type should have been STGTY_STORAGE instead of %d\n", statstg
.type
);
1108 ok(U(statstg
.cbSize
).LowPart
== 0, "Statstg cbSize.LowPart should have been 0 instead of %d\n", U(statstg
.cbSize
).LowPart
);
1109 ok(U(statstg
.cbSize
).HighPart
== 0, "Statstg cbSize.HighPart should have been 0 instead of %d\n", U(statstg
.cbSize
).HighPart
);
1110 ok(statstg
.grfMode
== STGM_SHARE_EXCLUSIVE
,
1111 "Statstg grfMode should have been STGM_SHARE_EXCLUSIVE instead of 0x%x\n", statstg
.grfMode
);
1112 ok(statstg
.grfLocksSupported
== 0, "Statstg grfLocksSupported should have been 0 instead of %d\n", statstg
.grfLocksSupported
);
1113 ok(IsEqualCLSID(&statstg
.clsid
, &CLSID_NULL
), "Statstg clsid is not CLSID_NULL\n");
1114 ok(statstg
.grfStateBits
== 0, "Statstg grfStateBits should have been 0 instead of %d\n", statstg
.grfStateBits
);
1115 ok(statstg
.reserved
== 0, "Statstg reserved should have been 0 instead of %d\n", statstg
.reserved
);
1116 CoTaskMemFree(statstg
.pwcsName
);
1118 r
= IStorage_CreateStorage( stg2
, stgname2
, STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, 0, 0, &stg3
);
1119 ok(r
== STG_E_ACCESSDENIED
, "CreateStorage should have returned STG_E_ACCESSDENIED instead of 0x%08x\n", r
);
1121 r
= IStorage_CreateStream( stg2
, stmname2
, STGM_CREATE
|STGM_SHARE_EXCLUSIVE
, 0, 0, &stm
);
1122 ok(r
== STG_E_ACCESSDENIED
, "CreateStream should have returned STG_E_ACCESSDENIED instead of 0x%08x\n", r
);
1124 IStorage_Release(stg2
);
1126 r
= IStorage_Release(stg
);
1127 ok(r
== 0, "wrong ref count\n");
1130 /* Multiple STGM_PRIORITY opens are possible. */
1131 r
= StgOpenStorage( filename
, NULL
, STGM_PRIORITY
, NULL
, 0, &stg
);
1132 ok(r
==S_OK
, "StgOpenStorage failed with error 0x%08x\n", r
);
1135 r
= IStorage_Release(stg
);
1136 ok(r
== 0, "wrong ref count\n");
1139 r
= StgOpenStorage( NULL
, stgprio
, STGM_TRANSACTED
|STGM_SHARE_DENY_WRITE
|STGM_READWRITE
, NULL
, 0, &stg
);
1140 ok(r
==S_OK
, "StgOpenStorage failed with error 0x%08x\n", r
);
1143 static const WCHAR stgname
[] = { ' ',' ',' ','2','9',0 };
1147 r
= IStorage_Stat( stg
, &statstg
, STATFLAG_NONAME
);
1148 ok(r
== S_OK
, "Stat should have succeeded instead of returning 0x%08x\n", r
);
1149 ok(statstg
.type
== STGTY_STORAGE
, "Statstg type should have been STGTY_STORAGE instead of %d\n", statstg
.type
);
1150 ok(U(statstg
.cbSize
).LowPart
== 0, "Statstg cbSize.LowPart should have been 0 instead of %d\n", U(statstg
.cbSize
).LowPart
);
1151 ok(U(statstg
.cbSize
).HighPart
== 0, "Statstg cbSize.HighPart should have been 0 instead of %d\n", U(statstg
.cbSize
).HighPart
);
1152 ok(statstg
.grfMode
== (STGM_TRANSACTED
|STGM_SHARE_DENY_WRITE
|STGM_READWRITE
),
1153 "Statstg grfMode should have been 0x10022 instead of 0x%x\n", statstg
.grfMode
);
1154 ok(statstg
.grfLocksSupported
== 0, "Statstg grfLocksSupported should have been 0 instead of %d\n", statstg
.grfLocksSupported
);
1155 ok(IsEqualCLSID(&statstg
.clsid
, &test_stg_cls
), "Statstg clsid is not test_stg_cls\n");
1156 ok(statstg
.grfStateBits
== 0, "Statstg grfStateBits should have been 0 instead of %d\n", statstg
.grfStateBits
);
1157 ok(statstg
.reserved
== 0, "Statstg reserved should have been 0 instead of %d\n", statstg
.reserved
);
1159 r
= IStorage_CreateStorage( stg
, stgname
, STGM_SHARE_EXCLUSIVE
, 0, 0, &stg2
);
1160 ok(r
== S_OK
, "CreateStorage should have succeeded instead of returning 0x%08x\n", r
);
1162 IStorage_Release(stg2
);
1164 r
= IStorage_Commit( stg
, 0 );
1165 ok(r
== S_OK
, "Commit should have succeeded instead of returning 0x%08x\n", r
);
1167 r
= IStorage_Release(stg
);
1168 ok(r
== 0, "wrong ref count\n");
1170 /* IStorage_Release(stgprio) not necessary because StgOpenStorage released it. */
1172 DeleteFileA(filenameA
);
1175 static void test_writeclassstg(void)
1177 IStorage
*stg
= NULL
;
1179 CLSID temp_cls
, cls2
;
1181 DeleteFileA(filenameA
);
1183 /* create the file */
1184 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
|
1185 STGM_READWRITE
, 0, &stg
);
1186 ok(r
==S_OK
, "StgCreateDocfile failed\n");
1188 r
= ReadClassStg( NULL
, NULL
);
1189 ok(r
== E_INVALIDARG
, "ReadClassStg should return E_INVALIDARG instead of 0x%08X\n", r
);
1191 memset(&temp_cls
, 0xcc, sizeof(temp_cls
));
1192 memset(&cls2
, 0xcc, sizeof(cls2
));
1193 r
= ReadClassStg( NULL
, &temp_cls
);
1194 ok(r
== E_INVALIDARG
, "got 0x%08x\n", r
);
1195 ok(IsEqualCLSID(&temp_cls
, &cls2
), "got wrong clsid\n");
1197 r
= ReadClassStg( stg
, NULL
);
1198 ok(r
== E_INVALIDARG
, "ReadClassStg should return E_INVALIDARG instead of 0x%08X\n", r
);
1200 temp_cls
.Data1
= 0xdeadbeef;
1201 r
= ReadClassStg( stg
, &temp_cls
);
1202 ok(r
== S_OK
, "ReadClassStg failed with 0x%08X\n", r
);
1204 ok(IsEqualCLSID(&temp_cls
, &CLSID_NULL
), "ReadClassStg returned wrong clsid\n");
1206 r
= WriteClassStg( NULL
, NULL
);
1207 ok(r
== E_INVALIDARG
, "WriteClassStg should return E_INVALIDARG instead of 0x%08X\n", r
);
1209 r
= WriteClassStg( stg
, NULL
);
1210 ok(r
== STG_E_INVALIDPOINTER
, "WriteClassStg should return STG_E_INVALIDPOINTER instead of 0x%08X\n", r
);
1212 r
= WriteClassStg( stg
, &test_stg_cls
);
1213 ok( r
== S_OK
, "WriteClassStg failed with 0x%08X\n", r
);
1215 r
= ReadClassStg( stg
, &temp_cls
);
1216 ok( r
== S_OK
, "ReadClassStg failed with 0x%08X\n", r
);
1217 ok(IsEqualCLSID(&temp_cls
, &test_stg_cls
), "ReadClassStg returned wrong clsid\n");
1219 r
= IStorage_Release( stg
);
1220 ok (r
== 0, "storage not released\n");
1222 DeleteFileA(filenameA
);
1225 static void test_streamenum(void)
1227 IStorage
*stg
= NULL
;
1229 IStream
*stm
= NULL
;
1230 static const WCHAR stmname
[] = { 'C','O','N','T','E','N','T','S',0 };
1231 static const WCHAR stmname2
[] = { 'A','B','C','D','E','F','G','H','I',0 };
1232 static const WCHAR stmname3
[] = { 'A','B','C','D','E','F','G','H','I','J',0 };
1233 static const STATSTG stat_null
;
1235 IEnumSTATSTG
*ee
= NULL
;
1238 DeleteFileA(filenameA
);
1240 /* create the file */
1241 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
|
1242 STGM_READWRITE
|STGM_TRANSACTED
, 0, &stg
);
1243 ok(r
==S_OK
, "StgCreateDocfile failed\n");
1245 r
= WriteClassStg( stg
, &test_stg_cls
);
1246 ok( r
== S_OK
, "WriteClassStg failed\n");
1248 r
= IStorage_Commit( stg
, STGC_DEFAULT
);
1249 ok( r
== S_OK
, "IStorage_Commit failed\n");
1251 /* now create a stream */
1252 r
= IStorage_CreateStream(stg
, stmname
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stm
);
1253 ok(r
==S_OK
, "IStorage->CreateStream failed\n");
1255 IStream_Release(stm
);
1257 /* first enum ... should be 1 stream */
1258 r
= IStorage_EnumElements(stg
, 0, NULL
, 0, &ee
);
1259 ok(r
==S_OK
, "IStorage->EnumElements failed\n");
1262 r
= IEnumSTATSTG_Next(ee
, 1, &stat
, &count
);
1263 ok(r
==S_OK
, "IEnumSTATSTG->Next failed\n");
1264 ok(count
== 1, "count wrong\n");
1267 CoTaskMemFree(stat
.pwcsName
);
1269 r
= IEnumSTATSTG_Release(ee
);
1270 ok(r
==S_OK
, "EnumSTATSTG_Release failed with error 0x%08x\n", r
);
1272 /* second enum... destroy the stream before reading */
1273 r
= IStorage_EnumElements(stg
, 0, NULL
, 0, &ee
);
1274 ok(r
==S_OK
, "IStorage->EnumElements failed\n");
1276 r
= IStorage_DestroyElement(stg
, stmname
);
1277 ok(r
==S_OK
, "IStorage->DestroyElement failed\n");
1279 memset(&stat
, 0xad, sizeof(stat
));
1281 r
= IEnumSTATSTG_Next(ee
, 1, &stat
, &count
);
1282 ok(r
==S_FALSE
, "IEnumSTATSTG->Next failed\n");
1283 ok(count
== 0, "count wrong\n");
1284 ok(memcmp(&stat
, &stat_null
, sizeof(stat
)) == 0, "stat is not zeroed\n");
1286 /* reset and try again */
1287 r
= IEnumSTATSTG_Reset(ee
);
1288 ok(r
==S_OK
, "IEnumSTATSTG->Reset failed\n");
1291 r
= IEnumSTATSTG_Next(ee
, 1, &stat
, &count
);
1292 ok(r
==S_FALSE
, "IEnumSTATSTG->Next failed\n");
1293 ok(count
== 0, "count wrong\n");
1295 /* add a stream before reading */
1296 r
= IEnumSTATSTG_Reset(ee
);
1297 ok(r
==S_OK
, "IEnumSTATSTG->Reset failed\n");
1299 r
= IStorage_CreateStream(stg
, stmname
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stm
);
1300 ok(r
==S_OK
, "IStorage->CreateStream failed\n");
1302 r
= IStream_Release(stm
);
1303 ok(r
==S_OK
, "Stream_Release failed with error 0x%08x\n", r
);
1306 r
= IEnumSTATSTG_Next(ee
, 1, &stat
, &count
);
1307 ok(r
==S_OK
, "IEnumSTATSTG->Next failed\n");
1308 ok(count
== 1, "count wrong\n");
1312 ok(lstrcmpiW(stat
.pwcsName
, stmname
) == 0, "expected CONTENTS, got %s\n", wine_dbgstr_w(stat
.pwcsName
));
1313 CoTaskMemFree(stat
.pwcsName
);
1316 r
= IStorage_CreateStream(stg
, stmname2
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stm
);
1317 ok(r
==S_OK
, "IStorage->CreateStream failed\n");
1319 r
= IStream_Release(stm
);
1320 ok(r
==S_OK
, "Stream_Release failed with error 0x%08x\n", r
);
1323 r
= IEnumSTATSTG_Next(ee
, 1, &stat
, &count
);
1324 ok(r
==S_OK
, "IEnumSTATSTG->Next failed\n");
1325 ok(count
== 1, "count wrong\n");
1329 ok(lstrcmpiW(stat
.pwcsName
, stmname2
) == 0, "expected ABCDEFGHI, got %s\n", wine_dbgstr_w(stat
.pwcsName
));
1330 CoTaskMemFree(stat
.pwcsName
);
1333 /* delete previous and next stream after reading */
1334 r
= IStorage_CreateStream(stg
, stmname3
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stm
);
1335 ok(r
==S_OK
, "IStorage->CreateStream failed\n");
1337 r
= IStream_Release(stm
);
1338 ok(r
==S_OK
, "Stream_Release failed with error 0x%08x\n", r
);
1340 r
= IEnumSTATSTG_Reset(ee
);
1341 ok(r
==S_OK
, "IEnumSTATSTG->Reset failed\n");
1344 r
= IEnumSTATSTG_Next(ee
, 1, &stat
, &count
);
1345 ok(r
==S_OK
, "IEnumSTATSTG->Next failed\n");
1346 ok(count
== 1, "count wrong\n");
1350 ok(lstrcmpiW(stat
.pwcsName
, stmname
) == 0, "expected CONTENTS, got %s\n", wine_dbgstr_w(stat
.pwcsName
));
1351 CoTaskMemFree(stat
.pwcsName
);
1354 r
= IStorage_DestroyElement(stg
, stmname
);
1355 ok(r
==S_OK
, "IStorage->DestroyElement failed\n");
1357 r
= IStorage_DestroyElement(stg
, stmname2
);
1358 ok(r
==S_OK
, "IStorage->DestroyElement failed\n");
1361 r
= IEnumSTATSTG_Next(ee
, 1, &stat
, &count
);
1362 ok(r
==S_OK
, "IEnumSTATSTG->Next failed\n");
1363 ok(count
== 1, "count wrong\n");
1367 ok(lstrcmpiW(stat
.pwcsName
, stmname3
) == 0, "expected ABCDEFGHIJ, got %s\n", wine_dbgstr_w(stat
.pwcsName
));
1368 CoTaskMemFree(stat
.pwcsName
);
1371 r
= IStorage_Release( stg
);
1372 todo_wine
ok (r
== 0, "storage not released\n");
1374 /* enumerator is still valid and working after the storage is released */
1375 r
= IEnumSTATSTG_Reset(ee
);
1376 ok(r
==S_OK
, "IEnumSTATSTG->Reset failed\n");
1379 r
= IEnumSTATSTG_Next(ee
, 1, &stat
, &count
);
1380 ok(r
==S_OK
, "IEnumSTATSTG->Next failed\n");
1381 ok(count
== 1, "count wrong\n");
1385 ok(lstrcmpiW(stat
.pwcsName
, stmname3
) == 0, "expected ABCDEFGHIJ, got %s\n", wine_dbgstr_w(stat
.pwcsName
));
1386 CoTaskMemFree(stat
.pwcsName
);
1389 /* the storage is left open until the enumerator is freed */
1390 r
= StgOpenStorage( filename
, NULL
, STGM_SHARE_EXCLUSIVE
|
1391 STGM_READWRITE
|STGM_TRANSACTED
, NULL
, 0, &stg
);
1392 ok(r
==STG_E_SHAREVIOLATION
||
1393 r
==STG_E_LOCKVIOLATION
, /* XP-SP2/W2K3-SP1 and below */
1394 "StgCreateDocfile failed, res=%x\n", r
);
1396 r
= IEnumSTATSTG_Release(ee
);
1397 ok (r
== 0, "enum not released\n");
1399 DeleteFileA(filenameA
);
1402 static void test_transact(void)
1404 IStorage
*stg
= NULL
, *stg2
= NULL
, *stg3
= NULL
;
1406 IStream
*stm
= NULL
;
1407 static const WCHAR stmname
[] = { 'C','O','N','T','E','N','T','S',0 };
1408 static const WCHAR stmname2
[] = { 'F','O','O',0 };
1409 static const WCHAR stgname
[] = { 'P','E','R','M','S','T','G',0 };
1410 static const WCHAR stgname2
[] = { 'T','E','M','P','S','T','G',0 };
1413 DeleteFileA(filenameA
);
1415 /* create the file */
1416 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
|
1417 STGM_READWRITE
|STGM_TRANSACTED
, 0, &stg
);
1418 ok(r
==S_OK
, "StgCreateDocfile failed\n");
1420 /* commit a new stream and storage */
1421 r
= IStorage_CreateStream(stg
, stmname2
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stm
);
1422 ok(r
==S_OK
, "IStorage->CreateStream failed\n");
1424 r
= IStream_Write(stm
, "this is stream 1\n", 16, NULL
);
1425 ok(r
==S_OK
, "IStream->Write failed\n");
1427 IStream_Release(stm
);
1429 r
= IStorage_CreateStorage(stg
, stgname
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stg2
);
1430 ok(r
==S_OK
, "IStorage->CreateStorage failed, hr=%08x\n", r
);
1434 /* Create two substorages but only commit one */
1435 r
= IStorage_CreateStorage(stg2
, stgname
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stg3
);
1436 ok(r
==S_OK
, "IStorage->CreateStorage failed, hr=%08x\n", r
);
1439 IStorage_Release(stg3
);
1441 r
= IStorage_Commit(stg
, 0);
1442 ok(r
==S_OK
, "IStorage->Commit failed\n");
1444 r
= IStorage_CreateStorage(stg2
, stgname2
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stg3
);
1445 ok(r
==S_OK
, "IStorage->CreateStorage failed, hr=%08x\n", r
);
1448 IStorage_Release(stg3
);
1450 IStorage_Release(stg2
);
1453 /* now create a stream and storage, but don't commit them */
1455 r
= IStorage_CreateStream(stg
, stmname
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stm
);
1456 ok(r
==S_OK
, "IStorage->CreateStream failed\n");
1458 r
= IStream_Write(stm
, "this is stream 2\n", 16, NULL
);
1459 ok(r
==S_OK
, "IStream->Write failed\n");
1461 /* IStream::Commit does nothing for OLE storage streams */
1462 r
= IStream_Commit(stm
, STGC_ONLYIFCURRENT
| STGC_DANGEROUSLYCOMMITMERELYTODISKCACHE
);
1463 ok(r
==S_OK
, "IStream->Commit failed\n");
1465 r
= IStorage_CreateStorage(stg
, stgname2
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stg2
);
1466 ok(r
==S_OK
, "IStorage->CreateStorage failed, hr=%08x\n", r
);
1469 IStorage_Release(stg2
);
1471 IStream_Release(stm
);
1473 IStorage_Release(stg
);
1477 r
= StgOpenStorage( filename
, NULL
, STGM_SHARE_DENY_NONE
| STGM_READ
| STGM_TRANSACTED
, NULL
, 0, &stg
);
1478 ok(r
==S_OK
, "StgOpenStorage failed\n");
1483 r
= IStorage_OpenStream(stg
, stmname
, NULL
, STGM_SHARE_DENY_NONE
|STGM_READ
, 0, &stm
);
1484 ok(r
==STG_E_INVALIDFLAG
, "IStorage->OpenStream failed %08x\n", r
);
1486 r
= IStorage_OpenStream(stg
, stmname
, NULL
, STGM_DELETEONRELEASE
|STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, 0, &stm
);
1487 ok(r
==STG_E_INVALIDFUNCTION
, "IStorage->OpenStream failed %08x\n", r
);
1489 r
= IStorage_OpenStream(stg
, stmname
, NULL
, STGM_TRANSACTED
|STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, 0, &stm
);
1490 ok(r
==STG_E_INVALIDFUNCTION
, "IStorage->OpenStream failed %08x\n", r
);
1492 r
= IStorage_OpenStorage(stg
, stmname
, NULL
, STGM_TRANSACTED
|STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, NULL
, 0, &stg2
);
1493 ok(r
==STG_E_FILENOTFOUND
, "IStorage->OpenStream failed %08x\n", r
);
1495 r
= IStorage_OpenStream(stg
, stmname
, NULL
, STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, 0, &stm
);
1496 ok(r
==STG_E_FILENOTFOUND
, "IStorage->OpenStream should fail %08x\n", r
);
1498 IStream_Release(stm
);
1500 r
= IStorage_OpenStorage(stg
, stgname2
, NULL
, STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, NULL
, 0, &stg2
);
1501 ok(r
==STG_E_FILENOTFOUND
, "IStorage->OpenStorage should fail %08x\n", r
);
1503 IStorage_Release(stg2
);
1505 r
= IStorage_OpenStorage(stg
, stmname2
, NULL
, STGM_TRANSACTED
|STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, NULL
, 0, &stg2
);
1506 ok(r
==STG_E_FILENOTFOUND
, "IStorage->OpenStream failed %08x\n", r
);
1508 r
= IStorage_OpenStream(stg
, stmname2
, NULL
, STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, 0, &stm
);
1509 ok(r
==S_OK
, "IStorage->OpenStream should succeed %08x\n", r
);
1511 IStream_Release(stm
);
1513 r
= IStorage_OpenStorage(stg
, stgname
, NULL
, STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, NULL
, 0, &stg2
);
1514 ok(r
==S_OK
, "IStorage->OpenStorage should succeed %08x\n", r
);
1517 r
= IStorage_OpenStorage(stg2
, stgname
, NULL
, STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, NULL
, 0, &stg3
);
1518 ok(r
==S_OK
, "IStorage->OpenStorage should succeed %08x\n", r
);
1520 IStorage_Release(stg3
);
1522 r
= IStorage_OpenStorage(stg2
, stgname2
, NULL
, STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, NULL
, 0, &stg3
);
1523 ok(r
==STG_E_FILENOTFOUND
, "IStorage->OpenStorage should fail %08x\n", r
);
1525 IStorage_Release(stg3
);
1527 IStorage_Release(stg2
);
1530 IStorage_Release(stg
);
1532 ret
= DeleteFileA(filenameA
);
1533 ok(ret
, "deleted file\n");
1536 static void test_substorage_share(void)
1538 IStorage
*stg
, *stg2
, *stg3
;
1539 IStream
*stm
, *stm2
;
1541 static const WCHAR stgname
[] = { 'P','E','R','M','S','T','G',0 };
1542 static const WCHAR stmname
[] = { 'C','O','N','T','E','N','T','S',0 };
1543 static const WCHAR othername
[] = { 'N','E','W','N','A','M','E',0 };
1546 DeleteFileA(filenameA
);
1548 /* create the file */
1549 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
|
1550 STGM_READWRITE
, 0, &stg
);
1551 ok(r
==S_OK
, "StgCreateDocfile failed\n");
1553 /* create a read/write storage and try to open it again */
1554 r
= IStorage_CreateStorage(stg
, stgname
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stg2
);
1555 ok(r
==S_OK
, "IStorage->CreateStorage failed, hr=%08x\n", r
);
1559 r
= IStorage_OpenStorage(stg
, stgname
, NULL
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stg3
);
1560 ok(r
==STG_E_ACCESSDENIED
, "IStorage->OpenStorage should fail %08x\n", r
);
1563 IStorage_Release(stg3
);
1565 r
= IStorage_OpenStorage(stg
, stgname
, NULL
, STGM_READ
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stg3
);
1566 ok(r
==STG_E_ACCESSDENIED
, "IStorage->OpenStorage should fail %08x\n", r
);
1569 IStorage_Release(stg3
);
1571 /* cannot rename the storage while it's open */
1572 r
= IStorage_RenameElement(stg
, stgname
, othername
);
1573 ok(r
==STG_E_ACCESSDENIED
, "IStorage->RenameElement should fail %08x\n", r
);
1574 if (SUCCEEDED(r
)) IStorage_RenameElement(stg
, othername
, stgname
);
1576 /* destroying an object while it's open invalidates it */
1577 r
= IStorage_DestroyElement(stg
, stgname
);
1578 ok(r
==S_OK
, "IStorage->DestroyElement failed, hr=%08x\n", r
);
1580 r
= IStorage_CreateStream(stg2
, stmname
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stm
);
1581 ok(r
==STG_E_REVERTED
, "IStorage->CreateStream failed, hr=%08x\n", r
);
1584 IStream_Release(stm
);
1586 IStorage_Release(stg2
);
1589 /* create a read/write stream and try to open it again */
1590 r
= IStorage_CreateStream(stg
, stmname
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stm
);
1591 ok(r
==S_OK
, "IStorage->CreateStream failed, hr=%08x\n", r
);
1595 r
= IStorage_OpenStream(stg
, stmname
, NULL
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, &stm2
);
1596 ok(r
==STG_E_ACCESSDENIED
, "IStorage->OpenStream should fail %08x\n", r
);
1599 IStream_Release(stm2
);
1601 r
= IStorage_OpenStream(stg
, stmname
, NULL
, STGM_READ
| STGM_SHARE_EXCLUSIVE
, 0, &stm2
);
1602 ok(r
==STG_E_ACCESSDENIED
, "IStorage->OpenStream should fail %08x\n", r
);
1605 IStream_Release(stm2
);
1607 /* cannot rename the stream while it's open */
1608 r
= IStorage_RenameElement(stg
, stmname
, othername
);
1609 ok(r
==STG_E_ACCESSDENIED
, "IStorage->RenameElement should fail %08x\n", r
);
1610 if (SUCCEEDED(r
)) IStorage_RenameElement(stg
, othername
, stmname
);
1612 /* destroying an object while it's open invalidates it */
1613 r
= IStorage_DestroyElement(stg
, stmname
);
1614 ok(r
==S_OK
, "IStorage->DestroyElement failed, hr=%08x\n", r
);
1616 r
= IStream_Write(stm
, "this shouldn't work\n", 20, NULL
);
1617 ok(r
==STG_E_REVERTED
, "IStream_Write should fail %08x\n", r
);
1619 IStream_Release(stm
);
1622 IStorage_Release(stg
);
1624 ret
= DeleteFileA(filenameA
);
1625 ok(ret
, "deleted file\n");
1628 static void test_revert(void)
1630 IStorage
*stg
= NULL
, *stg2
= NULL
, *stg3
= NULL
;
1632 IStream
*stm
= NULL
, *stm2
= NULL
;
1633 static const WCHAR stmname
[] = { 'C','O','N','T','E','N','T','S',0 };
1634 static const WCHAR stmname2
[] = { 'F','O','O',0 };
1635 static const WCHAR stgname
[] = { 'P','E','R','M','S','T','G',0 };
1636 static const WCHAR stgname2
[] = { 'T','E','M','P','S','T','G',0 };
1640 DeleteFileA(filenameA
);
1642 /* create the file */
1643 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
|
1644 STGM_READWRITE
|STGM_TRANSACTED
, 0, &stg
);
1645 ok(r
==S_OK
, "StgCreateDocfile failed\n");
1647 /* commit a new stream and storage */
1648 r
= IStorage_CreateStream(stg
, stmname2
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stm
);
1649 ok(r
==S_OK
, "IStorage->CreateStream failed\n");
1651 r
= IStream_Write(stm
, "this is stream 1\n", 16, NULL
);
1652 ok(r
==S_OK
, "IStream->Write failed\n");
1654 r
= IStorage_CreateStorage(stg
, stgname
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stg2
);
1655 ok(r
==S_OK
, "IStorage->CreateStorage failed, hr=%08x\n", r
);
1659 /* Create two substorages but only commit one */
1660 r
= IStorage_CreateStorage(stg2
, stgname
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stg3
);
1661 ok(r
==S_OK
, "IStorage->CreateStorage failed, hr=%08x\n", r
);
1664 IStorage_Release(stg3
);
1666 r
= IStorage_Commit(stg
, 0);
1667 ok(r
==S_OK
, "IStorage->Commit failed\n");
1669 r
= IStorage_CreateStorage(stg2
, stgname2
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stg3
);
1670 ok(r
==S_OK
, "IStorage->CreateStorage failed, hr=%08x\n", r
);
1673 IStorage_Release(stg3
);
1676 /* now create a stream and storage, then revert */
1677 r
= IStorage_CreateStream(stg
, stmname
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stm2
);
1678 ok(r
==S_OK
, "IStorage->CreateStream failed\n");
1680 r
= IStream_Write(stm2
, "this is stream 2\n", 16, NULL
);
1681 ok(r
==S_OK
, "IStream->Write failed\n");
1683 r
= IStorage_CreateStorage(stg
, stgname2
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stg3
);
1684 ok(r
==S_OK
, "IStorage->CreateStorage failed, hr=%08x\n", r
);
1686 r
= IStorage_Revert(stg
);
1687 ok(r
==S_OK
, "Storage_Revert failed with error 0x%08x\n", r
);
1689 /* all open objects become invalid */
1690 r
= IStream_Write(stm
, "this shouldn't work\n", 20, NULL
);
1691 ok(r
==STG_E_REVERTED
, "IStream_Write should fail %08x\n", r
);
1693 r
= IStream_Write(stm2
, "this shouldn't work\n", 20, NULL
);
1694 ok(r
==STG_E_REVERTED
, "IStream_Write should fail %08x\n", r
);
1696 r
= IStorage_Stat(stg2
, &statstg
, STATFLAG_NONAME
);
1697 ok(r
==STG_E_REVERTED
, "IStorage_Stat should fail %08x\n", r
);
1699 r
= IStorage_Stat(stg3
, &statstg
, STATFLAG_NONAME
);
1700 ok(r
==STG_E_REVERTED
, "IStorage_Stat should fail %08x\n", r
);
1702 IStream_Release(stm
);
1703 IStream_Release(stm2
);
1704 IStorage_Release(stg2
);
1705 IStorage_Release(stg3
);
1707 r
= IStorage_OpenStream(stg
, stmname
, NULL
, STGM_SHARE_DENY_NONE
|STGM_READ
, 0, &stm
);
1708 ok(r
==STG_E_INVALIDFLAG
, "IStorage->OpenStream failed %08x\n", r
);
1710 r
= IStorage_OpenStream(stg
, stmname
, NULL
, STGM_DELETEONRELEASE
|STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, 0, &stm
);
1711 ok(r
==STG_E_INVALIDFUNCTION
, "IStorage->OpenStream failed %08x\n", r
);
1713 r
= IStorage_OpenStream(stg
, stmname
, NULL
, STGM_TRANSACTED
|STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, 0, &stm
);
1714 ok(r
==STG_E_INVALIDFUNCTION
, "IStorage->OpenStream failed %08x\n", r
);
1716 r
= IStorage_OpenStorage(stg
, stmname
, NULL
, STGM_TRANSACTED
|STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, NULL
, 0, &stg2
);
1717 ok(r
==STG_E_FILENOTFOUND
, "IStorage->OpenStream failed %08x\n", r
);
1719 r
= IStorage_OpenStream(stg
, stmname
, NULL
, STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, 0, &stm
);
1720 ok(r
==STG_E_FILENOTFOUND
, "IStorage->OpenStream should fail %08x\n", r
);
1722 IStream_Release(stm
);
1724 r
= IStorage_OpenStorage(stg
, stgname2
, NULL
, STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, NULL
, 0, &stg2
);
1725 ok(r
==STG_E_FILENOTFOUND
, "IStorage->OpenStorage should fail %08x\n", r
);
1727 IStorage_Release(stg2
);
1729 r
= IStorage_OpenStorage(stg
, stmname2
, NULL
, STGM_TRANSACTED
|STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, NULL
, 0, &stg2
);
1730 ok(r
==STG_E_FILENOTFOUND
, "IStorage->OpenStream failed %08x\n", r
);
1732 r
= IStorage_OpenStream(stg
, stmname2
, NULL
, STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, 0, &stm
);
1733 ok(r
==S_OK
, "IStorage->OpenStream should succeed %08x\n", r
);
1735 IStream_Release(stm
);
1737 r
= IStorage_OpenStorage(stg
, stgname
, NULL
, STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, NULL
, 0, &stg2
);
1738 ok(r
==S_OK
, "IStorage->OpenStorage should succeed %08x\n", r
);
1741 r
= IStorage_OpenStorage(stg2
, stgname
, NULL
, STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, NULL
, 0, &stg3
);
1742 ok(r
==S_OK
, "IStorage->OpenStorage should succeed %08x\n", r
);
1744 IStorage_Release(stg3
);
1746 r
= IStorage_OpenStorage(stg2
, stgname2
, NULL
, STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, NULL
, 0, &stg3
);
1747 ok(r
==STG_E_FILENOTFOUND
, "IStorage->OpenStorage should fail %08x\n", r
);
1749 IStorage_Release(stg3
);
1751 IStorage_Release(stg2
);
1754 IStorage_Release(stg
);
1756 ret
= DeleteFileA(filenameA
);
1757 ok(ret
, "deleted file\n");
1759 /* Revert only invalidates objects in transacted mode */
1760 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
|
1761 STGM_READWRITE
, 0, &stg
);
1762 ok(r
==S_OK
, "StgCreateDocfile failed\n");
1764 r
= IStorage_CreateStream(stg
, stmname2
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stm
);
1765 ok(r
==S_OK
, "IStorage->CreateStream failed\n");
1767 r
= IStorage_Revert(stg
);
1768 ok(r
==S_OK
, "IStorage->Revert failed %08x\n", r
);
1770 r
= IStream_Write(stm
, "this works\n", 11, NULL
);
1771 ok(r
==S_OK
, "IStream_Write should succeed %08x\n", r
);
1773 IStream_Release(stm
);
1774 IStorage_Release(stg
);
1776 ret
= DeleteFileA(filenameA
);
1777 ok(ret
, "deleted file\n");
1780 static void test_parent_free(void)
1782 IStorage
*stg
= NULL
, *stg2
= NULL
, *stg3
= NULL
;
1784 IStream
*stm
= NULL
;
1785 static const WCHAR stmname
[] = { 'C','O','N','T','E','N','T','S',0 };
1786 static const WCHAR stgname
[] = { 'P','E','R','M','S','T','G',0 };
1791 DeleteFileA(filenameA
);
1793 /* create the file */
1794 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
|
1795 STGM_READWRITE
|STGM_TRANSACTED
, 0, &stg
);
1796 ok(r
==S_OK
, "StgCreateDocfile failed\n");
1798 /* create a new storage */
1799 r
= IStorage_CreateStorage(stg
, stgname
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stg2
);
1800 ok(r
==S_OK
, "IStorage->CreateStorage failed, hr=%08x\n", r
);
1804 /* now create a stream inside the new storage */
1805 r
= IStorage_CreateStream(stg2
, stmname
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stm
);
1806 ok(r
==S_OK
, "IStorage->CreateStream failed\n");
1810 /* create a storage inside the new storage */
1811 r
= IStorage_CreateStorage(stg2
, stgname
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stg3
);
1812 ok(r
==S_OK
, "IStorage->CreateStorage failed\n");
1815 /* free the parent */
1816 ref
= IStorage_Release(stg2
);
1817 ok(ref
== 0, "IStorage still has %u references\n", ref
);
1819 /* child objects are invalid */
1822 r
= IStream_Write(stm
, "this should fail\n", 17, NULL
);
1823 ok(r
==STG_E_REVERTED
, "IStream->Write should fail, hr=%x\n", r
);
1825 IStream_Release(stm
);
1827 r
= IStorage_Stat(stg3
, &statstg
, STATFLAG_NONAME
);
1828 ok(r
==STG_E_REVERTED
, "IStorage_Stat should fail %08x\n", r
);
1830 r
= IStorage_SetStateBits(stg3
, 1, 1);
1831 ok(r
==STG_E_REVERTED
, "IStorage_Stat should fail %08x\n", r
);
1833 IStorage_Release(stg3
);
1837 IStorage_Release(stg
);
1839 ret
= DeleteFileA(filenameA
);
1840 ok(ret
, "deleted file\n");
1843 static void test_nonroot_transacted(void)
1845 IStorage
*stg
= NULL
, *stg2
= NULL
, *stg3
= NULL
;
1847 IStream
*stm
= NULL
;
1848 static const WCHAR stgname
[] = { 'P','E','R','M','S','T','G',0 };
1849 static const WCHAR stmname
[] = { 'C','O','N','T','E','N','T','S',0 };
1850 static const WCHAR stmname2
[] = { 'F','O','O',0 };
1853 DeleteFileA(filenameA
);
1855 /* create a transacted file */
1856 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
|
1857 STGM_READWRITE
|STGM_TRANSACTED
, 0, &stg
);
1858 ok(r
==S_OK
, "StgCreateDocfile failed\n");
1860 /* create a transacted substorage */
1861 r
= IStorage_CreateStorage(stg
, stgname
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
| STGM_TRANSACTED
, 0, 0, &stg2
);
1862 ok(r
==S_OK
, "IStorage->CreateStorage failed, hr=%08x\n", r
);
1866 /* create and commit stmname */
1867 r
= IStorage_CreateStream(stg2
, stmname
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stm
);
1868 ok(r
==S_OK
, "IStorage->CreateStream failed\n");
1870 IStream_Release(stm
);
1872 IStorage_Commit(stg2
, 0);
1874 /* create and revert stmname2 */
1875 r
= IStorage_CreateStream(stg2
, stmname2
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stm
);
1876 ok(r
==S_OK
, "IStorage->CreateStream failed\n");
1878 IStream_Release(stm
);
1880 IStorage_Revert(stg2
);
1882 /* check that Commit and Revert really worked */
1883 r
= IStorage_OpenStream(stg2
, stmname
, NULL
, STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, 0, &stm
);
1884 ok(r
==S_OK
, "IStorage->OpenStream should succeed %08x\n", r
);
1886 IStream_Release(stm
);
1888 r
= IStorage_OpenStream(stg2
, stmname2
, NULL
, STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, 0, &stm
);
1889 ok(r
==STG_E_FILENOTFOUND
, "IStorage->OpenStream should fail %08x\n", r
);
1891 IStream_Release(stm
);
1893 IStorage_Release(stg2
);
1896 /* create a read-only transacted substorage */
1897 r
= IStorage_OpenStorage(stg
, stgname
, NULL
, STGM_READ
| STGM_SHARE_EXCLUSIVE
| STGM_TRANSACTED
, NULL
, 0, &stg2
);
1898 ok(r
==S_OK
, "IStorage->OpenStorage failed, hr=%08x\n", r
);
1902 /* The storage can be modified. */
1903 r
= IStorage_CreateStorage(stg2
, stgname
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stg3
);
1904 ok(r
==S_OK
, "IStorage->CreateStorage failed, hr=%08x\n", r
);
1906 IStorage_Release(stg3
);
1908 /* But changes cannot be committed. */
1909 r
= IStorage_Commit(stg2
, 0);
1910 ok(r
==STG_E_ACCESSDENIED
, "IStorage->Commit should fail, hr=%08x\n", r
);
1912 IStorage_Release(stg2
);
1915 IStorage_Release(stg
);
1917 /* create a non-transacted file */
1918 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
|
1919 STGM_READWRITE
, 0, &stg
);
1920 ok(r
==S_OK
, "StgCreateDocfile failed\n");
1922 /* create a transacted substorage */
1923 r
= IStorage_CreateStorage(stg
, stgname
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
| STGM_TRANSACTED
, 0, 0, &stg2
);
1924 ok(r
==S_OK
, "IStorage->CreateStorage failed, hr=%08x\n", r
);
1928 /* create and commit stmname */
1929 r
= IStorage_CreateStream(stg2
, stmname
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stm
);
1930 ok(r
==S_OK
, "IStorage->CreateStream failed\n");
1932 IStream_Release(stm
);
1934 IStorage_Commit(stg2
, 0);
1936 /* create and revert stmname2 */
1937 r
= IStorage_CreateStream(stg2
, stmname2
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stm
);
1938 ok(r
==S_OK
, "IStorage->CreateStream failed\n");
1940 IStream_Release(stm
);
1942 IStorage_Revert(stg2
);
1944 /* check that Commit and Revert really worked */
1945 r
= IStorage_OpenStream(stg2
, stmname
, NULL
, STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, 0, &stm
);
1946 ok(r
==S_OK
, "IStorage->OpenStream should succeed %08x\n", r
);
1948 IStream_Release(stm
);
1950 r
= IStorage_OpenStream(stg2
, stmname2
, NULL
, STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, 0, &stm
);
1951 ok(r
==STG_E_FILENOTFOUND
, "IStorage->OpenStream should fail %08x\n", r
);
1953 IStream_Release(stm
);
1955 IStorage_Release(stg2
);
1958 IStorage_Release(stg
);
1960 ret
= DeleteFileA(filenameA
);
1961 ok(ret
, "deleted file\n");
1964 static void test_ReadClassStm(void)
1966 CLSID clsid
, clsid2
;
1969 static const LARGE_INTEGER llZero
;
1971 hr
= ReadClassStm(NULL
, &clsid
);
1972 ok(hr
== E_INVALIDARG
, "ReadClassStm should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
1974 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &pStream
);
1975 ok_ole_success(hr
, "CreateStreamOnHGlobal");
1976 hr
= WriteClassStm(pStream
, &test_stg_cls
);
1977 ok_ole_success(hr
, "WriteClassStm");
1979 hr
= ReadClassStm(pStream
, NULL
);
1980 ok(hr
== E_INVALIDARG
, "ReadClassStm should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
1982 memset(&clsid
, 0xcc, sizeof(clsid
));
1983 memset(&clsid2
, 0xcc, sizeof(clsid2
));
1984 hr
= ReadClassStm(NULL
, &clsid
);
1985 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
1986 ok(IsEqualCLSID(&clsid
, &clsid2
), "got wrong clsid\n");
1988 /* test not rewound stream */
1989 hr
= ReadClassStm(pStream
, &clsid
);
1990 ok(hr
== STG_E_READFAULT
, "ReadClassStm should have returned STG_E_READFAULT instead of 0x%08x\n", hr
);
1991 ok(IsEqualCLSID(&clsid
, &CLSID_NULL
), "clsid should have been zeroed\n");
1993 hr
= IStream_Seek(pStream
, llZero
, STREAM_SEEK_SET
, NULL
);
1994 ok_ole_success(hr
, "IStream_Seek");
1995 hr
= ReadClassStm(pStream
, &clsid
);
1996 ok_ole_success(hr
, "ReadClassStm");
1997 ok(IsEqualCLSID(&clsid
, &test_stg_cls
), "clsid should have been set to CLSID_WineTest\n");
1999 IStream_Release(pStream
);
2009 static const struct access_res create
[16] =
2011 { TRUE
, ERROR_SUCCESS
, TRUE
},
2012 { TRUE
, ERROR_SUCCESS
, TRUE
},
2013 { TRUE
, ERROR_SUCCESS
, FALSE
},
2014 { TRUE
, ERROR_SUCCESS
, FALSE
},
2015 { FALSE
, ERROR_SHARING_VIOLATION
, FALSE
},
2016 { FALSE
, ERROR_SHARING_VIOLATION
, FALSE
},
2017 { FALSE
, ERROR_SHARING_VIOLATION
, FALSE
},
2018 { TRUE
, ERROR_SUCCESS
, FALSE
},
2019 { FALSE
, ERROR_SHARING_VIOLATION
, FALSE
},
2020 { FALSE
, ERROR_SHARING_VIOLATION
, FALSE
},
2021 { FALSE
, ERROR_SHARING_VIOLATION
, FALSE
},
2022 { TRUE
, ERROR_SUCCESS
, TRUE
},
2023 { FALSE
, ERROR_SHARING_VIOLATION
, FALSE
},
2024 { FALSE
, ERROR_SHARING_VIOLATION
, FALSE
},
2025 { FALSE
, ERROR_SHARING_VIOLATION
, FALSE
},
2026 { TRUE
, ERROR_SUCCESS
, TRUE
}
2029 static const struct access_res create_commit
[16] =
2031 { TRUE
, ERROR_SUCCESS
, TRUE
},
2032 { TRUE
, ERROR_SUCCESS
, TRUE
},
2033 { TRUE
, ERROR_SUCCESS
, FALSE
},
2034 { TRUE
, ERROR_SUCCESS
, FALSE
},
2035 { FALSE
, ERROR_SHARING_VIOLATION
, FALSE
},
2036 { FALSE
, ERROR_SHARING_VIOLATION
, FALSE
},
2037 { FALSE
, ERROR_SHARING_VIOLATION
, FALSE
},
2038 { TRUE
, ERROR_SUCCESS
, FALSE
},
2039 { FALSE
, ERROR_SHARING_VIOLATION
, FALSE
},
2040 { FALSE
, ERROR_SHARING_VIOLATION
, FALSE
},
2041 { FALSE
, ERROR_SHARING_VIOLATION
, FALSE
},
2042 { TRUE
, ERROR_SUCCESS
, TRUE
},
2043 { FALSE
, ERROR_SHARING_VIOLATION
, FALSE
},
2044 { FALSE
, ERROR_SHARING_VIOLATION
, FALSE
},
2045 { FALSE
, ERROR_SHARING_VIOLATION
, FALSE
},
2046 { TRUE
, ERROR_SUCCESS
, TRUE
}
2049 static const struct access_res create_close
[16] =
2051 { TRUE
, ERROR_SUCCESS
, FALSE
},
2052 { TRUE
, ERROR_SUCCESS
, FALSE
},
2053 { TRUE
, ERROR_SUCCESS
, FALSE
},
2054 { TRUE
, ERROR_SUCCESS
, FALSE
},
2055 { TRUE
, ERROR_SUCCESS
, FALSE
},
2056 { TRUE
, ERROR_SUCCESS
, FALSE
},
2057 { TRUE
, ERROR_SUCCESS
, FALSE
},
2058 { TRUE
, ERROR_SUCCESS
, FALSE
},
2059 { TRUE
, ERROR_SUCCESS
, FALSE
},
2060 { TRUE
, ERROR_SUCCESS
, FALSE
},
2061 { TRUE
, ERROR_SUCCESS
, FALSE
},
2062 { TRUE
, ERROR_SUCCESS
, FALSE
},
2063 { TRUE
, ERROR_SUCCESS
, FALSE
},
2064 { TRUE
, ERROR_SUCCESS
, FALSE
},
2065 { TRUE
, ERROR_SUCCESS
, FALSE
},
2066 { TRUE
, ERROR_SUCCESS
}
2069 static const DWORD access_modes
[4] = {
2073 GENERIC_READ
| GENERIC_WRITE
2076 static const DWORD share_modes
[4] = {
2080 FILE_SHARE_READ
| FILE_SHARE_WRITE
2083 static void _test_file_access(LPCSTR file
, const struct access_res
*ares
, DWORD line
)
2087 for (i
= 0; i
< sizeof(access_modes
)/sizeof(access_modes
[0]); i
++)
2089 for (j
= 0; j
< sizeof(share_modes
)/sizeof(share_modes
[0]); j
++)
2094 if (ares
[idx
].ignore
)
2097 SetLastError(0xdeadbeef);
2098 hfile
= CreateFileA(file
, access_modes
[i
], share_modes
[j
], NULL
, OPEN_EXISTING
,
2099 FILE_ATTRIBUTE_NORMAL
, 0);
2100 lasterr
= GetLastError();
2102 ok((hfile
!= INVALID_HANDLE_VALUE
) == ares
[idx
].gothandle
,
2103 "(%d, handle, %d): Expected %d, got %d\n",
2104 line
, idx
, ares
[idx
].gothandle
,
2105 (hfile
!= INVALID_HANDLE_VALUE
));
2107 ok(lasterr
== ares
[idx
].lasterr
||
2108 broken(lasterr
== 0xdeadbeef) /* win9x */,
2109 "(%d, lasterr, %d): Expected %d, got %d\n",
2110 line
, idx
, ares
[idx
].lasterr
, lasterr
);
2118 #define test_file_access(file, ares) _test_file_access(file, ares, __LINE__)
2120 static void test_access(void)
2122 static const WCHAR fileW
[] = {'w','i','n','e','t','e','s','t',0};
2123 static const char fileA
[] = "winetest";
2127 /* STGM_TRANSACTED */
2128 hr
= StgCreateDocfile(fileW
, STGM_CREATE
| STGM_READWRITE
|
2129 STGM_SHARE_EXCLUSIVE
| STGM_TRANSACTED
, 0, &stg
);
2130 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
2132 test_file_access(fileA
, create
);
2134 hr
= IStorage_Commit(stg
, STGC_DEFAULT
);
2135 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
2137 test_file_access(fileA
, create_commit
);
2139 IStorage_Release(stg
);
2141 test_file_access(fileA
, create_close
);
2146 hr
= StgCreateDocfile(fileW
, STGM_CREATE
| STGM_READWRITE
|
2147 STGM_SHARE_EXCLUSIVE
| STGM_DIRECT
, 0, &stg
);
2148 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
2150 test_file_access(fileA
, create
);
2152 hr
= IStorage_Commit(stg
, STGC_DEFAULT
);
2153 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
2155 test_file_access(fileA
, create_commit
);
2157 IStorage_Release(stg
);
2159 test_file_access(fileA
, create_close
);
2163 /* STGM_SHARE_DENY_NONE */
2164 hr
= StgCreateDocfile(fileW
, STGM_CREATE
| STGM_READWRITE
|
2165 STGM_SHARE_DENY_NONE
| STGM_TRANSACTED
, 0, &stg
);
2166 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
2168 test_file_access(fileA
, create
);
2170 hr
= IStorage_Commit(stg
, STGC_DEFAULT
);
2171 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
2173 test_file_access(fileA
, create_commit
);
2175 IStorage_Release(stg
);
2177 test_file_access(fileA
, create_close
);
2181 /* STGM_SHARE_DENY_READ */
2182 hr
= StgCreateDocfile(fileW
, STGM_CREATE
| STGM_READWRITE
|
2183 STGM_SHARE_DENY_READ
| STGM_TRANSACTED
, 0, &stg
);
2184 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
2186 test_file_access(fileA
, create
);
2188 hr
= IStorage_Commit(stg
, STGC_DEFAULT
);
2189 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
2191 test_file_access(fileA
, create_commit
);
2193 IStorage_Release(stg
);
2195 test_file_access(fileA
, create_close
);
2199 /* STGM_SHARE_DENY_WRITE */
2200 hr
= StgCreateDocfile(fileW
, STGM_CREATE
| STGM_READWRITE
|
2201 STGM_SHARE_DENY_WRITE
| STGM_TRANSACTED
, 0, &stg
);
2202 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
2204 test_file_access(fileA
, create
);
2206 hr
= IStorage_Commit(stg
, STGC_DEFAULT
);
2207 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
2209 test_file_access(fileA
, create_commit
);
2211 IStorage_Release(stg
);
2213 test_file_access(fileA
, create_close
);
2217 /* STGM_DIRECT_SWMR | STGM_READ | STGM_SHARE_DENY_NONE - reader mode for direct SWMR mode */
2218 hr
= StgCreateDocfile(fileW
, STGM_CREATE
| STGM_READWRITE
| STGM_SHARE_DENY_WRITE
| STGM_TRANSACTED
, 0, &stg
);
2219 ok(hr
== S_OK
, "got %08x\n", hr
);
2220 IStorage_Release(stg
);
2222 hr
= StgOpenStorage(fileW
, NULL
, STGM_DIRECT_SWMR
| STGM_READ
| STGM_SHARE_DENY_NONE
, NULL
, 0, &stg
);
2223 ok(hr
== S_OK
|| broken(hr
== STG_E_INVALIDFLAG
), "got %08x\n", hr
);
2227 test_file_access(fileA
, create
);
2229 IStorage_Release(stg
);
2230 test_file_access(fileA
, create_close
);
2235 static void test_readonly(void)
2237 IStorage
*stg
, *stg2
, *stg3
;
2240 static const WCHAR fileW
[] = {'w','i','n','e','t','e','s','t',0};
2241 static const WCHAR storageW
[] = {'s','t','o','r','a','g','e',0};
2242 static const WCHAR streamW
[] = {'s','t','r','e','a','m',0};
2244 hr
= StgCreateDocfile( fileW
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, &stg
);
2245 ok(hr
== S_OK
, "should succeed, res=%x\n", hr
);
2248 hr
= IStorage_CreateStorage( stg
, storageW
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stg2
);
2249 ok(hr
== S_OK
, "should succeed, res=%x\n", hr
);
2252 hr
= IStorage_CreateStream( stg2
, streamW
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stream
);
2253 ok(hr
== S_OK
, "should succeed, res=%x\n", hr
);
2255 IStream_Release(stream
);
2256 IStorage_Release(stg2
);
2258 IStorage_Release(stg
);
2261 /* re-open read only */
2262 hr
= StgOpenStorage( fileW
, NULL
, STGM_TRANSACTED
| STGM_SHARE_DENY_NONE
| STGM_READ
, NULL
, 0, &stg
);
2263 ok(hr
== S_OK
, "should succeed, res=%x\n", hr
);
2266 hr
= IStorage_OpenStorage( stg
, storageW
, NULL
, STGM_SHARE_EXCLUSIVE
| STGM_READ
, NULL
, 0, &stg2
);
2267 ok(hr
== S_OK
, "should succeed, res=%x\n", hr
);
2270 /* CreateStream on read-only storage, name exists */
2271 hr
= IStorage_CreateStream( stg2
, streamW
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READ
, 0, 0, &stream
);
2272 ok(hr
== STG_E_ACCESSDENIED
, "should fail, res=%x\n", hr
);
2274 IStream_Release(stream
);
2276 /* CreateStream on read-only storage, name does not exist */
2277 hr
= IStorage_CreateStream( stg2
, storageW
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READ
, 0, 0, &stream
);
2278 ok(hr
== STG_E_ACCESSDENIED
, "should fail, res=%x\n", hr
);
2280 IStream_Release(stream
);
2282 /* CreateStorage on read-only storage, name exists */
2283 hr
= IStorage_CreateStorage( stg2
, streamW
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READ
, 0, 0, &stg3
);
2284 ok(hr
== STG_E_FILEALREADYEXISTS
, "should fail, res=%x\n", hr
);
2286 IStorage_Release(stg3
);
2288 /* CreateStorage on read-only storage, name does not exist */
2289 hr
= IStorage_CreateStorage( stg2
, storageW
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READ
, 0, 0, &stg3
);
2290 ok(hr
== STG_E_ACCESSDENIED
, "should fail, res=%x\n", hr
);
2292 IStorage_Release(stg3
);
2294 /* DestroyElement on read-only storage, name exists */
2295 hr
= IStorage_DestroyElement( stg2
, streamW
);
2296 ok(hr
== STG_E_ACCESSDENIED
, "should fail, res=%x\n", hr
);
2298 /* DestroyElement on read-only storage, name does not exist */
2299 hr
= IStorage_DestroyElement( stg2
, storageW
);
2300 ok(hr
== STG_E_ACCESSDENIED
, "should fail, res=%x\n", hr
);
2302 IStorage_Release(stg2
);
2305 IStorage_Release(stg
);
2308 DeleteFileA("winetest");
2311 static void test_simple(void)
2313 /* Tests for STGM_SIMPLE mode */
2315 IStorage
*stg
, *stg2
;
2318 static const WCHAR stgname
[] = { 'S','t','g',0 };
2319 static const WCHAR stmname
[] = { 'C','O','N','T','E','N','T','S',0 };
2320 static const WCHAR stmname2
[] = { 'S','m','a','l','l',0 };
2322 ULARGE_INTEGER upos
;
2326 DeleteFileA(filenameA
);
2328 r
= StgCreateDocfile( filename
, STGM_SIMPLE
| STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, &stg
);
2329 ok(r
== S_OK
, "got %08x\n", r
);
2331 r
= IStorage_CreateStorage(stg
, stgname
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stg2
);
2332 ok(r
== STG_E_INVALIDFUNCTION
, "got %08x\n", r
);
2333 if (SUCCEEDED(r
)) IStorage_Release(stg2
);
2335 r
= IStorage_CreateStream(stg
, stmname
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stm
);
2336 ok(r
== STG_E_INVALIDFLAG
, "got %08x\n", r
);
2337 r
= IStorage_CreateStream(stg
, stmname
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stm
);
2338 ok(r
== S_OK
, "got %08x\n", r
);
2340 upos
.QuadPart
= 6000;
2341 r
= IStream_SetSize(stm
, upos
);
2342 ok(r
== S_OK
, "got %08x\n", r
);
2344 r
= IStream_Write(stm
, "foo", 3, &count
);
2345 ok(r
== S_OK
, "got %08x\n", r
);
2346 ok(count
== 3, "got %d\n", count
);
2349 r
= IStream_Seek(stm
, pos
, STREAM_SEEK_CUR
, &upos
);
2350 ok(r
== S_OK
, "got %08x\n", r
);
2351 ok(upos
.QuadPart
== 3, "got %d\n", upos
.u
.LowPart
);
2353 r
= IStream_Stat(stm
, &stat
, STATFLAG_NONAME
);
2355 broken(r
== STG_E_INVALIDFUNCTION
), /* NT4 and below */
2358 ok(stat
.cbSize
.QuadPart
== 3, "got %d\n", stat
.cbSize
.u
.LowPart
);
2361 r
= IStream_Seek(stm
, pos
, STREAM_SEEK_SET
, &upos
);
2362 ok(r
== S_OK
, "got %08x\n", r
);
2363 ok(upos
.QuadPart
== 1, "got %d\n", upos
.u
.LowPart
);
2365 r
= IStream_Stat(stm
, &stat
, STATFLAG_NONAME
);
2367 broken(r
== STG_E_INVALIDFUNCTION
), /* NT4 and below */
2370 ok(stat
.cbSize
.QuadPart
== 1, "got %d\n", stat
.cbSize
.u
.LowPart
);
2372 IStream_Release(stm
);
2374 r
= IStorage_CreateStream(stg
, stmname2
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stm
);
2375 ok(r
== S_OK
, "got %08x\n", r
);
2377 upos
.QuadPart
= 100;
2378 r
= IStream_SetSize(stm
, upos
);
2379 ok(r
== S_OK
, "got %08x\n", r
);
2381 r
= IStream_Write(stm
, "foo", 3, &count
);
2382 ok(r
== S_OK
, "got %08x\n", r
);
2383 ok(count
== 3, "got %d\n", count
);
2385 IStream_Release(stm
);
2387 IStorage_Commit(stg
, STGC_DEFAULT
);
2388 IStorage_Release(stg
);
2390 r
= StgOpenStorage( filename
, NULL
, STGM_SIMPLE
| STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, NULL
, 0, &stg
);
2391 if (r
== STG_E_INVALIDFLAG
)
2393 win_skip("Flag combination is not supported on NT4 and below\n");
2394 DeleteFileA(filenameA
);
2397 ok(r
== S_OK
, "got %08x\n", r
);
2399 r
= IStorage_OpenStorage(stg
, stgname
, NULL
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, NULL
, 0, &stg2
);
2400 ok(r
== STG_E_INVALIDFUNCTION
, "got %08x\n", r
);
2401 if (SUCCEEDED(r
)) IStorage_Release(stg2
);
2403 r
= IStorage_OpenStream(stg
, stmname
, NULL
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, &stm
);
2404 ok(r
== S_OK
, "got %08x\n", r
);
2406 r
= IStream_Stat(stm
, &stat
, STATFLAG_NONAME
);
2407 ok(r
== S_OK
, "got %08x\n", r
);
2408 ok(stat
.cbSize
.QuadPart
== 6000, "got %d\n", stat
.cbSize
.u
.LowPart
);
2410 IStream_Release(stm
);
2412 r
= IStorage_OpenStream(stg
, stmname2
, NULL
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, &stm
);
2413 ok(r
== S_OK
, "got %08x\n", r
);
2415 r
= IStream_Stat(stm
, &stat
, STATFLAG_NONAME
);
2416 ok(r
== S_OK
, "got %08x\n", r
);
2417 ok(stat
.cbSize
.QuadPart
== 4096, "got %d\n", stat
.cbSize
.u
.LowPart
);
2419 IStream_Release(stm
);
2422 IStorage_Release(stg
);
2424 DeleteFileA(filenameA
);
2427 static void test_fmtusertypestg(void)
2432 static const char fileA
[] = {'f','m','t','t','e','s','t',0};
2433 static const WCHAR fileW
[] = {'f','m','t','t','e','s','t',0};
2434 static WCHAR userTypeW
[] = {'S','t','g','U','s','r','T','y','p','e',0};
2435 static const WCHAR strmNameW
[] = {1,'C','o','m','p','O','b','j',0};
2436 static const STATSTG statstg_null
;
2438 hr
= StgCreateDocfile( fileW
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, &stg
);
2439 ok(hr
== S_OK
, "should succeed, res=%x\n", hr
);
2443 /* try to write the stream */
2444 hr
= WriteFmtUserTypeStg(stg
, 0, userTypeW
);
2445 ok(hr
== S_OK
, "should succeed, res=%x\n", hr
);
2447 /* check that the stream was created */
2448 hr
= IStorage_EnumElements(stg
, 0, NULL
, 0, &stat
);
2449 ok(hr
== S_OK
, "should succeed, res=%x\n", hr
);
2455 memset(&statstg
, 0xad, sizeof(statstg
));
2456 while ((hr
= IEnumSTATSTG_Next(stat
, 1, &statstg
, &got
)) == S_OK
&& got
== 1)
2458 if (strcmp_ww(statstg
.pwcsName
, strmNameW
) == 0)
2461 ok(0, "found unexpected stream or storage\n");
2462 CoTaskMemFree(statstg
.pwcsName
);
2464 ok(memcmp(&statstg
, &statstg_null
, sizeof(statstg
)) == 0, "statstg is not zeroed\n");
2465 ok(found
== TRUE
, "expected storage to contain stream \\0001CompObj\n");
2466 IEnumSTATSTG_Release(stat
);
2469 /* re-write the stream */
2470 hr
= WriteFmtUserTypeStg(stg
, 0, userTypeW
);
2471 ok(hr
== S_OK
, "should succeed, res=%x\n", hr
);
2473 /* check that the stream is still there */
2474 hr
= IStorage_EnumElements(stg
, 0, NULL
, 0, &stat
);
2475 ok(hr
== S_OK
, "should succeed, res=%x\n", hr
);
2481 memset(&statstg
, 0xad, sizeof(statstg
));
2482 while ((hr
= IEnumSTATSTG_Next(stat
, 1, &statstg
, &got
)) == S_OK
&& got
== 1)
2484 if (strcmp_ww(statstg
.pwcsName
, strmNameW
) == 0)
2487 ok(0, "found unexpected stream or storage\n");
2488 CoTaskMemFree(statstg
.pwcsName
);
2490 ok(memcmp(&statstg
, &statstg_null
, sizeof(statstg
)) == 0, "statstg is not zeroed\n");
2491 ok(found
== TRUE
, "expected storage to contain stream \\0001CompObj\n");
2492 IEnumSTATSTG_Release(stat
);
2495 IStorage_Release(stg
);
2496 DeleteFileA( fileA
);
2500 static void test_references(void)
2502 IStorage
*stg
,*stg2
;
2505 static const WCHAR StorName
[] = { 'D','a','t','a','S','p','a','c','e','I','n','f','o',0 };
2507 DeleteFileA(filenameA
);
2509 hr
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
|STGM_TRANSACTED
, 0, &stg
);
2510 ok(hr
==S_OK
, "StgCreateDocfile failed\n");
2514 IStorage_Release(stg
);
2516 hr
= StgOpenStorage( filename
, NULL
, STGM_TRANSACTED
| STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, NULL
, 0, &stg
);
2517 ok(hr
==S_OK
, "StgOpenStorage failed (result=%x)\n",hr
);
2521 hr
= IStorage_CreateStorage(stg
,StorName
,STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
,0,0,&stg2
);
2522 ok(hr
== S_OK
, "IStorage_CreateStorage failed (result=%x)\n",hr
);
2526 c1
= IStorage_AddRef(stg
);
2527 ok(c1
== 2, "creating internal storage added references to ancestor\n");
2528 c1
= IStorage_AddRef(stg
);
2529 IStorage_Release(stg2
);
2530 c2
= IStorage_AddRef(stg
) - 1;
2531 ok(c1
== c2
, "releasing internal storage removed references to ancestor\n");
2533 c1
= IStorage_Release(stg
);
2534 while ( c1
) c1
= IStorage_Release(stg
);
2538 DeleteFileA(filenameA
);
2543 * | `StreamA: "StreamA"
2545 * | `StreamB: "StreamB"
2546 * `StreamC: "StreamC"
2548 static HRESULT
create_test_file(IStorage
*dest
)
2550 IStorage
*stgA
= NULL
, *stgB
= NULL
;
2551 IStream
*strmA
= NULL
, *strmB
= NULL
, *strmC
= NULL
;
2552 const ULONG strmA_name_size
= lstrlenW(strmA_name
) * sizeof(WCHAR
);
2553 const ULONG strmB_name_size
= lstrlenW(strmB_name
) * sizeof(WCHAR
);
2554 const ULONG strmC_name_size
= lstrlenW(strmC_name
) * sizeof(WCHAR
);
2558 hr
= IStorage_CreateStorage(dest
, stgA_name
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stgA
);
2559 ok(hr
== S_OK
, "IStorage_CreateStorage failed: 0x%08x\n", hr
);
2563 hr
= IStorage_CreateStream(stgA
, strmA_name
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &strmA
);
2564 ok(hr
== S_OK
, "IStorage_CreateStream failed: 0x%08x\n", hr
);
2568 hr
= IStream_Write(strmA
, strmA_name
, strmA_name_size
, &bytes
);
2569 ok(hr
== S_OK
&& bytes
== strmA_name_size
, "IStream_Write failed: 0x%08x, %d of %d bytes written\n", hr
, bytes
, strmA_name_size
);
2571 hr
= IStorage_CreateStorage(dest
, stgB_name
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stgB
);
2572 ok(hr
== S_OK
, "IStorage_CreateStorage failed: 0x%08x\n", hr
);
2576 hr
= IStorage_CreateStream(stgB
, strmB_name
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &strmB
);
2577 ok(hr
== S_OK
, "IStorage_CreateStream failed: 0x%08x\n", hr
);
2581 hr
= IStream_Write(strmB
, strmB_name
, strmB_name_size
, &bytes
);
2582 ok(hr
== S_OK
&& bytes
== strmB_name_size
, "IStream_Write failed: 0x%08x, %d of %d bytes written\n", hr
, bytes
, strmB_name_size
);
2584 hr
= IStorage_CreateStream(dest
, strmC_name
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &strmC
);
2585 ok(hr
== S_OK
, "IStorage_CreateStream failed: 0x%08x\n", hr
);
2589 hr
= IStream_Write(strmC
, strmC_name
, strmC_name_size
, &bytes
);
2590 ok(hr
== S_OK
&& bytes
== strmC_name_size
, "IStream_Write failed: 0x%08x, %d of %d bytes written\n", hr
, bytes
, strmC_name_size
);
2594 IStream_Release(strmC
);
2596 IStream_Release(strmB
);
2598 IStorage_Release(stgB
);
2600 IStream_Release(strmA
);
2602 IStorage_Release(stgA
);
2607 static void test_copyto(void)
2609 IStorage
*file1
= NULL
, *file2
= NULL
, *stg_tmp
;
2614 /* create & populate file1 */
2615 hr
= StgCreateDocfile(file1_name
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, &file1
);
2616 ok(hr
== S_OK
, "StgCreateDocfile failed: 0x%08x\n", hr
);
2620 hr
= create_test_file(file1
);
2625 hr
= StgCreateDocfile(file2_name
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, &file2
);
2626 ok(hr
== S_OK
, "StgCreateDocfile failed: 0x%08x\n", hr
);
2630 /* copy file1 into file2 */
2631 hr
= IStorage_CopyTo(file1
, 0, NULL
, NULL
, NULL
);
2632 ok(hr
== STG_E_INVALIDPOINTER
, "CopyTo should give STG_E_INVALIDPONITER, gave: 0x%08x\n", hr
);
2634 hr
= IStorage_CopyTo(file1
, 0, NULL
, NULL
, file2
);
2635 ok(hr
== S_OK
, "CopyTo failed: 0x%08x\n", hr
);
2639 /* verify that all of file1 was copied */
2640 hr
= IStorage_OpenStorage(file2
, stgA_name
, NULL
,
2641 STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, NULL
, 0, &stg_tmp
);
2642 ok(hr
== S_OK
, "OpenStorage failed: 0x%08x\n", hr
);
2645 hr
= IStorage_OpenStream(stg_tmp
, strmA_name
, NULL
,
2646 STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, &strm_tmp
);
2647 ok(hr
== S_OK
, "OpenStream failed: 0x%08x\n", hr
);
2650 memset(buf
, 0, sizeof(buf
));
2651 hr
= IStream_Read(strm_tmp
, buf
, sizeof(buf
), NULL
);
2652 ok(hr
== S_OK
, "Read failed: 0x%08x\n", hr
);
2654 ok(strcmp_ww(buf
, strmA_name
) == 0,
2655 "Expected %s to be read, got %s\n", wine_dbgstr_w(strmA_name
), wine_dbgstr_w(buf
));
2657 IStream_Release(strm_tmp
);
2660 IStorage_Release(stg_tmp
);
2663 hr
= IStorage_OpenStorage(file2
, stgB_name
, NULL
,
2664 STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, NULL
, 0, &stg_tmp
);
2665 ok(hr
== S_OK
, "OpenStorage failed: 0x%08x\n", hr
);
2668 hr
= IStorage_OpenStream(stg_tmp
, strmB_name
, NULL
,
2669 STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, &strm_tmp
);
2670 ok(hr
== S_OK
, "OpenStream failed: 0x%08x\n", hr
);
2673 memset(buf
, 0, sizeof(buf
));
2674 hr
= IStream_Read(strm_tmp
, buf
, sizeof(buf
), NULL
);
2675 ok(hr
== S_OK
, "Read failed: 0x%08x\n", hr
);
2677 ok(strcmp_ww(buf
, strmB_name
) == 0,
2678 "Expected %s to be read, got %s\n", wine_dbgstr_w(strmB_name
), wine_dbgstr_w(buf
));
2680 IStream_Release(strm_tmp
);
2683 IStorage_Release(stg_tmp
);
2686 hr
= IStorage_OpenStream(file2
, strmC_name
, NULL
,
2687 STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, &strm_tmp
);
2688 ok(hr
== S_OK
, "OpenStream failed: 0x%08x\n", hr
);
2691 memset(buf
, 0, sizeof(buf
));
2692 hr
= IStream_Read(strm_tmp
, buf
, sizeof(buf
), NULL
);
2693 ok(hr
== S_OK
, "Read failed: 0x%08x\n", hr
);
2695 ok(strcmp_ww(buf
, strmC_name
) == 0,
2696 "Expected %s to be read, got %s\n", wine_dbgstr_w(strmC_name
), wine_dbgstr_w(buf
));
2698 IStream_Release(strm_tmp
);
2703 IStorage_Release(file1
);
2705 IStorage_Release(file2
);
2707 DeleteFileA(file1_nameA
);
2708 DeleteFileA(file2_nameA
);
2711 static void test_copyto_snbexclusions(void)
2713 static const WCHAR
*snb_exclude
[] = {stgA_name
, strmB_name
, strmC_name
, 0};
2715 IStorage
*file1
= NULL
, *file2
= NULL
, *stg_tmp
;
2720 /* create & populate file1 */
2721 hr
= StgCreateDocfile(file1_name
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, &file1
);
2722 ok(hr
== S_OK
, "StgCreateDocfile failed: 0x%08x\n", hr
);
2726 hr
= create_test_file(file1
);
2731 hr
= StgCreateDocfile(file2_name
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, &file2
);
2732 ok(hr
== S_OK
, "StgCreateDocfile failed: 0x%08x\n", hr
);
2736 /* copy file1 to file2 with name exclusions */
2737 hr
= IStorage_CopyTo(file1
, 0, NULL
, (SNB
)snb_exclude
, file2
);
2738 ok(hr
== S_OK
, "CopyTo failed: 0x%08x\n", hr
);
2742 /* verify that file1 copied over, respecting exclusions */
2743 hr
= IStorage_OpenStorage(file2
, stgA_name
, NULL
,
2744 STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, NULL
, 0, &stg_tmp
);
2745 ok(hr
== STG_E_FILENOTFOUND
, "OpenStorage should give STG_E_FILENOTFOUND, gave: 0x%08x\n", hr
);
2747 IStorage_Release(stg_tmp
);
2749 hr
= IStorage_OpenStream(file2
, strmA_name
, NULL
,
2750 STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, &strm_tmp
);
2751 ok(hr
== STG_E_FILENOTFOUND
, "OpenStream should give STG_E_FILENOTFOUND, gave: 0x%08x\n", hr
);
2753 IStream_Release(strm_tmp
);
2755 hr
= IStorage_OpenStorage(file2
, stgB_name
, NULL
,
2756 STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, NULL
, 0, &stg_tmp
);
2757 ok(hr
== S_OK
, "OpenStorage failed: 0x%08x\n", hr
);
2760 hr
= IStorage_OpenStream(stg_tmp
, strmB_name
, NULL
,
2761 STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, &strm_tmp
);
2762 ok(hr
== S_OK
, "OpenStream failed: 0x%08x\n", hr
);
2765 memset(buf
, 0, sizeof(buf
));
2766 hr
= IStream_Read(strm_tmp
, buf
, sizeof(buf
), NULL
);
2767 ok(hr
== S_OK
, "Read failed: 0x%08x\n", hr
);
2769 ok(strcmp_ww(buf
, strmB_name
) == 0,
2770 "Expected %s to be read, got %s\n", wine_dbgstr_w(strmB_name
), wine_dbgstr_w(buf
));
2772 IStream_Release(strm_tmp
);
2775 IStorage_Release(stg_tmp
);
2778 hr
= IStorage_OpenStream(file2
, strmC_name
, NULL
,
2779 STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, &strm_tmp
);
2780 ok(hr
== STG_E_FILENOTFOUND
, "OpenStream should give STG_E_FILENOTFOUND, gave: 0x%08x\n", hr
);
2782 IStream_Release(strm_tmp
);
2786 IStorage_Release(file1
);
2788 IStorage_Release(file2
);
2790 DeleteFileA(file1_nameA
);
2791 DeleteFileA(file2_nameA
);
2794 static void test_copyto_iidexclusions_storage(void)
2796 IStorage
*file1
= NULL
, *file2
= NULL
, *stg_tmp
;
2801 /* create & populate file1 */
2802 hr
= StgCreateDocfile(file1_name
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, &file1
);
2803 ok(hr
== S_OK
, "StgCreateDocfile failed: 0x%08x\n", hr
);
2807 hr
= create_test_file(file1
);
2812 hr
= StgCreateDocfile(file2_name
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, &file2
);
2813 ok(hr
== S_OK
, "StgCreateDocfile failed: 0x%08x\n", hr
);
2817 /* copy file1 to file2 with iid exclusions */
2818 hr
= IStorage_CopyTo(file1
, 1, &IID_IStorage
, NULL
, file2
);
2819 ok(hr
== S_OK
, "CopyTo failed: 0x%08x\n", hr
);
2823 /* verify that file1 copied over, respecting exclusions */
2824 hr
= IStorage_OpenStorage(file2
, stgA_name
, NULL
,
2825 STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, NULL
, 0, &stg_tmp
);
2826 ok(hr
== STG_E_FILENOTFOUND
, "OpenStorage should give STG_E_FILENOTFOUND, gave: 0x%08x\n", hr
);
2828 IStorage_Release(stg_tmp
);
2830 hr
= IStorage_OpenStream(file2
, strmA_name
, NULL
,
2831 STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, &strm_tmp
);
2832 ok(hr
== STG_E_FILENOTFOUND
, "OpenStream should give STG_E_FILENOTFOUND, gave: 0x%08x\n", hr
);
2834 IStream_Release(strm_tmp
);
2836 hr
= IStorage_OpenStorage(file2
, stgB_name
, NULL
,
2837 STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, NULL
, 0, &stg_tmp
);
2838 ok(hr
== STG_E_FILENOTFOUND
, "OpenStorage should give STG_E_FILENOTFOUND, gave: 0x%08x\n", hr
);
2840 IStorage_Release(stg_tmp
);
2842 hr
= IStorage_OpenStream(file2
, strmB_name
, NULL
,
2843 STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, &strm_tmp
);
2844 ok(hr
== STG_E_FILENOTFOUND
, "OpenStream should give STG_E_FILENOTFOUND, gave: 0x%08x\n", hr
);
2846 IStream_Release(strm_tmp
);
2848 hr
= IStorage_OpenStream(file2
, strmC_name
, NULL
,
2849 STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, &strm_tmp
);
2850 ok(hr
== S_OK
, "OpenStream failed: 0x%08x\n", hr
);
2853 memset(buf
, 0, sizeof(buf
));
2854 hr
= IStream_Read(strm_tmp
, buf
, sizeof(buf
), NULL
);
2855 ok(hr
== S_OK
, "Read failed: 0x%08x\n", hr
);
2857 ok(strcmp_ww(buf
, strmC_name
) == 0,
2858 "Expected %s to be read, got %s\n", wine_dbgstr_w(strmC_name
), wine_dbgstr_w(buf
));
2860 IStream_Release(strm_tmp
);
2865 IStorage_Release(file1
);
2867 IStorage_Release(file2
);
2869 DeleteFileA(file1_nameA
);
2870 DeleteFileA(file2_nameA
);
2873 static void test_copyto_iidexclusions_stream(void)
2875 IStorage
*file1
= NULL
, *file2
= NULL
, *stg_tmp
;
2879 /* create & populate file1 */
2880 hr
= StgCreateDocfile(file1_name
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, &file1
);
2881 ok(hr
== S_OK
, "StgCreateDocfile failed: 0x%08x\n", hr
);
2885 hr
= create_test_file(file1
);
2890 hr
= StgCreateDocfile(file2_name
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, &file2
);
2891 ok(hr
== S_OK
, "StgCreateDocfile failed: 0x%08x\n", hr
);
2895 /* copy file1 to file2 with iid exclusions */
2896 hr
= IStorage_CopyTo(file1
, 1, &IID_IStream
, NULL
, file2
);
2897 ok(hr
== S_OK
, "CopyTo failed: 0x%08x\n", hr
);
2901 /* verify that file1 copied over, respecting exclusions */
2902 hr
= IStorage_OpenStorage(file2
, stgA_name
, NULL
,
2903 STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, NULL
, 0, &stg_tmp
);
2904 ok(hr
== S_OK
, "OpenStorage failed: 0x%08x\n", hr
);
2907 hr
= IStorage_OpenStream(stg_tmp
, strmA_name
, NULL
,
2908 STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, &strm_tmp
);
2909 ok(hr
== STG_E_FILENOTFOUND
, "OpenStream should give STG_E_FILENOTFOUND, gave: 0x%08x\n", hr
);
2911 IStream_Release(strm_tmp
);
2913 IStorage_Release(stg_tmp
);
2916 hr
= IStorage_OpenStorage(file2
, stgB_name
, NULL
,
2917 STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, NULL
, 0, &stg_tmp
);
2918 ok(hr
== S_OK
, "OpenStorage failed: 0x%08x\n", hr
);
2921 hr
= IStorage_OpenStream(stg_tmp
, strmB_name
, NULL
,
2922 STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, &strm_tmp
);
2923 ok(hr
== STG_E_FILENOTFOUND
, "OpenStream should give STG_E_FILENOTFOUND, gave: 0x%08x\n", hr
);
2925 IStream_Release(strm_tmp
);
2927 IStorage_Release(stg_tmp
);
2930 hr
= IStorage_OpenStream(file2
, strmC_name
, NULL
,
2931 STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, &strm_tmp
);
2932 ok(hr
== STG_E_FILENOTFOUND
, "OpenStream should give STG_E_FILENOTFOUND, gave: 0x%08x\n", hr
);
2934 IStream_Release(strm_tmp
);
2938 IStorage_Release(file1
);
2940 IStorage_Release(file2
);
2942 DeleteFileA(file1_nameA
);
2943 DeleteFileA(file2_nameA
);
2946 static void test_rename(void)
2948 IStorage
*stg
, *stg2
;
2951 static const WCHAR stgname
[] = { 'P','E','R','M','S','T','G',0 };
2952 static const WCHAR stgname2
[] = { 'S','T','G',0 };
2953 static const WCHAR stmname
[] = { 'C','O','N','T','E','N','T','S',0 };
2954 static const WCHAR stmname2
[] = { 'E','N','T','S',0 };
2957 DeleteFileA(filenameA
);
2959 /* create the file */
2960 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
|
2961 STGM_READWRITE
, 0, &stg
);
2962 ok(r
==S_OK
, "StgCreateDocfile failed\n");
2964 /* create a substorage */
2965 r
= IStorage_CreateStorage(stg
, stgname
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stg2
);
2966 ok(r
==S_OK
, "IStorage->CreateStorage failed, hr=%08x\n", r
);
2968 /* create a stream in the substorage */
2969 r
= IStorage_CreateStream(stg2
, stmname
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stm
);
2970 ok(r
==S_OK
, "IStorage->CreateStream failed, hr=%08x\n", r
);
2971 IStream_Release(stm
);
2973 /* rename the stream */
2974 r
= IStorage_RenameElement(stg2
, stmname
, stmname2
);
2975 ok(r
==S_OK
, "IStorage->RenameElement failed, hr=%08x\n", r
);
2977 /* cannot open stream with old name */
2978 r
= IStorage_OpenStream(stg2
, stmname
, NULL
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, &stm
);
2979 ok(r
==STG_E_FILENOTFOUND
, "IStorage_OpenStream should fail, hr=%08x\n", r
);
2980 if (SUCCEEDED(r
)) IStream_Release(stm
);
2982 /* can open stream with new name */
2983 r
= IStorage_OpenStream(stg2
, stmname2
, NULL
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, &stm
);
2984 ok(r
==S_OK
, "IStorage_OpenStream failed, hr=%08x\n", r
);
2985 if (SUCCEEDED(r
)) IStream_Release(stm
);
2987 IStorage_Release(stg2
);
2989 /* rename the storage */
2990 IStorage_RenameElement(stg
, stgname
, stgname2
);
2992 /* cannot open storage with old name */
2993 r
= IStorage_OpenStorage(stg
, stgname
, NULL
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, NULL
, 0, &stg2
);
2994 ok(r
==STG_E_FILENOTFOUND
, "IStorage_OpenStream should fail, hr=%08x\n", r
);
2995 if (SUCCEEDED(r
)) IStorage_Release(stg2
);
2997 /* can open storage with new name */
2998 r
= IStorage_OpenStorage(stg
, stgname2
, NULL
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, NULL
, 0, &stg2
);
2999 ok(r
==S_OK
, "IStorage_OpenStream should fail, hr=%08x\n", r
);
3002 /* opened storage still has the stream */
3003 r
= IStorage_OpenStream(stg2
, stmname2
, NULL
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, &stm
);
3004 ok(r
==S_OK
, "IStorage_OpenStream failed, hr=%08x\n", r
);
3005 if (SUCCEEDED(r
)) IStream_Release(stm
);
3007 IStorage_Release(stg2
);
3010 IStorage_Release(stg
);
3012 ret
= DeleteFileA(filenameA
);
3013 ok(ret
, "deleted file\n");
3016 static void test_toplevel_stat(void)
3018 IStorage
*stg
= NULL
;
3021 char prev_dir
[MAX_PATH
];
3022 char temp
[MAX_PATH
];
3023 char full_path
[MAX_PATH
];
3025 WCHAR rel_path
[MAX_PATH
];
3027 DeleteFileA(filenameA
);
3029 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
|
3030 STGM_READWRITE
|STGM_TRANSACTED
, 0, &stg
);
3031 ok(r
==S_OK
, "StgCreateDocfile failed\n");
3033 r
= IStorage_Stat( stg
, &stat
, STATFLAG_DEFAULT
);
3034 ok(r
==S_OK
, "Storage_Stat failed with error 0x%08x\n", r
);
3035 ok(!strcmp_ww(stat
.pwcsName
, filename
), "expected %s, got %s\n",
3036 wine_dbgstr_w(filename
), wine_dbgstr_w(stat
.pwcsName
));
3037 CoTaskMemFree(stat
.pwcsName
);
3039 IStorage_Release( stg
);
3041 r
= StgOpenStorage( filename
, NULL
, STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, NULL
, 0, &stg
);
3042 ok(r
==S_OK
, "StgOpenStorage failed with error 0x%08x\n", r
);
3044 r
= IStorage_Stat( stg
, &stat
, STATFLAG_DEFAULT
);
3045 ok(r
==S_OK
, "Storage_Stat failed with error 0x%08x\n", r
);
3046 ok(!strcmp_ww(stat
.pwcsName
, filename
), "expected %s, got %s\n",
3047 wine_dbgstr_w(filename
), wine_dbgstr_w(stat
.pwcsName
));
3048 CoTaskMemFree(stat
.pwcsName
);
3050 IStorage_Release( stg
);
3052 DeleteFileA(filenameA
);
3054 /* Stat always returns the full path, even for files opened with a relative path. */
3055 GetCurrentDirectoryA(MAX_PATH
, prev_dir
);
3057 GetTempPathA(MAX_PATH
, temp
);
3059 SetCurrentDirectoryA(temp
);
3061 GetFullPathNameA(filenameA
, MAX_PATH
, full_path
, &rel_pathA
);
3062 MultiByteToWideChar(CP_ACP
, 0, rel_pathA
, -1, rel_path
, MAX_PATH
);
3064 r
= StgCreateDocfile( rel_path
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
|
3065 STGM_READWRITE
|STGM_TRANSACTED
, 0, &stg
);
3066 ok(r
==S_OK
, "StgCreateDocfile failed\n");
3068 r
= IStorage_Stat( stg
, &stat
, STATFLAG_DEFAULT
);
3069 ok(r
==S_OK
, "Storage_Stat failed with error 0x%08x\n", r
);
3070 ok(!strcmp_ww(stat
.pwcsName
, filename
), "expected %s, got %s\n",
3071 wine_dbgstr_w(filename
), wine_dbgstr_w(stat
.pwcsName
));
3072 CoTaskMemFree(stat
.pwcsName
);
3074 IStorage_Release( stg
);
3076 r
= StgOpenStorage( rel_path
, NULL
, STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, NULL
, 0, &stg
);
3077 ok(r
==S_OK
, "StgOpenStorage failed with error 0x%08x\n", r
);
3079 r
= IStorage_Stat( stg
, &stat
, STATFLAG_DEFAULT
);
3080 ok(r
==S_OK
, "Storage_Stat failed with error 0x%08x\n", r
);
3081 ok(!strcmp_ww(stat
.pwcsName
, filename
), "expected %s, got %s\n",
3082 wine_dbgstr_w(filename
), wine_dbgstr_w(stat
.pwcsName
));
3083 CoTaskMemFree(stat
.pwcsName
);
3085 IStorage_Release( stg
);
3087 SetCurrentDirectoryA(prev_dir
);
3089 DeleteFileA(filenameA
);
3092 static void test_substorage_enum(void)
3094 IStorage
*stg
, *stg2
;
3098 static const WCHAR stgname
[] = { 'P','E','R','M','S','T','G',0 };
3101 DeleteFileA(filenameA
);
3103 /* create the file */
3104 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
|
3105 STGM_READWRITE
, 0, &stg
);
3106 ok(r
==S_OK
, "StgCreateDocfile failed\n");
3108 /* create a substorage */
3109 r
= IStorage_CreateStorage(stg
, stgname
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stg2
);
3110 ok(r
==S_OK
, "IStorage->CreateStorage failed, hr=%08x\n", r
);
3112 /* create an enumelements */
3113 r
= IStorage_EnumElements(stg2
, 0, NULL
, 0, &ee
);
3114 ok(r
==S_OK
, "IStorage->EnumElements failed, hr=%08x\n", r
);
3116 /* release the substorage */
3117 ref
= IStorage_Release(stg2
);
3118 todo_wine
ok(ref
==0, "storage not released\n");
3120 /* reopening fails, because the substorage is really still open */
3121 r
= IStorage_OpenStorage(stg
, stgname
, NULL
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stg2
);
3122 ok(r
==STG_E_ACCESSDENIED
, "IStorage->OpenStorage failed, hr=%08x\n", r
);
3124 /* destroying the storage invalidates the enumerator */
3125 r
= IStorage_DestroyElement(stg
, stgname
);
3126 ok(r
==S_OK
, "IStorage->CreateStorage failed, hr=%08x\n", r
);
3128 r
= IEnumSTATSTG_Reset(ee
);
3129 ok(r
==STG_E_REVERTED
, "IEnumSTATSTG->Reset failed, hr=%08x\n", r
);
3131 IEnumSTATSTG_Release(ee
);
3133 IStorage_Release(stg
);
3135 ret
= DeleteFileA(filenameA
);
3136 ok(ret
, "deleted file\n");
3139 static void test_copyto_locking(void)
3141 IStorage
*stg
, *stg2
, *stg3
, *stg4
;
3144 static const WCHAR stgname
[] = { 'S','T','G','1',0 };
3145 static const WCHAR stgname2
[] = { 'S','T','G','2',0 };
3146 static const WCHAR stmname
[] = { 'C','O','N','T','E','N','T','S',0 };
3149 DeleteFileA(filenameA
);
3151 /* create the file */
3152 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
|
3153 STGM_READWRITE
, 0, &stg
);
3154 ok(r
==S_OK
, "StgCreateDocfile failed\n");
3156 /* create a substorage */
3157 r
= IStorage_CreateStorage(stg
, stgname
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stg2
);
3158 ok(r
==S_OK
, "IStorage->CreateStorage failed, hr=%08x\n", r
);
3160 /* create another substorage */
3161 r
= IStorage_CreateStorage(stg
, stgname2
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stg3
);
3162 ok(r
==S_OK
, "IStorage->CreateStorage failed, hr=%08x\n", r
);
3164 /* add a stream, and leave it open */
3165 r
= IStorage_CreateStream(stg2
, stmname
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stm
);
3166 ok(r
==S_OK
, "IStorage->CreateStream failed, hr=%08x\n", r
);
3168 /* Try to copy the storage while the stream is open */
3169 r
= IStorage_CopyTo(stg2
, 0, NULL
, NULL
, stg3
);
3170 ok(r
==S_OK
, "IStorage->CopyTo failed, hr=%08x\n", r
);
3172 IStream_Release(stm
);
3174 /* create a substorage */
3175 r
= IStorage_CreateStorage(stg2
, stgname
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stg4
);
3176 ok(r
==S_OK
, "IStorage->CreateStorage failed, hr=%08x\n", r
);
3178 /* Try to copy the storage while the substorage is open */
3179 r
= IStorage_CopyTo(stg2
, 0, NULL
, NULL
, stg3
);
3180 ok(r
==S_OK
, "IStorage->CopyTo failed, hr=%08x\n", r
);
3182 IStorage_Release(stg4
);
3183 IStorage_Release(stg3
);
3184 IStorage_Release(stg2
);
3185 IStorage_Release(stg
);
3187 ret
= DeleteFileA(filenameA
);
3188 ok(ret
, "deleted file\n");
3191 static void test_copyto_recursive(void)
3193 IStorage
*stg
, *stg2
, *stg3
, *stg4
;
3195 static const WCHAR stgname
[] = { 'S','T','G','1',0 };
3196 static const WCHAR stgname2
[] = { 'S','T','G','2',0 };
3199 DeleteFileA(filenameA
);
3201 /* create the file */
3202 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
|
3203 STGM_READWRITE
, 0, &stg
);
3204 ok(r
==S_OK
, "StgCreateDocfile failed\n");
3206 /* create a substorage */
3207 r
= IStorage_CreateStorage(stg
, stgname
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stg2
);
3208 ok(r
==S_OK
, "IStorage->CreateStorage failed, hr=%08x\n", r
);
3210 /* copy the parent to the child */
3211 r
= IStorage_CopyTo(stg
, 0, NULL
, NULL
, stg2
);
3212 ok(r
==STG_E_ACCESSDENIED
, "IStorage->CopyTo failed, hr=%08x\n", r
);
3214 /* create a transacted substorage */
3215 r
= IStorage_CreateStorage(stg
, stgname2
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
| STGM_TRANSACTED
, 0, 0, &stg3
);
3216 ok(r
==S_OK
, "IStorage->CreateStorage failed, hr=%08x\n", r
);
3218 /* copy the parent to the transacted child */
3219 r
= IStorage_CopyTo(stg
, 0, NULL
, NULL
, stg2
);
3220 ok(r
==STG_E_ACCESSDENIED
, "IStorage->CopyTo failed, hr=%08x\n", r
);
3222 /* create a transacted subsubstorage */
3223 r
= IStorage_CreateStorage(stg3
, stgname2
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
| STGM_TRANSACTED
, 0, 0, &stg4
);
3224 ok(r
==S_OK
, "IStorage->CreateStorage failed, hr=%08x\n", r
);
3226 /* copy the parent to the transacted child of the transacted child */
3227 r
= IStorage_CopyTo(stg
, 0, NULL
, NULL
, stg4
);
3228 ok(r
==STG_E_ACCESSDENIED
, "IStorage->CopyTo failed, hr=%08x\n", r
);
3230 /* copy the parent but exclude storage objects */
3231 r
= IStorage_CopyTo(stg
, 1, &IID_IStorage
, NULL
, stg4
);
3232 ok(r
==S_OK
, "IStorage->CopyTo failed, hr=%08x\n", r
);
3234 IStorage_Release(stg4
);
3235 IStorage_Release(stg3
);
3236 IStorage_Release(stg2
);
3237 IStorage_Release(stg
);
3239 ret
= DeleteFileA(filenameA
);
3240 ok(ret
, "deleted file\n");
3243 static void test_hglobal_storage_creation(void)
3245 ILockBytes
*ilb
= NULL
;
3246 IStorage
*stg
= NULL
;
3250 ULARGE_INTEGER offset
;
3252 r
= CreateILockBytesOnHGlobal(NULL
, TRUE
, &ilb
);
3253 ok(r
== S_OK
, "CreateILockBytesOnHGlobal failed, hr=%x\n", r
);
3255 offset
.QuadPart
= 0;
3256 memset(junk
, 0xaa, 512);
3257 r
= ILockBytes_WriteAt(ilb
, offset
, junk
, 512, NULL
);
3258 ok(r
== S_OK
, "ILockBytes_WriteAt failed, hr=%x\n", r
);
3260 offset
.QuadPart
= 2000;
3261 r
= ILockBytes_WriteAt(ilb
, offset
, junk
, 512, NULL
);
3262 ok(r
== S_OK
, "ILockBytes_WriteAt failed, hr=%x\n", r
);
3264 r
= StgCreateDocfileOnILockBytes(ilb
, STGM_CREATE
|STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, 0, &stg
);
3265 ok(r
== S_OK
, "StgCreateDocfileOnILockBytes failed, hr=%x\n", r
);
3267 IStorage_Release(stg
);
3269 r
= StgOpenStorageOnILockBytes(ilb
, NULL
, STGM_READ
|STGM_SHARE_EXCLUSIVE
,
3271 ok(r
== S_OK
, "StgOpenStorageOnILockBytes failed, hr=%x\n", r
);
3275 r
= IStorage_Stat(stg
, &stat
, STATFLAG_NONAME
);
3276 ok(r
== S_OK
, "StgOpenStorageOnILockBytes failed, hr=%x\n", r
);
3277 ok(IsEqualCLSID(&stat
.clsid
, &GUID_NULL
), "unexpected CLSID value\n");
3279 IStorage_Release(stg
);
3282 r
= ILockBytes_Stat(ilb
, &stat
, STATFLAG_NONAME
);
3283 ok(r
== S_OK
, "ILockBytes_Stat failed, hr=%x\n", r
);
3284 ok(stat
.cbSize
.u
.LowPart
< 2512, "expected truncated size, got %d\n", stat
.cbSize
.u
.LowPart
);
3286 ILockBytes_Release(ilb
);
3289 static void test_convert(void)
3291 static const WCHAR filename
[] = {'s','t','o','r','a','g','e','.','s','t','g',0};
3295 hr
= GetConvertStg(NULL
);
3296 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
3298 hr
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, &stg
);
3299 ok(hr
== S_OK
, "StgCreateDocfile failed\n");
3300 hr
= GetConvertStg(stg
);
3301 ok(hr
== STG_E_FILENOTFOUND
, "got 0x%08x\n", hr
);
3302 hr
= SetConvertStg(stg
, TRUE
);
3303 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3304 hr
= SetConvertStg(stg
, TRUE
);
3305 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3306 hr
= GetConvertStg(stg
);
3307 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3308 hr
= SetConvertStg(stg
, FALSE
);
3309 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3310 hr
= GetConvertStg(stg
);
3311 ok(hr
== S_FALSE
, "got 0x%08x\n", hr
);
3313 IStorage_Release(stg
);
3315 DeleteFileW(filename
);
3318 static void test_direct_swmr(void)
3320 static const WCHAR fileW
[] = {'w','i','n','e','t','e','s','t',0};
3321 IDirectWriterLock
*dwlock
;
3326 /* it's possible to create in writer mode */
3327 hr
= StgCreateDocfile(fileW
, STGM_CREATE
| STGM_READWRITE
| STGM_SHARE_DENY_WRITE
| STGM_DIRECT_SWMR
, 0, &stg
);
3329 ok(hr
== S_OK
, "got %08x\n", hr
);
3331 IStorage_Release(stg
);
3335 hr
= StgCreateDocfile(fileW
, STGM_CREATE
| STGM_READWRITE
| STGM_SHARE_DENY_WRITE
| STGM_TRANSACTED
, 0, &stg
);
3336 ok(hr
== S_OK
, "got %08x\n", hr
);
3337 IStorage_Release(stg
);
3340 hr
= StgOpenStorage(fileW
, NULL
, STGM_DIRECT_SWMR
| STGM_READ
| STGM_SHARE_DENY_NONE
, NULL
, 0, &stg
);
3341 ok(hr
== S_OK
|| broken(hr
== STG_E_INVALIDFLAG
), "got %08x\n", hr
);
3344 hr
= IStorage_QueryInterface(stg
, &IID_IDirectWriterLock
, (void**)&dwlock
);
3345 ok(hr
== E_NOINTERFACE
, "got %08x\n", hr
);
3346 IStorage_Release(stg
);
3350 hr
= StgOpenStorage(fileW
, NULL
, STGM_DIRECT_SWMR
| STGM_READWRITE
| STGM_SHARE_DENY_WRITE
, NULL
, 0, &stg
);
3351 ok(hr
== S_OK
, "got %08x\n", hr
);
3354 ref
= IStorage_AddRef(stg
);
3355 IStorage_Release(stg
);
3357 hr
= IStorage_QueryInterface(stg
, &IID_IDirectWriterLock
, (void**)&dwlock
);
3358 ok(hr
== S_OK
, "got %08x\n", hr
);
3360 ref2
= IStorage_AddRef(stg
);
3361 IStorage_Release(stg
);
3362 ok(ref2
== ref
+ 1, "got %u\n", ref2
);
3364 IDirectWriterLock_Release(dwlock
);
3365 IStorage_Release(stg
);
3377 const int *locked_bytes
;
3378 const int *fail_ranges
;
3382 static const int priority_locked_bytes
[] = { 0x158, 0x181, 0x193, -1 };
3383 static const int rwex_locked_bytes
[] = { 0x193, 0x1a7, 0x1bb, 0x1cf, -1 };
3384 static const int rw_locked_bytes
[] = { 0x193, 0x1a7, -1 };
3385 static const int nosn_locked_bytes
[] = { 0x16c, 0x193, 0x1a7, 0x1cf, -1 };
3386 static const int rwdw_locked_bytes
[] = { 0x193, 0x1a7, 0x1cf, -1 };
3387 static const int wodw_locked_bytes
[] = { 0x1a7, 0x1cf, -1 };
3388 static const int tr_locked_bytes
[] = { 0x193, -1 };
3389 static const int no_locked_bytes
[] = { -1 };
3390 static const int roex_locked_bytes
[] = { 0x193, 0x1bb, 0x1cf, -1 };
3392 static const int rwex_fail_ranges
[] = { 0x193,0x1e3, -1 };
3393 static const int rw_fail_ranges
[] = { 0x1bb,0x1e3, -1 };
3394 static const int rwdw_fail_ranges
[] = { 0x1a7,0x1e3, -1 };
3395 static const int dw_fail_ranges
[] = { 0x1a7,0x1cf, -1 };
3396 static const int tr_fail_ranges
[] = { 0x1bb,0x1cf, -1 };
3397 static const int pr_fail_ranges
[] = { 0x180,0x181, 0x1bb,0x1cf, -1 };
3398 static const int roex_fail_ranges
[] = { 0x0,-1 };
3400 static const struct lock_test lock_tests
[] = {
3401 { STGM_PRIORITY
, FALSE
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, priority_locked_bytes
, pr_fail_ranges
, FALSE
},
3402 { STGM_CREATE
|STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, TRUE
, GENERIC_READ
|GENERIC_WRITE
, FILE_SHARE_READ
, rwex_locked_bytes
, 0, FALSE
},
3403 { STGM_CREATE
|STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
|STGM_TRANSACTED
, TRUE
, GENERIC_READ
|GENERIC_WRITE
, FILE_SHARE_READ
, rwex_locked_bytes
, 0, FALSE
},
3404 { STGM_CREATE
|STGM_READWRITE
|STGM_TRANSACTED
, TRUE
, GENERIC_READ
|GENERIC_WRITE
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, rw_locked_bytes
, 0, FALSE
},
3405 { STGM_CREATE
|STGM_READWRITE
|STGM_SHARE_DENY_WRITE
|STGM_TRANSACTED
, TRUE
, GENERIC_READ
|GENERIC_WRITE
, FILE_SHARE_READ
, rwdw_locked_bytes
, 0, FALSE
},
3406 { STGM_CREATE
|STGM_WRITE
|STGM_SHARE_DENY_WRITE
|STGM_TRANSACTED
, TRUE
, GENERIC_READ
|GENERIC_WRITE
, FILE_SHARE_READ
, wodw_locked_bytes
, 0, FALSE
},
3407 { STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, FALSE
, GENERIC_READ
|GENERIC_WRITE
, FILE_SHARE_READ
, rwex_locked_bytes
, rwex_fail_ranges
, FALSE
},
3408 { STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
|STGM_TRANSACTED
, FALSE
, GENERIC_READ
|GENERIC_WRITE
, FILE_SHARE_READ
, rwex_locked_bytes
, rwex_fail_ranges
, FALSE
},
3409 { STGM_READWRITE
|STGM_TRANSACTED
, FALSE
, GENERIC_READ
|GENERIC_WRITE
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, rw_locked_bytes
, rw_fail_ranges
, FALSE
},
3410 { STGM_READWRITE
|STGM_TRANSACTED
|STGM_NOSNAPSHOT
, FALSE
, GENERIC_READ
|GENERIC_WRITE
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, nosn_locked_bytes
, rwdw_fail_ranges
, FALSE
},
3411 { STGM_READWRITE
|STGM_TRANSACTED
|STGM_SHARE_DENY_WRITE
, FALSE
, GENERIC_READ
|GENERIC_WRITE
, FILE_SHARE_READ
, rwdw_locked_bytes
, rwdw_fail_ranges
, FALSE
},
3412 { STGM_READ
|STGM_SHARE_DENY_WRITE
, FALSE
, GENERIC_READ
, FILE_SHARE_READ
, no_locked_bytes
, dw_fail_ranges
, TRUE
},
3413 { STGM_READ
|STGM_TRANSACTED
, FALSE
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, tr_locked_bytes
, tr_fail_ranges
, FALSE
},
3414 { STGM_READ
|STGM_SHARE_EXCLUSIVE
, FALSE
, GENERIC_READ
, FILE_SHARE_READ
, roex_locked_bytes
, roex_fail_ranges
, FALSE
},
3415 { STGM_READ
|STGM_SHARE_EXCLUSIVE
|STGM_TRANSACTED
, FALSE
, GENERIC_READ
, FILE_SHARE_READ
, roex_locked_bytes
, roex_fail_ranges
, FALSE
},
3418 static BOOL
can_open(LPCWSTR filename
, DWORD access
, DWORD sharing
)
3422 hfile
= CreateFileW(filename
, access
, sharing
, NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
3424 if (hfile
== INVALID_HANDLE_VALUE
)
3431 static void check_sharing(LPCWSTR filename
, const struct lock_test
*current
,
3432 DWORD access
, DWORD sharing
, const char *desc
, DWORD
*open_mode
, BOOL
*any_failure
)
3434 if (can_open(filename
, access
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
))
3436 *open_mode
= access
;
3437 if (!current
->todo
|| (current
->sharing
& sharing
))
3438 ok(current
->sharing
& sharing
||
3439 broken(!(current
->sharing
& sharing
) && access
== GENERIC_WRITE
&& (current
->stg_mode
& 0xf) != STGM_READ
) /* win2k */,
3440 "file with mode %x should not be openable with %s permission\n", current
->stg_mode
, desc
);
3443 todo_wine
ok(current
->sharing
& sharing
||
3444 broken(!(current
->sharing
& sharing
) && access
== GENERIC_WRITE
&& (current
->stg_mode
& 0xf) != STGM_READ
) /* win2k */,
3445 "file with mode %x should not be openable with %s permission\n", current
->stg_mode
, desc
);
3446 *any_failure
= TRUE
;
3451 if (!current
->todo
|| !(current
->sharing
& sharing
))
3452 ok(!(current
->sharing
& sharing
), "file with mode %x should be openable with %s permission\n", current
->stg_mode
, desc
);
3455 todo_wine
ok(!(current
->sharing
& sharing
), "file with mode %x should be openable with %s permission\n", current
->stg_mode
, desc
);
3456 *any_failure
= TRUE
;
3461 static void check_access(LPCWSTR filename
, const struct lock_test
*current
,
3462 DWORD access
, DWORD sharing
, const char *desc
, DWORD open_mode
, BOOL
*any_failure
)
3464 if (can_open(filename
, open_mode
, (FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
) & ~sharing
))
3466 if (!current
->todo
|| !(current
->access
& access
))
3467 ok(!(current
->access
& access
), "file with mode %x should not be openable without %s sharing\n", current
->stg_mode
, desc
);
3470 todo_wine
ok(!(current
->access
& access
), "file with mode %x should not be openable without %s sharing\n", current
->stg_mode
, desc
);
3471 *any_failure
= TRUE
;
3476 if (!current
->todo
|| (current
->access
& access
))
3477 ok(current
->access
& access
, "file with mode %x should be openable without %s sharing\n", current
->stg_mode
, desc
);
3480 todo_wine
ok(current
->access
& access
, "file with mode %x should be openable without %s sharing\n", current
->stg_mode
, desc
);
3481 *any_failure
= TRUE
;
3486 static void test_locking(void)
3488 static const WCHAR filename
[] = {'w','i','n','e','t','e','s','t',0};
3493 for (i
=0; i
<sizeof(lock_tests
)/sizeof(lock_tests
[0]); i
++)
3495 const struct lock_test
*current
= &lock_tests
[i
];
3496 BOOL any_failure
= FALSE
;
3497 DWORD open_mode
= 0;
3499 if (current
->create
)
3501 hr
= StgCreateDocfile(filename
, current
->stg_mode
, 0, &stg
);
3502 ok(SUCCEEDED(hr
), "StgCreateDocfile with mode %x failed with hr %x\n", current
->stg_mode
, hr
);
3503 if (FAILED(hr
)) continue;
3507 hr
= StgCreateDocfile(filename
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, &stg
);
3508 ok(SUCCEEDED(hr
), "StgCreateDocfile failed with hr %x\n", hr
);
3509 if (FAILED(hr
)) continue;
3510 IStorage_Release(stg
);
3512 hr
= StgOpenStorage(filename
, NULL
, current
->stg_mode
, NULL
, 0, &stg
);
3513 ok(SUCCEEDED(hr
), "StgOpenStorage with mode %x failed with hr %x\n", current
->stg_mode
, hr
);
3516 DeleteFileW(filename
);
3521 check_sharing(filename
, current
, GENERIC_READ
, FILE_SHARE_READ
, "READ", &open_mode
, &any_failure
);
3522 check_sharing(filename
, current
, GENERIC_WRITE
, FILE_SHARE_WRITE
, "WRITE", &open_mode
, &any_failure
);
3523 check_sharing(filename
, current
, DELETE
, FILE_SHARE_DELETE
, "DELETE", &open_mode
, &any_failure
);
3528 BOOL locked
, expect_locked
;
3530 const int* next_lock
= current
->locked_bytes
;
3532 check_access(filename
, current
, GENERIC_READ
, FILE_SHARE_READ
, "READ", open_mode
, &any_failure
);
3533 check_access(filename
, current
, GENERIC_WRITE
, FILE_SHARE_WRITE
, "WRITE", open_mode
, &any_failure
);
3534 check_access(filename
, current
, DELETE
, FILE_SHARE_DELETE
, "DELETE", open_mode
, &any_failure
);
3536 hfile
= CreateFileW(filename
, open_mode
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
3537 ok(hfile
!= INVALID_HANDLE_VALUE
, "couldn't open file with mode %x\n", current
->stg_mode
);
3539 ol
.u
.s
.OffsetHigh
= 0;
3542 for (ol
.u
.s
.Offset
= 0x7ffffe00; ol
.u
.s
.Offset
!= 0x80000000; ol
.u
.s
.Offset
++)
3544 if (LockFileEx(hfile
, LOCKFILE_EXCLUSIVE_LOCK
|LOCKFILE_FAIL_IMMEDIATELY
, 0, 1, 0, &ol
))
3548 ok(!LockFileEx(hfile
, LOCKFILE_FAIL_IMMEDIATELY
, 0, 1, 0, &ol
), "shared locks should not be used\n");
3552 UnlockFileEx(hfile
, 0, 1, 0, &ol
);
3554 if ((ol
.u
.s
.Offset
&0x1ff) == *next_lock
)
3556 expect_locked
= TRUE
;
3560 expect_locked
= FALSE
;
3562 if (!current
->todo
|| locked
== expect_locked
)
3563 ok(locked
== expect_locked
, "byte %x of file with mode %x is %slocked but should %sbe\n",
3564 ol
.u
.s
.Offset
, current
->stg_mode
, locked
?"":"not ", expect_locked
?"":"not ");
3568 todo_wine
ok(locked
== expect_locked
, "byte %x of file with mode %x is %slocked but should %sbe\n",
3569 ol
.u
.s
.Offset
, current
->stg_mode
, locked
?"":"not ", expect_locked
?"":"not ");
3576 IStorage_Release( stg
);
3578 if (!current
->create
)
3581 BOOL failed
, expect_failed
=FALSE
;
3583 const int* next_range
= current
->fail_ranges
;
3585 hfile
= CreateFileW(filename
, open_mode
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
3586 ok(hfile
!= INVALID_HANDLE_VALUE
, "couldn't open file with mode %x\n", current
->stg_mode
);
3588 ol
.u
.s
.OffsetHigh
= 0;
3591 for (ol
.u
.s
.Offset
= 0x7ffffe00; ol
.u
.s
.Offset
!= 0x80000000; ol
.u
.s
.Offset
++)
3593 if (ol
.u
.s
.Offset
== 0x7fffff92 ||
3594 (ol
.u
.s
.Offset
== 0x7fffff80 && current
->stg_mode
== (STGM_TRANSACTED
|STGM_READWRITE
)) ||
3595 (ol
.u
.s
.Offset
== 0x7fffff80 && current
->stg_mode
== (STGM_TRANSACTED
|STGM_READ
)))
3596 continue; /* This makes opens hang */
3598 if (ol
.u
.s
.Offset
< 0x7fffff00)
3599 LockFileEx(hfile
, 0, 0, 1, 0, &ol
);
3601 LockFileEx(hfile
, LOCKFILE_EXCLUSIVE_LOCK
, 0, 1, 0, &ol
);
3603 hr
= StgOpenStorage(filename
, NULL
, current
->stg_mode
, NULL
, 0, &stg
);
3604 ok(hr
== S_OK
|| hr
== STG_E_LOCKVIOLATION
|| hr
== STG_E_SHAREVIOLATION
, "failed with unexpected hr %x\n", hr
);
3605 if (SUCCEEDED(hr
)) IStorage_Release(stg
);
3607 UnlockFileEx(hfile
, 0, 1, 0, &ol
);
3609 failed
= FAILED(hr
);
3611 if (!expect_failed
&& (ol
.u
.s
.Offset
&0x1ff) == next_range
[0])
3613 expect_failed
= TRUE
;
3615 else if (expect_failed
&& (ol
.u
.s
.Offset
&0x1ff) == next_range
[1])
3617 expect_failed
= FALSE
;
3621 if (!current
->todo
|| failed
== expect_failed
)
3622 ok(failed
== expect_failed
, "open with byte %x locked, mode %x %s but should %s\n",
3623 ol
.u
.s
.Offset
, current
->stg_mode
, failed
?"failed":"succeeded", expect_failed
?"fail":"succeed");
3627 todo_wine
ok(failed
== expect_failed
, "open with byte %x locked, mode %x %s but should %s\n",
3628 ol
.u
.s
.Offset
, current
->stg_mode
, failed
?"failed":"succeeded", expect_failed
?"fail":"succeed");
3635 DeleteFileW(filename
);
3637 if (current
->todo
&& !any_failure
)
3638 todo_wine
ok(1, "tests succeeded for mode %x\n", current
->stg_mode
);
3642 static void test_transacted_shared(void)
3644 IStorage
*stg
= NULL
;
3645 IStorage
*stgrw
= NULL
;
3647 IStream
*stm
= NULL
;
3648 static const WCHAR stmname
[] = { 'C','O','N','T','E','N','T','S',0 };
3650 ULARGE_INTEGER upos
;
3654 DeleteFileA(filenameA
);
3656 /* create a new transacted storage with a stream */
3657 r
= StgCreateDocfile(filename
, STGM_CREATE
|
3658 STGM_READWRITE
|STGM_TRANSACTED
, 0, &stg
);
3659 ok(r
==S_OK
, "StgCreateDocfile failed %x\n", r
);
3661 r
= WriteClassStg(stg
, &test_stg_cls
);
3662 ok(r
== S_OK
, "WriteClassStg failed %x\n", r
);
3664 r
= IStorage_CreateStream(stg
, stmname
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stm
);
3665 ok(r
==S_OK
, "IStorage->CreateStream failed %x\n", r
);
3668 r
= IStream_Seek(stm
, pos
, 0, &upos
);
3669 ok(r
==S_OK
, "IStream->Seek failed %x\n", r
);
3671 r
= IStream_Write(stm
, "aaa", 3, NULL
);
3672 ok(r
==S_OK
, "IStream->Write failed %x\n", r
);
3674 r
= IStorage_Commit(stg
, STGC_ONLYIFCURRENT
);
3675 ok(r
==S_OK
, "IStorage->Commit failed %x\n", r
);
3677 /* open a second transacted read/write storage */
3678 r
= StgOpenStorage(filename
, NULL
, STGM_READWRITE
| STGM_TRANSACTED
| STGM_SHARE_DENY_NONE
, NULL
, 0, &stgrw
);
3679 ok(r
==S_OK
, "StgOpenStorage failed %x\n", r
);
3681 /* update stream on the first storage and commit */
3683 r
= IStream_Seek(stm
, pos
, 0, &upos
);
3684 ok(r
==S_OK
, "IStream->Seek failed %x\n", r
);
3686 r
= IStream_Write(stm
, "ccc", 3, NULL
);
3687 ok(r
==S_OK
, "IStream->Write failed %x\n", r
);
3689 r
= IStorage_Commit(stg
, STGC_ONLYIFCURRENT
);
3690 ok(r
==S_OK
, "IStorage->Commit failed %x\n", r
);
3692 /* update again without committing */
3694 r
= IStream_Seek(stm
, pos
, 0, &upos
);
3695 ok(r
==S_OK
, "IStream->Seek failed %x\n", r
);
3697 r
= IStream_Write(stm
, "ddd", 3, NULL
);
3698 ok(r
==S_OK
, "IStream->Write failed %x\n", r
);
3700 IStream_Release(stm
);
3702 /* we can still read the old content from the second storage */
3703 r
= IStorage_OpenStream(stgrw
, stmname
, NULL
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, &stm
);
3704 ok(r
==S_OK
, "IStorage->OpenStream failed %x\n", r
);
3707 r
= IStream_Seek(stm
, pos
, 0, &upos
);
3708 ok(r
==S_OK
, "IStream->Seek failed %x\n", r
);
3710 r
= IStream_Read(stm
, buffer
, sizeof(buffer
), &bytesread
);
3711 ok(r
==S_OK
, "IStream->Read failed %x\n", r
);
3712 ok(bytesread
== 3, "read wrong number of bytes %i\n", bytesread
);
3713 ok(memcmp(buffer
, "aaa", 3) == 0, "wrong data\n");
3715 /* and overwrite the data */
3717 r
= IStream_Seek(stm
, pos
, 0, &upos
);
3718 ok(r
==S_OK
, "IStream->Seek failed %x\n", r
);
3720 r
= IStream_Write(stm
, "bbb", 3, NULL
);
3721 ok(r
==S_OK
, "IStream->Write failed %x\n", r
);
3723 IStream_Release(stm
);
3725 /* commit fails because we're out of date */
3726 r
= IStorage_Commit(stgrw
, STGC_ONLYIFCURRENT
);
3727 ok(r
==STG_E_NOTCURRENT
, "IStorage->Commit failed %x\n", r
);
3729 /* unless we force it */
3730 r
= IStorage_Commit(stgrw
, STGC_DEFAULT
);
3731 ok(r
==S_OK
, "IStorage->Commit failed %x\n", r
);
3733 /* reverting gets us back to the last commit from the same storage */
3734 r
= IStorage_Revert(stg
);
3735 ok(r
==S_OK
, "IStorage->Revert failed %x\n", r
);
3737 r
= IStorage_OpenStream(stg
, stmname
, NULL
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, &stm
);
3738 ok(r
==S_OK
, "IStorage->CreateStream failed %x\n", r
);
3741 r
= IStream_Seek(stm
, pos
, 0, &upos
);
3742 ok(r
==S_OK
, "IStream->Seek failed %x\n", r
);
3744 r
= IStream_Read(stm
, buffer
, sizeof(buffer
), &bytesread
);
3745 ok(r
==S_OK
, "IStream->Read failed %x\n", r
);
3746 ok(bytesread
== 3, "read wrong number of bytes %i\n", bytesread
);
3747 ok(memcmp(buffer
, "ccc", 3) == 0, "wrong data\n");
3749 /* and committing fails forever */
3750 r
= IStorage_Commit(stg
, STGC_ONLYIFCURRENT
);
3751 ok(r
==STG_E_NOTCURRENT
, "IStorage->Commit failed %x\n", r
);
3753 IStream_Release(stm
);
3755 IStorage_Release(stg
);
3756 IStorage_Release(stgrw
);
3758 DeleteFileA(filenameA
);
3761 static void test_overwrite(void)
3763 IStorage
*stg
= NULL
;
3765 IStream
*stm
= NULL
;
3766 static const WCHAR stmname
[] = { 'C','O','N','T','E','N','T','S',0 };
3767 static const WCHAR stmname2
[] = { 'C','O','N','T','E','N','T','2',0 };
3769 ULARGE_INTEGER upos
;
3771 DWORD orig_size
, new_size
;
3776 DeleteFileA(filenameA
);
3778 r
= StgCreateDocfile(filename
, STGM_CREATE
| STGM_READWRITE
| STGM_TRANSACTED
, 0, &stg
);
3779 ok(r
==S_OK
, "StgCreateDocfile failed %x\n", r
);
3781 r
= WriteClassStg(stg
, &test_stg_cls
);
3782 ok(r
== S_OK
, "WriteClassStg failed %x\n", r
);
3784 r
= IStorage_CreateStream(stg
, stmname
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stm
);
3785 ok(r
==S_OK
, "IStorage->CreateStream failed %x\n", r
);
3788 r
= IStream_Seek(stm
, pos
, STREAM_SEEK_SET
, &upos
);
3789 ok(r
==S_OK
, "IStream->Seek failed %x\n", r
);
3791 memset(buffer
, 'a', sizeof(buffer
));
3794 /* Write enough bytes to pass the minimum storage file size */
3795 r
= IStream_Write(stm
, buffer
, sizeof(buffer
), NULL
);
3796 ok(r
==S_OK
, "IStream->Write failed %x\n", r
);
3799 r
= IStorage_Commit(stg
, STGC_DEFAULT
);
3800 ok(r
==S_OK
, "IStorage->Commit failed %x\n", r
);
3802 hfile
= CreateFileA(filenameA
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
3803 NULL
, OPEN_EXISTING
, 0, NULL
);
3804 ok(hfile
!= NULL
, "couldn't open file %d\n", GetLastError());
3806 orig_size
= GetFileSize(hfile
, NULL
);
3809 r
= IStream_Seek(stm
, pos
, STREAM_SEEK_SET
, &upos
);
3810 ok(r
==S_OK
, "IStream->Seek failed %x\n", r
);
3812 r
= IStream_Write(stm
, "b", 1, NULL
);
3813 ok(r
==S_OK
, "IStream->Write failed %x\n", r
);
3815 r
= IStorage_Commit(stg
, STGC_OVERWRITE
);
3816 ok(r
==S_OK
, "IStorage->Commit failed %x\n", r
);
3818 new_size
= GetFileSize(hfile
, NULL
);
3820 todo_wine
ok(new_size
== orig_size
, "file grew from %d bytes to %d\n", orig_size
, new_size
);
3822 IStream_Release(stm
);
3824 IStorage_RenameElement(stg
, stmname
, stmname2
);
3826 r
= IStorage_Commit(stg
, STGC_OVERWRITE
);
3827 ok(r
==S_OK
, "IStorage->Commit failed %x\n", r
);
3829 new_size
= GetFileSize(hfile
, NULL
);
3831 todo_wine
ok(new_size
== orig_size
, "file grew from %d bytes to %d\n", orig_size
, new_size
);
3833 IStorage_Release(stg
);
3835 r
= StgOpenStorage(filename
, NULL
, STGM_READWRITE
| STGM_TRANSACTED
| STGM_SHARE_EXCLUSIVE
, NULL
, 0, &stg
);
3836 ok(r
==S_OK
, "StgOpenStorage failed %x\n", r
);
3838 r
= IStorage_OpenStream(stg
, stmname2
, NULL
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, &stm
);
3839 ok(r
==S_OK
, "IStorage->CreateStream failed %x\n", r
);
3841 r
= IStream_Read(stm
, buffer
, sizeof(buffer
), &bytesread
);
3842 ok(r
==S_OK
, "IStream->Write failed %x\n", r
);
3843 ok(bytesread
== sizeof(buffer
), "only read %d bytes\n", bytesread
);
3844 ok(buffer
[0] == 'b', "unexpected data at byte 0\n");
3846 for (i
=1; i
<sizeof(buffer
); i
++)
3847 if (buffer
[i
] != 'a')
3849 ok(i
== sizeof(buffer
), "unexpected data at byte %i\n", i
);
3852 r
= IStream_Seek(stm
, pos
, STREAM_SEEK_SET
, &upos
);
3853 ok(r
==S_OK
, "IStream->Seek failed %x\n", r
);
3855 r
= IStream_Write(stm
, "c", 1, NULL
);
3856 ok(r
==S_OK
, "IStream->Write failed %x\n", r
);
3858 r
= IStorage_Commit(stg
, STGC_OVERWRITE
);
3859 ok(r
==S_OK
, "IStorage->Commit failed %x\n", r
);
3861 new_size
= GetFileSize(hfile
, NULL
);
3863 todo_wine
ok(new_size
== orig_size
, "file grew from %d bytes to %d\n", orig_size
, new_size
);
3865 IStream_Release(stm
);
3867 IStorage_Release(stg
);
3871 DeleteFileA(filenameA
);
3874 static void test_custom_lockbytes(void)
3876 static const WCHAR stmname
[] = { 'C','O','N','T','E','N','T','S',0 };
3877 TestLockBytes
* lockbytes
;
3882 CreateTestLockBytes(&lockbytes
);
3884 hr
= StgCreateDocfileOnILockBytes(&lockbytes
->ILockBytes_iface
, STGM_CREATE
|STGM_READWRITE
|STGM_TRANSACTED
, 0, &stg
);
3885 ok(hr
==S_OK
, "StgCreateDocfileOnILockBytes failed %x\n", hr
);
3887 hr
= IStorage_CreateStream(stg
, stmname
, STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, 0, 0, &stm
);
3888 ok(hr
==S_OK
, "IStorage_CreateStream failed %x\n", hr
);
3890 IStream_Release(stm
);
3892 hr
= IStorage_Commit(stg
, 0);
3894 IStorage_Release(stg
);
3896 ok(!lockbytes
->lock_called
, "unexpected call to LockRegion\n");
3898 lockbytes
->locks_supported
= LOCK_WRITE
|LOCK_EXCLUSIVE
|LOCK_ONLYONCE
;
3900 hr
= StgCreateDocfileOnILockBytes(&lockbytes
->ILockBytes_iface
, STGM_CREATE
|STGM_READWRITE
|STGM_TRANSACTED
, 0, &stg
);
3901 ok(hr
==S_OK
, "StgCreateDocfileOnILockBytes failed %x\n", hr
);
3903 hr
= IStorage_CreateStream(stg
, stmname
, STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, 0, 0, &stm
);
3904 ok(hr
==S_OK
, "IStorage_CreateStream failed %x\n", hr
);
3906 IStream_Release(stm
);
3908 hr
= IStorage_Commit(stg
, 0);
3910 IStorage_Release(stg
);
3912 ok(lockbytes
->lock_called
, "expected LockRegion to be called\n");
3914 lockbytes
->lock_hr
= STG_E_INVALIDFUNCTION
;
3916 hr
= StgCreateDocfileOnILockBytes(&lockbytes
->ILockBytes_iface
, STGM_CREATE
|STGM_READWRITE
|STGM_TRANSACTED
, 0, &stg
);
3917 ok(hr
==STG_E_INVALIDFUNCTION
, "StgCreateDocfileOnILockBytes failed %x\n", hr
);
3919 DeleteTestLockBytes(lockbytes
);
3922 START_TEST(storage32
)
3924 CHAR temp
[MAX_PATH
];
3926 GetTempPathA(MAX_PATH
, temp
);
3927 if(!GetTempFileNameA(temp
, "stg", 0, filenameA
))
3929 win_skip("Could not create temp file, %u\n", GetLastError());
3932 MultiByteToWideChar(CP_ACP
, 0, filenameA
, -1, filename
, MAX_PATH
);
3933 DeleteFileA(filenameA
);
3935 test_hglobal_storage_stat();
3936 test_create_storage_modes();
3937 test_stgcreatestorageex();
3938 test_storage_stream();
3939 test_open_storage();
3940 test_storage_suminfo();
3941 test_storage_refcount();
3944 test_substorage_share();
3947 test_nonroot_transacted();
3948 test_ReadClassStm();
3950 test_writeclassstg();
3953 test_fmtusertypestg();
3956 test_copyto_snbexclusions();
3957 test_copyto_iidexclusions_storage();
3958 test_copyto_iidexclusions_stream();
3960 test_toplevel_stat();
3961 test_substorage_enum();
3962 test_copyto_locking();
3963 test_copyto_recursive();
3964 test_hglobal_storage_creation();
3968 test_transacted_shared();
3970 test_custom_lockbytes();