- removed configurable tabs because they aren't valuable compared to their hit on performance

* WARNING: This change will very likely break your calling of generate_version_runner in unity *

git-svn-id: http://cmock.svn.sourceforge.net/svnroot/cmock/trunk@138 bf332499-1b4d-0410-844d-d2d48d5cc64c
This commit is contained in:
mvandervoord
2009-06-25 19:24:40 +00:00
parent f1ee6295d3
commit c9fdbe29fd
14 changed files with 188 additions and 216 deletions
-1
View File
@@ -8,7 +8,6 @@ class CMockConfig
:plugins => ['cexception', 'ignore'], :plugins => ['cexception', 'ignore'],
:includes => [], :includes => [],
:attributes => ['__ramfunc', '__irq', '__fiq'], :attributes => ['__ramfunc', '__irq', '__fiq'],
:tab => ' ',
:expect_call_count_type => 'unsigned short', :expect_call_count_type => 'unsigned short',
:enforce_strict_ordering => false, :enforce_strict_ordering => false,
:ignore_bool_type => 'unsigned char', :ignore_bool_type => 'unsigned char',
+18 -19
View File
@@ -2,7 +2,7 @@ $here = File.dirname __FILE__
class CMockGenerator class CMockGenerator
attr_reader :config, :file_writer, :tab, :module_name, :mock_name, :utils, :plugins attr_reader :config, :file_writer, :module_name, :mock_name, :utils, :plugins
def initialize(config, module_name, file_writer, utils, plugins=[]) def initialize(config, module_name, file_writer, utils, plugins=[])
@file_writer = file_writer @file_writer = file_writer
@@ -10,7 +10,6 @@ class CMockGenerator
@utils = utils @utils = utils
@plugins = plugins @plugins = plugins
@config = config @config = config
@tab = @config.tab
@mock_name = @config.mock_prefix + @module_name @mock_name = @config.mock_prefix + @module_name
@ordered = @config.enforce_strict_ordering @ordered = @config.enforce_strict_ordering
end end
@@ -93,9 +92,9 @@ class CMockGenerator
file << "static struct #{@mock_name}Instance\n" file << "static struct #{@mock_name}Instance\n"
file << "{\n" file << "{\n"
if (functions.size == 0) if (functions.size == 0)
file << "#{@tab}unsigned char placeHolder;\n" file << " unsigned char placeHolder;\n"
end end
file << "#{@tab}unsigned char allocFailure;\n" file << " unsigned char allocFailure;\n"
file << functions.collect{|function| @plugins.run(:instance_structure, function)}.join file << functions.collect{|function| @plugins.run(:instance_structure, function)}.join
file << "} Mock;\n\n" file << "} Mock;\n\n"
end end
@@ -112,35 +111,35 @@ class CMockGenerator
def create_mock_verify_function(file, functions) def create_mock_verify_function(file, functions)
file << "void #{@mock_name}_Verify(void)\n{\n" file << "void #{@mock_name}_Verify(void)\n{\n"
file << "#{@tab}TEST_ASSERT_EQUAL(0, Mock.allocFailure);\n" file << " TEST_ASSERT_EQUAL(0, Mock.allocFailure);\n"
file << functions.collect {|function| @plugins.run(:mock_verify, function)}.join file << functions.collect {|function| @plugins.run(:mock_verify, function)}.join
if (@ordered) if (@ordered)
file << "#{@tab}if (GlobalOrderError)\n" file << " if (GlobalOrderError)\n"
file << "#{@tab}{\n" file << " {\n"
file << "#{@tab}#{@tab}TEST_FAIL(GlobalOrderError);\n" file << " TEST_FAIL(GlobalOrderError);\n"
file << "#{@tab}}\n" file << " }\n"
end end
file << "}\n\n" file << "}\n\n"
end end
def create_mock_init_function(file) def create_mock_init_function(file)
file << "void #{@mock_name}_Init(void)\n{\n" file << "void #{@mock_name}_Init(void)\n{\n"
file << "#{@tab}#{@mock_name}_Destroy();\n" file << " #{@mock_name}_Destroy();\n"
file << "}\n\n" file << "}\n\n"
end end
def create_mock_destroy_function(file, functions) def create_mock_destroy_function(file, functions)
file << "void #{@mock_name}_Destroy(void)\n{\n" file << "void #{@mock_name}_Destroy(void)\n{\n"
file << functions.collect {|function| @plugins.run(:mock_destroy, function) }.join file << functions.collect {|function| @plugins.run(:mock_destroy, function) }.join
file << "#{@tab}memset(&Mock, 0, sizeof(Mock));\n" file << " memset(&Mock, 0, sizeof(Mock));\n"
if (@ordered) if (@ordered)
file << "#{@tab}GlobalExpectCount = 0;\n" file << " GlobalExpectCount = 0;\n"
file << "#{@tab}GlobalVerifyOrder = 0;\n" file << " GlobalVerifyOrder = 0;\n"
file << "#{@tab}if (GlobalOrderError)\n" file << " if (GlobalOrderError)\n"
file << "#{@tab}{\n" file << " {\n"
file << "#{@tab}#{@tab}free(GlobalOrderError);\n" file << " free(GlobalOrderError);\n"
file << "#{@tab}#{@tab}GlobalOrderError = NULL;\n" file << " GlobalOrderError = NULL;\n"
file << "#{@tab}}\n" file << " }\n"
end end
file << "}\n\n" file << "}\n\n"
end end
@@ -165,7 +164,7 @@ class CMockGenerator
# Return expected value, if necessary # Return expected value, if necessary
if (function[:return_type] != "void") if (function[:return_type] != "void")
file << @utils.code_handle_return_value(function, "#{@tab}").join file << @utils.code_handle_return_value(function, " ").join
end end
# Close out the function # Close out the function
+41 -42
View File
@@ -1,11 +1,10 @@
class CMockGeneratorPluginCException class CMockGeneratorPluginCException
attr_reader :config, :utils, :tab attr_reader :config, :utils
def initialize(config, utils) def initialize(config, utils)
@config = config @config = config
@tab = @config.tab
@utils = utils @utils = utils
["cexception_include", "cexception_throw_type"].each do |req| ["cexception_include", "cexception_throw_type"].each do |req|
@@ -22,12 +21,12 @@ class CMockGeneratorPluginCException
def instance_structure(function) def instance_structure(function)
call_count_type = @config.expect_call_count_type call_count_type = @config.expect_call_count_type
throw_type = @config.cexception_throw_type throw_type = @config.cexception_throw_type
[ "#{@tab}#{call_count_type} *#{function[:name]}_ThrowOnCallCount;\n", [ " #{call_count_type} *#{function[:name]}_ThrowOnCallCount;\n",
"#{@tab}#{call_count_type} *#{function[:name]}_ThrowOnCallCount_Head;\n", " #{call_count_type} *#{function[:name]}_ThrowOnCallCount_Head;\n",
"#{@tab}#{call_count_type} *#{function[:name]}_ThrowOnCallCount_Tail;\n", " #{call_count_type} *#{function[:name]}_ThrowOnCallCount_Tail;\n",
"#{@tab}#{throw_type} *#{function[:name]}_ThrowValue;\n", " #{throw_type} *#{function[:name]}_ThrowValue;\n",
"#{@tab}#{throw_type} *#{function[:name]}_ThrowValue_Head;\n", " #{throw_type} *#{function[:name]}_ThrowValue_Head;\n",
"#{@tab}#{throw_type} *#{function[:name]}_ThrowValue_Tail;\n" ] " #{throw_type} *#{function[:name]}_ThrowValue_Tail;\n" ]
end end
def mock_function_declarations(function) def mock_function_declarations(function)
@@ -40,18 +39,18 @@ class CMockGeneratorPluginCException
def mock_implementation(function) def mock_implementation(function)
[ "\n", [ "\n",
"#{@tab}if((Mock.#{function[:name]}_ThrowOnCallCount != Mock.#{function[:name]}_ThrowOnCallCount_Tail) &&\n", " if((Mock.#{function[:name]}_ThrowOnCallCount != Mock.#{function[:name]}_ThrowOnCallCount_Tail) &&\n",
"#{@tab}#{@tab}(Mock.#{function[:name]}_ThrowValue != Mock.#{function[:name]}_ThrowValue_Tail))\n", " (Mock.#{function[:name]}_ThrowValue != Mock.#{function[:name]}_ThrowValue_Tail))\n",
"#{@tab}{\n", " {\n",
"#{@tab}#{@tab}if (*Mock.#{function[:name]}_ThrowOnCallCount && \n", " if (*Mock.#{function[:name]}_ThrowOnCallCount && \n",
"#{@tab}#{@tab}#{@tab}(Mock.#{function[:name]}_CallCount == *Mock.#{function[:name]}_ThrowOnCallCount))\n", " (Mock.#{function[:name]}_CallCount == *Mock.#{function[:name]}_ThrowOnCallCount))\n",
"#{@tab}#{@tab}{\n", " {\n",
"#{@tab}#{@tab}#{@tab}#{@config.cexception_throw_type} toThrow = *Mock.#{function[:name]}_ThrowValue;\n", " #{@config.cexception_throw_type} toThrow = *Mock.#{function[:name]}_ThrowValue;\n",
"#{@tab}#{@tab}#{@tab}Mock.#{function[:name]}_ThrowOnCallCount++;\n", " Mock.#{function[:name]}_ThrowOnCallCount++;\n",
"#{@tab}#{@tab}#{@tab}Mock.#{function[:name]}_ThrowValue++;\n", " Mock.#{function[:name]}_ThrowValue++;\n",
"#{@tab}#{@tab}#{@tab}Throw(toThrow);\n", " Throw(toThrow);\n",
"#{@tab}#{@tab}}\n", " }\n",
"#{@tab}}\n" ] " }\n" ]
end end
def mock_interfaces(function) def mock_interfaces(function)
@@ -63,32 +62,32 @@ class CMockGeneratorPluginCException
@utils.code_add_base_expectation(function[:name]), @utils.code_add_base_expectation(function[:name]),
@utils.code_insert_item_into_expect_array(call_count_type, "Mock.#{function[:name]}_ThrowOnCallCount_Head", "Mock.#{function[:name]}_CallsExpected"), @utils.code_insert_item_into_expect_array(call_count_type, "Mock.#{function[:name]}_ThrowOnCallCount_Head", "Mock.#{function[:name]}_CallsExpected"),
@utils.code_insert_item_into_expect_array(throw_type, "Mock.#{function[:name]}_ThrowValue_Head", "toThrow"), @utils.code_insert_item_into_expect_array(throw_type, "Mock.#{function[:name]}_ThrowValue_Head", "toThrow"),
"#{@tab}Mock.#{function[:name]}_ThrowValue = Mock.#{function[:name]}_ThrowValue_Head;\n", " Mock.#{function[:name]}_ThrowValue = Mock.#{function[:name]}_ThrowValue_Head;\n",
"#{@tab}Mock.#{function[:name]}_ThrowOnCallCount = Mock.#{function[:name]}_ThrowOnCallCount_Head;\n", " Mock.#{function[:name]}_ThrowOnCallCount = Mock.#{function[:name]}_ThrowOnCallCount_Head;\n",
"#{@tab}while ((*Mock.#{function[:name]}_ThrowOnCallCount <= Mock.#{function[:name]}_CallCount) && (Mock.#{function[:name]}_ThrowOnCallCount < Mock.#{function[:name]}_ThrowOnCallCount_Tail))\n", " while ((*Mock.#{function[:name]}_ThrowOnCallCount <= Mock.#{function[:name]}_CallCount) && (Mock.#{function[:name]}_ThrowOnCallCount < Mock.#{function[:name]}_ThrowOnCallCount_Tail))\n",
"#{@tab}{\n", " {\n",
"#{@tab}#{@tab}Mock.#{function[:name]}_ThrowValue++;\n", " Mock.#{function[:name]}_ThrowValue++;\n",
"#{@tab}#{@tab}Mock.#{function[:name]}_ThrowOnCallCount++;\n", " Mock.#{function[:name]}_ThrowOnCallCount++;\n",
"#{@tab}}\n", " }\n",
(function[:args_string] != "void") ? "#{@tab}ExpectParameters_#{function[:name]}(#{@utils.create_call_list(function)});\n" : nil, (function[:args_string] != "void") ? " ExpectParameters_#{function[:name]}(#{@utils.create_call_list(function)});\n" : nil,
"}\n\n" ].compact "}\n\n" ].compact
end end
def mock_destroy(function) def mock_destroy(function)
[ "#{@tab}if(Mock.#{function[:name]}_ThrowOnCallCount_Head)\n", [ " if(Mock.#{function[:name]}_ThrowOnCallCount_Head)\n",
"#{@tab}{\n", " {\n",
"#{@tab}#{@tab}free(Mock.#{function[:name]}_ThrowOnCallCount_Head);\n", " free(Mock.#{function[:name]}_ThrowOnCallCount_Head);\n",
"#{@tab}}\n", " }\n",
"#{@tab}Mock.#{function[:name]}_ThrowOnCallCount=NULL;\n", " Mock.#{function[:name]}_ThrowOnCallCount=NULL;\n",
"#{@tab}Mock.#{function[:name]}_ThrowOnCallCount_Head=NULL;\n", " Mock.#{function[:name]}_ThrowOnCallCount_Head=NULL;\n",
"#{@tab}Mock.#{function[:name]}_ThrowOnCallCount_Tail=NULL;\n", " Mock.#{function[:name]}_ThrowOnCallCount_Tail=NULL;\n",
"#{@tab}if(Mock.#{function[:name]}_ThrowValue_Head)\n", " if(Mock.#{function[:name]}_ThrowValue_Head)\n",
"#{@tab}{\n", " {\n",
"#{@tab}#{@tab}free(Mock.#{function[:name]}_ThrowValue_Head);\n", " free(Mock.#{function[:name]}_ThrowValue_Head);\n",
"#{@tab}}\n", " }\n",
"#{@tab}Mock.#{function[:name]}_ThrowValue=NULL;\n", " Mock.#{function[:name]}_ThrowValue=NULL;\n",
"#{@tab}Mock.#{function[:name]}_ThrowValue_Head=NULL;\n", " Mock.#{function[:name]}_ThrowValue_Head=NULL;\n",
"#{@tab}Mock.#{function[:name]}_ThrowValue_Tail=NULL;\n" " Mock.#{function[:name]}_ThrowValue_Tail=NULL;\n"
] ]
end end
end end
+55 -56
View File
@@ -1,11 +1,10 @@
class CMockGeneratorPluginExpect class CMockGeneratorPluginExpect
attr_accessor :config, :utils, :tab, :unity_helper, :ordered attr_accessor :config, :utils, :unity_helper, :ordered
def initialize(config, utils) def initialize(config, utils)
@config = config @config = config
@tab = @config.tab
@ptr_handling = @config.when_ptr_star @ptr_handling = @config.when_ptr_star
@ordered = @config.enforce_strict_ordering @ordered = @config.enforce_strict_ordering
@utils = utils @utils = utils
@@ -14,25 +13,25 @@ class CMockGeneratorPluginExpect
def instance_structure(function) def instance_structure(function)
call_count_type = @config.expect_call_count_type call_count_type = @config.expect_call_count_type
lines = [ "#{@tab}#{call_count_type} #{function[:name]}_CallCount;\n", lines = [ " #{call_count_type} #{function[:name]}_CallCount;\n",
"#{@tab}#{call_count_type} #{function[:name]}_CallsExpected;\n" ] " #{call_count_type} #{function[:name]}_CallsExpected;\n" ]
if (function[:return_type] != "void") if (function[:return_type] != "void")
lines << [ "#{@tab}#{function[:return_type]} *#{function[:name]}_Return;\n", lines << [ " #{function[:return_type]} *#{function[:name]}_Return;\n",
"#{@tab}#{function[:return_type]} *#{function[:name]}_Return_Head;\n", " #{function[:return_type]} *#{function[:name]}_Return_Head;\n",
"#{@tab}#{function[:return_type]} *#{function[:name]}_Return_Tail;\n" ] " #{function[:return_type]} *#{function[:name]}_Return_Tail;\n" ]
end end
if (@ordered) if (@ordered)
lines << [ "#{@tab}int *#{function[:name]}_CallOrder;\n", lines << [ " int *#{function[:name]}_CallOrder;\n",
"#{@tab}int *#{function[:name]}_CallOrder_Head;\n", " int *#{function[:name]}_CallOrder_Head;\n",
"#{@tab}int *#{function[:name]}_CallOrder_Tail;\n" ] " int *#{function[:name]}_CallOrder_Tail;\n" ]
end end
function[:args].each do |arg| function[:args].each do |arg|
lines << [ "#{@tab}#{arg[:type]} *#{function[:name]}_Expected_#{arg[:name]};\n", lines << [ " #{arg[:type]} *#{function[:name]}_Expected_#{arg[:name]};\n",
"#{@tab}#{arg[:type]} *#{function[:name]}_Expected_#{arg[:name]}_Head;\n", " #{arg[:type]} *#{function[:name]}_Expected_#{arg[:name]}_Head;\n",
"#{@tab}#{arg[:type]} *#{function[:name]}_Expected_#{arg[:name]}_Tail;\n" ] " #{arg[:type]} *#{function[:name]}_Expected_#{arg[:name]}_Tail;\n" ]
end end
lines.flatten lines.flatten
end end
@@ -54,27 +53,27 @@ class CMockGeneratorPluginExpect
end end
def mock_implementation(function) def mock_implementation(function)
lines = [ "#{@tab}Mock.#{function[:name]}_CallCount++;\n", lines = [ " Mock.#{function[:name]}_CallCount++;\n",
"#{@tab}if (Mock.#{function[:name]}_CallCount > Mock.#{function[:name]}_CallsExpected)\n", " if (Mock.#{function[:name]}_CallCount > Mock.#{function[:name]}_CallsExpected)\n",
"#{@tab}{\n", " {\n",
"#{@tab}#{@tab}TEST_FAIL(\"Function '#{function[:name]}' called more times than expected\");\n", " TEST_FAIL(\"Function '#{function[:name]}' called more times than expected\");\n",
"#{@tab}}\n" ] " }\n" ]
if (@ordered) if (@ordered)
err_msg = "Out of order function calls. Function '#{function[:name]}'" #" expected to be call %i but was call %i" err_msg = "Out of order function calls. Function '#{function[:name]}'" #" expected to be call %i but was call %i"
lines << [ "#{@tab}{\n", lines << [ " {\n",
"#{@tab}#{@tab}int* p_expected = Mock.#{function[:name]}_CallOrder;\n", " int* p_expected = Mock.#{function[:name]}_CallOrder;\n",
"#{@tab}#{@tab}++GlobalVerifyOrder;\n", " ++GlobalVerifyOrder;\n",
"#{@tab}#{@tab}if (Mock.#{function[:name]}_CallOrder != Mock.#{function[:name]}_CallOrder_Tail)\n", " if (Mock.#{function[:name]}_CallOrder != Mock.#{function[:name]}_CallOrder_Tail)\n",
"#{@tab}#{@tab}#{@tab}Mock.#{function[:name]}_CallOrder++;\n", " Mock.#{function[:name]}_CallOrder++;\n",
"#{@tab}#{@tab}if ((*p_expected != GlobalVerifyOrder) && (GlobalOrderError == NULL))\n", " if ((*p_expected != GlobalVerifyOrder) && (GlobalOrderError == NULL))\n",
"#{@tab}#{@tab}{\n", " {\n",
"#{@tab}#{@tab}#{@tab}const char* ErrStr = \"#{err_msg}\";\n", " const char* ErrStr = \"#{err_msg}\";\n",
"#{@tab}#{@tab}#{@tab}GlobalOrderError = malloc(#{err_msg.size + 1});\n", " GlobalOrderError = malloc(#{err_msg.size + 1});\n",
"#{@tab}#{@tab}#{@tab}if (GlobalOrderError)\n", " if (GlobalOrderError)\n",
"#{@tab}#{@tab}#{@tab}#{@tab}strcpy(GlobalOrderError, ErrStr);\n", " strcpy(GlobalOrderError, ErrStr);\n",
"#{@tab}#{@tab}}\n", " }\n",
"#{@tab}}\n" ] " }\n" ]
end end
function[:args].each do |arg| function[:args].each do |arg|
@@ -110,51 +109,51 @@ class CMockGeneratorPluginExpect
lines << @utils.code_add_base_expectation(function[:name]) lines << @utils.code_add_base_expectation(function[:name])
if (function[:args_string] != "void") if (function[:args_string] != "void")
lines << "#{@tab}ExpectParameters_#{function[:name]}(#{@utils.create_call_list(function)});\n" lines << " ExpectParameters_#{function[:name]}(#{@utils.create_call_list(function)});\n"
end end
if (function[:return_type] != "void") if (function[:return_type] != "void")
lines << @utils.code_insert_item_into_expect_array(function[:return_type], "Mock.#{function[:name]}_Return_Head", 'toReturn') lines << @utils.code_insert_item_into_expect_array(function[:return_type], "Mock.#{function[:name]}_Return_Head", 'toReturn')
lines << "#{@tab}Mock.#{function[:name]}_Return = Mock.#{function[:name]}_Return_Head;\n" lines << " Mock.#{function[:name]}_Return = Mock.#{function[:name]}_Return_Head;\n"
lines << "#{@tab}Mock.#{function[:name]}_Return += Mock.#{function[:name]}_CallCount;\n" lines << " Mock.#{function[:name]}_Return += Mock.#{function[:name]}_CallCount;\n"
end end
lines << "}\n\n" lines << "}\n\n"
end end
def mock_verify(function) def mock_verify(function)
["#{@tab}TEST_ASSERT_EQUAL_MESSAGE(Mock.#{function[:name]}_CallsExpected, Mock.#{function[:name]}_CallCount, \"Function '#{function[:name]}' called unexpected number of times.\");\n"] [" TEST_ASSERT_EQUAL_MESSAGE(Mock.#{function[:name]}_CallsExpected, Mock.#{function[:name]}_CallCount, \"Function '#{function[:name]}' called unexpected number of times.\");\n"]
end end
def mock_destroy(function) def mock_destroy(function)
lines = [] lines = []
if (function[:return_type] != "void") if (function[:return_type] != "void")
lines << [ "#{@tab}if (Mock.#{function[:name]}_Return_Head)\n", lines << [ " if (Mock.#{function[:name]}_Return_Head)\n",
"#{@tab}{\n", " {\n",
"#{@tab}#{@tab}free(Mock.#{function[:name]}_Return_Head);\n", " free(Mock.#{function[:name]}_Return_Head);\n",
"#{@tab}}\n", " }\n",
"#{@tab}Mock.#{function[:name]}_Return=NULL;\n", " Mock.#{function[:name]}_Return=NULL;\n",
"#{@tab}Mock.#{function[:name]}_Return_Head=NULL;\n", " Mock.#{function[:name]}_Return_Head=NULL;\n",
"#{@tab}Mock.#{function[:name]}_Return_Tail=NULL;\n" " Mock.#{function[:name]}_Return_Tail=NULL;\n"
] ]
end end
if (@ordered) if (@ordered)
lines << [ "#{@tab}if (Mock.#{function[:name]}_CallOrder_Head)\n", lines << [ " if (Mock.#{function[:name]}_CallOrder_Head)\n",
"#{@tab}{\n", " {\n",
"#{@tab}#{@tab}free(Mock.#{function[:name]}_CallOrder_Head);\n", " free(Mock.#{function[:name]}_CallOrder_Head);\n",
"#{@tab}}\n", " }\n",
"#{@tab}Mock.#{function[:name]}_CallOrder=NULL;\n", " Mock.#{function[:name]}_CallOrder=NULL;\n",
"#{@tab}Mock.#{function[:name]}_CallOrder_Head=NULL;\n", " Mock.#{function[:name]}_CallOrder_Head=NULL;\n",
"#{@tab}Mock.#{function[:name]}_CallOrder_Tail=NULL;\n" " Mock.#{function[:name]}_CallOrder_Tail=NULL;\n"
] ]
end end
function[:args].each do |arg| function[:args].each do |arg|
lines << [ "#{@tab}if (Mock.#{function[:name]}_Expected_#{arg[:name]}_Head)\n", lines << [ " if (Mock.#{function[:name]}_Expected_#{arg[:name]}_Head)\n",
"#{@tab}{\n", " {\n",
"#{@tab}#{@tab}free(Mock.#{function[:name]}_Expected_#{arg[:name]}_Head);\n", " free(Mock.#{function[:name]}_Expected_#{arg[:name]}_Head);\n",
"#{@tab}}\n", " }\n",
"#{@tab}Mock.#{function[:name]}_Expected_#{arg[:name]}=NULL;\n", " Mock.#{function[:name]}_Expected_#{arg[:name]}=NULL;\n",
"#{@tab}Mock.#{function[:name]}_Expected_#{arg[:name]}_Head=NULL;\n", " Mock.#{function[:name]}_Expected_#{arg[:name]}_Head=NULL;\n",
"#{@tab}Mock.#{function[:name]}_Expected_#{arg[:name]}_Tail=NULL;\n" " Mock.#{function[:name]}_Expected_#{arg[:name]}_Tail=NULL;\n"
] ]
end end
lines.flatten lines.flatten
+22 -23
View File
@@ -1,11 +1,10 @@
class CMockGeneratorPluginIgnore class CMockGeneratorPluginIgnore
attr_reader :config, :utils, :tab attr_reader :config, :utils
def initialize(config, utils) def initialize(config, utils)
@config = config @config = config
@tab = @config.tab
@utils = utils @utils = utils
["ignore_bool_type"].each do |req| ["ignore_bool_type"].each do |req|
@@ -14,7 +13,7 @@ class CMockGeneratorPluginIgnore
end end
def instance_structure(function) def instance_structure(function)
return ["#{@tab}#{@config.ignore_bool_type} #{function[:name]}_IgnoreBool;\n"] return [" #{@config.ignore_bool_type} #{function[:name]}_IgnoreBool;\n"]
end end
def mock_function_declarations(function) def mock_function_declarations(function)
@@ -26,27 +25,27 @@ class CMockGeneratorPluginIgnore
end end
def mock_implementation_prefix(function) def mock_implementation_prefix(function)
lines = [ "#{@tab}if (Mock.#{function[:name]}_IgnoreBool)\n", lines = [ " if (Mock.#{function[:name]}_IgnoreBool)\n",
"#{@tab}{\n" " {\n"
] ]
if (function[:return_type] == "void") if (function[:return_type] == "void")
lines << ["#{@tab*2}return;\n"] lines << [" return;\n"]
else else
lines << [ "#{@tab*2}if (Mock.#{function[:name]}_Return != Mock.#{function[:name]}_Return_Tail)\n", lines << [ " if (Mock.#{function[:name]}_Return != Mock.#{function[:name]}_Return_Tail)\n",
"#{@tab*2}{\n", " {\n",
"#{@tab*3}#{function[:return_type]} toReturn = *Mock.#{function[:name]}_Return;\n", " #{function[:return_type]} toReturn = *Mock.#{function[:name]}_Return;\n",
"#{@tab*3}Mock.#{function[:name]}_Return++;\n", " Mock.#{function[:name]}_Return++;\n",
"#{@tab*3}Mock.#{function[:name]}_CallCount++;\n", " Mock.#{function[:name]}_CallCount++;\n",
"#{@tab*3}Mock.#{function[:name]}_CallsExpected++;\n", " Mock.#{function[:name]}_CallsExpected++;\n",
"#{@tab*3}return toReturn;\n", " return toReturn;\n",
"#{@tab*2}}\n", " }\n",
"#{@tab*2}else\n", " else\n",
"#{@tab*2}{\n", " {\n",
"#{@tab*3}return *(Mock.#{function[:name]}_Return_Tail - 1);\n", " return *(Mock.#{function[:name]}_Return_Tail - 1);\n",
"#{@tab*2}}\n" " }\n"
] ]
end end
lines << [ "#{@tab}}\n" ] lines << [ " }\n" ]
lines.flatten lines.flatten
end end
@@ -54,15 +53,15 @@ class CMockGeneratorPluginIgnore
if (function[:return_type] == "void") if (function[:return_type] == "void")
[ "void #{function[:name]}_Ignore(void)\n", [ "void #{function[:name]}_Ignore(void)\n",
"{\n", "{\n",
"#{@tab}Mock.#{function[:name]}_IgnoreBool = (unsigned char)1;\n", " Mock.#{function[:name]}_IgnoreBool = (unsigned char)1;\n",
"}\n\n" ] "}\n\n" ]
else else
[ "void #{function[:name]}_IgnoreAndReturn(#{function[:return_string]})\n", [ "void #{function[:name]}_IgnoreAndReturn(#{function[:return_string]})\n",
"{\n", "{\n",
"#{@tab}Mock.#{function[:name]}_IgnoreBool = (unsigned char)1;\n", " Mock.#{function[:name]}_IgnoreBool = (unsigned char)1;\n",
@utils.code_insert_item_into_expect_array(function[:return_type], "Mock.#{function[:name]}_Return_Head", 'toReturn'), @utils.code_insert_item_into_expect_array(function[:return_type], "Mock.#{function[:name]}_Return_Head", 'toReturn'),
"#{@tab}Mock.#{function[:name]}_Return = Mock.#{function[:name]}_Return_Head;\n", " Mock.#{function[:name]}_Return = Mock.#{function[:name]}_Return_Head;\n",
"#{@tab}Mock.#{function[:name]}_Return += Mock.#{function[:name]}_CallCount;\n", " Mock.#{function[:name]}_Return += Mock.#{function[:name]}_CallCount;\n",
"}\n\n" ] "}\n\n" ]
end end
end end
+40 -41
View File
@@ -1,11 +1,10 @@
class CMockGeneratorUtils class CMockGeneratorUtils
attr_accessor :config, :tab, :helpers, :ordered attr_accessor :config, :helpers, :ordered
def initialize(config, helpers={}) def initialize(config, helpers={})
@config = config @config = config
@tab = @config.tab
@ptr_handling = @config.when_ptr_star @ptr_handling = @config.when_ptr_star
@ordered = @config.enforce_strict_ordering @ordered = @config.enforce_strict_ordering
@helpers = helpers @helpers = helpers
@@ -26,54 +25,54 @@ class CMockGeneratorUtils
def code_insert_item_into_expect_array(type, array, newValue) def code_insert_item_into_expect_array(type, array, newValue)
tail = array.gsub(/Head$/,'Tail') tail = array.gsub(/Head$/,'Tail')
lines = ["\n"] lines = ["\n"]
lines << "#{@tab}{\n" lines << " {\n"
lines << "#{@tab}#{@tab}int sz = 0;\n" lines << " int sz = 0;\n"
lines << "#{@tab}#{@tab}#{type} *pointer = #{array};\n" lines << " #{type} *pointer = #{array};\n"
lines << "#{@tab}#{@tab}while (pointer && pointer != #{tail}) { sz++; pointer++; }\n" lines << " while (pointer && pointer != #{tail}) { sz++; pointer++; }\n"
lines << "#{@tab}#{@tab}if (sz == 0)\n" lines << " if (sz == 0)\n"
lines << "#{@tab}#{@tab}{\n" lines << " {\n"
lines << "#{@tab}#{@tab}#{@tab}#{array} = (#{type}*)malloc(2*sizeof(#{type}));\n" lines << " #{array} = (#{type}*)malloc(2*sizeof(#{type}));\n"
lines << "#{@tab}#{@tab}#{@tab}if (!#{array})\n" lines << " if (!#{array})\n"
lines << "#{@tab}#{@tab}#{@tab}#{@tab}Mock.allocFailure++;\n" lines << " Mock.allocFailure++;\n"
lines << "#{@tab}#{@tab}}\n" lines << " }\n"
lines << "#{@tab}#{@tab}else\n" lines << " else\n"
lines << "#{@tab}#{@tab}{\n" lines << " {\n"
lines << "#{@tab}#{@tab}#{@tab}#{type} *ptmp = (#{type}*)realloc(#{array}, sizeof(#{type}) * (sz+1));\n" lines << " #{type} *ptmp = (#{type}*)realloc(#{array}, sizeof(#{type}) * (sz+1));\n"
lines << "#{@tab}#{@tab}#{@tab}if (!ptmp)\n" lines << " if (!ptmp)\n"
lines << "#{@tab}#{@tab}#{@tab}#{@tab}Mock.allocFailure++;\n" lines << " Mock.allocFailure++;\n"
lines << "#{@tab}#{@tab}#{@tab}else\n" lines << " else\n"
lines << "#{@tab}#{@tab}#{@tab}#{@tab}#{array} = ptmp;\n" lines << " #{array} = ptmp;\n"
lines << "#{@tab}#{@tab}}\n" lines << " }\n"
lines << "#{@tab}#{@tab}memcpy(&#{array}[sz], &#{newValue}, sizeof(#{type}));\n" lines << " memcpy(&#{array}[sz], &#{newValue}, sizeof(#{type}));\n"
lines << "#{@tab}#{@tab}#{tail} = &#{array}[sz+1];\n" lines << " #{tail} = &#{array}[sz+1];\n"
lines << "#{@tab}}\n" lines << " }\n"
end end
def code_add_an_arg_expectation(function, arg_type, expected) def code_add_an_arg_expectation(function, arg_type, expected)
lines = code_insert_item_into_expect_array(arg_type, "Mock.#{function[:name]}_Expected_#{expected}_Head", expected) lines = code_insert_item_into_expect_array(arg_type, "Mock.#{function[:name]}_Expected_#{expected}_Head", expected)
lines << "#{@tab}Mock.#{function[:name]}_Expected_#{expected} = Mock.#{function[:name]}_Expected_#{expected}_Head;\n" lines << " Mock.#{function[:name]}_Expected_#{expected} = Mock.#{function[:name]}_Expected_#{expected}_Head;\n"
lines << "#{@tab}Mock.#{function[:name]}_Expected_#{expected} += Mock.#{function[:name]}_CallCount;\n" lines << " Mock.#{function[:name]}_Expected_#{expected} += Mock.#{function[:name]}_CallCount;\n"
end end
def code_add_base_expectation(func_name) def code_add_base_expectation(func_name)
lines = ["#{@tab}Mock.#{func_name}_CallsExpected++;\n"] lines = [" Mock.#{func_name}_CallsExpected++;\n"]
if (@ordered) if (@ordered)
lines << [ "#{@tab}++GlobalExpectCount;\n", lines << [ " ++GlobalExpectCount;\n",
code_insert_item_into_expect_array("int", "Mock.#{func_name}_CallOrder_Head", "GlobalExpectCount"), code_insert_item_into_expect_array("int", "Mock.#{func_name}_CallOrder_Head", "GlobalExpectCount"),
"#{@tab}Mock.#{func_name}_CallOrder = Mock.#{func_name}_CallOrder_Head;\n", " Mock.#{func_name}_CallOrder = Mock.#{func_name}_CallOrder_Head;\n",
"#{@tab}Mock.#{func_name}_CallOrder += Mock.#{func_name}_CallCount;\n" ] " Mock.#{func_name}_CallOrder += Mock.#{func_name}_CallCount;\n" ]
end end
lines.flatten lines.flatten
end end
def code_verify_an_arg_expectation(function, arg_type, actual) def code_verify_an_arg_expectation(function, arg_type, actual)
[ "\n", [ "\n",
"#{@tab}if (Mock.#{function[:name]}_Expected_#{actual} != Mock.#{function[:name]}_Expected_#{actual}_Tail)\n", " if (Mock.#{function[:name]}_Expected_#{actual} != Mock.#{function[:name]}_Expected_#{actual}_Tail)\n",
"#{@tab}{\n", " {\n",
"#{@tab}#{@tab}#{arg_type}* p_expected = Mock.#{function[:name]}_Expected_#{actual};\n", " #{arg_type}* p_expected = Mock.#{function[:name]}_Expected_#{actual};\n",
"#{@tab}#{@tab}Mock.#{function[:name]}_Expected_#{actual}++;\n", " Mock.#{function[:name]}_Expected_#{actual}++;\n",
expect_helper(arg_type, '*p_expected', actual, "\"Function '#{function[:name]}' called with unexpected value for argument '#{actual}'.\"","#{@tab}#{@tab}"), expect_helper(arg_type, '*p_expected', actual, "\"Function '#{function[:name]}' called with unexpected value for argument '#{actual}'.\""," "),
"#{@tab}}\n" ].flatten " }\n" ].flatten
end end
def expect_helper(c_type, expected, actual, msg, indent) def expect_helper(c_type, expected, actual, msg, indent)
@@ -89,9 +88,9 @@ class CMockGeneratorUtils
return "#{indent}#{unity_func}((void*)#{full_expected}, (void*)&(#{actual}), sizeof(#{c_type})#{unity_msg});\n" return "#{indent}#{unity_func}((void*)#{full_expected}, (void*)&(#{actual}), sizeof(#{c_type})#{unity_msg});\n"
when /_ARRAY/ when /_ARRAY/
return [ "#{indent}if (*p_expected == NULL)\n", return [ "#{indent}if (*p_expected == NULL)\n",
"#{indent}#{@tab}{ TEST_ASSERT_NULL(#{actual}); }\n", "#{indent} { TEST_ASSERT_NULL(#{actual}); }\n",
"#{indent}else\n", "#{indent}else\n",
"#{indent}#{@tab}{ #{unity_func}(#{expected}, #{actual}, 1#{unity_msg}); }\n" ] "#{indent} { #{unity_func}(#{expected}, #{actual}, 1#{unity_msg}); }\n" ]
else else
return "#{indent}#{unity_func}(#{expected}, #{actual}#{unity_msg});\n" return "#{indent}#{unity_func}(#{expected}, #{actual}#{unity_msg});\n"
end end
@@ -101,13 +100,13 @@ class CMockGeneratorUtils
[ "\n", [ "\n",
"#{indent}if (Mock.#{function[:name]}_Return != Mock.#{function[:name]}_Return_Tail)\n", "#{indent}if (Mock.#{function[:name]}_Return != Mock.#{function[:name]}_Return_Tail)\n",
"#{indent}{\n", "#{indent}{\n",
"#{indent}#{@tab}#{function[:return_type]} toReturn = *Mock.#{function[:name]}_Return;\n", "#{indent} #{function[:return_type]} toReturn = *Mock.#{function[:name]}_Return;\n",
"#{indent}#{@tab}Mock.#{function[:name]}_Return++;\n", "#{indent} Mock.#{function[:name]}_Return++;\n",
"#{indent}#{@tab}return toReturn;\n", "#{indent} return toReturn;\n",
"#{indent}}\n", "#{indent}}\n",
"#{indent}else\n", "#{indent}else\n",
"#{indent}{\n", "#{indent}{\n",
"#{indent}#{@tab}return *(Mock.#{function[:name]}_Return_Tail - 1);\n", "#{indent} return *(Mock.#{function[:name]}_Return_Tail - 1);\n",
"#{indent}}\n" ] "#{indent}}\n" ]
end end
end end
+1 -1
View File
@@ -206,7 +206,7 @@ module RakefileHelpers
runner_path = $cfg['compiler']['source_path'] + runner_name runner_path = $cfg['compiler']['source_path'] + runner_name
test_gen = UnityTestRunnerGenerator.new test_gen = UnityTestRunnerGenerator.new
gen_inc, gen_opt = UnityTestRunnerGenerator::grab_config(SYSTEST_GENERATED_FILES_PATH + cmock_config) gen_inc, gen_opt = UnityTestRunnerGenerator::grab_config(SYSTEST_GENERATED_FILES_PATH + cmock_config)
test_gen.run(test, runner_path, gen_inc, ' ', gen_opt) test_gen.run(test, runner_path, gen_inc, gen_opt)
compile(runner_path) compile(runner_path)
obj_list << runner_name.ext($cfg['compiler']['object_files']['extension']) obj_list << runner_name.ext($cfg['compiler']['object_files']['extension'])
-3
View File
@@ -14,7 +14,6 @@ class CMockConfigTest < Test::Unit::TestCase
assert_equal(CMockConfig::CMockDefaultOptions[:includes], config.includes) assert_equal(CMockConfig::CMockDefaultOptions[:includes], config.includes)
assert_equal(CMockConfig::CMockDefaultOptions[:attributes], config.attributes) assert_equal(CMockConfig::CMockDefaultOptions[:attributes], config.attributes)
assert_equal(CMockConfig::CMockDefaultOptions[:plugins], config.plugins) assert_equal(CMockConfig::CMockDefaultOptions[:plugins], config.plugins)
assert_equal(CMockConfig::CMockDefaultOptions[:tab], config.tab)
assert_equal(CMockConfig::CMockDefaultOptions[:expect_call_count_type],config.expect_call_count_type) assert_equal(CMockConfig::CMockDefaultOptions[:expect_call_count_type],config.expect_call_count_type)
assert_equal(CMockConfig::CMockDefaultOptions[:ignore_bool_type], config.ignore_bool_type) assert_equal(CMockConfig::CMockDefaultOptions[:ignore_bool_type], config.ignore_bool_type)
assert_equal(CMockConfig::CMockDefaultOptions[:cexception_include], config.cexception_include) assert_equal(CMockConfig::CMockDefaultOptions[:cexception_include], config.cexception_include)
@@ -30,7 +29,6 @@ class CMockConfigTest < Test::Unit::TestCase
assert_equal(test_includes, config.includes) assert_equal(test_includes, config.includes)
assert_equal(test_attributes, config.attributes) assert_equal(test_attributes, config.attributes)
assert_equal(CMockConfig::CMockDefaultOptions[:plugins], config.plugins) assert_equal(CMockConfig::CMockDefaultOptions[:plugins], config.plugins)
assert_equal(CMockConfig::CMockDefaultOptions[:tab], config.tab)
assert_equal(CMockConfig::CMockDefaultOptions[:expect_call_count_type], config.expect_call_count_type) assert_equal(CMockConfig::CMockDefaultOptions[:expect_call_count_type], config.expect_call_count_type)
assert_equal(test_bool_type, config.ignore_bool_type) assert_equal(test_bool_type, config.ignore_bool_type)
assert_equal(CMockConfig::CMockDefaultOptions[:cexception_include], config.cexception_include) assert_equal(CMockConfig::CMockDefaultOptions[:cexception_include], config.cexception_include)
@@ -44,7 +42,6 @@ class CMockConfigTest < Test::Unit::TestCase
assert_equal(CMockConfig::CMockDefaultOptions[:mock_path], config.mock_path) assert_equal(CMockConfig::CMockDefaultOptions[:mock_path], config.mock_path)
assert_equal(CMockConfig::CMockDefaultOptions[:includes], config.includes) assert_equal(CMockConfig::CMockDefaultOptions[:includes], config.includes)
assert_equal(test_plugins, config.plugins) assert_equal(test_plugins, config.plugins)
assert_equal(CMockConfig::CMockDefaultOptions[:tab], config.tab)
assert_equal(CMockConfig::CMockDefaultOptions[:expect_call_count_type], config.expect_call_count_type) assert_equal(CMockConfig::CMockDefaultOptions[:expect_call_count_type], config.expect_call_count_type)
assert_equal(CMockConfig::CMockDefaultOptions[:ignore_bool_type], config.ignore_bool_type) assert_equal(CMockConfig::CMockDefaultOptions[:ignore_bool_type], config.ignore_bool_type)
assert_equal(CMockConfig::CMockDefaultOptions[:cexception_include], config.cexception_include) assert_equal(CMockConfig::CMockDefaultOptions[:cexception_include], config.cexception_include)
-3
View File
@@ -40,13 +40,11 @@ class CMockGeneratorTest < Test::Unit::TestCase
@module_name = "PoutPoutFish" @module_name = "PoutPoutFish"
#no strict handling #no strict handling
@config.expect.tab.returns(" ")
@config.expect.mock_prefix.returns("Mock") @config.expect.mock_prefix.returns("Mock")
@config.expect.enforce_strict_ordering.returns(false) @config.expect.enforce_strict_ordering.returns(false)
@cmock_generator = CMockGenerator.new(@config, @module_name, @file_writer, @utils, @plugins) @cmock_generator = CMockGenerator.new(@config, @module_name, @file_writer, @utils, @plugins)
#strict handling #strict handling
@config.expect.tab.returns(" ")
@config.expect.mock_prefix.returns("Mock") @config.expect.mock_prefix.returns("Mock")
@config.expect.enforce_strict_ordering.returns(true) @config.expect.enforce_strict_ordering.returns(true)
@cmock_generator_strict = CMockGenerator.new(@config, @module_name, @file_writer, @utils, @plugins) @cmock_generator_strict = CMockGenerator.new(@config, @module_name, @file_writer, @utils, @plugins)
@@ -62,7 +60,6 @@ class CMockGeneratorTest < Test::Unit::TestCase
assert_equal(@utils, @cmock_generator.utils) assert_equal(@utils, @cmock_generator.utils)
assert_equal(@plugins, @cmock_generator.plugins) assert_equal(@plugins, @cmock_generator.plugins)
assert_equal("Mock#{@module_name}", @cmock_generator.mock_name) assert_equal("Mock#{@module_name}", @cmock_generator.mock_name)
assert_equal(" ", @cmock_generator.tab)
end end
should "create the top of a header file" do should "create the top of a header file" do
@@ -4,7 +4,6 @@ require 'cmock_generator_plugin_cexception'
class CMockGeneratorPluginCExceptionTest < Test::Unit::TestCase class CMockGeneratorPluginCExceptionTest < Test::Unit::TestCase
def setup def setup
create_mocks :config, :utils create_mocks :config, :utils
@config.expect.tab.returns(" ")
@config.stubs!(:respond_to?).returns(true) @config.stubs!(:respond_to?).returns(true)
@cmock_generator_plugin_cexception = CMockGeneratorPluginCException.new(@config, @utils) @cmock_generator_plugin_cexception = CMockGeneratorPluginCException.new(@config, @utils)
end end
@@ -15,7 +14,6 @@ class CMockGeneratorPluginCExceptionTest < Test::Unit::TestCase
should "have set up internal accessors correctly on init" do should "have set up internal accessors correctly on init" do
assert_equal(@config, @cmock_generator_plugin_cexception.config) assert_equal(@config, @cmock_generator_plugin_cexception.config)
assert_equal(@utils, @cmock_generator_plugin_cexception.utils) assert_equal(@utils, @cmock_generator_plugin_cexception.utils)
assert_equal(" ", @cmock_generator_plugin_cexception.tab)
end end
should "include the cexception library" do should "include the cexception library" do
@@ -6,7 +6,6 @@ class CMockGeneratorPluginExpectTest < Test::Unit::TestCase
create_mocks :config, :utils create_mocks :config, :utils
#no strict ordering #no strict ordering
@config.expect.tab.returns(" ")
@config.expect.when_ptr_star.returns(:compare_data) @config.expect.when_ptr_star.returns(:compare_data)
@config.expect.enforce_strict_ordering.returns(false) @config.expect.enforce_strict_ordering.returns(false)
@config.stubs!(:respond_to?).returns(true) @config.stubs!(:respond_to?).returns(true)
@@ -14,7 +13,6 @@ class CMockGeneratorPluginExpectTest < Test::Unit::TestCase
@cmock_generator_plugin_expect = CMockGeneratorPluginExpect.new(@config, @utils) @cmock_generator_plugin_expect = CMockGeneratorPluginExpect.new(@config, @utils)
#strict ordering #strict ordering
@config.expect.tab.returns(" ")
@config.expect.when_ptr_star.returns(:compare_data) @config.expect.when_ptr_star.returns(:compare_data)
@config.expect.enforce_strict_ordering.returns(true) @config.expect.enforce_strict_ordering.returns(true)
@config.stubs!(:respond_to?).returns(true) @config.stubs!(:respond_to?).returns(true)
@@ -28,7 +26,6 @@ class CMockGeneratorPluginExpectTest < Test::Unit::TestCase
should "have set up internal accessors correctly on init" do should "have set up internal accessors correctly on init" do
assert_equal(@config, @cmock_generator_plugin_expect.config) assert_equal(@config, @cmock_generator_plugin_expect.config)
assert_equal(@utils, @cmock_generator_plugin_expect.utils) assert_equal(@utils, @cmock_generator_plugin_expect.utils)
assert_equal(" ", @cmock_generator_plugin_expect.tab)
assert_equal(nil, @cmock_generator_plugin_expect.unity_helper) assert_equal(nil, @cmock_generator_plugin_expect.unity_helper)
end end
@@ -4,7 +4,6 @@ require 'cmock_generator_plugin_ignore'
class CMockGeneratorPluginIgnoreTest < Test::Unit::TestCase class CMockGeneratorPluginIgnoreTest < Test::Unit::TestCase
def setup def setup
create_mocks :config, :utils create_mocks :config, :utils
@config.expect.tab.returns(" ")
@config.stubs!(:respond_to?).returns(true) @config.stubs!(:respond_to?).returns(true)
@cmock_generator_plugin_ignore = CMockGeneratorPluginIgnore.new(@config, @utils) @cmock_generator_plugin_ignore = CMockGeneratorPluginIgnore.new(@config, @utils)
end end
@@ -15,7 +14,6 @@ class CMockGeneratorPluginIgnoreTest < Test::Unit::TestCase
should "have set up internal accessors correctly on init" do should "have set up internal accessors correctly on init" do
assert_equal(@config, @cmock_generator_plugin_ignore.config) assert_equal(@config, @cmock_generator_plugin_ignore.config)
assert_equal(@utils, @cmock_generator_plugin_ignore.utils) assert_equal(@utils, @cmock_generator_plugin_ignore.utils)
assert_equal(" ", @cmock_generator_plugin_ignore.tab)
end end
should "not have any additional include file requirements" do should "not have any additional include file requirements" do
+11 -16
View File
@@ -4,7 +4,6 @@ require 'cmock_generator_utils'
class CMockGeneratorUtilsTest < Test::Unit::TestCase class CMockGeneratorUtilsTest < Test::Unit::TestCase
def setup def setup
create_mocks :config, :unity_helper create_mocks :config, :unity_helper
@config.expect.tab.returns(" ")
@config.expect.when_ptr_star.returns(:compare_data) @config.expect.when_ptr_star.returns(:compare_data)
@config.expect.enforce_strict_ordering.returns(false) @config.expect.enforce_strict_ordering.returns(false)
@cmock_generator_utils = CMockGeneratorUtils.new(@config) @cmock_generator_utils = CMockGeneratorUtils.new(@config)
@@ -15,18 +14,15 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase
should "have set up internal accessors correctly on init" do should "have set up internal accessors correctly on init" do
assert_equal(@config, @cmock_generator_utils.config) assert_equal(@config, @cmock_generator_utils.config)
assert_equal(" ", @cmock_generator_utils.tab)
assert_equal({}, @cmock_generator_utils.helpers) assert_equal({}, @cmock_generator_utils.helpers)
end end
should "have set up internal accessors correctly on init, complete with passed helpers" do should "have set up internal accessors correctly on init, complete with passed helpers" do
create_mocks :config create_mocks :config
@config.expect.tab.returns(" ")
@config.expect.when_ptr_star.returns(:compare_ptr) @config.expect.when_ptr_star.returns(:compare_ptr)
@config.expect.enforce_strict_ordering.returns(false) @config.expect.enforce_strict_ordering.returns(false)
@cmock_generator_utils = CMockGeneratorUtils.new(@config, {:A=>1, :B=>2}) @cmock_generator_utils = CMockGeneratorUtils.new(@config, {:A=>1, :B=>2})
assert_equal(@config, @cmock_generator_utils.config) assert_equal(@config, @cmock_generator_utils.config)
assert_equal(" ", @cmock_generator_utils.tab)
assert_equal({:A=>1, :B=>2},@cmock_generator_utils.helpers) assert_equal({:A=>1, :B=>2},@cmock_generator_utils.helpers)
end end
@@ -84,20 +80,19 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase
should "make handle return" do should "make handle return" do
function = { :name => "Spatula", :return_type => "uint64"} function = { :name => "Spatula", :return_type => "uint64"}
indent = "[tab]"
expected = ["\n", expected = ["\n",
"[tab]if (Mock.Spatula_Return != Mock.Spatula_Return_Tail)\n", " if (Mock.Spatula_Return != Mock.Spatula_Return_Tail)\n",
"[tab]{\n", " {\n",
"[tab] uint64 toReturn = *Mock.Spatula_Return;\n", " uint64 toReturn = *Mock.Spatula_Return;\n",
"[tab] Mock.Spatula_Return++;\n", " Mock.Spatula_Return++;\n",
"[tab] return toReturn;\n", " return toReturn;\n",
"[tab]}\n", " }\n",
"[tab]else\n", " else\n",
"[tab]{\n", " {\n",
"[tab] return *(Mock.Spatula_Return_Tail - 1);\n", " return *(Mock.Spatula_Return_Tail - 1);\n",
"[tab]}\n" " }\n"
] ]
returned = @cmock_generator_utils.code_handle_return_value(function, indent) returned = @cmock_generator_utils.code_handle_return_value(function, ' ')
assert_equal(expected, returned) assert_equal(expected, returned)
end end
-4
View File
@@ -13,7 +13,6 @@ class CMockPluginManagerTest < Test::Unit::TestCase
end end
should "return all plugins by default" do should "return all plugins by default" do
@config.stubs!(:tab).returns(" ")
@config.expect.plugins.returns(['cexception','ignore']) @config.expect.plugins.returns(['cexception','ignore'])
@utils.expect.helpers.returns({}) @utils.expect.helpers.returns({})
@@ -32,7 +31,6 @@ class CMockPluginManagerTest < Test::Unit::TestCase
end end
should "return restricted plugins based on config" do should "return restricted plugins based on config" do
@config.stubs!(:tab).returns(" ")
@config.expect.plugins.returns([]) @config.expect.plugins.returns([])
@utils.expect.helpers.returns({}) @utils.expect.helpers.returns({})
@@ -51,7 +49,6 @@ class CMockPluginManagerTest < Test::Unit::TestCase
end end
should "run a desired method over each plugin requested and return the results" do should "run a desired method over each plugin requested and return the results" do
@config.stubs!(:tab).returns(" ")
@config.expect.plugins.returns([]) @config.expect.plugins.returns([])
@utils.expect.helpers.returns({}) @utils.expect.helpers.returns({})
@cmock_plugins = CMockPluginManager.new(@config, @utils) @cmock_plugins = CMockPluginManager.new(@config, @utils)
@@ -66,7 +63,6 @@ class CMockPluginManagerTest < Test::Unit::TestCase
end end
should "run a desired method and arg list over each plugin requested and return the results" do should "run a desired method and arg list over each plugin requested and return the results" do
@config.stubs!(:tab).returns(" ")
@config.expect.plugins.returns([]) @config.expect.plugins.returns([])
@utils.expect.helpers.returns({}) @utils.expect.helpers.returns({})
@cmock_plugins = CMockPluginManager.new(@config, @utils) @cmock_plugins = CMockPluginManager.new(@config, @utils)