This commit is contained in:
mvandervoord
2008-11-07 19:45:07 +00:00
parent 87838b85bc
commit fecd94cb5c
3 changed files with 162 additions and 162 deletions
+1 -1
View File
@@ -20,8 +20,8 @@ extern volatile EXCEPTION_FRAME_T ExceptionFrames[];
#define Try \ #define Try \
{ \ { \
jmp_buf *PrevFrame, NewFrame; \ jmp_buf *PrevFrame, NewFrame; \
PrevFrame = MY_FRAME.pFrame; \
unsigned int MY_ID = EXCEPTION_GET_ID(); \ unsigned int MY_ID = EXCEPTION_GET_ID(); \
PrevFrame = MY_FRAME.pFrame; \
MY_FRAME_FAST.pFrame = &NewFrame; \ MY_FRAME_FAST.pFrame = &NewFrame; \
MY_FRAME_FAST.Details = 0; \ MY_FRAME_FAST.Details = 0; \
MY_FRAME_FAST.Exception = EXCEPTION_NONE; \ MY_FRAME_FAST.Exception = EXCEPTION_NONE; \
+132 -132
View File
@@ -11,208 +11,208 @@ void tearDown(void)
void test_BasicTryDoesNothingIfNoThrow(void) void test_BasicTryDoesNothingIfNoThrow(void)
{ {
int i; int i;
Try Try
{ {
i += 1; i += 1;
} }
Catch Catch
{ {
TEST_FAIL("Should Not Enter Catch If Not Thrown") TEST_FAIL("Should Not Enter Catch If Not Thrown")
} }
} }
void test_BasicThrowAndCatch(void) void test_BasicThrowAndCatch(void)
{ {
volatile unsigned int ID = 0; volatile unsigned int ID = 0;
Try Try
{ {
Throw(0xBEEFBEEF); Throw(0xBEEFBEEF);
TEST_FAIL("Should Have Thrown An Error") TEST_FAIL("Should Have Thrown An Error")
} }
Catch Catch
{ {
ID = EXCEPTION_ID; ID = EXCEPTION_ID;
} }
TEST_ASSERT_EQUAL(0xBEEFBEEF, ID); TEST_ASSERT_EQUAL(0xBEEFBEEF, ID);
} }
void test_VerifyVolatilesSurviveThrowAndCatch(void) void test_VerifyVolatilesSurviveThrowAndCatch(void)
{ {
volatile unsigned int VolVal = 0; volatile unsigned int VolVal = 0;
Try Try
{ {
VolVal = 2; VolVal = 2;
Throw(0xBEEFBEEF); Throw(0xBEEFBEEF);
TEST_FAIL("Should Have Thrown An Error") TEST_FAIL("Should Have Thrown An Error")
} }
Catch Catch
{ {
VolVal += 2; VolVal += 2;
TEST_ASSERT_EQUAL(0xBEEFBEEF, EXCEPTION_ID); TEST_ASSERT_EQUAL(0xBEEFBEEF, EXCEPTION_ID);
} }
TEST_ASSERT_EQUAL(4, VolVal); TEST_ASSERT_EQUAL(4, VolVal);
} }
void HappyExceptionThrower(unsigned int ID) void HappyExceptionThrower(unsigned int ID)
{ {
if (ID != 0) if (ID != 0)
Throw(ID); Throw(ID);
} }
void test_ThrowFromASubFunctionAndCatchInRootFunc(void) void test_ThrowFromASubFunctionAndCatchInRootFunc(void)
{ {
volatile unsigned int ID = 0; volatile unsigned int ID = 0;
Try Try
{ {
HappyExceptionThrower(0xBADDF00D); HappyExceptionThrower(0xBADDF00D);
TEST_FAIL("Should Have Thrown An Exception"); TEST_FAIL("Should Have Thrown An Exception");
} }
Catch Catch
{ {
ID = EXCEPTION_ID; ID = EXCEPTION_ID;
} }
TEST_ASSERT_EQUAL(0xBADDF00D, ID); TEST_ASSERT_EQUAL(0xBADDF00D, ID);
} }
void HappyExceptionRethrower(unsigned int ID) void HappyExceptionRethrower(unsigned int ID)
{ {
Try Try
{
Throw(ID);
}
Catch
{
switch (EXCEPTION_ID)
{ {
Throw(ID); case 0xBADDF00D:
} Rethrow();
Catch break;
{ default:
switch (EXCEPTION_ID) break;
{
case 0xBADDF00D:
Rethrow();
break;
default:
break;
}
} }
}
} }
void test_ThrowAndCatchFromASubFunctionAndRethrowToCatchInRootFunc(void) void test_ThrowAndCatchFromASubFunctionAndRethrowToCatchInRootFunc(void)
{ {
volatile unsigned int ID = 0; volatile unsigned int ID = 0;
Try Try
{ {
HappyExceptionRethrower(0xBADDF00D); HappyExceptionRethrower(0xBADDF00D);
TEST_FAIL("Should Have Rethrown Exception"); TEST_FAIL("Should Have Rethrown Exception");
} }
Catch Catch
{ {
ID = EXCEPTION_ID; ID = EXCEPTION_ID;
} }
TEST_ASSERT_EQUAL(0xBADDF00D, ID); TEST_ASSERT_EQUAL(0xBADDF00D, ID);
} }
void test_ThrowAndCatchFromASubFunctionAndNoRethrowToCatchInRootFunc(void) void test_ThrowAndCatchFromASubFunctionAndNoRethrowToCatchInRootFunc(void)
{ {
Try Try
{ {
HappyExceptionRethrower(0xBADDBEEF); HappyExceptionRethrower(0xBADDBEEF);
} }
Catch Catch
{ {
TEST_FAIL("Should Not Have Thrown Error"); TEST_FAIL("Should Not Have Thrown Error");
} }
} }
void test_CanHaveMultipleTryBlocksInASingleFunction(void) void test_CanHaveMultipleTryBlocksInASingleFunction(void)
{ {
Try Try
{ {
HappyExceptionThrower(0x01234567); HappyExceptionThrower(0x01234567);
TEST_FAIL("Should Have Rethrown Exception"); TEST_FAIL("Should Have Thrown Exception");
} }
Catch Catch
{ {
TEST_ASSERT_EQUAL(0x01234567, EXCEPTION_ID); TEST_ASSERT_EQUAL(0x01234567, EXCEPTION_ID);
} }
Try Try
{ {
HappyExceptionThrower(0xF00D8888); HappyExceptionThrower(0xF00D8888);
TEST_FAIL("Should Have Rethrown Exception"); TEST_FAIL("Should Have Thrown Exception");
} }
Catch Catch
{ {
TEST_ASSERT_EQUAL(0xF00D8888, EXCEPTION_ID); TEST_ASSERT_EQUAL(0xF00D8888, EXCEPTION_ID);
} }
} }
void test_CanHaveNestedTryBlocksInASingleFunction_ThrowInside(void) void test_CanHaveNestedTryBlocksInASingleFunction_ThrowInside(void)
{ {
int i = 0; int i = 0;
Try
{
Try Try
{ {
Try HappyExceptionThrower(0x01234567);
{ i = 1;
HappyExceptionThrower(0x01234567); TEST_FAIL("Should Have Rethrown Exception");
i = 1;
TEST_FAIL("Should Have Rethrown Exception");
}
Catch
{
TEST_ASSERT_EQUAL(0x01234567, EXCEPTION_ID);
}
} }
Catch 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) void test_CanHaveNestedTryBlocksInASingleFunction_ThrowOutside(void)
{ {
int i = 0; int i = 0;
Try
{
Try Try
{ {
Try i = 2;
{
i = 2;
}
Catch
{
TEST_FAIL("Should NotBe Caught Here");
}
HappyExceptionThrower(0x01234567);
TEST_FAIL("Should Have Rethrown Exception");
} }
Catch 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) void HappyDetailedExceptionThrower(unsigned int ID, unsigned int Details)
{ {
if (ID != 0) if (ID != 0)
ThrowDetailed(ID, Details); ThrowDetailed(ID, Details);
} }
void test_CanThrowADetailedExceptionAndCheckOutTheResults(void) void test_CanThrowADetailedExceptionAndCheckOutTheResults(void)
{ {
Try Try
{ {
HappyDetailedExceptionThrower(0x12345678, 0x90ABCDEF); HappyDetailedExceptionThrower(0x12345678, 0x90ABCDEF);
TEST_FAIL("Should Have Thrown An Exception"); TEST_FAIL("Should Have Thrown An Exception");
} }
Catch Catch
{ {
TEST_ASSERT_EQUAL(0x12345678, EXCEPTION_ID); TEST_ASSERT_EQUAL(0x12345678, EXCEPTION_ID);
TEST_ASSERT_EQUAL(0x90ABCDEF, EXCEPTION_DETAILS); TEST_ASSERT_EQUAL(0x90ABCDEF, EXCEPTION_DETAILS);
} }
} }
+29 -29
View File
@@ -21,40 +21,40 @@ extern void test_CanThrowADetailedExceptionAndCheckOutTheResults(void);
static void runTest(UnityTestFunction test) static void runTest(UnityTestFunction test)
{ {
if (setjmp(AbortFrame) == 0) if (setjmp(AbortFrame) == 0)
{
setUp();
Try
{ {
setUp(); test();
Try
{
test();
}
Catch
{
TEST_FAIL("Unexpected exception!")
}
} }
tearDown(); Catch
{
TEST_FAIL("Unexpected exception!")
}
}
tearDown();
} }
int main(void) int main(void)
{ {
Unity.TestFile = __FILE__; Unity.TestFile = __FILE__;
UnityBegin(); UnityBegin();
// RUN_TEST calls runTest // RUN_TEST calls runTest
RUN_TEST(test_BasicTryDoesNothingIfNoThrow); RUN_TEST(test_BasicTryDoesNothingIfNoThrow);
RUN_TEST(test_BasicThrowAndCatch); RUN_TEST(test_BasicThrowAndCatch);
RUN_TEST(test_VerifyVolatilesSurviveThrowAndCatch); RUN_TEST(test_VerifyVolatilesSurviveThrowAndCatch);
RUN_TEST(test_ThrowFromASubFunctionAndCatchInRootFunc); RUN_TEST(test_ThrowFromASubFunctionAndCatchInRootFunc);
RUN_TEST(test_ThrowAndCatchFromASubFunctionAndRethrowToCatchInRootFunc); RUN_TEST(test_ThrowAndCatchFromASubFunctionAndRethrowToCatchInRootFunc);
RUN_TEST(test_ThrowAndCatchFromASubFunctionAndNoRethrowToCatchInRootFunc); RUN_TEST(test_ThrowAndCatchFromASubFunctionAndNoRethrowToCatchInRootFunc);
RUN_TEST(test_CanHaveMultipleTryBlocksInASingleFunction); RUN_TEST(test_CanHaveMultipleTryBlocksInASingleFunction);
RUN_TEST(test_CanHaveNestedTryBlocksInASingleFunction_ThrowInside); RUN_TEST(test_CanHaveNestedTryBlocksInASingleFunction_ThrowInside);
RUN_TEST(test_CanHaveNestedTryBlocksInASingleFunction_ThrowOutside); RUN_TEST(test_CanHaveNestedTryBlocksInASingleFunction_ThrowOutside);
RUN_TEST(test_CanThrowADetailedExceptionAndCheckOutTheResults); RUN_TEST(test_CanThrowADetailedExceptionAndCheckOutTheResults);
UnityEnd(); UnityEnd();
return 0; return 0;
} }