msvcp90: Added ctype<char>::narrow functions implementation.
[wine/multimedia.git] / dlls / amstream / tests / amstream.c
blob4798967cb2aace79340f4b6e086c8137d49938ef
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 #define COBJMACROS
23 #include "wine/test.h"
24 #include "initguid.h"
25 #include "amstream.h"
27 #define FILE_LEN 9
28 static const char fileA[FILE_LEN] = "test.avi";
30 static IAMMultiMediaStream* pams;
31 static IDirectDraw7* pdd7;
32 static IDirectDrawSurface7* pdds7;
34 static int create_ammultimediastream(void)
36 return S_OK == CoCreateInstance(
37 &CLSID_AMMultiMediaStream, NULL, CLSCTX_INPROC_SERVER, &IID_IAMMultiMediaStream, (LPVOID*)&pams);
40 static void release_ammultimediastream(void)
42 IAMMultiMediaStream_Release(pams);
45 static int create_directdraw(void)
47 HRESULT hr;
48 IDirectDraw* pdd = NULL;
49 DDSURFACEDESC2 ddsd;
51 hr = DirectDrawCreate(NULL, &pdd, NULL);
52 ok(hr==DD_OK, "DirectDrawCreate returned: %x\n", hr);
53 if (hr != DD_OK)
54 goto error;
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;
60 hr = IDirectDraw7_SetCooperativeLevel(pdd7, GetDesktopWindow(), DDSCL_NORMAL);
61 ok(hr==DD_OK, "SetCooperativeLevel returned: %x\n", hr);
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);
70 return TRUE;
72 error:
73 if (pdds7)
74 IDirectDrawSurface7_Release(pdds7);
75 if (pdd7)
76 IDirectDraw7_Release(pdd7);
77 if (pdd)
78 IDirectDraw_Release(pdd);
80 return FALSE;
83 static void release_directdraw(void)
85 IDirectDrawSurface7_Release(pdds7);
86 IDirectDraw7_Release(pdd7);
89 static void test_openfile(void)
91 HANDLE h;
92 HRESULT hr;
93 WCHAR fileW[FILE_LEN];
94 IGraphBuilder* pgraph;
96 if (!create_ammultimediastream())
97 return;
99 h = CreateFileA(fileA, 0, 0, NULL, OPEN_EXISTING, 0, NULL);
100 if (h == INVALID_HANDLE_VALUE) {
101 release_ammultimediastream();
102 return;
105 MultiByteToWideChar(CP_ACP, 0, fileA, -1, fileW, FILE_LEN);
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");
111 if (pgraph)
112 IGraphBuilder_Release(pgraph);
114 hr = IAMMultiMediaStream_OpenFile(pams, fileW, 0);
115 ok(hr==S_OK, "IAMMultiMediaStream_OpenFile returned: %x\n", hr);
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");
121 if (pgraph)
122 IGraphBuilder_Release(pgraph);
124 release_ammultimediastream();
127 static void renderfile(const char * fileA)
129 HRESULT hr;
130 WCHAR fileW[FILE_LEN];
131 IMediaStream *pvidstream = NULL;
132 IDirectDrawMediaStream *pddstream = NULL;
133 IDirectDrawStreamSample *pddsample = NULL;
135 if (!create_directdraw())
136 return;
138 MultiByteToWideChar(CP_ACP, 0, fileA, -1, fileW, FILE_LEN);
140 hr = IAMMultiMediaStream_Initialize(pams, STREAMTYPE_READ, 0, NULL);
141 ok(hr==S_OK, "IAMMultiMediaStream_Initialize returned: %x\n", hr);
143 hr = IAMMultiMediaStream_AddMediaStream(pams, (IUnknown*)pdd7, &MSPID_PrimaryVideo, 0, NULL);
144 ok(hr==S_OK, "IAMMultiMediaStream_AddMediaStream returned: %x\n", hr);
146 hr = IAMMultiMediaStream_AddMediaStream(pams, NULL, &MSPID_PrimaryAudio, AMMSF_ADDDEFAULTRENDERER, NULL);
147 ok(hr==S_OK, "IAMMultiMediaStream_AddMediaStream returned: %x\n", hr);
149 hr = IAMMultiMediaStream_OpenFile(pams, fileW, 0);
150 ok(hr==S_OK, "IAMMultiMediaStream_OpenFile returned: %x\n", hr);
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;
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;
160 hr = IDirectDrawMediaStream_CreateSample(pddstream, NULL, NULL, 0, &pddsample);
161 todo_wine ok(hr==S_OK, "IDirectDrawMediaStream_CreateSample returned: %x\n", hr);
163 error:
164 if (pddsample)
165 IDirectDrawMediaSample_Release(pddsample);
166 if (pddstream)
167 IDirectDrawMediaStream_Release(pddstream);
168 if (pvidstream)
169 IMediaStream_Release(pvidstream);
171 release_directdraw();
174 static void test_render(void)
176 HANDLE h;
178 if (!create_ammultimediastream())
179 return;
181 h = CreateFileA(fileA, 0, 0, NULL, OPEN_EXISTING, 0, NULL);
182 if (h != INVALID_HANDLE_VALUE) {
183 CloseHandle(h);
184 renderfile(fileA);
187 release_ammultimediastream();
190 START_TEST(amstream)
192 CoInitializeEx(NULL, COINIT_MULTITHREADED);
193 test_openfile();
194 test_render();
195 CoUninitialize();