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
25 #include "wine/test.h"
30 /* The following method expects a reference clock that will keep ticking for
31 * at least 5 seconds since its creation. This method assumes no other methods
32 * were called on the IReferenceClock interface since its creation.
34 static void test_IReferenceClock_methods(const char * clockdesc, IReferenceClock * pClock)
41 /* Test response from invalid (NULL) argument */
42 hr = IReferenceClock_GetTime(pClock, NULL);
43 ok (hr == E_POINTER, "%s - Expected E_POINTER (0x%08x), got 0x%08x\n", clockdesc, E_POINTER, hr);
45 /* Test response for valid value - try 1 */
46 /* TODO: test whether Windows actually returns S_FALSE in its first invocation */
47 time1 = (REFERENCE_TIME)0xdeadbeef;
48 hr = IReferenceClock_GetTime(pClock, &time1);
49 ok (hr == S_FALSE || hr == S_OK, "%s - Expected S_OK or S_FALSE, got 0x%08x\n", clockdesc, hr);
50 ok (time1 != 0xdeadbeef, "%s - value was NOT changed on return!\n", clockdesc);
52 /* Test response for valid value - try 2 */
53 time2 = (REFERENCE_TIME)0xdeadbeef;
54 hr = IReferenceClock_GetTime(pClock, &time2);
55 ok (hr == S_FALSE || hr == S_OK, "%s - Expected S_OK or S_FALSE, got 0x%08x\n", clockdesc, hr);
56 ok (time2 != 0xdeadbeef, "%s - value was NOT changed on return!\n", clockdesc);
58 /* In case the second invocation managed to return S_FALSE, MSDN says the
59 returned time is the same as the previous one. */
60 ok ((hr != S_FALSE || time1 == time2), "%s - returned S_FALSE, but values not equal!\n", clockdesc);
63 Sleep(1000); /* Sleep for at least 1 second */
64 hr = IReferenceClock_GetTime(pClock, &time2);
65 /* After a 1-second sleep, there is no excuse to get S_FALSE (see TODO above) */
66 ok (hr == S_OK, "%s - Expected S_OK, got 0x%08x\n", clockdesc, hr);
68 /* FIXME: How much deviation should be allowed after a sleep? */
70 ok (9980000 <= diff && diff <= 10020000, "%s - Expected difference around 10000000, got %lu\n", clockdesc, diff);
74 static void test_IReferenceClock_SystemClock(void)
76 IReferenceClock * pReferenceClock;
79 hr = CoCreateInstance(&CLSID_SystemClock, NULL, CLSCTX_INPROC_SERVER, &IID_IReferenceClock, (LPVOID*)&pReferenceClock);
80 ok(hr == S_OK, "Unable to create reference clock from system clock %x\n", hr);
83 test_IReferenceClock_methods("SystemClock", pReferenceClock);
84 IReferenceClock_Release(pReferenceClock);
88 START_TEST(referenceclock)
92 test_IReferenceClock_SystemClock();