mirror of
https://github.com/ThrowTheSwitch/CMock.git
synced 2026-08-27 21:39:59 +00:00
- push the internal function and argument names into a single each per mock to further reduce const overhead.
This commit is contained in:
+12
-3
@@ -68,7 +68,7 @@ class CMockGenerator
|
||||
|
||||
def create_mock_source_file(parsed_stuff)
|
||||
@file_writer.create_file(@mock_name + ".c", @subdir) do |file, filename|
|
||||
create_source_header_section(file, filename)
|
||||
create_source_header_section(file, filename, parsed_stuff[:functions])
|
||||
create_instance_structure(file, parsed_stuff[:functions])
|
||||
create_extern_declarations(file)
|
||||
create_mock_verify_function(file, parsed_stuff[:functions])
|
||||
@@ -120,7 +120,7 @@ class CMockGenerator
|
||||
header << "\n#endif\n"
|
||||
end
|
||||
|
||||
def create_source_header_section(file, filename)
|
||||
def create_source_header_section(file, filename, functions)
|
||||
header_file = (@subdir ? @subdir + '/' : '') + filename.gsub(".c",".h")
|
||||
file << "/* AUTOGENERATED FILE. DO NOT EDIT. */\n"
|
||||
file << "#include <string.h>\n"
|
||||
@@ -132,6 +132,15 @@ class CMockGenerator
|
||||
file << "#include \"#{header_file}\"\n"
|
||||
@includes_c_post_header.each {|inc| file << "#include #{inc}\n"}
|
||||
file << "\n"
|
||||
strs = []
|
||||
functions.each do |func|
|
||||
strs << func[:name]
|
||||
func[:args].each {|arg| strs << arg[:name] }
|
||||
end
|
||||
strs.uniq.sort.each do |str|
|
||||
file << "static const char* CMockString_#{str} = \"#{str}\";\n"
|
||||
end
|
||||
file << "\n"
|
||||
end
|
||||
|
||||
def create_instance_structure(file, functions)
|
||||
@@ -199,7 +208,7 @@ class CMockGenerator
|
||||
file << "#{function_mod_and_rettype} #{function[:name]}(#{args_string})\n"
|
||||
file << "{\n"
|
||||
file << " UNITY_LINE_TYPE cmock_line = TEST_LINE_NUM;\n"
|
||||
file << " UNITY_SET_DETAIL(\"#{function[:name]}\");\n"
|
||||
file << " UNITY_SET_DETAIL(CMockString_#{function[:name]});\n"
|
||||
file << " CMOCK_#{function[:name]}_CALL_INSTANCE* cmock_call_instance = (CMOCK_#{function[:name]}_CALL_INSTANCE*)CMock_Guts_GetAddressFor(Mock.#{function[:name]}_CallInstance);\n"
|
||||
file << " Mock.#{function[:name]}_CallInstance = CMock_Guts_MemNext(Mock.#{function[:name]}_CallInstance);\n"
|
||||
file << @plugins.run(:mock_implementation_precheck, function)
|
||||
|
||||
@@ -81,7 +81,7 @@ class CMockGeneratorPluginExpect
|
||||
|
||||
def mock_verify(function)
|
||||
func_name = function[:name]
|
||||
" UNITY_SET_DETAIL(\"#{function[:name]}\");\n" +
|
||||
" UNITY_SET_DETAIL(CMockString_#{function[:name]});\n" +
|
||||
" UNITY_TEST_ASSERT(CMOCK_GUTS_NONE == Mock.#{func_name}_CallInstance, cmock_line, CMockStringCalledLess);\n"
|
||||
end
|
||||
|
||||
|
||||
@@ -121,7 +121,7 @@ class CMockGeneratorUtils
|
||||
lines = ""
|
||||
lines << " if (!#{ignore})\n" if @ignore_arg
|
||||
lines << " {\n"
|
||||
lines << " UNITY_SET_DETAILS(\"#{function[:name]}\",\"#{arg_name}\");\n"
|
||||
lines << " UNITY_SET_DETAILS(CMockString_#{function[:name]},CMockString_#{arg_name});\n"
|
||||
case(unity_func)
|
||||
when "UNITY_TEST_ASSERT_EQUAL_MEMORY"
|
||||
c_type_local = c_type.gsub(/\*$/,'')
|
||||
@@ -157,7 +157,7 @@ class CMockGeneratorUtils
|
||||
lines = ""
|
||||
lines << " if (!#{ignore})\n" if @ignore_arg
|
||||
lines << " {\n"
|
||||
lines << " UNITY_SET_DETAILS(\"#{function[:name]}\",\"#{arg_name}\");\n"
|
||||
lines << " UNITY_SET_DETAILS(CMockString_#{function[:name]},CMockString_#{arg_name});\n"
|
||||
case(unity_func)
|
||||
when "UNITY_TEST_ASSERT_EQUAL_MEMORY"
|
||||
c_type_local = c_type.gsub(/\*$/,'')
|
||||
@@ -193,7 +193,7 @@ class CMockGeneratorUtils
|
||||
lines = ""
|
||||
lines << " if (!#{ignore})\n" if @ignore_arg
|
||||
lines << " {\n"
|
||||
lines << " UNITY_SET_DETAILS(\"#{function[:name]}\",\"#{arg_name}\");\n"
|
||||
lines << " UNITY_SET_DETAILS(CMockString_#{function[:name]},CMockString_#{arg_name});\n"
|
||||
case(unity_func)
|
||||
when "UNITY_TEST_ASSERT_EQUAL_MEMORY"
|
||||
c_type_local = c_type.gsub(/\*$/,'')
|
||||
|
||||
@@ -267,6 +267,10 @@ describe CMockGenerator, "Verify CMockGenerator Module" do
|
||||
|
||||
it "create a proper heading for a source file" do
|
||||
output = []
|
||||
functions = [ { :name => "uno", :args => [ { :name => "arg1" }, { :name => "arg2" } ] },
|
||||
{ :name => "dos", :args => [ { :name => "arg3" }, { :name => "arg2" } ] },
|
||||
{ :name => "tres", :args => [] }
|
||||
]
|
||||
expected = [ "/* AUTOGENERATED FILE. DO NOT EDIT. */\n",
|
||||
"#include <string.h>\n",
|
||||
"#include <stdlib.h>\n",
|
||||
@@ -274,10 +278,17 @@ describe CMockGenerator, "Verify CMockGenerator Module" do
|
||||
"#include \"unity.h\"\n",
|
||||
"#include \"cmock.h\"\n",
|
||||
"#include \"MockPoutPoutFish.h\"\n",
|
||||
"\n",
|
||||
"static const char* CMockString_arg1 = \"arg1\";\n",
|
||||
"static const char* CMockString_arg2 = \"arg2\";\n",
|
||||
"static const char* CMockString_arg3 = \"arg3\";\n",
|
||||
"static const char* CMockString_dos = \"dos\";\n",
|
||||
"static const char* CMockString_tres = \"tres\";\n",
|
||||
"static const char* CMockString_uno = \"uno\";\n",
|
||||
"\n"
|
||||
]
|
||||
|
||||
@cmock_generator.create_source_header_section(output, "MockPoutPoutFish.c")
|
||||
@cmock_generator.create_source_header_section(output, "MockPoutPoutFish.c", functions)
|
||||
|
||||
assert_equal(expected, output)
|
||||
end
|
||||
@@ -440,7 +451,7 @@ describe CMockGenerator, "Verify CMockGenerator Module" do
|
||||
expected = [ "static int SupaFunction(uint32 sandwiches, const char* named)\n",
|
||||
"{\n",
|
||||
" UNITY_LINE_TYPE cmock_line = TEST_LINE_NUM;\n",
|
||||
" UNITY_SET_DETAIL(\"SupaFunction\");\n",
|
||||
" UNITY_SET_DETAIL(CMockString_SupaFunction);\n",
|
||||
" CMOCK_SupaFunction_CALL_INSTANCE* cmock_call_instance = (CMOCK_SupaFunction_CALL_INSTANCE*)CMock_Guts_GetAddressFor(Mock.SupaFunction_CallInstance);\n",
|
||||
" Mock.SupaFunction_CallInstance = CMock_Guts_MemNext(Mock.SupaFunction_CallInstance);\n",
|
||||
" uno",
|
||||
@@ -474,7 +485,7 @@ describe CMockGenerator, "Verify CMockGenerator Module" do
|
||||
expected = [ "int __stdcall SupaFunction(uint32 sandwiches, corn ...)\n",
|
||||
"{\n",
|
||||
" UNITY_LINE_TYPE cmock_line = TEST_LINE_NUM;\n",
|
||||
" UNITY_SET_DETAIL(\"SupaFunction\");\n",
|
||||
" UNITY_SET_DETAIL(CMockString_SupaFunction);\n",
|
||||
" CMOCK_SupaFunction_CALL_INSTANCE* cmock_call_instance = (CMOCK_SupaFunction_CALL_INSTANCE*)CMock_Guts_GetAddressFor(Mock.SupaFunction_CallInstance);\n",
|
||||
" Mock.SupaFunction_CallInstance = CMock_Guts_MemNext(Mock.SupaFunction_CallInstance);\n",
|
||||
" uno",
|
||||
|
||||
@@ -201,7 +201,7 @@ describe CMockGeneratorPluginExpect, "Verify CMockGeneratorPluginExpect Module"
|
||||
|
||||
it "add mock verify lines" do
|
||||
function = {:name => "Banana" }
|
||||
expected = " UNITY_SET_DETAIL(\"Banana\");\n" +
|
||||
expected = " UNITY_SET_DETAIL(CMockString_Banana);\n" +
|
||||
" UNITY_TEST_ASSERT(CMOCK_GUTS_NONE == Mock.Banana_CallInstance, cmock_line, CMockStringCalledLess);\n"
|
||||
returned = @cmock_generator_plugin_expect.mock_verify(function)
|
||||
assert_equal(expected, returned)
|
||||
|
||||
@@ -205,7 +205,7 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do
|
||||
function = { :name => 'Pear' }
|
||||
arg = test_arg[:int]
|
||||
expected = " {\n" +
|
||||
" UNITY_SET_DETAILS(\"Pear\",\"MyInt\");\n" +
|
||||
" UNITY_SET_DETAILS(CMockString_Pear,CMockString_MyInt);\n" +
|
||||
" UNITY_TEST_ASSERT_EQUAL_INT(cmock_call_instance->Expected_MyInt, MyInt, cmock_line, CMockStringMismatch);\n" +
|
||||
" }\n"
|
||||
@unity_helper.expect :nil?, false
|
||||
@@ -217,7 +217,7 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do
|
||||
function = { :name => 'Pear' }
|
||||
arg = test_arg[:int_ptr]
|
||||
expected = " {\n" +
|
||||
" UNITY_SET_DETAILS(\"Pear\",\"MyIntPtr\");\n" +
|
||||
" UNITY_SET_DETAILS(CMockString_Pear,CMockString_MyIntPtr);\n" +
|
||||
" UNITY_TEST_ASSERT_EQUAL_PTR(cmock_call_instance->Expected_MyIntPtr, MyIntPtr, cmock_line, CMockStringMismatch);\n" +
|
||||
" }\n"
|
||||
assert_equal(expected, @cmock_generator_utils_simple.code_verify_an_arg_expectation(function, arg))
|
||||
@@ -227,7 +227,7 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do
|
||||
function = { :name => 'Pear' }
|
||||
arg = test_arg[:string]
|
||||
expected = " {\n" +
|
||||
" UNITY_SET_DETAILS(\"Pear\",\"MyStr\");\n" +
|
||||
" UNITY_SET_DETAILS(CMockString_Pear,CMockString_MyStr);\n" +
|
||||
" UNITY_TEST_ASSERT_EQUAL_STRING(cmock_call_instance->Expected_MyStr, MyStr, cmock_line, CMockStringMismatch);\n" +
|
||||
" }\n"
|
||||
@unity_helper.expect :nil?, false
|
||||
@@ -239,7 +239,7 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do
|
||||
function = { :name => 'Pear' }
|
||||
arg = test_arg[:mytype]
|
||||
expected = " {\n" +
|
||||
" UNITY_SET_DETAILS(\"Pear\",\"MyMyType\");\n" +
|
||||
" UNITY_SET_DETAILS(CMockString_Pear,CMockString_MyMyType);\n" +
|
||||
" UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)(&cmock_call_instance->Expected_MyMyType), (void*)(&MyMyType), sizeof(MY_TYPE), cmock_line, CMockStringMismatch);\n" +
|
||||
" }\n"
|
||||
@unity_helper.expect :nil?, false
|
||||
@@ -251,7 +251,7 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do
|
||||
function = { :name => 'Pear' }
|
||||
arg = test_arg[:mytype]
|
||||
expected = " {\n" +
|
||||
" UNITY_SET_DETAILS(\"Pear\",\"MyMyType\");\n" +
|
||||
" UNITY_SET_DETAILS(CMockString_Pear,CMockString_MyMyType);\n" +
|
||||
" UNITY_TEST_ASSERT_EQUAL_MY_TYPE(cmock_call_instance->Expected_MyMyType, MyMyType, cmock_line, CMockStringMismatch);\n" +
|
||||
" }\n"
|
||||
@unity_helper.expect :nil?, false
|
||||
@@ -263,7 +263,7 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do
|
||||
function = { :name => 'Pear' }
|
||||
arg = test_arg[:mytype]
|
||||
expected = " {\n" +
|
||||
" UNITY_SET_DETAILS(\"Pear\",\"MyMyType\");\n" +
|
||||
" UNITY_SET_DETAILS(CMockString_Pear,CMockString_MyMyType);\n" +
|
||||
" UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY(&cmock_call_instance->Expected_MyMyType, &MyMyType, 1, cmock_line, CMockStringMismatch);\n" +
|
||||
" }\n"
|
||||
@unity_helper.expect :nil?, false
|
||||
@@ -276,7 +276,7 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do
|
||||
arg = test_arg[:int]
|
||||
expected = " if (!cmock_call_instance->IgnoreArg_MyInt)\n" +
|
||||
" {\n" +
|
||||
" UNITY_SET_DETAILS(\"Pear\",\"MyInt\");\n" +
|
||||
" UNITY_SET_DETAILS(CMockString_Pear,CMockString_MyInt);\n" +
|
||||
" UNITY_TEST_ASSERT_EQUAL_INT(cmock_call_instance->Expected_MyInt, MyInt, cmock_line, CMockStringMismatch);\n" +
|
||||
" }\n"
|
||||
@unity_helper.expect :nil?, false
|
||||
@@ -289,7 +289,7 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do
|
||||
arg = test_arg[:int_ptr]
|
||||
expected = " if (!cmock_call_instance->IgnoreArg_MyIntPtr)\n" +
|
||||
" {\n" +
|
||||
" UNITY_SET_DETAILS(\"Pear\",\"MyIntPtr\");\n" +
|
||||
" UNITY_SET_DETAILS(CMockString_Pear,CMockString_MyIntPtr);\n" +
|
||||
" if (cmock_call_instance->Expected_MyIntPtr == NULL)\n" +
|
||||
" { UNITY_TEST_ASSERT_NULL(MyIntPtr, cmock_line, CMockStringExpNULL); }\n" +
|
||||
" else if (cmock_call_instance->Expected_MyIntPtr_Depth == 0)\n" +
|
||||
@@ -307,7 +307,7 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do
|
||||
arg = test_arg[:string]
|
||||
expected = " if (!cmock_call_instance->IgnoreArg_MyStr)\n" +
|
||||
" {\n" +
|
||||
" UNITY_SET_DETAILS(\"Pear\",\"MyStr\");\n" +
|
||||
" UNITY_SET_DETAILS(CMockString_Pear,CMockString_MyStr);\n" +
|
||||
" UNITY_TEST_ASSERT_EQUAL_STRING(cmock_call_instance->Expected_MyStr, MyStr, cmock_line, CMockStringMismatch);\n" +
|
||||
" }\n"
|
||||
@unity_helper.expect :nil?, false
|
||||
@@ -320,7 +320,7 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do
|
||||
arg = test_arg[:mytype]
|
||||
expected = " if (!cmock_call_instance->IgnoreArg_MyMyType)\n" +
|
||||
" {\n" +
|
||||
" UNITY_SET_DETAILS(\"Pear\",\"MyMyType\");\n" +
|
||||
" UNITY_SET_DETAILS(CMockString_Pear,CMockString_MyMyType);\n" +
|
||||
" if (cmock_call_instance->Expected_MyMyType == NULL)\n" +
|
||||
" { UNITY_TEST_ASSERT_NULL(MyMyType, cmock_line, CMockStringExpNULL); }\n" +
|
||||
" else\n" +
|
||||
@@ -336,7 +336,7 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do
|
||||
arg = test_arg[:mytype]
|
||||
expected = " if (!cmock_call_instance->IgnoreArg_MyMyType)\n" +
|
||||
" {\n" +
|
||||
" UNITY_SET_DETAILS(\"Pear\",\"MyMyType\");\n" +
|
||||
" UNITY_SET_DETAILS(CMockString_Pear,CMockString_MyMyType);\n" +
|
||||
" UNITY_TEST_ASSERT_EQUAL_MY_TYPE(cmock_call_instance->Expected_MyMyType, MyMyType, cmock_line, CMockStringMismatch);\n" +
|
||||
" }\n"
|
||||
@unity_helper.expect :nil?, false
|
||||
@@ -349,7 +349,7 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do
|
||||
arg = test_arg[:mytype_ptr]
|
||||
expected = " if (!cmock_call_instance->IgnoreArg_MyMyTypePtr)\n" +
|
||||
" {\n" +
|
||||
" UNITY_SET_DETAILS(\"Pear\",\"MyMyTypePtr\");\n" +
|
||||
" UNITY_SET_DETAILS(CMockString_Pear,CMockString_MyMyTypePtr);\n" +
|
||||
" if (cmock_call_instance->Expected_MyMyTypePtr == NULL)\n" +
|
||||
" { UNITY_TEST_ASSERT_NULL(MyMyTypePtr, cmock_line, CMockStringExpNULL); }\n" +
|
||||
" else if (cmock_call_instance->Expected_MyMyTypePtr_Depth == 0)\n" +
|
||||
@@ -367,7 +367,7 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do
|
||||
arg = test_arg[:mytype]
|
||||
expected = " if (!cmock_call_instance->IgnoreArg_MyMyType)\n" +
|
||||
" {\n" +
|
||||
" UNITY_SET_DETAILS(\"Pear\",\"MyMyType\");\n" +
|
||||
" UNITY_SET_DETAILS(CMockString_Pear,CMockString_MyMyType);\n" +
|
||||
" UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY(&cmock_call_instance->Expected_MyMyType, &MyMyType, 1, cmock_line, CMockStringMismatch);\n" +
|
||||
" }\n"
|
||||
@unity_helper.expect :nil?, false
|
||||
|
||||
Reference in New Issue
Block a user