use std::ffi::CStr;
const ANDROID_TIMEZONE_PROPERTY_NAME: &[u8] = b"persist.sys.timezone\0";
pub(crate) fn android_timezone_property_name() -> &'static CStr {
if cfg!(any(test, debug_assertions)) {
return CStr::from_bytes_with_nul(ANDROID_TIMEZONE_PROPERTY_NAME).unwrap();
}
unsafe { CStr::from_bytes_with_nul_unchecked(ANDROID_TIMEZONE_PROPERTY_NAME) }
}
#[cfg(test)]
mod tests {
use std::ffi::CStr;
use super::{android_timezone_property_name, ANDROID_TIMEZONE_PROPERTY_NAME};
#[test]
fn test_android_timezone_property_name_is_valid_cstr() {
CStr::from_bytes_with_nul(ANDROID_TIMEZONE_PROPERTY_NAME).unwrap();
let mut invalid_property_name = ANDROID_TIMEZONE_PROPERTY_NAME.to_owned();
invalid_property_name.push(b'\0');
CStr::from_bytes_with_nul(&invalid_property_name).unwrap_err();
}
#[test]
fn test_android_timezone_property_name_getter() {
let key = android_timezone_property_name().to_bytes_with_nul();
assert_eq!(key, ANDROID_TIMEZONE_PROPERTY_NAME);
std::str::from_utf8(key).unwrap();
}
}