mirror of
https://github.com/dnlbauer/xdrfile.git
synced 2026-09-10 22:25:30 +00:00
Unit test for path_to_cstring()
This commit is contained in:
16
src/lib.rs
16
src/lib.rs
@@ -78,7 +78,7 @@ use std::cell::Cell;
|
|||||||
use std::ffi::CString;
|
use std::ffi::CString;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
CouldNotOpenFile(std::path::PathBuf, FileMode),
|
CouldNotOpenFile(std::path::PathBuf, FileMode),
|
||||||
CouldNotReadAtomNumber(u32),
|
CouldNotReadAtomNumber(u32),
|
||||||
@@ -145,7 +145,7 @@ impl Error {
|
|||||||
|
|
||||||
impl std::error::Error for Error {}
|
impl std::error::Error for Error {}
|
||||||
|
|
||||||
pub type Result<T> = std::result::Result<T, Error>;
|
pub type Result<T, E = Error> = std::result::Result<T, E>;
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub enum FileMode {
|
pub enum FileMode {
|
||||||
@@ -579,4 +579,16 @@ mod tests {
|
|||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_path_to_cstring() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
let result_invalid = path_to_cstring("invalid/\0path");
|
||||||
|
|
||||||
|
assert_eq!(result_invalid, Err(Error::PathInvalidCstring));
|
||||||
|
|
||||||
|
let result_valid = path_to_cstring("valid/path");
|
||||||
|
|
||||||
|
assert_eq!(result_valid, Ok(CString::new("valid/path")?));
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user