diff options
author | Don Gagne <don@thegagnes.com> | 2014-09-02 15:33:43 -0700 |
---|---|---|
committer | Don Gagne <don@thegagnes.com> | 2014-09-02 15:33:43 -0700 |
commit | 1969c9ccf6797c4d86f32b9f57332a9e59071251 (patch) | |
tree | 1f75b06af386665d990a6f67f0879c4fc7560a86 /src/modules/unit_test/unit_test.h | |
parent | 6f0160bb5db552c921773f278e93d33862811a2a (diff) | |
download | px4-firmware-1969c9ccf6797c4d86f32b9f57332a9e59071251.tar.gz px4-firmware-1969c9ccf6797c4d86f32b9f57332a9e59071251.tar.bz2 px4-firmware-1969c9ccf6797c4d86f32b9f57332a9e59071251.zip |
Improved unit test framework
- Added init/cleanup calls before after test
- Added ut_compare macro with better failure reporting
Diffstat (limited to 'src/modules/unit_test/unit_test.h')
-rw-r--r-- | src/modules/unit_test/unit_test.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/modules/unit_test/unit_test.h b/src/modules/unit_test/unit_test.h index 32eb8c308..1a5489709 100644 --- a/src/modules/unit_test/unit_test.h +++ b/src/modules/unit_test/unit_test.h @@ -52,11 +52,15 @@ INLINE_GLOBAL(const char*, mu_last_test) UnitTest(); virtual ~UnitTest(); + + virtual void init(void) { }; + virtual void cleanup(void) { }; virtual void runTests(void) = 0; void printResults(void); void printAssert(const char* msg, const char* test, const char* file, int line); + void printCompare(const char* msg, const char *v1_text, int v1, const char *v2_text, int v2, const char* file, int line); #define ut_assert(message, test) \ do { \ @@ -68,10 +72,23 @@ INLINE_GLOBAL(const char*, mu_last_test) } \ } while (0) +#define ut_compare(message, v1, v2) \ + do { \ + int _v1 = v1; \ + int _v2 = v2; \ + if (_v1 != _v2) { \ + printCompare(message, #v1, _v1, #v2, _v2, __FILE__, __LINE__); \ + return false; \ + } else { \ + mu_assertion()++; \ + } \ + } while (0) + #define ut_run_test(test) \ do { \ warnx("RUNNING TEST: %s", #test); \ mu_tests_run()++; \ + init(); \ if (!test()) { \ warnx("TEST FAILED: %s", #test); \ mu_tests_failed()++; \ @@ -79,6 +96,7 @@ INLINE_GLOBAL(const char*, mu_last_test) warnx("TEST PASSED: %s", #test); \ mu_tests_passed()++; \ } \ + cleanup(); \ } while (0) }; |