dpkg-test.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * libdpkg - Debian packaging suite library routines
  3. * dpkg-test.h - private 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
  18. * License along with dpkg; if not, write to the Free Software
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21. #ifndef DPKG_TEST_H
  22. #define DPKG_TEST_H
  23. #include <config.h>
  24. #include <compat.h>
  25. #ifndef TEST_MAIN_PROVIDED
  26. #include <dpkg.h>
  27. #endif
  28. #include <assert.h>
  29. #include <string.h>
  30. /* XXX: Using assert is problematic with NDEBUG. */
  31. #define test_pass(a) assert((a))
  32. #define test_fail(a) assert(!(a))
  33. #define test_str(a, op, b) assert(strcmp((a), (b)) op 0)
  34. #define test_mem(a, op, b, size) assert(memcmp((a), (b), (size)) op 0)
  35. #ifndef TEST_MAIN_PROVIDED
  36. static void test(void);
  37. const char thisname[] = "test";
  38. int
  39. main(int argc, char **argv)
  40. {
  41. jmp_buf ejbuf;
  42. /* Initialize environment. */
  43. if (setjmp(ejbuf)) {
  44. error_unwind(ehflag_bombout);
  45. return 2;
  46. }
  47. push_error_handler(&ejbuf, print_error_fatal, NULL);
  48. test();
  49. /* Shutdown. */
  50. set_error_display(NULL, NULL);
  51. error_unwind(ehflag_normaltidy);
  52. return 0;
  53. }
  54. #endif
  55. #endif