mirror of
https://github.com/ThrowTheSwitch/CMock.git
synced 2026-06-06 05:25:29 +00:00
- some cleanup of how to handle default and user defined types before tackling pointers
git-svn-id: http://cmock.svn.sourceforge.net/svnroot/cmock/trunk@62 bf332499-1b4d-0410-844d-d2d48d5cc64c
This commit is contained in:
+43
-12
@@ -1,16 +1,5 @@
|
||||
|
||||
class CMockConfig
|
||||
|
||||
CMockTreatAsDefaults =
|
||||
{
|
||||
'INT' => ['int','char','short','long','int8','int16','int32',
|
||||
'int8_t','int16_t','int32_t', 'bool','bool_t','BOOL','BOOL_T',
|
||||
'INT8','INT16','INT32','INT8_T','INT16_T','INT32_T'],
|
||||
'HEX32' => ['unsigned int', 'unsigned long', 'uint32', 'uint32_t', 'UINT32','UINT32_T'],
|
||||
'HEX16' => ['unsigned short', 'uint16', 'uint16_t', 'UINT16', 'UINT16_T'],
|
||||
'HEX8' => ['unsigned char', 'uint8', 'uint8_t', 'UINT8', 'UINT8_T'],
|
||||
'STRING'=> ['char*', 'pCHAR', 'cstring', 'CSTRING']
|
||||
}
|
||||
|
||||
CMockDefaultOptions =
|
||||
{
|
||||
@@ -24,7 +13,7 @@ class CMockConfig
|
||||
:cexception_include => nil,
|
||||
:cexception_throw_type => 'int',
|
||||
:unity_helper => false,
|
||||
:treat_as => CMockTreatAsDefaults,
|
||||
:treat_as => {},
|
||||
:memcpy_if_unknown => true,
|
||||
:when_ptr_star =>:compare_data,
|
||||
:when_ptr_brackets => :compare_array,
|
||||
@@ -55,4 +44,46 @@ class CMockConfig
|
||||
return File.new(@options[:unity_helper]).read if (@options[:unity_helper])
|
||||
return nil
|
||||
end
|
||||
|
||||
def standard_treat_as_map
|
||||
{
|
||||
'int' => 'INT',
|
||||
'char' => 'INT',
|
||||
'short' => 'INT',
|
||||
'long' => 'INT',
|
||||
'int8' => 'INT',
|
||||
'int16' => 'INT',
|
||||
'int32' => 'INT',
|
||||
'int8_t' => 'INT',
|
||||
'int16_t' => 'INT',
|
||||
'int32_t' => 'INT',
|
||||
'INT8_T' => 'INT',
|
||||
'INT16_T' => 'INT',
|
||||
'INT32_T' => 'INT',
|
||||
'bool' => 'INT',
|
||||
'bool_t' => 'INT',
|
||||
'BOOL' => 'INT',
|
||||
'BOOL_T' => 'INT',
|
||||
'unsigned int' => 'HEX32',
|
||||
'unsigned long' => 'HEX32',
|
||||
'uint32' => 'HEX32',
|
||||
'uint32_t' => 'HEX32',
|
||||
'UINT32' => 'HEX32',
|
||||
'UINT32_T' => 'HEX32',
|
||||
'unsigned short' => 'HEX16',
|
||||
'uint16' => 'HEX16',
|
||||
'uint16_t' => 'HEX16',
|
||||
'UINT16' => 'HEX16',
|
||||
'UINT16_T' => 'HEX16',
|
||||
'unsigned char' => 'HEX8',
|
||||
'uint8' => 'HEX8',
|
||||
'uint8_t' => 'HEX8',
|
||||
'UINT8' => 'HEX8',
|
||||
'UINT8_T' => 'HEX8',
|
||||
'char*' => 'STRING',
|
||||
'pCHAR' => 'STRING',
|
||||
'cstring' => 'STRING',
|
||||
'CSTRING' => 'STRING',
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,11 +4,11 @@ class CMockUnityHelperParser
|
||||
|
||||
def initialize(config)
|
||||
@config = config
|
||||
@c_types = map_C_types(config.treat_as).merge(import_source(config.load_unity_helper))
|
||||
@c_types = map_C_types.merge(import_source)
|
||||
end
|
||||
|
||||
def get_helper(ctype)
|
||||
lookup = ctype.gsub(/const\s+/,'').strip.gsub(/\s+/,'_')#.gsub(/\*$/,'_ARRAY')
|
||||
lookup = ctype.gsub(/const\s+/,'').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.memcpy_if_unknown
|
||||
return 'TEST_ASSERT_EQUAL_MEMORY_MESSAGE'
|
||||
@@ -16,15 +16,18 @@ class CMockUnityHelperParser
|
||||
|
||||
private ###########################
|
||||
|
||||
def map_C_types(treat_as={})
|
||||
def map_C_types
|
||||
c_types = {}
|
||||
treat_as.each_pair do |expect, ctypes|
|
||||
ctypes.each {|ctype| c_types[ctype] = "TEST_ASSERT_EQUAL_#{expect}_MESSAGE"}
|
||||
[@config.standard_treat_as_map, @config.treat_as].each do |pairs|
|
||||
pairs.each_pair do |ctype, expecttype|
|
||||
c_types[ctype.gsub(/\s+/,'_')] = "TEST_ASSERT_EQUAL_#{expecttype}_MESSAGE"
|
||||
end unless pairs.nil?
|
||||
end
|
||||
c_types
|
||||
end
|
||||
|
||||
def import_source(source=nil)
|
||||
def import_source
|
||||
source = @config.load_unity_helper
|
||||
return {} if source.nil?
|
||||
|
||||
c_types = {}
|
||||
|
||||
@@ -15,6 +15,7 @@ class CMockUnityHelperParserTest < Test::Unit::TestCase
|
||||
" abcd;\n" +
|
||||
"// #define TEST_ASSERT_EQUAL_CHICKENS(a,b) {...};\n" +
|
||||
"or maybe // #define TEST_ASSERT_EQUAL_CHICKENS(a,b) {...};\n\n"
|
||||
@config.expects.standard_treat_as_map.returns({})
|
||||
@config.expects.treat_as.returns({})
|
||||
@config.expects.load_unity_helper.returns(source)
|
||||
@parser = CMockUnityHelperParser.new(@config)
|
||||
@@ -28,6 +29,7 @@ class CMockUnityHelperParserTest < Test::Unit::TestCase
|
||||
" abcd; /*\n" +
|
||||
"#define TEST_ASSERT_EQUAL_CHICKENS(a,b) {...};\n" +
|
||||
"#define TEST_ASSERT_EQUAL_CHICKENS(a,b) {...};\n */\n"
|
||||
@config.expects.standard_treat_as_map.returns({})
|
||||
@config.expects.treat_as.returns({})
|
||||
@config.expect.load_unity_helper.returns(source)
|
||||
@parser = CMockUnityHelperParser.new(@config)
|
||||
@@ -45,6 +47,7 @@ class CMockUnityHelperParserTest < Test::Unit::TestCase
|
||||
"#define TEST_ASSERT_WRONG_NAME_EQUAL(a,b) {...};\n" +
|
||||
"#define TEST_ASSERT_EQUAL_unsigned_funky_rabbits(a,b) {...};\n" +
|
||||
"abcd;\n"
|
||||
@config.expects.standard_treat_as_map.returns({})
|
||||
@config.expects.treat_as.returns({})
|
||||
@config.expect.load_unity_helper.returns(source)
|
||||
@parser = CMockUnityHelperParser.new(@config)
|
||||
@@ -65,6 +68,7 @@ class CMockUnityHelperParserTest < Test::Unit::TestCase
|
||||
"#define TEST_ASSERT_WRONG_NAME_EQUAL_ARRAY(a,b,c) {...};\n" +
|
||||
"#define TEST_ASSERT_EQUAL_unsigned_funky_rabbits_ARRAY(a,b,c) {...};\n" +
|
||||
"abcd;\n"
|
||||
@config.expects.standard_treat_as_map.returns({})
|
||||
@config.expects.treat_as.returns({})
|
||||
@config.expect.load_unity_helper.returns(source)
|
||||
@parser = CMockUnityHelperParser.new(@config)
|
||||
@@ -75,8 +79,68 @@ class CMockUnityHelperParserTest < Test::Unit::TestCase
|
||||
|
||||
assert_equal(expected, @parser.c_types)
|
||||
end
|
||||
|
||||
should "pull in the standard set of helpers and add them to my list" do
|
||||
pairs = {
|
||||
"UINT" => "HEX32",
|
||||
"unsigned long" => "HEX64",
|
||||
}
|
||||
expected = {
|
||||
"UINT" => "TEST_ASSERT_EQUAL_HEX32_MESSAGE",
|
||||
"unsigned_long" => "TEST_ASSERT_EQUAL_HEX64_MESSAGE",
|
||||
}
|
||||
@config.expects.standard_treat_as_map.returns(pairs)
|
||||
@config.expects.treat_as.returns({})
|
||||
@config.expect.load_unity_helper.returns(nil)
|
||||
@parser = CMockUnityHelperParser.new(@config)
|
||||
|
||||
assert_equal(expected, @parser.c_types)
|
||||
end
|
||||
|
||||
should "pull in the user specified set of helpers and add them to my list" do
|
||||
pairs = {
|
||||
"char*" => "STRING",
|
||||
"unsigned int" => "HEX32",
|
||||
}
|
||||
expected = {
|
||||
"char*" => "TEST_ASSERT_EQUAL_STRING_MESSAGE",
|
||||
"unsigned_int" => "TEST_ASSERT_EQUAL_HEX32_MESSAGE",
|
||||
}
|
||||
@config.expects.standard_treat_as_map.returns({})
|
||||
@config.expects.treat_as.returns(pairs)
|
||||
@config.expect.load_unity_helper.returns(nil)
|
||||
@parser = CMockUnityHelperParser.new(@config)
|
||||
|
||||
assert_equal(expected, @parser.c_types)
|
||||
end
|
||||
|
||||
should "merge standard and user specified helper into my list" do
|
||||
default = {
|
||||
"UINT" => "HEX32",
|
||||
"unsigned int" => "HEX32",
|
||||
}
|
||||
user = {
|
||||
"int" => "INT",
|
||||
"unsigned char" => "HEX8",
|
||||
}
|
||||
source = "#define TEST_ASSERT_EQUAL_TURKEYS_ARRAY(a,b,c) {...};\n"
|
||||
expected = {
|
||||
"UINT" => "TEST_ASSERT_EQUAL_HEX32_MESSAGE",
|
||||
"unsigned_int" => "TEST_ASSERT_EQUAL_HEX32_MESSAGE",
|
||||
"int" => "TEST_ASSERT_EQUAL_INT_MESSAGE",
|
||||
"unsigned_char" => "TEST_ASSERT_EQUAL_HEX8_MESSAGE",
|
||||
"TURKEYS*" => "TEST_ASSERT_EQUAL_TURKEYS_ARRAY",
|
||||
}
|
||||
@config.expects.standard_treat_as_map.returns(default)
|
||||
@config.expects.treat_as.returns(user)
|
||||
@config.expect.load_unity_helper.returns(source)
|
||||
@parser = CMockUnityHelperParser.new(@config)
|
||||
|
||||
assert_equal(expected, @parser.c_types)
|
||||
end
|
||||
|
||||
should "be able to fetch helpers on my list" do
|
||||
@config.expects.standard_treat_as_map.returns({})
|
||||
@config.expects.treat_as.returns({})
|
||||
@config.expect.load_unity_helper.returns("")
|
||||
@parser = CMockUnityHelperParser.new(@config)
|
||||
@@ -96,8 +160,9 @@ class CMockUnityHelperParserTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
should "return memory comparison when asked to fetch helper of types not on my list" do
|
||||
@config.expects.standard_treat_as_map.returns({})
|
||||
@config.expects.treat_as.returns({})
|
||||
@config.expect.load_unity_helper.returns("")
|
||||
@config.expects.load_unity_helper.returns("")
|
||||
@parser = CMockUnityHelperParser.new(@config)
|
||||
@parser.c_types = {
|
||||
'UINT8' => "TEST_ASSERT_EQUAL_UINT8_MESSAGE",
|
||||
@@ -112,6 +177,7 @@ class CMockUnityHelperParserTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
should "raise error when asked to fetch helper of type not on my list and not allowed to mem check" do
|
||||
@config.expects.standard_treat_as_map.returns({})
|
||||
@config.expects.treat_as.returns({})
|
||||
@config.expect.load_unity_helper.returns("")
|
||||
@config.expect.memcpy_if_unknown.returns(false)
|
||||
|
||||
Reference in New Issue
Block a user