assert.c 859 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. #define NDEBUG
  26. got_abort=0;
  27. printf("Don't worry -- This next test is supposed to print an assert message:\n");
  28. fprintf(stderr, "\t");
  29. assert(0==1);
  30. TEST_NUMERIC(got_abort, 0);
  31. #undef NDEBUG
  32. got_abort=0;
  33. assert(0==1);
  34. TEST_NUMERIC(got_abort, 1);
  35. exit(0);
  36. }