about summary refs log tree commit diff
path: root/library/std/src/sys/pal/unix/weak/tests.rs
blob: d807ba64e35772721953119c0de345f34995ca2a (plain)
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
use super::*;

#[test]
fn dlsym_existing() {
    const TEST_STRING: &'static CStr = c"Ferris!";

    // Try to find a symbol that definitely exists.
    dlsym! {
        fn strlen(cs: *const c_char) -> usize;
    }

    dlsym! {
        #[link_name = "strlen"]
        fn custom_name(cs: *const c_char) -> usize;
    }

    let strlen = strlen.get().unwrap();
    assert_eq!(unsafe { strlen(TEST_STRING.as_ptr()) }, TEST_STRING.count_bytes());

    let custom_name = custom_name.get().unwrap();
    assert_eq!(unsafe { custom_name(TEST_STRING.as_ptr()) }, TEST_STRING.count_bytes());
}

#[test]
fn dlsym_missing() {
    // Try to find a symbol that definitely does not exist.
    dlsym! {
        fn test_symbol_that_does_not_exist() -> i32;
    }

    assert!(test_symbol_that_does_not_exist.get().is_none());
}