From f35ca6191314fa4e09e2211cbe504a39be5c839c Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 2 Mar 2006 23:19:56 +0000 Subject: [PATCH] Add inner exception tests git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@8934 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- .../test-suite/csharp/csharp_exceptions_runme.cs | 12 ++++++++++++ SWIG/Examples/test-suite/csharp_exceptions.i | 14 ++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/SWIG/Examples/test-suite/csharp/csharp_exceptions_runme.cs b/SWIG/Examples/test-suite/csharp/csharp_exceptions_runme.cs index add2e0853..43585b106 100644 --- a/SWIG/Examples/test-suite/csharp/csharp_exceptions_runme.cs +++ b/SWIG/Examples/test-suite/csharp/csharp_exceptions_runme.cs @@ -291,6 +291,16 @@ public class runme if (testThreads[i].Failed) throw new Exception("Test Failed"); } } + + + // test inner exceptions + try { + csharp_exceptions.InnerExceptionTest(); + throw new Exception("InnerExceptionTest exception not caught"); + } catch (InvalidOperationException e) { + if (e.Message != "My OuterException message") throw new Exception("OuterException msg incorrect"); + if (e.InnerException.Message != "My InnerException message") throw new Exception("InnerException msg incorrect"); + } } public static string CRLF = "\r\n"; // Some CLR implementations use a CRLF instead of just CR } @@ -316,6 +326,8 @@ public class TestThread { throw new Exception("Exception message incorrect. Expected:\n[" + expectedMessage + "]\n" + "Received:\n[" + e.Message + "]"); if (e.ParamName != "input") throw new Exception("Exception ParamName incorrect. Expected:\n[input]\n" + "Received:\n[" + e.ParamName + "]"); + if (e.InnerException != null) + throw new Exception("Unexpected inner exception"); } if (throwsClass.dub != 1234.5678) // simple check which attempts to catch memory corruption throw new Exception("throwsException.dub = " + throwsClass.dub + " expected: 1234.5678"); diff --git a/SWIG/Examples/test-suite/csharp_exceptions.i b/SWIG/Examples/test-suite/csharp_exceptions.i index 6cc1ea5f1..bbb1a5c2f 100644 --- a/SWIG/Examples/test-suite/csharp_exceptions.i +++ b/SWIG/Examples/test-suite/csharp_exceptions.i @@ -223,3 +223,17 @@ struct ThrowsClass { } }; %} + +// test inner exceptions +%exception InnerExceptionTest() { + try { + $action + } catch(Ex &e) { + SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, e.what()); + SWIG_CSharpSetPendingException(SWIG_CSharpInvalidOperationException, "My OuterException message"); + } +} + +%inline %{ +void InnerExceptionTest() { throw Ex("My InnerException message"); } +%}