2008-03-24 11:07:13 +01:00
|
|
|
/* Unit test suite for SHLWAPI ShCreateStreamOnFile functions.
|
|
|
|
*
|
|
|
|
* Copyright 2008 Reece H. Dunn
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "wine/test.h"
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "objbase.h"
|
|
|
|
#include "shlwapi.h"
|
|
|
|
|
2008-03-27 10:34:15 +01:00
|
|
|
static void test_IStream_invalid_operations(IStream * stream, DWORD mode)
|
|
|
|
{
|
|
|
|
HRESULT ret;
|
|
|
|
IStream * clone;
|
|
|
|
ULONG refcount;
|
|
|
|
ULARGE_INTEGER uzero;
|
|
|
|
ULARGE_INTEGER uret;
|
|
|
|
LARGE_INTEGER zero;
|
|
|
|
ULONG count;
|
|
|
|
char data[256];
|
|
|
|
|
|
|
|
U(uzero).HighPart = 0;
|
|
|
|
U(uzero).LowPart = 0;
|
|
|
|
U(uret).HighPart = 0;
|
|
|
|
U(uret).LowPart = 0;
|
|
|
|
U(zero).HighPart = 0;
|
|
|
|
U(zero).LowPart = 0;
|
|
|
|
|
|
|
|
/* IStream::Read */
|
|
|
|
|
|
|
|
/* IStream_Read from the COBJMACROS is undefined by shlwapi.h, replaced by the IStream_Read helper function. */
|
|
|
|
|
|
|
|
ret = stream->lpVtbl->Read(stream, NULL, 0, &count);
|
|
|
|
ok(ret == S_OK, "expected S_OK, got 0x%08x\n", ret);
|
|
|
|
|
|
|
|
ret = stream->lpVtbl->Read(stream, data, 5, NULL);
|
|
|
|
ok(ret == S_FALSE || ret == S_OK, "expected S_FALSE or S_OK, got 0x%08x\n", ret);
|
|
|
|
|
|
|
|
ret = stream->lpVtbl->Read(stream, data, 0, NULL);
|
|
|
|
ok(ret == S_OK, "expected S_OK, got 0x%08x\n", ret);
|
|
|
|
|
|
|
|
ret = stream->lpVtbl->Read(stream, data, 3, &count);
|
|
|
|
ok(ret == S_FALSE || ret == S_OK, "expected S_FALSE or S_OK, got 0x%08x\n", ret);
|
|
|
|
|
|
|
|
/* IStream::Write */
|
|
|
|
|
|
|
|
/* IStream_Write from the COBJMACROS is undefined by shlwapi.h, replaced by the IStream_Write helper function. */
|
|
|
|
|
|
|
|
ret = stream->lpVtbl->Write(stream, NULL, 0, &count);
|
|
|
|
if (mode == STGM_READ)
|
2013-09-23 09:54:34 +02:00
|
|
|
{
|
|
|
|
ok(ret == STG_E_ACCESSDENIED /* XP */ || broken(ret == S_OK) /* Win2000 + IE5 */,
|
|
|
|
"expected STG_E_ACCESSDENIED, got 0x%08x\n", ret);
|
|
|
|
}
|
2008-03-27 10:34:15 +01:00
|
|
|
else
|
|
|
|
ok(ret == S_OK, "expected S_OK, got 0x%08x\n", ret);
|
|
|
|
|
|
|
|
strcpy(data, "Hello");
|
|
|
|
ret = stream->lpVtbl->Write(stream, data, 5, NULL);
|
|
|
|
if (mode == STGM_READ)
|
2013-09-23 09:54:34 +02:00
|
|
|
ok(ret == STG_E_ACCESSDENIED,
|
|
|
|
"expected STG_E_ACCESSDENIED, got 0x%08x\n", ret);
|
2008-03-27 10:34:15 +01:00
|
|
|
else
|
|
|
|
ok(ret == S_OK, "expected S_OK, got 0x%08x\n", ret);
|
|
|
|
|
|
|
|
strcpy(data, "Hello");
|
|
|
|
ret = stream->lpVtbl->Write(stream, data, 0, NULL);
|
|
|
|
if (mode == STGM_READ)
|
2013-09-23 09:54:34 +02:00
|
|
|
ok(ret == STG_E_ACCESSDENIED,
|
|
|
|
"expected STG_E_ACCESSDENIED, got 0x%08x\n", ret);
|
2008-03-27 10:34:15 +01:00
|
|
|
else
|
|
|
|
ok(ret == S_OK, "expected S_OK, got 0x%08x\n", ret);
|
|
|
|
|
|
|
|
strcpy(data, "Hello");
|
|
|
|
ret = stream->lpVtbl->Write(stream, data, 0, &count);
|
|
|
|
if (mode == STGM_READ)
|
2013-09-23 09:54:34 +02:00
|
|
|
ok(ret == STG_E_ACCESSDENIED,
|
|
|
|
"expected STG_E_ACCESSDENIED, got 0x%08x\n", ret);
|
2008-03-27 10:34:15 +01:00
|
|
|
else
|
|
|
|
ok(ret == S_OK, "expected S_OK, got 0x%08x\n", ret);
|
|
|
|
|
|
|
|
strcpy(data, "Hello");
|
|
|
|
ret = stream->lpVtbl->Write(stream, data, 3, &count);
|
|
|
|
if (mode == STGM_READ)
|
2013-09-23 09:54:34 +02:00
|
|
|
ok(ret == STG_E_ACCESSDENIED,
|
|
|
|
"expected STG_E_ACCESSDENIED, got 0x%08x\n", ret);
|
2008-03-27 10:34:15 +01:00
|
|
|
else
|
|
|
|
ok(ret == S_OK, "expected S_OK, got 0x%08x\n", ret);
|
|
|
|
|
|
|
|
/* IStream::Seek */
|
|
|
|
|
|
|
|
ret = IStream_Seek(stream, zero, STREAM_SEEK_SET, NULL);
|
|
|
|
ok(ret == S_OK, "expected S_OK, got 0x%08x\n", ret);
|
|
|
|
|
|
|
|
ret = IStream_Seek(stream, zero, 20, NULL);
|
2013-09-23 09:54:34 +02:00
|
|
|
ok(ret == E_INVALIDARG,
|
|
|
|
"expected E_INVALIDARG, got 0x%08x\n", ret);
|
2008-03-27 10:34:15 +01:00
|
|
|
|
|
|
|
/* IStream::CopyTo */
|
|
|
|
|
|
|
|
ret = IStream_CopyTo(stream, NULL, uzero, &uret, &uret);
|
|
|
|
ok(ret == S_OK, "expected S_OK, got 0x%08x\n", ret);
|
|
|
|
|
|
|
|
clone = NULL;
|
|
|
|
ret = IStream_CopyTo(stream, clone, uzero, &uret, &uret);
|
|
|
|
ok(ret == S_OK, "expected S_OK, got 0x%08x\n", ret);
|
|
|
|
|
|
|
|
ret = IStream_CopyTo(stream, stream, uzero, &uret, &uret);
|
|
|
|
ok(ret == S_OK, "expected S_OK, got 0x%08x\n", ret);
|
|
|
|
|
|
|
|
ret = IStream_CopyTo(stream, stream, uzero, &uret, NULL);
|
|
|
|
ok(ret == S_OK, "expected S_OK, got 0x%08x\n", ret);
|
|
|
|
|
|
|
|
ret = IStream_CopyTo(stream, stream, uzero, NULL, &uret);
|
|
|
|
ok(ret == S_OK, "expected S_OK, got 0x%08x\n", ret);
|
|
|
|
|
|
|
|
/* IStream::Commit */
|
|
|
|
|
|
|
|
ret = IStream_Commit(stream, STGC_DEFAULT);
|
|
|
|
ok(ret == S_OK, "expected S_OK, got 0x%08x\n", ret);
|
|
|
|
|
|
|
|
/* IStream::Revert */
|
|
|
|
|
|
|
|
ret = IStream_Revert(stream);
|
|
|
|
ok(ret == E_NOTIMPL, "expected E_NOTIMPL, got 0x%08x\n", ret);
|
|
|
|
|
|
|
|
/* IStream::LockRegion */
|
|
|
|
|
|
|
|
ret = IStream_LockRegion(stream, uzero, uzero, 0);
|
|
|
|
ok(ret == E_NOTIMPL /* XP */ || ret == S_OK /* Vista */,
|
|
|
|
"expected E_NOTIMPL or S_OK, got 0x%08x\n", ret);
|
|
|
|
|
|
|
|
/* IStream::UnlockRegion */
|
|
|
|
|
|
|
|
if (ret == E_NOTIMPL) /* XP */ {
|
|
|
|
ret = IStream_UnlockRegion(stream, uzero, uzero, 0);
|
|
|
|
ok(ret == E_NOTIMPL, "expected E_NOTIMPL, got 0x%08x\n", ret);
|
|
|
|
} else /* Vista */ {
|
|
|
|
ret = IStream_UnlockRegion(stream, uzero, uzero, 0);
|
|
|
|
ok(ret == S_OK, "expected S_OK, got 0x%08x\n", ret);
|
|
|
|
|
|
|
|
ret = IStream_UnlockRegion(stream, uzero, uzero, 0);
|
|
|
|
ok(ret == STG_E_LOCKVIOLATION, "expected STG_E_LOCKVIOLATION, got 0x%08x\n", ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* IStream::Stat */
|
|
|
|
|
|
|
|
ret = IStream_Stat(stream, NULL, 0);
|
2013-09-23 09:54:34 +02:00
|
|
|
ok(ret == STG_E_INVALIDPOINTER,
|
2008-04-18 22:03:29 +02:00
|
|
|
"expected STG_E_INVALIDPOINTER or E_NOTIMPL, got 0x%08x\n", ret);
|
2008-03-27 10:34:15 +01:00
|
|
|
|
|
|
|
/* IStream::Clone */
|
|
|
|
|
2009-08-24 21:24:05 +02:00
|
|
|
/* Passing a NULL pointer for the second IStream::Clone param crashes on Win7 */
|
2008-03-27 10:34:15 +01:00
|
|
|
|
|
|
|
clone = NULL;
|
|
|
|
ret = IStream_Clone(stream, &clone);
|
|
|
|
ok(ret == E_NOTIMPL, "expected E_NOTIMPL, got 0x%08x\n", ret);
|
|
|
|
ok(clone == NULL, "expected a NULL IStream object, got %p\n", stream);
|
|
|
|
|
|
|
|
if (clone) {
|
|
|
|
refcount = IStream_Release(clone);
|
|
|
|
ok(refcount == 0, "expected 0, got %d\n", refcount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-16 10:26:20 +02:00
|
|
|
static void test_stream_read_write(IStream *stream, DWORD mode)
|
|
|
|
{
|
|
|
|
static const LARGE_INTEGER start;
|
|
|
|
HRESULT ret;
|
|
|
|
unsigned char buf[16];
|
|
|
|
DWORD written, count;
|
2018-09-03 06:20:11 +02:00
|
|
|
STATSTG statstg;
|
2013-09-16 10:26:20 +02:00
|
|
|
|
|
|
|
/* IStream_Read/Write from the COBJMACROS is undefined by shlwapi.h */
|
|
|
|
|
|
|
|
written = 0xdeadbeaf;
|
|
|
|
ret = stream->lpVtbl->Write(stream, "\x5e\xa7", 2, &written);
|
|
|
|
if (mode == STGM_WRITE || mode == STGM_READWRITE)
|
|
|
|
{
|
|
|
|
ok(ret == S_OK, "IStream_Write error %#x (access %#x)\n", ret, mode);
|
|
|
|
ok(written == 2, "expected 2, got %u\n", written);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ok(ret == STG_E_ACCESSDENIED || broken(ret == S_OK) /* win2000 */, "expected STG_E_ACCESSDENIED, got %#x (access %#x)\n", ret, mode);
|
|
|
|
ok(written == 0xdeadbeaf || broken(written == 2) /* win2000 */, "expected 0xdeadbeaf, got %#x\n", written);
|
|
|
|
written = 0;
|
|
|
|
if (ret == S_OK) return; /* no point in further testing */
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = stream->lpVtbl->Seek(stream, start, STREAM_SEEK_SET, NULL);
|
|
|
|
ok(ret == S_OK, "Seek error %#x\n", ret);
|
|
|
|
|
|
|
|
count = 0xdeadbeaf;
|
|
|
|
ret = stream->lpVtbl->Read(stream, buf, 2, &count);
|
|
|
|
if (written != 0)
|
|
|
|
{
|
2013-09-19 09:09:41 +02:00
|
|
|
ok(ret == S_OK || broken(ret == S_FALSE) /* win2000 */, "IStream_Read error %#x (access %#x, written %u)\n", ret, mode, written);
|
|
|
|
if (ret == S_OK && (mode == STGM_WRITE || mode == STGM_READWRITE))
|
2013-09-16 10:26:20 +02:00
|
|
|
{
|
|
|
|
ok(count == 2, "expected 2, got %u\n", count);
|
|
|
|
ok(buf[0] == 0x5e && buf[1] == 0xa7, "expected 5ea7, got %02x%02x\n", buf[0], buf[1]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ok(count == 0, "expected 0, got %u\n", count);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ok(ret == S_FALSE, "expected S_FALSE, got %#x (access %#x, written %u)\n", ret, mode, written);
|
|
|
|
ok(count == 0, "expected 0, got %u\n", count);
|
|
|
|
}
|
|
|
|
|
2016-04-25 22:39:04 +02:00
|
|
|
ret = stream->lpVtbl->Seek(stream, start, STREAM_SEEK_SET, NULL);
|
|
|
|
ok(ret == S_OK, "Seek error %#x\n", ret);
|
|
|
|
|
|
|
|
count = 0xdeadbeaf;
|
|
|
|
ret = stream->lpVtbl->Read(stream, buf, 0, &count);
|
|
|
|
ok(ret == S_OK, "IStream_Read error %#x (access %#x, written %u)\n", ret, mode, written);
|
|
|
|
ok(count == 0, "expected 0, got %u\n", count);
|
|
|
|
|
|
|
|
count = 0xdeadbeaf;
|
|
|
|
ret = stream->lpVtbl->Read(stream, buf, sizeof(buf), &count);
|
|
|
|
ok(ret == S_FALSE, "expected S_FALSE, got %#x (access %#x, written %u)\n", ret, mode, written);
|
|
|
|
ok(count == written, "expected %u, got %u\n", written, count);
|
|
|
|
if (count)
|
|
|
|
ok(buf[0] == 0x5e && buf[1] == 0xa7, "expected 5ea7, got %02x%02x\n", buf[0], buf[1]);
|
2018-09-03 06:20:11 +02:00
|
|
|
|
|
|
|
memset(&statstg, 0xff, sizeof(statstg));
|
|
|
|
ret = IStream_Stat(stream, &statstg, 0);
|
|
|
|
ok(ret == S_OK, "Stat failed, hr %#x.\n", ret);
|
|
|
|
ok(statstg.pwcsName != NULL, "Unexpected name %s.\n", wine_dbgstr_w(statstg.pwcsName));
|
|
|
|
CoTaskMemFree(statstg.pwcsName);
|
|
|
|
|
|
|
|
memset(&statstg, 0xff, sizeof(statstg));
|
|
|
|
ret = IStream_Stat(stream, &statstg, STATFLAG_NONAME);
|
|
|
|
ok(ret == S_OK, "Stat failed, hr %#x.\n", ret);
|
|
|
|
ok(statstg.pwcsName == NULL, "Unexpected name %s.\n", wine_dbgstr_w(statstg.pwcsName));
|
2013-09-16 10:26:20 +02:00
|
|
|
}
|
|
|
|
|
2018-08-31 00:35:55 +02:00
|
|
|
static void test_stream_qi(IStream *stream)
|
|
|
|
{
|
|
|
|
IUnknown *unk;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = IStream_QueryInterface(stream, &IID_IStream, (void **)&unk);
|
|
|
|
ok(SUCCEEDED(hr), "Failed to get IStream interface, hr %#x.\n", hr);
|
|
|
|
IUnknown_Release(unk);
|
|
|
|
|
|
|
|
unk = NULL;
|
|
|
|
hr = IStream_QueryInterface(stream, &IID_ISequentialStream, (void **)&unk);
|
|
|
|
ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* XP */, "Failed to get ISequentialStream interface, hr %#x.\n", hr);
|
|
|
|
if (unk)
|
|
|
|
IUnknown_Release(unk);
|
|
|
|
|
|
|
|
hr = IStream_QueryInterface(stream, &IID_IUnknown, (void **)&unk);
|
|
|
|
ok(SUCCEEDED(hr), "Failed to get IUnknown interface, hr %#x.\n", hr);
|
|
|
|
IUnknown_Release(unk);
|
|
|
|
}
|
|
|
|
|
2008-04-13 15:05:07 +02:00
|
|
|
static void test_SHCreateStreamOnFileA(DWORD mode, DWORD stgm)
|
2008-03-24 11:07:13 +01:00
|
|
|
{
|
|
|
|
IStream * stream;
|
|
|
|
HRESULT ret;
|
|
|
|
ULONG refcount;
|
2008-06-06 13:20:26 +02:00
|
|
|
char test_file[MAX_PATH];
|
|
|
|
static const CHAR testA_txt[] = "\\testA.txt";
|
2008-03-24 11:07:13 +01:00
|
|
|
|
2008-04-13 15:05:07 +02:00
|
|
|
trace("SHCreateStreamOnFileA: testing mode %d, STGM flags %08x\n", mode, stgm);
|
2008-03-24 11:07:13 +01:00
|
|
|
|
2008-06-06 13:20:26 +02:00
|
|
|
/* Don't used a fixed path for the testA.txt file */
|
|
|
|
GetTempPathA(MAX_PATH, test_file);
|
|
|
|
lstrcatA(test_file, testA_txt);
|
|
|
|
|
2008-03-24 11:07:13 +01:00
|
|
|
/* invalid arguments */
|
|
|
|
|
|
|
|
stream = NULL;
|
2017-03-30 16:23:27 +02:00
|
|
|
ret = SHCreateStreamOnFileA(NULL, mode | stgm, &stream);
|
2010-02-23 08:39:05 +01:00
|
|
|
if (ret == E_INVALIDARG) /* Win98 SE */ {
|
|
|
|
win_skip("Not supported\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ok(ret == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) /* NT */ ||
|
|
|
|
ret == HRESULT_FROM_WIN32(ERROR_BAD_PATHNAME) /* 9x */,
|
|
|
|
"SHCreateStreamOnFileA: expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) "
|
|
|
|
"or HRESULT_FROM_WIN32(ERROR_BAD_PATHNAME), got 0x%08x\n", ret);
|
2008-03-24 11:07:13 +01:00
|
|
|
ok(stream == NULL, "SHCreateStreamOnFileA: expected a NULL IStream object, got %p\n", stream);
|
|
|
|
|
2014-01-24 23:07:39 +01:00
|
|
|
if (0) /* This test crashes on WinXP SP2 */
|
|
|
|
{
|
2017-03-30 16:23:27 +02:00
|
|
|
ret = SHCreateStreamOnFileA(test_file, mode | stgm, NULL);
|
2008-03-24 11:07:13 +01:00
|
|
|
ok(ret == E_INVALIDARG, "SHCreateStreamOnFileA: expected E_INVALIDARG, got 0x%08x\n", ret);
|
2014-01-24 23:07:39 +01:00
|
|
|
}
|
2008-03-24 11:07:13 +01:00
|
|
|
|
|
|
|
stream = NULL;
|
2017-03-30 16:23:27 +02:00
|
|
|
ret = SHCreateStreamOnFileA(test_file, mode | STGM_CONVERT | stgm, &stream);
|
2008-03-24 11:07:13 +01:00
|
|
|
ok(ret == E_INVALIDARG, "SHCreateStreamOnFileA: expected E_INVALIDARG, got 0x%08x\n", ret);
|
|
|
|
ok(stream == NULL, "SHCreateStreamOnFileA: expected a NULL IStream object, got %p\n", stream);
|
|
|
|
|
|
|
|
stream = NULL;
|
2017-03-30 16:23:27 +02:00
|
|
|
ret = SHCreateStreamOnFileA(test_file, mode | STGM_DELETEONRELEASE | stgm, &stream);
|
2008-03-24 11:07:13 +01:00
|
|
|
ok(ret == E_INVALIDARG, "SHCreateStreamOnFileA: expected E_INVALIDARG, got 0x%08x\n", ret);
|
|
|
|
ok(stream == NULL, "SHCreateStreamOnFileA: expected a NULL IStream object, got %p\n", stream);
|
|
|
|
|
2008-03-26 22:03:07 +01:00
|
|
|
stream = NULL;
|
2017-03-30 16:23:27 +02:00
|
|
|
ret = SHCreateStreamOnFileA(test_file, mode | STGM_TRANSACTED | stgm, &stream);
|
2008-03-26 22:03:07 +01:00
|
|
|
ok(ret == E_INVALIDARG, "SHCreateStreamOnFileA: expected E_INVALIDARG, got 0x%08x\n", ret);
|
|
|
|
ok(stream == NULL, "SHCreateStreamOnFileA: expected a NULL IStream object, got %p\n", stream);
|
|
|
|
|
2008-03-24 11:07:13 +01:00
|
|
|
/* file does not exist */
|
|
|
|
|
|
|
|
stream = NULL;
|
2017-03-30 16:23:27 +02:00
|
|
|
ret = SHCreateStreamOnFileA(test_file, mode | STGM_FAILIFTHERE | stgm, &stream);
|
2008-03-24 11:07:13 +01:00
|
|
|
ok(ret == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "SHCreateStreamOnFileA: expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got 0x%08x\n", ret);
|
|
|
|
ok(stream == NULL, "SHCreateStreamOnFileA: expected a NULL IStream object, got %p\n", stream);
|
|
|
|
|
|
|
|
stream = NULL;
|
2017-03-30 16:23:27 +02:00
|
|
|
ret = SHCreateStreamOnFileA(test_file, mode | STGM_CREATE | stgm, &stream);
|
2008-03-24 11:07:13 +01:00
|
|
|
ok(ret == S_OK, "SHCreateStreamOnFileA: expected S_OK, got 0x%08x\n", ret);
|
|
|
|
ok(stream != NULL, "SHCreateStreamOnFileA: expected a valid IStream object, got NULL\n");
|
|
|
|
|
|
|
|
if (stream) {
|
2018-08-31 00:35:55 +02:00
|
|
|
test_stream_qi(stream);
|
2008-03-27 10:34:15 +01:00
|
|
|
test_IStream_invalid_operations(stream, mode);
|
|
|
|
|
2008-03-24 11:07:13 +01:00
|
|
|
refcount = IStream_Release(stream);
|
|
|
|
ok(refcount == 0, "SHCreateStreamOnFileA: expected 0, got %d\n", refcount);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* NOTE: don't delete the file, as it will be used for the file exists tests. */
|
|
|
|
|
|
|
|
/* file exists */
|
|
|
|
|
|
|
|
stream = NULL;
|
2017-03-30 16:23:27 +02:00
|
|
|
ret = SHCreateStreamOnFileA(test_file, mode | STGM_FAILIFTHERE | stgm, &stream);
|
2008-03-24 11:07:13 +01:00
|
|
|
ok(ret == S_OK, "SHCreateStreamOnFileA: expected S_OK, got 0x%08x\n", ret);
|
|
|
|
ok(stream != NULL, "SHCreateStreamOnFileA: expected a valid IStream object, got NULL\n");
|
|
|
|
|
|
|
|
if (stream) {
|
2008-03-27 10:34:15 +01:00
|
|
|
test_IStream_invalid_operations(stream, mode);
|
|
|
|
|
2008-03-24 11:07:13 +01:00
|
|
|
refcount = IStream_Release(stream);
|
|
|
|
ok(refcount == 0, "SHCreateStreamOnFileA: expected 0, got %d\n", refcount);
|
|
|
|
}
|
|
|
|
|
|
|
|
stream = NULL;
|
2017-03-30 16:23:27 +02:00
|
|
|
ret = SHCreateStreamOnFileA(test_file, mode | STGM_CREATE | stgm, &stream);
|
2008-03-24 11:07:13 +01:00
|
|
|
ok(ret == S_OK, "SHCreateStreamOnFileA: expected S_OK, got 0x%08x\n", ret);
|
|
|
|
ok(stream != NULL, "SHCreateStreamOnFileA: expected a valid IStream object, got NULL\n");
|
|
|
|
|
|
|
|
if (stream) {
|
2010-12-29 20:23:27 +01:00
|
|
|
BOOL delret;
|
2013-09-16 10:26:20 +02:00
|
|
|
|
|
|
|
test_stream_read_write(stream, mode);
|
2008-03-27 10:34:15 +01:00
|
|
|
test_IStream_invalid_operations(stream, mode);
|
|
|
|
|
2008-03-24 11:07:13 +01:00
|
|
|
refcount = IStream_Release(stream);
|
|
|
|
ok(refcount == 0, "SHCreateStreamOnFileA: expected 0, got %d\n", refcount);
|
|
|
|
|
2010-12-29 20:23:27 +01:00
|
|
|
delret = DeleteFileA(test_file);
|
|
|
|
ok(delret, "SHCreateStreamOnFileA: could not delete file '%s', got error %d\n",
|
|
|
|
test_file, GetLastError());
|
2008-03-24 11:07:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-13 15:05:07 +02:00
|
|
|
static void test_SHCreateStreamOnFileW(DWORD mode, DWORD stgm)
|
2008-03-24 11:09:55 +01:00
|
|
|
{
|
|
|
|
IStream * stream;
|
|
|
|
HRESULT ret;
|
|
|
|
ULONG refcount;
|
2008-06-06 13:20:26 +02:00
|
|
|
WCHAR test_file[MAX_PATH];
|
2008-08-03 22:08:23 +02:00
|
|
|
CHAR test_fileA[MAX_PATH];
|
|
|
|
static const CHAR testW_txt[] = "\\testW.txt";
|
2008-03-24 11:09:55 +01:00
|
|
|
|
2008-04-13 15:05:07 +02:00
|
|
|
trace("SHCreateStreamOnFileW: testing mode %d, STGM flags %08x\n", mode, stgm);
|
2008-03-24 11:09:55 +01:00
|
|
|
|
2008-06-06 13:20:26 +02:00
|
|
|
/* Don't used a fixed path for the testW.txt file */
|
2008-08-03 22:08:23 +02:00
|
|
|
GetTempPathA(MAX_PATH, test_fileA);
|
|
|
|
lstrcatA(test_fileA, testW_txt);
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, test_fileA, -1, test_file, MAX_PATH);
|
2008-06-06 13:20:26 +02:00
|
|
|
|
2008-03-24 11:09:55 +01:00
|
|
|
/* invalid arguments */
|
|
|
|
|
2008-10-08 17:28:54 +02:00
|
|
|
if (0)
|
|
|
|
{
|
|
|
|
/* Crashes on NT4 */
|
|
|
|
stream = NULL;
|
2017-03-30 16:23:27 +02:00
|
|
|
ret = SHCreateStreamOnFileW(NULL, mode | stgm, &stream);
|
2008-10-08 17:28:54 +02:00
|
|
|
ok(ret == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) || /* XP */
|
|
|
|
ret == E_INVALIDARG /* Vista */,
|
|
|
|
"SHCreateStreamOnFileW: expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) or E_INVALIDARG, got 0x%08x\n", ret);
|
|
|
|
ok(stream == NULL, "SHCreateStreamOnFileW: expected a NULL IStream object, got %p\n", stream);
|
|
|
|
}
|
2008-03-24 11:09:55 +01:00
|
|
|
|
2008-10-08 17:28:54 +02:00
|
|
|
if (0)
|
|
|
|
{
|
|
|
|
/* This test crashes on WinXP SP2 */
|
2017-03-30 16:23:27 +02:00
|
|
|
ret = SHCreateStreamOnFileW(test_file, mode | stgm, NULL);
|
2008-10-08 17:28:54 +02:00
|
|
|
ok(ret == E_INVALIDARG, "SHCreateStreamOnFileW: expected E_INVALIDARG, got 0x%08x\n", ret);
|
|
|
|
}
|
2008-03-24 11:09:55 +01:00
|
|
|
|
|
|
|
stream = NULL;
|
2017-03-30 16:23:27 +02:00
|
|
|
ret = SHCreateStreamOnFileW(test_file, mode | STGM_CONVERT | stgm, &stream);
|
2008-03-24 11:09:55 +01:00
|
|
|
ok(ret == E_INVALIDARG, "SHCreateStreamOnFileW: expected E_INVALIDARG, got 0x%08x\n", ret);
|
|
|
|
ok(stream == NULL, "SHCreateStreamOnFileW: expected a NULL IStream object, got %p\n", stream);
|
|
|
|
|
|
|
|
stream = NULL;
|
2017-03-30 16:23:27 +02:00
|
|
|
ret = SHCreateStreamOnFileW(test_file, mode | STGM_DELETEONRELEASE | stgm, &stream);
|
2008-03-24 11:09:55 +01:00
|
|
|
ok(ret == E_INVALIDARG, "SHCreateStreamOnFileW: expected E_INVALIDARG, got 0x%08x\n", ret);
|
|
|
|
ok(stream == NULL, "SHCreateStreamOnFileW: expected a NULL IStream object, got %p\n", stream);
|
|
|
|
|
2008-03-26 22:03:07 +01:00
|
|
|
stream = NULL;
|
2017-03-30 16:23:27 +02:00
|
|
|
ret = SHCreateStreamOnFileW(test_file, mode | STGM_TRANSACTED | stgm, &stream);
|
2008-03-26 22:03:07 +01:00
|
|
|
ok(ret == E_INVALIDARG, "SHCreateStreamOnFileW: expected E_INVALIDARG, got 0x%08x\n", ret);
|
|
|
|
ok(stream == NULL, "SHCreateStreamOnFileW: expected a NULL IStream object, got %p\n", stream);
|
|
|
|
|
2008-03-24 11:09:55 +01:00
|
|
|
/* file does not exist */
|
|
|
|
|
|
|
|
stream = NULL;
|
2017-03-30 16:23:27 +02:00
|
|
|
ret = SHCreateStreamOnFileW(test_file, mode | STGM_FAILIFTHERE | stgm, &stream);
|
2010-02-23 08:39:05 +01:00
|
|
|
if (ret == E_INVALIDARG) /* Win98 SE */ {
|
|
|
|
win_skip("Not supported\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-03-24 11:09:55 +01:00
|
|
|
ok(ret == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "SHCreateStreamOnFileW: expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got 0x%08x\n", ret);
|
|
|
|
ok(stream == NULL, "SHCreateStreamOnFileW: expected a NULL IStream object, got %p\n", stream);
|
|
|
|
|
|
|
|
stream = NULL;
|
2017-03-30 16:23:27 +02:00
|
|
|
ret = SHCreateStreamOnFileW(test_file, mode | STGM_CREATE | stgm, &stream);
|
2008-03-24 11:09:55 +01:00
|
|
|
ok(ret == S_OK, "SHCreateStreamOnFileW: expected S_OK, got 0x%08x\n", ret);
|
|
|
|
ok(stream != NULL, "SHCreateStreamOnFileW: expected a valid IStream object, got NULL\n");
|
|
|
|
|
|
|
|
if (stream) {
|
2018-08-31 00:35:55 +02:00
|
|
|
test_stream_qi(stream);
|
2008-03-27 10:34:15 +01:00
|
|
|
test_IStream_invalid_operations(stream, mode);
|
|
|
|
|
2008-03-24 11:09:55 +01:00
|
|
|
refcount = IStream_Release(stream);
|
|
|
|
ok(refcount == 0, "SHCreateStreamOnFileW: expected 0, got %d\n", refcount);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* NOTE: don't delete the file, as it will be used for the file exists tests. */
|
|
|
|
|
|
|
|
/* file exists */
|
|
|
|
|
|
|
|
stream = NULL;
|
2017-03-30 16:23:27 +02:00
|
|
|
ret = SHCreateStreamOnFileW(test_file, mode | STGM_FAILIFTHERE | stgm, &stream);
|
2008-03-24 11:09:55 +01:00
|
|
|
ok(ret == S_OK, "SHCreateStreamOnFileW: expected S_OK, got 0x%08x\n", ret);
|
|
|
|
ok(stream != NULL, "SHCreateStreamOnFileW: expected a valid IStream object, got NULL\n");
|
|
|
|
|
|
|
|
if (stream) {
|
2008-03-27 10:34:15 +01:00
|
|
|
test_IStream_invalid_operations(stream, mode);
|
|
|
|
|
2008-03-24 11:09:55 +01:00
|
|
|
refcount = IStream_Release(stream);
|
|
|
|
ok(refcount == 0, "SHCreateStreamOnFileW: expected 0, got %d\n", refcount);
|
|
|
|
}
|
|
|
|
|
|
|
|
stream = NULL;
|
2017-03-30 16:23:27 +02:00
|
|
|
ret = SHCreateStreamOnFileW(test_file, mode | STGM_CREATE | stgm, &stream);
|
2008-03-24 11:09:55 +01:00
|
|
|
ok(ret == S_OK, "SHCreateStreamOnFileW: expected S_OK, got 0x%08x\n", ret);
|
|
|
|
ok(stream != NULL, "SHCreateStreamOnFileW: expected a valid IStream object, got NULL\n");
|
|
|
|
|
|
|
|
if (stream) {
|
2010-12-29 20:23:27 +01:00
|
|
|
BOOL delret;
|
2013-09-16 10:26:20 +02:00
|
|
|
|
|
|
|
test_stream_read_write(stream, mode);
|
2008-03-27 10:34:15 +01:00
|
|
|
test_IStream_invalid_operations(stream, mode);
|
|
|
|
|
2008-03-24 11:09:55 +01:00
|
|
|
refcount = IStream_Release(stream);
|
|
|
|
ok(refcount == 0, "SHCreateStreamOnFileW: expected 0, got %d\n", refcount);
|
|
|
|
|
2010-12-29 20:23:27 +01:00
|
|
|
delret = DeleteFileA(test_fileA);
|
|
|
|
ok(delret, "SHCreateStreamOnFileW: could not delete the test file, got error %d\n",
|
|
|
|
GetLastError());
|
2008-03-24 11:09:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-24 11:11:28 +01:00
|
|
|
static void test_SHCreateStreamOnFileEx(DWORD mode, DWORD stgm)
|
|
|
|
{
|
|
|
|
IStream * stream;
|
|
|
|
IStream * template = NULL;
|
|
|
|
HRESULT ret;
|
|
|
|
ULONG refcount;
|
2008-06-11 08:32:35 +02:00
|
|
|
WCHAR test_file[MAX_PATH];
|
2008-08-03 22:08:23 +02:00
|
|
|
CHAR test_fileA[MAX_PATH];
|
|
|
|
static const CHAR testEx_txt[] = "\\testEx.txt";
|
2010-12-29 20:23:27 +01:00
|
|
|
BOOL delret;
|
2008-03-24 11:11:28 +01:00
|
|
|
|
2015-05-12 12:38:35 +02:00
|
|
|
if (winetest_debug > 1)
|
|
|
|
trace("SHCreateStreamOnFileEx: testing mode %d, STGM flags %08x\n", mode, stgm);
|
2008-03-24 11:11:28 +01:00
|
|
|
|
2008-06-11 08:32:35 +02:00
|
|
|
/* Don't used a fixed path for the testEx.txt file */
|
2008-08-03 22:08:23 +02:00
|
|
|
GetTempPathA(MAX_PATH, test_fileA);
|
|
|
|
lstrcatA(test_fileA, testEx_txt);
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, test_fileA, -1, test_file, MAX_PATH);
|
2008-06-11 08:32:35 +02:00
|
|
|
|
2008-03-24 11:11:28 +01:00
|
|
|
/* invalid arguments */
|
|
|
|
|
2008-10-08 17:28:54 +02:00
|
|
|
if (0)
|
|
|
|
{
|
|
|
|
/* Crashes on NT4 */
|
|
|
|
stream = NULL;
|
2017-03-30 16:23:27 +02:00
|
|
|
ret = SHCreateStreamOnFileEx(NULL, mode, 0, FALSE, NULL, &stream);
|
2008-10-08 17:28:54 +02:00
|
|
|
ok(ret == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) || /* XP */
|
|
|
|
ret == E_INVALIDARG /* Vista */,
|
|
|
|
"SHCreateStreamOnFileEx: expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) or E_INVALIDARG, got 0x%08x\n", ret);
|
|
|
|
ok(stream == NULL, "SHCreateStreamOnFileEx: expected a NULL IStream object, got %p\n", stream);
|
|
|
|
}
|
2008-03-24 11:11:28 +01:00
|
|
|
|
|
|
|
stream = NULL;
|
2017-03-30 16:23:27 +02:00
|
|
|
ret = SHCreateStreamOnFileEx(test_file, mode, 0, FALSE, template, &stream);
|
2010-03-16 19:21:08 +01:00
|
|
|
if (ret == HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED)) {
|
|
|
|
win_skip("File probably locked by Anti-Virus/Spam software, trying again\n");
|
|
|
|
Sleep(1000);
|
2017-03-30 16:23:27 +02:00
|
|
|
ret = SHCreateStreamOnFileEx(test_file, mode, 0, FALSE, template, &stream);
|
2010-03-16 19:21:08 +01:00
|
|
|
}
|
2008-08-03 22:08:23 +02:00
|
|
|
ok( ret == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) ||
|
|
|
|
ret == HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER),
|
|
|
|
"SHCreateStreamOnFileEx: expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) or "
|
|
|
|
"HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER), got 0x%08x\n", ret);
|
|
|
|
|
2008-03-24 11:11:28 +01:00
|
|
|
ok(stream == NULL, "SHCreateStreamOnFileEx: expected a NULL IStream object, got %p\n", stream);
|
|
|
|
|
2008-10-08 17:28:54 +02:00
|
|
|
if (0)
|
|
|
|
{
|
|
|
|
/* This test crashes on WinXP SP2 */
|
2017-03-30 16:23:27 +02:00
|
|
|
ret = SHCreateStreamOnFileEx(test_file, mode, 0, FALSE, NULL, NULL);
|
2008-10-08 17:28:54 +02:00
|
|
|
ok(ret == E_INVALIDARG, "SHCreateStreamOnFileEx: expected E_INVALIDARG, got 0x%08x\n", ret);
|
|
|
|
}
|
2008-03-24 11:11:28 +01:00
|
|
|
|
|
|
|
/* file does not exist */
|
|
|
|
|
|
|
|
stream = NULL;
|
2017-03-30 16:23:27 +02:00
|
|
|
ret = SHCreateStreamOnFileEx(test_file, mode | STGM_FAILIFTHERE | stgm, 0, FALSE, NULL, &stream);
|
2008-03-26 22:03:07 +01:00
|
|
|
if ((stgm & STGM_TRANSACTED) == STGM_TRANSACTED && mode == STGM_READ) {
|
|
|
|
ok(ret == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) /* XP */ || ret == E_INVALIDARG /* Vista */,
|
|
|
|
"SHCreateStreamOnFileEx: expected E_INVALIDARG or HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got 0x%08x\n", ret);
|
|
|
|
|
|
|
|
if (ret == E_INVALIDARG) {
|
2008-04-02 16:51:11 +02:00
|
|
|
skip("SHCreateStreamOnFileEx: STGM_TRANSACTED not supported in this configuration.\n");
|
2008-03-26 22:03:07 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
2008-08-03 22:08:23 +02:00
|
|
|
ok( ret == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) ||
|
|
|
|
ret == HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER),
|
|
|
|
"SHCreateStreamOnFileEx: expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) or "
|
|
|
|
"HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER), got 0x%08x\n", ret);
|
2008-03-26 22:03:07 +01:00
|
|
|
}
|
2008-03-24 11:11:28 +01:00
|
|
|
ok(stream == NULL, "SHCreateStreamOnFileEx: expected a NULL IStream object, got %p\n", stream);
|
|
|
|
|
|
|
|
stream = NULL;
|
2017-03-30 16:23:27 +02:00
|
|
|
ret = SHCreateStreamOnFileEx(test_file, mode | STGM_FAILIFTHERE | stgm, 0, TRUE, NULL, &stream);
|
2008-08-03 22:08:23 +02:00
|
|
|
/* not supported on win9x */
|
|
|
|
if (broken(ret == HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER) && stream == NULL)) {
|
|
|
|
skip("Not supported\n");
|
|
|
|
DeleteFileA(test_fileA);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-03-24 11:11:28 +01:00
|
|
|
ok(ret == S_OK, "SHCreateStreamOnFileEx: expected S_OK, got 0x%08x\n", ret);
|
|
|
|
ok(stream != NULL, "SHCreateStreamOnFileEx: expected a valid IStream object, got NULL\n");
|
|
|
|
|
|
|
|
if (stream) {
|
2018-08-31 00:35:55 +02:00
|
|
|
test_stream_qi(stream);
|
2008-03-27 10:34:15 +01:00
|
|
|
test_IStream_invalid_operations(stream, mode);
|
|
|
|
|
2008-03-24 11:11:28 +01:00
|
|
|
refcount = IStream_Release(stream);
|
|
|
|
ok(refcount == 0, "SHCreateStreamOnFileEx: expected 0, got %d\n", refcount);
|
|
|
|
|
2010-12-29 20:23:27 +01:00
|
|
|
delret = DeleteFileA(test_fileA);
|
|
|
|
ok(delret, "SHCreateStreamOnFileEx: could not delete the test file, got error %d\n",
|
|
|
|
GetLastError());
|
2008-03-24 11:11:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
stream = NULL;
|
2017-03-30 16:23:27 +02:00
|
|
|
ret = SHCreateStreamOnFileEx(test_file, mode | STGM_CREATE | stgm, 0, FALSE, NULL, &stream);
|
2010-03-16 19:21:08 +01:00
|
|
|
if (ret == HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED)) {
|
|
|
|
win_skip("File probably locked by Anti-Virus/Spam software, trying again\n");
|
|
|
|
Sleep(1000);
|
2017-03-30 16:23:27 +02:00
|
|
|
ret = SHCreateStreamOnFileEx(test_file, mode | STGM_CREATE | stgm, 0, FALSE, NULL, &stream);
|
2010-03-16 19:21:08 +01:00
|
|
|
}
|
2008-03-24 11:11:28 +01:00
|
|
|
ok(ret == S_OK, "SHCreateStreamOnFileEx: expected S_OK, got 0x%08x\n", ret);
|
|
|
|
ok(stream != NULL, "SHCreateStreamOnFileEx: expected a valid IStream object, got NULL\n");
|
|
|
|
|
|
|
|
if (stream) {
|
2008-03-27 10:34:15 +01:00
|
|
|
test_IStream_invalid_operations(stream, mode);
|
|
|
|
|
2008-03-24 11:11:28 +01:00
|
|
|
refcount = IStream_Release(stream);
|
|
|
|
ok(refcount == 0, "SHCreateStreamOnFileEx: expected 0, got %d\n", refcount);
|
|
|
|
|
2010-12-29 20:23:27 +01:00
|
|
|
delret = DeleteFileA(test_fileA);
|
|
|
|
ok(delret, "SHCreateStreamOnFileEx: could not delete the test file, got error %d\n",
|
|
|
|
GetLastError());
|
2008-03-24 11:11:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
stream = NULL;
|
2017-03-30 16:23:27 +02:00
|
|
|
ret = SHCreateStreamOnFileEx(test_file, mode | STGM_CREATE | stgm, 0, TRUE, NULL, &stream);
|
2010-03-16 19:21:08 +01:00
|
|
|
if (ret == HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED)) {
|
|
|
|
win_skip("File probably locked by Anti-Virus/Spam software, trying again\n");
|
|
|
|
Sleep(1000);
|
2017-03-30 16:23:27 +02:00
|
|
|
ret = SHCreateStreamOnFileEx(test_file, mode | STGM_CREATE | stgm, 0, TRUE, NULL, &stream);
|
2010-03-16 19:21:08 +01:00
|
|
|
}
|
2008-03-24 11:11:28 +01:00
|
|
|
ok(ret == S_OK, "SHCreateStreamOnFileEx: expected S_OK, got 0x%08x\n", ret);
|
|
|
|
ok(stream != NULL, "SHCreateStreamOnFileEx: expected a valid IStream object, got NULL\n");
|
|
|
|
|
|
|
|
if (stream) {
|
2008-03-27 10:34:15 +01:00
|
|
|
test_IStream_invalid_operations(stream, mode);
|
|
|
|
|
2008-03-24 11:11:28 +01:00
|
|
|
refcount = IStream_Release(stream);
|
|
|
|
ok(refcount == 0, "SHCreateStreamOnFileEx: expected 0, got %d\n", refcount);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* NOTE: don't delete the file, as it will be used for the file exists tests. */
|
|
|
|
|
|
|
|
/* file exists */
|
|
|
|
|
|
|
|
stream = NULL;
|
2017-03-30 16:23:27 +02:00
|
|
|
ret = SHCreateStreamOnFileEx(test_file, mode | STGM_FAILIFTHERE | stgm, 0, FALSE, NULL, &stream);
|
2008-03-24 11:11:28 +01:00
|
|
|
ok(ret == S_OK, "SHCreateStreamOnFileEx: expected S_OK, got 0x%08x\n", ret);
|
|
|
|
ok(stream != NULL, "SHCreateStreamOnFileEx: expected a valid IStream object, got NULL\n");
|
|
|
|
|
|
|
|
if (stream) {
|
2008-03-27 10:34:15 +01:00
|
|
|
test_IStream_invalid_operations(stream, mode);
|
|
|
|
|
2008-03-24 11:11:28 +01:00
|
|
|
refcount = IStream_Release(stream);
|
|
|
|
ok(refcount == 0, "SHCreateStreamOnFileEx: expected 0, got %d\n", refcount);
|
|
|
|
}
|
|
|
|
|
|
|
|
stream = NULL;
|
2017-03-30 16:23:27 +02:00
|
|
|
ret = SHCreateStreamOnFileEx(test_file, mode | STGM_FAILIFTHERE | stgm, 0, TRUE, NULL, &stream);
|
2008-03-24 11:11:28 +01:00
|
|
|
ok(ret == HRESULT_FROM_WIN32(ERROR_FILE_EXISTS), "SHCreateStreamOnFileEx: expected HRESULT_FROM_WIN32(ERROR_FILE_EXISTS), got 0x%08x\n", ret);
|
|
|
|
ok(stream == NULL, "SHCreateStreamOnFileEx: expected a NULL IStream object, got %p\n", stream);
|
|
|
|
|
|
|
|
stream = NULL;
|
2017-03-30 16:23:27 +02:00
|
|
|
ret = SHCreateStreamOnFileEx(test_file, mode | STGM_CREATE | stgm, 0, FALSE, NULL, &stream);
|
2008-03-24 11:11:28 +01:00
|
|
|
ok(ret == S_OK, "SHCreateStreamOnFileEx: expected S_OK, got 0x%08x\n", ret);
|
|
|
|
ok(stream != NULL, "SHCreateStreamOnFileEx: expected a valid IStream object, got NULL\n");
|
|
|
|
|
|
|
|
if (stream) {
|
2008-03-27 10:34:15 +01:00
|
|
|
test_IStream_invalid_operations(stream, mode);
|
|
|
|
|
2008-03-24 11:11:28 +01:00
|
|
|
refcount = IStream_Release(stream);
|
|
|
|
ok(refcount == 0, "SHCreateStreamOnFileEx: expected 0, got %d\n", refcount);
|
|
|
|
}
|
|
|
|
|
|
|
|
stream = NULL;
|
2017-03-30 16:23:27 +02:00
|
|
|
ret = SHCreateStreamOnFileEx(test_file, mode | STGM_CREATE | stgm, 0, TRUE, NULL, &stream);
|
2008-03-24 11:11:28 +01:00
|
|
|
ok(ret == S_OK, "SHCreateStreamOnFileEx: expected S_OK, got 0x%08x\n", ret);
|
|
|
|
ok(stream != NULL, "SHCreateStreamOnFileEx: expected a valid IStream object, got NULL\n");
|
|
|
|
|
|
|
|
if (stream) {
|
2008-03-27 10:34:15 +01:00
|
|
|
test_IStream_invalid_operations(stream, mode);
|
|
|
|
|
2008-03-24 11:11:28 +01:00
|
|
|
refcount = IStream_Release(stream);
|
|
|
|
ok(refcount == 0, "SHCreateStreamOnFileEx: expected 0, got %d\n", refcount);
|
|
|
|
}
|
|
|
|
|
2010-12-29 20:23:27 +01:00
|
|
|
delret = DeleteFileA(test_fileA);
|
|
|
|
ok(delret, "SHCreateStreamOnFileEx: could not delete the test file, got error %d\n",
|
|
|
|
GetLastError());
|
2008-03-24 11:11:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-08 19:41:17 +01:00
|
|
|
static void test_SHCreateStreamOnFileEx_CopyTo(void)
|
2013-10-29 15:00:53 +01:00
|
|
|
{
|
|
|
|
HRESULT ret;
|
|
|
|
IStream *src, *dst;
|
|
|
|
WCHAR tmpPath[MAX_PATH];
|
|
|
|
WCHAR srcFileName[MAX_PATH];
|
|
|
|
WCHAR dstFileName[MAX_PATH];
|
|
|
|
ULARGE_INTEGER count, read, written;
|
|
|
|
LARGE_INTEGER distance;
|
|
|
|
static const char srcContents[1];
|
|
|
|
static const WCHAR prefix[] = { 'T', 'S', 'T', 0 };
|
|
|
|
|
|
|
|
GetTempPathW(MAX_PATH, tmpPath);
|
2018-01-08 09:19:29 +01:00
|
|
|
ret = GetTempFileNameW(tmpPath, prefix, 0, srcFileName);
|
|
|
|
ok(ret != 0, "GetTempFileName failed, got error %d\n", GetLastError());
|
|
|
|
ret = GetTempFileNameW(tmpPath, prefix, 0, dstFileName);
|
|
|
|
ok(ret != 0, "GetTempFileName failed, got error %d\n", GetLastError());
|
2013-10-29 15:00:53 +01:00
|
|
|
|
2017-03-30 16:23:27 +02:00
|
|
|
ret = SHCreateStreamOnFileEx(srcFileName, STGM_CREATE | STGM_READWRITE | STGM_DELETEONRELEASE, FILE_ATTRIBUTE_TEMPORARY, FALSE, NULL, &src);
|
2013-10-29 15:00:53 +01:00
|
|
|
ok(SUCCEEDED(ret), "SHCreateStreamOnFileEx failed with ret=0x%08x\n", ret);
|
|
|
|
|
|
|
|
written.QuadPart = 0;
|
2013-11-15 02:35:26 +01:00
|
|
|
ret = IStream_Write(src, srcContents, sizeof(srcContents), &U(written).LowPart);
|
2013-10-29 15:00:53 +01:00
|
|
|
ok(SUCCEEDED(ret), "ISequentialStream_Write failed with ret=0x%08x\n", ret);
|
|
|
|
|
|
|
|
distance.QuadPart = 0;
|
|
|
|
ret = IStream_Seek(src, distance, STREAM_SEEK_SET, &written);
|
|
|
|
ok(SUCCEEDED(ret), "ISequentialStream_Seek failed with ret=0x%08x\n", ret);
|
|
|
|
|
2017-03-30 16:23:27 +02:00
|
|
|
ret = SHCreateStreamOnFileEx(dstFileName, STGM_CREATE | STGM_READWRITE | STGM_DELETEONRELEASE, FILE_ATTRIBUTE_TEMPORARY, FALSE, NULL, &dst);
|
2013-10-29 15:00:53 +01:00
|
|
|
ok(SUCCEEDED(ret), "SHCreateStreamOnFileEx failed with ret=0x%08x\n", ret);
|
|
|
|
|
|
|
|
/* Test using a count larger than the source file, so that the Read operation will fall short */
|
|
|
|
count.QuadPart = 2;
|
|
|
|
|
|
|
|
ret = IStream_CopyTo(src, dst, count, &read, &written);
|
|
|
|
ok(SUCCEEDED(ret), "CopyTo failed with ret=0x%08x\n", ret);
|
|
|
|
|
2013-11-15 02:35:26 +01:00
|
|
|
ok(read.QuadPart == 1, "read does not match size: %d != 1\n", U(read).LowPart);
|
|
|
|
ok(written.QuadPart == 1, "written does not match size: %d != 1\n", U(written).LowPart);
|
2013-10-29 15:00:53 +01:00
|
|
|
|
|
|
|
IStream_Release(dst);
|
|
|
|
IStream_Release(src);
|
|
|
|
DeleteFileW( srcFileName );
|
|
|
|
DeleteFileW( dstFileName );
|
|
|
|
}
|
|
|
|
|
2018-09-07 13:55:59 +02:00
|
|
|
static void test_SHCreateMemStream(void)
|
|
|
|
{
|
|
|
|
static const BYTE initial[10];
|
|
|
|
IStream *stream, *stream2;
|
2020-11-27 00:21:24 +01:00
|
|
|
LARGE_INTEGER off;
|
2018-09-07 13:55:59 +02:00
|
|
|
IUnknown *unk;
|
|
|
|
char buff[10];
|
2020-11-27 00:21:24 +01:00
|
|
|
ULONG i, num;
|
2018-09-07 13:55:59 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
stream = SHCreateMemStream(initial, 0);
|
|
|
|
ok(stream != NULL, "Failed to create a stream.\n");
|
|
|
|
IStream_Release(stream);
|
|
|
|
|
|
|
|
stream = SHCreateMemStream(NULL, 10);
|
|
|
|
ok(stream != NULL, "Failed to create a stream.\n");
|
|
|
|
IStream_Release(stream);
|
|
|
|
|
|
|
|
stream = SHCreateMemStream(NULL, 0);
|
|
|
|
ok(stream != NULL, "Failed to create a stream.\n");
|
|
|
|
|
|
|
|
hr = IStream_QueryInterface(stream, &IID_ISequentialStream, (void **)&unk);
|
|
|
|
ok(hr == S_OK || broken(hr == E_NOINTERFACE) /* WinXP */, "Failed to QI, hr %#x.\n", hr);
|
|
|
|
if (unk)
|
|
|
|
IUnknown_Release(unk);
|
|
|
|
|
2020-11-27 00:21:24 +01:00
|
|
|
num = ~0;
|
|
|
|
hr = IStream_Read(stream, buff, sizeof(buff), &num);
|
|
|
|
ok(hr == S_FALSE, "Unexpected hr %#x.\n", hr);
|
|
|
|
ok(num == 0, "expected 0, got 0x%08x\n", num);
|
|
|
|
|
|
|
|
num = ~0;
|
|
|
|
memset(buff, 0x55, sizeof(buff));
|
|
|
|
hr = IStream_Write(stream, buff, sizeof(buff), &num);
|
|
|
|
ok(hr == S_OK, "Failed to write, hr %#x.\n", hr);
|
|
|
|
ok(num == sizeof(buff), "expected %u, got %u\n", sizeof(buff), num);
|
|
|
|
|
|
|
|
off.QuadPart = 0;
|
|
|
|
hr = IStream_Seek(stream, off, STREAM_SEEK_SET, NULL);
|
|
|
|
ok(hr == S_OK, "Failed to seek, hr %#x.\n", hr);
|
|
|
|
|
|
|
|
num = ~0;
|
|
|
|
memset(buff, 0, sizeof(buff));
|
|
|
|
hr = IStream_Read(stream, buff, sizeof(buff), &num);
|
|
|
|
ok(hr == S_OK, "Failed to read, hr %#x.\n", hr);
|
|
|
|
ok(num == sizeof(buff), "expected %u, got %u\n", sizeof(buff), num);
|
|
|
|
for (i = 0; i < ARRAY_SIZE(buff); i++)
|
|
|
|
ok(buff[i] == 0x55, "expected 0x55, got 0x%02x at %u\n", buff[i], i);
|
|
|
|
|
|
|
|
num = ~0;
|
|
|
|
hr = IStream_Read(stream, buff, sizeof(buff), &num);
|
|
|
|
ok(hr == S_FALSE, "Unexpected hr %#x.\n", hr);
|
|
|
|
ok(num == 0, "expected 0, got 0x%08x\n", num);
|
|
|
|
|
|
|
|
num = ~0;
|
|
|
|
memset(buff, 0x11, sizeof(buff));
|
|
|
|
hr = IStream_Write(stream, buff, sizeof(buff), &num);
|
|
|
|
ok(hr == S_OK, "Failed to write, hr %#x.\n", hr);
|
|
|
|
ok(num == sizeof(buff), "expected %u, got %u\n", sizeof(buff), num);
|
|
|
|
|
|
|
|
off.QuadPart = -sizeof(buff);
|
|
|
|
hr = IStream_Seek(stream, off, STREAM_SEEK_CUR, NULL);
|
|
|
|
ok(hr == S_OK, "Failed to seek, hr %#x.\n", hr);
|
|
|
|
|
|
|
|
num = ~0;
|
|
|
|
memset(buff, 0, sizeof(buff));
|
|
|
|
hr = IStream_Read(stream, buff, sizeof(buff), &num);
|
|
|
|
ok(hr == S_OK, "Failed to read, hr %#x.\n", hr);
|
|
|
|
ok(num == sizeof(buff), "expected %u, got %u\n", sizeof(buff), num);
|
|
|
|
for (i = 0; i < ARRAY_SIZE(buff); i++)
|
|
|
|
ok(buff[i] == 0x11, "expected 0x11, got 0x%02x at %u\n", buff[i], i);
|
|
|
|
|
|
|
|
num = ~0;
|
|
|
|
hr = IStream_Read(stream, buff, sizeof(buff), &num);
|
|
|
|
ok(hr == S_FALSE, "Unexpected hr %#x.\n", hr);
|
|
|
|
ok(num == 0, "expected 0, got 0x%08x\n", num);
|
2018-09-07 13:55:59 +02:00
|
|
|
|
|
|
|
hr = IStream_Clone(stream, &stream2);
|
|
|
|
todo_wine
|
|
|
|
ok(hr == S_OK || broken(hr == E_NOTIMPL) /* < Win8 */, "Failed to clone a stream, hr %#x.\n", hr);
|
|
|
|
if (hr == S_OK)
|
|
|
|
IStream_Release(stream2);
|
|
|
|
|
|
|
|
IStream_Release(stream);
|
|
|
|
}
|
2013-10-29 15:00:53 +01:00
|
|
|
|
2008-03-24 11:07:13 +01:00
|
|
|
START_TEST(istream)
|
|
|
|
{
|
2008-03-31 09:32:18 +02:00
|
|
|
static const DWORD stgm_access[] = {
|
|
|
|
STGM_READ,
|
|
|
|
STGM_WRITE,
|
|
|
|
STGM_READWRITE
|
|
|
|
};
|
|
|
|
|
2008-04-13 15:05:07 +02:00
|
|
|
static const DWORD stgm_sharing[] = {
|
|
|
|
0,
|
|
|
|
STGM_SHARE_DENY_NONE,
|
|
|
|
STGM_SHARE_DENY_READ,
|
|
|
|
STGM_SHARE_DENY_WRITE,
|
|
|
|
STGM_SHARE_EXCLUSIVE
|
|
|
|
};
|
|
|
|
|
2008-03-26 22:03:07 +01:00
|
|
|
static const DWORD stgm_flags[] = {
|
|
|
|
0,
|
|
|
|
STGM_CONVERT,
|
|
|
|
STGM_DELETEONRELEASE,
|
|
|
|
STGM_CONVERT | STGM_DELETEONRELEASE,
|
|
|
|
STGM_TRANSACTED | STGM_CONVERT,
|
|
|
|
STGM_TRANSACTED | STGM_DELETEONRELEASE,
|
|
|
|
STGM_TRANSACTED | STGM_CONVERT | STGM_DELETEONRELEASE
|
|
|
|
};
|
|
|
|
|
2008-04-13 15:05:07 +02:00
|
|
|
int i, j, k;
|
2008-03-31 09:32:18 +02:00
|
|
|
|
2018-06-26 22:44:25 +02:00
|
|
|
for (i = 0; i != ARRAY_SIZE(stgm_access); i++) {
|
|
|
|
for (j = 0; j != ARRAY_SIZE(stgm_sharing); j ++) {
|
2017-03-30 16:23:27 +02:00
|
|
|
test_SHCreateStreamOnFileA(stgm_access[i], stgm_sharing[j]);
|
|
|
|
test_SHCreateStreamOnFileW(stgm_access[i], stgm_sharing[j]);
|
2008-03-31 09:32:18 +02:00
|
|
|
|
2018-06-26 22:44:25 +02:00
|
|
|
for (k = 0; k != ARRAY_SIZE(stgm_flags); k++)
|
2017-03-30 16:23:27 +02:00
|
|
|
test_SHCreateStreamOnFileEx(stgm_access[i], stgm_sharing[j] | stgm_flags[k]);
|
2008-03-26 22:03:07 +01:00
|
|
|
}
|
2008-03-24 11:11:28 +01:00
|
|
|
}
|
2013-10-29 15:00:53 +01:00
|
|
|
|
2017-03-30 16:23:27 +02:00
|
|
|
test_SHCreateStreamOnFileEx_CopyTo();
|
2018-09-07 13:55:59 +02:00
|
|
|
test_SHCreateMemStream();
|
2008-03-24 11:07:13 +01:00
|
|
|
}
|