2020-10-04 19:48:01 -07:00
|
|
|
use cxx_gen::{generate_header_and_cc, Opt};
|
2020-10-04 19:49:10 -07:00
|
|
|
use std::str;
|
2020-07-30 19:39:04 -07:00
|
|
|
|
2020-10-04 19:49:10 -07:00
|
|
|
const BRIDGE0: &str = r#"
|
2020-07-30 19:39:04 -07:00
|
|
|
#[cxx::bridge]
|
|
|
|
mod ffi {
|
|
|
|
extern "C" {
|
|
|
|
pub fn do_cpp_thing(foo: &str);
|
|
|
|
}
|
|
|
|
}
|
2020-08-29 23:50:14 -07:00
|
|
|
"#;
|
2020-07-30 19:39:04 -07:00
|
|
|
|
|
|
|
#[test]
|
2020-10-04 19:49:10 -07:00
|
|
|
fn test_extern_c_function() {
|
2020-10-04 19:48:01 -07:00
|
|
|
let opt = Opt::default();
|
2020-10-04 19:49:10 -07:00
|
|
|
let source = BRIDGE0.parse().unwrap();
|
|
|
|
let generated = generate_header_and_cc(source, &opt).unwrap();
|
|
|
|
let output = str::from_utf8(&generated.implementation).unwrap();
|
2020-07-30 19:39:04 -07:00
|
|
|
// To avoid continual breakage we won't test every byte.
|
|
|
|
// Let's look for the major features.
|
2020-10-08 18:21:13 -07:00
|
|
|
assert!(output.contains("void cxxbridge05$do_cpp_thing(::rust::Str::Repr foo)"));
|
2020-07-30 19:39:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-10-04 19:49:10 -07:00
|
|
|
fn test_impl_annotation() {
|
2020-10-04 19:48:01 -07:00
|
|
|
let mut opt = Opt::default();
|
|
|
|
opt.cxx_impl_annotations = Some("ANNOTATION".to_owned());
|
2020-10-04 19:49:10 -07:00
|
|
|
let source = BRIDGE0.parse().unwrap();
|
|
|
|
let generated = generate_header_and_cc(source, &opt).unwrap();
|
|
|
|
let output = str::from_utf8(&generated.implementation).unwrap();
|
2020-10-08 18:21:13 -07:00
|
|
|
assert!(output.contains("ANNOTATION void cxxbridge05$do_cpp_thing(::rust::Str::Repr foo)"));
|
2020-07-30 19:39:04 -07:00
|
|
|
}
|