| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
#![warn(unused_results)] |
| 13 |
|
| 14 |
use std::ffi::{OsStr, OsString}; |
| 15 |
|
| 16 |
use crate::{PlatformInfoAPI, PlatformInfoError, UNameAPI}; |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#[derive(Clone, Debug, PartialEq, Eq)] |
| 21 |
pub struct PlatformInfo { |
| 22 |
unknown: OsString, |
| 23 |
} |
| 24 |
|
| 25 |
impl PlatformInfoAPI for PlatformInfo { |
| 26 |
fn new() -> Result<Self, PlatformInfoError> { |
| 27 |
Ok(Self { |
| 28 |
unknown: OsString::from(crate::lib_impl::HOST_OS_NAME), |
| 29 |
}) |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
impl UNameAPI for PlatformInfo { |
| 34 |
fn sysname(&self) -> &OsStr { |
| 35 |
&self.unknown |
| 36 |
} |
| 37 |
|
| 38 |
fn nodename(&self) -> &OsStr { |
| 39 |
&self.unknown |
| 40 |
} |
| 41 |
|
| 42 |
fn release(&self) -> &OsStr { |
| 43 |
&self.unknown |
| 44 |
} |
| 45 |
|
| 46 |
fn version(&self) -> &OsStr { |
| 47 |
&self.unknown |
| 48 |
} |
| 49 |
|
| 50 |
fn machine(&self) -> &OsStr { |
| 51 |
&self.unknown |
| 52 |
} |
| 53 |
|
| 54 |
fn osname(&self) -> &OsStr { |
| 55 |
&self.unknown |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
#[test] |
| 60 |
fn test_unknown() { |
| 61 |
let platform_info = PlatformInfo::new().unwrap(); |
| 62 |
|
| 63 |
assert_eq!(platform_info.sysname().to_string_lossy(), "unknown"); |
| 64 |
assert_eq!(platform_info.nodename().to_string_lossy(), "unknown"); |
| 65 |
assert_eq!(platform_info.release().to_string_lossy(), "unknown"); |
| 66 |
assert_eq!(platform_info.version().to_string_lossy(), "unknown"); |
| 67 |
assert_eq!(platform_info.machine().to_string_lossy(), "unknown"); |
| 68 |
assert_eq!(platform_info.osname().to_string_lossy(), "unknown"); |
| 69 |
} |
| 70 |
|
| 71 |
#[test] |
| 72 |
fn structure_clone() { |
| 73 |
let info = PlatformInfo::new().unwrap(); |
| 74 |
println!("{:?}", info); |
| 75 |
let info_copy = info.clone(); |
| 76 |
assert_eq!(info_copy, info); |
| 77 |
} |