Adds some macros used for mocking. Complementary library for bdd-for-c.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
757 B

  1. #ifndef BDD_FOR_C_MOCKS_H
  2. #define BDD_FOR_C_MOCKS_H
  3. #define mock_call_count_t unsigned char
  4. #define mock(X) static mock_call_count_t actual_##X = 0;
  5. #define mock_mode_t unsigned char
  6. #define mock_modes(X) static mock_mode_t current_mock_mode_##X = 0; enum mock_modes_##X
  7. #define mock_mode(X, Y) current_mock_mode_##X = Y
  8. #define mock_mode_if(X, Y) if (current_mock_mode_##X == Y)
  9. #define mock_return(X) actual_##X += 1; return
  10. #define mock_reset(X) actual_##X = 0
  11. #define mock_get_actual_calls(X) (mock_call_count_t) actual_##X
  12. #define mock_set_expected_calls(X, Y) static const mock_call_count_t expected_##X = Y
  13. #define mock_get_expected_calls(X) (mock_call_count_t) expected_##X
  14. #define mock_is_called(X) mock_get_actual_calls(X) > 0
  15. #endif