merge in small fix to avoid renaming problems

This commit is contained in:
Mark VanderVoord
2013-09-22 12:28:41 -04:00
parent 7c35571599
commit 342e1d7cce
+24 -24
View File
@@ -2,14 +2,14 @@
# 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]
# ==========================================
# ==========================================
$here = File.dirname __FILE__
class CMockGenerator
attr_accessor :config, :file_writer, :module_name, :clean_mock_name, :mock_name, :utils, :plugins, :ordered
def initialize(config, file_writer, utils, plugins)
@file_writer = file_writer
@utils = utils
@@ -18,7 +18,7 @@ class CMockGenerator
@prefix = @config.mock_prefix
@ordered = @config.enforce_strict_ordering
@framework = @config.framework.to_s
@includes_h_pre_orig_header = (@config.includes || @config.includes_h_pre_orig_header || []).map{|h| h =~ /</ ? h : "\"#{h}\""}
@includes_h_post_orig_header = (@config.includes_h_post_orig_header || []).map{|h| h =~ /</ ? h : "\"#{h}\""}
@includes_c_pre_header = (@config.includes_c_pre_header || []).map{|h| h =~ /</ ? h : "\"#{h}\""}
@@ -32,9 +32,9 @@ class CMockGenerator
create_mock_header_file(parsed_stuff)
create_mock_source_file(parsed_stuff)
end
private if $ThisIsOnlyATest.nil? ##############################
def create_mock_header_file(parsed_stuff)
@file_writer.create_file(@mock_name + ".h") do |file, filename|
create_mock_header_header(file, filename)
@@ -61,28 +61,28 @@ class CMockGenerator
end
end
end
def create_mock_header_header(file, filename)
def create_mock_header_header(file, filename)
define_name = @clean_mock_name.gsub(/\.h/, "_h").upcase
orig_filename = filename.gsub(@config.mock_prefix, "")
orig_filename = filename[@config.mock_prefix.size..-1]
file << "/* AUTOGENERATED FILE. DO NOT EDIT. */\n"
file << "#ifndef _#{define_name}_H\n"
file << "#define _#{define_name}_H\n\n"
@includes_h_pre_orig_header.each {|inc| file << "#include #{inc}\n"}
@includes_h_pre_orig_header.each {|inc| file << "#include #{inc}\n"}
file << "#include \"#{orig_filename}\"\n"
@includes_h_post_orig_header.each {|inc| file << "#include #{inc}\n"}
plugin_includes = @plugins.run(:include_files)
file << plugin_includes if (!plugin_includes.empty?)
file << "\n"
end
def create_typedefs(file, typedefs)
file << "\n"
typedefs.each {|typedef| file << "#{typedef}\n" }
file << "\n\n"
end
def create_mock_header_service_call_declarations(file)
def create_mock_header_service_call_declarations(file)
file << "void #{@clean_mock_name}_Init(void);\n"
file << "void #{@clean_mock_name}_Destroy(void);\n"
file << "void #{@clean_mock_name}_Verify(void);\n\n"
@@ -91,7 +91,7 @@ class CMockGenerator
def create_mock_header_footer(header)
header << "\n#endif\n"
end
def create_source_header_section(file, filename)
header_file = filename.gsub(".c",".h")
file << "/* AUTOGENERATED FILE. DO NOT EDIT. */\n"
@@ -105,9 +105,9 @@ class CMockGenerator
@includes_c_post_header.each {|inc| file << "#include #{inc}\n"}
file << "\n"
end
def create_instance_structure(file, functions)
functions.each do |function|
functions.each do |function|
file << "typedef struct _CMOCK_#{function[:name]}_CALL_INSTANCE\n{\n"
file << " UNITY_LINE_TYPE LineNumber;\n"
file << @plugins.run(:instance_typedefs, function)
@@ -123,7 +123,7 @@ class CMockGenerator
end
file << "} Mock;\n\n"
end
def create_extern_declarations(file)
file << "extern jmp_buf AbortFrame;\n"
if (@ordered)
@@ -132,7 +132,7 @@ class CMockGenerator
end
file << "\n"
end
def create_mock_verify_function(file, functions)
file << "void #{@clean_mock_name}_Verify(void)\n{\n"
verifications = functions.collect {|function| @plugins.run(:mock_verify, function)}.join
@@ -140,13 +140,13 @@ class CMockGenerator
file << verifications
file << "}\n\n"
end
def create_mock_init_function(file)
file << "void #{@clean_mock_name}_Init(void)\n{\n"
file << " #{@clean_mock_name}_Destroy();\n"
file << "}\n\n"
end
def create_mock_destroy_function(file, functions)
file << "void #{@clean_mock_name}_Destroy(void)\n{\n"
file << " CMock_Guts_MemFreeAll();\n"
@@ -158,15 +158,15 @@ class CMockGenerator
end
file << "}\n\n"
end
def create_mock_implementation(file, function)
# prepare return value and arguments
def create_mock_implementation(file, function)
# prepare return value and arguments
function_mod_and_rettype = (function[:modifier].empty? ? '' : "#{function[:modifier]} ") +
(function[:return][:type]) +
(function[:c_calling_convention] ? " #{function[:c_calling_convention]}" : '')
args_string = function[:args_string]
args_string += (", " + function[:var_arg]) unless (function[:var_arg].nil?)
# Create mock function
file << "#{function_mod_and_rettype} #{function[:name]}(#{args_string})\n"
file << "{\n"
@@ -184,10 +184,10 @@ class CMockGenerator
# file << " UNITY_TEST_ASSERT((cmock_call_instance->CallOrder == ++GlobalVerifyOrder), cmock_line, \"Out of order function calls. Function '#{function[:name]}'\");\n"
end
file << @plugins.run(:mock_implementation, function)
file << " return cmock_call_instance->ReturnVal;\n" unless (function[:return][:void?])
file << " return cmock_call_instance->ReturnVal;\n" unless (function[:return][:void?])
file << "}\n\n"
end
def create_mock_interfaces(file, function)
file << @utils.code_add_argument_loader(function)
file << @plugins.run(:mock_interfaces, function)