qedit: Implement IMediaDet_get_Filename.
[wine] / dlls / qedit / tests / mediadet.c
1 /*
2  * Unit tests for Media Detector
3  *
4  * Copyright (C) 2008 Google (Lei Zhang)
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 "ole2.h"
26 #include "uuids.h"
27 #include "wine/test.h"
28 #include "qedit.h"
29
30 static WCHAR test_avi_filename[MAX_PATH];
31
32 static BOOL init_tests(void)
33 {
34     static WCHAR temp_path[MAX_PATH];
35     static WCHAR prefix[] = {'D','E','S',0};
36     static WCHAR avi[] = {'a','v','i',0};
37     HRSRC res;
38     HGLOBAL data;
39     char *mem;
40     DWORD size, written;
41     HANDLE fh;
42
43     res = FindResourceW(NULL, (LPWSTR) 1, (LPWSTR) 256);
44     if (!res)
45         return FALSE;
46
47     data = LoadResource(NULL, res);
48     if (!data)
49         return FALSE;
50
51     mem = LockResource(data);
52     if (!mem)
53         return FALSE;
54
55     size = SizeofResource(NULL, res);
56     if (size == 0)
57         return FALSE;
58
59     if (!GetTempPathW(MAX_PATH, temp_path))
60         return FALSE;
61
62     /* We might end up relying on the extension here, so .TMP is no good.  */
63     if (!GetTempFileNameW(temp_path, prefix, 0, test_avi_filename))
64         return FALSE;
65
66     DeleteFileW(test_avi_filename);
67     lstrcpyW(test_avi_filename + lstrlenW(test_avi_filename) - 3, avi);
68
69     fh = CreateFileW(test_avi_filename, GENERIC_WRITE, 0, NULL,
70                      CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
71     if (fh == INVALID_HANDLE_VALUE)
72         return FALSE;
73
74     if (!WriteFile(fh, mem, size, &written, NULL) || written != size)
75         return FALSE;
76
77     CloseHandle(fh);
78
79     return TRUE;
80 }
81
82 static void test_mediadet(void)
83 {
84     HRESULT hr;
85     IMediaDet *pM = NULL;
86     BSTR filename = NULL;
87     long nstrms = 0;
88     long strm;
89     AM_MEDIA_TYPE mt;
90
91     hr = CoCreateInstance(&CLSID_MediaDet, NULL, CLSCTX_INPROC_SERVER,
92             &IID_IMediaDet, (LPVOID*)&pM);
93     ok(hr == S_OK, "CoCreateInstance failed with %x\n", hr);
94     ok(pM != NULL, "pM is NULL\n");
95
96     filename = NULL;
97     hr = IMediaDet_get_Filename(pM, &filename);
98     /* Despite what MSDN claims, this returns S_OK.  */
99     ok(hr == S_OK, "IMediaDet_get_Filename\n");
100     ok(filename == NULL, "IMediaDet_get_Filename\n");
101
102     filename = (BSTR) -1;
103     hr = IMediaDet_get_Filename(pM, &filename);
104     /* Despite what MSDN claims, this returns S_OK.  */
105     ok(hr == S_OK, "IMediaDet_get_Filename\n");
106     ok(filename == NULL, "IMediaDet_get_Filename\n");
107
108     filename = SysAllocString(test_avi_filename);
109     hr = IMediaDet_put_Filename(pM, filename);
110     ok(hr == S_OK, "IMediaDet_put_Filename -> %x\n", hr);
111     SysFreeString(filename);
112
113     hr = IMediaDet_get_OutputStreams(pM, &nstrms);
114     todo_wine ok(hr == S_OK, "IMediaDet_get_OutputStreams\n");
115     todo_wine ok(nstrms == 1, "IMediaDet_get_OutputStreams\n");
116
117     filename = NULL;
118     hr = IMediaDet_get_Filename(pM, &filename);
119     ok(hr == S_OK, "IMediaDet_get_Filename\n");
120     ok(lstrcmpW(filename, test_avi_filename) == 0,
121        "IMediaDet_get_Filename\n");
122     SysFreeString(filename);
123
124     hr = IMediaDet_get_Filename(pM, NULL);
125     ok(hr == E_POINTER, "IMediaDet_get_Filename\n");
126
127     hr = IMediaDet_put_CurrentStream(pM, 0);
128     todo_wine ok(hr == S_OK, "IMediaDet_put_CurrentStream\n");
129
130     strm = -1;
131     hr = IMediaDet_get_CurrentStream(pM, &strm);
132     todo_wine ok(hr == S_OK, "IMediaDet_get_CurrentStream\n");
133     todo_wine ok(strm == 0, "IMediaDet_get_CurrentStream\n");
134
135     ZeroMemory(&mt, sizeof mt);
136     hr = IMediaDet_get_StreamMediaType(pM, &mt);
137     todo_wine ok(hr == S_OK, "IMediaDet_get_StreamMediaType\n");
138     todo_wine ok(IsEqualGUID(&mt.majortype, &MEDIATYPE_Video),
139                  "IMediaDet_get_StreamMediaType\n");
140
141     hr = IMediaDet_Release(pM);
142     ok(hr == 0, "IMediaDet_Release returned: %x\n", hr);
143
144     DeleteFileW(test_avi_filename);
145 }
146
147 START_TEST(mediadet)
148 {
149     if (!init_tests())
150     {
151         skip("Couldn't initialize tests!\n");
152         return;
153     }
154
155     CoInitialize(NULL);
156     test_mediadet();
157     CoUninitialize();
158 }