- Centralized error strings to a few constants.

- Made use of the new UNITY_SET_DETAILS feature to background set up function & argument details for messages
- CMock now takes up a lot less memory! woo!
This commit is contained in:
Mark VanderVoord
2015-12-10 16:58:10 -05:00
parent ada6dd2d22
commit 647876644b
24 changed files with 456 additions and 94 deletions
+6 -4
View File
@@ -199,20 +199,22 @@ class CMockGenerator
file << "#{function_mod_and_rettype} #{function[:name]}(#{args_string})\n" file << "#{function_mod_and_rettype} #{function[:name]}(#{args_string})\n"
file << "{\n" file << "{\n"
file << " UNITY_LINE_TYPE cmock_line = TEST_LINE_NUM;\n" file << " UNITY_LINE_TYPE cmock_line = TEST_LINE_NUM;\n"
file << " UNITY_SET_DETAIL(\"#{function[:name]}\");\n"
file << " CMOCK_#{function[:name]}_CALL_INSTANCE* cmock_call_instance = (CMOCK_#{function[:name]}_CALL_INSTANCE*)CMock_Guts_GetAddressFor(Mock.#{function[:name]}_CallInstance);\n" file << " CMOCK_#{function[:name]}_CALL_INSTANCE* cmock_call_instance = (CMOCK_#{function[:name]}_CALL_INSTANCE*)CMock_Guts_GetAddressFor(Mock.#{function[:name]}_CallInstance);\n"
file << " Mock.#{function[:name]}_CallInstance = CMock_Guts_MemNext(Mock.#{function[:name]}_CallInstance);\n" file << " Mock.#{function[:name]}_CallInstance = CMock_Guts_MemNext(Mock.#{function[:name]}_CallInstance);\n"
file << @plugins.run(:mock_implementation_precheck, function) file << @plugins.run(:mock_implementation_precheck, function)
file << " UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, \"Function '#{function[:name]}' called more times than expected.\");\n" file << " UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringCalledMore);\n"
file << " cmock_line = cmock_call_instance->LineNumber;\n" file << " cmock_line = cmock_call_instance->LineNumber;\n"
if (@ordered) if (@ordered)
file << " if (cmock_call_instance->CallOrder > ++GlobalVerifyOrder)\n" file << " if (cmock_call_instance->CallOrder > ++GlobalVerifyOrder)\n"
file << " UNITY_TEST_FAIL(cmock_line, \"Function '#{function[:name]}' called earlier than expected.\");\n" file << " UNITY_TEST_FAIL(cmock_line, CMockStringCalledEarly);\n"
file << " if (cmock_call_instance->CallOrder < GlobalVerifyOrder)\n" file << " if (cmock_call_instance->CallOrder < GlobalVerifyOrder)\n"
file << " UNITY_TEST_FAIL(cmock_line, \"Function '#{function[:name]}' called later than expected.\");\n" file << " UNITY_TEST_FAIL(cmock_line, CMockStringCalledLate);\n"
# file << " UNITY_TEST_ASSERT((cmock_call_instance->CallOrder == ++GlobalVerifyOrder), cmock_line, \"Out of order function calls. Function '#{function[:name]}'\");\n" # file << " UNITY_TEST_ASSERT((cmock_call_instance->CallOrder == ++GlobalVerifyOrder), cmock_line, CMockStringCallOrder);\n"
end end
return_type = function[:return][:const?] ? "(const #{function[:return][:type]})" : ((function[:return][:type] =~ /cmock/) ? "(#{function[:return][:type]})" : '') return_type = function[:return][:const?] ? "(const #{function[:return][:type]})" : ((function[:return][:type] =~ /cmock/) ? "(#{function[:return][:type]})" : '')
file << @plugins.run(:mock_implementation, function) file << @plugins.run(:mock_implementation, function)
file << " UNITY_CLR_DETAILS();\n"
file << " return #{return_type}cmock_call_instance->ReturnVal;\n" unless (function[:return][:void?]) file << " return #{return_type}cmock_call_instance->ReturnVal;\n" unless (function[:return][:void?])
file << "}\n\n" file << "}\n\n"
end end
+5 -4
View File
@@ -2,13 +2,13 @@
# CMock Project - Automatic Mock Generation for C # CMock Project - Automatic Mock Generation for C
# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams # Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
# [Released under MIT License. Please refer to license.txt for details] # [Released under MIT License. Please refer to license.txt for details]
# ========================================== # ==========================================
class CMockGeneratorPluginCexception class CMockGeneratorPluginCexception
attr_reader :priority attr_reader :priority
attr_reader :config, :utils attr_reader :config, :utils
def initialize(config, utils) def initialize(config, utils)
@config = config @config = config
@utils = utils @utils = utils
@@ -22,7 +22,7 @@ class CMockGeneratorPluginCexception
def instance_typedefs(function) def instance_typedefs(function)
" CEXCEPTION_T ExceptionToThrow;\n" " CEXCEPTION_T ExceptionToThrow;\n"
end end
def mock_function_declarations(function) def mock_function_declarations(function)
if (function[:args_string] == "void") if (function[:args_string] == "void")
return "#define #{function[:name]}_ExpectAndThrow(cmock_to_throw) #{function[:name]}_CMockExpectAndThrow(__LINE__, cmock_to_throw)\n" + return "#define #{function[:name]}_ExpectAndThrow(cmock_to_throw) #{function[:name]}_CMockExpectAndThrow(__LINE__, cmock_to_throw)\n" +
@@ -34,7 +34,8 @@ class CMockGeneratorPluginCexception
end end
def mock_implementation(function) def mock_implementation(function)
" if (cmock_call_instance->ExceptionToThrow != CEXCEPTION_NONE)\n {\n" + " if (cmock_call_instance->ExceptionToThrow != CEXCEPTION_NONE)\n {\n" +
" UNITY_CLR_DETAILS();\n" +
" Throw(cmock_call_instance->ExceptionToThrow);\n }\n" " Throw(cmock_call_instance->ExceptionToThrow);\n }\n"
end end
+10 -8
View File
@@ -2,7 +2,7 @@
# CMock Project - Automatic Mock Generation for C # CMock Project - Automatic Mock Generation for C
# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams # Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
# [Released under MIT License. Please refer to license.txt for details] # [Released under MIT License. Please refer to license.txt for details]
# ========================================== # ==========================================
class CMockGeneratorPluginExpect class CMockGeneratorPluginExpect
@@ -17,7 +17,7 @@ class CMockGeneratorPluginExpect
@unity_helper = @utils.helpers[:unity_helper] @unity_helper = @utils.helpers[:unity_helper]
@priority = 5 @priority = 5
end end
def instance_typedefs(function) def instance_typedefs(function)
lines = "" lines = ""
lines << " #{function[:return][:type]} ReturnVal;\n" unless (function[:return][:void?]) lines << " #{function[:return][:type]} ReturnVal;\n" unless (function[:return][:void?])
@@ -27,7 +27,7 @@ class CMockGeneratorPluginExpect
end end
lines lines
end end
def mock_function_declarations(function) def mock_function_declarations(function)
if (function[:args].empty?) if (function[:args].empty?)
if (function[:return][:void?]) if (function[:return][:void?])
@@ -37,7 +37,7 @@ class CMockGeneratorPluginExpect
return "#define #{function[:name]}_ExpectAndReturn(cmock_retval) #{function[:name]}_CMockExpectAndReturn(__LINE__, cmock_retval)\n" + return "#define #{function[:name]}_ExpectAndReturn(cmock_retval) #{function[:name]}_CMockExpectAndReturn(__LINE__, cmock_retval)\n" +
"void #{function[:name]}_CMockExpectAndReturn(UNITY_LINE_TYPE cmock_line, #{function[:return][:str]});\n" "void #{function[:name]}_CMockExpectAndReturn(UNITY_LINE_TYPE cmock_line, #{function[:return][:str]});\n"
end end
else else
if (function[:return][:void?]) if (function[:return][:void?])
return "#define #{function[:name]}_Expect(#{function[:args_call]}) #{function[:name]}_CMockExpect(__LINE__, #{function[:args_call]})\n" + return "#define #{function[:name]}_Expect(#{function[:args_call]}) #{function[:name]}_CMockExpect(__LINE__, #{function[:args_call]})\n" +
"void #{function[:name]}_CMockExpect(UNITY_LINE_TYPE cmock_line, #{function[:args_string]});\n" "void #{function[:name]}_CMockExpect(UNITY_LINE_TYPE cmock_line, #{function[:args_string]});\n"
@@ -47,7 +47,7 @@ class CMockGeneratorPluginExpect
end end
end end
end end
def mock_implementation(function) def mock_implementation(function)
lines = "" lines = ""
function[:args].each do |arg| function[:args].each do |arg|
@@ -55,7 +55,7 @@ class CMockGeneratorPluginExpect
end end
lines lines
end end
def mock_interfaces(function) def mock_interfaces(function)
lines = "" lines = ""
func_name = function[:name] func_name = function[:name]
@@ -75,12 +75,14 @@ class CMockGeneratorPluginExpect
lines << @utils.code_add_base_expectation(func_name) lines << @utils.code_add_base_expectation(func_name)
lines << @utils.code_call_argument_loader(function) lines << @utils.code_call_argument_loader(function)
lines << @utils.code_assign_argument_quickly("cmock_call_instance->ReturnVal", function[:return]) unless (function[:return][:void?]) lines << @utils.code_assign_argument_quickly("cmock_call_instance->ReturnVal", function[:return]) unless (function[:return][:void?])
lines << " UNITY_CLR_DETAILS();\n"
lines << "}\n\n" lines << "}\n\n"
end end
def mock_verify(function) def mock_verify(function)
func_name = function[:name] func_name = function[:name]
" UNITY_TEST_ASSERT(CMOCK_GUTS_NONE == Mock.#{func_name}_CallInstance, cmock_line, \"Function '#{func_name}' called less times than expected.\");\n" " UNITY_SET_DETAIL(\"#{function[:name]}\");\n" +
" UNITY_TEST_ASSERT(CMOCK_GUTS_NONE == Mock.#{func_name}_CallInstance, cmock_line, CMockStringCalledLess);\n"
end end
end end
+1
View File
@@ -35,6 +35,7 @@ class CMockGeneratorPluginIgnore
def mock_implementation_precheck(function) def mock_implementation_precheck(function)
lines = " if (Mock.#{function[:name]}_IgnoreBool)\n {\n" lines = " if (Mock.#{function[:name]}_IgnoreBool)\n {\n"
lines << " UNITY_CLR_DETAILS();\n"
if (function[:return][:void?]) if (function[:return][:void?])
lines << " return;\n }\n" lines << " return;\n }\n"
else else
+1 -1
View File
@@ -35,7 +35,7 @@ class CMockGeneratorPluginIgnoreArg
lines << "{\n" lines << "{\n"
lines << " CMOCK_#{func_name}_CALL_INSTANCE* cmock_call_instance = " + lines << " CMOCK_#{func_name}_CALL_INSTANCE* cmock_call_instance = " +
"(CMOCK_#{func_name}_CALL_INSTANCE*)CMock_Guts_GetAddressFor(CMock_Guts_MemEndOfChain(Mock.#{func_name}_CallInstance));\n" "(CMOCK_#{func_name}_CALL_INSTANCE*)CMock_Guts_GetAddressFor(CMock_Guts_MemEndOfChain(Mock.#{func_name}_CallInstance));\n"
lines << " UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, \"#{arg_name} IgnoreArg called before Expect on '#{func_name}'.\");\n" lines << " UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringIgnPreExp);\n"
lines << " cmock_call_instance->IgnoreArg_#{arg_name} = 1;\n" lines << " cmock_call_instance->IgnoreArg_#{arg_name} = 1;\n"
lines << "}\n\n" lines << "}\n\n"
end end
@@ -46,7 +46,7 @@ class CMockGeneratorPluginReturnThruPtr
lines << "{\n" lines << "{\n"
lines << " CMOCK_#{func_name}_CALL_INSTANCE* cmock_call_instance = " + lines << " CMOCK_#{func_name}_CALL_INSTANCE* cmock_call_instance = " +
"(CMOCK_#{func_name}_CALL_INSTANCE*)CMock_Guts_GetAddressFor(CMock_Guts_MemEndOfChain(Mock.#{func_name}_CallInstance));\n" "(CMOCK_#{func_name}_CALL_INSTANCE*)CMock_Guts_GetAddressFor(CMock_Guts_MemEndOfChain(Mock.#{func_name}_CallInstance));\n"
lines << " UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, \"#{arg_name} ReturnThruPtr called before Expect on '#{func_name}'.\");\n" lines << " UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringPtrPreExp);\n"
lines << " cmock_call_instance->ReturnThruPtr_#{arg_name}_Used = 1;\n" lines << " cmock_call_instance->ReturnThruPtr_#{arg_name}_Used = 1;\n"
lines << " cmock_call_instance->ReturnThruPtr_#{arg_name}_Val = #{arg_name};\n" lines << " cmock_call_instance->ReturnThruPtr_#{arg_name}_Val = #{arg_name};\n"
lines << " cmock_call_instance->ReturnThruPtr_#{arg_name}_Size = cmock_size;\n" lines << " cmock_call_instance->ReturnThruPtr_#{arg_name}_Size = cmock_size;\n"
+29 -26
View File
@@ -121,30 +121,31 @@ class CMockGeneratorUtils
lines = "" lines = ""
lines << " if (!#{ignore})\n" if @ignore_arg lines << " if (!#{ignore})\n" if @ignore_arg
lines << " {\n" lines << " {\n"
lines << " UNITY_SET_DETAILS(\"#{function[:name]}\",\"#{arg_name}\");\n"
case(unity_func) case(unity_func)
when "UNITY_TEST_ASSERT_EQUAL_MEMORY" when "UNITY_TEST_ASSERT_EQUAL_MEMORY"
c_type_local = c_type.gsub(/\*$/,'') c_type_local = c_type.gsub(/\*$/,'')
lines << " UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type_local}), cmock_line, \"#{unity_msg}\");\n" lines << " UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type_local}), cmock_line, CMockStringMismatch);\n"
when "UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY" when "UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY"
if (pre == '&') if (pre == '&')
lines << " UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type.sub('*','')}), cmock_line, \"#{unity_msg}\");\n" lines << " UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type.sub('*','')}), cmock_line, CMockStringMismatch);\n"
else else
lines << " if (#{pre}#{expected} == NULL)\n" lines << " if (#{pre}#{expected} == NULL)\n"
lines << " { UNITY_TEST_ASSERT_NULL(#{pre}#{arg_name}, cmock_line, \"Expected NULL. #{unity_msg}\"); }\n" lines << " { UNITY_TEST_ASSERT_NULL(#{pre}#{arg_name}, cmock_line, CMockStringExpNULL); }\n"
lines << " else\n" lines << " else\n"
lines << " { UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type.sub('*','')}), cmock_line, \"#{unity_msg}\"); }\n" lines << " { UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type.sub('*','')}), cmock_line, CMockStringMismatch); }\n"
end end
when /_ARRAY/ when /_ARRAY/
if (pre == '&') if (pre == '&')
lines << " #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, 1, cmock_line, \"#{unity_msg}\");\n" lines << " #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, 1, cmock_line, CMockStringMismatch);\n"
else else
lines << " if (#{pre}#{expected} == NULL)\n" lines << " if (#{pre}#{expected} == NULL)\n"
lines << " { UNITY_TEST_ASSERT_NULL(#{pre}#{arg_name}, cmock_line, \"Expected NULL. #{unity_msg}\"); }\n" lines << " { UNITY_TEST_ASSERT_NULL(#{pre}#{arg_name}, cmock_line, CMockStringExpNULL); }\n"
lines << " else\n" lines << " else\n"
lines << " { #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, 1, cmock_line, \"#{unity_msg}\"); }\n" lines << " { #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, 1, cmock_line, CMockStringMismatch); }\n"
end end
else else
lines << " #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line, \"#{unity_msg}\");\n" lines << " #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line, CMockStringMismatch);\n"
end end
lines << " }\n" lines << " }\n"
lines lines
@@ -156,30 +157,31 @@ class CMockGeneratorUtils
lines = "" lines = ""
lines << " if (!#{ignore})\n" if @ignore_arg lines << " if (!#{ignore})\n" if @ignore_arg
lines << " {\n" lines << " {\n"
lines << " UNITY_SET_DETAILS(\"#{function[:name]}\",\"#{arg_name}\");\n"
case(unity_func) case(unity_func)
when "UNITY_TEST_ASSERT_EQUAL_MEMORY" when "UNITY_TEST_ASSERT_EQUAL_MEMORY"
c_type_local = c_type.gsub(/\*$/,'') c_type_local = c_type.gsub(/\*$/,'')
lines << " UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type_local}), cmock_line, \"#{unity_msg}\");\n" lines << " UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type_local}), cmock_line, CMockStringMismatch);\n"
when "UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY" when "UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY"
if (pre == '&') if (pre == '&')
lines << " UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type.sub('*','')}), cmock_line, \"#{unity_msg}\");\n" lines << " UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type.sub('*','')}), cmock_line, CMockStringMismatch);\n"
else else
lines << " if (#{pre}#{expected} == NULL)\n" lines << " if (#{pre}#{expected} == NULL)\n"
lines << " { UNITY_TEST_ASSERT_NULL(#{pre}#{arg_name}, cmock_line, \"Expected NULL. #{unity_msg}\"); }\n" lines << " { UNITY_TEST_ASSERT_NULL(#{pre}#{arg_name}, cmock_line, CMockStringExpNULL); }\n"
lines << " else\n" lines << " else\n"
lines << " { UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type.sub('*','')}), #{depth_name}, cmock_line, \"#{unity_msg}\"); }\n" lines << " { UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type.sub('*','')}), #{depth_name}, cmock_line, CMockStringMismatch); }\n"
end end
when /_ARRAY/ when /_ARRAY/
if (pre == '&') if (pre == '&')
lines << " #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, #{depth_name}, cmock_line, \"#{unity_msg}\");\n" lines << " #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, #{depth_name}, cmock_line, CMockStringMismatch);\n"
else else
lines << " if (#{pre}#{expected} == NULL)\n" lines << " if (#{pre}#{expected} == NULL)\n"
lines << " { UNITY_TEST_ASSERT_NULL(#{pre}#{arg_name}, cmock_line, \"Expected NULL. #{unity_msg}\"); }\n" lines << " { UNITY_TEST_ASSERT_NULL(#{pre}#{arg_name}, cmock_line, CMockStringExpNULL); }\n"
lines << " else\n" lines << " else\n"
lines << " { #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, #{depth_name}, cmock_line, \"#{unity_msg}\"); }\n" lines << " { #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, #{depth_name}, cmock_line, CMockStringMismatch); }\n"
end end
else else
lines << " #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line, \"#{unity_msg}\");\n" lines << " #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line, CMockStringMismatch);\n"
end end
lines << " }\n" lines << " }\n"
lines lines
@@ -191,32 +193,33 @@ class CMockGeneratorUtils
lines = "" lines = ""
lines << " if (!#{ignore})\n" if @ignore_arg lines << " if (!#{ignore})\n" if @ignore_arg
lines << " {\n" lines << " {\n"
lines << " UNITY_SET_DETAILS(\"#{function[:name]}\",\"#{arg_name}\");\n"
case(unity_func) case(unity_func)
when "UNITY_TEST_ASSERT_EQUAL_MEMORY" when "UNITY_TEST_ASSERT_EQUAL_MEMORY"
c_type_local = c_type.gsub(/\*$/,'') c_type_local = c_type.gsub(/\*$/,'')
lines << " UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type_local}), cmock_line, \"#{unity_msg}\");\n" lines << " UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type_local}), cmock_line, CMockStringMismatch);\n"
when "UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY" when "UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY"
if (pre == '&') if (pre == '&')
lines << " UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type.sub('*','')}), #{depth_name}, cmock_line, \"#{unity_msg}\");\n" lines << " UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type.sub('*','')}), #{depth_name}, cmock_line, CMockStringMismatch);\n"
else else
lines << " if (#{pre}#{expected} == NULL)\n" lines << " if (#{pre}#{expected} == NULL)\n"
lines << " { UNITY_TEST_ASSERT_NULL(#{arg_name}, cmock_line, \"Expected NULL. #{unity_msg}\"); }\n" lines << " { UNITY_TEST_ASSERT_NULL(#{arg_name}, cmock_line, CMockStringExpNULL); }\n"
lines << ((depth_name != 1) ? " else if (#{depth_name} == 0)\n { UNITY_TEST_ASSERT_EQUAL_PTR(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line, \"#{unity_msg}\"); }\n" : "") lines << ((depth_name != 1) ? " else if (#{depth_name} == 0)\n { UNITY_TEST_ASSERT_EQUAL_PTR(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line, CMockStringMismatch); }\n" : "")
lines << " else\n" lines << " else\n"
lines << " { UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type.sub('*','')}), #{depth_name}, cmock_line, \"#{unity_msg}\"); }\n" lines << " { UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type.sub('*','')}), #{depth_name}, cmock_line, CMockStringMismatch); }\n"
end end
when /_ARRAY/ when /_ARRAY/
if (pre == '&') if (pre == '&')
lines << " #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, #{depth_name}, cmock_line, \"#{unity_msg}\");\n" lines << " #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, #{depth_name}, cmock_line, CMockStringMismatch);\n"
else else
lines << " if (#{pre}#{expected} == NULL)\n" lines << " if (#{pre}#{expected} == NULL)\n"
lines << " { UNITY_TEST_ASSERT_NULL(#{pre}#{arg_name}, cmock_line, \"Expected NULL. #{unity_msg}\"); }\n" lines << " { UNITY_TEST_ASSERT_NULL(#{pre}#{arg_name}, cmock_line, CMockStringExpNULL); }\n"
lines << ((depth_name != 1) ? " else if (#{depth_name} == 0)\n { UNITY_TEST_ASSERT_EQUAL_PTR(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line, \"#{unity_msg}\"); }\n" : "") lines << ((depth_name != 1) ? " else if (#{depth_name} == 0)\n { UNITY_TEST_ASSERT_EQUAL_PTR(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line, CMockStringMismatch); }\n" : "")
lines << " else\n" lines << " else\n"
lines << " { #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, #{depth_name}, cmock_line, \"#{unity_msg}\"); }\n" lines << " { #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, #{depth_name}, cmock_line, CMockStringMismatch); }\n"
end end
else else
lines << " #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line, \"#{unity_msg}\");\n" lines << " #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line, CMockStringMismatch);\n"
end end
lines << " }\n" lines << " }\n"
lines lines
+9
View File
@@ -9,6 +9,15 @@
//public constants to be used by mocks //public constants to be used by mocks
const char* CMockStringOutOfMemory = "CMock has run out of memory. Please allocate more."; const char* CMockStringOutOfMemory = "CMock has run out of memory. Please allocate more.";
const char* CMockStringCalledMore = "Called more times than expected.";
const char* CMockStringCalledLess = "Called less times than expected.";
const char* CMockStringCalledEarly = "Called earlier than expected.";
const char* CMockStringCalledLate = "Called later than expected.";
const char* CMockStringCallOrder = "Called out of order.";
const char* CMockStringIgnPreExp = "IgnoreArg called before Expect.";
const char* CMockStringPtrPreExp = "ReturnThruPtr called before Expect.";
const char* CMockStringExpNULL = "Expected NULL.";
const char* CMockStringMismatch = "Function called with unexpected argument value.";
//private variables //private variables
#ifdef CMOCK_MEM_DYNAMIC #ifdef CMOCK_MEM_DYNAMIC
+10 -1
View File
@@ -8,7 +8,16 @@
#define CMOCK_FRAMEWORK_INTERNALS_H #define CMOCK_FRAMEWORK_INTERNALS_H
//These are constants that the generated mocks have access to //These are constants that the generated mocks have access to
const char* CMockStringOutOfMemory; extern const char* CMockStringOutOfMemory;
extern const char* CMockStringCalledMore;
extern const char* CMockStringCalledLess;
extern const char* CMockStringCalledEarly;
extern const char* CMockStringCalledLate;
extern const char* CMockStringCallOrder;
extern const char* CMockStringIgnPreExp;
extern const char* CMockStringPtrPreExp;
extern const char* CMockStringExpNULL;
extern const char* CMockStringMismatch;
//define CMOCK_MEM_DYNAMIC to grab memory as needed with malloc //define CMOCK_MEM_DYNAMIC to grab memory as needed with malloc
//when you do that, CMOCK_MEM_SIZE is used for incremental size instead of total //when you do that, CMOCK_MEM_SIZE is used for incremental size instead of total
+1
View File
@@ -61,6 +61,7 @@ compiler:
defines: defines:
prefix: '-D' prefix: '-D'
items: items:
- CMOCK
- 'UNITY_SUPPORT_64' - 'UNITY_SUPPORT_64'
- 'UNITY_POINTER_WIDTH=64' - 'UNITY_POINTER_WIDTH=64'
object_files: object_files:
+1
View File
@@ -29,6 +29,7 @@ compiler:
defines: defines:
prefix: '-D' prefix: '-D'
items: items:
- CMOCK
- 'UNITY_SUPPORT_64' - 'UNITY_SUPPORT_64'
object_files: object_files:
prefix: '-o' prefix: '-o'
+1
View File
@@ -28,6 +28,7 @@ compiler:
defines: defines:
prefix: '-D' prefix: '-D'
items: items:
- CMOCK
- 'UNITY_SUPPORT_64' - 'UNITY_SUPPORT_64'
- 'UNITY_POINTER_WIDTH=64' - 'UNITY_POINTER_WIDTH=64'
object_files: object_files:
+1
View File
@@ -29,6 +29,7 @@ compiler:
defines: defines:
prefix: '-D' prefix: '-D'
items: items:
- CMOCK
- 'CMOCK_MEM_STATIC' - 'CMOCK_MEM_STATIC'
- 'CMOCK_MEM_SIZE=1024' - 'CMOCK_MEM_SIZE=1024'
object_files: object_files:
+1
View File
@@ -46,6 +46,7 @@ compiler:
defines: defines:
prefix: '-D' prefix: '-D'
items: items:
- CMOCK
object_files: object_files:
prefix: '-o' prefix: '-o'
extension: '.r79' extension: '.r79'
+1
View File
@@ -45,6 +45,7 @@ compiler:
defines: defines:
prefix: '-D' prefix: '-D'
items: items:
- CMOCK
object_files: object_files:
prefix: '-o' prefix: '-o'
extension: '.r79' extension: '.r79'
@@ -0,0 +1,272 @@
---
:cmock:
:enforce_strict_ordering: 1
:plugins:
- :array
- :cexception
- :ignore
- :callback
- :return_thru_ptr
- :ignore_arg
- :expect_any_args
:callback_after_arg_check: false
:callback_include_count: false
:treat_externs: :include
:systest:
:types: |
typedef struct _POINT_T {
int x;
int y;
} POINT_T;
:mockable: |
#include "CException.h"
extern void foo(POINT_T* a);
POINT_T* bar(void);
void no_args(void);
:source:
:header: |
#include "CException.h"
void function_a(void);
void function_b(void);
void function_c(void);
int function_d(void);
void function_e(void);
:code: |
void function_a(void)
{
foo(bar());
no_args();
}
:tests:
:common: |
#include "CException.h"
void setUp(void) {}
void tearDown(void) {}
void my_foo_callback(POINT_T* a) { TEST_ASSERT_EQUAL_INT(2, a->x); }
:units:
- :pass: TRUE
:should: 'just pass if we do not insert anything ugly into it'
:code: |
test()
{
bar_ExpectAndReturn(NULL);
foo_Expect(NULL);
no_args_Expect();
function_a();
}
- :pass: FALSE
:should: 'not contain mock details in failed assertion after an expect and return'
:verify_error: 'FAIL: Expected 1 Was 2. CustomFail'
:code: |
test()
{
bar_ExpectAndReturn(NULL);
TEST_ASSERT_EQUAL_INT_MESSAGE(1,2,"CustomFail");
foo_Expect(NULL);
no_args_Expect();
function_a();
}
- :pass: FALSE
:should: 'not contain mock details in failed assertion after an expect'
:verify_error: 'FAIL: Expected 1 Was 2. CustomFail'
:code: |
test()
{
bar_ExpectAndReturn(NULL);
foo_Expect(NULL);
TEST_ASSERT_EQUAL_INT_MESSAGE(1,2,"CustomFail");
no_args_Expect();
function_a();
}
- :pass: FALSE
:should: 'not contain mock details in failed assertion after throw expectation'
:verify_error: 'FAIL: Expected 1 Was 2. CustomFail'
:code: |
test()
{
CEXCEPTION_T e;
bar_ExpectAndReturn(NULL);
foo_Expect(NULL);
no_args_ExpectAndThrow(5);
TEST_ASSERT_EQUAL_INT_MESSAGE(1,2,"CustomFail");
Try { function_a(); } Catch(e) {}
}
- :pass: FALSE
:should: 'not contain mock details in failed assertion after a mock call'
:verify_error: 'FAIL: Expected 1 Was 2. CustomFail'
:code: |
test()
{
bar_ExpectAndReturn(NULL);
foo_Expect(NULL);
no_args_Expect();
function_a();
TEST_ASSERT_EQUAL_INT_MESSAGE(1,2,"CustomFail");
}
- :pass: FALSE
:should: 'not contain mock details in failed assertion after throw'
:verify_error: 'FAIL: Expected 1 Was 2. CustomFail'
:code: |
test()
{
CEXCEPTION_T e;
bar_ExpectAndReturn(NULL);
foo_Expect(NULL);
no_args_ExpectAndThrow(5);
Try { function_a(); } Catch(e) {}
TEST_ASSERT_EQUAL_INT_MESSAGE(1,2,"CustomFail");
}
- :pass: FALSE
:should: 'not contain mock details in failed assertion after ignore'
:verify_error: 'FAIL: Expected 1 Was 2. CustomFail'
:code: |
test()
{
bar_ExpectAndReturn(NULL);
foo_Expect(NULL);
no_args_Ignore();
TEST_ASSERT_EQUAL_INT_MESSAGE(1,2,"CustomFail");
function_a();
}
- :pass: FALSE
:should: 'not contain mock details in failed assertion after ignored mock'
:verify_error: 'FAIL: Expected 1 Was 2. CustomFail'
:code: |
test()
{
bar_ExpectAndReturn(NULL);
foo_Expect(NULL);
no_args_Ignore();
function_a();
TEST_ASSERT_EQUAL_INT_MESSAGE(1,2,"CustomFail");
}
- :pass: FALSE
:should: 'not contain mock details in failed assertion after callback setup'
:verify_error: 'FAIL: Expected 1 Was 2. CustomFail'
:code: |
test()
{
POINT_T pt = { 2, 2 };
bar_ExpectAndReturn(&pt);
foo_StubWithCallback(my_foo_callback);
TEST_ASSERT_EQUAL_INT_MESSAGE(1,2,"CustomFail");
no_args_Expect();
function_a();
}
- :pass: FALSE
:should: 'not contain mock details in failed assertion after mock with callback'
:verify_error: 'FAIL: Expected 1 Was 2. CustomFail'
:code: |
test()
{
POINT_T pt = { 2, 2 };
bar_ExpectAndReturn(&pt);
foo_StubWithCallback(my_foo_callback);
no_args_Expect();
function_a();
TEST_ASSERT_EQUAL_INT_MESSAGE(1,2,"CustomFail");
}
- :pass: FALSE
:should: 'not contain mock details in failed assertion after expect any args'
:verify_error: 'FAIL: Expected 1 Was 2. CustomFail'
:code: |
test()
{
POINT_T pt = { 2, 2 };
bar_ExpectAndReturn(&pt);
foo_ExpectAnyArgs();
TEST_ASSERT_EQUAL_INT_MESSAGE(1,2,"CustomFail");
no_args_Expect();
function_a();
}
- :pass: FALSE
:should: 'not contain mock details in failed assertion after mock which expected any args'
:verify_error: 'FAIL: Expected 1 Was 2. CustomFail'
:code: |
test()
{
POINT_T pt = { 2, 2 };
bar_ExpectAndReturn(&pt);
foo_ExpectAnyArgs();
no_args_Expect();
function_a();
TEST_ASSERT_EQUAL_INT_MESSAGE(1,2,"CustomFail");
}
- :pass: FALSE
:should: 'not contain mock details in failed assertion after ignored arg'
:verify_error: 'FAIL: Expected 1 Was 2. CustomFail'
:code: |
test()
{
POINT_T pt = { 2, 2 };
bar_ExpectAndReturn(&pt);
foo_Expect(NULL);
foo_IgnoreArg_a();
TEST_ASSERT_EQUAL_INT_MESSAGE(1,2,"CustomFail");
no_args_Expect();
function_a();
}
- :pass: FALSE
:should: 'not contain mock details in failed assertion after mock which ignored an arg'
:verify_error: 'FAIL: Expected 1 Was 2. CustomFail'
:code: |
test()
{
POINT_T pt = { 2, 2 };
bar_ExpectAndReturn(&pt);
foo_Expect(NULL);
foo_IgnoreArg_a();
no_args_Expect();
function_a();
TEST_ASSERT_EQUAL_INT_MESSAGE(1,2,"CustomFail");
}
...
@@ -8,7 +8,7 @@
:systest: :systest:
:types: | :types: |
#define UINT32 unsigned int #define UINT32 unsigned int
typedef signed int custom_type; typedef signed int custom_type;
:mockable: | :mockable: |
@@ -17,7 +17,7 @@
UINT32 bar(custom_type b); UINT32 bar(custom_type b);
void baz(custom_type c); void baz(custom_type c);
:source: :source:
:header: | :header: |
#include "CException.h" #include "CException.h"
UINT32 function_a(int a, int b); UINT32 function_a(int a, int b);
@@ -26,13 +26,13 @@
void function_d(void); void function_d(void);
:code: | :code: |
UINT32 function_a(int a, int b) UINT32 function_a(int a, int b)
{ {
return foo((custom_type)a) + bar((custom_type)b); return foo((custom_type)a) + bar((custom_type)b);
} }
void function_b(void) void function_b(void)
{ {
baz((custom_type)1); baz((custom_type)1);
foo((custom_type)2); foo((custom_type)2);
bar((custom_type)3); bar((custom_type)3);
@@ -42,7 +42,7 @@
baz((custom_type)7); baz((custom_type)7);
} }
void function_c(void) void function_c(void)
{ {
foo((custom_type)1); foo((custom_type)1);
foo((custom_type)2); foo((custom_type)2);
@@ -50,7 +50,7 @@
bar((custom_type)4); bar((custom_type)4);
foo((custom_type)5); foo((custom_type)5);
} }
void function_d(void) void function_d(void)
{ {
CEXCEPTION_T e; CEXCEPTION_T e;
@@ -70,13 +70,13 @@
} }
Catch(e) {} Catch(e) {}
} }
:tests: :tests:
:common: | :common: |
#include "CException.h" #include "CException.h"
void setUp(void) {} void setUp(void) {}
void tearDown(void) {} void tearDown(void) {}
:units: :units:
- :pass: TRUE - :pass: TRUE
:should: 'successfully exercise two simple ExpectAndReturn mock calls' :should: 'successfully exercise two simple ExpectAndReturn mock calls'
@@ -87,20 +87,20 @@
bar_ExpectAndReturn((custom_type)2, 20); bar_ExpectAndReturn((custom_type)2, 20);
TEST_ASSERT_EQUAL(30, function_a(1, 2)); TEST_ASSERT_EQUAL(30, function_a(1, 2));
} }
- :pass: FALSE - :pass: FALSE
:should: 'fail because bar() is called but is not expected' :should: 'fail because bar() is called but is not expected'
:verify_error: 'called more times than expected' :verify_error: 'Called more times than expected'
:code: | :code: |
test() test()
{ {
foo_ExpectAndReturn((custom_type)1, 10); foo_ExpectAndReturn((custom_type)1, 10);
TEST_ASSERT_EQUAL(30, function_a(1, 2)); TEST_ASSERT_EQUAL(30, function_a(1, 2));
} }
- :pass: FALSE - :pass: FALSE
:should: 'fail because bar() is called twice but is expected once' :should: 'fail because bar() is called twice but is expected once'
:verify_error: 'called less times than expected' :verify_error: 'Called less times than expected'
:code: | :code: |
test() test()
{ {
@@ -112,7 +112,7 @@
- :pass: FALSE - :pass: FALSE
:should: 'fail because bar and foo called in reverse order' :should: 'fail because bar and foo called in reverse order'
:verify_error: 'called earlier than expected' :verify_error: 'Called earlier than expected'
:code: | :code: |
test() test()
{ {
@@ -185,7 +185,7 @@
bar_ExpectAndReturn((custom_type)6, 10); bar_ExpectAndReturn((custom_type)6, 10);
function_b(); function_b();
} }
- :pass: TRUE - :pass: TRUE
:should: 'pass when using cexception, as long as the order is right' :should: 'pass when using cexception, as long as the order is right'
:code: | :code: |
@@ -207,7 +207,7 @@
foo_ExpectAndReturn((custom_type)3, 10); foo_ExpectAndReturn((custom_type)3, 10);
function_d(); function_d();
} }
- :pass: TRUE - :pass: TRUE
:should: 'successfully handle back to back ExpectAndReturn setup and mock calls' :should: 'successfully handle back to back ExpectAndReturn setup and mock calls'
:code: | :code: |
@@ -216,30 +216,30 @@
foo_ExpectAndReturn((custom_type)1, 10); foo_ExpectAndReturn((custom_type)1, 10);
bar_ExpectAndReturn((custom_type)2, 20); bar_ExpectAndReturn((custom_type)2, 20);
TEST_ASSERT_EQUAL(30, function_a(1, 2)); TEST_ASSERT_EQUAL(30, function_a(1, 2));
foo_ExpectAndReturn((custom_type)3, 30); foo_ExpectAndReturn((custom_type)3, 30);
bar_ExpectAndReturn((custom_type)4, 40); bar_ExpectAndReturn((custom_type)4, 40);
TEST_ASSERT_EQUAL(70, function_a(3, 4)); TEST_ASSERT_EQUAL(70, function_a(3, 4));
foo_ExpectAndReturn((custom_type)1, 50); foo_ExpectAndReturn((custom_type)1, 50);
bar_ExpectAndReturn((custom_type)9, 60); bar_ExpectAndReturn((custom_type)9, 60);
TEST_ASSERT_EQUAL(110, function_a(1, 9)); TEST_ASSERT_EQUAL(110, function_a(1, 9));
} }
- :pass: FALSE - :pass: FALSE
:should: 'successfully catch errors during back to back ExpectAndReturn setup and mock calls' :should: 'successfully catch errors during back to back ExpectAndReturn setup and mock calls'
:verify_error: 'called earlier than expected' :verify_error: 'Called earlier than expected'
:code: | :code: |
test() test()
{ {
foo_ExpectAndReturn((custom_type)1, 10); foo_ExpectAndReturn((custom_type)1, 10);
bar_ExpectAndReturn((custom_type)2, 20); bar_ExpectAndReturn((custom_type)2, 20);
TEST_ASSERT_EQUAL(30, function_a(1, 2)); TEST_ASSERT_EQUAL(30, function_a(1, 2));
foo_ExpectAndReturn((custom_type)3, 30); foo_ExpectAndReturn((custom_type)3, 30);
bar_ExpectAndReturn((custom_type)4, 40); bar_ExpectAndReturn((custom_type)4, 40);
TEST_ASSERT_EQUAL(70, function_a(3, 4)); TEST_ASSERT_EQUAL(70, function_a(3, 4));
bar_ExpectAndReturn((custom_type)9, 60); bar_ExpectAndReturn((custom_type)9, 60);
foo_ExpectAndReturn((custom_type)1, 50); foo_ExpectAndReturn((custom_type)1, 50);
TEST_ASSERT_EQUAL(110, function_a(1, 9)); TEST_ASSERT_EQUAL(110, function_a(1, 9));
+6 -2
View File
@@ -440,13 +440,15 @@ describe CMockGenerator, "Verify CMockGenerator Module" do
expected = [ "static int SupaFunction(uint32 sandwiches, const char* named)\n", expected = [ "static int SupaFunction(uint32 sandwiches, const char* named)\n",
"{\n", "{\n",
" UNITY_LINE_TYPE cmock_line = TEST_LINE_NUM;\n", " UNITY_LINE_TYPE cmock_line = TEST_LINE_NUM;\n",
" UNITY_SET_DETAIL(\"SupaFunction\");\n",
" CMOCK_SupaFunction_CALL_INSTANCE* cmock_call_instance = (CMOCK_SupaFunction_CALL_INSTANCE*)CMock_Guts_GetAddressFor(Mock.SupaFunction_CallInstance);\n", " CMOCK_SupaFunction_CALL_INSTANCE* cmock_call_instance = (CMOCK_SupaFunction_CALL_INSTANCE*)CMock_Guts_GetAddressFor(Mock.SupaFunction_CallInstance);\n",
" Mock.SupaFunction_CallInstance = CMock_Guts_MemNext(Mock.SupaFunction_CallInstance);\n", " Mock.SupaFunction_CallInstance = CMock_Guts_MemNext(Mock.SupaFunction_CallInstance);\n",
" uno", " uno",
" UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, \"Function 'SupaFunction' called more times than expected.\");\n", " UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringCalledMore);\n",
" cmock_line = cmock_call_instance->LineNumber;\n", " cmock_line = cmock_call_instance->LineNumber;\n",
" dos", " dos",
" tres", " tres",
" UNITY_CLR_DETAILS();\n",
" return cmock_call_instance->ReturnVal;\n", " return cmock_call_instance->ReturnVal;\n",
"}\n\n" "}\n\n"
] ]
@@ -472,13 +474,15 @@ describe CMockGenerator, "Verify CMockGenerator Module" do
expected = [ "int __stdcall SupaFunction(uint32 sandwiches, corn ...)\n", expected = [ "int __stdcall SupaFunction(uint32 sandwiches, corn ...)\n",
"{\n", "{\n",
" UNITY_LINE_TYPE cmock_line = TEST_LINE_NUM;\n", " UNITY_LINE_TYPE cmock_line = TEST_LINE_NUM;\n",
" UNITY_SET_DETAIL(\"SupaFunction\");\n",
" CMOCK_SupaFunction_CALL_INSTANCE* cmock_call_instance = (CMOCK_SupaFunction_CALL_INSTANCE*)CMock_Guts_GetAddressFor(Mock.SupaFunction_CallInstance);\n", " CMOCK_SupaFunction_CALL_INSTANCE* cmock_call_instance = (CMOCK_SupaFunction_CALL_INSTANCE*)CMock_Guts_GetAddressFor(Mock.SupaFunction_CallInstance);\n",
" Mock.SupaFunction_CallInstance = CMock_Guts_MemNext(Mock.SupaFunction_CallInstance);\n", " Mock.SupaFunction_CallInstance = CMock_Guts_MemNext(Mock.SupaFunction_CallInstance);\n",
" uno", " uno",
" UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, \"Function 'SupaFunction' called more times than expected.\");\n", " UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringCalledMore);\n",
" cmock_line = cmock_call_instance->LineNumber;\n", " cmock_line = cmock_call_instance->LineNumber;\n",
" dos", " dos",
" tres", " tres",
" UNITY_CLR_DETAILS();\n",
" return cmock_call_instance->ReturnVal;\n", " return cmock_call_instance->ReturnVal;\n",
"}\n\n" "}\n\n"
] ]
@@ -52,8 +52,11 @@ describe CMockGeneratorPluginCexception, "Verify CMockGeneratorPluginCexception
it "add a mock implementation" do it "add a mock implementation" do
function = {:name => "Cherry", :args => [], :return => test_return[:void]} function = {:name => "Cherry", :args => [], :return => test_return[:void]}
expected = " if (cmock_call_instance->ExceptionToThrow != CEXCEPTION_NONE)\n {\n" + expected = " if (cmock_call_instance->ExceptionToThrow != CEXCEPTION_NONE)\n" +
" Throw(cmock_call_instance->ExceptionToThrow);\n }\n" " {\n" +
" UNITY_CLR_DETAILS();\n" +
" Throw(cmock_call_instance->ExceptionToThrow);\n" +
" }\n"
returned = @cmock_generator_plugin_cexception.mock_implementation(function) returned = @cmock_generator_plugin_cexception.mock_implementation(function)
assert_equal(expected, returned) assert_equal(expected, returned)
end end
@@ -142,6 +142,7 @@ describe CMockGeneratorPluginExpect, "Verify CMockGeneratorPluginExpect Module"
"{\n", "{\n",
"mock_retval_0 ", "mock_retval_0 ",
"mock_retval_1 ", "mock_retval_1 ",
" UNITY_CLR_DETAILS();\n",
"}\n\n" "}\n\n"
].join ].join
returned = @cmock_generator_plugin_expect.mock_interfaces(function) returned = @cmock_generator_plugin_expect.mock_interfaces(function)
@@ -158,6 +159,7 @@ describe CMockGeneratorPluginExpect, "Verify CMockGeneratorPluginExpect Module"
"mock_retval_0 ", "mock_retval_0 ",
"mock_retval_1 ", "mock_retval_1 ",
"mock_retval_2", "mock_retval_2",
" UNITY_CLR_DETAILS();\n",
"}\n\n" "}\n\n"
].join ].join
returned = @cmock_generator_plugin_expect.mock_interfaces(function) returned = @cmock_generator_plugin_expect.mock_interfaces(function)
@@ -174,6 +176,7 @@ describe CMockGeneratorPluginExpect, "Verify CMockGeneratorPluginExpect Module"
"mock_retval_0 ", "mock_retval_0 ",
"mock_retval_1 ", "mock_retval_1 ",
"mock_retval_2", "mock_retval_2",
" UNITY_CLR_DETAILS();\n",
"}\n\n" "}\n\n"
].join ].join
returned = @cmock_generator_plugin_expect.mock_interfaces(function) returned = @cmock_generator_plugin_expect.mock_interfaces(function)
@@ -188,6 +191,7 @@ describe CMockGeneratorPluginExpect, "Verify CMockGeneratorPluginExpect Module"
"{\n", "{\n",
"mock_retval_0 ", "mock_retval_0 ",
"mock_retval_1 ", "mock_retval_1 ",
" UNITY_CLR_DETAILS();\n",
"}\n\n" "}\n\n"
].join ].join
@cmock_generator_plugin_expect.ordered = true @cmock_generator_plugin_expect.ordered = true
@@ -197,7 +201,8 @@ describe CMockGeneratorPluginExpect, "Verify CMockGeneratorPluginExpect Module"
it "add mock verify lines" do it "add mock verify lines" do
function = {:name => "Banana" } function = {:name => "Banana" }
expected = " UNITY_TEST_ASSERT(CMOCK_GUTS_NONE == Mock.Banana_CallInstance, cmock_line, \"Function 'Banana' called less times than expected.\");\n" expected = " UNITY_SET_DETAIL(\"Banana\");\n" +
" UNITY_TEST_ASSERT(CMOCK_GUTS_NONE == Mock.Banana_CallInstance, cmock_line, CMockStringCalledLess);\n"
returned = @cmock_generator_plugin_expect.mock_verify(function) returned = @cmock_generator_plugin_expect.mock_verify(function)
assert_equal(expected, returned) assert_equal(expected, returned)
end end
@@ -85,7 +85,7 @@ describe CMockGeneratorPluginIgnoreArg, "Verify CMockGeneratorPluginIgnoreArg Mo
"{\n" + "{\n" +
" CMOCK_Pine_CALL_INSTANCE* cmock_call_instance = " + " CMOCK_Pine_CALL_INSTANCE* cmock_call_instance = " +
"(CMOCK_Pine_CALL_INSTANCE*)CMock_Guts_GetAddressFor(CMock_Guts_MemEndOfChain(Mock.Pine_CallInstance));\n" + "(CMOCK_Pine_CALL_INSTANCE*)CMock_Guts_GetAddressFor(CMock_Guts_MemEndOfChain(Mock.Pine_CallInstance));\n" +
" UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, \"chicken IgnoreArg called before Expect on 'Pine'.\");\n" + " UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringIgnPreExp);\n" +
" cmock_call_instance->IgnoreArg_chicken = 1;\n" + " cmock_call_instance->IgnoreArg_chicken = 1;\n" +
"}\n\n" + "}\n\n" +
@@ -93,7 +93,7 @@ describe CMockGeneratorPluginIgnoreArg, "Verify CMockGeneratorPluginIgnoreArg Mo
"{\n" + "{\n" +
" CMOCK_Pine_CALL_INSTANCE* cmock_call_instance = " + " CMOCK_Pine_CALL_INSTANCE* cmock_call_instance = " +
"(CMOCK_Pine_CALL_INSTANCE*)CMock_Guts_GetAddressFor(CMock_Guts_MemEndOfChain(Mock.Pine_CallInstance));\n" + "(CMOCK_Pine_CALL_INSTANCE*)CMock_Guts_GetAddressFor(CMock_Guts_MemEndOfChain(Mock.Pine_CallInstance));\n" +
" UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, \"beef IgnoreArg called before Expect on 'Pine'.\");\n" + " UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringIgnPreExp);\n" +
" cmock_call_instance->IgnoreArg_beef = 1;\n" + " cmock_call_instance->IgnoreArg_beef = 1;\n" +
"}\n\n" + "}\n\n" +
@@ -101,7 +101,7 @@ describe CMockGeneratorPluginIgnoreArg, "Verify CMockGeneratorPluginIgnoreArg Mo
"{\n" + "{\n" +
" CMOCK_Pine_CALL_INSTANCE* cmock_call_instance = " + " CMOCK_Pine_CALL_INSTANCE* cmock_call_instance = " +
"(CMOCK_Pine_CALL_INSTANCE*)CMock_Guts_GetAddressFor(CMock_Guts_MemEndOfChain(Mock.Pine_CallInstance));\n" + "(CMOCK_Pine_CALL_INSTANCE*)CMock_Guts_GetAddressFor(CMock_Guts_MemEndOfChain(Mock.Pine_CallInstance));\n" +
" UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, \"tofu IgnoreArg called before Expect on 'Pine'.\");\n" + " UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringIgnPreExp);\n" +
" cmock_call_instance->IgnoreArg_tofu = 1;\n" + " cmock_call_instance->IgnoreArg_tofu = 1;\n" +
"}\n\n" "}\n\n"
@@ -52,6 +52,7 @@ describe CMockGeneratorPluginIgnore, "Verify CMockGeneratorPluginIgnore Module"
function = {:name => "Mold", :args_string => "void", :return => test_return[:void]} function = {:name => "Mold", :args_string => "void", :return => test_return[:void]}
expected = [" if (Mock.Mold_IgnoreBool)\n", expected = [" if (Mock.Mold_IgnoreBool)\n",
" {\n", " {\n",
" UNITY_CLR_DETAILS();\n",
" return;\n", " return;\n",
" }\n" " }\n"
].join ].join
@@ -65,6 +66,7 @@ describe CMockGeneratorPluginIgnore, "Verify CMockGeneratorPluginIgnore Module"
@utils.expect :code_assign_argument_quickly, ' mock_retval_0', ["Mock.Fungus_FinalReturn", retval] @utils.expect :code_assign_argument_quickly, ' mock_retval_0', ["Mock.Fungus_FinalReturn", retval]
expected = [" if (Mock.Fungus_IgnoreBool)\n", expected = [" if (Mock.Fungus_IgnoreBool)\n",
" {\n", " {\n",
" UNITY_CLR_DETAILS();\n",
" if (cmock_call_instance == NULL)\n", " if (cmock_call_instance == NULL)\n",
" return Mock.Fungus_FinalReturn;\n", " return Mock.Fungus_FinalReturn;\n",
" mock_retval_0", " mock_retval_0",
@@ -108,7 +108,7 @@ describe CMockGeneratorPluginReturnThruPtr, "Verify CMockGeneratorPluginReturnTh
"{\n" + "{\n" +
" CMOCK_Pine_CALL_INSTANCE* cmock_call_instance = " + " CMOCK_Pine_CALL_INSTANCE* cmock_call_instance = " +
"(CMOCK_Pine_CALL_INSTANCE*)CMock_Guts_GetAddressFor(CMock_Guts_MemEndOfChain(Mock.Pine_CallInstance));\n" + "(CMOCK_Pine_CALL_INSTANCE*)CMock_Guts_GetAddressFor(CMock_Guts_MemEndOfChain(Mock.Pine_CallInstance));\n" +
" UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, \"tofu ReturnThruPtr called before Expect on 'Pine'.\");\n" + " UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringPtrPreExp);\n" +
" cmock_call_instance->ReturnThruPtr_tofu_Used = 1;\n" + " cmock_call_instance->ReturnThruPtr_tofu_Used = 1;\n" +
" cmock_call_instance->ReturnThruPtr_tofu_Val = tofu;\n" + " cmock_call_instance->ReturnThruPtr_tofu_Val = tofu;\n" +
" cmock_call_instance->ReturnThruPtr_tofu_Size = cmock_size;\n" + " cmock_call_instance->ReturnThruPtr_tofu_Size = cmock_size;\n" +
+60 -17
View File
@@ -204,7 +204,10 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do
it 'handle a simple assert when requested' do it 'handle a simple assert when requested' do
function = { :name => 'Pear' } function = { :name => 'Pear' }
arg = test_arg[:int] arg = test_arg[:int]
expected = " {\n UNITY_TEST_ASSERT_EQUAL_INT(cmock_call_instance->Expected_MyInt, MyInt, cmock_line, \"Function 'Pear' called with unexpected value for argument 'MyInt'.\");\n }\n" expected = " {\n" +
" UNITY_SET_DETAILS(\"Pear\",\"MyInt\");\n" +
" UNITY_TEST_ASSERT_EQUAL_INT(cmock_call_instance->Expected_MyInt, MyInt, cmock_line, CMockStringMismatch);\n" +
" }\n"
@unity_helper.expect :nil?, false @unity_helper.expect :nil?, false
@unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_INT', ''], ['int'] @unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_INT', ''], ['int']
assert_equal(expected, @cmock_generator_utils_simple.code_verify_an_arg_expectation(function, arg)) assert_equal(expected, @cmock_generator_utils_simple.code_verify_an_arg_expectation(function, arg))
@@ -213,14 +216,20 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do
it 'handle a pointer comparison when configured to do so' do it 'handle a pointer comparison when configured to do so' do
function = { :name => 'Pear' } function = { :name => 'Pear' }
arg = test_arg[:int_ptr] arg = test_arg[:int_ptr]
expected = " {\n UNITY_TEST_ASSERT_EQUAL_PTR(cmock_call_instance->Expected_MyIntPtr, MyIntPtr, cmock_line, \"Function 'Pear' called with unexpected value for argument 'MyIntPtr'.\");\n }\n" expected = " {\n" +
" UNITY_SET_DETAILS(\"Pear\",\"MyIntPtr\");\n" +
" UNITY_TEST_ASSERT_EQUAL_PTR(cmock_call_instance->Expected_MyIntPtr, MyIntPtr, cmock_line, CMockStringMismatch);\n" +
" }\n"
assert_equal(expected, @cmock_generator_utils_simple.code_verify_an_arg_expectation(function, arg)) assert_equal(expected, @cmock_generator_utils_simple.code_verify_an_arg_expectation(function, arg))
end end
it 'handle const char as string compares ' do it 'handle const char as string compares ' do
function = { :name => 'Pear' } function = { :name => 'Pear' }
arg = test_arg[:string] arg = test_arg[:string]
expected = " {\n UNITY_TEST_ASSERT_EQUAL_STRING(cmock_call_instance->Expected_MyStr, MyStr, cmock_line, \"Function 'Pear' called with unexpected value for argument 'MyStr'.\");\n }\n" expected = " {\n" +
" UNITY_SET_DETAILS(\"Pear\",\"MyStr\");\n" +
" UNITY_TEST_ASSERT_EQUAL_STRING(cmock_call_instance->Expected_MyStr, MyStr, cmock_line, CMockStringMismatch);\n" +
" }\n"
@unity_helper.expect :nil?, false @unity_helper.expect :nil?, false
@unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_STRING',''], ['char*'] @unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_STRING',''], ['char*']
assert_equal(expected, @cmock_generator_utils_simple.code_verify_an_arg_expectation(function, arg)) assert_equal(expected, @cmock_generator_utils_simple.code_verify_an_arg_expectation(function, arg))
@@ -229,7 +238,10 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do
it 'handle custom types as memory compares when we have no better way to do it' do it 'handle custom types as memory compares when we have no better way to do it' do
function = { :name => 'Pear' } function = { :name => 'Pear' }
arg = test_arg[:mytype] arg = test_arg[:mytype]
expected = " {\n UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)(&cmock_call_instance->Expected_MyMyType), (void*)(&MyMyType), sizeof(MY_TYPE), cmock_line, \"Function 'Pear' called with unexpected value for argument 'MyMyType'.\");\n }\n" expected = " {\n" +
" UNITY_SET_DETAILS(\"Pear\",\"MyMyType\");\n" +
" UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)(&cmock_call_instance->Expected_MyMyType), (void*)(&MyMyType), sizeof(MY_TYPE), cmock_line, CMockStringMismatch);\n" +
" }\n"
@unity_helper.expect :nil?, false @unity_helper.expect :nil?, false
@unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_MEMORY','&'], ['MY_TYPE'] @unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_MEMORY','&'], ['MY_TYPE']
assert_equal(expected, @cmock_generator_utils_simple.code_verify_an_arg_expectation(function, arg)) assert_equal(expected, @cmock_generator_utils_simple.code_verify_an_arg_expectation(function, arg))
@@ -238,7 +250,10 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do
it 'handle custom types with custom handlers when available, even if they do not support the extra message' do it 'handle custom types with custom handlers when available, even if they do not support the extra message' do
function = { :name => 'Pear' } function = { :name => 'Pear' }
arg = test_arg[:mytype] arg = test_arg[:mytype]
expected = " {\n UNITY_TEST_ASSERT_EQUAL_MY_TYPE(cmock_call_instance->Expected_MyMyType, MyMyType, cmock_line, \"Function 'Pear' called with unexpected value for argument 'MyMyType'.\");\n }\n" expected = " {\n" +
" UNITY_SET_DETAILS(\"Pear\",\"MyMyType\");\n" +
" UNITY_TEST_ASSERT_EQUAL_MY_TYPE(cmock_call_instance->Expected_MyMyType, MyMyType, cmock_line, CMockStringMismatch);\n" +
" }\n"
@unity_helper.expect :nil?, false @unity_helper.expect :nil?, false
@unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_MY_TYPE',''], ['MY_TYPE'] @unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_MY_TYPE',''], ['MY_TYPE']
assert_equal(expected, @cmock_generator_utils_simple.code_verify_an_arg_expectation(function, arg)) assert_equal(expected, @cmock_generator_utils_simple.code_verify_an_arg_expectation(function, arg))
@@ -247,7 +262,10 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do
it 'handle pointers to custom types with array handlers, even if the array extension is turned off' do it 'handle pointers to custom types with array handlers, even if the array extension is turned off' do
function = { :name => 'Pear' } function = { :name => 'Pear' }
arg = test_arg[:mytype] arg = test_arg[:mytype]
expected = " {\n UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY(&cmock_call_instance->Expected_MyMyType, &MyMyType, 1, cmock_line, \"Function 'Pear' called with unexpected value for argument 'MyMyType'.\");\n }\n" expected = " {\n" +
" UNITY_SET_DETAILS(\"Pear\",\"MyMyType\");\n" +
" UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY(&cmock_call_instance->Expected_MyMyType, &MyMyType, 1, cmock_line, CMockStringMismatch);\n" +
" }\n"
@unity_helper.expect :nil?, false @unity_helper.expect :nil?, false
@unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY','&'], ['MY_TYPE'] @unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY','&'], ['MY_TYPE']
assert_equal(expected, @cmock_generator_utils_simple.code_verify_an_arg_expectation(function, arg)) assert_equal(expected, @cmock_generator_utils_simple.code_verify_an_arg_expectation(function, arg))
@@ -256,7 +274,11 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do
it 'handle a simple assert when requested with array plugin enabled' do it 'handle a simple assert when requested with array plugin enabled' do
function = { :name => 'Pear' } function = { :name => 'Pear' }
arg = test_arg[:int] arg = test_arg[:int]
expected = " if (!cmock_call_instance->IgnoreArg_MyInt)\n {\n UNITY_TEST_ASSERT_EQUAL_INT(cmock_call_instance->Expected_MyInt, MyInt, cmock_line, \"Function 'Pear' called with unexpected value for argument 'MyInt'.\");\n }\n" expected = " if (!cmock_call_instance->IgnoreArg_MyInt)\n" +
" {\n" +
" UNITY_SET_DETAILS(\"Pear\",\"MyInt\");\n" +
" UNITY_TEST_ASSERT_EQUAL_INT(cmock_call_instance->Expected_MyInt, MyInt, cmock_line, CMockStringMismatch);\n" +
" }\n"
@unity_helper.expect :nil?, false @unity_helper.expect :nil?, false
@unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_INT',''], ['int'] @unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_INT',''], ['int']
assert_equal(expected, @cmock_generator_utils_complex.code_verify_an_arg_expectation(function, arg)) assert_equal(expected, @cmock_generator_utils_complex.code_verify_an_arg_expectation(function, arg))
@@ -267,12 +289,13 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do
arg = test_arg[:int_ptr] arg = test_arg[:int_ptr]
expected = " if (!cmock_call_instance->IgnoreArg_MyIntPtr)\n" + expected = " if (!cmock_call_instance->IgnoreArg_MyIntPtr)\n" +
" {\n" + " {\n" +
" UNITY_SET_DETAILS(\"Pear\",\"MyIntPtr\");\n" +
" if (cmock_call_instance->Expected_MyIntPtr == NULL)\n" + " if (cmock_call_instance->Expected_MyIntPtr == NULL)\n" +
" { UNITY_TEST_ASSERT_NULL(MyIntPtr, cmock_line, \"Expected NULL. Function 'Pear' called with unexpected value for argument 'MyIntPtr'.\"); }\n" + " { UNITY_TEST_ASSERT_NULL(MyIntPtr, cmock_line, CMockStringExpNULL); }\n" +
" else if (cmock_call_instance->Expected_MyIntPtr_Depth == 0)\n" + " else if (cmock_call_instance->Expected_MyIntPtr_Depth == 0)\n" +
" { UNITY_TEST_ASSERT_EQUAL_PTR(cmock_call_instance->Expected_MyIntPtr, MyIntPtr, cmock_line, \"Function 'Pear' called with unexpected value for argument 'MyIntPtr'.\"); }\n" + " { UNITY_TEST_ASSERT_EQUAL_PTR(cmock_call_instance->Expected_MyIntPtr, MyIntPtr, cmock_line, CMockStringMismatch); }\n" +
" else\n" + " else\n" +
" { UNITY_TEST_ASSERT_EQUAL_INT_ARRAY(cmock_call_instance->Expected_MyIntPtr, MyIntPtr, cmock_call_instance->Expected_MyIntPtr_Depth, cmock_line, \"Function 'Pear' called with unexpected value for argument 'MyIntPtr'.\"); }\n" + " { UNITY_TEST_ASSERT_EQUAL_INT_ARRAY(cmock_call_instance->Expected_MyIntPtr, MyIntPtr, cmock_call_instance->Expected_MyIntPtr_Depth, cmock_line, CMockStringMismatch); }\n" +
" }\n" " }\n"
@unity_helper.expect :nil?, false @unity_helper.expect :nil?, false
@unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_INT_ARRAY',''], ['int*'] @unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_INT_ARRAY',''], ['int*']
@@ -282,7 +305,11 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do
it 'handle const char as string compares with array plugin enabled' do it 'handle const char as string compares with array plugin enabled' do
function = { :name => 'Pear' } function = { :name => 'Pear' }
arg = test_arg[:string] arg = test_arg[:string]
expected = " if (!cmock_call_instance->IgnoreArg_MyStr)\n {\n UNITY_TEST_ASSERT_EQUAL_STRING(cmock_call_instance->Expected_MyStr, MyStr, cmock_line, \"Function 'Pear' called with unexpected value for argument 'MyStr'.\");\n }\n" expected = " if (!cmock_call_instance->IgnoreArg_MyStr)\n" +
" {\n" +
" UNITY_SET_DETAILS(\"Pear\",\"MyStr\");\n" +
" UNITY_TEST_ASSERT_EQUAL_STRING(cmock_call_instance->Expected_MyStr, MyStr, cmock_line, CMockStringMismatch);\n" +
" }\n"
@unity_helper.expect :nil?, false @unity_helper.expect :nil?, false
@unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_STRING',''], ['char*'] @unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_STRING',''], ['char*']
assert_equal(expected, @cmock_generator_utils_complex.code_verify_an_arg_expectation(function, arg)) assert_equal(expected, @cmock_generator_utils_complex.code_verify_an_arg_expectation(function, arg))
@@ -291,7 +318,14 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do
it 'handle custom types as memory compares when we have no better way to do it with array plugin enabled' do it 'handle custom types as memory compares when we have no better way to do it with array plugin enabled' do
function = { :name => 'Pear' } function = { :name => 'Pear' }
arg = test_arg[:mytype] arg = test_arg[:mytype]
expected = " if (!cmock_call_instance->IgnoreArg_MyMyType)\n {\n if (cmock_call_instance->Expected_MyMyType == NULL)\n { UNITY_TEST_ASSERT_NULL(MyMyType, cmock_line, \"Expected NULL. Function 'Pear' called with unexpected value for argument 'MyMyType'.\"); }\n else\n { UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY((void*)(cmock_call_instance->Expected_MyMyType), (void*)(MyMyType), sizeof(MY_TYPE), 1, cmock_line, \"Function 'Pear' called with unexpected value for argument 'MyMyType'.\"); }\n }\n" expected = " if (!cmock_call_instance->IgnoreArg_MyMyType)\n" +
" {\n" +
" UNITY_SET_DETAILS(\"Pear\",\"MyMyType\");\n" +
" if (cmock_call_instance->Expected_MyMyType == NULL)\n" +
" { UNITY_TEST_ASSERT_NULL(MyMyType, cmock_line, CMockStringExpNULL); }\n" +
" else\n" +
" { UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY((void*)(cmock_call_instance->Expected_MyMyType), (void*)(MyMyType), sizeof(MY_TYPE), 1, cmock_line, CMockStringMismatch); }\n" +
" }\n"
@unity_helper.expect :nil?, false @unity_helper.expect :nil?, false
@unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY', ''], ['MY_TYPE'] @unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY', ''], ['MY_TYPE']
assert_equal(expected, @cmock_generator_utils_complex.code_verify_an_arg_expectation(function, arg)) assert_equal(expected, @cmock_generator_utils_complex.code_verify_an_arg_expectation(function, arg))
@@ -300,7 +334,11 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do
it 'handle custom types with custom handlers when available, even if they do not support the extra message with array plugin enabled' do it 'handle custom types with custom handlers when available, even if they do not support the extra message with array plugin enabled' do
function = { :name => 'Pear' } function = { :name => 'Pear' }
arg = test_arg[:mytype] arg = test_arg[:mytype]
expected = " if (!cmock_call_instance->IgnoreArg_MyMyType)\n {\n UNITY_TEST_ASSERT_EQUAL_MY_TYPE(cmock_call_instance->Expected_MyMyType, MyMyType, cmock_line, \"Function 'Pear' called with unexpected value for argument 'MyMyType'.\");\n }\n" expected = " if (!cmock_call_instance->IgnoreArg_MyMyType)\n" +
" {\n" +
" UNITY_SET_DETAILS(\"Pear\",\"MyMyType\");\n" +
" UNITY_TEST_ASSERT_EQUAL_MY_TYPE(cmock_call_instance->Expected_MyMyType, MyMyType, cmock_line, CMockStringMismatch);\n" +
" }\n"
@unity_helper.expect :nil?, false @unity_helper.expect :nil?, false
@unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_MY_TYPE', ''], ['MY_TYPE'] @unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_MY_TYPE', ''], ['MY_TYPE']
assert_equal(expected, @cmock_generator_utils_complex.code_verify_an_arg_expectation(function, arg)) assert_equal(expected, @cmock_generator_utils_complex.code_verify_an_arg_expectation(function, arg))
@@ -311,12 +349,13 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do
arg = test_arg[:mytype_ptr] arg = test_arg[:mytype_ptr]
expected = " if (!cmock_call_instance->IgnoreArg_MyMyTypePtr)\n" + expected = " if (!cmock_call_instance->IgnoreArg_MyMyTypePtr)\n" +
" {\n" + " {\n" +
" UNITY_SET_DETAILS(\"Pear\",\"MyMyTypePtr\");\n" +
" if (cmock_call_instance->Expected_MyMyTypePtr == NULL)\n" + " if (cmock_call_instance->Expected_MyMyTypePtr == NULL)\n" +
" { UNITY_TEST_ASSERT_NULL(MyMyTypePtr, cmock_line, \"Expected NULL. Function 'Pear' called with unexpected value for argument 'MyMyTypePtr'.\"); }\n" + " { UNITY_TEST_ASSERT_NULL(MyMyTypePtr, cmock_line, CMockStringExpNULL); }\n" +
" else if (cmock_call_instance->Expected_MyMyTypePtr_Depth == 0)\n" + " else if (cmock_call_instance->Expected_MyMyTypePtr_Depth == 0)\n" +
" { UNITY_TEST_ASSERT_EQUAL_PTR(cmock_call_instance->Expected_MyMyTypePtr, MyMyTypePtr, cmock_line, \"Function 'Pear' called with unexpected value for argument 'MyMyTypePtr'.\"); }\n" + " { UNITY_TEST_ASSERT_EQUAL_PTR(cmock_call_instance->Expected_MyMyTypePtr, MyMyTypePtr, cmock_line, CMockStringMismatch); }\n" +
" else\n" + " else\n" +
" { UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY(cmock_call_instance->Expected_MyMyTypePtr, MyMyTypePtr, cmock_call_instance->Expected_MyMyTypePtr_Depth, cmock_line, \"Function 'Pear' called with unexpected value for argument 'MyMyTypePtr'.\"); }\n" + " { UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY(cmock_call_instance->Expected_MyMyTypePtr, MyMyTypePtr, cmock_call_instance->Expected_MyMyTypePtr_Depth, cmock_line, CMockStringMismatch); }\n" +
" }\n" " }\n"
@unity_helper.expect :nil?, false @unity_helper.expect :nil?, false
@unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY', ''], ['MY_TYPE*'] @unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY', ''], ['MY_TYPE*']
@@ -326,7 +365,11 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do
it 'handle custom types with array handlers when array plugin is enabled for non-array types' do it 'handle custom types with array handlers when array plugin is enabled for non-array types' do
function = { :name => 'Pear' } function = { :name => 'Pear' }
arg = test_arg[:mytype] arg = test_arg[:mytype]
expected = " if (!cmock_call_instance->IgnoreArg_MyMyType)\n {\n UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY(&cmock_call_instance->Expected_MyMyType, &MyMyType, 1, cmock_line, \"Function 'Pear' called with unexpected value for argument 'MyMyType'.\");\n }\n" expected = " if (!cmock_call_instance->IgnoreArg_MyMyType)\n" +
" {\n" +
" UNITY_SET_DETAILS(\"Pear\",\"MyMyType\");\n" +
" UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY(&cmock_call_instance->Expected_MyMyType, &MyMyType, 1, cmock_line, CMockStringMismatch);\n" +
" }\n"
@unity_helper.expect :nil?, false @unity_helper.expect :nil?, false
@unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY', '&'], ['MY_TYPE'] @unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY', '&'], ['MY_TYPE']
assert_equal(expected, @cmock_generator_utils_complex.code_verify_an_arg_expectation(function, arg)) assert_equal(expected, @cmock_generator_utils_complex.code_verify_an_arg_expectation(function, arg))