Simple interface for Mbed Cloud Client
Embed:
(wiki syntax)
Show/hide line numbers
testparameterized.c
00001 /* ========================================== 00002 Unity Project - A Test Framework for C 00003 Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams 00004 [Released under MIT License. Please refer to license.txt for details] 00005 ========================================== */ 00006 00007 #include <setjmp.h> 00008 #include <stdio.h> 00009 #include "unity.h" 00010 00011 void putcharSpy(int c) { (void)putchar(c);} // include passthrough for linking tests 00012 00013 #define TEST_CASE(...) 00014 00015 #define EXPECT_ABORT_BEGIN \ 00016 if (TEST_PROTECT()) \ 00017 { 00018 00019 #define VERIFY_FAILS_END \ 00020 } \ 00021 Unity.CurrentTestFailed = (Unity.CurrentTestFailed == 1) ? 0 : 1; \ 00022 if (Unity.CurrentTestFailed == 1) { \ 00023 SetToOneMeanWeAlreadyCheckedThisGuy = 1; \ 00024 UnityPrint("[[[[ Previous Test Should Have Failed But Did Not ]]]]"); \ 00025 UNITY_OUTPUT_CHAR('\n'); \ 00026 } 00027 00028 #define VERIFY_IGNORES_END \ 00029 } \ 00030 Unity.CurrentTestFailed = (Unity.CurrentTestIgnored == 1) ? 0 : 1; \ 00031 Unity.CurrentTestIgnored = 0; \ 00032 if (Unity.CurrentTestFailed == 1) { \ 00033 SetToOneMeanWeAlreadyCheckedThisGuy = 1; \ 00034 UnityPrint("[[[[ Previous Test Should Have Ignored But Did Not ]]]]"); \ 00035 UNITY_OUTPUT_CHAR('\n'); \ 00036 } 00037 00038 int SetToOneToFailInTearDown; 00039 int SetToOneMeanWeAlreadyCheckedThisGuy; 00040 00041 void setUp(void) 00042 { 00043 SetToOneToFailInTearDown = 0; 00044 SetToOneMeanWeAlreadyCheckedThisGuy = 0; 00045 } 00046 00047 void tearDown(void) 00048 { 00049 if (SetToOneToFailInTearDown == 1) 00050 TEST_FAIL_MESSAGE("<= Failed in tearDown"); 00051 if ((SetToOneMeanWeAlreadyCheckedThisGuy == 0) && (Unity.CurrentTestFailed > 0)) 00052 { 00053 UnityPrint("[[[[ Previous Test Should Have Passed But Did Not ]]]]"); 00054 UNITY_OUTPUT_CHAR('\n'); 00055 } 00056 } 00057 00058 TEST_CASE(0) 00059 TEST_CASE(44) 00060 TEST_CASE((90)+9) 00061 void test_TheseShouldAllPass(int Num) 00062 { 00063 TEST_ASSERT_TRUE(Num < 100); 00064 } 00065 00066 TEST_CASE(3) 00067 TEST_CASE(77) 00068 TEST_CASE( (99) + 1 - (1)) 00069 void test_TheseShouldAllFail(int Num) 00070 { 00071 EXPECT_ABORT_BEGIN 00072 TEST_ASSERT_TRUE(Num > 100); 00073 VERIFY_FAILS_END 00074 } 00075 00076 TEST_CASE(1) 00077 TEST_CASE(44) 00078 TEST_CASE(99) 00079 TEST_CASE(98) 00080 void test_TheseAreEveryOther(int Num) 00081 { 00082 if (Num & 1) 00083 { 00084 EXPECT_ABORT_BEGIN 00085 TEST_ASSERT_TRUE(Num > 100); 00086 VERIFY_FAILS_END 00087 } 00088 else 00089 { 00090 TEST_ASSERT_TRUE(Num < 100); 00091 } 00092 } 00093 00094 void test_NormalPassesStillWork(void) 00095 { 00096 TEST_ASSERT_TRUE(1); 00097 } 00098 00099 void test_NormalFailsStillWork(void) 00100 { 00101 EXPECT_ABORT_BEGIN 00102 TEST_ASSERT_TRUE(0); 00103 VERIFY_FAILS_END 00104 }
Generated on Tue Jul 12 2022 19:01:37 by 1.7.2