Add 'strict_mock_calling' option

- By default set to true to maintain the default behaviour of CMock
  - When mocked function is called and no Except/Ignor called,
    test will fail
- When set to false:
  - if test calls mocked function,
    and user did not specify Except/Ignore/...
    test will not fail because of this,
    all calls to mocked functions are ignored
This commit is contained in:
laurensmiers
2017-09-06 00:28:37 +02:00
parent 46f609efee
commit 9c9f08c48b
6 changed files with 59 additions and 0 deletions
+1
View File
@@ -19,6 +19,7 @@ class CMockConfig
:attributes => ['__ramfunc', '__irq', '__fiq', 'register', 'extern'],
:c_calling_conventions => ['__stdcall', '__cdecl', '__fastcall'],
:enforce_strict_ordering => false,
:strict_mock_calling => true,
:unity_helper_path => false,
:treat_as => {},
:treat_as_void => [],
+6
View File
@@ -18,6 +18,7 @@ class CMockGenerator
@weak = @config.weak
@ordered = @config.enforce_strict_ordering
@framework = @config.framework.to_s
@strict_mock_calling = @config.strict_mock_calling
@subdir = @config.subdir
@@ -202,6 +203,11 @@ class CMockGenerator
file << " CMock_Guts_MemFreeAll();\n"
file << " memset(&Mock, 0, sizeof(Mock));\n"
file << functions.collect {|function| @plugins.run(:mock_destroy, function)}.join
unless (@strict_mock_calling)
file << functions.collect {|function| @plugins.run(:mock_ignore, function)}.join
end
if (@ordered)
file << " GlobalExpectCount = 0;\n"
file << " GlobalVerifyOrder = 0;\n"
+4
View File
@@ -65,6 +65,10 @@ class CMockGeneratorPluginIgnore
lines << "}\n\n"
end
def mock_ignore(function)
" Mock.#{function[:name]}_IgnoreBool = (int) 1;\n"
end
def mock_verify(function)
func_name = function[:name]
" if (Mock.#{func_name}_IgnoreBool)\n Mock.#{func_name}_CallInstance = CMOCK_GUTS_NONE;\n"