assert.c 970 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include <stdio.h>
  2. #include "test.h"
  3. void test_assert_h(void)
  4. {
  5. int n = 0;
  6. testing_header("assert.h");
  7. #define NDEBUG
  8. #include <assert.h>
  9. testing_comment("Expression with side-effect should be removed by preprocessor");
  10. test_void(assert(n = 1));
  11. test_int_equals(n, 0);
  12. #undef NDEBUG
  13. #include <assert.h>
  14. testing_comment("Expression with side-effect should execute");
  15. test_void(assert(n = 1));
  16. test_int_equals(n, 1);
  17. #define NDEBUG
  18. #include <assert.h>
  19. testing_comment("Successful assertion should be removed by preprocessor");
  20. test_void(assert(n == 1));
  21. #undef NDEBUG
  22. #include <assert.h>
  23. testing_comment("Successful assertion should execute");
  24. test_void(assert(n == 1));
  25. #define NDEBUG
  26. #include <assert.h>
  27. testing_comment("Unsuccessful assertion should be removed by preprocessor");
  28. test_void(assert(n == 0));
  29. #undef NDEBUG
  30. #include <assert.h>
  31. testing_comment("Unsuccessful assertion should execute");
  32. test_void(assert(n == 0));
  33. testing_end();
  34. }