[RAPPS] Stopped GCC whining (fixed GCC build)
[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 #include <apitest.h>
9
10 #define WIN32_NO_STATUS
11 #include <ndk/ketypes.h>
12 #include <ndk/kefuncs.h>
13
14 #include <stdio.h>
15
16 START_TEST(TimerResolution)
17 {
18 NTSTATUS Status;
19 ULONG CurrentResolution;
20 ULONG MinimumResolution;
21 ULONG MaximumResolution;
22 ULONG CurrentResolution2;
23
24 /* Get the current timer resolution */
25 Status = NtSetTimerResolution(0, /* Ignored */
26 FALSE, /* Don't change resolution */
27 &CurrentResolution);
28
29 /*
30 * If the timer resolution hasn't been changed for this process,
31 * it returns STATUS_TIMER_RESOLUTION_NOT_SET
32 */
33 ok_hex(Status, STATUS_TIMER_RESOLUTION_NOT_SET);
34
35 /*
36 * Get the timer resolution limits and current timer resolution
37 * using a different method
38 */
39 Status = NtQueryTimerResolution(&MinimumResolution,
40 &MaximumResolution,
41 &CurrentResolution2);
42
43 /* This function should always return STATUS_SUCCESS */
44 ok_hex(Status, STATUS_SUCCESS);
45
46 /* The MinimumResolution should be higher than the MaximumResolution */
47 ok(MinimumResolution >= MaximumResolution, "MaximumResolution higher than MinimumResolution!\n");
48
49 /* These two values should be the same */
50 ok_hex(CurrentResolution, CurrentResolution2);
51
52 /*
53 * Even if you give it invalid values,
54 * NtSetTimerResolution will return STATUS_SUCCESS,
55 * but it will not change the resolution.
56 */
57 Status = NtSetTimerResolution(MinimumResolution + 1,
58 TRUE,
59 &CurrentResolution);
60 ok_hex(Status, STATUS_SUCCESS);
61 printf("Current resolution: %lu ; minimum resolution: %lu\n", CurrentResolution, MinimumResolution);
62 ok(CurrentResolution <= MinimumResolution, "Current resolution: %lu became too high! (minimum resolution: %lu)\n", CurrentResolution, MinimumResolution);
63
64 Status = NtSetTimerResolution(MaximumResolution - 1,
65 TRUE,
66 &CurrentResolution);
67 ok_hex(Status, STATUS_SUCCESS);
68 printf("Current resolution: %lu ; maximum resolution: %lu\n", CurrentResolution, MaximumResolution);
69 ok(CurrentResolution >= MaximumResolution, "Current resolution: %lu became too low! (maximum resolution: %lu)\n", CurrentResolution, MaximumResolution);
70
71 /* Get the current timer resolution */
72 Status = NtSetTimerResolution(0, /* Ignored */
73 FALSE, /* Don't change resolution */
74 &CurrentResolution);
75
76 /* Since we have changed the resolution earlier, it returns STATUS_SUCCESS. */
77 ok_hex(Status, STATUS_SUCCESS);
78
79 /* Get the current timer resolution again */
80 Status = NtSetTimerResolution(0, /* Ignored */
81 FALSE, /* Don't change resolution */
82 &CurrentResolution);
83
84 /* The resolution is not changed now, so it should return STATUS_TIMER_RESOLUTION_NOT_SET */
85 ok_hex(Status, STATUS_TIMER_RESOLUTION_NOT_SET);
86 }