Commit 27800ef4 authored by Mike Hearn's avatar Mike Hearn Committed by Alexandre Julliard

ole32: Add StgCreateFile test and conformance fix.

parent fec050c8
......@@ -5646,7 +5646,7 @@ HRESULT WINAPI StgCreateDocfile(
if ( FAILED( validateSTGM(grfMode) ))
goto end;
/* StgCreateDocFile always opens for write */
/* StgCreateDocFile seems to refuse readonly access, despite MSDN */
switch(STGM_ACCESS_MODE(grfMode))
{
case STGM_WRITE:
......@@ -5656,21 +5656,20 @@ HRESULT WINAPI StgCreateDocfile(
goto end;
}
/* can't share write */
switch(STGM_SHARE_MODE(grfMode))
{
case STGM_SHARE_EXCLUSIVE:
case STGM_SHARE_DENY_WRITE:
break;
default:
goto end;
}
/* if no share mode given then DENY_NONE is the default */
if (STGM_SHARE_MODE(grfMode) == 0)
grfMode |= STGM_SHARE_DENY_NONE;
/* shared reading requires transacted mode */
if( STGM_SHARE_MODE(grfMode) == STGM_SHARE_DENY_WRITE &&
!(grfMode&STGM_TRANSACTED) )
/* must have at least one access mode */
if (STGM_ACCESS_MODE(grfMode) == 0)
goto end;
/* in direct mode, can only use SHARE_EXCLUSIVE */
if (!(grfMode & STGM_TRANSACTED) && (STGM_SHARE_MODE(grfMode) != STGM_SHARE_EXCLUSIVE))
goto end;
/* but in transacted mode, any share mode is valid */
/*
* Generate a unique name.
*/
......
......@@ -116,15 +116,15 @@ static void test_create_storage_modes(void)
ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
ok(stg == NULL, "stg was set\n");
/* check what happens if the file already exists */
/* check what happens if the file already exists (which is how it's meant to be used) */
r = StgCreateDocfile( filename, STGM_SHARE_EXCLUSIVE | STGM_READWRITE, 0, &stg);
ok(r==S_OK, "StgCreateDocfile failed\n");
r = IStorage_Release(stg);
ok(r == 0, "storage not released\n");
r = StgCreateDocfile( filename, STGM_SHARE_EXCLUSIVE | STGM_READWRITE |STGM_TRANSACTED, 0, &stg);
ok(r==STG_E_FILEALREADYEXISTS, "StgCreateDocfile wrong error\n");
ok(r==STG_E_FILEALREADYEXISTS, "StgCreateDocfile wrong error\n"); /* FAILIFTHERE is default */
r = StgCreateDocfile( filename, STGM_READ, 0, &stg);
ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n"); /* need at least readmode and sharemode */
r = StgCreateDocfile( filename, STGM_SHARE_EXCLUSIVE, 0, &stg);
ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
r = StgCreateDocfile( filename, STGM_SHARE_DENY_WRITE, 0, &stg);
......@@ -141,6 +141,8 @@ static void test_create_storage_modes(void)
ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile failed\n");
r = StgCreateDocfile( filename, STGM_SHARE_DENY_WRITE | STGM_READ, 0, &stg);
ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile wrong error\n");
r = StgCreateDocfile( filename, STGM_TRANSACTED | STGM_SHARE_DENY_WRITE | STGM_READ, 0, &stg);
ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile wrong error\n");
ok(DeleteFileW(filename), "failed to delete file\n");
r = StgCreateDocfile( filename, STGM_SHARE_EXCLUSIVE | STGM_READWRITE |STGM_TRANSACTED, 0, &stg);
......@@ -158,7 +160,6 @@ static void test_create_storage_modes(void)
ok(r==S_OK, "StgCreateDocfile failed\n");
r = IStorage_Release(stg);
ok(r == 0, "storage not released\n");
ok(DeleteFileW(filename), "failed to delete file\n");
/* test the way excel uses StgCreateDocFile */
......@@ -171,6 +172,16 @@ static void test_create_storage_modes(void)
ok(DeleteFileW(filename), "failed to delete file\n");
}
/* and the way windows media uses it ... */
r = StgCreateDocfile( filename, STGM_CREATE | STGM_SHARE_DENY_NONE | STGM_READWRITE | STGM_TRANSACTED, 0, &stg);
ok(r==S_OK, "StgCreateDocfile the windows media way failed\n");
if (r == S_OK)
{
r = IStorage_Release(stg);
ok(r == 0, "storage not released\n");
ok(DeleteFileW(filename), "failed to delete file\n");
}
/* looks like we need STGM_TRANSACTED or STGM_CREATE */
r = StgCreateDocfile( filename, STGM_TRANSACTED|STGM_SHARE_DENY_WRITE|STGM_READWRITE, 0, &stg);
ok(r==S_OK, "StgCreateDocfile the excel way failed\n");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment