mirror of
https://github.com/ThrowTheSwitch/CMock.git
synced 2026-08-07 19:57:49 +00:00
- foundation work towards more awesome pointer/array handling. not there yet, so don't try this at home kids.
git-svn-id: http://cmock.svn.sourceforge.net/svnroot/cmock/trunk@145 bf332499-1b4d-0410-844d-d2d48d5cc64c
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
|
||||
class CMockGeneratorPluginArray
|
||||
|
||||
attr_accessor :config, :utils, :unity_helper, :ordered
|
||||
|
||||
def initialize(config, utils)
|
||||
@config = config
|
||||
@ptr_handling = @config.when_ptr_star
|
||||
@ordered = @config.enforce_strict_ordering
|
||||
@utils = utils
|
||||
@unity_helper = @utils.helpers[:unity_helper]
|
||||
end
|
||||
|
||||
def instance_structure(function)
|
||||
lines = ""
|
||||
function[:args].each do |arg|
|
||||
lines << INSTANCE_STRUCTURE_ITEM_SNIPPET % "#{function[:name]}_Expected_#{arg[:name]}" if (arg[:ptr?])
|
||||
end
|
||||
lines
|
||||
end
|
||||
|
||||
def mock_function_declarations(function)
|
||||
return nil unless function[:contains_ptr?]
|
||||
if (function[:args_string] == "void")
|
||||
if (function[:return_type] == 'void')
|
||||
return "void #{function[:name]}_ExpectWithArray(void);\n"
|
||||
else
|
||||
return "void #{function[:name]}_ExpectWithArrayAndReturn(#{function[:return_string]});\n"
|
||||
end
|
||||
else
|
||||
if (function[:return_type] == 'void')
|
||||
return "void #{function[:name]}_ExpectWithArray(#{function[:args_string]});\n"
|
||||
else
|
||||
return "void #{function[:name]}_ExpectWithArrayAndReturn(#{function[:args_string]}, #{function[:return_string]});\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def mock_implementation(function)
|
||||
nil
|
||||
end
|
||||
|
||||
def mock_interfaces(function)
|
||||
return nil unless function[:args_string].include? '*'
|
||||
nil
|
||||
end
|
||||
|
||||
def mock_verify(function)
|
||||
nil
|
||||
end
|
||||
|
||||
def mock_destroy(function)
|
||||
nil
|
||||
end
|
||||
|
||||
private #####################
|
||||
|
||||
INSTANCE_STRUCTURE_ITEM_SNIPPET = %q[
|
||||
int* %1$s_Depth;
|
||||
int* %1$s_Depth_Head;
|
||||
int* %1$s_Depth_Tail;
|
||||
]
|
||||
|
||||
end
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
class CMockGeneratorPluginCException
|
||||
class CMockGeneratorPluginCexception
|
||||
|
||||
attr_reader :config, :utils
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ class CMockGeneratorPluginExpect
|
||||
lines << MOCK_IMPLEMENT_ORDERED_SNIPPET % [function[:name], err_msg, (err_msg.size + 1).to_s]
|
||||
end
|
||||
function[:args].each do |arg|
|
||||
lines << @utils.code_verify_an_arg_expectation(function, arg[:type], arg[:name])
|
||||
lines << @utils.code_verify_an_arg_expectation(function, arg)
|
||||
end
|
||||
lines
|
||||
end
|
||||
@@ -64,7 +64,7 @@ class CMockGeneratorPluginExpect
|
||||
if (function[:args_string] != "void")
|
||||
lines << "void ExpectParameters_#{func_name}(#{function[:args_string]})\n{\n"
|
||||
function[:args].each do |arg|
|
||||
lines << @utils.code_add_an_arg_expectation(function, arg[:type], arg[:name])
|
||||
lines << @utils.code_add_an_arg_expectation(function, arg)
|
||||
end
|
||||
lines << "}\n\n"
|
||||
end
|
||||
|
||||
@@ -7,6 +7,7 @@ class CMockGeneratorUtils
|
||||
@config = config
|
||||
@ptr_handling = @config.when_ptr_star
|
||||
@ordered = @config.enforce_strict_ordering
|
||||
@arrays = @config.plugins.include? :array
|
||||
@helpers = helpers
|
||||
end
|
||||
|
||||
@@ -26,10 +27,16 @@ class CMockGeneratorUtils
|
||||
INSERT_EXPECT_CODE_SNIPPET % [type, array, newValue]
|
||||
end
|
||||
|
||||
def code_add_an_arg_expectation(function, arg_type, expected)
|
||||
var = "Mock.#{function[:name]}_Expected_#{expected}"
|
||||
lines = code_insert_item_into_expect_array(arg_type, var, expected)
|
||||
def code_add_an_arg_expectation(function, arg, depth=1)
|
||||
var = "Mock.#{function[:name]}_Expected_#{arg[:name]}"
|
||||
lines = code_insert_item_into_expect_array(arg[:type], var, arg[:name])
|
||||
lines << INSERT_EXPECT_SETUP_SNIPPET % [var, function[:name]]
|
||||
if (@arrays and arg[:ptr?])
|
||||
var += '_Depth'
|
||||
lines << INSERT_EXPECT_SHORT_CODE_SNIPPET % ['int', var, depth]
|
||||
lines << INSERT_EXPECT_SETUP_SNIPPET % [var, function[:name]]
|
||||
end
|
||||
lines
|
||||
end
|
||||
|
||||
def code_add_base_expectation(func_name)
|
||||
@@ -43,14 +50,16 @@ class CMockGeneratorUtils
|
||||
lines
|
||||
end
|
||||
|
||||
def code_verify_an_arg_expectation(function, arg_type, arg)
|
||||
(INSERT_ARG_VERIFY_START_SNIPPET % ["#{function[:name]}_Expected_#{arg}", arg_type]) +
|
||||
expect_helper(arg_type, '*p_expected', arg, "\"Function '#{function[:name]}' called with unexpected value for argument '#{arg}'.\"") +
|
||||
" }\n"
|
||||
def code_verify_an_arg_expectation(function, arg)
|
||||
(INSERT_ARG_VERIFY_START_SNIPPET % ["#{function[:name]}_Expected_#{arg[:name]}", arg[:type]]) +
|
||||
expect_helper(arg, '*p_expected', "\"Function '#{function[:name]}' called with unexpected value for argument '#{arg[:name]}'.\"", "#{function[:name]}_Expected_#{arg[:name]}_Depth") +
|
||||
"\n }\n"
|
||||
end
|
||||
|
||||
def expect_helper(c_type, expected, arg, msg)
|
||||
if ((c_type.strip[-1] == 42) and (@ptr_handling == :compare_ptr))
|
||||
def expect_helper(arg, expected, msg, depth_name='1')
|
||||
c_type = arg[:type]
|
||||
name = arg[:name]
|
||||
if ((arg[:ptr?]) and (@ptr_handling == :compare_ptr))
|
||||
unity_func = "TEST_ASSERT_EQUAL_INT_MESSAGE"
|
||||
else
|
||||
unity_func = (@helpers.nil? or @helpers[:unity_helper].nil?) ? "TEST_ASSERT_EQUAL_MESSAGE" : @helpers[:unity_helper].get_helper(c_type)
|
||||
@@ -59,13 +68,36 @@ class CMockGeneratorUtils
|
||||
case(unity_func)
|
||||
when "TEST_ASSERT_EQUAL_MEMORY_MESSAGE"
|
||||
full_expected = (expected =~ /^\*/) ? expected.slice(1..-1) : "&(#{expected})"
|
||||
return " TEST_ASSERT_EQUAL_MEMORY_MESSAGE((void*)#{full_expected}, (void*)&(#{arg}), sizeof(#{c_type})#{unity_msg});\n"
|
||||
return " TEST_ASSERT_EQUAL_MEMORY_MESSAGE((void*)#{full_expected}, (void*)&(#{name}), sizeof(#{c_type})#{unity_msg});\n"
|
||||
when "TEST_ASSERT_EQUAL_MEMORY_MESSAGE_ARRAY"
|
||||
return " if (*p_expected == NULL)\n { TEST_ASSERT_NULL(#{arg}); }\n else\n { TEST_ASSERT_EQUAL_MEMORY_MESSAGE((void*)(#{expected}), (void*)#{arg}, sizeof(#{c_type.sub('*','')})#{unity_msg}); }\n"
|
||||
if (@arrays)
|
||||
[ (INSERT_ARG_DEPTH_START_SNIPPET % [depth_name]),
|
||||
" if (*p_expected == NULL)",
|
||||
" { TEST_ASSERT_NULL(#{name}); }",
|
||||
" else",
|
||||
" { TEST_ASSERT_EQUAL_MEMORY_ARRAY_MESSAGE((void*)(#{expected}), (void*)#{name}, sizeof(#{c_type.sub('*','')}), Depth#{unity_msg}); }"].join("\n")
|
||||
else
|
||||
[ " if (*p_expected == NULL)",
|
||||
" { TEST_ASSERT_NULL(#{name}); }",
|
||||
" else",
|
||||
" { TEST_ASSERT_EQUAL_MEMORY_MESSAGE((void*)(#{expected}), (void*)#{name}, sizeof(#{c_type.sub('*','')})#{unity_msg}); }"].join("\n")
|
||||
|
||||
end
|
||||
when /_ARRAY/
|
||||
return " if (*p_expected == NULL)\n { TEST_ASSERT_NULL(#{arg}); }\n else\n { #{unity_func}(#{expected}, #{arg}, 1#{unity_msg}); }\n"
|
||||
if (@arrays)
|
||||
[ (INSERT_ARG_DEPTH_START_SNIPPET % ["#{function[:name]}_Expected_#{name}_Depth"]),
|
||||
" if (*p_expected == NULL)",
|
||||
" { TEST_ASSERT_NULL(#{name}); }",
|
||||
" else",
|
||||
" { #{unity_func}(#{expected}, #{name}, Depth); }"].join("\n")
|
||||
else
|
||||
[ " if (*p_expected == NULL)",
|
||||
" { TEST_ASSERT_NULL(#{name}); }",
|
||||
" else",
|
||||
" { #{unity_func}(#{expected}, #{name}, 1); }"].join("\n")
|
||||
end
|
||||
else
|
||||
return " #{unity_func}(#{expected}, #{arg}#{unity_msg});\n"
|
||||
return " #{unity_func}(#{expected}, #{name}#{unity_msg});\n"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -99,6 +131,30 @@ class CMockGeneratorUtils
|
||||
}
|
||||
]
|
||||
|
||||
INSERT_EXPECT_SHORT_CODE_SNIPPET = %q[
|
||||
{
|
||||
int sz = 0;
|
||||
%1$s *pointer = %2$s_Head;
|
||||
while (pointer && pointer != %2$s_Tail) { sz++; pointer++; }
|
||||
if (sz == 0)
|
||||
{
|
||||
%2$s_Head = (%1$s*)malloc(2*sizeof(%1$s));
|
||||
if (!%2$s_Head)
|
||||
Mock.allocFailure++;
|
||||
}
|
||||
else
|
||||
{
|
||||
%1$s *ptmp = (%1$s*)realloc(%2$s_Head, sizeof(%1$s) * (sz+1));
|
||||
if (!ptmp)
|
||||
Mock.allocFailure++;
|
||||
else
|
||||
%2$s_Head = ptmp;
|
||||
}
|
||||
%2$s_Head[sz] = %3$s;
|
||||
%2$s_Tail = &%2$s_Head[sz+1];
|
||||
}
|
||||
]
|
||||
|
||||
INSERT_EXPECT_SETUP_SNIPPET =
|
||||
" %1$s = %1$s_Head;\n %1$s += Mock.%2$s_CallCount;\n"
|
||||
|
||||
@@ -122,4 +178,9 @@ class CMockGeneratorUtils
|
||||
Mock.%1$s++;
|
||||
]
|
||||
|
||||
INSERT_ARG_DEPTH_START_SNIPPET = %q[
|
||||
int Depth = *Mock.%1$s;
|
||||
Mock.%1$s++;
|
||||
]
|
||||
|
||||
end
|
||||
@@ -104,13 +104,22 @@ class CMockHeaderParser
|
||||
args = []
|
||||
arg_list.split(',').each do |arg|
|
||||
arg.strip!
|
||||
return args if (arg =~ /^\s*((\.\.\.)|(void))\s*$/) # we're done if we reach void by itself or ...
|
||||
arg_elements = arg.split - @c_attributes # split up words and remove known attributes
|
||||
args << {:type => arg_elements[0..-2].join(' '), :name => arg_elements[-1]} # add the lucky winners to the list
|
||||
return args if (arg =~ /^\s*((\.\.\.)|(void))\s*$/) # we're done if we reach void by itself or ...
|
||||
arg_elements = arg.split - @c_attributes # split up words and remove known attributes
|
||||
args << { :type => (arg_type =arg_elements[0..-2].join(' ')),
|
||||
:name => arg_elements[-1],
|
||||
:ptr? => divine_ptr(arg_type)
|
||||
}
|
||||
end
|
||||
return args
|
||||
end
|
||||
|
||||
def divine_ptr(arg_type)
|
||||
return false unless arg_type.include? '*'
|
||||
return false if arg_type.gsub(/(const|char|\*|\s)+/,'').empty?
|
||||
return true
|
||||
end
|
||||
|
||||
def clean_args(arg_list)
|
||||
if ((@local_as_void.include?(arg_list.strip)) or (arg_list.empty?))
|
||||
return 'void'
|
||||
@@ -199,6 +208,7 @@ class CMockHeaderParser
|
||||
args = clean_args(args)
|
||||
decl[:args_string] = args
|
||||
decl[:args] = parse_args(args)
|
||||
decl[:contains_ptr?] = decl[:args].inject(false) {|ptr, arg| arg[:ptr?] ? true : ptr }
|
||||
|
||||
if (decl[:return_type].nil? or decl[:name].nil? or decl[:args].nil? or
|
||||
decl[:return_type].empty? or decl[:name].empty?)
|
||||
|
||||
@@ -1,18 +1,23 @@
|
||||
|
||||
require "cmock_generator_plugin_expect.rb"
|
||||
require "cmock_generator_plugin_ignore.rb"
|
||||
require "cmock_generator_plugin_cexception.rb"
|
||||
|
||||
class CMockPluginManager
|
||||
|
||||
attr_accessor :plugins
|
||||
|
||||
def initialize(config, utils)
|
||||
plugins_to_load = config.plugins
|
||||
@plugins = []
|
||||
@plugins << CMockGeneratorPluginExpect.new( config, utils )
|
||||
@plugins << CMockGeneratorPluginCException.new( config, utils ) if plugins_to_load.include? 'cexception'
|
||||
@plugins << CMockGeneratorPluginIgnore.new( config, utils ) if plugins_to_load.include? 'ignore'
|
||||
plugins_to_load = ["expect", config.plugins].flatten.uniq.compact
|
||||
plugins_to_load.each do |plugin|
|
||||
plugin_name = plugin.to_s
|
||||
object_name = "CMockGeneratorPlugin" + camelize(plugin_name)
|
||||
begin
|
||||
unless (Object.const_defined? object_name)
|
||||
require "cmock_generator_plugin_#{plugin_name.downcase}.rb"
|
||||
end
|
||||
@plugins << eval("#{object_name}.new(config, utils)")
|
||||
rescue
|
||||
raise "Unable to load plugin '#{plugin_name}'"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def run(method, args=nil)
|
||||
@@ -22,4 +27,8 @@ class CMockPluginManager
|
||||
return @plugins.collect{ |plugin| plugin.send(method, args) if plugin.respond_to?(method) }.flatten.join
|
||||
end
|
||||
end
|
||||
|
||||
def camelize(lower_case_and_underscored_word)
|
||||
lower_case_and_underscored_word.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,167 @@
|
||||
---
|
||||
:cmock:
|
||||
:plugins:
|
||||
- :array
|
||||
|
||||
:systest:
|
||||
:types: |
|
||||
typedef struct _POINT_T {
|
||||
int x;
|
||||
int y;
|
||||
} POINT_T;
|
||||
|
||||
:mockable: |
|
||||
void foo(POINT_T* a);
|
||||
POINT_T* bar(void);
|
||||
void fooa(POINT_T a[]);
|
||||
void foos(const char const * a);
|
||||
const char const * bars(void);
|
||||
|
||||
:source:
|
||||
:header: |
|
||||
void function_a(void);
|
||||
void function_b(void);
|
||||
void function_c(void);
|
||||
|
||||
:code: |
|
||||
void function_a(void)
|
||||
{
|
||||
foo(bar());
|
||||
}
|
||||
|
||||
void function_b(void) {
|
||||
fooa(bar());
|
||||
}
|
||||
|
||||
void function_c(void) {
|
||||
foos(bars());
|
||||
}
|
||||
|
||||
:tests:
|
||||
:common: |
|
||||
void setUp(void) {}
|
||||
void tearDown(void) {}
|
||||
|
||||
:units:
|
||||
- :pass: TRUE
|
||||
:should: 'handle the situation where we pass nulls to pointers'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
bar_ExpectAndReturn(NULL);
|
||||
foo_Expect(NULL);
|
||||
|
||||
function_a();
|
||||
}
|
||||
|
||||
- :pass: TRUE
|
||||
:should: 'handle the situation where we pass single object with expect'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
POINT_T pt = {1, 2};
|
||||
POINT_T ex = {1, 2};
|
||||
bar_ExpectAndReturn(&pt);
|
||||
foo_Expect(&ex);
|
||||
|
||||
function_a();
|
||||
}
|
||||
|
||||
- :pass: FALSE
|
||||
:should: 'handle the situation where we pass single object with expect and it is wrong'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
POINT_T pt = {1, 2};
|
||||
POINT_T ex = {1, 3};
|
||||
bar_ExpectAndReturn(&pt);
|
||||
foo_Expect(&ex);
|
||||
|
||||
function_a();
|
||||
}
|
||||
|
||||
- :pass: FALSE
|
||||
:should: 'handle the situation where we pass nulls to pointers and fail'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
POINT_T pt = {1, 2};
|
||||
bar_ExpectAndReturn(&pt);
|
||||
foo_Expect(NULL);
|
||||
|
||||
function_a();
|
||||
}
|
||||
|
||||
- :pass: TRUE
|
||||
:should: 'handle the situation where we pass nulls to arrays'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
bar_ExpectAndReturn(NULL);
|
||||
fooa_Expect(NULL);
|
||||
|
||||
function_b();
|
||||
}
|
||||
|
||||
- :pass: TRUE
|
||||
:should: 'handle the situation where we pass single array element with expect'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
POINT_T pt = {1, 2};
|
||||
POINT_T ex = {1, 2};
|
||||
bar_ExpectAndReturn(&pt);
|
||||
fooa_Expect(&ex);
|
||||
|
||||
function_b();
|
||||
}
|
||||
|
||||
- :pass: FALSE
|
||||
:should: 'handle the situation where we pass single array element with expect and it is wrong'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
POINT_T pt = {1, 2};
|
||||
POINT_T ex = {1, 3};
|
||||
bar_ExpectAndReturn(&pt);
|
||||
fooa_Expect(&ex);
|
||||
|
||||
function_b();
|
||||
}
|
||||
|
||||
- :pass: FALSE
|
||||
:should: 'handle the situation where we pass nulls to arrays and fail'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
POINT_T pt = {1, 2};
|
||||
bar_ExpectAndReturn(&pt);
|
||||
fooa_Expect(NULL);
|
||||
|
||||
function_b();
|
||||
}
|
||||
|
||||
- :pass: TRUE
|
||||
:should: 'handle standard c string as null terminated on not do crappy memory compares of a byte, passing'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
bars_ExpectAndReturn("This is a\0 silly string");
|
||||
foos_Expect("This is a\0 wacky string");
|
||||
|
||||
function_c();
|
||||
}
|
||||
|
||||
- :pass: FALSE
|
||||
:should: 'handle standard c string as null terminated on not do crappy memory compares of a byte, finding failures'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
bars_ExpectAndReturn("This is a silly string");
|
||||
foos_Expect("This is a wacky string");
|
||||
|
||||
function_c();
|
||||
}
|
||||
|
||||
|
||||
...
|
||||
@@ -21,6 +21,7 @@
|
||||
:header: |
|
||||
void function_a(void);
|
||||
void function_b(void);
|
||||
void function_c(void);
|
||||
|
||||
:code: |
|
||||
void function_a(void)
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
|
||||
require 'cmock_generator_plugin_cexception'
|
||||
|
||||
class CMockGeneratorPluginCExceptionTest < Test::Unit::TestCase
|
||||
class CMockGeneratorPluginCexceptionTest < Test::Unit::TestCase
|
||||
def setup
|
||||
create_mocks :config, :utils
|
||||
@config.stubs!(:respond_to?).returns(true)
|
||||
@cmock_generator_plugin_cexception = CMockGeneratorPluginCException.new(@config, @utils)
|
||||
@cmock_generator_plugin_cexception = CMockGeneratorPluginCexception.new(@config, @utils)
|
||||
end
|
||||
|
||||
def teardown
|
||||
|
||||
@@ -150,8 +150,8 @@ class CMockGeneratorPluginExpectTest < Test::Unit::TestCase
|
||||
should "add mock function implementation for functions of style 'int func(int veal, unsigned int sushi)'" do
|
||||
function = {:name => "Cherry", :args => [ { :type => "int", :name => "veal" }, { :type => "unsigned int", :name => "sushi" } ], :return_type => "int"}
|
||||
|
||||
@utils.expect.code_verify_an_arg_expectation(function, function[:args][0][:type], function[:args][0][:name]).returns("mocked_retval_1")
|
||||
@utils.expect.code_verify_an_arg_expectation(function, function[:args][1][:type], function[:args][1][:name]).returns("mocked_retval_2")
|
||||
@utils.expect.code_verify_an_arg_expectation(function, function[:args][0]).returns("mocked_retval_1")
|
||||
@utils.expect.code_verify_an_arg_expectation(function, function[:args][1]).returns("mocked_retval_2")
|
||||
|
||||
expected = ["\n",
|
||||
" Mock.Cherry_CallCount++;\n",
|
||||
@@ -250,7 +250,7 @@ class CMockGeneratorPluginExpectTest < Test::Unit::TestCase
|
||||
|
||||
should "add mock interfaces for functions of style 'int func(char* pescado)'" do
|
||||
function = {:name => "Lemon", :args => [{ :type => "char*", :name => "pescado"}], :args_string => "char* pescado", :return_type => "int", :return_string => "int toReturn"}
|
||||
@utils.expect.code_add_an_arg_expectation(function, "char*", "pescado").returns("mock_retval_2")
|
||||
@utils.expect.code_add_an_arg_expectation(function, {:type => "char*", :name => "pescado"}).returns("mock_retval_2")
|
||||
@utils.expect.code_add_base_expectation("Lemon").returns("mock_retval_0")
|
||||
@utils.expect.create_call_list(function).returns("mock_retval_3")
|
||||
@utils.expect.code_insert_item_into_expect_array(function[:return_type], "Mock.Lemon_Return", 'toReturn').returns("mock_retval_1")
|
||||
|
||||
@@ -6,6 +6,7 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase
|
||||
create_mocks :config, :unity_helper
|
||||
@config.expect.when_ptr_star.returns(:compare_data)
|
||||
@config.expect.enforce_strict_ordering.returns(false)
|
||||
@config.expect.plugins.returns([:arrays])
|
||||
@cmock_generator_utils = CMockGeneratorUtils.new(@config)
|
||||
end
|
||||
|
||||
@@ -21,6 +22,7 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase
|
||||
create_mocks :config
|
||||
@config.expect.when_ptr_star.returns(:compare_ptr)
|
||||
@config.expect.enforce_strict_ordering.returns(false)
|
||||
@config.expect.plugins.returns([])
|
||||
@cmock_generator_utils = CMockGeneratorUtils.new(@config, {:A=>1, :B=>2})
|
||||
assert_equal(@config, @cmock_generator_utils.config)
|
||||
assert_equal({:A=>1, :B=>2},@cmock_generator_utils.helpers)
|
||||
@@ -126,7 +128,7 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase
|
||||
" Mock.PizzaCutter_Expected_Spork = Mock.PizzaCutter_Expected_Spork_Head;\n",
|
||||
" Mock.PizzaCutter_Expected_Spork += Mock.PizzaCutter_CallCount;\n"
|
||||
].join
|
||||
returned = @cmock_generator_utils.code_add_an_arg_expectation(function, var_type, var_name)
|
||||
returned = @cmock_generator_utils.code_add_an_arg_expectation(function, {:type => var_type, :name => var_name})
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
@@ -179,10 +181,10 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase
|
||||
" {\n",
|
||||
" uint16* p_expected = Mock.CanOpener_Expected_CorkScrew;\n",
|
||||
" Mock.CanOpener_Expected_CorkScrew++;\n",
|
||||
" TEST_ASSERT_EQUAL_MESSAGE(*p_expected, CorkScrew, \"Function 'CanOpener' called with unexpected value for argument 'CorkScrew'.\");\n",
|
||||
" TEST_ASSERT_EQUAL_MESSAGE(*p_expected, CorkScrew, \"Function 'CanOpener' called with unexpected value for argument 'CorkScrew'.\");\n\n",
|
||||
" }\n"
|
||||
].join
|
||||
returned = @cmock_generator_utils.code_verify_an_arg_expectation(function, var_type, var_name)
|
||||
returned = @cmock_generator_utils.code_verify_an_arg_expectation(function, {:type => var_type, :name => var_name})
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
@@ -199,10 +201,10 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase
|
||||
" {\n",
|
||||
" const char** p_expected = Mock.MeasureCup_Expected_TeaSpoon;\n",
|
||||
" Mock.MeasureCup_Expected_TeaSpoon++;\n",
|
||||
" TEST_ASSERT_EQUAL_STRING_MESSAGE(*p_expected, TeaSpoon, \"Function 'MeasureCup' called with unexpected value for argument 'TeaSpoon'.\");\n",
|
||||
" TEST_ASSERT_EQUAL_STRING_MESSAGE(*p_expected, TeaSpoon, \"Function 'MeasureCup' called with unexpected value for argument 'TeaSpoon'.\");\n\n",
|
||||
" }\n"
|
||||
].join
|
||||
returned = @cmock_generator_utils.code_verify_an_arg_expectation(function, var_type, var_name)
|
||||
returned = @cmock_generator_utils.code_verify_an_arg_expectation(function, {:type => var_type, :name => var_name})
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
@@ -219,10 +221,10 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase
|
||||
" {\n",
|
||||
" MANDELBROT_SET_T* p_expected = Mock.TeaPot_Expected_TeaSpoon;\n",
|
||||
" Mock.TeaPot_Expected_TeaSpoon++;\n",
|
||||
" TEST_ASSERT_EQUAL_MANDELBROT_SET_T_MESSAGE(*p_expected, TeaSpoon, \"Function 'TeaPot' called with unexpected value for argument 'TeaSpoon'.\");\n",
|
||||
" TEST_ASSERT_EQUAL_MANDELBROT_SET_T_MESSAGE(*p_expected, TeaSpoon, \"Function 'TeaPot' called with unexpected value for argument 'TeaSpoon'.\");\n\n",
|
||||
" }\n"
|
||||
].join
|
||||
returned = @cmock_generator_utils.code_verify_an_arg_expectation(function, var_type, var_name)
|
||||
returned = @cmock_generator_utils.code_verify_an_arg_expectation(function, {:type => var_type, :name => var_name})
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
@@ -239,10 +241,10 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase
|
||||
" {\n",
|
||||
" SOME_STRUCT* p_expected = Mock.Toaster_Expected_Bread;\n",
|
||||
" Mock.Toaster_Expected_Bread++;\n",
|
||||
" TEST_ASSERT_EQUAL_MEMORY_MESSAGE((void*)p_expected, (void*)&(Bread), sizeof(SOME_STRUCT), \"Function 'Toaster' called with unexpected value for argument 'Bread'.\");\n",
|
||||
" TEST_ASSERT_EQUAL_MEMORY_MESSAGE((void*)p_expected, (void*)&(Bread), sizeof(SOME_STRUCT), \"Function 'Toaster' called with unexpected value for argument 'Bread'.\");\n\n",
|
||||
" }\n"
|
||||
].join
|
||||
returned = @cmock_generator_utils.code_verify_an_arg_expectation(function, var_type, var_name)
|
||||
returned = @cmock_generator_utils.code_verify_an_arg_expectation(function, {:type => var_type, :name => var_name})
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
@@ -265,7 +267,7 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase
|
||||
" { TEST_ASSERT_EQUAL_MEMORY_MESSAGE((void*)(*p_expected), (void*)Bread, sizeof(SOME_STRUCT), \"Function 'Toaster' called with unexpected value for argument 'Bread'.\"); }\n",
|
||||
" }\n"
|
||||
].join
|
||||
returned = @cmock_generator_utils.code_verify_an_arg_expectation(function, var_type, var_name)
|
||||
returned = @cmock_generator_utils.code_verify_an_arg_expectation(function, {:type => var_type, :name => var_name})
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
@@ -275,7 +277,7 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase
|
||||
var_name = "Strawberry"
|
||||
|
||||
@cmock_generator_utils.helpers = {:unity_helper => @unity_helper}
|
||||
@unity_helper.expect.get_helper(var_type).returns("TEST_ASSERT_EQUAL_FRUIT_ARRAY_MESSAGE")
|
||||
@unity_helper.expect.get_helper(var_type).returns("TEST_ASSERT_EQUAL_FRUIT_ARRAY")
|
||||
|
||||
expected = ["\n",
|
||||
" if (Mock.Blender_Expected_Strawberry != Mock.Blender_Expected_Strawberry_Tail)\n",
|
||||
@@ -285,10 +287,10 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase
|
||||
" if (*p_expected == NULL)\n",
|
||||
" { TEST_ASSERT_NULL(Strawberry); }\n",
|
||||
" else\n",
|
||||
" { TEST_ASSERT_EQUAL_FRUIT_ARRAY_MESSAGE(*p_expected, Strawberry, 1, \"Function 'Blender' called with unexpected value for argument 'Strawberry'.\"); }\n",
|
||||
" { TEST_ASSERT_EQUAL_FRUIT_ARRAY(*p_expected, Strawberry, 1); }\n",
|
||||
" }\n"
|
||||
].join
|
||||
returned = @cmock_generator_utils.code_verify_an_arg_expectation(function, var_type, var_name)
|
||||
returned = @cmock_generator_utils.code_verify_an_arg_expectation(function, {:type => var_type, :name => var_name})
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -262,7 +262,8 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
:name=>"FunkyVoidReturned",
|
||||
:return_type=>"void",
|
||||
:modifier=>"",
|
||||
:args=>[{:type=>"int", :name=>"a"}],
|
||||
:contains_ptr? => false,
|
||||
:args=>[{:type=>"int", :name=>"a", :ptr? => false}],
|
||||
:args_string=>"int a" }
|
||||
assert_equal(expected, @parser.parse_declaration(source))
|
||||
end
|
||||
@@ -274,6 +275,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
:name=>"FunkyVoidAsArg",
|
||||
:return_type=>"int",
|
||||
:modifier=>"",
|
||||
:contains_ptr? => false,
|
||||
:args=>[],
|
||||
:args_string=>"void" }
|
||||
assert_equal(expected, @parser.parse_declaration(source))
|
||||
@@ -286,7 +288,8 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
:name=>"FunkyVoidPointer",
|
||||
:return_type=>"char",
|
||||
:modifier=>"",
|
||||
:args=>[{:type=>"MY_FUNKY_VOID*", :name=>"bluh"}],
|
||||
:contains_ptr? => true,
|
||||
:args=>[{:type=>"MY_FUNKY_VOID*", :name=>"bluh", :ptr? => true}],
|
||||
:args_string=>"MY_FUNKY_VOID* bluh" }
|
||||
assert_equal(expected, @parser.parse_declaration(source))
|
||||
end
|
||||
@@ -359,7 +362,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
begin
|
||||
@parser.parse(source)
|
||||
rescue RuntimeError => e
|
||||
assert(e.message.include? "Failed Parsing Declaration Prototype!")
|
||||
assert(e.message.include?("Failed Parsing Declaration Prototype!"))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -371,8 +374,9 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
:name=>"Foo",
|
||||
:return_type=>"int",
|
||||
:modifier=>"",
|
||||
:args=>[ {:type=>"int", :name=>"a"},
|
||||
{:type=>"unsigned int", :name=>"b"}
|
||||
:contains_ptr? => false,
|
||||
:args=>[ {:type=>"int", :name=>"a", :ptr? => false},
|
||||
{:type=>"unsigned int", :name=>"b", :ptr? => false}
|
||||
],
|
||||
:args_string=>"int a, unsigned int b" }
|
||||
assert_equal(expected, @parser.parse_declaration(source))
|
||||
@@ -386,9 +390,10 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
:name=>"FunkyChicken",
|
||||
:return_type=>"void",
|
||||
:modifier=>"",
|
||||
:args=>[ {:type=>"uint", :name=>"la"},
|
||||
{:type=>"int", :name=>"de"},
|
||||
{:type=>"bool", :name=>"da"}
|
||||
:contains_ptr? => false,
|
||||
:args=>[ {:type=>"uint", :name=>"la", :ptr? => false},
|
||||
{:type=>"int", :name=>"de", :ptr? => false},
|
||||
{:type=>"bool", :name=>"da", :ptr? => false}
|
||||
],
|
||||
:args_string=>"uint la, int de, bool da" }
|
||||
assert_equal(expected, @parser.parse_declaration(source))
|
||||
@@ -402,6 +407,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
:name=>"tat",
|
||||
:return_type=>"void",
|
||||
:modifier=>"",
|
||||
:contains_ptr? => false,
|
||||
:args=>[ ],
|
||||
:args_string=>"void" }
|
||||
assert_equal(expected, @parser.parse_declaration(source))
|
||||
@@ -415,8 +421,9 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
:name=>"TheMatrix",
|
||||
:return_type=>"int",
|
||||
:modifier=>"const",
|
||||
:args=>[ {:type=>"int", :name=>"Trinity"},
|
||||
{:type=>"unsigned int*", :name=>"Neo"}
|
||||
:contains_ptr? => true,
|
||||
:args=>[ {:type=>"int", :name=>"Trinity", :ptr? => false},
|
||||
{:type=>"unsigned int*", :name=>"Neo", :ptr? => true}
|
||||
],
|
||||
:args_string=>"int Trinity, unsigned int* Neo" }
|
||||
assert_equal(expected, @parser.parse_declaration(source))
|
||||
@@ -432,8 +439,9 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
:name=>"TheMatrix",
|
||||
:return_type=>"int",
|
||||
:modifier=>"const",
|
||||
:args=>[ {:type=>"int", :name=>"Trinity"},
|
||||
{:type=>"unsigned int*", :name=>"Neo"}
|
||||
:contains_ptr? => true,
|
||||
:args=>[ {:type=>"int", :name=>"Trinity", :ptr? => false},
|
||||
{:type=>"unsigned int*", :name=>"Neo", :ptr? => true}
|
||||
],
|
||||
:args_string=>"int Trinity, unsigned int* Neo" },
|
||||
{ :var_arg=>nil,
|
||||
@@ -441,8 +449,9 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
:name=>"Morpheus",
|
||||
:return_type=>"int",
|
||||
:modifier=>"",
|
||||
:args=>[ {:type=>"int", :name=>"cmock_arg1"},
|
||||
{:type=>"unsigned int*", :name=>"cmock_arg2"}
|
||||
:contains_ptr? => true,
|
||||
:args=>[ {:type=>"int", :name=>"cmock_arg1", :ptr? => false},
|
||||
{:type=>"unsigned int*", :name=>"cmock_arg2", :ptr? => true}
|
||||
],
|
||||
:args_string=>"int cmock_arg1, unsigned int* cmock_arg2"
|
||||
}]
|
||||
@@ -459,8 +468,9 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
:name=>"TheMatrix",
|
||||
:return_type=>"int",
|
||||
:modifier=>"const",
|
||||
:args=>[ {:type=>"int", :name=>"Trinity"},
|
||||
{:type=>"unsigned int*", :name=>"Neo"}
|
||||
:contains_ptr? => true,
|
||||
:args=>[ {:type=>"int", :name=>"Trinity", :ptr? => false},
|
||||
{:type=>"unsigned int*", :name=>"Neo", :ptr? => true}
|
||||
],
|
||||
:args_string=>"int Trinity, unsigned int* Neo"
|
||||
}]
|
||||
@@ -479,7 +489,8 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
:name=>"DrHorrible",
|
||||
:return_type=>"void",
|
||||
:modifier=>"",
|
||||
:args=>[ {:type=>"int", :name=>"SingAlong"} ],
|
||||
:contains_ptr? => false,
|
||||
:args=>[ {:type=>"int", :name=>"SingAlong", :ptr? => false} ],
|
||||
:args_string=>"int SingAlong"
|
||||
},
|
||||
{ :var_arg=>nil,
|
||||
@@ -487,6 +498,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
:name=>"CaptainHammer",
|
||||
:return_type=>"int",
|
||||
:modifier=>"",
|
||||
:contains_ptr? => false,
|
||||
:args=>[ ],
|
||||
:args_string=>"void"
|
||||
}]
|
||||
@@ -504,7 +516,8 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
:name=>"DrHorrible",
|
||||
:return_type=>"int",
|
||||
:modifier=>"",
|
||||
:args=>[ {:type=>"struct SingAlong", :name=>"Blog"} ],
|
||||
:contains_ptr? => false,
|
||||
:args=>[ {:type=>"struct SingAlong", :name=>"Blog", :ptr? => false} ],
|
||||
:args_string=>"struct SingAlong Blog"
|
||||
},
|
||||
{ :var_arg=>nil,
|
||||
@@ -512,7 +525,8 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
:name=>"Penny",
|
||||
:return_type=>"void",
|
||||
:modifier=>"",
|
||||
:args=>[ {:type=>"struct _KeepYourHeadUp_*", :name=>"BillyBuddy"} ],
|
||||
:contains_ptr? => true,
|
||||
:args=>[ {:type=>"struct _KeepYourHeadUp_*", :name=>"BillyBuddy", :ptr? => true} ],
|
||||
:args_string=>"struct const _KeepYourHeadUp_* const BillyBuddy"
|
||||
},
|
||||
{ :var_arg=>nil,
|
||||
@@ -520,6 +534,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
:name=>"CaptainHammer",
|
||||
:return_type=>"struct TheseArentTheHammer",
|
||||
:modifier=>"",
|
||||
:contains_ptr? => false,
|
||||
:args=>[ ],
|
||||
:args_string=>"void"
|
||||
}]
|
||||
@@ -534,8 +549,9 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
:name=>"XFiles",
|
||||
:return_type=>"int",
|
||||
:modifier=>"",
|
||||
:args=>[ {:type=>"int", :name=>"Scully"},
|
||||
{:type=>"int", :name=>"Mulder"}
|
||||
:contains_ptr? => false,
|
||||
:args=>[ {:type=>"int", :name=>"Scully", :ptr? => false},
|
||||
{:type=>"int", :name=>"Mulder", :ptr? => false}
|
||||
],
|
||||
:args_string=>"int Scully, int Mulder"
|
||||
}]
|
||||
|
||||
@@ -23,7 +23,7 @@ class CMockPluginManagerTest < Test::Unit::TestCase
|
||||
test_plugins.each do |plugin|
|
||||
contained[:expect] = true if plugin.instance_of?(CMockGeneratorPluginExpect)
|
||||
contained[:ignore] = true if plugin.instance_of?(CMockGeneratorPluginIgnore)
|
||||
contained[:cexception] = true if plugin.instance_of?(CMockGeneratorPluginCException)
|
||||
contained[:cexception] = true if plugin.instance_of?(CMockGeneratorPluginCexception)
|
||||
end
|
||||
assert_equal(true, contained[:expect])
|
||||
assert_equal(true, contained[:ignore])
|
||||
@@ -41,7 +41,7 @@ class CMockPluginManagerTest < Test::Unit::TestCase
|
||||
test_plugins.each do |plugin|
|
||||
contained[:expect] = true if plugin.instance_of?(CMockGeneratorPluginExpect)
|
||||
contained[:ignore] = true if plugin.instance_of?(CMockGeneratorPluginIgnore)
|
||||
contained[:cexception] = true if plugin.instance_of?(CMockGeneratorPluginCException)
|
||||
contained[:cexception] = true if plugin.instance_of?(CMockGeneratorPluginCexception)
|
||||
end
|
||||
assert_equal(true, contained[:expect])
|
||||
assert_equal(false,contained[:ignore])
|
||||
|
||||
Reference in New Issue
Block a user