ReactOS  0.4.14-dev-49-gfb4591c
storage32.c File Reference
#include <stdio.h>
#include <windows.h>
#include "wine/test.h"
#include "ole2.h"
#include "objidl.h"
#include "initguid.h"
Include dependency graph for storage32.c:

Go to the source code of this file.

Classes

struct  TestLockBytes
 
struct  access_res
 
struct  lock_test
 

Macros

#define COBJMACROS
 
#define NONAMELESSUNION
 
#define NONAMELESSSTRUCT
 
#define ok_ole_success(hr, func)   ok(hr == S_OK, func " failed with error 0x%08x\n", hr)
 
#define test_file_access(file, ares)   _test_file_access(file, ares, __LINE__)
 

Typedefs

typedef struct TestLockBytes TestLockBytes
 

Functions

 DEFINE_GUID (test_stg_cls, 0x88888888, 0x0425, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0)
 
static int strcmp_ww (LPCWSTR strw1, LPCWSTR strw2)
 
static TestLockBytesimpl_from_ILockBytes (ILockBytes *iface)
 
static HRESULT WINAPI TestLockBytes_QueryInterface (ILockBytes *iface, REFIID iid, void **ppv)
 
static ULONG WINAPI TestLockBytes_AddRef (ILockBytes *iface)
 
static ULONG WINAPI TestLockBytes_Release (ILockBytes *iface)
 
static HRESULT WINAPI TestLockBytes_ReadAt (ILockBytes *iface, ULARGE_INTEGER ulOffset, void *pv, ULONG cb, ULONG *pcbRead)
 
static HRESULT WINAPI TestLockBytes_WriteAt (ILockBytes *iface, ULARGE_INTEGER ulOffset, const void *pv, ULONG cb, ULONG *pcbWritten)
 
static HRESULT WINAPI TestLockBytes_Flush (ILockBytes *iface)
 
static HRESULT WINAPI TestLockBytes_SetSize (ILockBytes *iface, ULARGE_INTEGER cb)
 
static HRESULT WINAPI TestLockBytes_LockRegion (ILockBytes *iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
 
static HRESULT WINAPI TestLockBytes_UnlockRegion (ILockBytes *iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
 
static HRESULT WINAPI TestLockBytes_Stat (ILockBytes *iface, STATSTG *pstatstg, DWORD grfStatFlag)
 
static void CreateTestLockBytes (TestLockBytes **This)
 
static void DeleteTestLockBytes (TestLockBytes *This)
 
static void test_hglobal_storage_stat (void)
 
static void test_create_storage_modes (void)
 
static void test_stgcreatestorageex (void)
 
static void test_storage_stream (void)
 
static BOOL touch_file (LPCSTR filename)
 
static BOOL is_zero_length (LPCSTR filename)
 
static BOOL is_existing_file (LPCSTR filename)
 
static void test_open_storage (void)
 
static void test_storage_suminfo (void)
 
static void test_storage_refcount (void)
 
static void test_writeclassstg (void)
 
static void test_streamenum (void)
 
static void test_transact (void)
 
static void test_substorage_share (void)
 
static void test_revert (void)
 
static void test_parent_free (void)
 
static void test_nonroot_transacted (void)
 
static void test_ReadClassStm (void)
 
static void _test_file_access (LPCSTR file, const struct access_res *ares, DWORD line)
 
static void test_access (void)
 
static void test_readonly (void)
 
static void test_simple (void)
 
static void test_fmtusertypestg (void)
 
static void test_references (void)
 
static HRESULT create_test_file (IStorage *dest)
 
static void test_copyto (void)
 
static void test_copyto_snbexclusions (void)
 
static void test_copyto_iidexclusions_storage (void)
 
static void test_copyto_iidexclusions_stream (void)
 
static void test_rename (void)
 
static void test_toplevel_stat (void)
 
static void test_substorage_enum (void)
 
static void test_copyto_locking (void)
 
static void test_copyto_recursive (void)
 
static void test_hglobal_storage_creation (void)
 
static void test_convert (void)
 
static void test_direct_swmr (void)
 
static BOOL can_open (LPCWSTR filename, DWORD access, DWORD sharing)
 
static void check_sharing (LPCWSTR filename, const struct lock_test *current, DWORD access, DWORD sharing, const char *desc, DWORD *open_mode, BOOL *any_failure)
 
static void check_access (LPCWSTR filename, const struct lock_test *current, DWORD access, DWORD sharing, const char *desc, DWORD open_mode, BOOL *any_failure)
 
static void test_locking (void)
 
static void test_transacted_shared (void)
 
static void test_overwrite (void)
 
static void test_custom_lockbytes (void)
 
 START_TEST (storage32)
 

Variables

static CHAR filenameA [MAX_PATH]
 
static WCHAR filename [MAX_PATH]
 
static const char file1_nameA [] = {'c','o','p','y','t','e','s','t','A',0}
 
static const WCHAR file1_name [] = {'c','o','p','y','t','e','s','t','A',0}
 
static const char file2_nameA [] = {'c','o','p','y','t','e','s','t','B',0}
 
static const WCHAR file2_name [] = {'c','o','p','y','t','e','s','t','B',0}
 
static const WCHAR stgA_name [] = {'S','t','o','r','a','g','e','A',0}
 
static const WCHAR stgB_name [] = {'S','t','o','r','a','g','e','B',0}
 
static const WCHAR strmA_name [] = {'S','t','r','e','a','m','A',0}
 
static const WCHAR strmB_name [] = {'S','t','r','e','a','m','B',0}
 
static const WCHAR strmC_name [] = {'S','t','r','e','a','m','C',0}
 
static const ILockBytesVtbl TestLockBytes_Vtbl
 
static const struct access_res create [16]
 
static const struct access_res create_commit [16]
 
static const struct access_res create_close [16]
 
static const DWORD access_modes [4]
 
static const DWORD share_modes [4]
 
static const int priority_locked_bytes [] = { 0x158, 0x181, 0x193, -1 }
 
static const int rwex_locked_bytes [] = { 0x193, 0x1a7, 0x1bb, 0x1cf, -1 }
 
static const int rw_locked_bytes [] = { 0x193, 0x1a7, -1 }
 
static const int nosn_locked_bytes [] = { 0x16c, 0x193, 0x1a7, 0x1cf, -1 }
 
static const int rwdw_locked_bytes [] = { 0x193, 0x1a7, 0x1cf, -1 }
 
static const int wodw_locked_bytes [] = { 0x1a7, 0x1cf, -1 }
 
static const int tr_locked_bytes [] = { 0x193, -1 }
 
static const int no_locked_bytes [] = { -1 }
 
static const int roex_locked_bytes [] = { 0x193, 0x1bb, 0x1cf, -1 }
 
static const int rwex_fail_ranges [] = { 0x193,0x1e3, -1 }
 
static const int rw_fail_ranges [] = { 0x1bb,0x1e3, -1 }
 
static const int rwdw_fail_ranges [] = { 0x1a7,0x1e3, -1 }
 
static const int dw_fail_ranges [] = { 0x1a7,0x1cf, -1 }
 
static const int tr_fail_ranges [] = { 0x1bb,0x1cf, -1 }
 
static const int pr_fail_ranges [] = { 0x180,0x181, 0x1bb,0x1cf, -1 }
 
static const int roex_fail_ranges [] = { 0x0,-1 }
 
static const struct lock_test lock_tests []
 

Macro Definition Documentation

◆ COBJMACROS

#define COBJMACROS

Definition at line 23 of file storage32.c.

◆ NONAMELESSSTRUCT

#define NONAMELESSSTRUCT

Definition at line 28 of file storage32.c.

◆ NONAMELESSUNION

#define NONAMELESSUNION

Definition at line 27 of file storage32.c.

◆ ok_ole_success

#define ok_ole_success (   hr,
  func 
)    ok(hr == S_OK, func " failed with error 0x%08x\n", hr)

Definition at line 40 of file storage32.c.

◆ test_file_access

#define test_file_access (   file,
  ares 
)    _test_file_access(file, ares, __LINE__)

Definition at line 2122 of file storage32.c.

Typedef Documentation

◆ TestLockBytes

Function Documentation

◆ _test_file_access()

static void _test_file_access ( LPCSTR  file,
const struct access_res ares,
DWORD  line 
)
static

Definition at line 2087 of file storage32.c.

2088 {
2089  int i, j, idx = 0;
2090 
2091  for (i = 0; i < ARRAY_SIZE(access_modes); i++)
2092  {
2093  for (j = 0; j < ARRAY_SIZE(share_modes); j++)
2094  {
2095  DWORD lasterr;
2096  HANDLE hfile;
2097 
2098  if (ares[idx].ignore)
2099  continue;
2100 
2101  SetLastError(0xdeadbeef);
2104  lasterr = GetLastError();
2105 
2106  ok((hfile != INVALID_HANDLE_VALUE) == ares[idx].gothandle,
2107  "(%d, handle, %d): Expected %d, got %d\n",
2108  line, idx, ares[idx].gothandle,
2109  (hfile != INVALID_HANDLE_VALUE));
2110 
2111  ok(lasterr == ares[idx].lasterr ||
2112  broken(lasterr == 0xdeadbeef) /* win9x */,
2113  "(%d, lasterr, %d): Expected %d, got %d\n",
2114  line, idx, ares[idx].lasterr, lasterr);
2115 
2116  CloseHandle(hfile);
2117  idx++;
2118  }
2119  }
2120 }
#define CloseHandle
Definition: compat.h:398
int ignore(int trapCode, ppc_trap_frame_t *trap)
Definition: mmuobject.c:296
static const DWORD share_modes[4]
Definition: storage32.c:2080
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned int idx
Definition: utils.c:41
smooth NULL
Definition: ftsmooth.c:416
Definition: parser.c:48
#define OPEN_EXISTING
Definition: compat.h:426
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:409
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
#define broken(x)
Definition: _sntprintf.h:21
#define ARRAY_SIZE(a)
Definition: main.h:24
#define ok(value,...)
Definition: atltest.h:57
static const DWORD access_modes[4]
Definition: storage32.c:2073
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:399
Definition: fci.c:126

◆ can_open()

static BOOL can_open ( LPCWSTR  filename,
DWORD  access,
DWORD  sharing 
)
static

Definition at line 3422 of file storage32.c.

3423 {
3424  HANDLE hfile;
3425 
3427 
3428  if (hfile == INVALID_HANDLE_VALUE)
3429  return FALSE;
3430 
3431  CloseHandle(hfile);
3432  return TRUE;
3433 }
static ULONG POBJECT_ATTRIBUTES PIO_STATUS_BLOCK ULONG sharing
Definition: pipe.c:68
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
const char * filename
Definition: ioapi.h:135
smooth NULL
Definition: ftsmooth.c:416
#define OPEN_EXISTING
Definition: compat.h:426
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
GLuint GLint GLboolean GLint GLenum access
Definition: glext.h:7866
#define CreateFileW
Definition: compat.h:400

Referenced by check_access(), and check_sharing().

◆ check_access()

static void check_access ( LPCWSTR  filename,
const struct lock_test current,
DWORD  access,
DWORD  sharing,
const char desc,
DWORD  open_mode,
BOOL any_failure 
)
static

Definition at line 3465 of file storage32.c.

3467 {
3469  {
3470  if (!current->todo || !(current->access & access))
3471  ok(!(current->access & access), "file with mode %x should not be openable without %s sharing\n", current->stg_mode, desc);
3472  else
3473  {
3474  todo_wine ok(!(current->access & access), "file with mode %x should not be openable without %s sharing\n", current->stg_mode, desc);
3475  *any_failure = TRUE;
3476  }
3477  }
3478  else
3479  {
3480  if (!current->todo || (current->access & access))
3481  ok(current->access & access, "file with mode %x should be openable without %s sharing\n", current->stg_mode, desc);
3482  else
3483  {
3484  todo_wine ok(current->access & access, "file with mode %x should be openable without %s sharing\n", current->stg_mode, desc);
3485  *any_failure = TRUE;
3486  }
3487  }
3488 }
static ULONG POBJECT_ATTRIBUTES PIO_STATUS_BLOCK ULONG sharing
Definition: pipe.c:68
#define TRUE
Definition: types.h:120
static BOOL can_open(LPCWSTR filename, DWORD access, DWORD sharing)
Definition: storage32.c:3422
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
const char * filename
Definition: ioapi.h:135
#define FILE_SHARE_READ
Definition: compat.h:125
const struct builtin_class_descr * desc
Definition: regcontrol.c:48
#define FILE_SHARE_DELETE
Definition: nt_native.h:682
#define todo_wine
Definition: test.h:154
GLuint GLint GLboolean GLint GLenum access
Definition: glext.h:7866
#define ok(value,...)
Definition: atltest.h:57
struct task_struct * current
Definition: linux.c:32

Referenced by test_locking().

◆ check_sharing()

static void check_sharing ( LPCWSTR  filename,
const struct lock_test current,
DWORD  access,
DWORD  sharing,
const char desc,
DWORD open_mode,
BOOL any_failure 
)
static

Definition at line 3435 of file storage32.c.

3437 {
3439  {
3440  *open_mode = access;
3441  if (!current->todo || (current->sharing & sharing))
3442  ok(current->sharing & sharing ||
3443  broken(!(current->sharing & sharing) && access == GENERIC_WRITE && (current->stg_mode & 0xf) != STGM_READ) /* win2k */,
3444  "file with mode %x should not be openable with %s permission\n", current->stg_mode, desc);
3445  else
3446  {
3447  todo_wine ok(current->sharing & sharing ||
3448  broken(!(current->sharing & sharing) && access == GENERIC_WRITE && (current->stg_mode & 0xf) != STGM_READ) /* win2k */,
3449  "file with mode %x should not be openable with %s permission\n", current->stg_mode, desc);
3450  *any_failure = TRUE;
3451  }
3452  }
3453  else
3454  {
3455  if (!current->todo || !(current->sharing & sharing))
3456  ok(!(current->sharing & sharing), "file with mode %x should be openable with %s permission\n", current->stg_mode, desc);
3457  else
3458  {
3459  todo_wine ok(!(current->sharing & sharing), "file with mode %x should be openable with %s permission\n", current->stg_mode, desc);
3460  *any_failure = TRUE;
3461  }
3462  }
3463 }
static ULONG POBJECT_ATTRIBUTES PIO_STATUS_BLOCK ULONG sharing
Definition: pipe.c:68
#define TRUE
Definition: types.h:120
static BOOL can_open(LPCWSTR filename, DWORD access, DWORD sharing)
Definition: storage32.c:3422
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
const char * filename
Definition: ioapi.h:135
#define FILE_SHARE_READ
Definition: compat.h:125
#define GENERIC_WRITE
Definition: nt_native.h:90
const struct builtin_class_descr * desc
Definition: regcontrol.c:48
#define STGM_READ
Definition: objbase.h:916
#define FILE_SHARE_DELETE
Definition: nt_native.h:682
#define todo_wine
Definition: test.h:154
#define broken(x)
Definition: _sntprintf.h:21
GLuint GLint GLboolean GLint GLenum access
Definition: glext.h:7866
#define ok(value,...)
Definition: atltest.h:57
struct task_struct * current
Definition: linux.c:32

Referenced by test_locking().

◆ create_test_file()

static HRESULT create_test_file ( IStorage dest)
static

Definition at line 2552 of file storage32.c.

