mirror of
https://github.com/ThrowTheSwitch/CMock.git
synced 2026-08-14 07:07:49 +00:00
add first simple test and remove warning "unused parameter"
This commit is contained in:
@@ -2,9 +2,6 @@
|
||||
# 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]
|
||||
#
|
||||
# !!! This file is not included in the original Cmock framework !!!
|
||||
# Adjusted copy of cmock_generator_plugin_ignore.rb
|
||||
# ==========================================
|
||||
|
||||
class CMockGeneratorPluginIgnoreStateless
|
||||
@@ -30,8 +27,8 @@ class CMockGeneratorPluginIgnoreStateless
|
||||
"#define #{function[:name]}_Ignore() #{function[:name]}_CMockIgnore()\n" +
|
||||
"void #{function[:name]}_CMockIgnore(void);\n"
|
||||
else
|
||||
"#define #{function[:name]}_IgnoreAndReturn(cmock_retval) #{function[:name]}_CMockIgnoreAndReturn(__LINE__, cmock_retval)\n" +
|
||||
"void #{function[:name]}_CMockIgnoreAndReturn(UNITY_LINE_TYPE cmock_line, #{function[:return][:str]});\n";
|
||||
"#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
|
||||
@@ -60,12 +57,10 @@ class CMockGeneratorPluginIgnoreStateless
|
||||
lines << if function[:return][:void?]
|
||||
"void #{function[:name]}_CMockIgnore(void)\n{\n"
|
||||
else
|
||||
"void #{function[:name]}_CMockIgnoreAndReturn(UNITY_LINE_TYPE cmock_line, #{function[:return][:str]})\n{\n"
|
||||
"void #{function[:name]}_CMockIgnoreAndReturn(#{function[:return][:str]})\n{\n"
|
||||
end
|
||||
unless function[:return][:void?]
|
||||
lines << " Mock.#{function[:name]}_CallInstance = CMOCK_GUTS_NONE;\n"
|
||||
end
|
||||
unless function[:return][:void?]
|
||||
lines << " Mock.#{function[:name]}_FinalReturn = cmock_to_return;\n"
|
||||
end
|
||||
lines << " Mock.#{function[:name]}_IgnoreBool = (char) 1;\n"
|
||||
|
||||
@@ -17,7 +17,7 @@ class CMockGeneratorUtils
|
||||
@return_thru_ptr = @config.plugins.include? :return_thru_ptr
|
||||
@ignore_arg = @config.plugins.include? :ignore_arg
|
||||
@ignore = @config.plugins.include? :ignore
|
||||
@ignore_stateless = @config.plugins.include? :ignore_stateless # added line
|
||||
@ignore_stateless = @config.plugins.include? :ignore_stateless
|
||||
@treat_as = @config.treat_as
|
||||
@helpers = helpers
|
||||
end
|
||||
@@ -53,7 +53,7 @@ class CMockGeneratorUtils
|
||||
lines << " UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringOutOfMemory);\n"
|
||||
lines << " memset(cmock_call_instance, 0, sizeof(*cmock_call_instance));\n"
|
||||
lines << " Mock.#{func_name}_CallInstance = CMock_Guts_MemChain(Mock.#{func_name}_CallInstance, cmock_guts_index);\n"
|
||||
lines << " Mock.#{func_name}_IgnoreBool = (char)0;\n" if @ignore || @ignore_stateless # altered line
|
||||
lines << " Mock.#{func_name}_IgnoreBool = (char)0;\n" if @ignore || @ignore_stateless
|
||||
lines << " cmock_call_instance->LineNumber = cmock_line;\n"
|
||||
lines << " cmock_call_instance->CallOrder = ++GlobalExpectCount;\n" if @ordered && global_ordering_supported
|
||||
lines << " cmock_call_instance->ExceptionToThrow = CEXCEPTION_NONE;\n" if @cexception
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
---
|
||||
:cmock:
|
||||
:plugins:
|
||||
- 'ignore_stateless'
|
||||
|
||||
:systest:
|
||||
:types: |
|
||||
|
||||
:mockable: |
|
||||
int foo(int a);
|
||||
void bar(int b);
|
||||
|
||||
:source:
|
||||
:header: |
|
||||
int function(int a, int b, int c);
|
||||
:code: |
|
||||
int function(int a, int b, int c)
|
||||
{
|
||||
bar(b);
|
||||
return foo(a) + foo(b) + foo(c);
|
||||
}
|
||||
|
||||
:tests:
|
||||
:common: |
|
||||
void setUp(void) {}
|
||||
void tearDown(void) {}
|
||||
|
||||
:units:
|
||||
- :pass: TRUE
|
||||
:should: 'successfully exercise simple ExpectAndReturn mock calls'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
bar_Expect(2);
|
||||
foo_ExpectAndReturn(1, 10);
|
||||
foo_ExpectAndReturn(2, 20);
|
||||
foo_ExpectAndReturn(3, 30);
|
||||
TEST_ASSERT_EQUAL(60, function(1, 2, 3));
|
||||
}
|
||||
Reference in New Issue
Block a user