Example #1
0
void test_OutOfProcess()
{
    LARGE_INTEGER move;
    ULARGE_INTEGER size;
    HRESULT res;
    HANDLE process;
    ULONG i;

    RTL_MEMORY_STREAM stream;
    RTL_MEMORY_STREAM previous;

    IStream * istream;

    UCHAR buffer[80];
    UCHAR buffer2[180];
    ULONG bytesRead;

    STATSTG stat;

    finalReleaseCallCount = 0;

    for (i = 0; i < sizeof(buffer2); i++)
    {
        buffer2[i] = i % UCHAR_MAX;
    }

    memset(&stream, 0x90, sizeof(stream));
    memset(&previous, 0x00, sizeof(previous));

    process = GetCurrentProcess();

    RtlInitOutOfProcessMemoryStream(&stream);

    ok(stream.FinalRelease == RtlFinalReleaseOutOfProcessMemoryStream,
       "stream.FinalRelease unexpected %p != %p.\n",
       stream.FinalRelease, RtlFinalReleaseOutOfProcessMemoryStream);

    ok(stream.RefCount == 0, "RefCount has a wrong value: %d (expected %d).\n", stream.RefCount, 0);

    CompareStructsAndSaveForLater(&previous, &stream, "After init");

    stream.Current = buffer2;
    stream.Start = buffer2;
    stream.End = buffer2 + sizeof(buffer2);
    stream.ProcessHandle = process;
    stream.FinalRelease = CustomFinalReleaseOutOfProcessMemoryStream;

    CompareStructsAndSaveForLater(&previous, &stream, "After assigning");

    res = IStream_QueryInterface((struct IStream*)&stream, &IID_IStream, (void**)&istream);

    ok(res == S_OK, "QueryInterface to IStream returned wrong hResult: 0x%08x.\n", res);

    ok(stream.RefCount == 1, "RefCount has a wrong value: %d (expected %d).\n", stream.RefCount, 1);

    ok(stream.ProcessHandle == process,
       "ProcessHandle changed unexpectedly: 0x%08x (expected 0x%p)\n",
       stream.ProcessHandle, process);

    CompareStructsAndSaveForLater(&previous, &stream, "After QueryInterface");

    res = IStream_Stat(istream, &stat, STATFLAG_NONAME);

    ok(res == S_OK, "Stat to IStream returned wrong hResult: 0x%08x.\n", res);

    ok(stream.Current == buffer2,
       "stream.Current points to the wrong address 0x%p (expected 0x%p)\n",
       stream.Current, buffer2);
    ok(stream.Start == buffer2, "stream.Start was changed unexpectedly\n");
    ok(stream.End == buffer2 + sizeof(buffer2), "stream.End was changed unexpectedly\n");
    ok(stream.ProcessHandle == process,
       "ProcessHandle changed unexpectedly: 0x%08x (expected 0x%p)\n",
       stream.ProcessHandle, process);

    ok(stat.cbSize.QuadPart == ((PUCHAR)stream.End - (PUCHAR)stream.Start),
       "stat.cbSize has the wrong value %lld (expected %d)\n",
       stat.cbSize.QuadPart, (PUCHAR)stream.End - (PUCHAR)stream.Start);

    CompareStructsAndSaveForLater(&previous, &stream, "After Stat");

    res = IStream_Read(istream, buffer, sizeof(buffer), &bytesRead);

    ok(res == S_OK, "Read to IStream returned wrong hResult: 0x%08x.\n", res);

    if (SUCCEEDED(res))
    {
        for (i = 0; i < bytesRead; i++)
        {
            ok(buffer[i] == i, "Buffer[%d] contains a wrong number %d (expected %d).\n", i, buffer[i], i);
        }
    }

    ok(stream.Current == buffer2 + sizeof(buffer),
       "stream.Current points to the wrong address 0x%p (expected 0x%p)\n",
       stream.Current, buffer2);
    ok(stream.Start == buffer2, "stream.Start was changed unexpectedly\n");
    ok(stream.End == buffer2 + sizeof(buffer2), "stream.End was changed unexpectedly\n");
    ok(stream.ProcessHandle == process,
       "ProcessHandle changed unexpectedly: 0x%08x (expected 0x%p)\n",
       stream.ProcessHandle, process);

    CompareStructsAndSaveForLater(&previous, &stream, "After Read 1");

    move.QuadPart = 40;

    res = IStream_Seek(istream, move, STREAM_SEEK_SET, &size);

    ok(res == S_OK, "Seek to IStream returned wrong hResult: 0x%08x.\n", res);

    ok(size.QuadPart == 40,
       "Seek returned wrong offset %lld (expected %d)\n",
       size.QuadPart, 40);

    ok(stream.Current == buffer2 + 40,
       "stream.Current points to the wrong address 0x%p (expected 0x%p)\n",
       stream.Current, buffer2);
    ok(stream.Start == buffer2, "stream.Start was changed unexpectedly\n");
    ok(stream.End == buffer2 + sizeof(buffer2), "stream.End was changed unexpectedly\n");
    ok(stream.ProcessHandle == process,
       "ProcessHandle changed unexpectedly: 0x%08x (expected 0x%p)\n",
       stream.ProcessHandle, process);

    CompareStructsAndSaveForLater(&previous, &stream, "After Seek");

    res = IStream_Read(istream, buffer, sizeof(buffer), &bytesRead);

    ok(res == S_OK, "Read to IStream returned wrong hResult: 0x%08x.\n", res);

    if (SUCCEEDED(res))
    {
        for (i = 0; i < bytesRead; i++)
        {
            ok(buffer[i] == (i + 40), "Buffer[%d] contains a wrong number %d (expected %d).\n", i, buffer[i], i + 40);
        }
    }

    ok(stream.Current == buffer2 + 40 + sizeof(buffer),
       "stream.Current points to the wrong address 0x%p (expected 0x%p)\n",
       stream.Current, buffer2);
    ok(stream.Start == buffer2, "stream.Start was changed unexpectedly\n");
    ok(stream.End == buffer2 + sizeof(buffer2), "stream.End was changed unexpectedly\n");
    ok(stream.ProcessHandle == process,
       "ProcessHandle changed unexpectedly: 0x%08x (expected 0x%p)\n",
       stream.ProcessHandle, process);

    CompareStructsAndSaveForLater(&previous, &stream, "After Read 2");

    res = IStream_Release(istream);

    ok(res == S_OK, "Release to IStream returned wrong hResult: 0x%08x.\n", res);

    ok(stream.RefCount == 0, "RefCount has a wrong value: %d (expected %d).\n", stream.RefCount, 0);

    ok(finalReleaseCallCount == 1, "FinalRelease was called %d times instead of 1.\n", finalReleaseCallCount);
}
Example #2
0
void test_InProcess()
{
    LARGE_INTEGER move;
    ULARGE_INTEGER size;
    HRESULT res;
    ULONG i;

    RTL_MEMORY_STREAM stream;
    RTL_MEMORY_STREAM previous;

    IStream * istream;

    UCHAR buffer[80];
    UCHAR buffer2[180];
    ULONG bytesRead;

    STATSTG stat;

    finalReleaseCallCount = 0;

    for (i = 0; i < sizeof(buffer2); i++)
    {
        buffer2[i] = i % UCHAR_MAX;
    }

    memset(&stream, 0x90, sizeof(stream));
    memset(&previous, 0x00, sizeof(previous));

    StartSeh()
        RtlInitMemoryStream(NULL);
    EndSeh(STATUS_ACCESS_VIOLATION);

    StartSeh()
        RtlInitMemoryStream(&stream);
    EndSeh(STATUS_SUCCESS);

    CompareStructsAndSaveForLater(&previous, &stream, "After init");

    ok(stream.RefCount == 0, "RefCount has a wrong value: %d (expected %d).\n", stream.RefCount, 0);

    stream.Current = buffer2;
    stream.Start = buffer2;
    stream.End = buffer2 + sizeof(buffer2);
    stream.FinalRelease = CustomFinalReleaseMemoryStream;

    CompareStructsAndSaveForLater(&previous, &stream, "After assigning");

    StartSeh()
        res = IStream_QueryInterface((struct IStream*)&stream, NULL, NULL);
        ok(res == E_INVALIDARG, "QueryInterface to IStream returned wrong hResult: 0x%08x.\n", res);
        ok(stream.RefCount == 0, "RefCount has a wrong value: %d (expected %d).\n", stream.RefCount, 2);
    EndSeh(STATUS_ACCESS_VIOLATION);

    StartSeh()
        res = IStream_QueryInterface((struct IStream*)&stream, &IID_IStream, NULL);
        ok(res == E_INVALIDARG, "QueryInterface to IStream returned wrong hResult: 0x%08x.\n", res);
        ok(stream.RefCount == 1, "RefCount has a wrong value: %d (expected %d).\n", stream.RefCount, 2);
    EndSeh(STATUS_ACCESS_VIOLATION);

    StartSeh()
        res = IStream_QueryInterface((struct IStream*)&stream, NULL, (void**)&istream);
        ok(res == E_INVALIDARG, "QueryInterface to IStream returned wrong hResult: 0x%08x.\n", res);
        ok(stream.RefCount == 1, "RefCount has a wrong value: %d (expected %d).\n", stream.RefCount, 2);
    EndSeh(STATUS_ACCESS_VIOLATION);

    StartSeh()
        res = IStream_QueryInterface((struct IStream*)&stream, &IID_IStream, (void**)&istream);
        ok(res == S_OK, "QueryInterface to IStream returned wrong hResult: 0x%08x.\n", res);
        ok(stream.RefCount == 2, "RefCount has a wrong value: %d (expected %d).\n", stream.RefCount, 2);
    EndSeh(STATUS_SUCCESS);

    CompareStructsAndSaveForLater(&previous, &stream, "After QueryInterface");

    StartSeh()
        res = IStream_Stat(istream, NULL, 0);
        ok(res == STG_E_INVALIDPOINTER, "Stat to IStream returned wrong hResult: 0x%08x.\n", res);
    EndSeh(STATUS_SUCCESS);

    StartSeh()
        res = IStream_Stat(istream, &stat, STATFLAG_NONAME);
        ok(res == S_OK, "Stat to IStream returned wrong hResult: 0x%08x.\n", res);
    EndSeh(STATUS_SUCCESS);

    ok(stream.Current == buffer2,
       "stream.Current points to the wrong address 0x%p (expected 0x%p)\n",
       stream.Current, buffer2);
    ok(stream.Start == buffer2, "stream.Start was changed unexpectedly\n");
    ok(stream.End == buffer2 + sizeof(buffer2), "stream.End was changed unexpectedly\n");

    ok(stat.cbSize.QuadPart == ((PUCHAR)stream.End - (PUCHAR)stream.Start),
       "stat.cbSize has the wrong value %lld (expected %d)\n",
       stat.cbSize.QuadPart, (PUCHAR)stream.End - (PUCHAR)stream.Start);

    CompareStructsAndSaveForLater(&previous, &stream, "After Stat");

    StartSeh()
        res = IStream_AddRef(istream);
        ok(res == 3, "AddRef to IStream returned wrong hResult: %d.\n", res);
    EndSeh(STATUS_SUCCESS);

    StartSeh()
        res = IStream_AddRef(istream);
        ok(res == 4, "AddRef to IStream returned wrong hResult: %d.\n", res);
    EndSeh(STATUS_SUCCESS);

    StartSeh()
        res = IStream_Release(istream);
        ok(res == 3, "Release to IStream returned wrong hResult: %d.\n", res);
    EndSeh(STATUS_SUCCESS);

    StartSeh()
        res = IStream_AddRef(istream);
        ok(res == 4, "AddRef to IStream returned wrong hResult: %d.\n", res);
    EndSeh(STATUS_SUCCESS);

    StartSeh()
        res = IStream_Release(istream);
        ok(res == 3, "Release to IStream returned wrong hResult: %d.\n", res);
    EndSeh(STATUS_SUCCESS);

    StartSeh()
        res = IStream_Release(istream);
        ok(res == 2, "Release to IStream returned wrong hResult: %d.\n", res);
    EndSeh(STATUS_SUCCESS);

    CompareStructsAndSaveForLater(&previous, &stream, "After AddRef");

    StartSeh()
        res = IStream_Read(istream, NULL, 0, &bytesRead);
        ok(res == S_OK, "Read to IStream returned wrong hResult: 0x%08x.\n", res);
    EndSeh(STATUS_SUCCESS);

    StartSeh()
        res = IStream_Read(istream, buffer, 40, NULL);
        ok(res == S_OK, "Read to IStream returned wrong hResult: 0x%08x.\n", res);
    EndSeh(STATUS_ACCESS_VIOLATION);

    StartSeh()
        res = IStream_Read(istream, buffer + 40, 39, &bytesRead);
        ok(res == S_OK, "Read to IStream returned wrong hResult: 0x%08x.\n", res);
    EndSeh(STATUS_SUCCESS);

    if (SUCCEEDED(res))
    {
        bytesRead += 40;
        for (i = 0; i < bytesRead; i++)
        {
            ok(buffer[i] == i, "Buffer[%d] contains a wrong number %d (expected %d).\n", i, buffer[i], i);
        }
    }

    ok(stream.Current == buffer2 + 79,
       "stream.Current points to the wrong address 0x%p (expected 0x%p)\n",
       stream.Current, buffer2);
    ok(stream.Start == buffer2, "stream.Start was changed unexpectedly\n");
    ok(stream.End == buffer2 + sizeof(buffer2), "stream.End was changed unexpectedly\n");

    CompareStructsAndSaveForLater(&previous, &stream, "After Read 1");

    size.QuadPart = 0x9090909090909090ull;

    StartSeh()
        move.QuadPart = -1;
        res = IStream_Seek(istream, move, STREAM_SEEK_END, &size);
        ok(res == STG_E_INVALIDPOINTER, "Seek to IStream returned wrong hResult: 0x%08x.\n", res);
        ok(size.QuadPart == 0x9090909090909090ull, "Seek modified the new location in an error (0x%08x,0x%08x).\n", size.HighPart, size.LowPart);
    EndSeh(STATUS_SUCCESS);

    StartSeh()
        move.QuadPart = 0;
        res = IStream_Seek(istream, move, STREAM_SEEK_END, &size);
        ok(res == S_OK, "Seek to IStream returned wrong hResult: 0x%08x.\n", res);
        ok(size.QuadPart == (PUCHAR)stream.End - (PUCHAR)stream.Start, "Seek new location unexpected value: 0x%08x.\n", size.LowPart);
    EndSeh(STATUS_SUCCESS);

    size.QuadPart = 0x9090909090909090ull;

    StartSeh()
        move.QuadPart = 1;
        res = IStream_Seek(istream, move, STREAM_SEEK_END, &size);
        ok(res == S_OK, "Seek to IStream returned wrong hResult: 0x%08x.\n", res);
        ok(size.QuadPart == (PUCHAR)stream.End - (PUCHAR)stream.Start - 1, "Seek new location unexpected value: 0x%08x.\n", size.LowPart);
    EndSeh(STATUS_SUCCESS);

    size.QuadPart = 0x9090909090909090ull;

    StartSeh()
        move.QuadPart = 2;
        res = IStream_Seek(istream, move, STREAM_SEEK_END, &size);
        ok(res == S_OK, "Seek to IStream returned wrong hResult: 0x%08x.\n", res);
        ok(size.QuadPart == (PUCHAR)stream.End - (PUCHAR)stream.Start - 2, "Seek new location unexpected value: 0x%08x.\n", size.LowPart);
    EndSeh(STATUS_SUCCESS);

    size.QuadPart = 0x9090909090909090ull;

    StartSeh()
        move.QuadPart = -20;
        res = IStream_Seek(istream, move, STREAM_SEEK_SET, &size);
        ok(res == STG_E_INVALIDPOINTER, "Seek to IStream returned wrong hResult: 0x%08x.\n", res);
        ok(size.QuadPart == 0x9090909090909090ull, "Seek modified the new location in an error.\n");
    EndSeh(STATUS_SUCCESS);

    StartSeh()
        move.QuadPart = 4000;
        res = IStream_Seek(istream, move, STREAM_SEEK_SET, &size);
        ok(res == STG_E_INVALIDPOINTER, "Seek to IStream returned wrong hResult: 0x%08x.\n", res);
        ok(size.QuadPart == 0x9090909090909090ull, "Seek modified the new location in an error.\n");
    EndSeh(STATUS_SUCCESS);

    StartSeh()
        move.QuadPart = 0x100000000ull;
        res = IStream_Seek(istream, move, STREAM_SEEK_SET, &size);
#ifdef _WIN64
        ok(res == STG_E_INVALIDPOINTER, "Seek to IStream returned wrong hResult: 0x%08x.\n", res);
        ok(size.QuadPart == 0x9090909090909090ull, "Seek modified the new location in an error (0x%08x,0x%08x).\n", size.HighPart, size.LowPart);
#else
        ok(res == S_OK, "Seek to IStream returned wrong hResult: 0x%08x.\n", res);
        ok(size.QuadPart == 0, "Seek new location unexpected value: 0x%08x.\n", size.LowPart);
#endif
    EndSeh(STATUS_SUCCESS);

#ifdef _WIN64
    StartSeh()
        move.QuadPart = 0;
        res = IStream_Seek(istream, move, STREAM_SEEK_SET, &size);
        ok(res == S_OK, "Seek to IStream returned wrong hResult: 0x%08x.\n", res);
        ok(size.QuadPart == 0, "Seek new location unexpected value: 0x%08x.\n", size.LowPart);
    EndSeh(STATUS_SUCCESS);
#endif

    size.QuadPart = 0x9090909090909090ull;

    StartSeh()
        move.QuadPart = -20;
        res = IStream_Seek(istream, move, STREAM_SEEK_CUR, &size);
        ok(res == STG_E_INVALIDPOINTER, "Seek to IStream returned wrong hResult: 0x%08x.\n", res);
        ok(size.QuadPart == 0x9090909090909090ull, "Seek modified the new location in an error (0x%08x,0x%08x).\n", size.HighPart, size.LowPart);
    EndSeh(STATUS_SUCCESS);

    StartSeh()
        move.QuadPart = 0x100000000ull;
        res = IStream_Seek(istream, move, STREAM_SEEK_CUR, &size);
#ifdef _WIN64
        ok(res == STG_E_INVALIDPOINTER, "Seek to IStream returned wrong hResult: 0x%08x.\n", res);
        ok(size.QuadPart == 0x9090909090909090ull, "Seek modified the new location in an error (0x%08x,0x%08x).\n", size.HighPart, size.LowPart);
#else
        ok(res == S_OK, "Seek to IStream returned wrong hResult: 0x%08x.\n", res);
        ok(size.QuadPart == 0, "Seek new location unexpected value: 0x%08x.\n", size.LowPart);
#endif
    EndSeh(STATUS_SUCCESS);

    StartSeh()
        move.QuadPart = 40;
        res = IStream_Seek(istream, move, STREAM_SEEK_SET, &size);
        ok(res == S_OK, "Seek to IStream returned wrong hResult: 0x%08x.\n", res);
    EndSeh(STATUS_SUCCESS);

    ok(size.QuadPart == 40,
       "Seek returned wrong offset %lld (expected %d)\n",
       size.QuadPart, 40);

    ok(stream.Current == buffer2 + 40,
       "stream.Current points to the wrong address 0x%p (expected 0x%p)\n",
       stream.Current, buffer2);
    ok(stream.Start == buffer2, "stream.Start was changed unexpectedly\n");
    ok(stream.End == buffer2 + sizeof(buffer2), "stream.End was changed unexpectedly\n");

    CompareStructsAndSaveForLater(&previous, &stream, "After Seek");

    res = IStream_Read(istream, buffer, sizeof(buffer), &bytesRead);

    ok(res == S_OK, "Read to IStream returned wrong hResult: 0x%08x.\n", res);

    if (SUCCEEDED(res))
    {
        for (i = 0; i < bytesRead; i++)
        {
            ok(buffer[i] == (i + 40), "Buffer[%d] contains a wrong number %d (expected %d).\n", i, buffer[i], i + 40);
        }
    }

    ok(stream.Current == buffer2 + 40 + sizeof(buffer),
       "stream.Current points to the wrong address 0x%p (expected 0x%p)\n",
       stream.Current, buffer2);
    ok(stream.Start == buffer2, "stream.Start was changed unexpectedly\n");
    ok(stream.End == buffer2 + sizeof(buffer2), "stream.End was changed unexpectedly\n");

    CompareStructsAndSaveForLater(&previous, &stream, "After Read 2");

    res = IStream_Release(istream);

    ok(res == 1, "Release to IStream returned wrong hResult: 0x%08x.\n", res);

    ok(stream.RefCount == 1, "RefCount has a wrong value: %d (expected %d).\n", stream.RefCount, 1);

    res = IStream_Release(istream);

    ok(res == S_OK, "Release to IStream returned wrong hResult: 0x%08x.\n", res);

    ok(stream.RefCount == 0, "RefCount has a wrong value: %d (expected %d).\n", stream.RefCount, 0);

    ok(finalReleaseCallCount == 1, "FinalRelease was called %d times instead of 1.\n", finalReleaseCallCount);
}
Example #3
0
File: main.c Project: GYGit/reactos
LRESULT WINAPI LresultFromObject( REFIID riid, WPARAM wParam, LPUNKNOWN pAcc )
{
    static const WCHAR atom_fmt[] = {'%','0','8','x',':','%','0','8','x',':','%','0','8','x',0};
    static const LARGE_INTEGER seek_zero = {{0}};

    WCHAR atom_str[sizeof(lresult_atom_prefix)/sizeof(WCHAR)+3*8+3];
    IStream *stream;
    HANDLE mapping;
    STATSTG stat;
    HRESULT hr;
    ATOM atom;
    void *view;

    TRACE("%s %ld %p\n", debugstr_guid(riid), wParam, pAcc);

    if(wParam)
        FIXME("unsupported wParam = %lx\n", wParam);

    if(!pAcc)
        return E_INVALIDARG;

    hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
    if(FAILED(hr))
        return hr;

    hr = CoMarshalInterface(stream, riid, pAcc, MSHCTX_LOCAL, NULL, MSHLFLAGS_NORMAL);
    if(FAILED(hr)) {
        IStream_Release(stream);
        return hr;
    }

    hr = IStream_Seek(stream, seek_zero, STREAM_SEEK_SET, NULL);
    if(FAILED(hr)) {
        IStream_Release(stream);
        return hr;
    }

    hr = IStream_Stat(stream, &stat, STATFLAG_NONAME);
    if(FAILED(hr)) {
        CoReleaseMarshalData(stream);
        IStream_Release(stream);
        return hr;
    }else if(stat.cbSize.u.HighPart) {
        FIXME("stream size to big\n");
        CoReleaseMarshalData(stream);
        IStream_Release(stream);
        return E_NOTIMPL;
    }

    mapping = CreateFileMappingW(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE,
            stat.cbSize.u.HighPart, stat.cbSize.u.LowPart, NULL);
    if(!mapping) {
        CoReleaseMarshalData(stream);
        IStream_Release(stream);
        return hr;
    }

    view = MapViewOfFile(mapping, FILE_MAP_WRITE, 0, 0, 0);
    if(!view) {
        CloseHandle(mapping);
        CoReleaseMarshalData(stream);
        IStream_Release(stream);
        return E_FAIL;
    }

    hr = IStream_Read(stream, view, stat.cbSize.u.LowPart, NULL);
    UnmapViewOfFile(view);
    if(FAILED(hr)) {
        CloseHandle(mapping);
        hr = IStream_Seek(stream, seek_zero, STREAM_SEEK_SET, NULL);
        if(SUCCEEDED(hr))
            CoReleaseMarshalData(stream);
        IStream_Release(stream);
        return hr;

    }

    memcpy(atom_str, lresult_atom_prefix, sizeof(lresult_atom_prefix));
    sprintfW(atom_str+sizeof(lresult_atom_prefix)/sizeof(WCHAR),
             atom_fmt, GetCurrentProcessId(), HandleToUlong(mapping), stat.cbSize.u.LowPart);
    atom = GlobalAddAtomW(atom_str);
    if(!atom) {
        CloseHandle(mapping);
        hr = IStream_Seek(stream, seek_zero, STREAM_SEEK_SET, NULL);
        if(SUCCEEDED(hr))
            CoReleaseMarshalData(stream);
        IStream_Release(stream);
        return E_FAIL;
    }

    IStream_Release(stream);
    return atom;
}
Example #4
0
File: mk.c Project: AndreRH/wine
static HRESULT WINAPI MkProtocol_StartEx(IInternetProtocolEx *iface, IUri *pUri,
        IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
        DWORD grfPI, HANDLE *dwReserved)
{
    MkProtocol *This = impl_from_IInternetProtocolEx(iface);
    LPWSTR mime, progid, display_name, colon_ptr;
    DWORD bindf=0, eaten=0, scheme=0, len;
    BSTR url, path = NULL;
    IParseDisplayName *pdn;
    BINDINFO bindinfo;
    STATSTG statstg;
    IMoniker *mon;
    HRESULT hres;
    CLSID clsid;

    TRACE("(%p)->(%p %p %p %08x %p)\n", This, pUri, pOIProtSink,
            pOIBindInfo, grfPI, dwReserved);

    hres = IUri_GetScheme(pUri, &scheme);
    if(FAILED(hres))
        return hres;
    if(scheme != URL_SCHEME_MK)
        return INET_E_INVALID_URL;

    memset(&bindinfo, 0, sizeof(bindinfo));
    bindinfo.cbSize = sizeof(BINDINFO);
    hres = IInternetBindInfo_GetBindInfo(pOIBindInfo, &bindf, &bindinfo);
    if(FAILED(hres)) {
        WARN("GetBindInfo failed: %08x\n", hres);
        return hres;
    }

    ReleaseBindInfo(&bindinfo);

    IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_SENDINGREQUEST, NULL);

    hres = IUri_GetDisplayUri(pUri, &url);
    if(FAILED(hres))
        return hres;
    hres = FindMimeFromData(NULL, url, NULL, 0, NULL, 0, &mime, 0);
    SysFreeString(url);
    if(SUCCEEDED(hres)) {
        IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_MIMETYPEAVAILABLE, mime);
        CoTaskMemFree(mime);
    }

    hres = IUri_GetPath(pUri, &path);
    if(FAILED(hres))
        return hres;
    len = SysStringLen(path)+1;
    hres = UrlUnescapeW(path, NULL, &len, URL_UNESCAPE_INPLACE);
    if (FAILED(hres)) {
        SysFreeString(path);
        return report_result(pOIProtSink, INET_E_RESOURCE_NOT_FOUND, ERROR_INVALID_PARAMETER);
    }

    progid = path+1; /* skip '@' symbol */
    colon_ptr = strchrW(path, ':');
    if(!colon_ptr) {
        SysFreeString(path);
        return report_result(pOIProtSink, INET_E_RESOURCE_NOT_FOUND, ERROR_INVALID_PARAMETER);
    }

    len = strlenW(path);
    display_name = heap_alloc((len+1)*sizeof(WCHAR));
    memcpy(display_name, path, (len+1)*sizeof(WCHAR));

    progid[colon_ptr-progid] = 0; /* overwrite ':' with NULL terminator */
    hres = CLSIDFromProgID(progid, &clsid);
    SysFreeString(path);
    if(FAILED(hres))
    {
        heap_free(display_name);
        return report_result(pOIProtSink, INET_E_RESOURCE_NOT_FOUND, ERROR_INVALID_PARAMETER);
    }

    hres = CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
            &IID_IParseDisplayName, (void**)&pdn);
    if(FAILED(hres)) {
        WARN("Could not create object %s\n", debugstr_guid(&clsid));
        heap_free(display_name);
        return report_result(pOIProtSink, hres, ERROR_INVALID_PARAMETER);
    }

    hres = IParseDisplayName_ParseDisplayName(pdn, NULL /* FIXME */, display_name, &eaten, &mon);
    heap_free(display_name);
    IParseDisplayName_Release(pdn);
    if(FAILED(hres)) {
        WARN("ParseDisplayName failed: %08x\n", hres);
        return report_result(pOIProtSink, hres, ERROR_INVALID_PARAMETER);
    }

    if(This->stream) {
        IStream_Release(This->stream);
        This->stream = NULL;
    }

    hres = IMoniker_BindToStorage(mon, NULL /* FIXME */, NULL, &IID_IStream, (void**)&This->stream);
    IMoniker_Release(mon);
    if(FAILED(hres)) {
        WARN("BindToStorage failed: %08x\n", hres);
        return report_result(pOIProtSink, hres, ERROR_INVALID_PARAMETER);
    }

    hres = IStream_Stat(This->stream, &statstg, STATFLAG_NONAME);
    if(FAILED(hres)) {
        WARN("Stat failed: %08x\n", hres);
        return report_result(pOIProtSink, hres, ERROR_INVALID_PARAMETER);
    }

    IInternetProtocolSink_ReportData(pOIProtSink,
            BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION,
            statstg.cbSize.u.LowPart, statstg.cbSize.u.LowPart);
    return report_result(pOIProtSink, S_OK, ERROR_SUCCESS);
}
Example #5
0
static void test_streamonhglobal(IStream *pStream)
{
    const char data[] = "Test String";
    ULARGE_INTEGER ull;
    LARGE_INTEGER ll;
    char buffer[128];
    ULONG read;
    STATSTG statstg;
    HRESULT hr;

    ull.QuadPart = sizeof(data);
    hr = IStream_SetSize(pStream, ull);
    ok_ole_success(hr, "IStream_SetSize");

    hr = IStream_Write(pStream, data, sizeof(data), NULL);
    ok_ole_success(hr, "IStream_Write");

    ll.QuadPart = 0;
    hr = IStream_Seek(pStream, ll, STREAM_SEEK_SET, NULL);
    ok_ole_success(hr, "IStream_Seek");

    /* should return S_OK, not S_FALSE */
    hr = IStream_Read(pStream, buffer, sizeof(buffer), &read);
    ok_ole_success(hr, "IStream_Read");
    ok(read == sizeof(data), "IStream_Read returned read %d\n", read);

    /* ignores HighPart */
    ull.u.HighPart = -1;
    ull.u.LowPart = 0;
    hr = IStream_SetSize(pStream, ull);
    ok_ole_success(hr, "IStream_SetSize");

    /* IStream_Seek -- NULL position argument */
    ll.u.HighPart = 0;
    ll.u.LowPart = 0;
    hr = IStream_Seek(pStream, ll, STREAM_SEEK_CUR, NULL);
    ok_ole_success(hr, "IStream_Seek");

    /* IStream_Seek -- valid position argument (seek from current position) */
    ull.u.HighPart = 0xCAFECAFE;
    ull.u.LowPart = 0xCAFECAFE;
    ll.u.HighPart = 0;
    ll.u.LowPart = 0;
    hr = IStream_Seek(pStream, ll, STREAM_SEEK_CUR, &ull);
    ok_ole_success(hr, "IStream_Seek");
    ok(ull.u.LowPart == sizeof(data), "LowPart set to %d\n", ull.u.LowPart);
    ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %d\n", ull.u.HighPart);

    /* IStream_Seek -- invalid seek argument */
    ull.u.HighPart = 0xCAFECAFE;
    ull.u.LowPart = 0xCAFECAFE;
    ll.u.HighPart = 0;
    ll.u.LowPart = 123;
    hr = IStream_Seek(pStream, ll, STREAM_SEEK_END+1, &ull);
    ok(hr == STG_E_SEEKERROR, "IStream_Seek should have returned STG_E_SEEKERROR instead of 0x%08x\n", hr);
    ok(ull.u.LowPart == sizeof(data), "LowPart set to %d\n", ull.u.LowPart);
    ok(ull.u.HighPart == 0, "should not have changed HighPart, got %d\n", ull.u.HighPart);

    /* IStream_Seek -- valid position argument (seek to beginning) */
    ull.u.HighPart = 0xCAFECAFE;
    ull.u.LowPart = 0xCAFECAFE;
    ll.u.HighPart = 0;
    ll.u.LowPart = 0;
    hr = IStream_Seek(pStream, ll, STREAM_SEEK_SET, &ull);
    ok_ole_success(hr, "IStream_Seek");
    ok(ull.u.LowPart == 0, "should have set LowPart to 0 instead of %d\n", ull.u.LowPart);
    ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %d\n", ull.u.HighPart);

    /* IStream_Seek -- valid position argument (seek to end) */
    ull.u.HighPart = 0xCAFECAFE;
    ull.u.LowPart = 0xCAFECAFE;
    ll.u.HighPart = 0;
    ll.u.LowPart = 0;
    hr = IStream_Seek(pStream, ll, STREAM_SEEK_END, &ull);
    ok_ole_success(hr, "IStream_Seek");
    ok(ull.u.LowPart == 0, "should have set LowPart to 0 instead of %d\n", ull.u.LowPart);
    ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %d\n", ull.u.HighPart);

    /* IStream_Seek -- ignore HighPart in the move value (seek from current position) */
    ll.u.HighPart = 0;
    ll.u.LowPart = sizeof(data);
    hr = IStream_Seek(pStream, ll, STREAM_SEEK_SET, &ull);
    ok_ole_success(hr, "IStream_Seek");

    ull.u.HighPart = 0xCAFECAFE;
    ull.u.LowPart = 0xCAFECAFE;
    ll.u.HighPart = -1;
    ll.u.LowPart = 0;
    hr = IStream_Seek(pStream, ll, STREAM_SEEK_CUR, &ull);
    ok_ole_success(hr, "IStream_Seek");
    ok(ull.u.LowPart == sizeof(data), "LowPart set to %d\n", ull.u.LowPart);
    ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %d\n", ull.u.HighPart);

    /* IStream_Seek -- ignore HighPart in the move value (seek to beginning) */
    ll.u.HighPart = 0;
    ll.u.LowPart = sizeof(data);
    hr = IStream_Seek(pStream, ll, STREAM_SEEK_SET, &ull);
    ok_ole_success(hr, "IStream_Seek");

    ull.u.HighPart = 0xCAFECAFE;
    ull.u.LowPart = 0xCAFECAFE;
    ll.u.HighPart = -1;
    ll.u.LowPart = 0;
    hr = IStream_Seek(pStream, ll, STREAM_SEEK_SET, &ull);
    ok_ole_success(hr, "IStream_Seek");
    ok(ull.u.LowPart == 0, "should have set LowPart to 0 instead of %d\n", ull.u.LowPart);
    ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %d\n", ull.u.HighPart);

    /* IStream_Seek -- invalid LowPart value (seek before start of stream) */
    ll.u.HighPart = 0;
    ll.u.LowPart = sizeof(data);
    hr = IStream_Seek(pStream, ll, STREAM_SEEK_SET, &ull);
    ok_ole_success(hr, "IStream_Seek");

    ull.u.HighPart = 0xCAFECAFE;
    ull.u.LowPart = 0xCAFECAFE;
    ll.u.HighPart = 0;
    ll.u.LowPart = 0x80000000;
    hr = IStream_Seek(pStream, ll, STREAM_SEEK_CUR, &ull);
    ok(hr == STG_E_SEEKERROR, "IStream_Seek should have returned STG_E_SEEKERROR instead of 0x%08x\n", hr);
    ok(ull.u.LowPart == sizeof(data), "LowPart set to %d\n", ull.u.LowPart);
    ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %d\n", ull.u.HighPart);

    /* IStream_Seek -- valid LowPart value (seek to start of stream) */
    ll.u.HighPart = 0;
    ll.u.LowPart = sizeof(data);
    hr = IStream_Seek(pStream, ll, STREAM_SEEK_SET, &ull);
    ok_ole_success(hr, "IStream_Seek");

    ull.u.HighPart = 0xCAFECAFE;
    ull.u.LowPart = 0xCAFECAFE;
    ll.u.HighPart = 0;
    ll.u.LowPart = -(DWORD)sizeof(data);
    hr = IStream_Seek(pStream, ll, STREAM_SEEK_CUR, &ull);
    ok_ole_success(hr, "IStream_Seek");
    ok(ull.u.LowPart == 0, "LowPart set to %d\n", ull.u.LowPart);
    ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %d\n", ull.u.HighPart);

    /* IStream_Seek -- invalid LowPart value (seek to start of stream-1) */
    ll.u.HighPart = 0;
    ll.u.LowPart = sizeof(data);
    hr = IStream_Seek(pStream, ll, STREAM_SEEK_SET, &ull);
    ok_ole_success(hr, "IStream_Seek");

    ull.u.HighPart = 0xCAFECAFE;
    ull.u.LowPart = 0xCAFECAFE;
    ll.u.HighPart = 0;
    ll.u.LowPart = -(DWORD)sizeof(data)-1;
    hr = IStream_Seek(pStream, ll, STREAM_SEEK_CUR, &ull);
    ok(hr == STG_E_SEEKERROR, "IStream_Seek should have returned STG_E_SEEKERROR instead of 0x%08x\n", hr);
    ok(ull.u.LowPart == sizeof(data), "LowPart set to %d\n", ull.u.LowPart);
    ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %d\n", ull.u.HighPart);

    /* IStream_Seek -- valid LowPart value (seek forward to 0x80000000) */
    ll.u.HighPart = 0;
    ll.u.LowPart = sizeof(data);
    hr = IStream_Seek(pStream, ll, STREAM_SEEK_SET, &ull);
    ok_ole_success(hr, "IStream_Seek");

    ull.u.HighPart = 0xCAFECAFE;
    ull.u.LowPart = 0xCAFECAFE;
    ll.u.HighPart = 0;
    ll.u.LowPart = 0x80000000 - sizeof(data);
    hr = IStream_Seek(pStream, ll, STREAM_SEEK_CUR, &ull);
    ok_ole_success(hr, "IStream_Seek");
    ok(ull.u.LowPart == 0x80000000, "LowPart set to %d\n", ull.u.LowPart);
    ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %d\n", ull.u.HighPart);

    /* IStream_Seek -- invalid LowPart value (seek to beginning) */
    ll.u.HighPart = 0;
    ll.u.LowPart = sizeof(data);
    hr = IStream_Seek(pStream, ll, STREAM_SEEK_SET, &ull);
    ok_ole_success(hr, "IStream_Seek");

    ull.u.HighPart = 0xCAFECAFE;
    ull.u.LowPart = 0xCAFECAFE;
    ll.u.HighPart = 0;
    ll.u.LowPart = 0x80000000;
    hr = IStream_Seek(pStream, ll, STREAM_SEEK_SET, &ull);
    ok(hr == STG_E_SEEKERROR, "IStream_Seek should have returned STG_E_SEEKERROR instead of 0x%08x\n", hr);
    ok(ull.u.LowPart == sizeof(data), "LowPart set to %d\n", ull.u.LowPart);
    ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %d\n", ull.u.HighPart);

    /* IStream_Seek -- valid LowPart value (seek to beginning) */
    ull.u.HighPart = 0xCAFECAFE;
    ull.u.LowPart = 0xCAFECAFE;
    ll.u.HighPart = 0;
    ll.u.LowPart = 0x7FFFFFFF;
    hr = IStream_Seek(pStream, ll, STREAM_SEEK_SET, &ull);
    ok_ole_success(hr, "IStream_Seek");
    ok(ull.u.LowPart == 0x7FFFFFFF, "should have set LowPart to 0x7FFFFFFF instead of %08x\n", ull.u.LowPart);
    ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %d\n", ull.u.HighPart);

    /* IStream_Seek -- valid LowPart value (seek from current position) */
    ll.u.HighPart = 0;
    ll.u.LowPart = 0;
    hr = IStream_Seek(pStream, ll, STREAM_SEEK_SET, &ull);
    ok_ole_success(hr, "IStream_Seek");

    ull.u.HighPart = 0xCAFECAFE;
    ull.u.LowPart = 0xCAFECAFE;
    ll.u.HighPart = 0;
    ll.u.LowPart = 0x7FFFFFFF;
    hr = IStream_Seek(pStream, ll, STREAM_SEEK_CUR, &ull);
    ok_ole_success(hr, "IStream_Seek");
    ok(ull.u.LowPart == 0x7FFFFFFF, "should have set LowPart to 0x7FFFFFFF instead of %08x\n", ull.u.LowPart);
    ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %d\n", ull.u.HighPart);

    /* IStream_Seek -- second seek allows you to go past 0x7FFFFFFF size */
    ull.u.HighPart = 0xCAFECAFE;
    ull.u.LowPart = 0xCAFECAFE;
    ll.u.HighPart = 0;
    ll.u.LowPart = 9;
    hr = IStream_Seek(pStream, ll, STREAM_SEEK_CUR, &ull);
    ok_ole_success(hr, "IStream_Seek");
    ok(ull.u.LowPart == 0x80000008, "should have set LowPart to 0x80000008 instead of %08x\n", ull.u.LowPart);
    ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %d\n", ull.u.HighPart);

    /* IStream_Seek -- seek wraps position/size on integer overflow */
    ull.u.HighPart = 0xCAFECAFE;
    ull.u.LowPart = 0xCAFECAFE;
    ll.u.HighPart = 0;
    ll.u.LowPart = 0x7FFFFFFF;
    hr = IStream_Seek(pStream, ll, STREAM_SEEK_CUR, &ull);
    ok_ole_success(hr, "IStream_Seek");
    ok(ull.u.LowPart == 0x00000007, "should have set LowPart to 0x00000007 instead of %08x\n", ull.u.LowPart);
    ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %d\n", ull.u.HighPart);

    hr = IStream_Commit(pStream, STGC_DEFAULT);
    ok_ole_success(hr, "IStream_Commit");

    hr = IStream_Revert(pStream);
    ok_ole_success(hr, "IStream_Revert");

    hr = IStream_LockRegion(pStream, ull, ull, LOCK_WRITE);
    ok(hr == STG_E_INVALIDFUNCTION, "IStream_LockRegion should have returned STG_E_INVALIDFUNCTION instead of 0x%08x\n", hr);

    hr = IStream_Stat(pStream, &statstg, STATFLAG_DEFAULT);
    ok_ole_success(hr, "IStream_Stat");
    ok(statstg.type == STGTY_STREAM, "statstg.type should have been STGTY_STREAM instead of %d\n", statstg.type);

    /* test OOM condition */
    ull.u.HighPart = -1;
    ull.u.LowPart = -1;
    hr = IStream_SetSize(pStream, ull);
    ok(hr == E_OUTOFMEMORY || broken(hr == S_OK), /* win9x */
       "IStream_SetSize with large size should have returned E_OUTOFMEMORY instead of 0x%08x\n", hr);
}
Example #6
0
static void wf_cliprdr_process_cb_filecontents_request_event(wfContext *wfc, RDP_CB_FILECONTENTS_REQUEST_EVENT *event)
{
	cliprdrContext		*cliprdr = (cliprdrContext *)wfc->cliprdr_context;
	UINT32				uSize = 0;
	BYTE				*pData = NULL;
	HRESULT				hRet = S_OK;
	FORMATETC			vFormatEtc;
	LPDATAOBJECT		pDataObj = NULL;
	STGMEDIUM			vStgMedium;
	LPSTREAM			pStream = NULL;
	BOOL				bIsStreamFile = TRUE;
	static LPSTREAM		pStreamStc = NULL;
	static UINT32		uStreamIdStc = 0;

	pData = (BYTE *)calloc(1, event->cbRequested);
	if (!pData)
		goto error;

	hRet = OleGetClipboard(&pDataObj);
	if (!SUCCEEDED(hRet))
	{
		fprintf(stderr, "filecontents: get ole clipboard failed.\n");
		goto error;
	}
	
	ZeroMemory(&vFormatEtc, sizeof(FORMATETC));
	ZeroMemory(&vStgMedium, sizeof(STGMEDIUM));

	vFormatEtc.cfFormat = cliprdr->ID_FILECONTENTS;
	vFormatEtc.tymed = TYMED_ISTREAM;
	vFormatEtc.dwAspect = 1;
	vFormatEtc.lindex = event->lindex;
	vFormatEtc.ptd = NULL;

	if (uStreamIdStc != event->streamId || pStreamStc == NULL)
	{
		LPENUMFORMATETC pEnumFormatEtc;
		ULONG CeltFetched;

		FORMATETC vFormatEtc2;
		if (pStreamStc != NULL)
		{
			IStream_Release(pStreamStc);
			pStreamStc = NULL;
		}

		bIsStreamFile = FALSE;

		hRet = IDataObject_EnumFormatEtc(pDataObj, DATADIR_GET, &pEnumFormatEtc);
		if (hRet == S_OK)
		{
			do {
				hRet = IEnumFORMATETC_Next(pEnumFormatEtc, 1, &vFormatEtc2, &CeltFetched);
				if (hRet == S_OK)
				{
					if (vFormatEtc2.cfFormat == cliprdr->ID_FILECONTENTS)
					{
						hRet = IDataObject_GetData(pDataObj, &vFormatEtc, &vStgMedium);
						if (hRet == S_OK)
						{
							pStreamStc = vStgMedium.pstm;
							uStreamIdStc = event->streamId;
							bIsStreamFile = TRUE;
						}
						break;
					}
				}
			} while (hRet == S_OK);
		}
	}

	if (bIsStreamFile == TRUE)
	{
		if (event->dwFlags == 0x00000001)            /* FILECONTENTS_SIZE */
		{
			STATSTG vStatStg;

			ZeroMemory(&vStatStg, sizeof(STATSTG));

			hRet = IStream_Stat(pStreamStc, &vStatStg, STATFLAG_NONAME);
			if (hRet == S_OK)
			{
				Write_UINT32(pData, vStatStg.cbSize.LowPart);
				Write_UINT32(pData + 4, vStatStg.cbSize.HighPart);
				uSize = event->cbRequested;
			}
		}
		else if (event->dwFlags == 0x00000002)     /* FILECONTENTS_RANGE */
		{
			LARGE_INTEGER dlibMove;
			ULARGE_INTEGER dlibNewPosition;

			dlibMove.HighPart = event->nPositionHigh;
			dlibMove.LowPart = event->nPositionLow;

			hRet = IStream_Seek(pStreamStc, dlibMove, STREAM_SEEK_SET, &dlibNewPosition);
			if (SUCCEEDED(hRet))
			{
				hRet = IStream_Read(pStreamStc, pData, event->cbRequested, (PULONG)&uSize);
			}

		}
	}
	else // is local file
	{
		if (event->dwFlags == 0x00000001)            /* FILECONTENTS_SIZE */
		{
			Write_UINT32(pData, cliprdr->fileDescriptor[event->lindex]->nFileSizeLow);
			Write_UINT32(pData + 4, cliprdr->fileDescriptor[event->lindex]->nFileSizeHigh);
			uSize = event->cbRequested;
		}
		else if (event->dwFlags == 0x00000002)     /* FILECONTENTS_RANGE */
		{
			BOOL bRet;

			bRet = wf_cliprdr_get_file_contents(cliprdr->file_names[event->lindex], pData,
				event->nPositionLow, event->nPositionHigh, event->cbRequested, &uSize);
			if (bRet == FALSE)
			{
				fprintf(stderr, "get file contents failed.\n");
				uSize = 0;
				goto error;
			}
		}
	}

	IDataObject_Release(pDataObj);

	if (uSize == 0)
	{
		free(pData);
		pData = NULL;
	}

	cliprdr_send_response_filecontents(cliprdr, event->streamId, uSize, pData);

	return;

error:
	if (pData)
	{
		free(pData);
		pData = NULL;
	}

	if (pDataObj)
	{
		IDataObject_Release(pDataObj);
		pDataObj = NULL;
	}
	fprintf(stderr, "filecontents: send failed response.\n");
	cliprdr_send_response_filecontents(cliprdr, event->streamId, 0, NULL);
	return;
}
Example #7
0
static HRESULT WINAPI
CFStub_Invoke(
    LPRPCSTUBBUFFER iface,RPCOLEMESSAGE* msg,IRpcChannelBuffer* chanbuf
) {
    CFStub *This = (CFStub *)iface;
    HRESULT hres;

    if (msg->iMethod == 3) { /* CreateInstance */
	IID iid;
	IClassFactory	*classfac;
	IUnknown	*ppv;
	IStream		*pStm;
	STATSTG		ststg;
	ULARGE_INTEGER	newpos;
	LARGE_INTEGER	seekto;
	ULONG		res;

	if (msg->cbBuffer < sizeof(IID)) {
	    FIXME("Not enough bytes in buffer (%ld)?\n",msg->cbBuffer);
	    return E_FAIL;
	}
	memcpy(&iid,msg->Buffer,sizeof(iid));
	TRACE("->CreateInstance(%s)\n",debugstr_guid(&iid));
	hres = IUnknown_QueryInterface(This->pUnkServer,&IID_IClassFactory,(LPVOID*)&classfac);
	if (hres) {
	    FIXME("Ole server does not provide an IClassFactory?\n");
	    return hres;
	}
	hres = IClassFactory_CreateInstance(classfac,NULL,&iid,(LPVOID*)&ppv);
	IClassFactory_Release(classfac);
	if (hres) {
	    msg->cbBuffer = 0;
	    FIXME("Failed to create an instance of %s\n",debugstr_guid(&iid));
	    return hres;
	}
	hres = CreateStreamOnHGlobal(0,TRUE,&pStm);
	if (hres) {
	    FIXME("Failed to create stream on hglobal\n");
	    return hres;
	}
	hres = CoMarshalInterface(pStm,&iid,ppv,0,NULL,0);
	IUnknown_Release((IUnknown*)ppv);
	if (hres) {
	    FIXME("CoMarshalInterface failed, %lx!\n",hres);
	    msg->cbBuffer = 0;
	    return hres;
	}
	hres = IStream_Stat(pStm,&ststg,0);
	if (hres) {
	    FIXME("Stat failed.\n");
	    return hres;
	}

	msg->cbBuffer = ststg.cbSize.u.LowPart;

        I_RpcGetBuffer((RPC_MESSAGE *)msg);
        if (hres) return hres;

	seekto.u.LowPart = 0;seekto.u.HighPart = 0;
	hres = IStream_Seek(pStm,seekto,SEEK_SET,&newpos);
	if (hres) {
	    FIXME("IStream_Seek failed, %lx\n",hres);
	    return hres;
	}
	hres = IStream_Read(pStm,msg->Buffer,msg->cbBuffer,&res);
	if (hres) {
	    FIXME("Stream Read failed, %lx\n",hres);
	    return hres;
	}
	IStream_Release(pStm);
	return S_OK;
    }
    FIXME("(%p,%p), stub!\n",msg,chanbuf);
    FIXME("iMethod is %ld\n",msg->iMethod);
    FIXME("cbBuffer is %ld\n",msg->cbBuffer);
    return E_FAIL;
}
Example #8
0
static void test_persiststreaminit(void)
{
    IXMLDocument *doc = NULL;
    IXMLElement *element = NULL;
    IPersistStreamInit *psi = NULL;
    IStream *stream = NULL;
    STATSTG stat;
    HRESULT hr;
    ULARGE_INTEGER size;
    CHAR path[MAX_PATH];
    CLSID id;
    BSTR str;
    static const WCHAR testW[] = {'t','e','s','t',0};

    hr = CoCreateInstance(&CLSID_XMLDocument, NULL, CLSCTX_INPROC_SERVER,
                          &IID_IXMLDocument, (LPVOID*)&doc);
    ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);

    hr = IXMLDocument_QueryInterface(doc, &IID_IPersistStreamInit, (LPVOID *)&psi);
    ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
    ok(psi != NULL, "Expected non-NULL psi\n");

    /* null arguments */
    hr = IPersistStreamInit_GetSizeMax(psi, NULL);
    ok(hr == E_NOTIMPL, "Expected E_NOTIMPL, got %08x\n", hr);

    hr = IPersistStreamInit_Load(psi, NULL);
    ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);

    hr = IPersistStreamInit_Save(psi, NULL, FALSE);
    todo_wine ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);

    hr = IPersistStreamInit_GetClassID(psi, NULL);
    ok(hr == E_POINTER, "Expected E_POINTER, got %08x\n", hr);

    hr = IPersistStreamInit_IsDirty(psi);
    todo_wine ok(hr == S_FALSE, "Expected S_FALSE, got %08x\n", hr);

    create_xml_file("bank.xml");
    GetFullPathNameA("bank.xml", MAX_PATH, path, NULL);
    create_stream_on_file(&stream, path);

    /* GetSizeMax not implemented */
    size.QuadPart = 0;
    hr = IPersistStreamInit_GetSizeMax(psi, &size);
    ok(hr == E_NOTIMPL, "Expected E_NOTIMPL, got %08x\n", hr);
    ok(size.QuadPart == 0, "Expected 0\n");

    hr = IPersistStreamInit_Load(psi, stream);
    IStream_Release(stream);
    ok(hr == S_OK || hr == XML_E_INVALIDATROOTLEVEL, "Expected S_OK, got %08x\n", hr);
    if(hr == XML_E_INVALIDATROOTLEVEL)
        goto cleanup;

    hr = IPersistStreamInit_IsDirty(psi);
    todo_wine ok(hr == S_FALSE, "Expected S_FALSE, got %08x\n", hr);

    /* try to save document */
    stream = NULL;
    hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
    ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
    hr = IPersistStreamInit_Save(psi, stream, FALSE);
    todo_wine ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);

    stat.cbSize.QuadPart = 0;
    hr = IStream_Stat(stream, &stat, 0);
    ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
    todo_wine ok(stat.cbSize.QuadPart > 0, "Expected >0\n");
    IStream_Release(stream);

    str = SysAllocString(testW);
    hr = IXMLDocument_get_root(doc, &element);
    ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
    hr = IXMLElement_put_text(element, str);
    ok(hr == E_NOTIMPL, "Expected E_NOTIMPL, got %08x\n", hr);
    IXMLElement_Release(element);
    SysFreeString(str);

    hr = IPersistStreamInit_IsDirty(psi);
    todo_wine ok(hr == S_FALSE, "Expected S_FALSE, got %08x\n", hr);

    create_stream_on_file(&stream, path);
    hr = IPersistStreamInit_Load(psi, stream);
    ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
    IStream_Release(stream);

    hr = IPersistStreamInit_IsDirty(psi);
    todo_wine ok(hr == S_FALSE, "Expected S_FALSE, got %08x\n", hr);

    /* reset internal stream */
    hr = IPersistStreamInit_InitNew(psi);
    ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);

    hr = IPersistStreamInit_IsDirty(psi);
    todo_wine ok(hr == S_FALSE, "Expected S_FALSE, got %08x\n", hr);

    stream = NULL;
    hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
    ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);

    hr = IPersistStreamInit_Save(psi, stream, FALSE);
    todo_wine ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);

    stat.cbSize.QuadPart = 0;
    hr = IStream_Stat(stream, &stat, 0);
    ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
    todo_wine ok(stat.cbSize.QuadPart > 0, "Expected >0\n");
    IStream_Release(stream);

    memset(&id, 0, sizeof(id));
    hr = IPersistStreamInit_GetClassID(psi, &id);
    ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
    ok(IsEqualCLSID(&id, &CLSID_XMLDocument), "Expected CLSID_XMLDocument\n");