2553 {
2554  IStorage *stgA = NULL, *stgB = NULL;
2555  IStream *strmA = NULL, *strmB = NULL, *strmC = NULL;
2556  const ULONG strmA_name_size = lstrlenW(strmA_name) * sizeof(WCHAR);
2557  const ULONG strmB_name_size = lstrlenW(strmB_name) * sizeof(WCHAR);
2558  const ULONG strmC_name_size = lstrlenW(strmC_name) * sizeof(WCHAR);
2559  ULONG bytes;
2560  HRESULT hr;
2561 
2562  hr = IStorage_CreateStorage(dest, stgA_name, STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &stgA);
2563  ok(hr == S_OK, "IStorage_CreateStorage failed: 0x%08x\n", hr);
2564  if(FAILED(hr))
2565  goto cleanup;
2566 
2567  hr = IStorage_CreateStream(stgA, strmA_name, STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &strmA);
2568  ok(hr == S_OK, "IStorage_CreateStream failed: 0x%08x\n", hr);
2569  if(FAILED(hr))
2570  goto cleanup;
2571 
2572  hr = IStream_Write(strmA, strmA_name, strmA_name_size, &bytes);
2573  ok(hr == S_OK && bytes == strmA_name_size, "IStream_Write failed: 0x%08x, %d of %d bytes written\n", hr, bytes, strmA_name_size);
2574 
2575  hr = IStorage_CreateStorage(dest, stgB_name, STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &stgB);
2576  ok(hr == S_OK, "IStorage_CreateStorage failed: 0x%08x\n", hr);
2577  if(FAILED(hr))
2578  goto cleanup;
2579 
2580  hr = IStorage_CreateStream(stgB, strmB_name, STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &strmB);
2581  ok(hr == S_OK, "IStorage_CreateStream failed: 0x%08x\n", hr);
2582  if(FAILED(hr))
2583  goto cleanup;
2584 
2585  hr = IStream_Write(strmB, strmB_name, strmB_name_size, &bytes);
2586  ok(hr == S_OK && bytes == strmB_name_size, "IStream_Write failed: 0x%08x, %d of %d bytes written\n", hr, bytes, strmB_name_size);
2587 
2588  hr = IStorage_CreateStream(dest, strmC_name, STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &strmC);
2589  ok(hr == S_OK, "IStorage_CreateStream failed: 0x%08x\n", hr);
2590  if(FAILED(hr))
2591  goto cleanup;
2592 
2593  hr = IStream_Write(strmC, strmC_name, strmC_name_size, &bytes);
2594  ok(hr == S_OK && bytes == strmC_name_size, "IStream_Write failed: 0x%08x, %d of %d bytes written\n", hr, bytes, strmC_name_size);
2595 
2596 cleanup:
2597  if(strmC)
2598  IStream_Release(strmC);
2599  if(strmB)
2600  IStream_Release(strmB);
2601  if(stgB)
2602  IStorage_Release(stgB);
2603  if(strmA)
2604  IStream_Release(strmA);
2605  if(stgA)
2606  IStorage_Release(stgA);
2607 
2608  return hr;
2609 }
HRESULT hr
Definition: shlfolder.c:183
#define STGM_SHARE_EXCLUSIVE
Definition: objbase.h:922
#define lstrlenW
Definition: compat.h:407
static unsigned char bytes[4]
Definition: adnsresfilter.c:74
smooth NULL
Definition: ftsmooth.c:416
static const WCHAR strmC_name[]
Definition: storage32.c:53
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:77
static const WCHAR stgB_name[]
Definition: storage32.c:50
#define STGM_READWRITE
Definition: objbase.h:918
#define S_OK
Definition: intsafe.h:59
#define ok(value,...)
Definition: atltest.h:57
static const WCHAR strmA_name[]
Definition: storage32.c:51
static const WCHAR strmB_name[]
Definition: storage32.c:52
static const WCHAR stgA_name[]
Definition: storage32.c:49
unsigned int ULONG
Definition: retypes.h:1
char * cleanup(char *str)
Definition: wpickclick.c:99
static char * dest
Definition: rtl.c:135

Referenced by test_copyto(), test_copyto_iidexclusions_storage(), test_copyto_iidexclusions_stream(), and test_copyto_snbexclusions().

◆ CreateTestLockBytes()

static void CreateTestLockBytes ( TestLockBytes **  This)
static

Definition at line 240 of file storage32.c.

241 {
243 
244  if (*This)
245  {
246  (*This)->ILockBytes_iface.lpVtbl = &TestLockBytes_Vtbl;
247  (*This)->ref = 1;
248  }
249 }
static const ILockBytesVtbl TestLockBytes_Vtbl
Definition: storage32.c:227
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define HEAP_ZERO_MEMORY
Definition: compat.h:123

Referenced by test_custom_lockbytes().

◆ DEFINE_GUID()

DEFINE_GUID ( test_stg_cls  ,
0x88888888  ,
0x0425  ,
0x0000  ,
,
,
,
,
,
,
,
 
)

◆ DeleteTestLockBytes()

static void DeleteTestLockBytes ( TestLockBytes This)
static

Definition at line 251 of file storage32.c.

252 {
253  ok(This->ILockBytes_iface.lpVtbl == &TestLockBytes_Vtbl, "test lock bytes %p deleted with incorrect vtable\n", This);
254  ok(This->ref == 1, "test lock bytes %p deleted with %i references instead of 1\n", This, This->ref);
255  HeapFree(GetProcessHeap(), 0, This->contents);
257 }
static const ILockBytesVtbl TestLockBytes_Vtbl
Definition: storage32.c:227
#define GetProcessHeap()
Definition: compat.h:395
#define ok(value,...)
Definition: atltest.h:57
#define HeapFree(x, y, z)
Definition: compat.h:394

Referenced by test_custom_lockbytes().

◆ impl_from_ILockBytes()

static TestLockBytes* impl_from_ILockBytes ( ILockBytes iface)
inlinestatic

Definition at line 75 of file storage32.c.

76 {
77  return CONTAINING_RECORD(iface, TestLockBytes, ILockBytes_iface);
78 }
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560

Referenced by TestLockBytes_AddRef(), TestLockBytes_LockRegion(), TestLockBytes_QueryInterface(), TestLockBytes_ReadAt(), TestLockBytes_Release(), TestLockBytes_SetSize(), TestLockBytes_Stat(), TestLockBytes_UnlockRegion(), and TestLockBytes_WriteAt().

◆ is_existing_file()

static BOOL is_existing_file ( LPCSTR  filename)
static

Definition at line 729 of file storage32.c.

730 {
731  HANDLE file;
732 
734  OPEN_EXISTING, 0, NULL);
736  return FALSE;
737  CloseHandle(file);
738  return TRUE;
739 }
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
const char * filename
Definition: ioapi.h:135
smooth NULL
Definition: ftsmooth.c:416
#define OPEN_EXISTING
Definition: compat.h:426
const char file[]
Definition: icontest.c:11
#define GENERIC_READ
Definition: compat.h:124
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:399
Definition: fci.c:126

Referenced by test_open_storage().

◆ is_zero_length()

static BOOL is_zero_length ( LPCSTR  filename)
static

Definition at line 715 of file storage32.c.

716 {
717  HANDLE file;
718  DWORD len;
719 
721  OPEN_EXISTING, 0, NULL);
723  return FALSE;
724  len = GetFileSize(file, NULL);
725  CloseHandle(file);
726  return len == 0;
727 }
#define CloseHandle
Definition: compat.h:398
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
const char * filename
Definition: ioapi.h:135
smooth NULL
Definition: ftsmooth.c:416
#define OPEN_EXISTING
Definition: compat.h:426
const char file[]
Definition: icontest.c:11
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh)
Definition: fileinfo.c:481
GLenum GLsizei len
Definition: glext.h:6722
#define GENERIC_READ
Definition: compat.h:124
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:399
Definition: fci.c:126

Referenced by test_open_storage().

◆ START_TEST()

START_TEST ( storage32  )

Definition at line 3926 of file storage32.c.

3927 {
3928  CHAR temp[MAX_PATH];
3929 
3931  if(!GetTempFileNameA(temp, "stg", 0, filenameA))
3932  {
3933  win_skip("Could not create temp file, %u\n", GetLastError());
3934  return;
3935  }
3938 
3946  test_streamenum();
3947  test_transact();
3949  test_revert();
3950  test_parent_free();
3953  test_access();
3955  test_readonly();
3956  test_simple();
3958  test_references();
3959  test_copyto();
3963  test_rename();
3969  test_convert();
3970  test_direct_swmr();
3971  test_locking();
3973  test_overwrite();
3975 }
static void test_readonly(void)
Definition: storage32.c:2239
static void test_nonroot_transacted(void)
Definition: storage32.c:1847
static void test_streamenum(void)
Definition: storage32.c:1229
static void test_convert(void)
Definition: storage32.c:3293
static void test_ReadClassStm(void)
Definition: storage32.c:1968
static void test_storage_refcount(void)
Definition: storage32.c:1019
#define CP_ACP
Definition: compat.h:99
char CHAR
Definition: xmlstorage.h:175
static void test_substorage_enum(void)
Definition: storage32.c:3096
static void test_hglobal_storage_creation(void)
Definition: storage32.c:3247
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
const char * filename
Definition: ioapi.h:135
static void test_locking(void)
Definition: storage32.c:3490
static void test_direct_swmr(void)
Definition: storage32.c:3322
static void test_substorage_share(void)
Definition: storage32.c:1540
static void test_storage_stream(void)
Definition: storage32.c:504
static void test_rename(void)
Definition: storage32.c:2950
static void test_copyto(void)
Definition: storage32.c:2611
static void test_transact(void)
Definition: storage32.c:1406
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
static void test_revert(void)
Definition: storage32.c:1632
static void test_copyto_recursive(void)
Definition: storage32.c:3195
static void test_copyto_iidexclusions_storage(void)
Definition: storage32.c:2798
static void test_copyto_snbexclusions(void)
Definition: storage32.c:2715
static void test_copyto_locking(void)
Definition: storage32.c:3143
static void test_hglobal_storage_stat(void)
Definition: storage32.c:259
static void test_access(void)
Definition: storage32.c:2124
static void test_create_storage_modes(void)
Definition: storage32.c:297
#define MAX_PATH
Definition: compat.h:26
static CHAR filenameA[MAX_PATH]
Definition: storage32.c:42
static void test_open_storage(void)
Definition: storage32.c:741
static void test_parent_free(void)
Definition: storage32.c:1784
static void test_references(void)
Definition: storage32.c:2504
static void test_simple(void)
Definition: storage32.c:2315
DWORD WINAPI GetTempPathA(IN DWORD nBufferLength, OUT LPSTR lpBuffer)
Definition: path.c:2053
static calc_node_t temp
Definition: rpn_ieee.c:38
static void test_stgcreatestorageex(void)
Definition: storage32.c:451
#define MultiByteToWideChar
Definition: compat.h:100
static void test_custom_lockbytes(void)
Definition: storage32.c:3878
static void test_fmtusertypestg(void)
Definition: storage32.c:2431
static void test_toplevel_stat(void)
Definition: storage32.c:3020
static void test_overwrite(void)
Definition: storage32.c:3765
static void test_storage_suminfo(void)
Definition: storage32.c:911
static void test_copyto_iidexclusions_stream(void)
Definition: storage32.c:2877
#define win_skip
Definition: test.h:141
UINT WINAPI GetTempFileNameA(IN LPCSTR lpPathName, IN LPCSTR lpPrefixString, IN UINT uUnique, OUT LPSTR lpTempFileName)
Definition: filename.c:26
static void test_transacted_shared(void)
Definition: storage32.c:3646
static void test_writeclassstg(void)
Definition: storage32.c:1179

◆ strcmp_ww()

static int strcmp_ww ( LPCWSTR  strw1,
LPCWSTR  strw2 
)
static

Definition at line 56 of file storage32.c.

57 {
58  CHAR stra1[512], stra2[512];
59  WideCharToMultiByte(CP_ACP, 0, strw1, -1, stra1, sizeof(stra1), NULL, NULL);
60  WideCharToMultiByte(CP_ACP, 0, strw2, -1, stra2, sizeof(stra2), NULL, NULL);
61  return lstrcmpA(stra1, stra2);
62 }
#define WideCharToMultiByte
Definition: compat.h:101
#define CP_ACP
Definition: compat.h:99
char CHAR
Definition: xmlstorage.h:175
int WINAPI lstrcmpA(LPCSTR lpString1, LPCSTR lpString2)
Definition: lstring.c:18
smooth NULL
Definition: ftsmooth.c:416

Referenced by test_copyto(), test_copyto_iidexclusions_storage(), test_copyto_snbexclusions(), test_fmtusertypestg(), and test_toplevel_stat().

◆ test_access()

static void test_access ( void  )
static

Definition at line 2124 of file storage32.c.

2125 {
2126  static const WCHAR fileW[] = {'w','i','n','e','t','e','s','t',0};
2127  static const char fileA[] = "winetest";
2128  IStorage *stg;
2129  HRESULT hr;
2130 
2131  /* STGM_TRANSACTED */
2134  ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
2135 
2136  test_file_access(fileA, create);
2137 
2138  hr = IStorage_Commit(stg, STGC_DEFAULT);
2139  ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
2140 
2142 
2143  IStorage_Release(stg);
2144 
2146 
2147  DeleteFileA(fileA);
2148 
2149  /* STGM_DIRECT */
2151  STGM_SHARE_EXCLUSIVE | STGM_DIRECT, 0, &stg);
2152  ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
2153 
2154  test_file_access(fileA, create);
2155 
2156  hr = IStorage_Commit(stg, STGC_DEFAULT);
2157  ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
2158 
2160 
2161  IStorage_Release(stg);
2162 
2164 
2165  DeleteFileA(fileA);
2166 
2167  /* STGM_SHARE_DENY_NONE */
2170  ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
2171 
2172  test_file_access(fileA, create);
2173 
2174  hr = IStorage_Commit(stg, STGC_DEFAULT);
2175  ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
2176 
2178 
2179  IStorage_Release(stg);
2180 
2182 
2183  DeleteFileA(fileA);
2184 
2185  /* STGM_SHARE_DENY_READ */
2188  ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
2189 
2190  test_file_access(fileA, create);
2191 
2192  hr = IStorage_Commit(stg, STGC_DEFAULT);
2193  ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
2194 
2196 
2197  IStorage_Release(stg);
2198 
2200 
2201  DeleteFileA(fileA);
2202 
2203  /* STGM_SHARE_DENY_WRITE */
2206  ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
2207 
2208  test_file_access(fileA, create);
2209 
2210  hr = IStorage_Commit(stg, STGC_DEFAULT);
2211  ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
2212 
2214 
2215  IStorage_Release(stg);
2216 
2218 
2219  DeleteFileA(fileA);
2220 
2221  /* STGM_DIRECT_SWMR | STGM_READ | STGM_SHARE_DENY_NONE - reader mode for direct SWMR mode */
2223  ok(hr == S_OK, "got %08x\n", hr);
2224  IStorage_Release(stg);
2225 
2227  ok(hr == S_OK || broken(hr == STG_E_INVALIDFLAG), "got %08x\n", hr);
2228  if(hr != S_OK)
2229  return;
2230 
2231  test_file_access(fileA, create);
2232 
2233  IStorage_Release(stg);
2235 
2236  DeleteFileA(fileA);
2237 }
#define STGM_SHARE_DENY_NONE
Definition: objbase.h:919
#define test_file_access(file, ares)
Definition: storage32.c:2122
HRESULT hr
Definition: shlfolder.c:183
#define STGM_SHARE_EXCLUSIVE
Definition: objbase.h:922
#define STGM_CREATE
Definition: objbase.h:925
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
#define STGM_READ
Definition: objbase.h:916
#define STGM_DIRECT_SWMR
Definition: objbase.h:930
__wchar_t WCHAR
Definition: xmlstorage.h:180
static const struct access_res create[16]
Definition: storage32.c:2013
LONG HRESULT
Definition: typedefs.h:77
HRESULT WINAPI StgOpenStorage(const OLECHAR *pwcsName, IStorage *pstgPriority, DWORD grfMode, SNB snbExclude, DWORD reserved, IStorage **ppstgOpen)
Definition: storage32.c:8756
#define STGM_DIRECT
Definition: objbase.h:913
#define STG_E_INVALIDFLAG
Definition: winerror.h:2587
HRESULT WINAPI StgCreateDocfile(LPCOLESTR pwcsName, DWORD grfMode, DWORD reserved, IStorage **ppstgOpen)
Definition: storage32.c:8637
#define STGM_READWRITE
Definition: objbase.h:918
#define broken(x)
Definition: _sntprintf.h:21
static const struct access_res create_commit[16]
Definition: storage32.c:2033
#define S_OK
Definition: intsafe.h:59
#define ok(value,...)
Definition: atltest.h:57
static const struct access_res create_close[16]
Definition: storage32.c:2053
#define STGM_TRANSACTED
Definition: objbase.h:914
#define STGM_SHARE_DENY_WRITE
Definition: objbase.h:921
static const WCHAR fileW[]
Definition: url.c:111
#define STGM_SHARE_DENY_READ
Definition: objbase.h:920

Referenced by START_TEST().

◆ test_convert()

static void test_convert ( void  )
static

Definition at line 3293 of file storage32.c.

3294 {
3295  static const WCHAR filename[] = {'s','t','o','r','a','g','e','.','s','t','g',0};
3296  IStorage *stg;
3297  HRESULT hr;
3298 
3299  hr = GetConvertStg(NULL);
3300  ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
3301 
3303  ok(hr == S_OK, "StgCreateDocfile failed\n");
3304  hr = GetConvertStg(stg);
3305  ok(hr == STG_E_FILENOTFOUND, "got 0x%08x\n", hr);
3306  hr = SetConvertStg(stg, TRUE);
3307  ok(hr == S_OK, "got 0x%08x\n", hr);
3308  hr = SetConvertStg(stg, TRUE);
3309  ok(hr == S_OK, "got 0x%08x\n", hr);
3310  hr = GetConvertStg(stg);
3311  ok(hr == S_OK, "got 0x%08x\n", hr);
3312  hr = SetConvertStg(stg, FALSE);
3313  ok(hr == S_OK, "got 0x%08x\n", hr);
3314  hr = GetConvertStg(stg);
3315  ok(hr == S_FALSE, "got 0x%08x\n", hr);
3316 
3317  IStorage_Release(stg);
3318 
3320 }
#define TRUE
Definition: types.h:120
HRESULT WINAPI SetConvertStg(IStorage *storage, BOOL convert)
Definition: storage32.c:10649
HRESULT hr
Definition: shlfolder.c:183
#define STGM_SHARE_EXCLUSIVE
Definition: objbase.h:922
#define STGM_CREATE
Definition: objbase.h:925
const char * filename
Definition: ioapi.h:135
HRESULT WINAPI GetConvertStg(IStorage *stg)
Definition: storage32.c:10618
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
#define S_FALSE
Definition: winerror.h:2357
#define E_INVALIDARG
Definition: ddrawi.h:101
smooth NULL
Definition: ftsmooth.c:416
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:77
#define STG_E_FILENOTFOUND
Definition: winerror.h:2565
HRESULT WINAPI StgCreateDocfile(LPCOLESTR pwcsName, DWORD grfMode, DWORD reserved, IStorage **ppstgOpen)
Definition: storage32.c:8637
#define STGM_READWRITE
Definition: objbase.h:918
#define S_OK
Definition: intsafe.h:59
#define ok(value,...)
Definition: atltest.h:57

