summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBoris-Chengbiao Zhou <bobo1239@web.de>2021-04-30 02:16:49 +0200
committerEmilio Cobos Álvarez <emilio@crisal.io>2021-04-30 10:57:18 +0200
commit49430588d720dbb99f6694f7742c1462d36ca01a (patch)
treebf22fc512b75434ac2f5a8bdb04bcf5bd220bf8a /tests
parent425a14617a9b807e51f37610385a24a0485d89fc (diff)
Add a C naming option (#2045)
Closes #2045. Fixes #1252.
Diffstat (limited to 'tests')
-rw-r--r--tests/expectations/tests/c_naming.rs92
-rw-r--r--tests/headers/c_naming.h19
2 files changed, 111 insertions, 0 deletions
diff --git a/tests/expectations/tests/c_naming.rs b/tests/expectations/tests/c_naming.rs
new file mode 100644
index 00000000..041e75ea
--- /dev/null
+++ b/tests/expectations/tests/c_naming.rs
@@ -0,0 +1,92 @@
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
+
+#[repr(C)]
+#[derive(Debug, Default, Copy, Clone)]
+pub struct struct_a {
+ pub a: ::std::os::raw::c_int,
+}
+#[test]
+fn bindgen_test_layout_struct_a() {
+ assert_eq!(
+ ::std::mem::size_of::<struct_a>(),
+ 4usize,
+ concat!("Size of: ", stringify!(struct_a))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<struct_a>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(struct_a))
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<struct_a>())).a as *const _ as usize },
+ 0usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(struct_a),
+ "::",
+ stringify!(a)
+ )
+ );
+}
+pub type a = *const struct_a;
+#[repr(C)]
+#[derive(Copy, Clone)]
+pub union union_b {
+ pub a: ::std::os::raw::c_int,
+ pub b: ::std::os::raw::c_int,
+}
+#[test]
+fn bindgen_test_layout_union_b() {
+ assert_eq!(
+ ::std::mem::size_of::<union_b>(),
+ 4usize,
+ concat!("Size of: ", stringify!(union_b))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<union_b>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(union_b))
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<union_b>())).a as *const _ as usize },
+ 0usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(union_b),
+ "::",
+ stringify!(a)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<union_b>())).b as *const _ as usize },
+ 0usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(union_b),
+ "::",
+ stringify!(b)
+ )
+ );
+}
+impl Default for union_b {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
+}
+pub type b = union_b;
+pub const enum_c_A: enum_c = 0;
+pub type enum_c = ::std::os::raw::c_uint;
+extern "C" {
+ pub fn takes_a(arg: a);
+}
+extern "C" {
+ pub fn takes_b(arg: b);
+}
+extern "C" {
+ pub fn takes_c(arg: enum_c);
+}
diff --git a/tests/headers/c_naming.h b/tests/headers/c_naming.h
new file mode 100644
index 00000000..fd84c271
--- /dev/null
+++ b/tests/headers/c_naming.h
@@ -0,0 +1,19 @@
+// bindgen-flags: --c-naming
+
+typedef const struct a {
+ int a;
+} *a;
+
+union b {
+ int a;
+ int b;
+};
+typedef union b b;
+
+enum c {
+ A,
+};
+
+void takes_a(a arg) {}
+void takes_b(b arg) {}
+void takes_c(enum c arg) {}