add StopIgnore to new plugin

This commit is contained in:
cloudsftp
2020-08-19 11:25:27 +02:00
parent 56faeb935f
commit d304ff273a
4 changed files with 76 additions and 3 deletions
+4 -1
View File
@@ -180,8 +180,11 @@ IgnoreStateless:
This plugin is similar to the Ignore plugin, but the IgnoreAndReturn functions are
stateless. So the Ignored function will always return the last specified return value
and does not queue the return values as the IgnoreAndReturn of the default plugin will.
To stop ignoring a function you can call StopIgnore or simply overwrite the Ignore
(resp. IgnoreAndReturn) with an Expect (resp. ExpectAndReturn).
(resp. IgnoreAndReturn) with an Expect (resp. ExpectAndReturn). Note that calling
Ignore (resp IgnoreAndReturn) will clear your previous called Expect
(resp. ExpectAndReturn), so they are not restored after StopIgnore is called.
You can use this plugin by using `:ignore_stateless` instead of `:ignore` in your
CMock configuration file.
@@ -30,6 +30,11 @@ class CMockGeneratorPluginIgnoreStateless
"#define #{function[:name]}_IgnoreAndReturn(cmock_retval) #{function[:name]}_CMockIgnoreAndReturn(cmock_retval)\n" +
"void #{function[:name]}_CMockIgnoreAndReturn(#{function[:return][:str]});\n";
end
# Add stop ignore function. it does not matter if there are any args
lines << "#define #{function[:name]}_StopIgnore() #{function[:name]}_CMockStopIgnore()\n" \
"void #{function[:name]}_CMockStopIgnore(void);\n"
lines
end
def mock_implementation_precheck(function)
@@ -61,6 +66,11 @@ class CMockGeneratorPluginIgnoreStateless
lines << " Mock.#{function[:name]}_IgnoreBool = (char)1;\n"
lines << "}\n\n"
# Add stop ignore function. it does not matter if there are any args
lines << "void #{function[:name]}_CMockStopIgnore(void)\n{\n"
lines << " Mock.#{function[:name]}_IgnoreBool = (char)0;\n"
lines << "}\n\n"
lines
end
@@ -273,4 +273,53 @@
TEST_ASSERT_EQUAL(60, function(4, 5, 6));
}
# StopIgnore
- :pass: FALSE
:should: 'fail when function is called after ignore is stopped'
:code: |
test()
{
bar_Ignore();
foo_IgnoreAndReturn(10);
function(0, 0, 0);
bar_StopIgnore();
function(0, 0, 0);
}
- :pass: FALSE
:should: 'delete expect after ignore is stopped'
:code: |
test()
{
bar_Ignore();
foo_ExpectAndReturn(0, 40);
foo_ExpectAndReturn(0, 30);
foo_ExpectAndReturn(0, 40);
foo_IgnoreAndReturn(20);
foo_StopIgnore();
TEST_ASSERT_EQUAL(110, function(0, 0, 0)); // THIS SHOULD FAIL
}
- :pass: TRUE
:should: 'delete expected return values after ignore is stopped'
:code: |
test()
{
bar_Ignore();
foo_ExpectAndReturn(0, 40);
foo_ExpectAndReturn(0, 30);
foo_ExpectAndReturn(0, 40);
foo_IgnoreAndReturn(20);
foo_StopIgnore();
foo_ExpectAndReturn(0, 50);
foo_ExpectAndReturn(0, 30);
foo_ExpectAndReturn(0, 40);
TEST_ASSERT_EQUAL(120, function(0, 0, 0));
}
...
@@ -35,7 +35,8 @@ describe CMockGeneratorPluginIgnoreStateless, "Verify CMockGeneratorPluginIgnore
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()\nvoid Mold_CMockIgnore(void);\n"
expected = "#define Mold_Ignore() Mold_CMockIgnore()\nvoid Mold_CMockIgnore(void);\n" +
"#define Mold_StopIgnore() Mold_CMockStopIgnore()\nvoid Mold_CMockStopIgnore(void);\n"
returned = @cmock_generator_plugin_ignore_stateless.mock_function_declarations(function)
assert_equal(expected, returned)
end
@@ -43,7 +44,9 @@ describe CMockGeneratorPluginIgnoreStateless, "Verify CMockGeneratorPluginIgnore
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"
"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
@@ -82,6 +85,10 @@ describe CMockGeneratorPluginIgnoreStateless, "Verify CMockGeneratorPluginIgnore
expected = ["void Slime_CMockIgnore(void)\n",
"{\n",
" Mock.Slime_IgnoreBool = (char)1;\n",
"}\n\n",
"void Slime_CMockStopIgnore(void)\n",
"{\n",
" Mock.Slime_IgnoreBool = (char)0;\n",
"}\n\n"
].join
returned = @cmock_generator_plugin_ignore_stateless.mock_interfaces(function)
@@ -96,6 +103,10 @@ describe CMockGeneratorPluginIgnoreStateless, "Verify CMockGeneratorPluginIgnore
" Mock.Slime_CallInstance = CMOCK_GUTS_NONE;\n",
" Mock.Slime_FinalReturn = cmock_to_return;\n",
" Mock.Slime_IgnoreBool = (char)1;\n",
"}\n\n",
"void Slime_CMockStopIgnore(void)\n",
"{\n",
" Mock.Slime_IgnoreBool = (char)0;\n",
"}\n\n"
].join
returned = @cmock_generator_plugin_ignore_stateless.mock_interfaces(function)