Add &mut tests

This commit is contained in:
David Tolnay 2020-08-27 00:55:48 -07:00
parent f1c7f3219b
commit 18d93b6d58
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
3 changed files with 29 additions and 0 deletions

View File

@ -32,6 +32,7 @@ pub mod ffi {
fn c_return_box() -> Box<R>;
fn c_return_unique_ptr() -> UniquePtr<C>;
fn c_return_ref(shared: &Shared) -> &usize;
fn c_return_mut(shared: &mut Shared) -> &mut usize;
fn c_return_str(shared: &Shared) -> &str;
fn c_return_sliceu8(shared: &Shared) -> &[u8];
fn c_return_rust_string() -> String;
@ -41,8 +42,10 @@ pub mod ffi {
fn c_return_unique_ptr_vector_shared() -> UniquePtr<CxxVector<Shared>>;
fn c_return_unique_ptr_vector_opaque() -> UniquePtr<CxxVector<C>>;
fn c_return_ref_vector(c: &C) -> &CxxVector<u8>;
fn c_return_mut_vector(c: &mut C) -> &mut CxxVector<u8>;
fn c_return_rust_vec() -> Vec<u8>;
fn c_return_ref_rust_vec(c: &C) -> &Vec<u8>;
fn c_return_mut_rust_vec(c: &mut C) -> &mut Vec<u8>;
fn c_return_identity(_: usize) -> usize;
fn c_return_sum(_: usize, _: usize) -> usize;
fn c_return_enum(n: u16) -> Enum;
@ -113,11 +116,13 @@ pub mod ffi {
fn r_return_box() -> Box<R>;
fn r_return_unique_ptr() -> UniquePtr<C>;
fn r_return_ref(shared: &Shared) -> &usize;
fn r_return_mut(shared: &mut Shared) -> &mut usize;
fn r_return_str(shared: &Shared) -> &str;
fn r_return_rust_string() -> String;
fn r_return_unique_ptr_string() -> UniquePtr<CxxString>;
fn r_return_rust_vec() -> Vec<u8>;
fn r_return_ref_rust_vec(shared: &Shared) -> &Vec<u8>;
fn r_return_mut_rust_vec(shared: &mut Shared) -> &mut Vec<u8>;
fn r_return_identity(_: usize) -> usize;
fn r_return_sum(_: usize, _: usize) -> usize;
fn r_return_enum(n: u32) -> Enum;
@ -195,6 +200,10 @@ fn r_return_ref(shared: &ffi::Shared) -> &usize {
&shared.z
}
fn r_return_mut(shared: &mut ffi::Shared) -> &mut usize {
&mut shared.z
}
fn r_return_str(shared: &ffi::Shared) -> &str {
let _ = shared;
"2020"
@ -220,6 +229,11 @@ fn r_return_ref_rust_vec(shared: &ffi::Shared) -> &Vec<u8> {
unimplemented!()
}
fn r_return_mut_rust_vec(shared: &mut ffi::Shared) -> &mut Vec<u8> {
let _ = shared;
unimplemented!()
}
fn r_return_identity(n: usize) -> usize {
n
}

View File

@ -35,6 +35,8 @@ size_t C::get_fail() { throw std::runtime_error("unimplemented"); }
const std::vector<uint8_t> &C::get_v() const { return this->v; }
std::vector<uint8_t> &C::get_v() { return this->v; }
size_t c_return_primitive() { return 2020; }
Shared c_return_shared() { return Shared{2020}; }
@ -49,6 +51,8 @@ std::unique_ptr<C> c_return_unique_ptr() {
const size_t &c_return_ref(const Shared &shared) { return shared.z; }
size_t &c_return_mut(Shared &shared) { return shared.z; }
rust::Str c_return_str(const Shared &shared) {
(void)shared;
return "2020";
@ -99,6 +103,8 @@ const std::vector<uint8_t> &c_return_ref_vector(const C &c) {
return c.get_v();
}
std::vector<uint8_t> &c_return_mut_vector(C &c) { return c.get_v(); }
rust::Vec<uint8_t> c_return_rust_vec() {
throw std::runtime_error("unimplemented");
}
@ -108,6 +114,11 @@ const rust::Vec<uint8_t> &c_return_ref_rust_vec(const C &c) {
throw std::runtime_error("unimplemented");
}
rust::Vec<uint8_t> &c_return_mut_rust_vec(C &c) {
(void)c;
throw std::runtime_error("unimplemented");
}
size_t c_return_identity(size_t n) { return n; }
size_t c_return_sum(size_t n1, size_t n2) { return n1 + n2; }

View File

@ -19,6 +19,7 @@ public:
size_t set_succeed(size_t n);
size_t get_fail();
const std::vector<uint8_t> &get_v() const;
std::vector<uint8_t> &get_v();
private:
size_t n;
@ -35,6 +36,7 @@ Shared c_return_shared();
rust::Box<R> c_return_box();
std::unique_ptr<C> c_return_unique_ptr();
const size_t &c_return_ref(const Shared &shared);
size_t &c_return_mut(Shared &shared);
rust::Str c_return_str(const Shared &shared);
rust::Slice<uint8_t> c_return_sliceu8(const Shared &shared);
rust::String c_return_rust_string();
@ -44,8 +46,10 @@ std::unique_ptr<std::vector<double>> c_return_unique_ptr_vector_f64();
std::unique_ptr<std::vector<Shared>> c_return_unique_ptr_vector_shared();
std::unique_ptr<std::vector<C>> c_return_unique_ptr_vector_opaque();
const std::vector<uint8_t> &c_return_ref_vector(const C &c);
std::vector<uint8_t> &c_return_mut_vector(C &c);
rust::Vec<uint8_t> c_return_rust_vec();
const rust::Vec<uint8_t> &c_return_ref_rust_vec(const C &c);
rust::Vec<uint8_t> &c_return_mut_rust_vec(C &c);
size_t c_return_identity(size_t n);
size_t c_return_sum(size_t n1, size_t n2);
Enum c_return_enum(uint16_t n);