assert.c 891 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. #undef NDEBUG
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <assert.h>
  12. #include <signal.h>
  13. #include "../testsuite.h"
  14. int got_abort;
  15. static void aborthandler(int junk)
  16. {
  17. got_abort = 1;
  18. }
  19. int main(int argc, char *argv[])
  20. {
  21. signal(SIGABRT, aborthandler);
  22. init_testsuite("Testing functions defined in assert.h:\n\t");
  23. got_abort=0;
  24. assert(0 == 0);
  25. TEST_NUMERIC(got_abort, 0);
  26. #define NDEBUG
  27. got_abort = 0;
  28. printf("Don't worry -- This next test is supposed to print an assert message:\n");
  29. fprintf(stderr, "\t");
  30. assert(0 == 1);
  31. TEST_NUMERIC(got_abort, 0);
  32. #undef NDEBUG
  33. got_abort = 0;
  34. assert(0 == 1);
  35. TEST_NUMERIC(got_abort, 1);
  36. exit(0);
  37. }