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
- Committer:
- sbouber1
- Date:
- 2016-06-14
- Revision:
- 31:1c50d2d8c155
- Parent:
- 30:cf12566013a5
- Child:
- 40:1668630544c7
File content as of revision 31:1c50d2d8c155:
#ifndef __TESTING_H__
#define __TESTING_H__
// #define RUN_TESTS
#ifdef RUN_TESTS
#define MAIN test_main
#else
#define MAIN real_main
#endif
#define MOCK(N, F) static inline float N(int i,int t) {return (F);}
#define DEF_MOCKS(A,B,C) MockSensorController temp(false,0,A); \
MockSensorController salt(false,0,B); \
MockSensorController prox(false,0,C);
#define ALARM_TEST(N,T,S,P,TIME) bool N(TestCase *tc) { \
DEF_MOCKS(T,S,P); \
AlarmController alarm(false,0,&temp,&salt,&prox); \
for(int i = 0; i < TIME; i++) { \
alarm.run(); \
Thread::wait(1000); \
} \
return alarm.is_error(); \
}
#define START_TESTS() int __num_failed=0; \
int __num_passed = 0; \
bool __pass = false;
#define TESTCASE(N,F) __pass = !TestCase(N,F).failed;\
if(__pass) __num_passed++; \
else __num_failed++;
#define END_TESTS() printf("====================================================\r\n"); \
printf("Ran a total of %d test cases\r\n", __num_passed + __num_failed); \
printf("Number of tests passed: %d\r\n", __num_passed); \
printf("Number of tests failed: %d\r\n", __num_failed); \
printf("====================================================\r\n");
#include "mbed.h"
class TestCase {
public:
TestCase(const char *name, bool (*evaluate)(TestCase *tc)) {
this->name = name;
this->evaluate = evaluate;
this->failed = false;
if(!failed && this->evaluate(this)) {
printf("TESTCASE %s PASSED!\r\n", this->name);
} else {
printf("TESTCASE %s FAILED!\r\n", this->name);
}
}
void assert(bool b, const char *error);
bool failed;
private:
const char *name;
bool (*evaluate)(TestCase *tc);
};
#endif