quartz: Fix parser and pins logic to no longer deadlock.
[wine] / dlls / quartz / tests / referenceclock.c
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 #include <assert.h>
22
23 #define COBJMACROS
24
25 #include "wine/test.h"
26 #include "uuids.h"
27 #include "dshow.h"
28 #include "control.h"
29
30 static void test_IReferenceClock_query_interface(const char * clockdesc, IReferenceClock * pClock)
31 {
32     HRESULT hr;
33     IUnknown *pF;
34
35     hr = IReferenceClock_QueryInterface(pClock, &IID_IUnknown, (LPVOID *)&pF);
36     ok(hr == S_OK, "IReferenceClock_QueryInterface returned %x\n", hr);
37     ok(pF != NULL, "pF is NULL\n");
38
39     hr = IReferenceClock_QueryInterface(pClock, &IID_IDirectDraw, (LPVOID *)&pF);
40     ok(hr == E_NOINTERFACE, "IReferenceClock_QueryInterface returned %x\n", hr);
41     ok(pF == NULL, "pF is not NULL\n");
42
43     hr = IReferenceClock_QueryInterface(pClock, &IID_IReferenceClock, (LPVOID *)&pF);
44     ok(hr == S_OK, "IReferenceClock_QueryInterface returned %x\n", hr);
45     ok(pF != NULL, "pF is NULL\n");
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     signed 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;
89     ok (9940000 <= diff && diff <= 10240000, "%s - Expected difference around 10000000, got %lu\n", clockdesc, diff);
90
91 }
92
93 static void test_IReferenceClock_SystemClock(void)
94 {
95     IReferenceClock * pReferenceClock;
96     HRESULT hr;
97
98     hr = CoCreateInstance(&CLSID_SystemClock, NULL, CLSCTX_INPROC_SERVER, &IID_IReferenceClock, (LPVOID*)&pReferenceClock);
99     ok(hr == S_OK, "Unable to create reference clock from system clock %x\n", hr);
100     if (hr == S_OK)
101     {
102         test_IReferenceClock_query_interface("SystemClock", pReferenceClock);
103         test_IReferenceClock_methods("SystemClock", pReferenceClock);
104         IReferenceClock_Release(pReferenceClock);
105     }
106 }
107
108 START_TEST(referenceclock)
109 {
110     CoInitialize(NULL);
111
112     test_IReferenceClock_SystemClock();
113 }