ReactOS  0.4.15-dev-489-g75a0787
Timer.c
Go to the documentation of this file.
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 "precomp.h"
9 
10 START_TEST(TimerResolution)
11 {
13  ULONG CurrentResolution;
14  ULONG MinimumResolution;
15  ULONG MaximumResolution;
16  ULONG CurrentResolution2;
17 
18  /* Get the current timer resolution */
19  Status = NtSetTimerResolution(0, /* Ignored */
20  FALSE, /* Don't change resolution */
21  &CurrentResolution);
22 
23  /*
24  * If the timer resolution hasn't been changed for this process,
25  * it returns STATUS_TIMER_RESOLUTION_NOT_SET
26  */
28 
29  /*
30  * Get the timer resolution limits and current timer resolution
31  * using a different method
32  */
33  Status = NtQueryTimerResolution(&MinimumResolution,
34  &MaximumResolution,
35  &CurrentResolution2);
36 
37  /* This function should always return STATUS_SUCCESS */
39 
40  /* The MinimumResolution should be higher than the MaximumResolution */
41  ok(MinimumResolution >= MaximumResolution, "MaximumResolution higher than MinimumResolution!\n");
42 
43  /* These two values should be the same */
44  ok_hex(CurrentResolution, CurrentResolution2);
45 
46  /*
47  * Even if you give it invalid values,
48  * NtSetTimerResolution will return STATUS_SUCCESS,
49  * but it will not change the resolution.
50  */
51  Status = NtSetTimerResolution(MinimumResolution + 1,
52  TRUE,
53  &CurrentResolution);
55  printf("Current resolution: %lu ; minimum resolution: %lu\n", CurrentResolution, MinimumResolution);
56  ok(CurrentResolution <= MinimumResolution, "Current resolution: %lu became too high! (minimum resolution: %lu)\n", CurrentResolution, MinimumResolution);
57 
58  Status = NtSetTimerResolution(MaximumResolution - 1,
59  TRUE,
60  &CurrentResolution);
62  printf("Current resolution: %lu ; maximum resolution: %lu\n", CurrentResolution, MaximumResolution);
63  ok(abs((LONG)MaximumResolution - (LONG)CurrentResolution) < 200, "Current resolution: %lu became too low! (maximum resolution: %lu)\n", CurrentResolution, MaximumResolution);
64 
65  /* Get the current timer resolution */
66  Status = NtSetTimerResolution(0, /* Ignored */
67  FALSE, /* Don't change resolution */
68  &CurrentResolution);
69 
70  /* Since we have changed the resolution earlier, it returns STATUS_SUCCESS. */
72 
73  /* Get the current timer resolution again */
74  Status = NtSetTimerResolution(0, /* Ignored */
75  FALSE, /* Don't change resolution */
76  &CurrentResolution);
77 
78  /* The resolution is not changed now, so it should return STATUS_TIMER_RESOLUTION_NOT_SET */
80 }
#define abs(i)
Definition: fconv.c:206
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
#define ok_hex(expression, result)
Definition: atltest.h:94
NTSTATUS NTAPI NtQueryTimerResolution(OUT PULONG MinimumResolution, OUT PULONG MaximumResolution, OUT PULONG ActualResolution)
Definition: time.c:481
long LONG
Definition: pedump.c:60
START_TEST(TimerResolution)
Definition: Timer.c:10
Status
Definition: gdiplustypes.h:24
#define ok(value,...)
Definition: atltest.h:57
NTSTATUS NTAPI NtSetTimerResolution(IN ULONG DesiredResolution, IN BOOLEAN SetResolution, OUT PULONG CurrentResolution)
Definition: time.c:532
unsigned int ULONG
Definition: retypes.h:1
#define STATUS_TIMER_RESOLUTION_NOT_SET
Definition: ntstatus.h:699
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define printf
Definition: config.h:203