diff --git a/docs/CMock_Summary.md b/docs/CMock_Summary.md index a1bec86..e226551 100644 --- a/docs/CMock_Summary.md +++ b/docs/CMock_Summary.md @@ -209,14 +209,16 @@ where `CMOCK_func_CALLBACK` looks like: `retval func(params, int NumCalls)` You can choose from two options: -* `func_CheckWithCallback` tells the mock to check its arguments and calling +* `func_AddCallback` tells the mock to check its arguments and calling order (based on any Expects you've set up) before calling the callback. -* `func_IgnoreWithCallback` tells the mock to skip all the normal checks (just -like Ignore) and jump directly to the callback instead. +* `func_Stub` tells the mock to skip all the normal checks and jump directly +to the callback instead. In this case, you are replacing the normal mock calls +with your own custom stub function. There is also an older name, `func_StubWithCallback`, which is just an alias for either `func_CheckWithCallback` or `func_IgnoreWithCallback` depending on -setting of the `:callback_after_arg_check` toggle. +setting of the `:callback_after_arg_check` toggle. This is deprecated and we +recommend using the two options above. Cexception: diff --git a/lib/cmock_generator_plugin_callback.rb b/lib/cmock_generator_plugin_callback.rb index 02ea990..564e0ac 100644 --- a/lib/cmock_generator_plugin_callback.rb +++ b/lib/cmock_generator_plugin_callback.rb @@ -20,7 +20,7 @@ class CMockGeneratorPluginCallback def instance_structure(function) func_name = function[:name] - " int #{func_name}_IgnoreWithCallbackBool;\n" \ + " int #{func_name}_CallbackBool;\n" \ " CMOCK_#{func_name}_CALLBACK #{func_name}_CallbackFunctionPointer;\n" \ " int #{func_name}_CallbackCalls;\n" end @@ -28,13 +28,13 @@ class CMockGeneratorPluginCallback def mock_function_declarations(function) func_name = function[:name] return_type = function[:return][:type] - action = @config.callback_after_arg_check ? 'Check' : 'Ignore' + action = @config.callback_after_arg_check ? 'AddCallback' : 'Stub' style = (@include_count ? 1 : 0) | (function[:args].empty? ? 0 : 2) styles = [ "void", "int cmock_num_calls", function[:args_string], "#{function[:args_string]}, int cmock_num_calls" ] "typedef #{return_type} (* CMOCK_#{func_name}_CALLBACK)(#{styles[style]});\n" \ - "void #{func_name}_CheckWithCallback(CMOCK_#{func_name}_CALLBACK Callback);\n" \ - "void #{func_name}_IgnoreWithCallback(CMOCK_#{func_name}_CALLBACK Callback);\n" \ - "#define #{func_name}_StubWithCallback #{func_name}_#{action}WithCallback\n" + "void #{func_name}_AddCallback(CMOCK_#{func_name}_CALLBACK Callback);\n" \ + "void #{func_name}_Stub(CMOCK_#{func_name}_CALLBACK Callback);\n" \ + "#define #{func_name}_StubWithCallback #{func_name}_#{action}\n" end def generate_call(function) @@ -53,7 +53,7 @@ class CMockGeneratorPluginCallback end def mock_implementation_precheck(function) - " if (Mock.#{function[:name]}_IgnoreWithCallbackBool &&\n" \ + " if (!Mock.#{function[:name]}_CallbackBool &&\n" \ " Mock.#{function[:name]}_CallbackFunctionPointer != NULL)\n {\n" + if function[:return][:void?] " #{generate_call(function)};\n" \ @@ -70,13 +70,13 @@ class CMockGeneratorPluginCallback func_name = function[:name] has_ignore = @config.plugins.include? :ignore lines = "" - lines << "void #{func_name}_CheckWithCallback(CMOCK_#{func_name}_CALLBACK Callback)\n{\n" + lines << "void #{func_name}_AddCallback(CMOCK_#{func_name}_CALLBACK Callback)\n{\n" lines << " Mock.#{func_name}_IgnoreBool = (int)0;\n" if has_ignore - lines << " Mock.#{func_name}_IgnoreWithCallbackBool = (int)0;\n" + lines << " Mock.#{func_name}_CallbackBool = (int)1;\n" lines << " Mock.#{func_name}_CallbackFunctionPointer = Callback;\n}\n\n" - lines << "void #{func_name}_IgnoreWithCallback(CMOCK_#{func_name}_CALLBACK Callback)\n{\n" + lines << "void #{func_name}_Stub(CMOCK_#{func_name}_CALLBACK Callback)\n{\n" lines << " Mock.#{func_name}_IgnoreBool = (int)0;\n" if has_ignore - lines << " Mock.#{func_name}_IgnoreWithCallbackBool = (int)1;\n" + lines << " Mock.#{func_name}_CallbackBool = (int)0;\n" lines << " Mock.#{func_name}_CallbackFunctionPointer = Callback;\n}\n\n" end diff --git a/test/unit/cmock_generator_plugin_callback_test.rb b/test/unit/cmock_generator_plugin_callback_test.rb index 6fc0a60..e2ea60b 100644 --- a/test/unit/cmock_generator_plugin_callback_test.rb +++ b/test/unit/cmock_generator_plugin_callback_test.rb @@ -32,7 +32,7 @@ describe CMockGeneratorPluginCallback, "Verify CMockGeneratorPluginCallback Modu it "add to instance structure" do function = {:name => "Oak", :args => [:type => "int*", :name => "blah", :ptr? => true], :return => test_return[:int_ptr]} - expected = " int Oak_IgnoreWithCallbackBool;\n" + + expected = " int Oak_CallbackBool;\n" + " CMOCK_Oak_CALLBACK Oak_CallbackFunctionPointer;\n" + " int Oak_CallbackCalls;\n" returned = @cmock_generator_plugin_callback.instance_structure(function) @@ -42,9 +42,9 @@ describe CMockGeneratorPluginCallback, "Verify CMockGeneratorPluginCallback Modu it "add mock function declaration for function without arguments" do function = {:name => "Maple", :args_string => "void", :args => [], :return => test_return[:void]} expected = [ "typedef void (* CMOCK_Maple_CALLBACK)(int cmock_num_calls);\n", - "void Maple_CheckWithCallback(CMOCK_Maple_CALLBACK Callback);\n", - "void Maple_IgnoreWithCallback(CMOCK_Maple_CALLBACK Callback);\n", - "#define Maple_StubWithCallback Maple_IgnoreWithCallback\n" ].join + "void Maple_AddCallback(CMOCK_Maple_CALLBACK Callback);\n", + "void Maple_Stub(CMOCK_Maple_CALLBACK Callback);\n", + "#define Maple_StubWithCallback Maple_Stub\n" ].join returned = @cmock_generator_plugin_callback.mock_function_declarations(function) assert_equal(expected, returned) end @@ -52,9 +52,9 @@ describe CMockGeneratorPluginCallback, "Verify CMockGeneratorPluginCallback Modu it "add mock function declaration for function without arguments when count is also turned off" do function = {:name => "Maple", :args_string => "void", :args => [], :return => test_return[:void]} expected = [ "typedef void (* CMOCK_Maple_CALLBACK)(void);\n", - "void Maple_CheckWithCallback(CMOCK_Maple_CALLBACK Callback);\n", - "void Maple_IgnoreWithCallback(CMOCK_Maple_CALLBACK Callback);\n", - "#define Maple_StubWithCallback Maple_IgnoreWithCallback\n" ].join + "void Maple_AddCallback(CMOCK_Maple_CALLBACK Callback);\n", + "void Maple_Stub(CMOCK_Maple_CALLBACK Callback);\n", + "#define Maple_StubWithCallback Maple_Stub\n" ].join @cmock_generator_plugin_callback.include_count = false returned = @cmock_generator_plugin_callback.mock_function_declarations(function) assert_equal(expected, returned) @@ -63,9 +63,9 @@ describe CMockGeneratorPluginCallback, "Verify CMockGeneratorPluginCallback Modu it "add mock function declaration for function with arguments" do function = {:name => "Maple", :args_string => "int* tofu", :args => [1], :return => test_return[:void]} expected = [ "typedef void (* CMOCK_Maple_CALLBACK)(int* tofu, int cmock_num_calls);\n", - "void Maple_CheckWithCallback(CMOCK_Maple_CALLBACK Callback);\n", - "void Maple_IgnoreWithCallback(CMOCK_Maple_CALLBACK Callback);\n", - "#define Maple_StubWithCallback Maple_IgnoreWithCallback\n" ].join + "void Maple_AddCallback(CMOCK_Maple_CALLBACK Callback);\n", + "void Maple_Stub(CMOCK_Maple_CALLBACK Callback);\n", + "#define Maple_StubWithCallback Maple_Stub\n" ].join returned = @cmock_generator_plugin_callback.mock_function_declarations(function) assert_equal(expected, returned) end @@ -73,9 +73,9 @@ describe CMockGeneratorPluginCallback, "Verify CMockGeneratorPluginCallback Modu it "add mock function declaration for function with return values" do function = {:name => "Maple", :args_string => "int* tofu", :args => [1], :return => test_return[:string]} expected = [ "typedef const char* (* CMOCK_Maple_CALLBACK)(int* tofu, int cmock_num_calls);\n", - "void Maple_CheckWithCallback(CMOCK_Maple_CALLBACK Callback);\n", - "void Maple_IgnoreWithCallback(CMOCK_Maple_CALLBACK Callback);\n", - "#define Maple_StubWithCallback Maple_IgnoreWithCallback\n" ].join + "void Maple_AddCallback(CMOCK_Maple_CALLBACK Callback);\n", + "void Maple_Stub(CMOCK_Maple_CALLBACK Callback);\n", + "#define Maple_StubWithCallback Maple_Stub\n" ].join returned = @cmock_generator_plugin_callback.mock_function_declarations(function) assert_equal(expected, returned) end @@ -83,9 +83,9 @@ describe CMockGeneratorPluginCallback, "Verify CMockGeneratorPluginCallback Modu it "add mock function declaration for function with return values and count is turned off" do function = {:name => "Maple", :args_string => "int* tofu", :args => [1], :return => test_return[:string]} expected = [ "typedef const char* (* CMOCK_Maple_CALLBACK)(int* tofu);\n", - "void Maple_CheckWithCallback(CMOCK_Maple_CALLBACK Callback);\n", - "void Maple_IgnoreWithCallback(CMOCK_Maple_CALLBACK Callback);\n", - "#define Maple_StubWithCallback Maple_IgnoreWithCallback\n" ].join + "void Maple_AddCallback(CMOCK_Maple_CALLBACK Callback);\n", + "void Maple_Stub(CMOCK_Maple_CALLBACK Callback);\n", + "#define Maple_StubWithCallback Maple_Stub\n" ].join @cmock_generator_plugin_callback.include_count = false returned = @cmock_generator_plugin_callback.mock_function_declarations(function) assert_equal(expected, returned) @@ -173,7 +173,7 @@ describe CMockGeneratorPluginCallback, "Verify CMockGeneratorPluginCallback Modu it "add mock function implementation for functions without arg check and of style 'void func(void)' when count turned off" do function = {:name => "Apple", :args => [], :args_string => "void", :return => test_return[:void]} - expected = [" if (Mock.Apple_IgnoreWithCallbackBool &&\n", + expected = [" if (!Mock.Apple_CallbackBool &&\n", " Mock.Apple_CallbackFunctionPointer != NULL)\n", " {\n", " Mock.Apple_CallbackFunctionPointer();\n", @@ -188,7 +188,7 @@ describe CMockGeneratorPluginCallback, "Verify CMockGeneratorPluginCallback Modu it "add mock function implementation for functions without arg check and of style 'int func(void)'" do function = {:name => "Apple", :args => [], :args_string => "void", :return => test_return[:int]} - expected = [" if (Mock.Apple_IgnoreWithCallbackBool &&\n", + expected = [" if (!Mock.Apple_CallbackBool &&\n", " Mock.Apple_CallbackFunctionPointer != NULL)\n", " {\n", " int ret = Mock.Apple_CallbackFunctionPointer(Mock.Apple_CallbackCalls++);\n", @@ -206,7 +206,7 @@ describe CMockGeneratorPluginCallback, "Verify CMockGeneratorPluginCallback Modu { :type => 'uint8_t', :name => 'flag', :ptr? => false} ], :args_string => "int* steak, uint8_t flag", :return=> test_return[:void]} - expected = [" if (Mock.Apple_IgnoreWithCallbackBool &&\n", + expected = [" if (!Mock.Apple_CallbackBool &&\n", " Mock.Apple_CallbackFunctionPointer != NULL)\n", " {\n", " Mock.Apple_CallbackFunctionPointer(steak, flag, Mock.Apple_CallbackCalls++);\n", @@ -224,7 +224,7 @@ describe CMockGeneratorPluginCallback, "Verify CMockGeneratorPluginCallback Modu { :type => 'uint8_t', :name => 'flag', :ptr? => false} ], :args_string => "int* steak, uint8_t flag", :return=> test_return[:void]} - expected = [" if (Mock.Apple_IgnoreWithCallbackBool &&\n", + expected = [" if (!Mock.Apple_CallbackBool &&\n", " Mock.Apple_CallbackFunctionPointer != NULL)\n", " {\n", " Mock.Apple_CallbackFunctionPointer(steak, flag);\n", @@ -243,7 +243,7 @@ describe CMockGeneratorPluginCallback, "Verify CMockGeneratorPluginCallback Modu { :type => 'uint8_t', :name => 'flag', :ptr? => false} ], :args_string => "int* steak, uint8_t flag", :return => test_return[:int]} - expected = [" if (Mock.Apple_IgnoreWithCallbackBool &&\n", + expected = [" if (!Mock.Apple_CallbackBool &&\n", " Mock.Apple_CallbackFunctionPointer != NULL)\n", " {\n", " int ret = Mock.Apple_CallbackFunctionPointer(steak, flag, Mock.Apple_CallbackCalls++);\n", @@ -262,16 +262,16 @@ describe CMockGeneratorPluginCallback, "Verify CMockGeneratorPluginCallback Modu :return => test_return[:int] } - expected = ["void Lemon_CheckWithCallback(CMOCK_Lemon_CALLBACK Callback)\n", + expected = ["void Lemon_AddCallback(CMOCK_Lemon_CALLBACK Callback)\n", "{\n", " Mock.Lemon_IgnoreBool = (int)0;\n", - " Mock.Lemon_IgnoreWithCallbackBool = (int)0;\n", + " Mock.Lemon_CallbackBool = (int)1;\n", " Mock.Lemon_CallbackFunctionPointer = Callback;\n", "}\n\n", - "void Lemon_IgnoreWithCallback(CMOCK_Lemon_CALLBACK Callback)\n", + "void Lemon_Stub(CMOCK_Lemon_CALLBACK Callback)\n", "{\n", " Mock.Lemon_IgnoreBool = (int)0;\n", - " Mock.Lemon_IgnoreWithCallbackBool = (int)1;\n", + " Mock.Lemon_CallbackBool = (int)0;\n", " Mock.Lemon_CallbackFunctionPointer = Callback;\n", "}\n\n" ].join