- multi-dimensional arrays now get pointer comparisons (which is better than crashing, right?)

- the pointer size can now be specified (particularly for systems which need 64 bit pointers)
- removed a redundant parsing step

git-svn-id: http://cmock.svn.sourceforge.net/svnroot/cmock/trunk@180 bf332499-1b4d-0410-844d-d2d48d5cc64c
This commit is contained in:
mvandervoord
2010-07-20 02:28:48 +00:00
parent 840e38998b
commit 35c59f1c38
5 changed files with 71 additions and 9 deletions
+1
View File
@@ -19,6 +19,7 @@ class CMockConfig
:treat_as => {},
:treat_as_void => [],
:memcmp_if_unknown => true,
:ptr_size => 32,
:when_no_prototypes => :warn, #the options being :ignore, :warn, or :error
:when_ptr => :compare_data, #the options being :compare_ptr, :compare_data, or :smart
:verbosity => 2, #the options being 0 errors only, 1 warnings and errors, 2 normal info, 3 verbose
+9 -8
View File
@@ -11,10 +11,11 @@ class CMockGeneratorUtils
def initialize(config, helpers={})
@config = config
@ptr_handling = @config.when_ptr
@ordered = @config.enforce_strict_ordering
@arrays = @config.plugins.include? :array
@cexception = @config.plugins.include? :cexception
@treat_as = @config.treat_as
@ordered = @config.enforce_strict_ordering
@arrays = @config.plugins.include? :array
@cexception = @config.plugins.include? :cexception
@treat_as = @config.treat_as
@ptr_compare_assert = "UNITY_TEST_ASSERT_EQUAL_HEX#{@config.ptr_size.to_s}"
@helpers = helpers
if (@arrays)
@@ -89,8 +90,8 @@ class CMockGeneratorUtils
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))
["UNITY_TEST_ASSERT_EQUAL_HEX32", '']
unity_func = if ((arg[:ptr?]) and ((c_type =~ /\*\*/) or (@ptr_handling == :compare_ptr)))
[@ptr_compare_assert, '']
else
(@helpers.nil? or @helpers[:unity_helper].nil?) ? ["UNITY_TEST_ASSERT_EQUAL",''] : @helpers[:unity_helper].get_helper(c_type)
end
@@ -155,7 +156,7 @@ class CMockGeneratorUtils
when "UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY"
[ " if (#{pre}#{expected} == NULL)",
" { UNITY_TEST_ASSERT_NULL(#{arg_name}, cmock_line, \"Expected NULL. #{unity_msg}\"); }",
((depth_name != 1) ? " else if (#{depth_name} == 0)\n { UNITY_TEST_ASSERT_EQUAL_HEX32(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line, \"#{unity_msg}\"); }" : nil),
((depth_name != 1) ? " else if (#{depth_name} == 0)\n { #{@ptr_compare_assert}(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line, \"#{unity_msg}\"); }" : nil),
" else",
" { UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type.sub('*','')}), #{depth_name}, cmock_line, \"#{unity_msg}\"); }\n"].compact.join("\n")
when /_ARRAY/
@@ -164,7 +165,7 @@ class CMockGeneratorUtils
else
[ " if (#{pre}#{expected} == NULL)",
" { UNITY_TEST_ASSERT_NULL(#{pre}#{arg_name}, cmock_line, \"Expected NULL. #{unity_msg}\"); }",
((depth_name != 1) ? " else if (#{depth_name} == 0)\n { UNITY_TEST_ASSERT_EQUAL_HEX32(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line, \"#{unity_msg}\"); }" : nil),
((depth_name != 1) ? " else if (#{depth_name} == 0)\n { #{@ptr_compare_assert}(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line, \"#{unity_msg}\"); }" : nil),
" else",
" { #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, #{depth_name}, cmock_line, \"#{unity_msg}\"); }\n"].compact.join("\n")
end
-1
View File
@@ -213,7 +213,6 @@ class CMockHeaderParser
}
#remove default argument statements from mock definitions
args.gsub!(/=\s*[a-zA-Z0-9_\.]+\s*\,/, ',')
args.gsub!(/=\s*[a-zA-Z0-9_\.]+\s*/, ' ')
#check for var args
@@ -0,0 +1,59 @@
---
#The purpose of this test is to play with our really rough multidimensional array support, which involves an implicit cast not supported everywhere
:cmock:
:plugins:
- :array
:systest:
:types: |
:mockable: |
void foo(unsigned char** a);
unsigned char** bar(void);
:source:
:header: |
void function_a(void);
:code: |
void function_a(void) {
foo(bar());
}
:tests:
:common: |
void setUp(void) {}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: 'handle two dimensional array of unsigned characters just like we would handle a single dimensional array in expect (where we really only care about first element)'
:code: |
test()
{
unsigned char a[] = { 1, 2, 3, 4, 5, 6 };
unsigned char** pa = (unsigned char**)(&a);
bar_ExpectAndReturn(pa);
foo_Expect(pa);
function_a();
}
- :pass: FALSE
:should: 'handle two dimensional array of unsigned characters just like we would handle a single dimensional array in expect as failures (where we really only care about first element)'
:code: |
test()
{
unsigned char a[] = { 1, 2, 3, 4, 5, 6 };
unsigned char b[] = { 5, 6, 7, 8, 9, 0 };
unsigned char** pa = (unsigned char**)(&a);
unsigned char** pb = (unsigned char**)(&b);
bar_ExpectAndReturn(pa);
foo_Expect(pb);
function_a();
}
...
+2
View File
@@ -16,6 +16,7 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase
@config.expect.plugins.returns([])
@config.expect.plugins.returns([])
@config.expect.treat_as.returns(['int','short','long','char','char*'])
@config.expect.ptr_size.returns(32)
@cmock_generator_utils_simple = CMockGeneratorUtils.new(@config, {:unity_helper => @unity_helper})
@config.expect.when_ptr.returns(:smart)
@@ -23,6 +24,7 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase
@config.expect.plugins.returns([:array, :cexception])
@config.expect.plugins.returns([:array, :cexception])
@config.expect.treat_as.returns(['int','short','long','char','uint32_t','char*'])
@config.expect.ptr_size.returns(32)
@cmock_generator_utils_complex = CMockGeneratorUtils.new(@config, {:unity_helper => @unity_helper, :A=>1, :B=>2})
end