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
|
|
@ -20,8 +20,78 @@ public class li_std_auto_ptr_runme {
|
|||
}
|
||||
}
|
||||
|
||||
private static void checkCount(int expected_count) {
|
||||
int actual_count = Klass.getTotal_count();
|
||||
if (actual_count != expected_count)
|
||||
throw new RuntimeException("Counts incorrect, expected:" + expected_count + " actual:" + actual_count);
|
||||
}
|
||||
|
||||
public static void main(String argv[]) throws Throwable
|
||||
{
|
||||
// auto_ptr as input
|
||||
{
|
||||
Klass kin = new Klass("KlassInput");
|
||||
checkCount(1);
|
||||
String s = li_std_auto_ptr.takeKlassAutoPtr(kin);
|
||||
checkCount(0);
|
||||
if (!s.equals("KlassInput"))
|
||||
throw new RuntimeException("Incorrect string: " + s);
|
||||
if (!li_std_auto_ptr.is_nullptr(kin))
|
||||
throw new RuntimeException("is_nullptr failed");
|
||||
kin.delete(); // Should not fail, even though already deleted
|
||||
checkCount(0);
|
||||
}
|
||||
|
||||
{
|
||||
Klass kin = new Klass("KlassInput");
|
||||
checkCount(1);
|
||||
String s = li_std_auto_ptr.takeKlassAutoPtr(kin);
|
||||
checkCount(0);
|
||||
if (!s.equals("KlassInput"))
|
||||
throw new RuntimeException("Incorrect string: " + s);
|
||||
if (!li_std_auto_ptr.is_nullptr(kin))
|
||||
throw new RuntimeException("is_nullptr failed");
|
||||
boolean exception_thrown = false;
|
||||
try {
|
||||
li_std_auto_ptr.takeKlassAutoPtr(kin);
|
||||
} catch (RuntimeException e) {
|
||||
exception_thrown = true;
|
||||
}
|
||||
if (!exception_thrown)
|
||||
throw new RuntimeException("double usage of takeKlassAutoPtr should have been an error");
|
||||
kin.delete(); // Should not fail, even though already deleted
|
||||
checkCount(0);
|
||||
}
|
||||
|
||||
{
|
||||
Klass kin = new Klass("KlassInput");
|
||||
boolean exception_thrown = false;
|
||||
try {
|
||||
Klass notowned = li_std_auto_ptr.get_not_owned_ptr(kin);
|
||||
li_std_auto_ptr.takeKlassAutoPtr(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);
|
||||
String s = li_std_auto_ptr.takeKlassAutoPtr(kini);
|
||||
checkCount(0);
|
||||
if (!s.equals("KlassInheritanceInput"))
|
||||
throw new RuntimeException("Incorrect string: " + s);
|
||||
if (!li_std_auto_ptr.is_nullptr(kini))
|
||||
throw new RuntimeException("is_nullptr failed");
|
||||
kini.delete(); // Should not fail, even though already deleted
|
||||
checkCount(0);
|
||||
}
|
||||
|
||||
// auto_ptr as output
|
||||
Klass k1 = li_std_auto_ptr.makeKlassAutoPtr("first");
|
||||
if (!k1.getLabel().equals("first"))
|
||||
throw new RuntimeException("wrong object label");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue