A metronome using the FRDM K64F board

Committer:
ram54288
Date:
Sun May 14 18:40:18 2017 +0000
Revision:
0:a7a43371b306
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ram54288 0:a7a43371b306 1 /* ==========================================
ram54288 0:a7a43371b306 2 Unity Project - A Test Framework for C
ram54288 0:a7a43371b306 3 Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
ram54288 0:a7a43371b306 4 [Released under MIT License. Please refer to license.txt for details]
ram54288 0:a7a43371b306 5 ========================================== */
ram54288 0:a7a43371b306 6
ram54288 0:a7a43371b306 7 #include <setjmp.h>
ram54288 0:a7a43371b306 8 #include <stdio.h>
ram54288 0:a7a43371b306 9 #include "unity.h"
ram54288 0:a7a43371b306 10
ram54288 0:a7a43371b306 11 void putcharSpy(int c) { (void)putchar(c);} // include passthrough for linking tests
ram54288 0:a7a43371b306 12
ram54288 0:a7a43371b306 13 #define TEST_CASE(...)
ram54288 0:a7a43371b306 14
ram54288 0:a7a43371b306 15 #define EXPECT_ABORT_BEGIN \
ram54288 0:a7a43371b306 16 if (TEST_PROTECT()) \
ram54288 0:a7a43371b306 17 {
ram54288 0:a7a43371b306 18
ram54288 0:a7a43371b306 19 #define VERIFY_FAILS_END \
ram54288 0:a7a43371b306 20 } \
ram54288 0:a7a43371b306 21 Unity.CurrentTestFailed = (Unity.CurrentTestFailed == 1) ? 0 : 1; \
ram54288 0:a7a43371b306 22 if (Unity.CurrentTestFailed == 1) { \
ram54288 0:a7a43371b306 23 SetToOneMeanWeAlreadyCheckedThisGuy = 1; \
ram54288 0:a7a43371b306 24 UnityPrint("[[[[ Previous Test Should Have Failed But Did Not ]]]]"); \
ram54288 0:a7a43371b306 25 UNITY_OUTPUT_CHAR('\n'); \
ram54288 0:a7a43371b306 26 }
ram54288 0:a7a43371b306 27
ram54288 0:a7a43371b306 28 #define VERIFY_IGNORES_END \
ram54288 0:a7a43371b306 29 } \
ram54288 0:a7a43371b306 30 Unity.CurrentTestFailed = (Unity.CurrentTestIgnored == 1) ? 0 : 1; \
ram54288 0:a7a43371b306 31 Unity.CurrentTestIgnored = 0; \
ram54288 0:a7a43371b306 32 if (Unity.CurrentTestFailed == 1) { \
ram54288 0:a7a43371b306 33 SetToOneMeanWeAlreadyCheckedThisGuy = 1; \
ram54288 0:a7a43371b306 34 UnityPrint("[[[[ Previous Test Should Have Ignored But Did Not ]]]]"); \
ram54288 0:a7a43371b306 35 UNITY_OUTPUT_CHAR('\n'); \
ram54288 0:a7a43371b306 36 }
ram54288 0:a7a43371b306 37
ram54288 0:a7a43371b306 38 int SetToOneToFailInTearDown;
ram54288 0:a7a43371b306 39 int SetToOneMeanWeAlreadyCheckedThisGuy;
ram54288 0:a7a43371b306 40
ram54288 0:a7a43371b306 41 void setUp(void)
ram54288 0:a7a43371b306 42 {
ram54288 0:a7a43371b306 43 SetToOneToFailInTearDown = 0;
ram54288 0:a7a43371b306 44 SetToOneMeanWeAlreadyCheckedThisGuy = 0;
ram54288 0:a7a43371b306 45 }
ram54288 0:a7a43371b306 46
ram54288 0:a7a43371b306 47 void tearDown(void)
ram54288 0:a7a43371b306 48 {
ram54288 0:a7a43371b306 49 if (SetToOneToFailInTearDown == 1)
ram54288 0:a7a43371b306 50 TEST_FAIL_MESSAGE("<= Failed in tearDown");
ram54288 0:a7a43371b306 51 if ((SetToOneMeanWeAlreadyCheckedThisGuy == 0) && (Unity.CurrentTestFailed > 0))
ram54288 0:a7a43371b306 52 {
ram54288 0:a7a43371b306 53 UnityPrint("[[[[ Previous Test Should Have Passed But Did Not ]]]]");
ram54288 0:a7a43371b306 54 UNITY_OUTPUT_CHAR('\n');
ram54288 0:a7a43371b306 55 }
ram54288 0:a7a43371b306 56 }
ram54288 0:a7a43371b306 57
ram54288 0:a7a43371b306 58 TEST_CASE(0)
ram54288 0:a7a43371b306 59 TEST_CASE(44)
ram54288 0:a7a43371b306 60 TEST_CASE((90)+9)
ram54288 0:a7a43371b306 61 void test_TheseShouldAllPass(int Num)
ram54288 0:a7a43371b306 62 {
ram54288 0:a7a43371b306 63 TEST_ASSERT_TRUE(Num < 100);
ram54288 0:a7a43371b306 64 }
ram54288 0:a7a43371b306 65
ram54288 0:a7a43371b306 66 TEST_CASE(3)
ram54288 0:a7a43371b306 67 TEST_CASE(77)
ram54288 0:a7a43371b306 68 TEST_CASE( (99) + 1 - (1))
ram54288 0:a7a43371b306 69 void test_TheseShouldAllFail(int Num)
ram54288 0:a7a43371b306 70 {
ram54288 0:a7a43371b306 71 EXPECT_ABORT_BEGIN
ram54288 0:a7a43371b306 72 TEST_ASSERT_TRUE(Num > 100);
ram54288 0:a7a43371b306 73 VERIFY_FAILS_END
ram54288 0:a7a43371b306 74 }
ram54288 0:a7a43371b306 75
ram54288 0:a7a43371b306 76 TEST_CASE(1)
ram54288 0:a7a43371b306 77 TEST_CASE(44)
ram54288 0:a7a43371b306 78 TEST_CASE(99)
ram54288 0:a7a43371b306 79 TEST_CASE(98)
ram54288 0:a7a43371b306 80 void test_TheseAreEveryOther(int Num)
ram54288 0:a7a43371b306 81 {
ram54288 0:a7a43371b306 82 if (Num & 1)
ram54288 0:a7a43371b306 83 {
ram54288 0:a7a43371b306 84 EXPECT_ABORT_BEGIN
ram54288 0:a7a43371b306 85 TEST_ASSERT_TRUE(Num > 100);
ram54288 0:a7a43371b306 86 VERIFY_FAILS_END
ram54288 0:a7a43371b306 87 }
ram54288 0:a7a43371b306 88 else
ram54288 0:a7a43371b306 89 {
ram54288 0:a7a43371b306 90 TEST_ASSERT_TRUE(Num < 100);
ram54288 0:a7a43371b306 91 }
ram54288 0:a7a43371b306 92 }
ram54288 0:a7a43371b306 93
ram54288 0:a7a43371b306 94 void test_NormalPassesStillWork(void)
ram54288 0:a7a43371b306 95 {
ram54288 0:a7a43371b306 96 TEST_ASSERT_TRUE(1);
ram54288 0:a7a43371b306 97 }
ram54288 0:a7a43371b306 98
ram54288 0:a7a43371b306 99 void test_NormalFailsStillWork(void)
ram54288 0:a7a43371b306 100 {
ram54288 0:a7a43371b306 101 EXPECT_ABORT_BEGIN
ram54288 0:a7a43371b306 102 TEST_ASSERT_TRUE(0);
ram54288 0:a7a43371b306 103 VERIFY_FAILS_END
ram54288 0:a7a43371b306 104 }