Referenced by START_TEST().

◆ test_copyto()

static void test_copyto ( void  )
static

Definition at line 2611 of file storage32.c.

2612 {
2613  IStorage *file1 = NULL, *file2 = NULL, *stg_tmp;
2614  IStream *strm_tmp;
2615  WCHAR buf[64];
2616  HRESULT hr;
2617 
2618  /* create & populate file1 */
2620  ok(hr == S_OK, "StgCreateDocfile failed: 0x%08x\n", hr);
2621  if(FAILED(hr))
2622  goto cleanup;
2623 
2624  hr = create_test_file(file1);
2625  if(FAILED(hr))
2626  goto cleanup;
2627 
2628  /* create file2 */
2630  ok(hr == S_OK, "StgCreateDocfile failed: 0x%08x\n", hr);
2631  if(FAILED(hr))
2632  goto cleanup;
2633 
2634  /* copy file1 into file2 */
2635  hr = IStorage_CopyTo(file1, 0, NULL, NULL, NULL);
2636  ok(hr == STG_E_INVALIDPOINTER, "CopyTo should give STG_E_INVALIDPONITER, gave: 0x%08x\n", hr);
2637 
2638  hr = IStorage_CopyTo(file1, 0, NULL, NULL, file2);
2639  ok(hr == S_OK, "CopyTo failed: 0x%08x\n", hr);
2640  if(FAILED(hr))
2641  goto cleanup;
2642 
2643  /* verify that all of file1 was copied */
2644  hr = IStorage_OpenStorage(file2, stgA_name, NULL,
2645  STGM_READWRITE | STGM_SHARE_EXCLUSIVE, NULL, 0, &stg_tmp);
2646  ok(hr == S_OK, "OpenStorage failed: 0x%08x\n", hr);
2647 
2648  if(SUCCEEDED(hr)){
2649  hr = IStorage_OpenStream(stg_tmp, strmA_name, NULL,
2650  STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, &strm_tmp);
2651  ok(hr == S_OK, "OpenStream failed: 0x%08x\n", hr);
2652 
2653  if(SUCCEEDED(hr)){
2654  memset(buf, 0, sizeof(buf));
2655  hr = IStream_Read(strm_tmp, buf, sizeof(buf), NULL);
2656  ok(hr == S_OK, "Read failed: 0x%08x\n", hr);
2657  if(SUCCEEDED(hr))
2658  ok(strcmp_ww(buf, strmA_name) == 0,
2659  "Expected %s to be read, got %s\n", wine_dbgstr_w(strmA_name), wine_dbgstr_w(buf));
2660 
2661  IStream_Release(strm_tmp);
2662  }
2663 
2664  IStorage_Release(stg_tmp);
2665  }
2666 
2667  hr = IStorage_OpenStorage(file2, stgB_name, NULL,
2668  STGM_READWRITE | STGM_SHARE_EXCLUSIVE, NULL, 0, &stg_tmp);
2669  ok(hr == S_OK, "OpenStorage failed: 0x%08x\n", hr);
2670 
2671  if(SUCCEEDED(hr)){
2672  hr = IStorage_OpenStream(stg_tmp, strmB_name, NULL,
2673  STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, &strm_tmp);
2674  ok(hr == S_OK, "OpenStream failed: 0x%08x\n", hr);
2675 
2676  if(SUCCEEDED(hr)){
2677  memset(buf, 0, sizeof(buf));
2678  hr = IStream_Read(strm_tmp, buf, sizeof(buf), NULL);
2679  ok(hr == S_OK, "Read failed: 0x%08x\n", hr);
2680  if(SUCCEEDED(hr))
2681  ok(strcmp_ww(buf, strmB_name) == 0,
2682  "Expected %s to be read, got %s\n", wine_dbgstr_w(strmB_name), wine_dbgstr_w(buf));
2683 
2684  IStream_Release(strm_tmp);
2685  }
2686 
2687  IStorage_Release(stg_tmp);
2688  }
2689 
2690  hr = IStorage_OpenStream(file2, strmC_name, NULL,
2691  STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, &strm_tmp);
2692  ok(hr == S_OK, "OpenStream failed: 0x%08x\n", hr);
2693 
2694  if(SUCCEEDED(hr)){
2695  memset(buf, 0, sizeof(buf));
2696  hr = IStream_Read(strm_tmp, buf, sizeof(buf), NULL);
2697  ok(hr == S_OK, "Read failed: 0x%08x\n", hr);
2698  if(SUCCEEDED(hr))
2699  ok(strcmp_ww(buf, strmC_name) == 0,
2700  "Expected %s to be read, got %s\n", wine_dbgstr_w(strmC_name), wine_dbgstr_w(buf));
2701 
2702  IStream_Release(strm_tmp);
2703  }
2704 
2705 cleanup:
2706  if(file1)
2707  IStorage_Release(file1);
2708  if(file2)
2709  IStorage_Release(file2);
2710 
2713 }
HRESULT hr
Definition: shlfolder.c:183
#define STG_E_INVALIDPOINTER
Definition: winerror.h:2571
#define STGM_SHARE_EXCLUSIVE
Definition: objbase.h:922
static const WCHAR file2_name[]
Definition: storage32.c:48
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
char * wine_dbgstr_w(const wchar_t *wstr)
Definition: atltest.h:87
static int strcmp_ww(LPCWSTR strw1, LPCWSTR strw2)
Definition: storage32.c:56
#define STGM_CREATE
Definition: objbase.h:925
static const WCHAR file1_name[]
Definition: storage32.c:46
static const char file2_nameA[]
Definition: storage32.c:47
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
static const WCHAR strmC_name[]
Definition: storage32.c:53
static const char file1_nameA[]
Definition: storage32.c:45
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:77
static const WCHAR stgB_name[]
Definition: storage32.c:50
HRESULT WINAPI StgCreateDocfile(LPCOLESTR pwcsName, DWORD grfMode, DWORD reserved, IStorage **ppstgOpen)
Definition: storage32.c:8637
#define STGM_READWRITE
Definition: objbase.h:918
#define S_OK
Definition: intsafe.h:59
#define ok(value,...)
Definition: atltest.h:57
static const WCHAR strmA_name[]
Definition: storage32.c:51
static const WCHAR strmB_name[]
Definition: storage32.c:52
static const WCHAR stgA_name[]
Definition: storage32.c:49
char * cleanup(char *str)
Definition: wpickclick.c:99
static HRESULT create_test_file(IStorage *dest)
Definition: storage32.c:2552
#define memset(x, y, z)
Definition: compat.h:39
#define SUCCEEDED(hr)
Definition: intsafe.h:57

Referenced by START_TEST().

◆ test_copyto_iidexclusions_storage()

static void test_copyto_iidexclusions_storage ( void  )
static

Definition at line 2798 of file storage32.c.

2799 {
2800  IStorage *file1 = NULL, *file2 = NULL, *stg_tmp;
2801  IStream *strm_tmp;
2802  WCHAR buf[64];
2803  HRESULT hr;
2804 
2805  /* create & populate file1 */
2807  ok(hr == S_OK, "StgCreateDocfile failed: 0x%08x\n", hr);
2808  if(FAILED(hr))
2809  goto cleanup;
2810 
2811  hr = create_test_file(file1);
2812  if(FAILED(hr))
2813  goto cleanup;
2814 
2815  /* create file2 */
2817  ok(hr == S_OK, "StgCreateDocfile failed: 0x%08x\n", hr);
2818  if(FAILED(hr))
2819  goto cleanup;
2820 
2821  /* copy file1 to file2 with iid exclusions */
2822  hr = IStorage_CopyTo(file1, 1, &IID_IStorage, NULL, file2);
2823  ok(hr == S_OK, "CopyTo failed: 0x%08x\n", hr);
2824  if(FAILED(hr))
2825  goto cleanup;
2826 
2827  /* verify that file1 copied over, respecting exclusions */
2828  hr = IStorage_OpenStorage(file2, stgA_name, NULL,
2829  STGM_READWRITE | STGM_SHARE_EXCLUSIVE, NULL, 0, &stg_tmp);
2830  ok(hr == STG_E_FILENOTFOUND, "OpenStorage should give STG_E_FILENOTFOUND, gave: 0x%08x\n", hr);
2831  if(SUCCEEDED(hr))
2832  IStorage_Release(stg_tmp);
2833 
2834  hr = IStorage_OpenStream(file2, strmA_name, NULL,
2835  STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, &strm_tmp);
2836  ok(hr == STG_E_FILENOTFOUND, "OpenStream should give STG_E_FILENOTFOUND, gave: 0x%08x\n", hr);
2837  if(SUCCEEDED(hr))
2838  IStream_Release(strm_tmp);
2839 
2840  hr = IStorage_OpenStorage(file2, stgB_name, NULL,
2841  STGM_READWRITE | STGM_SHARE_EXCLUSIVE, NULL, 0, &stg_tmp);
2842  ok(hr == STG_E_FILENOTFOUND, "OpenStorage should give STG_E_FILENOTFOUND, gave: 0x%08x\n", hr);
2843  if(SUCCEEDED(hr))
2844  IStorage_Release(stg_tmp);
2845 
2846  hr = IStorage_OpenStream(file2, strmB_name, NULL,
2847  STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, &strm_tmp);
2848  ok(hr == STG_E_FILENOTFOUND, "OpenStream should give STG_E_FILENOTFOUND, gave: 0x%08x\n", hr);
2849  if(SUCCEEDED(hr))
2850  IStream_Release(strm_tmp);
2851 
2852  hr = IStorage_OpenStream(file2, strmC_name, NULL,
2853  STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, &strm_tmp);
2854  ok(hr == S_OK, "OpenStream failed: 0x%08x\n", hr);
2855 
2856  if(SUCCEEDED(hr)){
2857  memset(buf, 0, sizeof(buf));
2858  hr = IStream_Read(strm_tmp, buf, sizeof(buf), NULL);
2859  ok(hr == S_OK, "Read failed: 0x%08x\n", hr);
2860  if(SUCCEEDED(hr))
2861  ok(strcmp_ww(buf, strmC_name) == 0,
2862  "Expected %s to be read, got %s\n", wine_dbgstr_w(strmC_name), wine_dbgstr_w(buf));
2863 
2864  IStream_Release(strm_tmp);
2865  }
2866 
2867 cleanup:
2868  if(file1)
2869  IStorage_Release(file1);
2870  if(file2)
2871  IStorage_Release(file2);
2872 
2875 }
HRESULT hr
Definition: shlfolder.c:183
#define STGM_SHARE_EXCLUSIVE
Definition: objbase.h:922
static const WCHAR file2_name[]
Definition: storage32.c:48
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
char * wine_dbgstr_w(const wchar_t *wstr)
Definition: atltest.h:87
static int strcmp_ww(LPCWSTR strw1, LPCWSTR strw2)
Definition: storage32.c:56
#define STGM_CREATE
Definition: objbase.h:925
static const WCHAR file1_name[]
Definition: storage32.c:46
static const char file2_nameA[]
Definition: storage32.c:47
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
static const WCHAR strmC_name[]
Definition: storage32.c:53
static const char file1_nameA[]
Definition: storage32.c:45
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:77
static const WCHAR stgB_name[]
Definition: storage32.c:50
#define STG_E_FILENOTFOUND
Definition: winerror.h:2565
HRESULT WINAPI StgCreateDocfile(LPCOLESTR pwcsName, DWORD grfMode, DWORD reserved, IStorage **ppstgOpen)
Definition: storage32.c:8637
#define STGM_READWRITE
Definition: objbase.h:918
#define S_OK
Definition: intsafe.h:59
#define ok(value,...)
Definition: atltest.h:57
static const WCHAR strmA_name[]
Definition: storage32.c:51
static const WCHAR strmB_name[]
Definition: storage32.c:52
static const WCHAR stgA_name[]
Definition: storage32.c:49
char * cleanup(char *str)
Definition: wpickclick.c:99
static HRESULT create_test_file(IStorage *dest)
Definition: storage32.c:2552
#define memset(x, y, z)
Definition: compat.h:39
#define SUCCEEDED(hr)
Definition: intsafe.h:57

Referenced by START_TEST().

◆ test_copyto_iidexclusions_stream()

static void test_copyto_iidexclusions_stream ( void  )
static

Definition at line 2877 of file storage32.c.

2878 {
2879  IStorage *file1 = NULL, *file2 = NULL, *stg_tmp;
2880  IStream *strm_tmp;
2881  HRESULT hr;
2882 
2883  /* create & populate file1 */
2885  ok(hr == S_OK, "StgCreateDocfile failed: 0x%08x\n", hr);
2886  if(FAILED(hr))
2887  goto cleanup;
2888 
2889  hr = create_test_file(file1);
2890  if(FAILED(hr))
2891  goto cleanup;
2892 
2893  /* create file2 */
2895  ok(hr == S_OK, "StgCreateDocfile failed: 0x%08x\n", hr);
2896  if(FAILED(hr))
2897  goto cleanup;
2898 
2899  /* copy file1 to file2 with iid exclusions */
2900  hr = IStorage_CopyTo(file1, 1, &IID_IStream, NULL, file2);
2901  ok(hr == S_OK, "CopyTo failed: 0x%08x\n", hr);
2902  if(FAILED(hr))
2903  goto cleanup;
2904 
2905  /* verify that file1 copied over, respecting exclusions */
2906  hr = IStorage_OpenStorage(file2, stgA_name, NULL,
2907  STGM_READWRITE | STGM_SHARE_EXCLUSIVE, NULL, 0, &stg_tmp);
2908  ok(hr == S_OK, "OpenStorage failed: 0x%08x\n", hr);
2909 
2910  if(SUCCEEDED(hr)){
2911  hr = IStorage_OpenStream(stg_tmp, strmA_name, NULL,
2912  STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, &strm_tmp);
2913  ok(hr == STG_E_FILENOTFOUND, "OpenStream should give STG_E_FILENOTFOUND, gave: 0x%08x\n", hr);
2914  if(SUCCEEDED(hr))
2915  IStream_Release(strm_tmp);
2916 
2917  IStorage_Release(stg_tmp);
2918  }
2919 
2920  hr = IStorage_OpenStorage(file2, stgB_name, NULL,
2921  STGM_READWRITE | STGM_SHARE_EXCLUSIVE, NULL, 0, &stg_tmp);
2922  ok(hr == S_OK, "OpenStorage failed: 0x%08x\n", hr);
2923 
2924  if(SUCCEEDED(hr)){
2925  hr = IStorage_OpenStream(stg_tmp, strmB_name, NULL,
2926  STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, &strm_tmp);
2927  ok(hr == STG_E_FILENOTFOUND, "OpenStream should give STG_E_FILENOTFOUND, gave: 0x%08x\n", hr);
2928  if(SUCCEEDED(hr))
2929  IStream_Release(strm_tmp);
2930 
2931  IStorage_Release(stg_tmp);
2932  }
2933 
2934  hr = IStorage_OpenStream(file2, strmC_name, NULL,
2935  STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, &strm_tmp);
2936  ok(hr == STG_E_FILENOTFOUND, "OpenStream should give STG_E_FILENOTFOUND, gave: 0x%08x\n", hr);
2937  if(SUCCEEDED(hr))
2938  IStream_Release(strm_tmp);
2939 
2940 cleanup:
2941  if(file1)
2942  IStorage_Release(file1);
2943  if(file2)
2944  IStorage_Release(file2);
2945 
2948 }
HRESULT hr
Definition: shlfolder.c:183
#define STGM_SHARE_EXCLUSIVE
Definition: objbase.h:922
static const WCHAR file2_name[]
Definition: storage32.c:48
#define STGM_CREATE
Definition: objbase.h:925
static const WCHAR file1_name[]
Definition: storage32.c:46
static const char file2_nameA[]
Definition: storage32.c:47
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
static const WCHAR strmC_name[]
Definition: storage32.c:53
static const char file1_nameA[]
Definition: storage32.c:45
LONG HRESULT
Definition: typedefs.h:77
static const WCHAR stgB_name[]
Definition: storage32.c:50
#define STG_E_FILENOTFOUND
Definition: winerror.h:2565
HRESULT WINAPI StgCreateDocfile(LPCOLESTR pwcsName, DWORD grfMode, DWORD reserved, IStorage **ppstgOpen)
Definition: storage32.c:8637
#define STGM_READWRITE
Definition: objbase.h:918
#define S_OK
Definition: intsafe.h:59
#define ok(value,...)
Definition: atltest.h:57
static const WCHAR strmA_name[]
Definition: storage32.c:51
static const WCHAR strmB_name[]
Definition: storage32.c:52
static const WCHAR stgA_name[]
Definition: storage32.c:49
char * cleanup(char *str)
Definition: wpickclick.c:99
static HRESULT create_test_file(IStorage *dest)
Definition: storage32.c:2552
#define SUCCEEDED(hr)
Definition: intsafe.h:57

