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
26 #include "wine/test.h"
32 DEFINE_GUID( test_stg_cls
, 0x88888888, 0x0425, 0x0000, 0,0,0,0,0,0,0,0);
34 #define ok_ole_success(hr, func) ok(hr == S_OK, func " failed with error 0x%08x\n", hr)
36 static CHAR filenameA
[MAX_PATH
];
37 static WCHAR filename
[MAX_PATH
];
39 static const char file1_nameA
[] = {'c','o','p','y','t','e','s','t','A',0};
40 static const WCHAR file1_name
[] = {'c','o','p','y','t','e','s','t','A',0};
41 static const char file2_nameA
[] = {'c','o','p','y','t','e','s','t','B',0};
42 static const WCHAR file2_name
[] = {'c','o','p','y','t','e','s','t','B',0};
43 static const WCHAR stgA_name
[] = {'S','t','o','r','a','g','e','A',0};
44 static const WCHAR stgB_name
[] = {'S','t','o','r','a','g','e','B',0};
45 static const WCHAR strmA_name
[] = {'S','t','r','e','a','m','A',0};
46 static const WCHAR strmB_name
[] = {'S','t','r','e','a','m','B',0};
47 static const WCHAR strmC_name
[] = {'S','t','r','e','a','m','C',0};
49 /* Win9x and WinMe don't have lstrcmpW */
50 static int strcmp_ww(LPCWSTR strw1
, LPCWSTR strw2
)
52 CHAR stra1
[512], stra2
[512];
53 WideCharToMultiByte(CP_ACP
, 0, strw1
, -1, stra1
, sizeof(stra1
), NULL
, NULL
);
54 WideCharToMultiByte(CP_ACP
, 0, strw2
, -1, stra2
, sizeof(stra2
), NULL
, NULL
);
55 return lstrcmpA(stra1
, stra2
);
58 static void test_hglobal_storage_stat(void)
60 ILockBytes
*ilb
= NULL
;
66 r
= CreateILockBytesOnHGlobal( NULL
, TRUE
, &ilb
);
67 ok( r
== S_OK
, "CreateILockBytesOnHGlobal failed\n");
69 mode
= STGM_CREATE
|STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
;/*0x1012*/
70 r
= StgCreateDocfileOnILockBytes( ilb
, mode
, 0, &stg
);
71 ok( r
== S_OK
, "StgCreateDocfileOnILockBytes failed\n");
73 r
= WriteClassStg( stg
, &test_stg_cls
);
74 ok( r
== S_OK
, "WriteClassStg failed\n");
76 memset( &stat
, 0, sizeof stat
);
77 r
= IStorage_Stat( stg
, &stat
, 0 );
79 ok( stat
.pwcsName
== NULL
, "storage name not null\n");
80 ok( stat
.type
== 1, "type is wrong\n");
81 ok( stat
.grfMode
== 0x12, "grf mode is incorrect\n");
82 ok( !memcmp(&stat
.clsid
, &test_stg_cls
, sizeof test_stg_cls
), "CLSID is wrong\n");
84 refcount
= IStorage_Release( stg
);
85 ok( refcount
== 0, "IStorage refcount is wrong\n");
86 refcount
= ILockBytes_Release( ilb
);
87 ok( refcount
== 0, "ILockBytes refcount is wrong\n");
90 static void test_create_storage_modes(void)
95 DeleteFileA(filenameA
);
97 /* test with some invalid parameters */
98 r
= StgCreateDocfile( NULL
, 0, 0, &stg
);
99 ok(r
==STG_E_INVALIDFLAG
, "StgCreateDocfile succeeded\n");
100 r
= StgCreateDocfile( filename
, 0, 0, &stg
);
101 ok(r
==STG_E_INVALIDFLAG
, "StgCreateDocfile succeeded\n");
102 r
= StgCreateDocfile( filename
, STGM_CREATE
, 0, &stg
);
103 ok(r
==STG_E_INVALIDFLAG
, "StgCreateDocfile succeeded\n");
104 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_READWRITE
, 0, &stg
);
105 ok(r
==STG_E_INVALIDFLAG
, "StgCreateDocfile succeeded\n");
106 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
, 0, &stg
);
107 ok(r
==STG_E_INVALIDFLAG
, "StgCreateDocfile succeeded\n");
108 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, NULL
);
109 ok(r
==STG_E_INVALIDPOINTER
, "StgCreateDocfile succeeded\n");
110 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 1, &stg
);
111 ok(r
==STG_E_INVALIDPARAMETER
, "StgCreateDocfile succeeded\n");
112 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_SHARE_DENY_WRITE
| STGM_READWRITE
, 0, &stg
);
113 ok(r
==STG_E_INVALIDFLAG
, "StgCreateDocfile succeeded\n");
114 r
= StgCreateDocfile( filename
, STGM_SHARE_EXCLUSIVE
| STGM_READ
, 0, &stg
);
115 ok(r
==STG_E_INVALIDFLAG
, "StgCreateDocfile succeeded\n");
116 r
= StgCreateDocfile( filename
, STGM_PRIORITY
, 0, &stg
);
117 ok(r
==STG_E_INVALIDFLAG
, "StgCreateDocfile succeeded\n");
119 /* StgCreateDocfile seems to be very particular about the flags it accepts */
120 r
= StgCreateDocfile( filename
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
|STGM_TRANSACTED
| STGM_WRITE
, 0, &stg
);
121 ok(r
==STG_E_INVALIDFLAG
, "StgCreateDocfile succeeded\n");
122 r
= StgCreateDocfile( filename
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
|STGM_TRANSACTED
| 8, 0, &stg
);
123 ok(r
==STG_E_INVALIDFLAG
, "StgCreateDocfile succeeded\n");
124 r
= StgCreateDocfile( filename
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
|STGM_TRANSACTED
| 0x80, 0, &stg
);
125 ok(r
==STG_E_INVALIDFLAG
, "StgCreateDocfile succeeded\n");
126 r
= StgCreateDocfile( filename
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
|STGM_TRANSACTED
| 0x800, 0, &stg
);
127 ok(r
==STG_E_INVALIDFLAG
, "StgCreateDocfile succeeded\n");
128 r
= StgCreateDocfile( filename
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
|STGM_TRANSACTED
| 0x8000, 0, &stg
);
129 ok(r
==STG_E_INVALIDFLAG
, "StgCreateDocfile succeeded\n");
130 r
= StgCreateDocfile( filename
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
|STGM_TRANSACTED
| 0x80000, 0, &stg
);
131 ok(r
==STG_E_INVALIDFLAG
, "StgCreateDocfile succeeded\n");
132 r
= StgCreateDocfile( filename
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
|STGM_TRANSACTED
| 0x800000, 0, &stg
);
133 ok(r
==STG_E_INVALIDFLAG
, "StgCreateDocfile succeeded\n");
134 ok(stg
== NULL
, "stg was set\n");
136 /* check what happens if the file already exists (which is how it's meant to be used) */
137 r
= StgCreateDocfile( filename
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, &stg
);
138 ok(r
==S_OK
, "StgCreateDocfile failed\n");
139 r
= IStorage_Release(stg
);
140 ok(r
== 0, "storage not released\n");
141 r
= StgCreateDocfile( filename
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
|STGM_TRANSACTED
, 0, &stg
);
142 ok(r
==STG_E_FILEALREADYEXISTS
, "StgCreateDocfile wrong error\n"); /* FAILIFTHERE is default */
143 r
= StgCreateDocfile( filename
, STGM_READ
, 0, &stg
);
144 ok(r
==STG_E_INVALIDFLAG
, "StgCreateDocfile succeeded\n"); /* need at least readmode and sharemode */
145 r
= StgCreateDocfile( filename
, STGM_SHARE_EXCLUSIVE
, 0, &stg
);
146 ok(r
==STG_E_INVALIDFLAG
, "StgCreateDocfile succeeded\n");
147 r
= StgCreateDocfile( filename
, STGM_SHARE_DENY_WRITE
, 0, &stg
);
148 ok(r
==STG_E_INVALIDFLAG
, "StgCreateDocfile succeeded\n");
149 r
= StgCreateDocfile( filename
, STGM_SHARE_DENY_NONE
, 0, &stg
);
150 ok(r
==STG_E_INVALIDFLAG
, "StgCreateDocfile failed\n");
151 r
= StgCreateDocfile( filename
, STGM_SHARE_DENY_NONE
| STGM_TRANSACTED
, 0, &stg
);
152 ok(r
==STG_E_INVALIDFLAG
, "StgCreateDocfile failed\n");
153 r
= StgCreateDocfile( filename
, STGM_SHARE_DENY_NONE
| STGM_READWRITE
, 0, &stg
);
154 ok(r
==STG_E_INVALIDFLAG
, "StgCreateDocfile failed\n");
155 r
= StgCreateDocfile( filename
, STGM_SHARE_DENY_NONE
| STGM_WRITE
, 0, &stg
);
156 ok(r
==STG_E_INVALIDFLAG
, "StgCreateDocfile failed\n");
157 r
= StgCreateDocfile( filename
, STGM_SHARE_DENY_WRITE
| STGM_WRITE
, 0, &stg
);
158 ok(r
==STG_E_INVALIDFLAG
, "StgCreateDocfile failed\n");
159 r
= StgCreateDocfile( filename
, STGM_SHARE_DENY_WRITE
| STGM_READ
, 0, &stg
);
160 ok(r
==STG_E_INVALIDFLAG
, "StgCreateDocfile wrong error\n");
161 r
= StgCreateDocfile( filename
, STGM_TRANSACTED
| STGM_SHARE_DENY_WRITE
| STGM_READ
, 0, &stg
);
162 ok(r
==STG_E_INVALIDFLAG
, "StgCreateDocfile wrong error\n");
163 ok(DeleteFileA(filenameA
), "failed to delete file\n");
165 r
= StgCreateDocfile( filename
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
|STGM_TRANSACTED
, 0, &stg
);
166 ok(r
==S_OK
, "StgCreateDocfile failed\n");
167 r
= IStorage_Release(stg
);
168 ok(r
== 0, "storage not released\n");
169 r
= StgCreateDocfile( filename
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
|STGM_TRANSACTED
|STGM_FAILIFTHERE
, 0, &stg
);
170 ok(r
==STG_E_FILEALREADYEXISTS
, "StgCreateDocfile wrong error\n");
171 r
= StgCreateDocfile( filename
, STGM_SHARE_EXCLUSIVE
| STGM_WRITE
, 0, &stg
);
172 ok(r
==STG_E_FILEALREADYEXISTS
, "StgCreateDocfile wrong error\n");
174 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_SHARE_DENY_WRITE
| STGM_READWRITE
, 0, &stg
);
175 ok(r
==STG_E_INVALIDFLAG
, "StgCreateDocfile succeeded\n");
176 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
|STGM_TRANSACTED
, 0, &stg
);
177 ok(r
==S_OK
, "StgCreateDocfile failed\n");
178 r
= IStorage_Release(stg
);
179 ok(r
== 0, "storage not released\n");
180 ok(DeleteFileA(filenameA
), "failed to delete file\n");
182 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_READWRITE
|STGM_TRANSACTED
, 0, &stg
);
183 ok(r
==S_OK
, "StgCreateDocfile failed\n");
184 r
= IStorage_Release(stg
);
185 ok(r
== 0, "storage not released\n");
186 ok(DeleteFileA(filenameA
), "failed to delete file\n");
188 /* test the way excel uses StgCreateDocFile */
189 r
= StgCreateDocfile( filename
, STGM_TRANSACTED
|STGM_CREATE
|STGM_SHARE_DENY_WRITE
|STGM_READWRITE
, 0, &stg
);
190 ok(r
==S_OK
, "StgCreateDocfile the excel way failed\n");
193 r
= IStorage_Release(stg
);
194 ok(r
== 0, "storage not released\n");
195 ok(DeleteFileA(filenameA
), "failed to delete file\n");
198 /* and the way windows media uses it ... */
199 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_SHARE_DENY_NONE
| STGM_READWRITE
| STGM_TRANSACTED
, 0, &stg
);
200 ok(r
==S_OK
, "StgCreateDocfile the windows media way failed\n");
203 r
= IStorage_Release(stg
);
204 ok(r
== 0, "storage not released\n");
205 ok(DeleteFileA(filenameA
), "failed to delete file\n");
208 /* looks like we need STGM_TRANSACTED or STGM_CREATE */
209 r
= StgCreateDocfile( filename
, STGM_TRANSACTED
|STGM_SHARE_DENY_WRITE
|STGM_READWRITE
, 0, &stg
);
210 ok(r
==S_OK
, "StgCreateDocfile the excel way failed\n");
213 r
= IStorage_Release(stg
);
214 ok(r
== 0, "storage not released\n");
215 ok(DeleteFileA(filenameA
), "failed to delete file\n");
218 r
= StgCreateDocfile( filename
, STGM_TRANSACTED
|STGM_CREATE
|STGM_SHARE_DENY_WRITE
|STGM_WRITE
, 0, &stg
);
219 ok(r
==S_OK
, "StgCreateDocfile the excel way failed\n");
222 r
= IStorage_Release(stg
);
223 ok(r
== 0, "storage not released\n");
224 ok(DeleteFileA(filenameA
), "failed to delete file\n");
227 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, &stg
);
228 ok(r
==S_OK
, "StgCreateDocfile the powerpoint way failed\n");
231 r
= IStorage_Release(stg
);
232 ok(r
== 0, "storage not released\n");
233 ok(DeleteFileA(filenameA
), "failed to delete file\n");
236 /* test the way msi uses StgCreateDocfile */
237 r
= StgCreateDocfile( filename
, STGM_DIRECT
| STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, &stg
);
238 ok(r
==S_OK
, "StgCreateDocFile failed\n");
239 r
= IStorage_Release(stg
);
240 ok(r
== 0, "storage not released\n");
241 ok(DeleteFileA(filenameA
), "failed to delete file\n");
244 static void test_storage_stream(void)
246 static const WCHAR stmname
[] = { 'C','O','N','T','E','N','T','S',0 };
247 static const WCHAR longname
[] = {
248 'a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a',
249 'a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a',0
251 IStorage
*stg
= NULL
;
254 IStream
*stm2
= NULL
;
258 unsigned char buffer
[0x100];
260 DeleteFileA(filenameA
);
262 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
|STGM_TRANSACTED
, 0, &stg
);
263 ok(r
==S_OK
, "StgCreateDocfile failed\n");
265 /* try create some invalid streams */
266 r
= IStorage_CreateStream(stg
, stmname
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 1, 0, &stm
);
267 ok(r
==STG_E_INVALIDPARAMETER
, "IStorage->CreateStream wrong error\n");
268 r
= IStorage_CreateStream(stg
, stmname
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 1, &stm
);
269 ok(r
==STG_E_INVALIDPARAMETER
, "IStorage->CreateStream wrong error\n");
270 r
= IStorage_CreateStream(stg
, stmname
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, NULL
);
271 ok(r
==STG_E_INVALIDPOINTER
, "IStorage->CreateStream wrong error\n");
272 r
= IStorage_CreateStream(stg
, NULL
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stm
);
273 ok(r
==STG_E_INVALIDNAME
, "IStorage->CreateStream wrong error\n");
274 r
= IStorage_CreateStream(stg
, longname
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stm
);
275 ok(r
==STG_E_INVALIDNAME
|| broken(r
==S_OK
) /* nt4 */,
276 "IStorage->CreateStream wrong error, got %d GetLastError()=%d\n", r
, GetLastError());
277 r
= IStorage_CreateStream(stg
, stmname
, STGM_READWRITE
, 0, 0, &stm
);
278 ok(r
==STG_E_INVALIDFLAG
, "IStorage->CreateStream wrong error\n");
279 r
= IStorage_CreateStream(stg
, stmname
, STGM_READ
, 0, 0, &stm
);
280 ok(r
==STG_E_INVALIDFLAG
, "IStorage->CreateStream wrong error\n");
281 r
= IStorage_CreateStream(stg
, stmname
, STGM_WRITE
, 0, 0, &stm
);
282 ok(r
==STG_E_INVALIDFLAG
, "IStorage->CreateStream wrong error\n");
283 r
= IStorage_CreateStream(stg
, stmname
, STGM_SHARE_DENY_NONE
| STGM_READWRITE
, 0, 0, &stm
);
284 ok(r
==STG_E_INVALIDFLAG
, "IStorage->CreateStream wrong error\n");
285 r
= IStorage_CreateStream(stg
, stmname
, STGM_SHARE_DENY_NONE
| STGM_READ
, 0, 0, &stm
);
286 ok(r
==STG_E_INVALIDFLAG
, "IStorage->CreateStream wrong error\n");
288 /* now really create a stream and delete it */
289 r
= IStorage_CreateStream(stg
, stmname
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stm
);
290 ok(r
==S_OK
, "IStorage->CreateStream failed\n");
291 r
= IStream_Release(stm
);
292 ok(r
== 0, "wrong ref count\n");
293 r
= IStorage_CreateStream(stg
, stmname
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stm
);
294 ok(r
==STG_E_FILEALREADYEXISTS
, "IStorage->CreateStream failed\n");
295 r
= IStorage_DestroyElement(stg
,stmname
);
296 ok(r
==S_OK
, "IStorage->DestroyElement failed\n");
298 /* create a stream and write to it */
299 r
= IStorage_CreateStream(stg
, stmname
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stm
);
300 ok(r
==S_OK
, "IStorage->CreateStream failed\n");
302 r
= IStream_Clone(stm
, &stm2
);
303 ok(r
==S_OK
, "failed to clone stream\n");
305 r
= IStream_Write(stm
, NULL
, 0, NULL
);
306 ok(r
==STG_E_INVALIDPOINTER
, "IStream->Write wrong error\n");
307 r
= IStream_Write(stm
, "Hello\n", 0, NULL
);
308 ok(r
==S_OK
, "failed to write stream\n");
309 r
= IStream_Write(stm
, "Hello\n", 0, &count
);
310 ok(r
==S_OK
, "failed to write stream\n");
311 r
= IStream_Write(stm
, "Hello\n", 6, &count
);
312 ok(r
==S_OK
, "failed to write stream\n");
313 r
= IStream_Commit(stm
, STGC_DEFAULT
);
314 ok(r
==S_OK
, "failed to commit stream\n");
315 r
= IStream_Commit(stm
, STGC_DEFAULT
);
316 ok(r
==S_OK
, "failed to commit stream\n");
318 /* seek round a bit, reset the stream size */
320 r
= IStream_Seek(stm
, pos
, 3, &p
);
321 ok(r
==STG_E_INVALIDFUNCTION
, "IStream->Seek returned wrong error\n");
322 r
= IStream_Seek(stm
, pos
, STREAM_SEEK_SET
, NULL
);
323 ok(r
==S_OK
, "failed to seek stream\n");
324 r
= IStream_Seek(stm
, pos
, STREAM_SEEK_SET
, &p
);
325 ok(r
==S_OK
, "failed to seek stream\n");
326 r
= IStream_SetSize(stm
,p
);
327 ok(r
==S_OK
, "failed to set pos\n");
329 r
= IStream_Seek(stm
, pos
, STREAM_SEEK_SET
, &p
);
330 ok(r
==S_OK
, "failed to seek stream\n");
331 ok(p
.QuadPart
== 10, "at wrong place\n");
333 r
= IStream_Seek(stm
, pos
, STREAM_SEEK_END
, &p
);
334 ok(r
==S_OK
, "failed to seek stream\n");
335 ok(p
.QuadPart
== 0, "at wrong place\n");
336 r
= IStream_Read(stm
, buffer
, sizeof buffer
, &count
);
337 ok(r
==S_OK
, "failed to set pos\n");
338 ok(count
== 0, "read bytes from empty stream\n");
341 r
= IStream_Release(stm2
);
342 ok(r
== 0, "wrong ref count\n");
344 /* create a stream and write to it */
345 r
= IStorage_CreateStream(stg
, stmname
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stm2
);
346 ok(r
==S_OK
, "IStorage->CreateStream failed\n");
348 r
= IStream_Seek(stm
, pos
, STREAM_SEEK_SET
, &p
);
349 ok(r
==STG_E_REVERTED
, "overwritten stream should return STG_E_REVERTED instead of 0x%08x\n", r
);
351 r
= IStream_Release(stm2
);
352 ok(r
== 0, "wrong ref count\n");
353 r
= IStream_Release(stm
);
354 ok(r
== 0, "wrong ref count\n");
356 r
= IStorage_Release(stg
);
357 ok(r
== 0, "wrong ref count\n");
359 /* try create some invalid streams */
362 r
= StgOpenStorage(filename
, NULL
, STGM_READ
| STGM_SHARE_DENY_WRITE
, NULL
, 0, &stg
);
363 ok(r
== S_OK
, "should succeed\n");
366 r
= IStorage_OpenStream(stg
, stmname
, NULL
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, &stm
);
367 ok(r
== STG_E_INVALIDFLAG
, "IStorage->OpenStream should return STG_E_INVALIDFLAG instead of 0x%08x\n", r
);
368 IStorage_Release(stg
);
371 r
= DeleteFileA(filenameA
);
372 ok(r
, "file should exist\n");
375 static BOOL
touch_file(LPCSTR filename
)
379 file
= CreateFileA(filename
, GENERIC_READ
|GENERIC_WRITE
, 0, NULL
,
380 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
381 if (file
==INVALID_HANDLE_VALUE
)
387 static BOOL
is_zero_length(LPCSTR filename
)
392 file
= CreateFileA(filename
, GENERIC_READ
, 0, NULL
,
393 OPEN_EXISTING
, 0, NULL
);
394 if (file
==INVALID_HANDLE_VALUE
)
396 len
= GetFileSize(file
, NULL
);
401 static BOOL
is_existing_file(LPCSTR filename
)
405 file
= CreateFileA(filename
, GENERIC_READ
, 0, NULL
,
406 OPEN_EXISTING
, 0, NULL
);
407 if (file
==INVALID_HANDLE_VALUE
)
413 static void test_open_storage(void)
415 static const WCHAR szNonExist
[] = { 'n','o','n','e','x','i','s','t',0 };
416 IStorage
*stg
= NULL
, *stg2
= NULL
;
420 /* try opening a zero length file - it should stay zero length */
421 DeleteFileA(filenameA
);
422 touch_file(filenameA
);
423 stgm
= STGM_NOSCRATCH
| STGM_TRANSACTED
| STGM_SHARE_DENY_WRITE
| STGM_READWRITE
;
424 r
= StgOpenStorage( filename
, NULL
, stgm
, NULL
, 0, &stg
);
425 ok(r
==STG_E_FILEALREADYEXISTS
, "StgOpenStorage didn't fail\n");
427 stgm
= STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
;
428 r
= StgOpenStorage( filename
, NULL
, stgm
, NULL
, 0, &stg
);
429 ok(r
==STG_E_FILEALREADYEXISTS
, "StgOpenStorage didn't fail\n");
430 ok(is_zero_length(filenameA
), "file length changed\n");
432 DeleteFileA(filenameA
);
434 /* try opening a nonexistent file - it should not create it */
435 stgm
= STGM_DIRECT
| STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
;
436 r
= StgOpenStorage( filename
, NULL
, stgm
, NULL
, 0, &stg
);
437 ok(r
!=S_OK
, "StgOpenStorage failed: 0x%08x\n", r
);
438 if (r
==S_OK
) IStorage_Release(stg
);
439 ok(!is_existing_file(filenameA
), "StgOpenStorage should not create a file\n");
440 DeleteFileA(filenameA
);
442 /* create the file */
443 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
|STGM_TRANSACTED
, 0, &stg
);
444 ok(r
==S_OK
, "StgCreateDocfile failed\n");
445 IStorage_Release(stg
);
447 r
= StgOpenStorage( filename
, NULL
, 0, NULL
, 0, &stg
);
448 ok(r
==STG_E_INVALIDFLAG
, "StgOpenStorage wrong error\n");
449 r
= StgOpenStorage( NULL
, NULL
, STGM_SHARE_EXCLUSIVE
, NULL
, 0, &stg
);
450 ok(r
==STG_E_INVALIDNAME
, "StgOpenStorage wrong error\n");
451 r
= StgOpenStorage( filename
, NULL
, STGM_SHARE_EXCLUSIVE
| STGM_READ
, NULL
, 0, NULL
);
452 ok(r
==STG_E_INVALIDPOINTER
, "StgOpenStorage wrong error\n");
453 r
= StgOpenStorage( filename
, NULL
, STGM_SHARE_EXCLUSIVE
| STGM_READ
, NULL
, 1, &stg
);
454 ok(r
==STG_E_INVALIDPARAMETER
, "StgOpenStorage wrong error\n");
455 r
= StgOpenStorage( szNonExist
, NULL
, STGM_SHARE_EXCLUSIVE
| STGM_READ
, NULL
, 0, &stg
);
456 ok(r
==STG_E_FILENOTFOUND
, "StgOpenStorage failed\n");
457 r
= StgOpenStorage( filename
, NULL
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READ
, NULL
, 0, &stg
);
458 ok(r
==STG_E_INVALIDFLAG
, "StgOpenStorage failed\n");
459 r
= StgOpenStorage( filename
, NULL
, STGM_SHARE_DENY_NONE
| STGM_READ
, NULL
, 0, &stg
);
460 ok(r
==STG_E_INVALIDFLAG
, "StgOpenStorage failed\n");
461 r
= StgOpenStorage( filename
, NULL
, STGM_SHARE_DENY_READ
| STGM_READ
, NULL
, 0, &stg
);
462 ok(r
==STG_E_INVALIDFLAG
, "StgOpenStorage failed\n");
463 r
= StgOpenStorage( filename
, NULL
, STGM_SHARE_DENY_WRITE
| STGM_READWRITE
, NULL
, 0, &stg
);
464 ok(r
==STG_E_INVALIDFLAG
, "StgOpenStorage failed\n");
466 /* open it for real */
467 r
= StgOpenStorage( filename
, NULL
, STGM_SHARE_DENY_NONE
| STGM_READ
| STGM_TRANSACTED
, NULL
, 0, &stg
); /* XLViewer 97/2000 */
468 ok(r
==S_OK
, "StgOpenStorage failed\n");
471 r
= IStorage_Release(stg
);
472 ok(r
== 0, "wrong ref count\n");
475 r
= StgOpenStorage( filename
, NULL
, STGM_SHARE_DENY_WRITE
| STGM_READ
, NULL
, 0, &stg
);
476 ok(r
==S_OK
, "StgOpenStorage failed\n");
479 r
= IStorage_Release(stg
);
480 ok(r
== 0, "wrong ref count\n");
483 /* test the way word opens its custom dictionary */
484 r
= StgOpenStorage( filename
, NULL
, STGM_NOSCRATCH
| STGM_TRANSACTED
|
485 STGM_SHARE_DENY_WRITE
| STGM_READWRITE
, NULL
, 0, &stg
);
486 ok(r
==S_OK
, "StgOpenStorage failed\n");
489 r
= IStorage_Release(stg
);
490 ok(r
== 0, "wrong ref count\n");
493 r
= StgOpenStorage( filename
, NULL
, STGM_SHARE_EXCLUSIVE
| STGM_READ
, NULL
, 0, &stg
);
494 ok(r
==S_OK
, "StgOpenStorage failed\n");
495 r
= StgOpenStorage( filename
, NULL
, STGM_SHARE_EXCLUSIVE
| STGM_READ
, NULL
, 0, &stg2
);
496 ok(r
==STG_E_SHAREVIOLATION
, "StgOpenStorage failed\n");
499 r
= IStorage_Release(stg
);
500 ok(r
== 0, "wrong ref count\n");
503 /* now try write to a storage file we opened read-only */
504 r
= StgOpenStorage( filename
, NULL
, STGM_SHARE_EXCLUSIVE
| STGM_READ
, NULL
, 0, &stg
);
505 ok(r
==S_OK
, "StgOpenStorage failed\n");
508 static const WCHAR stmname
[] = { 'w','i','n','e','t','e','s','t',0};
510 IStorage
*stg2
= NULL
;
512 r
= IStorage_CreateStream( stg
, stmname
, STGM_WRITE
| STGM_SHARE_EXCLUSIVE
,
514 ok(r
== STG_E_ACCESSDENIED
, "CreateStream should fail\n");
515 r
= IStorage_CreateStorage( stg
, stmname
, STGM_WRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stg2
);
516 ok(r
== STG_E_ACCESSDENIED
, "CreateStream should fail\n");
518 r
= IStorage_Release(stg
);
519 ok(r
== 0, "wrong ref count\n");
522 /* open like visio 2003 */
524 r
= StgOpenStorage( filename
, NULL
, STGM_PRIORITY
| STGM_SHARE_DENY_NONE
, NULL
, 0, &stg
);
525 ok(r
== S_OK
, "should succeed\n");
527 IStorage_Release(stg
);
529 /* test other sharing modes with STGM_PRIORITY */
531 r
= StgOpenStorage( filename
, NULL
, STGM_PRIORITY
| STGM_SHARE_EXCLUSIVE
, NULL
, 0, &stg
);
532 ok(r
== S_OK
, "should succeed\n");
534 IStorage_Release(stg
);
537 r
= StgOpenStorage( filename
, NULL
, STGM_PRIORITY
| STGM_SHARE_DENY_WRITE
, NULL
, 0, &stg
);
538 ok(r
== S_OK
, "should succeed\n");
540 IStorage_Release(stg
);
543 r
= StgOpenStorage( filename
, NULL
, STGM_PRIORITY
| STGM_SHARE_DENY_READ
, NULL
, 0, &stg
);
544 ok(r
== S_OK
, "should succeed\n");
546 IStorage_Release(stg
);
548 /* open like Project 2003 */
550 r
= StgOpenStorage( filename
, NULL
, STGM_PRIORITY
, NULL
, 0, &stg
);
551 ok(r
== S_OK
, "should succeed\n");
552 r
= StgOpenStorage( filename
, NULL
, STGM_PRIORITY
, NULL
, 0, &stg2
);
553 ok(r
== S_OK
, "should succeed\n");
555 IStorage_Release(stg2
);
557 IStorage_Release(stg
);
560 r
= StgOpenStorage( filename
, NULL
, STGM_PRIORITY
| STGM_READWRITE
, NULL
, 0, &stg
);
561 ok(r
== STG_E_INVALIDFLAG
, "should fail\n");
563 r
= StgOpenStorage( filename
, NULL
, STGM_TRANSACTED
| STGM_PRIORITY
, NULL
, 0, &stg
);
564 ok(r
== STG_E_INVALIDFLAG
, "should fail\n");
566 r
= StgOpenStorage( filename
, NULL
, STGM_SIMPLE
| STGM_PRIORITY
, NULL
, 0, &stg
);
567 ok(r
== STG_E_INVALIDFLAG
, "should fail\n");
569 r
= StgOpenStorage( filename
, NULL
, STGM_DELETEONRELEASE
| STGM_PRIORITY
, NULL
, 0, &stg
);
570 ok(r
== STG_E_INVALIDFUNCTION
, "should fail\n");
572 r
= StgOpenStorage( filename
, NULL
, STGM_NOSCRATCH
| STGM_PRIORITY
, NULL
, 0, &stg
);
573 ok(r
== STG_E_INVALIDFLAG
, "should fail\n");
575 r
= StgOpenStorage( filename
, NULL
, STGM_NOSNAPSHOT
| STGM_PRIORITY
, NULL
, 0, &stg
);
576 ok(r
== STG_E_INVALIDFLAG
, "should fail\n");
578 r
= DeleteFileA(filenameA
);
579 ok(r
, "file didn't exist\n");
582 static void test_storage_suminfo(void)
584 IStorage
*stg
= NULL
;
585 IPropertySetStorage
*propset
= NULL
;
586 IPropertyStorage
*ps
= NULL
;
589 DeleteFileA(filenameA
);
591 /* create the file */
592 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
|
593 STGM_READWRITE
|STGM_TRANSACTED
, 0, &stg
);
594 ok(r
==S_OK
, "StgCreateDocfile failed\n");
596 r
= IStorage_QueryInterface( stg
, &IID_IPropertySetStorage
, (LPVOID
) &propset
);
597 ok(r
== S_OK
, "query interface failed\n");
600 r
= IPropertySetStorage_Delete( propset
, &FMTID_SummaryInformation
);
601 ok(r
== STG_E_FILENOTFOUND
, "deleted property set storage\n");
603 r
= IPropertySetStorage_Open( propset
, &FMTID_SummaryInformation
,
604 STGM_READ
| STGM_SHARE_EXCLUSIVE
, &ps
);
605 ok(r
== STG_E_FILENOTFOUND
, "opened property set storage\n");
607 r
= IPropertySetStorage_Create( propset
, &FMTID_SummaryInformation
, NULL
, 0,
608 STGM_READ
| STGM_SHARE_EXCLUSIVE
, &ps
);
609 ok(r
== STG_E_INVALIDFLAG
, "created property set storage\n");
611 r
= IPropertySetStorage_Create( propset
, &FMTID_SummaryInformation
, NULL
, 0,
613 ok(r
== STG_E_INVALIDFLAG
, "created property set storage\n");
615 r
= IPropertySetStorage_Create( propset
, &FMTID_SummaryInformation
, NULL
, 0, 0, &ps
);
616 ok(r
== STG_E_INVALIDFLAG
, "created property set storage\n");
618 r
= IPropertySetStorage_Create( propset
, &FMTID_SummaryInformation
, NULL
, 0,
619 STGM_WRITE
|STGM_SHARE_EXCLUSIVE
, &ps
);
620 ok(r
== STG_E_INVALIDFLAG
, "created property set storage\n");
622 r
= IPropertySetStorage_Create( propset
, &FMTID_SummaryInformation
, NULL
, 0,
623 STGM_CREATE
|STGM_WRITE
|STGM_SHARE_EXCLUSIVE
, &ps
);
624 ok(r
== STG_E_INVALIDFLAG
, "created property set storage\n");
626 /* now try really creating a property set */
627 r
= IPropertySetStorage_Create( propset
, &FMTID_SummaryInformation
, NULL
, 0,
628 STGM_CREATE
|STGM_READWRITE
|STGM_SHARE_EXCLUSIVE
, &ps
);
629 ok(r
== S_OK
, "failed to create property set storage\n");
632 IPropertyStorage_Release(ps
);
634 /* now try creating the same thing again */
635 r
= IPropertySetStorage_Create( propset
, &FMTID_SummaryInformation
, NULL
, 0,
636 STGM_CREATE
|STGM_READWRITE
|STGM_SHARE_EXCLUSIVE
, &ps
);
637 ok(r
== S_OK
, "failed to create property set storage\n");
639 IPropertyStorage_Release(ps
);
641 /* should be able to open it */
642 r
= IPropertySetStorage_Open( propset
, &FMTID_SummaryInformation
,
643 STGM_READWRITE
|STGM_SHARE_EXCLUSIVE
, &ps
);
644 ok(r
== S_OK
, "open failed\n");
646 IPropertyStorage_Release(ps
);
649 r
= IPropertySetStorage_Delete( propset
, &FMTID_SummaryInformation
);
650 ok(r
== S_OK
, "failed to delete property set storage\n");
652 /* try opening with an invalid FMTID */
653 r
= IPropertySetStorage_Open( propset
, NULL
,
654 STGM_READWRITE
|STGM_SHARE_EXCLUSIVE
, &ps
);
655 ok(r
== E_INVALIDARG
, "open succeeded\n");
657 IPropertyStorage_Release(ps
);
660 r
= IPropertySetStorage_Open( propset
, &IID_IStorage
,
661 STGM_READWRITE
|STGM_SHARE_EXCLUSIVE
, &ps
);
662 ok(r
== STG_E_FILENOTFOUND
, "open succeeded\n");
664 IPropertyStorage_Release(ps
);
667 /* try some invalid flags */
668 r
= IPropertySetStorage_Open( propset
, &FMTID_SummaryInformation
,
669 STGM_CREATE
| STGM_READWRITE
|STGM_SHARE_EXCLUSIVE
, &ps
);
670 ok(r
== STG_E_INVALIDFLAG
, "open succeeded\n");
672 IPropertyStorage_Release(ps
);
674 /* after deleting it, it should be gone */
675 r
= IPropertySetStorage_Open( propset
, &FMTID_SummaryInformation
,
676 STGM_READWRITE
|STGM_SHARE_EXCLUSIVE
, &ps
);
677 ok(r
== STG_E_FILENOTFOUND
, "open failed\n");
679 IPropertyStorage_Release(ps
);
681 r
= IPropertySetStorage_Release( propset
);
682 ok(r
== 1, "ref count wrong\n");
684 r
= IStorage_Release(stg
);
685 ok(r
== 0, "ref count wrong\n");
687 DeleteFileA(filenameA
);
690 static void test_storage_refcount(void)
692 IStorage
*stg
= NULL
;
693 IStorage
*stgprio
= NULL
;
696 static const WCHAR stmname
[] = { 'C','O','N','T','E','N','T','S',0 };
702 DeleteFileA(filenameA
);
704 /* create the file */
705 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
|
706 STGM_READWRITE
|STGM_TRANSACTED
, 0, &stg
);
707 ok(r
==S_OK
, "StgCreateDocfile failed\n");
709 r
= WriteClassStg( stg
, &test_stg_cls
);
710 ok( r
== S_OK
, "WriteClassStg failed\n");
712 r
= IStorage_Commit( stg
, STGC_DEFAULT
);
713 ok( r
== S_OK
, "IStorage_Commit failed\n");
715 /* now create a stream */
716 r
= IStorage_CreateStream(stg
, stmname
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stm
);
717 ok(r
==S_OK
, "IStorage->CreateStream failed\n");
719 r
= IStorage_Release( stg
);
720 ok (r
== 0, "storage not released\n");
723 r
= IStream_Seek( stm
, pos
, 0, &upos
);
724 ok (r
== STG_E_REVERTED
, "seek should fail\n");
726 r
= IStream_Stat( stm
, &stat
, STATFLAG_DEFAULT
);
727 ok (r
== STG_E_REVERTED
, "stat should fail\n");
729 r
= IStream_Write( stm
, "Test string", strlen("Test string"), NULL
);
730 ok (r
== STG_E_REVERTED
, "IStream_Write should return STG_E_REVERTED instead of 0x%08x\n", r
);
732 r
= IStream_Read( stm
, buffer
, sizeof(buffer
), NULL
);
733 ok (r
== STG_E_REVERTED
, "IStream_Read should return STG_E_REVERTED instead of 0x%08x\n", r
);
735 r
= IStream_Release(stm
);
736 ok (r
== 0, "stream not released\n");
738 /* tests that STGM_PRIORITY doesn't prevent readwrite access from other
739 * StgOpenStorage calls in transacted mode */
740 r
= StgOpenStorage( filename
, NULL
, STGM_PRIORITY
, NULL
, 0, &stgprio
);
741 ok(r
==S_OK
, "StgOpenStorage failed with error 0x%08x\n", r
);
744 /* non-transacted mode read/write fails */
745 r
= StgOpenStorage( filename
, NULL
, STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, NULL
, 0, &stg
);
746 ok(r
==STG_E_LOCKVIOLATION
, "StgOpenStorage should return STG_E_LOCKVIOLATION instead of 0x%08x\n", r
);
749 /* non-transacted mode read-only succeeds */
750 r
= StgOpenStorage( filename
, NULL
, STGM_SHARE_DENY_WRITE
|STGM_READ
, NULL
, 0, &stg
);
751 ok(r
==S_OK
, "StgOpenStorage failed with error 0x%08x\n", r
);
752 IStorage_Release(stg
);
754 r
= StgOpenStorage( filename
, NULL
, STGM_TRANSACTED
|STGM_SHARE_DENY_WRITE
|STGM_READWRITE
, NULL
, 0, &stg
);
755 ok(r
==S_OK
, "StgOpenStorage failed with error 0x%08x\n", r
);
758 static const WCHAR stgname
[] = { ' ',' ',' ','2','9',0 };
759 static const WCHAR stgname2
[] = { 'C','V','_','i','e','w',0 };
760 static const WCHAR stmname2
[] = { 'V','a','r','2','D','a','t','a',0 };
765 r
= IStorage_Stat( stg
, &statstg
, STATFLAG_NONAME
);
766 ok(r
== S_OK
, "Stat should have succeded instead of returning 0x%08x\n", r
);
767 ok(statstg
.type
== STGTY_STORAGE
, "Statstg type should have been STGTY_STORAGE instead of %d\n", statstg
.type
);
768 ok(U(statstg
.cbSize
).LowPart
== 0, "Statstg cbSize.LowPart should have been 0 instead of %d\n", U(statstg
.cbSize
).LowPart
);
769 ok(U(statstg
.cbSize
).HighPart
== 0, "Statstg cbSize.HighPart should have been 0 instead of %d\n", U(statstg
.cbSize
).HighPart
);
770 ok(statstg
.grfMode
== (STGM_TRANSACTED
|STGM_SHARE_DENY_WRITE
|STGM_READWRITE
),
771 "Statstg grfMode should have been 0x10022 instead of 0x%x\n", statstg
.grfMode
);
772 ok(statstg
.grfLocksSupported
== 0, "Statstg grfLocksSupported should have been 0 instead of %d\n", statstg
.grfLocksSupported
);
773 ok(IsEqualCLSID(&statstg
.clsid
, &test_stg_cls
), "Statstg clsid is not test_stg_cls\n");
774 ok(statstg
.grfStateBits
== 0, "Statstg grfStateBits should have been 0 instead of %d\n", statstg
.grfStateBits
);
775 ok(statstg
.reserved
== 0, "Statstg reserved should have been 0 instead of %d\n", statstg
.reserved
);
777 r
= IStorage_CreateStorage( stg
, stgname
, STGM_SHARE_EXCLUSIVE
, 0, 0, &stg2
);
778 ok(r
== S_OK
, "CreateStorage should have succeeded instead of returning 0x%08x\n", r
);
780 r
= IStorage_Stat( stg2
, &statstg
, STATFLAG_DEFAULT
);
781 ok(r
== S_OK
, "Stat should have succeded instead of returning 0x%08x\n", r
);
782 ok(!memcmp(statstg
.pwcsName
, stgname
, sizeof(stgname
)),
783 "Statstg pwcsName should have been the name the storage was created with\n");
784 ok(statstg
.type
== STGTY_STORAGE
, "Statstg type should have been STGTY_STORAGE instead of %d\n", statstg
.type
);
785 ok(U(statstg
.cbSize
).LowPart
== 0, "Statstg cbSize.LowPart should have been 0 instead of %d\n", U(statstg
.cbSize
).LowPart
);
786 ok(U(statstg
.cbSize
).HighPart
== 0, "Statstg cbSize.HighPart should have been 0 instead of %d\n", U(statstg
.cbSize
).HighPart
);
787 ok(statstg
.grfMode
== STGM_SHARE_EXCLUSIVE
,
788 "Statstg grfMode should have been STGM_SHARE_EXCLUSIVE instead of 0x%x\n", statstg
.grfMode
);
789 ok(statstg
.grfLocksSupported
== 0, "Statstg grfLocksSupported should have been 0 instead of %d\n", statstg
.grfLocksSupported
);
790 ok(IsEqualCLSID(&statstg
.clsid
, &CLSID_NULL
), "Statstg clsid is not CLSID_NULL\n");
791 ok(statstg
.grfStateBits
== 0, "Statstg grfStateBits should have been 0 instead of %d\n", statstg
.grfStateBits
);
792 ok(statstg
.reserved
== 0, "Statstg reserved should have been 0 instead of %d\n", statstg
.reserved
);
793 CoTaskMemFree(statstg
.pwcsName
);
795 r
= IStorage_CreateStorage( stg2
, stgname2
, STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, 0, 0, &stg3
);
796 ok(r
== STG_E_ACCESSDENIED
, "CreateStorage should have returned STG_E_ACCESSDENIED instead of 0x%08x\n", r
);
798 r
= IStorage_CreateStream( stg2
, stmname2
, STGM_CREATE
|STGM_SHARE_EXCLUSIVE
, 0, 0, &stm
);
799 ok(r
== STG_E_ACCESSDENIED
, "CreateStream should have returned STG_E_ACCESSDENIED instead of 0x%08x\n", r
);
801 IStorage_Release(stg2
);
803 r
= IStorage_Release(stg
);
804 ok(r
== 0, "wrong ref count\n");
806 IStorage_Release(stgprio
);
808 DeleteFileA(filenameA
);
811 static void test_writeclassstg(void)
813 IStorage
*stg
= NULL
;
817 DeleteFileA(filenameA
);
819 /* create the file */
820 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
|
821 STGM_READWRITE
, 0, &stg
);
822 ok(r
==S_OK
, "StgCreateDocfile failed\n");
824 r
= ReadClassStg( NULL
, NULL
);
825 ok(r
== E_INVALIDARG
, "ReadClassStg should return E_INVALIDARG instead of 0x%08X\n", r
);
827 r
= ReadClassStg( stg
, NULL
);
828 ok(r
== E_INVALIDARG
, "ReadClassStg should return E_INVALIDARG instead of 0x%08X\n", r
);
830 temp_cls
.Data1
= 0xdeadbeef;
831 r
= ReadClassStg( stg
, &temp_cls
);
832 ok(r
== S_OK
, "ReadClassStg failed with 0x%08X\n", r
);
834 ok(IsEqualCLSID(&temp_cls
, &CLSID_NULL
), "ReadClassStg returned wrong clsid\n");
836 r
= WriteClassStg( NULL
, NULL
);
837 ok(r
== E_INVALIDARG
, "WriteClassStg should return E_INVALIDARG instead of 0x%08X\n", r
);
839 r
= WriteClassStg( stg
, NULL
);
840 ok(r
== STG_E_INVALIDPOINTER
, "WriteClassStg should return STG_E_INVALIDPOINTER instead of 0x%08X\n", r
);
842 r
= WriteClassStg( stg
, &test_stg_cls
);
843 ok( r
== S_OK
, "WriteClassStg failed with 0x%08X\n", r
);
845 r
= ReadClassStg( stg
, &temp_cls
);
846 ok( r
== S_OK
, "ReadClassStg failed with 0x%08X\n", r
);
847 ok(IsEqualCLSID(&temp_cls
, &test_stg_cls
), "ReadClassStg returned wrong clsid\n");
849 r
= IStorage_Release( stg
);
850 ok (r
== 0, "storage not released\n");
852 DeleteFileA(filenameA
);
855 static void test_streamenum(void)
857 IStorage
*stg
= NULL
;
860 static const WCHAR stmname
[] = { 'C','O','N','T','E','N','T','S',0 };
861 static const WCHAR stmname2
[] = { 'A','B','C','D','E','F','G','H','I',0 };
862 static const WCHAR stmname3
[] = { 'A','B','C','D','E','F','G','H','I','J',0 };
864 IEnumSTATSTG
*ee
= NULL
;
867 DeleteFileA(filenameA
);
869 /* create the file */
870 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
|
871 STGM_READWRITE
|STGM_TRANSACTED
, 0, &stg
);
872 ok(r
==S_OK
, "StgCreateDocfile failed\n");
874 r
= WriteClassStg( stg
, &test_stg_cls
);
875 ok( r
== S_OK
, "WriteClassStg failed\n");
877 r
= IStorage_Commit( stg
, STGC_DEFAULT
);
878 ok( r
== S_OK
, "IStorage_Commit failed\n");
880 /* now create a stream */
881 r
= IStorage_CreateStream(stg
, stmname
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stm
);
882 ok(r
==S_OK
, "IStorage->CreateStream failed\n");
884 r
= IStream_Release(stm
);
886 /* first enum ... should be 1 stream */
887 r
= IStorage_EnumElements(stg
, 0, NULL
, 0, &ee
);
888 ok(r
==S_OK
, "IStorage->EnumElements failed\n");
891 r
= IEnumSTATSTG_Next(ee
, 1, &stat
, &count
);
892 ok(r
==S_OK
, "IEnumSTATSTG->Next failed\n");
893 ok(count
== 1, "count wrong\n");
896 CoTaskMemFree(stat
.pwcsName
);
898 r
= IEnumSTATSTG_Release(ee
);
900 /* second enum... destroy the stream before reading */
901 r
= IStorage_EnumElements(stg
, 0, NULL
, 0, &ee
);
902 ok(r
==S_OK
, "IStorage->EnumElements failed\n");
904 r
= IStorage_DestroyElement(stg
, stmname
);
905 ok(r
==S_OK
, "IStorage->DestroyElement failed\n");
908 r
= IEnumSTATSTG_Next(ee
, 1, &stat
, &count
);
909 ok(r
==S_FALSE
, "IEnumSTATSTG->Next failed\n");
910 ok(count
== 0, "count wrong\n");
912 /* reset and try again */
913 r
= IEnumSTATSTG_Reset(ee
);
914 ok(r
==S_OK
, "IEnumSTATSTG->Reset failed\n");
917 r
= IEnumSTATSTG_Next(ee
, 1, &stat
, &count
);
918 ok(r
==S_FALSE
, "IEnumSTATSTG->Next failed\n");
919 ok(count
== 0, "count wrong\n");
921 /* add a stream before reading */
922 r
= IEnumSTATSTG_Reset(ee
);
923 ok(r
==S_OK
, "IEnumSTATSTG->Reset failed\n");
925 r
= IStorage_CreateStream(stg
, stmname
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stm
);
926 ok(r
==S_OK
, "IStorage->CreateStream failed\n");
928 r
= IStream_Release(stm
);
931 r
= IEnumSTATSTG_Next(ee
, 1, &stat
, &count
);
932 ok(r
==S_OK
, "IEnumSTATSTG->Next failed\n");
933 ok(count
== 1, "count wrong\n");
937 ok(lstrcmpiW(stat
.pwcsName
, stmname
) == 0, "expected CONTENTS, got %s\n", wine_dbgstr_w(stat
.pwcsName
));
938 CoTaskMemFree(stat
.pwcsName
);
941 r
= IStorage_CreateStream(stg
, stmname2
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stm
);
942 ok(r
==S_OK
, "IStorage->CreateStream failed\n");
944 r
= IStream_Release(stm
);
947 r
= IEnumSTATSTG_Next(ee
, 1, &stat
, &count
);
948 ok(r
==S_OK
, "IEnumSTATSTG->Next failed\n");
949 ok(count
== 1, "count wrong\n");
953 ok(lstrcmpiW(stat
.pwcsName
, stmname2
) == 0, "expected ABCDEFGHI, got %s\n", wine_dbgstr_w(stat
.pwcsName
));
954 CoTaskMemFree(stat
.pwcsName
);
957 /* delete previous and next stream after reading */
958 r
= IStorage_CreateStream(stg
, stmname3
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stm
);
959 ok(r
==S_OK
, "IStorage->CreateStream failed\n");
961 r
= IStream_Release(stm
);
963 r
= IEnumSTATSTG_Reset(ee
);
964 ok(r
==S_OK
, "IEnumSTATSTG->Reset failed\n");
967 r
= IEnumSTATSTG_Next(ee
, 1, &stat
, &count
);
968 ok(r
==S_OK
, "IEnumSTATSTG->Next failed\n");
969 ok(count
== 1, "count wrong\n");
973 ok(lstrcmpiW(stat
.pwcsName
, stmname
) == 0, "expected CONTENTS, got %s\n", wine_dbgstr_w(stat
.pwcsName
));
974 CoTaskMemFree(stat
.pwcsName
);
977 r
= IStorage_DestroyElement(stg
, stmname
);
978 ok(r
==S_OK
, "IStorage->DestroyElement failed\n");
980 r
= IStorage_DestroyElement(stg
, stmname2
);
981 ok(r
==S_OK
, "IStorage->DestroyElement failed\n");
984 r
= IEnumSTATSTG_Next(ee
, 1, &stat
, &count
);
985 ok(r
==S_OK
, "IEnumSTATSTG->Next failed\n");
986 ok(count
== 1, "count wrong\n");
990 ok(lstrcmpiW(stat
.pwcsName
, stmname3
) == 0, "expected ABCDEFGHIJ, got %s\n", wine_dbgstr_w(stat
.pwcsName
));
991 CoTaskMemFree(stat
.pwcsName
);
994 r
= IStorage_Release( stg
);
995 todo_wine
ok (r
== 0, "storage not released\n");
997 /* enumerator is still valid and working after the storage is released */
998 r
= IEnumSTATSTG_Reset(ee
);
999 ok(r
==S_OK
, "IEnumSTATSTG->Reset failed\n");
1002 r
= IEnumSTATSTG_Next(ee
, 1, &stat
, &count
);
1003 ok(r
==S_OK
, "IEnumSTATSTG->Next failed\n");
1004 ok(count
== 1, "count wrong\n");
1008 ok(lstrcmpiW(stat
.pwcsName
, stmname3
) == 0, "expected ABCDEFGHIJ, got %s\n", wine_dbgstr_w(stat
.pwcsName
));
1009 CoTaskMemFree(stat
.pwcsName
);
1012 /* the storage is left open until the enumerator is freed */
1013 r
= StgOpenStorage( filename
, NULL
, STGM_SHARE_EXCLUSIVE
|
1014 STGM_READWRITE
|STGM_TRANSACTED
, NULL
, 0, &stg
);
1015 ok(r
==STG_E_SHAREVIOLATION
||
1016 r
==STG_E_LOCKVIOLATION
, /* XP-SP2/W2K3-SP1 and below */
1017 "StgCreateDocfile failed, res=%x\n", r
);
1019 r
= IEnumSTATSTG_Release(ee
);
1020 ok (r
== 0, "enum not released\n");
1022 DeleteFileA(filenameA
);
1025 static void test_transact(void)
1027 IStorage
*stg
= NULL
, *stg2
= NULL
, *stg3
= NULL
;
1029 IStream
*stm
= NULL
;
1030 static const WCHAR stmname
[] = { 'C','O','N','T','E','N','T','S',0 };
1031 static const WCHAR stmname2
[] = { 'F','O','O',0 };
1032 static const WCHAR stgname
[] = { 'P','E','R','M','S','T','G',0 };
1033 static const WCHAR stgname2
[] = { 'T','E','M','P','S','T','G',0 };
1035 DeleteFileA(filenameA
);
1037 /* create the file */
1038 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
|
1039 STGM_READWRITE
|STGM_TRANSACTED
, 0, &stg
);
1040 ok(r
==S_OK
, "StgCreateDocfile failed\n");
1042 /* commit a new stream and storage */
1043 r
= IStorage_CreateStream(stg
, stmname2
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stm
);
1044 ok(r
==S_OK
, "IStorage->CreateStream failed\n");
1046 r
= IStream_Write(stm
, "this is stream 1\n", 16, NULL
);
1047 ok(r
==S_OK
, "IStream->Write failed\n");
1049 IStream_Release(stm
);
1051 r
= IStorage_CreateStorage(stg
, stgname
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stg2
);
1052 ok(r
==S_OK
, "IStorage->CreateStorage failed, hr=%08x\n", r
);
1056 /* Create two substorages but only commit one */
1057 r
= IStorage_CreateStorage(stg2
, stgname
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stg3
);
1058 ok(r
==S_OK
, "IStorage->CreateStorage failed, hr=%08x\n", r
);
1061 IStorage_Release(stg3
);
1063 r
= IStorage_Commit(stg
, 0);
1064 ok(r
==S_OK
, "IStorage->Commit failed\n");
1066 r
= IStorage_CreateStorage(stg2
, stgname2
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stg3
);
1067 ok(r
==S_OK
, "IStorage->CreateStorage failed, hr=%08x\n", r
);
1070 IStorage_Release(stg3
);
1072 IStorage_Release(stg2
);
1075 /* now create a stream and storage, but don't commit them */
1077 r
= IStorage_CreateStream(stg
, stmname
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stm
);
1078 ok(r
==S_OK
, "IStorage->CreateStream failed\n");
1080 r
= IStream_Write(stm
, "this is stream 2\n", 16, NULL
);
1081 ok(r
==S_OK
, "IStream->Write failed\n");
1083 /* IStream::Commit does nothing for OLE storage streams */
1084 r
= IStream_Commit(stm
, STGC_ONLYIFCURRENT
| STGC_DANGEROUSLYCOMMITMERELYTODISKCACHE
);
1085 ok(r
==S_OK
, "IStream->Commit failed\n");
1087 r
= IStorage_CreateStorage(stg
, stgname2
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stg2
);
1088 ok(r
==S_OK
, "IStorage->CreateStorage failed, hr=%08x\n", r
);
1091 IStorage_Release(stg2
);
1093 IStream_Release(stm
);
1095 IStorage_Release(stg
);
1099 r
= StgOpenStorage( filename
, NULL
, STGM_SHARE_DENY_NONE
| STGM_READ
| STGM_TRANSACTED
, NULL
, 0, &stg
);
1100 ok(r
==S_OK
, "StgOpenStorage failed\n");
1105 r
= IStorage_OpenStream(stg
, stmname
, NULL
, STGM_SHARE_DENY_NONE
|STGM_READ
, 0, &stm
);
1106 ok(r
==STG_E_INVALIDFLAG
, "IStorage->OpenStream failed %08x\n", r
);
1108 r
= IStorage_OpenStream(stg
, stmname
, NULL
, STGM_DELETEONRELEASE
|STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, 0, &stm
);
1109 ok(r
==STG_E_INVALIDFUNCTION
, "IStorage->OpenStream failed %08x\n", r
);
1111 r
= IStorage_OpenStream(stg
, stmname
, NULL
, STGM_TRANSACTED
|STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, 0, &stm
);
1112 ok(r
==STG_E_INVALIDFUNCTION
, "IStorage->OpenStream failed %08x\n", r
);
1114 r
= IStorage_OpenStorage(stg
, stmname
, NULL
, STGM_TRANSACTED
|STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, NULL
, 0, &stg2
);
1115 ok(r
==STG_E_FILENOTFOUND
, "IStorage->OpenStream failed %08x\n", r
);
1117 r
= IStorage_OpenStream(stg
, stmname
, NULL
, STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, 0, &stm
);
1118 ok(r
==STG_E_FILENOTFOUND
, "IStorage->OpenStream should fail %08x\n", r
);
1120 IStream_Release(stm
);
1122 r
= IStorage_OpenStorage(stg
, stgname2
, NULL
, STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, NULL
, 0, &stg2
);
1123 ok(r
==STG_E_FILENOTFOUND
, "IStorage->OpenStorage should fail %08x\n", r
);
1125 IStorage_Release(stg2
);
1127 r
= IStorage_OpenStorage(stg
, stmname2
, NULL
, STGM_TRANSACTED
|STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, NULL
, 0, &stg2
);
1128 ok(r
==STG_E_FILENOTFOUND
, "IStorage->OpenStream failed %08x\n", r
);
1130 r
= IStorage_OpenStream(stg
, stmname2
, NULL
, STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, 0, &stm
);
1131 ok(r
==S_OK
, "IStorage->OpenStream should succeed %08x\n", r
);
1133 IStream_Release(stm
);
1135 r
= IStorage_OpenStorage(stg
, stgname
, NULL
, STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, NULL
, 0, &stg2
);
1136 ok(r
==S_OK
, "IStorage->OpenStorage should succeed %08x\n", r
);
1139 r
= IStorage_OpenStorage(stg2
, stgname
, NULL
, STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, NULL
, 0, &stg3
);
1140 ok(r
==S_OK
, "IStorage->OpenStorage should succeed %08x\n", r
);
1142 IStorage_Release(stg3
);
1144 r
= IStorage_OpenStorage(stg2
, stgname2
, NULL
, STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, NULL
, 0, &stg3
);
1145 ok(r
==STG_E_FILENOTFOUND
, "IStorage->OpenStorage should fail %08x\n", r
);
1147 IStorage_Release(stg3
);
1149 IStorage_Release(stg2
);
1152 IStorage_Release(stg
);
1154 r
= DeleteFileA(filenameA
);
1155 ok( r
== TRUE
, "deleted file\n");
1158 static void test_substorage_share(void)
1160 IStorage
*stg
, *stg2
, *stg3
;
1161 IStream
*stm
, *stm2
;
1163 static const WCHAR stgname
[] = { 'P','E','R','M','S','T','G',0 };
1164 static const WCHAR stmname
[] = { 'C','O','N','T','E','N','T','S',0 };
1165 static const WCHAR othername
[] = { 'N','E','W','N','A','M','E',0 };
1167 DeleteFileA(filenameA
);
1169 /* create the file */
1170 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
|
1171 STGM_READWRITE
, 0, &stg
);
1172 ok(r
==S_OK
, "StgCreateDocfile failed\n");
1174 /* create a read/write storage and try to open it again */
1175 r
= IStorage_CreateStorage(stg
, stgname
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stg2
);
1176 ok(r
==S_OK
, "IStorage->CreateStorage failed, hr=%08x\n", r
);
1180 r
= IStorage_OpenStorage(stg
, stgname
, NULL
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stg3
);
1181 ok(r
==STG_E_ACCESSDENIED
, "IStorage->OpenStorage should fail %08x\n", r
);
1184 IStorage_Release(stg3
);
1186 r
= IStorage_OpenStorage(stg
, stgname
, NULL
, STGM_READ
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stg3
);
1187 ok(r
==STG_E_ACCESSDENIED
, "IStorage->OpenStorage should fail %08x\n", r
);
1190 IStorage_Release(stg3
);
1192 /* cannot rename the storage while it's open */
1193 r
= IStorage_RenameElement(stg
, stgname
, othername
);
1194 ok(r
==STG_E_ACCESSDENIED
, "IStorage->RenameElement should fail %08x\n", r
);
1195 if (SUCCEEDED(r
)) IStorage_RenameElement(stg
, othername
, stgname
);
1197 /* destroying an object while it's open invalidates it */
1198 r
= IStorage_DestroyElement(stg
, stgname
);
1199 ok(r
==S_OK
, "IStorage->DestroyElement failed, hr=%08x\n", r
);
1201 r
= IStorage_CreateStream(stg2
, stmname
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stm
);
1202 ok(r
==STG_E_REVERTED
, "IStorage->CreateStream failed, hr=%08x\n", r
);
1205 IStorage_Release(stm
);
1207 IStorage_Release(stg2
);
1210 /* create a read/write stream and try to open it again */
1211 r
= IStorage_CreateStream(stg
, stmname
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stm
);
1212 ok(r
==S_OK
, "IStorage->CreateStream failed, hr=%08x\n", r
);
1216 r
= IStorage_OpenStream(stg
, stmname
, NULL
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, &stm2
);
1217 ok(r
==STG_E_ACCESSDENIED
, "IStorage->OpenStream should fail %08x\n", r
);
1220 IStorage_Release(stm2
);
1222 r
= IStorage_OpenStream(stg
, stmname
, NULL
, STGM_READ
| STGM_SHARE_EXCLUSIVE
, 0, &stm2
);
1223 ok(r
==STG_E_ACCESSDENIED
, "IStorage->OpenStream should fail %08x\n", r
);
1226 IStorage_Release(stm2
);
1228 /* cannot rename the stream while it's open */
1229 r
= IStorage_RenameElement(stg
, stmname
, othername
);
1230 ok(r
==STG_E_ACCESSDENIED
, "IStorage->RenameElement should fail %08x\n", r
);
1231 if (SUCCEEDED(r
)) IStorage_RenameElement(stg
, othername
, stmname
);
1233 /* destroying an object while it's open invalidates it */
1234 r
= IStorage_DestroyElement(stg
, stmname
);
1235 ok(r
==S_OK
, "IStorage->DestroyElement failed, hr=%08x\n", r
);
1237 r
= IStream_Write(stm
, "this shouldn't work\n", 20, NULL
);
1238 ok(r
==STG_E_REVERTED
, "IStream_Write should fail %08x\n", r
);
1240 IStorage_Release(stm
);
1243 IStorage_Release(stg
);
1245 r
= DeleteFileA(filenameA
);
1246 ok( r
== TRUE
, "deleted file\n");
1249 static void test_revert(void)
1251 IStorage
*stg
= NULL
, *stg2
= NULL
, *stg3
= NULL
;
1253 IStream
*stm
= NULL
, *stm2
= NULL
;
1254 static const WCHAR stmname
[] = { 'C','O','N','T','E','N','T','S',0 };
1255 static const WCHAR stmname2
[] = { 'F','O','O',0 };
1256 static const WCHAR stgname
[] = { 'P','E','R','M','S','T','G',0 };
1257 static const WCHAR stgname2
[] = { 'T','E','M','P','S','T','G',0 };
1260 DeleteFileA(filenameA
);
1262 /* create the file */
1263 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
|
1264 STGM_READWRITE
|STGM_TRANSACTED
, 0, &stg
);
1265 ok(r
==S_OK
, "StgCreateDocfile failed\n");
1267 /* commit a new stream and storage */
1268 r
= IStorage_CreateStream(stg
, stmname2
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stm
);
1269 ok(r
==S_OK
, "IStorage->CreateStream failed\n");
1271 r
= IStream_Write(stm
, "this is stream 1\n", 16, NULL
);
1272 ok(r
==S_OK
, "IStream->Write failed\n");
1274 r
= IStorage_CreateStorage(stg
, stgname
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stg2
);
1275 ok(r
==S_OK
, "IStorage->CreateStorage failed, hr=%08x\n", r
);
1279 /* Create two substorages but only commit one */
1280 r
= IStorage_CreateStorage(stg2
, stgname
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stg3
);
1281 ok(r
==S_OK
, "IStorage->CreateStorage failed, hr=%08x\n", r
);
1284 IStorage_Release(stg3
);
1286 r
= IStorage_Commit(stg
, 0);
1287 ok(r
==S_OK
, "IStorage->Commit failed\n");
1289 r
= IStorage_CreateStorage(stg2
, stgname2
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stg3
);
1290 ok(r
==S_OK
, "IStorage->CreateStorage failed, hr=%08x\n", r
);
1293 IStorage_Release(stg3
);
1296 /* now create a stream and storage, then revert */
1297 r
= IStorage_CreateStream(stg
, stmname
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stm2
);
1298 ok(r
==S_OK
, "IStorage->CreateStream failed\n");
1300 r
= IStream_Write(stm2
, "this is stream 2\n", 16, NULL
);
1301 ok(r
==S_OK
, "IStream->Write failed\n");
1303 r
= IStorage_CreateStorage(stg
, stgname2
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stg3
);
1304 ok(r
==S_OK
, "IStorage->CreateStorage failed, hr=%08x\n", r
);
1306 r
= IStorage_Revert(stg
);
1308 /* all open objects become invalid */
1309 r
= IStream_Write(stm
, "this shouldn't work\n", 20, NULL
);
1310 ok(r
==STG_E_REVERTED
, "IStream_Write should fail %08x\n", r
);
1312 r
= IStream_Write(stm2
, "this shouldn't work\n", 20, NULL
);
1313 ok(r
==STG_E_REVERTED
, "IStream_Write should fail %08x\n", r
);
1315 r
= IStorage_Stat(stg2
, &statstg
, STATFLAG_NONAME
);
1316 ok(r
==STG_E_REVERTED
, "IStorage_Stat should fail %08x\n", r
);
1318 r
= IStorage_Stat(stg3
, &statstg
, STATFLAG_NONAME
);
1319 ok(r
==STG_E_REVERTED
, "IStorage_Stat should fail %08x\n", r
);
1321 IStream_Release(stm
);
1322 IStream_Release(stm2
);
1323 IStorage_Release(stg2
);
1324 IStorage_Release(stg3
);
1326 r
= IStorage_OpenStream(stg
, stmname
, NULL
, STGM_SHARE_DENY_NONE
|STGM_READ
, 0, &stm
);
1327 ok(r
==STG_E_INVALIDFLAG
, "IStorage->OpenStream failed %08x\n", r
);
1329 r
= IStorage_OpenStream(stg
, stmname
, NULL
, STGM_DELETEONRELEASE
|STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, 0, &stm
);
1330 ok(r
==STG_E_INVALIDFUNCTION
, "IStorage->OpenStream failed %08x\n", r
);
1332 r
= IStorage_OpenStream(stg
, stmname
, NULL
, STGM_TRANSACTED
|STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, 0, &stm
);
1333 ok(r
==STG_E_INVALIDFUNCTION
, "IStorage->OpenStream failed %08x\n", r
);
1335 r
= IStorage_OpenStorage(stg
, stmname
, NULL
, STGM_TRANSACTED
|STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, NULL
, 0, &stg2
);
1336 ok(r
==STG_E_FILENOTFOUND
, "IStorage->OpenStream failed %08x\n", r
);
1338 r
= IStorage_OpenStream(stg
, stmname
, NULL
, STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, 0, &stm
);
1339 ok(r
==STG_E_FILENOTFOUND
, "IStorage->OpenStream should fail %08x\n", r
);
1341 IStream_Release(stm
);
1343 r
= IStorage_OpenStorage(stg
, stgname2
, NULL
, STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, NULL
, 0, &stg2
);
1344 ok(r
==STG_E_FILENOTFOUND
, "IStorage->OpenStorage should fail %08x\n", r
);
1346 IStorage_Release(stg2
);
1348 r
= IStorage_OpenStorage(stg
, stmname2
, NULL
, STGM_TRANSACTED
|STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, NULL
, 0, &stg2
);
1349 ok(r
==STG_E_FILENOTFOUND
, "IStorage->OpenStream failed %08x\n", r
);
1351 r
= IStorage_OpenStream(stg
, stmname2
, NULL
, STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, 0, &stm
);
1352 ok(r
==S_OK
, "IStorage->OpenStream should succeed %08x\n", r
);
1354 IStream_Release(stm
);
1356 r
= IStorage_OpenStorage(stg
, stgname
, NULL
, STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, NULL
, 0, &stg2
);
1357 ok(r
==S_OK
, "IStorage->OpenStorage should succeed %08x\n", r
);
1360 r
= IStorage_OpenStorage(stg2
, stgname
, NULL
, STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, NULL
, 0, &stg3
);
1361 ok(r
==S_OK
, "IStorage->OpenStorage should succeed %08x\n", r
);
1363 IStorage_Release(stg3
);
1365 r
= IStorage_OpenStorage(stg2
, stgname2
, NULL
, STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, NULL
, 0, &stg3
);
1366 ok(r
==STG_E_FILENOTFOUND
, "IStorage->OpenStorage should fail %08x\n", r
);
1368 IStorage_Release(stg3
);
1370 IStorage_Release(stg2
);
1373 IStorage_Release(stg
);
1375 r
= DeleteFileA(filenameA
);
1376 ok( r
== TRUE
, "deleted file\n");
1378 /* Revert only invalidates objects in transacted mode */
1379 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
|
1380 STGM_READWRITE
, 0, &stg
);
1381 ok(r
==S_OK
, "StgCreateDocfile failed\n");
1383 r
= IStorage_CreateStream(stg
, stmname2
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stm
);
1384 ok(r
==S_OK
, "IStorage->CreateStream failed\n");
1386 r
= IStorage_Revert(stg
);
1387 ok(r
==S_OK
, "IStorage->Revert failed %08x\n", r
);
1389 r
= IStream_Write(stm
, "this works\n", 11, NULL
);
1390 ok(r
==S_OK
, "IStream_Write should succeed %08x\n", r
);
1392 IStream_Release(stm
);
1393 IStream_Release(stg
);
1395 r
= DeleteFileA(filenameA
);
1396 ok( r
== TRUE
, "deleted file\n");
1399 static void test_parent_free(void)
1401 IStorage
*stg
= NULL
, *stg2
= NULL
, *stg3
= NULL
;
1403 IStream
*stm
= NULL
;
1404 static const WCHAR stmname
[] = { 'C','O','N','T','E','N','T','S',0 };
1405 static const WCHAR stgname
[] = { 'P','E','R','M','S','T','G',0 };
1409 DeleteFileA(filenameA
);
1411 /* create the file */
1412 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
|
1413 STGM_READWRITE
|STGM_TRANSACTED
, 0, &stg
);
1414 ok(r
==S_OK
, "StgCreateDocfile failed\n");
1416 /* create a new storage */
1417 r
= IStorage_CreateStorage(stg
, stgname
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stg2
);
1418 ok(r
==S_OK
, "IStorage->CreateStorage failed, hr=%08x\n", r
);
1422 /* now create a stream inside the new storage */
1423 r
= IStorage_CreateStream(stg2
, stmname
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stm
);
1424 ok(r
==S_OK
, "IStorage->CreateStream failed\n");
1428 /* create a storage inside the new storage */
1429 r
= IStorage_CreateStorage(stg2
, stgname
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stg3
);
1430 ok(r
==S_OK
, "IStorage->CreateStorage failed\n");
1433 /* free the parent */
1434 ref
= IStorage_Release(stg2
);
1435 ok(ref
== 0, "IStorage still has %u references\n", ref
);
1437 /* child objects are invalid */
1440 r
= IStream_Write(stm
, "this should fail\n", 17, NULL
);
1441 ok(r
==STG_E_REVERTED
, "IStream->Write sould fail, hr=%x\n", r
);
1443 IStream_Release(stm
);
1445 r
= IStorage_Stat(stg3
, &statstg
, STATFLAG_NONAME
);
1446 ok(r
==STG_E_REVERTED
, "IStorage_Stat should fail %08x\n", r
);
1448 r
= IStorage_SetStateBits(stg3
, 1, 1);
1449 ok(r
==STG_E_REVERTED
, "IStorage_Stat should fail %08x\n", r
);
1451 IStorage_Release(stg3
);
1455 IStorage_Release(stg
);
1457 r
= DeleteFileA(filenameA
);
1458 ok( r
== TRUE
, "deleted file\n");
1461 static void test_nonroot_transacted(void)
1463 IStorage
*stg
= NULL
, *stg2
= NULL
, *stg3
= NULL
;
1465 IStream
*stm
= NULL
;
1466 static const WCHAR stgname
[] = { 'P','E','R','M','S','T','G',0 };
1467 static const WCHAR stmname
[] = { 'C','O','N','T','E','N','T','S',0 };
1468 static const WCHAR stmname2
[] = { 'F','O','O',0 };
1470 DeleteFileA(filenameA
);
1472 /* create a transacted file */
1473 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
|
1474 STGM_READWRITE
|STGM_TRANSACTED
, 0, &stg
);
1475 ok(r
==S_OK
, "StgCreateDocfile failed\n");
1477 /* create a transacted substorage */
1478 r
= IStorage_CreateStorage(stg
, stgname
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
| STGM_TRANSACTED
, 0, 0, &stg2
);
1479 ok(r
==S_OK
, "IStorage->CreateStorage failed, hr=%08x\n", r
);
1483 /* create and commit stmname */
1484 r
= IStorage_CreateStream(stg2
, stmname
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stm
);
1485 ok(r
==S_OK
, "IStorage->CreateStream failed\n");
1487 IStream_Release(stm
);
1489 IStorage_Commit(stg2
, 0);
1491 /* create and revert stmname2 */
1492 r
= IStorage_CreateStream(stg2
, stmname2
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stm
);
1493 ok(r
==S_OK
, "IStorage->CreateStream failed\n");
1495 IStream_Release(stm
);
1497 IStorage_Revert(stg2
);
1499 /* check that Commit and Revert really worked */
1500 r
= IStorage_OpenStream(stg2
, stmname
, NULL
, STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, 0, &stm
);
1501 ok(r
==S_OK
, "IStorage->OpenStream should succeed %08x\n", r
);
1503 IStream_Release(stm
);
1505 r
= IStorage_OpenStream(stg2
, stmname2
, NULL
, STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, 0, &stm
);
1506 ok(r
==STG_E_FILENOTFOUND
, "IStorage->OpenStream should fail %08x\n", r
);
1508 IStream_Release(stm
);
1510 IStorage_Release(stg2
);
1513 /* create a read-only transacted substorage */
1514 r
= IStorage_OpenStorage(stg
, stgname
, NULL
, STGM_READ
| STGM_SHARE_EXCLUSIVE
| STGM_TRANSACTED
, NULL
, 0, &stg2
);
1515 ok(r
==S_OK
, "IStorage->OpenStorage failed, hr=%08x\n", r
);
1519 /* The storage can be modified. */
1520 r
= IStorage_CreateStorage(stg2
, stgname
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stg3
);
1521 ok(r
==S_OK
, "IStorage->CreateStorage failed, hr=%08x\n", r
);
1523 IStream_Release(stg3
);
1525 /* But changes cannot be committed. */
1526 r
= IStorage_Commit(stg2
, 0);
1527 ok(r
==STG_E_ACCESSDENIED
, "IStorage->Commit should fail, hr=%08x\n", r
);
1529 IStorage_Release(stg2
);
1532 IStorage_Release(stg
);
1534 /* create a non-transacted file */
1535 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
|
1536 STGM_READWRITE
, 0, &stg
);
1537 ok(r
==S_OK
, "StgCreateDocfile failed\n");
1539 /* create a transacted substorage */
1540 r
= IStorage_CreateStorage(stg
, stgname
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
| STGM_TRANSACTED
, 0, 0, &stg2
);
1541 ok(r
==S_OK
, "IStorage->CreateStorage failed, hr=%08x\n", r
);
1545 /* create and commit stmname */
1546 r
= IStorage_CreateStream(stg2
, stmname
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stm
);
1547 ok(r
==S_OK
, "IStorage->CreateStream failed\n");
1549 IStream_Release(stm
);
1551 IStorage_Commit(stg2
, 0);
1553 /* create and revert stmname2 */
1554 r
= IStorage_CreateStream(stg2
, stmname2
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stm
);
1555 ok(r
==S_OK
, "IStorage->CreateStream failed\n");
1557 IStream_Release(stm
);
1559 IStorage_Revert(stg2
);
1561 /* check that Commit and Revert really worked */
1562 r
= IStorage_OpenStream(stg2
, stmname
, NULL
, STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, 0, &stm
);
1563 ok(r
==S_OK
, "IStorage->OpenStream should succeed %08x\n", r
);
1565 IStream_Release(stm
);
1567 r
= IStorage_OpenStream(stg2
, stmname2
, NULL
, STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, 0, &stm
);
1568 ok(r
==STG_E_FILENOTFOUND
, "IStorage->OpenStream should fail %08x\n", r
);
1570 IStream_Release(stm
);
1572 IStorage_Release(stg2
);
1575 IStream_Release(stg
);
1577 r
= DeleteFileA(filenameA
);
1578 ok( r
== TRUE
, "deleted file\n");
1581 static void test_ReadClassStm(void)
1586 static const LARGE_INTEGER llZero
;
1588 hr
= ReadClassStm(NULL
, &clsid
);
1589 ok(hr
== E_INVALIDARG
, "ReadClassStm should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
1591 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &pStream
);
1592 ok_ole_success(hr
, "CreateStreamOnHGlobal");
1593 hr
= WriteClassStm(pStream
, &test_stg_cls
);
1594 ok_ole_success(hr
, "WriteClassStm");
1596 hr
= ReadClassStm(pStream
, NULL
);
1597 ok(hr
== E_INVALIDARG
, "ReadClassStm should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
1599 /* test not rewound stream */
1600 hr
= ReadClassStm(pStream
, &clsid
);
1601 ok(hr
== STG_E_READFAULT
, "ReadClassStm should have returned STG_E_READFAULT instead of 0x%08x\n", hr
);
1602 ok(IsEqualCLSID(&clsid
, &CLSID_NULL
), "clsid should have been zeroed\n");
1604 hr
= IStream_Seek(pStream
, llZero
, STREAM_SEEK_SET
, NULL
);
1605 ok_ole_success(hr
, "IStream_Seek");
1606 hr
= ReadClassStm(pStream
, &clsid
);
1607 ok_ole_success(hr
, "ReadClassStm");
1608 ok(IsEqualCLSID(&clsid
, &test_stg_cls
), "clsid should have been set to CLSID_WineTest\n");
1610 IStream_Release(pStream
);
1620 static const struct access_res create
[16] =
1622 { TRUE
, ERROR_SUCCESS
, TRUE
},
1623 { TRUE
, ERROR_SUCCESS
, TRUE
},
1624 { TRUE
, ERROR_SUCCESS
, FALSE
},
1625 { TRUE
, ERROR_SUCCESS
, FALSE
},
1626 { FALSE
, ERROR_SHARING_VIOLATION
, FALSE
},
1627 { FALSE
, ERROR_SHARING_VIOLATION
, FALSE
},
1628 { FALSE
, ERROR_SHARING_VIOLATION
, FALSE
},
1629 { TRUE
, ERROR_SUCCESS
, FALSE
},
1630 { FALSE
, ERROR_SHARING_VIOLATION
, FALSE
},
1631 { FALSE
, ERROR_SHARING_VIOLATION
, FALSE
},
1632 { FALSE
, ERROR_SHARING_VIOLATION
, FALSE
},
1633 { TRUE
, ERROR_SUCCESS
, TRUE
},
1634 { FALSE
, ERROR_SHARING_VIOLATION
, FALSE
},
1635 { FALSE
, ERROR_SHARING_VIOLATION
, FALSE
},
1636 { FALSE
, ERROR_SHARING_VIOLATION
, FALSE
},
1637 { TRUE
, ERROR_SUCCESS
, TRUE
}
1640 static const struct access_res create_commit
[16] =
1642 { TRUE
, ERROR_SUCCESS
, TRUE
},
1643 { TRUE
, ERROR_SUCCESS
, TRUE
},
1644 { TRUE
, ERROR_SUCCESS
, FALSE
},
1645 { TRUE
, ERROR_SUCCESS
, FALSE
},
1646 { FALSE
, ERROR_SHARING_VIOLATION
, FALSE
},
1647 { FALSE
, ERROR_SHARING_VIOLATION
, FALSE
},
1648 { FALSE
, ERROR_SHARING_VIOLATION
, FALSE
},
1649 { TRUE
, ERROR_SUCCESS
, FALSE
},
1650 { FALSE
, ERROR_SHARING_VIOLATION
, FALSE
},
1651 { FALSE
, ERROR_SHARING_VIOLATION
, FALSE
},
1652 { FALSE
, ERROR_SHARING_VIOLATION
, FALSE
},
1653 { TRUE
, ERROR_SUCCESS
, TRUE
},
1654 { FALSE
, ERROR_SHARING_VIOLATION
, FALSE
},
1655 { FALSE
, ERROR_SHARING_VIOLATION
, FALSE
},
1656 { FALSE
, ERROR_SHARING_VIOLATION
, FALSE
},
1657 { TRUE
, ERROR_SUCCESS
, TRUE
}
1660 static const struct access_res create_close
[16] =
1662 { TRUE
, ERROR_SUCCESS
, FALSE
},
1663 { TRUE
, ERROR_SUCCESS
, FALSE
},
1664 { TRUE
, ERROR_SUCCESS
, FALSE
},
1665 { TRUE
, ERROR_SUCCESS
, FALSE
},
1666 { TRUE
, ERROR_SUCCESS
, FALSE
},
1667 { TRUE
, ERROR_SUCCESS
, FALSE
},
1668 { TRUE
, ERROR_SUCCESS
, FALSE
},
1669 { TRUE
, ERROR_SUCCESS
, FALSE
},
1670 { TRUE
, ERROR_SUCCESS
, FALSE
},
1671 { TRUE
, ERROR_SUCCESS
, FALSE
},
1672 { TRUE
, ERROR_SUCCESS
, FALSE
},
1673 { TRUE
, ERROR_SUCCESS
, FALSE
},
1674 { TRUE
, ERROR_SUCCESS
, FALSE
},
1675 { TRUE
, ERROR_SUCCESS
, FALSE
},
1676 { TRUE
, ERROR_SUCCESS
, FALSE
},
1677 { TRUE
, ERROR_SUCCESS
}
1680 static void _test_file_access(LPCSTR file
, const struct access_res
*ares
, DWORD line
)
1682 DWORD access
= 0, share
= 0;
1687 for (i
= 0; i
< 4; i
++)
1689 if (i
== 0) access
= 0;
1690 if (i
== 1) access
= GENERIC_READ
;
1691 if (i
== 2) access
= GENERIC_WRITE
;
1692 if (i
== 3) access
= GENERIC_READ
| GENERIC_WRITE
;
1694 for (j
= 0; j
< 4; j
++)
1696 if (ares
[idx
].ignore
)
1699 if (j
== 0) share
= 0;
1700 if (j
== 1) share
= FILE_SHARE_READ
;
1701 if (j
== 2) share
= FILE_SHARE_WRITE
;
1702 if (j
== 3) share
= FILE_SHARE_READ
| FILE_SHARE_WRITE
;
1704 SetLastError(0xdeadbeef);
1705 hfile
= CreateFileA(file
, access
, share
, NULL
, OPEN_EXISTING
,
1706 FILE_ATTRIBUTE_NORMAL
, 0);
1707 lasterr
= GetLastError();
1709 ok((hfile
!= INVALID_HANDLE_VALUE
) == ares
[idx
].gothandle
,
1710 "(%d, handle, %d): Expected %d, got %d\n",
1711 line
, idx
, ares
[idx
].gothandle
,
1712 (hfile
!= INVALID_HANDLE_VALUE
));
1714 ok(lasterr
== ares
[idx
].lasterr
||
1715 broken(lasterr
== 0xdeadbeef) /* win9x */,
1716 "(%d, lasterr, %d): Expected %d, got %d\n",
1717 line
, idx
, ares
[idx
].lasterr
, lasterr
);
1725 #define test_file_access(file, ares) _test_file_access(file, ares, __LINE__)
1727 static void test_access(void)
1732 static const WCHAR fileW
[] = {'w','i','n','e','t','e','s','t',0};
1734 /* STGM_TRANSACTED */
1736 hr
= StgCreateDocfile(fileW
, STGM_CREATE
| STGM_READWRITE
|
1737 STGM_SHARE_EXCLUSIVE
| STGM_TRANSACTED
, 0, &stg
);
1738 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
1740 test_file_access("winetest", create
);
1742 hr
= IStorage_Commit(stg
, STGC_DEFAULT
);
1743 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
1745 test_file_access("winetest", create_commit
);
1747 IStorage_Release(stg
);
1749 test_file_access("winetest", create_close
);
1751 DeleteFileA("winetest");
1755 hr
= StgCreateDocfile(fileW
, STGM_CREATE
| STGM_READWRITE
|
1756 STGM_SHARE_EXCLUSIVE
| STGM_DIRECT
, 0, &stg
);
1757 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
1759 test_file_access("winetest", create
);
1761 hr
= IStorage_Commit(stg
, STGC_DEFAULT
);
1762 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
1764 test_file_access("winetest", create_commit
);
1766 IStorage_Release(stg
);
1768 test_file_access("winetest", create_close
);
1770 DeleteFileA("winetest");
1772 /* STGM_SHARE_DENY_NONE */
1774 hr
= StgCreateDocfile(fileW
, STGM_CREATE
| STGM_READWRITE
|
1775 STGM_SHARE_DENY_NONE
| STGM_TRANSACTED
, 0, &stg
);
1776 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
1778 test_file_access("winetest", create
);
1780 hr
= IStorage_Commit(stg
, STGC_DEFAULT
);
1781 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
1783 test_file_access("winetest", create_commit
);
1785 IStorage_Release(stg
);
1787 test_file_access("winetest", create_close
);
1789 DeleteFileA("winetest");
1791 /* STGM_SHARE_DENY_READ */
1793 hr
= StgCreateDocfile(fileW
, STGM_CREATE
| STGM_READWRITE
|
1794 STGM_SHARE_DENY_READ
| STGM_TRANSACTED
, 0, &stg
);
1795 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
1797 test_file_access("winetest", create
);
1799 hr
= IStorage_Commit(stg
, STGC_DEFAULT
);
1800 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
1802 test_file_access("winetest", create_commit
);
1804 IStorage_Release(stg
);
1806 test_file_access("winetest", create_close
);
1808 DeleteFileA("winetest");
1810 /* STGM_SHARE_DENY_WRITE */
1812 hr
= StgCreateDocfile(fileW
, STGM_CREATE
| STGM_READWRITE
|
1813 STGM_SHARE_DENY_WRITE
| STGM_TRANSACTED
, 0, &stg
);
1814 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
1816 test_file_access("winetest", create
);
1818 hr
= IStorage_Commit(stg
, STGC_DEFAULT
);
1819 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
1821 test_file_access("winetest", create_commit
);
1823 IStorage_Release(stg
);
1825 test_file_access("winetest", create_close
);
1827 DeleteFileA("winetest");
1830 static void test_readonly(void)
1832 IStorage
*stg
, *stg2
, *stg3
;
1835 static const WCHAR fileW
[] = {'w','i','n','e','t','e','s','t',0};
1836 static const WCHAR storageW
[] = {'s','t','o','r','a','g','e',0};
1837 static const WCHAR streamW
[] = {'s','t','r','e','a','m',0};
1839 hr
= StgCreateDocfile( fileW
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, &stg
);
1840 ok(hr
== S_OK
, "should succeed, res=%x\n", hr
);
1843 hr
= IStorage_CreateStorage( stg
, storageW
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stg2
);
1844 ok(hr
== S_OK
, "should succeed, res=%x\n", hr
);
1847 hr
= IStorage_CreateStream( stg2
, streamW
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stream
);
1848 ok(hr
== S_OK
, "should succeed, res=%x\n", hr
);
1850 IStream_Release(stream
);
1851 IStorage_Release(stg2
);
1853 IStorage_Release(stg
);
1856 /* re-open read only */
1857 hr
= StgOpenStorage( fileW
, NULL
, STGM_TRANSACTED
| STGM_SHARE_DENY_NONE
| STGM_READ
, NULL
, 0, &stg
);
1858 ok(hr
== S_OK
, "should succeed, res=%x\n", hr
);
1861 hr
= IStorage_OpenStorage( stg
, storageW
, NULL
, STGM_SHARE_EXCLUSIVE
| STGM_READ
, NULL
, 0, &stg2
);
1862 ok(hr
== S_OK
, "should succeed, res=%x\n", hr
);
1865 /* CreateStream on read-only storage, name exists */
1866 hr
= IStorage_CreateStream( stg2
, streamW
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READ
, 0, 0, &stream
);
1867 ok(hr
== STG_E_ACCESSDENIED
, "should fail, res=%x\n", hr
);
1869 IStream_Release(stream
);
1871 /* CreateStream on read-only storage, name does not exist */
1872 hr
= IStorage_CreateStream( stg2
, storageW
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READ
, 0, 0, &stream
);
1873 ok(hr
== STG_E_ACCESSDENIED
, "should fail, res=%x\n", hr
);
1875 IStream_Release(stream
);
1877 /* CreateStorage on read-only storage, name exists */
1878 hr
= IStorage_CreateStorage( stg2
, streamW
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READ
, 0, 0, &stg3
);
1879 ok(hr
== STG_E_FILEALREADYEXISTS
, "should fail, res=%x\n", hr
);
1881 IStream_Release(stg3
);
1883 /* CreateStorage on read-only storage, name does not exist */
1884 hr
= IStorage_CreateStorage( stg2
, storageW
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READ
, 0, 0, &stg3
);
1885 ok(hr
== STG_E_ACCESSDENIED
, "should fail, res=%x\n", hr
);
1887 IStream_Release(stg3
);
1889 /* DestroyElement on read-only storage, name exists */
1890 hr
= IStorage_DestroyElement( stg2
, streamW
);
1891 ok(hr
== STG_E_ACCESSDENIED
, "should fail, res=%x\n", hr
);
1893 /* DestroyElement on read-only storage, name does not exist */
1894 hr
= IStorage_DestroyElement( stg2
, storageW
);
1895 ok(hr
== STG_E_ACCESSDENIED
, "should fail, res=%x\n", hr
);
1897 IStorage_Release(stg2
);
1900 IStorage_Release(stg
);
1903 DeleteFileA("winetest");
1906 static void test_simple(void)
1908 /* Tests for STGM_SIMPLE mode */
1910 IStorage
*stg
, *stg2
;
1913 static const WCHAR stgname
[] = { 'S','t','g',0 };
1914 static const WCHAR stmname
[] = { 'C','O','N','T','E','N','T','S',0 };
1915 static const WCHAR stmname2
[] = { 'S','m','a','l','l',0 };
1917 ULARGE_INTEGER upos
;
1921 DeleteFileA(filenameA
);
1923 r
= StgCreateDocfile( filename
, STGM_SIMPLE
| STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, &stg
);
1924 ok(r
== S_OK
, "got %08x\n", r
);
1926 r
= IStorage_CreateStorage(stg
, stgname
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stg2
);
1927 ok(r
== STG_E_INVALIDFUNCTION
, "got %08x\n", r
);
1928 if (SUCCEEDED(r
)) IStorage_Release(stg2
);
1930 r
= IStorage_CreateStream(stg
, stmname
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stm
);
1931 ok(r
== STG_E_INVALIDFLAG
, "got %08x\n", r
);
1932 r
= IStorage_CreateStream(stg
, stmname
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stm
);
1933 ok(r
== S_OK
, "got %08x\n", r
);
1935 upos
.QuadPart
= 6000;
1936 r
= IStream_SetSize(stm
, upos
);
1937 ok(r
== S_OK
, "got %08x\n", r
);
1939 r
= IStream_Write(stm
, "foo", 3, &count
);
1940 ok(r
== S_OK
, "got %08x\n", r
);
1941 ok(count
== 3, "got %d\n", count
);
1944 r
= IStream_Seek(stm
, pos
, STREAM_SEEK_CUR
, &upos
);
1945 ok(r
== S_OK
, "got %08x\n", r
);
1946 ok(upos
.QuadPart
== 3, "got %d\n", upos
.u
.LowPart
);
1948 r
= IStream_Stat(stm
, &stat
, STATFLAG_NONAME
);
1950 broken(r
== STG_E_INVALIDFUNCTION
), /* NT4 and below */
1953 ok(stat
.cbSize
.QuadPart
== 3, "got %d\n", stat
.cbSize
.u
.LowPart
);
1956 r
= IStream_Seek(stm
, pos
, STREAM_SEEK_SET
, &upos
);
1957 ok(r
== S_OK
, "got %08x\n", r
);
1958 ok(upos
.QuadPart
== 1, "got %d\n", upos
.u
.LowPart
);
1960 r
= IStream_Stat(stm
, &stat
, STATFLAG_NONAME
);
1962 broken(r
== STG_E_INVALIDFUNCTION
), /* NT4 and below */
1965 ok(stat
.cbSize
.QuadPart
== 1, "got %d\n", stat
.cbSize
.u
.LowPart
);
1967 IStream_Release(stm
);
1969 r
= IStorage_CreateStream(stg
, stmname2
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, 0, &stm
);
1970 ok(r
== S_OK
, "got %08x\n", r
);
1972 upos
.QuadPart
= 100;
1973 r
= IStream_SetSize(stm
, upos
);
1974 ok(r
== S_OK
, "got %08x\n", r
);
1976 r
= IStream_Write(stm
, "foo", 3, &count
);
1977 ok(r
== S_OK
, "got %08x\n", r
);
1978 ok(count
== 3, "got %d\n", count
);
1980 IStream_Release(stm
);
1982 IStorage_Commit(stg
, STGC_DEFAULT
);
1983 IStorage_Release(stg
);
1985 r
= StgOpenStorage( filename
, NULL
, STGM_SIMPLE
| STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, NULL
, 0, &stg
);
1986 if (r
== STG_E_INVALIDFLAG
)
1988 win_skip("Flag combination is not supported on NT4 and below\n");
1989 DeleteFileA(filenameA
);
1992 ok(r
== S_OK
, "got %08x\n", r
);
1994 r
= IStorage_OpenStorage(stg
, stgname
, NULL
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, NULL
, 0, &stg2
);
1995 ok(r
== STG_E_INVALIDFUNCTION
, "got %08x\n", r
);
1996 if (SUCCEEDED(r
)) IStorage_Release(stg2
);
1998 r
= IStorage_OpenStream(stg
, stmname
, NULL
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, &stm
);
1999 ok(r
== S_OK
, "got %08x\n", r
);
2001 r
= IStream_Stat(stm
, &stat
, STATFLAG_NONAME
);
2002 ok(r
== S_OK
, "got %08x\n", r
);
2003 ok(stat
.cbSize
.QuadPart
== 6000, "got %d\n", stat
.cbSize
.u
.LowPart
);
2005 IStream_Release(stm
);
2007 r
= IStorage_OpenStream(stg
, stmname2
, NULL
, STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, &stm
);
2008 ok(r
== S_OK
, "got %08x\n", r
);
2010 r
= IStream_Stat(stm
, &stat
, STATFLAG_NONAME
);
2011 ok(r
== S_OK
, "got %08x\n", r
);
2012 ok(stat
.cbSize
.QuadPart
== 4096, "got %d\n", stat
.cbSize
.u
.LowPart
);
2014 IStream_Release(stm
);
2017 IStorage_Release(stg
);
2019 DeleteFileA(filenameA
);
2022 static void test_fmtusertypestg(void)
2027 static const char fileA
[] = {'f','m','t','t','e','s','t',0};
2028 static const WCHAR fileW
[] = {'f','m','t','t','e','s','t',0};
2029 static WCHAR userTypeW
[] = {'S','t','g','U','s','r','T','y','p','e',0};
2030 static WCHAR strmNameW
[] = {1,'C','o','m','p','O','b','j',0};
2032 hr
= StgCreateDocfile( fileW
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, &stg
);
2033 ok(hr
== S_OK
, "should succeed, res=%x\n", hr
);
2037 /* try to write the stream */
2038 hr
= WriteFmtUserTypeStg(stg
, 0, userTypeW
);
2039 ok(hr
== S_OK
, "should succeed, res=%x\n", hr
);
2041 /* check that the stream was created */
2042 hr
= IStorage_EnumElements(stg
, 0, NULL
, 0, &stat
);
2043 ok(hr
== S_OK
, "should succeed, res=%x\n", hr
);
2049 while ((hr
= IEnumSTATSTG_Next(stat
, 1, &statstg
, &got
)) == S_OK
&& got
== 1)
2051 if (strcmp_ww(statstg
.pwcsName
, strmNameW
) == 0)
2054 ok(0, "found unexpected stream or storage\n");
2055 CoTaskMemFree(statstg
.pwcsName
);
2057 ok(found
== TRUE
, "expected storage to contain stream \\0001CompObj\n");
2058 IEnumSTATSTG_Release(stat
);
2061 /* re-write the stream */
2062 hr
= WriteFmtUserTypeStg(stg
, 0, userTypeW
);
2063 ok(hr
== S_OK
, "should succeed, res=%x\n", hr
);
2065 /* check that the stream is still there */
2066 hr
= IStorage_EnumElements(stg
, 0, NULL
, 0, &stat
);
2067 ok(hr
== S_OK
, "should succeed, res=%x\n", hr
);
2073 while ((hr
= IEnumSTATSTG_Next(stat
, 1, &statstg
, &got
)) == S_OK
&& got
== 1)
2075 if (strcmp_ww(statstg
.pwcsName
, strmNameW
) == 0)
2078 ok(0, "found unexpected stream or storage\n");
2079 CoTaskMemFree(statstg
.pwcsName
);
2081 ok(found
== TRUE
, "expected storage to contain stream \\0001CompObj\n");
2082 IEnumSTATSTG_Release(stat
);
2085 IStorage_Release(stg
);
2086 DeleteFileA( fileA
);
2090 static void test_references(void)
2092 IStorage
*stg
,*stg2
;
2095 static const WCHAR StorName
[] = { 'D','a','t','a','S','p','a','c','e','I','n','f','o',0 };
2097 DeleteFileA(filenameA
);
2099 hr
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
|STGM_TRANSACTED
, 0, &stg
);
2100 ok(hr
==S_OK
, "StgCreateDocfile failed\n");
2104 IStorage_Release(stg
);
2106 hr
= StgOpenStorage( filename
, NULL
, STGM_TRANSACTED
| STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, NULL
, 0, &stg
);
2107 ok(hr
==S_OK
, "StgOpenStorage failed (result=%x)\n",hr
);
2111 hr
= IStorage_CreateStorage(stg
,StorName
,STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
,0,0,&stg2
);
2112 ok(hr
== S_OK
, "IStorage_CreateStorage failed (result=%x)\n",hr
);
2116 c1
= IStorage_AddRef(stg
);
2117 ok(c1
== 2, "creating internal storage added references to ancestor\n");
2118 c1
= IStorage_AddRef(stg
);
2119 IStorage_Release(stg2
);
2120 c2
= IStorage_AddRef(stg
) - 1;
2121 ok(c1
== c2
, "releasing internal storage removed references to ancestor\n");
2123 c1
= IStorage_Release(stg
);
2124 while ( c1
) c1
= IStorage_Release(stg
);
2128 DeleteFileA(filenameA
);
2133 * | `StreamA: "StreamA"
2135 * | `StreamB: "StreamB"
2136 * `StreamC: "StreamC"
2138 static HRESULT
create_test_file(IStorage
*dest
)
2140 IStorage
*stgA
= NULL
, *stgB
= NULL
;
2141 IStream
*strmA
= NULL
, *strmB
= NULL
, *strmC
= NULL
;
2142 const ULONG strmA_name_size
= lstrlenW(strmA_name
) * sizeof(WCHAR
);
2143 const ULONG strmB_name_size
= lstrlenW(strmB_name
) * sizeof(WCHAR
);
2144 const ULONG strmC_name_size
= lstrlenW(strmC_name
) * sizeof(WCHAR
);
2148 hr
= IStorage_CreateStorage(dest
, stgA_name
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stgA
);
2149 ok(hr
== S_OK
, "IStorage_CreateStorage failed: 0x%08x\n", hr
);
2153 hr
= IStorage_CreateStream(stgA
, strmA_name
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &strmA
);
2154 ok(hr
== S_OK
, "IStorage_CreateStream failed: 0x%08x\n", hr
);
2158 hr
= IStream_Write(strmA
, strmA_name
, strmA_name_size
, &bytes
);
2159 ok(hr
== S_OK
&& bytes
== strmA_name_size
, "IStream_Write failed: 0x%08x, %d of %d bytes written\n", hr
, bytes
, strmA_name_size
);
2161 hr
= IStorage_CreateStorage(dest
, stgB_name
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stgB
);
2162 ok(hr
== S_OK
, "IStorage_CreateStorage failed: 0x%08x\n", hr
);
2166 hr
= IStorage_CreateStream(stgB
, strmB_name
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &strmB
);
2167 ok(hr
== S_OK
, "IStorage_CreateStream failed: 0x%08x\n", hr
);
2171 hr
= IStream_Write(strmB
, strmB_name
, strmB_name_size
, &bytes
);
2172 ok(hr
== S_OK
&& bytes
== strmB_name_size
, "IStream_Write failed: 0x%08x, %d of %d bytes written\n", hr
, bytes
, strmB_name_size
);
2174 hr
= IStorage_CreateStream(dest
, strmC_name
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &strmC
);
2175 ok(hr
== S_OK
, "IStorage_CreateStream failed: 0x%08x\n", hr
);
2179 hr
= IStream_Write(strmC
, strmC_name
, strmC_name_size
, &bytes
);
2180 ok(hr
== S_OK
&& bytes
== strmC_name_size
, "IStream_Write failed: 0x%08x, %d of %d bytes written\n", hr
, bytes
, strmC_name_size
);
2184 IStream_Release(strmC
);
2186 IStream_Release(strmB
);
2188 IStorage_Release(stgB
);
2190 IStream_Release(strmA
);
2192 IStorage_Release(stgA
);
2197 static void test_copyto(void)
2199 IStorage
*file1
= NULL
, *file2
= NULL
, *stg_tmp
;
2204 /* create & populate file1 */
2205 hr
= StgCreateDocfile(file1_name
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, &file1
);
2206 ok(hr
== S_OK
, "StgCreateDocfile failed: 0x%08x\n", hr
);
2210 hr
= create_test_file(file1
);
2215 hr
= StgCreateDocfile(file2_name
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, &file2
);
2216 ok(hr
== S_OK
, "StgCreateDocfile failed: 0x%08x\n", hr
);
2220 /* copy file1 into file2 */
2221 hr
= IStorage_CopyTo(file1
, 0, NULL
, NULL
, NULL
);
2222 ok(hr
== STG_E_INVALIDPOINTER
, "CopyTo should give STG_E_INVALIDPONITER, gave: 0x%08x\n", hr
);
2224 hr
= IStorage_CopyTo(file1
, 0, NULL
, NULL
, file2
);
2225 ok(hr
== S_OK
, "CopyTo failed: 0x%08x\n", hr
);
2229 /* verify that all of file1 was copied */
2230 hr
= IStorage_OpenStorage(file2
, stgA_name
, NULL
,
2231 STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, NULL
, 0, &stg_tmp
);
2232 ok(hr
== S_OK
, "OpenStorage failed: 0x%08x\n", hr
);
2235 hr
= IStorage_OpenStream(stg_tmp
, strmA_name
, NULL
,
2236 STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, &strm_tmp
);
2237 ok(hr
== S_OK
, "OpenStream failed: 0x%08x\n", hr
);
2240 memset(buf
, 0, sizeof(buf
));
2241 hr
= IStream_Read(strm_tmp
, buf
, sizeof(buf
), NULL
);
2242 ok(hr
== S_OK
, "Read failed: 0x%08x\n", hr
);
2244 ok(strcmp_ww(buf
, strmA_name
) == 0,
2245 "Expected %s to be read, got %s\n", wine_dbgstr_w(strmA_name
), wine_dbgstr_w(buf
));
2247 IStream_Release(strm_tmp
);
2250 IStorage_Release(stg_tmp
);
2253 hr
= IStorage_OpenStorage(file2
, stgB_name
, NULL
,
2254 STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, NULL
, 0, &stg_tmp
);
2255 ok(hr
== S_OK
, "OpenStorage failed: 0x%08x\n", hr
);
2258 hr
= IStorage_OpenStream(stg_tmp
, strmB_name
, NULL
,
2259 STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, &strm_tmp
);
2260 ok(hr
== S_OK
, "OpenStream failed: 0x%08x\n", hr
);
2263 memset(buf
, 0, sizeof(buf
));
2264 hr
= IStream_Read(strm_tmp
, buf
, sizeof(buf
), NULL
);
2265 ok(hr
== S_OK
, "Read failed: 0x%08x\n", hr
);
2267 ok(strcmp_ww(buf
, strmB_name
) == 0,
2268 "Expected %s to be read, got %s\n", wine_dbgstr_w(strmB_name
), wine_dbgstr_w(buf
));
2270 IStream_Release(strm_tmp
);
2273 IStorage_Release(stg_tmp
);
2276 hr
= IStorage_OpenStream(file2
, strmC_name
, NULL
,
2277 STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, &strm_tmp
);
2278 ok(hr
== S_OK
, "OpenStream failed: 0x%08x\n", hr
);
2281 memset(buf
, 0, sizeof(buf
));
2282 hr
= IStream_Read(strm_tmp
, buf
, sizeof(buf
), NULL
);
2283 ok(hr
== S_OK
, "Read failed: 0x%08x\n", hr
);
2285 ok(strcmp_ww(buf
, strmC_name
) == 0,
2286 "Expected %s to be read, got %s\n", wine_dbgstr_w(strmC_name
), wine_dbgstr_w(buf
));
2288 IStream_Release(strm_tmp
);
2293 IStorage_Release(file1
);
2295 IStorage_Release(file2
);
2297 DeleteFileA(file1_nameA
);
2298 DeleteFileA(file2_nameA
);
2301 static void test_copyto_snbexclusions(void)
2303 static const WCHAR
*snb_exclude
[] = {stgA_name
, strmB_name
, strmC_name
, 0};
2305 IStorage
*file1
= NULL
, *file2
= NULL
, *stg_tmp
;
2310 /* create & populate file1 */
2311 hr
= StgCreateDocfile(file1_name
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, &file1
);
2312 ok(hr
== S_OK
, "StgCreateDocfile failed: 0x%08x\n", hr
);
2316 hr
= create_test_file(file1
);
2321 hr
= StgCreateDocfile(file2_name
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, &file2
);
2322 ok(hr
== S_OK
, "StgCreateDocfile failed: 0x%08x\n", hr
);
2326 /* copy file1 to file2 with name exclusions */
2327 hr
= IStorage_CopyTo(file1
, 0, NULL
, (SNB
)snb_exclude
, file2
);
2328 ok(hr
== S_OK
, "CopyTo failed: 0x%08x\n", hr
);
2332 /* verify that file1 copied over, respecting exclusions */
2333 hr
= IStorage_OpenStorage(file2
, stgA_name
, NULL
,
2334 STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, NULL
, 0, &stg_tmp
);
2335 ok(hr
== STG_E_FILENOTFOUND
, "OpenStorage should give STG_E_FILENOTFOUND, gave: 0x%08x\n", hr
);
2337 IStorage_Release(stg_tmp
);
2339 hr
= IStorage_OpenStream(file2
, strmA_name
, NULL
,
2340 STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, &strm_tmp
);
2341 ok(hr
== STG_E_FILENOTFOUND
, "OpenStream should give STG_E_FILENOTFOUND, gave: 0x%08x\n", hr
);
2343 IStream_Release(strm_tmp
);
2345 hr
= IStorage_OpenStorage(file2
, stgB_name
, NULL
,
2346 STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, NULL
, 0, &stg_tmp
);
2347 ok(hr
== S_OK
, "OpenStorage failed: 0x%08x\n", hr
);
2350 hr
= IStorage_OpenStream(stg_tmp
, strmB_name
, NULL
,
2351 STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, &strm_tmp
);
2352 ok(hr
== S_OK
, "OpenStream failed: 0x%08x\n", hr
);
2355 memset(buf
, 0, sizeof(buf
));
2356 hr
= IStream_Read(strm_tmp
, buf
, sizeof(buf
), NULL
);
2357 ok(hr
== S_OK
, "Read failed: 0x%08x\n", hr
);
2359 ok(strcmp_ww(buf
, strmB_name
) == 0,
2360 "Expected %s to be read, got %s\n", wine_dbgstr_w(strmB_name
), wine_dbgstr_w(buf
));
2362 IStream_Release(strm_tmp
);
2365 IStorage_Release(stg_tmp
);
2368 hr
= IStorage_OpenStream(file2
, strmC_name
, NULL
,
2369 STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, &strm_tmp
);
2370 ok(hr
== STG_E_FILENOTFOUND
, "OpenStream should give STG_E_FILENOTFOUND, gave: 0x%08x\n", hr
);
2372 IStream_Release(strm_tmp
);
2376 IStorage_Release(file1
);
2378 IStorage_Release(file2
);
2380 DeleteFileA(file1_nameA
);
2381 DeleteFileA(file2_nameA
);
2384 static void test_copyto_iidexclusions_storage(void)
2386 IStorage
*file1
= NULL
, *file2
= NULL
, *stg_tmp
;
2391 /* create & populate file1 */
2392 hr
= StgCreateDocfile(file1_name
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, &file1
);
2393 ok(hr
== S_OK
, "StgCreateDocfile failed: 0x%08x\n", hr
);
2397 hr
= create_test_file(file1
);
2402 hr
= StgCreateDocfile(file2_name
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, &file2
);
2403 ok(hr
== S_OK
, "StgCreateDocfile failed: 0x%08x\n", hr
);
2407 /* copy file1 to file2 with iid exclusions */
2408 hr
= IStorage_CopyTo(file1
, 1, &IID_IStorage
, NULL
, file2
);
2409 ok(hr
== S_OK
, "CopyTo failed: 0x%08x\n", hr
);
2413 /* verify that file1 copied over, respecting exclusions */
2414 hr
= IStorage_OpenStorage(file2
, stgA_name
, NULL
,
2415 STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, NULL
, 0, &stg_tmp
);
2416 ok(hr
== STG_E_FILENOTFOUND
, "OpenStorage should give STG_E_FILENOTFOUND, gave: 0x%08x\n", hr
);
2418 IStorage_Release(stg_tmp
);
2420 hr
= IStorage_OpenStream(file2
, strmA_name
, NULL
,
2421 STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, &strm_tmp
);
2422 ok(hr
== STG_E_FILENOTFOUND
, "OpenStream should give STG_E_FILENOTFOUND, gave: 0x%08x\n", hr
);
2424 IStream_Release(strm_tmp
);
2426 hr
= IStorage_OpenStorage(file2
, stgB_name
, NULL
,
2427 STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, NULL
, 0, &stg_tmp
);
2428 ok(hr
== STG_E_FILENOTFOUND
, "OpenStorage should give STG_E_FILENOTFOUND, gave: 0x%08x\n", hr
);
2430 IStorage_Release(stg_tmp
);
2432 hr
= IStorage_OpenStream(file2
, strmB_name
, NULL
,
2433 STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, &strm_tmp
);
2434 ok(hr
== STG_E_FILENOTFOUND
, "OpenStream should give STG_E_FILENOTFOUND, gave: 0x%08x\n", hr
);
2436 IStream_Release(strm_tmp
);
2438 hr
= IStorage_OpenStream(file2
, strmC_name
, NULL
,
2439 STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, &strm_tmp
);
2440 ok(hr
== S_OK
, "OpenStream failed: 0x%08x\n", hr
);
2443 memset(buf
, 0, sizeof(buf
));
2444 hr
= IStream_Read(strm_tmp
, buf
, sizeof(buf
), NULL
);
2445 ok(hr
== S_OK
, "Read failed: 0x%08x\n", hr
);
2447 ok(strcmp_ww(buf
, strmC_name
) == 0,
2448 "Expected %s to be read, got %s\n", wine_dbgstr_w(strmC_name
), wine_dbgstr_w(buf
));
2450 IStream_Release(strm_tmp
);
2455 IStorage_Release(file1
);
2457 IStorage_Release(file2
);
2459 DeleteFileA(file1_nameA
);
2460 DeleteFileA(file2_nameA
);
2463 static void test_copyto_iidexclusions_stream(void)
2465 IStorage
*file1
= NULL
, *file2
= NULL
, *stg_tmp
;
2469 /* create & populate file1 */
2470 hr
= StgCreateDocfile(file1_name
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, &file1
);
2471 ok(hr
== S_OK
, "StgCreateDocfile failed: 0x%08x\n", hr
);
2475 hr
= create_test_file(file1
);
2480 hr
= StgCreateDocfile(file2_name
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
, 0, &file2
);
2481 ok(hr
== S_OK
, "StgCreateDocfile failed: 0x%08x\n", hr
);
2485 /* copy file1 to file2 with iid exclusions */
2486 hr
= IStorage_CopyTo(file1
, 1, &IID_IStream
, NULL
, file2
);
2487 ok(hr
== S_OK
, "CopyTo failed: 0x%08x\n", hr
);
2491 /* verify that file1 copied over, respecting exclusions */
2492 hr
= IStorage_OpenStorage(file2
, stgA_name
, NULL
,
2493 STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, NULL
, 0, &stg_tmp
);
2494 ok(hr
== S_OK
, "OpenStorage failed: 0x%08x\n", hr
);
2497 hr
= IStorage_OpenStream(stg_tmp
, strmA_name
, NULL
,
2498 STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, &strm_tmp
);
2499 ok(hr
== STG_E_FILENOTFOUND
, "OpenStream should give STG_E_FILENOTFOUND, gave: 0x%08x\n", hr
);
2501 IStream_Release(strm_tmp
);
2503 IStorage_Release(stg_tmp
);
2506 hr
= IStorage_OpenStorage(file2
, stgB_name
, NULL
,
2507 STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, NULL
, 0, &stg_tmp
);
2508 ok(hr
== S_OK
, "OpenStorage failed: 0x%08x\n", hr
);
2511 hr
= IStorage_OpenStream(stg_tmp
, strmB_name
, NULL
,
2512 STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, &strm_tmp
);
2513 ok(hr
== STG_E_FILENOTFOUND
, "OpenStream should give STG_E_FILENOTFOUND, gave: 0x%08x\n", hr
);
2515 IStream_Release(strm_tmp
);
2517 IStorage_Release(stg_tmp
);
2520 hr
= IStorage_OpenStream(file2
, strmC_name
, NULL
,
2521 STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, &strm_tmp
);
2522 ok(hr
== STG_E_FILENOTFOUND
, "OpenStream should give STG_E_FILENOTFOUND, gave: 0x%08x\n", hr
);
2524 IStream_Release(strm_tmp
);
2528 IStorage_Release(file1
);
2530 IStorage_Release(file2
);
2532 DeleteFileA(file1_nameA
);
2533 DeleteFileA(file2_nameA
);
2536 static void test_rename(void)
2538 IStorage
*stg
, *stg2
;
2541 static const WCHAR stgname
[] = { 'P','E','R','M','S','T','G',0 };
2542 static const WCHAR stgname2
[] = { 'S','T','G',0 };
2543 static const WCHAR stmname
[] = { 'C','O','N','T','E','N','T','S',0 };
2544 static const WCHAR stmname2
[] = { 'E','N','T','S',0 };
2546 DeleteFileA(filenameA
);
2548 /* create the file */
2549 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
|
2550 STGM_READWRITE
, 0, &stg
);
2551 ok(r
==S_OK
, "StgCreateDocfile failed\n");
2553 /* create a substorage */
2554 r
= IStorage_CreateStorage(stg
, stgname
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stg2
);
2555 ok(r
==S_OK
, "IStorage->CreateStorage failed, hr=%08x\n", r
);
2557 /* create a stream in the substorage */
2558 r
= IStorage_CreateStream(stg2
, stmname
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stm
);
2559 ok(r
==S_OK
, "IStorage->CreateStream failed, hr=%08x\n", r
);
2560 IStream_Release(stm
);
2562 /* rename the stream */
2563 r
= IStorage_RenameElement(stg2
, stmname
, stmname2
);
2564 ok(r
==S_OK
, "IStorage->RenameElement failed, hr=%08x\n", r
);
2566 /* cannot open stream with old name */
2567 r
= IStorage_OpenStream(stg2
, stmname
, NULL
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, &stm
);
2568 ok(r
==STG_E_FILENOTFOUND
, "IStorage_OpenStream should fail, hr=%08x\n", r
);
2569 if (SUCCEEDED(r
)) IStream_Release(stm
);
2571 /* can open stream with new name */
2572 r
= IStorage_OpenStream(stg2
, stmname2
, NULL
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, &stm
);
2573 ok(r
==S_OK
, "IStorage_OpenStream failed, hr=%08x\n", r
);
2574 if (SUCCEEDED(r
)) IStream_Release(stm
);
2576 IStorage_Release(stg2
);
2578 /* rename the storage */
2579 IStorage_RenameElement(stg
, stgname
, stgname2
);
2581 /* cannot open storage with old name */
2582 r
= IStorage_OpenStorage(stg
, stgname
, NULL
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, NULL
, 0, &stg2
);
2583 ok(r
==STG_E_FILENOTFOUND
, "IStorage_OpenStream should fail, hr=%08x\n", r
);
2584 if (SUCCEEDED(r
)) IStorage_Release(stg2
);
2586 /* can open storage with new name */
2587 r
= IStorage_OpenStorage(stg
, stgname2
, NULL
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, NULL
, 0, &stg2
);
2588 ok(r
==S_OK
, "IStorage_OpenStream should fail, hr=%08x\n", r
);
2591 /* opened storage still has the stream */
2592 r
= IStorage_OpenStream(stg2
, stmname2
, NULL
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, &stm
);
2593 ok(r
==S_OK
, "IStorage_OpenStream failed, hr=%08x\n", r
);
2594 if (SUCCEEDED(r
)) IStream_Release(stm
);
2596 IStorage_Release(stg2
);
2599 IStorage_Release(stg
);
2601 r
= DeleteFileA(filenameA
);
2602 ok( r
== TRUE
, "deleted file\n");
2605 static void test_toplevel_stat(void)
2607 IStorage
*stg
= NULL
;
2610 char prev_dir
[MAX_PATH
];
2611 char temp
[MAX_PATH
];
2612 char full_path
[MAX_PATH
];
2614 WCHAR rel_path
[MAX_PATH
];
2616 DeleteFileA(filenameA
);
2618 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
|
2619 STGM_READWRITE
|STGM_TRANSACTED
, 0, &stg
);
2620 ok(r
==S_OK
, "StgCreateDocfile failed\n");
2622 r
= IStorage_Stat( stg
, &stat
, STATFLAG_DEFAULT
);
2623 ok(!strcmp_ww(stat
.pwcsName
, filename
), "expected %s, got %s\n",
2624 wine_dbgstr_w(filename
), wine_dbgstr_w(stat
.pwcsName
));
2625 CoTaskMemFree(stat
.pwcsName
);
2627 IStorage_Release( stg
);
2629 r
= StgOpenStorage( filename
, NULL
, STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, NULL
, 0, &stg
);
2630 ok(r
==S_OK
, "StgOpenStorage failed with error 0x%08x\n", r
);
2632 r
= IStorage_Stat( stg
, &stat
, STATFLAG_DEFAULT
);
2633 ok(!strcmp_ww(stat
.pwcsName
, filename
), "expected %s, got %s\n",
2634 wine_dbgstr_w(filename
), wine_dbgstr_w(stat
.pwcsName
));
2635 CoTaskMemFree(stat
.pwcsName
);
2637 IStorage_Release( stg
);
2639 DeleteFileA(filenameA
);
2641 /* Stat always returns the full path, even for files opened with a relative path. */
2642 GetCurrentDirectoryA(MAX_PATH
, prev_dir
);
2644 GetTempPathA(MAX_PATH
, temp
);
2646 SetCurrentDirectoryA(temp
);
2648 GetFullPathNameA(filenameA
, MAX_PATH
, full_path
, &rel_pathA
);
2649 MultiByteToWideChar(CP_ACP
, 0, rel_pathA
, -1, rel_path
, MAX_PATH
);
2651 r
= StgCreateDocfile( rel_path
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
|
2652 STGM_READWRITE
|STGM_TRANSACTED
, 0, &stg
);
2653 ok(r
==S_OK
, "StgCreateDocfile failed\n");
2655 r
= IStorage_Stat( stg
, &stat
, STATFLAG_DEFAULT
);
2656 ok(!strcmp_ww(stat
.pwcsName
, filename
), "expected %s, got %s\n",
2657 wine_dbgstr_w(filename
), wine_dbgstr_w(stat
.pwcsName
));
2658 CoTaskMemFree(stat
.pwcsName
);
2660 IStorage_Release( stg
);
2662 r
= StgOpenStorage( rel_path
, NULL
, STGM_SHARE_EXCLUSIVE
|STGM_READWRITE
, NULL
, 0, &stg
);
2663 ok(r
==S_OK
, "StgOpenStorage failed with error 0x%08x\n", r
);
2665 r
= IStorage_Stat( stg
, &stat
, STATFLAG_DEFAULT
);
2666 ok(!strcmp_ww(stat
.pwcsName
, filename
), "expected %s, got %s\n",
2667 wine_dbgstr_w(filename
), wine_dbgstr_w(stat
.pwcsName
));
2668 CoTaskMemFree(stat
.pwcsName
);
2670 IStorage_Release( stg
);
2672 SetCurrentDirectoryA(prev_dir
);
2674 DeleteFileA(filenameA
);
2677 static void test_substorage_enum(void)
2679 IStorage
*stg
, *stg2
;
2683 static const WCHAR stgname
[] = { 'P','E','R','M','S','T','G',0 };
2685 DeleteFileA(filenameA
);
2687 /* create the file */
2688 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
|
2689 STGM_READWRITE
, 0, &stg
);
2690 ok(r
==S_OK
, "StgCreateDocfile failed\n");
2692 /* create a substorage */
2693 r
= IStorage_CreateStorage(stg
, stgname
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stg2
);
2694 ok(r
==S_OK
, "IStorage->CreateStorage failed, hr=%08x\n", r
);
2696 /* create an enumelements */
2697 r
= IStorage_EnumElements(stg2
, 0, NULL
, 0, &ee
);
2698 ok(r
==S_OK
, "IStorage->EnumElements failed, hr=%08x\n", r
);
2700 /* release the substorage */
2701 ref
= IStorage_Release(stg2
);
2702 todo_wine
ok(ref
==0, "storage not released\n");
2704 /* reopening fails, because the substorage is really still open */
2705 r
= IStorage_OpenStorage(stg
, stgname
, NULL
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stg2
);
2706 ok(r
==STG_E_ACCESSDENIED
, "IStorage->OpenStorage failed, hr=%08x\n", r
);
2708 /* destroying the storage invalidates the enumerator */
2709 r
= IStorage_DestroyElement(stg
, stgname
);
2710 ok(r
==S_OK
, "IStorage->CreateStorage failed, hr=%08x\n", r
);
2712 r
= IEnumSTATSTG_Reset(ee
);
2713 ok(r
==STG_E_REVERTED
, "IEnumSTATSTG->Reset failed, hr=%08x\n", r
);
2715 IEnumSTATSTG_Release(ee
);
2717 IStorage_Release(stg
);
2719 r
= DeleteFileA(filenameA
);
2720 ok( r
== TRUE
, "deleted file\n");
2723 static void test_copyto_locking(void)
2725 IStorage
*stg
, *stg2
, *stg3
, *stg4
;
2728 static const WCHAR stgname
[] = { 'S','T','G','1',0 };
2729 static const WCHAR stgname2
[] = { 'S','T','G','2',0 };
2730 static const WCHAR stmname
[] = { 'C','O','N','T','E','N','T','S',0 };
2732 DeleteFileA(filenameA
);
2734 /* create the file */
2735 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
|
2736 STGM_READWRITE
, 0, &stg
);
2737 ok(r
==S_OK
, "StgCreateDocfile failed\n");
2739 /* create a substorage */
2740 r
= IStorage_CreateStorage(stg
, stgname
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stg2
);
2741 ok(r
==S_OK
, "IStorage->CreateStorage failed, hr=%08x\n", r
);
2743 /* create another substorage */
2744 r
= IStorage_CreateStorage(stg
, stgname2
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stg3
);
2745 ok(r
==S_OK
, "IStorage->CreateStorage failed, hr=%08x\n", r
);
2747 /* add a stream, and leave it open */
2748 r
= IStorage_CreateStream(stg2
, stmname
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stm
);
2749 ok(r
==S_OK
, "IStorage->CreateStream failed, hr=%08x\n", r
);
2751 /* Try to copy the storage while the stream is open */
2752 r
= IStorage_CopyTo(stg2
, 0, NULL
, NULL
, stg3
);
2753 ok(r
==S_OK
, "IStorage->CopyTo failed, hr=%08x\n", r
);
2755 IStream_Release(stm
);
2757 /* create a substorage */
2758 r
= IStorage_CreateStorage(stg2
, stgname
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stg4
);
2759 ok(r
==S_OK
, "IStorage->CreateStorage failed, hr=%08x\n", r
);
2761 /* Try to copy the storage while the substorage is open */
2762 r
= IStorage_CopyTo(stg2
, 0, NULL
, NULL
, stg3
);
2763 todo_wine
ok(r
==S_OK
, "IStorage->CopyTo failed, hr=%08x\n", r
);
2765 IStorage_Release(stg4
);
2766 IStorage_Release(stg3
);
2767 IStorage_Release(stg2
);
2768 IStorage_Release(stg
);
2770 r
= DeleteFileA(filenameA
);
2771 ok( r
== TRUE
, "deleted file\n");
2774 static void test_copyto_recursive(void)
2776 IStorage
*stg
, *stg2
, *stg3
, *stg4
;
2778 static const WCHAR stgname
[] = { 'S','T','G','1',0 };
2779 static const WCHAR stgname2
[] = { 'S','T','G','2',0 };
2781 DeleteFileA(filenameA
);
2783 /* create the file */
2784 r
= StgCreateDocfile( filename
, STGM_CREATE
| STGM_SHARE_EXCLUSIVE
|
2785 STGM_READWRITE
, 0, &stg
);
2786 ok(r
==S_OK
, "StgCreateDocfile failed\n");
2788 /* create a substorage */
2789 r
= IStorage_CreateStorage(stg
, stgname
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stg2
);
2790 ok(r
==S_OK
, "IStorage->CreateStorage failed, hr=%08x\n", r
);
2792 /* copy the parent to the child */
2793 r
= IStorage_CopyTo(stg
, 0, NULL
, NULL
, stg2
);
2794 ok(r
==STG_E_ACCESSDENIED
, "IStorage->CopyTo failed, hr=%08x\n", r
);
2796 /* create a transacted substorage */
2797 r
= IStorage_CreateStorage(stg
, stgname2
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
| STGM_TRANSACTED
, 0, 0, &stg3
);
2798 ok(r
==S_OK
, "IStorage->CreateStorage failed, hr=%08x\n", r
);
2800 /* copy the parent to the transacted child */
2801 r
= IStorage_CopyTo(stg
, 0, NULL
, NULL
, stg2
);
2802 ok(r
==STG_E_ACCESSDENIED
, "IStorage->CopyTo failed, hr=%08x\n", r
);
2804 /* create a transacted subsubstorage */
2805 r
= IStorage_CreateStorage(stg3
, stgname2
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
| STGM_TRANSACTED
, 0, 0, &stg4
);
2806 ok(r
==S_OK
, "IStorage->CreateStorage failed, hr=%08x\n", r
);
2808 /* copy the parent to the transacted child of the transacted child */
2809 r
= IStorage_CopyTo(stg
, 0, NULL
, NULL
, stg4
);
2810 ok(r
==STG_E_ACCESSDENIED
, "IStorage->CopyTo failed, hr=%08x\n", r
);
2812 /* copy the parent but exclude storage objects */
2813 r
= IStorage_CopyTo(stg
, 1, &IID_IStorage
, NULL
, stg4
);
2814 ok(r
==S_OK
, "IStorage->CopyTo failed, hr=%08x\n", r
);
2816 IStorage_Release(stg4
);
2817 IStorage_Release(stg3
);
2818 IStorage_Release(stg2
);
2819 IStorage_Release(stg
);
2821 r
= DeleteFileA(filenameA
);
2822 ok( r
== TRUE
, "deleted file\n");
2825 START_TEST(storage32
)
2827 CHAR temp
[MAX_PATH
];
2829 GetTempPathA(MAX_PATH
, temp
);
2830 if(!GetTempFileNameA(temp
, "stg", 0, filenameA
))
2832 win_skip("Could not create temp file, %u\n", GetLastError());
2835 MultiByteToWideChar(CP_ACP
, 0, filenameA
, -1, filename
, MAX_PATH
);
2836 DeleteFileA(filenameA
);
2838 test_hglobal_storage_stat();
2839 test_create_storage_modes();
2840 test_storage_stream();
2841 test_open_storage();
2842 test_storage_suminfo();
2843 test_storage_refcount();
2846 test_substorage_share();
2849 test_nonroot_transacted();
2850 test_ReadClassStm();
2852 test_writeclassstg();
2855 test_fmtusertypestg();
2858 test_copyto_snbexclusions();
2859 test_copyto_iidexclusions_storage();
2860 test_copyto_iidexclusions_stream();
2862 test_toplevel_stat();
2863 test_substorage_enum();
2864 test_copyto_locking();
2865 test_copyto_recursive();