log_test_helpers.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* Copyright (c) 2014-2016, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. #include "or.h"
  4. #ifndef TOR_LOG_TEST_HELPERS_H
  5. #define TOR_LOG_TEST_HELPERS_H
  6. typedef struct mock_saved_log_entry_t {
  7. int severity;
  8. const char *funcname;
  9. const char *suffix;
  10. const char *format;
  11. char *generated_msg;
  12. struct mock_saved_log_entry_t *next;
  13. } mock_saved_log_entry_t;
  14. void mock_saving_logv(int severity, log_domain_mask_t domain,
  15. const char *funcname, const char *suffix,
  16. const char *format, va_list ap)
  17. CHECK_PRINTF(5, 0);
  18. void mock_clean_saved_logs(void);
  19. const smartlist_t *mock_saved_logs(void);
  20. int setup_capture_of_logs(int new_level);
  21. void teardown_capture_of_logs(int prev);
  22. int mock_saved_log_has_message(const char *msg);
  23. int mock_saved_log_has_severity(int severity);
  24. int mock_saved_log_has_entry(void);
  25. #define expect_log_msg(str) \
  26. tt_assert_msg(mock_saved_log_has_message(str), \
  27. "expected log to contain " # str);
  28. #define expect_no_log_msg(str) \
  29. tt_assert_msg(!mock_saved_log_has_message(str), \
  30. "expected log to not contain " # str);
  31. #define expect_log_severity(severity) \
  32. tt_assert_msg(mock_saved_log_has_severity(severity), \
  33. "expected log to contain severity " # severity);
  34. #define expect_no_log_severity(severity) \
  35. tt_assert_msg(!mock_saved_log_has_severity(severity), \
  36. "expected log to not contain severity " # severity);
  37. #define expect_log_entry() \
  38. tt_assert_msg(mock_saved_log_has_entry(), \
  39. "expected log to contain entries");
  40. #define expect_no_log_entry() \
  41. tt_assert_msg(!mock_saved_log_has_entry(), \
  42. "expected log to not contain entries");
  43. #endif