[ruby] add a test for null shared_ptr in containers.
This commit is contained in:
parent
661c3fc554
commit
0c3298073b
2 changed files with 63 additions and 0 deletions
48
Examples/test-suite/cpp11_shared_ptr_nullptr_in_containers.i
Normal file
48
Examples/test-suite/cpp11_shared_ptr_nullptr_in_containers.i
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
%module cpp11_shared_ptr_nullptr_in_containers
|
||||
|
||||
%{
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
%}
|
||||
|
||||
%include <std_shared_ptr.i>
|
||||
%include <std_vector.i>
|
||||
|
||||
%shared_ptr(C)
|
||||
|
||||
%inline %{
|
||||
|
||||
class C {
|
||||
public:
|
||||
C() : m(-1) {}
|
||||
C(int i) : m(i) {}
|
||||
int get_m() { return m; }
|
||||
int m;
|
||||
};
|
||||
|
||||
%}
|
||||
|
||||
%template() std::vector<std::shared_ptr<C> >;
|
||||
|
||||
%inline %{
|
||||
|
||||
std::vector<std::shared_ptr<C> > ret_vec_c_shared_ptr() {
|
||||
std::vector<std::shared_ptr<C> > ret(3);
|
||||
ret[0] = std::shared_ptr<C>(new C(0));
|
||||
ret[2] = std::shared_ptr<C>(new C(2));
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<C> > ret_arg_vec(const std::vector<std::shared_ptr<C> >& v) {
|
||||
return v;
|
||||
}
|
||||
|
||||
bool is_last_null(const std::vector<std::shared_ptr<C> >& v) {
|
||||
if( *v.end() ) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
%}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
require "cpp11_shared_ptr_nullptr_in_containers"
|
||||
|
||||
include Cpp11_shared_ptr_nullptr_in_containers
|
||||
|
||||
a = ret_vec_c_shared_ptr()
|
||||
raise unless a[0].get_m == 0
|
||||
raise unless a[1] == nil
|
||||
raise unless a[2].get_m == 2
|
||||
|
||||
a = ret_arg_vec([C.new(7), nil, C.new(9)])
|
||||
raise unless a[0].get_m == 7
|
||||
raise unless a[1] == nil
|
||||
raise unless a[2].get_m == 9
|
||||
|
||||
raise unless is_last_null([C.new(7), C.new(8), nil])
|
||||
Loading…
Add table
Add a link
Reference in a new issue