check_nofork.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 <stdio.h>
  23. #include <check.h>
  24. Suite *s;
  25. TCase *tc;
  26. SRunner *sr;
  27. START_TEST(test_nofork_exit)
  28. {
  29. char* s = NULL;
  30. ck_assert(NULL != s);
  31. /* this test should not crash in nofork mode */
  32. ck_assert_str_eq("test", s);
  33. }
  34. END_TEST
  35. #if !defined(HAVE_FORK) || HAVE_FORK == 0
  36. START_TEST(test_check_fork)
  37. {
  38. ck_assert_int_eq(-1, check_fork());
  39. }
  40. END_TEST
  41. #endif
  42. int main(void)
  43. {
  44. s = suite_create("NoFork");
  45. tc = tcase_create("Exit");
  46. sr = srunner_create(s);
  47. suite_add_tcase(s, tc);
  48. tcase_add_test(tc, test_nofork_exit);
  49. srunner_set_fork_status(sr, CK_NOFORK);
  50. srunner_run_all(sr, CK_MINIMAL);
  51. srunner_free(sr);
  52. #if !defined(HAVE_FORK) || HAVE_FORK == 0
  53. s = suite_create("NoForkSupport");
  54. tc = tcase_create("NoFork");
  55. sr = srunner_create(s);
  56. /* The following should not fail, but should be ignored */
  57. srunner_set_fork_status(sr, CK_FORK);
  58. if(srunner_fork_status(sr) != CK_NOFORK)
  59. {
  60. fprintf(stderr, "Call to srunner_set_fork_status() was not ignored\n");
  61. exit(1);
  62. }
  63. suite_add_tcase(s, tc);
  64. tcase_add_test(tc, test_check_fork);
  65. srunner_run_all(sr, CK_MINIMAL);
  66. srunner_free(sr);
  67. #endif
  68. return 0;
  69. }