From 09cfc53bdf0264ca7aa69a3a3cf9bde3bb375efd Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 1 Mar 2014 16:14:36 +0000 Subject: [PATCH] Better error detection in some java testcases --- .../test-suite/java/dynamic_cast_runme.java | 3 +- .../java/ignore_parameter_runme.java | 16 +++++------ .../test-suite/java/java_jnitypes_runme.java | 3 +- Examples/test-suite/java/long_long_runme.java | 6 ++-- .../test-suite/java/primitive_ref_runme.java | 28 +++++++++---------- Examples/test-suite/java/unions_runme.java | 15 ++++------ 6 files changed, 31 insertions(+), 40 deletions(-) diff --git a/Examples/test-suite/java/dynamic_cast_runme.java b/Examples/test-suite/java/dynamic_cast_runme.java index be1f97b35..e13c73dda 100644 --- a/Examples/test-suite/java/dynamic_cast_runme.java +++ b/Examples/test-suite/java/dynamic_cast_runme.java @@ -22,8 +22,7 @@ public class dynamic_cast_runme { // Note it is possible to downcast y with a Java cast. String a = dynamic_cast.do_test((Bar)y); if (!a.equals("Bar::test")) { - System.err.println("Failed!"); - System.exit(1); + throw new RuntimeException("Failed!"); } } } diff --git a/Examples/test-suite/java/ignore_parameter_runme.java b/Examples/test-suite/java/ignore_parameter_runme.java index 7dbcb06db..57ff360fb 100644 --- a/Examples/test-suite/java/ignore_parameter_runme.java +++ b/Examples/test-suite/java/ignore_parameter_runme.java @@ -16,16 +16,16 @@ public class ignore_parameter_runme { { // Compilation will ensure the number of arguments and type are correct. // Then check the return value is the same as the value given to the ignored parameter. - if (!ignore_parameter.jaguar(200, 0.0).equals("hello")) { System.err.println("Runtime Error in jaguar()");} - if (ignore_parameter.lotus("fast", 0.0) != 101) { System.err.println("Runtime Error in lotus()");} - if (ignore_parameter.tvr("fast", 200) != 8.8) { System.err.println("Runtime Error in tvr()");} - if (ignore_parameter.ferrari() != 101) { System.err.println("Runtime Error in ferrari()");} + if (!ignore_parameter.jaguar(200, 0.0).equals("hello")) { throw new RuntimeException("Runtime Error in jaguar()");} + if (ignore_parameter.lotus("fast", 0.0) != 101) { throw new RuntimeException("Runtime Error in lotus()");} + if (ignore_parameter.tvr("fast", 200) != 8.8) { throw new RuntimeException("Runtime Error in tvr()");} + if (ignore_parameter.ferrari() != 101) { throw new RuntimeException("Runtime Error in ferrari()");} SportsCars sc = new SportsCars(); - if (!sc.daimler(200, 0.0).equals("hello")) { System.err.println("Runtime Error in daimler()");} - if (sc.astonmartin("fast", 0.0) != 101) { System.err.println("Runtime Error in astonmartin()");} - if (sc.bugatti("fast", 200) != 8.8) { System.err.println("Runtime Error in bugatti()");} - if (sc.lamborghini() != 101) { System.err.println("Runtime Error in lamborghini()");} + if (!sc.daimler(200, 0.0).equals("hello")) { throw new RuntimeException("Runtime Error in daimler()");} + if (sc.astonmartin("fast", 0.0) != 101) { throw new RuntimeException("Runtime Error in astonmartin()");} + if (sc.bugatti("fast", 200) != 8.8) { throw new RuntimeException("Runtime Error in bugatti()");} + if (sc.lamborghini() != 101) { throw new RuntimeException("Runtime Error in lamborghini()");} // Check constructors are also generated correctly MiniCooper mc = new MiniCooper(200, 0.0); diff --git a/Examples/test-suite/java/java_jnitypes_runme.java b/Examples/test-suite/java/java_jnitypes_runme.java index 3e9d9e4c5..b2816c017 100644 --- a/Examples/test-suite/java/java_jnitypes_runme.java +++ b/Examples/test-suite/java/java_jnitypes_runme.java @@ -51,7 +51,6 @@ public class java_jnitypes_runme { } public static void testFailed(String str) { - System.err.println(str + " test failed"); - System.exit(1); + throw new RuntimeException(str + " test failed"); } } diff --git a/Examples/test-suite/java/long_long_runme.java b/Examples/test-suite/java/long_long_runme.java index d3092b326..3a967f7a7 100644 --- a/Examples/test-suite/java/long_long_runme.java +++ b/Examples/test-suite/java/long_long_runme.java @@ -66,8 +66,7 @@ public class long_long_runme { long_long.setLl(ll); long ll_check = long_long.getLl(); if (ll != ll_check) { - System.err.println("Runtime test using long long failed. ll=" + ll + " ll_check=" + ll_check); - System.exit(1); + throw new RuntimeException("Runtime test using long long failed. ll=" + ll + " ll_check=" + ll_check); } } @@ -75,8 +74,7 @@ public class long_long_runme { long_long.setUll(ull); BigInteger ull_check = long_long.getUll(); if (ull.compareTo(ull_check) != 0) { - System.err.println("Runtime test using unsigned long long failed. ull=" + ull.toString() + " ull_check=" + ull_check.toString()); - System.exit(1); + throw new RuntimeException("Runtime test using unsigned long long failed. ull=" + ull.toString() + " ull_check=" + ull_check.toString()); } } } diff --git a/Examples/test-suite/java/primitive_ref_runme.java b/Examples/test-suite/java/primitive_ref_runme.java index 2955004db..0307eb782 100644 --- a/Examples/test-suite/java/primitive_ref_runme.java +++ b/Examples/test-suite/java/primitive_ref_runme.java @@ -18,47 +18,47 @@ public class primitive_ref_runme { public static void main(String argv[]) { if (primitive_ref.ref_int(3) != 3) { - System.err.println( "ref_int failed!" ); + throw new RuntimeException( "ref_int failed!" ); } if (primitive_ref.ref_uint(3) != 3) { - System.err.println( "ref_uint failed!" ); + throw new RuntimeException( "ref_uint failed!" ); } if (primitive_ref.ref_short((short)3) != 3) { - System.err.println( "ref_short failed!" ); + throw new RuntimeException( "ref_short failed!" ); } if (primitive_ref.ref_ushort(3) != 3) { - System.err.println( "ref_ushort failed!" ); + throw new RuntimeException( "ref_ushort failed!" ); } if (primitive_ref.ref_long(3) != 3) { - System.err.println( "ref_long failed!" ); + throw new RuntimeException( "ref_long failed!" ); } if (primitive_ref.ref_ulong(3) != 3) { - System.err.println( "ref_ulong failed!" ); + throw new RuntimeException( "ref_ulong failed!" ); } if (primitive_ref.ref_schar((byte)3) != 3) { - System.err.println( "ref_schar failed!" ); + throw new RuntimeException( "ref_schar failed!" ); } if (primitive_ref.ref_uchar((short)3) != 3) { - System.err.println( "ref_uchar failed!" ); + throw new RuntimeException( "ref_uchar failed!" ); } if (primitive_ref.ref_bool(true) != true) { - System.err.println( "ref_bool failed!" ); + throw new RuntimeException( "ref_bool failed!" ); } if (primitive_ref.ref_float((float)3.5) != 3.5) { - System.err.println( "ref_float failed!" ); + throw new RuntimeException( "ref_float failed!" ); } if (primitive_ref.ref_double(3.5) != 3.5) { - System.err.println( "ref_double failed!" ); + throw new RuntimeException( "ref_double failed!" ); } if (primitive_ref.ref_char('x') != 'x') { - System.err.println( "ref_char failed!" ); + throw new RuntimeException( "ref_char failed!" ); } if (primitive_ref.ref_longlong(0x123456789ABCDEF0L) != 0x123456789ABCDEF0L) { - System.err.println( "ref_longlong failed!" ); + throw new RuntimeException( "ref_longlong failed!" ); } BigInteger bi = new BigInteger("18446744073709551615"); //0xFFFFFFFFFFFFFFFFL if (bi.compareTo(primitive_ref.ref_ulonglong(bi)) != 0) { - System.err.println( "ref_ulonglong failed!" ); + throw new RuntimeException( "ref_ulonglong failed!" ); } } } diff --git a/Examples/test-suite/java/unions_runme.java b/Examples/test-suite/java/unions_runme.java index 16a5b3b87..6a073a0f5 100644 --- a/Examples/test-suite/java/unions_runme.java +++ b/Examples/test-suite/java/unions_runme.java @@ -34,14 +34,12 @@ public class unions_runme { eut.getUni().setSmall(small); short Jill1 = eut.getUni().getSmall().getJill(); if (Jill1 != 200) { - System.err.println("Runtime test1 failed. eut.uni.small.jill=" + Jill1); - System.exit(1); + throw new RuntimeException("Runtime test1 failed. eut.uni.small.jill=" + Jill1); } int Num1 = eut.getNumber(); if (Num1 != 1) { - System.err.println("Runtime test2 failed. eut.number=" + Num1); - System.exit(1); + throw new RuntimeException("Runtime test2 failed. eut.number=" + Num1); } // Secondly check the BigStruct in EmbeddedUnionTest @@ -49,20 +47,17 @@ public class unions_runme { eut.getUni().setBig(big); int Jack1 = eut.getUni().getBig().getJack(); if (Jack1 != 300) { - System.err.println("Runtime test3 failed. eut.uni.big.jack=" + Jack1); - System.exit(1); + throw new RuntimeException("Runtime test3 failed. eut.uni.big.jack=" + Jack1); } short Jill2 = eut.getUni().getBig().getSmallstruct().getJill(); if (Jill2 != 200) { - System.err.println("Runtime test4 failed. eut.uni.big.smallstruct.jill=" + Jill2); - System.exit(1); + throw new RuntimeException("Runtime test4 failed. eut.uni.big.smallstruct.jill=" + Jill2); } int Num2 = eut.getNumber(); if (Num2 != 2) { - System.err.println("Runtime test5 failed. eut.number=" + Num2); - System.exit(1); + throw new RuntimeException("Runtime test5 failed. eut.number=" + Num2); } } }