From 6f2a234dcaf9e2c02e743ce048ab97ba4d571aff Mon Sep 17 00:00:00 2001 From: Roland Stahn Date: Fri, 13 Jun 2025 11:35:32 +0200 Subject: [PATCH] Add tests with 'create_error_stubs' set to false --- ...erator_no_error_stubs_plugin_array_test.rb | 87 +++++++++++++++++++ ...error_stubs_plugin_expect_any_args_test.rb | 38 ++++++++ ...rator_no_error_stubs_plugin_expect_test.rb | 54 ++++++++++++ ...rror_stubs_plugin_ignore_stateless_test.rb | 42 +++++++++ ...rator_no_error_stubs_plugin_ignore_test.rb | 42 +++++++++ 5 files changed, 263 insertions(+) create mode 100644 test/unit/cmock_generator_no_error_stubs_plugin_array_test.rb create mode 100644 test/unit/cmock_generator_no_error_stubs_plugin_expect_any_args_test.rb create mode 100644 test/unit/cmock_generator_no_error_stubs_plugin_expect_test.rb create mode 100644 test/unit/cmock_generator_no_error_stubs_plugin_ignore_stateless_test.rb create mode 100644 test/unit/cmock_generator_no_error_stubs_plugin_ignore_test.rb diff --git a/test/unit/cmock_generator_no_error_stubs_plugin_array_test.rb b/test/unit/cmock_generator_no_error_stubs_plugin_array_test.rb new file mode 100644 index 0000000..50ae54a --- /dev/null +++ b/test/unit/cmock_generator_no_error_stubs_plugin_array_test.rb @@ -0,0 +1,87 @@ +# ========================================================================= +# CMock - Automatic Mock Generation for C +# ThrowTheSwitch.org +# Copyright (c) 2007-25 Mike Karlesky, Mark VanderVoord, & Greg Williams +# SPDX-License-Identifier: MIT +# ========================================================================= + +require File.expand_path(File.dirname(__FILE__)) + "/../test_helper" +require File.expand_path(File.dirname(__FILE__)) + '/../../lib/cmock_generator_plugin_array' +require File.expand_path(File.dirname(__FILE__)) + '/../../lib/cmock_generator_utils' + +class UtilsStub + def helpers + {} + end + def arg_type_with_const(arg) + CMockGeneratorUtils.arg_type_with_const(arg) + end + def code_add_base_expectation(func) + "mock_retval_0" + end +end + +describe CMockGeneratorPluginArray, "Verify Generation Of Mock Function Declarations Without Error Stubs By CMockPGeneratorluginArray Module" do + before do + #no strict ordering + @config = create_stub( + :when_ptr => :compare_data, + :enforce_strict_ordering => false, + :respond_to? => true, + :create_error_stubs => false) + + @utils = UtilsStub.new + + @cmock_generator_plugin_array = CMockGeneratorPluginArray.new(@config, @utils) + end + + after do + end + + it "add another mock function declaration for functions of style 'void func(int* tofu)'" do + function = {:name => "Pine", + :args => [{ :type => "int*", + :name => "tofu", + :ptr? => true, + }], + :return => test_return[:void], + :contains_ptr? => true } + + expected = "#define #{function[:name]}_ExpectWithArray(tofu, tofu_Depth) #{function[:name]}_CMockExpectWithArray(__LINE__, tofu, (tofu_Depth))\n" + + "void #{function[:name]}_CMockExpectWithArray(UNITY_LINE_TYPE cmock_line, int* tofu, int tofu_Depth);\n" + returned = @cmock_generator_plugin_array.mock_function_declarations(function) + assert_equal(expected, returned) + end + + it "add another mock function declaration for functions of style 'const char* func(int* tofu)'" do + function = {:name => "Pine", + :args => [{ :type => "int*", + :name => "tofu", + :ptr? => true, + }], + :return => test_return[:string], + :contains_ptr? => true } + + expected = "#define #{function[:name]}_ExpectWithArrayAndReturn(tofu, tofu_Depth, cmock_retval) #{function[:name]}_CMockExpectWithArrayAndReturn(__LINE__, tofu, (tofu_Depth), cmock_retval)\n" + + "void #{function[:name]}_CMockExpectWithArrayAndReturn(UNITY_LINE_TYPE cmock_line, int* tofu, int tofu_Depth, const char* cmock_to_return);\n" + returned = @cmock_generator_plugin_array.mock_function_declarations(function) + assert_equal(expected, returned) + end + + it "add another mock function declaration for functions of style 'const char* func(const int* tofu)'" do + function = {:name => "Pine", + :args => [{ :type => "const int*", + :name => "tofu", + :ptr? => true, + :const? => true, + }], + :return => test_return[:string], + :contains_ptr? => true } + + expected = "#define #{function[:name]}_ExpectWithArrayAndReturn(tofu, tofu_Depth, cmock_retval) #{function[:name]}_CMockExpectWithArrayAndReturn(__LINE__, tofu, (tofu_Depth), cmock_retval)\n" + + "void #{function[:name]}_CMockExpectWithArrayAndReturn(UNITY_LINE_TYPE cmock_line, const int* tofu, int tofu_Depth, const char* cmock_to_return);\n" + returned = @cmock_generator_plugin_array.mock_function_declarations(function) + assert_equal(expected, returned) + end + +end diff --git a/test/unit/cmock_generator_no_error_stubs_plugin_expect_any_args_test.rb b/test/unit/cmock_generator_no_error_stubs_plugin_expect_any_args_test.rb new file mode 100644 index 0000000..3de4226 --- /dev/null +++ b/test/unit/cmock_generator_no_error_stubs_plugin_expect_any_args_test.rb @@ -0,0 +1,38 @@ +# ========================================================================= +# CMock - Automatic Mock Generation for C +# ThrowTheSwitch.org +# Copyright (c) 2007-25 Mike Karlesky, Mark VanderVoord, & Greg Williams +# SPDX-License-Identifier: MIT +# ========================================================================= + +require File.expand_path(File.dirname(__FILE__)) + "/../test_helper" +require File.expand_path(File.dirname(__FILE__)) + '/../../lib/cmock_generator_plugin_expect_any_args.rb' + +describe CMockGeneratorPluginExpectAnyArgs, "Verify Generation Of Mock Function Declarations Without Error Stubs By CMockGeneratorPluginExpectAnyArgs Module" do + + before do + create_mocks :config, :utils + @config = create_stub(:respond_to? => true, :create_error_stubs => false) + @cmock_generator_plugin_expect_any_args = CMockGeneratorPluginExpectAnyArgs.new(@config, @utils) + end + + after do + end + + it "handle function declarations for functions without return values" do + function = {:name => "Mold", :args_string => "int meh", :args => [ :stuff ], :return => test_return[:void]} + expected = "#define Mold_ExpectAnyArgs() Mold_CMockExpectAnyArgs(__LINE__)\n"+ + "void Mold_CMockExpectAnyArgs(UNITY_LINE_TYPE cmock_line);\n" + returned = @cmock_generator_plugin_expect_any_args.mock_function_declarations(function) + assert_equal(expected, returned) + end + + it "handle function declarations for functions that returns something" do + function = {:name => "Fungus", :args_string => "int meh", :args => [ :stuff ], :return => test_return[:string]} + expected = "#define Fungus_ExpectAnyArgsAndReturn(cmock_retval) Fungus_CMockExpectAnyArgsAndReturn(__LINE__, cmock_retval)\n"+ + "void Fungus_CMockExpectAnyArgsAndReturn(UNITY_LINE_TYPE cmock_line, const char* cmock_to_return);\n" + returned = @cmock_generator_plugin_expect_any_args.mock_function_declarations(function) + assert_equal(expected, returned) + end + +end diff --git a/test/unit/cmock_generator_no_error_stubs_plugin_expect_test.rb b/test/unit/cmock_generator_no_error_stubs_plugin_expect_test.rb new file mode 100644 index 0000000..795fa57 --- /dev/null +++ b/test/unit/cmock_generator_no_error_stubs_plugin_expect_test.rb @@ -0,0 +1,54 @@ +# ========================================================================= +# CMock - Automatic Mock Generation for C +# ThrowTheSwitch.org +# Copyright (c) 2007-25 Mike Karlesky, Mark VanderVoord, & Greg Williams +# SPDX-License-Identifier: MIT +# ========================================================================= + +require File.expand_path(File.dirname(__FILE__)) + "/../test_helper" +require File.expand_path(File.dirname(__FILE__)) + '/../../lib/cmock_generator_plugin_expect' + +describe CMockGeneratorPluginExpect, "Verify Generation Of Mock Function Declarations Without Error Stubs By CMockGeneratorPluginExpect Module" do + + before do + create_mocks :config, :utils + + @config = create_stub( + :when_ptr => :compare_data, + :enforce_strict_ordering => false, + :respond_to? => true, + :create_error_stubs => false, + :plugins => [ :expect ] ) + + @utils.expect :helpers, {} + @cmock_generator_plugin_expect = CMockGeneratorPluginExpect.new(@config, @utils) + end + + after do + end + + it "add mock function declarations for functions of style 'void func(void)'" do + function = {:name => "Maple", :args => [], :return => test_return[:void]} + expected = "#define Maple_Expect() Maple_CMockExpect(__LINE__)\n" + + "void Maple_CMockExpect(UNITY_LINE_TYPE cmock_line);\n" + returned = @cmock_generator_plugin_expect.mock_function_declarations(function) + assert_equal(expected, returned) + end + + it "add mock function declarations for functions of style 'int func(void)'" do + function = {:name => "Spruce", :args => [], :return => test_return[:int]} + expected = "#define Spruce_ExpectAndReturn(cmock_retval) Spruce_CMockExpectAndReturn(__LINE__, cmock_retval)\n" + + "void Spruce_CMockExpectAndReturn(UNITY_LINE_TYPE cmock_line, int cmock_to_return);\n" + returned = @cmock_generator_plugin_expect.mock_function_declarations(function) + assert_equal(expected, returned) + end + + it "add mock function declarations for functions of style 'const char* func(int tofu)'" do + function = {:name => "Pine", :args => ["int tofu"], :args_string => "int tofu", :args_call => 'tofu', :return => test_return[:string]} + expected = "#define Pine_ExpectAndReturn(tofu, cmock_retval) Pine_CMockExpectAndReturn(__LINE__, tofu, cmock_retval)\n" + + "void Pine_CMockExpectAndReturn(UNITY_LINE_TYPE cmock_line, int tofu, const char* cmock_to_return);\n" + returned = @cmock_generator_plugin_expect.mock_function_declarations(function) + assert_equal(expected, returned) + end + +end diff --git a/test/unit/cmock_generator_no_error_stubs_plugin_ignore_stateless_test.rb b/test/unit/cmock_generator_no_error_stubs_plugin_ignore_stateless_test.rb new file mode 100644 index 0000000..62464aa --- /dev/null +++ b/test/unit/cmock_generator_no_error_stubs_plugin_ignore_stateless_test.rb @@ -0,0 +1,42 @@ +# ========================================================================= +# CMock - Automatic Mock Generation for C +# ThrowTheSwitch.org +# Copyright (c) 2007-25 Mike Karlesky, Mark VanderVoord, & Greg Williams +# SPDX-License-Identifier: MIT +# ========================================================================= + +require File.expand_path(File.dirname(__FILE__)) + "/../test_helper" +require File.expand_path(File.dirname(__FILE__)) + '/../../lib/cmock_generator_plugin_ignore_stateless' + +describe CMockGeneratorPluginIgnoreStateless, "Verify Generation Of Mock Function Declarations Without Error Stubs By CMockGeneratorPluginIgnoreStateless Module" do + + before do + create_mocks :config, :utils + @config = create_stub(:respond_to? => true, :create_error_stubs => false) + @cmock_generator_plugin_ignore_stateless = CMockGeneratorPluginIgnoreStateless.new(@config, @utils) + end + + after do + end + + it "handle function declarations for functions without return values" do + function = {:name => "Mold", :args_string => "void", :return => test_return[:void]} + expected = "#define Mold_Ignore() Mold_CMockIgnore()\n" + + "void Mold_CMockIgnore(void);\n" + + "#define Mold_StopIgnore() Mold_CMockStopIgnore()\n" + + "void Mold_CMockStopIgnore(void);\n" + returned = @cmock_generator_plugin_ignore_stateless.mock_function_declarations(function) + assert_equal(expected, returned) + end + + it "handle function declarations for functions that returns something" do + function = {:name => "Fungus", :args_string => "void", :return => test_return[:string]} + expected = "#define Fungus_IgnoreAndReturn(cmock_retval) Fungus_CMockIgnoreAndReturn(cmock_retval)\n"+ + "void Fungus_CMockIgnoreAndReturn(const char* cmock_to_return);\n" + + "#define Fungus_StopIgnore() Fungus_CMockStopIgnore()\n"+ + "void Fungus_CMockStopIgnore(void);\n" + returned = @cmock_generator_plugin_ignore_stateless.mock_function_declarations(function) + assert_equal(expected, returned) + end + +end diff --git a/test/unit/cmock_generator_no_error_stubs_plugin_ignore_test.rb b/test/unit/cmock_generator_no_error_stubs_plugin_ignore_test.rb new file mode 100644 index 0000000..97ed8d8 --- /dev/null +++ b/test/unit/cmock_generator_no_error_stubs_plugin_ignore_test.rb @@ -0,0 +1,42 @@ +# ========================================================================= +# CMock - Automatic Mock Generation for C +# ThrowTheSwitch.org +# Copyright (c) 2007-25 Mike Karlesky, Mark VanderVoord, & Greg Williams +# SPDX-License-Identifier: MIT +# ========================================================================= + +require File.expand_path(File.dirname(__FILE__)) + "/../test_helper" +require File.expand_path(File.dirname(__FILE__)) + '/../../lib/cmock_generator_plugin_ignore' + +describe CMockGeneratorPluginIgnore, "Verify Generation Of Mock Function Declarations Without Error Stubs By CMockGeneratorPluginIgnore Module" do + + before do + create_mocks :config, :utils + @config = create_stub(:respond_to? => true, :create_error_stubs => false) + @cmock_generator_plugin_ignore = CMockGeneratorPluginIgnore.new(@config, @utils) + end + + after do + end + + it "handle function declarations for functions without return values" do + function = {:name => "Mold", :args_string => "void", :return => test_return[:void]} + expected = "#define Mold_Ignore() Mold_CMockIgnore()\n" + + "void Mold_CMockIgnore(void);\n" + + "#define Mold_StopIgnore() Mold_CMockStopIgnore()\n" + + "void Mold_CMockStopIgnore(void);\n" + returned = @cmock_generator_plugin_ignore.mock_function_declarations(function) + assert_equal(expected, returned) + end + + it "handle function declarations for functions that returns something" do + function = {:name => "Fungus", :args_string => "void", :return => test_return[:string]} + expected = "#define Fungus_IgnoreAndReturn(cmock_retval) Fungus_CMockIgnoreAndReturn(__LINE__, cmock_retval)\n"+ + "void Fungus_CMockIgnoreAndReturn(UNITY_LINE_TYPE cmock_line, const char* cmock_to_return);\n" + + "#define Fungus_StopIgnore() Fungus_CMockStopIgnore()\n"+ + "void Fungus_CMockStopIgnore(void);\n" + returned = @cmock_generator_plugin_ignore.mock_function_declarations(function) + assert_equal(expected, returned) + end + +end