1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
use std::os::raw::c_int; use widestring::WideChar; extern "C" { pub fn new_t_accepts(input: *const WideChar, out: *mut *mut WideChar, max: *mut usize) -> c_int; } #[cfg(test)] mod tests { use core::ffi::c_void; use std::mem; use libc::{free, malloc}; use widestring::{WideCString, WideChar}; use super::new_t_accepts; #[test] fn test_new_t_accepts() { let input = WideCString::from_str("Dit is een test. En nog een zin.").unwrap(); let mut output_len = input.len() + 1; let mut output = unsafe { malloc(output_len * mem::size_of::<WideChar>()) } as *mut WideChar; assert_eq!( unsafe { new_t_accepts(input.as_ptr(), &mut output, &mut output_len) }, 1 ); let output_str = unsafe { WideCString::from_ptr_with_nul(output, output_len) }.unwrap(); assert_eq!( output_str.to_string_lossy(), "Dit is een test .\nEn nog een zin ." ); unsafe { free(output as *mut c_void) }; } }