Debian Codegraph @

doc/tutorial_src/struct_parameters.c

raw symbols SCIP
1 #include <cgreen/cgreen.h>
2 #include <cgreen/constraint_syntax_helpers.h>
3 #include <cgreen/mocks.h>
4
5 Describe(StructParameters);
6 BeforeEach(StructParameters) {}
7 AfterEach(StructParameters) {}
8
9 /*
10 This is uncompilable code that is inserted as a non-example
11
12 typedef struct {
13 int i;
14 char *string;
15 } Struct;
16
17 int function_taking_struct(Struct s) {
18 return (int)mock(?);
19 }
20 */
21
22 typedef struct {
23 int i;
24 char *string;
25 } Struct;
26
27 int function_checking_a_field(Struct s) {
28 return (int)mock(s.i);
29 }
30
31
32 Ensure(StructParameters, can_mock_field_in_parameter) {
33 Struct struct_to_send = { .i = 12, .string = "hello" };
34
35 expect(function_checking_a_field, when(s.i, is_equal_to(12)),
36 will_return(12));
37
38 assert_that(function_checking_a_field(struct_to_send), is_equal_to(12));
39
40 }
41
42 int function_checking_multiple_fields(Struct s) {
43 return (int)mock(s.i, s.string);
44 }
45
46 Ensure(StructParameters, can_mock_muultiple_fields_in_parameter) {
47 Struct struct_to_send = { .i = 13, .string = "hello world!" };
48
49 expect(function_checking_multiple_fields,
50 when(s.i, is_equal_to(13)),
51 when(s.string, begins_with_string("hello")),
52 will_return(13));
53
54 assert_that(function_checking_multiple_fields(struct_to_send), is_equal_to(13));
55 }