unity_fixture.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* Copyright (c) 2010 James Grenning and Contributed to Unity Project
  2. * ==========================================
  3. * Unity Project - A Test Framework for C
  4. * Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
  5. * [Released under MIT License. Please refer to license.txt for details]
  6. * ========================================== */
  7. #ifndef UNITY_FIXTURE_H_
  8. #define UNITY_FIXTURE_H_
  9. #include "osi_compiler.h"
  10. OSI_EXTERN_C_BEGIN
  11. #include "unity.h"
  12. #include "unity_internals.h"
  13. #include "unity_fixture_malloc_overrides.h"
  14. #include "unity_fixture_internals.h"
  15. int UnityMain(int argc, const char* argv[], void (*runAllTests)(void));
  16. #define TEST_PROVIDE_APP_START(fn)\
  17. extern void fn(void);\
  18. void osiAppStart(void) { fn(); }
  19. #define TEST_GROUP(group)\
  20. static const char* TEST_GROUP_##group = #group
  21. #define TEST_SETUP(group) OSI_EXTERN_C void TEST_##group##_SETUP(void);\
  22. void TEST_##group##_SETUP(void)
  23. #define TEST_TEAR_DOWN(group) OSI_EXTERN_C void TEST_##group##_TEAR_DOWN(void);\
  24. void TEST_##group##_TEAR_DOWN(void)
  25. #define TEST(group, name) \
  26. OSI_EXTERN_C void TEST_##group##_##name##_(void);\
  27. OSI_EXTERN_C void TEST_##group##_##name##_run(void);\
  28. void TEST_##group##_##name##_run(void)\
  29. {\
  30. UnityTestRunner(TEST_##group##_SETUP,\
  31. TEST_##group##_##name##_,\
  32. TEST_##group##_TEAR_DOWN,\
  33. "TEST(" #group ", " #name ")",\
  34. TEST_GROUP_##group, #name,\
  35. __FILE__, __LINE__);\
  36. }\
  37. void TEST_##group##_##name##_(void)
  38. #define IGNORE_TEST(group, name) \
  39. OSI_EXTERN_C void TEST_##group##_##name##_(void);\
  40. OSI_EXTERN_C void TEST_##group##_##name##_run(void);\
  41. OSI_EXTERN_C void TEST_##group##_##name##_run(void)\
  42. {\
  43. UnityIgnoreTest("IGNORE_TEST(" #group ", " #name ")", TEST_GROUP_##group, #name);\
  44. }\
  45. void TEST_##group##_##name##_(void)
  46. /* Call this for each test, insider the group runner */
  47. #define RUN_TEST_CASE(group, name) \
  48. TEST_##group##_##name##_run();
  49. /* This goes at the bottom of each test file or in a separate c file */
  50. #define TEST_GROUP_RUNNER(group)\
  51. OSI_EXTERN_C void TEST_##group##_GROUP_RUNNER(void);\
  52. void TEST_##group##_GROUP_RUNNER(void)
  53. /* Call this from main */
  54. #define RUN_TEST_GROUP(group)\
  55. { OSI_EXTERN_C void TEST_##group##_GROUP_RUNNER(void);\
  56. TEST_##group##_GROUP_RUNNER(); }
  57. /* CppUTest Compatibility Macros */
  58. #ifndef UNITY_EXCLUDE_CPPUTEST_ASSERTS
  59. /* Sets a pointer and automatically restores it to its old value after teardown */
  60. #define UT_PTR_SET(ptr, newPointerValue) UnityPointer_Set((void**)&(ptr), (void*)(newPointerValue), __LINE__)
  61. #define TEST_ASSERT_POINTERS_EQUAL(expected, actual) TEST_ASSERT_EQUAL_PTR((expected), (actual))
  62. #define TEST_ASSERT_BYTES_EQUAL(expected, actual) TEST_ASSERT_EQUAL_HEX8(0xff & (expected), 0xff & (actual))
  63. #define FAIL(message) TEST_FAIL_MESSAGE((message))
  64. #define CHECK(condition) TEST_ASSERT_TRUE((condition))
  65. #define LONGS_EQUAL(expected, actual) TEST_ASSERT_EQUAL_INT((expected), (actual))
  66. #define STRCMP_EQUAL(expected, actual) TEST_ASSERT_EQUAL_STRING((expected), (actual))
  67. #define DOUBLES_EQUAL(expected, actual, delta) TEST_ASSERT_DOUBLE_WITHIN((delta), (expected), (actual))
  68. #endif
  69. /* You must compile with malloc replacement, as defined in unity_fixture_malloc_overrides.h */
  70. void UnityMalloc_MakeMallocFailAfterCount(int countdown);
  71. OSI_EXTERN_C_END
  72. #endif /* UNITY_FIXTURE_H_ */