Merge branch 'feature/less_const'

This commit is contained in:
Mark VanderVoord
2016-01-04 19:14:56 -05:00
32 changed files with 1098 additions and 493 deletions
+30
View File
@@ -0,0 +1,30 @@
* text=auto
# These files are text and should be normalized (convert crlf to lf)
*.rb text
*.test text
*.c text
*.cpp text
*.h text
*.txt text
*.yml text
*.s79 text
*.bat text
*.xcl text
*.inc text
*.info text
*.md text
makefile text
rakefile text
#These files are binary and should not be normalized
*.doc binary
*.odt binary
*.pdf binary
*.ewd binary
*.eww binary
*.dni binary
*.wsdt binary
*.dbgdt binary
*.mac binary
+3 -1
View File
@@ -62,7 +62,9 @@ namespace :test do
desc "Run C Unit Tests" desc "Run C Unit Tests"
task :c => [:prep_system_tests] do task :c => [:prep_system_tests] do
build_and_test_c_files unless ($cfg['unsupported'].include? "C")
build_and_test_c_files
end
end end
desc "Run System Tests" desc "Run System Tests"
+17 -6
View File
@@ -68,7 +68,7 @@ class CMockGenerator
def create_mock_source_file(parsed_stuff) def create_mock_source_file(parsed_stuff)
@file_writer.create_file(@mock_name + ".c", @subdir) do |file, filename| @file_writer.create_file(@mock_name + ".c", @subdir) do |file, filename|
create_source_header_section(file, filename) create_source_header_section(file, filename, parsed_stuff[:functions])
create_instance_structure(file, parsed_stuff[:functions]) create_instance_structure(file, parsed_stuff[:functions])
create_extern_declarations(file) create_extern_declarations(file)
create_mock_verify_function(file, parsed_stuff[:functions]) create_mock_verify_function(file, parsed_stuff[:functions])
@@ -120,7 +120,7 @@ class CMockGenerator
header << "\n#endif\n" header << "\n#endif\n"
end end
def create_source_header_section(file, filename) def create_source_header_section(file, filename, functions)
header_file = (@subdir ? @subdir + '/' : '') + filename.gsub(".c",".h") header_file = (@subdir ? @subdir + '/' : '') + filename.gsub(".c",".h")
file << "/* AUTOGENERATED FILE. DO NOT EDIT. */\n" file << "/* AUTOGENERATED FILE. DO NOT EDIT. */\n"
file << "#include <string.h>\n" file << "#include <string.h>\n"
@@ -132,6 +132,15 @@ class CMockGenerator
file << "#include \"#{header_file}\"\n" file << "#include \"#{header_file}\"\n"
@includes_c_post_header.each {|inc| file << "#include #{inc}\n"} @includes_c_post_header.each {|inc| file << "#include #{inc}\n"}
file << "\n" file << "\n"
strs = []
functions.each do |func|
strs << func[:name]
func[:args].each {|arg| strs << arg[:name] }
end
strs.uniq.sort.each do |str|
file << "static const char* CMockString_#{str} = \"#{str}\";\n"
end
file << "\n"
end end
def create_instance_structure(file, functions) def create_instance_structure(file, functions)
@@ -199,20 +208,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(CMockString_#{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(CMockString_#{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
@@ -4,7 +4,7 @@ class CMockGeneratorPluginReturnThruPtr
def initialize(config, utils) def initialize(config, utils)
@utils = utils @utils = utils
@priority = 1 @priority = 1 #TODO: it's 1 to come before ignore_arg returns... but should be after expects otherwise (like 9)
end end
def instance_typedefs(function) def instance_typedefs(function)
@@ -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"
+30 -27
View File
@@ -37,7 +37,7 @@ class CMockGeneratorUtils
def code_add_base_expectation(func_name, global_ordering_supported=true) def code_add_base_expectation(func_name, global_ordering_supported=true)
lines = " CMOCK_MEM_INDEX_TYPE cmock_guts_index = CMock_Guts_MemNew(sizeof(CMOCK_#{func_name}_CALL_INSTANCE));\n" lines = " CMOCK_MEM_INDEX_TYPE cmock_guts_index = CMock_Guts_MemNew(sizeof(CMOCK_#{func_name}_CALL_INSTANCE));\n"
lines << " CMOCK_#{func_name}_CALL_INSTANCE* cmock_call_instance = (CMOCK_#{func_name}_CALL_INSTANCE*)CMock_Guts_GetAddressFor(cmock_guts_index);\n" lines << " CMOCK_#{func_name}_CALL_INSTANCE* cmock_call_instance = (CMOCK_#{func_name}_CALL_INSTANCE*)CMock_Guts_GetAddressFor(cmock_guts_index);\n"
lines << " UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, \"CMock has run out of memory. Please allocate more.\");\n" lines << " UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringOutOfMemory);\n"
lines << " memset(cmock_call_instance, 0, sizeof(*cmock_call_instance));\n" lines << " memset(cmock_call_instance, 0, sizeof(*cmock_call_instance));\n"
lines << " Mock.#{func_name}_CallInstance = CMock_Guts_MemChain(Mock.#{func_name}_CallInstance, cmock_guts_index);\n" lines << " Mock.#{func_name}_CallInstance = CMock_Guts_MemChain(Mock.#{func_name}_CallInstance, cmock_guts_index);\n"
lines << " Mock.#{func_name}_IgnoreBool = (int)0;\n" if (@ignore) lines << " Mock.#{func_name}_IgnoreBool = (int)0;\n" if (@ignore)
@@ -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(CMockString_#{function[:name]},CMockString_#{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(CMockString_#{function[:name]},CMockString_#{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(CMockString_#{function[:name]},CMockString_#{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
+381 -381
View File
@@ -1,381 +1,381 @@
# ========================================== # ==========================================
# 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]
# ========================================== # ==========================================
require 'yaml' require 'yaml'
require 'fileutils' require 'fileutils'
require './vendor/unity/auto/generate_test_runner' require './vendor/unity/auto/generate_test_runner'
require './vendor/unity/auto/unity_test_summary' require './vendor/unity/auto/unity_test_summary'
require './test/system/systest_generator' require './test/system/systest_generator'
require './vendor/unity/auto/colour_reporter.rb' require './vendor/unity/auto/colour_reporter.rb'
module RakefileHelpers module RakefileHelpers
SYSTEST_GENERATED_FILES_PATH = 'test/system/generated/' SYSTEST_GENERATED_FILES_PATH = 'test/system/generated/'
SYSTEST_BUILD_FILES_PATH = 'test/system/build/' SYSTEST_BUILD_FILES_PATH = 'test/system/build/'
SYSTEST_COMPILE_MOCKABLES_PATH = 'test/system/test_compilation/' SYSTEST_COMPILE_MOCKABLES_PATH = 'test/system/test_compilation/'
C_EXTENSION = '.c' C_EXTENSION = '.c'
RESULT_EXTENSION = '.result' RESULT_EXTENSION = '.result'
def load_configuration(config_file) def load_configuration(config_file)
$cfg_file = config_file $cfg_file = config_file
$cfg = YAML.load(File.read('./targets/' + $cfg_file)) $cfg = YAML.load(File.read('./targets/' + $cfg_file))
$colour_output = false unless $cfg['colour'] $colour_output = false unless $cfg['colour']
end end
def configure_clean def configure_clean
CLEAN.include(SYSTEST_GENERATED_FILES_PATH + '*.*') CLEAN.include(SYSTEST_GENERATED_FILES_PATH + '*.*')
CLEAN.include(SYSTEST_BUILD_FILES_PATH + '*.*') CLEAN.include(SYSTEST_BUILD_FILES_PATH + '*.*')
end end
def configure_toolchain(config_file) def configure_toolchain(config_file)
load_configuration(config_file) load_configuration(config_file)
configure_clean configure_clean
end end
def get_local_include_dirs def get_local_include_dirs
include_dirs = $cfg['compiler']['includes']['items'].dup include_dirs = $cfg['compiler']['includes']['items'].dup
include_dirs.delete_if {|dir| dir.is_a?(Array)} include_dirs.delete_if {|dir| dir.is_a?(Array)}
return include_dirs return include_dirs
end end
def extract_headers(filename) def extract_headers(filename)
includes = [] includes = []
lines = File.readlines(filename) lines = File.readlines(filename)
lines.each do |line| lines.each do |line|
m = line.match(/^\s*#include\s+\"\s*(.+\.[hH])\s*\"/) m = line.match(/^\s*#include\s+\"\s*(.+\.[hH])\s*\"/)
if not m.nil? if not m.nil?
includes << m[1] includes << m[1]
end end
end end
return includes return includes
end end
def find_source_file(header, paths) def find_source_file(header, paths)
paths.each do |dir| paths.each do |dir|
src_file = dir + header.ext(C_EXTENSION) src_file = dir + header.ext(C_EXTENSION)
if (File.exists?(src_file)) if (File.exists?(src_file))
return src_file return src_file
end end
end end
return nil return nil
end end
def squash(prefix, items) def squash(prefix, items)
result = '' result = ''
items.each { |item| result += " #{prefix}#{tackit(item)}" } items.each { |item| result += " #{prefix}#{tackit(item)}" }
return result return result
end end
def build_compiler_fields def build_compiler_fields
command = tackit($cfg['compiler']['path']) command = tackit($cfg['compiler']['path'])
if $cfg['compiler']['defines']['items'].nil? if $cfg['compiler']['defines']['items'].nil?
defines = '' defines = ''
else else
defines = squash($cfg['compiler']['defines']['prefix'], $cfg['compiler']['defines']['items']) defines = squash($cfg['compiler']['defines']['prefix'], $cfg['compiler']['defines']['items'])
end end
options = squash('', $cfg['compiler']['options']) options = squash('', $cfg['compiler']['options'])
includes = squash($cfg['compiler']['includes']['prefix'], $cfg['compiler']['includes']['items']) includes = squash($cfg['compiler']['includes']['prefix'], $cfg['compiler']['includes']['items'])
includes = includes.gsub(/\\ /, ' ').gsub(/\\\"/, '"').gsub(/\\$/, '') # Remove trailing slashes (for IAR) includes = includes.gsub(/\\ /, ' ').gsub(/\\\"/, '"').gsub(/\\$/, '') # Remove trailing slashes (for IAR)
return {:command => command, :defines => defines, :options => options, :includes => includes} return {:command => command, :defines => defines, :options => options, :includes => includes}
end end
def compile(file, defines=[]) def compile(file, defines=[])
compiler = build_compiler_fields compiler = build_compiler_fields
cmd_str = "#{compiler[:command]}#{compiler[:defines]}#{defines.inject(''){|all, a| ' -D'+a+all }}#{compiler[:options]}#{compiler[:includes]} #{file} " + cmd_str = "#{compiler[:command]}#{compiler[:defines]}#{defines.inject(''){|all, a| ' -D'+a+all }}#{compiler[:options]}#{compiler[:includes]} #{file} " +
"#{$cfg['compiler']['object_files']['prefix']}#{$cfg['compiler']['object_files']['destination']}" "#{$cfg['compiler']['object_files']['prefix']}#{$cfg['compiler']['object_files']['destination']}"
obj_file = "#{File.basename(file, C_EXTENSION)}#{$cfg['compiler']['object_files']['extension']}" obj_file = "#{File.basename(file, C_EXTENSION)}#{$cfg['compiler']['object_files']['extension']}"
execute(cmd_str + obj_file) execute(cmd_str + obj_file)
return obj_file return obj_file
end end
def build_linker_fields def build_linker_fields
command = tackit($cfg['linker']['path']) command = tackit($cfg['linker']['path'])
if $cfg['linker']['options'].nil? if $cfg['linker']['options'].nil?
options = '' options = ''
else else
options = squash('', $cfg['linker']['options']) options = squash('', $cfg['linker']['options'])
end end
if ($cfg['linker']['includes'].nil? || $cfg['linker']['includes']['items'].nil?) if ($cfg['linker']['includes'].nil? || $cfg['linker']['includes']['items'].nil?)
includes = '' includes = ''
else else
includes = squash($cfg['linker']['includes']['prefix'], $cfg['linker']['includes']['items']) includes = squash($cfg['linker']['includes']['prefix'], $cfg['linker']['includes']['items'])
end end
includes = includes.gsub(/\\ /, ' ').gsub(/\\\"/, '"').gsub(/\\$/, '') # Remove trailing slashes (for IAR) includes = includes.gsub(/\\ /, ' ').gsub(/\\\"/, '"').gsub(/\\$/, '') # Remove trailing slashes (for IAR)
return {:command => command, :options => options, :includes => includes} return {:command => command, :options => options, :includes => includes}
end end
def link_it(exe_name, obj_list) def link_it(exe_name, obj_list)
linker = build_linker_fields linker = build_linker_fields
cmd_str = "#{linker[:command]}#{linker[:options]}#{linker[:includes]} " + cmd_str = "#{linker[:command]}#{linker[:options]}#{linker[:includes]} " +
(obj_list.map{|obj|"#{$cfg['linker']['object_files']['path']}#{obj} "}).uniq.join + (obj_list.map{|obj|"#{$cfg['linker']['object_files']['path']}#{obj} "}).uniq.join +
$cfg['linker']['bin_files']['prefix'] + ' ' + $cfg['linker']['bin_files']['prefix'] + ' ' +
$cfg['linker']['bin_files']['destination'] + $cfg['linker']['bin_files']['destination'] +
exe_name + $cfg['linker']['bin_files']['extension'] exe_name + $cfg['linker']['bin_files']['extension']
execute(cmd_str) execute(cmd_str)
end end
def build_simulator_fields def build_simulator_fields
return nil if $cfg['simulator'].nil? return nil if $cfg['simulator'].nil?
if $cfg['simulator']['path'].nil? if $cfg['simulator']['path'].nil?
command = '' command = ''
else else
command = (tackit($cfg['simulator']['path']) + ' ') command = (tackit($cfg['simulator']['path']) + ' ')
end end
if $cfg['simulator']['pre_support'].nil? if $cfg['simulator']['pre_support'].nil?
pre_support = '' pre_support = ''
else else
pre_support = squash('', $cfg['simulator']['pre_support']) pre_support = squash('', $cfg['simulator']['pre_support'])
end end
if $cfg['simulator']['post_support'].nil? if $cfg['simulator']['post_support'].nil?
post_support = '' post_support = ''
else else
post_support = squash('', $cfg['simulator']['post_support']) post_support = squash('', $cfg['simulator']['post_support'])
end end
return {:command => command, :pre_support => pre_support, :post_support => post_support} return {:command => command, :pre_support => pre_support, :post_support => post_support}
end end
def execute(command_string, verbose=true, raise_on_failure=true) def execute(command_string, verbose=true, raise_on_failure=true)
#report command_string #report command_string
output = `#{command_string}`.chomp output = `#{command_string}`.chomp
report(output) if (verbose && !output.nil? && (output.length > 0)) report(output) if (verbose && !output.nil? && (output.length > 0))
if ($?.exitstatus != 0) and (raise_on_failure) if ($?.exitstatus != 0) and (raise_on_failure)
raise "#{command_string} failed. (Returned #{$?.exitstatus})" raise "#{command_string} failed. (Returned #{$?.exitstatus})"
end end
return output return output
end end
def tackit(strings) def tackit(strings)
case(strings) case(strings)
when Array when Array
"\"#{strings.join}\"" "\"#{strings.join}\""
when /^-/ when /^-/
strings strings
when /\s/ when /\s/
"\"#{strings}\"" "\"#{strings}\""
else else
strings strings
end end
end end
def report_summary def report_summary
summary = UnityTestSummary.new summary = UnityTestSummary.new
summary.set_root_path(File.expand_path(File.dirname(__FILE__)) + '/') summary.set_root_path(File.expand_path(File.dirname(__FILE__)) + '/')
results_glob = "#{$cfg['compiler']['build_path']}*.test*" results_glob = "#{$cfg['compiler']['build_path']}*.test*"
results_glob.gsub!(/\\/, '/') results_glob.gsub!(/\\/, '/')
results = Dir[results_glob] results = Dir[results_glob]
summary.set_targets(results) summary.set_targets(results)
summary.run summary.run
fail_out "FAIL: There were failures" if (summary.failures > 0) fail_out "FAIL: There were failures" if (summary.failures > 0)
end end
def run_system_test_interactions(test_case_files) def run_system_test_interactions(test_case_files)
load './lib/cmock.rb' load './lib/cmock.rb'
SystemTestGenerator.new.generate_files(test_case_files) SystemTestGenerator.new.generate_files(test_case_files)
test_files = FileList.new(SYSTEST_GENERATED_FILES_PATH + 'test*.c') test_files = FileList.new(SYSTEST_GENERATED_FILES_PATH + 'test*.c')
load_configuration($cfg_file) load_configuration($cfg_file)
$cfg['compiler']['defines']['items'] = [] if $cfg['compiler']['defines']['items'].nil? $cfg['compiler']['defines']['items'] = [] if $cfg['compiler']['defines']['items'].nil?
include_dirs = get_local_include_dirs include_dirs = get_local_include_dirs
# Build and execute each unit test # Build and execute each unit test
test_files.each do |test| test_files.each do |test|
obj_list = [] obj_list = []
test_base = File.basename(test, C_EXTENSION) test_base = File.basename(test, C_EXTENSION)
cmock_config = test_base.gsub(/test_/, '') + '_cmock.yml' cmock_config = test_base.gsub(/test_/, '') + '_cmock.yml'
report "Executing system tests in #{File.basename(test)}..." report "Executing system tests in #{File.basename(test)}..."
# Detect dependencies and build required required modules # Detect dependencies and build required required modules
extract_headers(test).each do |header| extract_headers(test).each do |header|
# Generate any needed mocks # Generate any needed mocks
if header =~ /^mock_(.*)\.h/i if header =~ /^mock_(.*)\.h/i
module_name = $1 module_name = $1
cmock = CMock.new(SYSTEST_GENERATED_FILES_PATH + cmock_config) cmock = CMock.new(SYSTEST_GENERATED_FILES_PATH + cmock_config)
cmock.setup_mocks("#{$cfg['compiler']['source_path']}#{module_name}.h") cmock.setup_mocks("#{$cfg['compiler']['source_path']}#{module_name}.h")
end end
# Compile corresponding source file if it exists # Compile corresponding source file if it exists
src_file = find_source_file(header, include_dirs) src_file = find_source_file(header, include_dirs)
if !src_file.nil? if !src_file.nil?
obj_list << compile(src_file) obj_list << compile(src_file)
end end
end end
# Generate and build the test suite runner # Generate and build the test suite runner
runner_name = test_base + '_runner.c' runner_name = test_base + '_runner.c'
runner_path = $cfg['compiler']['source_path'] + runner_name runner_path = $cfg['compiler']['source_path'] + runner_name
UnityTestRunnerGenerator.new(SYSTEST_GENERATED_FILES_PATH + cmock_config).run(test, runner_path) UnityTestRunnerGenerator.new(SYSTEST_GENERATED_FILES_PATH + cmock_config).run(test, runner_path)
obj_list << compile(runner_path) obj_list << compile(runner_path)
# Build the test module # Build the test module
obj_list << compile(test) obj_list << compile(test)
# Link the test executable # Link the test executable
link_it(test_base, obj_list) link_it(test_base, obj_list)
# Execute unit test and generate results file # Execute unit test and generate results file
simulator = build_simulator_fields simulator = build_simulator_fields
executable = $cfg['linker']['bin_files']['destination'] + test_base + $cfg['linker']['bin_files']['extension'] executable = $cfg['linker']['bin_files']['destination'] + test_base + $cfg['linker']['bin_files']['extension']
if simulator.nil? if simulator.nil?
cmd_str = executable cmd_str = executable
else else
cmd_str = "#{simulator[:command]} #{simulator[:pre_support]} #{executable} #{simulator[:post_support]}" cmd_str = "#{simulator[:command]} #{simulator[:pre_support]} #{executable} #{simulator[:post_support]}"
end end
output = execute(cmd_str, false, false) output = execute(cmd_str, false, false)
test_results = $cfg['compiler']['build_path'] + test_base + RESULT_EXTENSION test_results = $cfg['compiler']['build_path'] + test_base + RESULT_EXTENSION
File.open(test_results, 'w') { |f| f.print output } File.open(test_results, 'w') { |f| f.print output }
end end
# Parse and report test results # Parse and report test results
total_tests = 0 total_tests = 0
total_failures = 0 total_failures = 0
failure_messages = [] failure_messages = []
test_case_files.each do |test_case| test_case_files.each do |test_case|
tests = (YAML.load_file(test_case))[:systest][:tests][:units] tests = (YAML.load_file(test_case))[:systest][:tests][:units]
total_tests += tests.size total_tests += tests.size
test_file = 'test_' + File.basename(test_case).ext(C_EXTENSION) test_file = 'test_' + File.basename(test_case).ext(C_EXTENSION)
result_file = test_file.ext(RESULT_EXTENSION) result_file = test_file.ext(RESULT_EXTENSION)
test_results = File.readlines(SYSTEST_BUILD_FILES_PATH + result_file).reject {|line| line.size < 10 } # we're rejecting lines that are too short to be realistic, which handles line ending problems test_results = File.readlines(SYSTEST_BUILD_FILES_PATH + result_file).reject {|line| line.size < 10 } # we're rejecting lines that are too short to be realistic, which handles line ending problems
tests.each_with_index do |test, index| tests.each_with_index do |test, index|
# compare test's intended pass/fail state with pass/fail state in actual results; # compare test's intended pass/fail state with pass/fail state in actual results;
# if they don't match, the system test has failed # if they don't match, the system test has failed
this_failed = case(test[:pass]) this_failed = case(test[:pass])
when :ignore when :ignore
(test_results[index] =~ /:IGNORE/).nil? (test_results[index] =~ /:IGNORE/).nil?
when true when true
(test_results[index] =~ /:PASS/).nil? (test_results[index] =~ /:PASS/).nil?
when false when false
(test_results[index] =~ /:FAIL/).nil? (test_results[index] =~ /:FAIL/).nil?
end end
if (this_failed) if (this_failed)
total_failures += 1 total_failures += 1
test_results[index] =~ /test#{index+1}:(.+)/ test_results[index] =~ /test#{index+1}:(.+)/
failure_messages << "#{test_file}:test#{index+1}:should #{test[:should]}:#{$1}" failure_messages << "#{test_file}:test#{index+1}:should #{test[:should]}:#{$1}"
end end
# some tests have additional requirements to check for (checking the actual output message) # some tests have additional requirements to check for (checking the actual output message)
if (test[:verify_error]) and not (test_results[index] =~ /test#{index+1}:.*#{test[:verify_error]}/) if (test[:verify_error]) and not (test_results[index] =~ /test#{index+1}:.*#{test[:verify_error]}/)
total_failures += 1 total_failures += 1
failure_messages << "#{test_file}:test#{index+1}:should #{test[:should]}:should have output matching '#{test[:verify_error]}'" failure_messages << "#{test_file}:test#{index+1}:should #{test[:should]}:should have output matching '#{test[:verify_error]}' but was '#{test_results[index]}'"
end end
end end
end end
report "\n" report "\n"
report "------------------------------------\n" report "------------------------------------\n"
report "SYSTEM TEST MOCK INTERACTION SUMMARY\n" report "SYSTEM TEST MOCK INTERACTION SUMMARY\n"
report "------------------------------------\n" report "------------------------------------\n"
report "#{total_tests} Tests #{total_failures} Failures 0 Ignored\n" report "#{total_tests} Tests #{total_failures} Failures 0 Ignored\n"
report "\n" report "\n"
if (failure_messages.size > 0) if (failure_messages.size > 0)
report 'System test failures:' report 'System test failures:'
failure_messages.each do |failure| failure_messages.each do |failure|
report failure report failure
end end
end end
report '' report ''
return total_failures return total_failures
end end
def profile_this(filename) def profile_this(filename)
profile = true profile = true
begin begin
require 'ruby-prof' require 'ruby-prof'
RubyProf.start RubyProf.start
rescue rescue
profile = false profile = false
end end
yield yield
if (profile) if (profile)
profile_result = RubyProf.stop profile_result = RubyProf.stop
File.open("Profile_#{filename}.html", 'w') do |f| File.open("Profile_#{filename}.html", 'w') do |f|
RubyProf::GraphHtmlPrinter.new(profile_result).print(f) RubyProf::GraphHtmlPrinter.new(profile_result).print(f)
end end
end end
end end
def run_system_test_compilations(mockables) def run_system_test_compilations(mockables)
load './lib/cmock.rb' load './lib/cmock.rb'
load_configuration($cfg_file) load_configuration($cfg_file)
$cfg['compiler']['defines']['items'] = [] if $cfg['compiler']['defines']['items'].nil? $cfg['compiler']['defines']['items'] = [] if $cfg['compiler']['defines']['items'].nil?
report "\n" report "\n"
report "------------------------------------\n" report "------------------------------------\n"
report "SYSTEM TEST MOCK COMPILATION SUMMARY\n" report "SYSTEM TEST MOCK COMPILATION SUMMARY\n"
report "------------------------------------\n" report "------------------------------------\n"
mockables.each do |header| mockables.each do |header|
mock_filename = 'mock_' + File.basename(header).ext('.c') mock_filename = 'mock_' + File.basename(header).ext('.c')
CMock.new(SYSTEST_COMPILE_MOCKABLES_PATH + 'config.yml').setup_mocks(header) CMock.new(SYSTEST_COMPILE_MOCKABLES_PATH + 'config.yml').setup_mocks(header)
report "Compiling #{mock_filename}..." report "Compiling #{mock_filename}..."
compile(SYSTEST_GENERATED_FILES_PATH + mock_filename) compile(SYSTEST_GENERATED_FILES_PATH + mock_filename)
end end
end end
def run_system_test_profiles(mockables) def run_system_test_profiles(mockables)
load './lib/cmock.rb' load './lib/cmock.rb'
load_configuration($cfg_file) load_configuration($cfg_file)
$cfg['compiler']['defines']['items'] = [] if $cfg['compiler']['defines']['items'].nil? $cfg['compiler']['defines']['items'] = [] if $cfg['compiler']['defines']['items'].nil?
report "\n" report "\n"
report "--------------------------\n" report "--------------------------\n"
report "SYSTEM TEST MOCK PROFILING\n" report "SYSTEM TEST MOCK PROFILING\n"
report "--------------------------\n" report "--------------------------\n"
mockables.each do |header| mockables.each do |header|
mock_filename = 'mock_' + File.basename(header).ext('.c') mock_filename = 'mock_' + File.basename(header).ext('.c')
profile_this(mock_filename.gsub('.c','')) do profile_this(mock_filename.gsub('.c','')) do
10.times do 10.times do
CMock.new(SYSTEST_COMPILE_MOCKABLES_PATH + 'config.yml').setup_mocks(header) CMock.new(SYSTEST_COMPILE_MOCKABLES_PATH + 'config.yml').setup_mocks(header)
end end
end end
report "Compiling #{mock_filename}..." report "Compiling #{mock_filename}..."
compile(SYSTEST_GENERATED_FILES_PATH + mock_filename) compile(SYSTEST_GENERATED_FILES_PATH + mock_filename)
end end
end end
def build_and_test_c_files def build_and_test_c_files
report "\n" report "\n"
report "----------------\n" report "----------------\n"
report "UNIT TEST C CODE\n" report "UNIT TEST C CODE\n"
report "----------------\n" report "----------------\n"
errors = false errors = false
FileList.new("test/c/*.yml").each do |yaml_file| FileList.new("test/c/*.yml").each do |yaml_file|
test = YAML.load(File.read(yaml_file)) test = YAML.load(File.read(yaml_file))
report "\nTesting #{yaml_file.sub('.yml','')}" report "\nTesting #{yaml_file.sub('.yml','')}"
report "(#{test[:options].join(', ')})" report "(#{test[:options].join(', ')})"
test[:files].each { |f| compile(f, test[:options]) } test[:files].each { |f| compile(f, test[:options]) }
obj_files = test[:files].map { |f| f.gsub!(/.*\//,'').gsub!(C_EXTENSION, $cfg['compiler']['object_files']['extension']) } obj_files = test[:files].map { |f| f.gsub!(/.*\//,'').gsub!(C_EXTENSION, $cfg['compiler']['object_files']['extension']) }
link_it('TestCMockC', obj_files) link_it('TestCMockC', obj_files)
if $cfg['simulator'].nil? if $cfg['simulator'].nil?
execute($cfg['linker']['bin_files']['destination'] + 'TestCMockC' + $cfg['linker']['bin_files']['extension']) execute($cfg['linker']['bin_files']['destination'] + 'TestCMockC' + $cfg['linker']['bin_files']['extension'])
else else
execute(tackit($cfg['simulator']['path'].join) + ' ' + execute(tackit($cfg['simulator']['path'].join) + ' ' +
$cfg['simulator']['pre_support'].map{|o| tackit(o)}.join(' ') + ' ' + $cfg['simulator']['pre_support'].map{|o| tackit(o)}.join(' ') + ' ' +
$cfg['linker']['bin_files']['destination'] + $cfg['linker']['bin_files']['destination'] +
'TestCMockC' + 'TestCMockC' +
$cfg['linker']['bin_files']['extension'] + ' ' + $cfg['linker']['bin_files']['extension'] + ' ' +
$cfg['simulator']['post_support'].map{|o| tackit(o)}.join(' ') ) $cfg['simulator']['post_support'].map{|o| tackit(o)}.join(' ') )
end end
end end
end end
def fail_out(msg) def fail_out(msg)
puts msg puts msg
exit(-1) exit(-1)
end end
end end
+12 -1
View File
@@ -5,8 +5,19 @@
========================================== */ ========================================== */
#include "unity.h" #include "unity.h"
#include "cmock.h"
#include "cmock_internals.h" //public constants to be used by mocks
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
+2
View File
@@ -7,6 +7,8 @@
#ifndef CMOCK_FRAMEWORK_H #ifndef CMOCK_FRAMEWORK_H
#define CMOCK_FRAMEWORK_H #define CMOCK_FRAMEWORK_H
#include "cmock_internals.h"
//should be big enough to index full range of CMOCK_MEM_MAX //should be big enough to index full range of CMOCK_MEM_MAX
#ifndef CMOCK_MEM_INDEX_TYPE #ifndef CMOCK_MEM_INDEX_TYPE
#define CMOCK_MEM_INDEX_TYPE unsigned int #define CMOCK_MEM_INDEX_TYPE unsigned int
+11 -1
View File
@@ -7,7 +7,17 @@
#ifndef CMOCK_FRAMEWORK_INTERNALS_H #ifndef CMOCK_FRAMEWORK_INTERNALS_H
#define CMOCK_FRAMEWORK_INTERNALS_H #define CMOCK_FRAMEWORK_INTERNALS_H
#include "cmock.h" //These are constants that the generated mocks have access to
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
+2
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:
@@ -83,6 +84,7 @@ linker:
destination: *systest_build_path destination: *systest_build_path
unsupported: unsupported:
- out_of_memory
- callingconv - callingconv
colour: true colour: true
+2
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'
@@ -50,6 +51,7 @@ linker:
destination: *systest_build_path destination: *systest_build_path
unsupported: unsupported:
- out_of_memory
- unity_64bit_support - unity_64bit_support
- callingconv - callingconv
+2
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:
@@ -51,6 +52,7 @@ linker:
destination: *systest_build_path destination: *systest_build_path
unsupported: unsupported:
- out_of_memory
- callingconv - callingconv
colour: true colour: true
+80
View File
@@ -0,0 +1,80 @@
---
compiler:
path: gcc
source_path: &systest_generated_path 'test/system/generated/'
unit_tests_path: &unit_tests_path 'examples/test/'
mocks_path: &systest_mocks_path 'test/system/generated/'
build_path: &systest_build_path 'test/system/build/'
options:
- '-c'
- '-Wall'
- '-Wextra'
- '-Wunused-parameter'
- '-Wno-address'
- '-Wno-invalid-token-paste'
- '-std=c99'
- '-pedantic'
- '-O0'
includes:
prefix: '-I'
items:
- *systest_generated_path
- *unit_tests_path
- *systest_mocks_path
- 'src/'
- 'vendor/unity/src/'
- 'vendor/c_exception/lib/'
- 'test/system/test_compilation/'
- 'test/'
defines:
prefix: '-D'
items:
- CMOCK
- 'CMOCK_MEM_STATIC'
- 'CMOCK_MEM_SIZE=1024'
object_files:
prefix: '-o'
extension: '.o'
destination: *systest_build_path
linker:
path: gcc
options:
- -lm
includes:
prefix: '-I'
object_files:
path: *systest_build_path
extension: '.o'
bin_files:
prefix: '-o'
extension: '.exe'
destination: *systest_build_path
unsupported:
- all_plugins_but_other_limits
- all_plugins_coexist
- array_and_pointer_handling
- const_primitives_handling
- enforce_strict_ordering
- expect_and_return_custom_types
- expect_and_return_treat_as
- expect_and_throw
- expect_any_args
- fancy_pointer_handling
- function_pointer_handling
- newer_standards_stuff1
- nonstandard_pased_stuff_1
- nonstandard_pased_stuff_2
- parsing_challenges
- return_thru_ptr_and_expect_any_args
- return_thru_ptr_ignore_arg
- struct_union_enum_expect_and_return
- struct_union_enum_expect_and_return_with_plugins
- stubs_with_callbacks
- unity_64bit_support
- unity_ignores
- callingconv
- C
colour: true
+5 -3
View File
@@ -15,7 +15,7 @@ compiler:
- --no_code_motion - --no_code_motion
- --no_tbaa - --no_tbaa
- --no_clustering - --no_clustering
- --no_scheduling - --no_scheduling
- --debug - --debug
- --cpu_mode thumb - --cpu_mode thumb
- --endian little - --endian little
@@ -46,11 +46,12 @@ compiler:
defines: defines:
prefix: '-D' prefix: '-D'
items: items:
- CMOCK
object_files: object_files:
prefix: '-o' prefix: '-o'
extension: '.r79' extension: '.r79'
destination: *systest_build_path destination: *systest_build_path
linker: linker:
path: [*tools_root, 'common\bin\xlink.exe'] path: [*tools_root, 'common\bin\xlink.exe']
options: options:
@@ -80,7 +81,7 @@ linker:
prefix: '-o' prefix: '-o'
extension: '.d79' extension: '.d79'
destination: *systest_build_path destination: *systest_build_path
simulator: simulator:
path: [*tools_root, 'common\bin\CSpyBat.exe'] path: [*tools_root, 'common\bin\CSpyBat.exe']
pre_support: pre_support:
@@ -100,6 +101,7 @@ simulator:
- sim - sim
unsupported: unsupported:
- out_of_memory
- nonstandard_parsed_stuff_1 - nonstandard_parsed_stuff_1
- const - const
- callingconv - callingconv
+5 -3
View File
@@ -14,7 +14,7 @@ compiler:
- --no_code_motion - --no_code_motion
- --no_tbaa - --no_tbaa
- --no_clustering - --no_clustering
- --no_scheduling - --no_scheduling
- --debug - --debug
- --cpu_mode thumb - --cpu_mode thumb
- --endian=little - --endian=little
@@ -45,11 +45,12 @@ compiler:
defines: defines:
prefix: '-D' prefix: '-D'
items: items:
- CMOCK
object_files: object_files:
prefix: '-o' prefix: '-o'
extension: '.r79' extension: '.r79'
destination: *systest_build_path destination: *systest_build_path
linker: linker:
path: [*tools_root, 'arm\bin\ilinkarm.exe'] path: [*tools_root, 'arm\bin\ilinkarm.exe']
options: options:
@@ -65,7 +66,7 @@ linker:
prefix: '-o' prefix: '-o'
extension: '.out' extension: '.out'
destination: *systest_build_path destination: *systest_build_path
simulator: simulator:
path: [*tools_root, 'common\bin\CSpyBat.exe'] path: [*tools_root, 'common\bin\CSpyBat.exe']
pre_support: pre_support:
@@ -85,6 +86,7 @@ simulator:
- sim - sim
unsupported: unsupported:
- out_of_memory
- nonstandard_parsed_stuff_1 - nonstandard_parsed_stuff_1
- const - const
- callingconv - callingconv
+1 -1
View File
@@ -5,7 +5,7 @@
========================================== */ ========================================== */
#include "unity.h" #include "unity.h"
#include "cmock_internals.h" #include "cmock.h"
#define TEST_MEM_INDEX_SIZE (sizeof(CMOCK_MEM_INDEX_TYPE)) #define TEST_MEM_INDEX_SIZE (sizeof(CMOCK_MEM_INDEX_TYPE))
+1
View File
@@ -6,6 +6,7 @@
- 'vendor/unity/src/unity.c' - 'vendor/unity/src/unity.c'
:options: :options:
- 'TEST' - 'TEST'
- 'CMOCK_MEM_STATIC'
- 'CMOCK_MEM_SIZE=128' - 'CMOCK_MEM_SIZE=128'
- 'CMOCK_MEM_ALIGN=2' - 'CMOCK_MEM_ALIGN=2'
- 'CMOCK_MEM_INDEX_TYPE=int' - 'CMOCK_MEM_INDEX_TYPE=int'
@@ -0,0 +1,308 @@
---
: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);
int function_b(void);
:code: |
void function_a(void)
{
foo(bar());
no_args();
}
int function_b(void)
{
POINT_T pt = { 1, 2 };
foo(&pt);
return (pt.x + pt.y);
}
: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");
}
- :pass: FALSE
:should: 'not contain mock details in failed assertion after mock which threw a CException'
:verify_error: 'FAIL: Expected 1 Was 2. CustomFail'
:code: |
test()
{
CEXCEPTION_T e;
bar_ExpectAndThrow(0x12);
Try {
function_a();
}
Catch(e) {}
TEST_ASSERT_EQUAL_INT_MESSAGE(1,2,"CustomFail");
}
- :pass: FALSE
:should: 'not contain mock details in failed assertion after mock which used a return thru ptr'
#:verify_error: 'FAIL: Expected 3 Was 7. CustomFail' #TODO: put back in once ReturnThruPtr fixed
:code: |
test()
{
POINT_T pt1 = { 1, 2 };
POINT_T pt2 = { 3, 4 };
foo_Expect(&pt1);
foo_ReturnThruPtr_a(&pt2);
TEST_ASSERT_EQUAL_INT(3, function_b());
}
...
@@ -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));
@@ -0,0 +1,65 @@
---
:cmock:
:plugins: []
:treat_as:
custom_type: INT
:systest:
:types: |
typedef struct _BIG_FAT_STRUCT_T
{
char bytes[512];
} BIG_FAT_STRUCT_T;
:mockable: |
void foo(BIG_FAT_STRUCT_T a);
:source:
:header: |
void function_a(void);
void function_b(void);
:code: |
void function_a(void)
{
BIG_FAT_STRUCT_T stuff = { { 8, 0 } };
foo(stuff);
}
void function_b(void)
{
BIG_FAT_STRUCT_T stuff1 = { { 9, 1, 0 } };
BIG_FAT_STRUCT_T stuff2 = { { 9, 2, 0 } };
foo(stuff1);
foo(stuff2);
}
:tests:
:common: |
void setUp(void) {}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: 'successfully should be able to run function a because it only takes half the memory'
:code: |
test()
{
BIG_FAT_STRUCT_T expected = { { 8, 0 } };
foo_Expect(expected);
function_a();
}
- :pass: FALSE
:should: 'should error out because we do not have eough memory to handle two of these structures'
:code: |
test()
{
BIG_FAT_STRUCT_T expected1 = { { 9, 1, 0 } };
BIG_FAT_STRUCT_T expected2 = { { 9, 2, 0 } };
foo_Expect(expected1);
foo_Expect(expected2);
function_b();
}
...
+18 -3
View File
@@ -267,6 +267,10 @@ describe CMockGenerator, "Verify CMockGenerator Module" do
it "create a proper heading for a source file" do it "create a proper heading for a source file" do
output = [] output = []
functions = [ { :name => "uno", :args => [ { :name => "arg1" }, { :name => "arg2" } ] },
{ :name => "dos", :args => [ { :name => "arg3" }, { :name => "arg2" } ] },
{ :name => "tres", :args => [] }
]
expected = [ "/* AUTOGENERATED FILE. DO NOT EDIT. */\n", expected = [ "/* AUTOGENERATED FILE. DO NOT EDIT. */\n",
"#include <string.h>\n", "#include <string.h>\n",
"#include <stdlib.h>\n", "#include <stdlib.h>\n",
@@ -274,10 +278,17 @@ describe CMockGenerator, "Verify CMockGenerator Module" do
"#include \"unity.h\"\n", "#include \"unity.h\"\n",
"#include \"cmock.h\"\n", "#include \"cmock.h\"\n",
"#include \"MockPoutPoutFish.h\"\n", "#include \"MockPoutPoutFish.h\"\n",
"\n",
"static const char* CMockString_arg1 = \"arg1\";\n",
"static const char* CMockString_arg2 = \"arg2\";\n",
"static const char* CMockString_arg3 = \"arg3\";\n",
"static const char* CMockString_dos = \"dos\";\n",
"static const char* CMockString_tres = \"tres\";\n",
"static const char* CMockString_uno = \"uno\";\n",
"\n" "\n"
] ]
@cmock_generator.create_source_header_section(output, "MockPoutPoutFish.c") @cmock_generator.create_source_header_section(output, "MockPoutPoutFish.c", functions)
assert_equal(expected, output) assert_equal(expected, output)
end end
@@ -440,13 +451,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(CMockString_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 +485,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(CMockString_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(CMockString_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" +
+63 -20
View File
@@ -58,7 +58,7 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do
expected = expected =
" CMOCK_MEM_INDEX_TYPE cmock_guts_index = CMock_Guts_MemNew(sizeof(CMOCK_Apple_CALL_INSTANCE));\n" + " CMOCK_MEM_INDEX_TYPE cmock_guts_index = CMock_Guts_MemNew(sizeof(CMOCK_Apple_CALL_INSTANCE));\n" +
" CMOCK_Apple_CALL_INSTANCE* cmock_call_instance = (CMOCK_Apple_CALL_INSTANCE*)CMock_Guts_GetAddressFor(cmock_guts_index);\n" + " CMOCK_Apple_CALL_INSTANCE* cmock_call_instance = (CMOCK_Apple_CALL_INSTANCE*)CMock_Guts_GetAddressFor(cmock_guts_index);\n" +
" UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, \"CMock has run out of memory. Please allocate more.\");\n" + " UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringOutOfMemory);\n" +
" memset(cmock_call_instance, 0, sizeof(*cmock_call_instance));\n" + " memset(cmock_call_instance, 0, sizeof(*cmock_call_instance));\n" +
" Mock.Apple_CallInstance = CMock_Guts_MemChain(Mock.Apple_CallInstance, cmock_guts_index);\n" + " Mock.Apple_CallInstance = CMock_Guts_MemChain(Mock.Apple_CallInstance, cmock_guts_index);\n" +
" cmock_call_instance->LineNumber = cmock_line;\n" " cmock_call_instance->LineNumber = cmock_line;\n"
@@ -70,7 +70,7 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do
expected = expected =
" CMOCK_MEM_INDEX_TYPE cmock_guts_index = CMock_Guts_MemNew(sizeof(CMOCK_Apple_CALL_INSTANCE));\n" + " CMOCK_MEM_INDEX_TYPE cmock_guts_index = CMock_Guts_MemNew(sizeof(CMOCK_Apple_CALL_INSTANCE));\n" +
" CMOCK_Apple_CALL_INSTANCE* cmock_call_instance = (CMOCK_Apple_CALL_INSTANCE*)CMock_Guts_GetAddressFor(cmock_guts_index);\n" + " CMOCK_Apple_CALL_INSTANCE* cmock_call_instance = (CMOCK_Apple_CALL_INSTANCE*)CMock_Guts_GetAddressFor(cmock_guts_index);\n" +
" UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, \"CMock has run out of memory. Please allocate more.\");\n" + " UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringOutOfMemory);\n" +
" memset(cmock_call_instance, 0, sizeof(*cmock_call_instance));\n" + " memset(cmock_call_instance, 0, sizeof(*cmock_call_instance));\n" +
" Mock.Apple_CallInstance = CMock_Guts_MemChain(Mock.Apple_CallInstance, cmock_guts_index);\n" + " Mock.Apple_CallInstance = CMock_Guts_MemChain(Mock.Apple_CallInstance, cmock_guts_index);\n" +
" Mock.Apple_IgnoreBool = (int)0;\n" + " Mock.Apple_IgnoreBool = (int)0;\n" +
@@ -85,7 +85,7 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do
expected = expected =
" CMOCK_MEM_INDEX_TYPE cmock_guts_index = CMock_Guts_MemNew(sizeof(CMOCK_Apple_CALL_INSTANCE));\n" + " CMOCK_MEM_INDEX_TYPE cmock_guts_index = CMock_Guts_MemNew(sizeof(CMOCK_Apple_CALL_INSTANCE));\n" +
" CMOCK_Apple_CALL_INSTANCE* cmock_call_instance = (CMOCK_Apple_CALL_INSTANCE*)CMock_Guts_GetAddressFor(cmock_guts_index);\n" + " CMOCK_Apple_CALL_INSTANCE* cmock_call_instance = (CMOCK_Apple_CALL_INSTANCE*)CMock_Guts_GetAddressFor(cmock_guts_index);\n" +
" UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, \"CMock has run out of memory. Please allocate more.\");\n" + " UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringOutOfMemory);\n" +
" memset(cmock_call_instance, 0, sizeof(*cmock_call_instance));\n" + " memset(cmock_call_instance, 0, sizeof(*cmock_call_instance));\n" +
" Mock.Apple_CallInstance = CMock_Guts_MemChain(Mock.Apple_CallInstance, cmock_guts_index);\n" + " Mock.Apple_CallInstance = CMock_Guts_MemChain(Mock.Apple_CallInstance, cmock_guts_index);\n" +
" Mock.Apple_IgnoreBool = (int)0;\n" + " Mock.Apple_IgnoreBool = (int)0;\n" +
@@ -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(CMockString_Pear,CMockString_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(CMockString_Pear,CMockString_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(CMockString_Pear,CMockString_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(CMockString_Pear,CMockString_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(CMockString_Pear,CMockString_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(CMockString_Pear,CMockString_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(CMockString_Pear,CMockString_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(CMockString_Pear,CMockString_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(CMockString_Pear,CMockString_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(CMockString_Pear,CMockString_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(CMockString_Pear,CMockString_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(CMockString_Pear,CMockString_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(CMockString_Pear,CMockString_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))
+1 -1