5 fn test_loading_atoi() {
10 // The C library does not need to be loaded since it is already linked in
11 let lib = match DynamicLibrary::open(None) {
12 Err(error) => panic!("Could not load self as module: {}", error),
16 let atoi: extern "C" fn(*const libc::c_char) -> libc::c_int = unsafe {
17 match lib.symbol("atoi") {
18 Err(error) => panic!("Could not load function atoi: {}", error),
19 Ok(atoi) => mem::transmute::<*mut u8, _>(atoi),
23 let argument = CString::new("1383428980").unwrap();
24 let expected_result = 0x52757374;
25 let result = atoi(argument.as_ptr());
26 if result != expected_result {
27 panic!("atoi({:?}) != {} but equaled {} instead", argument, expected_result, result)
32 fn test_errors_do_not_crash() {
39 // Open /dev/null as a library to get an error, and make sure
40 // that only causes an error, and not a crash.
41 let path = Path::new("/dev/null");
42 match DynamicLibrary::open(Some(&path)) {
44 Ok(_) => panic!("Successfully opened the empty library."),