Release 1.4-rc5.
[wine] / dlls / amstream / tests / amstream.c
1 /*
2  * Unit tests for MultiMedia Stream functions
3  *
4  * Copyright (C) 2009 Christian Costa
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * 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 #define COBJMACROS
22
23 #include "wine/test.h"
24 #include "initguid.h"
25 #include "amstream.h"
26
27 #define FILE_LEN 9
28 static const char fileA[FILE_LEN] = "test.avi";
29
30 static IAMMultiMediaStream* pams;
31 static IDirectDraw7* pdd7;
32 static IDirectDrawSurface7* pdds7;
33
34 static int create_ammultimediastream(void)
35 {
36     return S_OK == CoCreateInstance(
37         &CLSID_AMMultiMediaStream, NULL, CLSCTX_INPROC_SERVER, &IID_IAMMultiMediaStream, (LPVOID*)&pams);
38 }
39
40 static void release_ammultimediastream(void)
41 {
42     IAMMultiMediaStream_Release(pams);
43 }
44
45 static int create_directdraw(void)
46 {
47     HRESULT hr;
48     IDirectDraw* pdd = NULL;
49     DDSURFACEDESC2 ddsd;
50
51     hr = DirectDrawCreate(NULL, &pdd, NULL);
52     ok(hr==DD_OK, "DirectDrawCreate returned: %x\n", hr);
53     if (hr != DD_OK)
54        goto error;
55
56     hr = IDirectDraw_QueryInterface(pdd, &IID_IDirectDraw7, (LPVOID*)&pdd7);
57     ok(hr==DD_OK, "QueryInterface returned: %x\n", hr);
58     if (hr != DD_OK) goto error;
59
60     hr = IDirectDraw7_SetCooperativeLevel(pdd7, GetDesktopWindow(), DDSCL_NORMAL);
61     ok(hr==DD_OK, "SetCooperativeLevel returned: %x\n", hr);
62
63     ZeroMemory(&ddsd, sizeof(ddsd));
64     ddsd.dwSize = sizeof(ddsd);
65     ddsd.dwFlags = DDSD_CAPS;
66     ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
67     hr = IDirectDraw7_CreateSurface(pdd7, &ddsd, &pdds7, NULL);
68     ok(hr==DD_OK, "CreateSurface returned: %x\n", hr);
69
70     return TRUE;
71
72 error:
73     if (pdds7)
74         IDirectDrawSurface7_Release(pdds7);
75     if (pdd7)
76         IDirectDraw7_Release(pdd7);
77     if (pdd)
78         IDirectDraw_Release(pdd);
79
80     return FALSE;
81 }
82
83 static void release_directdraw(void)
84 {
85     IDirectDrawSurface7_Release(pdds7);
86     IDirectDraw7_Release(pdd7);
87 }
88
89 static void test_openfile(void)
90 {
91     HANDLE h;
92     HRESULT hr;
93     WCHAR fileW[FILE_LEN];
94     IGraphBuilder* pgraph;
95
96     if (!create_ammultimediastream())
97         return;
98
99     h = CreateFileA(fileA, 0, 0, NULL, OPEN_EXISTING, 0, NULL);
100     if (h == INVALID_HANDLE_VALUE) {
101         release_ammultimediastream();
102         return;
103     }
104
105     MultiByteToWideChar(CP_ACP, 0, fileA, -1, fileW, FILE_LEN);
106
107     hr = IAMMultiMediaStream_GetFilterGraph(pams, &pgraph);
108     ok(hr==S_OK, "IAMMultiMediaStream_GetFilterGraph returned: %x\n", hr);
109     ok(pgraph==NULL, "Filtergraph should not be created yet\n");
110
111     if (pgraph)
112         IGraphBuilder_Release(pgraph);
113
114     hr = IAMMultiMediaStream_OpenFile(pams, fileW, 0);
115     ok(hr==S_OK, "IAMMultiMediaStream_OpenFile returned: %x\n", hr);
116
117     hr = IAMMultiMediaStream_GetFilterGraph(pams, &pgraph);
118     ok(hr==S_OK, "IAMMultiMediaStream_GetFilterGraph returned: %x\n", hr);
119     ok(pgraph!=NULL, "Filtergraph should be created\n");
120
121     if (pgraph)
122         IGraphBuilder_Release(pgraph);
123
124     release_ammultimediastream();
125 }
126
127 static void renderfile(const char * fileA)
128 {
129     HRESULT hr;
130     WCHAR fileW[FILE_LEN];
131     IMediaStream *pvidstream = NULL;
132     IDirectDrawMediaStream *pddstream = NULL;
133     IDirectDrawStreamSample *pddsample = NULL;
134
135     if (!create_directdraw())
136         return;
137
138     MultiByteToWideChar(CP_ACP, 0, fileA, -1, fileW, FILE_LEN);
139
140     hr = IAMMultiMediaStream_Initialize(pams, STREAMTYPE_READ, 0, NULL);
141     ok(hr==S_OK, "IAMMultiMediaStream_Initialize returned: %x\n", hr);
142
143     hr = IAMMultiMediaStream_AddMediaStream(pams, (IUnknown*)pdd7, &MSPID_PrimaryVideo, 0, NULL);
144     ok(hr==S_OK, "IAMMultiMediaStream_AddMediaStream returned: %x\n", hr);
145
146     hr = IAMMultiMediaStream_AddMediaStream(pams, NULL, &MSPID_PrimaryAudio, AMMSF_ADDDEFAULTRENDERER, NULL);
147     ok(hr==S_OK, "IAMMultiMediaStream_AddMediaStream returned: %x\n", hr);
148
149     hr = IAMMultiMediaStream_OpenFile(pams, fileW, 0);
150     ok(hr==S_OK, "IAMMultiMediaStream_OpenFile returned: %x\n", hr);
151
152     hr = IAMMultiMediaStream_GetMediaStream(pams, &MSPID_PrimaryVideo, &pvidstream);
153     ok(hr==S_OK, "IAMMultiMediaStream_GetMediaStream returned: %x\n", hr);
154     if (FAILED(hr)) goto error;
155
156     hr = IMediaStream_QueryInterface(pvidstream, &IID_IDirectDrawMediaStream, (LPVOID*)&pddstream);
157     ok(hr==S_OK, "IMediaStream_QueryInterface returned: %x\n", hr);
158     if (FAILED(hr)) goto error;
159
160     hr = IDirectDrawMediaStream_CreateSample(pddstream, NULL, NULL, 0, &pddsample);
161     todo_wine ok(hr==S_OK, "IDirectDrawMediaStream_CreateSample returned: %x\n", hr);
162
163 error:
164     if (pddsample)
165         IDirectDrawMediaSample_Release(pddsample);
166     if (pddstream)
167         IDirectDrawMediaStream_Release(pddstream);
168     if (pvidstream)
169         IMediaStream_Release(pvidstream);
170
171     release_directdraw();
172 }
173
174 static void test_render(void)
175 {
176     HANDLE h;
177
178     if (!create_ammultimediastream())
179         return;
180
181     h = CreateFileA(fileA, 0, 0, NULL, OPEN_EXISTING, 0, NULL);
182     if (h != INVALID_HANDLE_VALUE) {
183         CloseHandle(h);
184         renderfile(fileA);
185     }
186
187     release_ammultimediastream();
188 }
189
190 START_TEST(amstream)
191 {
192     CoInitializeEx(NULL, COINIT_MULTITHREADED);
193     test_openfile();
194     test_render();
195     CoUninitialize();
196 }