cleanup:
    IPersistStreamInit_Release(psi);
    IXMLDocument_Release(doc);
    DeleteFileA("bank.xml");
}
Example #9
0
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)
    {
        ok(ret == STG_E_ACCESSDENIED /* XP */ || broken(ret == S_OK) /* Win2000 + IE5 */,
           "expected STG_E_ACCESSDENIED, got 0x%08x\n", ret);
    }
    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)
        ok(ret == STG_E_ACCESSDENIED,
           "expected STG_E_ACCESSDENIED, got 0x%08x\n", ret);
    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)
        ok(ret == STG_E_ACCESSDENIED,
           "expected STG_E_ACCESSDENIED, got 0x%08x\n", ret);
    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)
        ok(ret == STG_E_ACCESSDENIED,
           "expected STG_E_ACCESSDENIED, got 0x%08x\n", ret);
    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)
        ok(ret == STG_E_ACCESSDENIED,
           "expected STG_E_ACCESSDENIED, got 0x%08x\n", ret);
    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);
    ok(ret == E_INVALIDARG,
       "expected E_INVALIDARG, got 0x%08x\n", ret);

    /* 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);
    ok(ret == STG_E_INVALIDPOINTER,
       "expected STG_E_INVALIDPOINTER or E_NOTIMPL, got 0x%08x\n", ret);

    /* IStream::Clone */

    /* Passing a NULL pointer for the second IStream::Clone param crashes on Win7 */

    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);
    }
}