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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
#include <cgreen/cgreen.h>
#include <cgreen/constraint_syntax_helpers.h>
#include <cgreen/mocks.h>
Describe(StructParameters);
BeforeEach(StructParameters) {}
AfterEach(StructParameters) {}
/*
This is uncompilable code that is inserted as a non-example
typedef struct {
int i;
char *string;
} Struct;
int function_taking_struct(Struct s) {
return (int)mock(?);
}
*/
typedef struct {
int i;
char *string;
} Struct;
int function_checking_a_field(Struct s) {
return (int)mock(s.i);
}
Ensure(StructParameters, can_mock_field_in_parameter) {
Struct struct_to_send = { .i = 12, .string = "hello" };
expect(function_checking_a_field, when(s.i, is_equal_to(12)),
will_return(12));
assert_that(function_checking_a_field(struct_to_send), is_equal_to(12));
}
int function_checking_multiple_fields(Struct s) {
return (int)mock(s.i, s.string);
}
Ensure(StructParameters, can_mock_muultiple_fields_in_parameter) {
Struct struct_to_send = { .i = 13, .string = "hello world!" };
expect(function_checking_multiple_fields,
when(s.i, is_equal_to(13)),
when(s.string, begins_with_string("hello")),
will_return(13));
assert_that(function_checking_multiple_fields(struct_to_send), is_equal_to(13));
}
|