* added callback plugin

* cleaned up plugin prioritization
* updated plain docs

git-svn-id: http://cmock.svn.sourceforge.net/svnroot/cmock/trunk@148 bf332499-1b4d-0410-844d-d2d48d5cc64c
This commit is contained in:
mvandervoord
2009-12-04 18:52:59 +00:00
parent eee379f611
commit 06ef8bb221
18 changed files with 465 additions and 163 deletions
Binary file not shown.
Binary file not shown.
-102
View File
@@ -1,102 +0,0 @@
Running CMock
=============
CMock is a Ruby script and class. You can therefore use it directly from the command line,
or include it in your own scripts or rakefiles.
Mocking from the Command Line
-----------------------------
After unpacking CMock, you will find CMock.rb in the 'lib' directory. This is the file
that you want to run. It takes a list of header files to be mocked, as well as an optional
yaml file for a more detailed configuration (see config options below).
For example, this will create three mocks using the configuration specified in MyConfig.yml:
ruby cmock.rb -oMyConfig.yml super.h duper.h awesome.h
And this will create two mocks using the default configuration:
ruby cmock.rb ../mocking/stuff/is/fun.h ../try/it/yourself.h
Mocking From Scripts or Rake
----------------------------
CMock can be used directly from your own scripts or from a rakefile. Start by including
cmock.rb, then create an instance of CMock. When you create your instance, you may
initialize it in one of three ways.
You may specify nothing, allowing it to run with default settings:
cmock = CMock.new
You may specify a YAML file containing the configuration options you desire:
cmock = CMock.new('../MyConfig.yml')
You may specify the options explicitly:
cmock = CMock.new('plugins' => ['cexception','ignore'],'mock_path' => 'my/mocks/')
Config Options:
---------------
The following configuration options can be specified in the yaml file or directly when instantiating.
Option Purpose
----------------------------------------------------------------
plugins An array of which plugins to enable. 'expect' is always active.
'cexception' and 'ignore' are also currently available.
mock_path The directory where you would like the mock files generated to
be placed.
includes An array of additional include files which should be added to the
mocks. Useful for global types and definitions used in your project.
tab What does tab mean in your project? By default: a pair of spaces.
expect_call_count_type Used internally by CMock... but maybe you don't like int's for
some reason?
ignore_bool_type Used internally by Ignore plugin... but maybe you have a better
bool type?
cexception_include Tell cexception plugin where to find Exception.h... only need to
define if it's not in your build path already.
cexception_throw_type Tell cexception what type you are “throwing” around in your
application. It assumes an int
CMock Generated Mock Module Summary
===================================
In addition to the mocks themselves, CMock will generate the following functions for use in
your tests. The expect functions are always generated. While the ignore and cexception
functions are only generated if those plugins are enabled:
Original Function => Generated Expect Functions
-------------------------------------------------
void func(void) => void func_Expect(void)
void func(params) => void func_Expect(expected_params)
retval func(void) => void func_ExpectAndReturn(retval_to_return)
retval func(params) => void func_ExpectAndReturn(expected_params, retval_to_return)
Original Function => Generated CException Functions
-----------------------------------------------------
void func(void) => void func_ExpectAndThrow(value_to_throw)
void func(params) => void func_ExpectAndThrow(expected_params, value_to_throw)
retval func(void) => void func_ExpectAndThrow(value_to_throw)
retval func(params) => void func_ExpectAndThrow(expected_params, value_to_throw)
Original Function => Generated Ignore Functions
-------------------------------------------------
void func(void) => void func_Ignore(void)
void func(params) => void func_Ignore(void)
retval func(void) => void func_IgnoreAndReturn(retval_to_return)
retval func(params) => void func_IgnoreAndReturn(retval_to_return)
+1
View File
@@ -25,6 +25,7 @@ class CMockConfig
when Hash then options = CMockDefaultOptions.clone.merge(options)
else raise "If you specify arguments, it should be a filename or a hash of options"
end
options[:plugins] ||= []
@options = options
@options.each_key { |key| eval("def #{key}() return @options[:#{key}] end") }
end
-1
View File
@@ -158,7 +158,6 @@ class CMockGenerator
file << "#{function[:attributes]} " if (!function[:attributes].nil? && function[:attributes].length > 0)
file << "#{function_mod_and_rettype} #{function[:name]}(#{args_string})\n"
file << "{\n"
file << @plugins.run(:mock_implementation_prefix, function)
file << @plugins.run(:mock_implementation, function)
# Return expected value, if necessary
+2 -4
View File
@@ -1,6 +1,7 @@
class CMockGeneratorPluginArray
attr_reader :priority
attr_accessor :config, :utils, :unity_helper, :ordered
def initialize(config, utils)
@@ -9,6 +10,7 @@ class CMockGeneratorPluginArray
@ordered = @config.enforce_strict_ordering
@utils = utils
@unity_helper = @utils.helpers[:unity_helper]
@priority = 8
end
def instance_structure(function)
@@ -37,10 +39,6 @@ class CMockGeneratorPluginArray
end
end
def mock_implementation(function)
nil
end
def mock_interfaces(function)
return nil unless function[:contains_ptr?]
+79
View File
@@ -0,0 +1,79 @@
class CMockGeneratorPluginCallback
attr_reader :priority
attr_reader :config, :utils
def initialize(config, utils)
@config = config
@utils = utils
@priority = 3
end
def instance_structure(function)
INSTANCE_STRUCTURE_SNIPPET % [function[:name]]
end
def mock_function_declarations(function)
if (function[:args_string] == "void")
MOCK_DECLARATION_SNIPPET % [function[:name], function[:return_type], '']
else
MOCK_DECLARATION_SNIPPET % [function[:name], function[:return_type], function[:args_string] + ', ']
end
end
def mock_implementation(function)
call_string = function[:args].empty? ? '' : function[:args].map{|m| m[:name]}.join(', ') + ', '
if (function[:return_type] == 'void')
return MOCK_IMPLEMENTATION_NORET_SNIPPET % [function[:name], call_string]
else
return MOCK_IMPLEMENTATION_RETVAL_SNIPPET % [function[:name], call_string]
end
end
def mock_interfaces(function)
MOCK_INTERFACE_SNIPPET % [function[:name]]
end
def mock_destroy(function)
MOCK_DESTROY_SNIPPET % function[:name]
end
private ############
INSTANCE_STRUCTURE_SNIPPET = %q[ CMOCK_%1$s_CALLBACK %1$s_CallbackFunctionPointer;
]
MOCK_DECLARATION_SNIPPET = %q[
typedef %2$s (* CMOCK_%1$s_CALLBACK)(%3$sint NumCalls);
void %1$s_StubWithCallback(CMOCK_%1$s_CALLBACK Callback);
]
MOCK_IMPLEMENTATION_NORET_SNIPPET = %q[
if (Mock.%1$s_CallbackFunctionPointer != NULL)
{
Mock.%1$s_CallsExpected++;
Mock.%1$s_CallbackFunctionPointer(%2$sMock.%1$s_CallCount++);
return;
}
]
MOCK_IMPLEMENTATION_RETVAL_SNIPPET = %q[
if (Mock.%1$s_CallbackFunctionPointer != NULL)
{
Mock.%1$s_CallsExpected++;
return Mock.%1$s_CallbackFunctionPointer(%2$sMock.%1$s_CallCount++);
}
]
MOCK_INTERFACE_SNIPPET = %q[
void %1$s_StubWithCallback(CMOCK_%1$s_CALLBACK Callback)
{
Mock.%1$s_CallbackFunctionPointer = Callback;
}
]
MOCK_DESTROY_SNIPPET = %q[
Mock.%1$s_CallbackFunctionPointer = NULL;
]
end
+15 -14
View File
@@ -1,37 +1,38 @@
class CMockGeneratorPluginCexception
attr_reader :priority
attr_reader :config, :utils
def initialize(config, utils)
@config = config
@utils = utils
@priority = 7
raise "'cexception_include' needs to be defined in config" unless @config.respond_to?(:cexception_include)
end
def include_files
include = @config.cexception_include
include = "Exception.h" if (include.nil?)
return "#include \"#{include}\"\n"
end
def instance_structure(function)
INSTANCE_STRUCTURE_SNIPPET % function[:name]
end
def mock_function_declarations(function)
if (function[:args_string] == "void")
return "void #{function[:name]}_ExpectAndThrow(EXCEPTION_T toThrow);\n"
else
return "void #{function[:name]}_ExpectAndThrow(#{function[:args_string]}, EXCEPTION_T toThrow);\n"
return "void #{function[:name]}_ExpectAndThrow(EXCEPTION_T toThrow);\n"
else
return "void #{function[:name]}_ExpectAndThrow(#{function[:args_string]}, EXCEPTION_T toThrow);\n"
end
end
def mock_implementation(function)
MOCK_IMPLEMENTATION_SNIPPET % function[:name]
end
def mock_interfaces(function)
arg_insert = (function[:args_string] == "void") ? "" : "#{function[:args_string]}, "
call_string = function[:args].map{|m| m[:name]}.join(', ')
@@ -43,13 +44,13 @@ class CMockGeneratorPluginCexception
(function[:args_string] != "void") ? " ExpectParameters_#{function[:name]}(#{call_string});\n" : nil,
"}\n\n" ].join
end
def mock_destroy(function)
MOCK_DESTROY_SNIPPET % function[:name]
end
private ############
INSTANCE_STRUCTURE_SNIPPET = %q[
int *%1$s_ThrowOnCallCount;
int *%1$s_ThrowOnCallCount_Head;
@@ -63,7 +64,7 @@ class CMockGeneratorPluginCexception
if ((Mock.%1$s_ThrowOnCallCount != Mock.%1$s_ThrowOnCallCount_Tail) &&
(Mock.%1$s_ThrowValue != Mock.%1$s_ThrowValue_Tail))
{
if (*Mock.%1$s_ThrowOnCallCount &&
if (*Mock.%1$s_ThrowOnCallCount &&
(Mock.%1$s_CallCount == *Mock.%1$s_ThrowOnCallCount))
{
EXCEPTION_T toThrow = *Mock.%1$s_ThrowValue;
+2
View File
@@ -1,6 +1,7 @@
class CMockGeneratorPluginExpect
attr_reader :priority
attr_accessor :config, :utils, :unity_helper, :ordered
def initialize(config, utils)
@@ -9,6 +10,7 @@ class CMockGeneratorPluginExpect
@ordered = @config.enforce_strict_ordering
@utils = utils
@unity_helper = @utils.helpers[:unity_helper]
@priority = 5
end
def instance_structure(function)
+3 -1
View File
@@ -1,11 +1,13 @@
class CMockGeneratorPluginIgnore
attr_reader :priority
attr_reader :config, :utils
def initialize(config, utils)
@config = config
@utils = utils
@priority = 2
end
def instance_structure(function)
@@ -20,7 +22,7 @@ class CMockGeneratorPluginIgnore
end
end
def mock_implementation_prefix(function)
def mock_implementation(function)
lines = " if (Mock.#{function[:name]}_IgnoreBool)\n {"
if (function[:return_type] == "void")
lines << "\n return;\n"
+1
View File
@@ -18,6 +18,7 @@ class CMockPluginManager
raise "Unable to load plugin '#{plugin_name}'"
end
end
@plugins.sort! {|a,b| a.priority <=> b.priority }
end
def run(method, args=nil)
@@ -0,0 +1,207 @@
---
:cmock:
:plugins:
- :callback
:systest:
:types: |
#define UINT32 unsigned int
typedef signed int custom_type;
:mockable: |
UINT32 foo(custom_type* a);
UINT32 bar(custom_type* b);
int baz(void);
void fuz(int* args, int num);
:source:
:header: |
void function_a(int a, int b);
UINT32 function_b(void);
int function_c(void);
:code: |
void function_a(int a, int b)
{
int args[6] = {0, 1, 2, 3, 5, 5};
args[0] = a;
fuz(args, b);
}
UINT32 function_b(void)
{
UINT32 sum = 0;
custom_type a = 0;
custom_type b = 0;
sum = foo(&a) + bar(&b);
return sum + a + b;
}
int function_c(void)
{
return (baz() + baz() + baz());
}
:tests:
:common: |
void setUp(void) {}
void tearDown(void) {}
UINT32 FooAndBarHelper(custom_type* data, int num)
{
num++;
*data = (custom_type)(num * 2);
return (*data * 2);
}
int BazCallbackPointless(int num)
{
return num;
}
int BazCallbackComplainsIfCalledMoreThanTwice(int num)
{
TEST_ASSERT_MESSAGE(num < 2, "Do Not Call Baz More Than Twice");
return num;
}
void FuzVerifier(int* args, int num_args, int num_calls)
{
int i;
TEST_ASSERT_MESSAGE(num_args < 5, "No More Than 5 Args Allowed");
for (i = 0; i < num_args; i++)
{
TEST_ASSERT_EQUAL(num_calls + i, args[i]);
}
}
:units:
- :pass: TRUE
:should: 'successfully exercise two simple ExpectAndReturn mock calls the normal way'
:code: |
test()
{
custom_type exp = 0;
foo_ExpectAndReturn(&exp, 10);
bar_ExpectAndReturn(&exp, 20);
TEST_ASSERT_EQUAL(30, function_b());
}
- :pass: FALSE
:should: 'successfully exercise two simple ExpectAndReturn mock calls and catch failure the normal way'
:code: |
test()
{
custom_type exp = 1;
foo_ExpectAndReturn(&exp, 10);
bar_ExpectAndReturn(&exp, 20);
TEST_ASSERT_EQUAL(30, function_b());
}
- :pass: TRUE
:should: 'successfully exercise using some basic callbacks'
:code: |
test()
{
foo_StubWithCallback((CMOCK_foo_CALLBACK)FooAndBarHelper);
bar_StubWithCallback((CMOCK_bar_CALLBACK)FooAndBarHelper);
TEST_ASSERT_EQUAL(12, function_b());
}
- :pass: FALSE
:should: 'successfully exercise using some basic callbacks and notice failures'
:code: |
test()
{
foo_StubWithCallback((CMOCK_foo_CALLBACK)FooAndBarHelper);
bar_StubWithCallback((CMOCK_bar_CALLBACK)FooAndBarHelper);
TEST_ASSERT_EQUAL(10, function_b());
}
- :pass: TRUE
:should: 'successfully exercise a callback with no arguments'
:code: |
test()
{
baz_StubWithCallback((CMOCK_baz_CALLBACK)BazCallbackPointless);
TEST_ASSERT_EQUAL(3, function_c());
}
- :pass: FALSE
:should: 'successfully throw a failure from within a callback function'
:code: |
test()
{
baz_StubWithCallback((CMOCK_baz_CALLBACK)BazCallbackComplainsIfCalledMoreThanTwice);
function_c();
}
- :pass: TRUE
:should: 'be usable for things like dynamically sized memory checking for passing conditions'
:code: |
test()
{
fuz_StubWithCallback((CMOCK_fuz_CALLBACK)FuzVerifier);
function_a(0, 4);
}
- :pass: FALSE
:should: 'be usable for things like dynamically sized memory checking for failing conditions'
:code: |
test()
{
fuz_StubWithCallback((CMOCK_fuz_CALLBACK)FuzVerifier);
function_a(0, 5);
}
- :pass: FALSE
:should: 'be usable for things like dynamically sized memory checking for failing conditions 2'
:code: |
test()
{
fuz_StubWithCallback((CMOCK_fuz_CALLBACK)FuzVerifier);
function_a(1, 4);
}
- :pass: TRUE
:should: 'run them interlaced'
:code: |
test()
{
custom_type exp = 0;
foo_ExpectAndReturn(&exp, 10);
foo_ExpectAndReturn(&exp, 15);
bar_ExpectAndReturn(&exp, 20);
bar_ExpectAndReturn(&exp, 40);
fuz_StubWithCallback((CMOCK_fuz_CALLBACK)FuzVerifier);
baz_StubWithCallback((CMOCK_baz_CALLBACK)BazCallbackPointless);
TEST_ASSERT_EQUAL(30, function_b());
TEST_ASSERT_EQUAL(55, function_b());
function_a(0, 4);
TEST_ASSERT_EQUAL(3, function_c());
}
- :pass: TRUE
:should: 'run them back to back'
:code: |
test()
{
custom_type exp = 0;
foo_ExpectAndReturn(&exp, 10);
bar_ExpectAndReturn(&exp, 20);
TEST_ASSERT_EQUAL(30, function_b());
foo_ExpectAndReturn(&exp, 15);
bar_ExpectAndReturn(&exp, 40);
TEST_ASSERT_EQUAL(55, function_b());
fuz_StubWithCallback((CMOCK_fuz_CALLBACK)FuzVerifier);
function_a(0, 4);
baz_StubWithCallback((CMOCK_baz_CALLBACK)BazCallbackPointless);
TEST_ASSERT_EQUAL(3, function_c());
}
...
-10
View File
@@ -25,10 +25,6 @@ class MockedPluginHelper
return " #{@return_this}_#{name}(#{args}, #{rettype})"
end
def mock_implementation_prefix(name, rettype)
return " Pre#{name}#{@return_this}.#{rettype}"
end
def mock_implementation(name, args)
return " Mock#{name}#{@return_this}(#{args.join(", ")})"
end
@@ -326,14 +322,11 @@ class CMockGeneratorTest < Test::Unit::TestCase
expected = [ "__inline ",
"static bool SupaFunction(uint32 sandwiches, const char* named)\n",
"{\n",
" PreSupaFunctionUno.bool",
" PreSupaFunctionDos.bool",
" MockSupaFunctionUno(uint32 sandwiches, const char* named)",
" MockSupaFunctionDos(uint32 sandwiches, const char* named)",
" UtilsSupaFunction.bool",
"}\n\n"
]
@plugins.expect.run(:mock_implementation_prefix, function).returns([" PreSupaFunctionUno.bool"," PreSupaFunctionDos.bool"])
@plugins.expect.run(:mock_implementation, function).returns([" MockSupaFunctionUno(uint32 sandwiches, const char* named)"," MockSupaFunctionDos(uint32 sandwiches, const char* named)"])
@utils.expect.code_handle_return_value(function).returns([" UtilsSupaFunction.bool"])
@@ -354,14 +347,11 @@ class CMockGeneratorTest < Test::Unit::TestCase
output = []
expected = [ "int SupaFunction(uint32 sandwiches, corn ...)\n",
"{\n",
" PreSupaFunctionUno.int",
" PreSupaFunctionDos.int",
" MockSupaFunctionUno(uint32 sandwiches)",
" MockSupaFunctionDos(uint32 sandwiches)",
" UtilsSupaFunction.int",
"}\n\n"
]
@plugins.expect.run(:mock_implementation_prefix, function).returns([" PreSupaFunctionUno.int"," PreSupaFunctionDos.int"])
@plugins.expect.run(:mock_implementation, function).returns([" MockSupaFunctionUno(uint32 sandwiches)"," MockSupaFunctionDos(uint32 sandwiches)"])
@utils.expect.code_handle_return_value(function).returns([" UtilsSupaFunction.int"])
+3 -14
View File
@@ -20,6 +20,7 @@ class CMockGeneratorPluginArrayTest < Test::Unit::TestCase
assert_equal(@config, @cmock_generator_plugin_array.config)
assert_equal(@utils, @cmock_generator_plugin_array.utils)
assert_equal(nil, @cmock_generator_plugin_array.unity_helper)
assert_equal(8, @cmock_generator_plugin_array.priority)
end
should "not include any additional include files" do
@@ -78,21 +79,9 @@ class CMockGeneratorPluginArrayTest < Test::Unit::TestCase
returned = @cmock_generator_plugin_array.mock_function_declarations(function)
assert_equal(expected, returned)
end
should "not require anything for implementation prefix" do
assert(!@cmock_generator_plugin_array.respond_to?(:mock_implementation_prefix))
end
should "not have a mock function implementation for functions of style 'int* func(void)'" do
function = {:name => "Apple", :args => [], :return_type => "int*", :contains_ptr? => false}
returned = @cmock_generator_plugin_array.mock_implementation(function)
assert_nil(returned)
end
should "not have a mock function implementation for functions containing pointers either (handled in expect)" do
function = {:name => "Apple", :args => [{ :type => 'int*', :name => 'sausage', :ptr? => true}], :return_type => "int*", :contains_ptr? => true}
returned = @cmock_generator_plugin_array.mock_implementation(function)
assert_nil(returned)
should "not have a mock function implementation" do
assert(!@cmock_generator_plugin_array.respond_to?(:mock_implementation))
end
should "not have a mock interfaces for functions of style 'int* func(void)'" do
@@ -0,0 +1,144 @@
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
require 'cmock_generator_plugin_callback'
class CMockGeneratorPluginCallbackTest < Test::Unit::TestCase
def setup
create_mocks :config, :utils
@cmock_generator_plugin_callback = CMockGeneratorPluginCallback.new(@config, @utils)
end
def teardown
end
should "have set up internal accessors correctly on init" do
assert_equal(@config, @cmock_generator_plugin_callback.config)
assert_equal(@utils, @cmock_generator_plugin_callback.utils)
assert_equal(3, @cmock_generator_plugin_callback.priority)
end
should "not include any additional include files" do
assert(!@cmock_generator_plugin_callback.respond_to?(:include_files))
end
should "add to control structure" do
function = {:name => "Oak", :args => [:type => "int*", :name => "blah", :ptr? => true], :return_type => "int*"}
expected = " CMOCK_Oak_CALLBACK Oak_CallbackFunctionPointer;\n"
returned = @cmock_generator_plugin_callback.instance_structure(function)
assert_equal(expected, returned)
end
should "add mock function declaration for function without arguments" do
function = {:name => "Maple", :args_string => "void", :return_type => "void"}
expected = [ "\n",
"typedef void (* CMOCK_Maple_CALLBACK)(int NumCalls);\n",
"void Maple_StubWithCallback(CMOCK_Maple_CALLBACK Callback);\n" ].join
returned = @cmock_generator_plugin_callback.mock_function_declarations(function)
assert_equal(expected, returned)
end
should "add mock function declaration for function with arguments" do
function = {:name => "Maple", :args_string => "int* tofu", :return_type => "void"}
expected = [ "\n",
"typedef void (* CMOCK_Maple_CALLBACK)(int* tofu, int NumCalls);\n",
"void Maple_StubWithCallback(CMOCK_Maple_CALLBACK Callback);\n" ].join
returned = @cmock_generator_plugin_callback.mock_function_declarations(function)
assert_equal(expected, returned)
end
should "add mock function declaration for function with return values" do
function = {:name => "Maple", :args_string => "int* tofu", :return_type => "char*"}
expected = [ "\n",
"typedef char* (* CMOCK_Maple_CALLBACK)(int* tofu, int NumCalls);\n",
"void Maple_StubWithCallback(CMOCK_Maple_CALLBACK Callback);\n" ].join
returned = @cmock_generator_plugin_callback.mock_function_declarations(function)
assert_equal(expected, returned)
end
should "add mock function implementation for functions of style 'void func(void)'" do
function = {:name => "Apple", :args => [], :args_string => "void", :return_type => "void"}
expected = ["\n",
" if (Mock.Apple_CallbackFunctionPointer != NULL)\n",
" {\n",
" Mock.Apple_CallsExpected++;\n",
" Mock.Apple_CallbackFunctionPointer(Mock.Apple_CallCount++);\n",
" return;\n",
" }\n"
].join
returned = @cmock_generator_plugin_callback.mock_implementation(function)
assert_equal(expected, returned)
end
should "add mock function implementation for functions of style 'int func(void)'" do
function = {:name => "Apple", :args => [], :args_string => "void", :return_type => "int"}
expected = ["\n",
" if (Mock.Apple_CallbackFunctionPointer != NULL)\n",
" {\n",
" Mock.Apple_CallsExpected++;\n",
" return Mock.Apple_CallbackFunctionPointer(Mock.Apple_CallCount++);\n",
" }\n"
].join
returned = @cmock_generator_plugin_callback.mock_implementation(function)
assert_equal(expected, returned)
end
should "add mock function implementation for functions of style 'void func(int* steak, uint8_t flag)'" do
function = {:name => "Apple",
:args => [ { :type => 'int*', :name => 'steak', :ptr? => true},
{ :type => 'uint8_t', :name => 'flag', :ptr? => false} ],
:args_string => "int* steak, uint8_t flag",
:return_type => "void"}
expected = ["\n",
" if (Mock.Apple_CallbackFunctionPointer != NULL)\n",
" {\n",
" Mock.Apple_CallsExpected++;\n",
" Mock.Apple_CallbackFunctionPointer(steak, flag, Mock.Apple_CallCount++);\n",
" return;\n",
" }\n"
].join
returned = @cmock_generator_plugin_callback.mock_implementation(function)
assert_equal(expected, returned)
end
should "add mock function implementation for functions of style 'int16_t func(int* steak, uint8_t flag)'" do
function = {:name => "Apple",
:args => [ { :type => 'int*', :name => 'steak', :ptr? => true},
{ :type => 'uint8_t', :name => 'flag', :ptr? => false} ],
:args_string => "int* steak, uint8_t flag",
:return_type => "int16_t"}
expected = ["\n",
" if (Mock.Apple_CallbackFunctionPointer != NULL)\n",
" {\n",
" Mock.Apple_CallsExpected++;\n",
" return Mock.Apple_CallbackFunctionPointer(steak, flag, Mock.Apple_CallCount++);\n",
" }\n"
].join
returned = @cmock_generator_plugin_callback.mock_implementation(function)
assert_equal(expected, returned)
end
should "add mock interfaces for functions " do
function = {:name => "Lemon",
:args => [{ :type => "char*", :name => "pescado"}],
:args_string => "char* pescado",
:return_type => "int",
:return_string => "int toReturn" }
expected = ["\n",
"void Lemon_StubWithCallback(CMOCK_Lemon_CALLBACK Callback)\n",
"{\n",
" Mock.Lemon_CallbackFunctionPointer = Callback;\n",
"}\n"
].join
returned = @cmock_generator_plugin_callback.mock_interfaces(function)
assert_equal(expected, returned)
end
should "add mock destroy for functions" do
function = {:name => "Peach", :args => [], :return_type => "void" }
expected = ["\n",
" Mock.Peach_CallbackFunctionPointer = NULL;\n" ].join
returned = @cmock_generator_plugin_callback.mock_destroy(function)
assert_equal(expected, returned)
end
end
@@ -14,6 +14,7 @@ class CMockGeneratorPluginCexceptionTest < Test::Unit::TestCase
should "have set up internal accessors correctly on init" do
assert_equal(@config, @cmock_generator_plugin_cexception.config)
assert_equal(@utils, @cmock_generator_plugin_cexception.utils)
assert_equal(7, @cmock_generator_plugin_cexception.priority)
end
should "include the cexception library" do
@@ -58,17 +59,13 @@ class CMockGeneratorPluginCexceptionTest < Test::Unit::TestCase
assert_equal(expected, returned)
end
should "add nothing during implementation prefix" do
assert(!@cmock_generator_plugin_cexception.respond_to?(:mock_implementation_prefix))
end
should "add a mock implementation" do
function = {:name => "Cherry", :args => [], :return_type => "void"}
expected = ["\n",
" if ((Mock.Cherry_ThrowOnCallCount != Mock.Cherry_ThrowOnCallCount_Tail) &&\n",
" (Mock.Cherry_ThrowValue != Mock.Cherry_ThrowValue_Tail))\n",
" {\n",
" if (*Mock.Cherry_ThrowOnCallCount && \n",
" if (*Mock.Cherry_ThrowOnCallCount &&\n",
" (Mock.Cherry_CallCount == *Mock.Cherry_ThrowOnCallCount))\n",
" {\n",
" EXCEPTION_T toThrow = *Mock.Cherry_ThrowValue;\n",
@@ -27,6 +27,7 @@ class CMockGeneratorPluginExpectTest < Test::Unit::TestCase
assert_equal(@config, @cmock_generator_plugin_expect.config)
assert_equal(@utils, @cmock_generator_plugin_expect.utils)
assert_equal(nil, @cmock_generator_plugin_expect.unity_helper)
assert_equal(5, @cmock_generator_plugin_expect.priority)
end
should "not include any additional include files" do
@@ -129,10 +130,6 @@ class CMockGeneratorPluginExpectTest < Test::Unit::TestCase
returned = @cmock_generator_plugin_expect.mock_function_declarations(function)
assert_equal(expected, returned)
end
should "not require anything for implementation prefix" do
assert(!@cmock_generator_plugin_expect.respond_to?(:mock_implementation_prefix))
end
should "add mock function implementation for functions of style 'void func(void)'" do
function = {:name => "Apple", :args => [], :return_type => "void"}
@@ -14,6 +14,7 @@ class CMockGeneratorPluginIgnoreTest < Test::Unit::TestCase
should "have set up internal accessors correctly on init" do
assert_equal(@config, @cmock_generator_plugin_ignore.config)
assert_equal(@utils, @cmock_generator_plugin_ignore.utils)
assert_equal(2, @cmock_generator_plugin_ignore.priority)
end
should "not have any additional include file requirements" do
@@ -41,18 +42,18 @@ class CMockGeneratorPluginIgnoreTest < Test::Unit::TestCase
assert_equal(expected, returned)
end
should "add required code to implementation prefix with void function" do
should "add required code to implementation with void function" do
function = {:name => "Mold", :args_string => "void", :return_type => "void"}
expected = [" if (Mock.Mold_IgnoreBool)\n",
" {\n",
" return;\n",
" }\n"
].join
returned = @cmock_generator_plugin_ignore.mock_implementation_prefix(function)
returned = @cmock_generator_plugin_ignore.mock_implementation(function)
assert_equal(expected, returned)
end
should "add required code to implementation prefix with return functions" do
should "add required code to implementation with return functions" do
function = {:name => "Fungus", :args_string => "void", :return_type => "int"}
expected = [" if (Mock.Fungus_IgnoreBool)\n",
" {\n",
@@ -70,14 +71,10 @@ class CMockGeneratorPluginIgnoreTest < Test::Unit::TestCase
" }\n",
" }\n"
].join
returned = @cmock_generator_plugin_ignore.mock_implementation_prefix(function)
returned = @cmock_generator_plugin_ignore.mock_implementation(function)
assert_equal(expected, returned)
end
should "have nothing new for mock implementation" do
assert(!@cmock_generator_plugin_ignore.respond_to?(:mock_implementation))
end
should "add a new mock interface for ignoring when function had no return value" do
function = {:name => "Slime", :args => [], :args_string => "void", :return_type => "void"}
expected = ["\n",