auto_ptr and unique_ptr test tweaks
This commit is contained in:
parent
fe17296eb4
commit
a741c7dbcf
14 changed files with 30 additions and 16 deletions
|
|
@ -53,8 +53,8 @@ public class cpp11_std_unique_ptr_runme {
|
||||||
|
|
||||||
using (Klass kin = new Klass("KlassInput")) {
|
using (Klass kin = new Klass("KlassInput")) {
|
||||||
bool exception_thrown = false;
|
bool exception_thrown = false;
|
||||||
|
Klass notowned = cpp11_std_unique_ptr.get_not_owned_ptr(kin);
|
||||||
try {
|
try {
|
||||||
Klass notowned = cpp11_std_unique_ptr.get_not_owned_ptr(kin);
|
|
||||||
cpp11_std_unique_ptr.takeKlassUniquePtr(notowned);
|
cpp11_std_unique_ptr.takeKlassUniquePtr(notowned);
|
||||||
} catch (ApplicationException e) {
|
} catch (ApplicationException e) {
|
||||||
if (!e.Message.Contains("Cannot release ownership as memory is not owned"))
|
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)
|
if (!exception_thrown)
|
||||||
throw new ApplicationException("Should have thrown 'Cannot release ownership as memory is not owned' error");
|
throw new ApplicationException("Should have thrown 'Cannot release ownership as memory is not owned' error");
|
||||||
|
checkCount(1);
|
||||||
}
|
}
|
||||||
checkCount(0);
|
checkCount(0);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,8 +53,8 @@ public class li_std_auto_ptr_runme {
|
||||||
|
|
||||||
using (Klass kin = new Klass("KlassInput")) {
|
using (Klass kin = new Klass("KlassInput")) {
|
||||||
bool exception_thrown = false;
|
bool exception_thrown = false;
|
||||||
|
Klass notowned = li_std_auto_ptr.get_not_owned_ptr(kin);
|
||||||
try {
|
try {
|
||||||
Klass notowned = li_std_auto_ptr.get_not_owned_ptr(kin);
|
|
||||||
li_std_auto_ptr.takeKlassAutoPtr(notowned);
|
li_std_auto_ptr.takeKlassAutoPtr(notowned);
|
||||||
} catch (ApplicationException e) {
|
} catch (ApplicationException e) {
|
||||||
if (!e.Message.Contains("Cannot release ownership as memory is not owned"))
|
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)
|
if (!exception_thrown)
|
||||||
throw new ApplicationException("Should have thrown 'Cannot release ownership as memory is not owned' error");
|
throw new ApplicationException("Should have thrown 'Cannot release ownership as memory is not owned' error");
|
||||||
|
checkCount(1);
|
||||||
}
|
}
|
||||||
checkCount(0);
|
checkCount(0);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -68,8 +68,8 @@ public class cpp11_std_unique_ptr_runme {
|
||||||
{
|
{
|
||||||
Klass kin = new Klass("KlassInput");
|
Klass kin = new Klass("KlassInput");
|
||||||
boolean exception_thrown = false;
|
boolean exception_thrown = false;
|
||||||
|
Klass notowned = cpp11_std_unique_ptr.get_not_owned_ptr(kin);
|
||||||
try {
|
try {
|
||||||
Klass notowned = cpp11_std_unique_ptr.get_not_owned_ptr(kin);
|
|
||||||
cpp11_std_unique_ptr.takeKlassUniquePtr(notowned);
|
cpp11_std_unique_ptr.takeKlassUniquePtr(notowned);
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
if (!e.getMessage().contains("Cannot release ownership as memory is not owned"))
|
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)
|
if (!exception_thrown)
|
||||||
throw new RuntimeException("Should have thrown 'Cannot release ownership as memory is not owned' error");
|
throw new RuntimeException("Should have thrown 'Cannot release ownership as memory is not owned' error");
|
||||||
|
checkCount(1);
|
||||||
kin.delete();
|
kin.delete();
|
||||||
checkCount(0);
|
checkCount(0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -68,8 +68,8 @@ public class li_std_auto_ptr_runme {
|
||||||
{
|
{
|
||||||
Klass kin = new Klass("KlassInput");
|
Klass kin = new Klass("KlassInput");
|
||||||
boolean exception_thrown = false;
|
boolean exception_thrown = false;
|
||||||
|
Klass notowned = li_std_auto_ptr.get_not_owned_ptr(kin);
|
||||||
try {
|
try {
|
||||||
Klass notowned = li_std_auto_ptr.get_not_owned_ptr(kin);
|
|
||||||
li_std_auto_ptr.takeKlassAutoPtr(notowned);
|
li_std_auto_ptr.takeKlassAutoPtr(notowned);
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
if (!e.getMessage().contains("Cannot release ownership as memory is not owned"))
|
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)
|
if (!exception_thrown)
|
||||||
throw new RuntimeException("Should have thrown 'Cannot release ownership as memory is not owned' error");
|
throw new RuntimeException("Should have thrown 'Cannot release ownership as memory is not owned' error");
|
||||||
|
checkCount(1);
|
||||||
kin.delete();
|
kin.delete();
|
||||||
checkCount(0);
|
checkCount(0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -54,8 +54,8 @@ checkCount(0);
|
||||||
|
|
||||||
kin = Klass("KlassInput");
|
kin = Klass("KlassInput");
|
||||||
exception_thrown = false;
|
exception_thrown = false;
|
||||||
|
notowned = get_not_owned_ptr(kin);
|
||||||
try
|
try
|
||||||
notowned = get_not_owned_ptr(kin);
|
|
||||||
takeKlassUniquePtr(notowned);
|
takeKlassUniquePtr(notowned);
|
||||||
catch e
|
catch e
|
||||||
if (isempty(strfind(e.message, "cannot release ownership as memory is not owned")))
|
if (isempty(strfind(e.message, "cannot release ownership as memory is not owned")))
|
||||||
|
|
@ -66,6 +66,7 @@ end_try_catch
|
||||||
if (!exception_thrown)
|
if (!exception_thrown)
|
||||||
error("Should have thrown 'Cannot release ownership as memory is not owned' error");
|
error("Should have thrown 'Cannot release ownership as memory is not owned' error");
|
||||||
endif
|
endif
|
||||||
|
checkCount(1);
|
||||||
clear kin;
|
clear kin;
|
||||||
checkCount(0);
|
checkCount(0);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,8 +53,8 @@ checkCount(0);
|
||||||
|
|
||||||
kin = Klass("KlassInput");
|
kin = Klass("KlassInput");
|
||||||
exception_thrown = false;
|
exception_thrown = false;
|
||||||
|
notowned = get_not_owned_ptr(kin);
|
||||||
try
|
try
|
||||||
notowned = get_not_owned_ptr(kin);
|
|
||||||
takeKlassAutoPtr(notowned);
|
takeKlassAutoPtr(notowned);
|
||||||
catch e
|
catch e
|
||||||
if (isempty(strfind(e.message, "cannot release ownership as memory is not owned")))
|
if (isempty(strfind(e.message, "cannot release ownership as memory is not owned")))
|
||||||
|
|
@ -65,6 +65,7 @@ end_try_catch
|
||||||
if (!exception_thrown)
|
if (!exception_thrown)
|
||||||
error("Should have thrown 'Cannot release ownership as memory is not owned' error");
|
error("Should have thrown 'Cannot release ownership as memory is not owned' error");
|
||||||
endif
|
endif
|
||||||
|
checkCount(1);
|
||||||
clear kin;
|
clear kin;
|
||||||
checkCount(0);
|
checkCount(0);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use Test::More tests => 24;
|
use Test::More tests => 25;
|
||||||
BEGIN { use_ok('cpp11_std_unique_ptr') }
|
BEGIN { use_ok('cpp11_std_unique_ptr') }
|
||||||
require_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 $kin = new cpp11_std_unique_ptr::Klass("KlassInput");
|
||||||
|
my $notowned = cpp11_std_unique_ptr::get_not_owned_ptr($kin);
|
||||||
eval {
|
eval {
|
||||||
my $notowned = cpp11_std_unique_ptr::get_not_owned_ptr($kin);
|
|
||||||
cpp11_std_unique_ptr::takeKlassUniquePtr($notowned);
|
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");
|
like($@, qr/\bcannot release ownership as memory is not owned\b/, "double usage of takeKlassUniquePtr should be an error");
|
||||||
|
checkCount(1);
|
||||||
undef $kin;
|
undef $kin;
|
||||||
checkCount(0);
|
checkCount(0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use Test::More tests => 24;
|
use Test::More tests => 25;
|
||||||
BEGIN { use_ok('li_std_auto_ptr') }
|
BEGIN { use_ok('li_std_auto_ptr') }
|
||||||
require_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 $kin = new li_std_auto_ptr::Klass("KlassInput");
|
||||||
|
my $notowned = li_std_auto_ptr::get_not_owned_ptr($kin);
|
||||||
eval {
|
eval {
|
||||||
my $notowned = li_std_auto_ptr::get_not_owned_ptr($kin);
|
|
||||||
li_std_auto_ptr::takeKlassAutoPtr($notowned);
|
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");
|
like($@, qr/\bcannot release ownership as memory is not owned\b/, "double usage of takeKlassAutoPtr should be an error");
|
||||||
|
checkCount(1);
|
||||||
undef $kin;
|
undef $kin;
|
||||||
checkCount(0);
|
checkCount(0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,13 +43,14 @@ checkCount(0)
|
||||||
|
|
||||||
kin = Klass("KlassInput")
|
kin = Klass("KlassInput")
|
||||||
exception_thrown = False
|
exception_thrown = False
|
||||||
|
notowned = get_not_owned_ptr(kin)
|
||||||
try:
|
try:
|
||||||
notowned = get_not_owned_ptr(kin)
|
|
||||||
takeKlassUniquePtr(notowned)
|
takeKlassUniquePtr(notowned)
|
||||||
except RuntimeError as e:
|
except RuntimeError as e:
|
||||||
exception_thrown = True
|
exception_thrown = True
|
||||||
if not exception_thrown:
|
if not exception_thrown:
|
||||||
raise RuntimeError("Should have thrown 'Cannot release ownership as memory is not owned' error")
|
raise RuntimeError("Should have thrown 'Cannot release ownership as memory is not owned' error")
|
||||||
|
checkCount(1)
|
||||||
del kin
|
del kin
|
||||||
checkCount(0)
|
checkCount(0)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,13 +43,14 @@ checkCount(0)
|
||||||
|
|
||||||
kin = Klass("KlassInput")
|
kin = Klass("KlassInput")
|
||||||
exception_thrown = False
|
exception_thrown = False
|
||||||
|
notowned = get_not_owned_ptr(kin)
|
||||||
try:
|
try:
|
||||||
notowned = get_not_owned_ptr(kin)
|
|
||||||
takeKlassAutoPtr(notowned)
|
takeKlassAutoPtr(notowned)
|
||||||
except RuntimeError as e:
|
except RuntimeError as e:
|
||||||
exception_thrown = True
|
exception_thrown = True
|
||||||
if not exception_thrown:
|
if not exception_thrown:
|
||||||
raise RuntimeError("Should have thrown 'Cannot release ownership as memory is not owned' error")
|
raise RuntimeError("Should have thrown 'Cannot release ownership as memory is not owned' error")
|
||||||
|
checkCount(1)
|
||||||
del kin
|
del kin
|
||||||
checkCount(0)
|
checkCount(0)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -70,8 +70,8 @@ checkCount(0)
|
||||||
|
|
||||||
kin = Cpp11_std_unique_ptr::Klass.new("KlassInput")
|
kin = Cpp11_std_unique_ptr::Klass.new("KlassInput")
|
||||||
exception_thrown = false
|
exception_thrown = false
|
||||||
|
notowned = Cpp11_std_unique_ptr::get_not_owned_ptr(kin)
|
||||||
begin
|
begin
|
||||||
notowned = Cpp11_std_unique_ptr::get_not_owned_ptr(kin)
|
|
||||||
Cpp11_std_unique_ptr::takeKlassUniquePtr(notowned)
|
Cpp11_std_unique_ptr::takeKlassUniquePtr(notowned)
|
||||||
rescue RuntimeError => e
|
rescue RuntimeError => e
|
||||||
if (!e.to_s.include? "cannot release ownership as memory is not owned")
|
if (!e.to_s.include? "cannot release ownership as memory is not owned")
|
||||||
|
|
@ -82,6 +82,7 @@ end
|
||||||
if (!exception_thrown)
|
if (!exception_thrown)
|
||||||
raise RuntimeError, "Should have thrown 'Cannot release ownership as memory is not owned' error"
|
raise RuntimeError, "Should have thrown 'Cannot release ownership as memory is not owned' error"
|
||||||
end
|
end
|
||||||
|
checkCount(1)
|
||||||
Cpp11_std_unique_ptr.takeKlassUniquePtr(kin) # Ensure object is deleted (can't rely on GC)
|
Cpp11_std_unique_ptr.takeKlassUniquePtr(kin) # Ensure object is deleted (can't rely on GC)
|
||||||
checkCount(0)
|
checkCount(0)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -70,8 +70,8 @@ checkCount(0)
|
||||||
|
|
||||||
kin = Li_std_auto_ptr::Klass.new("KlassInput")
|
kin = Li_std_auto_ptr::Klass.new("KlassInput")
|
||||||
exception_thrown = false
|
exception_thrown = false
|
||||||
|
notowned = Li_std_auto_ptr::get_not_owned_ptr(kin)
|
||||||
begin
|
begin
|
||||||
notowned = Li_std_auto_ptr::get_not_owned_ptr(kin)
|
|
||||||
Li_std_auto_ptr::takeKlassAutoPtr(notowned)
|
Li_std_auto_ptr::takeKlassAutoPtr(notowned)
|
||||||
rescue RuntimeError
|
rescue RuntimeError
|
||||||
if (!e.to_s.include? "cannot release ownership as memory is not owned")
|
if (!e.to_s.include? "cannot release ownership as memory is not owned")
|
||||||
|
|
@ -82,6 +82,7 @@ end
|
||||||
if (!exception_thrown)
|
if (!exception_thrown)
|
||||||
raise RuntimeError, "Should have thrown 'Cannot release ownership as memory is not owned' error"
|
raise RuntimeError, "Should have thrown 'Cannot release ownership as memory is not owned' error"
|
||||||
end
|
end
|
||||||
|
checkCount(1)
|
||||||
Li_std_auto_ptr.takeKlassAutoPtr(kin) # Ensure object is deleted (can't rely on GC)
|
Li_std_auto_ptr.takeKlassAutoPtr(kin) # Ensure object is deleted (can't rely on GC)
|
||||||
checkCount(0)
|
checkCount(0)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -90,8 +90,8 @@ checkCount 0
|
||||||
|
|
||||||
Klass kin "KlassInput"
|
Klass kin "KlassInput"
|
||||||
set exception_thrown 0
|
set exception_thrown 0
|
||||||
|
set notowned [get_not_owned_ptr kin]
|
||||||
if [ catch {
|
if [ catch {
|
||||||
set notowned [get_not_owned_ptr kin]
|
|
||||||
takeKlassUniquePtr notowned
|
takeKlassUniquePtr notowned
|
||||||
} ] {
|
} ] {
|
||||||
set exception_thrown 1
|
set exception_thrown 1
|
||||||
|
|
@ -99,6 +99,7 @@ if [ catch {
|
||||||
if {!$exception_thrown} {
|
if {!$exception_thrown} {
|
||||||
error "Should have thrown 'Cannot release ownership as memory is not owned' error"
|
error "Should have thrown 'Cannot release ownership as memory is not owned' error"
|
||||||
}
|
}
|
||||||
|
checkCount 1
|
||||||
kin -delete
|
kin -delete
|
||||||
checkCount 0
|
checkCount 0
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -61,8 +61,8 @@ checkCount 0
|
||||||
|
|
||||||
Klass kin "KlassInput"
|
Klass kin "KlassInput"
|
||||||
set exception_thrown 0
|
set exception_thrown 0
|
||||||
|
set notowned [get_not_owned_ptr kin]
|
||||||
if [ catch {
|
if [ catch {
|
||||||
set notowned [get_not_owned_ptr kin]
|
|
||||||
takeKlassAutoPtr notowned
|
takeKlassAutoPtr notowned
|
||||||
} ] {
|
} ] {
|
||||||
set exception_thrown 1
|
set exception_thrown 1
|
||||||
|
|
@ -70,6 +70,7 @@ if [ catch {
|
||||||
if {!$exception_thrown} {
|
if {!$exception_thrown} {
|
||||||
error "Should have thrown 'Cannot release ownership as memory is not owned' error"
|
error "Should have thrown 'Cannot release ownership as memory is not owned' error"
|
||||||
}
|
}
|
||||||
|
checkCount 1
|
||||||
kin -delete
|
kin -delete
|
||||||
checkCount 0
|
checkCount 0
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue