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