| 1 | #cxx . . $ `<file>/tests/mock_messages_tests.c`/include <cgreen/boxed_double.h>cxx . . $ `<file>/include/cgreen/boxed_double.h`/ |
| 2 | #include <cgreen/cgreen.h>cxx . . $ `<file>/include/cgreen/cgreen.h`/ |
| 3 | #include <cgreen/mocks.h>cxx . . $ `<file>/include/cgreen/mocks.h`/ |
| 4 | #include <cgreen/unit.h>cxx . . $ `<file>/include/cgreen/unit.h`/ |
| 5 | #include <stdlib.h> |
| 6 | |
| 7 | #ifdef __cplusplus |
| 8 | using namespace cgreen; |
| 9 | #endif |
| 10 | |
| 11 | /* NOTE: These tests are not designed to pass, they are run to output |
| 12 | messages which need to be compared to some golden output */ |
| 13 | |
| 14 | Describecxx . . $ `include/cgreen/unit.h:12:9`!(Mocks); |
| 15 | BeforeEachcxx . . $ `include/cgreen/unit.h:15:9`!(Mocks) {} |
| 16 | AfterEachcxx . . $ `include/cgreen/unit.h:18:9`!(Mocks) {} |
| 17 | |
| 18 | static int integer_outcxx . . $ integer_out(b126dc7c1de90089).(void) { |
| 19 | return (int)mockcxx . . $ `include/cgreen/mocks.h:34:9`!(); |
| 20 | } |
| 21 | |
| 22 | static char *string_outcxx . . $ string_out(ff224f080444ee45).(int p1) { |
| 23 | return (char *)mockcxx . . $ `include/cgreen/mocks.h:34:9`!(p1); |
| 24 | } |
| 25 | |
| 26 | static int sample_mockcxx . . $ sample_mock(95e580389a7cc305).(int i, const char *s) { |
| 27 | return (int)mockcxx . . $ `include/cgreen/mocks.h:34:9`!(i, s); |
| 28 | } |
| 29 | |
| 30 | Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(Mocks, can_declare_function_never_called) { |
| 31 | never_expectcxx . . $ `include/cgreen/mocks.h:25:9`!(sample_mock); |
| 32 | |
| 33 | sample_mockcxx . . $ sample_mock(95e580389a7cc305).(0, ""); |
| 34 | } |
| 35 | |
| 36 | Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(Mocks, when_never_expected_mock_function_is_not_called_pass_counter_increments_by_one) { |
| 37 | never_expectcxx . . $ `include/cgreen/mocks.h:25:9`!(sample_mock); |
| 38 | } |
| 39 | |
| 40 | Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(Mocks, calls_beyond_expected_sequence_fail_when_mocks_are_strict) { |
| 41 | expectcxx . . $ `include/cgreen/mocks.h:21:9`!(integer_out, |
| 42 | will_returncxx . . $ `include/cgreen/constraint_syntax_helpers.h:58:9`!(1) |
| 43 | ); |
| 44 | |
| 45 | expectcxx . . $ `include/cgreen/mocks.h:21:9`!(integer_out, |
| 46 | will_returncxx . . $ `include/cgreen/constraint_syntax_helpers.h:58:9`!(2) |
| 47 | ); |
| 48 | |
| 49 | expectcxx . . $ `include/cgreen/mocks.h:21:9`!(integer_out, |
| 50 | will_returncxx . . $ `include/cgreen/constraint_syntax_helpers.h:58:9`!(3) |
| 51 | ); |
| 52 | |
| 53 | assert_thatcxx . . $ `include/cgreen/assertions.h:30:9`!(integer_out(), is_equal_tocxx . . $ `include/cgreen/constraint_syntax_helpers.h:26:9`!(1)); |
| 54 | assert_thatcxx . . $ `include/cgreen/assertions.h:30:9`!(integer_out(), is_equal_tocxx . . $ `include/cgreen/constraint_syntax_helpers.h:26:9`!(2)); |
| 55 | assert_thatcxx . . $ `include/cgreen/assertions.h:30:9`!(integer_out(), is_equal_tocxx . . $ `include/cgreen/constraint_syntax_helpers.h:26:9`!(3)); |
| 56 | // expected fail |
| 57 | assert_thatcxx . . $ `include/cgreen/assertions.h:30:9`!(integer_out(), is_equal_tocxx . . $ `include/cgreen/constraint_syntax_helpers.h:26:9`!(3)); |
| 58 | } |
| 59 | |
| 60 | static void unexpected_mockcxx . . $ unexpected_mock(49f6e7a06ebc5aa8).(void) { mockcxx . . $ `include/cgreen/mocks.h:34:9`!(); } |
| 61 | |
| 62 | Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(Mocks, lists_unexpected_mock_calls) { unexpected_mockcxx . . $ unexpected_mock(49f6e7a06ebc5aa8).(); } |
| 63 | |
| 64 | |
| 65 | // These are tentative solutions to mocks returning doubles and |
| 66 | // trapping type errors when they do. |
| 67 | |
| 68 | /* xEnsure(Mocks, traps_double_return_value_for_int_mock) { */ |
| 69 | /* expect(integer_out, will_return_double(3.1415926)); */ |
| 70 | /* integer_out(); */ |
| 71 | /* } */ |
| 72 | |
| 73 | /* static double double_out() { */ |
| 74 | /* return mock_double(); */ |
| 75 | /* } */ |
| 76 | |
| 77 | /* xEnsure(Mocks, traps_int_return_value_for_double_mock) { */ |
| 78 | /* expect(double_out, will_return_double(3.1415926)); */ |
| 79 | /* assert_that(double_out(), is_equal_to_double(3.1415926)); */ |
| 80 | /* } */ |
| 81 | |
| 82 | Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(Mocks, failure_when_no_presets_for_default_strict_mock) { |
| 83 | assert_thatcxx . . $ `include/cgreen/assertions.h:30:9`!(integer_out(), is_equal_tocxx . . $ `include/cgreen/constraint_syntax_helpers.h:26:9`!(0)); |
| 84 | } |
| 85 | |
| 86 | Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(Mocks, failure_reported_when_expect_after_never_expect_for_same_function) { |
| 87 | never_expectcxx . . $ `include/cgreen/mocks.h:25:9`!(integer_out); |
| 88 | |
| 89 | expectcxx . . $ `include/cgreen/mocks.h:21:9`!(integer_out); |
| 90 | } |
| 91 | |
| 92 | Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(Mocks, failure_reported_when_expect_after_always_expect_for_same_function) { |
| 93 | always_expectcxx . . $ `include/cgreen/mocks.h:23:9`!(integer_out, |
| 94 | will_returncxx . . $ `include/cgreen/constraint_syntax_helpers.h:58:9`!(666) |
| 95 | ); |
| 96 | |
| 97 | expectcxx . . $ `include/cgreen/mocks.h:21:9`!(integer_out); |
| 98 | } |
| 99 | |
| 100 | Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(Mocks, reports_multiple_always_expect) { |
| 101 | always_expectcxx . . $ `include/cgreen/mocks.h:23:9`!(integer_out); |
| 102 | always_expectcxx . . $ `include/cgreen/mocks.h:23:9`!(integer_out); |
| 103 | } |
| 104 | |
| 105 | Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(Mocks, reports_always_expect_after_never_expect_for_same_function) { |
| 106 | never_expectcxx . . $ `include/cgreen/mocks.h:25:9`!(integer_out); |
| 107 | always_expectcxx . . $ `include/cgreen/mocks.h:23:9`!(integer_out); |
| 108 | } |
| 109 | |
| 110 | Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(Mocks, reports_never_expect_after_always_expect_for_same_function) { |
| 111 | always_expectcxx . . $ `include/cgreen/mocks.h:23:9`!(integer_out); |
| 112 | never_expectcxx . . $ `include/cgreen/mocks.h:25:9`!(integer_out); |
| 113 | } |
| 114 | |
| 115 | Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(Mocks, reports_multiple_never_expect) { |
| 116 | never_expectcxx . . $ `include/cgreen/mocks.h:25:9`!(integer_out); |
| 117 | never_expectcxx . . $ `include/cgreen/mocks.h:25:9`!(integer_out); |
| 118 | } |
| 119 | |
| 120 | Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(Mocks, single_uncalled_expectation_fails_tally) { |
| 121 | expectcxx . . $ `include/cgreen/mocks.h:21:9`!(string_out, |
| 122 | will_returncxx . . $ `include/cgreen/constraint_syntax_helpers.h:58:9`!(5), |
| 123 | whencxx . . $ `include/cgreen/mocks.h:38:9`!(i, is_equal_tocxx . . $ `include/cgreen/constraint_syntax_helpers.h:26:9`!(666)), |
| 124 | whencxx . . $ `include/cgreen/mocks.h:38:9`!(s, is_equal_to_stringcxx . . $ `include/cgreen/constraint_syntax_helpers.h:41:9`!("devil")) |
| 125 | ); |
| 126 | } |
| 127 | |
| 128 | |
| 129 | Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(Mocks, should_detect_two_unfulfilled_expectations_on_unknown_functions) { |
| 130 | expectcxx . . $ `include/cgreen/mocks.h:21:9`!(f1, will_returncxx . . $ `include/cgreen/constraint_syntax_helpers.h:58:9`!('a')); |
| 131 | expectcxx . . $ `include/cgreen/mocks.h:21:9`!(f2, will_returncxx . . $ `include/cgreen/constraint_syntax_helpers.h:58:9`!('b')); |
| 132 | } |
| 133 | |
| 134 | Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(Mocks, should_detect_two_unfulfilled_expectations_without_constraints_on_unknown_functions) { |
| 135 | expectcxx . . $ `include/cgreen/mocks.h:21:9`!(f1); |
| 136 | expectcxx . . $ `include/cgreen/mocks.h:21:9`!(f2); |
| 137 | } |
| 138 | |
| 139 | static double double_outcxx . . $ double_out(31fa7155c10fdd13).(void) { |
| 140 | return (double)mockcxx . . $ `include/cgreen/mocks.h:34:9`!(); |
| 141 | } |
| 142 | |
| 143 | static void double_incxx . . $ double_in(ba8836b59fb42830).(double in) { |
| 144 | mockcxx . . $ `include/cgreen/mocks.h:34:9`!(box_double(in)); |
| 145 | } |
| 146 | |
| 147 | /* TODO: this will not report anything until v2 */ |
| 148 | /* Why? */ |
| 149 | xEnsurecxx . . $ `include/cgreen/unit.h:28:9`!(Mocks, reports_mock_cannot_return_double) { |
| 150 | expectcxx . . $ `include/cgreen/mocks.h:21:9`!(double_out, will_return_doublecxx . . $ `include/cgreen/constraint_syntax_helpers.h:60:9`!(4.123)); |
| 151 | double_outcxx . . $ double_out(31fa7155c10fdd13).(); |
| 152 | } |
| 153 | |
| 154 | Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(Mocks, learning_mocks_emit_none_when_learning_no_mocks) { |
| 155 | cgreen_mocks_arecxx . . $ cgreen_mocks_are(366adfdc1bb4e579).(learning_mockscxx . . $ learning_mocks.); |
| 156 | } |
| 157 | |
| 158 | Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(Mocks, learning_mocks_emit_pastable_code) { |
| 159 | cgreen_mocks_arecxx . . $ cgreen_mocks_are(366adfdc1bb4e579).(learning_mockscxx . . $ learning_mocks.); |
| 160 | string_outcxx . . $ string_out(ff224f080444ee45).(1); |
| 161 | string_outcxx . . $ string_out(ff224f080444ee45).(2); |
| 162 | integer_outcxx . . $ integer_out(b126dc7c1de90089).(); |
| 163 | integer_outcxx . . $ integer_out(b126dc7c1de90089).(); |
| 164 | string_outcxx . . $ string_out(ff224f080444ee45).(3); |
| 165 | integer_outcxx . . $ integer_out(b126dc7c1de90089).(); |
| 166 | } |
| 167 | |
| 168 | Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(Mocks, can_learn_double_expects) { |
| 169 | cgreen_mocks_arecxx . . $ cgreen_mocks_are(366adfdc1bb4e579).(learning_mockscxx . . $ learning_mocks.); |
| 170 | double_incxx . . $ double_in(ba8836b59fb42830).(3.14); |
| 171 | } |
| 172 | |
| 173 | /* It would be very nice if learning mocks could survive unexpected |
| 174 | terminations but since the child process is already gone when the |
| 175 | parent process detects this we need to either start catching |
| 176 | exceptions in the child or communicate the learned mock calls to |
| 177 | the parent some other way. |
| 178 | */ |
| 179 | xEnsurecxx . . $ `include/cgreen/unit.h:28:9`!(Mocks, learning_mocks_survive_termination) { |
| 180 | int *ip = 0; |
| 181 | cgreen_mocks_arecxx . . $ cgreen_mocks_are(366adfdc1bb4e579).(learning_mockscxx . . $ learning_mocks.); |
| 182 | string_outcxx . . $ string_out(ff224f080444ee45).(1); |
| 183 | *ip = 0; |
| 184 | } |
| 185 | |
| 186 | static void simple_mocked_functioncxx . . $ simple_mocked_function(3e454b8ccf442868).(int first, int second) { |
| 187 | mockcxx . . $ `include/cgreen/mocks.h:34:9`!(first, second); |
| 188 | } |
| 189 | |
| 190 | Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(Mocks, constraint_number_of_calls_when_not_called_enough_times) { |
| 191 | expectcxx . . $ `include/cgreen/mocks.h:21:9`!(simple_mocked_function, timescxx . . $ `include/cgreen/mocks.h:40:9`!(2)); |
| 192 | simple_mocked_functioncxx . . $ simple_mocked_function(3e454b8ccf442868).(1, 2); |
| 193 | } |
| 194 | |
| 195 | Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(Mocks, constraint_number_of_calls_out_of_order_expectations_fail) { |
| 196 | expectcxx . . $ `include/cgreen/mocks.h:21:9`!(simple_mocked_function, whencxx . . $ `include/cgreen/mocks.h:38:9`!(first, is_equal_tocxx . . $ `include/cgreen/constraint_syntax_helpers.h:26:9`!(1)), timescxx . . $ `include/cgreen/mocks.h:40:9`!(1)); |
| 197 | expectcxx . . $ `include/cgreen/mocks.h:21:9`!(simple_mocked_function, whencxx . . $ `include/cgreen/mocks.h:38:9`!(first, is_equal_tocxx . . $ `include/cgreen/constraint_syntax_helpers.h:26:9`!(2)), timescxx . . $ `include/cgreen/mocks.h:40:9`!(1)); |
| 198 | simple_mocked_functioncxx . . $ simple_mocked_function(3e454b8ccf442868).(2, 2); |
| 199 | simple_mocked_functioncxx . . $ simple_mocked_function(3e454b8ccf442868).(1, 2); |
| 200 | } |