main object is now CMock instead of CMockSetup. Cleaned up the way objects are created, particularly related to plugins.

git-svn-id: http://cmock.svn.sourceforge.net/svnroot/cmock/trunk@19 bf332499-1b4d-0410-844d-d2d48d5cc64c
This commit is contained in:
mvandervoord
2008-07-19 15:42:56 +00:00
parent 8329466dee
commit 56d13b90f6
4 changed files with 63 additions and 54 deletions
+40 -2
View File
@@ -1,4 +1,42 @@
$here = File.dirname __FILE__
require "#{$here}/cmock_setup"
require "#{$here}/cmock_generator"
require "#{$here}/cmock_header_parser"
require "#{$here}/cmock_generator"
require "#{$here}/cmock_file_writer"
require "#{$here}/cmock_config"
require "#{$here}/cmock_plugin_manager"
require "#{$here}/cmock_generator_utils"
class CMock
def initialize(mocks_path='mocks', includes=[], use_cexception=true, allow_ignore_mock=false)
@mocks_path = mocks_path
@includes = includes
@use_cexception = use_cexception
@allow_ignore_mock = allow_ignore_mock
end
def setup_mocks(files)
files.each do |src|
generate_mock src
end
end
private ###############################
def generate_mock(src)
name = File.basename(src, '.h')
path = File.dirname(src)
cm_config = CMockConfig.new(path, @mocks_path, @includes, @use_cexception, @allow_ignore_mock)
cm_parser = CMockHeaderParser.new(File.read(src))
cm_writer = CMockFileWriter.new(cm_config)
cm_gen_utils = CMockGeneratorUtils.new(cm_config)
cm_gen_plugins = CMockPluginManager.new(cm_config, cm_gen_utils).get_generator_plugins
cm_generator = CMockGenerator.new(cm_config, name, cm_writer, cm_gen_utils, cm_gen_plugins)
puts "Creating mock for #{name}..."
parsed_stuff = cm_parser.parse
cm_generator.create_mock(parsed_stuff)
end
end
+3 -12
View File
@@ -1,24 +1,15 @@
$here = File.dirname __FILE__
require "#{$here}/cmock_generator_utils.rb"
require "#{$here}/cmock_generator_plugin_ignore.rb"
require "#{$here}/cmock_generator_plugin_cexception.rb"
class CMockGenerator
attr_accessor :module_name
def initialize(config, module_name, file_writer)
def initialize(config, module_name, file_writer, utils, plugins=[])
@config = config
@file_writer = file_writer
@tab = @config.tab
@module_name = module_name
@mock_name = "Mock" + @module_name
@utils = CMockGeneratorUtils.new( @config )
@plugins = []
@plugins << CMockGeneratorPluginCException.new( @config, @utils ) if @config.use_cexception
@plugins << CMockGeneratorPluginIgnore.new( @config, @utils ) if @config.allow_ignore_mock
@utils = utils
@plugins = plugins
end
def create_mock(parsed_stuff)
+20
View File
@@ -0,0 +1,20 @@
require "#{$here}/cmock_generator_plugin_ignore.rb"
require "#{$here}/cmock_generator_plugin_cexception.rb"
class CMockPluginManager
def initialize(config, utils)
@config = config
@utils = utils
end
def get_generator_plugins
@plugins = []
@plugins << CMockGeneratorPluginCException.new( @config, @utils ) if @config.use_cexception
@plugins << CMockGeneratorPluginIgnore.new( @config, @utils ) if @config.allow_ignore_mock
return @plugins
end
end
#!!!!!!!!!!!!!!!!!!!!!!!!! eventually I plan to scan a plugin directory to pull in all this stuff, and maybe check the yaml file after that to see what is currently allowed. that sounds swank, no?
-40
View File
@@ -1,40 +0,0 @@
$here = File.dirname __FILE__
require "#{$here}/cmock_header_parser"
require "#{$here}/cmock_generator"
require "#{$here}/cmock_file_writer"
require "#{$here}/cmock_config"
class CMockSetup
attr_accessor :mocks_path, :auto_path
def initialize(mocks_path='mocks', includes=[], use_cexception=true, allow_ignore_mock=false)
@mocks_path = mocks_path
@includes = includes
@use_cexception = use_cexception
@allow_ignore_mock = allow_ignore_mock
end
def setup_mocks(files)
files.each do |src|
generate_mock src
end
end
private
def generate_mock(src)
name = File.basename(src, '.h')
path = File.dirname(src)
cmc = CMockConfig.new(path, @mocks_path, @includes, @use_cexception, @allow_ignore_mock)
cmp = CMockHeaderParser.new(File.read(src))
cmf = CMockFileWriter.new(cmc)
cmg = CMockGenerator.new(cmc, name, cmf)
puts "Creating mock for #{name}..."
parsed_stuff = cmp.parse
cmg.create_mock(parsed_stuff)
end
end