test.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /* Copyright 2001,2002 Roger Dingledine, Matej Pfajfar. */
  2. /* See LICENSE for licensing information */
  3. /* $Id$ */
  4. #ifndef __TEST_H
  5. #define __TEST_H
  6. #include <string.h>
  7. #define STMT_BEGIN do {
  8. #define STMT_END } while (0)
  9. #define test_fail() \
  10. STMT_BEGIN \
  11. printf("\nFile %s: line %d (%s): assertion failed.", \
  12. __FILE__, \
  13. __LINE__, \
  14. __PRETTY_FUNCTION__); \
  15. return; \
  16. STMT_END
  17. #define test_assert(expr) \
  18. STMT_BEGIN \
  19. if(expr) { printf("."); } else { \
  20. printf("\nFile %s: line %d (%s): assertion failed: (%s)\n", \
  21. __FILE__, \
  22. __LINE__, \
  23. __PRETTY_FUNCTION__, \
  24. #expr); \
  25. return; \
  26. } STMT_END
  27. #define test_eq(expr1, expr2) \
  28. STMT_BEGIN \
  29. long v1=(long)(expr1), v2=(long)(expr2); \
  30. if(v1==v2) { printf("."); } else { \
  31. printf("\nFile %s: line %d (%s): Assertion failed: (%s==%s)\n"\
  32. " (%ld != %ld)\n", \
  33. __FILE__, \
  34. __LINE__, \
  35. __PRETTY_FUNCTION__, \
  36. #expr1, #expr2, \
  37. v1, v2); \
  38. return; \
  39. } STMT_END
  40. #define test_neq(expr1, expr2) \
  41. STMT_BEGIN \
  42. long v1=(long)(expr1), v2=(long)(expr2); \
  43. if(v1!=v2) { printf("."); } else { \
  44. printf("\nFile %s: line %d (%s): Assertion failed: (%s!=%s)\n"\
  45. " (%ld == %ld)\n", \
  46. __FILE__, \
  47. __LINE__, \
  48. __PRETTY_FUNCTION__, \
  49. #expr1, #expr2, \
  50. v1, v2); \
  51. return; \
  52. } STMT_END
  53. #define test_streq(expr1, expr2) \
  54. STMT_BEGIN \
  55. char *v1=(expr1), *v2=(expr2); \
  56. if(!strcmp(v1,v2)) { printf("."); } else { \
  57. printf("\nFile %s: line %d (%s): Assertion failed: (%s==%s)\n"\
  58. " (\"%s\" != \"%s\")\n", \
  59. __FILE__, \
  60. __LINE__, \
  61. __PRETTY_FUNCTION__, \
  62. #expr1, #expr2, \
  63. v1, v2); \
  64. return; \
  65. } STMT_END
  66. #define test_strneq(expr1, expr2) \
  67. STMT_BEGIN \
  68. char *v1=(expr1), *v2=(expr2); \
  69. if(strcmp(v1,v2)) { printf("."); } else { \
  70. printf("\nFile %s: line %d (%s): Assertion failed: (%s!=%s)\n"\
  71. " (\"%s\" == \"%s\")\n", \
  72. __FILE__, \
  73. __LINE__, \
  74. __PRETTY_FUNCTION__, \
  75. #expr1, #expr2, \
  76. v1, v2); \
  77. return; \
  78. } STMT_END
  79. #define test_memeq(expr1, expr2, len) \
  80. STMT_BEGIN \
  81. void *v1=(expr1), *v2=(expr2); \
  82. if(!memcmp(v1,v2,(len))) { printf("."); } else { \
  83. printf("\nFile %s: line %d (%s): Assertion failed: (%s==%s)\n", \
  84. __FILE__, \
  85. __LINE__, \
  86. __PRETTY_FUNCTION__, \
  87. #expr1, #expr2); \
  88. return; \
  89. } STMT_END
  90. #define test_memneq(expr1, expr2, len) \
  91. STMT_BEGIN \
  92. void *v1=(expr1), *v2=(expr2); \
  93. if(memcmp(v1,v2,(len))) { printf("."); } else { \
  94. printf("\nFile %s: line %d (%s): Assertion failed: (%s!=%s)\n", \
  95. __FILE__, \
  96. __LINE__, \
  97. __PRETTY_FUNCTION__, \
  98. #expr1, #expr2); \
  99. return; \
  100. } STMT_END
  101. #endif
  102. /*
  103. Local Variables:
  104. mode:c
  105. indent-tabs-mode:nil
  106. c-basic-offset:2
  107. End:
  108. */