- 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:
mvandervoord
2009-11-26 00:55:02 +00:00
parent f63d8d7813
commit 0f857f24ec
13 changed files with 398 additions and 68 deletions
+64
View File
@@ -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 -1
View File
@@ -1,5 +1,5 @@
class CMockGeneratorPluginCException class CMockGeneratorPluginCexception
attr_reader :config, :utils attr_reader :config, :utils
+2 -2
View File
@@ -51,7 +51,7 @@ class CMockGeneratorPluginExpect
lines << MOCK_IMPLEMENT_ORDERED_SNIPPET % [function[:name], err_msg, (err_msg.size + 1).to_s] lines << MOCK_IMPLEMENT_ORDERED_SNIPPET % [function[:name], err_msg, (err_msg.size + 1).to_s]
end end
function[:args].each do |arg| 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 end
lines lines
end end
@@ -64,7 +64,7 @@ class CMockGeneratorPluginExpect
if (function[:args_string] != "void") if (function[:args_string] != "void")
lines << "void ExpectParameters_#{func_name}(#{function[:args_string]})\n{\n" lines << "void ExpectParameters_#{func_name}(#{function[:args_string]})\n{\n"
function[:args].each do |arg| 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 end
lines << "}\n\n" lines << "}\n\n"
end end
+74 -13
View File
@@ -7,6 +7,7 @@ class CMockGeneratorUtils
@config = config @config = config
@ptr_handling = @config.when_ptr_star @ptr_handling = @config.when_ptr_star
@ordered = @config.enforce_strict_ordering @ordered = @config.enforce_strict_ordering
@arrays = @config.plugins.include? :array
@helpers = helpers @helpers = helpers
end end
@@ -26,10 +27,16 @@ class CMockGeneratorUtils
INSERT_EXPECT_CODE_SNIPPET % [type, array, newValue] INSERT_EXPECT_CODE_SNIPPET % [type, array, newValue]
end end
def code_add_an_arg_expectation(function, arg_type, expected) def code_add_an_arg_expectation(function, arg, depth=1)
var = "Mock.#{function[:name]}_Expected_#{expected}" var = "Mock.#{function[:name]}_Expected_#{arg[:name]}"
lines = code_insert_item_into_expect_array(arg_type, var, expected) lines = code_insert_item_into_expect_array(arg[:type], var, arg[:name])
lines << INSERT_EXPECT_SETUP_SNIPPET % [var, function[: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 end
def code_add_base_expectation(func_name) def code_add_base_expectation(func_name)
@@ -43,14 +50,16 @@ class CMockGeneratorUtils
lines lines
end end
def code_verify_an_arg_expectation(function, arg_type, arg) def code_verify_an_arg_expectation(function, arg)
(INSERT_ARG_VERIFY_START_SNIPPET % ["#{function[:name]}_Expected_#{arg}", arg_type]) + (INSERT_ARG_VERIFY_START_SNIPPET % ["#{function[:name]}_Expected_#{arg[:name]}", arg[:type]]) +
expect_helper(arg_type, '*p_expected', arg, "\"Function '#{function[:name]}' called with unexpected value for argument '#{arg}'.\"") + expect_helper(arg, '*p_expected', "\"Function '#{function[:name]}' called with unexpected value for argument '#{arg[:name]}'.\"", "#{function[:name]}_Expected_#{arg[:name]}_Depth") +
" }\n" "\n }\n"
end end
def expect_helper(c_type, expected, arg, msg) def expect_helper(arg, expected, msg, depth_name='1')
if ((c_type.strip[-1] == 42) and (@ptr_handling == :compare_ptr)) c_type = arg[:type]
name = arg[:name]
if ((arg[:ptr?]) and (@ptr_handling == :compare_ptr))
unity_func = "TEST_ASSERT_EQUAL_INT_MESSAGE" unity_func = "TEST_ASSERT_EQUAL_INT_MESSAGE"
else else
unity_func = (@helpers.nil? or @helpers[:unity_helper].nil?) ? "TEST_ASSERT_EQUAL_MESSAGE" : @helpers[:unity_helper].get_helper(c_type) 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) case(unity_func)
when "TEST_ASSERT_EQUAL_MEMORY_MESSAGE" when "TEST_ASSERT_EQUAL_MEMORY_MESSAGE"
full_expected = (expected =~ /^\*/) ? expected.slice(1..-1) : "&(#{expected})" 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" 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/ 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 else
return " #{unity_func}(#{expected}, #{arg}#{unity_msg});\n" return " #{unity_func}(#{expected}, #{name}#{unity_msg});\n"
end end
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 = INSERT_EXPECT_SETUP_SNIPPET =
" %1$s = %1$s_Head;\n %1$s += Mock.%2$s_CallCount;\n" " %1$s = %1$s_Head;\n %1$s += Mock.%2$s_CallCount;\n"
@@ -122,4 +178,9 @@ class CMockGeneratorUtils
Mock.%1$s++; Mock.%1$s++;
] ]
INSERT_ARG_DEPTH_START_SNIPPET = %q[
int Depth = *Mock.%1$s;
Mock.%1$s++;
]
end end
+13 -3
View File
@@ -104,13 +104,22 @@ class CMockHeaderParser
args = [] args = []
arg_list.split(',').each do |arg| arg_list.split(',').each do |arg|
arg.strip! arg.strip!
return args if (arg =~ /^\s*((\.\.\.)|(void))\s*$/) # we're done if we reach void by itself or ... 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 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 args << { :type => (arg_type =arg_elements[0..-2].join(' ')),
:name => arg_elements[-1],
:ptr? => divine_ptr(arg_type)
}
end end
return args return args
end 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) def clean_args(arg_list)
if ((@local_as_void.include?(arg_list.strip)) or (arg_list.empty?)) if ((@local_as_void.include?(arg_list.strip)) or (arg_list.empty?))
return 'void' return 'void'
@@ -199,6 +208,7 @@ class CMockHeaderParser
args = clean_args(args) args = clean_args(args)
decl[:args_string] = args decl[:args_string] = args
decl[:args] = parse_args(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 if (decl[:return_type].nil? or decl[:name].nil? or decl[:args].nil? or
decl[:return_type].empty? or decl[:name].empty?) decl[:return_type].empty? or decl[:name].empty?)
+17 -8
View File
@@ -1,18 +1,23 @@
require "cmock_generator_plugin_expect.rb"
require "cmock_generator_plugin_ignore.rb"
require "cmock_generator_plugin_cexception.rb"
class CMockPluginManager class CMockPluginManager
attr_accessor :plugins attr_accessor :plugins
def initialize(config, utils) def initialize(config, utils)
plugins_to_load = config.plugins
@plugins = [] @plugins = []
@plugins << CMockGeneratorPluginExpect.new( config, utils ) plugins_to_load = ["expect", config.plugins].flatten.uniq.compact
@plugins << CMockGeneratorPluginCException.new( config, utils ) if plugins_to_load.include? 'cexception' plugins_to_load.each do |plugin|
@plugins << CMockGeneratorPluginIgnore.new( config, utils ) if plugins_to_load.include? 'ignore' 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 end
def run(method, args=nil) 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 return @plugins.collect{ |plugin| plugin.send(method, args) if plugin.respond_to?(method) }.flatten.join
end end
end end
def camelize(lower_case_and_underscored_word)
lower_case_and_underscored_word.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
end
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: | :header: |
void function_a(void); void function_a(void);
void function_b(void); void function_b(void);
void function_c(void);
:code: | :code: |
void function_a(void) void function_a(void)
@@ -1,11 +1,11 @@
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper" require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
require 'cmock_generator_plugin_cexception' require 'cmock_generator_plugin_cexception'
class CMockGeneratorPluginCExceptionTest < Test::Unit::TestCase class CMockGeneratorPluginCexceptionTest < Test::Unit::TestCase
def setup def setup
create_mocks :config, :utils create_mocks :config, :utils
@config.stubs!(:respond_to?).returns(true) @config.stubs!(:respond_to?).returns(true)
@cmock_generator_plugin_cexception = CMockGeneratorPluginCException.new(@config, @utils) @cmock_generator_plugin_cexception = CMockGeneratorPluginCexception.new(@config, @utils)
end end
def teardown 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 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"} 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][0]).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][1]).returns("mocked_retval_2")
expected = ["\n", expected = ["\n",
" Mock.Cherry_CallCount++;\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 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"} 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.code_add_base_expectation("Lemon").returns("mock_retval_0")
@utils.expect.create_call_list(function).returns("mock_retval_3") @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") @utils.expect.code_insert_item_into_expect_array(function[:return_type], "Mock.Lemon_Return", 'toReturn').returns("mock_retval_1")
+15 -13
View File
@@ -6,6 +6,7 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase
create_mocks :config, :unity_helper create_mocks :config, :unity_helper
@config.expect.when_ptr_star.returns(:compare_data) @config.expect.when_ptr_star.returns(:compare_data)
@config.expect.enforce_strict_ordering.returns(false) @config.expect.enforce_strict_ordering.returns(false)
@config.expect.plugins.returns([:arrays])
@cmock_generator_utils = CMockGeneratorUtils.new(@config) @cmock_generator_utils = CMockGeneratorUtils.new(@config)
end end
@@ -21,6 +22,7 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase
create_mocks :config create_mocks :config
@config.expect.when_ptr_star.returns(:compare_ptr) @config.expect.when_ptr_star.returns(:compare_ptr)
@config.expect.enforce_strict_ordering.returns(false) @config.expect.enforce_strict_ordering.returns(false)
@config.expect.plugins.returns([])
@cmock_generator_utils = CMockGeneratorUtils.new(@config, {:A=>1, :B=>2}) @cmock_generator_utils = CMockGeneratorUtils.new(@config, {:A=>1, :B=>2})
assert_equal(@config, @cmock_generator_utils.config) assert_equal(@config, @cmock_generator_utils.config)
assert_equal({:A=>1, :B=>2},@cmock_generator_utils.helpers) 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_Expected_Spork_Head;\n",
" Mock.PizzaCutter_Expected_Spork += Mock.PizzaCutter_CallCount;\n" " Mock.PizzaCutter_Expected_Spork += Mock.PizzaCutter_CallCount;\n"
].join ].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) assert_equal(expected, returned)
end end
@@ -179,10 +181,10 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase
" {\n", " {\n",
" uint16* p_expected = Mock.CanOpener_Expected_CorkScrew;\n", " uint16* p_expected = Mock.CanOpener_Expected_CorkScrew;\n",
" 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" " }\n"
].join ].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) assert_equal(expected, returned)
end end
@@ -199,10 +201,10 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase
" {\n", " {\n",
" const char** p_expected = Mock.MeasureCup_Expected_TeaSpoon;\n", " const char** p_expected = Mock.MeasureCup_Expected_TeaSpoon;\n",
" 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" " }\n"
].join ].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) assert_equal(expected, returned)
end end
@@ -219,10 +221,10 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase
" {\n", " {\n",
" MANDELBROT_SET_T* p_expected = Mock.TeaPot_Expected_TeaSpoon;\n", " MANDELBROT_SET_T* p_expected = Mock.TeaPot_Expected_TeaSpoon;\n",
" 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" " }\n"
].join ].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) assert_equal(expected, returned)
end end
@@ -239,10 +241,10 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase
" {\n", " {\n",
" SOME_STRUCT* p_expected = Mock.Toaster_Expected_Bread;\n", " SOME_STRUCT* p_expected = Mock.Toaster_Expected_Bread;\n",
" 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" " }\n"
].join ].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) assert_equal(expected, returned)
end 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", " { 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 ].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) assert_equal(expected, returned)
end end
@@ -275,7 +277,7 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase
var_name = "Strawberry" var_name = "Strawberry"
@cmock_generator_utils.helpers = {:unity_helper => @unity_helper} @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", expected = ["\n",
" if (Mock.Blender_Expected_Strawberry != Mock.Blender_Expected_Strawberry_Tail)\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", " if (*p_expected == NULL)\n",
" { TEST_ASSERT_NULL(Strawberry); }\n", " { TEST_ASSERT_NULL(Strawberry); }\n",
" else\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" " }\n"
].join ].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) assert_equal(expected, returned)
end end
end end
+37 -21
View File
@@ -262,7 +262,8 @@ class CMockHeaderParserTest < Test::Unit::TestCase
:name=>"FunkyVoidReturned", :name=>"FunkyVoidReturned",
:return_type=>"void", :return_type=>"void",
:modifier=>"", :modifier=>"",
:args=>[{:type=>"int", :name=>"a"}], :contains_ptr? => false,
:args=>[{:type=>"int", :name=>"a", :ptr? => false}],
:args_string=>"int a" } :args_string=>"int a" }
assert_equal(expected, @parser.parse_declaration(source)) assert_equal(expected, @parser.parse_declaration(source))
end end
@@ -274,6 +275,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
:name=>"FunkyVoidAsArg", :name=>"FunkyVoidAsArg",
:return_type=>"int", :return_type=>"int",
:modifier=>"", :modifier=>"",
:contains_ptr? => false,
:args=>[], :args=>[],
:args_string=>"void" } :args_string=>"void" }
assert_equal(expected, @parser.parse_declaration(source)) assert_equal(expected, @parser.parse_declaration(source))
@@ -286,7 +288,8 @@ class CMockHeaderParserTest < Test::Unit::TestCase
:name=>"FunkyVoidPointer", :name=>"FunkyVoidPointer",
:return_type=>"char", :return_type=>"char",
:modifier=>"", :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" } :args_string=>"MY_FUNKY_VOID* bluh" }
assert_equal(expected, @parser.parse_declaration(source)) assert_equal(expected, @parser.parse_declaration(source))
end end
@@ -359,7 +362,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
begin begin
@parser.parse(source) @parser.parse(source)
rescue RuntimeError => e rescue RuntimeError => e
assert(e.message.include? "Failed Parsing Declaration Prototype!") assert(e.message.include?("Failed Parsing Declaration Prototype!"))
end end
end end
@@ -371,8 +374,9 @@ class CMockHeaderParserTest < Test::Unit::TestCase
:name=>"Foo", :name=>"Foo",
:return_type=>"int", :return_type=>"int",
:modifier=>"", :modifier=>"",
:args=>[ {:type=>"int", :name=>"a"}, :contains_ptr? => false,
{:type=>"unsigned int", :name=>"b"} :args=>[ {:type=>"int", :name=>"a", :ptr? => false},
{:type=>"unsigned int", :name=>"b", :ptr? => false}
], ],
:args_string=>"int a, unsigned int b" } :args_string=>"int a, unsigned int b" }
assert_equal(expected, @parser.parse_declaration(source)) assert_equal(expected, @parser.parse_declaration(source))
@@ -386,9 +390,10 @@ class CMockHeaderParserTest < Test::Unit::TestCase
:name=>"FunkyChicken", :name=>"FunkyChicken",
:return_type=>"void", :return_type=>"void",
:modifier=>"", :modifier=>"",
:args=>[ {:type=>"uint", :name=>"la"}, :contains_ptr? => false,
{:type=>"int", :name=>"de"}, :args=>[ {:type=>"uint", :name=>"la", :ptr? => false},
{:type=>"bool", :name=>"da"} {:type=>"int", :name=>"de", :ptr? => false},
{:type=>"bool", :name=>"da", :ptr? => false}
], ],
:args_string=>"uint la, int de, bool da" } :args_string=>"uint la, int de, bool da" }
assert_equal(expected, @parser.parse_declaration(source)) assert_equal(expected, @parser.parse_declaration(source))
@@ -402,6 +407,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
:name=>"tat", :name=>"tat",
:return_type=>"void", :return_type=>"void",
:modifier=>"", :modifier=>"",
:contains_ptr? => false,
:args=>[ ], :args=>[ ],
:args_string=>"void" } :args_string=>"void" }
assert_equal(expected, @parser.parse_declaration(source)) assert_equal(expected, @parser.parse_declaration(source))
@@ -415,8 +421,9 @@ class CMockHeaderParserTest < Test::Unit::TestCase
:name=>"TheMatrix", :name=>"TheMatrix",
:return_type=>"int", :return_type=>"int",
:modifier=>"const", :modifier=>"const",
:args=>[ {:type=>"int", :name=>"Trinity"}, :contains_ptr? => true,
{:type=>"unsigned int*", :name=>"Neo"} :args=>[ {:type=>"int", :name=>"Trinity", :ptr? => false},
{:type=>"unsigned int*", :name=>"Neo", :ptr? => true}
], ],
:args_string=>"int Trinity, unsigned int* Neo" } :args_string=>"int Trinity, unsigned int* Neo" }
assert_equal(expected, @parser.parse_declaration(source)) assert_equal(expected, @parser.parse_declaration(source))
@@ -432,8 +439,9 @@ class CMockHeaderParserTest < Test::Unit::TestCase
:name=>"TheMatrix", :name=>"TheMatrix",
:return_type=>"int", :return_type=>"int",
:modifier=>"const", :modifier=>"const",
:args=>[ {:type=>"int", :name=>"Trinity"}, :contains_ptr? => true,
{:type=>"unsigned int*", :name=>"Neo"} :args=>[ {:type=>"int", :name=>"Trinity", :ptr? => false},
{:type=>"unsigned int*", :name=>"Neo", :ptr? => true}
], ],
:args_string=>"int Trinity, unsigned int* Neo" }, :args_string=>"int Trinity, unsigned int* Neo" },
{ :var_arg=>nil, { :var_arg=>nil,
@@ -441,8 +449,9 @@ class CMockHeaderParserTest < Test::Unit::TestCase
:name=>"Morpheus", :name=>"Morpheus",
:return_type=>"int", :return_type=>"int",
:modifier=>"", :modifier=>"",
:args=>[ {:type=>"int", :name=>"cmock_arg1"}, :contains_ptr? => true,
{:type=>"unsigned int*", :name=>"cmock_arg2"} :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" :args_string=>"int cmock_arg1, unsigned int* cmock_arg2"
}] }]
@@ -459,8 +468,9 @@ class CMockHeaderParserTest < Test::Unit::TestCase
:name=>"TheMatrix", :name=>"TheMatrix",
:return_type=>"int", :return_type=>"int",
:modifier=>"const", :modifier=>"const",
:args=>[ {:type=>"int", :name=>"Trinity"}, :contains_ptr? => true,
{:type=>"unsigned int*", :name=>"Neo"} :args=>[ {:type=>"int", :name=>"Trinity", :ptr? => false},
{:type=>"unsigned int*", :name=>"Neo", :ptr? => true}
], ],
:args_string=>"int Trinity, unsigned int* Neo" :args_string=>"int Trinity, unsigned int* Neo"
}] }]
@@ -479,7 +489,8 @@ class CMockHeaderParserTest < Test::Unit::TestCase
:name=>"DrHorrible", :name=>"DrHorrible",
:return_type=>"void", :return_type=>"void",
:modifier=>"", :modifier=>"",
:args=>[ {:type=>"int", :name=>"SingAlong"} ], :contains_ptr? => false,
:args=>[ {:type=>"int", :name=>"SingAlong", :ptr? => false} ],
:args_string=>"int SingAlong" :args_string=>"int SingAlong"
}, },
{ :var_arg=>nil, { :var_arg=>nil,
@@ -487,6 +498,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
:name=>"CaptainHammer", :name=>"CaptainHammer",
:return_type=>"int", :return_type=>"int",
:modifier=>"", :modifier=>"",
:contains_ptr? => false,
:args=>[ ], :args=>[ ],
:args_string=>"void" :args_string=>"void"
}] }]
@@ -504,7 +516,8 @@ class CMockHeaderParserTest < Test::Unit::TestCase
:name=>"DrHorrible", :name=>"DrHorrible",
:return_type=>"int", :return_type=>"int",
:modifier=>"", :modifier=>"",
:args=>[ {:type=>"struct SingAlong", :name=>"Blog"} ], :contains_ptr? => false,
:args=>[ {:type=>"struct SingAlong", :name=>"Blog", :ptr? => false} ],
:args_string=>"struct SingAlong Blog" :args_string=>"struct SingAlong Blog"
}, },
{ :var_arg=>nil, { :var_arg=>nil,
@@ -512,7 +525,8 @@ class CMockHeaderParserTest < Test::Unit::TestCase
:name=>"Penny", :name=>"Penny",
:return_type=>"void", :return_type=>"void",
:modifier=>"", :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" :args_string=>"struct const _KeepYourHeadUp_* const BillyBuddy"
}, },
{ :var_arg=>nil, { :var_arg=>nil,
@@ -520,6 +534,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
:name=>"CaptainHammer", :name=>"CaptainHammer",
:return_type=>"struct TheseArentTheHammer", :return_type=>"struct TheseArentTheHammer",
:modifier=>"", :modifier=>"",
:contains_ptr? => false,
:args=>[ ], :args=>[ ],
:args_string=>"void" :args_string=>"void"
}] }]
@@ -534,8 +549,9 @@ class CMockHeaderParserTest < Test::Unit::TestCase
:name=>"XFiles", :name=>"XFiles",
:return_type=>"int", :return_type=>"int",
:modifier=>"", :modifier=>"",
:args=>[ {:type=>"int", :name=>"Scully"}, :contains_ptr? => false,
{:type=>"int", :name=>"Mulder"} :args=>[ {:type=>"int", :name=>"Scully", :ptr? => false},
{:type=>"int", :name=>"Mulder", :ptr? => false}
], ],
:args_string=>"int Scully, int Mulder" :args_string=>"int Scully, int Mulder"
}] }]
+2 -2
View File
@@ -23,7 +23,7 @@ class CMockPluginManagerTest < Test::Unit::TestCase
test_plugins.each do |plugin| test_plugins.each do |plugin|
contained[:expect] = true if plugin.instance_of?(CMockGeneratorPluginExpect) contained[:expect] = true if plugin.instance_of?(CMockGeneratorPluginExpect)
contained[:ignore] = true if plugin.instance_of?(CMockGeneratorPluginIgnore) 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 end
assert_equal(true, contained[:expect]) assert_equal(true, contained[:expect])
assert_equal(true, contained[:ignore]) assert_equal(true, contained[:ignore])
@@ -41,7 +41,7 @@ class CMockPluginManagerTest < Test::Unit::TestCase
test_plugins.each do |plugin| test_plugins.each do |plugin|
contained[:expect] = true if plugin.instance_of?(CMockGeneratorPluginExpect) contained[:expect] = true if plugin.instance_of?(CMockGeneratorPluginExpect)
contained[:ignore] = true if plugin.instance_of?(CMockGeneratorPluginIgnore) 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 end
assert_equal(true, contained[:expect]) assert_equal(true, contained[:expect])
assert_equal(false,contained[:ignore]) assert_equal(false,contained[:ignore])