curlcheck.h 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
  9. *
  10. * This software is licensed as described in the file COPYING, which
  11. * you should have received as part of this distribution. The terms
  12. * are also available at http://curl.haxx.se/docs/copyright.html.
  13. *
  14. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. * copies of the Software, and permit persons to whom the Software is
  16. * furnished to do so, under the terms of the COPYING file.
  17. *
  18. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. * KIND, either express or implied.
  20. *
  21. ***************************************************************************/
  22. #include "test.h"
  23. /* The fail macros mark the current test step as failed, and continue */
  24. #define fail_if(expr, msg) \
  25. if(expr) { \
  26. fprintf(stderr, "%s:%d Assertion '%s' met: %s\n" , \
  27. __FILE__, __LINE__, #expr, msg); \
  28. unitfail++; \
  29. }
  30. #define fail_unless(expr, msg) \
  31. if(!(expr)) { \
  32. fprintf(stderr, "%s:%d Assertion '%s' failed: %s\n", \
  33. __FILE__, __LINE__, #expr, msg); \
  34. unitfail++; \
  35. }
  36. #define verify_memory(dynamic, check, len) \
  37. if(dynamic && memcmp(dynamic, check, len)) { \
  38. fprintf(stderr, "%s:%d The dynamic string didn't match '%s'\n", \
  39. __FILE__, __LINE__, check); \
  40. unitfail++; \
  41. }
  42. /* fail() is for when the test case figured out by itself that a check
  43. proved a failure */
  44. #define fail(msg) do { \
  45. fprintf(stderr, "%s:%d test failed: '%s'\n", \
  46. __FILE__, __LINE__, msg); \
  47. unitfail++; \
  48. } WHILE_FALSE
  49. /* The abort macros mark the current test step as failed, and exit the test */
  50. #define abort_if(expr, msg) \
  51. if(expr) { \
  52. fprintf(stderr, "%s:%d Abort assertion '%s' met: %s\n" , \
  53. __FILE__, __LINE__, #expr, msg); \
  54. unitfail++; \
  55. goto unit_test_abort; \
  56. }
  57. #define abort_unless(expr, msg) \
  58. if(!(expr)) { \
  59. fprintf(stderr, "%s:%d Abort assertion '%s' failed: %s\n", \
  60. __FILE__, __LINE__, #expr, msg); \
  61. unitfail++; \
  62. goto unit_test_abort; \
  63. }
  64. #define abort_test(msg) do { \
  65. fprintf(stderr, "%s:%d test aborted: '%s'\n", \
  66. __FILE__, __LINE__, msg); \
  67. unitfail++; \
  68. goto unit_test_abort; \
  69. } WHILE_FALSE
  70. extern int unitfail;
  71. #define UNITTEST_START \
  72. int test(char *arg) \
  73. { \
  74. (void)arg; \
  75. if (unit_setup()) { \
  76. fail("unit_setup() failure"); \
  77. } else {
  78. #define UNITTEST_STOP \
  79. goto unit_test_abort; /* avoid warning */ \
  80. unit_test_abort: \
  81. unit_stop(); \
  82. } \
  83. return unitfail; \
  84. }