Skip to content

Commit

Permalink
Add test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
masnagam committed Nov 6, 2024
1 parent 7b12a62 commit 7fcd29d
Show file tree
Hide file tree
Showing 8 changed files with 151 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/expectations/recursive_type_reference.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <cstdarg>
#include <cstdint>
#include <cstdlib>
#include <ostream>
#include <new>

struct B;

struct A {
B *buf;
uintptr_t len;
};

struct B {
int32_t something;
A nested;
};

extern "C" {

void root(const B *foo);

} // extern "C"
18 changes: 18 additions & 0 deletions tests/expectations/recursive_type_reference_both.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

struct B;

typedef struct A {
struct B *buf;
uintptr_t len;
} A;

typedef struct B {
int32_t something;
struct A nested;
} B;

void root(const struct B *foo);
26 changes: 26 additions & 0 deletions tests/expectations/recursive_type_reference_both.compat.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

struct B;

typedef struct A {
struct B *buf;
uintptr_t len;
} A;

typedef struct B {
int32_t something;
struct A nested;
} B;

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

void root(const struct B *foo);

#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
18 changes: 18 additions & 0 deletions tests/expectations/recursive_type_reference_tag.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

struct B;

struct A {
struct B *buf;
uintptr_t len;
};

struct B {
int32_t something;
struct A nested;
};

void root(const struct B *foo);
26 changes: 26 additions & 0 deletions tests/expectations/recursive_type_reference_tag.compat.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

struct B;

struct A {
struct B *buf;
uintptr_t len;
};

struct B {
int32_t something;
struct A nested;
};

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

void root(const struct B *foo);

#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
17 changes: 17 additions & 0 deletions tests/expectations/recursive_type_reference_tag.pyx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, intptr_t
from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, uintptr_t
cdef extern from *:
ctypedef bint bool
ctypedef struct va_list

cdef extern from *:

cdef struct A:
B *buf;
uintptr_t len;

cdef struct B:
int32_t something;
A nested;

void root(const B *foo);
14 changes: 14 additions & 0 deletions tests/rust/recursive_type_reference.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#[repr(C)]
struct A {
buf: *mut B,
len: usize,
}

#[repr(C)]
struct B {
something: i32,
nested: A,
}

#[no_mangle]
pub extern "C" fn root(foo: &B) {}
9 changes: 9 additions & 0 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,11 +328,16 @@ fn test_file(name: &'static str, filename: &'static str) {
.tempdir()
.expect("Creating tmp dir failed");
let tmp_dir = tmp_dir.path();
let recursive = test.file_name().unwrap().to_str().unwrap().starts_with("recursive_");
// Run tests in deduplication priority order. C++ compatibility tests are run first,
// otherwise we would lose the C++ compiler run if they were deduplicated.
let mut cbindgen_outputs = HashSet::new();
for cpp_compat in &[true, false] {
for style in &[Style::Type, Style::Tag, Style::Both] {
if recursive && matches!(style, Style::Type) {
// Test cases for recursive type references do not work with `Style::Type`.
continue;
}
run_compile_test(
name,
test,
Expand Down Expand Up @@ -360,6 +365,10 @@ fn test_file(name: &'static str, filename: &'static str) {
// `Style::Both` should be identical to `Style::Tag` for Cython.
let mut cbindgen_outputs = HashSet::new();
for style in &[Style::Type, Style::Tag] {
if recursive && matches!(style, Style::Type) {
// Test cases for recursive type references do not work with `Style::Type`.
continue;
}
run_compile_test(
name,
test,
Expand Down

0 comments on commit 7fcd29d

Please sign in to comment.