Java unique_ptr test ownership enhancement to test
Make sure the object is owned before releasing ownership and passing ownership to unique_ptr instance.
This commit is contained in:
parent
1bf15210ef
commit
8bd9eb3f16
2 changed files with 19 additions and 0 deletions
|
|
@ -63,6 +63,10 @@ bool is_nullptr(Klass *p) {
|
|||
return p == nullptr;
|
||||
}
|
||||
|
||||
Klass *get_not_owned_ptr(Klass *p) {
|
||||
return p;
|
||||
}
|
||||
|
||||
std::unique_ptr<Klass> makeKlassUniquePtr(const char* label) {
|
||||
return std::unique_ptr<Klass>(new Klass(label));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,6 +63,21 @@ public class cpp11_std_unique_ptr_runme {
|
|||
checkCount(0);
|
||||
}
|
||||
|
||||
{
|
||||
Klass kin = new Klass("KlassInput");
|
||||
boolean exception_thrown = false;
|
||||
try {
|
||||
Klass notowned = cpp11_std_unique_ptr.get_not_owned_ptr(kin);
|
||||
cpp11_std_unique_ptr.takeKlassUniquePtr(notowned);
|
||||
} catch (RuntimeException e) {
|
||||
exception_thrown = true;
|
||||
}
|
||||
if (!exception_thrown)
|
||||
throw new RuntimeException("Should have thrown 'Cannot release ownership as memory is not owned' error");
|
||||
kin.delete();
|
||||
checkCount(0);
|
||||
}
|
||||
|
||||
{
|
||||
KlassInheritance kini = new KlassInheritance("KlassInheritanceInput");
|
||||
checkCount(1);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue