test.c 957 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <stdlib.h>
  4. #include <stdarg.h>
  5. #include <string.h>
  6. #include <setjmp.h>
  7. #include <cmocka.h>
  8. static int
  9. setup(void **state) {
  10. int *answer = malloc(sizeof(int));
  11. *answer = 42;
  12. *state = answer;
  13. return 0;
  14. }
  15. static int
  16. teardown(void **state) {
  17. free(*state);
  18. return 0;
  19. }
  20. static void
  21. null_test_success(void **state) {
  22. (void) state;
  23. }
  24. static void
  25. int_test_success(void **state) {
  26. int *answer = *state;
  27. assert_int_equal(*answer, 42);
  28. }
  29. static void
  30. failing_test(void **state) {
  31. /* This tests fails to test that make check fails */
  32. assert_int_equal(0, 42);
  33. }
  34. int
  35. main(void) {
  36. const struct CMUnitTest tests[] = {
  37. cmocka_unit_test(null_test_success),
  38. cmocka_unit_test_setup_teardown(int_test_success, setup, teardown),
  39. /* cmocka_unit_test(failing_test), */
  40. };
  41. return cmocka_run_group_tests_name("success_test", tests, NULL, NULL);
  42. }