class CMockConfig

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]

Constants

CMOCK_DEFAULT_OPTIONS

Public Class Methods

load_config_file_from_yaml(yaml_filename) click to toggle source
# File vendor/cmock/lib/cmock_config.rb, line 108
def self.load_config_file_from_yaml(yaml_filename)
  require 'yaml'
  require 'fileutils'
  YAML.load_file(yaml_filename)[:cmock]
end
new(options = nil) click to toggle source
# File vendor/cmock/lib/cmock_config.rb, line 56
def initialize(options = nil)
  case options
  when NilClass then options = CMOCK_DEFAULT_OPTIONS.dup
  when String   then options = CMOCK_DEFAULT_OPTIONS.dup.merge(load_config_file_from_yaml(options))
  when Hash     then options = CMOCK_DEFAULT_OPTIONS.dup.merge(options)
  else raise 'If you specify arguments, it should be a filename or a hash of options'
  end

  # do some quick type verification
  %i[plugins attributes treat_as_void].each do |opt|
    unless options[opt].class == Array
      options[opt] = []
      puts "WARNING: :#{opt} should be an array." unless options[:verbosity] < 1
    end
  end
  %i[includes includes_h_pre_orig_header includes_h_post_orig_header includes_c_pre_header includes_c_post_header].each do |opt|
    unless options[opt].nil? || (options[opt].class == Array)
      options[opt] = []
      puts "WARNING: :#{opt} should be an array." unless options[:verbosity] < 1
    end
  end
  options[:unity_helper_path] ||= options[:unity_helper]
  options[:unity_helper_path] = [options[:unity_helper_path]] if options[:unity_helper_path].is_a? String

  if options[:unity_helper_path]
    require 'pathname'
    includes1 = options[:includes_c_post_header] || []
    includes2 = options[:unity_helper_path].map do |path|
      Pathname(path).relative_path_from(Pathname(options[:mock_path])).to_s
    end
    options[:includes_c_post_header] = (includes1 + includes2).uniq
  end

  options[:plugins].compact!
  options[:plugins].map!(&:to_sym)
  @options = options

  treat_as_map = standard_treat_as_map # .clone
  treat_as_map.merge!(@options[:treat_as])
  @options[:treat_as] = treat_as_map

  @options.each_key do |key|
    unless methods.include?(key)
      eval("def #{key}() return @options[:#{key}] end")
    end
  end
end

Public Instance Methods

load_config_file_from_yaml(yaml_filename) click to toggle source
# File vendor/cmock/lib/cmock_config.rb, line 104
def load_config_file_from_yaml(yaml_filename)
  self.class.load_config_file_from_yaml yaml_filename
end
load_unity_helper() click to toggle source
# File vendor/cmock/lib/cmock_config.rb, line 118
def load_unity_helper
  return nil unless @options[:unity_helper_path]

  @options[:unity_helper_path].inject('') do |unity_helper, filename|
    unity_helper + "\n" + File.new(filename).read
  end
end
path(new_path) click to toggle source
# File vendor/cmock/lib/cmock_config.rb, line 114
def path(new_path)
  @src_path = new_path
end
standard_treat_as_map() click to toggle source
# File vendor/cmock/lib/cmock_config.rb, line 126
def standard_treat_as_map
  {
    'int'             => 'INT',
    'char'            => 'INT8',
    'short'           => 'INT16',
    'long'            => 'INT',
    'int8'            => 'INT8',
    'int16'           => 'INT16',
    'int32'           => 'INT',
    'int8_t'          => 'INT8',
    'int16_t'         => 'INT16',
    'int32_t'         => 'INT',
    'INT8_T'          => 'INT8',
    'INT16_T'         => 'INT16',
    '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',
    'void*'           => 'HEX8_ARRAY',
    'void const*'     => 'HEX8_ARRAY',
    'const void*'     => 'HEX8_ARRAY',
    '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',
    'char const*'     => 'STRING',
    'const char*'     => 'STRING',
    'pCHAR'           => 'STRING',
    'cstring'         => 'STRING',
    'CSTRING'         => 'STRING',
    'float'           => 'FLOAT',
    'double'          => 'FLOAT'
  }
end