mod common;
use oscall::{AsHandle, Error, ErrorKind, OwnedHandle};
#[test]
fn error() {
let err = Error::from(ErrorKind::NotFound);
assert_eq!(err.kind(), ErrorKind::NotFound);
assert_eq!(err, ErrorKind::NotFound);
assert_eq!(Error::from_raw_os_error(err.raw_os_error()), err);
assert!(err.to_string().starts_with("entity not found (os error "));
let io = std::io::Error::from_raw_os_error(err.raw_os_error());
assert_eq!(io.kind(), std::io::ErrorKind::NotFound);
}
#[test]
fn handle() {
let dir = common::tmp_dir("core-handle");
let file = std::fs::File::create(dir.join("file")).unwrap();
let borrowed = common::handle_of(&file);
assert_eq!(borrowed.as_handle().as_raw(), borrowed.as_raw());
#[cfg(windows)]
let raw = std::os::windows::io::IntoRawHandle::into_raw_handle(file);
#[cfg(not(windows))]
let raw = std::os::fd::IntoRawFd::into_raw_fd(file);
let owned = unsafe { OwnedHandle::from_raw(raw) };
assert_eq!(owned.as_raw(), raw);
assert_eq!(owned.as_handle().as_raw(), raw);
let raw = owned.into_raw();
drop(unsafe { OwnedHandle::from_raw(raw) });
std::fs::remove_file(dir.join("file")).unwrap();
}