2007-08-11 04:29:26 +02:00
|
|
|
/*
|
2019-03-13 15:54:03 +01:00
|
|
|
* System clock unit tests
|
2007-08-11 04:29:26 +02:00
|
|
|
*
|
|
|
|
* Copyright (C) 2007 Alex Villacís Lasso
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
#include "dshow.h"
|
2019-03-13 15:54:03 +01:00
|
|
|
#include "wine/test.h"
|
2007-08-11 04:29:26 +02:00
|
|
|
|
2019-03-13 15:54:04 +01:00
|
|
|
static ULONGLONG (WINAPI *pGetTickCount64)(void);
|
|
|
|
|
2020-05-28 00:38:09 +02:00
|
|
|
static BOOL compare_time(REFERENCE_TIME x, REFERENCE_TIME y, unsigned int max_diff)
|
|
|
|
{
|
|
|
|
REFERENCE_TIME diff = x > y ? x - y : y - x;
|
|
|
|
return diff <= max_diff;
|
|
|
|
}
|
|
|
|
|
2019-03-13 15:54:03 +01:00
|
|
|
static IReferenceClock *create_system_clock(void)
|
2007-12-13 12:12:42 +01:00
|
|
|
{
|
2019-11-29 00:35:38 +01:00
|
|
|
IReferenceClock *clock = NULL;
|
2019-03-13 15:54:03 +01:00
|
|
|
HRESULT hr = CoCreateInstance(&CLSID_SystemClock, NULL, CLSCTX_INPROC_SERVER,
|
2019-11-29 00:35:38 +01:00
|
|
|
&IID_IReferenceClock, (void **)&clock);
|
2019-03-13 15:54:03 +01:00
|
|
|
ok(hr == S_OK, "Got hr %#x.\n", hr);
|
2019-11-29 00:35:38 +01:00
|
|
|
return clock;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG get_refcount(void *iface)
|
|
|
|
{
|
|
|
|
IUnknown *unknown = iface;
|
|
|
|
IUnknown_AddRef(unknown);
|
|
|
|
return IUnknown_Release(unknown);
|
2019-03-13 15:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#define check_interface(a, b, c) check_interface_(__LINE__, a, b, c)
|
|
|
|
static void check_interface_(unsigned int line, void *iface_ptr, REFIID iid, BOOL supported)
|
|
|
|
{
|
|
|
|
IUnknown *iface = iface_ptr;
|
|
|
|
HRESULT hr, expected_hr;
|
|
|
|
IUnknown *unk;
|
|
|
|
|
|
|
|
expected_hr = supported ? S_OK : E_NOINTERFACE;
|
|
|
|
|
|
|
|
hr = IUnknown_QueryInterface(iface, iid, (void **)&unk);
|
|
|
|
ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x, expected %#x.\n", hr, expected_hr);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
IUnknown_Release(unk);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_interfaces(void)
|
|
|
|
{
|
|
|
|
IReferenceClock *clock = create_system_clock();
|
|
|
|
ULONG ref;
|
2007-12-13 12:12:42 +01:00
|
|
|
|
2019-03-13 15:54:03 +01:00
|
|
|
check_interface(clock, &IID_IReferenceClock, TRUE);
|
|
|
|
check_interface(clock, &IID_IUnknown, TRUE);
|
2007-12-13 12:12:42 +01:00
|
|
|
|
2019-03-13 15:54:03 +01:00
|
|
|
check_interface(clock, &IID_IDirectDraw, FALSE);
|
2007-12-13 12:12:42 +01:00
|
|
|
|
2019-03-13 15:54:03 +01:00
|
|
|
ref = IReferenceClock_Release(clock);
|
|
|
|
ok(!ref, "Got outstanding refcount %d.\n", ref);
|
2007-12-13 12:12:42 +01:00
|
|
|
}
|
|
|
|
|
2019-11-29 00:35:38 +01:00
|
|
|
static const GUID test_iid = {0x33333333};
|
|
|
|
static LONG outer_ref = 1;
|
|
|
|
|
|
|
|
static HRESULT WINAPI outer_QueryInterface(IUnknown *iface, REFIID iid, void **out)
|
|
|
|
{
|
|
|
|
if (IsEqualGUID(iid, &IID_IUnknown)
|
|
|
|
|| IsEqualGUID(iid, &IID_IReferenceClock)
|
|
|
|
|| IsEqualGUID(iid, &test_iid))
|
|
|
|
{
|
|
|
|
*out = (IUnknown *)0xdeadbeef;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
ok(0, "unexpected call %s\n", wine_dbgstr_guid(iid));
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI outer_AddRef(IUnknown *iface)
|
|
|
|
{
|
|
|
|
return InterlockedIncrement(&outer_ref);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI outer_Release(IUnknown *iface)
|
|
|
|
{
|
|
|
|
return InterlockedDecrement(&outer_ref);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IUnknownVtbl outer_vtbl =
|
|
|
|
{
|
|
|
|
outer_QueryInterface,
|
|
|
|
outer_AddRef,
|
|
|
|
outer_Release,
|
|
|
|
};
|
|
|
|
|
|
|
|
static IUnknown test_outer = {&outer_vtbl};
|
|
|
|
|
|
|
|
static void test_aggregation(void)
|
|
|
|
{
|
|
|
|
IReferenceClock *clock, *clock2;
|
|
|
|
IUnknown *unk, *unk2;
|
|
|
|
HRESULT hr;
|
|
|
|
ULONG ref;
|
|
|
|
|
|
|
|
clock = (IReferenceClock *)0xdeadbeef;
|
|
|
|
hr = CoCreateInstance(&CLSID_SystemClock, &test_outer, CLSCTX_INPROC_SERVER,
|
|
|
|
&IID_IReferenceClock, (void **)&clock);
|
|
|
|
ok(hr == E_NOINTERFACE, "Got hr %#x.\n", hr);
|
|
|
|
ok(!clock, "Got interface %p.\n", clock);
|
|
|
|
|
|
|
|
hr = CoCreateInstance(&CLSID_SystemClock, &test_outer, CLSCTX_INPROC_SERVER,
|
|
|
|
&IID_IUnknown, (void **)&unk);
|
|
|
|
ok(hr == S_OK, "Got hr %#x.\n", hr);
|
|
|
|
ok(outer_ref == 1, "Got unexpected refcount %d.\n", outer_ref);
|
|
|
|
ok(unk != &test_outer, "Returned IUnknown should not be outer IUnknown.\n");
|
|
|
|
ref = get_refcount(unk);
|
|
|
|
ok(ref == 1, "Got unexpected refcount %d.\n", ref);
|
|
|
|
|
|
|
|
ref = IUnknown_AddRef(unk);
|
|
|
|
ok(ref == 2, "Got unexpected refcount %d.\n", ref);
|
|
|
|
ok(outer_ref == 1, "Got unexpected refcount %d.\n", outer_ref);
|
|
|
|
|
|
|
|
ref = IUnknown_Release(unk);
|
|
|
|
ok(ref == 1, "Got unexpected refcount %d.\n", ref);
|
|
|
|
ok(outer_ref == 1, "Got unexpected refcount %d.\n", outer_ref);
|
|
|
|
|
|
|
|
hr = IUnknown_QueryInterface(unk, &IID_IUnknown, (void **)&unk2);
|
|
|
|
ok(hr == S_OK, "Got hr %#x.\n", hr);
|
|
|
|
ok(unk2 == unk, "Got unexpected IUnknown %p.\n", unk2);
|
|
|
|
IUnknown_Release(unk2);
|
|
|
|
|
|
|
|
hr = IUnknown_QueryInterface(unk, &IID_IReferenceClock, (void **)&clock);
|
|
|
|
ok(hr == S_OK, "Got hr %#x.\n", hr);
|
|
|
|
|
|
|
|
hr = IReferenceClock_QueryInterface(clock, &IID_IUnknown, (void **)&unk2);
|
|
|
|
ok(hr == S_OK, "Got hr %#x.\n", hr);
|
|
|
|
ok(unk2 == (IUnknown *)0xdeadbeef, "Got unexpected IUnknown %p.\n", unk2);
|
|
|
|
|
|
|
|
hr = IReferenceClock_QueryInterface(clock, &IID_IReferenceClock, (void **)&clock2);
|
|
|
|
ok(hr == S_OK, "Got hr %#x.\n", hr);
|
|
|
|
ok(clock2 == (IReferenceClock *)0xdeadbeef, "Got unexpected IReferenceClock %p.\n", clock2);
|
|
|
|
|
|
|
|
hr = IUnknown_QueryInterface(unk, &test_iid, (void **)&unk2);
|
|
|
|
ok(hr == E_NOINTERFACE, "Got hr %#x.\n", hr);
|
|
|
|
ok(!unk2, "Got unexpected IUnknown %p.\n", unk2);
|
|
|
|
|
|
|
|
hr = IReferenceClock_QueryInterface(clock, &test_iid, (void **)&unk2);
|
|
|
|
ok(hr == S_OK, "Got hr %#x.\n", hr);
|
|
|
|
ok(unk2 == (IUnknown *)0xdeadbeef, "Got unexpected IUnknown %p.\n", unk2);
|
|
|
|
|
|
|
|
IReferenceClock_Release(clock);
|
|
|
|
ref = IUnknown_Release(unk);
|
|
|
|
ok(!ref, "Got unexpected refcount %d.\n", ref);
|
|
|
|
ok(outer_ref == 1, "Got unexpected refcount %d.\n", outer_ref);
|
|
|
|
}
|
|
|
|
|
2019-03-13 15:54:04 +01:00
|
|
|
static void test_get_time(void)
|
2007-08-11 04:29:26 +02:00
|
|
|
{
|
2019-03-13 15:54:04 +01:00
|
|
|
IReferenceClock *clock = create_system_clock();
|
|
|
|
REFERENCE_TIME time1, time2;
|
2007-08-11 04:29:26 +02:00
|
|
|
HRESULT hr;
|
2019-03-13 15:54:04 +01:00
|
|
|
ULONG ref;
|
2007-08-11 04:29:26 +02:00
|
|
|
|
2019-03-13 15:54:04 +01:00
|
|
|
hr = IReferenceClock_GetTime(clock, NULL);
|
|
|
|
ok(hr == E_POINTER, "Got hr %#x.\n", hr);
|
|
|
|
|
|
|
|
hr = IReferenceClock_GetTime(clock, &time1);
|
|
|
|
if (pGetTickCount64)
|
2019-03-14 18:12:18 +01:00
|
|
|
time2 = pGetTickCount64() * 10000;
|
2019-03-13 15:54:04 +01:00
|
|
|
else
|
2020-06-04 06:38:39 +02:00
|
|
|
time2 = (REFERENCE_TIME)GetTickCount() * 10000;
|
2019-03-13 15:54:05 +01:00
|
|
|
ok(hr == S_OK, "Got hr %#x.\n", hr);
|
2019-03-13 15:54:04 +01:00
|
|
|
ok(time1 % 10000 == 0, "Expected no less than 1ms coarseness, but got time %s.\n",
|
|
|
|
wine_dbgstr_longlong(time1));
|
2020-05-28 00:38:09 +02:00
|
|
|
ok(compare_time(time1, time2, 20 * 10000), "Expected about %s, got %s.\n",
|
2019-03-13 15:54:04 +01:00
|
|
|
wine_dbgstr_longlong(time2), wine_dbgstr_longlong(time1));
|
|
|
|
|
|
|
|
hr = IReferenceClock_GetTime(clock, &time2);
|
|
|
|
ok(hr == (time2 == time1 ? S_FALSE : S_OK), "Got hr %#x.\n", hr);
|
|
|
|
|
|
|
|
Sleep(100);
|
|
|
|
hr = IReferenceClock_GetTime(clock, &time2);
|
|
|
|
ok(hr == S_OK, "Got hr %#x.\n", hr);
|
2019-10-18 17:01:46 +02:00
|
|
|
ok(time2 - time1 > 80 * 10000, "Expected about %s, but got %s.\n",
|
|
|
|
wine_dbgstr_longlong(time1 + 80 * 10000), wine_dbgstr_longlong(time2));
|
2007-08-11 04:29:26 +02:00
|
|
|
|
2019-03-13 15:54:04 +01:00
|
|
|
ref = IReferenceClock_Release(clock);
|
|
|
|
ok(!ref, "Got outstanding refcount %d.\n", ref);
|
2007-08-11 04:29:26 +02:00
|
|
|
}
|
|
|
|
|
2019-03-14 18:12:20 +01:00
|
|
|
static void test_advise(void)
|
|
|
|
{
|
|
|
|
IReferenceClock *clock = create_system_clock();
|
|
|
|
HANDLE event, semaphore;
|
|
|
|
REFERENCE_TIME current;
|
|
|
|
DWORD_PTR cookie;
|
|
|
|
unsigned int i;
|
|
|
|
HRESULT hr;
|
|
|
|
ULONG ref;
|
|
|
|
|
|
|
|
event = CreateEventA(NULL, TRUE, FALSE, NULL);
|
|
|
|
semaphore = CreateSemaphoreA(NULL, 0, 10, NULL);
|
|
|
|
|
|
|
|
hr = IReferenceClock_GetTime(clock, ¤t);
|
|
|
|
ok(SUCCEEDED(hr), "Got hr %#x.\n", hr);
|
|
|
|
|
|
|
|
hr = IReferenceClock_AdviseTime(clock, current, 500 * 10000, (HEVENT)event, NULL);
|
|
|
|
ok(hr == E_POINTER, "Got hr %#x.\n", hr);
|
|
|
|
|
|
|
|
hr = IReferenceClock_AdviseTime(clock, -1000 * 10000, 500 * 10000, (HEVENT)event, &cookie);
|
|
|
|
ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr);
|
|
|
|
|
|
|
|
hr = IReferenceClock_AdviseTime(clock, current, 500 * 10000, (HEVENT)event, &cookie);
|
|
|
|
ok(hr == S_OK, "Got hr %#x.\n", hr);
|
2019-10-31 04:57:08 +01:00
|
|
|
ok(WaitForSingleObject(event, 460) == WAIT_TIMEOUT, "Event should not be signaled.\n");
|
|
|
|
ok(!WaitForSingleObject(event, 80), "Event should be signaled.\n");
|
2019-03-14 18:12:20 +01:00
|
|
|
|
|
|
|
hr = IReferenceClock_Unadvise(clock, cookie);
|
|
|
|
ok(hr == S_FALSE, "Got hr %#x.\n", hr);
|
|
|
|
|
|
|
|
ResetEvent(event);
|
|
|
|
hr = IReferenceClock_GetTime(clock, ¤t);
|
|
|
|
ok(SUCCEEDED(hr), "Got hr %#x.\n", hr);
|
|
|
|
hr = IReferenceClock_AdviseTime(clock, current, 500 * 10000, (HEVENT)event, &cookie);
|
|
|
|
ok(hr == S_OK, "Got hr %#x.\n", hr);
|
|
|
|
hr = IReferenceClock_Unadvise(clock, cookie);
|
|
|
|
ok(hr == S_OK, "Got hr %#x.\n", hr);
|
2019-10-31 04:57:08 +01:00
|
|
|
ok(WaitForSingleObject(event, 540) == WAIT_TIMEOUT, "Event should not be signaled.\n");
|
2019-03-14 18:12:20 +01:00
|
|
|
|
|
|
|
ResetEvent(event);
|
|
|
|
hr = IReferenceClock_GetTime(clock, ¤t);
|
|
|
|
ok(SUCCEEDED(hr), "Got hr %#x.\n", hr);
|
|
|
|
hr = IReferenceClock_AdviseTime(clock, current + 500 * 10000, 0, (HEVENT)event, &cookie);
|
|
|
|
ok(hr == S_OK, "Got hr %#x.\n", hr);
|
2019-10-31 04:57:08 +01:00
|
|
|
ok(WaitForSingleObject(event, 460) == WAIT_TIMEOUT, "Event should not be signaled.\n");
|
|
|
|
ok(!WaitForSingleObject(event, 80), "Event should be signaled.\n");
|
2019-03-14 18:12:20 +01:00
|
|
|
|
|
|
|
hr = IReferenceClock_GetTime(clock, ¤t);
|
|
|
|
ok(SUCCEEDED(hr), "Got hr %#x.\n", hr);
|
|
|
|
|
|
|
|
hr = IReferenceClock_AdvisePeriodic(clock, current, 500 * 10000, (HSEMAPHORE)semaphore, NULL);
|
|
|
|
ok(hr == E_POINTER, "Got hr %#x.\n", hr);
|
|
|
|
|
|
|
|
hr = IReferenceClock_AdvisePeriodic(clock, current, 0, (HSEMAPHORE)semaphore, &cookie);
|
|
|
|
ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr);
|
|
|
|
|
|
|
|
hr = IReferenceClock_AdvisePeriodic(clock, current, -500 * 10000, (HSEMAPHORE)semaphore, &cookie);
|
|
|
|
ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr);
|
|
|
|
|
|
|
|
hr = IReferenceClock_AdvisePeriodic(clock, -500 * 10000, 1000 * 10000, (HSEMAPHORE)semaphore, &cookie);
|
|
|
|
ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr);
|
|
|
|
|
2020-05-17 21:38:15 +02:00
|
|
|
hr = IReferenceClock_AdvisePeriodic(clock, current, 100 * 10000, (HSEMAPHORE)semaphore, &cookie);
|
2019-03-14 18:12:20 +01:00
|
|
|
ok(hr == S_OK, "Got hr %#x.\n", hr);
|
2020-05-17 21:38:15 +02:00
|
|
|
ok(!WaitForSingleObject(semaphore, 50), "Semaphore should be signaled.\n");
|
2019-03-14 18:12:20 +01:00
|
|
|
for (i = 0; i < 5; ++i)
|
2020-05-17 21:38:15 +02:00
|
|
|
ok(!WaitForSingleObject(semaphore, 500), "Semaphore should be signaled.\n");
|
2019-03-14 18:12:20 +01:00
|
|
|
|
|
|
|
hr = IReferenceClock_Unadvise(clock, cookie);
|
|
|
|
ok(hr == S_OK, "Got hr %#x.\n", hr);
|
2020-05-17 21:38:15 +02:00
|
|
|
ok(WaitForSingleObject(semaphore, 200) == WAIT_TIMEOUT, "Semaphore should not be signaled.\n");
|
2019-03-14 18:12:20 +01:00
|
|
|
|
|
|
|
CloseHandle(event);
|
|
|
|
CloseHandle(semaphore);
|
|
|
|
|
|
|
|
ref = IReferenceClock_Release(clock);
|
|
|
|
ok(!ref, "Got outstanding refcount %d.\n", ref);
|
|
|
|
}
|
|
|
|
|
2019-03-13 15:54:02 +01:00
|
|
|
START_TEST(systemclock)
|
2007-08-11 04:29:26 +02:00
|
|
|
{
|
|
|
|
CoInitialize(NULL);
|
|
|
|
|
2019-03-13 15:54:04 +01:00
|
|
|
pGetTickCount64 = (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"), "GetTickCount64");
|
|
|
|
|
2019-03-13 15:54:03 +01:00
|
|
|
test_interfaces();
|
2019-11-29 00:35:38 +01:00
|
|
|
test_aggregation();
|
2019-03-13 15:54:04 +01:00
|
|
|
test_get_time();
|
2019-03-14 18:12:20 +01:00
|
|
|
test_advise();
|
2008-05-19 17:04:48 +02:00
|
|
|
|
|
|
|
CoUninitialize();
|
2007-08-11 04:29:26 +02:00
|
|
|
}
|