comctl32/toolbar: When a null lParam is passed to TB_GETBUTTONTEXTA, we should not...
[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 #include <assert.h>
22
23 #define COBJMACROS
24
25 #include "wine/test.h"
26 #include "initguid.h"
27 #include "amstream.h"
28
29 #define FILE_LEN 9
30 static const char fileA[FILE_LEN] = "test.avi";
31
32 IAMMultiMediaStream* pams;
33 IDirectDraw7* pdd7 = NULL;
34 IDirectDrawSurface7* pdds7 = NULL;
35
36 static int create_ammultimediastream(void)
37 {
38     return S_OK == CoCreateInstance(
39         &CLSID_AMMultiMediaStream, NULL, CLSCTX_INPROC_SERVER, &IID_IAMMultiMediaStream, (LPVOID*)&pams);
40 }
41
42 static void release_ammultimediastream(void)
43 {
44     IAMMultiMediaStream_Release(pams);
45 }
46
47 static int create_directdraw(void)
48 {
49     HRESULT hr;
50     IDirectDraw* pdd = NULL;
51     DDSURFACEDESC2 ddsd;
52
53     hr = DirectDrawCreate(NULL, &pdd, NULL);
54     ok(hr==DD_OK, "DirectDrawCreate returned: %x\n", hr);
55     if (hr != DD_OK)
56        goto error;
57
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;
61
62     hr = IDirectDraw7_SetCooperativeLevel(pdd7, GetDesktopWindow(), DDSCL_NORMAL);
63     ok(hr==DD_OK, "SetCooperativeLevel returned: %x\n", hr);
64
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);
71
72     return TRUE;
73
74 error:
75     if (pdds7)
76         IDirectDrawSurface7_Release(pdds7);
77     if (pdd7)
78         IDirectDraw7_Release(pdd7);
79     if (pdd)
80         IDirectDraw_Release(pdd);
81
82     return FALSE;
83 }
84
85 static void release_directdraw(void)
86 {
87     IDirectDrawSurface7_Release(pdds7);
88     IDirectDraw7_Release(pdd7);
89 }
90
91 static void test_openfile(void)
92 {
93     HANDLE h;
94     HRESULT hr;
95     WCHAR fileW[FILE_LEN];
96     IGraphBuilder* pgraph;
97
98     if (!create_ammultimediastream())
99         return;
100
101     h = CreateFileA(fileA, 0, 0, NULL, OPEN_EXISTING, 0, NULL);
102     if (h == INVALID_HANDLE_VALUE) {
103         release_ammultimediastream();
104         return;
105     }
106
107     MultiByteToWideChar(CP_ACP, 0, fileA, -1, fileW, FILE_LEN);
108
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");
112
113     if (pgraph)
114         IGraphBuilder_Release(pgraph);
115
116     hr = IAMMultiMediaStream_OpenFile(pams, fileW, 0);
117     ok(hr==S_OK, "IAMMultiMediaStream_OpenFile returned: %x\n", hr);
118
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");
122
123     if (pgraph)
124         IGraphBuilder_Release(pgraph);
125
126     release_ammultimediastream();
127 }
128
129 static void renderfile(const char * fileA)
130 {
131     HRESULT hr;
132     WCHAR fileW[FILE_LEN];
133     IMediaStream *pvidstream = NULL;
134     IDirectDrawMediaStream *pddstream = NULL;
135     IDirectDrawStreamSample *pddsample = NULL;
136
137     if (!create_directdraw())
138         return;
139
140     MultiByteToWideChar(CP_ACP, 0, fileA, -1, fileW, FILE_LEN);
141
142     hr = IAMMultiMediaStream_Initialize(pams, STREAMTYPE_READ, 0, NULL);
143     ok(hr==S_OK, "IAMMultiMediaStream_Initialize returned: %x\n", hr);
144
145     hr = IAMMultiMediaStream_AddMediaStream(pams, (IUnknown*)pdd7, &MSPID_PrimaryVideo, 0, NULL);
146     ok(hr==S_OK, "IAMMultiMediaStream_AddMediaStream returned: %x\n", hr);
147
148     hr = IAMMultiMediaStream_AddMediaStream(pams, NULL, &MSPID_PrimaryAudio, AMMSF_ADDDEFAULTRENDERER, NULL);
149     ok(hr==S_OK, "IAMMultiMediaStream_AddMediaStream returned: %x\n", hr);
150
151     hr = IAMMultiMediaStream_OpenFile(pams, fileW, 0);
152     ok(hr==S_OK, "IAMMultiMediaStream_OpenFile returned: %x\n", hr);
153
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;
157
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;
161
162     hr = IDirectDrawMediaStream_CreateSample(pddstream, NULL, NULL, 0, &pddsample);
163     todo_wine ok(hr==S_OK, "IDirectDrawMediaStream_CreateSample returned: %x\n", hr);
164
165 error:
166     if (pddsample)
167         IDirectDrawMediaSample_Release(pddsample);
168     if (pddstream)
169         IDirectDrawMediaStream_Release(pddstream);
170     if (pvidstream)
171         IMediaStream_Release(pvidstream);
172
173     release_directdraw();
174 }
175
176 static void test_render(void)
177 {
178     HANDLE h;
179
180     if (!create_ammultimediastream())
181         return;
182
183     h = CreateFileA(fileA, 0, 0, NULL, OPEN_EXISTING, 0, NULL);
184     if (h != INVALID_HANDLE_VALUE) {
185         CloseHandle(h);
186         renderfile(fileA);
187     }
188
189     release_ammultimediastream();
190 }
191
192 START_TEST(amstream)
193 {
194     CoInitializeEx(NULL, COINIT_MULTITHREADED);
195     test_openfile();
196     test_render();
197     CoUninitialize();
198 }