| 1 | #include <cgreen/cgreen.h> |
| 2 | #include <cgreen/message_formatting.h> |
| 3 | #include "cgreen_value_internal.h" |
| 4 | #include "utils.h" |
| 5 | |
| 6 | Describe(TestConstraint); |
| 7 | BeforeEach(TestConstraint) {} |
| 8 | AfterEach(TestConstraint) {} |
| 9 | |
| 10 | bool compare_want_smaller_value(Constraint *constraint, CgreenValue actual) { |
| 11 | return actual.value.integer_value < constraint->expected_value.value.integer_value ; |
| 12 | } |
| 13 | |
| 14 | Constraint *create_smaller_than_constraint(intptr_t expected_value, const char *expected_value_name) { |
| 15 | Constraint *constraint = create_constraint(); |
| 16 | |
| 17 | constraint->expected_value = make_cgreen_integer_value(expected_value); |
| 18 | constraint->expected_value_name = string_dup(expected_value_name); |
| 19 | constraint->type = CGREEN_VALUE_COMPARER_CONSTRAINT; |
| 20 | |
| 21 | constraint->compare = &compare_want_smaller_value; |
| 22 | constraint->execute = &test_want; |
| 23 | constraint->name = "be smaller than"; |
| 24 | constraint->size_of_expected_value = sizeof(intptr_t); |
| 25 | |
| 26 | return constraint; |
| 27 | } |
| 28 | #define is_smaller_than(value) create_smaller_than_constraint(value, #value) |
| 29 | |
| 30 | |
| 31 | Ensure(TestConstraint, custom_constraint_using_a_function_with_arguments_function) { |
| 32 | assert_that(9, is_smaller_than(10)); |
| 33 | } |
| 34 | |
| 35 | int main(int argc, char **argv) { |
| 36 | TestSuite *suite = create_test_suite(); |
| 37 | add_test_with_context(suite, TestConstraint, custom_constraint_using_a_function_with_arguments_function); |
| 38 | run_test_suite(suite, create_text_reporter()); |
| 39 | } |