summaryrefslogtreecommitdiff
path: root/src/common/test.h
blob: 187828e9211669ebc8da291564b26280ba9bbe29 (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/* Copyright 2001,2002 Roger Dingledine, Matej Pfajfar. */
/* See LICENSE for licensing information */
/* $Id$ */

#ifndef __TEST_H
#define __TEST_H

#define test_fail()                                             \
  if (1) {                                                      \
    printf("\nFile %s: line %d (%s): assertion failed.",        \
      __FILE__,                                                 \
      __LINE__,                                                 \
      __PRETTY_FUNCTION__);                                     \
    return;                                                     \
  }

#define test_assert(expr)                                       \
  if(expr) { printf("."); } else {                              \
    printf("\nFile %s: line %d (%s): assertion failed: (%s)\n", \
      __FILE__,                                                 \
      __LINE__,                                                 \
      __PRETTY_FUNCTION__,                                      \
      #expr);                                                   \
    return;                                                     \
  }

#define test_eq(expr1, expr2)                                   \
  if(expr1==expr2) { printf("."); } else {                      \
    printf("\nFile %s: line %d (%s): Assertion failed: (%s==%s)\n"\
           "      (%ld != %ld)\n",                              \
      __FILE__,                                                 \
      __LINE__,                                                 \
      __PRETTY_FUNCTION__,                                      \
      #expr1, #expr2,                                           \
      (long)expr1, (long)expr2);                                \
    return;                                                     \
  }

#define test_neq(expr1, expr2)                                  \
  if(expr1!=expr2) { printf("."); } else {                      \
    printf("\nFile %s: line %d (%s): Assertion failed: (%s!=%s)\n"\
           "      (%ld == %ld)\n",                              \
      __FILE__,                                                 \
      __LINE__,                                                 \
      __PRETTY_FUNCTION__,                                      \
      #expr1, #expr2,                                           \
      (long)expr1, (long)expr2);                                \
    return;                                                     \
  }

#define test_streq(expr1, expr2)                                \
  if(!strcmp(expr1,expr2)) { printf("."); } else {              \
    printf("\nFile %s: line %d (%s): Assertion failed: (%s==%s)\n"\
           "      (%s != %s)\n",                                \
      __FILE__,                                                 \
      __LINE__,                                                 \
      __PRETTY_FUNCTION__,                                      \
      #expr1, #expr2,                                           \
      (long)expr1, (long)expr2);                                \
    return;                                                     \
  }

#define test_strneq(expr1, expr2)                               \
  if(strcmp(expr1,expr2)) { printf("."); } else {               \
    printf("\nFile %s: line %d (%s): Assertion failed: (%s!=%s)\n"\
           "      (%s == %s)\n",                                \
      __FILE__,                                                 \
      __LINE__,                                                 \
      __PRETTY_FUNCTION__,                                      \
      #expr1, #expr2,                                           \
      expr1, expr2);                                            \
    return;                                                     \
  }

#endif