Referenced by START_TEST().

◆ test_copyto_locking()

static void test_copyto_locking ( void  )
static

Definition at line 3143 of file storage32.c.

3144 {
3145  IStorage *stg, *stg2, *stg3, *stg4;
3146  IStream *stm;
3147  HRESULT r;
3148  static const WCHAR stgname[] = { 'S','T','G','1',0 };
3149  static const WCHAR stgname2[] = { 'S','T','G','2',0 };
3150  static const WCHAR stmname[] = { 'C','O','N','T','E','N','T','S',0 };
3151  BOOL ret;
3152 
3154 
3155  /* create the file */
3157  STGM_READWRITE, 0, &stg);
3158  ok(r==S_OK, "StgCreateDocfile failed\n");
3159 
3160  /* create a substorage */
3161  r = IStorage_CreateStorage(stg, stgname, STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &stg2);
3162  ok(r==S_OK, "IStorage->CreateStorage failed, hr=%08x\n", r);
3163 
3164  /* create another substorage */
3165  r = IStorage_CreateStorage(stg, stgname2, STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &stg3);
3166  ok(r==S_OK, "IStorage->CreateStorage failed, hr=%08x\n", r);
3167 
3168  /* add a stream, and leave it open */
3169  r = IStorage_CreateStream(stg2, stmname, STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &stm);
3170  ok(r==S_OK, "IStorage->CreateStream failed, hr=%08x\n", r);
3171 
3172  /* Try to copy the storage while the stream is open */
3173  r = IStorage_CopyTo(stg2, 0, NULL, NULL, stg3);
3174  ok(r==S_OK, "IStorage->CopyTo failed, hr=%08x\n", r);
3175 
3176  IStream_Release(stm);
3177 
3178  /* create a substorage */
3179  r = IStorage_CreateStorage(stg2, stgname, STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &stg4);
3180  ok(r==S_OK, "IStorage->CreateStorage failed, hr=%08x\n", r);
3181 
3182  /* Try to copy the storage while the substorage is open */
3183  r = IStorage_CopyTo(stg2, 0, NULL, NULL, stg3);
3184  ok(r==S_OK, "IStorage->CopyTo failed, hr=%08x\n", r);
3185 
3186  IStorage_Release(stg4);
3187  IStorage_Release(stg3);
3188  IStorage_Release(stg2);
3189  IStorage_Release(stg);
3190 
3192  ok(ret, "deleted file\n");
3193 }
#define STGM_SHARE_EXCLUSIVE
Definition: objbase.h:922
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
#define STGM_CREATE
Definition: objbase.h:925
const char * filename
Definition: ioapi.h:135
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:77
static CHAR filenameA[MAX_PATH]
Definition: storage32.c:42
int ret
HRESULT WINAPI StgCreateDocfile(LPCOLESTR pwcsName, DWORD grfMode, DWORD reserved, IStorage **ppstgOpen)
Definition: storage32.c:8637
#define STGM_READWRITE
Definition: objbase.h:918
#define S_OK
Definition: intsafe.h:59
#define ok(value,...)
Definition: atltest.h:57

Referenced by START_TEST().

◆ test_copyto_recursive()

static void test_copyto_recursive ( void  )
static

Definition at line 3195 of file storage32.c.

3196 {
3197  IStorage *stg, *stg2, *stg3, *stg4;
3198  HRESULT r;
3199  static const WCHAR stgname[] = { 'S','T','G','1',0 };
3200  static const WCHAR stgname2[] = { 'S','T','G','2',0 };
3201  BOOL ret;
3202 
3204 
3205  /* create the file */
3207  STGM_READWRITE, 0, &stg);
3208  ok(r==S_OK, "StgCreateDocfile failed\n");
3209 
3210  /* create a substorage */
3211  r = IStorage_CreateStorage(stg, stgname, STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &stg2);
3212  ok(r==S_OK, "IStorage->CreateStorage failed, hr=%08x\n", r);
3213 
3214  /* copy the parent to the child */
3215  r = IStorage_CopyTo(stg, 0, NULL, NULL, stg2);
3216  ok(r==STG_E_ACCESSDENIED, "IStorage->CopyTo failed, hr=%08x\n", r);
3217 
3218  /* create a transacted substorage */
3219  r = IStorage_CreateStorage(stg, stgname2, STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_TRANSACTED, 0, 0, &stg3);
3220  ok(r==S_OK, "IStorage->CreateStorage failed, hr=%08x\n", r);
3221 
3222  /* copy the parent to the transacted child */
3223  r = IStorage_CopyTo(stg, 0, NULL, NULL, stg2);
3224  ok(r==STG_E_ACCESSDENIED, "IStorage->CopyTo failed, hr=%08x\n", r);
3225 
3226  /* create a transacted subsubstorage */
3227  r = IStorage_CreateStorage(stg3, stgname2, STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_TRANSACTED, 0, 0, &stg4);
3228  ok(r==S_OK, "IStorage->CreateStorage failed, hr=%08x\n", r);
3229 
3230  /* copy the parent to the transacted child of the transacted child */
3231  r = IStorage_CopyTo(stg, 0, NULL, NULL, stg4);
3232  ok(r==STG_E_ACCESSDENIED, "IStorage->CopyTo failed, hr=%08x\n", r);
3233 
3234  /* copy the parent but exclude storage objects */
3235  r = IStorage_CopyTo(stg, 1, &IID_IStorage, NULL, stg4);
3236  ok(r==S_OK, "IStorage->CopyTo failed, hr=%08x\n", r);
3237 
3238  IStorage_Release(stg4);
3239  IStorage_Release(stg3);
3240  IStorage_Release(stg2);
3241  IStorage_Release(stg);
3242 
3244  ok(ret, "deleted file\n");
3245 }
#define STGM_SHARE_EXCLUSIVE
Definition: objbase.h:922
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
#define STGM_CREATE
Definition: objbase.h:925
const char * filename
Definition: ioapi.h:135
#define STG_E_ACCESSDENIED
Definition: winerror.h:2568
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:77
static CHAR filenameA[MAX_PATH]
Definition: storage32.c:42
int ret
HRESULT WINAPI StgCreateDocfile(LPCOLESTR pwcsName, DWORD grfMode, DWORD reserved, IStorage **ppstgOpen)
Definition: storage32.c:8637
#define STGM_READWRITE
Definition: objbase.h:918
#define S_OK
Definition: intsafe.h:59
#define ok(value,...)
Definition: atltest.h:57
#define STGM_TRANSACTED
Definition: objbase.h:914

Referenced by START_TEST().

◆ test_copyto_snbexclusions()

static void test_copyto_snbexclusions ( void  )
static

Definition at line 2715 of file storage32.c.

2716 {
2717  static const WCHAR *snb_exclude[] = {stgA_name, strmB_name, strmC_name, 0};
2718 
2719  IStorage *file1 = NULL, *file2 = NULL, *stg_tmp;
2720  IStream *strm_tmp;
2721  WCHAR buf[64];
2722  HRESULT hr;
2723 
2724  /* create & populate file1 */
2726  ok(hr == S_OK, "StgCreateDocfile failed: 0x%08x\n", hr);
2727  if(FAILED(hr))
2728  goto cleanup;
2729 
2730  hr = create_test_file(file1);
2731  if(FAILED(hr))
2732  goto cleanup;
2733 
2734  /* create file2 */
2736  ok(hr == S_OK, "StgCreateDocfile failed: 0x%08x\n", hr);
2737  if(FAILED(hr))
2738  goto cleanup;
2739 
2740  /* copy file1 to file2 with name exclusions */
2741  hr = IStorage_CopyTo(file1, 0, NULL, (SNB)snb_exclude, file2);
2742  ok(hr == S_OK, "CopyTo failed: 0x%08x\n", hr);
2743  if(FAILED(hr))
2744  goto cleanup;
2745 
2746  /* verify that file1 copied over, respecting exclusions */
2747  hr = IStorage_OpenStorage(file2, stgA_name, NULL,
2748  STGM_READWRITE | STGM_SHARE_EXCLUSIVE, NULL, 0, &stg_tmp);
2749  ok(hr == STG_E_FILENOTFOUND, "OpenStorage should give STG_E_FILENOTFOUND, gave: 0x%08x\n", hr);
2750  if(SUCCEEDED(hr))
2751  IStorage_Release(stg_tmp);
2752 
2753  hr = IStorage_OpenStream(file2, strmA_name, NULL,
2754  STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, &strm_tmp);
2755  ok(hr == STG_E_FILENOTFOUND, "OpenStream should give STG_E_FILENOTFOUND, gave: 0x%08x\n", hr);
2756  if(SUCCEEDED(hr))
2757  IStream_Release(strm_tmp);
2758 
2759  hr = IStorage_OpenStorage(file2, stgB_name, NULL,
2760  STGM_READWRITE | STGM_SHARE_EXCLUSIVE, NULL, 0, &stg_tmp);
2761  ok(hr == S_OK, "OpenStorage failed: 0x%08x\n", hr);
2762 
2763  if(SUCCEEDED(hr)){
2764  hr = IStorage_OpenStream(stg_tmp, strmB_name, NULL,
2765  STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, &strm_tmp);
2766  ok(hr == S_OK, "OpenStream failed: 0x%08x\n", hr);
2767 
2768  if(SUCCEEDED(hr)){
2769  memset(buf, 0, sizeof(buf));
2770  hr = IStream_Read(strm_tmp, buf, sizeof(buf), NULL);
2771  ok(hr == S_OK, "Read failed: 0x%08x\n", hr);
2772  if(SUCCEEDED(hr))
2773  ok(strcmp_ww(buf, strmB_name) == 0,
2774  "Expected %s to be read, got %s\n", wine_dbgstr_w(strmB_name), wine_dbgstr_w(buf));
2775 
2776  IStream_Release(strm_tmp);
2777  }
2778 
2779  IStorage_Release(stg_tmp);
2780  }
2781 
2782  hr = IStorage_OpenStream(file2, strmC_name, NULL,
2783  STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, &strm_tmp);
2784  ok(hr == STG_E_FILENOTFOUND, "OpenStream should give STG_E_FILENOTFOUND, gave: 0x%08x\n", hr);
2785  if(SUCCEEDED(hr))
2786  IStream_Release(strm_tmp);
2787 
2788 cleanup:
2789  if(file1)
2790  IStorage_Release(file1);
2791  if(file2)
2792  IStorage_Release(file2);
2793 
2796 }
HRESULT hr
Definition: shlfolder.c:183
#define STGM_SHARE_EXCLUSIVE
Definition: objbase.h:922
static const WCHAR file2_name[]
Definition: storage32.c:48
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
char * wine_dbgstr_w(const wchar_t *wstr)
Definition: atltest.h:87
static int strcmp_ww(LPCWSTR strw1, LPCWSTR strw2)
Definition: storage32.c:56
#define STGM_CREATE
Definition: objbase.h:925
static const WCHAR file1_name[]
Definition: storage32.c:46
static const char file2_nameA[]
Definition: storage32.c:47
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
static const WCHAR strmC_name[]
Definition: storage32.c:53
static const char file1_nameA[]
Definition: storage32.c:45
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:77
static const WCHAR stgB_name[]
Definition: storage32.c:50
#define STG_E_FILENOTFOUND
Definition: winerror.h:2565
HRESULT WINAPI StgCreateDocfile(LPCOLESTR pwcsName, DWORD grfMode, DWORD reserved, IStorage **ppstgOpen)
Definition: storage32.c:8637
#define STGM_READWRITE
Definition: objbase.h:918
#define S_OK
Definition: intsafe.h:59
#define ok(value,...)
Definition: atltest.h:57
static const WCHAR strmA_name[]
Definition: storage32.c:51
static const WCHAR strmB_name[]
Definition: storage32.c:52
static const WCHAR stgA_name[]
Definition: storage32.c:49
char * cleanup(char *str)
Definition: wpickclick.c:99
static HRESULT create_test_file(IStorage *dest)
Definition: storage32.c:2552
#define memset(x, y, z)
Definition: compat.h:39
#define SUCCEEDED(hr)
Definition: intsafe.h:57

Referenced by START_TEST().

◆ test_create_storage_modes()

static void test_create_storage_modes ( void  )
static

Definition at line 297 of file storage32.c.

298 {
299  IStorage *stg = NULL;
300  HRESULT r;
301 
303 
304  /* test with some invalid parameters */
305  r = StgCreateDocfile( NULL, 0, 0, &stg);
306  ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
307  r = StgCreateDocfile( filename, 0, 0, &stg);
308  ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
309  r = StgCreateDocfile( filename, STGM_CREATE, 0, &stg);
310  ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
312  ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
314  ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
316  ok(r==STG_E_INVALIDPOINTER, "StgCreateDocfile succeeded\n");
318  ok(r==STG_E_INVALIDPARAMETER, "StgCreateDocfile succeeded\n");
320  ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
322  ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
324  ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
325 
326  /* StgCreateDocfile seems to be very particular about the flags it accepts */
328  ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
330  ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
332  ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
334  ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
336  ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
338  ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
340  ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
341  ok(stg == NULL, "stg was set\n");
342 
343  /* check what happens if the file already exists (which is how it's meant to be used) */
345  ok(r==S_OK, "StgCreateDocfile failed\n");
346  r = IStorage_Release(stg);
347  ok(r == 0, "storage not released\n");
349  ok(r==STG_E_FILEALREADYEXISTS, "StgCreateDocfile wrong error\n"); /* FAILIFTHERE is default */
350  r = StgCreateDocfile( filename, STGM_READ, 0, &stg);
351  ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n"); /* need at least readmode and sharemode */
353  ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
355  ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
357  ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile failed\n");
359  ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile failed\n");
361  ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile failed\n");
363  ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile failed\n");
365  ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile failed\n");
367  ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile wrong error\n");
369  ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile wrong error\n");
370  ok(DeleteFileA(filenameA), "failed to delete file\n");
371 
373  ok(r==S_OK, "StgCreateDocfile failed\n");
374  r = IStorage_Release(stg);
375  ok(r == 0, "storage not released\n");
377  ok(r==STG_E_FILEALREADYEXISTS, "StgCreateDocfile wrong error\n");
379  ok(r==STG_E_FILEALREADYEXISTS, "StgCreateDocfile wrong error\n");
380 
382  ok(r==STG_E_INVALIDFLAG, "StgCreateDocfile succeeded\n");
384  ok(r==S_OK, "StgCreateDocfile failed\n");
385  r = IStorage_Release(stg);
386  ok(r == 0, "storage not released\n");
387  ok(DeleteFileA(filenameA), "failed to delete file\n");
388 
390  ok(r==S_OK, "StgCreateDocfile failed\n");
391  r = IStorage_Release(stg);
392  ok(r == 0, "storage not released\n");
393  ok(DeleteFileA(filenameA), "failed to delete file\n");
394 
395  /* test the way excel uses StgCreateDocFile */
397  ok(r==S_OK, "StgCreateDocfile the excel way failed\n");
398  if(r == S_OK)
399  {
400  r = IStorage_Release(stg);
401  ok(r == 0, "storage not released\n");
402  ok(DeleteFileA(filenameA), "failed to delete file\n");
403  }
404 
405  /* and the way windows media uses it ... */
407  ok(r==S_OK, "StgCreateDocfile the windows media way failed\n");
408  if (r == S_OK)
409  {
410  r = IStorage_Release(stg);
411  ok(r == 0, "storage not released\n");
412  ok(DeleteFileA(filenameA), "failed to delete file\n");
413  }
414 
415  /* looks like we need STGM_TRANSACTED or STGM_CREATE */
417  ok(r==S_OK, "StgCreateDocfile the excel way failed\n");
418  if(r == S_OK)
419  {
420  r = IStorage_Release(stg);
421  ok(r == 0, "storage not released\n");
422  ok(DeleteFileA(filenameA), "failed to delete file\n");
423  }
424 
426  ok(r==S_OK, "StgCreateDocfile the excel way failed\n");
427  if(r == S_OK)
428  {
429  r = IStorage_Release(stg);
430  ok(r == 0, "storage not released\n");
431  ok(DeleteFileA(filenameA), "failed to delete file\n");
432  }
433 
435  ok(r==S_OK, "StgCreateDocfile the powerpoint way failed\n");
436  if(r == S_OK)
437  {
438  r = IStorage_Release(stg);
439  ok(r == 0, "storage not released\n");
440  ok(DeleteFileA(filenameA), "failed to delete file\n");
441  }
442 
443  /* test the way msi uses StgCreateDocfile */
445  ok(r==S_OK, "StgCreateDocFile failed\n");
446  r = IStorage_Release(stg);
447  ok(r == 0, "storage not released\n");
448  ok(DeleteFileA(filenameA), "failed to delete file\n");
449 }
#define STGM_SHARE_DENY_NONE
Definition: objbase.h:919
#define STG_E_INVALIDPOINTER
Definition: winerror.h:2571
#define STGM_SHARE_EXCLUSIVE
Definition: objbase.h:922
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
#define STGM_FAILIFTHERE
Definition: objbase.h:927
#define STGM_CREATE
Definition: objbase.h:925
const char * filename
Definition: ioapi.h:135
smooth NULL
Definition: ftsmooth.c:416
#define STGM_WRITE
Definition: objbase.h:917
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
#define STGM_READ
Definition: objbase.h:916
LONG HRESULT
Definition: typedefs.h:77
#define STG_E_FILEALREADYEXISTS
Definition: winerror.h:2579
#define STGM_DIRECT
Definition: objbase.h:913
#define STG_E_INVALIDFLAG
Definition: winerror.h:2587
static CHAR filenameA[MAX_PATH]
Definition: storage32.c:42
#define STG_E_INVALIDPARAMETER
Definition: winerror.h:2580
HRESULT WINAPI StgCreateDocfile(LPCOLESTR pwcsName, DWORD grfMode, DWORD reserved, IStorage **ppstgOpen)
Definition: storage32.c:8637
#define STGM_READWRITE
Definition: objbase.h:918
#define S_OK
Definition: intsafe.h:59
#define STGM_PRIORITY
Definition: objbase.h:923
#define ok(value,...)
Definition: atltest.h:57
#define STGM_TRANSACTED
Definition: objbase.h:914
#define STGM_SHARE_DENY_WRITE
Definition: objbase.h:921

