| 1 | #cxx . . $ `<file>/tests/mocks_struct_tests.c`/include <cgreen/cgreen.h>cxx . . $ `<file>/include/cgreen/cgreen.h`/ |
| 2 | #include <cgreen/constraint.h>cxx . . $ `<file>/include/cgreen/constraint.h`/ |
| 3 | #include <cgreen/constraint_syntax_helpers.h>cxx . . $ `<file>/include/cgreen/constraint_syntax_helpers.h`/ |
| 4 | #include <cgreen/mocks.h>cxx . . $ `<file>/include/cgreen/mocks.h`/ |
| 5 | #include <stdint.h> |
| 6 | #include <cgreen/cgreen_value.h>cxx . . $ `<file>/include/cgreen/cgreen_value.h`/ |
| 7 | |
| 8 | #ifdef __cpluspluscxx . . $ `<built-in>:440:9`! |
| 9 | using namespace cgreen; |
| 10 | |
| 11 | namespace cgreencxx . . $ cgreen/ { |
| 12 | extern "C" { |
| 13 | extern CgreenValuecxx . . $ CgreenValue# make_cgreen_pointer_value(void *ptr); |
| 14 | } |
| 15 | } |
| 16 | |
| 17 | #else |
| 18 | extern CgreenValuecxx . . $ CgreenValue# make_cgreen_pointer_valuecxx . . $ make_cgreen_pointer_value(32799a8d7b9a4e33).(void *ptr); |
| 19 | #endif |
| 20 | |
| 21 | Describecxx . . $ contextForMockStruct.(MockStruct); |
| 22 | BeforeEachcxx . . $ `include/cgreen/unit.h:15:9`!(MockStruct) {} |
| 23 | AfterEachcxx . . $ AfterEach_For_MockStruct_Function(49f6e7a06ebc5aa8).(MockStruct) {} |
| 24 | |
| 25 | typedef structcxx . . $ $anonymous_type_57aec631ef0773ad_0# { |
| 26 | int icxx . . $ $anonymous_type_57aec631ef0773ad_0#i.; |
| 27 | const char *stringcxx . . $ $anonymous_type_57aec631ef0773ad_0#string.; |
| 28 | } Structcxx . . $ Struct#; |
| 29 | |
| 30 | |
| 31 | /* If you are only interested in a single, or few, fields: */ |
| 32 | void function_mocking_fieldcxx . . $ function_mocking_field(50fc3cf3e5cdc2a).(Structcxx . . $ Struct# s) { |
| 33 | mockcxx . . $ $anonymous_type_57aec631ef0773ad_0#i.(s.i); |
| 34 | } |
| 35 | |
| 36 | Ensurecxx . . $ MockStruct__can_mock_a_struct_parameters_field(49f6e7a06ebc5aa8).(MockStruct, can_mock_a_struct_parameters_field) { |
| 37 | Structcxx . . $ Struct# struct_to_send = { .i = 12, .string = "hello" }; |
| 38 | |
| 39 | expectcxx . . $ Constraint#(function_mocking_field, whencxx . . $ `include/cgreen/mocks.h:38:9`!(s.i, is_equal_tocxx . . $ `include/cgreen/constraint_syntax_helpers.h:26:9`!(12))); |
| 40 | |
| 41 | function_mocking_fieldcxx . . $ function_mocking_field(50fc3cf3e5cdc2a).(struct_to_send); |
| 42 | } |
| 43 | |
| 44 | void *cgreen_memdupcxx . . $ cgreen_memdup(417ab160f6baadc6).(void *s, size_tcxx . . $ size_t# size) { |
| 45 | void *p = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(size); |
| 46 | memcpycxx . . $ memcpy(cc817cb175f282d).(p, s, size); |
| 47 | return p; |
| 48 | } |
| 49 | |
| 50 | #define memdupcxx . . $ `tests/mocks_struct_tests.c:50:9`!(s) cgreen_memdup(&s, sizeof(s)) |
| 51 | |
| 52 | /* If you need to get the whole struct: */ |
| 53 | void function_mocking_the_whole_structcxx . . $ function_mocking_the_whole_struct(50fc3cf3e5cdc2a).(Structcxx . . $ Struct# s) { |
| 54 | Structcxx . . $ Struct# *sP = (Structcxx . . $ Struct# *)memdupcxx . . $ `tests/mocks_struct_tests.c:50:9`!(s); |
| 55 | mockcxx . . $ intptr_t#(sP); |
| 56 | } |
| 57 | |
| 58 | Ensurecxx . . $ CgreenSpec__MockStruct__can_mock_a_struct_parameter__.(MockStruct, can_mock_a_struct_parameter) { |
| 59 | Structcxx . . $ Struct# struct_to_send = { .i = 13, .string = "hello" }; |
| 60 | Structcxx . . $ Struct# *p; |
| 61 | |
| 62 | expectcxx . . $ Constraint#(function_mocking_the_whole_struct, will_capture_parametercxx . . $ `include/cgreen/constraint_syntax_helpers.h:64:9`!(sP, p)); |
| 63 | |
| 64 | function_mocking_the_whole_structcxx . . $ function_mocking_the_whole_struct(50fc3cf3e5cdc2a).(struct_to_send); |
| 65 | |
| 66 | assert_thatcxx . . $ cgreen/(p->i, is_equal_tocxx . . $ `include/cgreen/constraint_syntax_helpers.h:26:9`!(13)); |
| 67 | } |