summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDavid Drysdale <drysdale@google.com>2021-11-26 01:42:47 +0000
committerGitHub <noreply@github.com>2021-11-26 02:42:47 +0100
commit7bd23291e29e1874f57a628e94d7632b3b367ae6 (patch)
treea7381f98e6fb46c2020bccb344e98ba0e38523ab /tests
parent04f5c0715832feee6c059128cd5cd70056e861f7 (diff)
Add --blocklist-file option (#2097)
Update Item to hold a `clang::SourceLocation` and use this to allow blocklisting based on filename. The existing code has a special case that always maps <stdint.h> integer types to corresponding Rust integer types, even if the C types are blocklisted. To match this special case behaviour, also treat these C <stdint.h> types as being eligible for derived Copy/Clone/Debug traits. Fixes #2096
Diffstat (limited to 'tests')
-rw-r--r--tests/expectations/tests/blocklist-file.rs94
-rw-r--r--tests/headers/blocklist-file.hpp18
-rw-r--r--tests/headers/blocklisted/fake-stdint.h7
-rw-r--r--tests/headers/blocklisted/file.hpp26
4 files changed, 145 insertions, 0 deletions
diff --git a/tests/expectations/tests/blocklist-file.rs b/tests/expectations/tests/blocklist-file.rs
new file mode 100644
index 00000000..fe00b5ab
--- /dev/null
+++ b/tests/expectations/tests/blocklist-file.rs
@@ -0,0 +1,94 @@
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
+
+#[repr(C)]
+#[derive(Debug, Default, Copy, Clone)]
+pub struct SizedIntegers {
+ pub x: u8,
+ pub y: u16,
+ pub z: u32,
+}
+#[test]
+fn bindgen_test_layout_SizedIntegers() {
+ assert_eq!(
+ ::std::mem::size_of::<SizedIntegers>(),
+ 8usize,
+ concat!("Size of: ", stringify!(SizedIntegers))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<SizedIntegers>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(SizedIntegers))
+ );
+ assert_eq!(
+ unsafe {
+ &(*(::std::ptr::null::<SizedIntegers>())).x as *const _ as usize
+ },
+ 0usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(SizedIntegers),
+ "::",
+ stringify!(x)
+ )
+ );
+ assert_eq!(
+ unsafe {
+ &(*(::std::ptr::null::<SizedIntegers>())).y as *const _ as usize
+ },
+ 2usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(SizedIntegers),
+ "::",
+ stringify!(y)
+ )
+ );
+ assert_eq!(
+ unsafe {
+ &(*(::std::ptr::null::<SizedIntegers>())).z as *const _ as usize
+ },
+ 4usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(SizedIntegers),
+ "::",
+ stringify!(z)
+ )
+ );
+}
+#[repr(C)]
+#[derive(Debug, Default, Copy, Clone)]
+pub struct StructWithBlocklistedFwdDecl {
+ pub b: u8,
+}
+#[test]
+fn bindgen_test_layout_StructWithBlocklistedFwdDecl() {
+ assert_eq!(
+ ::std::mem::size_of::<StructWithBlocklistedFwdDecl>(),
+ 1usize,
+ concat!("Size of: ", stringify!(StructWithBlocklistedFwdDecl))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<StructWithBlocklistedFwdDecl>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(StructWithBlocklistedFwdDecl))
+ );
+ assert_eq!(
+ unsafe {
+ &(*(::std::ptr::null::<StructWithBlocklistedFwdDecl>())).b
+ as *const _ as usize
+ },
+ 0usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(StructWithBlocklistedFwdDecl),
+ "::",
+ stringify!(b)
+ )
+ );
+}
diff --git a/tests/headers/blocklist-file.hpp b/tests/headers/blocklist-file.hpp
new file mode 100644
index 00000000..ad8bcd66
--- /dev/null
+++ b/tests/headers/blocklist-file.hpp
@@ -0,0 +1,18 @@
+// bindgen-flags: --blocklist-file ".*/blocklisted/file.*" -- -Itests/headers
+
+// Forward declaration of struct that's defined in a blocklisted file.
+struct StructWithBlocklistedDefinition;
+
+#include "blocklisted/file.hpp"
+#include "blocklisted/fake-stdint.h"
+
+struct SizedIntegers {
+ uint8_t x;
+ uint16_t y;
+ uint32_t z;
+};
+
+// Actual definition of struct that has a forward declaration in a blocklisted file.
+struct StructWithBlocklistedFwdDecl {
+ uint8_t b;
+};
diff --git a/tests/headers/blocklisted/fake-stdint.h b/tests/headers/blocklisted/fake-stdint.h
new file mode 100644
index 00000000..a8cfe010
--- /dev/null
+++ b/tests/headers/blocklisted/fake-stdint.h
@@ -0,0 +1,7 @@
+// <stdint.h>-like types get special treatment even when blocklisted.
+typedef signed char int8_t;
+typedef unsigned char uint8_t;
+typedef signed short int16_t;
+typedef unsigned short uint16_t;
+typedef signed int int32_t;
+typedef unsigned int uint32_t;
diff --git a/tests/headers/blocklisted/file.hpp b/tests/headers/blocklisted/file.hpp
new file mode 100644
index 00000000..4bcb589e
--- /dev/null
+++ b/tests/headers/blocklisted/file.hpp
@@ -0,0 +1,26 @@
+void SomeFunction();
+extern int someVar;
+#define SOME_DEFUN 123
+
+class someClass {
+ void somePrivateMethod();
+public:
+ void somePublicMethod(int foo);
+};
+
+extern "C" void ExternFunction();
+
+namespace foo {
+ void NamespacedFunction();
+}
+
+namespace bar {
+ void NamespacedFunction();
+}
+
+
+struct StructWithBlocklistedFwdDecl;
+
+struct StructWithBlocklistedDefinition {
+ StructWithBlocklistedFwdDecl* other;
+};