Referenced by START_TEST().

◆ test_custom_lockbytes()

static void test_custom_lockbytes ( void  )
static

Definition at line 3878 of file storage32.c.

3879 {
3880  static const WCHAR stmname[] = { 'C','O','N','T','E','N','T','S',0 };
3881  TestLockBytes* lockbytes;
3882  HRESULT hr;
3883  IStorage* stg;
3884  IStream* stm;
3885 
3886  CreateTestLockBytes(&lockbytes);
3887 
3889  ok(hr==S_OK, "StgCreateDocfileOnILockBytes failed %x\n", hr);
3890 
3891  hr = IStorage_CreateStream(stg, stmname, STGM_SHARE_EXCLUSIVE|STGM_READWRITE, 0, 0, &stm);
3892  ok(hr==S_OK, "IStorage_CreateStream failed %x\n", hr);
3893 
3894  IStream_Release(stm);
3895 
3896  hr = IStorage_Commit(stg, 0);
3897 
3898  IStorage_Release(stg);
3899 
3900  ok(!lockbytes->lock_called, "unexpected call to LockRegion\n");
3901 
3902  lockbytes->locks_supported = LOCK_WRITE|LOCK_EXCLUSIVE|LOCK_ONLYONCE;
3903 
3905  ok(hr==S_OK, "StgCreateDocfileOnILockBytes failed %x\n", hr);
3906 
3907  hr = IStorage_CreateStream(stg, stmname, STGM_SHARE_EXCLUSIVE|STGM_READWRITE, 0, 0, &stm);
3908  ok(hr==S_OK, "IStorage_CreateStream failed %x\n", hr);
3909 
3910  IStream_Release(stm);
3911 
3912  hr = IStorage_Commit(stg, 0);
3913 
3914  IStorage_Release(stg);
3915 
3916  ok(lockbytes->lock_called, "expected LockRegion to be called\n");
3917 
3918  lockbytes->lock_hr = STG_E_INVALIDFUNCTION;
3919 
3921  ok(hr==STG_E_INVALIDFUNCTION, "StgCreateDocfileOnILockBytes failed %x\n", hr);
3922 
3923  DeleteTestLockBytes(lockbytes);
3924 }
static void DeleteTestLockBytes(TestLockBytes *This)
Definition: storage32.c:251
HRESULT hr
Definition: shlfolder.c:183
#define STGM_SHARE_EXCLUSIVE
Definition: objbase.h:922
HRESULT lock_hr
Definition: storage32.c:70
#define STGM_CREATE
Definition: objbase.h:925
ILockBytes ILockBytes_iface
Definition: storage32.c:65
ULONG lock_called
Definition: storage32.c:72
HRESULT WINAPI StgCreateDocfileOnILockBytes(ILockBytes *plkbyt, DWORD grfMode, DWORD reserved, IStorage **ppstgOpen)
Definition: storage32.c:8947
#define STG_E_INVALIDFUNCTION
Definition: winerror.h:2564
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:77
ULONG locks_supported
Definition: storage32.c:71
#define STGM_READWRITE
Definition: objbase.h:918
#define S_OK
Definition: intsafe.h:59
#define ok(value,...)
Definition: atltest.h:57
#define STGM_TRANSACTED
Definition: objbase.h:914
static void CreateTestLockBytes(TestLockBytes **This)
Definition: storage32.c:240

Referenced by START_TEST().

◆ test_direct_swmr()

static void test_direct_swmr ( void  )
static

Definition at line 3322 of file storage32.c.

3323 {
3324  static const WCHAR fileW[] = {'w','i','n','e','t','e','s','t',0};
3325  IDirectWriterLock *dwlock;
3326  ULONG ref, ref2;
3327  IStorage *stg;
3328  HRESULT hr;
3329 
3330  /* it's possible to create in writer mode */
3332 todo_wine
3333  ok(hr == S_OK, "got %08x\n", hr);
3334 if (hr == S_OK) {
3335  IStorage_Release(stg);
3336  DeleteFileW(fileW);
3337 }
3338 
3340  ok(hr == S_OK, "got %08x\n", hr);
3341  IStorage_Release(stg);
3342 
3343  /* reader mode */
3345  ok(hr == S_OK || broken(hr == STG_E_INVALIDFLAG), "got %08x\n", hr);
3346  if(hr == S_OK)
3347  {
3348  hr = IStorage_QueryInterface(stg, &IID_IDirectWriterLock, (void**)&dwlock);
3349  ok(hr == E_NOINTERFACE, "got %08x\n", hr);
3350  IStorage_Release(stg);
3351  }
3352 
3353  /* writer mode */
3355  ok(hr == S_OK, "got %08x\n", hr);
3356  if(hr == S_OK)
3357  {
3358  ref = IStorage_AddRef(stg);
3359  IStorage_Release(stg);
3360 
3361  hr = IStorage_QueryInterface(stg, &IID_IDirectWriterLock, (void**)&dwlock);
3362  ok(hr == S_OK, "got %08x\n", hr);
3363 
3364  ref2 = IStorage_AddRef(stg);
3365  IStorage_Release(stg);
3366  ok(ref2 == ref + 1, "got %u\n", ref2);
3367 
3368  IDirectWriterLock_Release(dwlock);
3369  IStorage_Release(stg);
3370  }
3371 
3372  DeleteFileW(fileW);
3373 }
#define STGM_SHARE_DENY_NONE
Definition: objbase.h:919
#define E_NOINTERFACE
Definition: winerror.h:2364
HRESULT hr
Definition: shlfolder.c:183
#define STGM_CREATE
Definition: objbase.h:925
Definition: send.c:47
GLenum GLint ref
Definition: glext.h:6028
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
smooth NULL
Definition: ftsmooth.c:416
#define STGM_READ
Definition: objbase.h:916
#define STGM_DIRECT_SWMR
Definition: objbase.h:930
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:77
HRESULT WINAPI StgOpenStorage(const OLECHAR *pwcsName, IStorage *pstgPriority, DWORD grfMode, SNB snbExclude, DWORD reserved, IStorage **ppstgOpen)
Definition: storage32.c:8756
#define STG_E_INVALIDFLAG
Definition: winerror.h:2587
#define todo_wine
Definition: test.h:154
HRESULT WINAPI StgCreateDocfile(LPCOLESTR pwcsName, DWORD grfMode, DWORD reserved, IStorage **ppstgOpen)
Definition: storage32.c:8637
#define STGM_READWRITE
Definition: objbase.h:918
#define broken(x)
Definition: _sntprintf.h:21
#define S_OK
Definition: intsafe.h:59
#define ok(value,...)
Definition: atltest.h:57
unsigned int ULONG
Definition: retypes.h:1
#define STGM_TRANSACTED
Definition: objbase.h:914
#define STGM_SHARE_DENY_WRITE
Definition: objbase.h:921
static const WCHAR fileW[]
Definition: url.c:111

Referenced by START_TEST().

◆ test_fmtusertypestg()

static void test_fmtusertypestg ( void  )
static

Definition at line 2431 of file storage32.c.

2432 {
2433  IStorage *stg;
2434  IEnumSTATSTG *stat;
2435  HRESULT hr;
2436  static const char fileA[] = {'f','m','t','t','e','s','t',0};
2437  static const WCHAR fileW[] = {'f','m','t','t','e','s','t',0};
2438  static WCHAR userTypeW[] = {'S','t','g','U','s','r','T','y','p','e',0};
2439  static const WCHAR strmNameW[] = {1,'C','o','m','p','O','b','j',0};
2440  static const STATSTG statstg_null;
2441 
2443  ok(hr == S_OK, "should succeed, res=%x\n", hr);
2444 
2445  if (SUCCEEDED(hr))
2446  {
2447  /* try to write the stream */
2448  hr = WriteFmtUserTypeStg(stg, 0, userTypeW);
2449  ok(hr == S_OK, "should succeed, res=%x\n", hr);
2450 
2451  /* check that the stream was created */
2452  hr = IStorage_EnumElements(stg, 0, NULL, 0, &stat);
2453  ok(hr == S_OK, "should succeed, res=%x\n", hr);
2454  if (SUCCEEDED(hr))
2455  {
2456  BOOL found = FALSE;
2457  STATSTG statstg;
2458  DWORD got;
2459  memset(&statstg, 0xad, sizeof(statstg));
2460  while ((hr = IEnumSTATSTG_Next(stat, 1, &statstg, &got)) == S_OK && got == 1)
2461  {
2462  if (strcmp_ww(statstg.pwcsName, strmNameW) == 0)
2463  found = TRUE;
2464  else
2465  ok(0, "found unexpected stream or storage\n");
2466  CoTaskMemFree(statstg.pwcsName);
2467  }
2468  ok(memcmp(&statstg, &statstg_null, sizeof(statstg)) == 0, "statstg is not zeroed\n");
2469  ok(found == TRUE, "expected storage to contain stream \\0001CompObj\n");
2470  IEnumSTATSTG_Release(stat);
2471  }
2472 
2473  /* re-write the stream */
2474  hr = WriteFmtUserTypeStg(stg, 0, userTypeW);
2475  ok(hr == S_OK, "should succeed, res=%x\n", hr);
2476 
2477  /* check that the stream is still there */
2478  hr = IStorage_EnumElements(stg, 0, NULL, 0, &stat);
2479  ok(hr == S_OK, "should succeed, res=%x\n", hr);
2480  if (SUCCEEDED(hr))
2481  {
2482  BOOL found = FALSE;
2483  STATSTG statstg;
2484  DWORD got;
2485  memset(&statstg, 0xad, sizeof(statstg));
2486  while ((hr = IEnumSTATSTG_Next(stat, 1, &statstg, &got)) == S_OK && got == 1)
2487  {
2488  if (strcmp_ww(statstg.pwcsName, strmNameW) == 0)
2489  found = TRUE;
2490  else
2491  ok(0, "found unexpected stream or storage\n");
2492  CoTaskMemFree(statstg.pwcsName);
2493  }
2494  ok(memcmp(&statstg, &statstg_null, sizeof(statstg)) == 0, "statstg is not zeroed\n");
2495  ok(found == TRUE, "expected storage to contain stream \\0001CompObj\n");
2496  IEnumSTATSTG_Release(stat);
2497  }
2498 
2499  IStorage_Release(stg);
2500  DeleteFileA( fileA );
2501  }
2502 }
#define TRUE
Definition: types.h:120
HRESULT WINAPI WriteFmtUserTypeStg(LPSTORAGE pstg, CLIPFORMAT cf, LPOLESTR lpszUserType)
Definition: storage32.c:9357
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
VOID WINAPI CoTaskMemFree(LPVOID ptr)
Definition: ifs.c:422
HRESULT hr
Definition: shlfolder.c:183
#define STGM_SHARE_EXCLUSIVE
Definition: objbase.h:922
static int strcmp_ww(LPCWSTR strw1, LPCWSTR strw2)
Definition: storage32.c:56
#define STGM_CREATE
Definition: objbase.h:925
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:77
unsigned long DWORD
Definition: ntddk_ex.h:95
Definition: stat.h:55
HRESULT WINAPI StgCreateDocfile(LPCOLESTR pwcsName, DWORD grfMode, DWORD reserved, IStorage **ppstgOpen)
Definition: storage32.c:8637
#define STGM_READWRITE
Definition: objbase.h:918
_CRTIMP int __cdecl stat(const char *_Filename, struct stat *_Stat)
Definition: stat.h:345
#define S_OK
Definition: intsafe.h:59
#define ok(value,...)
Definition: atltest.h:57
#define memset(x, y, z)
Definition: compat.h:39
static const WCHAR fileW[]
Definition: url.c:111
#define SUCCEEDED(hr)
Definition: intsafe.h:57

Referenced by START_TEST().

◆ test_hglobal_storage_creation()

static void test_hglobal_storage_creation ( void  )
static

Definition at line 3247 of file storage32.c.

3248 {
3249  ILockBytes *ilb = NULL;
3250  IStorage *stg = NULL;
3251  HRESULT r;
3252  STATSTG stat;
3253  char junk[512];
3255 
3257  ok(r == S_OK, "CreateILockBytesOnHGlobal failed, hr=%x\n", r);
3258 
3259  offset.QuadPart = 0;
3260  memset(junk, 0xaa, 512);
3261  r = ILockBytes_WriteAt(ilb, offset, junk, 512, NULL);
3262  ok(r == S_OK, "ILockBytes_WriteAt failed, hr=%x\n", r);
3263 
3264  offset.QuadPart = 2000;
3265  r = ILockBytes_WriteAt(ilb, offset, junk, 512, NULL);
3266  ok(r == S_OK, "ILockBytes_WriteAt failed, hr=%x\n", r);
3267 
3269  ok(r == S_OK, "StgCreateDocfileOnILockBytes failed, hr=%x\n", r);
3270 
3271  IStorage_Release(stg);
3272 
3274  NULL, 0, &stg);
3275  ok(r == S_OK, "StgOpenStorageOnILockBytes failed, hr=%x\n", r);
3276 
3277  if (SUCCEEDED(r))
3278  {
3279  r = IStorage_Stat(stg, &stat, STATFLAG_NONAME);
3280  ok(r == S_OK, "StgOpenStorageOnILockBytes failed, hr=%x\n", r);
3281  ok(IsEqualCLSID(&stat.clsid, &GUID_NULL), "unexpected CLSID value\n");
3282 
3283  IStorage_Release(stg);
3284  }
3285 
3286  r = ILockBytes_Stat(ilb, &stat, STATFLAG_NONAME);
3287  ok(r == S_OK, "ILockBytes_Stat failed, hr=%x\n", r);
3288  ok(stat.cbSize.u.LowPart < 2512, "expected truncated size, got %d\n", stat.cbSize.u.LowPart);
3289 
3290  ILockBytes_Release(ilb);
3291 }
#define TRUE
Definition: types.h:120
HRESULT WINAPI CreateILockBytesOnHGlobal(HGLOBAL global, BOOL delete_on_release, ILockBytes **ret)
Definition: memlockbytes.c:100
#define STGM_SHARE_EXCLUSIVE
Definition: objbase.h:922
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
#define STGM_CREATE
Definition: objbase.h:925
uint8_t junk[422]
Definition: fsck.fat.h:69
GLintptr offset
Definition: glext.h:5920
HRESULT WINAPI StgCreateDocfileOnILockBytes(ILockBytes *plkbyt, DWORD grfMode, DWORD reserved, IStorage **ppstgOpen)
Definition: storage32.c:8947
smooth NULL
Definition: ftsmooth.c:416
#define STGM_READ
Definition: objbase.h:916
LONG HRESULT
Definition: typedefs.h:77
HRESULT WINAPI StgOpenStorageOnILockBytes(ILockBytes *plkbyt, IStorage *pstgPriority, DWORD grfMode, SNB snbExclude, DWORD reserved, IStorage **ppstgOpen)
Definition: storage32.c:8985
Definition: stat.h:55
#define GUID_NULL
Definition: ks.h:106
#define STGM_READWRITE
Definition: objbase.h:918
_CRTIMP int __cdecl stat(const char *_Filename, struct stat *_Stat)
Definition: stat.h:345
#define S_OK
Definition: intsafe.h:59
#define ok(value,...)
Definition: atltest.h:57
#define memset(x, y, z)
Definition: compat.h:39
#define IsEqualCLSID(rclsid1, rclsid2)
Definition: guiddef.h:96
#define SUCCEEDED(hr)
Definition: intsafe.h:57

Referenced by START_TEST().

◆ test_hglobal_storage_stat()

static void test_hglobal_storage_stat ( void  )
static

Definition at line 259 of file storage32.c.

