add a test for shared_ptr with director
This commit is contained in:
parent
79620b10a9
commit
1c968b3695
2 changed files with 47 additions and 0 deletions
23
Examples/test-suite/cpp11_shared_ptr_director.i
Normal file
23
Examples/test-suite/cpp11_shared_ptr_director.i
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
%module(directors="1") "cpp11_shared_ptr_director"
|
||||
|
||||
%{
|
||||
#include <memory>
|
||||
%}
|
||||
|
||||
%include "std_shared_ptr.i";
|
||||
%shared_ptr(Created);
|
||||
%feature("director") Creator;
|
||||
|
||||
%inline %{
|
||||
struct Created {};
|
||||
|
||||
struct Creator {
|
||||
Creator() {};
|
||||
virtual std::shared_ptr<Created> create() = 0;
|
||||
virtual ~Creator() {}
|
||||
};
|
||||
|
||||
void crash(Creator* creator) {
|
||||
std::shared_ptr<Created> ptr = creator->create();
|
||||
}
|
||||
%}
|
||||
24
Examples/test-suite/ruby/cpp11_shared_ptr_director_runme.rb
Normal file
24
Examples/test-suite/ruby/cpp11_shared_ptr_director_runme.rb
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
require 'cpp11_shared_ptr_director'
|
||||
|
||||
include Cpp11_shared_ptr_director
|
||||
|
||||
class Derived < Creator
|
||||
|
||||
def initialize(flag)
|
||||
@return_none = flag
|
||||
super()
|
||||
end
|
||||
|
||||
def create
|
||||
if @return_none
|
||||
nil
|
||||
else
|
||||
Created.new
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
crash(Derived.new(false))
|
||||
crash(Derived.new(true))
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue