| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper" |
| 9 |
require File.expand_path(File.dirname(__FILE__)) + '/../../lib/cmock_config' |
| 10 |
|
| 11 |
|
| 12 |
describe CMockConfig, "Verify CMockConfig Module" do |
| 13 |
|
| 14 |
it "use default settings when no parameters are specified" do |
| 15 |
config = CMockConfig.new |
| 16 |
assert_equal(CMockConfig::CMOCK_DEFAULT_OPTIONS[:mock_path], config.mock_path) |
| 17 |
assert_nil(CMockConfig::CMOCK_DEFAULT_OPTIONS[:includes]) |
| 18 |
assert_nil(config.includes) |
| 19 |
assert_equal(CMockConfig::CMOCK_DEFAULT_OPTIONS[:attributes], config.attributes) |
| 20 |
assert_equal(CMockConfig::CMOCK_DEFAULT_OPTIONS[:plugins], config.plugins) |
| 21 |
assert_equal(CMockConfig::CMOCK_DEFAULT_OPTIONS[:treat_externs], config.treat_externs) |
| 22 |
assert_equal(CMockConfig::CMOCK_DEFAULT_OPTIONS[:treat_inlines], config.treat_inlines) |
| 23 |
assert_equal(CMockConfig::CMOCK_DEFAULT_OPTIONS[:inline_function_patterns], config.inline_function_patterns) |
| 24 |
end |
| 25 |
|
| 26 |
it "replace only options specified in a hash" do |
| 27 |
test_includes = ['hello'] |
| 28 |
test_attributes = ['blah', 'bleh'] |
| 29 |
config = CMockConfig.new(:includes => test_includes, :attributes => test_attributes) |
| 30 |
assert_equal(CMockConfig::CMOCK_DEFAULT_OPTIONS[:mock_path], config.mock_path) |
| 31 |
assert_equal(test_includes, config.includes) |
| 32 |
assert_equal(test_attributes, config.attributes) |
| 33 |
assert_equal(CMockConfig::CMOCK_DEFAULT_OPTIONS[:plugins], config.plugins) |
| 34 |
assert_equal(CMockConfig::CMOCK_DEFAULT_OPTIONS[:treat_externs], config.treat_externs) |
| 35 |
assert_equal(CMockConfig::CMOCK_DEFAULT_OPTIONS[:treat_inlines], config.treat_inlines) |
| 36 |
assert_equal(CMockConfig::CMOCK_DEFAULT_OPTIONS[:inline_function_patterns], config.inline_function_patterns) |
| 37 |
end |
| 38 |
|
| 39 |
it "replace only options specified in a yaml file" do |
| 40 |
test_plugins = [:soda, :pizza] |
| 41 |
config = CMockConfig.new("#{File.expand_path(File.dirname(__FILE__))}/cmock_config_test.yml") |
| 42 |
assert_equal(CMockConfig::CMOCK_DEFAULT_OPTIONS[:mock_path], config.mock_path) |
| 43 |
assert_nil(CMockConfig::CMOCK_DEFAULT_OPTIONS[:includes]) |
| 44 |
assert_nil(config.includes) |
| 45 |
assert_equal(test_plugins, config.plugins) |
| 46 |
assert_equal(:include, config.treat_externs) |
| 47 |
assert_equal(:include, config.treat_inlines) |
| 48 |
assert_equal(['MY_INLINE_FUNCTION_DECLARATION_PATTERN'], config.inline_function_patterns) |
| 49 |
end |
| 50 |
|
| 51 |
it "populate treat_as map with internal standard_treat_as_map defaults, redefine defaults, and add custom values" do |
| 52 |
|
| 53 |
user_treat_as1 = { |
| 54 |
'BOOL' => 'UINT8', |
| 55 |
'unsigned long' => 'INT', |
| 56 |
'U8' => 'UINT8', |
| 57 |
'U16' => 'UINT16' |
| 58 |
} |
| 59 |
user_treat_as2 = { |
| 60 |
'BOOL' => 'INT16', |
| 61 |
'U16' => 'HEX16' |
| 62 |
} |
| 63 |
|
| 64 |
config1 = CMockConfig.new({:treat_as => user_treat_as1}) |
| 65 |
config2 = CMockConfig.new({:treat_as => user_treat_as2}) |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
assert_equal('INT', config1.treat_as['BOOL_T']) |
| 70 |
assert_equal('HEX32', config1.treat_as['unsigned int']) |
| 71 |
assert_equal('HEX8_ARRAY',config1.treat_as['void*']) |
| 72 |
assert_equal('STRING', config1.treat_as['CSTRING']) |
| 73 |
assert_equal('STRING', config1.treat_as['char*']) |
| 74 |
assert_equal('HEX8', config1.treat_as['unsigned char']) |
| 75 |
assert_equal('INT', config1.treat_as['long']) |
| 76 |
assert_equal('INT16', config1.treat_as['short']) |
| 77 |
|
| 78 |
|
| 79 |
assert_equal('UINT8', config1.treat_as['BOOL']) |
| 80 |
assert_equal('INT', config1.treat_as['unsigned long']) |
| 81 |
|
| 82 |
|
| 83 |
assert_equal('UINT8', config1.treat_as['U8']) |
| 84 |
assert_equal('UINT16', config1.treat_as['U16']) |
| 85 |
|
| 86 |
|
| 87 |
assert_equal('INT', config1.standard_treat_as_map['BOOL']) |
| 88 |
assert_equal('HEX32', config1.standard_treat_as_map['unsigned long']) |
| 89 |
assert_equal('STRING', config1.standard_treat_as_map['char*']) |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
assert_equal('INT', config2.treat_as['BOOL_T']) |
| 94 |
assert_equal('HEX32', config2.treat_as['unsigned int']) |
| 95 |
assert_equal('HEX8_ARRAY',config2.treat_as['void*']) |
| 96 |
assert_equal('STRING', config2.treat_as['CSTRING']) |
| 97 |
assert_equal('STRING', config2.treat_as['char*']) |
| 98 |
assert_equal('HEX8', config2.treat_as['unsigned char']) |
| 99 |
assert_equal('INT', config2.treat_as['long']) |
| 100 |
assert_equal('INT16', config2.treat_as['short']) |
| 101 |
assert_equal('HEX32', config2.treat_as['unsigned long']) |
| 102 |
|
| 103 |
|
| 104 |
assert_equal('INT16', config2.treat_as['BOOL']) |
| 105 |
|
| 106 |
|
| 107 |
assert_equal('HEX16', config2.treat_as['U16']) |
| 108 |
|
| 109 |
|
| 110 |
assert_equal('INT', config2.standard_treat_as_map['BOOL']) |
| 111 |
assert_equal('HEX32', config2.standard_treat_as_map['unsigned long']) |
| 112 |
assert_equal('STRING', config2.standard_treat_as_map['char*']) |
| 113 |
end |
| 114 |
|
| 115 |
it "standard treat_as map should be incorruptable" do |
| 116 |
config = CMockConfig.new({}) |
| 117 |
|
| 118 |
assert_equal('INT', config.standard_treat_as_map['BOOL_T']) |
| 119 |
|
| 120 |
local = config.standard_treat_as_map |
| 121 |
local['BOOL_T'] = "U8" |
| 122 |
|
| 123 |
assert_equal('INT', config.standard_treat_as_map['BOOL_T']) |
| 124 |
end |
| 125 |
|
| 126 |
end |