unity_fixture.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 "unity.h"
  10. #include "unity_internals.h"
  11. #include "unity_fixture_malloc_overrides.h"
  12. #include "unity_fixture_internals.h"
  13. int UnityMain(int argc, const char* argv[], void (*runAllTests)(void));
  14. #define TEST_GROUP(group)\
  15. static const char* TEST_GROUP_##group = #group
  16. #define TEST_SETUP(group) void TEST_##group##_SETUP(void);\
  17. void TEST_##group##_SETUP(void)
  18. #define TEST_TEAR_DOWN(group) void TEST_##group##_TEAR_DOWN(void);\
  19. void TEST_##group##_TEAR_DOWN(void)
  20. #define TEST(group, name) \
  21. void TEST_##group##_##name##_(void);\
  22. void TEST_##group##_##name##_run(void);\
  23. void TEST_##group##_##name##_run(void)\
  24. {\
  25. UnityTestRunner(TEST_##group##_SETUP,\
  26. TEST_##group##_##name##_,\
  27. TEST_##group##_TEAR_DOWN,\
  28. "TEST(" #group ", " #name ")",\
  29. TEST_GROUP_##group, #name,\
  30. __FILE__, __LINE__);\
  31. }\
  32. void TEST_##group##_##name##_(void)
  33. #define IGNORE_TEST(group, name) \
  34. void TEST_##group##_##name##_(void);\
  35. void TEST_##group##_##name##_run(void);\
  36. void TEST_##group##_##name##_run(void)\
  37. {\
  38. UnityIgnoreTest("IGNORE_TEST(" #group ", " #name ")", TEST_GROUP_##group, #name);\
  39. }\
  40. void TEST_##group##_##name##_(void)
  41. /* Call this for each test, insider the group runner */
  42. #define RUN_TEST_CASE(group, name) \
  43. { void TEST_##group##_##name##_run(void);\
  44. TEST_##group##_##name##_run(); }
  45. /* This goes at the bottom of each test file or in a separate c file */
  46. #define TEST_GROUP_RUNNER(group)\
  47. void TEST_##group##_GROUP_RUNNER(void);\
  48. void TEST_##group##_GROUP_RUNNER(void)
  49. /* Call this from main */
  50. #define RUN_TEST_GROUP(group)\
  51. { void TEST_##group##_GROUP_RUNNER(void);\
  52. TEST_##group##_GROUP_RUNNER(); }
  53. /* CppUTest Compatibility Macros */
  54. #ifndef UNITY_EXCLUDE_CPPUTEST_ASSERTS
  55. /* Sets a pointer and automatically restores it to its old value after teardown */
  56. #define UT_PTR_SET(ptr, newPointerValue) UnityPointer_Set((void**)&(ptr), (void*)(newPointerValue), __LINE__)
  57. #define TEST_ASSERT_POINTERS_EQUAL(expected, actual) TEST_ASSERT_EQUAL_PTR((expected), (actual))
  58. #define TEST_ASSERT_BYTES_EQUAL(expected, actual) TEST_ASSERT_EQUAL_HEX8(0xff & (expected), 0xff & (actual))
  59. #define FAIL(message) TEST_FAIL_MESSAGE((message))
  60. #define CHECK(condition) TEST_ASSERT_TRUE((condition))
  61. #define LONGS_EQUAL(expected, actual) TEST_ASSERT_EQUAL_INT((expected), (actual))
  62. #define STRCMP_EQUAL(expected, actual) TEST_ASSERT_EQUAL_STRING((expected), (actual))
  63. #define DOUBLES_EQUAL(expected, actual, delta) TEST_ASSERT_DOUBLE_WITHIN((delta), (expected), (actual))
  64. #endif
  65. /* You must compile with malloc replacement, as defined in unity_fixture_malloc_overrides.h */
  66. void UnityMalloc_MakeMallocFailAfterCount(int count);
  67. #endif /* UNITY_FIXTURE_H_ */