260 {
261  ILockBytes *ilb = NULL;
262  IStorage *stg = NULL;
263  HRESULT r;
264  STATSTG stat;
265  DWORD mode, refcount;
266 
267  r = CreateILockBytesOnHGlobal( NULL, TRUE, &ilb );
268  ok( r == S_OK, "CreateILockBytesOnHGlobal failed\n");
269 
270  r = StgIsStorageILockBytes( ilb );
271  ok( r == S_FALSE, "StgIsStorageILockBytes should have failed\n");
272 
274  r = StgCreateDocfileOnILockBytes( ilb, mode, 0, &stg );
275  ok( r == S_OK, "StgCreateDocfileOnILockBytes failed\n");
276 
277  r = WriteClassStg( stg, &test_stg_cls );
278  ok( r == S_OK, "WriteClassStg failed\n");
279 
280  r = StgIsStorageILockBytes( ilb );
281  ok( r == S_OK, "StgIsStorageILockBytes failed\n");
282 
283  memset( &stat, 0, sizeof stat );
284  r = IStorage_Stat( stg, &stat, 0 );
285 
286  ok( stat.pwcsName == NULL, "storage name not null\n");
287  ok( stat.type == 1, "type is wrong\n");
288  ok( stat.grfMode == 0x12, "grf mode is incorrect\n");
289  ok( !memcmp(&stat.clsid, &test_stg_cls, sizeof test_stg_cls), "CLSID is wrong\n");
290 
291  refcount = IStorage_Release( stg );
292  ok( refcount == 0, "IStorage refcount is wrong\n");
293  refcount = ILockBytes_Release( ilb );
294  ok( refcount == 0, "ILockBytes refcount is wrong\n");
295 }
#define TRUE
Definition: types.h:120
HRESULT WINAPI CreateILockBytesOnHGlobal(HGLOBAL global, BOOL delete_on_release, ILockBytes **ret)
Definition: memlockbytes.c:100
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
#define STGM_SHARE_EXCLUSIVE
Definition: objbase.h:922
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
#define STGM_CREATE
Definition: objbase.h:925
HRESULT WINAPI StgCreateDocfileOnILockBytes(ILockBytes *plkbyt, DWORD grfMode, DWORD reserved, IStorage **ppstgOpen)
Definition: storage32.c:8947
#define S_FALSE
Definition: winerror.h:2357
smooth NULL
Definition: ftsmooth.c:416
LONG HRESULT
Definition: typedefs.h:77
unsigned long DWORD
Definition: ntddk_ex.h:95
HRESULT WINAPI StgIsStorageILockBytes(ILockBytes *plkbyt)
Definition: storage32.c:9057
Definition: stat.h:55
GLenum mode
Definition: glext.h:6217
#define STGM_READWRITE
Definition: objbase.h:918
_CRTIMP int __cdecl stat(const char *_Filename, struct stat *_Stat)
Definition: stat.h:345
HRESULT WINAPI WriteClassStg(IStorage *pStg, REFCLSID rclsid)
Definition: storage32.c:9079
#define S_OK
Definition: intsafe.h:59
#define ok(value,...)
Definition: atltest.h:57
#define memset(x, y, z)
Definition: compat.h:39

Referenced by START_TEST().

◆ test_locking()

static void test_locking ( void  )
static

Definition at line 3490 of file storage32.c.

3491 {
3492  static const WCHAR filename[] = {'w','i','n','e','t','e','s','t',0};
3493  int i;
3494  IStorage *stg;
3495  HRESULT hr;
3496 
3497  for (i = 0; i < ARRAY_SIZE(lock_tests); i++)
3498  {
3499  const struct lock_test *current = &lock_tests[i];
3500  BOOL any_failure = FALSE;
3501  DWORD open_mode = 0;
3502 
3503  if (current->create)
3504  {
3505  hr = StgCreateDocfile(filename, current->stg_mode, 0, &stg);
3506  ok(SUCCEEDED(hr), "StgCreateDocfile with mode %x failed with hr %x\n", current->stg_mode, hr);
3507  if (FAILED(hr)) continue;
3508  }
3509  else
3510  {
3512  ok(SUCCEEDED(hr), "StgCreateDocfile failed with hr %x\n", hr);
3513  if (FAILED(hr)) continue;
3514  IStorage_Release(stg);
3515 
3516  hr = StgOpenStorage(filename, NULL, current->stg_mode, NULL, 0, &stg);
3517  ok(SUCCEEDED(hr), "StgOpenStorage with mode %x failed with hr %x\n", current->stg_mode, hr);
3518  if (FAILED(hr))
3519  {
3521  continue;
3522  }
3523  }
3524 
3525  check_sharing(filename, current, GENERIC_READ, FILE_SHARE_READ, "READ", &open_mode, &any_failure);
3526  check_sharing(filename, current, GENERIC_WRITE, FILE_SHARE_WRITE, "WRITE", &open_mode, &any_failure);
3527  check_sharing(filename, current, DELETE, FILE_SHARE_DELETE, "DELETE", &open_mode, &any_failure);
3528 
3529  if (open_mode != 0)
3530  {
3531  HANDLE hfile;
3532  BOOL locked, expect_locked;
3533  OVERLAPPED ol;
3534  const int* next_lock = current->locked_bytes;
3535 
3536  check_access(filename, current, GENERIC_READ, FILE_SHARE_READ, "READ", open_mode, &any_failure);
3537  check_access(filename, current, GENERIC_WRITE, FILE_SHARE_WRITE, "WRITE", open_mode, &any_failure);
3538  check_access(filename, current, DELETE, FILE_SHARE_DELETE, "DELETE", open_mode, &any_failure);
3539 
3541  ok(hfile != INVALID_HANDLE_VALUE, "couldn't open file with mode %x\n", current->stg_mode);
3542 
3543  ol.OffsetHigh = 0;
3544  ol.hEvent = NULL;
3545 
3546  for (ol.Offset = 0x7ffffe00; ol.Offset != 0x80000000; ol.Offset++)
3547  {
3549  locked = FALSE;
3550  else
3551  {
3552  ok(!LockFileEx(hfile, LOCKFILE_FAIL_IMMEDIATELY, 0, 1, 0, &ol), "shared locks should not be used\n");
3553  locked = TRUE;
3554  }
3555 
3556  UnlockFileEx(hfile, 0, 1, 0, &ol);
3557 
3558  if ((ol.Offset&0x1ff) == *next_lock)
3559  {
3560  expect_locked = TRUE;
3561  next_lock++;
3562  }
3563  else
3564  expect_locked = FALSE;
3565 
3566  if (!current->todo || locked == expect_locked)
3567  ok(locked == expect_locked, "byte %x of file with mode %x is %slocked but should %sbe\n",
3568  ol.Offset, current->stg_mode, locked?"":"not ", expect_locked?"":"not ");
3569  else
3570  {
3571  any_failure = TRUE;
3572  todo_wine ok(locked == expect_locked, "byte %x of file with mode %x is %slocked but should %sbe\n",
3573  ol.Offset, current->stg_mode, locked?"":"not ", expect_locked?"":"not ");
3574  }
3575  }
3576 
3577  CloseHandle(hfile);
3578  }
3579 
3580  IStorage_Release( stg );
3581 
3582  if (!current->create)
3583  {
3584  HANDLE hfile;
3585  BOOL failed, expect_failed=FALSE;
3586  OVERLAPPED ol;
3587  const int* next_range = current->fail_ranges;
3588 
3590  ok(hfile != INVALID_HANDLE_VALUE, "couldn't open file with mode %x\n", current->stg_mode);
3591 
3592  ol.OffsetHigh = 0;
3593  ol.hEvent = NULL;
3594 
3595  for (ol.Offset = 0x7ffffe00; ol.Offset != 0x80000000; ol.Offset++)
3596  {
3597  if (ol.Offset == 0x7fffff92 ||
3598  (ol.Offset == 0x7fffff80 && current->stg_mode == (STGM_TRANSACTED|STGM_READWRITE)) ||
3599  (ol.Offset == 0x7fffff80 && current->stg_mode == (STGM_TRANSACTED|STGM_READ)))
3600  continue; /* This makes opens hang */
3601 
3602  if (ol.Offset < 0x7fffff00)
3603  LockFileEx(hfile, 0, 0, 1, 0, &ol);
3604  else
3605  LockFileEx(hfile, LOCKFILE_EXCLUSIVE_LOCK, 0, 1, 0, &ol);
3606 
3607  hr = StgOpenStorage(filename, NULL, current->stg_mode, NULL, 0, &stg);
3608  ok(hr == S_OK || hr == STG_E_LOCKVIOLATION || hr == STG_E_SHAREVIOLATION, "failed with unexpected hr %x\n", hr);
3609  if (SUCCEEDED(hr)) IStorage_Release(stg);
3610 
3611  UnlockFileEx(hfile, 0, 1, 0, &ol);
3612 
3613  failed = FAILED(hr);
3614 
3615  if (!expect_failed && (ol.Offset&0x1ff) == next_range[0])
3616  {
3617  expect_failed = TRUE;
3618  }
3619  else if (expect_failed && (ol.Offset&0x1ff) == next_range[1])
3620  {
3621  expect_failed = FALSE;
3622  next_range += 2;
3623  }
3624 
3625  if (!current->todo || failed == expect_failed)
3626  ok(failed == expect_failed, "open with byte %x locked, mode %x %s but should %s\n",
3627  ol.Offset, current->stg_mode, failed?"failed":"succeeded", expect_failed?"fail":"succeed");
3628  else
3629  {
3630  any_failure = TRUE;
3631  todo_wine ok(failed == expect_failed, "open with byte %x locked, mode %x %s but should %s\n",
3632  ol.Offset, current->stg_mode, failed?"failed":"succeeded", expect_failed?"fail":"succeed");
3633  }
3634  }
3635 
3636  CloseHandle(hfile);
3637  }
3638 
3640 
3641  if (current->todo && !any_failure)
3642  todo_wine ok(1, "tests succeeded for mode %x\n", current->stg_mode);
3643  }
3644 }
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
HRESULT hr
Definition: shlfolder.c:183
#define STGM_SHARE_EXCLUSIVE
Definition: objbase.h:922
#define STGM_CREATE
Definition: objbase.h:925
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
const char * filename
Definition: ioapi.h:135
DWORD Offset
Definition: winbase.h:787
#define FILE_SHARE_READ
Definition: compat.h:125
static const struct lock_test lock_tests[]
Definition: storage32.c:3404
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GENERIC_WRITE
Definition: nt_native.h:90
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
HANDLE hEvent
Definition: winbase.h:792
#define LOCKFILE_FAIL_IMMEDIATELY
Definition: winbase.h:366
smooth NULL
Definition: ftsmooth.c:416
static void check_access(LPCWSTR filename, const struct lock_test *current, DWORD access, DWORD sharing, const char *desc, DWORD open_mode, BOOL *any_failure)
Definition: storage32.c:3465
#define OPEN_EXISTING
Definition: compat.h:426
#define STGM_READ
Definition: objbase.h:916
#define STG_E_SHAREVIOLATION
Definition: winerror.h:2577
static void check_sharing(LPCWSTR filename, const struct lock_test *current, DWORD access, DWORD sharing, const char *desc, DWORD *open_mode, BOOL *any_failure)
Definition: storage32.c:3435
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:77
HRESULT WINAPI StgOpenStorage(const OLECHAR *pwcsName, IStorage *pstgPriority, DWORD grfMode, SNB snbExclude, DWORD reserved, IStorage **ppstgOpen)
Definition: storage32.c:8756
unsigned long DWORD
Definition: ntddk_ex.h:95
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
#define FILE_SHARE_DELETE
Definition: nt_native.h:682
#define todo_wine
Definition: test.h:154
BOOL WINAPI UnlockFileEx(IN HANDLE hFile, IN DWORD dwReserved, IN DWORD nNumberOfBytesToUnLockLow, IN DWORD nNumberOfBytesToUnLockHigh, IN LPOVERLAPPED lpOverlapped)
Definition: lock.c:183
HRESULT WINAPI StgCreateDocfile(LPCOLESTR pwcsName, DWORD grfMode, DWORD reserved, IStorage **ppstgOpen)
Definition: storage32.c:8637
#define GENERIC_READ
Definition: compat.h:124
#define STGM_READWRITE
Definition: objbase.h:918
#define S_OK
Definition: intsafe.h:59
BOOL WINAPI LockFileEx(IN HANDLE hFile, IN DWORD dwFlags, IN DWORD dwReserved, IN DWORD nNumberOfBytesToLockLow, IN DWORD nNumberOfBytesToLockHigh, IN LPOVERLAPPED lpOverlapped)
Definition: lock.c:82
#define STG_E_LOCKVIOLATION
Definition: winerror.h:2578
DWORD OffsetHigh
Definition: winbase.h:788
#define ARRAY_SIZE(a)
Definition: main.h:24
#define ok(value,...)
Definition: atltest.h:57
#define LOCKFILE_EXCLUSIVE_LOCK
Definition: winbase.h:367
#define CreateFileW
Definition: compat.h:400
#define STGM_TRANSACTED
Definition: objbase.h:914
#define SUCCEEDED(hr)
Definition: intsafe.h:57
struct task_struct * current
Definition: linux.c:32
#define DELETE
Definition: nt_native.h:57

Referenced by START_TEST().

◆ test_nonroot_transacted()

static void test_nonroot_transacted ( void  )
static

Definition at line 1847 of file storage32.c.

1848 {
1849  IStorage *stg = NULL, *stg2 = NULL, *stg3 = NULL;
1850  HRESULT r;
1851  IStream *stm = NULL;
1852  static const WCHAR stgname[] = { 'P','E','R','M','S','T','G',0 };
1853  static const WCHAR stmname[] = { 'C','O','N','T','E','N','T','S',0 };
1854  static const WCHAR stmname2[] = { 'F','O','O',0 };
1855  BOOL ret;
1856 
1858 
1859  /* create a transacted file */
1861  STGM_READWRITE |STGM_TRANSACTED, 0, &stg);
1862  ok(r==S_OK, "StgCreateDocfile failed\n");
1863 
1864  /* create a transacted substorage */
1865  r = IStorage_CreateStorage(stg, stgname, STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_TRANSACTED, 0, 0, &stg2);
1866  ok(r==S_OK, "IStorage->CreateStorage failed, hr=%08x\n", r);
1867 
1868  if (r == S_OK)
1869  {
1870  /* create and commit stmname */
1871  r = IStorage_CreateStream(stg2, stmname, STGM_SHARE_EXCLUSIVE | STGM_READWRITE, 0, 0, &stm );
1872  ok(r==S_OK, "IStorage->CreateStream failed\n");
1873  if (r == S_OK)
1874  IStream_Release(stm);
1875 
1876  IStorage_Commit(stg2, 0);
1877 
1878  /* create and revert stmname2 */
1879  r = IStorage_CreateStream(stg2, stmname2, STGM_SHARE_EXCLUSIVE | STGM_READWRITE, 0, 0, &stm );
1880  ok(r==S_OK, "IStorage->CreateStream failed\n");
1881  if (r == S_OK)
1882  IStream_Release(stm);
1883 
1884  IStorage_Revert(stg2);
1885 
1886  /* check that Commit and Revert really worked */
1887  r = IStorage_OpenStream(stg2, stmname, NULL, STGM_SHARE_EXCLUSIVE|STGM_READWRITE, 0, &stm );
1888  ok(r==S_OK, "IStorage->OpenStream should succeed %08x\n", r);
1889  if (r == S_OK)
1890  IStream_Release(stm);
1891 
1892  r = IStorage_OpenStream(stg2, stmname2, NULL, STGM_SHARE_EXCLUSIVE|STGM_READWRITE, 0, &stm );
1893  ok(r==STG_E_FILENOTFOUND, "IStorage->OpenStream should fail %08x\n", r);
1894  if (r == S_OK)
1895  IStream_Release(stm);
1896 
1897  IStorage_Release(stg2);
1898  }
1899 
1900  /* create a read-only transacted substorage */
1901  r = IStorage_OpenStorage(stg, stgname, NULL, STGM_READ | STGM_SHARE_EXCLUSIVE | STGM_TRANSACTED, NULL, 0, &stg2);
1902  ok(r==S_OK, "IStorage->OpenStorage failed, hr=%08x\n", r);
1903 
1904  if (r == S_OK)
1905  {
1906  /* The storage can be modified. */
1907  r = IStorage_CreateStorage(stg2, stgname, STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &stg3);
1908  ok(r==S_OK, "IStorage->CreateStorage failed, hr=%08x\n", r);
1909  if (r == S_OK)
1910  IStorage_Release(stg3);
1911 
1912  /* But changes cannot be committed. */
1913  r = IStorage_Commit(stg2, 0);
1914  ok(r==STG_E_ACCESSDENIED, "IStorage->Commit should fail, hr=%08x\n", r);
1915 
1916  IStorage_Release(stg2);
1917  }
1918 
1919  IStorage_Release(stg);
1920 
1921  /* create a non-transacted file */
1923  STGM_READWRITE, 0, &stg);
1924  ok(r==S_OK, "StgCreateDocfile failed\n");
1925 
1926  /* create a transacted substorage */
1927  r = IStorage_CreateStorage(stg, stgname, STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_TRANSACTED, 0, 0, &stg2);
1928  ok(r==S_OK, "IStorage->CreateStorage failed, hr=%08x\n", r);
1929 
1930  if (r == S_OK)
1931  {
1932  /* create and commit stmname */
1933  r = IStorage_CreateStream(stg2, stmname, STGM_SHARE_EXCLUSIVE | STGM_READWRITE, 0, 0, &stm );
1934  ok(r==S_OK, "IStorage->CreateStream failed\n");
1935  if (r == S_OK)
1936  IStream_Release(stm);
1937 
1938  IStorage_Commit(stg2, 0);
1939 
1940  /* create and revert stmname2 */
1941  r = IStorage_CreateStream(stg2, stmname2, STGM_SHARE_EXCLUSIVE | STGM_READWRITE, 0, 0, &stm );
1942  ok(r==S_OK, "IStorage->CreateStream failed\n");
1943  if (r == S_OK)
1944  IStream_Release(stm);
1945 
1946  IStorage_Revert(stg2);
1947 
1948  /* check that Commit and Revert really worked */
1949  r = IStorage_OpenStream(stg2, stmname, NULL, STGM_SHARE_EXCLUSIVE|STGM_READWRITE, 0, &stm );
1950  ok(r==S_OK, "IStorage->OpenStream should succeed %08x\n", r);
1951  if (r == S_OK)
1952  IStream_Release(stm);
1953 
1954  r = IStorage_OpenStream(stg2, stmname2, NULL, STGM_SHARE_EXCLUSIVE|STGM_READWRITE, 0, &stm );
1955  ok(r==STG_E_FILENOTFOUND, "IStorage->OpenStream should fail %08x\n", r);
1956  if (r == S_OK)
1957  IStream_Release(stm);
1958 
1959  IStorage_Release(stg2);
1960  }
1961 
1962  IStorage_Release(stg);
1963 
1965  ok(ret, "deleted file\n");
1966 }
#define STGM_SHARE_EXCLUSIVE
Definition: objbase.h:922
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
#define STGM_CREATE
Definition: objbase.h:925
const char * filename
Definition: ioapi.h:135
#define STG_E_ACCESSDENIED
Definition: winerror.h:2568
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
#define STGM_READ
Definition: objbase.h:916
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:77
static CHAR filenameA[MAX_PATH]
Definition: storage32.c:42
int ret
#define STG_E_FILENOTFOUND
Definition: winerror.h:2565
HRESULT WINAPI StgCreateDocfile(LPCOLESTR pwcsName, DWORD grfMode, DWORD reserved, IStorage **ppstgOpen)
Definition: storage32.c:8637
#define STGM_READWRITE
Definition: objbase.h:918
#define S_OK
Definition: intsafe.h:59
#define ok(value,...)
Definition: atltest.h:57
#define STGM_TRANSACTED
Definition: objbase.h:914

