Skip to content

Commit ac75938

Browse files
committed
std: sys: pal: uefi: tests: Add systemtime tests
Add tests to ensure that extream system times are still representable. Signed-off-by: Ayush Singh <[email protected]>
1 parent d7d9815 commit ac75938

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

library/std/src/sys/pal/uefi/tests.rs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
use super::alloc::*;
2+
use super::time::system_time_internal::{from_uefi, to_uefi};
3+
use crate::time::Duration;
4+
5+
const SECS_IN_MINUTE: u64 = 60;
26

37
#[test]
48
fn align() {
@@ -19,3 +23,62 @@ fn align() {
1923
}
2024
}
2125
}
26+
27+
#[test]
28+
fn systemtime_start() {
29+
let t = r_efi::efi::Time {
30+
year: 1900,
31+
month: 1,
32+
day: 1,
33+
hour: 0,
34+
minute: 0,
35+
second: 0,
36+
pad1: 0,
37+
nanosecond: 0,
38+
timezone: -1440,
39+
daylight: 0,
40+
pad2: 0,
41+
};
42+
assert_eq!(from_uefi(&t), Duration::new(0, 0));
43+
assert_eq!(t, to_uefi(&from_uefi(&t), -1440, 0).unwrap());
44+
assert!(to_uefi(&from_uefi(&t), 0, 0).is_none());
45+
}
46+
47+
#[test]
48+
fn systemtime_utc_start() {
49+
let t = r_efi::efi::Time {
50+
year: 1900,
51+
month: 1,
52+
day: 1,
53+
hour: 0,
54+
minute: 0,
55+
second: 0,
56+
pad1: 0,
57+
nanosecond: 0,
58+
timezone: 0,
59+
daylight: 0,
60+
pad2: 0,
61+
};
62+
assert_eq!(from_uefi(&t), Duration::new(1440 * SECS_IN_MINUTE, 0));
63+
assert_eq!(t, to_uefi(&from_uefi(&t), 0, 0).unwrap());
64+
assert!(to_uefi(&from_uefi(&t), -1440, 0).is_some());
65+
}
66+
67+
#[test]
68+
fn systemtime_end() {
69+
let t = r_efi::efi::Time {
70+
year: 9999,
71+
month: 12,
72+
day: 31,
73+
hour: 23,
74+
minute: 59,
75+
second: 59,
76+
pad1: 0,
77+
nanosecond: 0,
78+
timezone: 1440,
79+
daylight: 0,
80+
pad2: 0,
81+
};
82+
assert!(to_uefi(&from_uefi(&t), 1440, 0).is_some());
83+
assert!(to_uefi(&from_uefi(&t), 1439, 0).is_none());
84+
}

0 commit comments

Comments
 (0)