Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed DRV88255 TextLCD Ping mbed-rtos
testing.h
00001 #ifndef __TESTING_H__ 00002 #define __TESTING_H__ 00003 00004 00005 #include "mbed.h" 00006 #include "settings.h" 00007 00008 class TestCase { 00009 00010 public: 00011 TestCase(const char *name, bool (*evaluate)(TestCase *tc)) { 00012 this->name = name; 00013 this->evaluate = evaluate; 00014 this->failed = false; 00015 00016 if(!failed && this->evaluate(this)) { 00017 printf("TESTCASE %s PASSED!\r\n", this->name); 00018 } else { 00019 printf("TESTCASE %s FAILED!\r\n", this->name); 00020 } 00021 } 00022 00023 void assert(bool b, const char *error); 00024 00025 bool failed; 00026 00027 private: 00028 const char *name; 00029 bool (*evaluate)(TestCase *tc); 00030 00031 }; 00032 00033 00034 #define MOCK(N, F) static inline float N(int i,int t) {return (F);} 00035 00036 #define DEF_MOCKS(A,B,C) MockSensorController temp(false,0,A); \ 00037 MockSensorController salt(false,0,B); \ 00038 MockSensorController prox(false,0,C); 00039 00040 #define ALARM_TEST(N,T,S,P,TIME) bool N(TestCase *tc) { \ 00041 DEF_MOCKS(T,S,P); \ 00042 SensorAlarmController temp_alarm(false,0,&temp,TEMP_MIN_CRIT, TEMP_MIN_UNDESIRED, TEMP_MAX_CRIT, TEMP_MAX_UNDESIRED); \ 00043 SensorAlarmController salt_alarm(false,0,&salt,SALT_MIN_CRIT, SALT_MIN_UNDESIRED, SALT_MAX_CRIT, SALT_MAX_UNDESIRED); \ 00044 SensorAlarmController prox_alarm(false,0,&salt,VOLUME_MIN_CRIT, VOLUME_MIN_UNDESIRED, VOLUME_MAX_CRIT, VOLUME_MAX_UNDESIRED); \ 00045 for(int i = 0; i < TIME; i++) { \ 00046 temp_alarm.run(); \ 00047 salt_alarm.run(); \ 00048 prox_alarm.run(); \ 00049 Thread::wait(1000); \ 00050 } \ 00051 return temp_alarm.isError() || salt_alarm.isError() || prox_alarm.isError(); \ 00052 } 00053 00054 #define START_TESTS() int __num_failed=0; \ 00055 int __num_passed = 0; \ 00056 bool __pass = false; 00057 00058 #define TESTCASE(N,F) __pass = !TestCase(N,F).failed;\ 00059 if(__pass) __num_passed++; \ 00060 else __num_failed++; 00061 00062 #define END_TESTS() printf("====================================================\r\n"); \ 00063 printf("Ran a total of %d test cases\r\n", __num_passed + __num_failed); \ 00064 printf("Number of tests passed: %d\r\n", __num_passed); \ 00065 printf("Number of tests failed: %d\r\n", __num_failed); \ 00066 printf("====================================================\r\n"); 00067 00068 00069 00070 #endif
Generated on Tue Jul 12 2022 18:59:29 by
1.7.2