diff --git a/lib/cmock_config.rb b/lib/cmock_config.rb index 21d7f50..866b6e0 100644 --- a/lib/cmock_config.rb +++ b/lib/cmock_config.rb @@ -60,7 +60,7 @@ class CMockConfig options[:plugins].map! {|p| p.to_sym} @options = options - treat_as_map = standard_treat_as_map().clone + treat_as_map = standard_treat_as_map()#.clone treat_as_map.merge!(@options[:treat_as]) @options[:treat_as] = treat_as_map diff --git a/lib/cmock_unityhelper_parser.rb b/lib/cmock_unityhelper_parser.rb index 3ddffb3..c22db7a 100644 --- a/lib/cmock_unityhelper_parser.rb +++ b/lib/cmock_unityhelper_parser.rb @@ -34,11 +34,12 @@ class CMockUnityHelperParser def map_C_types c_types = {} @config.treat_as.each_pair do |ctype, expecttype| + c_type = ctype.gsub(/\s+/,'_') if (expecttype =~ /\*/) - c_types[ctype.gsub(/\s+/,'_')] = "UNITY_TEST_ASSERT_EQUAL_#{expecttype.gsub(/\*/,'')}_ARRAY" + c_types[c_type] = "UNITY_TEST_ASSERT_EQUAL_#{expecttype.gsub(/\*/,'')}_ARRAY" else - c_types[ctype.gsub(/\s+/,'_')] = "UNITY_TEST_ASSERT_EQUAL_#{expecttype}" - c_types[ctype.gsub(/\s+/,'_')+'*'] = "UNITY_TEST_ASSERT_EQUAL_#{expecttype}_ARRAY" + c_types[c_type] = "UNITY_TEST_ASSERT_EQUAL_#{expecttype}" + c_types[c_type+'*'] ||= "UNITY_TEST_ASSERT_EQUAL_#{expecttype}_ARRAY" end end c_types diff --git a/test/system/test_compilation/callingconv.h b/test/system/test_compilation/callingconv.h index a8209af..49c524d 100644 --- a/test/system/test_compilation/callingconv.h +++ b/test/system/test_compilation/callingconv.h @@ -4,4 +4,8 @@ [Released under MIT License. Please refer to license.txt for details] ========================================== */ +#ifndef WIN32 +#define __stdcall +#endif + int __stdcall this_uses_calling_conventions(int b); diff --git a/test/system/test_interactions/all_plugins_but_other_limits.yml b/test/system/test_interactions/all_plugins_but_other_limits.yml index be6df13..bec1a1d 100644 --- a/test/system/test_interactions/all_plugins_but_other_limits.yml +++ b/test/system/test_interactions/all_plugins_but_other_limits.yml @@ -187,7 +187,7 @@ } - :pass: TRUE - :should: 'handle standard c string as null terminated on not do crappy memory compares of a byte, passing' + :should: 'handle standard c string as null terminated and not do crappy memory compares of a byte, passing' :code: | test() { @@ -198,7 +198,7 @@ } - :pass: FALSE - :should: 'handle standard c string as null terminated on not do crappy memory compares of a byte, finding failures' + :should: 'handle standard c string as null terminated and not do crappy memory compares of a byte, finding failures' :code: | test() { diff --git a/test/unit/cmock_config_test.rb b/test/unit/cmock_config_test.rb index 5bf988e..28f8ce8 100644 --- a/test/unit/cmock_config_test.rb +++ b/test/unit/cmock_config_test.rb @@ -1,80 +1 @@ -# ========================================== -# CMock Project - Automatic Mock Generation for C -# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams -# [Released under MIT License. Please refer to license.txt for details] -# ========================================== - -require File.expand_path(File.dirname(__FILE__)) + "/../test_helper" -require 'cmock_config' - -class CMockConfigTest < Test::Unit::TestCase - def setup - end - - def teardown - end - - should "use default settings when no parameters are specified" do - config = CMockConfig.new - assert_equal(CMockConfig::CMockDefaultOptions[:mock_path], config.mock_path) - assert_equal(CMockConfig::CMockDefaultOptions[:includes], config.includes) - assert_equal(CMockConfig::CMockDefaultOptions[:attributes], config.attributes) - assert_equal(CMockConfig::CMockDefaultOptions[:plugins], config.plugins) - assert_equal(CMockConfig::CMockDefaultOptions[:treat_externs], config.treat_externs) - end - - should "replace only options specified in a hash" do - test_includes = ['hello'] - test_attributes = ['blah', 'bleh'] - config = CMockConfig.new(:includes => test_includes, :attributes => test_attributes) - assert_equal(CMockConfig::CMockDefaultOptions[:mock_path], config.mock_path) - assert_equal(test_includes, config.includes) - assert_equal(test_attributes, config.attributes) - assert_equal(CMockConfig::CMockDefaultOptions[:plugins], config.plugins) - assert_equal(CMockConfig::CMockDefaultOptions[:treat_externs], config.treat_externs) - end - - should "replace only options specified in a yaml file" do - test_plugins = [:soda, :pizza] - config = CMockConfig.new("#{File.expand_path(File.dirname(__FILE__))}/cmock_config_test.yml") - assert_equal(CMockConfig::CMockDefaultOptions[:mock_path], config.mock_path) - assert_equal(CMockConfig::CMockDefaultOptions[:includes], config.includes) - assert_equal(test_plugins, config.plugins) - assert_equal(:include, config.treat_externs) - end - - should "populate treat_as map with internal standard_treat_as_map defaults, redefine defaults, and add custom values" do - user_treat_as = { - 'BOOL' => 'UINT8', # redefine standard default - 'unsigned long' => 'INT', # redefine standard default - 'U8' => 'UINT8', # custom value - 'U16' => 'UINT16' # custom value - } - - config = CMockConfig.new({:treat_as => user_treat_as}) - - # standard defaults - assert_equal('INT', config.treat_as['BOOL_T']) - assert_equal('HEX32', config.treat_as['unsigned int']) - assert_equal('PTR', config.treat_as['void*']) - assert_equal('STRING', config.treat_as['CSTRING']) - assert_equal('STRING', config.treat_as['char*']) - assert_equal('HEX8', config.treat_as['unsigned char']) - assert_equal('INT', config.treat_as['long']) - assert_equal('INT16', config.treat_as['short']) - - # overrides - assert_equal('UINT8', config.treat_as['BOOL']) - assert_equal('INT', config.treat_as['unsigned long']) - - # added custom values - assert_equal('UINT8', config.treat_as['U8']) - assert_equal('UINT16', config.treat_as['U16']) - - # standard_treat_as_map: unchanged - assert_equal('INT', config.standard_treat_as_map['BOOL']) - assert_equal('HEX32', config.standard_treat_as_map['unsigned long']) - assert_equal('STRING', config.standard_treat_as_map['char*']) - end - -end +# ========================================== # CMock Project - Automatic Mock Generation for C # Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams # [Released under MIT License. Please refer to license.txt for details] # ========================================== require File.expand_path(File.dirname(__FILE__)) + "/../test_helper" require 'cmock_config' class CMockConfigTest < Test::Unit::TestCase def setup end def teardown end should "use default settings when no parameters are specified" do config = CMockConfig.new assert_equal(CMockConfig::CMockDefaultOptions[:mock_path], config.mock_path) assert_equal(CMockConfig::CMockDefaultOptions[:includes], config.includes) assert_equal(CMockConfig::CMockDefaultOptions[:attributes], config.attributes) assert_equal(CMockConfig::CMockDefaultOptions[:plugins], config.plugins) assert_equal(CMockConfig::CMockDefaultOptions[:treat_externs], config.treat_externs) end should "replace only options specified in a hash" do test_includes = ['hello'] test_attributes = ['blah', 'bleh'] config = CMockConfig.new(:includes => test_includes, :attributes => test_attributes) assert_equal(CMockConfig::CMockDefaultOptions[:mock_path], config.mock_path) assert_equal(test_includes, config.includes) assert_equal(test_attributes, config.attributes) assert_equal(CMockConfig::CMockDefaultOptions[:plugins], config.plugins) assert_equal(CMockConfig::CMockDefaultOptions[:treat_externs], config.treat_externs) end should "replace only options specified in a yaml file" do test_plugins = [:soda, :pizza] config = CMockConfig.new("#{File.expand_path(File.dirname(__FILE__))}/cmock_config_test.yml") assert_equal(CMockConfig::CMockDefaultOptions[:mock_path], config.mock_path) assert_equal(CMockConfig::CMockDefaultOptions[:includes], config.includes) assert_equal(test_plugins, config.plugins) assert_equal(:include, config.treat_externs) end should "populate treat_as map with internal standard_treat_as_map defaults, redefine defaults, and add custom values" do user_treat_as1 = { 'BOOL' => 'UINT8', # redefine standard default 'unsigned long' => 'INT', # redefine standard default 'U8' => 'UINT8', # custom value 'U16' => 'UINT16' # custom value } user_treat_as2 = { 'BOOL' => 'INT16', # redefine standard default 'U16' => 'HEX16' # custom value } config1 = CMockConfig.new({:treat_as => user_treat_as1}) config2 = CMockConfig.new({:treat_as => user_treat_as2}) # ----- USER SET 1 # standard defaults assert_equal('INT', config1.treat_as['BOOL_T']) assert_equal('HEX32', config1.treat_as['unsigned int']) assert_equal('PTR', config1.treat_as['void*']) assert_equal('STRING', config1.treat_as['CSTRING']) assert_equal('STRING', config1.treat_as['char*']) assert_equal('HEX8', config1.treat_as['unsigned char']) assert_equal('INT', config1.treat_as['long']) assert_equal('INT16', config1.treat_as['short']) # overrides assert_equal('UINT8', config1.treat_as['BOOL']) assert_equal('INT', config1.treat_as['unsigned long']) # added custom values assert_equal('UINT8', config1.treat_as['U8']) assert_equal('UINT16', config1.treat_as['U16']) # standard_treat_as_map: unchanged assert_equal('INT', config1.standard_treat_as_map['BOOL']) assert_equal('HEX32', config1.standard_treat_as_map['unsigned long']) assert_equal('STRING', config1.standard_treat_as_map['char*']) # ----- USER SET 2 # standard defaults assert_equal('INT', config2.treat_as['BOOL_T']) assert_equal('HEX32', config2.treat_as['unsigned int']) assert_equal('PTR', config2.treat_as['void*']) assert_equal('STRING', config2.treat_as['CSTRING']) assert_equal('STRING', config2.treat_as['char*']) assert_equal('HEX8', config2.treat_as['unsigned char']) assert_equal('INT', config2.treat_as['long']) assert_equal('INT16', config2.treat_as['short']) assert_equal('HEX32', config2.treat_as['unsigned long']) # overrides assert_equal('INT16', config2.treat_as['BOOL']) # added custom values assert_equal('HEX16', config2.treat_as['U16']) # standard_treat_as_map: unchanged assert_equal('INT', config2.standard_treat_as_map['BOOL']) assert_equal('HEX32', config2.standard_treat_as_map['unsigned long']) assert_equal('STRING', config2.standard_treat_as_map['char*']) end def "standard treat_as map should be incorruptable" do config = CMockConfig.new({}) assert_equal('INT', config.standard_treat_as_map['BOOL_T']) local = config.standard_treat_as_map local['BOOL_T'] = "U8" assert_equal('INT', config.standard_treat_as_map['BOOL_T']) end end \ No newline at end of file