Add support for std::auto_ptr inputs
Ported from std::unique, behaviour is identical with regard to memory ownership/handling
This commit is contained in:
parent
5dd5e80a84
commit
db5e37a1d7
11 changed files with 477 additions and 47 deletions
|
|
@ -1,9 +1,67 @@
|
|||
use strict;
|
||||
use warnings;
|
||||
use Test::More tests => 6;
|
||||
use Test::More tests => 24;
|
||||
BEGIN { use_ok('li_std_auto_ptr') }
|
||||
require_ok('li_std_auto_ptr');
|
||||
|
||||
# adapted from ../java/li_std_auto_ptr_runme.java
|
||||
|
||||
sub checkCount {
|
||||
my($expected_count) = @_;
|
||||
my $actual_count = li_std_auto_ptr::Klass::getTotal_count();
|
||||
is($actual_count, $expected_count, "Counts incorrect, expected: $expected_count actual: $actual_count");
|
||||
}
|
||||
|
||||
# auto_ptr as input
|
||||
{
|
||||
my $kin = new li_std_auto_ptr::Klass("KlassInput");
|
||||
checkCount(1);
|
||||
my $s = li_std_auto_ptr::takeKlassAutoPtr($kin);
|
||||
checkCount(0);
|
||||
is($s, "KlassInput", "Incorrect string: $s");
|
||||
is(li_std_auto_ptr::is_nullptr($kin), 1, "is_nullptr check");
|
||||
undef $kin; # Should not fail, even though already deleted
|
||||
checkCount(0);
|
||||
}
|
||||
|
||||
{
|
||||
my $kin = new li_std_auto_ptr::Klass("KlassInput");
|
||||
checkCount(1);
|
||||
my $s = li_std_auto_ptr::takeKlassAutoPtr($kin);
|
||||
checkCount(0);
|
||||
is($s, "KlassInput", "Incorrect string: $s");
|
||||
is(li_std_auto_ptr::is_nullptr($kin), 1, "is_nullptr check");
|
||||
eval {
|
||||
li_std_auto_ptr::takeKlassAutoPtr($kin);
|
||||
};
|
||||
like($@, qr/\bcannot release ownership as memory is not owned\b/, "double usage of takeKlassAutoPtr should be an error");
|
||||
undef $kin; # Should not fail, even though already deleted
|
||||
checkCount(0);
|
||||
}
|
||||
|
||||
{
|
||||
my $kin = new li_std_auto_ptr::Klass("KlassInput");
|
||||
eval {
|
||||
my $notowned = li_std_auto_ptr::get_not_owned_ptr($kin);
|
||||
li_std_auto_ptr::takeKlassAutoPtr($notowned);
|
||||
};
|
||||
like($@, qr/\bcannot release ownership as memory is not owned\b/, "double usage of takeKlassAutoPtr should be an error");
|
||||
undef $kin;
|
||||
checkCount(0);
|
||||
}
|
||||
|
||||
{
|
||||
my $kini = new li_std_auto_ptr::KlassInheritance("KlassInheritanceInput");
|
||||
checkCount(1);
|
||||
my $s = li_std_auto_ptr::takeKlassAutoPtr($kini);
|
||||
checkCount(0);
|
||||
is($s, "KlassInheritanceInput", "Incorrect string: $s");
|
||||
is(li_std_auto_ptr::is_nullptr($kini), 1, "is_nullptr failed");
|
||||
undef $kini; # Should not fail, even though already deleted
|
||||
checkCount(0);
|
||||
}
|
||||
|
||||
# auto_ptr as output
|
||||
my $k1 = li_std_auto_ptr::makeKlassAutoPtr("first");
|
||||
my $k2 = li_std_auto_ptr::makeKlassAutoPtr("second");
|
||||
is(li_std_auto_ptr::Klass::getTotal_count, 2, "have 2 pointers");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue