mirror of
https://github.com/ThrowTheSwitch/CMock.git
synced 2026-07-30 15:57:50 +00:00
- made index follow alignment rules too
- added support to track line numbers - tweaked color support git-svn-id: http://cmock.svn.sourceforge.net/svnroot/cmock/trunk@158 bf332499-1b4d-0410-844d-d2d48d5cc64c
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
---
|
||||
colour: true
|
||||
|
||||
compiler:
|
||||
path: gcc
|
||||
source_path: &systest_generated_path 'test/system/generated/'
|
||||
@@ -46,3 +44,5 @@ linker:
|
||||
destination: *systest_build_path
|
||||
|
||||
unsupported: []
|
||||
|
||||
colour: true
|
||||
|
||||
@@ -161,7 +161,7 @@
|
||||
//*************************************************************************
|
||||
-D_CSTACK_SIZE=(100*4)
|
||||
-D_IRQ_STACK_SIZE=(3*8*4)
|
||||
-D_HEAP_SIZE=(1024*1)
|
||||
-D_HEAP_SIZE=(1024*2)
|
||||
|
||||
-Z(DATA)CSTACK+_CSTACK_SIZE=RAMSTART-RAMEND
|
||||
-Z(DATA)IRQ_STACK+_IRQ_STACK_SIZE=RAMSTART-RAMEND
|
||||
|
||||
@@ -15,7 +15,7 @@ define symbol __ICFEDIT_size_irqstack__ = 0x100;
|
||||
define symbol __ICFEDIT_size_fiqstack__ = 0x40;
|
||||
define symbol __ICFEDIT_size_undstack__ = 0x40;
|
||||
define symbol __ICFEDIT_size_abtstack__ = 0x40;
|
||||
define symbol __ICFEDIT_size_heap__ = 0x400;
|
||||
define symbol __ICFEDIT_size_heap__ = 0x800;
|
||||
/**** End of ICF editor section. ###ICF###*/
|
||||
|
||||
|
||||
|
||||
+4
-2
@@ -98,7 +98,9 @@ simulator:
|
||||
- [*tools_root, 'arm\config\ioat91sam7X256.ddf']
|
||||
- -d
|
||||
- sim
|
||||
|
||||
|
||||
unsupported:
|
||||
- nonstandard_parsed_stuff_1
|
||||
- const
|
||||
- const
|
||||
|
||||
colour: true
|
||||
|
||||
+4
-2
@@ -83,7 +83,9 @@ simulator:
|
||||
- [*tools_root, 'arm\config\debugger\Atmel\ioat91sam7X256.ddf']
|
||||
- -d
|
||||
- sim
|
||||
|
||||
|
||||
unsupported:
|
||||
- nonstandard_parsed_stuff_1
|
||||
- const
|
||||
- const
|
||||
|
||||
colour: true
|
||||
|
||||
@@ -91,8 +91,8 @@ class CMockGenerator
|
||||
def create_instance_structure(file, functions)
|
||||
functions.each do |function|
|
||||
file << "typedef struct _CMOCK_#{function[:name]}_CALL_INSTANCE\n{\n"
|
||||
stuff = @plugins.run(:instance_typedefs, function)
|
||||
file << ((stuff.empty?) ? " char PlaceHolder;\n" : stuff)
|
||||
file << " UNITY_LINE_TYPE LineNumber;\n"
|
||||
file << @plugins.run(:instance_typedefs, function)
|
||||
file << "\n} CMOCK_#{function[:name]}_CALL_INSTANCE;\n\n"
|
||||
end
|
||||
file << "static struct #{@mock_name}Instance\n{\n"
|
||||
@@ -118,8 +118,10 @@ class CMockGenerator
|
||||
|
||||
def create_mock_verify_function(file, functions)
|
||||
file << "void #{@mock_name}_Verify(void)\n{\n"
|
||||
file << functions.collect {|function| @plugins.run(:mock_verify, function)}.join
|
||||
file << " TEST_ASSERT_NULL_MESSAGE(GlobalOrderError, GlobalOrderError);\n" if (@ordered)
|
||||
verifications = functions.collect {|function| @plugins.run(:mock_verify, function)}.join
|
||||
verifications += " UNITY_TEST_ASSERT_NULL(GlobalOrderError, cmock_line, NULL);\n" if (@ordered)
|
||||
file << " UNITY_LINE_TYPE cmock_line = TEST_LINE_NUM;\n" unless verifications.empty?
|
||||
file << verifications
|
||||
file << "}\n\n"
|
||||
end
|
||||
|
||||
@@ -157,13 +159,14 @@ class CMockGenerator
|
||||
args_string += (", " + function[:var_arg]) unless (function[:var_arg].nil?)
|
||||
|
||||
# Create mock function
|
||||
file << "#{function[:attributes]} " if (!function[:attributes].nil? && function[:attributes].length > 0)
|
||||
file << "#{function_mod_and_rettype} #{function[:name]}(#{args_string})\n"
|
||||
file << "{\n"
|
||||
file << " UNITY_LINE_TYPE cmock_line = TEST_LINE_NUM;\n"
|
||||
file << " CMOCK_#{function[:name]}_CALL_INSTANCE* cmock_call_instance = Mock.#{function[:name]}_CallInstance;\n"
|
||||
file << " Mock.#{function[:name]}_CallInstance = (CMOCK_#{function[:name]}_CALL_INSTANCE*)CMock_Guts_MemNext(Mock.#{function[:name]}_CallInstance);\n"
|
||||
file << @plugins.run(:mock_implementation_precheck, function)
|
||||
file << " TEST_ASSERT_NOT_NULL_MESSAGE(cmock_call_instance, \"Function '#{function[:name]}' called more times than expected\");\n"
|
||||
file << " UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, \"Function '#{function[:name]}' called more times than expected\");\n"
|
||||
file << " cmock_line = cmock_call_instance->LineNumber;\n"
|
||||
file << @plugins.run(:mock_implementation, function)
|
||||
file << " return cmock_call_instance->ReturnVal;\n" unless (function[:return][:void?])
|
||||
file << "}\n\n"
|
||||
|
||||
@@ -19,19 +19,14 @@ class CMockGeneratorPluginArray
|
||||
|
||||
def mock_function_declarations(function)
|
||||
return nil unless function[:contains_ptr?]
|
||||
if (function[:args_string] == "void")
|
||||
if (function[:return][:void?])
|
||||
return "void #{function[:name]}_ExpectWithArray(void);\n"
|
||||
else
|
||||
return "void #{function[:name]}_ExpectWithArrayAndReturn(#{function[:return][:str]});\n"
|
||||
end
|
||||
args_call = function[:args].map{|m| m[:ptr?] ? "#{m[:name]}, #{m[:name]}_Depth" : "#{m[:name]}"}.join(', ')
|
||||
args_string = function[:args].map{|m| m[:ptr?] ? "#{m[:type]} #{m[:name]}, int #{m[:name]}_Depth" : "#{m[:type]} #{m[:name]}"}.join(', ')
|
||||
if (function[:return][:void?])
|
||||
return "#define #{function[:name]}_ExpectWithArray(#{args_call}) #{function[:name]}_CMockExpectWithArray(__LINE__, #{args_call})\n" +
|
||||
"void #{function[:name]}_CMockExpectWithArray(UNITY_LINE_TYPE cmock_line, #{args_string});\n"
|
||||
else
|
||||
args_string = function[:args].map{|m| m[:ptr?] ? "#{m[:type]} #{m[:name]}, int #{m[:name]}_Depth" : "#{m[:type]} #{m[:name]}"}.join(', ')
|
||||
if (function[:return][:void?])
|
||||
return "void #{function[:name]}_ExpectWithArray(#{args_string});\n"
|
||||
else
|
||||
return "void #{function[:name]}_ExpectWithArrayAndReturn(#{args_string}, #{function[:return][:str]});\n"
|
||||
end
|
||||
return "#define #{function[:name]}_ExpectWithArrayAndReturn(#{args_call}, cmock_retval) #{function[:name]}_CMockExpectWithArrayAndReturn(__LINE__, #{args_call}, cmock_retval)\n" +
|
||||
"void #{function[:name]}_CMockExpectWithArrayAndReturn(UNITY_LINE_TYPE cmock_line, #{args_string}, #{function[:return][:str]});\n"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -42,9 +37,9 @@ class CMockGeneratorPluginArray
|
||||
args_string = function[:args].map{|m| m[:ptr?] ? "#{m[:type]} #{m[:name]}, int #{m[:name]}_Depth" : "#{m[:type]} #{m[:name]}"}.join(', ')
|
||||
call_string = function[:args].map{|m| m[:ptr?] ? "#{m[:name]}, #{m[:name]}_Depth" : m[:name]}.join(', ')
|
||||
if (function[:return][:void?])
|
||||
lines << "void #{func_name}_ExpectWithArray(#{args_string})\n"
|
||||
lines << "void #{func_name}_CMockExpectWithArray(UNITY_LINE_TYPE cmock_line, #{args_string})\n"
|
||||
else
|
||||
lines << "void #{func_name}_ExpectWithArrayAndReturn(#{args_string}, #{function[:return][:str]})\n"
|
||||
lines << "void #{func_name}_CMockExpectWithArrayAndReturn(UNITY_LINE_TYPE cmock_line, #{args_string}, #{function[:return][:str]})\n"
|
||||
end
|
||||
lines << "{\n"
|
||||
lines << @utils.code_add_base_expectation(func_name)
|
||||
|
||||
@@ -21,9 +21,11 @@ class CMockGeneratorPluginCexception
|
||||
|
||||
def mock_function_declarations(function)
|
||||
if (function[:args_string] == "void")
|
||||
return "void #{function[:name]}_ExpectAndThrow(CEXCEPTION_T cmock_to_throw);\n"
|
||||
return "#define #{function[:name]}_ExpectAndThrow(cmock_to_throw) #{function[:name]}_CMockExpectAndThrow(__LINE__, cmock_to_throw)\n" +
|
||||
"void #{function[:name]}_CMockExpectAndThrow(UNITY_LINE_TYPE cmock_line, CEXCEPTION_T cmock_to_throw);\n"
|
||||
else
|
||||
return "void #{function[:name]}_ExpectAndThrow(#{function[:args_string]}, CEXCEPTION_T cmock_to_throw);\n"
|
||||
return "#define #{function[:name]}_ExpectAndThrow(#{function[:args_call]}, cmock_to_throw) #{function[:name]}_CMockExpectAndThrow(__LINE__, #{function[:args_call]}, cmock_to_throw)\n" +
|
||||
"void #{function[:name]}_CMockExpectAndThrow(UNITY_LINE_TYPE cmock_line, #{function[:args_string]}, CEXCEPTION_T cmock_to_throw);\n"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -35,7 +37,7 @@ class CMockGeneratorPluginCexception
|
||||
def mock_interfaces(function)
|
||||
arg_insert = (function[:args_string] == "void") ? "" : "#{function[:args_string]}, "
|
||||
call_string = function[:args].map{|m| m[:name]}.join(', ')
|
||||
[ "void #{function[:name]}_ExpectAndThrow(#{arg_insert}CEXCEPTION_T cmock_to_throw)\n{\n",
|
||||
[ "void #{function[:name]}_CMockExpectAndThrow(UNITY_LINE_TYPE cmock_line, #{arg_insert}CEXCEPTION_T cmock_to_throw)\n{\n",
|
||||
@utils.code_add_base_expectation(function[:name]),
|
||||
@utils.code_call_argument_loader(function),
|
||||
" cmock_call_instance->ExceptionToThrow = cmock_to_throw;\n",
|
||||
|
||||
@@ -26,15 +26,19 @@ class CMockGeneratorPluginExpect
|
||||
def mock_function_declarations(function)
|
||||
if (function[:args].empty?)
|
||||
if (function[:return][:void?])
|
||||
return "void #{function[:name]}_Expect(void);\n"
|
||||
return "#define #{function[:name]}_Expect() #{function[:name]}_CMockExpect(__LINE__)\n" +
|
||||
"void #{function[:name]}_CMockExpect(UNITY_LINE_TYPE cmock_line);\n"
|
||||
else
|
||||
return "void #{function[:name]}_ExpectAndReturn(#{function[:return][:str]});\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"
|
||||
end
|
||||
else
|
||||
if (function[:return][:void?])
|
||||
return "void #{function[:name]}_Expect(#{function[:args_string]});\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"
|
||||
else
|
||||
return "void #{function[:name]}_ExpectAndReturn(#{function[:args_string]}, #{function[:return][:str]});\n"
|
||||
return "#define #{function[:name]}_ExpectAndReturn(#{function[:args_call]}, cmock_retval) #{function[:name]}_CMockExpectAndReturn(__LINE__, #{function[:args_call]}, cmock_retval)\n" +
|
||||
"void #{function[:name]}_CMockExpectAndReturn(UNITY_LINE_TYPE cmock_line, #{function[:args_string]}, #{function[:return][:str]});\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -42,7 +46,7 @@ class CMockGeneratorPluginExpect
|
||||
def mock_implementation(function)
|
||||
lines = ""
|
||||
if (@ordered)
|
||||
lines << " TEST_ASSERT_MESSAGE((cmock_call_instance->CallOrder == ++GlobalVerifyOrder), \"Out of order function calls. Function '#{function[:name]}'\");\n"
|
||||
lines << " UNITY_TEST_ASSERT((cmock_call_instance->CallOrder == ++GlobalVerifyOrder), cmock_line, \"Out of order function calls. Function '#{function[:name]}'\");\n"
|
||||
end
|
||||
function[:args].each do |arg|
|
||||
lines << @utils.code_verify_an_arg_expectation(function, arg)
|
||||
@@ -54,12 +58,16 @@ class CMockGeneratorPluginExpect
|
||||
lines = ""
|
||||
func_name = function[:name]
|
||||
if (function[:return][:void?])
|
||||
lines << "void #{func_name}_Expect(#{function[:args_string]})\n{\n"
|
||||
if (function[:args_string] == "void")
|
||||
lines << "void #{func_name}_CMockExpect(UNITY_LINE_TYPE cmock_line)\n{\n"
|
||||
else
|
||||
lines << "void #{func_name}_CMockExpect(UNITY_LINE_TYPE cmock_line, #{function[:args_string]})\n{\n"
|
||||
end
|
||||
else
|
||||
if (function[:args_string] == "void")
|
||||
lines << "void #{func_name}_ExpectAndReturn(#{function[:return][:str]})\n{\n"
|
||||
lines << "void #{func_name}_CMockExpectAndReturn(UNITY_LINE_TYPE cmock_line, #{function[:return][:str]})\n{\n"
|
||||
else
|
||||
lines << "void #{func_name}_ExpectAndReturn(#{function[:args_string]}, #{function[:return][:str]})\n{\n"
|
||||
lines << "void #{func_name}_CMockExpectAndReturn(UNITY_LINE_TYPE cmock_line, #{function[:args_string]}, #{function[:return][:str]})\n{\n"
|
||||
end
|
||||
end
|
||||
lines << @utils.code_add_base_expectation(func_name)
|
||||
@@ -70,7 +78,7 @@ class CMockGeneratorPluginExpect
|
||||
|
||||
def mock_verify(function)
|
||||
func_name = function[:name]
|
||||
" TEST_ASSERT_NULL_MESSAGE(Mock.#{func_name}_CallInstance, \"Function '#{func_name}' called less times than expected.\");\n"
|
||||
" UNITY_TEST_ASSERT_NULL(Mock.#{func_name}_CallInstance, cmock_line, \"Function '#{func_name}' called less times than expected.\");\n"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -20,9 +20,11 @@ class CMockGeneratorPluginIgnore
|
||||
|
||||
def mock_function_declarations(function)
|
||||
if (function[:return][:void?])
|
||||
return "void #{function[:name]}_Ignore(void);\n"
|
||||
return "#define #{function[:name]}_Ignore() #{function[:name]}_CMockIgnore(__LINE__)\n" +
|
||||
"void #{function[:name]}_CMockIgnore(UNITY_LINE_TYPE cmock_line);\n"
|
||||
else
|
||||
return "void #{function[:name]}_IgnoreAndReturn(#{function[:return][:str]});\n"
|
||||
return "#define #{function[:name]}_IgnoreAndReturn(cmock_retval) #{function[:name]}_CMockIgnoreAndReturn(__LINE__, cmock_retval)\n" +
|
||||
"void #{function[:name]}_CMockIgnoreAndReturn(UNITY_LINE_TYPE cmock_line, #{function[:return][:str]});\n"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -42,9 +44,9 @@ class CMockGeneratorPluginIgnore
|
||||
def mock_interfaces(function)
|
||||
lines = ""
|
||||
if (function[:return][:void?])
|
||||
lines << "void #{function[:name]}_Ignore(void)\n{\n"
|
||||
lines << "void #{function[:name]}_CMockIgnore(UNITY_LINE_TYPE cmock_line)\n{\n"
|
||||
else
|
||||
lines << "void #{function[:name]}_IgnoreAndReturn(#{function[:return][:str]})\n{\n"
|
||||
lines << "void #{function[:name]}_CMockIgnoreAndReturn(UNITY_LINE_TYPE cmock_line, #{function[:return][:str]})\n{\n"
|
||||
end
|
||||
unless (function[:return][:void?])
|
||||
lines << @utils.code_add_base_expectation(function[:name], false)
|
||||
|
||||
@@ -25,8 +25,9 @@ class CMockGeneratorUtils
|
||||
|
||||
def code_add_base_expectation(func_name, global_ordering_supported=true)
|
||||
lines = " CMOCK_#{func_name}_CALL_INSTANCE* cmock_call_instance = (CMOCK_#{func_name}_CALL_INSTANCE*)CMock_Guts_MemNew(sizeof(CMOCK_#{func_name}_CALL_INSTANCE));\n"
|
||||
lines << " TEST_ASSERT_NOT_NULL_MESSAGE(cmock_call_instance, \"CMock has run out of memory. Please allocate more.\");\n"
|
||||
lines << " UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, \"CMock has run out of memory. Please allocate more.\");\n"
|
||||
lines << " Mock.#{func_name}_CallInstance = (CMOCK_#{func_name}_CALL_INSTANCE*)CMock_Guts_MemChain((void*)Mock.#{func_name}_CallInstance, (void*)cmock_call_instance);\n"
|
||||
lines << " cmock_call_instance->LineNumber = cmock_line;\n"
|
||||
lines << " cmock_call_instance->CallOrder = ++GlobalExpectCount;\n" if (@ordered and global_ordering_supported)
|
||||
lines << " cmock_call_instance->ExceptionToThrow = CEXCEPTION_NONE;\n" if (@cexception)
|
||||
lines
|
||||
@@ -84,32 +85,32 @@ class CMockGeneratorUtils
|
||||
arg_name = arg[:name]
|
||||
expected = "cmock_call_instance->Expected_#{arg_name}"
|
||||
unity_func = if ((arg[:ptr?]) and (@ptr_handling == :compare_ptr))
|
||||
"TEST_ASSERT_EQUAL_HEX32_MESSAGE"
|
||||
"UNITY_TEST_ASSERT_EQUAL_HEX32"
|
||||
else
|
||||
(@helpers.nil? or @helpers[:unity_helper].nil?) ? "TEST_ASSERT_EQUAL_MESSAGE" : @helpers[:unity_helper].get_helper(c_type)
|
||||
(@helpers.nil? or @helpers[:unity_helper].nil?) ? "UNITY_TEST_ASSERT_EQUAL" : @helpers[:unity_helper].get_helper(c_type)
|
||||
end
|
||||
unity_msg = (unity_func =~ /_MESSAGE/) ? ", \"Function '#{function[:name]}' called with unexpected value for argument '#{arg_name}'.\"" : ''
|
||||
unity_msg = ", \"Function '#{function[:name]}' called with unexpected value for argument '#{arg_name}'.\""
|
||||
return c_type, arg_name, expected, unity_func, unity_msg
|
||||
end
|
||||
|
||||
def code_verify_an_arg_expectation_with_no_arrays(function, arg)
|
||||
c_type, arg_name, expected, unity_func, unity_msg = lookup_expect_type(function, arg)
|
||||
case(unity_func)
|
||||
when "TEST_ASSERT_EQUAL_MEMORY_MESSAGE"
|
||||
when "UNITY_TEST_ASSERT_EQUAL_MEMORY"
|
||||
full_expected = (expected =~ /^\*/) ? expected.slice(1..-1) : "(&#{expected})"
|
||||
return " TEST_ASSERT_EQUAL_MEMORY_MESSAGE((void*)#{full_expected}, (void*)(&#{arg_name}), sizeof(#{c_type})#{unity_msg});\n"
|
||||
when "TEST_ASSERT_EQUAL_MEMORY_MESSAGE_ARRAY"
|
||||
return " UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)#{full_expected}, (void*)(&#{arg_name}), sizeof(#{c_type}), cmock_line#{unity_msg});\n"
|
||||
when "UNITY_TEST_ASSERT_EQUAL_MEMORY"
|
||||
[ " if (#{expected} == NULL)",
|
||||
" { TEST_ASSERT_NULL(#{arg_name}); }",
|
||||
" { UNITY_TEST_ASSERT_NULL(#{arg_name}, cmock_line, NULL); }",
|
||||
" else",
|
||||
" { TEST_ASSERT_EQUAL_MEMORY_MESSAGE((void*)(#{expected}), (void*)#{arg_name}, sizeof(#{c_type.sub('*','')})#{unity_msg}); }\n"].join("\n")
|
||||
" { UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)(#{expected}), (void*)#{arg_name}, sizeof(#{c_type.sub('*','')}), cmock_line#{unity_msg}); }\n"].join("\n")
|
||||
when /_ARRAY/
|
||||
[ " if (#{expected} == NULL)",
|
||||
" { TEST_ASSERT_NULL(#{arg_name}); }",
|
||||
" { UNITY_TEST_ASSERT_NULL(#{arg_name}, cmock_line, NULL); }",
|
||||
" else",
|
||||
" { #{unity_func}(#{expected}, #{arg_name}, 1); }\n"].join("\n")
|
||||
" { #{unity_func}(#{expected}, #{arg_name}, 1, cmock_line, NULL); }\n"].join("\n")
|
||||
else
|
||||
return " #{unity_func}(#{expected}, #{arg_name}#{unity_msg});\n"
|
||||
return " #{unity_func}(#{expected}, #{arg_name}, cmock_line#{unity_msg});\n"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -117,21 +118,21 @@ class CMockGeneratorUtils
|
||||
c_type, arg_name, expected, unity_func, unity_msg = lookup_expect_type(function, arg)
|
||||
depth_name = (arg[:ptr?]) ? "cmock_call_instance->Expected_#{arg_name}_Depth" : 1
|
||||
case(unity_func)
|
||||
when "TEST_ASSERT_EQUAL_MEMORY_MESSAGE"
|
||||
when "UNITY_TEST_ASSERT_EQUAL_MEMORY"
|
||||
full_expected = (expected =~ /^\*/) ? expected.slice(1..-1) : "(&#{expected})"
|
||||
return " TEST_ASSERT_EQUAL_MEMORY_MESSAGE((void*)#{full_expected}, (void*)(&#{arg_name}), sizeof(#{c_type})#{unity_msg});\n"
|
||||
when "TEST_ASSERT_EQUAL_MEMORY_MESSAGE_ARRAY"
|
||||
return " UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)#{full_expected}, (void*)(&#{arg_name}), sizeof(#{c_type}), cmock_line#{unity_msg});\n"
|
||||
when "UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY"
|
||||
[ " if (#{expected} == NULL)",
|
||||
" { TEST_ASSERT_NULL(#{arg_name}); }",
|
||||
" { UNITY_TEST_ASSERT_NULL(#{arg_name}, cmock_line, NULL); }",
|
||||
" else",
|
||||
" { TEST_ASSERT_EQUAL_MEMORY_ARRAY_MESSAGE((void*)(#{expected}), (void*)#{arg_name}, sizeof(#{c_type.sub('*','')}), #{depth_name}#{unity_msg}); }\n"].compact.join("\n")
|
||||
" { UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY((void*)(#{expected}), (void*)#{arg_name}, sizeof(#{c_type.sub('*','')}), #{depth_name}, cmock_line#{unity_msg}); }\n"].compact.join("\n")
|
||||
when /_ARRAY/
|
||||
[ " if (#{expected} == NULL)",
|
||||
" { TEST_ASSERT_NULL(#{arg_name}); }",
|
||||
" { UNITY_TEST_ASSERT_NULL(#{arg_name}, cmock_line, NULL); }",
|
||||
" else",
|
||||
" { #{unity_func}(#{expected}, #{arg_name}, #{depth_name}); }\n"].compact.join("\n")
|
||||
" { #{unity_func}(#{expected}, #{arg_name}, #{depth_name}, cmock_line, NULL); }\n"].compact.join("\n")
|
||||
else
|
||||
return " #{unity_func}(#{expected}, #{arg_name}#{unity_msg});\n"
|
||||
return " #{unity_func}(#{expected}, #{arg_name}, cmock_line#{unity_msg});\n"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -139,23 +140,23 @@ class CMockGeneratorUtils
|
||||
c_type, arg_name, expected, unity_func, unity_msg = lookup_expect_type(function, arg)
|
||||
depth_name = (arg[:ptr?]) ? "cmock_call_instance->Expected_#{arg_name}_Depth" : 1
|
||||
case(unity_func)
|
||||
when "TEST_ASSERT_EQUAL_MEMORY_MESSAGE"
|
||||
when "UNITY_TEST_ASSERT_EQUAL_MEMORY"
|
||||
full_expected = (expected =~ /^\*/) ? expected.slice(1..-1) : "(&#{expected})"
|
||||
return " TEST_ASSERT_EQUAL_MEMORY_MESSAGE((void*)#{full_expected}, (void*)(&#{arg_name}), sizeof(#{c_type})#{unity_msg});\n"
|
||||
when "TEST_ASSERT_EQUAL_MEMORY_MESSAGE_ARRAY"
|
||||
return " UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)#{full_expected}, (void*)(&#{arg_name}), sizeof(#{c_type}), cmock_line#{unity_msg});\n"
|
||||
when "UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY"
|
||||
[ " if (#{expected} == NULL)",
|
||||
" { TEST_ASSERT_NULL(#{arg_name}); }",
|
||||
((depth_name != 1) ? " else if (#{depth_name} == 0)\n { TEST_ASSERT_EQUAL_HEX32(#{expected}, #{arg_name}); }" : nil),
|
||||
" { UNITY_TEST_ASSERT_NULL(#{arg_name}, cmock_line, NULL); }",
|
||||
((depth_name != 1) ? " else if (#{depth_name} == 0)\n { UNITY_TEST_ASSERT_EQUAL_HEX32(#{expected}, #{arg_name}, cmock_line, NULL); }" : nil),
|
||||
" else",
|
||||
" { TEST_ASSERT_EQUAL_MEMORY_ARRAY_MESSAGE((void*)(#{expected}), (void*)#{arg_name}, sizeof(#{c_type.sub('*','')}), #{depth_name}#{unity_msg}); }\n"].compact.join("\n")
|
||||
" { UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY((void*)(#{expected}), (void*)#{arg_name}, sizeof(#{c_type.sub('*','')}), #{depth_name}, cmock_line#{unity_msg}); }\n"].compact.join("\n")
|
||||
when /_ARRAY/
|
||||
[ " if (#{expected} == NULL)",
|
||||
" { TEST_ASSERT_NULL(#{arg_name}); }",
|
||||
((depth_name != 1) ? " else if (#{depth_name} == 0)\n { TEST_ASSERT_EQUAL_HEX32(#{expected}, #{arg_name}); }" : nil),
|
||||
" { UNITY_TEST_ASSERT_NULL(#{arg_name}, cmock_line, NULL); }",
|
||||
((depth_name != 1) ? " else if (#{depth_name} == 0)\n { UNITY_TEST_ASSERT_EQUAL_HEX32(#{expected}, #{arg_name}, cmock_line, NULL); }" : nil),
|
||||
" else",
|
||||
" { #{unity_func}(#{expected}, #{arg_name}, #{depth_name}); }\n"].compact.join("\n")
|
||||
" { #{unity_func}(#{expected}, #{arg_name}, #{depth_name}, cmock_line, NULL); }\n"].compact.join("\n")
|
||||
else
|
||||
return " #{unity_func}(#{expected}, #{arg_name}#{unity_msg});\n"
|
||||
return " #{unity_func}(#{expected}, #{arg_name}, cmock_line#{unity_msg});\n"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -217,6 +217,7 @@ class CMockHeaderParser
|
||||
args = clean_args(args)
|
||||
decl[:args_string] = args
|
||||
decl[:args] = parse_args(args)
|
||||
decl[:args_call] = decl[:args].map{|a| a[:name]}.join(', ')
|
||||
decl[:contains_ptr?] = decl[:args].inject(false) {|ptr, arg| arg[:ptr?] ? true : ptr }
|
||||
|
||||
if (decl[:return][:type].nil? or decl[:name].nil? or decl[:args].nil? or
|
||||
|
||||
@@ -4,6 +4,7 @@ class CMockUnityHelperParser
|
||||
|
||||
def initialize(config)
|
||||
@config = config
|
||||
@fallback = @config.plugins.include?(:array) ? 'UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY' : 'UNITY_TEST_ASSERT_EQUAL_MEMORY'
|
||||
@c_types = map_C_types.merge(import_source)
|
||||
end
|
||||
|
||||
@@ -11,11 +12,7 @@ class CMockUnityHelperParser
|
||||
lookup = ctype.gsub(/(?:^|(\S?)(\s*)|(\W))const(?:$|(\s*)(\S)|(\W))/,'\1\3\5\6').strip.gsub(/\s+/,'_')
|
||||
return @c_types[lookup] if (@c_types[lookup])
|
||||
raise("Don't know how to test #{ctype} and memory tests are disabled!") unless @config.memcmp_if_unknown
|
||||
if (ctype =~ /\*/)
|
||||
return 'TEST_ASSERT_EQUAL_MEMORY_MESSAGE_ARRAY'
|
||||
else
|
||||
return 'TEST_ASSERT_EQUAL_MEMORY_MESSAGE'
|
||||
end
|
||||
return @fallback
|
||||
end
|
||||
|
||||
private ###########################
|
||||
@@ -23,7 +20,7 @@ class CMockUnityHelperParser
|
||||
def map_C_types
|
||||
c_types = {}
|
||||
@config.treat_as.each_pair do |ctype, expecttype|
|
||||
c_types[ctype.gsub(/\s+/,'_')] = "TEST_ASSERT_EQUAL_#{expecttype}_MESSAGE"
|
||||
c_types[ctype.gsub(/\s+/,'_')] = "UNITY_TEST_ASSERT_EQUAL_#{expecttype}"
|
||||
end
|
||||
c_types
|
||||
end
|
||||
@@ -36,20 +33,20 @@ class CMockUnityHelperParser
|
||||
source = source.gsub(/\/\*.*?\*\//m, '') #remove block comments
|
||||
|
||||
#scan for comparison helpers
|
||||
m = Regexp.new('^\s*#define\s+(TEST_ASSERT_EQUAL_(\w+)_MESSAGE|TEST_ASSERT_EQUAL_(\w+))\s*\(' + Array.new(2,'\s*\w+\s*').join(',') + '\)')
|
||||
a = source.scan(m).flatten.compact
|
||||
(a.size/2).times do |i|
|
||||
expect = a[i*2]
|
||||
ctype = a[(i*2)+1]
|
||||
match_regex = Regexp.new('^\s*#define\s+(UNITY_TEST_ASSERT_EQUAL_(\w+))\s*\(' + Array.new(4,'\s*\w+\s*').join(',') + '\)')
|
||||
pairs = source.scan(match_regex).flatten.compact
|
||||
(pairs.size/2).times do |i|
|
||||
expect = pairs[i*2]
|
||||
ctype = pairs[(i*2)+1]
|
||||
c_types[ctype] = expect unless expect.include?("_ARRAY")
|
||||
end
|
||||
|
||||
#scan for array variants of those helpers
|
||||
m = Regexp.new('^\s*#define\s+(TEST_ASSERT_EQUAL_(\w+_ARRAY)_MESSAGE|TEST_ASSERT_EQUAL_(\w+_ARRAY))\s*\(' + Array.new(3,'\s*\w+\s*').join(',') + '\)')
|
||||
a = source.scan(m).flatten.compact
|
||||
(a.size/2).times do |i|
|
||||
expect = a[i*2]
|
||||
ctype = a[(i*2)+1]
|
||||
match_regex = Regexp.new('^\s*#define\s+(UNITY_TEST_ASSERT_EQUAL_(\w+_ARRAY))\s*\(' + Array.new(5,'\s*\w+\s*').join(',') + '\)')
|
||||
pairs = source.scan(match_regex).flatten.compact
|
||||
(pairs.size/2).times do |i|
|
||||
expect = pairs[i*2]
|
||||
ctype = pairs[(i*2)+1]
|
||||
c_types[ctype.gsub('_ARRAY','*')] = expect
|
||||
end
|
||||
|
||||
|
||||
+13
-10
@@ -14,7 +14,7 @@ configure_clean
|
||||
configure_toolchain(DEFAULT_CONFIG_FILE)
|
||||
|
||||
task :default => ['test:all']
|
||||
task :cruise => [:default]
|
||||
task :cruise => [:no_color, :default]
|
||||
|
||||
desc "Load configuration"
|
||||
task :config, :config_file do |t, args|
|
||||
@@ -46,14 +46,13 @@ namespace :test do
|
||||
build_and_test_c_files
|
||||
end
|
||||
|
||||
#get a list of all system tests, removing unsupported tests for this compiler
|
||||
sys_unsupported = $cfg['unsupported'].map {|a| 'test/system/test_interactions/'+a+'.yml'}
|
||||
sys_tests_to_run = FileList['test/system/test_interactions/*.yml'] - sys_unsupported
|
||||
compile_unsupported = $cfg['unsupported'].map {|a| SYSTEST_COMPILE_MOCKABLES_PATH+a+'.h'}
|
||||
compile_tests_to_run = FileList[SYSTEST_COMPILE_MOCKABLES_PATH + '*.h'] - compile_unsupported
|
||||
|
||||
desc "Run System Tests"
|
||||
task :system => [:clobber] do
|
||||
#get a list of all system tests, removing unsupported tests for this compiler
|
||||
sys_unsupported = $cfg['unsupported'].map {|a| 'test/system/test_interactions/'+a+'.yml'}
|
||||
sys_tests_to_run = FileList['test/system/test_interactions/*.yml'] - sys_unsupported
|
||||
compile_unsupported = $cfg['unsupported'].map {|a| SYSTEST_COMPILE_MOCKABLES_PATH+a+'.h'}
|
||||
compile_tests_to_run = FileList[SYSTEST_COMPILE_MOCKABLES_PATH + '*.h'] - compile_unsupported
|
||||
unless (sys_unsupported.empty? and compile_unsupported.empty?)
|
||||
report "\nIgnoring these system tests..."
|
||||
sys_unsupported.each {|a| report a}
|
||||
@@ -67,7 +66,7 @@ namespace :test do
|
||||
end
|
||||
|
||||
#individual system tests
|
||||
sys_tests_to_run.each do |test|
|
||||
FileList['test/system/test_interactions/*.yml'].each do |test|
|
||||
desc "Run system test #{File.basename(test,'.*')}"
|
||||
task "test:#{File.basename(test,'.*')}" do
|
||||
run_system_test_interactions([test])
|
||||
@@ -78,5 +77,9 @@ namespace :test do
|
||||
task :profile => [:clobber] do
|
||||
run_system_test_profiles(FileList[SYSTEST_COMPILE_MOCKABLES_PATH + '*.h'])
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
task :no_color do
|
||||
$colour_output = false
|
||||
end
|
||||
|
||||
+2
-38
@@ -3,56 +3,20 @@ require 'fileutils'
|
||||
require 'generate_test_runner'
|
||||
require 'unity_test_summary'
|
||||
require 'systest_generator'
|
||||
require 'vendor/unity/auto/colour_reporter.rb'
|
||||
|
||||
module RakefileHelpers
|
||||
|
||||
SYSTEST_GENERATED_FILES_PATH = 'test/system/generated/'
|
||||
SYSTEST_BUILD_FILES_PATH = 'test/system/build/'
|
||||
SYSTEST_COMPILE_MOCKABLES_PATH = 'test/system/test_compilation/'
|
||||
|
||||
C_EXTENSION = '.c'
|
||||
RESULT_EXTENSION = '.result'
|
||||
|
||||
def report(message)
|
||||
unless ($cfg and $cfg['colour'])
|
||||
puts($stdout.puts(message))
|
||||
else
|
||||
require 'vendor/unity/auto/colour_prompt.rb'
|
||||
message.each_line do |line|
|
||||
line.chomp!
|
||||
if line.include?('Tests') &&
|
||||
line.include?('Failures') &&
|
||||
line.include?('Ignored')
|
||||
if line.include?('0 Failures')
|
||||
colour = :green
|
||||
else
|
||||
colour = :red
|
||||
end
|
||||
elsif line.include?('PASS') ||
|
||||
line == 'OK'
|
||||
colour = :green
|
||||
elsif line.include? "Running Unity system tests..."
|
||||
colour = :blue
|
||||
elsif line.include?('FAIL') ||
|
||||
line.include?('Expected') ||
|
||||
line.include?('Memory Mismatch') ||
|
||||
line.include?('not within delta')
|
||||
colour = :red
|
||||
elsif line.include?(' IGNORED')
|
||||
colour = :yellow
|
||||
else
|
||||
colour = :blue
|
||||
end
|
||||
colour_puts colour, line
|
||||
end
|
||||
end
|
||||
$stdout.flush
|
||||
$stderr.flush
|
||||
end
|
||||
|
||||
def load_configuration(config_file)
|
||||
$cfg_file = config_file
|
||||
$cfg = YAML.load(File.read($cfg_file))
|
||||
$colour_output = false unless $cfg['colour']
|
||||
end
|
||||
|
||||
def configure_clean
|
||||
|
||||
+3
-2
@@ -27,8 +27,9 @@
|
||||
#endif
|
||||
|
||||
//automatically calculated defs for easier reading
|
||||
#define CMOCK_MEM_INDEX_SIZE (sizeof(CMOCK_MEM_INDEX_TYPE))
|
||||
#define CMOCK_MEM_ALIGN_MASK ((1u << CMOCK_MEM_ALIGN) - 1)
|
||||
#define CMOCK_MEM_ALIGN_SIZE (1u << CMOCK_MEM_ALIGN)
|
||||
#define CMOCK_MEM_ALIGN_MASK (CMOCK_MEM_ALIGN_SIZE - 1)
|
||||
#define CMOCK_MEM_INDEX_SIZE ((sizeof(CMOCK_MEM_INDEX_TYPE) > CMOCK_MEM_ALIGN_SIZE) ? sizeof(CMOCK_MEM_INDEX_TYPE) : CMOCK_MEM_ALIGN_SIZE)
|
||||
|
||||
//private variables
|
||||
#ifdef CMOCK_MEM_DYNAMIC
|
||||
|
||||
@@ -148,8 +148,8 @@ void test_ThatWeCanAskForAllSortsOfSizes(void)
|
||||
unsigned int i;
|
||||
unsigned int* first = NULL;
|
||||
unsigned int* next;
|
||||
unsigned int sizes[10] = {3, 1, 80, 5, 4, 31, 7, 911, 2, 80};
|
||||
unsigned int sizes_buffered[10] = {8, 4, 84, 8, 8, 36, 12, 916, 4, 84}; //includes counter
|
||||
unsigned int sizes[10] = {3, 1, 80, 5, 4, 31, 7, 911, 2, 80};
|
||||
unsigned int sizes_buffered[10] = {8, 8, 84, 12, 8, 36, 12, 916, 8, 84}; //includes counter
|
||||
unsigned int sum = 0;
|
||||
unsigned int cap;
|
||||
|
||||
@@ -163,8 +163,7 @@ void test_ThatWeCanAskForAllSortsOfSizes(void)
|
||||
|
||||
sum += sizes_buffered[i];
|
||||
cap = (StartingSize > (sum + CMOCK_MEM_SIZE)) ? StartingSize : (sum + CMOCK_MEM_SIZE);
|
||||
TEST_ASSERT_EQUAL(sum, CMock_Guts_MemBytesUsed());
|
||||
TEST_ASSERT(0 <= CMock_Guts_MemBytesFree());
|
||||
TEST_ASSERT_EQUAL(sum, CMock_Guts_MemBytesUsed());
|
||||
TEST_ASSERT(cap >= CMock_Guts_MemBytesFree());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
/* AUTOGENERATED FILE. DO NOT EDIT. */
|
||||
#include "unity.h"
|
||||
#include <setjmp.h>
|
||||
#include <stdio.h>
|
||||
|
||||
char MessageBuffer[50];
|
||||
|
||||
extern void setUp(void);
|
||||
extern void tearDown(void);
|
||||
@@ -18,13 +22,16 @@ static void runTest(UnityTestFunction test)
|
||||
setUp();
|
||||
test();
|
||||
}
|
||||
tearDown();
|
||||
if (TEST_PROTECT())
|
||||
{
|
||||
tearDown();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
Unity.TestFile = __FILE__;
|
||||
Unity.TestFile = "TestCMockDynamic.c";
|
||||
UnityBegin();
|
||||
|
||||
// RUN_TEST calls runTest
|
||||
@@ -36,6 +43,5 @@ int main(void)
|
||||
RUN_TEST(test_ThatWeCanAskForAllSortsOfSizes, 146);
|
||||
|
||||
UnityEnd();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
/* AUTOGENERATED FILE. DO NOT EDIT. */
|
||||
#include "unity.h"
|
||||
#include <setjmp.h>
|
||||
#include <stdio.h>
|
||||
|
||||
char MessageBuffer[50];
|
||||
|
||||
extern void setUp(void);
|
||||
extern void tearDown(void);
|
||||
@@ -19,13 +23,16 @@ static void runTest(UnityTestFunction test)
|
||||
setUp();
|
||||
test();
|
||||
}
|
||||
tearDown();
|
||||
if (TEST_PROTECT())
|
||||
{
|
||||
tearDown();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
Unity.TestFile = __FILE__;
|
||||
Unity.TestFile = "TestCMock.c";
|
||||
UnityBegin();
|
||||
|
||||
// RUN_TEST calls runTest
|
||||
@@ -38,6 +45,5 @@ int main(void)
|
||||
RUN_TEST(test_ThatWeCanAskForAllSortsOfSizes, 225);
|
||||
|
||||
UnityEnd();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -94,14 +94,15 @@
|
||||
|
||||
:unity_helper:
|
||||
:header: |
|
||||
void AssertEqualExampleStruct(EXAMPLE_STRUCT_T expected, EXAMPLE_STRUCT_T actual);
|
||||
#define TEST_ASSERT_EQUAL_EXAMPLE_STRUCT_T(expected, actual) {AssertEqualExampleStruct(expected, actual);}
|
||||
void AssertEqualExampleStruct(EXAMPLE_STRUCT_T expected, EXAMPLE_STRUCT_T actual, unsigned short line);
|
||||
#define UNITY_TEST_ASSERT_EQUAL_EXAMPLE_STRUCT_T(expected, actual, line, message) {AssertEqualExampleStruct(expected, actual, line);}
|
||||
#define TEST_ASSERT_EQUAL_EXAMPLE_STRUCT_T(expected, actual) UNITY_TEST_ASSERT_EQUAL_EXAMPLE_STRUCT_T(expected, actual, __LINE__, NULL);
|
||||
|
||||
:code: |
|
||||
void AssertEqualExampleStruct(EXAMPLE_STRUCT_T expected, EXAMPLE_STRUCT_T actual)
|
||||
void AssertEqualExampleStruct(EXAMPLE_STRUCT_T expected, EXAMPLE_STRUCT_T actual, unsigned short line)
|
||||
{
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(expected.x, actual.x, "Example Struct Failed For Field x");
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(expected.y, actual.y, "Example Struct Failed For Field y");
|
||||
UNITY_TEST_ASSERT_EQUAL_INT(expected.x, actual.x, line, "Example Struct Failed For Field x");
|
||||
UNITY_TEST_ASSERT_EQUAL_INT(expected.y, actual.y, line, "Example Struct Failed For Field y");
|
||||
}
|
||||
|
||||
...
|
||||
|
||||
@@ -145,7 +145,6 @@ class CMockGeneratorTest < Test::Unit::TestCase
|
||||
expected = [ "static struct MockPoutPoutFishInstance\n",
|
||||
"{\n",
|
||||
" unsigned char placeHolder;\n",
|
||||
"",
|
||||
"} Mock;\n\n"
|
||||
].join
|
||||
|
||||
@@ -160,10 +159,11 @@ class CMockGeneratorTest < Test::Unit::TestCase
|
||||
{ :name => "Second", :args => "bool Smarty", :return => test_return[:string] }
|
||||
]
|
||||
expected = [ "typedef struct _CMOCK_First_CALL_INSTANCE\n{\n",
|
||||
" UNITY_LINE_TYPE LineNumber;\n",
|
||||
" b1 b2",
|
||||
"\n} CMOCK_First_CALL_INSTANCE;\n\n",
|
||||
"typedef struct _CMOCK_Second_CALL_INSTANCE\n{\n",
|
||||
" char PlaceHolder;\n",
|
||||
" UNITY_LINE_TYPE LineNumber;\n",
|
||||
"\n} CMOCK_Second_CALL_INSTANCE;\n\n",
|
||||
"static struct MockPoutPoutFishInstance\n{\n",
|
||||
" d1",
|
||||
@@ -222,11 +222,12 @@ class CMockGeneratorTest < Test::Unit::TestCase
|
||||
]
|
||||
output = []
|
||||
expected = [ "void MockPoutPoutFish_Verify(void)\n{\n",
|
||||
" UNITY_LINE_TYPE cmock_line = TEST_LINE_NUM;\n",
|
||||
" Uno_First" +
|
||||
" Dos_First" +
|
||||
" Uno_Second" +
|
||||
" Dos_Second",
|
||||
" TEST_ASSERT_NULL_MESSAGE(GlobalOrderError, GlobalOrderError);\n",
|
||||
" Dos_Second" +
|
||||
" UNITY_TEST_ASSERT_NULL(GlobalOrderError, cmock_line, NULL);\n",
|
||||
"}\n\n"
|
||||
]
|
||||
@plugins.expect.run(:mock_verify, functions[0]).returns([" Uno_First"," Dos_First"])
|
||||
@@ -300,12 +301,14 @@ class CMockGeneratorTest < Test::Unit::TestCase
|
||||
:attributes => "__inline"
|
||||
}
|
||||
output = []
|
||||
expected = [ "__inline static int SupaFunction(uint32 sandwiches, const char* named)\n",
|
||||
expected = [ "static int SupaFunction(uint32 sandwiches, const char* named)\n",
|
||||
"{\n",
|
||||
" UNITY_LINE_TYPE cmock_line = TEST_LINE_NUM;\n",
|
||||
" CMOCK_SupaFunction_CALL_INSTANCE* cmock_call_instance = Mock.SupaFunction_CallInstance;\n",
|
||||
" Mock.SupaFunction_CallInstance = (CMOCK_SupaFunction_CALL_INSTANCE*)CMock_Guts_MemNext(Mock.SupaFunction_CallInstance);\n",
|
||||
" uno",
|
||||
" TEST_ASSERT_NOT_NULL_MESSAGE(cmock_call_instance, \"Function 'SupaFunction' called more times than expected\");\n",
|
||||
" UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, \"Function 'SupaFunction' called more times than expected\");\n",
|
||||
" cmock_line = cmock_call_instance->LineNumber;\n",
|
||||
" dos",
|
||||
" tres",
|
||||
" return cmock_call_instance->ReturnVal;\n",
|
||||
@@ -331,10 +334,12 @@ class CMockGeneratorTest < Test::Unit::TestCase
|
||||
output = []
|
||||
expected = [ "int SupaFunction(uint32 sandwiches, corn ...)\n",
|
||||
"{\n",
|
||||
" UNITY_LINE_TYPE cmock_line = TEST_LINE_NUM;\n",
|
||||
" CMOCK_SupaFunction_CALL_INSTANCE* cmock_call_instance = Mock.SupaFunction_CallInstance;\n",
|
||||
" Mock.SupaFunction_CallInstance = (CMOCK_SupaFunction_CALL_INSTANCE*)CMock_Guts_MemNext(Mock.SupaFunction_CallInstance);\n",
|
||||
" uno",
|
||||
" TEST_ASSERT_NOT_NULL_MESSAGE(cmock_call_instance, \"Function 'SupaFunction' called more times than expected\");\n",
|
||||
" UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, \"Function 'SupaFunction' called more times than expected\");\n",
|
||||
" cmock_line = cmock_call_instance->LineNumber;\n",
|
||||
" dos",
|
||||
" tres",
|
||||
" return cmock_call_instance->ReturnVal;\n",
|
||||
|
||||
@@ -55,7 +55,8 @@ class CMockGeneratorPluginArrayTest < Test::Unit::TestCase
|
||||
:return => test_return[:void],
|
||||
:contains_ptr? => true }
|
||||
|
||||
expected = "void #{function[:name]}_ExpectWithArray(int* tofu, int tofu_Depth);\n"
|
||||
expected = "#define #{function[:name]}_ExpectWithArray(tofu, tofu_Depth) #{function[:name]}_CMockExpectWithArray(__LINE__, tofu, tofu_Depth)\n" +
|
||||
"void #{function[:name]}_CMockExpectWithArray(UNITY_LINE_TYPE cmock_line, int* tofu, int tofu_Depth);\n"
|
||||
returned = @cmock_generator_plugin_array.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
@@ -69,7 +70,8 @@ class CMockGeneratorPluginArrayTest < Test::Unit::TestCase
|
||||
:return => test_return[:string],
|
||||
:contains_ptr? => true }
|
||||
|
||||
expected = "void #{function[:name]}_ExpectWithArrayAndReturn(int* tofu, int tofu_Depth, const char* cmock_to_return);\n"
|
||||
expected = "#define #{function[:name]}_ExpectWithArrayAndReturn(tofu, tofu_Depth, cmock_retval) #{function[:name]}_CMockExpectWithArrayAndReturn(__LINE__, tofu, tofu_Depth, cmock_retval)\n" +
|
||||
"void #{function[:name]}_CMockExpectWithArrayAndReturn(UNITY_LINE_TYPE cmock_line, int* tofu, int tofu_Depth, const char* cmock_to_return);\n"
|
||||
returned = @cmock_generator_plugin_array.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
@@ -92,7 +94,7 @@ class CMockGeneratorPluginArrayTest < Test::Unit::TestCase
|
||||
:contains_ptr? => true }
|
||||
@utils.expect.code_add_base_expectation("Lemon").returns("mock_retval_0")
|
||||
|
||||
expected = ["void Lemon_ExpectWithArrayAndReturn(int* pescado, int pescado_Depth, int pes, int* cmock_to_return)\n",
|
||||
expected = ["void Lemon_CMockExpectWithArrayAndReturn(UNITY_LINE_TYPE cmock_line, int* pescado, int pescado_Depth, int pes, int* cmock_to_return)\n",
|
||||
"{\n",
|
||||
"mock_retval_0",
|
||||
" CMockExpectParameters_Lemon(cmock_call_instance, pescado, pescado_Depth, pes);\n",
|
||||
|
||||
@@ -40,14 +40,16 @@ class CMockGeneratorPluginCexceptionTest < Test::Unit::TestCase
|
||||
|
||||
should "add mock function declarations for functions without arguments" do
|
||||
function = { :name => "Spruce", :args_string => "void", :return => test_return[:void] }
|
||||
expected = "void Spruce_ExpectAndThrow(CEXCEPTION_T cmock_to_throw);\n"
|
||||
expected = "#define Spruce_ExpectAndThrow(cmock_to_throw) Spruce_CMockExpectAndThrow(__LINE__, cmock_to_throw)\n"+
|
||||
"void Spruce_CMockExpectAndThrow(UNITY_LINE_TYPE cmock_line, CEXCEPTION_T cmock_to_throw);\n"
|
||||
returned = @cmock_generator_plugin_cexception.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
should "add mock function declarations for functions with arguments" do
|
||||
function = { :name => "Spruce", :args_string => "const char* Petunia, uint32_t Lily", :return => test_return[:void] }
|
||||
expected = "void Spruce_ExpectAndThrow(const char* Petunia, uint32_t Lily, CEXCEPTION_T cmock_to_throw);\n"
|
||||
function = { :name => "Spruce", :args_string => "const char* Petunia, uint32_t Lily", :args_call => "Petunia, Lily", :return => test_return[:void] }
|
||||
expected = "#define Spruce_ExpectAndThrow(Petunia, Lily, cmock_to_throw) Spruce_CMockExpectAndThrow(__LINE__, Petunia, Lily, cmock_to_throw)\n" +
|
||||
"void Spruce_CMockExpectAndThrow(UNITY_LINE_TYPE cmock_line, const char* Petunia, uint32_t Lily, CEXCEPTION_T cmock_to_throw);\n"
|
||||
returned = @cmock_generator_plugin_cexception.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
@@ -65,7 +67,7 @@ class CMockGeneratorPluginCexceptionTest < Test::Unit::TestCase
|
||||
@utils.expect.code_add_base_expectation("Pear").returns("mock_retval_0")
|
||||
@utils.expect.code_call_argument_loader(function).returns("")
|
||||
|
||||
expected = ["void Pear_ExpectAndThrow(CEXCEPTION_T cmock_to_throw)\n",
|
||||
expected = ["void Pear_CMockExpectAndThrow(UNITY_LINE_TYPE cmock_line, CEXCEPTION_T cmock_to_throw)\n",
|
||||
"{\n",
|
||||
"mock_retval_0",
|
||||
"",
|
||||
@@ -81,7 +83,7 @@ class CMockGeneratorPluginCexceptionTest < Test::Unit::TestCase
|
||||
@utils.expect.code_add_base_expectation("Pear").returns("mock_retval_0")
|
||||
@utils.expect.code_call_argument_loader(function).returns("mock_return_1")
|
||||
|
||||
expected = ["void Pear_ExpectAndThrow(int blah, CEXCEPTION_T cmock_to_throw)\n",
|
||||
expected = ["void Pear_CMockExpectAndThrow(UNITY_LINE_TYPE cmock_line, int blah, CEXCEPTION_T cmock_to_throw)\n",
|
||||
"{\n",
|
||||
"mock_retval_0",
|
||||
"mock_return_1",
|
||||
|
||||
@@ -71,21 +71,24 @@ class CMockGeneratorPluginExpectTest < Test::Unit::TestCase
|
||||
|
||||
should "add mock function declaration for functions of style 'void func(void)'" do
|
||||
function = {:name => "Maple", :args => [], :return => test_return[:void]}
|
||||
expected = "void Maple_Expect(void);\n"
|
||||
expected = "#define Maple_Expect() Maple_CMockExpect(__LINE__)\n" +
|
||||
"void Maple_CMockExpect(UNITY_LINE_TYPE cmock_line);\n"
|
||||
returned = @cmock_generator_plugin_expect.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
should "add mock function declaration for functions of style 'int func(void)'" do
|
||||
function = {:name => "Spruce", :args => [], :return => test_return[:int]}
|
||||
expected = "void Spruce_ExpectAndReturn(int cmock_to_return);\n"
|
||||
expected = "#define Spruce_ExpectAndReturn(cmock_retval) Spruce_CMockExpectAndReturn(__LINE__, cmock_retval)\n" +
|
||||
"void Spruce_CMockExpectAndReturn(UNITY_LINE_TYPE cmock_line, int cmock_to_return);\n"
|
||||
returned = @cmock_generator_plugin_expect.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
should "add mock function declaration for functions of style 'const char* func(int tofu)'" do
|
||||
function = {:name => "Pine", :args => ["int tofu"], :args_string => "int tofu", :return => test_return[:string]}
|
||||
expected = "void Pine_ExpectAndReturn(int tofu, const char* cmock_to_return);\n"
|
||||
function = {:name => "Pine", :args => ["int tofu"], :args_string => "int tofu", :args_call => 'tofu', :return => test_return[:string]}
|
||||
expected = "#define Pine_ExpectAndReturn(tofu, cmock_retval) Pine_CMockExpectAndReturn(__LINE__, tofu, cmock_retval)\n" +
|
||||
"void Pine_CMockExpectAndReturn(UNITY_LINE_TYPE cmock_line, int tofu, const char* cmock_to_return);\n"
|
||||
returned = @cmock_generator_plugin_expect.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
@@ -109,7 +112,7 @@ class CMockGeneratorPluginExpectTest < Test::Unit::TestCase
|
||||
|
||||
should "add mock function implementation using ordering if needed" do
|
||||
function = {:name => "Apple", :args => [], :return => test_return[:void]}
|
||||
expected = " TEST_ASSERT_MESSAGE((cmock_call_instance->CallOrder == ++GlobalVerifyOrder), \"Out of order function calls. Function 'Apple'\");\n"
|
||||
expected = " UNITY_TEST_ASSERT((cmock_call_instance->CallOrder == ++GlobalVerifyOrder), cmock_line, \"Out of order function calls. Function 'Apple'\");\n"
|
||||
@cmock_generator_plugin_expect.ordered = true
|
||||
returned = @cmock_generator_plugin_expect.mock_implementation(function)
|
||||
assert_equal(expected, returned)
|
||||
@@ -118,7 +121,7 @@ class CMockGeneratorPluginExpectTest < Test::Unit::TestCase
|
||||
should "add mock function implementation for functions of style 'void func(int worm)' and strict ordering" do
|
||||
function = {:name => "Apple", :args => [{ :type => "int", :name => "worm" }], :return => test_return[:void]}
|
||||
@utils.expect.code_verify_an_arg_expectation(function, function[:args][0]).returns("mocked_retval_0")
|
||||
expected = " TEST_ASSERT_MESSAGE((cmock_call_instance->CallOrder == ++GlobalVerifyOrder), \"Out of order function calls. Function 'Apple'\");\nmocked_retval_0"
|
||||
expected = " UNITY_TEST_ASSERT((cmock_call_instance->CallOrder == ++GlobalVerifyOrder), cmock_line, \"Out of order function calls. Function 'Apple'\");\nmocked_retval_0"
|
||||
@cmock_generator_plugin_expect.ordered = true
|
||||
returned = @cmock_generator_plugin_expect_strict.mock_implementation(function)
|
||||
assert_equal(expected, returned)
|
||||
@@ -128,7 +131,7 @@ class CMockGeneratorPluginExpectTest < Test::Unit::TestCase
|
||||
function = {:name => "Pear", :args => [], :args_string => "void", :return => test_return[:void]}
|
||||
@utils.expect.code_add_base_expectation("Pear").returns("mock_retval_0 ")
|
||||
@utils.expect.code_call_argument_loader(function).returns("mock_retval_1 ")
|
||||
expected = ["void Pear_Expect(void)\n",
|
||||
expected = ["void Pear_CMockExpect(UNITY_LINE_TYPE cmock_line)\n",
|
||||
"{\n",
|
||||
"mock_retval_0 ",
|
||||
"mock_retval_1 ",
|
||||
@@ -143,7 +146,7 @@ class CMockGeneratorPluginExpectTest < Test::Unit::TestCase
|
||||
@utils.expect.code_add_base_expectation("Orange").returns("mock_retval_0 ")
|
||||
@utils.expect.code_call_argument_loader(function).returns("mock_retval_1 ")
|
||||
@utils.expect.code_assign_argument_quickly("cmock_call_instance->ReturnVal", function[:return]).returns("mock_retval_2")
|
||||
expected = ["void Orange_ExpectAndReturn(int cmock_to_return)\n",
|
||||
expected = ["void Orange_CMockExpectAndReturn(UNITY_LINE_TYPE cmock_line, int cmock_to_return)\n",
|
||||
"{\n",
|
||||
"mock_retval_0 ",
|
||||
"mock_retval_1 ",
|
||||
@@ -159,7 +162,7 @@ class CMockGeneratorPluginExpectTest < Test::Unit::TestCase
|
||||
@utils.expect.code_add_base_expectation("Lemon").returns("mock_retval_0 ")
|
||||
@utils.expect.code_call_argument_loader(function).returns("mock_retval_1 ")
|
||||
@utils.expect.code_assign_argument_quickly("cmock_call_instance->ReturnVal", function[:return]).returns("mock_retval_2")
|
||||
expected = ["void Lemon_ExpectAndReturn(char* pescado, int cmock_to_return)\n",
|
||||
expected = ["void Lemon_CMockExpectAndReturn(UNITY_LINE_TYPE cmock_line, char* pescado, int cmock_to_return)\n",
|
||||
"{\n",
|
||||
"mock_retval_0 ",
|
||||
"mock_retval_1 ",
|
||||
@@ -174,7 +177,7 @@ class CMockGeneratorPluginExpectTest < Test::Unit::TestCase
|
||||
function = {:name => "Pear", :args => [], :args_string => "void", :return => test_return[:void]}
|
||||
@utils.expect.code_add_base_expectation("Pear").returns("mock_retval_0 ")
|
||||
@utils.expect.code_call_argument_loader(function).returns("mock_retval_1 ")
|
||||
expected = ["void Pear_Expect(void)\n",
|
||||
expected = ["void Pear_CMockExpect(UNITY_LINE_TYPE cmock_line)\n",
|
||||
"{\n",
|
||||
"mock_retval_0 ",
|
||||
"mock_retval_1 ",
|
||||
@@ -187,7 +190,7 @@ class CMockGeneratorPluginExpectTest < Test::Unit::TestCase
|
||||
|
||||
should "add mock verify lines" do
|
||||
function = {:name => "Banana" }
|
||||
expected = " TEST_ASSERT_NULL_MESSAGE(Mock.Banana_CallInstance, \"Function 'Banana' called less times than expected.\");\n"
|
||||
expected = " UNITY_TEST_ASSERT_NULL(Mock.Banana_CallInstance, cmock_line, \"Function 'Banana' called less times than expected.\");\n"
|
||||
returned = @cmock_generator_plugin_expect.mock_verify(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
@@ -30,14 +30,15 @@ class CMockGeneratorPluginIgnoreTest < Test::Unit::TestCase
|
||||
|
||||
should "handle function declarations for functions without return values" do
|
||||
function = {:name => "Mold", :args_string => "void", :return => test_return[:void]}
|
||||
expected = "void Mold_Ignore(void);\n"
|
||||
expected = "#define Mold_Ignore() Mold_CMockIgnore(__LINE__)\nvoid Mold_CMockIgnore(UNITY_LINE_TYPE cmock_line);\n"
|
||||
returned = @cmock_generator_plugin_ignore.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
should "handle function declarations for functions that returns something" do
|
||||
function = {:name => "Fungus", :args_string => "void", :return => test_return[:string]}
|
||||
expected = "void Fungus_IgnoreAndReturn(const char* cmock_to_return);\n"
|
||||
expected = "#define Fungus_IgnoreAndReturn(cmock_retval) Fungus_CMockIgnoreAndReturn(__LINE__, cmock_retval)\n"+
|
||||
"void Fungus_CMockIgnoreAndReturn(UNITY_LINE_TYPE cmock_line, const char* cmock_to_return);\n"
|
||||
returned = @cmock_generator_plugin_ignore.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
@@ -71,7 +72,7 @@ class CMockGeneratorPluginIgnoreTest < Test::Unit::TestCase
|
||||
|
||||
should "add a new mock interface for ignoring when function had no return value" do
|
||||
function = {:name => "Slime", :args => [], :args_string => "void", :return => test_return[:void]}
|
||||
expected = ["void Slime_Ignore(void)\n",
|
||||
expected = ["void Slime_CMockIgnore(UNITY_LINE_TYPE cmock_line)\n",
|
||||
"{\n",
|
||||
" Mock.Slime_IgnoreBool = (int)1;\n",
|
||||
"}\n\n"
|
||||
@@ -83,7 +84,7 @@ class CMockGeneratorPluginIgnoreTest < Test::Unit::TestCase
|
||||
should "add a new mock interface for ignoring when function has return value" do
|
||||
function = {:name => "Slime", :args => [], :args_string => "void", :return => test_return[:int]}
|
||||
@utils.expect.code_add_base_expectation("Slime", false).returns("mock_return_1")
|
||||
expected = ["void Slime_IgnoreAndReturn(int cmock_to_return)\n",
|
||||
expected = ["void Slime_CMockIgnoreAndReturn(UNITY_LINE_TYPE cmock_line, int cmock_to_return)\n",
|
||||
"{\n",
|
||||
"mock_return_1",
|
||||
" cmock_call_instance->ReturnVal = cmock_to_return;\n",
|
||||
|
||||
@@ -40,8 +40,9 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase
|
||||
should "add code for a base expectation with no plugins" do
|
||||
expected =
|
||||
" CMOCK_Apple_CALL_INSTANCE* cmock_call_instance = (CMOCK_Apple_CALL_INSTANCE*)CMock_Guts_MemNew(sizeof(CMOCK_Apple_CALL_INSTANCE));\n" +
|
||||
" TEST_ASSERT_NOT_NULL_MESSAGE(cmock_call_instance, \"CMock has run out of memory. Please allocate more.\");\n" +
|
||||
" Mock.Apple_CallInstance = (CMOCK_Apple_CALL_INSTANCE*)CMock_Guts_MemChain((void*)Mock.Apple_CallInstance, (void*)cmock_call_instance);\n"
|
||||
" UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, \"CMock has run out of memory. Please allocate more.\");\n" +
|
||||
" Mock.Apple_CallInstance = (CMOCK_Apple_CALL_INSTANCE*)CMock_Guts_MemChain((void*)Mock.Apple_CallInstance, (void*)cmock_call_instance);\n" +
|
||||
" cmock_call_instance->LineNumber = cmock_line;\n"
|
||||
output = @cmock_generator_utils_simple.code_add_base_expectation("Apple")
|
||||
assert_equal(expected, output)
|
||||
end
|
||||
@@ -49,8 +50,9 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase
|
||||
should "add code for a base expectation with all plugins" do
|
||||
expected =
|
||||
" CMOCK_Apple_CALL_INSTANCE* cmock_call_instance = (CMOCK_Apple_CALL_INSTANCE*)CMock_Guts_MemNew(sizeof(CMOCK_Apple_CALL_INSTANCE));\n" +
|
||||
" TEST_ASSERT_NOT_NULL_MESSAGE(cmock_call_instance, \"CMock has run out of memory. Please allocate more.\");\n" +
|
||||
" UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, \"CMock has run out of memory. Please allocate more.\");\n" +
|
||||
" Mock.Apple_CallInstance = (CMOCK_Apple_CALL_INSTANCE*)CMock_Guts_MemChain((void*)Mock.Apple_CallInstance, (void*)cmock_call_instance);\n" +
|
||||
" cmock_call_instance->LineNumber = cmock_line;\n" +
|
||||
" cmock_call_instance->CallOrder = ++GlobalExpectCount;\n" +
|
||||
" cmock_call_instance->ExceptionToThrow = CEXCEPTION_NONE;\n"
|
||||
output = @cmock_generator_utils_complex.code_add_base_expectation("Apple", true)
|
||||
@@ -60,8 +62,9 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase
|
||||
should "add code for a base expectation with all plugins and ordering not supported" do
|
||||
expected =
|
||||
" CMOCK_Apple_CALL_INSTANCE* cmock_call_instance = (CMOCK_Apple_CALL_INSTANCE*)CMock_Guts_MemNew(sizeof(CMOCK_Apple_CALL_INSTANCE));\n" +
|
||||
" TEST_ASSERT_NOT_NULL_MESSAGE(cmock_call_instance, \"CMock has run out of memory. Please allocate more.\");\n" +
|
||||
" UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, \"CMock has run out of memory. Please allocate more.\");\n" +
|
||||
" Mock.Apple_CallInstance = (CMOCK_Apple_CALL_INSTANCE*)CMock_Guts_MemChain((void*)Mock.Apple_CallInstance, (void*)cmock_call_instance);\n" +
|
||||
" cmock_call_instance->LineNumber = cmock_line;\n" +
|
||||
" cmock_call_instance->ExceptionToThrow = CEXCEPTION_NONE;\n"
|
||||
output = @cmock_generator_utils_complex.code_add_base_expectation("Apple", false)
|
||||
assert_equal(expected, output)
|
||||
@@ -167,39 +170,39 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase
|
||||
should 'handle a simple assert when requested' do
|
||||
function = { :name => 'Pear' }
|
||||
arg = test_arg[:int]
|
||||
expected = " TEST_ASSERT_EQUAL_INT_MESSAGE(cmock_call_instance->Expected_MyInt, MyInt, \"Function 'Pear' called with unexpected value for argument 'MyInt'.\");\n"
|
||||
@unity_helper.expect.get_helper('int').returns('TEST_ASSERT_EQUAL_INT_MESSAGE')
|
||||
expected = " UNITY_TEST_ASSERT_EQUAL_INT(cmock_call_instance->Expected_MyInt, MyInt, cmock_line, \"Function 'Pear' called with unexpected value for argument 'MyInt'.\");\n"
|
||||
@unity_helper.expect.get_helper('int').returns('UNITY_TEST_ASSERT_EQUAL_INT')
|
||||
assert_equal(expected, @cmock_generator_utils_simple.code_verify_an_arg_expectation(function, arg))
|
||||
end
|
||||
|
||||
should 'handle a pointer comparison when configured to do so' do
|
||||
function = { :name => 'Pear' }
|
||||
arg = test_arg[:int_ptr]
|
||||
expected = " TEST_ASSERT_EQUAL_HEX32_MESSAGE(cmock_call_instance->Expected_MyIntPtr, MyIntPtr, \"Function 'Pear' called with unexpected value for argument 'MyIntPtr'.\");\n"
|
||||
expected = " UNITY_TEST_ASSERT_EQUAL_HEX32(cmock_call_instance->Expected_MyIntPtr, MyIntPtr, cmock_line, \"Function 'Pear' called with unexpected value for argument 'MyIntPtr'.\");\n"
|
||||
assert_equal(expected, @cmock_generator_utils_simple.code_verify_an_arg_expectation(function, arg))
|
||||
end
|
||||
|
||||
should 'handle const char as string compares ' do
|
||||
function = { :name => 'Pear' }
|
||||
arg = test_arg[:string]
|
||||
expected = " TEST_ASSERT_EQUAL_STRING_MESSAGE(cmock_call_instance->Expected_MyStr, MyStr, \"Function 'Pear' called with unexpected value for argument 'MyStr'.\");\n"
|
||||
@unity_helper.expect.get_helper('char*').returns('TEST_ASSERT_EQUAL_STRING_MESSAGE')
|
||||
expected = " UNITY_TEST_ASSERT_EQUAL_STRING(cmock_call_instance->Expected_MyStr, MyStr, cmock_line, \"Function 'Pear' called with unexpected value for argument 'MyStr'.\");\n"
|
||||
@unity_helper.expect.get_helper('char*').returns('UNITY_TEST_ASSERT_EQUAL_STRING')
|
||||
assert_equal(expected, @cmock_generator_utils_simple.code_verify_an_arg_expectation(function, arg))
|
||||
end
|
||||
|
||||
should 'handle custom types as memory compares when we have no better way to do it' do
|
||||
function = { :name => 'Pear' }
|
||||
arg = test_arg[:mytype]
|
||||
expected = " TEST_ASSERT_EQUAL_MEMORY_MESSAGE((void*)(&cmock_call_instance->Expected_MyMyType), (void*)(&MyMyType), sizeof(MY_TYPE), \"Function 'Pear' called with unexpected value for argument 'MyMyType'.\");\n"
|
||||
@unity_helper.expect.get_helper('MY_TYPE').returns('TEST_ASSERT_EQUAL_MEMORY_MESSAGE')
|
||||
expected = " 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"
|
||||
@unity_helper.expect.get_helper('MY_TYPE').returns('UNITY_TEST_ASSERT_EQUAL_MEMORY')
|
||||
assert_equal(expected, @cmock_generator_utils_simple.code_verify_an_arg_expectation(function, arg))
|
||||
end
|
||||
|
||||
should 'handle custom types with custom handlers when available, even if they do not support the extra message' do
|
||||
function = { :name => 'Pear' }
|
||||
arg = test_arg[:mytype]
|
||||
expected = " TEST_ASSERT_EQUAL_MY_TYPE(cmock_call_instance->Expected_MyMyType, MyMyType);\n"
|
||||
@unity_helper.expect.get_helper('MY_TYPE').returns('TEST_ASSERT_EQUAL_MY_TYPE')
|
||||
expected = " UNITY_TEST_ASSERT_EQUAL_MY_TYPE(cmock_call_instance->Expected_MyMyType, MyMyType, cmock_line, \"Function 'Pear' called with unexpected value for argument 'MyMyType'.\");\n"
|
||||
@unity_helper.expect.get_helper('MY_TYPE').returns('UNITY_TEST_ASSERT_EQUAL_MY_TYPE')
|
||||
assert_equal(expected, @cmock_generator_utils_simple.code_verify_an_arg_expectation(function, arg))
|
||||
end
|
||||
|
||||
@@ -207,16 +210,16 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase
|
||||
# should 'handle pointers to custom types with array handlers, even if the array extension is turned off' do
|
||||
# function = { :name => 'Pear' }
|
||||
# arg = test_arg[:mytype]
|
||||
# expected = " TEST_ASSERT_EQUAL_MY_TYPE_ARRAY(&cmock_call_instance->Expected_MyMyType, &MyMyType, 1);\n"
|
||||
# @unity_helper.expect.get_helper('MY_TYPE').returns('TEST_ASSERT_EQUAL_MY_TYPE_ARRAY')
|
||||
# expected = " UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY(&cmock_call_instance->Expected_MyMyType, &MyMyType, 1);\n"
|
||||
# @unity_helper.expect.get_helper('MY_TYPE').returns('UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY')
|
||||
# assert_equal(expected, @cmock_generator_utils_simple.code_verify_an_arg_expectation(function, arg))
|
||||
# end
|
||||
|
||||
should 'handle a simple assert when requested with array plugin enabled' do
|
||||
function = { :name => 'Pear' }
|
||||
arg = test_arg[:int]
|
||||
expected = " TEST_ASSERT_EQUAL_INT_MESSAGE(cmock_call_instance->Expected_MyInt, MyInt, \"Function 'Pear' called with unexpected value for argument 'MyInt'.\");\n"
|
||||
@unity_helper.expect.get_helper('int').returns('TEST_ASSERT_EQUAL_INT_MESSAGE')
|
||||
expected = " UNITY_TEST_ASSERT_EQUAL_INT(cmock_call_instance->Expected_MyInt, MyInt, cmock_line, \"Function 'Pear' called with unexpected value for argument 'MyInt'.\");\n"
|
||||
@unity_helper.expect.get_helper('int').returns('UNITY_TEST_ASSERT_EQUAL_INT')
|
||||
assert_equal(expected, @cmock_generator_utils_complex.code_verify_an_arg_expectation(function, arg))
|
||||
end
|
||||
|
||||
@@ -224,36 +227,36 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase
|
||||
function = { :name => 'Pear' }
|
||||
arg = test_arg[:int_ptr]
|
||||
expected = " if (cmock_call_instance->Expected_MyIntPtr == NULL)\n" +
|
||||
" { TEST_ASSERT_NULL(MyIntPtr); }\n" +
|
||||
" { UNITY_TEST_ASSERT_NULL(MyIntPtr, cmock_line, NULL); }\n" +
|
||||
" else if (cmock_call_instance->Expected_MyIntPtr_Depth == 0)\n" +
|
||||
" { TEST_ASSERT_EQUAL_HEX32(cmock_call_instance->Expected_MyIntPtr, MyIntPtr); }\n" +
|
||||
" { UNITY_TEST_ASSERT_EQUAL_HEX32(cmock_call_instance->Expected_MyIntPtr, MyIntPtr, cmock_line, NULL); }\n" +
|
||||
" else\n" +
|
||||
" { TEST_ASSERT_EQUAL_INT_ARRAY(cmock_call_instance->Expected_MyIntPtr, MyIntPtr, cmock_call_instance->Expected_MyIntPtr_Depth); }\n"
|
||||
@unity_helper.expect.get_helper('int*').returns('TEST_ASSERT_EQUAL_INT_ARRAY')
|
||||
" { UNITY_TEST_ASSERT_EQUAL_INT_ARRAY(cmock_call_instance->Expected_MyIntPtr, MyIntPtr, cmock_call_instance->Expected_MyIntPtr_Depth, cmock_line, NULL); }\n"
|
||||
@unity_helper.expect.get_helper('int*').returns('UNITY_TEST_ASSERT_EQUAL_INT_ARRAY')
|
||||
assert_equal(expected, @cmock_generator_utils_complex.code_verify_an_arg_expectation(function, arg))
|
||||
end
|
||||
|
||||
should 'handle const char as string compares with array plugin enabled' do
|
||||
function = { :name => 'Pear' }
|
||||
arg = test_arg[:string]
|
||||
expected = " TEST_ASSERT_EQUAL_STRING_MESSAGE(cmock_call_instance->Expected_MyStr, MyStr, \"Function 'Pear' called with unexpected value for argument 'MyStr'.\");\n"
|
||||
@unity_helper.expect.get_helper('char*').returns('TEST_ASSERT_EQUAL_STRING_MESSAGE')
|
||||
expected = " UNITY_TEST_ASSERT_EQUAL_STRING(cmock_call_instance->Expected_MyStr, MyStr, cmock_line, \"Function 'Pear' called with unexpected value for argument 'MyStr'.\");\n"
|
||||
@unity_helper.expect.get_helper('char*').returns('UNITY_TEST_ASSERT_EQUAL_STRING')
|
||||
assert_equal(expected, @cmock_generator_utils_complex.code_verify_an_arg_expectation(function, arg))
|
||||
end
|
||||
|
||||
should 'handle custom types as memory compares when we have no better way to do it with array plugin enabled' do
|
||||
function = { :name => 'Pear' }
|
||||
arg = test_arg[:mytype]
|
||||
expected = " TEST_ASSERT_EQUAL_MEMORY_MESSAGE((void*)(&cmock_call_instance->Expected_MyMyType), (void*)(&MyMyType), sizeof(MY_TYPE), \"Function 'Pear' called with unexpected value for argument 'MyMyType'.\");\n"
|
||||
@unity_helper.expect.get_helper('MY_TYPE').returns('TEST_ASSERT_EQUAL_MEMORY_MESSAGE')
|
||||
expected = " 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"
|
||||
@unity_helper.expect.get_helper('MY_TYPE').returns('UNITY_TEST_ASSERT_EQUAL_MEMORY')
|
||||
assert_equal(expected, @cmock_generator_utils_complex.code_verify_an_arg_expectation(function, arg))
|
||||
end
|
||||
|
||||
should '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' }
|
||||
arg = test_arg[:mytype]
|
||||
expected = " TEST_ASSERT_EQUAL_MY_TYPE(cmock_call_instance->Expected_MyMyType, MyMyType);\n"
|
||||
@unity_helper.expect.get_helper('MY_TYPE').returns('TEST_ASSERT_EQUAL_MY_TYPE')
|
||||
expected = " UNITY_TEST_ASSERT_EQUAL_MY_TYPE(cmock_call_instance->Expected_MyMyType, MyMyType, cmock_line, \"Function 'Pear' called with unexpected value for argument 'MyMyType'.\");\n"
|
||||
@unity_helper.expect.get_helper('MY_TYPE').returns('UNITY_TEST_ASSERT_EQUAL_MY_TYPE')
|
||||
assert_equal(expected, @cmock_generator_utils_complex.code_verify_an_arg_expectation(function, arg))
|
||||
end
|
||||
|
||||
@@ -261,12 +264,12 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase
|
||||
function = { :name => 'Pear' }
|
||||
arg = test_arg[:mytype_ptr]
|
||||
expected = " if (cmock_call_instance->Expected_MyMyTypePtr == NULL)\n" +
|
||||
" { TEST_ASSERT_NULL(MyMyTypePtr); }\n" +
|
||||
" { UNITY_TEST_ASSERT_NULL(MyMyTypePtr, cmock_line, NULL); }\n" +
|
||||
" else if (cmock_call_instance->Expected_MyMyTypePtr_Depth == 0)\n" +
|
||||
" { TEST_ASSERT_EQUAL_HEX32(cmock_call_instance->Expected_MyMyTypePtr, MyMyTypePtr); }\n" +
|
||||
" { UNITY_TEST_ASSERT_EQUAL_HEX32(cmock_call_instance->Expected_MyMyTypePtr, MyMyTypePtr, cmock_line, NULL); }\n" +
|
||||
" else\n" +
|
||||
" { TEST_ASSERT_EQUAL_MY_TYPE_ARRAY(cmock_call_instance->Expected_MyMyTypePtr, MyMyTypePtr, cmock_call_instance->Expected_MyMyTypePtr_Depth); }\n"
|
||||
@unity_helper.expect.get_helper('MY_TYPE*').returns('TEST_ASSERT_EQUAL_MY_TYPE_ARRAY')
|
||||
" { UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY(cmock_call_instance->Expected_MyMyTypePtr, MyMyTypePtr, cmock_call_instance->Expected_MyMyTypePtr_Depth, cmock_line, NULL); }\n"
|
||||
@unity_helper.expect.get_helper('MY_TYPE*').returns('UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY')
|
||||
assert_equal(expected, @cmock_generator_utils_complex.code_verify_an_arg_expectation(function, arg))
|
||||
end
|
||||
|
||||
@@ -274,8 +277,8 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase
|
||||
# should 'handle custom types with array handlers when array plugin is enabled for non-array types' do
|
||||
# function = { :name => 'Pear' }
|
||||
# arg = test_arg[:mytype]
|
||||
# expected = " TEST_ASSERT_EQUAL_MY_TYPE_ARRAY(&cmock_call_instance->Expected_MyMyType, &MyMyType, 1);\n"
|
||||
# @unity_helper.expect.get_helper('MY_TYPE').returns('TEST_ASSERT_EQUAL_MY_TYPE_ARRAY')
|
||||
# expected = " UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY(&cmock_call_instance->Expected_MyMyType, &MyMyType, 1);\n"
|
||||
# @unity_helper.expect.get_helper('MY_TYPE').returns('UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY')
|
||||
# assert_equal(expected, @cmock_generator_utils_complex.code_verify_an_arg_expectation(function, arg))
|
||||
# end
|
||||
end
|
||||
|
||||
@@ -276,7 +276,8 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
:modifier=>"",
|
||||
:contains_ptr? => false,
|
||||
:args=>[{:type=>"int", :name=>"a", :ptr? => false, :const? => false}],
|
||||
:args_string=>"int a" }
|
||||
:args_string=>"int a",
|
||||
:args_call=>"a"}
|
||||
assert_equal(expected, @parser.parse_declaration(source))
|
||||
end
|
||||
|
||||
@@ -294,7 +295,8 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
:modifier=>"",
|
||||
:contains_ptr? => false,
|
||||
:args=>[],
|
||||
:args_string=>"void" }
|
||||
:args_string=>"void",
|
||||
:args_call=>"" }
|
||||
assert_equal(expected, @parser.parse_declaration(source))
|
||||
end
|
||||
|
||||
@@ -312,7 +314,8 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
:modifier=>"",
|
||||
:contains_ptr? => true,
|
||||
:args=>[{:type=>"MY_FUNKY_VOID*", :name=>"bluh", :ptr? => true, :const? => false}],
|
||||
:args_string=>"MY_FUNKY_VOID* bluh" }
|
||||
:args_string=>"MY_FUNKY_VOID* bluh",
|
||||
:args_call=>"bluh" }
|
||||
assert_equal(expected, @parser.parse_declaration(source))
|
||||
end
|
||||
|
||||
@@ -405,7 +408,8 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
:args=>[ {:type=>"int", :name=>"a", :ptr? => false, :const? => false},
|
||||
{:type=>"unsigned int", :name=>"b", :ptr? => false, :const? => false}
|
||||
],
|
||||
:args_string=>"int a, unsigned int b" }
|
||||
:args_string=>"int a, unsigned int b",
|
||||
:args_call=>"a, b" }
|
||||
assert_equal(expected, @parser.parse_declaration(source))
|
||||
end
|
||||
|
||||
@@ -427,7 +431,8 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
{:type=>"int", :name=>"de", :ptr? => false, :const? => false},
|
||||
{:type=>"bool", :name=>"da", :ptr? => false, :const? => false}
|
||||
],
|
||||
:args_string=>"uint la, int de, bool da" }
|
||||
:args_string=>"uint la, int de, bool da",
|
||||
:args_call=>"la, de, da" }
|
||||
assert_equal(expected, @parser.parse_declaration(source))
|
||||
end
|
||||
|
||||
@@ -446,7 +451,8 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
:modifier=>"",
|
||||
:contains_ptr? => false,
|
||||
:args=>[ ],
|
||||
:args_string=>"void" }
|
||||
:args_string=>"void",
|
||||
:args_call=>"" }
|
||||
assert_equal(expected, @parser.parse_declaration(source))
|
||||
end
|
||||
|
||||
@@ -467,7 +473,8 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
:args=>[ {:type=>"int", :name=>"Trinity", :ptr? => false, :const? => false},
|
||||
{:type=>"unsigned int*", :name=>"Neo", :ptr? => true, :const? => false}
|
||||
],
|
||||
:args_string=>"int Trinity, unsigned int* Neo" }
|
||||
:args_string=>"int Trinity, unsigned int* Neo",
|
||||
:args_call=>"Trinity, Neo" }
|
||||
assert_equal(expected, @parser.parse_declaration(source))
|
||||
end
|
||||
|
||||
@@ -490,7 +497,8 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
:args=>[ {:type=>"int", :name=>"Trinity", :ptr? => false, :const? => false},
|
||||
{:type=>"unsigned int*", :name=>"Neo", :ptr? => true, :const? => false}
|
||||
],
|
||||
:args_string=>"int Trinity, unsigned int* Neo" },
|
||||
:args_string=>"int Trinity, unsigned int* Neo",
|
||||
:args_call=>"Trinity, Neo" },
|
||||
{ :var_arg=>nil,
|
||||
:return=> { :type => "int",
|
||||
:name => 'cmock_to_return',
|
||||
@@ -505,7 +513,8 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
:args=>[ {:type=>"int", :name=>"cmock_arg1", :ptr? => false, :const? => false},
|
||||
{:type=>"unsigned int*", :name=>"cmock_arg2", :ptr? => true, :const? => false}
|
||||
],
|
||||
:args_string=>"int cmock_arg1, unsigned int* cmock_arg2"
|
||||
:args_string=>"int cmock_arg1, unsigned int* cmock_arg2",
|
||||
:args_call=>"cmock_arg1, cmock_arg2"
|
||||
}]
|
||||
assert_equal(expected, @parser.parse(source)[:functions])
|
||||
end
|
||||
@@ -529,7 +538,8 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
:args=>[ {:type=>"int", :name=>"Trinity", :ptr? => false, :const? => false},
|
||||
{:type=>"unsigned int*", :name=>"Neo", :ptr? => true, :const? => false}
|
||||
],
|
||||
:args_string=>"int Trinity, unsigned int* Neo"
|
||||
:args_string=>"int Trinity, unsigned int* Neo",
|
||||
:args_call=>"Trinity, Neo"
|
||||
}]
|
||||
assert_equal(expected, @parser.parse(source)[:functions])
|
||||
end
|
||||
@@ -553,7 +563,8 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
:modifier=>"",
|
||||
:contains_ptr? => false,
|
||||
:args=>[ {:type=>"int", :name=>"SingAlong", :ptr? => false, :const? => false} ],
|
||||
:args_string=>"int SingAlong"
|
||||
:args_string=>"int SingAlong",
|
||||
:args_call=>"SingAlong"
|
||||
},
|
||||
{ :var_arg=>nil,
|
||||
:return=> { :type => "int",
|
||||
@@ -567,7 +578,8 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
:modifier=>"",
|
||||
:contains_ptr? => false,
|
||||
:args=>[ ],
|
||||
:args_string=>"void"
|
||||
:args_string=>"void",
|
||||
:args_call=>""
|
||||
}]
|
||||
assert_equal(expected, @parser.parse(source)[:functions])
|
||||
end
|
||||
@@ -590,7 +602,8 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
:modifier=>"",
|
||||
:contains_ptr? => false,
|
||||
:args=>[ {:type=>"struct SingAlong", :name=>"Blog", :ptr? => false, :const? => false} ],
|
||||
:args_string=>"struct SingAlong Blog"
|
||||
:args_string=>"struct SingAlong Blog",
|
||||
:args_call=>"Blog"
|
||||
},
|
||||
{ :var_arg=>nil,
|
||||
:return=> { :type => "void",
|
||||
@@ -604,7 +617,8 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
:modifier=>"",
|
||||
:contains_ptr? => true,
|
||||
:args=>[ {:type=>"struct _KeepYourHeadUp_*", :name=>"BillyBuddy", :ptr? => true, :const? => true} ],
|
||||
:args_string=>"struct const _KeepYourHeadUp_* const BillyBuddy"
|
||||
:args_string=>"struct const _KeepYourHeadUp_* const BillyBuddy",
|
||||
:args_call=>"BillyBuddy"
|
||||
},
|
||||
{ :var_arg=>nil,
|
||||
:return=> { :type => "struct TheseArentTheHammer",
|
||||
@@ -618,7 +632,8 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
:modifier=>"",
|
||||
:contains_ptr? => false,
|
||||
:args=>[ ],
|
||||
:args_string=>"void"
|
||||
:args_string=>"void",
|
||||
:args_call=>""
|
||||
}]
|
||||
assert_equal(expected, @parser.parse(source)[:functions])
|
||||
end
|
||||
@@ -640,7 +655,8 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
:args=>[ {:type=>"int", :name=>"Scully", :ptr? => false, :const? => false},
|
||||
{:type=>"int", :name=>"Mulder", :ptr? => false, :const? => false}
|
||||
],
|
||||
:args_string=>"int Scully, int Mulder"
|
||||
:args_string=>"int Scully, int Mulder",
|
||||
:args_call=>"Scully, Mulder"
|
||||
}]
|
||||
assert_equal(expected, @parser.parse(source)[:functions])
|
||||
end
|
||||
|
||||
@@ -13,8 +13,9 @@ class CMockUnityHelperParserTest < Test::Unit::TestCase
|
||||
should "ignore lines that are commented out" do
|
||||
source =
|
||||
" abcd;\n" +
|
||||
"// #define TEST_ASSERT_EQUAL_CHICKENS(a,b) {...};\n" +
|
||||
"or maybe // #define TEST_ASSERT_EQUAL_CHICKENS(a,b) {...};\n\n"
|
||||
"// #define UNITY_TEST_ASSERT_EQUAL_CHICKENS(a,b,line,msg) {...};\n" +
|
||||
"or maybe // #define UNITY_TEST_ASSERT_EQUAL_CHICKENS(a,b,line,msg) {...};\n\n"
|
||||
@config.expects.plugins.returns([]) #not :array
|
||||
@config.expects.treat_as.returns({})
|
||||
@config.expects.load_unity_helper.returns(source)
|
||||
@parser = CMockUnityHelperParser.new(@config)
|
||||
@@ -26,8 +27,9 @@ class CMockUnityHelperParserTest < Test::Unit::TestCase
|
||||
should "ignore stuff in block comments" do
|
||||
source =
|
||||
" abcd; /*\n" +
|
||||
"#define TEST_ASSERT_EQUAL_CHICKENS(a,b) {...};\n" +
|
||||
"#define TEST_ASSERT_EQUAL_CHICKENS(a,b) {...};\n */\n"
|
||||
"#define UNITY_TEST_ASSERT_EQUAL_CHICKENS(a,b,line,msg) {...};\n" +
|
||||
"#define UNITY_TEST_ASSERT_EQUAL_CHICKENS(a,b,line,msg) {...};\n */\n"
|
||||
@config.expects.plugins.returns([]) #not :array
|
||||
@config.expects.treat_as.returns({})
|
||||
@config.expect.load_unity_helper.returns(source)
|
||||
@parser = CMockUnityHelperParser.new(@config)
|
||||
@@ -39,18 +41,19 @@ class CMockUnityHelperParserTest < Test::Unit::TestCase
|
||||
should "notice equal helpers in the proper form and ignore others" do
|
||||
source =
|
||||
"abcd;\n" +
|
||||
"#define TEST_ASSERT_EQUAL_TURKEYS_T(a,b) {...};\n" +
|
||||
"#define UNITY_TEST_ASSERT_EQUAL_TURKEYS_T(a,b,line,msg) {...};\n" +
|
||||
"abcd;\n" +
|
||||
"#define TEST_ASSERT_EQUAL_WRONG_NUM_ARGS(a,b,c) {...};\n" +
|
||||
"#define TEST_ASSERT_WRONG_NAME_EQUAL(a,b) {...};\n" +
|
||||
"#define TEST_ASSERT_EQUAL_unsigned_funky_rabbits(a,b) {...};\n" +
|
||||
"#define UNITY_TEST_ASSERT_EQUAL_WRONG_NUM_ARGS(a,b,c,d,e) {...};\n" +
|
||||
"#define UNITY_TEST_ASSERT_WRONG_NAME_EQUAL(a,b,c,d) {...};\n" +
|
||||
"#define UNITY_TEST_ASSERT_EQUAL_unsigned_funky_rabbits(a,b,c,d) {...};\n" +
|
||||
"abcd;\n"
|
||||
@config.expects.plugins.returns([]) #not :array
|
||||
@config.expects.treat_as.returns({})
|
||||
@config.expect.load_unity_helper.returns(source)
|
||||
@parser = CMockUnityHelperParser.new(@config)
|
||||
expected = {
|
||||
'TURKEYS_T' => "TEST_ASSERT_EQUAL_TURKEYS_T",
|
||||
'unsigned_funky_rabbits' => "TEST_ASSERT_EQUAL_unsigned_funky_rabbits"
|
||||
'TURKEYS_T' => "UNITY_TEST_ASSERT_EQUAL_TURKEYS_T",
|
||||
'unsigned_funky_rabbits' => "UNITY_TEST_ASSERT_EQUAL_unsigned_funky_rabbits"
|
||||
}
|
||||
|
||||
assert_equal(expected, @parser.c_types)
|
||||
@@ -59,18 +62,19 @@ class CMockUnityHelperParserTest < Test::Unit::TestCase
|
||||
should "notice equal helpers that contain arrays" do
|
||||
source =
|
||||
"abcd;\n" +
|
||||
"#define TEST_ASSERT_EQUAL_TURKEYS_ARRAY(a,b,c) {...};\n" +
|
||||
"#define UNITY_TEST_ASSERT_EQUAL_TURKEYS_ARRAY(a,b,c,d,e) {...};\n" +
|
||||
"abcd;\n" +
|
||||
"#define TEST_ASSERT_EQUAL_WRONG_NUM_ARGS_ARRAY(a,b,c,d) {...};\n" +
|
||||
"#define TEST_ASSERT_WRONG_NAME_EQUAL_ARRAY(a,b,c) {...};\n" +
|
||||
"#define TEST_ASSERT_EQUAL_unsigned_funky_rabbits_ARRAY(a,b,c) {...};\n" +
|
||||
"#define UNITY_TEST_ASSERT_EQUAL_WRONG_NUM_ARGS_ARRAY(a,b,c,d,e,f) {...};\n" +
|
||||
"#define UNITY_TEST_ASSERT_WRONG_NAME_EQUAL_ARRAY(a,b,c,d,e) {...};\n" +
|
||||
"#define UNITY_TEST_ASSERT_EQUAL_unsigned_funky_rabbits_ARRAY(a,b,c,d,e) {...};\n" +
|
||||
"abcd;\n"
|
||||
@config.expects.plugins.returns([]) #not :array
|
||||
@config.expects.treat_as.returns({})
|
||||
@config.expect.load_unity_helper.returns(source)
|
||||
@parser = CMockUnityHelperParser.new(@config)
|
||||
expected = {
|
||||
'TURKEYS*' => "TEST_ASSERT_EQUAL_TURKEYS_ARRAY",
|
||||
'unsigned_funky_rabbits*' => "TEST_ASSERT_EQUAL_unsigned_funky_rabbits_ARRAY"
|
||||
'TURKEYS*' => "UNITY_TEST_ASSERT_EQUAL_TURKEYS_ARRAY",
|
||||
'unsigned_funky_rabbits*' => "UNITY_TEST_ASSERT_EQUAL_unsigned_funky_rabbits_ARRAY"
|
||||
}
|
||||
|
||||
assert_equal(expected, @parser.c_types)
|
||||
@@ -82,9 +86,10 @@ class CMockUnityHelperParserTest < Test::Unit::TestCase
|
||||
"unsigned long" => "HEX64",
|
||||
}
|
||||
expected = {
|
||||
"UINT" => "TEST_ASSERT_EQUAL_HEX32_MESSAGE",
|
||||
"unsigned_long" => "TEST_ASSERT_EQUAL_HEX64_MESSAGE",
|
||||
"UINT" => "UNITY_TEST_ASSERT_EQUAL_HEX32",
|
||||
"unsigned_long" => "UNITY_TEST_ASSERT_EQUAL_HEX64",
|
||||
}
|
||||
@config.expects.plugins.returns([]) #not :array
|
||||
@config.expects.treat_as.returns(pairs)
|
||||
@config.expect.load_unity_helper.returns(nil)
|
||||
@parser = CMockUnityHelperParser.new(@config)
|
||||
@@ -98,9 +103,10 @@ class CMockUnityHelperParserTest < Test::Unit::TestCase
|
||||
"unsigned int" => "HEX32",
|
||||
}
|
||||
expected = {
|
||||
"char*" => "TEST_ASSERT_EQUAL_STRING_MESSAGE",
|
||||
"unsigned_int" => "TEST_ASSERT_EQUAL_HEX32_MESSAGE",
|
||||
"char*" => "UNITY_TEST_ASSERT_EQUAL_STRING",
|
||||
"unsigned_int" => "UNITY_TEST_ASSERT_EQUAL_HEX32",
|
||||
}
|
||||
@config.expects.plugins.returns([]) #not :array
|
||||
@config.expects.treat_as.returns(pairs)
|
||||
@config.expect.load_unity_helper.returns(nil)
|
||||
@parser = CMockUnityHelperParser.new(@config)
|
||||
@@ -109,54 +115,69 @@ class CMockUnityHelperParserTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
should "be able to fetch helpers on my list" do
|
||||
@config.expects.plugins.returns([]) #not :array
|
||||
@config.expects.treat_as.returns({})
|
||||
@config.expect.load_unity_helper.returns("")
|
||||
@parser = CMockUnityHelperParser.new(@config)
|
||||
@parser.c_types = {
|
||||
'UINT8' => "TEST_ASSERT_EQUAL_UINT8_MESSAGE",
|
||||
'UINT16*' => "TEST_ASSERT_EQUAL_UINT16_ARRAY",
|
||||
'SPINACH' => "TEST_ASSERT_EQUAL_SPINACH",
|
||||
'LONG_LONG' => "TEST_ASSERT_EQUAL_LONG_LONG"
|
||||
'UINT8' => "UNITY_TEST_ASSERT_EQUAL_UINT8",
|
||||
'UINT16*' => "UNITY_TEST_ASSERT_EQUAL_UINT16_ARRAY",
|
||||
'SPINACH' => "UNITY_TEST_ASSERT_EQUAL_SPINACH",
|
||||
'LONG_LONG' => "UNITY_TEST_ASSERT_EQUAL_LONG_LONG"
|
||||
}
|
||||
|
||||
[["UINT8","UINT8_MESSAGE"],
|
||||
[["UINT8","UINT8"],
|
||||
["UINT16*","UINT16_ARRAY"],
|
||||
["const SPINACH","SPINACH"],
|
||||
["LONG LONG","LONG_LONG"] ].each do |ctype, exptype|
|
||||
assert_equal("TEST_ASSERT_EQUAL_#{exptype}", @parser.get_helper(ctype))
|
||||
assert_equal("UNITY_TEST_ASSERT_EQUAL_#{exptype}", @parser.get_helper(ctype))
|
||||
end
|
||||
end
|
||||
|
||||
should "return memory comparison when asked to fetch helper of types not on my list" do
|
||||
@config.expects.plugins.returns([]) #not :array
|
||||
@config.expects.treat_as.returns({})
|
||||
@config.expects.load_unity_helper.returns("")
|
||||
@parser = CMockUnityHelperParser.new(@config)
|
||||
@parser.c_types = {
|
||||
'UINT8' => "TEST_ASSERT_EQUAL_UINT8_MESSAGE",
|
||||
'UINT16*' => "TEST_ASSERT_EQUAL_UINT16_ARRAY",
|
||||
'SPINACH' => "TEST_ASSERT_EQUAL_SPINACH",
|
||||
'UINT8' => "UNITY_TEST_ASSERT_EQUAL_UINT8",
|
||||
'UINT16*' => "UNITY_TEST_ASSERT_EQUAL_UINT16_ARRAY",
|
||||
'SPINACH' => "UNITY_TEST_ASSERT_EQUAL_SPINACH",
|
||||
}
|
||||
|
||||
["UINT16","SPINACH_T","SALAD","PINEAPPLE"].each do |ctype|
|
||||
@config.expect.memcmp_if_unknown.returns(true)
|
||||
assert_equal("TEST_ASSERT_EQUAL_MEMORY_MESSAGE", @parser.get_helper(ctype))
|
||||
assert_equal("UNITY_TEST_ASSERT_EQUAL_MEMORY", @parser.get_helper(ctype))
|
||||
end
|
||||
end
|
||||
|
||||
should "return memory array comparison when asked to fetch helper of types not on my list" do
|
||||
@config.expects.plugins.returns([:array])
|
||||
@config.expects.treat_as.returns({})
|
||||
@config.expects.load_unity_helper.returns("")
|
||||
@parser = CMockUnityHelperParser.new(@config)
|
||||
@parser.c_types = {
|
||||
'UINT8' => "UNITY_TEST_ASSERT_EQUAL_UINT8",
|
||||
'UINT16*' => "UNITY_TEST_ASSERT_EQUAL_UINT16_ARRAY",
|
||||
'SPINACH' => "UNITY_TEST_ASSERT_EQUAL_SPINACH",
|
||||
}
|
||||
|
||||
["UINT8*","SPINACH_T*"].each do |ctype|
|
||||
@config.expect.memcmp_if_unknown.returns(true)
|
||||
assert_equal("TEST_ASSERT_EQUAL_MEMORY_MESSAGE_ARRAY", @parser.get_helper(ctype))
|
||||
assert_equal("UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY", @parser.get_helper(ctype))
|
||||
end
|
||||
end
|
||||
|
||||
should "raise error when asked to fetch helper of type not on my list and not allowed to mem check" do
|
||||
@config.expects.plugins.returns([]) #not :array
|
||||
@config.expects.treat_as.returns({})
|
||||
@config.expect.load_unity_helper.returns("")
|
||||
@config.expect.memcmp_if_unknown.returns(false)
|
||||
@parser = CMockUnityHelperParser.new(@config)
|
||||
@parser.c_types = {
|
||||
'UINT8' => "TEST_ASSERT_EQUAL_UINT8_MESSAGE",
|
||||
'UINT16*' => "TEST_ASSERT_EQUAL_UINT16_ARRAY",
|
||||
'SPINACH' => "TEST_ASSERT_EQUAL_SPINACH",
|
||||
'UINT8' => "UNITY_TEST_ASSERT_EQUAL_UINT8",
|
||||
'UINT16*' => "UNITY_TEST_ASSERT_EQUAL_UINT16_ARRAY",
|
||||
'SPINACH' => "UNITY_TEST_ASSERT_EQUAL_SPINACH",
|
||||
}
|
||||
|
||||
assert_raise(RuntimeError) { @parser.get_helper("UINT16") }
|
||||
|
||||
Reference in New Issue
Block a user