msxml3: Don't use stream written value when saving to stream.

This commit is contained in:
Nikolay Sivov 2012-07-07 12:13:08 +04:00 committed by Alexandre Julliard
parent 6c4465f4ac
commit 1a0552443c
2 changed files with 141 additions and 18 deletions

View File

@ -2328,13 +2328,14 @@ static int XMLCALL domdoc_stream_save_writecallback(void *ctx, const char *buffe
HRESULT hr;
hr = IStream_Write((IStream*)ctx, buffer, len, &written);
TRACE("0x%08x %p %d %u\n", hr, buffer, len, written);
if (hr != S_OK)
{
WARN("stream write error: 0x%08x\n", hr);
return -1;
}
else
return written;
return len;
}
static int XMLCALL domdoc_stream_save_closecallback(void *ctx)

View File

@ -1288,6 +1288,118 @@ static const IServiceProviderVtbl testprovVtbl =
testprov_t testprov = { { &testprovVtbl } };
/* IStream */
static HRESULT WINAPI istream_QueryInterface(IStream *iface, REFIID riid, void **ppvObject)
{
*ppvObject = NULL;
if (IsEqualGUID(riid, &IID_IStream) ||
IsEqualGUID(riid, &IID_IUnknown))
*ppvObject = iface;
else
return E_NOINTERFACE;
return S_OK;
}
static ULONG WINAPI istream_AddRef(IStream *iface)
{
return 2;
}
static ULONG WINAPI istream_Release(IStream *iface)
{
return 1;
}
static HRESULT WINAPI istream_Read(IStream *iface, void *ptr, ULONG len, ULONG *pread)
{
ok(0, "unexpected call\n");
return E_NOTIMPL;
}
static HRESULT WINAPI istream_Write(IStream *iface, const void *ptr, ULONG len, ULONG *written)
{
*written = len/2;
return S_OK;
}
static HRESULT WINAPI istream_Seek(IStream *iface, LARGE_INTEGER move, DWORD origin, ULARGE_INTEGER *new_pos)
{
ok(0, "unexpected call\n");
return E_NOTIMPL;
}
static HRESULT WINAPI istream_SetSize(IStream *iface, ULARGE_INTEGER size)
{
ok(0, "unexpected call\n");
return E_NOTIMPL;
}
static HRESULT WINAPI istream_CopyTo(IStream *iface, IStream *stream, ULARGE_INTEGER len,
ULARGE_INTEGER *pread, ULARGE_INTEGER *written)
{
ok(0, "unexpected call\n");
return E_NOTIMPL;
}
static HRESULT WINAPI istream_Commit(IStream *iface, DWORD flags)
{
ok(0, "unexpected call\n");
return E_NOTIMPL;
}
static HRESULT WINAPI istream_Revert(IStream *iface)
{
ok(0, "unexpected call\n");
return E_NOTIMPL;
}
static HRESULT WINAPI istream_LockRegion(IStream *iface, ULARGE_INTEGER offset,
ULARGE_INTEGER len, DWORD locktype)
{
ok(0, "unexpected call\n");
return E_NOTIMPL;
}
static HRESULT WINAPI istream_UnlockRegion(IStream *iface, ULARGE_INTEGER offset,
ULARGE_INTEGER len, DWORD locktype)
{
ok(0, "unexpected call\n");
return E_NOTIMPL;
}
static HRESULT WINAPI istream_Stat(IStream *iface, STATSTG *pstatstg, DWORD flag)
{
ok(0, "unexpected call\n");
return E_NOTIMPL;
}
static HRESULT WINAPI istream_Clone(IStream *iface, IStream **stream)
{
ok(0, "unexpected call\n");
return E_NOTIMPL;
}
static const IStreamVtbl StreamVtbl = {
istream_QueryInterface,
istream_AddRef,
istream_Release,
istream_Read,
istream_Write,
istream_Seek,
istream_SetSize,
istream_CopyTo,
istream_Commit,
istream_Revert,
istream_LockRegion,
istream_UnlockRegion,
istream_Stat,
istream_Clone
};
static IStream savestream = { &StreamVtbl };
#define EXPECT_CHILDREN(node) _expect_children((IXMLDOMNode*)node, __LINE__)
static void _expect_children(IXMLDOMNode *node, int line)
{
@ -7124,10 +7236,10 @@ static void test_save(void)
{
IXMLDOMDocument *doc, *doc2;
IXMLDOMElement *root;
VARIANT file, vDoc;
BSTR sOrig, sNew, filename;
char buffer[100];
DWORD read = 0;
VARIANT dest;
HANDLE hfile;
HRESULT hr;
@ -7148,10 +7260,10 @@ static void test_save(void)
hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)root, NULL);
EXPECT_HR(hr, S_OK);
V_VT(&vDoc) = VT_UNKNOWN;
V_UNKNOWN(&vDoc) = (IUnknown*)doc2;
V_VT(&dest) = VT_UNKNOWN;
V_UNKNOWN(&dest) = (IUnknown*)doc2;
hr = IXMLDOMDocument_save(doc, vDoc);
hr = IXMLDOMDocument_save(doc, dest);
EXPECT_HR(hr, S_OK);
hr = IXMLDOMDocument_get_xml(doc, &sOrig);
@ -7169,10 +7281,10 @@ static void test_save(void)
IXMLDOMDocument_Release(doc2);
/* save to path */
V_VT(&file) = VT_BSTR;
V_BSTR(&file) = _bstr_("test.xml");
V_VT(&dest) = VT_BSTR;
V_BSTR(&dest) = _bstr_("test.xml");
hr = IXMLDOMDocument_save(doc, file);
hr = IXMLDOMDocument_save(doc, dest);
EXPECT_HR(hr, S_OK);
hfile = CreateFileA("test.xml", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
@ -7188,24 +7300,34 @@ static void test_save(void)
/* save to path VT_BSTR | VT_BYREF */
filename = _bstr_("test.xml");
V_VT(&file) = VT_BSTR | VT_BYREF;
V_BSTRREF(&file) = &filename;
V_VT(&dest) = VT_BSTR | VT_BYREF;
V_BSTRREF(&dest) = &filename;
hr = IXMLDOMDocument_save(doc, file);
hr = IXMLDOMDocument_save(doc, dest);
EXPECT_HR(hr, S_OK);
IXMLDOMDocument_Release(doc);
hfile = CreateFileA("test.xml", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
ok(hfile != INVALID_HANDLE_VALUE, "Could not open file: %u\n", GetLastError());
if(hfile == INVALID_HANDLE_VALUE) return;
ReadFile(hfile, buffer, sizeof(buffer), &read, NULL);
ok(read != 0, "could not read file\n");
ok(buffer[0] != '<' || buffer[1] != '?', "File contains processing instruction\n");
if (hfile != INVALID_HANDLE_VALUE)
{
ReadFile(hfile, buffer, sizeof(buffer), &read, NULL);
ok(read != 0, "could not read file\n");
ok(buffer[0] != '<' || buffer[1] != '?', "File contains processing instruction\n");
CloseHandle(hfile);
DeleteFile("test.xml");
CloseHandle(hfile);
DeleteFile("test.xml");
}
/* save to stream */
V_VT(&dest) = VT_UNKNOWN;
V_UNKNOWN(&dest) = (IUnknown*)&savestream;
hr = IXMLDOMDocument_save(doc, dest);
EXPECT_HR(hr, S_OK);
IXMLDOMDocument_Release(doc);
free_bstrs();
}