mirror of
https://github.com/sile/hls_m3u8.git
synced 2024-09-27 22:11:54 +00:00
more tests
This commit is contained in:
parent
35592584ee
commit
8368df0c90
4 changed files with 70 additions and 8 deletions
|
@ -32,21 +32,17 @@ impl DecimalFloatingPoint {
|
|||
}
|
||||
|
||||
pub(crate) fn to_duration(self) -> Duration {
|
||||
let secs = self.0 as u64;
|
||||
let nanos = (self.0.fract() * 1_000_000_000.0) as u32;
|
||||
Duration::new(secs, nanos)
|
||||
Duration::from_secs_f64(self.0)
|
||||
}
|
||||
|
||||
pub(crate) fn from_duration(duration: Duration) -> Self {
|
||||
let n =
|
||||
(duration.as_secs() as f64) + (f64::from(duration.subsec_nanos()) / 1_000_000_000.0);
|
||||
DecimalFloatingPoint(n)
|
||||
Self(duration.as_secs_f64())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<u32> for DecimalFloatingPoint {
|
||||
fn from(f: u32) -> Self {
|
||||
DecimalFloatingPoint(f64::from(f))
|
||||
Self(f64::from(f))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -108,5 +104,44 @@ mod tests {
|
|||
decimal_floating_point,
|
||||
"4.1".parse::<DecimalFloatingPoint>().unwrap()
|
||||
);
|
||||
|
||||
assert!("1#".parse::<DecimalFloatingPoint>().is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_new() {
|
||||
assert!(DecimalFloatingPoint::new(std::f64::INFINITY).is_err());
|
||||
assert!(DecimalFloatingPoint::new(-1.0).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_as_f64() {
|
||||
assert_eq!(DecimalFloatingPoint::new(1.0).unwrap().as_f64(), 1.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_from_duration() {
|
||||
assert_eq!(
|
||||
DecimalFloatingPoint::from_duration(Duration::from_nanos(11_234_500_112_345)),
|
||||
DecimalFloatingPoint::new(11234.500112345).unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_from() {
|
||||
assert_eq!(
|
||||
DecimalFloatingPoint::from(1u32),
|
||||
DecimalFloatingPoint::new(1.0).unwrap()
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
DecimalFloatingPoint::from(1 as f64),
|
||||
DecimalFloatingPoint::new(1.0).unwrap()
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
DecimalFloatingPoint::from(1 as f32),
|
||||
DecimalFloatingPoint::new(1.0).unwrap()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -494,6 +494,29 @@ mod test {
|
|||
DecryptionKey::new(EncryptionMethod::Aes128, "https://www.example.com/")
|
||||
.required_version(),
|
||||
ProtocolVersion::V1
|
||||
)
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
DecryptionKey::builder()
|
||||
.method(EncryptionMethod::Aes128)
|
||||
.uri("https://www.example.com/")
|
||||
.key_format(KeyFormat::Identity)
|
||||
.key_format_versions(vec![1, 2, 3])
|
||||
.build()
|
||||
.unwrap()
|
||||
.required_version(),
|
||||
ProtocolVersion::V5
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
DecryptionKey::builder()
|
||||
.method(EncryptionMethod::Aes128)
|
||||
.uri("https://www.example.com/")
|
||||
.iv([1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7])
|
||||
.build()
|
||||
.unwrap()
|
||||
.required_version(),
|
||||
ProtocolVersion::V2
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -104,5 +104,7 @@ mod tests {
|
|||
EncryptionMethod::None,
|
||||
"NONE".parse::<EncryptionMethod>().unwrap()
|
||||
);
|
||||
|
||||
assert!("unknown".parse::<EncryptionMethod>().is_err());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,5 +56,7 @@ mod tests {
|
|||
|
||||
let level = HdcpLevel::None;
|
||||
assert_eq!(level, "NONE".parse::<HdcpLevel>().unwrap());
|
||||
|
||||
assert!("unk".parse::<HdcpLevel>().is_err());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue