Added YUV routines needed for v4l driver, and in the future possibly
[wine/gsoc-2012-control.git] / dlls / ole32 / tests / storage32.c
blobd5479e4efac6df49a5b5eb604ec91ce61d47f3b4
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <stdio.h>
23 #define COBJMACROS
25 #include "wine/test.h"
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winerror.h"
29 #include "ole2.h"
30 #include "objidl.h"
31 #include "initguid.h"
33 DEFINE_GUID( test_stg_cls, 0x88888888, 0x0425, 0x0000, 0,0,0,0,0,0,0,0);
35 void test_hglobal_storage_stat(void)
37 ILockBytes *ilb = NULL;
38 IStorage *stg = NULL;
39 HRESULT r;
40 STATSTG stat;
41 DWORD mode, refcount;
43 r = CreateILockBytesOnHGlobal( NULL, TRUE, &ilb );
44 ok( r == S_OK, "CreateILockBytesOnHGlobal failed\n");
46 mode = STGM_CREATE|STGM_SHARE_EXCLUSIVE|STGM_READWRITE;/*0x1012*/
47 r = StgCreateDocfileOnILockBytes( ilb, mode, 0, &stg );
48 ok( r == S_OK, "CreateILockBytesOnHGlobal failed\n");
50 r = WriteClassStg( stg, &test_stg_cls );
51 ok( r == S_OK, "WriteClassStg failed\n");
53 memset( &stat, 0, sizeof stat );
54 r = IStorage_Stat( stg, &stat, 0 );
56 ok( stat.pwcsName == NULL, "storage name not null\n");
57 ok( stat.type == 1, "type is wrong\n");
58 todo_wine {
59 ok( stat.grfMode == 0x12, "grf mode is incorrect\n");
61 ok( !memcmp(&stat.clsid, &test_stg_cls, sizeof test_stg_cls), "CLSID is wrong\n");
63 refcount = IStorage_Release( stg );
64 ok( refcount == 0, "IStorage refcount is wrong\n");
65 refcount = ILockBytes_Release( ilb );
66 ok( refcount == 0, "ILockBytes refcount is wrong\n");
69 void test_create_storage_modes(void)
71 static const WCHAR szPrefix[] = { 's','t','g',0 };
72 static const WCHAR szDot[] = { '.',0 };
73 WCHAR filename[MAX_PATH];
74 IStorage *stg = NULL;
75 HRESULT r;
77 if(!GetTempFileNameW(szDot, szPrefix, 0, filename))
78 return;
80 DeleteFileW(filename);
82 /* test with some invalid parameters */
83 r = StgCreateDocfile( NULL, 0, 0, &stg);
84 ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
85 r = StgCreateDocfile( filename, 0, 0, &stg);
86 ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
87 r = StgCreateDocfile( filename, STGM_CREATE, 0, &stg);
88 ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
89 r = StgCreateDocfile( filename, STGM_CREATE | STGM_READWRITE, 0, &stg);
90 ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
91 r = StgCreateDocfile( filename, STGM_CREATE | STGM_SHARE_EXCLUSIVE, 0, &stg);
92 ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
93 r = StgCreateDocfile( filename, STGM_CREATE | STGM_SHARE_EXCLUSIVE | STGM_READWRITE, 0, NULL);
94 ok(r==STG_E_INVALIDPOINTER, "StgCreateDocfile succeeded\n");
95 r = StgCreateDocfile( filename, STGM_CREATE | STGM_SHARE_EXCLUSIVE | STGM_READWRITE, 1, &stg);
96 ok(r==STG_E_INVALIDPARAMETER, "StgCreateDocfile succeeded\n");
97 r = StgCreateDocfile( filename, STGM_CREATE | STGM_SHARE_DENY_WRITE | STGM_READWRITE, 0, &stg);
98 ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
99 r = StgCreateDocfile( filename, STGM_SHARE_EXCLUSIVE | STGM_READ, 0, &stg);
100 ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
101 r = StgCreateDocfile( filename, STGM_PRIORITY, 0, &stg);
102 ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
104 /* StgCreateDocfile seems to be very particular about the flags it accepts */
105 r = StgCreateDocfile( filename, STGM_SHARE_EXCLUSIVE | STGM_READWRITE |STGM_TRANSACTED | STGM_WRITE, 0, &stg);
106 ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
107 r = StgCreateDocfile( filename, STGM_SHARE_EXCLUSIVE | STGM_READWRITE |STGM_TRANSACTED | 8, 0, &stg);
108 ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
109 r = StgCreateDocfile( filename, STGM_SHARE_EXCLUSIVE | STGM_READWRITE |STGM_TRANSACTED | 0x80, 0, &stg);
110 ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
111 r = StgCreateDocfile( filename, STGM_SHARE_EXCLUSIVE | STGM_READWRITE |STGM_TRANSACTED | 0x800, 0, &stg);
112 ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
113 r = StgCreateDocfile( filename, STGM_SHARE_EXCLUSIVE | STGM_READWRITE |STGM_TRANSACTED | 0x8000, 0, &stg);
114 ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
115 r = StgCreateDocfile( filename, STGM_SHARE_EXCLUSIVE | STGM_READWRITE |STGM_TRANSACTED | 0x80000, 0, &stg);
116 ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
117 r = StgCreateDocfile( filename, STGM_SHARE_EXCLUSIVE | STGM_READWRITE |STGM_TRANSACTED | 0x800000, 0, &stg);
118 ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
119 ok(stg == NULL, "stg was set\n");
121 /* check what happens if the file already exists */
122 r = StgCreateDocfile( filename, STGM_SHARE_EXCLUSIVE | STGM_READWRITE, 0, &stg);
123 ok(r==S_OK, "StgCreateDocfile failed\n");
124 r = IStorage_Release(stg);
125 ok(r == 0, "storage not released\n");
126 r = StgCreateDocfile( filename, STGM_SHARE_EXCLUSIVE | STGM_READWRITE |STGM_TRANSACTED, 0, &stg);
127 ok(r==STG_E_FILEALREADYEXISTS, "StgCreateDocfile wrong error\n");
128 r = StgCreateDocfile( filename, STGM_READ, 0, &stg);
129 ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
130 r = StgCreateDocfile( filename, STGM_SHARE_EXCLUSIVE, 0, &stg);
131 ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
132 r = StgCreateDocfile( filename, STGM_SHARE_DENY_WRITE, 0, &stg);
133 ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
134 r = StgCreateDocfile( filename, STGM_SHARE_DENY_NONE, 0, &stg);
135 ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile failed\n");
136 r = StgCreateDocfile( filename, STGM_SHARE_DENY_NONE | STGM_TRANSACTED, 0, &stg);
137 ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile failed\n");
138 r = StgCreateDocfile( filename, STGM_SHARE_DENY_NONE | STGM_READWRITE, 0, &stg);
139 ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile failed\n");
140 r = StgCreateDocfile( filename, STGM_SHARE_DENY_NONE | STGM_WRITE, 0, &stg);
141 ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile failed\n");
142 r = StgCreateDocfile( filename, STGM_SHARE_DENY_WRITE | STGM_WRITE, 0, &stg);
143 ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile failed\n");
144 r = StgCreateDocfile( filename, STGM_SHARE_DENY_WRITE | STGM_READ, 0, &stg);
145 ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile wrong error\n");
146 ok(DeleteFileW(filename), "failed to delete file\n");
148 r = StgCreateDocfile( filename, STGM_SHARE_EXCLUSIVE | STGM_READWRITE |STGM_TRANSACTED, 0, &stg);
149 ok(r==S_OK, "StgCreateDocfile failed\n");
150 r = IStorage_Release(stg);
151 ok(r == 0, "storage not released\n");
152 r = StgCreateDocfile( filename, STGM_SHARE_EXCLUSIVE | STGM_READWRITE |STGM_TRANSACTED |STGM_FAILIFTHERE, 0, &stg);
153 ok(r==STG_E_FILEALREADYEXISTS, "StgCreateDocfile wrong error\n");
154 r = StgCreateDocfile( filename, STGM_SHARE_EXCLUSIVE | STGM_WRITE, 0, &stg);
155 ok(r==STG_E_FILEALREADYEXISTS, "StgCreateDocfile wrong error\n");
157 r = StgCreateDocfile( filename, STGM_CREATE | STGM_SHARE_DENY_WRITE | STGM_READWRITE, 0, &stg);
158 ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
159 r = StgCreateDocfile( filename, STGM_CREATE | STGM_SHARE_EXCLUSIVE | STGM_READWRITE |STGM_TRANSACTED, 0, &stg);
160 ok(r==S_OK, "StgCreateDocfile failed\n");
161 r = IStorage_Release(stg);
162 ok(r == 0, "storage not released\n");
164 ok(DeleteFileW(filename), "failed to delete file\n");
166 /* test the way excel uses StgCreateDocFile */
167 r = StgCreateDocfile( filename, STGM_TRANSACTED|STGM_CREATE|STGM_SHARE_DENY_WRITE|STGM_READWRITE, 0, &stg);
168 ok(r==S_OK, "StgCreateDocfile the excel way failed\n");
169 if(r == S_OK)
171 r = IStorage_Release(stg);
172 ok(r == 0, "storage not released\n");
173 ok(DeleteFileW(filename), "failed to delete file\n");
176 /* looks like we need STGM_TRANSACTED or STGM_CREATE */
177 r = StgCreateDocfile( filename, STGM_TRANSACTED|STGM_SHARE_DENY_WRITE|STGM_READWRITE, 0, &stg);
178 ok(r==S_OK, "StgCreateDocfile the excel way failed\n");
179 if(r == S_OK)
181 r = IStorage_Release(stg);
182 ok(r == 0, "storage not released\n");
183 ok(DeleteFileW(filename), "failed to delete file\n");
186 r = StgCreateDocfile( filename, STGM_TRANSACTED|STGM_CREATE|STGM_SHARE_DENY_WRITE|STGM_WRITE, 0, &stg);
187 ok(r==S_OK, "StgCreateDocfile the excel way failed\n");
188 if(r == S_OK)
190 r = IStorage_Release(stg);
191 ok(r == 0, "storage not released\n");
192 ok(DeleteFileW(filename), "failed to delete file\n");
195 r = StgCreateDocfile( filename, STGM_CREATE | STGM_SHARE_EXCLUSIVE | STGM_READWRITE, 0, &stg);
196 ok(r==S_OK, "StgCreateDocfile the powerpoint way failed\n");
197 if(r == S_OK)
199 r = IStorage_Release(stg);
200 ok(r == 0, "storage not released\n");
201 ok(DeleteFileW(filename), "failed to delete file\n");
204 /* test the way msi uses StgCreateDocfile */
205 r = StgCreateDocfile( filename, STGM_DIRECT | STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, &stg);
206 ok(r==S_OK, "StgCreateDocFile failed\n");
207 r = IStorage_Release(stg);
208 ok(r == 0, "storage not released\n");
209 ok(DeleteFileW(filename), "failed to delete file\n");
212 void test_storage_stream(void)
214 static const WCHAR stmname[] = { 'C','O','N','T','E','N','T','S',0 };
215 static const WCHAR szPrefix[] = { 's','t','g',0 };
216 static const WCHAR szDot[] = { '.',0 };
217 static const WCHAR longname[] = {
218 'a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a',
219 'a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a',0
221 WCHAR filename[MAX_PATH];
222 IStorage *stg = NULL;
223 HRESULT r;
224 IStream *stm = NULL;
225 ULONG count = 0;
226 LARGE_INTEGER pos;
227 ULARGE_INTEGER p;
228 unsigned char buffer[0x100];
230 if(!GetTempFileNameW(szDot, szPrefix, 0, filename))
231 return;
233 DeleteFileW(filename);
235 r = StgCreateDocfile( filename, STGM_CREATE | STGM_SHARE_EXCLUSIVE | STGM_READWRITE |STGM_TRANSACTED, 0, &stg);
236 ok(r==S_OK, "StgCreateDocfile failed\n");
238 /* try create some invalid streams */
239 r = IStorage_CreateStream(stg, stmname, STGM_SHARE_EXCLUSIVE | STGM_READWRITE, 1, 0, &stm );
240 ok(r==STG_E_INVALIDPARAMETER, "IStorage->CreateStream wrong error\n");
241 r = IStorage_CreateStream(stg, stmname, STGM_SHARE_EXCLUSIVE | STGM_READWRITE, 0, 1, &stm );
242 ok(r==STG_E_INVALIDPARAMETER, "IStorage->CreateStream wrong error\n");
243 r = IStorage_CreateStream(stg, stmname, STGM_SHARE_EXCLUSIVE | STGM_READWRITE, 0, 0, NULL );
244 ok(r==STG_E_INVALIDPOINTER, "IStorage->CreateStream wrong error\n");
245 r = IStorage_CreateStream(stg, NULL, STGM_SHARE_EXCLUSIVE | STGM_READWRITE, 0, 0, &stm );
246 ok(r==STG_E_INVALIDNAME, "IStorage->CreateStream wrong error\n");
247 r = IStorage_CreateStream(stg, longname, STGM_SHARE_EXCLUSIVE | STGM_READWRITE, 0, 0, &stm );
248 ok(r==STG_E_INVALIDNAME, "IStorage->CreateStream wrong error, got %ld GetLastError()=%ld\n", r, GetLastError());
249 r = IStorage_CreateStream(stg, stmname, STGM_READWRITE, 0, 0, &stm );
250 ok(r==STG_E_INVALIDFLAG, "IStorage->CreateStream wrong error\n");
251 r = IStorage_CreateStream(stg, stmname, STGM_READ, 0, 0, &stm );
252 ok(r==STG_E_INVALIDFLAG, "IStorage->CreateStream wrong error\n");
253 r = IStorage_CreateStream(stg, stmname, STGM_WRITE, 0, 0, &stm );
254 ok(r==STG_E_INVALIDFLAG, "IStorage->CreateStream wrong error\n");
255 r = IStorage_CreateStream(stg, stmname, STGM_SHARE_DENY_NONE | STGM_READWRITE, 0, 0, &stm );
256 ok(r==STG_E_INVALIDFLAG, "IStorage->CreateStream wrong error\n");
257 r = IStorage_CreateStream(stg, stmname, STGM_SHARE_DENY_NONE | STGM_READ, 0, 0, &stm );
258 ok(r==STG_E_INVALIDFLAG, "IStorage->CreateStream wrong error\n");
260 /* now really create a stream and delete it */
261 r = IStorage_CreateStream(stg, stmname, STGM_SHARE_EXCLUSIVE | STGM_READWRITE, 0, 0, &stm );
262 ok(r==S_OK, "IStorage->CreateStream failed\n");
263 r = IStream_Release(stm);
264 ok(r == 0, "wrong ref count\n");
265 r = IStorage_CreateStream(stg, stmname, STGM_SHARE_EXCLUSIVE | STGM_READWRITE, 0, 0, &stm );
266 ok(r==STG_E_FILEALREADYEXISTS, "IStorage->CreateStream failed\n");
267 r = IStorage_DestroyElement(stg,stmname);
268 ok(r==S_OK, "IStorage->DestroyElement failed\n");
270 /* create a stream and write to it */
271 r = IStorage_CreateStream(stg, stmname, STGM_SHARE_EXCLUSIVE | STGM_READWRITE, 0, 0, &stm );
272 ok(r==S_OK, "IStorage->CreateStream failed\n");
274 r = IStream_Write(stm, NULL, 0, NULL );
275 ok(r==STG_E_INVALIDPOINTER, "IStream->Write wrong error\n");
276 r = IStream_Write(stm, "Hello\n", 0, NULL );
277 ok(r==S_OK, "failed to write stream\n");
278 r = IStream_Write(stm, "Hello\n", 0, &count );
279 ok(r==S_OK, "failed to write stream\n");
280 r = IStream_Write(stm, "Hello\n", 6, &count );
281 ok(r==S_OK, "failed to write stream\n");
282 r = IStream_Commit(stm, STGC_DEFAULT );
283 ok(r==S_OK, "failed to commit stream\n");
284 r = IStream_Commit(stm, STGC_DEFAULT );
285 ok(r==S_OK, "failed to commit stream\n");
287 /* seek round a bit, reset the stream size */
288 pos.QuadPart = 0;
289 r = IStream_Seek(stm, pos, 3, &p );
290 ok(r==STG_E_INVALIDFUNCTION, "IStream->Seek returned wrong error\n");
291 r = IStream_Seek(stm, pos, STREAM_SEEK_SET, NULL);
292 ok(r==S_OK, "failed to seek stream\n");
293 r = IStream_Seek(stm, pos, STREAM_SEEK_SET, &p );
294 ok(r==S_OK, "failed to seek stream\n");
295 r = IStream_SetSize(stm,p);
296 ok(r==S_OK, "failed to set pos\n");
297 pos.QuadPart = 10;
298 r = IStream_Seek(stm, pos, STREAM_SEEK_SET, &p );
299 ok(r==S_OK, "failed to seek stream\n");
300 ok(p.QuadPart == 10, "at wrong place\n");
301 pos.QuadPart = 0;
302 r = IStream_Seek(stm, pos, STREAM_SEEK_END, &p );
303 ok(r==S_OK, "failed to seek stream\n");
304 ok(p.QuadPart == 0, "at wrong place\n");
305 r = IStream_Read(stm, buffer, sizeof buffer, &count );
306 ok(r==S_OK, "failed to set pos\n");
307 ok(count == 0, "read bytes from empty stream\n");
309 /* wrap up */
310 r = IStream_Release(stm);
311 ok(r == 0, "wrong ref count\n");
312 r = IStorage_Release(stg);
313 ok(r == 0, "wrong ref count\n");
314 r = DeleteFileW(filename);
315 ok(r == TRUE, "file should exist\n");
318 static BOOL touch_file(LPCWSTR filename)
320 HANDLE file;
322 file = CreateFileW(filename, GENERIC_READ|GENERIC_WRITE, 0, NULL,
323 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
324 if (file==INVALID_HANDLE_VALUE)
325 return FALSE;
326 CloseHandle(file);
327 return TRUE;
330 static BOOL is_zero_length(LPCWSTR filename)
332 HANDLE file;
333 DWORD len;
335 file = CreateFileW(filename, GENERIC_READ, 0, NULL,
336 OPEN_EXISTING, 0, NULL);
337 if (file==INVALID_HANDLE_VALUE)
338 return FALSE;
339 len = GetFileSize(file, NULL);
340 CloseHandle(file);
341 return len == 0;
344 void test_open_storage(void)
346 static const WCHAR szPrefix[] = { 's','t','g',0 };
347 static const WCHAR szNonExist[] = { 'n','o','n','e','x','i','s','t',0 };
348 static const WCHAR szDot[] = { '.',0 };
349 WCHAR filename[MAX_PATH];
350 IStorage *stg = NULL, *stg2 = NULL;
351 HRESULT r;
352 DWORD stgm;
354 if(!GetTempFileNameW(szDot, szPrefix, 0, filename))
355 return;
357 /* try opening a zero length file - it should stay zero length */
358 DeleteFileW(filename);
359 touch_file(filename);
360 stgm = STGM_NOSCRATCH | STGM_TRANSACTED | STGM_SHARE_DENY_WRITE | STGM_READWRITE;
361 r = StgOpenStorage( filename, NULL, stgm, NULL, 0, &stg);
362 ok(r==STG_E_FILEALREADYEXISTS, "StgOpenStorage didn't fail\n");
364 stgm = STGM_SHARE_EXCLUSIVE | STGM_READWRITE;
365 r = StgOpenStorage( filename, NULL, stgm, NULL, 0, &stg);
366 ok(r==STG_E_FILEALREADYEXISTS, "StgOpenStorage didn't fail\n");
367 ok(is_zero_length(filename), "file length changed\n");
369 DeleteFileW(filename);
371 /* create the file */
372 r = StgCreateDocfile( filename, STGM_CREATE | STGM_SHARE_EXCLUSIVE | STGM_READWRITE |STGM_TRANSACTED, 0, &stg);
373 ok(r==S_OK, "StgCreateDocfile failed\n");
374 IStorage_Release(stg);
376 r = StgOpenStorage( filename, NULL, 0, NULL, 0, &stg);
377 ok(r==STG_E_INVALIDFLAG, "StgOpenStorage wrong error\n");
378 r = StgOpenStorage( NULL, NULL, STGM_SHARE_EXCLUSIVE, NULL, 0, &stg);
379 ok(r==STG_E_INVALIDNAME, "StgOpenStorage wrong error\n");
380 r = StgOpenStorage( filename, NULL, STGM_SHARE_EXCLUSIVE | STGM_READ, NULL, 0, NULL);
381 ok(r==STG_E_INVALIDPOINTER, "StgOpenStorage wrong error\n");
382 r = StgOpenStorage( filename, NULL, STGM_SHARE_EXCLUSIVE | STGM_READ, NULL, 1, &stg);
383 ok(r==STG_E_INVALIDPARAMETER, "StgOpenStorage wrong error\n");
384 r = StgOpenStorage( szNonExist, NULL, STGM_SHARE_EXCLUSIVE | STGM_READ, NULL, 0, &stg);
385 ok(r==STG_E_FILENOTFOUND, "StgOpenStorage failed\n");
386 r = StgOpenStorage( filename, NULL, STGM_CREATE | STGM_SHARE_EXCLUSIVE | STGM_READ, NULL, 0, &stg);
387 ok(r==STG_E_INVALIDFLAG, "StgOpenStorage failed\n");
388 r = StgOpenStorage( filename, NULL, STGM_SHARE_DENY_NONE | STGM_READ, NULL, 0, &stg);
389 ok(r==STG_E_INVALIDFLAG, "StgOpenStorage failed\n");
390 r = StgOpenStorage( filename, NULL, STGM_SHARE_DENY_READ | STGM_READ, NULL, 0, &stg);
391 ok(r==STG_E_INVALIDFLAG, "StgOpenStorage failed\n");
392 r = StgOpenStorage( filename, NULL, STGM_SHARE_DENY_WRITE | STGM_READWRITE, NULL, 0, &stg);
393 ok(r==STG_E_INVALIDFLAG, "StgOpenStorage failed\n");
395 /* open it for real */
396 r = StgOpenStorage( filename, NULL, STGM_SHARE_DENY_WRITE | STGM_READ, NULL, 0, &stg);
397 ok(r==S_OK, "StgOpenStorage failed\n");
398 if(stg)
400 r = IStorage_Release(stg);
401 ok(r == 0, "wrong ref count\n");
404 /* test the way word opens its custom dictionary */
405 r = StgOpenStorage( filename, NULL, STGM_NOSCRATCH | STGM_TRANSACTED |
406 STGM_SHARE_DENY_WRITE | STGM_READWRITE, NULL, 0, &stg);
407 ok(r==S_OK, "StgOpenStorage failed\n");
408 if(stg)
410 r = IStorage_Release(stg);
411 ok(r == 0, "wrong ref count\n");
414 r = StgOpenStorage( filename, NULL, STGM_SHARE_EXCLUSIVE | STGM_READ, NULL, 0, &stg);
415 ok(r==S_OK, "StgOpenStorage failed\n");
416 r = StgOpenStorage( filename, NULL, STGM_SHARE_EXCLUSIVE | STGM_READ, NULL, 0, &stg2);
417 ok(r==STG_E_SHAREVIOLATION, "StgOpenStorage failed\n");
418 if(stg)
420 r = IStorage_Release(stg);
421 ok(r == 0, "wrong ref count\n");
424 /* now try write to a storage file we opened read-only */
425 r = StgOpenStorage( filename, NULL, STGM_SHARE_EXCLUSIVE | STGM_READ, NULL, 0, &stg);
426 ok(r==S_OK, "StgOpenStorage failed\n");
427 if(stg)
429 const static WCHAR stmname[] = { 'w','i','n','e','t','e','s','t',0};
430 IStream *stm = NULL;
431 IStorage *stg2 = NULL;
433 r = IStorage_CreateStream( stg, stmname, STGM_WRITE | STGM_SHARE_EXCLUSIVE,
434 0, 0, &stm );
435 ok(r == STG_E_ACCESSDENIED, "CreateStream should fail\n");
436 r = IStorage_CreateStorage( stg, stmname, STGM_WRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &stg2);
437 ok(r == STG_E_ACCESSDENIED, "CreateStream should fail\n");
439 r = IStorage_Release(stg);
440 ok(r == 0, "wrong ref count\n");
443 r = DeleteFileW(filename);
444 ok(r, "file didn't exist\n");
447 void test_storage_suminfo(void)
449 static const WCHAR szDot[] = { '.',0 };
450 static const WCHAR szPrefix[] = { 's','t','g',0 };
451 WCHAR filename[MAX_PATH];
452 IStorage *stg = NULL;
453 IPropertySetStorage *propset = NULL;
454 IPropertyStorage *ps = NULL;
455 HRESULT r;
457 if(!GetTempFileNameW(szDot, szPrefix, 0, filename))
458 return;
460 DeleteFileW(filename);
462 /* create the file */
463 r = StgCreateDocfile( filename, STGM_CREATE | STGM_SHARE_EXCLUSIVE |
464 STGM_READWRITE |STGM_TRANSACTED, 0, &stg);
465 ok(r==S_OK, "StgCreateDocfile failed\n");
467 r = IStorage_QueryInterface( stg, &IID_IPropertySetStorage, (LPVOID) &propset );
468 ok(r == S_OK, "query interface failed\n");
470 /* delete it */
471 r = IPropertySetStorage_Delete( propset, &FMTID_SummaryInformation );
472 ok(r == STG_E_FILENOTFOUND, "deleted property set storage\n");
474 r = IPropertySetStorage_Open( propset, &FMTID_SummaryInformation,
475 STGM_READ | STGM_SHARE_EXCLUSIVE, &ps );
476 ok(r == STG_E_FILENOTFOUND, "opened property set storage\n");
478 r = IPropertySetStorage_Create( propset, &FMTID_SummaryInformation, NULL, 0,
479 STGM_READ | STGM_SHARE_EXCLUSIVE, &ps );
480 ok(r == STG_E_INVALIDFLAG, "created property set storage\n");
482 r = IPropertySetStorage_Create( propset, &FMTID_SummaryInformation, NULL, 0,
483 STGM_READ, &ps );
484 ok(r == STG_E_INVALIDFLAG, "created property set storage\n");
486 r = IPropertySetStorage_Create( propset, &FMTID_SummaryInformation, NULL, 0, 0, &ps );
487 ok(r == STG_E_INVALIDFLAG, "created property set storage\n");
489 r = IPropertySetStorage_Create( propset, &FMTID_SummaryInformation, NULL, 0,
490 STGM_WRITE|STGM_SHARE_EXCLUSIVE, &ps );
491 ok(r == STG_E_INVALIDFLAG, "created property set storage\n");
493 r = IPropertySetStorage_Create( propset, &FMTID_SummaryInformation, NULL, 0,
494 STGM_CREATE|STGM_WRITE|STGM_SHARE_EXCLUSIVE, &ps );
495 ok(r == STG_E_INVALIDFLAG, "created property set storage\n");
497 /* now try really creating a a property set */
498 r = IPropertySetStorage_Create( propset, &FMTID_SummaryInformation, NULL, 0,
499 STGM_CREATE|STGM_READWRITE|STGM_SHARE_EXCLUSIVE, &ps );
500 ok(r == S_OK, "failed to create property set storage\n");
502 if( ps )
503 IPropertyStorage_Release(ps);
505 /* now try creating the same thing again */
506 r = IPropertySetStorage_Create( propset, &FMTID_SummaryInformation, NULL, 0,
507 STGM_CREATE|STGM_READWRITE|STGM_SHARE_EXCLUSIVE, &ps );
508 ok(r == S_OK, "failed to create property set storage\n");
509 if( ps )
510 IPropertyStorage_Release(ps);
512 /* should be able to open it */
513 r = IPropertySetStorage_Open( propset, &FMTID_SummaryInformation,
514 STGM_READWRITE|STGM_SHARE_EXCLUSIVE, &ps);
515 ok(r == S_OK, "open failed\n");
516 if(r == S_OK)
517 IPropertyStorage_Release(ps);
519 /* delete it */
520 r = IPropertySetStorage_Delete( propset, &FMTID_SummaryInformation );
521 ok(r == S_OK, "failed to delete property set storage\n");
523 /* try opening with an invalid FMTID */
524 r = IPropertySetStorage_Open( propset, NULL,
525 STGM_READWRITE|STGM_SHARE_EXCLUSIVE, &ps);
526 ok(r == E_INVALIDARG, "open succeeded\n");
527 if(r == S_OK)
528 IPropertyStorage_Release(ps);
530 /* try a bad guid */
531 r = IPropertySetStorage_Open( propset, &IID_IStorage,
532 STGM_READWRITE|STGM_SHARE_EXCLUSIVE, &ps);
533 ok(r == STG_E_FILENOTFOUND, "open succeeded\n");
534 if(r == S_OK)
535 IPropertyStorage_Release(ps);
538 /* try some invalid flags */
539 r = IPropertySetStorage_Open( propset, &FMTID_SummaryInformation,
540 STGM_CREATE | STGM_READWRITE|STGM_SHARE_EXCLUSIVE, &ps);
541 ok(r == STG_E_INVALIDFLAG, "open succeeded\n");
542 if(r == S_OK)
543 IPropertyStorage_Release(ps);
545 /* after deleting it, it should be gone */
546 r = IPropertySetStorage_Open( propset, &FMTID_SummaryInformation,
547 STGM_READWRITE|STGM_SHARE_EXCLUSIVE, &ps);
548 ok(r == STG_E_FILENOTFOUND, "open failed\n");
549 if(r == S_OK)
550 IPropertyStorage_Release(ps);
552 r = IPropertySetStorage_Release( propset );
553 ok(r == 1, "ref count wrong\n");
555 r = IStorage_Release(stg);
556 ok(r == 0, "ref count wrong\n");
558 DeleteFileW(filename);
561 START_TEST(storage32)
563 test_hglobal_storage_stat();
564 test_create_storage_modes();
565 test_storage_stream();
566 test_open_storage();
567 test_storage_suminfo();