diff --git a/tests/ffi/lib.rs b/tests/ffi/lib.rs index 7504704b..df5c2794 100644 --- a/tests/ffi/lib.rs +++ b/tests/ffi/lib.rs @@ -120,6 +120,7 @@ pub mod ffi { fn c_take_str(s: &str); fn c_take_slice_char(s: &[c_char]); fn c_take_slice_shared(s: &[Shared]); + fn c_take_slice_shared_sort(s: &mut [Shared]); fn c_take_rust_string(s: String); fn c_take_unique_ptr_string(s: UniquePtr); fn c_take_unique_ptr_vector_u8(v: UniquePtr>); diff --git a/tests/ffi/tests.cc b/tests/ffi/tests.cc index 05ff4b87..2bb7d71f 100644 --- a/tests/ffi/tests.cc +++ b/tests/ffi/tests.cc @@ -280,6 +280,15 @@ void c_take_slice_shared(rust::Slice s) { } } +void c_take_slice_shared_sort(rust::Slice s) { + // Exercise requirements of RandomAccessIterator. + // https://en.cppreference.com/w/cpp/named_req/RandomAccessIterator + std::sort(s.begin(), s.end()); + if (s[0].z == 0 && s[1].z == 2 && s[2].z == 4 && s[3].z == 7) { + cxx_test_suite_set_correct(); + } +} + void c_take_rust_string(rust::String s) { if (std::string(s) == "2020") { cxx_test_suite_set_correct(); diff --git a/tests/ffi/tests.h b/tests/ffi/tests.h index 51ab51df..50a80054 100644 --- a/tests/ffi/tests.h +++ b/tests/ffi/tests.h @@ -123,6 +123,7 @@ void c_take_ref_ns_c(const ::H::H &h); void c_take_str(rust::Str s); void c_take_slice_char(rust::Slice s); void c_take_slice_shared(rust::Slice s); +void c_take_slice_shared_sort(rust::Slice s); void c_take_rust_string(rust::String s); void c_take_unique_ptr_string(std::unique_ptr s); void c_take_unique_ptr_vector_u8(std::unique_ptr> v); diff --git a/tests/test.rs b/tests/test.rs index 60bf1bdb..0620a9ca 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -125,6 +125,17 @@ fn test_c_take() { ffi::Shared { z: 2020 }, ffi::Shared { z: 2021 }, ])); + let shared_sort_slice = &mut [ + ffi::Shared { z: 2 }, + ffi::Shared { z: 0 }, + ffi::Shared { z: 7 }, + ffi::Shared { z: 4 }, + ]; + check!(ffi::c_take_slice_shared_sort(shared_sort_slice)); + assert_eq!(shared_sort_slice[0].z, 0); + assert_eq!(shared_sort_slice[1].z, 2); + assert_eq!(shared_sort_slice[2].z, 4); + assert_eq!(shared_sort_slice[3].z, 7); check!(ffi::c_take_rust_string("2020".to_owned())); check!(ffi::c_take_unique_ptr_string( ffi::c_return_unique_ptr_string()