File: custom_constraint2.c

package info (click to toggle)
cgreen 1.6.4-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,588 kB
  • sloc: ansic: 12,276; sh: 558; makefile: 474; cpp: 403; python: 181; xml: 33; sed: 13
file content (39 lines) | stat: -rw-r--r-- 1,405 bytes parent folder | download | duplicates (2)
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());
}