test.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * libdpkg - Debian packaging suite library routines
  3. * test.h - test suite support
  4. *
  5. * Copyright © 2009-2012 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 published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This is distributed in the hope that it will be useful,
  13. * but 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 <assert.h>
  23. #include <string.h>
  24. #ifndef TEST_MAIN_PROVIDED
  25. #include <dpkg/ehandle.h>
  26. #endif
  27. /* Make sure NDEBUG is never defined, as we rely on the assert() macro. */
  28. #undef NDEBUG
  29. #define test_pass(a) assert((a))
  30. #define test_fail(a) assert(!(a))
  31. #define test_str(a, op, b) assert(strcmp((a), (b)) op 0)
  32. #define test_mem(a, op, b, size) assert(memcmp((a), (b), (size)) op 0)
  33. #ifndef TEST_MAIN_PROVIDED
  34. static void test(void);
  35. int
  36. main(int argc, char **argv)
  37. {
  38. push_error_context();
  39. test();
  40. pop_error_context(ehflag_normaltidy);
  41. return 0;
  42. }
  43. #endif
  44. #endif