assert.c 892 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Test application for functions defined in ctype.h
  4. * Copyright (C) 2000-2006 by Erik Andersen <andersen@uclibc.org>
  5. *
  6. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  7. */
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <assert.h>
  11. #include <signal.h>
  12. #include "../testsuite.h"
  13. int got_abort;
  14. void aborthandler(int junk)
  15. {
  16. got_abort = 1;
  17. }
  18. int main(int argc, char *argv[])
  19. {
  20. signal(SIGABRT, aborthandler);
  21. init_testsuite("Testing functions defined in assert.h:\n\t");
  22. got_abort=0;
  23. assert(0 == 0);
  24. TEST_NUMERIC(got_abort, 0);
  25. #ifndef NDEBUG
  26. # define NDEBUG
  27. #endif
  28. got_abort = 0;
  29. printf("Don't worry -- This next test is supposed to print an assert message:\n");
  30. fprintf(stderr, "\t");
  31. assert(0 == 1);
  32. TEST_NUMERIC(got_abort, 0);
  33. #undef NDEBUG
  34. got_abort = 0;
  35. assert(0 == 1);
  36. TEST_NUMERIC(got_abort, 1);
  37. exit(0);
  38. }