From fecd94cb5c8316c751d2e72221340b04576fd0cb Mon Sep 17 00:00:00 2001 From: mvandervoord Date: Fri, 7 Nov 2008 19:45:07 +0000 Subject: [PATCH] git-svn-id: http://cexception.svn.sourceforge.net/svnroot/cexception/trunk@2 50f63946-2846-0410-8d77-f904c773002e --- lib/Exception.h | 2 +- test/TestException.c | 264 ++++++++++++++++++------------------ test/TestException_Runner.c | 58 ++++---- 3 files changed, 162 insertions(+), 162 deletions(-) diff --git a/lib/Exception.h b/lib/Exception.h index 0aee739..b41af17 100644 --- a/lib/Exception.h +++ b/lib/Exception.h @@ -20,8 +20,8 @@ extern volatile EXCEPTION_FRAME_T ExceptionFrames[]; #define Try \ { \ jmp_buf *PrevFrame, NewFrame; \ - PrevFrame = MY_FRAME.pFrame; \ unsigned int MY_ID = EXCEPTION_GET_ID(); \ + PrevFrame = MY_FRAME.pFrame; \ MY_FRAME_FAST.pFrame = &NewFrame; \ MY_FRAME_FAST.Details = 0; \ MY_FRAME_FAST.Exception = EXCEPTION_NONE; \ diff --git a/test/TestException.c b/test/TestException.c index 87992bc..7d82e30 100644 --- a/test/TestException.c +++ b/test/TestException.c @@ -11,208 +11,208 @@ void tearDown(void) void test_BasicTryDoesNothingIfNoThrow(void) { - int i; - Try - { - i += 1; - } - Catch - { - TEST_FAIL("Should Not Enter Catch If Not Thrown") - } + int i; + Try + { + i += 1; + } + Catch + { + TEST_FAIL("Should Not Enter Catch If Not Thrown") + } } void test_BasicThrowAndCatch(void) { - volatile unsigned int ID = 0; + volatile unsigned int ID = 0; - Try - { - Throw(0xBEEFBEEF); - TEST_FAIL("Should Have Thrown An Error") - } - Catch - { - ID = EXCEPTION_ID; - } + Try + { + Throw(0xBEEFBEEF); + TEST_FAIL("Should Have Thrown An Error") + } + Catch + { + ID = EXCEPTION_ID; + } - TEST_ASSERT_EQUAL(0xBEEFBEEF, ID); + TEST_ASSERT_EQUAL(0xBEEFBEEF, ID); } void test_VerifyVolatilesSurviveThrowAndCatch(void) { - volatile unsigned int VolVal = 0; + volatile unsigned int VolVal = 0; - Try - { - VolVal = 2; - Throw(0xBEEFBEEF); - TEST_FAIL("Should Have Thrown An Error") - } - Catch - { - VolVal += 2; - TEST_ASSERT_EQUAL(0xBEEFBEEF, EXCEPTION_ID); - } + Try + { + VolVal = 2; + Throw(0xBEEFBEEF); + TEST_FAIL("Should Have Thrown An Error") + } + Catch + { + VolVal += 2; + TEST_ASSERT_EQUAL(0xBEEFBEEF, EXCEPTION_ID); + } - TEST_ASSERT_EQUAL(4, VolVal); + TEST_ASSERT_EQUAL(4, VolVal); } void HappyExceptionThrower(unsigned int ID) { - if (ID != 0) - Throw(ID); + if (ID != 0) + Throw(ID); } void test_ThrowFromASubFunctionAndCatchInRootFunc(void) { - volatile unsigned int ID = 0; + volatile unsigned int ID = 0; - Try - { + Try + { - HappyExceptionThrower(0xBADDF00D); - TEST_FAIL("Should Have Thrown An Exception"); - } - Catch - { - ID = EXCEPTION_ID; - } + HappyExceptionThrower(0xBADDF00D); + TEST_FAIL("Should Have Thrown An Exception"); + } + Catch + { + ID = EXCEPTION_ID; + } - TEST_ASSERT_EQUAL(0xBADDF00D, ID); + TEST_ASSERT_EQUAL(0xBADDF00D, ID); } void HappyExceptionRethrower(unsigned int ID) { - Try + Try + { + Throw(ID); + } + Catch + { + switch (EXCEPTION_ID) { - Throw(ID); - } - Catch - { - switch (EXCEPTION_ID) - { - case 0xBADDF00D: - Rethrow(); - break; - default: - break; - } + case 0xBADDF00D: + Rethrow(); + break; + default: + break; } + } } void test_ThrowAndCatchFromASubFunctionAndRethrowToCatchInRootFunc(void) { - volatile unsigned int ID = 0; - Try - { - HappyExceptionRethrower(0xBADDF00D); - TEST_FAIL("Should Have Rethrown Exception"); - } - Catch - { - ID = EXCEPTION_ID; - } + volatile unsigned int ID = 0; + Try + { + HappyExceptionRethrower(0xBADDF00D); + TEST_FAIL("Should Have Rethrown Exception"); + } + Catch + { + ID = EXCEPTION_ID; + } - TEST_ASSERT_EQUAL(0xBADDF00D, ID); + TEST_ASSERT_EQUAL(0xBADDF00D, ID); } void test_ThrowAndCatchFromASubFunctionAndNoRethrowToCatchInRootFunc(void) { - Try - { - HappyExceptionRethrower(0xBADDBEEF); - } - Catch - { - TEST_FAIL("Should Not Have Thrown Error"); - } + Try + { + HappyExceptionRethrower(0xBADDBEEF); + } + Catch + { + TEST_FAIL("Should Not Have Thrown Error"); + } } void test_CanHaveMultipleTryBlocksInASingleFunction(void) { - Try - { - HappyExceptionThrower(0x01234567); - TEST_FAIL("Should Have Rethrown Exception"); - } - Catch - { - TEST_ASSERT_EQUAL(0x01234567, EXCEPTION_ID); - } + Try + { + HappyExceptionThrower(0x01234567); + TEST_FAIL("Should Have Thrown Exception"); + } + Catch + { + TEST_ASSERT_EQUAL(0x01234567, EXCEPTION_ID); + } - Try - { - HappyExceptionThrower(0xF00D8888); - TEST_FAIL("Should Have Rethrown Exception"); - } - Catch - { - TEST_ASSERT_EQUAL(0xF00D8888, EXCEPTION_ID); - } + Try + { + HappyExceptionThrower(0xF00D8888); + TEST_FAIL("Should Have Thrown Exception"); + } + Catch + { + TEST_ASSERT_EQUAL(0xF00D8888, EXCEPTION_ID); + } } void test_CanHaveNestedTryBlocksInASingleFunction_ThrowInside(void) { - int i = 0; + int i = 0; + Try + { Try { - Try - { - HappyExceptionThrower(0x01234567); - i = 1; - TEST_FAIL("Should Have Rethrown Exception"); - } - Catch - { - TEST_ASSERT_EQUAL(0x01234567, EXCEPTION_ID); - } + HappyExceptionThrower(0x01234567); + i = 1; + TEST_FAIL("Should Have Rethrown Exception"); } Catch { - TEST_FAIL("Should Have Been Caught By Inside Catch"); + TEST_ASSERT_EQUAL(0x01234567, EXCEPTION_ID); } + } + Catch + { + TEST_FAIL("Should Have Been Caught By Inside Catch"); + } } void test_CanHaveNestedTryBlocksInASingleFunction_ThrowOutside(void) { - int i = 0; + int i = 0; + Try + { Try { - Try - { - i = 2; - } - Catch - { - TEST_FAIL("Should NotBe Caught Here"); - } - HappyExceptionThrower(0x01234567); - TEST_FAIL("Should Have Rethrown Exception"); + i = 2; } Catch { - TEST_ASSERT_EQUAL(0x01234567, EXCEPTION_ID); + TEST_FAIL("Should NotBe Caught Here"); } + HappyExceptionThrower(0x01234567); + TEST_FAIL("Should Have Rethrown Exception"); + } + Catch + { + TEST_ASSERT_EQUAL(0x01234567, EXCEPTION_ID); + } } void HappyDetailedExceptionThrower(unsigned int ID, unsigned int Details) { - if (ID != 0) - ThrowDetailed(ID, Details); + if (ID != 0) + ThrowDetailed(ID, Details); } void test_CanThrowADetailedExceptionAndCheckOutTheResults(void) { - Try - { - HappyDetailedExceptionThrower(0x12345678, 0x90ABCDEF); - TEST_FAIL("Should Have Thrown An Exception"); - } - Catch - { - TEST_ASSERT_EQUAL(0x12345678, EXCEPTION_ID); - TEST_ASSERT_EQUAL(0x90ABCDEF, EXCEPTION_DETAILS); - } + Try + { + HappyDetailedExceptionThrower(0x12345678, 0x90ABCDEF); + TEST_FAIL("Should Have Thrown An Exception"); + } + Catch + { + TEST_ASSERT_EQUAL(0x12345678, EXCEPTION_ID); + TEST_ASSERT_EQUAL(0x90ABCDEF, EXCEPTION_DETAILS); + } } diff --git a/test/TestException_Runner.c b/test/TestException_Runner.c index 5cfeb8e..6889bf9 100644 --- a/test/TestException_Runner.c +++ b/test/TestException_Runner.c @@ -21,40 +21,40 @@ extern void test_CanThrowADetailedExceptionAndCheckOutTheResults(void); static void runTest(UnityTestFunction test) { - if (setjmp(AbortFrame) == 0) + if (setjmp(AbortFrame) == 0) + { + setUp(); + Try { - setUp(); - Try - { - test(); - } - Catch - { - TEST_FAIL("Unexpected exception!") - } + test(); } - tearDown(); + Catch + { + TEST_FAIL("Unexpected exception!") + } + } + tearDown(); } - - + + int main(void) { - Unity.TestFile = __FILE__; - UnityBegin(); + Unity.TestFile = __FILE__; + UnityBegin(); - // RUN_TEST calls runTest - RUN_TEST(test_BasicTryDoesNothingIfNoThrow); - RUN_TEST(test_BasicThrowAndCatch); - RUN_TEST(test_VerifyVolatilesSurviveThrowAndCatch); - RUN_TEST(test_ThrowFromASubFunctionAndCatchInRootFunc); - RUN_TEST(test_ThrowAndCatchFromASubFunctionAndRethrowToCatchInRootFunc); - RUN_TEST(test_ThrowAndCatchFromASubFunctionAndNoRethrowToCatchInRootFunc); - RUN_TEST(test_CanHaveMultipleTryBlocksInASingleFunction); - RUN_TEST(test_CanHaveNestedTryBlocksInASingleFunction_ThrowInside); - RUN_TEST(test_CanHaveNestedTryBlocksInASingleFunction_ThrowOutside); - RUN_TEST(test_CanThrowADetailedExceptionAndCheckOutTheResults); + // RUN_TEST calls runTest + RUN_TEST(test_BasicTryDoesNothingIfNoThrow); + RUN_TEST(test_BasicThrowAndCatch); + RUN_TEST(test_VerifyVolatilesSurviveThrowAndCatch); + RUN_TEST(test_ThrowFromASubFunctionAndCatchInRootFunc); + RUN_TEST(test_ThrowAndCatchFromASubFunctionAndRethrowToCatchInRootFunc); + RUN_TEST(test_ThrowAndCatchFromASubFunctionAndNoRethrowToCatchInRootFunc); + RUN_TEST(test_CanHaveMultipleTryBlocksInASingleFunction); + RUN_TEST(test_CanHaveNestedTryBlocksInASingleFunction_ThrowInside); + RUN_TEST(test_CanHaveNestedTryBlocksInASingleFunction_ThrowOutside); + RUN_TEST(test_CanThrowADetailedExceptionAndCheckOutTheResults); - UnityEnd(); - - return 0; + UnityEnd(); + + return 0; }