util.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright (c) 2009-2012 Petri Lehtinen <petri@digip.org>
  3. *
  4. * Jansson is free software; you can redistribute it and/or modify
  5. * it under the terms of the MIT license. See LICENSE for details.
  6. */
  7. #ifndef UTIL_H
  8. #define UTIL_H
  9. #ifdef HAVE_CONFIG_H
  10. #include <config.h>
  11. #endif
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #if HAVE_LOCALE_H
  15. #include <locale.h>
  16. #endif
  17. #include <jansson.h>
  18. #define failhdr fprintf(stderr, "%s:%s:%d: ", __FILE__, __FUNCTION__, __LINE__)
  19. #define fail(msg) \
  20. do { \
  21. failhdr; \
  22. fprintf(stderr, "%s\n", msg); \
  23. exit(1); \
  24. } while(0)
  25. /* Assumes json_error_t error */
  26. #define check_error(text_, source_, line_, column_, position_) \
  27. do { \
  28. if(strcmp(error.text, text_) != 0) { \
  29. failhdr; \
  30. fprintf(stderr, "text: \"%s\" != \"%s\"\n", error.text, text_); \
  31. exit(1); \
  32. } \
  33. if(strcmp(error.source, source_) != 0) { \
  34. failhdr; \
  35. \
  36. fprintf(stderr, "source: \"%s\" != \"%s\"\n", error.source, source_); \
  37. exit(1); \
  38. } \
  39. if(error.line != line_) { \
  40. failhdr; \
  41. fprintf(stderr, "line: %d != %d\n", error.line, line_); \
  42. exit(1); \
  43. } \
  44. if(error.column != column_) { \
  45. failhdr; \
  46. fprintf(stderr, "column: %d != %d\n", error.column, column_); \
  47. exit(1); \
  48. } \
  49. if(error.position != position_) { \
  50. failhdr; \
  51. fprintf(stderr, "position: %d != %d\n", error.position, position_); \
  52. exit(1); \
  53. } \
  54. } while(0)
  55. static void run_tests();
  56. int main() {
  57. #ifdef HAVE_SETLOCALE
  58. setlocale(LC_ALL, "");
  59. #endif
  60. run_tests();
  61. return 0;
  62. }
  63. #endif
粤ICP备19079148号