| 1 |
// This file is part of the uutils coreutils package. |
| 2 |
// |
| 3 |
// (c) Ingvar Stepanyan <[email protected]> |
| 4 |
// |
| 5 |
// For the full copyright and license information, please view the LICENSE file |
| 6 |
// that was distributed with this source code. |
| 7 |
|
| 8 |
// spell-checker:ignore (API) nodename osname sysname |
| 9 |
// spell-checker:ignore (names) Ingvar Stepanyan * [email protected] |
| 10 |
// spell-checker:ignore (uutils) coreutils uutils |
| 11 |
|
| 12 |
#![warn(unused_results)] // enable warnings for unused results |
| 13 |
|
| 14 |
use std::ffi::{OsStr, OsString}; |
| 15 |
|
| 16 |
use crate::{PlatformInfoAPI, PlatformInfoError, UNameAPI}; |
| 17 |
|
| 18 |
// PlatformInfo |
| 19 |
/// Handles initial retrieval and holds cached information for the current platform ("unknown" in this case). |
| 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 processor(&self) -> &OsStr { |
| 55 |
&self.unknown |
| 56 |
} |
| 57 |
|
| 58 |
fn osname(&self) -> &OsStr { |
| 59 |
&self.unknown |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
#[test] |
| 64 |
fn test_unknown() { |
| 65 |
let platform_info = PlatformInfo::new().unwrap(); |
| 66 |
|
| 67 |
assert_eq!(platform_info.sysname().to_string_lossy(), "unknown"); |
| 68 |
assert_eq!(platform_info.nodename().to_string_lossy(), "unknown"); |
| 69 |
assert_eq!(platform_info.release().to_string_lossy(), "unknown"); |
| 70 |
assert_eq!(platform_info.version().to_string_lossy(), "unknown"); |
| 71 |
assert_eq!(platform_info.machine().to_string_lossy(), "unknown"); |
| 72 |
assert_eq!(platform_info.processor().to_string_lossy(), "unknown"); |
| 73 |
assert_eq!(platform_info.osname().to_string_lossy(), "unknown"); |
| 74 |
} |
| 75 |
|
| 76 |
#[test] |
| 77 |
fn structure_clone() { |
| 78 |
let info = PlatformInfo::new().unwrap(); |
| 79 |
println!("{:?}", info); |
| 80 |
let info_copy = info.clone(); |
| 81 |
assert_eq!(info_copy, info); |
| 82 |
} |