aboutsummaryrefslogtreecommitdiff
path: root/src/test/log_test_helpers.h
blob: 1966f170fb6cb8d054b3611ea424c6bf31d31ae7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* Copyright (c) 2014-2016, The Tor Project, Inc. */
/* See LICENSE for licensing information */

#include "or.h"

#ifndef TOR_LOG_TEST_HELPERS_H
#define TOR_LOG_TEST_HELPERS_H

typedef struct mock_saved_log_entry_t {
  int severity;
  const char *funcname;
  const char *suffix;
  const char *format;
  char *generated_msg;
  struct mock_saved_log_entry_t *next;
} mock_saved_log_entry_t;

void mock_saving_logv(int severity, log_domain_mask_t domain,
                      const char *funcname, const char *suffix,
                      const char *format, va_list ap)
  CHECK_PRINTF(5, 0);
void mock_clean_saved_logs(void);
const smartlist_t *mock_saved_logs(void);
int setup_capture_of_logs(int new_level);
void teardown_capture_of_logs(int prev);

int mock_saved_log_has_message(const char *msg);
int mock_saved_log_has_severity(int severity);
int mock_saved_log_has_entry(void);

#define expect_log_msg(str) \
  tt_assert_msg(mock_saved_log_has_message(str), \
                "expected log to contain " # str);

#define expect_no_log_msg(str) \
  tt_assert_msg(!mock_saved_log_has_message(str), \
                "expected log to not contain " # str);

#define expect_log_severity(severity) \
  tt_assert_msg(mock_saved_log_has_severity(severity), \
                "expected log to contain severity " # severity);

#define expect_no_log_severity(severity) \
  tt_assert_msg(!mock_saved_log_has_severity(severity), \
                "expected log to not contain severity " # severity);

#define expect_log_entry() \
  tt_assert_msg(mock_saved_log_has_entry(), \
                "expected log to contain entries");

#define expect_no_log_entry() \
  tt_assert_msg(!mock_saved_log_has_entry(), \
                "expected log to not contain entries");

#endif