Commit 71424b80 authored by Mike McCormack's avatar Mike McCormack Committed by Alexandre Julliard

Tests and fixes for StgOpenStorage.

parent fed06be7
...@@ -51,6 +51,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(storage); ...@@ -51,6 +51,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(storage);
#define FILE_BEGIN 0 #define FILE_BEGIN 0
#define STGM_SHARE_MODE(stgm) ((stgm)&0xf0)
/* Used for OleConvertIStorageToOLESTREAM and OleConvertOLESTREAMToIStorage */ /* Used for OleConvertIStorageToOLESTREAM and OleConvertOLESTREAMToIStorage */
#define OLESTREAM_ID 0x501 #define OLESTREAM_ID 0x501
...@@ -5580,18 +5581,44 @@ HRESULT WINAPI StgOpenStorage( ...@@ -5580,18 +5581,44 @@ HRESULT WINAPI StgOpenStorage(
snbExclude, reserved, ppstgOpen); snbExclude, reserved, ppstgOpen);
/* /*
* Perform a sanity check * Perform sanity checks
*/ */
if (( pwcsName == 0) || (ppstgOpen == 0) ) if (pwcsName == 0)
{
hr = STG_E_INVALIDNAME;
goto end;
}
if (ppstgOpen == 0)
{ {
hr = STG_E_INVALIDPOINTER; hr = STG_E_INVALIDPOINTER;
goto end; goto end;
} }
if (reserved)
{
hr = STG_E_INVALIDPARAMETER;
goto end;
}
/*
* Validate the sharing mode
*/
switch(STGM_SHARE_MODE(grfMode))
{
case STGM_SHARE_EXCLUSIVE:
case STGM_SHARE_DENY_WRITE:
break;
default:
hr = STG_E_INVALIDFLAG;
goto end;
}
/* /*
* Validate the STGM flags * Validate the STGM flags
*/ */
if ( FAILED( validateSTGM(grfMode) )) if ( FAILED( validateSTGM(grfMode) ) ||
(grfMode&STGM_CREATE))
{ {
hr = STG_E_INVALIDFLAG; hr = STG_E_INVALIDFLAG;
goto end; goto end;
...@@ -5616,8 +5643,6 @@ HRESULT WINAPI StgOpenStorage( ...@@ -5616,8 +5643,6 @@ HRESULT WINAPI StgOpenStorage(
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS,
0); 0);
length = GetFileSize(hFile, NULL);
if (hFile==INVALID_HANDLE_VALUE) if (hFile==INVALID_HANDLE_VALUE)
{ {
DWORD last_error = GetLastError(); DWORD last_error = GetLastError();
...@@ -5650,6 +5675,8 @@ HRESULT WINAPI StgOpenStorage( ...@@ -5650,6 +5675,8 @@ HRESULT WINAPI StgOpenStorage(
goto end; goto end;
} }
length = GetFileSize(hFile, NULL);
/* /*
* Allocate and initialize the new IStorage32object. * Allocate and initialize the new IStorage32object.
*/ */
......
...@@ -256,9 +256,63 @@ void test_storage_stream(void) ...@@ -256,9 +256,63 @@ void test_storage_stream(void)
ok(r == TRUE, "file should exist\n"); ok(r == TRUE, "file should exist\n");
} }
void test_open_storage(void)
{
static const WCHAR szPrefix[] = { 's','t','g',0 };
static const WCHAR szNonExist[] = { 'n','o','n','e','x','i','s','t',0 };
static const WCHAR szDot[] = { '.',0 };
WCHAR filename[MAX_PATH];
IStorage *stg = NULL, *stg2 = NULL;
HRESULT r;
if(!GetTempFileNameW(szDot, szPrefix, 0, filename))
return;
DeleteFileW(filename);
/* create the file */
r = StgCreateDocfile( filename, STGM_CREATE | STGM_SHARE_EXCLUSIVE | STGM_READWRITE |STGM_TRANSACTED, 0, &stg);
ok(r==S_OK, "StgCreateDocfile failed\n");
IStorage_Release(stg);
r = StgOpenStorage( filename, NULL, 0, NULL, 0, &stg);
ok(r==STG_E_INVALIDFLAG, "StgOpenStorage wrong error\n");
r = StgOpenStorage( NULL, NULL, STGM_SHARE_EXCLUSIVE, NULL, 0, &stg);
ok(r==STG_E_INVALIDNAME, "StgOpenStorage wrong error\n");
r = StgOpenStorage( filename, NULL, STGM_SHARE_EXCLUSIVE | STGM_READ, NULL, 0, NULL);
ok(r==STG_E_INVALIDPOINTER, "StgOpenStorage wrong error\n");
r = StgOpenStorage( filename, NULL, STGM_SHARE_EXCLUSIVE | STGM_READ, NULL, 1, &stg);
ok(r==STG_E_INVALIDPARAMETER, "StgOpenStorage wrong error\n");
r = StgOpenStorage( szNonExist, NULL, STGM_SHARE_EXCLUSIVE | STGM_READ, NULL, 0, &stg);
ok(r==STG_E_FILENOTFOUND, "StgOpenStorage failed\n");
r = StgOpenStorage( filename, NULL, STGM_CREATE | STGM_SHARE_EXCLUSIVE | STGM_READ, NULL, 0, &stg);
ok(r==STG_E_INVALIDFLAG, "StgOpenStorage failed\n");
r = StgOpenStorage( filename, NULL, STGM_SHARE_DENY_NONE | STGM_READ, NULL, 0, &stg);
ok(r==STG_E_INVALIDFLAG, "StgOpenStorage failed\n");
r = StgOpenStorage( filename, NULL, STGM_SHARE_DENY_READ | STGM_READ, NULL, 0, &stg);
ok(r==STG_E_INVALIDFLAG, "StgOpenStorage failed\n");
/* open it for real */
r = StgOpenStorage( filename, NULL, STGM_SHARE_DENY_WRITE | STGM_READ, NULL, 0, &stg);
ok(r==S_OK, "StgOpenStorage failed\n");
r = IStorage_Release(stg);
ok(r == 0, "wrong ref count\n");
r = StgOpenStorage( filename, NULL, STGM_SHARE_EXCLUSIVE | STGM_READ, NULL, 0, &stg);
ok(r==S_OK, "StgOpenStorage failed\n");
r = StgOpenStorage( filename, NULL, STGM_SHARE_EXCLUSIVE | STGM_READ, NULL, 0, &stg2);
ok(r==STG_E_SHAREVIOLATION, "StgOpenStorage failed\n");
r = IStorage_Release(stg);
ok(r == 0, "wrong ref count\n");
r = DeleteFileW(filename);
ok(r, "file didn't exist\n");
}
START_TEST(storage32) START_TEST(storage32)
{ {
test_hglobal_storage_stat(); test_hglobal_storage_stat();
test_create_storage_modes(); test_create_storage_modes();
test_storage_stream(); test_storage_stream();
test_open_storage();
} }
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