filtergraph.c 2.77 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * Unit tests for Direct Show functions
 *
 * Copyright (C) 2004 Christian Costa
 *
 * 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
18
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 20 21
 */

#include <assert.h>
22 23 24

#define COBJMACROS

25 26 27 28 29
#include "wine/test.h"
#include "uuids.h"
#include "dshow.h"
#include "control.h"

30 31
static const WCHAR file[] = {'t','e','s','t','.','a','v','i',0};

32 33
IGraphBuilder* pgraph;

34
static int createfiltergraph(void)
35
{
36 37
    return S_OK == CoCreateInstance(
        &CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, &IID_IGraphBuilder, (LPVOID*)&pgraph);
38 39
}

40
static void renderfile(void)
41 42 43 44
{
    HRESULT hr;

    hr = IGraphBuilder_RenderFile(pgraph, file, NULL);
45
    ok(hr==S_OK, "RenderFile returned: %x\n", hr);
46 47
}

48
static void rungraph(void)
49 50 51
{
    HRESULT hr;
    IMediaControl* pmc;
52 53
    IMediaEvent* pme;
    HANDLE hEvent;
54 55

    hr = IGraphBuilder_QueryInterface(pgraph, &IID_IMediaControl, (LPVOID*)&pmc);
56
    ok(hr==S_OK, "Cannot get IMediaControl interface returned: %x\n", hr);
57 58

    hr = IMediaControl_Run(pmc);
59
    ok(hr==S_FALSE, "Cannot run the graph returned: %x\n", hr);
60

61
    hr = IGraphBuilder_QueryInterface(pgraph, &IID_IMediaEvent, (LPVOID*)&pme);
62
    ok(hr==S_OK, "Cannot get IMediaEvent interface returned: %x\n", hr);
63 64

    hr = IMediaEvent_GetEventHandle(pme, (OAEVENT*)&hEvent);
65
    ok(hr==S_OK, "Cannot get event handle returned: %x\n", hr);
66 67

    /* WaitForSingleObject(hEvent, INFINITE); */
68
    Sleep(20000);
69

70
    hr = IMediaControl_Release(pme);
71
    ok(hr==2, "Releasing mediaevent returned: %x\n", hr);
72

73
    hr = IMediaControl_Stop(pmc);
74
    ok(hr==S_OK, "Cannot stop the graph returned: %x\n", hr);
75 76
    
    hr = IMediaControl_Release(pmc);
77
    ok(hr==1, "Releasing mediacontrol returned: %x\n", hr);
78 79
}

80
static void releasefiltergraph(void)
81 82 83 84
{
    HRESULT hr;

    hr = IGraphBuilder_Release(pgraph);
85
    ok(hr==0, "Releasing filtergraph returned: %x\n", hr);
86 87 88 89
}

START_TEST(filtergraph)
{
90 91
    HANDLE h;
	
92
    CoInitialize(NULL);
93 94
    if (!createfiltergraph())
        return;
95 96 97 98 99 100 101 102

    h = CreateFileW(file, 0, 0, NULL, OPEN_EXISTING, 0, NULL);
    if (h != INVALID_HANDLE_VALUE) {
	CloseHandle(h);
	renderfile();
	rungraph();
    }

103 104
    releasefiltergraph();
}