use crate::{c, error};
#[derive(Clone, Copy, Debug)]
#[must_use]
#[repr(transparent)]
pub struct Result(c::int);
impl From<Result> for core::result::Result<(), error::Unspecified> {
fn from(ret: Result) -> Self {
match ret.0 {
1 => Ok(()),
c => {
debug_assert_eq!(c, 0, "`bssl::Result` value must be 0 or 1");
Err(error::Unspecified)
},
}
}
}
#[cfg(test)]
macro_rules! bssl_test {
( $fn_name:ident, $bssl_test_main_fn_name:ident ) => {
#[test]
fn $fn_name() {
use $crate::{c, cpu};
extern "C" {
#[must_use]
fn $bssl_test_main_fn_name() -> c::int;
}
cpu::cache_detected_features();
::std::env::set_current_dir(crate::test::ring_src_path()).unwrap();
let result = unsafe { $bssl_test_main_fn_name() };
assert_eq!(result, 0);
}
};
}
#[cfg(test)]
mod tests {
mod result {
use crate::{bssl, c};
use core::mem;
#[test]
fn size_and_alignment() {
type Underlying = c::int;
assert_eq!(mem::size_of::<bssl::Result>(), mem::size_of::<Underlying>());
assert_eq!(
mem::align_of::<bssl::Result>(),
mem::align_of::<Underlying>()
);
}
#[test]
fn semantics() {
assert!(Result::from(bssl::Result(0)).is_err());
assert!(Result::from(bssl::Result(1)).is_ok());
}
}
}