pstoedit_sys/
lib.rs

1//! Native bindings to [pstoedit](http://pstoedit.net).
2//!
3//! This crate contains low-level bindings to the C API of pstoedit, a C++
4//! program that can translate PostScript and PDF graphics into other vector
5//! formats.
6//!
7//! # Compatibility
8//! Multiple versions of pstoedit are supported, but the appropriate feature
9//! starting with `pstoedit_` has to be enabled.
10//!
11//! - `pstoedit_4_01`: compatible with pstoedit version 4.01, and likely with future
12//!   4.xx releases.
13//! - `pstoedit_4_00`: compatible with pstoedit version 4.00–4.01, and likely
14//!   with future 4.xx releases.
15//! - No feature starting with `pstoedit_`: compatible with pstoedit version
16//!   3.17–3.78.
17
18#![cfg_attr(docsrs, feature(doc_cfg))]
19
20#[allow(non_camel_case_types)]
21#[allow(non_snake_case)]
22#[allow(non_upper_case_globals)]
23mod bindings;
24
25pub use bindings::*;
26
27#[cfg(test)]
28mod tests {
29    use super::*;
30    use std::os::raw::{c_char, c_int};
31    use std::{env, ptr};
32
33    #[test]
34    fn dll_version() {
35        #[cfg(not(feature = "pstoedit_4_00"))]
36        assert_eq!(pstoeditdllversion, 301);
37        #[cfg(feature = "pstoedit_4_00")]
38        assert_eq!(pstoeditdllversion, 401);
39    }
40
41    #[test]
42    fn init() {
43        assert!(unsafe { pstoedit_checkversion(pstoeditdllversion) } != 0);
44    }
45
46    #[test]
47    fn driver_info() {
48        init();
49        let drivers: *mut DriverDescription_S = unsafe { getPstoeditDriverInfo_plainC() };
50        assert!(drivers != ptr::null_mut());
51        unsafe { clearPstoeditDriverInfo_plainC(drivers) };
52    }
53
54    #[test]
55    fn native_driver_info() {
56        init();
57        let drivers: *mut DriverDescription_S = unsafe { getPstoeditNativeDriverInfo_plainC() };
58        assert!(drivers != ptr::null_mut());
59        unsafe { clearPstoeditDriverInfo_plainC(drivers) };
60    }
61
62    #[test]
63    fn pstoedit() {
64        init();
65        // Perform ghostscript test
66        let argv = [
67            b"pstoedit\0".as_ptr() as *const c_char,
68            b"-gstest\0".as_ptr() as *const c_char,
69        ];
70        let argc = argv.len() as c_int;
71        // Get ghostscript through string, not environment
72        let psinterpreter = b"gs\0".as_ptr() as *const c_char;
73        env::set_var("GS", "should_not_be_used");
74        let result = unsafe { pstoedit_plainC(argc, argv.as_ptr(), psinterpreter) };
75        assert_eq!(result, 0);
76    }
77}