unity_config.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #ifndef UNITY_CONFIG_H
  2. #define UNITY_CONFIG_H
  3. // This file gets included from unity.h via unity_internals.h
  4. // It is inside #ifdef __cplusplus / extern "C" block, so we can
  5. // only use C features here
  6. // Adapt Unity to our environment, disable FP support
  7. #include <esp_err.h>
  8. /* Some definitions applicable to Unity running in FreeRTOS */
  9. #define UNITY_FREERTOS_PRIORITY 5
  10. #define UNITY_FREERTOS_CPU 0
  11. #define UNITY_EXCLUDE_FLOAT
  12. #define UNITY_EXCLUDE_DOUBLE
  13. #define UNITY_OUTPUT_CHAR unity_putc
  14. #define UNITY_OUTPUT_FLUSH unity_flush
  15. // Define helpers to register test cases from multiple files
  16. #define UNITY_EXPAND2(a, b) a ## b
  17. #define UNITY_EXPAND(a, b) UNITY_EXPAND2(a, b)
  18. #define UNITY_TEST_UID(what) UNITY_EXPAND(what, __LINE__)
  19. #define UNITY_TEST_REG_HELPER reg_helper ## UNITY_TEST_UID
  20. #define UNITY_TEST_DESC_UID desc ## UNITY_TEST_UID
  21. struct test_desc_t
  22. {
  23. const char* name;
  24. const char* desc;
  25. void (*fn)(void);
  26. const char* file;
  27. int line;
  28. struct test_desc_t* next;
  29. };
  30. void unity_testcase_register(struct test_desc_t* desc);
  31. void unity_run_menu();
  32. void unity_run_tests_with_filter(const char* filter);
  33. void unity_run_all_tests();
  34. /* Test case macro, a-la CATCH framework.
  35. First argument is a free-form description,
  36. second argument is (by convention) a list of identifiers, each one in square brackets.
  37. Identifiers are used to group related tests, or tests with specific properties.
  38. Use like:
  39. TEST_CASE("Frobnicator forbnicates", "[frobnicator][rom]")
  40. {
  41. // test goes here
  42. }
  43. */
  44. #define TEST_CASE(name_, desc_) \
  45. static void UNITY_TEST_UID(test_func_) (void); \
  46. static void __attribute__((constructor)) UNITY_TEST_UID(test_reg_helper_) () \
  47. { \
  48. static struct test_desc_t UNITY_TEST_UID(test_desc_) = { \
  49. .name = name_, \
  50. .desc = desc_, \
  51. .fn = &UNITY_TEST_UID(test_func_), \
  52. .file = __FILE__, \
  53. .line = __LINE__, \
  54. .next = NULL \
  55. }; \
  56. unity_testcase_register( & UNITY_TEST_UID(test_desc_) ); \
  57. }\
  58. static void UNITY_TEST_UID(test_func_) (void)
  59. /**
  60. * Note: initialization of test_desc_t fields above has to be done exactly
  61. * in the same order as the fields are declared in the structure.
  62. * Otherwise the initializer will not be valid in C++ (which doesn't
  63. * support designated initializers). G++ can parse the syntax, but
  64. * field names are treated as annotations and don't affect initialization
  65. * order. Also make sure all the fields are initialized.
  66. */
  67. // shorthand to check esp_err_t return code
  68. #define TEST_ESP_OK(rc) TEST_ASSERT_EQUAL_HEX32(ESP_OK, rc)
  69. #define TEST_ESP_ERR(err, rc) TEST_ASSERT_EQUAL_HEX32(err, rc)
  70. #endif //UNITY_CONFIG_H