check_check_exit.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Check: a unit test framework for C
  3. * Copyright (C) 2001, 2002 Arien Malec
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2.1 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, write to the
  17. * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
  18. * MA 02110-1301, USA.
  19. */
  20. #include "../lib/libcompat.h"
  21. #include <stdlib.h>
  22. #include <signal.h>
  23. #include <stdio.h>
  24. #include <string.h>
  25. #include "check.h"
  26. #include "check_check.h"
  27. START_TEST(test_early_exit_normal)
  28. {
  29. exit(0);
  30. ck_abort_msg("Should've exitted...");
  31. }
  32. END_TEST
  33. START_TEST(test_early_exit_with_allowed_error)
  34. {
  35. exit(-1);
  36. ck_abort_msg("Should've exitted...");
  37. }
  38. END_TEST
  39. START_TEST(loop_early_exit_normal)
  40. {
  41. exit(0);
  42. ck_abort_msg("Should've exitted...");
  43. }
  44. END_TEST
  45. START_TEST(loop_early_exit_allowed_exit)
  46. {
  47. exit(-2);
  48. ck_abort_msg("Should've exitted...");
  49. }
  50. END_TEST
  51. START_TEST(loop_early_exit_signal_segv)
  52. {
  53. raise (SIGSEGV);
  54. ck_abort_msg("Should've exitted...");
  55. }
  56. END_TEST
  57. Suite *make_exit_suite(void)
  58. {
  59. Suite *s;
  60. TCase *tc;
  61. s = suite_create("Exit");
  62. tc = tcase_create("Core");
  63. suite_add_tcase (s, tc);
  64. tcase_add_test(tc,test_early_exit_normal);
  65. tcase_add_exit_test(tc,test_early_exit_with_allowed_error,-1);
  66. tcase_add_loop_test(tc,loop_early_exit_normal,0,5);
  67. tcase_add_loop_exit_test(tc,loop_early_exit_allowed_exit,-2,0,5);
  68. tcase_add_loop_test_raise_signal(tc, loop_early_exit_signal_segv, SIGSEGV, 0, 5);
  69. return s;
  70. }