Referenced by START_TEST().

◆ test_open_storage()

static void test_open_storage ( void  )
static

Definition at line 741 of file storage32.c.

742 {
743  static const WCHAR szNonExist[] = { 'n','o','n','e','x','i','s','t',0 };
744  IStorage *stg = NULL, *stg2 = NULL;
745  HRESULT r;
746  DWORD stgm;
747  BOOL ret;
748 
749  /* try opening a zero length file - it should stay zero length */
753  r = StgOpenStorage( filename, NULL, stgm, NULL, 0, &stg);
754  ok(r==STG_E_FILEALREADYEXISTS, "StgOpenStorage didn't fail\n");
755 
757  r = StgOpenStorage( filename, NULL, stgm, NULL, 0, &stg);
758  ok(r==STG_E_FILEALREADYEXISTS, "StgOpenStorage didn't fail\n");
759  ok(is_zero_length(filenameA), "file length changed\n");
760 
762 
763  /* try opening a nonexistent file - it should not create it */
765  r = StgOpenStorage( filename, NULL, stgm, NULL, 0, &stg);
766  ok(r!=S_OK, "StgOpenStorage failed: 0x%08x\n", r);
767  if (r==S_OK) IStorage_Release(stg);
768  ok(!is_existing_file(filenameA), "StgOpenStorage should not create a file\n");
770 
771  /* create the file */
773  ok(r==S_OK, "StgCreateDocfile failed\n");
774  IStorage_Release(stg);
775 
776  r = StgOpenStorage( filename, NULL, 0, NULL, 0, &stg);
777  ok(r==STG_E_INVALIDFLAG, "StgOpenStorage wrong error\n");
779  ok(r==STG_E_INVALIDNAME, "StgOpenStorage wrong error\n");
781  ok(r==STG_E_INVALIDPOINTER, "StgOpenStorage wrong error\n");
783  ok(r==STG_E_INVALIDPARAMETER, "StgOpenStorage wrong error\n");
784  r = StgOpenStorage( szNonExist, NULL, STGM_SHARE_EXCLUSIVE | STGM_READ, NULL, 0, &stg);
785  ok(r==STG_E_FILENOTFOUND, "StgOpenStorage failed\n");
787  ok(r==STG_E_INVALIDFLAG, "StgOpenStorage failed\n");
789  ok(r==STG_E_INVALIDFLAG, "StgOpenStorage failed\n");
791  ok(r==STG_E_INVALIDFLAG, "StgOpenStorage failed\n");
793  ok(r==STG_E_INVALIDFLAG, "StgOpenStorage failed\n");
794 
795  /* open it for real */
796  r = StgOpenStorage( filename, NULL, STGM_SHARE_DENY_NONE | STGM_READ | STGM_TRANSACTED, NULL, 0, &stg); /* XLViewer 97/2000 */
797  ok(r==S_OK, "StgOpenStorage failed\n");
798  if(stg)
799  {
800  r = IStorage_Release(stg);
801  ok(r == 0, "wrong ref count\n");
802  }
803 
805  ok(r==S_OK, "StgOpenStorage failed\n");
806  if(stg)
807  {
808  r = IStorage_Release(stg);
809  ok(r == 0, "wrong ref count\n");
810  }
811 
812  /* test the way word opens its custom dictionary */
815  ok(r==S_OK, "StgOpenStorage failed\n");
816  if(stg)
817  {
818  r = IStorage_Release(stg);
819  ok(r == 0, "wrong ref count\n");
820  }
821 
823  ok(r==S_OK, "StgOpenStorage failed\n");
825  ok(r==STG_E_SHAREVIOLATION, "StgOpenStorage failed\n");
826  if(stg)
827  {
828  r = IStorage_Release(stg);
829  ok(r == 0, "wrong ref count\n");
830  }
831 
832  /* now try write to a storage file we opened read-only */
834  ok(r==S_OK, "StgOpenStorage failed\n");
835  if(stg)
836  {
837  static const WCHAR stmname[] = { 'w','i','n','e','t','e','s','t',0};
838  IStream *stm = NULL;
839  IStorage *stg2 = NULL;
840 
841  r = IStorage_CreateStream( stg, stmname, STGM_WRITE | STGM_SHARE_EXCLUSIVE,
842  0, 0, &stm );
843  ok(r == STG_E_ACCESSDENIED, "CreateStream should fail\n");
844  r = IStorage_CreateStorage( stg, stmname, STGM_WRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &stg2);
845  ok(r == STG_E_ACCESSDENIED, "CreateStream should fail\n");
846 
847  r = IStorage_Release(stg);
848  ok(r == 0, "wrong ref count\n");
849  }
850 
851  /* open like visio 2003 */
852  stg = NULL;
854  ok(r == S_OK, "should succeed\n");
855  if (stg)
856  IStorage_Release(stg);
857 
858  /* test other sharing modes with STGM_PRIORITY */
859  stg = NULL;
861  ok(r == S_OK, "should succeed\n");
862  if (stg)
863  IStorage_Release(stg);
864 
865  stg = NULL;
867  ok(r == S_OK, "should succeed\n");
868  if (stg)
869  IStorage_Release(stg);
870 
871  stg = NULL;
873  ok(r == S_OK, "should succeed\n");
874  if (stg)
875  IStorage_Release(stg);
876 
877  /* open like Project 2003 */
878  stg = NULL;
880  ok(r == S_OK, "should succeed\n");
881  r = StgOpenStorage( filename, NULL, STGM_PRIORITY, NULL, 0, &stg2);
882  ok(r == S_OK, "should succeed\n");
883  if (stg2)
884  IStorage_Release(stg2);
885  if (stg)
886  IStorage_Release(stg);
887 
888  stg = NULL;
890  ok(r == STG_E_INVALIDFLAG, "should fail\n");
891 
893  ok(r == STG_E_INVALIDFLAG, "should fail\n");
894 
896  ok(r == STG_E_INVALIDFLAG, "should fail\n");
897 
899  ok(r == STG_E_INVALIDFUNCTION, "should fail\n");
900 
902  ok(r == STG_E_INVALIDFLAG, "should fail\n");
903 
905  ok(r == STG_E_INVALIDFLAG, "should fail\n");
906 
908  ok(ret, "file didn't exist\n");
909 }
#define STGM_SHARE_DENY_NONE
Definition: objbase.h:919
#define STG_E_INVALIDNAME
Definition: winerror.h:2584
#define STG_E_INVALIDPOINTER
Definition: winerror.h:2571
#define STGM_SHARE_EXCLUSIVE
Definition: objbase.h:922
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
#define STGM_NOSNAPSHOT
Definition: objbase.h:929
#define STGM_CREATE
Definition: objbase.h:925
static BOOL is_zero_length(LPCSTR filename)
Definition: storage32.c:715
const char * filename
Definition: ioapi.h:135
#define STG_E_ACCESSDENIED
Definition: winerror.h:2568
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
#define STGM_WRITE
Definition: objbase.h:917
#define STGM_DELETEONRELEASE
Definition: objbase.h:924
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
#define STG_E_INVALIDFUNCTION
Definition: winerror.h:2564
#define STGM_READ
Definition: objbase.h:916
#define STG_E_SHAREVIOLATION
Definition: winerror.h:2577
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:77
#define STG_E_FILEALREADYEXISTS
Definition: winerror.h:2579
HRESULT WINAPI StgOpenStorage(const OLECHAR *pwcsName, IStorage *pstgPriority, DWORD grfMode, SNB snbExclude, DWORD reserved, IStorage **ppstgOpen)
Definition: storage32.c:8756
#define STGM_DIRECT
Definition: objbase.h:913
#define STG_E_INVALIDFLAG
Definition: winerror.h:2587
unsigned long DWORD
Definition: ntddk_ex.h:95
static CHAR filenameA[MAX_PATH]
Definition: storage32.c:42
#define STG_E_INVALIDPARAMETER
Definition: winerror.h:2580
static BOOL touch_file(LPCSTR filename)
Definition: storage32.c:703
int ret
#define STG_E_FILENOTFOUND
Definition: winerror.h:2565
HRESULT WINAPI StgCreateDocfile(LPCOLESTR pwcsName, DWORD grfMode, DWORD reserved, IStorage **ppstgOpen)
Definition: storage32.c:8637
#define STGM_READWRITE
Definition: objbase.h:918
#define S_OK
Definition: intsafe.h:59
#define STGM_PRIORITY
Definition: objbase.h:923
#define ok(value,...)
Definition: atltest.h:57
#define STGM_NOSCRATCH
Definition: objbase.h:928
static BOOL is_existing_file(LPCSTR filename)
Definition: storage32.c:729
#define STGM_TRANSACTED
Definition: objbase.h:914
#define STGM_SHARE_DENY_WRITE
Definition: objbase.h:921
#define STGM_SIMPLE
Definition: objbase.h:915
#define STGM_SHARE_DENY_READ
Definition: objbase.h:920

Referenced by START_TEST().

◆ test_overwrite()

static void test_overwrite ( void  )
static

Definition at line 3765 of file storage32.c.

3766 {
3767  IStorage *stg = NULL;
3768  HRESULT r;
3769  IStream *stm = NULL;
3770  static const WCHAR stmname[] = { 'C','O','N','T','E','N','T','S',0 };
3771  static const WCHAR stmname2[] = { 'C','O','N','T','E','N','T','2',0 };
3773  ULARGE_INTEGER upos;
3774  char buffer[4096];
3775  DWORD orig_size, new_size;
3776  ULONG bytesread;
3777  HANDLE hfile;
3778  int i;
3779 
3781 
3783  ok(r==S_OK, "StgCreateDocfile failed %x\n", r);
3784 
3785  r = WriteClassStg(stg, &test_stg_cls);
3786  ok(r == S_OK, "WriteClassStg failed %x\n", r);
3787 
3788  r = IStorage_CreateStream(stg, stmname, STGM_SHARE_EXCLUSIVE | STGM_READWRITE, 0, 0, &stm);
3789  ok(r==S_OK, "IStorage->CreateStream failed %x\n", r);
3790 
3791  pos.QuadPart = 0;
3792  r = IStream_Seek(stm, pos, STREAM_SEEK_SET, &upos);
3793  ok(r==S_OK, "IStream->Seek failed %x\n", r);
3794 
3795  memset(buffer, 'a', sizeof(buffer));
3796  for (i=0; i<4; i++)
3797  {
3798  /* Write enough bytes to pass the minimum storage file size */
3799  r = IStream_Write(stm, buffer, sizeof(buffer), NULL);
3800  ok(r==S_OK, "IStream->Write failed %x\n", r);
3801  }
3802 
3803  r = IStorage_Commit(stg, STGC_DEFAULT);
3804  ok(r==S_OK, "IStorage->Commit failed %x\n", r);
3805 
3807  NULL, OPEN_EXISTING, 0, NULL);
3808  ok(hfile != NULL, "couldn't open file %d\n", GetLastError());
3809 
3810  orig_size = GetFileSize(hfile, NULL);
3811 
3812  pos.QuadPart = 0;
3813  r = IStream_Seek(stm, pos, STREAM_SEEK_SET, &upos);
3814  ok(r==S_OK, "IStream->Seek failed %x\n", r);
3815 
3816  r = IStream_Write(stm, "b", 1, NULL);
3817  ok(r==S_OK, "IStream->Write failed %x\n", r);
3818 
3819  r = IStorage_Commit(stg, STGC_OVERWRITE);
3820  ok(r==S_OK, "IStorage->Commit failed %x\n", r);
3821 
3822  new_size = GetFileSize(hfile, NULL);
3823 
3824  todo_wine ok(new_size == orig_size, "file grew from %d bytes to %d\n", orig_size, new_size);
3825 
3826  IStream_Release(stm);
3827 
3828  IStorage_RenameElement(stg, stmname, stmname2);
3829 
3830  r = IStorage_Commit(stg, STGC_OVERWRITE);
3831  ok(r==S_OK, "IStorage->Commit failed %x\n", r);
3832 
3833  new_size = GetFileSize(hfile, NULL);
3834 
3835  todo_wine ok(new_size == orig_size, "file grew from %d bytes to %d\n", orig_size, new_size);
3836 
3837  IStorage_Release(stg);
3838 
3840  ok(r==S_OK, "StgOpenStorage failed %x\n", r);
3841 
3842  r = IStorage_OpenStream(stg, stmname2, NULL, STGM_SHARE_EXCLUSIVE | STGM_READWRITE, 0, &stm);
3843  ok(r==S_OK, "IStorage->CreateStream failed %x\n", r);
3844 
3845  r = IStream_Read(stm, buffer, sizeof(buffer), &bytesread);
3846  ok(r==S_OK, "IStream->Write failed %x\n", r);
3847  ok(bytesread == sizeof(buffer), "only read %d bytes\n", bytesread);
3848  ok(buffer[0] == 'b', "unexpected data at byte 0\n");
3849 
3850  for (i=1; i<sizeof(buffer); i++)
3851  if (buffer[i] != 'a')
3852  break;
3853  ok(i == sizeof(buffer), "unexpected data at byte %i\n", i);
3854 
3855  pos.QuadPart = 0;
3856  r = IStream_Seek(stm, pos, STREAM_SEEK_SET, &upos);
3857  ok(r==S_OK, "IStream->Seek failed %x\n", r);
3858 
3859  r = IStream_Write(stm, "c", 1, NULL);
3860  ok(r==S_OK, "IStream->Write failed %x\n", r);
3861 
3862  r = IStorage_Commit(stg, STGC_OVERWRITE);
3863  ok(r==S_OK, "IStorage->Commit failed %x\n", r);
3864 
3865  new_size = GetFileSize(hfile, NULL);
3866 
3867  todo_wine ok(new_size == orig_size, "file grew from %d bytes to %d\n", orig_size, new_size);
3868 
3869  IStream_Release(stm);
3870 
3871  IStorage_Release(stg);
3872 
3873  CloseHandle(hfile);
3874 
3876 }
#define CloseHandle
Definition: compat.h:398
#define STGM_SHARE_EXCLUSIVE
Definition: objbase.h:922
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
#define STGM_CREATE
Definition: objbase.h:925
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
GLuint buffer
Definition: glext.h:5915
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
const char * filename
Definition: ioapi.h:135
#define FILE_SHARE_READ
Definition: compat.h:125
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
#define OPEN_EXISTING
Definition: compat.h:426
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:77
HRESULT WINAPI StgOpenStorage(const OLECHAR *pwcsName, IStorage *pstgPriority, DWORD grfMode, SNB snbExclude, DWORD reserved, IStorage **ppstgOpen)
Definition: storage32.c:8756
unsigned long DWORD
Definition: ntddk_ex.h:95
static CHAR filenameA[MAX_PATH]
Definition: storage32.c:42
DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh)
Definition: fileinfo.c:481
#define FILE_SHARE_DELETE
Definition: nt_native.h:682
#define todo_wine
Definition: test.h:154
HRESULT WINAPI StgCreateDocfile(LPCOLESTR pwcsName, DWORD grfMode, DWORD reserved, IStorage **ppstgOpen)
Definition: storage32.c:8637
#define GENERIC_READ
Definition: compat.h:124
#define STGM_READWRITE
Definition: objbase.h:918
HRESULT WINAPI WriteClassStg(IStorage *pStg, REFCLSID rclsid)
Definition: storage32.c:9079
#define S_OK
Definition: intsafe.h:59
#define ok(value,...)
Definition: atltest.h:57
unsigned int ULONG
Definition: retypes.h:1
#define STGM_TRANSACTED
Definition: objbase.h:914
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:399
#define memset(x, y, z)
Definition: compat.h:39

