mirror of
https://gitee.com/openharmony/third_party_rust_cxx
synced 2025-02-17 15:09:41 +00:00
Tests for opaque C types in namepsaces
This commit is contained in:
parent
585bb0bc56
commit
d47af7a9d3
@ -25,6 +25,9 @@ pub mod ffi2 {
|
||||
#[namespace (namespace = G)]
|
||||
type G = crate::other::G;
|
||||
|
||||
#[namespace(namespace = H)]
|
||||
type H;
|
||||
|
||||
fn c_take_trivial_ptr(d: UniquePtr<D>);
|
||||
fn c_take_trivial_ref(d: &D);
|
||||
fn c_take_trivial(d: D);
|
||||
@ -41,5 +44,7 @@ pub mod ffi2 {
|
||||
fn c_return_trivial_ns() -> G;
|
||||
fn c_return_opaque_ptr() -> UniquePtr<E>;
|
||||
fn c_return_ns_opaque_ptr() -> UniquePtr<F>;
|
||||
fn c_return_ns_unique_ptr() -> UniquePtr<H>;
|
||||
fn c_take_ref_ns_c(h: &H);
|
||||
}
|
||||
}
|
||||
|
@ -55,6 +55,10 @@ std::unique_ptr<C> c_return_unique_ptr() {
|
||||
return std::unique_ptr<C>(new C{2020});
|
||||
}
|
||||
|
||||
std::unique_ptr<::H::H> c_return_ns_unique_ptr() {
|
||||
return std::unique_ptr<::H::H>(new ::H::H{"hello"});
|
||||
}
|
||||
|
||||
const size_t &c_return_ref(const Shared &shared) { return shared.z; }
|
||||
|
||||
const size_t &c_return_ns_ref(const ::A::AShared &shared) { return shared.z; }
|
||||
@ -220,6 +224,12 @@ void c_take_ref_c(const C &c) {
|
||||
}
|
||||
}
|
||||
|
||||
void c_take_ref_ns_c(const ::H::H &h) {
|
||||
if (h.h == "hello") {
|
||||
cxx_test_suite_set_correct();
|
||||
}
|
||||
}
|
||||
|
||||
void c_take_str(rust::Str s) {
|
||||
if (std::string(s) == "2020") {
|
||||
cxx_test_suite_set_correct();
|
||||
|
@ -25,6 +25,13 @@ namespace G {
|
||||
};
|
||||
}
|
||||
|
||||
namespace H {
|
||||
class H {
|
||||
public:
|
||||
std::string h;
|
||||
};
|
||||
}
|
||||
|
||||
namespace tests {
|
||||
|
||||
struct R;
|
||||
@ -70,6 +77,7 @@ Shared c_return_shared();
|
||||
::A::B::ABShared c_return_nested_ns_shared();
|
||||
rust::Box<R> c_return_box();
|
||||
std::unique_ptr<C> c_return_unique_ptr();
|
||||
std::unique_ptr<::H::H> c_return_ns_unique_ptr();
|
||||
const size_t &c_return_ref(const Shared &shared);
|
||||
const size_t &c_return_ns_ref(const ::A::AShared &shared);
|
||||
const size_t &c_return_nested_ns_ref(const ::A::B::ABShared &shared);
|
||||
@ -103,6 +111,7 @@ void c_take_box(rust::Box<R> r);
|
||||
void c_take_unique_ptr(std::unique_ptr<C> c);
|
||||
void c_take_ref_r(const R &r);
|
||||
void c_take_ref_c(const C &c);
|
||||
void c_take_ref_ns_c(const ::H::H &h);
|
||||
void c_take_str(rust::Str s);
|
||||
void c_take_sliceu8(rust::Slice<uint8_t> s);
|
||||
void c_take_rust_string(rust::String s);
|
||||
|
@ -30,6 +30,7 @@ fn test_c_return() {
|
||||
assert_eq!(2020, ffi::c_return_shared().z);
|
||||
assert_eq!(2020, *ffi::c_return_box());
|
||||
ffi::c_return_unique_ptr();
|
||||
ffi2::c_return_ns_unique_ptr();
|
||||
assert_eq!(2020, *ffi::c_return_ref(&shared));
|
||||
assert_eq!(2020, *ffi::c_return_ns_ref(&ns_shared));
|
||||
assert_eq!(2020, *ffi::c_return_nested_ns_ref(&nested_ns_shared));
|
||||
@ -97,6 +98,7 @@ fn test_c_try_return() {
|
||||
#[test]
|
||||
fn test_c_take() {
|
||||
let unique_ptr = ffi::c_return_unique_ptr();
|
||||
let unique_ptr_ns = ffi2::c_return_ns_unique_ptr();
|
||||
|
||||
check!(ffi::c_take_primitive(2020));
|
||||
check!(ffi::c_take_shared(ffi::Shared { z: 2020 }));
|
||||
@ -104,6 +106,7 @@ fn test_c_take() {
|
||||
check!(ffi::c_take_nested_ns_shared(ffi::ABShared { z: 2020 }));
|
||||
check!(ffi::c_take_box(Box::new(2020)));
|
||||
check!(ffi::c_take_ref_c(&unique_ptr));
|
||||
check!(ffi2::c_take_ref_ns_c(&unique_ptr_ns));
|
||||
check!(cxx_test_suite::module::ffi::c_take_unique_ptr(unique_ptr));
|
||||
check!(ffi::c_take_str("2020"));
|
||||
check!(ffi::c_take_sliceu8(b"2020"));
|
||||
|
Loading…
x
Reference in New Issue
Block a user