[ROSTESTS]
[reactos.git] / rostests / apitests / ntdll / Timer.c
1 /*
2 * PROJECT: ReactOS API tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for NtQueryTimerResolution and NtSetTimerResolution.
5 * PROGRAMMER: Aleksandar Andrejevic <theflash AT sdf DOT lonestar DOT org>
6 */
7
8 #define WIN32_NO_STATUS
9 #include <wine/test.h>
10 #include <ndk/ketypes.h>
11 #include <ndk/kefuncs.h>
12
13 #include <stdio.h>
14
15 START_TEST(TimerResolution)
16 {
17 NTSTATUS Status;
18 ULONG CurrentResolution;
19 ULONG MinimumResolution;
20 ULONG MaximumResolution;
21 ULONG CurrentResolution2;
22
23 /* Get the current timer resolution */
24 Status = NtSetTimerResolution(0, /* Ignored */
25 FALSE, /* Don't change resolution */
26 &CurrentResolution);
27
28 /*
29 * When not setting the resolution, it always
30 * returns STATUS_TIMER_RESOLUTION_NOT_SET
31 */
32 ok_hex(Status, STATUS_TIMER_RESOLUTION_NOT_SET);
33
34 /*
35 * Get the timer resolution limits and current timer resolution
36 * using a different method
37 */
38 Status = NtQueryTimerResolution(&MinimumResolution,
39 &MaximumResolution,
40 &CurrentResolution2);
41
42 /* This function should always return STATUS_SUCCESS */
43 ok_hex(Status, STATUS_SUCCESS);
44
45 /* These two values should be the same */
46 ok_hex(CurrentResolution, CurrentResolution2);
47
48 /*
49 * Even if you give it invalid values,
50 * NtSetTimerResolution will return STATUS_SUCCESS,
51 * but it will not change the resolution.
52 */
53 Status = NtSetTimerResolution(MinimumResolution - 1,
54 TRUE,
55 &CurrentResolution);
56 ok_hex(Status, STATUS_SUCCESS);
57 printf("Current resolution: %d ; minimum resolution: %d\n", CurrentResolution, MinimumResolution);
58 ok(CurrentResolution >= MinimumResolution, "Current resolution: %d became too low! (minimum resolution: %d)\n", CurrentResolution, MinimumResolution);
59
60 Status = NtSetTimerResolution(MaximumResolution + 1,
61 TRUE,
62 &CurrentResolution);
63 ok_hex(Status, STATUS_SUCCESS);
64 printf("Current resolution: %d ; maximum resolution: %d\n", CurrentResolution, MaximumResolution);
65 ok(CurrentResolution <= MaximumResolution, "Current resolution: %d became too high! (maximum resolution: %d)\n", CurrentResolution, MaximumResolution);
66 }