Referenced by START_TEST().

◆ test_parent_free()

static void test_parent_free ( void  )
static

Definition at line 1784 of file storage32.c.

1785 {
1786  IStorage *stg = NULL, *stg2 = NULL, *stg3 = NULL;
1787  HRESULT r;
1788  IStream *stm = NULL;
1789  static const WCHAR stmname[] = { 'C','O','N','T','E','N','T','S',0 };
1790  static const WCHAR stgname[] = { 'P','E','R','M','S','T','G',0 };
1791  ULONG ref;
1792  STATSTG statstg;
1793  BOOL ret;
1794 
1796 
1797  /* create the file */
1799  STGM_READWRITE |STGM_TRANSACTED, 0, &stg);
1800  ok(r==S_OK, "StgCreateDocfile failed\n");
1801 
1802  /* create a new storage */
1803  r = IStorage_CreateStorage(stg, stgname, STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &stg2);
1804  ok(r==S_OK, "IStorage->CreateStorage failed, hr=%08x\n", r);
1805 
1806  if (r == S_OK)
1807  {
1808  /* now create a stream inside the new storage */
1809  r = IStorage_CreateStream(stg2, stmname, STGM_SHARE_EXCLUSIVE | STGM_READWRITE, 0, 0, &stm );
1810  ok(r==S_OK, "IStorage->CreateStream failed\n");
1811 
1812  if (r == S_OK)
1813  {
1814  /* create a storage inside the new storage */
1815  r = IStorage_CreateStorage(stg2, stgname, STGM_SHARE_EXCLUSIVE | STGM_READWRITE, 0, 0, &stg3 );
1816  ok(r==S_OK, "IStorage->CreateStorage failed\n");
1817  }
1818 
1819  /* free the parent */
1820  ref = IStorage_Release(stg2);
1821  ok(ref == 0, "IStorage still has %u references\n", ref);
1822 
1823  /* child objects are invalid */
1824  if (r == S_OK)
1825  {
1826  r = IStream_Write(stm, "this should fail\n", 17, NULL);
1827  ok(r==STG_E_REVERTED, "IStream->Write should fail, hr=%x\n", r);
1828 
1829  IStream_Release(stm);
1830 
1831  r = IStorage_Stat(stg3, &statstg, STATFLAG_NONAME);
1832  ok(r==STG_E_REVERTED, "IStorage_Stat should fail %08x\n", r);
1833 
1834  r = IStorage_SetStateBits(stg3, 1, 1);
1835  ok(r==STG_E_REVERTED, "IStorage_Stat should fail %08x\n", r);
1836 
1837  IStorage_Release(stg3);
1838  }
1839  }
1840 
1841  IStorage_Release(stg);
1842 
1844  ok(ret, "deleted file\n");
1845 }
#define STGM_SHARE_EXCLUSIVE
Definition: objbase.h:922
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
#define STGM_CREATE
Definition: objbase.h:925
const char * filename
Definition: ioapi.h:135
Definition: send.c:47
unsigned int BOOL
Definition: ntddk_ex.h:94
GLenum GLint ref
Definition: glext.h:6028
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:77
static CHAR filenameA[MAX_PATH]
Definition: storage32.c:42
int ret
HRESULT WINAPI StgCreateDocfile(LPCOLESTR pwcsName, DWORD grfMode, DWORD reserved, IStorage **ppstgOpen)
Definition: storage32.c:8637
#define STGM_READWRITE
Definition: objbase.h:918
#define S_OK
Definition: intsafe.h:59
#define STG_E_REVERTED
Definition: winerror.h:2590
#define ok(value,...)
Definition: atltest.h:57
unsigned int ULONG
Definition: retypes.h:1
#define STGM_TRANSACTED
Definition: objbase.h:914

Referenced by START_TEST().

◆ test_ReadClassStm()

static void test_ReadClassStm ( void  )
static

Definition at line 1968 of file storage32.c.

1969 {
1970  CLSID clsid, clsid2;
1971  HRESULT hr;
1972  IStream *pStream;
1973  static const LARGE_INTEGER llZero;
1974 
1975  hr = ReadClassStm(NULL, &clsid);
1976  ok(hr == E_INVALIDARG, "ReadClassStm should have returned E_INVALIDARG instead of 0x%08x\n", hr);
1977 
1978  hr = CreateStreamOnHGlobal(NULL, TRUE, &pStream);
1979  ok_ole_success(hr, "CreateStreamOnHGlobal");
1980  hr = WriteClassStm(pStream, &test_stg_cls);
1981  ok_ole_success(hr, "WriteClassStm");
1982 
1983  hr = ReadClassStm(pStream, NULL);
1984  ok(hr == E_INVALIDARG, "ReadClassStm should have returned E_INVALIDARG instead of 0x%08x\n", hr);
1985 
1986  memset(&clsid, 0xcc, sizeof(clsid));
1987  memset(&clsid2, 0xcc, sizeof(clsid2));
1988  hr = ReadClassStm(NULL, &clsid);
1989  ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
1990  ok(IsEqualCLSID(&clsid, &clsid2), "got wrong clsid\n");
1991 
1992  /* test not rewound stream */
1993  hr = ReadClassStm(pStream, &clsid);
1994  ok(hr == STG_E_READFAULT, "ReadClassStm should have returned STG_E_READFAULT instead of 0x%08x\n", hr);
1995  ok(IsEqualCLSID(&clsid, &CLSID_NULL), "clsid should have been zeroed\n");
1996 
1997  hr = IStream_Seek(pStream, llZero, STREAM_SEEK_SET, NULL);
1998  ok_ole_success(hr, "IStream_Seek");
1999  hr = ReadClassStm(pStream, &clsid);
2000  ok_ole_success(hr, "ReadClassStm");
2001  ok(IsEqualCLSID(&clsid, &test_stg_cls), "clsid should have been set to CLSID_WineTest\n");
2002 
2003  IStream_Release(pStream);
2004 }
#define TRUE
Definition: types.h:120
HRESULT hr
Definition: shlfolder.c:183
HRESULT WINAPI CreateStreamOnHGlobal(HGLOBAL hGlobal, BOOL fDeleteOnRelease, LPSTREAM *ppstm)
#define E_INVALIDARG
Definition: ddrawi.h:101
HRESULT WINAPI WriteClassStm(IStream *pStm, REFCLSID rclsid)
Definition: storage32.c:9526
smooth NULL
Definition: ftsmooth.c:416
static const LARGE_INTEGER llZero
Definition: moniker.c:1113
#define ok_ole_success(hr, func)
Definition: storage32.c:40
#define CLSID_NULL
Definition: guiddef.h:99
LONG HRESULT
Definition: typedefs.h:77
REFCLSID clsid
Definition: msctf.c:84
HRESULT WINAPI ReadClassStm(IStream *pStm, CLSID *pclsid)
Definition: storage32.c:9549
#define ok(value,...)
Definition: atltest.h:57
#define STG_E_READFAULT
Definition: winerror.h:2576
#define memset(x, y, z)
Definition: compat.h:39
#define IsEqualCLSID(rclsid1, rclsid2)
Definition: guiddef.h:96

Referenced by START_TEST().

◆ test_readonly()

static void test_readonly ( void  )
static

Definition at line 2239 of file storage32.c.

2240 {
2241  IStorage *stg, *stg2, *stg3;
2242  IStream *stream;
2243  HRESULT hr;
2244  static const WCHAR fileW[] = {'w','i','n','e','t','e','s','t',0};
2245  static const WCHAR storageW[] = {'s','t','o','r','a','g','e',0};
2246  static const WCHAR streamW[] = {'s','t','r','e','a','m',0};
2247 
2249  ok(hr == S_OK, "should succeed, res=%x\n", hr);
2250  if (SUCCEEDED(hr))
2251  {
2252  hr = IStorage_CreateStorage( stg, storageW, STGM_CREATE | STGM_SHARE_EXCLUSIVE | STGM_READWRITE, 0, 0, &stg2 );
2253  ok(hr == S_OK, "should succeed, res=%x\n", hr);
2254  if (SUCCEEDED(hr))
2255  {
2256  hr = IStorage_CreateStream( stg2, streamW, STGM_CREATE | STGM_SHARE_EXCLUSIVE | STGM_READWRITE, 0, 0, &stream );
2257  ok(hr == S_OK, "should succeed, res=%x\n", hr);
2258  if (SUCCEEDED(hr))
2259  IStream_Release(stream);
2260  IStorage_Release(stg2);
2261  }
2262  IStorage_Release(stg);
2263  }
2264 
2265  /* re-open read only */
2267  ok(hr == S_OK, "should succeed, res=%x\n", hr);
2268  if (SUCCEEDED(hr))
2269  {
2270  hr = IStorage_OpenStorage( stg, storageW, NULL, STGM_SHARE_EXCLUSIVE | STGM_READ, NULL, 0, &stg2 );
2271  ok(hr == S_OK, "should succeed, res=%x\n", hr);
2272  if (SUCCEEDED(hr))
2273  {
2274  /* CreateStream on read-only storage, name exists */
2275  hr = IStorage_CreateStream( stg2, streamW, STGM_CREATE | STGM_SHARE_EXCLUSIVE | STGM_READ, 0, 0, &stream );
2276  ok(hr == STG_E_ACCESSDENIED, "should fail, res=%x\n", hr);
2277  if (SUCCEEDED(hr))
2278  IStream_Release(stream);
2279 
2280  /* CreateStream on read-only storage, name does not exist */
2281  hr = IStorage_CreateStream( stg2, storageW, STGM_CREATE | STGM_SHARE_EXCLUSIVE | STGM_READ, 0, 0, &stream );
2282  ok(hr == STG_E_ACCESSDENIED, "should fail, res=%x\n", hr);
2283  if (SUCCEEDED(hr))
2284  IStream_Release(stream);
2285 
2286  /* CreateStorage on read-only storage, name exists */
2287  hr = IStorage_CreateStorage( stg2, streamW, STGM_CREATE | STGM_SHARE_EXCLUSIVE | STGM_READ, 0, 0, &stg3 );
2288  ok(hr == STG_E_FILEALREADYEXISTS, "should fail, res=%x\n", hr);
2289  if (SUCCEEDED(hr))
2290  IStorage_Release(stg3);
2291 
2292  /* CreateStorage on read-only storage, name does not exist */
2293  hr = IStorage_CreateStorage( stg2, storageW, STGM_CREATE | STGM_SHARE_EXCLUSIVE | STGM_READ, 0, 0, &stg3 );
2294  ok(hr == STG_E_ACCESSDENIED, "should fail, res=%x\n", hr);
2295  if (SUCCEEDED(hr))
2296  IStorage_Release(stg3);
2297 
2298  /* DestroyElement on read-only storage, name exists */
2299  hr = IStorage_DestroyElement( stg2, streamW );
2300  ok(hr == STG_E_ACCESSDENIED, "should fail, res=%x\n", hr);
2301 
2302  /* DestroyElement on read-only storage, name does not exist */
2303  hr = IStorage_DestroyElement( stg2, storageW );
2304  ok(hr == STG_E_ACCESSDENIED, "should fail, res=%x\n", hr);
2305 
2306  IStorage_Release(stg2);
2307  }
2308 
2309  IStorage_Release(stg);
2310  }
2311 
2312  DeleteFileA("winetest");
2313 }
#define STGM_SHARE_DENY_NONE
Definition: objbase.h:919
HRESULT hr
Definition: shlfolder.c:183
#define STGM_SHARE_EXCLUSIVE
Definition: objbase.h:922
#define STGM_CREATE
Definition: objbase.h:925
#define STG_E_ACCESSDENIED
Definition: winerror.h:2568
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
#define STGM_READ
Definition: objbase.h:916
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:77
#define STG_E_FILEALREADYEXISTS
Definition: winerror.h:2579
HRESULT WINAPI StgOpenStorage(const OLECHAR *pwcsName, IStorage *pstgPriority, DWORD grfMode, SNB snbExclude, DWORD reserved, IStorage **ppstgOpen)
Definition: storage32.c:8756
Definition: parse.h:22
GLuint GLuint stream
Definition: glext.h:7522
HRESULT WINAPI StgCreateDocfile(LPCOLESTR pwcsName, DWORD grfMode, DWORD reserved, IStorage **ppstgOpen)
Definition: storage32.c:8637
#define STGM_READWRITE
Definition: objbase.h:918
#define S_OK
Definition: intsafe.h:59
#define ok(value,...)
Definition: atltest.h:57
#define STGM_TRANSACTED
Definition: objbase.h:914
static const WCHAR fileW[]
Definition: url.c:111
#define SUCCEEDED(hr)
Definition: intsafe.h:57

Referenced by START_TEST().

◆ test_references()

static void test_references ( void  )
static

Definition at line 2504 of file storage32.c.

2505 {
2506  IStorage *stg,*stg2;
2507  HRESULT hr;
2508  unsigned c1,c2;
2509  static const WCHAR StorName[] = { 'D','a','t','a','S','p','a','c','e','I','n','f','o',0 };
2510 
2512 
2514  ok(hr==S_OK, "StgCreateDocfile failed\n");
2515 
2516  if (SUCCEEDED(hr))
2517  {
2518  IStorage_Release(stg);
2519 
2521  ok(hr==S_OK, "StgOpenStorage failed (result=%x)\n",hr);
2522 
2523  if (SUCCEEDED(hr))
2524  {
2525  hr = IStorage_CreateStorage(stg,StorName,STGM_READWRITE | STGM_SHARE_EXCLUSIVE,0,0,&stg2);
2526  ok(hr == S_OK, "IStorage_CreateStorage failed (result=%x)\n",hr);
2527 
2528  if (SUCCEEDED(hr))
2529  {
2530  c1 = IStorage_AddRef(stg);
2531  ok(c1 == 2, "creating internal storage added references to ancestor\n");
2532  c1 = IStorage_AddRef(stg);
2533  IStorage_Release(stg2);
2534  c2 = IStorage_AddRef(stg) - 1;
2535  ok(c1 == c2, "releasing internal storage removed references to ancestor\n");
2536  }
2537  c1 = IStorage_Release(stg);
2538  while ( c1 ) c1 = IStorage_Release(stg);
2539  }
2540  }
2541 
2543 }
HRESULT hr
Definition: shlfolder.c:183
#define STGM_SHARE_EXCLUSIVE
Definition: objbase.h:922
#define STGM_CREATE
Definition: objbase.h:925
const char * filename
Definition: ioapi.h:135
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:77
HRESULT WINAPI StgOpenStorage(const OLECHAR *pwcsName, IStorage *pstgPriority, DWORD grfMode, SNB snbExclude, DWORD reserved, IStorage **ppstgOpen)
Definition: storage32.c:8756
static CHAR filenameA[MAX_PATH]
Definition: storage32.c:42
HRESULT WINAPI StgCreateDocfile(LPCOLESTR pwcsName, DWORD grfMode, DWORD reserved, IStorage **ppstgOpen)
Definition: storage32.c:8637
#define STGM_READWRITE
Definition: objbase.h:918
#define S_OK
Definition: intsafe.h:59
#define ok(value,...)
Definition: atltest.h:57
#define STGM_TRANSACTED
Definition: objbase.h:914
#define SUCCEEDED(hr)
Definition: intsafe.h:57

Referenced by START_TEST().

◆ test_rename()

static void test_rename ( void  )
static

Definition at line 2950 of file storage32.c.

2951 {
2952  IStorage *stg, *stg2;
2953  IStream *stm;
2954  HRESULT r;
2955  static const WCHAR stgname[] = { 'P','E','R','M','S','T','G',0 };
2956  static const WCHAR stgname2[] = { 'S','T','G',0 };
2957  static const WCHAR stmname[] = { 'C','O','N','T','E','N','T','S',0 };
2958  static const WCHAR stmname2[] = { 'E','N','T','S',0 };
2959  BOOL ret;
2960 
2962 
2963  /* create the file */
2965  STGM_READWRITE, 0, &stg);
2966  ok(r==S_OK, "StgCreateDocfile failed\n");
2967 
2968  /* create a substorage */
2969  r = IStorage_CreateStorage(stg, stgname, STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &stg2);
2970  ok(r==S_OK, "IStorage->CreateStorage failed, hr=%08x\n", r);
2971 
2972  /* create a stream in the substorage */
2973  r = IStorage_CreateStream(stg2, stmname, STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &stm);
2974  ok(r==S_OK, "IStorage->CreateStream failed, hr=%08x\n", r);
2975  IStream_Release(stm);
2976 
2977  /* rename the stream */
2978  r = IStorage_RenameElement(stg2, stmname, stmname2);
2979  ok(r==S_OK,