2008-02-13 23:47:12 +01:00
|
|
|
/*
|
|
|
|
* Unit tests for Media Detector
|
|
|
|
*
|
2008-04-10 01:01:30 +02:00
|
|
|
* Copyright (C) 2008 Google (Lei Zhang, Dan Hipschman)
|
2008-02-13 23:47:12 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
|
2008-07-08 16:17:17 +02:00
|
|
|
#include "initguid.h"
|
2008-04-05 01:01:27 +02:00
|
|
|
#include "ole2.h"
|
2008-04-10 01:02:02 +02:00
|
|
|
#include "vfwmsgs.h"
|
2008-04-05 01:01:27 +02:00
|
|
|
#include "uuids.h"
|
2008-02-13 23:47:12 +01:00
|
|
|
#include "wine/test.h"
|
|
|
|
#include "qedit.h"
|
2008-04-09 01:53:52 +02:00
|
|
|
#include "rc.h"
|
2008-02-13 23:47:12 +01:00
|
|
|
|
2008-04-05 00:59:08 +02:00
|
|
|
static WCHAR test_avi_filename[MAX_PATH];
|
2008-04-09 01:53:52 +02:00
|
|
|
static WCHAR test_sound_avi_filename[MAX_PATH];
|
2008-04-05 00:59:08 +02:00
|
|
|
|
2008-04-09 01:53:52 +02:00
|
|
|
static BOOL unpack_avi_file(int id, WCHAR name[MAX_PATH])
|
2008-04-05 00:59:08 +02:00
|
|
|
{
|
|
|
|
static WCHAR temp_path[MAX_PATH];
|
|
|
|
static WCHAR prefix[] = {'D','E','S',0};
|
|
|
|
static WCHAR avi[] = {'a','v','i',0};
|
|
|
|
HRSRC res;
|
|
|
|
HGLOBAL data;
|
|
|
|
char *mem;
|
|
|
|
DWORD size, written;
|
|
|
|
HANDLE fh;
|
|
|
|
|
2009-01-03 20:14:18 +01:00
|
|
|
res = FindResource(NULL, MAKEINTRESOURCE(id), MAKEINTRESOURCE(AVI_RES_TYPE));
|
2008-04-05 00:59:08 +02:00
|
|
|
if (!res)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
data = LoadResource(NULL, res);
|
|
|
|
if (!data)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
mem = LockResource(data);
|
|
|
|
if (!mem)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
size = SizeofResource(NULL, res);
|
|
|
|
if (size == 0)
|
|
|
|
return FALSE;
|
|
|
|
|
2008-04-09 01:51:28 +02:00
|
|
|
if (!GetTempPathW(MAX_PATH, temp_path))
|
2008-04-05 00:59:08 +02:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* We might end up relying on the extension here, so .TMP is no good. */
|
2008-04-09 01:53:52 +02:00
|
|
|
if (!GetTempFileNameW(temp_path, prefix, 0, name))
|
2008-04-05 00:59:08 +02:00
|
|
|
return FALSE;
|
|
|
|
|
2008-04-09 01:53:52 +02:00
|
|
|
DeleteFileW(name);
|
|
|
|
lstrcpyW(name + lstrlenW(name) - 3, avi);
|
2008-04-05 00:59:08 +02:00
|
|
|
|
2008-04-09 01:53:52 +02:00
|
|
|
fh = CreateFileW(name, GENERIC_WRITE, 0, NULL, CREATE_NEW,
|
|
|
|
FILE_ATTRIBUTE_NORMAL, NULL);
|
2008-04-05 00:59:08 +02:00
|
|
|
if (fh == INVALID_HANDLE_VALUE)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!WriteFile(fh, mem, size, &written, NULL) || written != size)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
CloseHandle(fh);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2008-04-09 01:53:52 +02:00
|
|
|
static BOOL init_tests(void)
|
|
|
|
{
|
|
|
|
return unpack_avi_file(TEST_AVI_RES, test_avi_filename)
|
|
|
|
&& unpack_avi_file(TEST_SOUND_AVI_RES, test_sound_avi_filename);
|
|
|
|
}
|
|
|
|
|
2008-02-13 23:47:12 +01:00
|
|
|
static void test_mediadet(void)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
IMediaDet *pM = NULL;
|
2008-04-05 00:59:08 +02:00
|
|
|
BSTR filename = NULL;
|
2008-04-05 01:00:05 +02:00
|
|
|
long nstrms = 0;
|
2008-04-05 01:01:06 +02:00
|
|
|
long strm;
|
2008-04-05 01:01:27 +02:00
|
|
|
AM_MEDIA_TYPE mt;
|
2008-04-10 01:02:02 +02:00
|
|
|
double fps;
|
2008-04-09 01:53:52 +02:00
|
|
|
int flags;
|
2008-04-10 01:02:02 +02:00
|
|
|
int i;
|
2008-02-13 23:47:12 +01:00
|
|
|
|
2008-04-09 01:53:52 +02:00
|
|
|
/* test.avi has one video stream. */
|
2008-02-13 23:47:12 +01:00
|
|
|
hr = CoCreateInstance(&CLSID_MediaDet, NULL, CLSCTX_INPROC_SERVER,
|
|
|
|
&IID_IMediaDet, (LPVOID*)&pM);
|
|
|
|
ok(hr == S_OK, "CoCreateInstance failed with %x\n", hr);
|
|
|
|
ok(pM != NULL, "pM is NULL\n");
|
2008-02-13 23:12:17 +01:00
|
|
|
|
2008-04-09 01:52:50 +02:00
|
|
|
filename = NULL;
|
|
|
|
hr = IMediaDet_get_Filename(pM, &filename);
|
|
|
|
/* Despite what MSDN claims, this returns S_OK. */
|
|
|
|
ok(hr == S_OK, "IMediaDet_get_Filename\n");
|
|
|
|
ok(filename == NULL, "IMediaDet_get_Filename\n");
|
|
|
|
|
|
|
|
filename = (BSTR) -1;
|
|
|
|
hr = IMediaDet_get_Filename(pM, &filename);
|
|
|
|
/* Despite what MSDN claims, this returns S_OK. */
|
|
|
|
ok(hr == S_OK, "IMediaDet_get_Filename\n");
|
|
|
|
ok(filename == NULL, "IMediaDet_get_Filename\n");
|
|
|
|
|
2008-04-09 01:53:52 +02:00
|
|
|
nstrms = -1;
|
|
|
|
hr = IMediaDet_get_OutputStreams(pM, &nstrms);
|
|
|
|
ok(hr == E_INVALIDARG, "IMediaDet_get_OutputStreams\n");
|
|
|
|
ok(nstrms == -1, "IMediaDet_get_OutputStreams\n");
|
|
|
|
|
2008-04-09 01:55:37 +02:00
|
|
|
strm = -1;
|
|
|
|
/* The stream defaults to 0, even without a file! */
|
|
|
|
hr = IMediaDet_get_CurrentStream(pM, &strm);
|
|
|
|
ok(hr == S_OK, "IMediaDet_get_CurrentStream\n");
|
|
|
|
ok(strm == 0, "IMediaDet_get_CurrentStream\n");
|
|
|
|
|
|
|
|
hr = IMediaDet_get_CurrentStream(pM, NULL);
|
|
|
|
ok(hr == E_POINTER, "IMediaDet_get_CurrentStream\n");
|
|
|
|
|
|
|
|
/* But put_CurrentStream doesn't. */
|
|
|
|
hr = IMediaDet_put_CurrentStream(pM, 0);
|
|
|
|
ok(hr == E_INVALIDARG, "IMediaDet_put_CurrentStream\n");
|
|
|
|
|
|
|
|
hr = IMediaDet_put_CurrentStream(pM, -1);
|
|
|
|
ok(hr == E_INVALIDARG, "IMediaDet_put_CurrentStream\n");
|
|
|
|
|
2008-04-10 01:01:30 +02:00
|
|
|
hr = IMediaDet_get_StreamMediaType(pM, &mt);
|
|
|
|
ok(hr == E_INVALIDARG, "IMediaDet_get_StreamMediaType\n");
|
|
|
|
|
|
|
|
hr = IMediaDet_get_StreamMediaType(pM, NULL);
|
|
|
|
ok(hr == E_POINTER, "IMediaDet_get_StreamMediaType\n");
|
|
|
|
|
2008-04-05 00:59:08 +02:00
|
|
|
filename = SysAllocString(test_avi_filename);
|
|
|
|
hr = IMediaDet_put_Filename(pM, filename);
|
2008-04-09 01:52:14 +02:00
|
|
|
ok(hr == S_OK, "IMediaDet_put_Filename -> %x\n", hr);
|
2008-04-05 00:59:08 +02:00
|
|
|
SysFreeString(filename);
|
|
|
|
|
2008-04-09 01:55:37 +02:00
|
|
|
strm = -1;
|
|
|
|
/* The stream defaults to 0. */
|
|
|
|
hr = IMediaDet_get_CurrentStream(pM, &strm);
|
|
|
|
ok(hr == S_OK, "IMediaDet_get_CurrentStream\n");
|
|
|
|
ok(strm == 0, "IMediaDet_get_CurrentStream\n");
|
|
|
|
|
2008-04-10 01:01:30 +02:00
|
|
|
ZeroMemory(&mt, sizeof mt);
|
|
|
|
hr = IMediaDet_get_StreamMediaType(pM, &mt);
|
|
|
|
ok(hr == S_OK, "IMediaDet_get_StreamMediaType\n");
|
|
|
|
CoTaskMemFree(mt.pbFormat);
|
|
|
|
|
2008-04-09 01:55:37 +02:00
|
|
|
/* Even before get_OutputStreams. */
|
|
|
|
hr = IMediaDet_put_CurrentStream(pM, 1);
|
|
|
|
ok(hr == E_INVALIDARG, "IMediaDet_put_CurrentStream\n");
|
|
|
|
|
2008-04-05 01:00:05 +02:00
|
|
|
hr = IMediaDet_get_OutputStreams(pM, &nstrms);
|
2008-04-09 01:53:52 +02:00
|
|
|
ok(hr == S_OK, "IMediaDet_get_OutputStreams\n");
|
|
|
|
ok(nstrms == 1, "IMediaDet_get_OutputStreams\n");
|
2008-04-05 01:00:05 +02:00
|
|
|
|
2008-04-05 01:00:41 +02:00
|
|
|
filename = NULL;
|
|
|
|
hr = IMediaDet_get_Filename(pM, &filename);
|
2008-04-09 01:52:50 +02:00
|
|
|
ok(hr == S_OK, "IMediaDet_get_Filename\n");
|
|
|
|
ok(lstrcmpW(filename, test_avi_filename) == 0,
|
|
|
|
"IMediaDet_get_Filename\n");
|
2008-04-05 01:00:41 +02:00
|
|
|
SysFreeString(filename);
|
|
|
|
|
2008-04-09 01:52:50 +02:00
|
|
|
hr = IMediaDet_get_Filename(pM, NULL);
|
|
|
|
ok(hr == E_POINTER, "IMediaDet_get_Filename\n");
|
|
|
|
|
2008-04-09 01:55:37 +02:00
|
|
|
strm = -1;
|
|
|
|
hr = IMediaDet_get_CurrentStream(pM, &strm);
|
|
|
|
ok(hr == S_OK, "IMediaDet_get_CurrentStream\n");
|
|
|
|
ok(strm == 0, "IMediaDet_get_CurrentStream\n");
|
|
|
|
|
|
|
|
hr = IMediaDet_get_CurrentStream(pM, NULL);
|
|
|
|
ok(hr == E_POINTER, "IMediaDet_get_CurrentStream\n");
|
|
|
|
|
|
|
|
hr = IMediaDet_put_CurrentStream(pM, -1);
|
|
|
|
ok(hr == E_INVALIDARG, "IMediaDet_put_CurrentStream\n");
|
|
|
|
|
|
|
|
hr = IMediaDet_put_CurrentStream(pM, 1);
|
|
|
|
ok(hr == E_INVALIDARG, "IMediaDet_put_CurrentStream\n");
|
|
|
|
|
|
|
|
/* Try again. */
|
|
|
|
strm = -1;
|
|
|
|
hr = IMediaDet_get_CurrentStream(pM, &strm);
|
|
|
|
ok(hr == S_OK, "IMediaDet_get_CurrentStream\n");
|
|
|
|
ok(strm == 0, "IMediaDet_get_CurrentStream\n");
|
|
|
|
|
2008-04-05 01:01:06 +02:00
|
|
|
hr = IMediaDet_put_CurrentStream(pM, 0);
|
2008-04-09 01:55:37 +02:00
|
|
|
ok(hr == S_OK, "IMediaDet_put_CurrentStream\n");
|
2008-04-05 01:01:06 +02:00
|
|
|
|
|
|
|
strm = -1;
|
|
|
|
hr = IMediaDet_get_CurrentStream(pM, &strm);
|
2008-04-09 01:55:37 +02:00
|
|
|
ok(hr == S_OK, "IMediaDet_get_CurrentStream\n");
|
|
|
|
ok(strm == 0, "IMediaDet_get_CurrentStream\n");
|
2008-04-05 01:01:06 +02:00
|
|
|
|
2008-04-05 01:01:27 +02:00
|
|
|
ZeroMemory(&mt, sizeof mt);
|
|
|
|
hr = IMediaDet_get_StreamMediaType(pM, &mt);
|
2008-04-10 01:01:30 +02:00
|
|
|
ok(hr == S_OK, "IMediaDet_get_StreamMediaType\n");
|
|
|
|
ok(IsEqualGUID(&mt.majortype, &MEDIATYPE_Video),
|
2008-04-05 01:01:27 +02:00
|
|
|
"IMediaDet_get_StreamMediaType\n");
|
2008-04-10 01:01:30 +02:00
|
|
|
CoTaskMemFree(mt.pbFormat);
|
2008-04-05 01:01:27 +02:00
|
|
|
|
2008-04-10 01:02:02 +02:00
|
|
|
hr = IMediaDet_get_FrameRate(pM, NULL);
|
|
|
|
ok(hr == E_POINTER, "IMediaDet_get_FrameRate\n");
|
|
|
|
|
|
|
|
hr = IMediaDet_get_FrameRate(pM, &fps);
|
|
|
|
ok(hr == S_OK, "IMediaDet_get_FrameRate\n");
|
|
|
|
ok(fps == 10.0, "IMediaDet_get_FrameRate\n");
|
|
|
|
|
2008-02-13 23:12:17 +01:00
|
|
|
hr = IMediaDet_Release(pM);
|
|
|
|
ok(hr == 0, "IMediaDet_Release returned: %x\n", hr);
|
2008-04-05 00:59:08 +02:00
|
|
|
|
|
|
|
DeleteFileW(test_avi_filename);
|
2008-04-09 01:53:52 +02:00
|
|
|
|
|
|
|
/* test_sound.avi has one video stream and one audio stream. */
|
|
|
|
hr = CoCreateInstance(&CLSID_MediaDet, NULL, CLSCTX_INPROC_SERVER,
|
|
|
|
&IID_IMediaDet, (LPVOID*)&pM);
|
|
|
|
ok(hr == S_OK, "CoCreateInstance failed with %x\n", hr);
|
|
|
|
ok(pM != NULL, "pM is NULL\n");
|
|
|
|
|
|
|
|
filename = SysAllocString(test_sound_avi_filename);
|
|
|
|
hr = IMediaDet_put_Filename(pM, filename);
|
|
|
|
ok(hr == S_OK, "IMediaDet_put_Filename -> %x\n", hr);
|
|
|
|
SysFreeString(filename);
|
|
|
|
|
|
|
|
hr = IMediaDet_get_OutputStreams(pM, &nstrms);
|
|
|
|
ok(hr == S_OK, "IMediaDet_get_OutputStreams\n");
|
|
|
|
ok(nstrms == 2, "IMediaDet_get_OutputStreams\n");
|
|
|
|
|
|
|
|
filename = NULL;
|
|
|
|
hr = IMediaDet_get_Filename(pM, &filename);
|
|
|
|
ok(hr == S_OK, "IMediaDet_get_Filename\n");
|
|
|
|
ok(lstrcmpW(filename, test_sound_avi_filename) == 0,
|
|
|
|
"IMediaDet_get_Filename\n");
|
|
|
|
SysFreeString(filename);
|
|
|
|
|
|
|
|
/* I don't know if the stream order is deterministic. Just check
|
|
|
|
for both an audio and video stream. */
|
|
|
|
flags = 0;
|
|
|
|
|
2008-04-10 01:02:02 +02:00
|
|
|
for (i = 0; i < 2; ++i)
|
|
|
|
{
|
|
|
|
hr = IMediaDet_put_CurrentStream(pM, i);
|
|
|
|
ok(hr == S_OK, "IMediaDet_put_CurrentStream\n");
|
|
|
|
|
|
|
|
strm = -1;
|
|
|
|
hr = IMediaDet_get_CurrentStream(pM, &strm);
|
|
|
|
ok(hr == S_OK, "IMediaDet_get_CurrentStream\n");
|
|
|
|
ok(strm == i, "IMediaDet_get_CurrentStream\n");
|
|
|
|
|
|
|
|
ZeroMemory(&mt, sizeof mt);
|
|
|
|
hr = IMediaDet_get_StreamMediaType(pM, &mt);
|
|
|
|
ok(hr == S_OK, "IMediaDet_get_StreamMediaType\n");
|
|
|
|
flags += (IsEqualGUID(&mt.majortype, &MEDIATYPE_Video)
|
|
|
|
? 1
|
|
|
|
: (IsEqualGUID(&mt.majortype, &MEDIATYPE_Audio)
|
|
|
|
? 2
|
|
|
|
: 0));
|
|
|
|
|
|
|
|
if (IsEqualGUID(&mt.majortype, &MEDIATYPE_Audio))
|
|
|
|
{
|
|
|
|
hr = IMediaDet_get_FrameRate(pM, &fps);
|
|
|
|
ok(hr == VFW_E_INVALIDMEDIATYPE, "IMediaDet_get_FrameRate\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
CoTaskMemFree(mt.pbFormat);
|
|
|
|
}
|
2008-04-10 01:01:30 +02:00
|
|
|
ok(flags == 3, "IMediaDet_get_StreamMediaType\n");
|
2008-04-09 01:53:52 +02:00
|
|
|
|
2008-04-09 01:55:37 +02:00
|
|
|
hr = IMediaDet_put_CurrentStream(pM, 2);
|
|
|
|
ok(hr == E_INVALIDARG, "IMediaDet_put_CurrentStream\n");
|
|
|
|
|
|
|
|
strm = -1;
|
|
|
|
hr = IMediaDet_get_CurrentStream(pM, &strm);
|
|
|
|
ok(hr == S_OK, "IMediaDet_get_CurrentStream\n");
|
|
|
|
ok(strm == 1, "IMediaDet_get_CurrentStream\n");
|
|
|
|
|
2008-04-09 01:53:52 +02:00
|
|
|
hr = IMediaDet_Release(pM);
|
|
|
|
ok(hr == 0, "IMediaDet_Release returned: %x\n", hr);
|
|
|
|
|
|
|
|
DeleteFileW(test_sound_avi_filename);
|
2008-02-13 23:47:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
START_TEST(mediadet)
|
|
|
|
{
|
2008-04-05 00:59:08 +02:00
|
|
|
if (!init_tests())
|
|
|
|
{
|
|
|
|
skip("Couldn't initialize tests!\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-02-13 23:47:12 +01:00
|
|
|
CoInitialize(NULL);
|
|
|
|
test_mediadet();
|
2008-04-05 00:58:17 +02:00
|
|
|
CoUninitialize();
|
2008-02-13 23:47:12 +01:00
|
|
|
}
|