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
39
40
41
42
43
44
45
46
47
48
#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
#![allow(dead_code)]
// TODO: extern block uses type u128, which is not FFI-safe
#![allow(improper_ctypes)]

#[cfg(feature = "no-build")]
mod bindings;
#[cfg(feature = "no-build")]
pub use bindings::bindings_eric_39_6_4_0_linux_x86_64::*;

#[cfg(not(feature = "no-build"))]
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));

#[cfg(test)]
mod tests {
    use super::*;
    use anyhow::Context;
    use std::{env, ffi::CString};

    #[test]
    fn test_ericapi() {
        let plugin_path =
            env::var("PLUGIN_PATH").expect("Missing environment variable 'PLUGIN_PATH'");
        let plugin_path = CString::new(plugin_path)
            .context("Can't convert to CString")
            .unwrap();

        let log_path =
            env::current_dir().expect("Missing environment variable for current directory");
        let log_path = CString::new(log_path.to_str().unwrap())
            .context("Can't convert to CString")
            .unwrap();

        unsafe {
            let error_code = EricInitialisiere(plugin_path.as_ptr(), log_path.as_ptr());
            assert_eq!(error_code, 0);

            let buffer = EricRueckgabepufferErzeugen();
            let error_code = EricVersion(buffer);
            assert_eq!(error_code, 0);

            let error_code = EricBeende();
            assert_eq!(error_code, 0);
        }
    }
}