| 1 | #include <cgreen/cgreen.h> |
| 2 | #include <cgreen/mocks.h> |
| 3 | #include <cgreen/constraint.h> |
| 4 | |
| 5 | #include <stdio.h> |
| 6 | #include <stdlib.h> |
| 7 | #include <unistd.h> |
| 8 | |
| 9 | #ifdef __cplusplus |
| 10 | using namespace cgreen; |
| 11 | #endif |
| 12 | |
| 13 | Describe(AssertionMessage); |
| 14 | BeforeEach(AssertionMessage) {} |
| 15 | AfterEach(AssertionMessage) {} |
| 16 | |
| 17 | |
| 18 | char something[42]; |
| 19 | Ensure(AssertionMessage, for_comparing_content_with_negative_length) { |
| 20 | assert_that(47, is_equal_to_contents_of(something, -4)); |
| 21 | } |
| 22 | |
| 23 | Ensure(AssertionMessage, return_value_constraints_are_not_allowed) { |
| 24 | assert_that(0, will_return(1)); |
| 25 | } |
| 26 | |
| 27 | Ensure(AssertionMessage, for_compare_area_to_null) { |
| 28 | char area[100]; |
| 29 | void *null_pointer = NULL; |
| 30 | assert_that(area, is_equal_to_contents_of(null_pointer, 1)); |
| 31 | } |
| 32 | |
| 33 | Ensure(AssertionMessage, for_compare_null_to_area) { |
| 34 | char area[100]; |
| 35 | assert_that(NULL, is_equal_to_contents_of(area, 1)); |
| 36 | } |
| 37 | |
| 38 | Ensure(AssertionMessage, for_actual_with_percent) { |
| 39 | assert_that(strlen("%d"), is_equal_to(3)); /* Actually, it's not but should preserve '%' */ |
| 40 | } |
| 41 | |
| 42 | /* CAUTION: These two tests outputs the expected warning messages, but |
| 43 | also fails the comparisons, obviously, since that is what they try |
| 44 | to warn against. So the output of those failed constraints might |
| 45 | change unintentionally. */ |
| 46 | Ensure(AssertionMessage, for_using_double_constraints_with_assert_that) { |
| 47 | assert_that(3, is_equal_to_double(3.1415926)); |
| 48 | assert_that(0, is_less_than_double(3.1415926)); |
| 49 | assert_that(7, is_greater_than_double(3.1415926)); |
| 50 | } |
| 51 | |
| 52 | Ensure(AssertionMessage, for_using_non_double_constraints_with_assert_that_double) { |
| 53 | assert_that_double(3, is_equal_to(3)); |
| 54 | } |