Release 0.9.39.
[wine/gsoc-2012-control.git] / dlls / ole32 / tests / storage32.c
blobe6c3542453e3ec1be45d4f055d7952e5516c5644
1 /*
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
21 #include <stdio.h>
23 #define COBJMACROS
25 #include <windows.h>
26 #include "wine/test.h"
28 #include "ole2.h"
29 #include "objidl.h"
30 #include "initguid.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 void test_hglobal_storage_stat(void)
38 ILockBytes *ilb = NULL;
39 IStorage *stg = NULL;
40 HRESULT r;
41 STATSTG stat;
42 DWORD mode, refcount;
44 r = CreateILockBytesOnHGlobal( NULL, TRUE, &ilb );
45 ok( r == S_OK, "CreateILockBytesOnHGlobal failed\n");
47 mode = STGM_CREATE|STGM_SHARE_EXCLUSIVE|STGM_READWRITE;/*0x1012*/
48 r = StgCreateDocfileOnILockBytes( ilb, mode, 0, &stg );
49 ok( r == S_OK, "StgCreateDocfileOnILockBytes failed\n");
51 r = WriteClassStg( stg, &test_stg_cls );
52 ok( r == S_OK, "WriteClassStg failed\n");
54 memset( &stat, 0, sizeof stat );
55 r = IStorage_Stat( stg, &stat, 0 );
57 ok( stat.pwcsName == NULL, "storage name not null\n");
58 ok( stat.type == 1, "type is wrong\n");
59 ok( stat.grfMode == 0x12, "grf mode is incorrect\n");
60 ok( !memcmp(&stat.clsid, &test_stg_cls, sizeof test_stg_cls), "CLSID is wrong\n");
62 refcount = IStorage_Release( stg );
63 ok( refcount == 0, "IStorage refcount is wrong\n");
64 refcount = ILockBytes_Release( ilb );
65 ok( refcount == 0, "ILockBytes refcount is wrong\n");
68 static void test_create_storage_modes(void)
70 static const WCHAR szPrefix[] = { 's','t','g',0 };
71 static const WCHAR szDot[] = { '.',0 };
72 WCHAR filename[MAX_PATH];
73 IStorage *stg = NULL;
74 HRESULT r;
76 if(!GetTempFileNameW(szDot, szPrefix, 0, filename))
77 return;
79 DeleteFileW(filename);
81 /* test with some invalid parameters */
82 r = StgCreateDocfile( NULL, 0, 0, &stg);
83 ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
84 r = StgCreateDocfile( filename, 0, 0, &stg);
85 ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
86 r = StgCreateDocfile( filename, STGM_CREATE, 0, &stg);
87 ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
88 r = StgCreateDocfile( filename, STGM_CREATE | STGM_READWRITE, 0, &stg);
89 ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
90 r = StgCreateDocfile( filename, STGM_CREATE | STGM_SHARE_EXCLUSIVE, 0, &stg);
91 ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
92 r = StgCreateDocfile( filename, STGM_CREATE | STGM_SHARE_EXCLUSIVE | STGM_READWRITE, 0, NULL);
93 ok(r==STG_E_INVALIDPOINTER, "StgCreateDocfile succeeded\n");
94 r = StgCreateDocfile( filename, STGM_CREATE | STGM_SHARE_EXCLUSIVE | STGM_READWRITE, 1, &stg);
95 ok(r==STG_E_INVALIDPARAMETER, "StgCreateDocfile succeeded\n");
96 r = StgCreateDocfile( filename, STGM_CREATE | STGM_SHARE_DENY_WRITE | STGM_READWRITE, 0, &stg);
97 ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
98 r = StgCreateDocfile( filename, STGM_SHARE_EXCLUSIVE | STGM_READ, 0, &stg);
99 ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
100 r = StgCreateDocfile( filename, STGM_PRIORITY, 0, &stg);
101 ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
103 /* StgCreateDocfile seems to be very particular about the flags it accepts */
104 r = StgCreateDocfile( filename, STGM_SHARE_EXCLUSIVE | STGM_READWRITE |STGM_TRANSACTED | STGM_WRITE, 0, &stg);
105 ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
106 r = StgCreateDocfile( filename, STGM_SHARE_EXCLUSIVE | STGM_READWRITE |STGM_TRANSACTED | 8, 0, &stg);
107 ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
108 r = StgCreateDocfile( filename, STGM_SHARE_EXCLUSIVE | STGM_READWRITE |STGM_TRANSACTED | 0x80, 0, &stg);
109 ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
110 r = StgCreateDocfile( filename, STGM_SHARE_EXCLUSIVE | STGM_READWRITE |STGM_TRANSACTED | 0x800, 0, &stg);
111 ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
112 r = StgCreateDocfile( filename, STGM_SHARE_EXCLUSIVE | STGM_READWRITE |STGM_TRANSACTED | 0x8000, 0, &stg);
113 ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
114 r = StgCreateDocfile( filename, STGM_SHARE_EXCLUSIVE | STGM_READWRITE |STGM_TRANSACTED | 0x80000, 0, &stg);
115 ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
116 r = StgCreateDocfile( filename, STGM_SHARE_EXCLUSIVE | STGM_READWRITE |STGM_TRANSACTED | 0x800000, 0, &stg);
117 ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
118 ok(stg == NULL, "stg was set\n");
120 /* check what happens if the file already exists (which is how it's meant to be used) */
121 r = StgCreateDocfile( filename, STGM_SHARE_EXCLUSIVE | STGM_READWRITE, 0, &stg);
122 ok(r==S_OK, "StgCreateDocfile failed\n");
123 r = IStorage_Release(stg);
124 ok(r == 0, "storage not released\n");
125 r = StgCreateDocfile( filename, STGM_SHARE_EXCLUSIVE | STGM_READWRITE |STGM_TRANSACTED, 0, &stg);
126 ok(r==STG_E_FILEALREADYEXISTS, "StgCreateDocfile wrong error\n"); /* FAILIFTHERE is default */
127 r = StgCreateDocfile( filename, STGM_READ, 0, &stg);
128 ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n"); /* need at least readmode and sharemode */
129 r = StgCreateDocfile( filename, STGM_SHARE_EXCLUSIVE, 0, &stg);
130 ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
131 r = StgCreateDocfile( filename, STGM_SHARE_DENY_WRITE, 0, &stg);
132 ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
133 r = StgCreateDocfile( filename, STGM_SHARE_DENY_NONE, 0, &stg);
134 ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile failed\n");
135 r = StgCreateDocfile( filename, STGM_SHARE_DENY_NONE | STGM_TRANSACTED, 0, &stg);
136 ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile failed\n");
137 r = StgCreateDocfile( filename, STGM_SHARE_DENY_NONE | STGM_READWRITE, 0, &stg);
138 ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile failed\n");
139 r = StgCreateDocfile( filename, STGM_SHARE_DENY_NONE | STGM_WRITE, 0, &stg);
140 ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile failed\n");
141 r = StgCreateDocfile( filename, STGM_SHARE_DENY_WRITE | STGM_WRITE, 0, &stg);
142 ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile failed\n");
143 r = StgCreateDocfile( filename, STGM_SHARE_DENY_WRITE | STGM_READ, 0, &stg);
144 ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile wrong error\n");
145 r = StgCreateDocfile( filename, STGM_TRANSACTED | STGM_SHARE_DENY_WRITE | STGM_READ, 0, &stg);
146 ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile wrong error\n");
147 ok(DeleteFileW(filename), "failed to delete file\n");
149 r = StgCreateDocfile( filename, STGM_SHARE_EXCLUSIVE | STGM_READWRITE |STGM_TRANSACTED, 0, &stg);
150 ok(r==S_OK, "StgCreateDocfile failed\n");
151 r = IStorage_Release(stg);
152 ok(r == 0, "storage not released\n");
153 r = StgCreateDocfile( filename, STGM_SHARE_EXCLUSIVE | STGM_READWRITE |STGM_TRANSACTED |STGM_FAILIFTHERE, 0, &stg);
154 ok(r==STG_E_FILEALREADYEXISTS, "StgCreateDocfile wrong error\n");
155 r = StgCreateDocfile( filename, STGM_SHARE_EXCLUSIVE | STGM_WRITE, 0, &stg);
156 ok(r==STG_E_FILEALREADYEXISTS, "StgCreateDocfile wrong error\n");
158 r = StgCreateDocfile( filename, STGM_CREATE | STGM_SHARE_DENY_WRITE | STGM_READWRITE, 0, &stg);
159 ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
160 r = StgCreateDocfile( filename, STGM_CREATE | STGM_SHARE_EXCLUSIVE | STGM_READWRITE |STGM_TRANSACTED, 0, &stg);
161 ok(r==S_OK, "StgCreateDocfile failed\n");
162 r = IStorage_Release(stg);
163 ok(r == 0, "storage not released\n");
164 ok(DeleteFileW(filename), "failed to delete file\n");
166 r = StgCreateDocfile( filename, STGM_CREATE | STGM_READWRITE |STGM_TRANSACTED, 0, &stg);
167 ok(r==S_OK, "StgCreateDocfile failed\n");
168 r = IStorage_Release(stg);
169 ok(r == 0, "storage not released\n");
170 ok(DeleteFileW(filename), "failed to delete file\n");
172 /* test the way excel uses StgCreateDocFile */
173 r = StgCreateDocfile( filename, STGM_TRANSACTED|STGM_CREATE|STGM_SHARE_DENY_WRITE|STGM_READWRITE, 0, &stg);
174 ok(r==S_OK, "StgCreateDocfile the excel way failed\n");
175 if(r == S_OK)
177 r = IStorage_Release(stg);
178 ok(r == 0, "storage not released\n");
179 ok(DeleteFileW(filename), "failed to delete file\n");
182 /* and the way windows media uses it ... */
183 r = StgCreateDocfile( filename, STGM_CREATE | STGM_SHARE_DENY_NONE | STGM_READWRITE | STGM_TRANSACTED, 0, &stg);
184 ok(r==S_OK, "StgCreateDocfile the windows media way failed\n");
185 if (r == S_OK)
187 r = IStorage_Release(stg);
188 ok(r == 0, "storage not released\n");
189 ok(DeleteFileW(filename), "failed to delete file\n");
192 /* looks like we need STGM_TRANSACTED or STGM_CREATE */
193 r = StgCreateDocfile( filename, STGM_TRANSACTED|STGM_SHARE_DENY_WRITE|STGM_READWRITE, 0, &stg);
194 ok(r==S_OK, "StgCreateDocfile the excel way failed\n");
195 if(r == S_OK)
197 r = IStorage_Release(stg);
198 ok(r == 0, "storage not released\n");
199 ok(DeleteFileW(filename), "failed to delete file\n");
202 r = StgCreateDocfile( filename, STGM_TRANSACTED|STGM_CREATE|STGM_SHARE_DENY_WRITE|STGM_WRITE, 0, &stg);
203 ok(r==S_OK, "StgCreateDocfile the excel way failed\n");
204 if(r == S_OK)
206 r = IStorage_Release(stg);
207 ok(r == 0, "storage not released\n");
208 ok(DeleteFileW(filename), "failed to delete file\n");
211 r = StgCreateDocfile( filename, STGM_CREATE | STGM_SHARE_EXCLUSIVE | STGM_READWRITE, 0, &stg);
212 ok(r==S_OK, "StgCreateDocfile the powerpoint way failed\n");
213 if(r == S_OK)
215 r = IStorage_Release(stg);
216 ok(r == 0, "storage not released\n");
217 ok(DeleteFileW(filename), "failed to delete file\n");
220 /* test the way msi uses StgCreateDocfile */
221 r = StgCreateDocfile( filename, STGM_DIRECT | STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, &stg);
222 ok(r==S_OK, "StgCreateDocFile failed\n");
223 r = IStorage_Release(stg);
224 ok(r == 0, "storage not released\n");
225 ok(DeleteFileW(filename), "failed to delete file\n");
228 static void test_storage_stream(void)
230 static const WCHAR stmname[] = { 'C','O','N','T','E','N','T','S',0 };
231 static const WCHAR szPrefix[] = { 's','t','g',0 };
232 static const WCHAR szDot[] = { '.',0 };
233 static const WCHAR longname[] = {
234 'a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a',
235 'a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a',0
237 WCHAR filename[MAX_PATH];
238 IStorage *stg = NULL;
239 HRESULT r;
240 IStream *stm = NULL;
241 IStream *stm2 = NULL;
242 ULONG count = 0;
243 LARGE_INTEGER pos;
244 ULARGE_INTEGER p;
245 unsigned char buffer[0x100];
247 if(!GetTempFileNameW(szDot, szPrefix, 0, filename))
248 return;
250 DeleteFileW(filename);
252 r = StgCreateDocfile( filename, STGM_CREATE | STGM_SHARE_EXCLUSIVE | STGM_READWRITE |STGM_TRANSACTED, 0, &stg);
253 ok(r==S_OK, "StgCreateDocfile failed\n");
255 /* try create some invalid streams */
256 r = IStorage_CreateStream(stg, stmname, STGM_SHARE_EXCLUSIVE | STGM_READWRITE, 1, 0, &stm );
257 ok(r==STG_E_INVALIDPARAMETER, "IStorage->CreateStream wrong error\n");
258 r = IStorage_CreateStream(stg, stmname, STGM_SHARE_EXCLUSIVE | STGM_READWRITE, 0, 1, &stm );
259 ok(r==STG_E_INVALIDPARAMETER, "IStorage->CreateStream wrong error\n");
260 r = IStorage_CreateStream(stg, stmname, STGM_SHARE_EXCLUSIVE | STGM_READWRITE, 0, 0, NULL );
261 ok(r==STG_E_INVALIDPOINTER, "IStorage->CreateStream wrong error\n");
262 r = IStorage_CreateStream(stg, NULL, STGM_SHARE_EXCLUSIVE | STGM_READWRITE, 0, 0, &stm );
263 ok(r==STG_E_INVALIDNAME, "IStorage->CreateStream wrong error\n");
264 r = IStorage_CreateStream(stg, longname, STGM_SHARE_EXCLUSIVE | STGM_READWRITE, 0, 0, &stm );
265 ok(r==STG_E_INVALIDNAME, "IStorage->CreateStream wrong error, got %d GetLastError()=%d\n", r, GetLastError());
266 r = IStorage_CreateStream(stg, stmname, STGM_READWRITE, 0, 0, &stm );
267 ok(r==STG_E_INVALIDFLAG, "IStorage->CreateStream wrong error\n");
268 r = IStorage_CreateStream(stg, stmname, STGM_READ, 0, 0, &stm );
269 ok(r==STG_E_INVALIDFLAG, "IStorage->CreateStream wrong error\n");
270 r = IStorage_CreateStream(stg, stmname, STGM_WRITE, 0, 0, &stm );
271 ok(r==STG_E_INVALIDFLAG, "IStorage->CreateStream wrong error\n");
272 r = IStorage_CreateStream(stg, stmname, STGM_SHARE_DENY_NONE | STGM_READWRITE, 0, 0, &stm );
273 ok(r==STG_E_INVALIDFLAG, "IStorage->CreateStream wrong error\n");
274 r = IStorage_CreateStream(stg, stmname, STGM_SHARE_DENY_NONE | STGM_READ, 0, 0, &stm );
275 ok(r==STG_E_INVALIDFLAG, "IStorage->CreateStream wrong error\n");
277 /* now really create a stream and delete it */
278 r = IStorage_CreateStream(stg, stmname, STGM_SHARE_EXCLUSIVE | STGM_READWRITE, 0, 0, &stm );
279 ok(r==S_OK, "IStorage->CreateStream failed\n");
280 r = IStream_Release(stm);
281 ok(r == 0, "wrong ref count\n");
282 r = IStorage_CreateStream(stg, stmname, STGM_SHARE_EXCLUSIVE | STGM_READWRITE, 0, 0, &stm );
283 ok(r==STG_E_FILEALREADYEXISTS, "IStorage->CreateStream failed\n");
284 r = IStorage_DestroyElement(stg,stmname);
285 ok(r==S_OK, "IStorage->DestroyElement failed\n");
287 /* create a stream and write to it */
288 r = IStorage_CreateStream(stg, stmname, STGM_SHARE_EXCLUSIVE | STGM_READWRITE, 0, 0, &stm );
289 ok(r==S_OK, "IStorage->CreateStream failed\n");
291 r = IStream_Clone(stm, &stm2);
292 ok(r==S_OK, "failed to clone stream\n");
294 r = IStream_Write(stm, NULL, 0, NULL );
295 ok(r==STG_E_INVALIDPOINTER, "IStream->Write wrong error\n");
296 r = IStream_Write(stm, "Hello\n", 0, NULL );
297 ok(r==S_OK, "failed to write stream\n");
298 r = IStream_Write(stm, "Hello\n", 0, &count );
299 ok(r==S_OK, "failed to write stream\n");
300 r = IStream_Write(stm, "Hello\n", 6, &count );
301 ok(r==S_OK, "failed to write stream\n");
302 r = IStream_Commit(stm, STGC_DEFAULT );
303 ok(r==S_OK, "failed to commit stream\n");
304 r = IStream_Commit(stm, STGC_DEFAULT );
305 ok(r==S_OK, "failed to commit stream\n");
307 /* seek round a bit, reset the stream size */
308 pos.QuadPart = 0;
309 r = IStream_Seek(stm, pos, 3, &p );
310 ok(r==STG_E_INVALIDFUNCTION, "IStream->Seek returned wrong error\n");
311 r = IStream_Seek(stm, pos, STREAM_SEEK_SET, NULL);
312 ok(r==S_OK, "failed to seek stream\n");
313 r = IStream_Seek(stm, pos, STREAM_SEEK_SET, &p );
314 ok(r==S_OK, "failed to seek stream\n");
315 r = IStream_SetSize(stm,p);
316 ok(r==S_OK, "failed to set pos\n");
317 p.u.HighPart = 1;
318 r = IStream_SetSize(stm,p);
319 ok(r==STG_E_INVALIDFUNCTION, "setting to invalid pos should fail with STG_E_INVALIDFUNCTION instead of error 0x%08x\n", r);
320 pos.QuadPart = 10;
321 r = IStream_Seek(stm, pos, STREAM_SEEK_SET, &p );
322 ok(r==S_OK, "failed to seek stream\n");
323 ok(p.QuadPart == 10, "at wrong place\n");
324 pos.QuadPart = 0;
325 r = IStream_Seek(stm, pos, STREAM_SEEK_END, &p );
326 ok(r==S_OK, "failed to seek stream\n");
327 ok(p.QuadPart == 0, "at wrong place\n");
328 r = IStream_Read(stm, buffer, sizeof buffer, &count );
329 ok(r==S_OK, "failed to set pos\n");
330 ok(count == 0, "read bytes from empty stream\n");
332 /* wrap up */
333 r = IStream_Release(stm2);
334 ok(r == 0, "wrong ref count\n");
335 r = IStream_Release(stm);
336 ok(r == 0, "wrong ref count\n");
337 r = IStorage_Release(stg);
338 ok(r == 0, "wrong ref count\n");
339 r = DeleteFileW(filename);
340 ok(r, "file should exist\n");
343 static BOOL touch_file(LPCWSTR filename)
345 HANDLE file;
347 file = CreateFileW(filename, GENERIC_READ|GENERIC_WRITE, 0, NULL,
348 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
349 if (file==INVALID_HANDLE_VALUE)
350 return FALSE;
351 CloseHandle(file);
352 return TRUE;
355 static BOOL is_zero_length(LPCWSTR filename)
357 HANDLE file;
358 DWORD len;
360 file = CreateFileW(filename, GENERIC_READ, 0, NULL,
361 OPEN_EXISTING, 0, NULL);
362 if (file==INVALID_HANDLE_VALUE)
363 return FALSE;
364 len = GetFileSize(file, NULL);
365 CloseHandle(file);
366 return len == 0;
369 static BOOL is_existing_file(LPCWSTR filename)
371 HANDLE file;
373 file = CreateFileW(filename, GENERIC_READ, 0, NULL,
374 OPEN_EXISTING, 0, NULL);
375 if (file==INVALID_HANDLE_VALUE)
376 return FALSE;
377 CloseHandle(file);
378 return TRUE;
381 static void test_open_storage(void)
383 static const WCHAR szPrefix[] = { 's','t','g',0 };
384 static const WCHAR szNonExist[] = { 'n','o','n','e','x','i','s','t',0 };
385 static const WCHAR szDot[] = { '.',0 };
386 WCHAR filename[MAX_PATH];
387 IStorage *stg = NULL, *stg2 = NULL;
388 HRESULT r;
389 DWORD stgm;
391 if(!GetTempFileNameW(szDot, szPrefix, 0, filename))
392 return;
394 /* try opening a zero length file - it should stay zero length */
395 DeleteFileW(filename);
396 touch_file(filename);
397 stgm = STGM_NOSCRATCH | STGM_TRANSACTED | STGM_SHARE_DENY_WRITE | STGM_READWRITE;
398 r = StgOpenStorage( filename, NULL, stgm, NULL, 0, &stg);
399 ok(r==STG_E_FILEALREADYEXISTS, "StgOpenStorage didn't fail\n");
401 stgm = STGM_SHARE_EXCLUSIVE | STGM_READWRITE;
402 r = StgOpenStorage( filename, NULL, stgm, NULL, 0, &stg);
403 ok(r==STG_E_FILEALREADYEXISTS, "StgOpenStorage didn't fail\n");
404 ok(is_zero_length(filename), "file length changed\n");
406 DeleteFileW(filename);
408 /* try opening a nonexistent file - it should not create it */
409 stgm = STGM_DIRECT | STGM_SHARE_EXCLUSIVE | STGM_READWRITE;
410 r = StgOpenStorage( filename, NULL, stgm, NULL, 0, &stg);
411 ok(r!=S_OK, "StgOpenStorage failed: 0x%08x\n", r);
412 if (r==S_OK) IStorage_Release(stg);
413 ok(!is_existing_file(filename), "StgOpenStorage should not create a file\n");
414 DeleteFileW(filename);
416 /* create the file */
417 r = StgCreateDocfile( filename, STGM_CREATE | STGM_SHARE_EXCLUSIVE | STGM_READWRITE |STGM_TRANSACTED, 0, &stg);
418 ok(r==S_OK, "StgCreateDocfile failed\n");
419 IStorage_Release(stg);
421 r = StgOpenStorage( filename, NULL, 0, NULL, 0, &stg);
422 ok(r==STG_E_INVALIDFLAG, "StgOpenStorage wrong error\n");
423 r = StgOpenStorage( NULL, NULL, STGM_SHARE_EXCLUSIVE, NULL, 0, &stg);
424 ok(r==STG_E_INVALIDNAME, "StgOpenStorage wrong error\n");
425 r = StgOpenStorage( filename, NULL, STGM_SHARE_EXCLUSIVE | STGM_READ, NULL, 0, NULL);
426 ok(r==STG_E_INVALIDPOINTER, "StgOpenStorage wrong error\n");
427 r = StgOpenStorage( filename, NULL, STGM_SHARE_EXCLUSIVE | STGM_READ, NULL, 1, &stg);
428 ok(r==STG_E_INVALIDPARAMETER, "StgOpenStorage wrong error\n");
429 r = StgOpenStorage( szNonExist, NULL, STGM_SHARE_EXCLUSIVE | STGM_READ, NULL, 0, &stg);
430 ok(r==STG_E_FILENOTFOUND, "StgOpenStorage failed\n");
431 r = StgOpenStorage( filename, NULL, STGM_CREATE | STGM_SHARE_EXCLUSIVE | STGM_READ, NULL, 0, &stg);
432 ok(r==STG_E_INVALIDFLAG, "StgOpenStorage failed\n");
433 r = StgOpenStorage( filename, NULL, STGM_SHARE_DENY_NONE | STGM_READ, NULL, 0, &stg);
434 ok(r==STG_E_INVALIDFLAG, "StgOpenStorage failed\n");
435 r = StgOpenStorage( filename, NULL, STGM_SHARE_DENY_READ | STGM_READ, NULL, 0, &stg);
436 ok(r==STG_E_INVALIDFLAG, "StgOpenStorage failed\n");
437 r = StgOpenStorage( filename, NULL, STGM_SHARE_DENY_WRITE | STGM_READWRITE, NULL, 0, &stg);
438 ok(r==STG_E_INVALIDFLAG, "StgOpenStorage failed\n");
440 /* open it for real */
441 r = StgOpenStorage( filename, NULL, STGM_SHARE_DENY_NONE | STGM_READ | STGM_TRANSACTED, NULL, 0, &stg); /* XLViewer 97/2000 */
442 ok(r==S_OK, "StgOpenStorage failed\n");
443 if(stg)
445 r = IStorage_Release(stg);
446 ok(r == 0, "wrong ref count\n");
449 r = StgOpenStorage( filename, NULL, STGM_SHARE_DENY_WRITE | STGM_READ, NULL, 0, &stg);
450 ok(r==S_OK, "StgOpenStorage failed\n");
451 if(stg)
453 r = IStorage_Release(stg);
454 ok(r == 0, "wrong ref count\n");
457 /* test the way word opens its custom dictionary */
458 r = StgOpenStorage( filename, NULL, STGM_NOSCRATCH | STGM_TRANSACTED |
459 STGM_SHARE_DENY_WRITE | STGM_READWRITE, NULL, 0, &stg);
460 ok(r==S_OK, "StgOpenStorage failed\n");
461 if(stg)
463 r = IStorage_Release(stg);
464 ok(r == 0, "wrong ref count\n");
467 r = StgOpenStorage( filename, NULL, STGM_SHARE_EXCLUSIVE | STGM_READ, NULL, 0, &stg);
468 ok(r==S_OK, "StgOpenStorage failed\n");
469 r = StgOpenStorage( filename, NULL, STGM_SHARE_EXCLUSIVE | STGM_READ, NULL, 0, &stg2);
470 ok(r==STG_E_SHAREVIOLATION, "StgOpenStorage failed\n");
471 if(stg)
473 r = IStorage_Release(stg);
474 ok(r == 0, "wrong ref count\n");
477 /* now try write to a storage file we opened read-only */
478 r = StgOpenStorage( filename, NULL, STGM_SHARE_EXCLUSIVE | STGM_READ, NULL, 0, &stg);
479 ok(r==S_OK, "StgOpenStorage failed\n");
480 if(stg)
482 static const WCHAR stmname[] = { 'w','i','n','e','t','e','s','t',0};
483 IStream *stm = NULL;
484 IStorage *stg2 = NULL;
486 r = IStorage_CreateStream( stg, stmname, STGM_WRITE | STGM_SHARE_EXCLUSIVE,
487 0, 0, &stm );
488 ok(r == STG_E_ACCESSDENIED, "CreateStream should fail\n");
489 r = IStorage_CreateStorage( stg, stmname, STGM_WRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &stg2);
490 ok(r == STG_E_ACCESSDENIED, "CreateStream should fail\n");
492 r = IStorage_Release(stg);
493 ok(r == 0, "wrong ref count\n");
496 /* open like visio 2003 */
497 stg = NULL;
498 r = StgOpenStorage( filename, NULL, STGM_PRIORITY | STGM_SHARE_DENY_NONE, NULL, 0, &stg);
499 ok(r == S_OK, "should succeed\n");
500 if (stg)
501 IStorage_Release(stg);
503 /* test other sharing modes with STGM_PRIORITY */
504 stg = NULL;
505 r = StgOpenStorage( filename, NULL, STGM_PRIORITY | STGM_SHARE_EXCLUSIVE, NULL, 0, &stg);
506 ok(r == S_OK, "should succeed\n");
507 if (stg)
508 IStorage_Release(stg);
510 stg = NULL;
511 r = StgOpenStorage( filename, NULL, STGM_PRIORITY | STGM_SHARE_DENY_WRITE, NULL, 0, &stg);
512 ok(r == S_OK, "should succeed\n");
513 if (stg)
514 IStorage_Release(stg);
516 stg = NULL;
517 r = StgOpenStorage( filename, NULL, STGM_PRIORITY | STGM_SHARE_DENY_READ, NULL, 0, &stg);
518 ok(r == S_OK, "should succeed\n");
519 if (stg)
520 IStorage_Release(stg);
522 /* open like Project 2003 */
523 stg = NULL;
524 r = StgOpenStorage( filename, NULL, STGM_PRIORITY, NULL, 0, &stg);
525 ok(r == S_OK, "should succeed\n");
526 r = StgOpenStorage( filename, NULL, STGM_PRIORITY, NULL, 0, &stg2);
527 ok(r == S_OK, "should succeed\n");
528 if (stg2)
529 IStorage_Release(stg2);
530 if (stg)
531 IStorage_Release(stg);
533 stg = NULL;
534 r = StgOpenStorage( filename, NULL, STGM_PRIORITY | STGM_READWRITE, NULL, 0, &stg);
535 ok(r == STG_E_INVALIDFLAG, "should fail\n");
537 r = StgOpenStorage( filename, NULL, STGM_TRANSACTED | STGM_PRIORITY, NULL, 0, &stg);
538 ok(r == STG_E_INVALIDFLAG, "should fail\n");
540 r = StgOpenStorage( filename, NULL, STGM_SIMPLE | STGM_PRIORITY, NULL, 0, &stg);
541 ok(r == STG_E_INVALIDFLAG, "should fail\n");
543 r = StgOpenStorage( filename, NULL, STGM_DELETEONRELEASE | STGM_PRIORITY, NULL, 0, &stg);
544 ok(r == STG_E_INVALIDFUNCTION, "should fail\n");
546 r = StgOpenStorage( filename, NULL, STGM_NOSCRATCH | STGM_PRIORITY, NULL, 0, &stg);
547 ok(r == STG_E_INVALIDFLAG, "should fail\n");
549 r = StgOpenStorage( filename, NULL, STGM_NOSNAPSHOT | STGM_PRIORITY, NULL, 0, &stg);
550 ok(r == STG_E_INVALIDFLAG, "should fail\n");
552 r = DeleteFileW(filename);
553 ok(r, "file didn't exist\n");
556 static void test_storage_suminfo(void)
558 static const WCHAR szDot[] = { '.',0 };
559 static const WCHAR szPrefix[] = { 's','t','g',0 };
560 WCHAR filename[MAX_PATH];
561 IStorage *stg = NULL;
562 IPropertySetStorage *propset = NULL;
563 IPropertyStorage *ps = NULL;
564 HRESULT r;
566 if(!GetTempFileNameW(szDot, szPrefix, 0, filename))
567 return;
569 DeleteFileW(filename);
571 /* create the file */
572 r = StgCreateDocfile( filename, STGM_CREATE | STGM_SHARE_EXCLUSIVE |
573 STGM_READWRITE |STGM_TRANSACTED, 0, &stg);
574 ok(r==S_OK, "StgCreateDocfile failed\n");
576 r = IStorage_QueryInterface( stg, &IID_IPropertySetStorage, (LPVOID) &propset );
577 ok(r == S_OK, "query interface failed\n");
579 /* delete it */
580 r = IPropertySetStorage_Delete( propset, &FMTID_SummaryInformation );
581 ok(r == STG_E_FILENOTFOUND, "deleted property set storage\n");
583 r = IPropertySetStorage_Open( propset, &FMTID_SummaryInformation,
584 STGM_READ | STGM_SHARE_EXCLUSIVE, &ps );
585 ok(r == STG_E_FILENOTFOUND, "opened property set storage\n");
587 r = IPropertySetStorage_Create( propset, &FMTID_SummaryInformation, NULL, 0,
588 STGM_READ | STGM_SHARE_EXCLUSIVE, &ps );
589 ok(r == STG_E_INVALIDFLAG, "created property set storage\n");
591 r = IPropertySetStorage_Create( propset, &FMTID_SummaryInformation, NULL, 0,
592 STGM_READ, &ps );
593 ok(r == STG_E_INVALIDFLAG, "created property set storage\n");
595 r = IPropertySetStorage_Create( propset, &FMTID_SummaryInformation, NULL, 0, 0, &ps );
596 ok(r == STG_E_INVALIDFLAG, "created property set storage\n");
598 r = IPropertySetStorage_Create( propset, &FMTID_SummaryInformation, NULL, 0,
599 STGM_WRITE|STGM_SHARE_EXCLUSIVE, &ps );
600 ok(r == STG_E_INVALIDFLAG, "created property set storage\n");
602 r = IPropertySetStorage_Create( propset, &FMTID_SummaryInformation, NULL, 0,
603 STGM_CREATE|STGM_WRITE|STGM_SHARE_EXCLUSIVE, &ps );
604 ok(r == STG_E_INVALIDFLAG, "created property set storage\n");
606 /* now try really creating a property set */
607 r = IPropertySetStorage_Create( propset, &FMTID_SummaryInformation, NULL, 0,
608 STGM_CREATE|STGM_READWRITE|STGM_SHARE_EXCLUSIVE, &ps );
609 ok(r == S_OK, "failed to create property set storage\n");
611 if( ps )
612 IPropertyStorage_Release(ps);
614 /* now try creating the same thing again */
615 r = IPropertySetStorage_Create( propset, &FMTID_SummaryInformation, NULL, 0,
616 STGM_CREATE|STGM_READWRITE|STGM_SHARE_EXCLUSIVE, &ps );
617 ok(r == S_OK, "failed to create property set storage\n");
618 if( ps )
619 IPropertyStorage_Release(ps);
621 /* should be able to open it */
622 r = IPropertySetStorage_Open( propset, &FMTID_SummaryInformation,
623 STGM_READWRITE|STGM_SHARE_EXCLUSIVE, &ps);
624 ok(r == S_OK, "open failed\n");
625 if(r == S_OK)
626 IPropertyStorage_Release(ps);
628 /* delete it */
629 r = IPropertySetStorage_Delete( propset, &FMTID_SummaryInformation );
630 ok(r == S_OK, "failed to delete property set storage\n");
632 /* try opening with an invalid FMTID */
633 r = IPropertySetStorage_Open( propset, NULL,
634 STGM_READWRITE|STGM_SHARE_EXCLUSIVE, &ps);
635 ok(r == E_INVALIDARG, "open succeeded\n");
636 if(r == S_OK)
637 IPropertyStorage_Release(ps);
639 /* try a bad guid */
640 r = IPropertySetStorage_Open( propset, &IID_IStorage,
641 STGM_READWRITE|STGM_SHARE_EXCLUSIVE, &ps);
642 ok(r == STG_E_FILENOTFOUND, "open succeeded\n");
643 if(r == S_OK)
644 IPropertyStorage_Release(ps);
647 /* try some invalid flags */
648 r = IPropertySetStorage_Open( propset, &FMTID_SummaryInformation,
649 STGM_CREATE | STGM_READWRITE|STGM_SHARE_EXCLUSIVE, &ps);
650 ok(r == STG_E_INVALIDFLAG, "open succeeded\n");
651 if(r == S_OK)
652 IPropertyStorage_Release(ps);
654 /* after deleting it, it should be gone */
655 r = IPropertySetStorage_Open( propset, &FMTID_SummaryInformation,
656 STGM_READWRITE|STGM_SHARE_EXCLUSIVE, &ps);
657 ok(r == STG_E_FILENOTFOUND, "open failed\n");
658 if(r == S_OK)
659 IPropertyStorage_Release(ps);
661 r = IPropertySetStorage_Release( propset );
662 ok(r == 1, "ref count wrong\n");
664 r = IStorage_Release(stg);
665 ok(r == 0, "ref count wrong\n");
667 DeleteFileW(filename);
670 static void test_storage_refcount(void)
672 static const WCHAR szPrefix[] = { 's','t','g',0 };
673 static const WCHAR szDot[] = { '.',0 };
674 WCHAR filename[MAX_PATH];
675 IStorage *stg = NULL;
676 IStorage *stgprio = NULL;
677 HRESULT r;
678 IStream *stm = NULL;
679 static const WCHAR stmname[] = { 'C','O','N','T','E','N','T','S',0 };
680 LARGE_INTEGER pos;
681 ULARGE_INTEGER upos;
682 STATSTG stat;
683 char buffer[10];
685 if(!GetTempFileNameW(szDot, szPrefix, 0, filename))
686 return;
688 DeleteFileW(filename);
690 /* create the file */
691 r = StgCreateDocfile( filename, STGM_CREATE | STGM_SHARE_EXCLUSIVE |
692 STGM_READWRITE |STGM_TRANSACTED, 0, &stg);
693 ok(r==S_OK, "StgCreateDocfile failed\n");
695 r = WriteClassStg( stg, &test_stg_cls );
696 ok( r == S_OK, "WriteClassStg failed\n");
698 r = IStorage_Commit( stg, STGC_DEFAULT );
699 ok( r == S_OK, "IStorage_Commit failed\n");
701 /* now create a stream */
702 r = IStorage_CreateStream(stg, stmname, STGM_SHARE_EXCLUSIVE | STGM_READWRITE, 0, 0, &stm );
703 ok(r==S_OK, "IStorage->CreateStream failed\n");
705 r = IStorage_Release( stg );
706 ok (r == 0, "storage not released\n");
708 pos.QuadPart = 0;
709 r = IStream_Seek( stm, pos, 0, &upos );
710 ok (r == STG_E_REVERTED, "seek should fail\n");
712 r = IStream_Stat( stm, &stat, STATFLAG_DEFAULT );
713 ok (r == STG_E_REVERTED, "stat should fail\n");
715 r = IStream_Write( stm, "Test string", strlen("Test string"), NULL);
716 ok (r == STG_E_REVERTED, "IStream_Write should return STG_E_REVERTED instead of 0x%08x\n", r);
718 r = IStream_Read( stm, buffer, sizeof(buffer), NULL);
719 ok (r == STG_E_REVERTED, "IStream_Read should return STG_E_REVERTED instead of 0x%08x\n", r);
721 r = IStream_Release(stm);
722 ok (r == 0, "stream not released\n");
724 /* tests that STGM_PRIORITY doesn't prevent readwrite access from other
725 * StgOpenStorage calls in transacted mode */
726 r = StgOpenStorage( filename, NULL, STGM_PRIORITY, NULL, 0, &stgprio);
727 ok(r==S_OK, "StgOpenStorage failed with error 0x%08x\n", r);
729 todo_wine {
730 /* non-transacted mode read/write fails */
731 r = StgOpenStorage( filename, NULL, STGM_SHARE_EXCLUSIVE|STGM_READWRITE, NULL, 0, &stg);
732 ok(r==STG_E_LOCKVIOLATION, "StgOpenStorage should return STG_E_LOCKVIOLATION instead of 0x%08x\n", r);
735 /* non-transacted mode read-only succeeds */
736 r = StgOpenStorage( filename, NULL, STGM_SHARE_DENY_WRITE|STGM_READ, NULL, 0, &stg);
737 ok(r==S_OK, "StgOpenStorage failed with error 0x%08x\n", r);
738 IStorage_Release(stg);
740 r = StgOpenStorage( filename, NULL, STGM_TRANSACTED|STGM_SHARE_DENY_WRITE|STGM_READWRITE, NULL, 0, &stg);
741 ok(r==S_OK, "StgOpenStorage failed with error 0x%08x\n", r);
742 if(stg)
744 static const WCHAR stgname[] = { ' ',' ',' ','2','9',0 };
745 static const WCHAR stgname2[] = { 'C','V','_','i','e','w',0 };
746 static const WCHAR stmname2[] = { 'V','a','r','2','D','a','t','a',0 };
747 IStorage *stg2;
748 IStorage *stg3;
749 STATSTG statstg;
751 r = IStorage_Stat( stg, &statstg, STATFLAG_NONAME );
752 ok(r == S_OK, "Stat should have succeded instead of returning 0x%08x\n", r);
753 ok(statstg.type == STGTY_STORAGE, "Statstg type should have been STGTY_STORAGE instead of %d\n", statstg.type);
754 ok(U(statstg.cbSize).LowPart == 0, "Statstg cbSize.LowPart should have been 0 instead of %d\n", U(statstg.cbSize).LowPart);
755 ok(U(statstg.cbSize).HighPart == 0, "Statstg cbSize.HighPart should have been 0 instead of %d\n", U(statstg.cbSize).HighPart);
756 ok(statstg.grfMode == (STGM_TRANSACTED|STGM_SHARE_DENY_WRITE|STGM_READWRITE),
757 "Statstg grfMode should have been 0x10022 instead of 0x%x\n", statstg.grfMode);
758 ok(statstg.grfLocksSupported == 0, "Statstg grfLocksSupported should have been 0 instead of %d\n", statstg.grfLocksSupported);
759 ok(IsEqualCLSID(&statstg.clsid, &test_stg_cls), "Statstg clsid is not test_stg_cls\n");
760 ok(statstg.grfStateBits == 0, "Statstg grfStateBits should have been 0 instead of %d\n", statstg.grfStateBits);
761 ok(statstg.reserved == 0, "Statstg reserved should have been 0 instead of %d\n", statstg.reserved);
763 r = IStorage_CreateStorage( stg, stgname, STGM_SHARE_EXCLUSIVE, 0, 0, &stg2 );
764 ok(r == S_OK, "CreateStorage should have succeeded instead of returning 0x%08x\n", r);
766 r = IStorage_Stat( stg2, &statstg, STATFLAG_DEFAULT );
767 ok(r == S_OK, "Stat should have succeded instead of returning 0x%08x\n", r);
768 ok(!lstrcmpW(statstg.pwcsName, stgname),
769 "Statstg pwcsName should have been the name the storage was created with\n");
770 ok(statstg.type == STGTY_STORAGE, "Statstg type should have been STGTY_STORAGE instead of %d\n", statstg.type);
771 ok(U(statstg.cbSize).LowPart == 0, "Statstg cbSize.LowPart should have been 0 instead of %d\n", U(statstg.cbSize).LowPart);
772 ok(U(statstg.cbSize).HighPart == 0, "Statstg cbSize.HighPart should have been 0 instead of %d\n", U(statstg.cbSize).HighPart);
773 ok(statstg.grfMode == STGM_SHARE_EXCLUSIVE,
774 "Statstg grfMode should have been STGM_SHARE_EXCLUSIVE instead of 0x%x\n", statstg.grfMode);
775 ok(statstg.grfLocksSupported == 0, "Statstg grfLocksSupported should have been 0 instead of %d\n", statstg.grfLocksSupported);
776 ok(IsEqualCLSID(&statstg.clsid, &CLSID_NULL), "Statstg clsid is not CLSID_NULL\n");
777 ok(statstg.grfStateBits == 0, "Statstg grfStateBits should have been 0 instead of %d\n", statstg.grfStateBits);
778 ok(statstg.reserved == 0, "Statstg reserved should have been 0 instead of %d\n", statstg.reserved);
779 CoTaskMemFree(statstg.pwcsName);
781 r = IStorage_CreateStorage( stg2, stgname2, STGM_SHARE_EXCLUSIVE|STGM_READWRITE, 0, 0, &stg3 );
782 ok(r == STG_E_ACCESSDENIED, "CreateStorage should have returned STG_E_ACCESSDENIED instead of 0x%08x\n", r);
784 r = IStorage_CreateStream( stg2, stmname2, STGM_CREATE|STGM_SHARE_EXCLUSIVE, 0, 0, &stm );
785 ok(r == STG_E_ACCESSDENIED, "CreateStream should have returned STG_E_ACCESSDENIED instead of 0x%08x\n", r);
787 IStorage_Release(stg2);
789 r = IStorage_Release(stg);
790 ok(r == 0, "wrong ref count\n");
792 IStorage_Release(stgprio);
794 DeleteFileW(filename);
797 static void test_streamenum(void)
799 static const WCHAR szPrefix[] = { 's','t','g',0 };
800 static const WCHAR szDot[] = { '.',0 };
801 WCHAR filename[MAX_PATH];
802 IStorage *stg = NULL;
803 HRESULT r;
804 IStream *stm = NULL;
805 static const WCHAR stmname[] = { 'C','O','N','T','E','N','T','S',0 };
806 STATSTG stat;
807 IEnumSTATSTG *ee = NULL;
808 ULONG count;
810 if(!GetTempFileNameW(szDot, szPrefix, 0, filename))
811 return;
813 DeleteFileW(filename);
815 /* create the file */
816 r = StgCreateDocfile( filename, STGM_CREATE | STGM_SHARE_EXCLUSIVE |
817 STGM_READWRITE |STGM_TRANSACTED, 0, &stg);
818 ok(r==S_OK, "StgCreateDocfile failed\n");
820 r = WriteClassStg( stg, &test_stg_cls );
821 ok( r == S_OK, "WriteClassStg failed\n");
823 r = IStorage_Commit( stg, STGC_DEFAULT );
824 ok( r == S_OK, "IStorage_Commit failed\n");
826 /* now create a stream */
827 r = IStorage_CreateStream(stg, stmname, STGM_SHARE_EXCLUSIVE | STGM_READWRITE, 0, 0, &stm );
828 ok(r==S_OK, "IStorage->CreateStream failed\n");
830 r = IStream_Release(stm);
832 /* first enum ... should be 1 stream */
833 r = IStorage_EnumElements(stg, 0, NULL, 0, &ee);
834 ok(r==S_OK, "IStorage->EnumElements failed\n");
836 count = 0xf00;
837 r = IEnumSTATSTG_Next(ee, 1, &stat, &count);
838 ok(r==S_OK, "IEnumSTATSTG->Next failed\n");
839 ok(count == 1, "count wrong\n");
841 r = IEnumSTATSTG_Release(ee);
843 /* second enum... destroy the stream before reading */
844 r = IStorage_EnumElements(stg, 0, NULL, 0, &ee);
845 ok(r==S_OK, "IStorage->EnumElements failed\n");
847 r = IStorage_DestroyElement(stg, stmname);
848 ok(r==S_OK, "IStorage->EnumElements failed\n");
850 todo_wine {
851 count = 0xf00;
852 r = IEnumSTATSTG_Next(ee, 1, &stat, &count);
853 ok(r==S_FALSE, "IEnumSTATSTG->Next failed\n");
854 ok(count == 0, "count wrong\n");
857 /* reset and try again */
858 r = IEnumSTATSTG_Reset(ee);
859 ok(r==S_OK, "IEnumSTATSTG->Reset failed\n");
861 count = 0xf00;
862 r = IEnumSTATSTG_Next(ee, 1, &stat, &count);
863 ok(r==S_FALSE, "IEnumSTATSTG->Next failed\n");
864 ok(count == 0, "count wrong\n");
866 r = IEnumSTATSTG_Release(ee);
867 ok (r == 0, "enum not released\n");
869 r = IStorage_Release( stg );
870 ok (r == 0, "storage not released\n");
872 DeleteFileW(filename);
875 static void test_transact(void)
877 static const WCHAR szPrefix[] = { 's','t','g',0 };
878 static const WCHAR szDot[] = { '.',0 };
879 WCHAR filename[MAX_PATH];
880 IStorage *stg = NULL, *stg2 = NULL;
881 HRESULT r;
882 IStream *stm = NULL;
883 static const WCHAR stmname[] = { 'C','O','N','T','E','N','T','S',0 };
884 static const WCHAR stmname2[] = { 'F','O','O',0 };
886 if(!GetTempFileNameW(szDot, szPrefix, 0, filename))
887 return;
889 DeleteFileW(filename);
891 /* create the file */
892 r = StgCreateDocfile( filename, STGM_CREATE | STGM_SHARE_EXCLUSIVE |
893 STGM_READWRITE |STGM_TRANSACTED, 0, &stg);
894 ok(r==S_OK, "StgCreateDocfile failed\n");
896 /* now create a stream, but don't commit it */
897 r = IStorage_CreateStream(stg, stmname2, STGM_SHARE_EXCLUSIVE | STGM_READWRITE, 0, 0, &stm );
898 ok(r==S_OK, "IStorage->CreateStream failed\n");
900 r = IStream_Write(stm, "this is stream 1\n", 16, NULL);
901 ok(r==S_OK, "IStream->Write failed\n");
903 r = IStream_Release(stm);
905 r = IStorage_Commit(stg, 0);
906 ok(r==S_OK, "IStorage->Commit failed\n");
908 /* now create a stream, but don't commit it */
909 stm = NULL;
910 r = IStorage_CreateStream(stg, stmname, STGM_SHARE_EXCLUSIVE | STGM_READWRITE, 0, 0, &stm );
911 ok(r==S_OK, "IStorage->CreateStream failed\n");
913 r = IStream_Write(stm, "this is stream 2\n", 16, NULL);
914 ok(r==S_OK, "IStream->Write failed\n");
916 r = IStream_Commit(stm, STGC_ONLYIFCURRENT | STGC_DANGEROUSLYCOMMITMERELYTODISKCACHE);
917 ok(r==S_OK, "IStream->Commit failed\n");
919 r = IStream_Release(stm);
921 IStorage_Release(stg);
923 stm = NULL;
924 stg = NULL;
925 r = StgOpenStorage( filename, NULL, STGM_SHARE_DENY_NONE | STGM_READ | STGM_TRANSACTED, NULL, 0, &stg);
926 ok(r==S_OK, "StgOpenStorage failed\n");
928 if (!stg)
929 return;
931 r = IStorage_OpenStream(stg, stmname, NULL, STGM_SHARE_DENY_NONE|STGM_READ, 0, &stm );
932 ok(r==STG_E_INVALIDFLAG, "IStorage->OpenStream failed %08x\n", r);
934 r = IStorage_OpenStream(stg, stmname, NULL, STGM_DELETEONRELEASE|STGM_SHARE_EXCLUSIVE|STGM_READWRITE, 0, &stm );
935 ok(r==STG_E_INVALIDFUNCTION, "IStorage->OpenStream failed %08x\n", r);
937 r = IStorage_OpenStream(stg, stmname, NULL, STGM_TRANSACTED|STGM_SHARE_EXCLUSIVE|STGM_READWRITE, 0, &stm );
938 ok(r==STG_E_INVALIDFUNCTION, "IStorage->OpenStream failed %08x\n", r);
940 r = IStorage_OpenStorage(stg, stmname, NULL, STGM_TRANSACTED|STGM_SHARE_EXCLUSIVE|STGM_READWRITE, NULL, 0, &stg2 );
941 ok(r==STG_E_FILENOTFOUND, "IStorage->OpenStream failed %08x\n", r);
943 todo_wine {
944 r = IStorage_OpenStream(stg, stmname, NULL, STGM_SHARE_EXCLUSIVE|STGM_READWRITE, 0, &stm );
945 ok(r==STG_E_FILENOTFOUND, "IStorage->OpenStream should fail %08x\n", r);
947 if (stm)
948 r = IStream_Release(stm);
950 r = IStorage_OpenStorage(stg, stmname2, NULL, STGM_TRANSACTED|STGM_SHARE_EXCLUSIVE|STGM_READWRITE, NULL, 0, &stg2 );
951 ok(r==STG_E_FILENOTFOUND, "IStorage->OpenStream failed %08x\n", r);
953 r = IStorage_OpenStream(stg, stmname2, NULL, STGM_SHARE_EXCLUSIVE|STGM_READWRITE, 0, &stm );
954 ok(r==S_OK, "IStorage->OpenStream should fail %08x\n", r);
955 if (stm)
956 r = IStream_Release(stm);
958 IStorage_Release(stg);
960 r = DeleteFileW(filename);
961 ok( r == TRUE, "deleted file\n");
964 static void test_ReadClassStm(void)
966 CLSID clsid;
967 HRESULT hr;
968 IStream *pStream;
969 static const LARGE_INTEGER llZero;
971 hr = ReadClassStm(NULL, &clsid);
972 ok(hr == E_INVALIDARG, "ReadClassStm should have returned E_INVALIDARG instead of 0x%08x\n", hr);
974 hr = CreateStreamOnHGlobal(NULL, TRUE, &pStream);
975 ok_ole_success(hr, "CreateStreamOnHGlobal");
976 hr = WriteClassStm(pStream, &test_stg_cls);
977 ok_ole_success(hr, "WriteClassStm");
979 hr = ReadClassStm(pStream, NULL);
980 ok(hr == E_INVALIDARG, "ReadClassStm should have returned E_INVALIDARG instead of 0x%08x\n", hr);
982 /* test not rewound stream */
983 hr = ReadClassStm(pStream, &clsid);
984 ok(hr == STG_E_READFAULT, "ReadClassStm should have returned STG_E_READFAULT instead of 0x%08x\n", hr);
985 ok(IsEqualCLSID(&clsid, &CLSID_NULL), "clsid should have been zeroed\n");
987 hr = IStream_Seek(pStream, llZero, STREAM_SEEK_SET, NULL);
988 ok_ole_success(hr, "IStream_Seek");
989 hr = ReadClassStm(pStream, &clsid);
990 ok_ole_success(hr, "ReadClassStm");
991 ok(IsEqualCLSID(&clsid, &test_stg_cls), "clsid should have been set to CLSID_WineTest\n");
994 START_TEST(storage32)
996 test_hglobal_storage_stat();
997 test_create_storage_modes();
998 test_storage_stream();
999 test_open_storage();
1000 test_storage_suminfo();
1001 test_storage_refcount();
1002 test_streamenum();
1003 test_transact();
1004 test_ReadClassStm();