- rolled in color coding changes from Martyn

- cleaned up utils to make faster and clearer
- corrected mistake in system test helper

git-svn-id: http://cmock.svn.sourceforge.net/svnroot/cmock/trunk@157 bf332499-1b4d-0410-844d-d2d48d5cc64c
This commit is contained in:
mvandervoord
2010-03-13 04:53:12 +00:00
parent 1ff34b5c04
commit b2241274e4
8 changed files with 215 additions and 107 deletions
+31
View File
@@ -0,0 +1,31 @@
Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
The end-user documentation included with the redistribution, if
any, must include the following acknowledgment: "This product
includes software developed for the CMock Project, by Mike Karlesky,
Mark VanderVoord, and Greg Williams and other contributors", in
the same place and form as other third-party acknowledgments.
Alternately, this acknowledgment may appear in the software
itself, in the same form and location as other such third-party
acknowledgments.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
+2
View File
@@ -1,4 +1,6 @@
---
colour: true
compiler:
path: gcc
source_path: &systest_generated_path 'test/system/generated/'
+2 -1
View File
@@ -17,7 +17,8 @@ class CMockGeneratorPluginCallback
def mock_function_declarations(function)
func_name = function[:name]
"typedef #{function[:return][:type]} (* CMOCK_#{func_name}_CALLBACK)(#{(function[:args_string] == "void") ? '' : function[:args_string] + ', '}int cmock_num_calls);\n" +
return_type = function[:return][:const?] ? "const #{function[:return][:type]}" : function[:return][:type]
"typedef #{return_type} (* CMOCK_#{func_name}_CALLBACK)(#{(function[:args_string] == "void") ? '' : function[:args_string] + ', '}int cmock_num_calls);\n" +
"void #{func_name}_StubWithCallback(CMOCK_#{func_name}_CALLBACK Callback);\n"
end
+86 -40
View File
@@ -11,6 +11,16 @@ class CMockGeneratorUtils
@cexception = @config.plugins.include? :cexception
@treat_as = @config.treat_as
@helpers = helpers
if (@arrays)
case(@ptr_handling)
when :smart then alias :code_verify_an_arg_expectation :code_verify_an_arg_expectation_with_smart_arrays
when :compare_data then alias :code_verify_an_arg_expectation :code_verify_an_arg_expectation_with_normal_arrays
when :compare_ptr then raise "ERROR: the array plugin doesn't enjoy working with :compare_ptr only. Disable one option."
end
else
alias :code_verify_an_arg_expectation :code_verify_an_arg_expectation_with_no_arrays
end
end
def code_add_base_expectation(func_name, global_ordering_supported=true)
@@ -39,7 +49,10 @@ class CMockGeneratorUtils
def code_add_argument_loader(function)
if (function[:args_string] != "void")
if (@arrays)
args_string = function[:args].map{|m| m[:ptr?] ? "#{m[:type]} #{m[:name]}, int #{m[:name]}_Depth" : "#{m[:type]} #{m[:name]}"}.join(', ')
args_string = function[:args].map do |m|
const_str = m[ :const? ] ? 'const ' : ''
m[:ptr?] ? "#{const_str}#{m[:type]} #{m[:name]}, int #{m[:name]}_Depth" : "#{const_str}#{m[:type]} #{m[:name]}"
end.join(', ')
"void CMockExpectParameters_#{function[:name]}(CMOCK_#{function[:name]}_CALL_INSTANCE* cmock_call_instance, #{args_string})\n{\n" +
function[:args].inject("") { |all, arg| all + code_add_an_arg_expectation(arg, (arg[:ptr?] ? "#{arg[:name]}_Depth" : 1) ) } +
"}\n\n"
@@ -56,8 +69,7 @@ class CMockGeneratorUtils
def code_call_argument_loader(function)
if (function[:args_string] != "void")
args = function[:args].map do |m|
arg = m[:const?] ? "(#{m[:type]})#{m[:name]}" : m[:name]
(@arrays and m[:ptr?]) ? "#{arg}, 1" : arg
(@arrays and m[:ptr?]) ? "#{m[:name]}, 1" : m[:name]
end
" CMockExpectParameters_#{function[:name]}(cmock_call_instance, #{args.join(', ')});\n"
else
@@ -65,52 +77,86 @@ class CMockGeneratorUtils
end
end
def code_verify_an_arg_expectation(function, arg)
c_type = arg[:type]
arg_name = arg[:name]
expected = "cmock_call_instance->Expected_#{arg_name}"
msg = "\"Function '#{function[:name]}' called with unexpected value for argument '#{arg_name}'.\""
depth_name = (arg[:ptr?]) ? "cmock_call_instance->Expected_#{arg_name}_Depth" : 1
if ((arg[:ptr?]) and (@ptr_handling == :compare_ptr))
unity_func = "TEST_ASSERT_EQUAL_HEX32_MESSAGE"
else
unity_func = (@helpers.nil? or @helpers[:unity_helper].nil?) ? "TEST_ASSERT_EQUAL_MESSAGE" : @helpers[:unity_helper].get_helper(c_type)
end
unity_msg = (unity_func =~ /_MESSAGE/) ? ", #{msg}" : ''
#private ######################
def lookup_expect_type(function, arg)
c_type = arg[:type]
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"
else
(@helpers.nil? or @helpers[:unity_helper].nil?) ? "TEST_ASSERT_EQUAL_MESSAGE" : @helpers[:unity_helper].get_helper(c_type)
end
unity_msg = (unity_func =~ /_MESSAGE/) ? ", \"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"
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"
if (@arrays)
[ " if (#{expected} == NULL)",
" { TEST_ASSERT_NULL(#{arg_name}); }",
(((@ptr_handling == :smart) and (depth_name != 1)) ? " else if (#{depth_name} == 0)\n { TEST_ASSERT_EQUAL_HEX32(#{expected}, #{arg_name}); }" : 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")
else
[ " if (#{expected} == NULL)",
" { TEST_ASSERT_NULL(#{arg_name}); }",
" else",
" { TEST_ASSERT_EQUAL_MEMORY_MESSAGE((void*)(#{expected}), (void*)#{arg_name}, sizeof(#{c_type.sub('*','')})#{unity_msg}); }\n"].join("\n")
end
[ " if (#{expected} == NULL)",
" { TEST_ASSERT_NULL(#{arg_name}); }",
" else",
" { TEST_ASSERT_EQUAL_MEMORY_MESSAGE((void*)(#{expected}), (void*)#{arg_name}, sizeof(#{c_type.sub('*','')})#{unity_msg}); }\n"].join("\n")
when /_ARRAY/
if (@arrays)
[ " if (#{expected} == NULL)",
" { TEST_ASSERT_NULL(#{arg_name}); }",
(((@ptr_handling == :smart) and (depth_name != 1)) ? " else if (#{depth_name} == 0)\n { TEST_ASSERT_EQUAL_HEX32(#{expected}, #{arg_name}); }" : nil),
" else",
" { #{unity_func}(#{expected}, #{arg_name}, #{depth_name}); }\n"].compact.join("\n")
else
[ " if (#{expected} == NULL)",
" { TEST_ASSERT_NULL(#{arg_name}); }",
" else",
" { #{unity_func}(#{expected}, #{arg_name}, 1); }\n"].join("\n")
end
[ " if (#{expected} == NULL)",
" { TEST_ASSERT_NULL(#{arg_name}); }",
" else",
" { #{unity_func}(#{expected}, #{arg_name}, 1); }\n"].join("\n")
else
return " #{unity_func}(#{expected}, #{arg_name}#{unity_msg});\n"
end
end
def code_verify_an_arg_expectation_with_normal_arrays(function, arg)
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"
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"
[ " if (#{expected} == NULL)",
" { TEST_ASSERT_NULL(#{arg_name}); }",
" else",
" { TEST_ASSERT_EQUAL_MEMORY_ARRAY_MESSAGE((void*)(#{expected}), (void*)#{arg_name}, sizeof(#{c_type.sub('*','')}), #{depth_name}#{unity_msg}); }\n"].compact.join("\n")
when /_ARRAY/
[ " if (#{expected} == NULL)",
" { TEST_ASSERT_NULL(#{arg_name}); }",
" else",
" { #{unity_func}(#{expected}, #{arg_name}, #{depth_name}); }\n"].compact.join("\n")
else
return " #{unity_func}(#{expected}, #{arg_name}#{unity_msg});\n"
end
end
def code_verify_an_arg_expectation_with_smart_arrays(function, arg)
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"
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"
[ " 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),
" else",
" { TEST_ASSERT_EQUAL_MEMORY_ARRAY_MESSAGE((void*)(#{expected}), (void*)#{arg_name}, sizeof(#{c_type.sub('*','')}), #{depth_name}#{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),
" else",
" { #{unity_func}(#{expected}, #{arg_name}, #{depth_name}); }\n"].compact.join("\n")
else
return " #{unity_func}(#{expected}, #{arg_name}#{unity_msg});\n"
end
end
end
+59 -28
View File
@@ -14,7 +14,38 @@ module RakefileHelpers
RESULT_EXTENSION = '.result'
def report(message)
puts 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
@@ -145,7 +176,7 @@ module RakefileHelpers
end
def execute(command_string, verbose=true)
#puts command_string
#report command_string
output = `#{command_string}`.chomp
report(output) if (verbose && !output.nil? && (output.length > 0))
if $?.exitstatus != 0
@@ -192,7 +223,7 @@ module RakefileHelpers
test_base = File.basename(test, C_EXTENSION)
cmock_config = test_base.gsub(/test_/, '') + '_cmock.yml'
puts "Executing system test cases contained in #{File.basename(test)}..."
report "Executing system test cases contained in #{File.basename(test)}..."
# Detect dependencies and build required required modules
extract_headers(test).each do |header|
@@ -265,21 +296,21 @@ module RakefileHelpers
end
end
puts "\n"
puts "------------------------------------\n"
puts "SYSTEM TEST MOCK INTERACTION SUMMARY\n"
puts "------------------------------------\n"
puts "TOTAL TESTS: #{total_tests} TOTAL FAILURES: #{total_failures}\n"
puts "\n"
report "\n"
report "------------------------------------\n"
report "SYSTEM TEST MOCK INTERACTION SUMMARY\n"
report "------------------------------------\n"
report "#{total_tests} Tests #{total_failures} Failures 0 Ignored\n"
report "\n"
if (failure_messages.size > 0)
puts 'System test failures:'
report 'System test failures:'
failure_messages.each do |failure|
puts failure
report failure
end
end
puts ''
report ''
return total_failures
end
@@ -309,14 +340,14 @@ module RakefileHelpers
load_configuration($cfg_file)
$cfg['compiler']['defines']['items'] = [] if $cfg['compiler']['defines']['items'].nil?
puts "\n"
puts "------------------------------------\n"
puts "SYSTEM TEST MOCK COMPILATION SUMMARY\n"
puts "------------------------------------\n"
report "\n"
report "------------------------------------\n"
report "SYSTEM TEST MOCK COMPILATION SUMMARY\n"
report "------------------------------------\n"
mockables.each do |header|
mock_filename = 'mock_' + File.basename(header).ext('.c')
CMock.new(SYSTEST_COMPILE_MOCKABLES_PATH + 'config.yml').setup_mocks(header)
puts "Compiling #{mock_filename}..."
report "Compiling #{mock_filename}..."
compile(SYSTEST_GENERATED_FILES_PATH + mock_filename)
end
end
@@ -327,10 +358,10 @@ module RakefileHelpers
load_configuration($cfg_file)
$cfg['compiler']['defines']['items'] = [] if $cfg['compiler']['defines']['items'].nil?
puts "\n"
puts "--------------------------\n"
puts "SYSTEM TEST MOCK PROFILING\n"
puts "--------------------------\n"
report "\n"
report "--------------------------\n"
report "SYSTEM TEST MOCK PROFILING\n"
report "--------------------------\n"
mockables.each do |header|
mock_filename = 'mock_' + File.basename(header).ext('.c')
profile_this(mock_filename.gsub('.c','')) do
@@ -338,21 +369,21 @@ module RakefileHelpers
CMock.new(SYSTEST_COMPILE_MOCKABLES_PATH + 'config.yml').setup_mocks(header)
end
end
puts "Compiling #{mock_filename}..."
report "Compiling #{mock_filename}..."
compile(SYSTEST_GENERATED_FILES_PATH + mock_filename)
end
end
def build_and_test_c_files
puts "\n"
puts "----------------\n"
puts "UNIT TEST C CODE\n"
puts "----------------\n"
report "\n"
report "----------------\n"
report "UNIT TEST C CODE\n"
report "----------------\n"
errors = false
FileList.new("test/c/*.yml").each do |yaml_file|
test = YAML.load(File.read(yaml_file))
puts "\nTesting #{yaml_file.sub('.yml','')}"
puts "(#{test[:options].join(', ')})"
report "\nTesting #{yaml_file.sub('.yml','')}"
report "(#{test[:options].join(', ')})"
test[:files].each { |f| compile(f, test[:options]) }
obj_files = test[:files].map { |f| f.gsub!(/.*\//,'').gsub!(C_EXTENSION, $cfg['compiler']['object_files']['extension']) }
link('TestCMockC', obj_files)
+1 -1
View File
@@ -178,4 +178,4 @@ void test_ThatWeCanAskForAllSortsOfSizes(void)
//there aren't any after that
TEST_ASSERT_NULL(next);
}
}
+9 -9
View File
@@ -18,20 +18,20 @@ class Test::Unit::TestCase
def test_return
{
:int => {:type => "int", :name => 'cmock_to_return', :ptr? => false, :const? => false, :void? => false, :str => 'int cmock_to_return'},
:int_ptr => {:type => "int*", :name => 'cmock_to_return', :ptr? => true, :const? => false, :void? => false, :str => 'int* cmock_to_return'},
:void => {:type => "void", :name => 'cmock_to_return', :ptr? => false, :const? => false, :void? => true, :str => 'void cmock_to_return'},
:string => {:type => "const char*", :name => 'cmock_to_return', :ptr? => false, :const? => true, :void? => false, :str => 'const char* cmock_to_return'},
:int => {:type => "int", :name => 'cmock_to_return', :ptr? => false, :const? => false, :void? => false, :str => 'int cmock_to_return'},
:int_ptr => {:type => "int*", :name => 'cmock_to_return', :ptr? => true, :const? => false, :void? => false, :str => 'int* cmock_to_return'},
:void => {:type => "void", :name => 'cmock_to_return', :ptr? => false, :const? => false, :void? => true, :str => 'void cmock_to_return'},
:string => {:type => "char*", :name => 'cmock_to_return', :ptr? => false, :const? => true, :void? => false, :str => 'const char* cmock_to_return'},
}
end
def test_arg
{
:int => {:type => "int", :name => 'MyInt', :ptr? => false, :const? => false},
:int_ptr => {:type => "int*", :name => 'MyIntPtr', :ptr? => true, :const? => false},
:mytype => {:type => "const MY_TYPE", :name => 'MyMyType', :ptr? => false, :const? => true},
:mytype_ptr => {:type => "MY_TYPE*", :name => 'MyMyTypePtr', :ptr? => true, :const? => false},
:string => {:type => "const char*", :name => 'MyStr', :ptr? => false, :const? => true},
:int => {:type => "int", :name => 'MyInt', :ptr? => false, :const? => false},
:int_ptr => {:type => "int*", :name => 'MyIntPtr', :ptr? => true, :const? => false},
:mytype => {:type => "MY_TYPE", :name => 'MyMyType', :ptr? => false, :const? => true},
:mytype_ptr => {:type => "MY_TYPE*", :name => 'MyMyTypePtr', :ptr? => true, :const? => false},
:string => {:type => "char*", :name => 'MyStr', :ptr? => false, :const? => true},
}
end
end
+25 -28
View File
@@ -9,14 +9,14 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase
@config.expect.enforce_strict_ordering.returns(false)
@config.expect.plugins.returns([])
@config.expect.plugins.returns([])
@config.expect.treat_as.returns(['int','short','long','char','const char*'])
@config.expect.treat_as.returns(['int','short','long','char','char*'])
@cmock_generator_utils_simple = CMockGeneratorUtils.new(@config, {:unity_helper => @unity_helper})
@config.expect.when_ptr.returns(:smart)
@config.expect.enforce_strict_ordering.returns(true)
@config.expect.plugins.returns([:array, :cexception])
@config.expect.plugins.returns([:array, :cexception])
@config.expect.treat_as.returns(['int','short','long','char','uint32_t','const char*'])
@config.expect.treat_as.returns(['int','short','long','char','uint32_t','char*'])
@cmock_generator_utils_complex = CMockGeneratorUtils.new(@config, {:unity_helper => @unity_helper, :A=>1, :B=>2})
end
@@ -120,8 +120,8 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase
}
expected = "void CMockExpectParameters_Melon(CMOCK_Melon_CALL_INSTANCE* cmock_call_instance, stuff)\n{\n" +
" cmock_call_instance->Expected_MyIntPtr = MyIntPtr;\n" +
" memcpy(&cmock_call_instance->Expected_MyMyType, &MyMyType, sizeof(const MY_TYPE));\n" +
" cmock_call_instance->Expected_MyStr = (const char*)MyStr;\n" +
" memcpy(&cmock_call_instance->Expected_MyMyType, &MyMyType, sizeof(MY_TYPE));\n" +
" cmock_call_instance->Expected_MyStr = (char*)MyStr;\n" +
"}\n\n"
assert_equal(expected, @cmock_generator_utils_simple.code_add_argument_loader(function))
end
@@ -134,8 +134,8 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase
expected = "void CMockExpectParameters_Melon(CMOCK_Melon_CALL_INSTANCE* cmock_call_instance, int* MyIntPtr, int MyIntPtr_Depth, const MY_TYPE MyMyType, const char* MyStr)\n{\n" +
" cmock_call_instance->Expected_MyIntPtr = MyIntPtr;\n" +
" cmock_call_instance->Expected_MyIntPtr_Depth = MyIntPtr_Depth;\n" +
" memcpy(&cmock_call_instance->Expected_MyMyType, &MyMyType, sizeof(const MY_TYPE));\n" +
" cmock_call_instance->Expected_MyStr = (const char*)MyStr;\n" +
" memcpy(&cmock_call_instance->Expected_MyMyType, &MyMyType, sizeof(MY_TYPE));\n" +
" cmock_call_instance->Expected_MyStr = (char*)MyStr;\n" +
"}\n\n"
assert_equal(expected, @cmock_generator_utils_complex.code_add_argument_loader(function))
end
@@ -151,7 +151,7 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase
:args_string => "stuff",
:args => [test_arg[:int_ptr], test_arg[:mytype], test_arg[:string]]
}
expected = " CMockExpectParameters_Pineapple(cmock_call_instance, MyIntPtr, (const MY_TYPE)MyMyType, (const char*)MyStr);\n"
expected = " CMockExpectParameters_Pineapple(cmock_call_instance, MyIntPtr, MyMyType, MyStr);\n"
assert_equal(expected, @cmock_generator_utils_simple.code_call_argument_loader(function))
end
@@ -160,7 +160,7 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase
:args_string => "stuff",
:args => [test_arg[:int_ptr], test_arg[:mytype], test_arg[:string]]
}
expected = " CMockExpectParameters_Pineapple(cmock_call_instance, MyIntPtr, 1, (const MY_TYPE)MyMyType, (const char*)MyStr);\n"
expected = " CMockExpectParameters_Pineapple(cmock_call_instance, MyIntPtr, 1, MyMyType, MyStr);\n"
assert_equal(expected, @cmock_generator_utils_complex.code_call_argument_loader(function))
end
@@ -183,15 +183,15 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase
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('const char*').returns('TEST_ASSERT_EQUAL_STRING_MESSAGE')
@unity_helper.expect.get_helper('char*').returns('TEST_ASSERT_EQUAL_STRING_MESSAGE')
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(const MY_TYPE), \"Function 'Pear' called with unexpected value for argument 'MyMyType'.\");\n"
@unity_helper.expect.get_helper('const MY_TYPE').returns('TEST_ASSERT_EQUAL_MEMORY_MESSAGE')
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')
assert_equal(expected, @cmock_generator_utils_simple.code_verify_an_arg_expectation(function, arg))
end
@@ -199,21 +199,18 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase
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('const MY_TYPE').returns('TEST_ASSERT_EQUAL_MY_TYPE')
@unity_helper.expect.get_helper('MY_TYPE').returns('TEST_ASSERT_EQUAL_MY_TYPE')
assert_equal(expected, @cmock_generator_utils_simple.code_verify_an_arg_expectation(function, arg))
end
should 'handle custom types with array handlers, even if the array extension is turned off' do
function = { :name => 'Pear' }
arg = test_arg[:mytype_ptr]
expected = " if (cmock_call_instance->Expected_MyMyTypePtr == NULL)\n" +
" { TEST_ASSERT_NULL(MyMyTypePtr); }\n" +
" else\n" +
" { TEST_ASSERT_EQUAL_MY_TYPE_ARRAY(cmock_call_instance->Expected_MyMyTypePtr, MyMyTypePtr, 1); }\n"
@cmock_generator_utils_simple.ptr_handling = :smart
@unity_helper.expect.get_helper('MY_TYPE*').returns('TEST_ASSERT_EQUAL_MY_TYPE_ARRAY')
assert_equal(expected, @cmock_generator_utils_simple.code_verify_an_arg_expectation(function, arg))
end
#This is not yet supported
# 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')
# 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' }
@@ -240,15 +237,15 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase
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('const char*').returns('TEST_ASSERT_EQUAL_STRING_MESSAGE')
@unity_helper.expect.get_helper('char*').returns('TEST_ASSERT_EQUAL_STRING_MESSAGE')
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(const MY_TYPE), \"Function 'Pear' called with unexpected value for argument 'MyMyType'.\");\n"
@unity_helper.expect.get_helper('const MY_TYPE').returns('TEST_ASSERT_EQUAL_MEMORY_MESSAGE')
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')
assert_equal(expected, @cmock_generator_utils_complex.code_verify_an_arg_expectation(function, arg))
end
@@ -256,7 +253,7 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase
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('const MY_TYPE').returns('TEST_ASSERT_EQUAL_MY_TYPE')
@unity_helper.expect.get_helper('MY_TYPE').returns('TEST_ASSERT_EQUAL_MY_TYPE')
assert_equal(expected, @cmock_generator_utils_complex.code_verify_an_arg_expectation(function, arg))
end
@@ -278,7 +275,7 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase
# 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('const MY_TYPE').returns('TEST_ASSERT_EQUAL_MY_TYPE_ARRAY')
# @unity_helper.expect.get_helper('MY_TYPE').returns('TEST_ASSERT_EQUAL_MY_TYPE_ARRAY')
# assert_equal(expected, @cmock_generator_utils_complex.code_verify_an_arg_expectation(function, arg))
# end
end