From 1bf15210ef5f86e588cc8a08ff5b1206637feb03 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 16 Jul 2022 23:02:21 +0100 Subject: [PATCH] Java unique_ptr enhance test for double release --- .../java/cpp11_std_unique_ptr_runme.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Examples/test-suite/java/cpp11_std_unique_ptr_runme.java b/Examples/test-suite/java/cpp11_std_unique_ptr_runme.java index 3f2b15f44..4ac72d720 100644 --- a/Examples/test-suite/java/cpp11_std_unique_ptr_runme.java +++ b/Examples/test-suite/java/cpp11_std_unique_ptr_runme.java @@ -42,6 +42,27 @@ public class cpp11_std_unique_ptr_runme { checkCount(0); } + { + Klass kin = new Klass("KlassInput"); + checkCount(1); + String s = cpp11_std_unique_ptr.takeKlassUniquePtr(kin); + checkCount(0); + if (!s.equals("KlassInput")) + throw new RuntimeException("Incorrect string: " + s); + if (!cpp11_std_unique_ptr.is_nullptr(kin)) + throw new RuntimeException("is_nullptr failed"); + boolean exception_thrown = false; + try { + cpp11_std_unique_ptr.takeKlassUniquePtr(kin); + } catch (RuntimeException e) { + exception_thrown = true; + } + if (!exception_thrown) + throw new RuntimeException("double usage of takeKlassUniquePtr should have been an error"); + kin.delete(); // Should not fail, even though already deleted + checkCount(0); + } + { KlassInheritance kini = new KlassInheritance("KlassInheritanceInput"); checkCount(1);