| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper" |
| 8 |
require File.expand_path(File.dirname(__FILE__)) + '/../../lib/cmock_generator_plugin_expect' |
| 9 |
|
| 10 |
describe CMockGeneratorPluginExpect, "Verify CMockGeneratorPluginExpect Module Without Global Ordering" do |
| 11 |
|
| 12 |
before do |
| 13 |
create_mocks :config, :utils |
| 14 |
|
| 15 |
@config = create_stub( |
| 16 |
:when_ptr => :compare_data, |
| 17 |
:enforce_strict_ordering => false, |
| 18 |
:respond_to? => true, |
| 19 |
:plugins => [ :expect ] ) |
| 20 |
|
| 21 |
@utils.expect :helpers, {} |
| 22 |
@cmock_generator_plugin_expect = CMockGeneratorPluginExpect.new(@config, @utils) |
| 23 |
end |
| 24 |
|
| 25 |
after do |
| 26 |
end |
| 27 |
|
| 28 |
it "have set up internal priority on init" do |
| 29 |
assert_nil(@cmock_generator_plugin_expect.unity_helper) |
| 30 |
assert_equal(5, @cmock_generator_plugin_expect.priority) |
| 31 |
end |
| 32 |
|
| 33 |
it "not include any additional include files" do |
| 34 |
assert(!@cmock_generator_plugin_expect.respond_to?(:include_files)) |
| 35 |
end |
| 36 |
|
| 37 |
it "add to typedef structure mock needs of functions of style 'void func(void)'" do |
| 38 |
function = {:name => "Oak", :args => [], :return => test_return[:void]} |
| 39 |
expected = "" |
| 40 |
returned = @cmock_generator_plugin_expect.instance_typedefs(function) |
| 41 |
assert_equal(expected, returned) |
| 42 |
end |
| 43 |
|
| 44 |
it "add to typedef structure mock needs of functions of style 'int func(void)'" do |
| 45 |
function = {:name => "Elm", :args => [], :return => test_return[:int]} |
| 46 |
expected = " int ReturnVal;\n" |
| 47 |
returned = @cmock_generator_plugin_expect.instance_typedefs(function) |
| 48 |
assert_equal(expected, returned) |
| 49 |
end |
| 50 |
|
| 51 |
it "add to typedef structure mock needs of functions of style 'void func(int chicken, char* pork)'" do |
| 52 |
function = {:name => "Cedar", :args => [{ :name => "chicken", :type => "int"}, { :name => "pork", :type => "char*"}], :return => test_return[:void]} |
| 53 |
expected = " int Expected_chicken;\n char* Expected_pork;\n" |
| 54 |
returned = @cmock_generator_plugin_expect.instance_typedefs(function) |
| 55 |
assert_equal(expected, returned) |
| 56 |
end |
| 57 |
|
| 58 |
it "add to typedef structure mock needs of functions of style 'int func(float beef)'" do |
| 59 |
function = {:name => "Birch", :args => [{ :name => "beef", :type => "float"}], :return => test_return[:int]} |
| 60 |
expected = " int ReturnVal;\n float Expected_beef;\n" |
| 61 |
returned = @cmock_generator_plugin_expect.instance_typedefs(function) |
| 62 |
assert_equal(expected, returned) |
| 63 |
end |
| 64 |
|
| 65 |
it "add mock function declaration for functions of style 'void func(void)'" do |
| 66 |
function = {:name => "Maple", :args => [], :return => test_return[:void]} |
| 67 |
expected = "#define Maple_Expect() Maple_CMockExpect(__LINE__)\n" + |
| 68 |
"void Maple_CMockExpect(UNITY_LINE_TYPE cmock_line);\n" |
| 69 |
returned = @cmock_generator_plugin_expect.mock_function_declarations(function) |
| 70 |
assert_equal(expected, returned) |
| 71 |
end |
| 72 |
|
| 73 |
it "add mock function declaration for functions of style 'int func(void)'" do |
| 74 |
function = {:name => "Spruce", :args => [], :return => test_return[:int]} |
| 75 |
expected = "#define Spruce_ExpectAndReturn(cmock_retval) Spruce_CMockExpectAndReturn(__LINE__, cmock_retval)\n" + |
| 76 |
"void Spruce_CMockExpectAndReturn(UNITY_LINE_TYPE cmock_line, int cmock_to_return);\n" |
| 77 |
returned = @cmock_generator_plugin_expect.mock_function_declarations(function) |
| 78 |
assert_equal(expected, returned) |
| 79 |
end |
| 80 |
|
| 81 |
it "add mock function declaration for functions of style 'const char* func(int tofu)'" do |
| 82 |
function = {:name => "Pine", :args => ["int tofu"], :args_string => "int tofu", :args_call => 'tofu', :return => test_return[:string]} |
| 83 |
expected = "#define Pine_ExpectAndReturn(tofu, cmock_retval) Pine_CMockExpectAndReturn(__LINE__, tofu, cmock_retval)\n" + |
| 84 |
"void Pine_CMockExpectAndReturn(UNITY_LINE_TYPE cmock_line, int tofu, const char* cmock_to_return);\n" |
| 85 |
returned = @cmock_generator_plugin_expect.mock_function_declarations(function) |
| 86 |
assert_equal(expected, returned) |
| 87 |
end |
| 88 |
|
| 89 |
it "add mock function implementation for functions of style 'void func(void)'" do |
| 90 |
function = {:name => "Apple", :args => [], :return => test_return[:void]} |
| 91 |
expected = "" |
| 92 |
returned = @cmock_generator_plugin_expect.mock_implementation(function) |
| 93 |
assert_equal(expected, returned) |
| 94 |
end |
| 95 |
|
| 96 |
it "add mock function implementation for functions of style 'int func(int veal, unsigned int sushi)'" do |
| 97 |
function = {:name => "Cherry", :args => [ { :type => "int", :name => "veal" }, { :type => "unsigned int", :name => "sushi" } ], :return => test_return[:int]} |
| 98 |
|
| 99 |
@utils.expect :code_verify_an_arg_expectation, " mocked_retval_1", [function, function[:args][0]] |
| 100 |
@utils.expect :code_verify_an_arg_expectation, " mocked_retval_2", [function, function[:args][1]] |
| 101 |
expected = " mocked_retval_1 mocked_retval_2" |
| 102 |
returned = @cmock_generator_plugin_expect.mock_implementation(function) |
| 103 |
assert_equal(expected, returned) |
| 104 |
end |
| 105 |
|
| 106 |
it "add mock function implementation using ordering if needed" do |
| 107 |
function = {:name => "Apple", :args => [], :return => test_return[:void]} |
| 108 |
expected = "" |
| 109 |
@cmock_generator_plugin_expect.ordered = true |
| 110 |
returned = @cmock_generator_plugin_expect.mock_implementation(function) |
| 111 |
assert_equal(expected, returned) |
| 112 |
end |
| 113 |
|
| 114 |
it "add mock interfaces for functions of style 'void func(void)'" do |
| 115 |
function = {:name => "Pear", :args => [], :args_string => "void", :return => test_return[:void]} |
| 116 |
@utils.expect :code_add_base_expectation, "mock_retval_0 ", ["Pear"] |
| 117 |
@utils.expect :code_call_argument_loader, "mock_retval_1 ", [function] |
| 118 |
expected = ["void Pear_CMockExpect(UNITY_LINE_TYPE cmock_line)\n", |
| 119 |
"{\n", |
| 120 |
"mock_retval_0 ", |
| 121 |
"mock_retval_1 ", |
| 122 |
"}\n\n" |
| 123 |
].join |
| 124 |
returned = @cmock_generator_plugin_expect.mock_interfaces(function) |
| 125 |
assert_equal(expected, returned) |
| 126 |
end |
| 127 |
|
| 128 |
it "add mock interfaces for functions of style 'int func(void)'" do |
| 129 |
function = {:name => "Orange", :args => [], :args_string => "void", :return => test_return[:int]} |
| 130 |
@utils.expect :code_add_base_expectation, "mock_retval_0 ", ["Orange"] |
| 131 |
@utils.expect :code_call_argument_loader, "mock_retval_1 ", [function] |
| 132 |
@utils.expect :code_assign_argument_quickly, "mock_retval_2", ["cmock_call_instance->ReturnVal", function[:return]] |
| 133 |
expected = ["void Orange_CMockExpectAndReturn(UNITY_LINE_TYPE cmock_line, int cmock_to_return)\n", |
| 134 |
"{\n", |
| 135 |
"mock_retval_0 ", |
| 136 |
"mock_retval_1 ", |
| 137 |
"mock_retval_2", |
| 138 |
"}\n\n" |
| 139 |
].join |
| 140 |
returned = @cmock_generator_plugin_expect.mock_interfaces(function) |
| 141 |
assert_equal(expected, returned) |
| 142 |
end |
| 143 |
|
| 144 |
it "add mock interfaces for functions of style 'int func(char* pescado)'" do |
| 145 |
function = {:name => "Lemon", :args => [{ :type => "char*", :name => "pescado"}], :args_string => "char* pescado", :return => test_return[:int]} |
| 146 |
@utils.expect :code_add_base_expectation, "mock_retval_0 ", ["Lemon"] |
| 147 |
@utils.expect :code_call_argument_loader, "mock_retval_1 ", [function] |
| 148 |
@utils.expect :code_assign_argument_quickly, "mock_retval_2", ["cmock_call_instance->ReturnVal", function[:return]] |
| 149 |
expected = ["void Lemon_CMockExpectAndReturn(UNITY_LINE_TYPE cmock_line, char* pescado, int cmock_to_return)\n", |
| 150 |
"{\n", |
| 151 |
"mock_retval_0 ", |
| 152 |
"mock_retval_1 ", |
| 153 |
"mock_retval_2", |
| 154 |
"}\n\n" |
| 155 |
].join |
| 156 |
returned = @cmock_generator_plugin_expect.mock_interfaces(function) |
| 157 |
assert_equal(expected, returned) |
| 158 |
end |
| 159 |
|
| 160 |
it "add mock interfaces for functions when using ordering" do |
| 161 |
function = {:name => "Pear", :args => [], :args_string => "void", :return => test_return[:void]} |
| 162 |
@utils.expect :code_add_base_expectation, "mock_retval_0 ", ["Pear"] |
| 163 |
@utils.expect :code_call_argument_loader, "mock_retval_1 ", [function] |
| 164 |
expected = ["void Pear_CMockExpect(UNITY_LINE_TYPE cmock_line)\n", |
| 165 |
"{\n", |
| 166 |
"mock_retval_0 ", |
| 167 |
"mock_retval_1 ", |
| 168 |
"}\n\n" |
| 169 |
].join |
| 170 |
@cmock_generator_plugin_expect.ordered = true |
| 171 |
returned = @cmock_generator_plugin_expect.mock_interfaces(function) |
| 172 |
assert_equal(expected, returned) |
| 173 |
end |
| 174 |
|
| 175 |
it "add mock verify lines" do |
| 176 |
function = {:name => "Banana" } |
| 177 |
expected = " if (CMOCK_GUTS_NONE != call_instance)\n" \ |
| 178 |
" {\n" \ |
| 179 |
" UNITY_SET_DETAIL(CMockString_Banana);\n" \ |
| 180 |
" UNITY_TEST_FAIL(cmock_line, CMockStringCalledLess);\n" \ |
| 181 |
" }\n" |
| 182 |
returned = @cmock_generator_plugin_expect.mock_verify(function) |
| 183 |
assert_equal(expected, returned) |
| 184 |
end |
| 185 |
end |