windowscodecs: Implement JpegEncoder_Frame_Commit.
[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 #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, (LPVOID *)&pF);
34     ok(hr == S_OK, "IReferenceClock_QueryInterface returned %x\n", hr);
35     ok(pF != NULL, "pF is NULL\n");
36
37     hr = IReferenceClock_QueryInterface(pClock, &IID_IDirectDraw, (LPVOID *)&pF);
38     ok(hr == E_NOINTERFACE, "IReferenceClock_QueryInterface returned %x\n", hr);
39     ok(pF == NULL, "pF is not NULL\n");
40
41     hr = IReferenceClock_QueryInterface(pClock, &IID_IReferenceClock, (LPVOID *)&pF);
42     ok(hr == S_OK, "IReferenceClock_QueryInterface returned %x\n", hr);
43     ok(pF != NULL, "pF is NULL\n");
44 }
45
46 /* The following method expects a reference clock that will keep ticking for
47  * at least 5 seconds since its creation. This method assumes no other methods
48  * were called on the IReferenceClock interface since its creation.
49  */
50 static void test_IReferenceClock_methods(const char * clockdesc, IReferenceClock * pClock)
51 {
52     HRESULT hr;
53     REFERENCE_TIME time1;
54     REFERENCE_TIME time2;
55     LONG diff;
56
57     /* Test response from invalid (NULL) argument */
58     hr = IReferenceClock_GetTime(pClock, NULL);
59     ok (hr == E_POINTER, "%s - Expected E_POINTER (0x%08x), got 0x%08x\n", clockdesc, E_POINTER, hr);
60
61     /* Test response for valid value - try 1 */
62     /* TODO: test whether Windows actually returns S_FALSE in its first invocation */
63     time1 = (REFERENCE_TIME)0xdeadbeef;
64     hr = IReferenceClock_GetTime(pClock, &time1);
65     ok (hr == S_FALSE || hr == S_OK, "%s - Expected S_OK or S_FALSE, got 0x%08x\n", clockdesc, hr);
66     ok (time1 != 0xdeadbeef, "%s - value was NOT changed on return!\n", clockdesc);
67
68     /* Test response for valid value - try 2 */
69     time2 = (REFERENCE_TIME)0xdeadbeef;
70     hr = IReferenceClock_GetTime(pClock, &time2);
71     ok (hr == S_FALSE || hr == S_OK, "%s - Expected S_OK or S_FALSE, got 0x%08x\n", clockdesc, hr);
72     ok (time2 != 0xdeadbeef, "%s - value was NOT changed on return!\n", clockdesc);
73
74     /* In case the second invocation managed to return S_FALSE, MSDN says the
75        returned time is the same as the previous one. */
76     ok ((hr != S_FALSE || time1 == time2), "%s - returned S_FALSE, but values not equal!\n", clockdesc);
77
78     time1 = time2;
79     Sleep(1000); /* Sleep for at least 1 second */
80     hr = IReferenceClock_GetTime(pClock, &time2);
81     /* After a 1-second sleep, there is no excuse to get S_FALSE (see TODO above) */
82     ok (hr == S_OK, "%s - Expected S_OK, got 0x%08x\n", clockdesc, hr);
83
84     /* FIXME: How much deviation should be allowed after a sleep? */
85     /* 0.3% is common, and 0.4% is sometimes observed. */
86     diff = time2 - time1;
87     ok (9940000 <= diff && diff <= 10240000, "%s - Expected difference around 10000000, got %u\n", clockdesc, diff);
88
89 }
90
91 static void test_IReferenceClock_SystemClock(void)
92 {
93     IReferenceClock * pReferenceClock;
94     HRESULT hr;
95
96     hr = CoCreateInstance(&CLSID_SystemClock, NULL, CLSCTX_INPROC_SERVER, &IID_IReferenceClock, (LPVOID*)&pReferenceClock);
97     ok(hr == S_OK, "Unable to create reference clock from system clock %x\n", hr);
98     if (hr == S_OK)
99     {
100         test_IReferenceClock_query_interface("SystemClock", pReferenceClock);
101         test_IReferenceClock_methods("SystemClock", pReferenceClock);
102         IReferenceClock_Release(pReferenceClock);
103     }
104 }
105
106 START_TEST(referenceclock)
107 {
108     CoInitialize(NULL);
109
110     test_IReferenceClock_SystemClock();
111
112     CoUninitialize();
113 }