- Fixed callback-after-arg-check so that it actually checks args

- Fixed ignore-when-ignoring-args-only
- Fixed error in memory comparisons when pointers used
- Fixed system testing of CMock(!)

git-svn-id: http://cmock.svn.sourceforge.net/svnroot/cmock/trunk@167 bf332499-1b4d-0410-844d-d2d48d5cc64c
This commit is contained in:
mvandervoord
2010-06-19 20:11:13 +00:00
parent 2bf2364b82
commit f201cf2903
12 changed files with 112 additions and 26 deletions
+7 -1
View File
@@ -13,13 +13,15 @@ class CMockGeneratorPluginCallback
def initialize(config, utils)
@config = config
@utils = utils
@priority = 3
@priority = 6
@include_count = @config.callback_include_count
if (@config.callback_after_arg_check)
alias :mock_implementation :mock_implementation_for_callbacks
alias :mock_implementation_precheck :nothing
else
alias :mock_implementation_precheck :mock_implementation_for_callbacks
alias :mock_implementation :nothing
end
end
@@ -52,6 +54,10 @@ class CMockGeneratorPluginCallback
when 7 then " return Mock.#{func_name}_CallbackFunctionPointer(#{function[:args].map{|m| m[:name]}.join(', ')}, Mock.#{func_name}_CallbackCalls++);\n }\n"
end
end
def nothing(function)
return ""
end
def mock_interfaces(function)
func_name = function[:name]
+5 -1
View File
@@ -58,8 +58,12 @@ class CMockGeneratorPluginIgnore
else
lines << "void #{function[:name]}_CMockIgnoreAndReturn(UNITY_LINE_TYPE cmock_line, #{function[:return][:str]})\n{\n"
end
unless (function[:return][:void?])
if (@config.ignore == :args_only)
lines << @utils.code_add_base_expectation(function[:name], true)
elsif (!function[:return][:void?])
lines << @utils.code_add_base_expectation(function[:name], false)
end
unless (function[:return][:void?])
lines << " cmock_call_instance->ReturnVal = cmock_to_return;\n"
end
lines << " Mock.#{function[:name]}_IgnoreBool = (int)1;\n"
+6 -6
View File
@@ -102,8 +102,8 @@ class CMockGeneratorUtils
c_type, arg_name, expected, unity_func, pre, unity_msg = lookup_expect_type(function, arg)
case(unity_func)
when "UNITY_TEST_ASSERT_EQUAL_MEMORY"
full_expected = (expected =~ /^\*/) ? expected.slice(1..-1) : "(&#{expected})"
return " UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)#{full_expected}, (void*)(&#{arg_name}), sizeof(#{c_type}), cmock_line#{unity_msg});\n"
c_type_local = c_type.gsub(/\*$/,'')
return " UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type_local}), cmock_line#{unity_msg});\n"
when "UNITY_TEST_ASSERT_EQUAL_MEMORY"
[ " if (#{pre}#{expected} == NULL)",
" { UNITY_TEST_ASSERT_NULL(#{pre}#{arg_name}, cmock_line, NULL); }",
@@ -124,8 +124,8 @@ class CMockGeneratorUtils
depth_name = (arg[:ptr?]) ? "cmock_call_instance->Expected_#{arg_name}_Depth" : 1
case(unity_func)
when "UNITY_TEST_ASSERT_EQUAL_MEMORY"
full_expected = (expected =~ /^\*/) ? expected.slice(1..-1) : "(&#{expected})"
return " UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)#{full_expected}, (void*)(&#{arg_name}), sizeof(#{c_type}), cmock_line#{unity_msg});\n"
c_type_local = c_type.gsub(/\*$/,'')
return " UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type_local}), cmock_line#{unity_msg});\n"
when "UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY"
[ " if (#{pre}#{expected} == NULL)",
" { UNITY_TEST_ASSERT_NULL(#{pre}#{arg_name}, cmock_line, NULL); }",
@@ -150,8 +150,8 @@ class CMockGeneratorUtils
depth_name = (arg[:ptr?]) ? "cmock_call_instance->Expected_#{arg_name}_Depth" : 1
case(unity_func)
when "UNITY_TEST_ASSERT_EQUAL_MEMORY"
full_expected = (expected =~ /^\*/) ? expected.slice(1..-1) : "(&#{expected})"
return " UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)#{full_expected}, (void*)(&#{arg_name}), sizeof(#{c_type}), cmock_line#{unity_msg});\n"
c_type_local = c_type.gsub(/\*$/,'')
return " UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type_local}), cmock_line#{unity_msg});\n"
when "UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY"
[ " if (#{pre}#{expected} == NULL)",
" { UNITY_TEST_ASSERT_NULL(#{arg_name}, cmock_line, NULL); }",
+1 -1
View File
@@ -25,7 +25,7 @@ class CMockUnityHelperParser
return [@c_types[lookup], '&'] if (@c_types[lookup])
end
raise("Don't know how to test #{ctype} and memory tests are disabled!") unless @config.memcmp_if_unknown
return [@fallback, '']
return (lookup =~ /\*$/) ? [@fallback, '&'] : [@fallback, '']
end
private ###########################
+10 -8
View File
@@ -176,7 +176,7 @@ module RakefileHelpers
end
def run_system_test_interactions(test_case_files)
require 'cmock'
load 'cmock.rb'
SystemTestGenerator.new.generate_files(test_case_files)
test_files = FileList.new(SYSTEST_GENERATED_FILES_PATH + 'test*.c')
@@ -194,7 +194,7 @@ module RakefileHelpers
test_base = File.basename(test, C_EXTENSION)
cmock_config = test_base.gsub(/test_/, '') + '_cmock.yml'
report "Executing system test cases contained in #{File.basename(test)}..."
report "Executing system tests in #{File.basename(test)}..."
# Detect dependencies and build required required modules
extract_headers(test).each do |header|
@@ -251,18 +251,20 @@ module RakefileHelpers
test_file = 'test_' + File.basename(test_case).ext(C_EXTENSION)
result_file = test_file.ext(RESULT_EXTENSION)
test_results = File.read(SYSTEST_BUILD_FILES_PATH + result_file)
test_results = File.readlines(SYSTEST_BUILD_FILES_PATH + result_file)
tests.each_with_index do |test, index|
# compare test's intended pass/fail state with pass/fail state in actual results;
# if they don't match, the system test has failed
if ((test[:pass] and (test_results =~ /:PASS/).nil?) or (!test[:pass] and (test_results =~ /:FAIL/).nil?))
if ((test[:pass] and (test_results[index] =~ /:PASS/).nil?) or (!test[:pass] and (test_results[index] =~ /:FAIL/).nil?))
total_failures += 1
test_results =~ /test#{index+1}:(.+)/
test_results[index] =~ /test#{index+1}:(.+)/
failure_messages << "#{test_file}:test#{index+1}:should #{test[:should]}:#{$1}"
elsif (test[:verify_error]) and not (test_results =~ /test#{index+1}:.*#{test[:verify_error]}/)
print "FAIL1"
elsif (test[:verify_error]) and not (test_results[index] =~ /test#{index+1}:.*#{test[:verify_error]}/)
total_failures += 1
failure_messages << "#{test_file}:test#{index+1}:should #{test[:should]}:should have output matching '#{test[:verify_error]}'"
print "FAIL2"
end
end
end
@@ -306,7 +308,7 @@ module RakefileHelpers
end
def run_system_test_compilations(mockables)
require 'cmock'
load 'cmock.rb'
load_configuration($cfg_file)
$cfg['compiler']['defines']['items'] = [] if $cfg['compiler']['defines']['items'].nil?
@@ -324,7 +326,7 @@ module RakefileHelpers
end
def run_system_test_profiles(mockables)
require 'cmock'
load 'cmock.rb'
load_configuration($cfg_file)
$cfg['compiler']['defines']['items'] = [] if $cfg['compiler']['defines']['items'].nil?
@@ -292,24 +292,24 @@
}
- :pass: TRUE
:should: 'that we can properly ignore last function but the other will work properly'
:should: 'that we can properly ignore first function but the other will work properly'
:code: |
test()
{
int expect_list[] = { 1, 2, 3, 4, 6 };
mixed_ExpectWithArrayAndReturn(6, expect_list, 4, 7, 13);
no_pointers_Ignore();
mixed_ExpectWithArrayAndReturn(6, expect_list, 4, 7, 13);
TEST_ASSERT_EQUAL(13, function_d());
}
- :pass: TRUE
:should: 'that we can properly ignore first function but the other will work properly'
:should: 'that we can properly ignore last function but the other will work properly'
:code: |
test()
{
mixed_IgnoreAndReturn(13);
no_pointers_Expect(1, "silly");
mixed_IgnoreAndReturn(13);
TEST_ASSERT_EQUAL(13, function_d());
}
@@ -326,7 +326,7 @@
function_e();
}
- :pass: TRUE
- :pass: FALSE
:should: 'that we fail if we do not ignore a call once because we are counting calls'
:code: |
test()
@@ -6,6 +6,8 @@
- :cexception
- :ignore
- :callback
:callback_after_arg_check: true
#:callback_include_count: false
:systest:
:types: |
@@ -67,6 +69,7 @@
#include "CException.h"
void setUp(void) {}
void tearDown(void) {}
void my_foo_callback(POINT_T* a) { TEST_ASSERT_EQUAL_INT(2, a->x); }
:units:
- :pass: TRUE
@@ -321,4 +324,57 @@
function_e();
}
- :pass: TRUE
:should: 'that we can use a callback and an expect'
:code: |
test()
{
POINT_T pt1 = {2, 3};
POINT_T pt2 = {2, 3};
bar_ExpectAndReturn(&pt1);
foo_Expect(&pt2);
foo_StubWithCallback((CMOCK_foo_CALLBACK)my_foo_callback);
function_a();
}
- :pass: FALSE
:should: 'that we can fail even when using a callback if we want to expect call but did not and we are checking that'
:code: |
test()
{
POINT_T pt = {2, 3};
bar_ExpectAndReturn(&pt);
foo_StubWithCallback((CMOCK_foo_CALLBACK)my_foo_callback);
function_a();
}
- :pass: FALSE
:should: 'that we can fail even when using a callback if args are wrong and we are checking those'
:code: |
test()
{
POINT_T pt1 = {2, 3};
POINT_T pt2 = {1, 3};
bar_ExpectAndReturn(&pt1);
foo_Expect(&pt2);
foo_StubWithCallback((CMOCK_foo_CALLBACK)my_foo_callback);
function_a();
}
- :pass: FALSE
:should: 'that we can fail from the callback itself'
:code: |
test()
{
POINT_T pt = {3, 3};
bar_ExpectAndReturn(&pt);
foo_Expect(&pt);
foo_StubWithCallback((CMOCK_foo_CALLBACK)my_foo_callback);
function_a();
}
...
@@ -2,6 +2,8 @@
:cmock:
:plugins:
- :callback
:treat_as:
custom_type: INT
:systest:
:types: |
@@ -23,7 +23,7 @@ class CMockGeneratorPluginCallbackTest < Test::Unit::TestCase
should "have set up internal accessors correctly on init" do
assert_equal(@config, @cmock_generator_plugin_callback.config)
assert_equal(@utils, @cmock_generator_plugin_callback.utils)
assert_equal(3, @cmock_generator_plugin_callback.priority)
assert_equal(6, @cmock_generator_plugin_callback.priority)
end
should "not include any additional include files" do
@@ -122,12 +122,28 @@ class CMockGeneratorPluginIgnoreTest < Test::Unit::TestCase
" Mock.Slime_IgnoreBool = (int)1;\n",
"}\n\n"
].join
@config.expect.ignore.returns(:args_and_calls)
returned = @cmock_generator_plugin_ignore.mock_interfaces(function)
assert_equal(expected, returned)
end
should "add a new mock interface for ignoring when function had no return value and we are checking args only" do
function = {:name => "Slime", :args => [], :args_string => "void", :return => test_return[:void]}
expected = ["void Slime_CMockIgnore(UNITY_LINE_TYPE cmock_line)\n",
"{\n",
"mock_return_1",
" Mock.Slime_IgnoreBool = (int)1;\n",
"}\n\n"
].join
@config.expect.ignore.returns(:args_only)
@utils.expect.code_add_base_expectation("Slime", true).returns("mock_return_1")
returned = @cmock_generator_plugin_ignore.mock_interfaces(function)
assert_equal(expected, returned)
end
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]}
@config.expect.ignore.returns(:args_and_calls)
@utils.expect.code_add_base_expectation("Slime", false).returns("mock_return_1")
expected = ["void Slime_CMockIgnoreAndReturn(UNITY_LINE_TYPE cmock_line, int cmock_to_return)\n",
"{\n",
+2 -2
View File
@@ -200,7 +200,7 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase
function = { :name => 'Pear' }
arg = test_arg[:mytype]
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',''])
@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
@@ -253,7 +253,7 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase
function = { :name => 'Pear' }
arg = test_arg[:mytype]
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',''])
@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
+1 -1
View File
@@ -157,7 +157,7 @@ class CMockUnityHelperParserTest < Test::Unit::TestCase
["UINT32","SPINACH_T","SALAD","PINEAPPLE"].each do |ctype|
@config.expect.memcmp_if_unknown.returns(true)
assert_equal(["UNITY_TEST_ASSERT_EQUAL_MEMORY",''], @parser.get_helper(ctype))
assert_equal(["UNITY_TEST_ASSERT_EQUAL_MEMORY",'&'], @parser.get_helper(ctype))
end
end