eric_bindings/
lib.rs

1#![allow(non_upper_case_globals)]
2#![allow(non_camel_case_types)]
3#![allow(non_snake_case)]
4#![allow(dead_code)]
5// TODO: extern block uses type u128, which is not FFI-safe
6#![allow(improper_ctypes)]
7
8include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
9
10#[cfg(test)]
11mod tests {
12    use super::*;
13    use anyhow::Context;
14    use std::{
15        env,
16        ffi::CString,
17        path::{Path, PathBuf},
18        str::FromStr,
19    };
20
21    fn get_plugin_path(eric_path: &Path) -> PathBuf {
22        env::var("PLUGIN_PATH")
23            .ok()
24            .map(|path| PathBuf::from_str(&path).expect("invalid path for `PLUGIN_PATH`"))
25            .unwrap_or_else(|| eric_path.join("lib").join("plugins"))
26    }
27
28    #[test]
29    fn test_ericapi() {
30        let eric_path = env::var("ERIC_PATH").expect("Missing environment variable `ERIC_PATH`");
31        let eric_path = Path::new(&eric_path);
32        let plugin_path = get_plugin_path(eric_path);
33        let plugin_path = CString::new(plugin_path.to_str().expect("empty path for `ERIC_PATH`"))
34            .context("Can't convert to CString")
35            .unwrap();
36
37        let log_path =
38            env::current_dir().expect("Missing environment variable for current directory");
39        let log_path = CString::new(log_path.to_str().unwrap())
40            .context("Can't convert to CString")
41            .unwrap();
42
43        let error_code = unsafe { EricInitialisiere(plugin_path.as_ptr(), log_path.as_ptr()) };
44        assert_eq!(error_code, 0);
45
46        let buffer = unsafe { EricRueckgabepufferErzeugen() };
47        let error_code = unsafe { EricVersion(buffer) };
48        assert_eq!(error_code, 0);
49
50        let error_code = unsafe { EricBeende() };
51        assert_eq!(error_code, 0);
52    }
53}