Skip to content

Commit ddc146e

Browse files
committed
Adding tests for functions in other namespaces.
1 parent d47af7a commit ddc146e

File tree

5 files changed

+38
-0
lines changed

5 files changed

+38
-0
lines changed

tests/ffi/extra.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,10 @@ pub mod ffi2 {
4646
fn c_return_ns_opaque_ptr() -> UniquePtr<F>;
4747
fn c_return_ns_unique_ptr() -> UniquePtr<H>;
4848
fn c_take_ref_ns_c(h: &H);
49+
50+
#[namespace (namespace = other)]
51+
fn ns_c_take_trivial(d: D);
52+
#[namespace (namespace = other)]
53+
fn ns_c_return_trivial() -> D;
4954
}
5055
}

tests/ffi/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ pub mod ffi {
199199
fn cOverloadedFunction(x: i32) -> String;
200200
#[rust_name = "str_overloaded_function"]
201201
fn cOverloadedFunction(x: &str) -> String;
202+
203+
#[namespace (namespace = other)]
204+
fn ns_c_take_ns_shared(shared: AShared);
202205
}
203206

204207
extern "C" {

tests/ffi/tests.cc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,3 +627,24 @@ extern "C" const char *cxx_run_test() noexcept {
627627
}
628628

629629
} // namespace tests
630+
631+
namespace other {
632+
633+
void ns_c_take_trivial(::tests::D d) {
634+
if (d.d == 30) {
635+
cxx_test_suite_set_correct();
636+
}
637+
}
638+
639+
::tests::D ns_c_return_trivial() {
640+
::tests::D d;
641+
d.d = 30;
642+
return d;
643+
}
644+
645+
void ns_c_take_ns_shared(::A::AShared shared) {
646+
if (shared.z == 2020) {
647+
cxx_test_suite_set_correct();
648+
}
649+
}
650+
}

tests/ffi/tests.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,9 @@ rust::String cOverloadedFunction(int32_t x);
177177
rust::String cOverloadedFunction(rust::Str x);
178178

179179
} // namespace tests
180+
181+
namespace other {
182+
void ns_c_take_trivial(::tests::D d);
183+
::tests::D ns_c_return_trivial();
184+
void ns_c_take_ns_shared(::A::AShared shared);
185+
} // namespace other

tests/test.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ fn test_c_take() {
103103
check!(ffi::c_take_primitive(2020));
104104
check!(ffi::c_take_shared(ffi::Shared { z: 2020 }));
105105
check!(ffi::c_take_ns_shared(ffi::AShared { z: 2020 }));
106+
check!(ffi::ns_c_take_ns_shared(ffi::AShared { z: 2020 }));
106107
check!(ffi::c_take_nested_ns_shared(ffi::ABShared { z: 2020 }));
107108
check!(ffi::c_take_box(Box::new(2020)));
108109
check!(ffi::c_take_ref_c(&unique_ptr));
@@ -226,6 +227,8 @@ fn test_extern_trivial() {
226227
let d = ffi2::c_return_trivial_ptr();
227228
check!(ffi2::c_take_trivial_ptr(d));
228229
cxx::UniquePtr::new(ffi2::D { d: 42 });
230+
let d = ffi2::ns_c_return_trivial();
231+
check!(ffi2::ns_c_take_trivial(d));
229232

230233
let g = ffi2::c_return_trivial_ns();
231234
check!(ffi2::c_take_trivial_ns_ref(&g));

0 commit comments

Comments
 (0)