std::unique_ptr std::auto_ptr tidyup

Add docs on additional support
Additional testing for invalid usage for parameter inputs
This commit is contained in:
William S Fulton 2022-07-19 08:57:47 +01:00
commit 1b63af0f2c
10 changed files with 107 additions and 22 deletions

View file

@ -41,7 +41,9 @@ public class cpp11_std_unique_ptr_runme {
bool exception_thrown = false;
try {
cpp11_std_unique_ptr.takeKlassUniquePtr(kin);
} catch (ApplicationException) {
} catch (ApplicationException e) {
if (!e.Message.Contains("Cannot release ownership as memory is not owned"))
throw new ApplicationException("incorrect exception message");
exception_thrown = true;
}
if (!exception_thrown)
@ -52,10 +54,12 @@ public class cpp11_std_unique_ptr_runme {
using (Klass kin = new Klass("KlassInput")) {
bool exception_thrown = false;
try {
Klass notowned = cpp11_std_unique_ptr.get_not_owned_ptr(kin);
cpp11_std_unique_ptr.takeKlassUniquePtr(notowned);
} catch (ApplicationException) {
exception_thrown = true;
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"))
throw new ApplicationException("incorrect exception message");
exception_thrown = true;
}
if (!exception_thrown)
throw new ApplicationException("Should have thrown 'Cannot release ownership as memory is not owned' error");

View file

@ -41,7 +41,9 @@ public class li_std_auto_ptr_runme {
bool exception_thrown = false;
try {
li_std_auto_ptr.takeKlassAutoPtr(kin);
} catch (ApplicationException) {
} catch (ApplicationException e) {
if (!e.Message.Contains("Cannot release ownership as memory is not owned"))
throw new ApplicationException("incorrect exception message");
exception_thrown = true;
}
if (!exception_thrown)
@ -52,10 +54,12 @@ public class li_std_auto_ptr_runme {
using (Klass kin = new Klass("KlassInput")) {
bool exception_thrown = false;
try {
Klass notowned = li_std_auto_ptr.get_not_owned_ptr(kin);
li_std_auto_ptr.takeKlassAutoPtr(notowned);
} catch (ApplicationException) {
exception_thrown = true;
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"))
throw new ApplicationException("incorrect exception message");
exception_thrown = true;
}
if (!exception_thrown)
throw new ApplicationException("Should have thrown 'Cannot release ownership as memory is not owned' error");

View file

@ -55,6 +55,8 @@ public class cpp11_std_unique_ptr_runme {
try {
cpp11_std_unique_ptr.takeKlassUniquePtr(kin);
} catch (RuntimeException e) {
if (!e.getMessage().contains("Cannot release ownership as memory is not owned"))
throw new RuntimeException("incorrect exception message");
exception_thrown = true;
}
if (!exception_thrown)
@ -70,6 +72,8 @@ public class cpp11_std_unique_ptr_runme {
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"))
throw new RuntimeException("incorrect exception message");
exception_thrown = true;
}
if (!exception_thrown)

View file

@ -55,6 +55,8 @@ public class li_std_auto_ptr_runme {
try {
li_std_auto_ptr.takeKlassAutoPtr(kin);
} catch (RuntimeException e) {
if (!e.getMessage().contains("Cannot release ownership as memory is not owned"))
throw new RuntimeException("incorrect exception message");
exception_thrown = true;
}
if (!exception_thrown)
@ -70,6 +72,8 @@ public class li_std_auto_ptr_runme {
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"))
throw new RuntimeException("incorrect exception message");
exception_thrown = true;
}
if (!exception_thrown)

View file

@ -33,6 +33,8 @@ exception_thrown = False
try:
s = takeKlassUniquePtr(kin)
except RuntimeError as e:
if "cannot release ownership as memory is not owned" not in str(e):
raise RuntimeError("incorrect exception message");
exception_thrown = True
if not exception_thrown:
raise RuntimeError("double usage of takeKlassUniquePtr should have been an error")

View file

@ -33,6 +33,8 @@ exception_thrown = False
try:
s = takeKlassAutoPtr(kin)
except RuntimeError as e:
if "cannot release ownership as memory is not owned" not in str(e):
raise RuntimeError("incorrect exception message");
exception_thrown = True
if not exception_thrown:
raise RuntimeError("double usage of takeKlassAutoPtr should have been an error")

View file

@ -73,7 +73,10 @@ exception_thrown = false
begin
notowned = Cpp11_std_unique_ptr::get_not_owned_ptr(kin)
Cpp11_std_unique_ptr::takeKlassUniquePtr(notowned)
rescue RuntimeError
rescue RuntimeError => e
if (!e.to_s.include? "cannot release ownership as memory is not owned")
raise RuntimeError, "incorrect exception message"
end
exception_thrown = true
end
if (!exception_thrown)

View file

@ -74,6 +74,9 @@ 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")
raise RuntimeError, "incorrect exception message"
end
exception_thrown = true
end
if (!exception_thrown)