Release 1.6-rc2.
[wine/testsucceed.git] / dlls / quartz / tests / referenceclock.c
bloba96bd48b31092ce45acfc41b8b1f1cd6fc9500d2
1 /*
2 * Unit tests for Direct Show functions - IReferenceClock
4 * Copyright (C) 2007 Alex VillacĂ­s Lasso
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.
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.
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
21 #define COBJMACROS
23 #include "wine/test.h"
24 #include "uuids.h"
25 #include "dshow.h"
26 #include "control.h"
28 static void test_IReferenceClock_query_interface(const char * clockdesc, IReferenceClock * pClock)
30 HRESULT hr;
31 IUnknown *pF;
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");
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");
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");
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.
50 static void test_IReferenceClock_methods(const char * clockdesc, IReferenceClock * pClock)
52 HRESULT hr;
53 REFERENCE_TIME time1;
54 REFERENCE_TIME time2;
55 LONG diff;
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);
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);
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);
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);
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);
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);
91 static void test_IReferenceClock_SystemClock(void)
93 IReferenceClock * pReferenceClock;
94 HRESULT hr;
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)
100 test_IReferenceClock_query_interface("SystemClock", pReferenceClock);
101 test_IReferenceClock_methods("SystemClock", pReferenceClock);
102 IReferenceClock_Release(pReferenceClock);
106 START_TEST(referenceclock)
108 CoInitialize(NULL);
110 test_IReferenceClock_SystemClock();
112 CoUninitialize();