ReactOS  0.4.15-dev-1197-g8081ba9
referenceclock.c
Go to the documentation of this file.
1 /*
2  * Unit tests for Direct Show functions - IReferenceClock
3  *
4  * Copyright (C) 2007 Alex VillacĂ­s Lasso
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 #define COBJMACROS
22 
23 #include "wine/test.h"
24 #include "uuids.h"
25 #include "dshow.h"
26 #include "control.h"
27 
28 static void test_IReferenceClock_query_interface(const char * clockdesc, IReferenceClock * pClock)
29 {
30  HRESULT hr;
31  IUnknown *pF;
32 
33  hr = IReferenceClock_QueryInterface(pClock, &IID_IUnknown, (void**)&pF);
34  ok(hr == S_OK, "IReferenceClock_QueryInterface returned %x\n", hr);
35  ok(pF != NULL, "pF is NULL\n");
36  if (SUCCEEDED(hr)) IUnknown_Release(pF);
37 
38  hr = IReferenceClock_QueryInterface(pClock, &IID_IDirectDraw, (void**)&pF);
39  ok(hr == E_NOINTERFACE, "IReferenceClock_QueryInterface returned %x\n", hr);
40  ok(pF == NULL, "pF is not NULL\n");
41 
42  hr = IReferenceClock_QueryInterface(pClock, &IID_IReferenceClock, (void**)&pF);
43  ok(hr == S_OK, "IReferenceClock_QueryInterface returned %x\n", hr);
44  ok(pF != NULL, "pF is NULL\n");
45  if (SUCCEEDED(hr)) IUnknown_Release(pF);
46 }
47 
48 /* The following method expects a reference clock that will keep ticking for
49  * at least 5 seconds since its creation. This method assumes no other methods
50  * were called on the IReferenceClock interface since its creation.
51  */
52 static void test_IReferenceClock_methods(const char * clockdesc, IReferenceClock * pClock)
53 {
54  HRESULT hr;
55  REFERENCE_TIME time1;
56  REFERENCE_TIME time2;
57  LONG diff;
58 
59  /* Test response from invalid (NULL) argument */
60  hr = IReferenceClock_GetTime(pClock, NULL);
61  ok (hr == E_POINTER, "%s - Expected E_POINTER (0x%08x), got 0x%08x\n", clockdesc, E_POINTER, hr);
62 
63  /* Test response for valid value - try 1 */
64  /* TODO: test whether Windows actually returns S_FALSE in its first invocation */
65  time1 = (REFERENCE_TIME)0xdeadbeef;
66  hr = IReferenceClock_GetTime(pClock, &time1);
67  ok (hr == S_FALSE || hr == S_OK, "%s - Expected S_OK or S_FALSE, got 0x%08x\n", clockdesc, hr);
68  ok (time1 != 0xdeadbeef, "%s - value was NOT changed on return!\n", clockdesc);
69 
70  /* Test response for valid value - try 2 */
71  time2 = (REFERENCE_TIME)0xdeadbeef;
72  hr = IReferenceClock_GetTime(pClock, &time2);
73  ok (hr == S_FALSE || hr == S_OK, "%s - Expected S_OK or S_FALSE, got 0x%08x\n", clockdesc, hr);
74  ok (time2 != 0xdeadbeef, "%s - value was NOT changed on return!\n", clockdesc);
75 
76  /* In case the second invocation managed to return S_FALSE, MSDN says the
77  returned time is the same as the previous one. */
78  ok ((hr != S_FALSE || time1 == time2), "%s - returned S_FALSE, but values not equal!\n", clockdesc);
79 
80  time1 = time2;
81  Sleep(1000); /* Sleep for at least 1 second */
82  hr = IReferenceClock_GetTime(pClock, &time2);
83  /* After a 1-second sleep, there is no excuse to get S_FALSE (see TODO above) */
84  ok (hr == S_OK, "%s - Expected S_OK, got 0x%08x\n", clockdesc, hr);
85 
86  /* FIXME: How much deviation should be allowed after a sleep? */
87  /* 0.3% is common, and 0.4% is sometimes observed. */
88  diff = time2 - time1;
90  ok (9940000 <= diff && diff <= 10240000, "%s - Expected difference around 10000000, got %u\n", clockdesc, diff);
91 
92 }
93 
95 {
96  IReferenceClock * pReferenceClock;
97  HRESULT hr;
98 
99  hr = CoCreateInstance(&CLSID_SystemClock, NULL, CLSCTX_INPROC_SERVER, &IID_IReferenceClock, (LPVOID*)&pReferenceClock);
100  ok(hr == S_OK, "Unable to create reference clock from system clock %x\n", hr);
101  if (hr == S_OK)
102  {
103  test_IReferenceClock_query_interface("SystemClock", pReferenceClock);
104  test_IReferenceClock_methods("SystemClock", pReferenceClock);
105  IReferenceClock_Release(pReferenceClock);
106  }
107 }
108 
109 START_TEST(referenceclock)
110 {
112 
114 
115  CoUninitialize();
116 }
static void test_IReferenceClock_methods(const char *clockdesc, IReferenceClock *pClock)
#define IReferenceClock_QueryInterface(p, a, b)
Definition: dmusicc.h:750
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
#define E_NOINTERFACE
Definition: winerror.h:2364
HRESULT hr
Definition: shlfolder.c:183
long LONG
Definition: pedump.c:60
#define S_FALSE
Definition: winerror.h:2357
smooth NULL
Definition: ftsmooth.c:416
LONGLONG REFERENCE_TIME
Definition: dmusicks.h:9
LONG HRESULT
Definition: typedefs.h:79
const GUID IID_IUnknown
START_TEST(referenceclock)
#define IReferenceClock_GetTime(p, a)
Definition: dmusicc.h:754
static void test_IReferenceClock_SystemClock(void)
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3325
#define S_OK
Definition: intsafe.h:51
#define IReferenceClock_Release(p)
Definition: dmusicc.h:752
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: compobj.c:2067
#define ros_skip_flaky
Definition: test.h:166
#define ok(value,...)
Definition: atltest.h:57
HRESULT WINAPI CoInitialize(LPVOID lpReserved)
Definition: compobj.c:1964
static void test_IReferenceClock_query_interface(const char *clockdesc, IReferenceClock *pClock)
#define E_POINTER
Definition: winerror.h:2365
#define SUCCEEDED(hr)
Definition: intsafe.h:49