auto_ptr and unique_ptr test tweaks

This commit is contained in:
William S Fulton 2022-08-03 20:32:58 +01:00
commit a741c7dbcf
14 changed files with 30 additions and 16 deletions

View file

@ -53,8 +53,8 @@ public class cpp11_std_unique_ptr_runme {
using (Klass kin = new Klass("KlassInput")) {
bool exception_thrown = false;
Klass notowned = cpp11_std_unique_ptr.get_not_owned_ptr(kin);
try {
Klass notowned = cpp11_std_unique_ptr.get_not_owned_ptr(kin);
cpp11_std_unique_ptr.takeKlassUniquePtr(notowned);
} catch (ApplicationException e) {
if (!e.Message.Contains("Cannot release ownership as memory is not owned"))
@ -63,6 +63,7 @@ public class cpp11_std_unique_ptr_runme {
}
if (!exception_thrown)
throw new ApplicationException("Should have thrown 'Cannot release ownership as memory is not owned' error");
checkCount(1);
}
checkCount(0);

View file

@ -53,8 +53,8 @@ public class li_std_auto_ptr_runme {
using (Klass kin = new Klass("KlassInput")) {
bool exception_thrown = false;
Klass notowned = li_std_auto_ptr.get_not_owned_ptr(kin);
try {
Klass notowned = li_std_auto_ptr.get_not_owned_ptr(kin);
li_std_auto_ptr.takeKlassAutoPtr(notowned);
} catch (ApplicationException e) {
if (!e.Message.Contains("Cannot release ownership as memory is not owned"))
@ -63,6 +63,7 @@ public class li_std_auto_ptr_runme {
}
if (!exception_thrown)
throw new ApplicationException("Should have thrown 'Cannot release ownership as memory is not owned' error");
checkCount(1);
}
checkCount(0);

View file

@ -68,8 +68,8 @@ public class cpp11_std_unique_ptr_runme {
{
Klass kin = new Klass("KlassInput");
boolean exception_thrown = false;
Klass notowned = cpp11_std_unique_ptr.get_not_owned_ptr(kin);
try {
Klass notowned = cpp11_std_unique_ptr.get_not_owned_ptr(kin);
cpp11_std_unique_ptr.takeKlassUniquePtr(notowned);
} catch (RuntimeException e) {
if (!e.getMessage().contains("Cannot release ownership as memory is not owned"))
@ -78,6 +78,7 @@ public class cpp11_std_unique_ptr_runme {
}
if (!exception_thrown)
throw new RuntimeException("Should have thrown 'Cannot release ownership as memory is not owned' error");
checkCount(1);
kin.delete();
checkCount(0);
}

View file

@ -68,8 +68,8 @@ public class li_std_auto_ptr_runme {
{
Klass kin = new Klass("KlassInput");
boolean exception_thrown = false;
Klass notowned = li_std_auto_ptr.get_not_owned_ptr(kin);
try {
Klass notowned = li_std_auto_ptr.get_not_owned_ptr(kin);
li_std_auto_ptr.takeKlassAutoPtr(notowned);
} catch (RuntimeException e) {
if (!e.getMessage().contains("Cannot release ownership as memory is not owned"))
@ -78,6 +78,7 @@ public class li_std_auto_ptr_runme {
}
if (!exception_thrown)
throw new RuntimeException("Should have thrown 'Cannot release ownership as memory is not owned' error");
checkCount(1);
kin.delete();
checkCount(0);
}

View file

@ -54,8 +54,8 @@ checkCount(0);
kin = Klass("KlassInput");
exception_thrown = false;
notowned = get_not_owned_ptr(kin);
try
notowned = get_not_owned_ptr(kin);
takeKlassUniquePtr(notowned);
catch e
if (isempty(strfind(e.message, "cannot release ownership as memory is not owned")))
@ -66,6 +66,7 @@ end_try_catch
if (!exception_thrown)
error("Should have thrown 'Cannot release ownership as memory is not owned' error");
endif
checkCount(1);
clear kin;
checkCount(0);

View file

@ -53,8 +53,8 @@ checkCount(0);
kin = Klass("KlassInput");
exception_thrown = false;
notowned = get_not_owned_ptr(kin);
try
notowned = get_not_owned_ptr(kin);
takeKlassAutoPtr(notowned);
catch e
if (isempty(strfind(e.message, "cannot release ownership as memory is not owned")))
@ -65,6 +65,7 @@ end_try_catch
if (!exception_thrown)
error("Should have thrown 'Cannot release ownership as memory is not owned' error");
endif
checkCount(1);
clear kin;
checkCount(0);

View file

@ -1,6 +1,6 @@
use strict;
use warnings;
use Test::More tests => 24;
use Test::More tests => 25;
BEGIN { use_ok('cpp11_std_unique_ptr') }
require_ok('cpp11_std_unique_ptr');
@ -41,11 +41,12 @@ sub checkCount {
{
my $kin = new cpp11_std_unique_ptr::Klass("KlassInput");
my $notowned = cpp11_std_unique_ptr::get_not_owned_ptr($kin);
eval {
my $notowned = cpp11_std_unique_ptr::get_not_owned_ptr($kin);
cpp11_std_unique_ptr::takeKlassUniquePtr($notowned);
};
like($@, qr/\bcannot release ownership as memory is not owned\b/, "double usage of takeKlassUniquePtr should be an error");
checkCount(1);
undef $kin;
checkCount(0);
}

View file

@ -1,6 +1,6 @@
use strict;
use warnings;
use Test::More tests => 24;
use Test::More tests => 25;
BEGIN { use_ok('li_std_auto_ptr') }
require_ok('li_std_auto_ptr');
@ -41,11 +41,12 @@ sub checkCount {
{
my $kin = new li_std_auto_ptr::Klass("KlassInput");
my $notowned = li_std_auto_ptr::get_not_owned_ptr($kin);
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");
checkCount(1);
undef $kin;
checkCount(0);
}

View file

@ -43,13 +43,14 @@ checkCount(0)
kin = Klass("KlassInput")
exception_thrown = False
notowned = get_not_owned_ptr(kin)
try:
notowned = get_not_owned_ptr(kin)
takeKlassUniquePtr(notowned)
except RuntimeError as e:
exception_thrown = True
if not exception_thrown:
raise RuntimeError("Should have thrown 'Cannot release ownership as memory is not owned' error")
checkCount(1)
del kin
checkCount(0)

View file

@ -43,13 +43,14 @@ checkCount(0)
kin = Klass("KlassInput")
exception_thrown = False
notowned = get_not_owned_ptr(kin)
try:
notowned = get_not_owned_ptr(kin)
takeKlassAutoPtr(notowned)
except RuntimeError as e:
exception_thrown = True
if not exception_thrown:
raise RuntimeError("Should have thrown 'Cannot release ownership as memory is not owned' error")
checkCount(1)
del kin
checkCount(0)

View file

@ -70,8 +70,8 @@ checkCount(0)
kin = Cpp11_std_unique_ptr::Klass.new("KlassInput")
exception_thrown = false
notowned = Cpp11_std_unique_ptr::get_not_owned_ptr(kin)
begin
notowned = Cpp11_std_unique_ptr::get_not_owned_ptr(kin)
Cpp11_std_unique_ptr::takeKlassUniquePtr(notowned)
rescue RuntimeError => e
if (!e.to_s.include? "cannot release ownership as memory is not owned")
@ -82,6 +82,7 @@ end
if (!exception_thrown)
raise RuntimeError, "Should have thrown 'Cannot release ownership as memory is not owned' error"
end
checkCount(1)
Cpp11_std_unique_ptr.takeKlassUniquePtr(kin) # Ensure object is deleted (can't rely on GC)
checkCount(0)

View file

@ -70,8 +70,8 @@ checkCount(0)
kin = Li_std_auto_ptr::Klass.new("KlassInput")
exception_thrown = false
notowned = Li_std_auto_ptr::get_not_owned_ptr(kin)
begin
notowned = Li_std_auto_ptr::get_not_owned_ptr(kin)
Li_std_auto_ptr::takeKlassAutoPtr(notowned)
rescue RuntimeError
if (!e.to_s.include? "cannot release ownership as memory is not owned")
@ -82,6 +82,7 @@ end
if (!exception_thrown)
raise RuntimeError, "Should have thrown 'Cannot release ownership as memory is not owned' error"
end
checkCount(1)
Li_std_auto_ptr.takeKlassAutoPtr(kin) # Ensure object is deleted (can't rely on GC)
checkCount(0)

View file

@ -90,8 +90,8 @@ checkCount 0
Klass kin "KlassInput"
set exception_thrown 0
set notowned [get_not_owned_ptr kin]
if [ catch {
set notowned [get_not_owned_ptr kin]
takeKlassUniquePtr notowned
} ] {
set exception_thrown 1
@ -99,6 +99,7 @@ if [ catch {
if {!$exception_thrown} {
error "Should have thrown 'Cannot release ownership as memory is not owned' error"
}
checkCount 1
kin -delete
checkCount 0

View file

@ -61,8 +61,8 @@ checkCount 0
Klass kin "KlassInput"
set exception_thrown 0
set notowned [get_not_owned_ptr kin]
if [ catch {
set notowned [get_not_owned_ptr kin]
takeKlassAutoPtr notowned
} ] {
set exception_thrown 1
@ -70,6 +70,7 @@ if [ catch {
if {!$exception_thrown} {
error "Should have thrown 'Cannot release ownership as memory is not owned' error"
}
checkCount 1
kin -delete
checkCount 0