err_macros.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* This is part of the netCDF package.
  2. Copyright 2005 University Corporation for Atmospheric Research/Unidata
  3. See COPYRIGHT file for conditions of use.
  4. Common includes, defines, etc., for test code in the libsrc4 and
  5. nc_test4 directories.
  6. */
  7. #ifndef _ERR_MACROS_H
  8. #define _ERR_MACROS_H
  9. #include <config.h>
  10. #include <assert.h>
  11. #include <stdio.h>
  12. #include <string.h>
  13. #include <stdlib.h>
  14. /* Err is used to keep track of errors within each set of tests,
  15. * total_err is the number of errors in the entire test program, which
  16. * generally cosists of several sets of tests. */
  17. static int total_err = 0, err = 0;
  18. #if 0
  19. /* This is handy for print statements. */
  20. static char *format_name[] = {"", "classic", "64-bit offset", "netCDF-4",
  21. "netCDF-4 classic model"};
  22. #endif
  23. /* This macro prints an error message with line number and name of
  24. * test program. */
  25. #define ERR do { \
  26. fflush(stdout); /* Make sure our stdout is synced with stderr. */ \
  27. err++; \
  28. fprintf(stderr, "Sorry! Unexpected result, %s, line: %d\n", \
  29. __FILE__, __LINE__); \
  30. return 2; \
  31. } while (0)
  32. /* This macro prints an error message with line number and name of
  33. * test program, and then exits the program. */
  34. #define ERR_RET do { \
  35. fflush(stdout); /* Make sure our stdout is synced with stderr. */ \
  36. fprintf(stderr, "Sorry! Unexpected result, %s, line: %d\n", \
  37. __FILE__, __LINE__); \
  38. return 2; \
  39. } while (0)
  40. /* After a set of tests, report the number of errors, and increment
  41. * total_err. */
  42. #define SUMMARIZE_ERR do { \
  43. if (err) \
  44. { \
  45. printf("%d failures\n", err); \
  46. total_err += err; \
  47. err = 0; \
  48. } \
  49. else \
  50. printf("ok.\n"); \
  51. } while (0)
  52. /* If extra memory debugging is not in use (as it usually isn't),
  53. * define away the nc_exit function, which may be in some tests. */
  54. #ifndef EXTRA_MEM_DEBUG
  55. #define nc_exit()
  56. #endif
  57. /* This macro prints out our total number of errors, if any, and exits
  58. * with a 0 if there are not, or a 2 if there were errors. Make will
  59. * stop if a non-zero value is returned from a test program. */
  60. #define FINAL_RESULTS do { \
  61. if (total_err) \
  62. { \
  63. printf("%d errors detected! Sorry!\n", total_err); \
  64. return 2; \
  65. } \
  66. printf("*** Tests successful!\n"); \
  67. return 0; \
  68. } while (0)
  69. #endif /* _ERR_MACROS_H */