wer: Add new stubbed wer.dll.
[wine/hramrach.git] / dlls / quartz / tests / referenceclock.c
blobddce02eaa7220f2854b02d12c5bc772654b5d66a
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 #include <assert.h>
23 #define COBJMACROS
25 #include "wine/test.h"
26 #include "uuids.h"
27 #include "dshow.h"
28 #include "control.h"
30 static void test_IReferenceClock_query_interface(const char * clockdesc, IReferenceClock * pClock)
32 HRESULT hr;
33 IUnknown *pF;
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");
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");
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");
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.
52 static void test_IReferenceClock_methods(const char * clockdesc, IReferenceClock * pClock)
54 HRESULT hr;
55 REFERENCE_TIME time1;
56 REFERENCE_TIME time2;
57 LONG diff;
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);
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);
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);
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);
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);
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 %u\n", clockdesc, diff);
93 static void test_IReferenceClock_SystemClock(void)
95 IReferenceClock * pReferenceClock;
96 HRESULT hr;
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)
102 test_IReferenceClock_query_interface("SystemClock", pReferenceClock);
103 test_IReferenceClock_methods("SystemClock", pReferenceClock);
104 IReferenceClock_Release(pReferenceClock);
108 START_TEST(referenceclock)
110 CoInitialize(NULL);
112 test_IReferenceClock_SystemClock();
114 CoUninitialize();