push e7552b73e75828caa36d732caa646c0c70d8de9d
[wine/hacks.git] / dlls / amstream / tests / amstream.c
blobf59bc060d782a2f96099423d355b837d9328232e
1 /*
2 * Unit tests for MultiMedia Stream functions
4 * Copyright (C) 2009 Christian Costa
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.
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.
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
21 #include <assert.h>
23 #define COBJMACROS
25 #include "wine/test.h"
26 #include "initguid.h"
27 #include "amstream.h"
29 #define FILE_LEN 9
30 static const char fileA[FILE_LEN] = "test.avi";
32 IAMMultiMediaStream* pams;
33 IDirectDraw7* pdd7 = NULL;
34 IDirectDrawSurface7* pdds7 = NULL;
36 static int create_ammultimediastream(void)
38 return S_OK == CoCreateInstance(
39 &CLSID_AMMultiMediaStream, NULL, CLSCTX_INPROC_SERVER, &IID_IAMMultiMediaStream, (LPVOID*)&pams);
42 static void release_ammultimediastream(void)
44 IAMMultiMediaStream_Release(pams);
47 static int create_directdraw(void)
49 HRESULT hr;
50 IDirectDraw* pdd = NULL;
51 DDSURFACEDESC2 ddsd;
53 hr = DirectDrawCreate(NULL, &pdd, NULL);
54 ok(hr==DD_OK, "DirectDrawCreate returned: %x\n", hr);
55 if (hr != DD_OK)
56 goto error;
58 hr = IDirectDraw_QueryInterface(pdd, &IID_IDirectDraw7, (LPVOID*)&pdd7);
59 ok(hr==DD_OK, "QueryInterface returned: %x\n", hr);
60 if (hr != DD_OK) goto error;
62 hr = IDirectDraw7_SetCooperativeLevel(pdd7, GetDesktopWindow(), DDSCL_NORMAL);
63 ok(hr==DD_OK, "SetCooperativeLevel returned: %x\n", hr);
65 ZeroMemory(&ddsd, sizeof(ddsd));
66 ddsd.dwSize = sizeof(ddsd);
67 ddsd.dwFlags = DDSD_CAPS;
68 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
69 hr = IDirectDraw7_CreateSurface(pdd7, &ddsd, &pdds7, NULL);
70 ok(hr==DD_OK, "CreateSurface returned: %x\n", hr);
72 return TRUE;
74 error:
75 if (pdds7)
76 IDirectDrawSurface7_Release(pdds7);
77 if (pdd7)
78 IDirectDraw7_Release(pdd7);
79 if (pdd)
80 IDirectDraw_Release(pdd);
82 return FALSE;
85 static void release_directdraw(void)
87 IDirectDrawSurface7_Release(pdds7);
88 IDirectDraw7_Release(pdd7);
91 static void test_openfile(void)
93 HANDLE h;
94 HRESULT hr;
95 WCHAR fileW[FILE_LEN];
96 IGraphBuilder* pgraph;
98 if (!create_ammultimediastream())
99 return;
101 h = CreateFileA(fileA, 0, 0, NULL, OPEN_EXISTING, 0, NULL);
102 if (h == INVALID_HANDLE_VALUE) {
103 release_ammultimediastream();
104 return;
107 MultiByteToWideChar(CP_ACP, 0, fileA, -1, fileW, FILE_LEN);
109 hr = IAMMultiMediaStream_GetFilterGraph(pams, &pgraph);
110 ok(hr==S_OK, "IAMMultiMediaStream_GetFilterGraph returned: %x\n", hr);
111 ok(pgraph==NULL, "Filtergraph should not be created yet\n");
113 if (pgraph)
114 IGraphBuilder_Release(pgraph);
116 hr = IAMMultiMediaStream_OpenFile(pams, fileW, 0);
117 ok(hr==S_OK, "IAMMultiMediaStream_OpenFile returned: %x\n", hr);
119 hr = IAMMultiMediaStream_GetFilterGraph(pams, &pgraph);
120 ok(hr==S_OK, "IAMMultiMediaStream_GetFilterGraph returned: %x\n", hr);
121 ok(pgraph!=NULL, "Filtergraph should be created\n");
123 if (pgraph)
124 IGraphBuilder_Release(pgraph);
126 release_ammultimediastream();
129 static void renderfile(const char * fileA)
131 HRESULT hr;
132 WCHAR fileW[FILE_LEN];
133 IMediaStream *pvidstream = NULL;
134 IDirectDrawMediaStream *pddstream = NULL;
135 IDirectDrawStreamSample *pddsample = NULL;
137 if (!create_directdraw())
138 return;
140 MultiByteToWideChar(CP_ACP, 0, fileA, -1, fileW, FILE_LEN);
142 hr = IAMMultiMediaStream_Initialize(pams, STREAMTYPE_READ, 0, NULL);
143 ok(hr==S_OK, "IAMMultiMediaStream_Initialize returned: %x\n", hr);
145 hr = IAMMultiMediaStream_AddMediaStream(pams, (IUnknown*)pdd7, &MSPID_PrimaryVideo, 0, NULL);
146 ok(hr==S_OK, "IAMMultiMediaStream_AddMediaStream returned: %x\n", hr);
148 hr = IAMMultiMediaStream_AddMediaStream(pams, NULL, &MSPID_PrimaryAudio, AMMSF_ADDDEFAULTRENDERER, NULL);
149 ok(hr==S_OK, "IAMMultiMediaStream_AddMediaStream returned: %x\n", hr);
151 hr = IAMMultiMediaStream_OpenFile(pams, fileW, 0);
152 ok(hr==S_OK, "IAMMultiMediaStream_OpenFile returned: %x\n", hr);
154 hr = IAMMultiMediaStream_GetMediaStream(pams, &MSPID_PrimaryVideo, &pvidstream);
155 ok(hr==S_OK, "IAMMultiMediaStream_GetMediaStream returned: %x\n", hr);
156 if (FAILED(hr)) goto error;
158 hr = IMediaStream_QueryInterface(pvidstream, &IID_IDirectDrawMediaStream, (LPVOID*)&pddstream);
159 ok(hr==S_OK, "IMediaStream_QueryInterface returned: %x\n", hr);
160 if (FAILED(hr)) goto error;
162 hr = IDirectDrawMediaStream_CreateSample(pddstream, NULL, NULL, 0, &pddsample);
163 todo_wine ok(hr==S_OK, "IDirectDrawMediaStream_CreateSample returned: %x\n", hr);
165 error:
166 if (pddsample)
167 IDirectDrawMediaSample_Release(pddsample);
168 if (pddstream)
169 IDirectDrawMediaStream_Release(pddstream);
170 if (pvidstream)
171 IMediaStream_Release(pvidstream);
173 release_directdraw();
176 static void test_render(void)
178 HANDLE h;
180 if (!create_ammultimediastream())
181 return;
183 h = CreateFileA(fileA, 0, 0, NULL, OPEN_EXISTING, 0, NULL);
184 if (h != INVALID_HANDLE_VALUE) {
185 CloseHandle(h);
186 renderfile(fileA);
189 release_ammultimediastream();
192 START_TEST(amstream)
194 CoInitializeEx(NULL, COINIT_MULTITHREADED);
195 test_openfile();
196 test_render();
197 CoUninitialize();