test.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * libdpkg - Debian packaging suite library routines
  3. * test.h - test suite support
  4. *
  5. * Copyright © 2009 Guillem Jover <guillem@debian.org>
  6. *
  7. * This is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2,
  10. * or (at your option) any later version.
  11. *
  12. * This is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #ifndef LIBDPKG_TEST_H
  21. #define LIBDPKG_TEST_H
  22. #include <config.h>
  23. #include <compat.h>
  24. #include <assert.h>
  25. #include <string.h>
  26. #ifndef TEST_MAIN_PROVIDED
  27. #include <dpkg/dpkg.h>
  28. #endif
  29. /* XXX: Using assert is problematic with NDEBUG. */
  30. #define test_pass(a) assert((a))
  31. #define test_fail(a) assert(!(a))
  32. #define test_str(a, op, b) assert(strcmp((a), (b)) op 0)
  33. #define test_mem(a, op, b, size) assert(memcmp((a), (b), (size)) op 0)
  34. #ifndef TEST_MAIN_PROVIDED
  35. static void test(void);
  36. const char thisname[] = "test";
  37. int
  38. main(int argc, char **argv)
  39. {
  40. jmp_buf ejbuf;
  41. /* Initialize environment. */
  42. if (setjmp(ejbuf)) {
  43. error_unwind(ehflag_bombout);
  44. return 2;
  45. }
  46. push_error_handler(&ejbuf, print_error_fatal, NULL);
  47. test();
  48. /* Shutdown. */
  49. set_error_display(NULL, NULL);
  50. error_unwind(ehflag_normaltidy);
  51. return 0;
  52. }
  53. #endif
  54. #endif