diff --git a/lib/cmock_generator.rb b/lib/cmock_generator.rb index 83dcd1d..9e93f10 100644 --- a/lib/cmock_generator.rb +++ b/lib/cmock_generator.rb @@ -23,7 +23,7 @@ class CMockGenerator @includes_h_post_orig_header = (@config.includes_h_post_orig_header || []).map{|h| h =~ /CallOrder == ++GlobalVerifyOrder), cmock_line, \"Out of order function calls. Function '#{function[:name]}'\");\n" end - return_type_cast = function[:return][:const?] ? "(const #{function[:return][:type]})" : '' + return_type = function[:return][:const?] ? "(const #{function[:return][:type]})" : ((function[:return][:type] =~ /cmock/) ? "(#{function[:return][:type]})" : '') file << @plugins.run(:mock_implementation, function) - file << " return #{return_type_cast}cmock_call_instance->ReturnVal;\n" unless (function[:return][:void?]) + file << " return #{return_type}cmock_call_instance->ReturnVal;\n" unless (function[:return][:void?]) file << "}\n\n" end diff --git a/lib/cmock_generator_plugin_callback.rb b/lib/cmock_generator_plugin_callback.rb index 2e05f79..9caacd2 100644 --- a/lib/cmock_generator_plugin_callback.rb +++ b/lib/cmock_generator_plugin_callback.rb @@ -2,19 +2,19 @@ # 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] -# ========================================== +# ========================================== class CMockGeneratorPluginCallback attr_accessor :include_count attr_reader :priority attr_reader :config, :utils - + def initialize(config, utils) @config = config @utils = utils @priority = 6 - + @include_count = @config.callback_include_count if (@config.callback_after_arg_check) alias :mock_implementation :mock_implementation_for_callbacks @@ -54,14 +54,14 @@ class CMockGeneratorPluginCallback when 7 then " return Mock.#{func_name}_CallbackFunctionPointer(#{function[:args].map{|m| m[:name]}.join(', ')}, Mock.#{func_name}_CallbackCalls++);\n }\n" end end - + def nothing(function) return "" end def mock_interfaces(function) func_name = function[:name] - "void #{func_name}_StubWithCallback(CMOCK_#{func_name}_CALLBACK Callback)\n{\n" + + "void #{func_name}_StubWithCallback(CMOCK_#{func_name}_CALLBACK Callback)\n{\n" + " Mock.#{func_name}_CallbackFunctionPointer = Callback;\n}\n\n" end @@ -69,7 +69,7 @@ class CMockGeneratorPluginCallback " Mock.#{function[:name]}_CallbackFunctionPointer = NULL;\n" + " Mock.#{function[:name]}_CallbackCalls = 0;\n" end - + def mock_verify(function) func_name = function[:name] " if (Mock.#{func_name}_CallbackFunctionPointer != NULL)\n Mock.#{func_name}_CallInstance = CMOCK_GUTS_NONE;\n" diff --git a/lib/cmock_generator_plugin_expect_any_args.rb b/lib/cmock_generator_plugin_expect_any_args.rb index 2a3b481..0704527 100644 --- a/lib/cmock_generator_plugin_expect_any_args.rb +++ b/lib/cmock_generator_plugin_expect_any_args.rb @@ -45,8 +45,8 @@ class CMockGeneratorPluginExpectAnyArgs else retval = function[:return].merge( { :name => "cmock_call_instance->ReturnVal"} ) lines << " " + @utils.code_assign_argument_quickly("Mock.#{function[:name]}_FinalReturn", retval) unless (retval[:void?]) - return_type_cast = function[:return][:const?] ? "(const #{function[:return][:type]})" : '' - lines << " return #{return_type_cast}cmock_call_instance->ReturnVal;\n }\n" + return_type = function[:return][:const?] ? "(const #{function[:return][:type]})" : ((function[:return][:type] =~ /cmock/) ? "(#{function[:return][:type]})" : '') + lines << " return #{return_type}cmock_call_instance->ReturnVal;\n }\n" end lines end diff --git a/lib/cmock_generator_plugin_ignore.rb b/lib/cmock_generator_plugin_ignore.rb index 5397393..f031d72 100644 --- a/lib/cmock_generator_plugin_ignore.rb +++ b/lib/cmock_generator_plugin_ignore.rb @@ -39,10 +39,10 @@ class CMockGeneratorPluginIgnore lines << " return;\n }\n" else retval = function[:return].merge( { :name => "cmock_call_instance->ReturnVal"} ) - return_type = function[:return][:const?] ? "const #{function[:return][:type]}" : function[:return][:type] - lines << " if (cmock_call_instance == NULL)\n return (#{return_type})Mock.#{function[:name]}_FinalReturn;\n" + return_type = function[:return][:const?] ? "(const #{function[:return][:type]})" : ((function[:return][:type] =~ /cmock/) ? "(#{function[:return][:type]})" : '') + lines << " if (cmock_call_instance == NULL)\n return #{return_type}Mock.#{function[:name]}_FinalReturn;\n" lines << " " + @utils.code_assign_argument_quickly("Mock.#{function[:name]}_FinalReturn", retval) unless (retval[:void?]) - lines << " return (#{return_type})cmock_call_instance->ReturnVal;\n }\n" + lines << " return #{return_type}cmock_call_instance->ReturnVal;\n }\n" end lines end diff --git a/test/system/test_compilation/parsing.h b/test/system/test_compilation/parsing.h index e1bcb8b..95426e9 100644 --- a/test/system/test_compilation/parsing.h +++ b/test/system/test_compilation/parsing.h @@ -45,3 +45,5 @@ unsigned int ** ptr_ptr_return4(unsigned int ** a); extern unsigned long int incredible_descriptors(register const unsigned short a); int32_t example_c99_type(int32_t param1); + +void I2CIntRegister(uint32_t ui32Base, void (*pfnHandler)(void)); diff --git a/test/unit/cmock_generator_plugin_ignore_test.rb b/test/unit/cmock_generator_plugin_ignore_test.rb index 82e262d..2692e35 100644 --- a/test/unit/cmock_generator_plugin_ignore_test.rb +++ b/test/unit/cmock_generator_plugin_ignore_test.rb @@ -66,9 +66,9 @@ describe CMockGeneratorPluginIgnore, "Verify CMockGeneratorPluginIgnore Module" expected = [" if (Mock.Fungus_IgnoreBool)\n", " {\n", " if (cmock_call_instance == NULL)\n", - " return (int)Mock.Fungus_FinalReturn;\n", + " return Mock.Fungus_FinalReturn;\n", " mock_retval_0", - " return (int)cmock_call_instance->ReturnVal;\n", + " return cmock_call_instance->ReturnVal;\n", " }\n" ].join returned = @cmock_generator_plugin_ignore.mock_implementation_precheck(function) diff --git a/test/unit/cmock_header_parser_test.rb b/test/unit/cmock_header_parser_test.rb index ccde240..c72f027 100644 --- a/test/unit/cmock_header_parser_test.rb +++ b/test/unit/cmock_header_parser_test.rb @@ -1009,6 +1009,29 @@ describe CMockHeaderParser, "Verify CMockHeaderParser Module" do assert_equal(typedefs, result[:typedefs]) end + it "extract functions containing a function pointer with a void" do + source = "void FunkyTurkey(void (*func_ptr)(void))" + expected = [{ :var_arg=>nil, + :return=>{ :type => "void", + :name => 'cmock_to_return', + :ptr? => false, + :const? => false, + :str => "void cmock_to_return", + :void? => true + }, + :name=>"FunkyTurkey", + :modifier=>"", + :contains_ptr? => false, + :args=>[ {:type=>"cmock_module_func_ptr1", :name=>"func_ptr", :ptr? => false, :const? => false} + ], + :args_string=>"cmock_module_func_ptr1 func_ptr", + :args_call=>"func_ptr" }] + typedefs = ["typedef void(*cmock_module_func_ptr1)(void);"] + result = @parser.parse("module", source) + assert_equal(expected, result[:functions]) + assert_equal(typedefs, result[:typedefs]) + end + it "extract functions containing a function pointer with an implied void" do source = "void FunkyTurkey(unsigned int (*func_ptr)())" expected = [{ :var_arg=>nil,