| 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_ignore_stateless' |
| 9 |
|
| 10 |
describe CMockGeneratorPluginIgnoreStateless, "Verify CMockGeneratorPluginIgnoreStateless Module" do |
| 11 |
|
| 12 |
before do |
| 13 |
create_mocks :config, :utils |
| 14 |
@config = create_stub(:respond_to? => true) |
| 15 |
@cmock_generator_plugin_ignore_stateless = CMockGeneratorPluginIgnoreStateless.new(@config, @utils) |
| 16 |
end |
| 17 |
|
| 18 |
after do |
| 19 |
end |
| 20 |
|
| 21 |
it "have set up internal priority" do |
| 22 |
assert_equal(2, @cmock_generator_plugin_ignore_stateless.priority) |
| 23 |
end |
| 24 |
|
| 25 |
it "not have any additional include file requirements" do |
| 26 |
assert(!@cmock_generator_plugin_ignore_stateless.respond_to?(:include_files)) |
| 27 |
end |
| 28 |
|
| 29 |
it "add a required variable to the instance structure" do |
| 30 |
function = {:name => "Grass", :args => [], :return => test_return[:void]} |
| 31 |
expected = " char Grass_IgnoreBool;\n" |
| 32 |
returned = @cmock_generator_plugin_ignore_stateless.instance_structure(function) |
| 33 |
assert_equal(expected, returned) |
| 34 |
end |
| 35 |
|
| 36 |
it "handle function declarations for functions without return values" do |
| 37 |
function = {:name => "Mold", :args_string => "void", :return => test_return[:void]} |
| 38 |
expected = "#define Mold_Ignore() Mold_CMockIgnore()\nvoid Mold_CMockIgnore(void);\n" + |
| 39 |
"#define Mold_StopIgnore() Mold_CMockStopIgnore()\nvoid Mold_CMockStopIgnore(void);\n" |
| 40 |
returned = @cmock_generator_plugin_ignore_stateless.mock_function_declarations(function) |
| 41 |
assert_equal(expected, returned) |
| 42 |
end |
| 43 |
|
| 44 |
it "handle function declarations for functions that returns something" do |
| 45 |
function = {:name => "Fungus", :args_string => "void", :return => test_return[:string]} |
| 46 |
expected = "#define Fungus_IgnoreAndReturn(cmock_retval) Fungus_CMockIgnoreAndReturn(cmock_retval)\n"+ |
| 47 |
"void Fungus_CMockIgnoreAndReturn(const char* cmock_to_return);\n" + |
| 48 |
"#define Fungus_StopIgnore() Fungus_CMockStopIgnore()\n"+ |
| 49 |
"void Fungus_CMockStopIgnore(void);\n" |
| 50 |
returned = @cmock_generator_plugin_ignore_stateless.mock_function_declarations(function) |
| 51 |
assert_equal(expected, returned) |
| 52 |
end |
| 53 |
|
| 54 |
it "add required code to implementation precheck with void function" do |
| 55 |
function = {:name => "Mold", :args_string => "void", :return => test_return[:void]} |
| 56 |
expected = [" if (Mock.Mold_IgnoreBool)\n", |
| 57 |
" {\n", |
| 58 |
" UNITY_CLR_DETAILS();\n", |
| 59 |
" return;\n", |
| 60 |
" }\n" |
| 61 |
].join |
| 62 |
returned = @cmock_generator_plugin_ignore_stateless.mock_implementation_precheck(function) |
| 63 |
assert_equal(expected, returned) |
| 64 |
end |
| 65 |
|
| 66 |
it "add required code to implementation precheck with return functions" do |
| 67 |
function = {:name => "Fungus", :args_string => "void", :return => test_return[:int]} |
| 68 |
retval = test_return[:int].merge({ :name => "cmock_call_instance->ReturnVal"}) |
| 69 |
@utils.expect :code_assign_argument_quickly, ' mock_retval_0', ["Mock.Fungus_FinalReturn", retval] |
| 70 |
expected = [" if (Mock.Fungus_IgnoreBool)\n", |
| 71 |
" {\n", |
| 72 |
" UNITY_CLR_DETAILS();\n", |
| 73 |
" if (cmock_call_instance == NULL)\n", |
| 74 |
" return Mock.Fungus_FinalReturn;\n", |
| 75 |
" mock_retval_0", |
| 76 |
" return cmock_call_instance->ReturnVal;\n", |
| 77 |
" }\n" |
| 78 |
].join |
| 79 |
returned = @cmock_generator_plugin_ignore_stateless.mock_implementation_precheck(function) |
| 80 |
assert_equal(expected, returned) |
| 81 |
end |
| 82 |
|
| 83 |
it "add a new mock interface for ignoring when function had no return value" do |
| 84 |
function = {:name => "Slime", :args => [], :args_string => "void", :return => test_return[:void]} |
| 85 |
expected = ["void Slime_CMockIgnore(void)\n", |
| 86 |
"{\n", |
| 87 |
" Mock.Slime_IgnoreBool = (char)1;\n", |
| 88 |
"}\n\n", |
| 89 |
"void Slime_CMockStopIgnore(void)\n", |
| 90 |
"{\n", |
| 91 |
" Mock.Slime_IgnoreBool = (char)0;\n", |
| 92 |
"}\n\n" |
| 93 |
].join |
| 94 |
returned = @cmock_generator_plugin_ignore_stateless.mock_interfaces(function) |
| 95 |
assert_equal(expected, returned) |
| 96 |
end |
| 97 |
|
| 98 |
it "add a new mock interface for ignoring when function has return value" do |
| 99 |
function = {:name => "Slime", :args => [], :args_string => "void", :return => test_return[:int]} |
| 100 |
@utils.expect :code_add_base_expectation, "mock_return_1", ["Slime", false] |
| 101 |
expected = ["void Slime_CMockIgnoreAndReturn(int cmock_to_return)\n", |
| 102 |
"{\n", |
| 103 |
" Mock.Slime_CallInstance = CMOCK_GUTS_NONE;\n", |
| 104 |
" Mock.Slime_FinalReturn = cmock_to_return;\n", |
| 105 |
" Mock.Slime_IgnoreBool = (char)1;\n", |
| 106 |
"}\n\n", |
| 107 |
"void Slime_CMockStopIgnore(void)\n", |
| 108 |
"{\n", |
| 109 |
" Mock.Slime_IgnoreBool = (char)0;\n", |
| 110 |
"}\n\n" |
| 111 |
].join |
| 112 |
returned = @cmock_generator_plugin_ignore_stateless.mock_interfaces(function) |
| 113 |
assert_equal(expected, returned) |
| 114 |
end |
| 115 |
|
| 116 |
end |