summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/expectations/Cargo.toml3
-rw-r--r--tests/expectations/tests/dynamic_loading_simple.rs81
-rw-r--r--tests/expectations/tests/dynamic_loading_template.rs56
-rw-r--r--tests/expectations/tests/dynamic_loading_with_blacklist.rs117
-rw-r--r--tests/expectations/tests/dynamic_loading_with_class.rs109
-rw-r--r--tests/expectations/tests/dynamic_loading_with_whitelist.rs66
-rw-r--r--tests/headers/dynamic_loading_simple.h5
-rw-r--r--tests/headers/dynamic_loading_template.hpp10
-rw-r--r--tests/headers/dynamic_loading_with_blacklist.hpp15
-rw-r--r--tests/headers/dynamic_loading_with_class.hpp15
-rw-r--r--tests/headers/dynamic_loading_with_whitelist.hpp15
11 files changed, 491 insertions, 1 deletions
diff --git a/tests/expectations/Cargo.toml b/tests/expectations/Cargo.toml
index 6acb1d40..c78cc09a 100644
--- a/tests/expectations/Cargo.toml
+++ b/tests/expectations/Cargo.toml
@@ -10,4 +10,5 @@ authors = [
[dependencies]
objc = "0.2"
-block = "0.1" \ No newline at end of file
+block = "0.1"
+libloading = "0.6.2"
diff --git a/tests/expectations/tests/dynamic_loading_simple.rs b/tests/expectations/tests/dynamic_loading_simple.rs
new file mode 100644
index 00000000..b195a05d
--- /dev/null
+++ b/tests/expectations/tests/dynamic_loading_simple.rs
@@ -0,0 +1,81 @@
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
+
+extern crate libloading;
+pub struct TestLib {
+ __library: ::libloading::Library,
+ foo: Result<
+ unsafe extern "C" fn(
+ x: ::std::os::raw::c_int,
+ y: ::std::os::raw::c_int,
+ ) -> ::std::os::raw::c_int,
+ ::libloading::Error,
+ >,
+ bar: Result<
+ unsafe extern "C" fn(
+ x: *mut ::std::os::raw::c_void,
+ ) -> ::std::os::raw::c_int,
+ ::libloading::Error,
+ >,
+ baz: Result<
+ unsafe extern "C" fn() -> ::std::os::raw::c_int,
+ ::libloading::Error,
+ >,
+}
+impl TestLib {
+ pub unsafe fn new<P>(path: P) -> Result<Self, ::libloading::Error>
+ where
+ P: AsRef<::std::ffi::OsStr>,
+ {
+ let __library = ::libloading::Library::new(path)?;
+ let foo = __library.get("foo".as_bytes()).map(|sym| *sym);
+ let bar = __library.get("bar".as_bytes()).map(|sym| *sym);
+ let baz = __library.get("baz".as_bytes()).map(|sym| *sym);
+ Ok(TestLib {
+ __library: __library,
+ foo,
+ bar,
+ baz,
+ })
+ }
+ pub fn can_call(&self) -> CheckTestLib {
+ CheckTestLib { __library: self }
+ }
+ pub unsafe fn foo(
+ &self,
+ x: ::std::os::raw::c_int,
+ y: ::std::os::raw::c_int,
+ ) -> ::std::os::raw::c_int {
+ let sym = self.foo.as_ref().expect("Expected function, got error.");
+ (sym)(x, y)
+ }
+ pub unsafe fn bar(
+ &self,
+ x: *mut ::std::os::raw::c_void,
+ ) -> ::std::os::raw::c_int {
+ let sym = self.bar.as_ref().expect("Expected function, got error.");
+ (sym)(x)
+ }
+ pub unsafe fn baz(&self) -> ::std::os::raw::c_int {
+ let sym = self.baz.as_ref().expect("Expected function, got error.");
+ (sym)()
+ }
+}
+pub struct CheckTestLib<'a> {
+ __library: &'a TestLib,
+}
+impl<'a> CheckTestLib<'a> {
+ pub fn foo(&self) -> Result<(), &'a ::libloading::Error> {
+ self.__library.foo.as_ref().map(|_| ())
+ }
+ pub fn bar(&self) -> Result<(), &'a ::libloading::Error> {
+ self.__library.bar.as_ref().map(|_| ())
+ }
+ pub fn baz(&self) -> Result<(), &'a ::libloading::Error> {
+ self.__library.baz.as_ref().map(|_| ())
+ }
+}
diff --git a/tests/expectations/tests/dynamic_loading_template.rs b/tests/expectations/tests/dynamic_loading_template.rs
new file mode 100644
index 00000000..b9fa1698
--- /dev/null
+++ b/tests/expectations/tests/dynamic_loading_template.rs
@@ -0,0 +1,56 @@
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
+
+extern crate libloading;
+pub struct TestLib {
+ __library: ::libloading::Library,
+ foo: Result<
+ unsafe extern "C" fn(x: ::std::os::raw::c_int) -> ::std::os::raw::c_int,
+ ::libloading::Error,
+ >,
+ foo1: Result<unsafe extern "C" fn(x: f32) -> f32, ::libloading::Error>,
+}
+impl TestLib {
+ pub unsafe fn new<P>(path: P) -> Result<Self, ::libloading::Error>
+ where
+ P: AsRef<::std::ffi::OsStr>,
+ {
+ let __library = ::libloading::Library::new(path)?;
+ let foo = __library.get("foo".as_bytes()).map(|sym| *sym);
+ let foo1 = __library.get("foo1".as_bytes()).map(|sym| *sym);
+ Ok(TestLib {
+ __library: __library,
+ foo,
+ foo1,
+ })
+ }
+ pub fn can_call(&self) -> CheckTestLib {
+ CheckTestLib { __library: self }
+ }
+ pub unsafe fn foo(
+ &self,
+ x: ::std::os::raw::c_int,
+ ) -> ::std::os::raw::c_int {
+ let sym = self.foo.as_ref().expect("Expected function, got error.");
+ (sym)(x)
+ }
+ pub unsafe fn foo1(&self, x: f32) -> f32 {
+ let sym = self.foo1.as_ref().expect("Expected function, got error.");
+ (sym)(x)
+ }
+}
+pub struct CheckTestLib<'a> {
+ __library: &'a TestLib,
+}
+impl<'a> CheckTestLib<'a> {
+ pub fn foo(&self) -> Result<(), &'a ::libloading::Error> {
+ self.__library.foo.as_ref().map(|_| ())
+ }
+ pub fn foo1(&self) -> Result<(), &'a ::libloading::Error> {
+ self.__library.foo1.as_ref().map(|_| ())
+ }
+}
diff --git a/tests/expectations/tests/dynamic_loading_with_blacklist.rs b/tests/expectations/tests/dynamic_loading_with_blacklist.rs
new file mode 100644
index 00000000..259054b2
--- /dev/null
+++ b/tests/expectations/tests/dynamic_loading_with_blacklist.rs
@@ -0,0 +1,117 @@
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
+
+#[repr(C)]
+#[derive(Debug, Default, Copy, Clone)]
+pub struct X {
+ pub _x: ::std::os::raw::c_int,
+}
+#[test]
+fn bindgen_test_layout_X() {
+ assert_eq!(
+ ::std::mem::size_of::<X>(),
+ 4usize,
+ concat!("Size of: ", stringify!(X))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<X>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(X))
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<X>()))._x as *const _ as usize },
+ 0usize,
+ concat!("Offset of field: ", stringify!(X), "::", stringify!(_x))
+ );
+}
+extern "C" {
+ #[link_name = "\u{1}_ZN1X13some_functionEv"]
+ pub fn X_some_function(this: *mut X);
+}
+extern "C" {
+ #[link_name = "\u{1}_ZN1X19some_other_functionEv"]
+ pub fn X_some_other_function(this: *mut X);
+}
+extern "C" {
+ #[link_name = "\u{1}_ZN1XC1Ei"]
+ pub fn X_X(this: *mut X, x: ::std::os::raw::c_int);
+}
+impl X {
+ #[inline]
+ pub unsafe fn some_function(&mut self) {
+ X_some_function(self)
+ }
+ #[inline]
+ pub unsafe fn some_other_function(&mut self) {
+ X_some_other_function(self)
+ }
+ #[inline]
+ pub unsafe fn new(x: ::std::os::raw::c_int) -> Self {
+ let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit();
+ X_X(__bindgen_tmp.as_mut_ptr(), x);
+ __bindgen_tmp.assume_init()
+ }
+}
+extern crate libloading;
+pub struct TestLib {
+ __library: ::libloading::Library,
+ foo: Result<
+ unsafe extern "C" fn(
+ x: *mut ::std::os::raw::c_void,
+ ) -> ::std::os::raw::c_int,
+ ::libloading::Error,
+ >,
+ bar: Result<
+ unsafe extern "C" fn(
+ x: *mut ::std::os::raw::c_void,
+ ) -> ::std::os::raw::c_int,
+ ::libloading::Error,
+ >,
+}
+impl TestLib {
+ pub unsafe fn new<P>(path: P) -> Result<Self, ::libloading::Error>
+ where
+ P: AsRef<::std::ffi::OsStr>,
+ {
+ let __library = ::libloading::Library::new(path)?;
+ let foo = __library.get("foo".as_bytes()).map(|sym| *sym);
+ let bar = __library.get("bar".as_bytes()).map(|sym| *sym);
+ Ok(TestLib {
+ __library: __library,
+ foo,
+ bar,
+ })
+ }
+ pub fn can_call(&self) -> CheckTestLib {
+ CheckTestLib { __library: self }
+ }
+ pub unsafe fn foo(
+ &self,
+ x: *mut ::std::os::raw::c_void,
+ ) -> ::std::os::raw::c_int {
+ let sym = self.foo.as_ref().expect("Expected function, got error.");
+ (sym)(x)
+ }
+ pub unsafe fn bar(
+ &self,
+ x: *mut ::std::os::raw::c_void,
+ ) -> ::std::os::raw::c_int {
+ let sym = self.bar.as_ref().expect("Expected function, got error.");
+ (sym)(x)
+ }
+}
+pub struct CheckTestLib<'a> {
+ __library: &'a TestLib,
+}
+impl<'a> CheckTestLib<'a> {
+ pub fn foo(&self) -> Result<(), &'a ::libloading::Error> {
+ self.__library.foo.as_ref().map(|_| ())
+ }
+ pub fn bar(&self) -> Result<(), &'a ::libloading::Error> {
+ self.__library.bar.as_ref().map(|_| ())
+ }
+}
diff --git a/tests/expectations/tests/dynamic_loading_with_class.rs b/tests/expectations/tests/dynamic_loading_with_class.rs
new file mode 100644
index 00000000..636f01bb
--- /dev/null
+++ b/tests/expectations/tests/dynamic_loading_with_class.rs
@@ -0,0 +1,109 @@
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
+
+#[repr(C)]
+#[derive(Debug, Default, Copy, Clone)]
+pub struct A {
+ pub _x: ::std::os::raw::c_int,
+}
+#[test]
+fn bindgen_test_layout_A() {
+ assert_eq!(
+ ::std::mem::size_of::<A>(),
+ 4usize,
+ concat!("Size of: ", stringify!(A))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<A>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(A))
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<A>()))._x as *const _ as usize },
+ 0usize,
+ concat!("Offset of field: ", stringify!(A), "::", stringify!(_x))
+ );
+}
+extern "C" {
+ #[link_name = "\u{1}_ZN1A13some_functionEv"]
+ pub fn A_some_function(this: *mut A);
+}
+extern "C" {
+ #[link_name = "\u{1}_ZN1A19some_other_functionEv"]
+ pub fn A_some_other_function(this: *mut A);
+}
+extern "C" {
+ #[link_name = "\u{1}_ZN1AC1Ei"]
+ pub fn A_A(this: *mut A, x: ::std::os::raw::c_int);
+}
+impl A {
+ #[inline]
+ pub unsafe fn some_function(&mut self) {
+ A_some_function(self)
+ }
+ #[inline]
+ pub unsafe fn some_other_function(&mut self) {
+ A_some_other_function(self)
+ }
+ #[inline]
+ pub unsafe fn new(x: ::std::os::raw::c_int) -> Self {
+ let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit();
+ A_A(__bindgen_tmp.as_mut_ptr(), x);
+ __bindgen_tmp.assume_init()
+ }
+}
+extern crate libloading;
+pub struct TestLib {
+ __library: ::libloading::Library,
+ foo: Result<
+ unsafe extern "C" fn(
+ x: *mut ::std::os::raw::c_void,
+ ) -> ::std::os::raw::c_int,
+ ::libloading::Error,
+ >,
+ bar: Result<unsafe extern "C" fn(), ::libloading::Error>,
+}
+impl TestLib {
+ pub unsafe fn new<P>(path: P) -> Result<Self, ::libloading::Error>
+ where
+ P: AsRef<::std::ffi::OsStr>,
+ {
+ let __library = ::libloading::Library::new(path)?;
+ let foo = __library.get("foo".as_bytes()).map(|sym| *sym);
+ let bar = __library.get("bar".as_bytes()).map(|sym| *sym);
+ Ok(TestLib {
+ __library: __library,
+ foo,
+ bar,
+ })
+ }
+ pub fn can_call(&self) -> CheckTestLib {
+ CheckTestLib { __library: self }
+ }
+ pub unsafe fn foo(
+ &self,
+ x: *mut ::std::os::raw::c_void,
+ ) -> ::std::os::raw::c_int {
+ let sym = self.foo.as_ref().expect("Expected function, got error.");
+ (sym)(x)
+ }
+ pub unsafe fn bar(&self) -> () {
+ let sym = self.bar.as_ref().expect("Expected function, got error.");
+ (sym)()
+ }
+}
+pub struct CheckTestLib<'a> {
+ __library: &'a TestLib,
+}
+impl<'a> CheckTestLib<'a> {
+ pub fn foo(&self) -> Result<(), &'a ::libloading::Error> {
+ self.__library.foo.as_ref().map(|_| ())
+ }
+ pub fn bar(&self) -> Result<(), &'a ::libloading::Error> {
+ self.__library.bar.as_ref().map(|_| ())
+ }
+}
diff --git a/tests/expectations/tests/dynamic_loading_with_whitelist.rs b/tests/expectations/tests/dynamic_loading_with_whitelist.rs
new file mode 100644
index 00000000..a1f8a2a4
--- /dev/null
+++ b/tests/expectations/tests/dynamic_loading_with_whitelist.rs
@@ -0,0 +1,66 @@
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
+
+extern crate libloading;
+pub struct TestLib {
+ __library: ::libloading::Library,
+ foo: Result<
+ unsafe extern "C" fn(
+ x: *mut ::std::os::raw::c_void,
+ ) -> ::std::os::raw::c_int,
+ ::libloading::Error,
+ >,
+ baz: Result<
+ unsafe extern "C" fn(
+ x: *mut ::std::os::raw::c_void,
+ ) -> ::std::os::raw::c_int,
+ ::libloading::Error,
+ >,
+}
+impl TestLib {
+ pub unsafe fn new<P>(path: P) -> Result<Self, ::libloading::Error>
+ where
+ P: AsRef<::std::ffi::OsStr>,
+ {
+ let __library = ::libloading::Library::new(path)?;
+ let foo = __library.get("foo".as_bytes()).map(|sym| *sym);
+ let baz = __library.get("baz".as_bytes()).map(|sym| *sym);
+ Ok(TestLib {
+ __library: __library,
+ foo,
+ baz,
+ })
+ }
+ pub fn can_call(&self) -> CheckTestLib {
+ CheckTestLib { __library: self }
+ }
+ pub unsafe fn foo(
+ &self,
+ x: *mut ::std::os::raw::c_void,
+ ) -> ::std::os::raw::c_int {
+ let sym = self.foo.as_ref().expect("Expected function, got error.");
+ (sym)(x)
+ }
+ pub unsafe fn baz(
+ &self,
+ x: *mut ::std::os::raw::c_void,
+ ) -> ::std::os::raw::c_int {
+ let sym = self.baz.as_ref().expect("Expected function, got error.");
+ (sym)(x)
+ }
+}
+pub struct CheckTestLib<'a> {
+ __library: &'a TestLib,
+}
+impl<'a> CheckTestLib<'a> {
+ pub fn foo(&self) -> Result<(), &'a ::libloading::Error> {
+ self.__library.foo.as_ref().map(|_| ())
+ }
+ pub fn baz(&self) -> Result<(), &'a ::libloading::Error> {
+ self.__library.baz.as_ref().map(|_| ())
+ }
+}
diff --git a/tests/headers/dynamic_loading_simple.h b/tests/headers/dynamic_loading_simple.h
new file mode 100644
index 00000000..f418851b
--- /dev/null
+++ b/tests/headers/dynamic_loading_simple.h
@@ -0,0 +1,5 @@
+// bindgen-flags: --dynamic-loading TestLib
+
+int foo(int x, int y);
+int bar(void *x);
+int baz();
diff --git a/tests/headers/dynamic_loading_template.hpp b/tests/headers/dynamic_loading_template.hpp
new file mode 100644
index 00000000..27f04c8e
--- /dev/null
+++ b/tests/headers/dynamic_loading_template.hpp
@@ -0,0 +1,10 @@
+// bindgen-flags: --dynamic-loading TestLib
+
+template<typename T>
+T foo(T x);
+
+template<>
+int foo(int x);
+
+template<>
+float foo(float x);
diff --git a/tests/headers/dynamic_loading_with_blacklist.hpp b/tests/headers/dynamic_loading_with_blacklist.hpp
new file mode 100644
index 00000000..2988ba69
--- /dev/null
+++ b/tests/headers/dynamic_loading_with_blacklist.hpp
@@ -0,0 +1,15 @@
+// bindgen-flags: --dynamic-loading TestLib --blacklist-function baz
+
+class X {
+ int _x;
+
+ public:
+ X(int x);
+
+ void some_function();
+ void some_other_function();
+};
+
+int foo(void *x);
+int bar(void *x);
+int baz(void *x);
diff --git a/tests/headers/dynamic_loading_with_class.hpp b/tests/headers/dynamic_loading_with_class.hpp
new file mode 100644
index 00000000..632db4d0
--- /dev/null
+++ b/tests/headers/dynamic_loading_with_class.hpp
@@ -0,0 +1,15 @@
+// bindgen-flags: --dynamic-loading TestLib
+
+int foo(void *x);
+
+class A {
+ int _x;
+
+ public:
+ A(int x);
+
+ void some_function();
+ void some_other_function();
+};
+
+void bar();
diff --git a/tests/headers/dynamic_loading_with_whitelist.hpp b/tests/headers/dynamic_loading_with_whitelist.hpp
new file mode 100644
index 00000000..922b5461
--- /dev/null
+++ b/tests/headers/dynamic_loading_with_whitelist.hpp
@@ -0,0 +1,15 @@
+// bindgen-flags: --dynamic-loading TestLib --whitelist-function baz --whitelist-function foo
+
+class X {
+ int _x;
+
+ public:
+ X(int x);
+
+ void some_function();
+ void some_other_function();
+};
+
+int foo(void *x);
+int bar(void *x);
+int baz(void *x);