| 1 | #cxx . . $ `<file>/tests/custom_constraint_messages_tests.c`/include <cgreen/cgreen.h>cxx . . $ `<file>/include/cgreen/cgreen.h`/ |
| 2 | #include <cgreen/message_formatting.h>cxx . . $ `<file>/include/cgreen/message_formatting.h`/ |
| 3 | #include "constraint_internal.h"cxx . . $ `<file>/src/constraint_internal.h`/ |
| 4 | #include "cgreen_value_internal.h"cxx . . $ `<file>/src/cgreen_value_internal.h`/ |
| 5 | #include "utils.h"cxx . . $ `<file>/src/utils.h`/ |
| 6 | |
| 7 | Describecxx . . $ `include/cgreen/unit.h:12:9`!(CustomConstraint); |
| 8 | BeforeEachcxx . . $ `include/cgreen/unit.h:15:9`!(CustomConstraint) {} |
| 9 | AfterEachcxx . . $ `include/cgreen/unit.h:18:9`!(CustomConstraint) {} |
| 10 | |
| 11 | |
| 12 | /* Example 1 from documentation : is_bigger_than_5() |
| 13 | |
| 14 | No argument to the constraint. |
| 15 | |
| 16 | */ |
| 17 | |
| 18 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! compare_want_greater_than_5cxx . . $ compare_want_greater_than_5(967c8d0e1b1425dd).(Constraintcxx . . $ Constraint# *constraint, CgreenValuecxx . . $ CgreenValue# actual) { |
| 19 | (void)constraint; |
| 20 | return actual.valuecxx . . $ $anonymous_type_b16cac6eed758fe0_1#value..integer_valuecxx . . $ $anonymous_type_b16cac6eed758fe0_1#$anonymous_type_2#integer_value. > 5; |
| 21 | } |
| 22 | |
| 23 | Constraintcxx . . $ Constraint# static_is_bigger_than_5cxx . . $ static_is_bigger_than_5. = { |
| 24 | /* .type */ CGREEN_VALUE_COMPARER_CONSTRAINTcxx . . $ CGREEN_VALUE_COMPARER_CONSTRAINT., |
| 25 | /* .name */ "be bigger than 5", |
| 26 | /* .destroy */ destroy_static_constraintcxx . . $ destroy_static_constraint(f159a969fe179808)., |
| 27 | /* .compare */ compare_want_greater_than_5cxx . . $ compare_want_greater_than_5(967c8d0e1b1425dd)., |
| 28 | /* .test */ test_wantcxx . . $ test_want(c0af3e8d8bd2e1e5)., |
| 29 | /* .format_failure_message_for */ failure_message_forcxx . . $ failure_message_for(12dea272953de187)., |
| 30 | /* .actual_value_message */ "", |
| 31 | /* .expected_value_message */ "", |
| 32 | /* .expected_value */ {CGREEN_INTEGERcxx . . $ CGREEN_INTEGER., {5}, 0}, |
| 33 | /* .stored_value_name */ "null", |
| 34 | /* .parameter_name */ NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, |
| 35 | /* .size_of_stored_value */ 0, |
| 36 | /* .side_effect_callback */ NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, |
| 37 | /* .side_effect_data */ NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`! |
| 38 | }; |
| 39 | |
| 40 | /* Remember: failing tests to get output */ |
| 41 | Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(CustomConstraint, custom_constraint_using_static_function) { |
| 42 | Constraintcxx . . $ Constraint# * is_bigger_than_5 = &static_is_bigger_than_5cxx . . $ static_is_bigger_than_5.; |
| 43 | assert_thatcxx . . $ `include/cgreen/assertions.h:30:9`!(1, is_bigger_than_5); |
| 44 | } |
| 45 | |
| 46 | |
| 47 | /* Example 2 from documentation : is_smaller_than() |
| 48 | |
| 49 | Standard data type argument to constraint. |
| 50 | |
| 51 | */ |
| 52 | |
| 53 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! compare_want_smaller_valuecxx . . $ compare_want_smaller_value(967c8d0e1b1425dd).(Constraintcxx . . $ Constraint# *constraint, CgreenValuecxx . . $ CgreenValue# actual) { |
| 54 | return actual.valuecxx . . $ $anonymous_type_b16cac6eed758fe0_1#value..integer_valuecxx . . $ $anonymous_type_b16cac6eed758fe0_1#$anonymous_type_2#integer_value. < constraint->expected_valuecxx . . $ Constraint_#expected_value..valuecxx . . $ $anonymous_type_b16cac6eed758fe0_1#value..integer_valuecxx . . $ $anonymous_type_b16cac6eed758fe0_1#$anonymous_type_2#integer_value. ; |
| 55 | } |
| 56 | |
| 57 | Constraintcxx . . $ Constraint# *create_smaller_than_constraintcxx . . $ create_smaller_than_constraint(f83092978cf2a14d).(intptr_tcxx . . $ intptr_t# expected_value, const char *expected_value_name) { |
| 58 | Constraintcxx . . $ Constraint# *constraint = create_constraintcxx . . $ create_constraint(ba55e2de72051eb6).(); |
| 59 | |
| 60 | constraint->expected_valuecxx . . $ Constraint_#expected_value. = make_cgreen_integer_valuecxx . . $ make_cgreen_integer_value(1194b204c86a8e67).(expected_value); |
| 61 | constraint->expected_value_namecxx . . $ Constraint_#expected_value_name. = string_dupcxx . . $ string_dup(a8b8e32347182212).(expected_value_name); |
| 62 | constraint->typecxx . . $ Constraint_#type. = CGREEN_VALUE_COMPARER_CONSTRAINTcxx . . $ CGREEN_VALUE_COMPARER_CONSTRAINT.; |
| 63 | |
| 64 | constraint->comparecxx . . $ Constraint_#compare. = &compare_want_smaller_valuecxx . . $ compare_want_smaller_value(967c8d0e1b1425dd).; |
| 65 | constraint->executecxx . . $ Constraint_#execute. = &test_wantcxx . . $ test_want(c0af3e8d8bd2e1e5).; |
| 66 | constraint->namecxx . . $ Constraint_#name. = "be smaller than"; |
| 67 | constraint->size_of_expected_valuecxx . . $ Constraint_#size_of_expected_value. = sizeof(intptr_tcxx . . $ intptr_t#); |
| 68 | |
| 69 | return constraint; |
| 70 | } |
| 71 | #define is_smaller_thancxx . . $ `tests/custom_constraint_messages_tests.c:71:9`!(value) create_smaller_than_constraint(value, #value) |
| 72 | |
| 73 | |
| 74 | Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(CustomConstraint, custom_constraint_using_a_function_with_arguments_function) { |
| 75 | assert_thatcxx . . $ `include/cgreen/assertions.h:30:9`!(19, is_smaller_thancxx . . $ `tests/custom_constraint_messages_tests.c:71:9`!(10)); |
| 76 | } |
| 77 | |
| 78 | |
| 79 | /* Example 3 from documentation : can_fit_in_box() |
| 80 | |
| 81 | Using custom data types. |
| 82 | |
| 83 | */ |
| 84 | typedef struct Structcxx . . $ Struct# { |
| 85 | char idcxx . . $ Struct#id.; |
| 86 | int sizecxx . . $ Struct#size.; |
| 87 | } Structcxx . . $ Struct#; |
| 88 | |
| 89 | typedef struct Piececxx . . $ Piece# { |
| 90 | char idcxx . . $ Piece#id.; |
| 91 | int sizecxx . . $ Piece#size.; |
| 92 | } Piececxx . . $ Piece#; |
| 93 | |
| 94 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! compare_piece_and_box_sizecxx . . $ compare_piece_and_box_size(967c8d0e1b1425dd).(Constraintcxx . . $ Constraint# *constraint, CgreenValuecxx . . $ CgreenValue# actual) { |
| 95 | return ((Piececxx . . $ Piece# *)actual.valuecxx . . $ $anonymous_type_b16cac6eed758fe0_1#value..pointer_valuecxx . . $ $anonymous_type_b16cac6eed758fe0_1#$anonymous_type_2#pointer_value.)->sizecxx . . $ Piece#size. |
| 96 | < ((Structcxx . . $ Struct#*)constraint->expected_valuecxx . . $ Constraint_#expected_value..valuecxx . . $ $anonymous_type_b16cac6eed758fe0_1#value..pointer_valuecxx . . $ $anonymous_type_b16cac6eed758fe0_1#$anonymous_type_2#pointer_value.)->sizecxx . . $ Struct#size. ; |
| 97 | } |
| 98 | |
| 99 | static void test_fit_piececxx . . $ test_fit_piece(c0af3e8d8bd2e1e5).(Constraintcxx . . $ Constraint# *constraint, const char *function_name, CgreenValuecxx . . $ CgreenValue# actual, |
| 100 | const char *test_file, int test_line, TestReportercxx . . $ TestReporter# *reporter) { |
| 101 | (*reporter->assert_truecxx . . $ TestReporter_#assert_true.)( |
| 102 | reporter, |
| 103 | test_file, |
| 104 | test_line, |
| 105 | (*constraint->comparecxx . . $ Constraint_#compare.)(constraint, actual), |
| 106 | "Piece [%f], does not fit in [%f] in function [%s] parameter [%s]", |
| 107 | ((Piececxx . . $ Piece# *)constraint->expected_valuecxx . . $ Constraint_#expected_value..valuecxx . . $ $anonymous_type_b16cac6eed758fe0_1#value..pointer_valuecxx . . $ $anonymous_type_b16cac6eed758fe0_1#$anonymous_type_2#pointer_value.)->idcxx . . $ Piece#id., |
| 108 | ((Structcxx . . $ Struct# *)actual.valuecxx . . $ $anonymous_type_b16cac6eed758fe0_1#value..pointer_valuecxx . . $ $anonymous_type_b16cac6eed758fe0_1#$anonymous_type_2#pointer_value.)->idcxx . . $ Struct#id., |
| 109 | function_name, |
| 110 | constraint->parameter_namecxx . . $ Constraint_#parameter_name.); |
| 111 | } |
| 112 | |
| 113 | Constraintcxx . . $ Constraint# *create_piece_fit_in_box_constraintcxx . . $ create_piece_fit_in_box_constraint(f83092978cf2a14d).(intptr_tcxx . . $ intptr_t# expected_value, const char *expected_value_name) { |
| 114 | Constraintcxx . . $ Constraint# *constraint = create_constraintcxx . . $ create_constraint(ba55e2de72051eb6).(); |
| 115 | |
| 116 | constraint->expected_valuecxx . . $ Constraint_#expected_value. = make_cgreen_pointer_valuecxx . . $ make_cgreen_pointer_value(32799a8d7b9a4e33).((void*)expected_value); |
| 117 | constraint->expected_value_namecxx . . $ Constraint_#expected_value_name. = string_dupcxx . . $ string_dup(a8b8e32347182212).(expected_value_name); |
| 118 | constraint->typecxx . . $ Constraint_#type. = CGREEN_CONTENT_COMPARER_CONSTRAINTcxx . . $ CGREEN_CONTENT_COMPARER_CONSTRAINT.; |
| 119 | |
| 120 | constraint->comparecxx . . $ Constraint_#compare. = &compare_piece_and_box_sizecxx . . $ compare_piece_and_box_size(967c8d0e1b1425dd).; |
| 121 | constraint->executecxx . . $ Constraint_#execute. = &test_fit_piececxx . . $ test_fit_piece(c0af3e8d8bd2e1e5).; |
| 122 | constraint->namecxx . . $ Constraint_#name. = "fit in box"; |
| 123 | constraint->size_of_expected_valuecxx . . $ Constraint_#size_of_expected_value. = sizeof(intptr_tcxx . . $ intptr_t#); |
| 124 | |
| 125 | return constraint; |
| 126 | } |
| 127 | #define can_fit_in_boxcxx . . $ `tests/custom_constraint_messages_tests.c:127:9`!(box) create_piece_fit_in_box_constraint((intptr_t)box, #box) |
| 128 | |
| 129 | Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(CustomConstraint, more_complex_custom_constraint_function) { |
| 130 | Structcxx . . $ Struct# box1 = {.id = (char)1, .size = 5}; |
| 131 | Piececxx . . $ Piece# piece99 = {.id = (char)99, .size = 6}; |
| 132 | assert_thatcxx . . $ `include/cgreen/assertions.h:30:9`!(&piece99, can_fit_in_boxcxx . . $ `tests/custom_constraint_messages_tests.c:127:9`!(&box1)); |
| 133 | } |