- better array and pointer support

git-svn-id: http://cmock.svn.sourceforge.net/svnroot/cmock/trunk@146 bf332499-1b4d-0410-844d-d2d48d5cc64c
This commit is contained in:
mvandervoord
2009-11-27 03:40:48 +00:00
parent 0f857f24ec
commit dbb397adbe
12 changed files with 679 additions and 53 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
tools_root: &tools_root 'C:\Program Files\IAR Systems\Embedded Workbench 5.0\'
tools_root: &tools_root 'C:\Program Files\IAR Systems\Embedded Workbench 5.3\'
compiler:
path: [*tools_root, 'arm\bin\iccarm.exe']
source_path: &systest_generated_path 'test/system/generated/'
+2 -2
View File
@@ -15,8 +15,8 @@ class CMockConfig
:treat_as_void => [],
:memcmp_if_unknown => true,
:when_no_prototypes => :warn, #the options being :ignore, :warn, or :error
:when_ptr_star =>:compare_data, #the options being :compare_ptr, :compare_data, :compare_array
:when_ptr_brackets => :compare_array, #not really supported yet
:when_ptr_star =>:compare_data, #the options being :compare_ptr, :compare_data
:when_ptr_brackets => :compare_data, #not really supported yet
}
def initialize(options=nil)
+52 -11
View File
@@ -14,7 +14,7 @@ class CMockGeneratorPluginArray
def instance_structure(function)
lines = ""
function[:args].each do |arg|
lines << INSTANCE_STRUCTURE_ITEM_SNIPPET % "#{function[:name]}_Expected_#{arg[:name]}" if (arg[:ptr?])
lines << INSTANCE_STRUCTURE_DEPTH_SNIPPET % "#{function[:name]}_Expected_#{arg[:name]}" if (arg[:ptr?])
end
lines
end
@@ -28,10 +28,11 @@ class CMockGeneratorPluginArray
return "void #{function[:name]}_ExpectWithArrayAndReturn(#{function[:return_string]});\n"
end
else
args_string = function[:args].map{|m| m[:ptr?] ? "#{m[:type]} #{m[:name]}, int #{m[:name]}_Depth" : "#{m[:type]} #{m[:name]}"}.join(', ')
if (function[:return_type] == 'void')
return "void #{function[:name]}_ExpectWithArray(#{function[:args_string]});\n"
return "void #{function[:name]}_ExpectWithArray(#{args_string});\n"
else
return "void #{function[:name]}_ExpectWithArrayAndReturn(#{function[:args_string]}, #{function[:return_string]});\n"
return "void #{function[:name]}_ExpectWithArrayAndReturn(#{args_string}, #{function[:return_string]});\n"
end
end
end
@@ -41,24 +42,64 @@ class CMockGeneratorPluginArray
end
def mock_interfaces(function)
return nil unless function[:args_string].include? '*'
nil
end
def mock_verify(function)
nil
return nil unless function[:contains_ptr?]
lines = []
func_name = function[:name]
args_string = function[:args].map{|m| m[:ptr?] ? "#{m[:type]} #{m[:name]}, int #{m[:name]}_Depth" : "#{m[:type]} #{m[:name]}"}.join(', ')
call_string = function[:args].map{|m| m[:ptr?] ? "#{m[:name]}, #{m[:name]}_Depth" : m[:name]}.join(', ')
# Parameter Helper Function
if (function[:args_string] != "void")
lines << "void ExpectParametersWithArray_#{func_name}(#{args_string})\n{\n"
function[:args].each do |arg|
lines << @utils.code_add_an_arg_expectation(function, arg, arg[:ptr?] ? "#{arg[:name]}_Depth" : "1")
end
lines << "}\n\n"
end
#Main Mock Interface
if (function[:return_type] == "void")
lines << "void #{func_name}_ExpectWithArray(#{args_string})\n"
else
lines << "void #{func_name}_ExpectWithArrayAndReturn(#{args_string}, #{function[:return_string]})\n"
end
lines << "{\n"
lines << @utils.code_add_base_expectation(func_name)
lines << " ExpectParametersWithArray_#{func_name}(#{call_string});\n"
if (function[:return_type] != "void")
lines << @utils.code_insert_item_into_expect_array(function[:return_type], "Mock.#{func_name}_Return", 'toReturn')
lines << " Mock.#{func_name}_Return = Mock.#{func_name}_Return_Head;\n"
lines << " Mock.#{func_name}_Return += Mock.#{func_name}_CallCount;\n"
end
lines << "}\n\n"
end
def mock_destroy(function)
nil
lines = []
function[:args].each do |arg|
lines << DESTROY_DEPTH_SNIPPET % "#{function[:name]}_Expected_#{arg[:name]}" if arg[:ptr?]
end
lines.flatten
end
private #####################
INSTANCE_STRUCTURE_ITEM_SNIPPET = %q[
INSTANCE_STRUCTURE_DEPTH_SNIPPET = %q[
int* %1$s_Depth;
int* %1$s_Depth_Head;
int* %1$s_Depth_Tail;
]
DESTROY_DEPTH_SNIPPET = %q[
if (Mock.%1$s_Depth_Head)
{
free(Mock.%1$s_Depth_Head);
}
Mock.%1$s_Depth=NULL;
Mock.%1$s_Depth_Head=NULL;
Mock.%1$s_Depth_Tail=NULL;
]
end
+2 -1
View File
@@ -34,12 +34,13 @@ class CMockGeneratorPluginCexception
def mock_interfaces(function)
arg_insert = (function[:args_string] == "void") ? "" : "#{function[:args_string]}, "
call_string = function[:args].map{|m| m[:name]}.join(', ')
[ "void #{function[:name]}_ExpectAndThrow(#{arg_insert}EXCEPTION_T toThrow)\n{\n",
@utils.code_add_base_expectation(function[:name]),
@utils.code_insert_item_into_expect_array('int', "Mock.#{function[:name]}_ThrowOnCallCount", "Mock.#{function[:name]}_CallsExpected"),
@utils.code_insert_item_into_expect_array('EXCEPTION_T', "Mock.#{function[:name]}_ThrowValue", "toThrow"),
(MOCK_INTERFACE_THROW_HANDLING_SNIPPET % function[:name]),
(function[:args_string] != "void") ? " ExpectParameters_#{function[:name]}(#{@utils.create_call_list(function)});\n" : nil,
(function[:args_string] != "void") ? " ExpectParameters_#{function[:name]}(#{call_string});\n" : nil,
"}\n\n" ].join
end
+1 -1
View File
@@ -83,7 +83,7 @@ class CMockGeneratorPluginExpect
lines << @utils.code_add_base_expectation(func_name)
if (function[:args_string] != "void")
lines << " ExpectParameters_#{func_name}(#{@utils.create_call_list(function)});\n"
lines << " ExpectParameters_#{func_name}(#{function[:args].map{|m| m[:name]}.join(', ')});\n"
end
if (function[:return_type] != "void")
-12
View File
@@ -11,18 +11,6 @@ class CMockGeneratorUtils
@helpers = helpers
end
def create_call_list(function)
call_list = ""
function[:args].each do |arg|
if call_list.empty?
call_list = arg[:name]
else
call_list += ", " + arg[:name]
end
end
return call_list
end
def code_insert_item_into_expect_array(type, array, newValue)
INSERT_EXPECT_CODE_SNIPPET % [type, array, newValue]
end
@@ -0,0 +1,295 @@
---
:cmock:
:enforce_strict_ordering: 1
:plugins:
- :array
- :cexception
- :ignore
:systest:
:types: |
typedef struct _POINT_T {
int x;
int y;
} POINT_T;
:mockable: |
#include "Exception.h"
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);
void no_pointers(int a, char* b);
int mixed(int a, int* b, int c);
:source:
:header: |
#include "Exception.h"
void function_a(void);
void function_b(void);
void function_c(void);
int function_d(void);
:code: |
void function_a(void)
{
foo(bar());
}
void function_b(void) {
fooa(bar());
}
void function_c(void) {
EXCEPTION_T e;
Try {
foos(bars());
} Catch(e) { foos("err"); }
}
int function_d(void) {
int test_list[] = { 1, 2, 3, 4, 5 };
no_pointers(1, "silly");
return mixed(6, test_list, 7);
}
:tests:
:common: |
#include "CException.h"
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: FALSE
:should: 'handle the situation where we expected nulls to pointers but did not get that'
:code: |
test()
{
POINT_T pt = {1, 2};
bar_ExpectAndReturn(&pt);
foo_Expect(NULL);
function_a();
}
- :pass: FALSE
:should: 'handle the situation where we did not expect nulls to pointers but got null'
:code: |
test()
{
POINT_T ex = {1, 2};
bar_ExpectAndReturn(NULL);
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: TRUE
:should: 'handle the situation where we pass single object with expect and use array handler'
:code: |
test()
{
POINT_T pt = {1, 2};
POINT_T ex = {1, 2};
bar_ExpectAndReturn(&pt);
foo_ExpectWithArray(&ex, 1);
function_a();
}
- :pass: FALSE
:should: 'handle the situation where we pass single object with expect and use array handler and it is wrong'
:code: |
test()
{
POINT_T pt = {1, 2};
POINT_T ex = {1, 3};
bar_ExpectAndReturn(&pt);
foo_ExpectWithArray(&ex, 1);
function_a();
}
- :pass: TRUE
:should: 'handle the situation where we pass multiple objects with expect and use array handler'
:code: |
test()
{
POINT_T pt[] = {{1, 2}, {3, 4}, {5, 6}};
POINT_T ex[] = {{1, 2}, {3, 4}, {5, 6}};
bar_ExpectAndReturn(pt);
foo_ExpectWithArray(ex, 3);
function_a();
}
- :pass: FALSE
:should: 'handle the situation where we pass multiple objects with expect and use array handler and it is wrong at end'
:code: |
test()
{
POINT_T pt[] = {{1, 2}, {3, 4}, {5, 6}};
POINT_T ex[] = {{1, 2}, {3, 4}, {5, 9}};
bar_ExpectAndReturn(pt);
foo_ExpectWithArray(ex, 3);
function_a();
}
- :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: 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();
}
- :pass: TRUE
:should: 'handle creating array expects when we have mixed arguments for single object'
:code: |
test()
{
int expect_list[] = { 1, 9 };
no_pointers_Expect(1, "silly");
mixed_ExpectAndReturn(6, expect_list, 7, 13);
TEST_ASSERT_EQUAL(13, function_d());
}
- :pass: FALSE
:should: 'handle creating array expects when we have mixed arguments and handle failures for single object'
:code: |
test()
{
int expect_list[] = { 9, 1 };
no_pointers_Expect(1, "silly");
mixed_ExpectAndReturn(6, expect_list, 7, 13);
TEST_ASSERT_EQUAL(13, function_d());
}
- :pass: TRUE
:should: 'handle creating array expects when we have mixed arguments for multiple objects'
:code: |
test()
{
int expect_list[] = { 1, 2, 3, 4, 6 };
no_pointers_Expect(1, "silly");
mixed_ExpectWithArrayAndReturn(6, expect_list, 4, 7, 13);
TEST_ASSERT_EQUAL(13, function_d());
}
- :pass: FALSE
:should: 'handle creating array expects when we have mixed arguments and handle failures for multiple objects'
:code: |
test()
{
int expect_list[] = { 1, 2, 3, 4, 6 };
no_pointers_Expect(1, "silly");
mixed_ExpectWithArrayAndReturn(6, expect_list, 5, 7, 13);
TEST_ASSERT_EQUAL(13, function_d());
}
- :pass: TRUE
:should: 'handle an exception being caught'
:code: |
test()
{
bars_ExpectAndReturn("This is a\0 silly string");
foos_ExpectAndThrow("This is a\0 wacky string", 55);
foos_Expect("err");
function_c();
}
- :pass: FALSE
:should: 'handle an exception being caught but still catch following errors'
:code: |
test()
{
bars_ExpectAndReturn("This is a\0 silly string");
foos_ExpectAndThrow("This is a\0 wacky string", 55);
foos_Expect("wrong error");
function_c();
}
- :pass: FALSE
:should: 'fail strict ordering problems even though we would otherwise have passed'
:code: |
test()
{
int expect_list[] = { 1, 2, 3, 4, 6 };
mixed_ExpectWithArrayAndReturn(6, expect_list, 4, 7, 13);
no_pointers_Expect(1, "silly");
TEST_ASSERT_EQUAL(13, function_d());
}
- :pass: TRUE
:should: 'that we can properly ignore one of the function but the other will work properly'
:code: |
test()
{
int expect_list[] = { 1, 2, 3, 4, 6 };
mixed_ExpectWithArrayAndReturn(6, expect_list, 4, 7, 13);
no_pointers_Ignore();
TEST_ASSERT_EQUAL(13, function_d());
}
...
@@ -16,12 +16,15 @@
void fooa(POINT_T a[]);
void foos(const char const * a);
const char const * bars(void);
void no_pointers(int a, char* b);
int mixed(int a, int* b, int c);
:source:
:header: |
void function_a(void);
void function_b(void);
void function_c(void);
int function_d(void);
:code: |
void function_a(void)
@@ -37,6 +40,12 @@
foos(bars());
}
int function_d(void) {
int test_list[] = { 1, 2, 3, 4, 5 };
no_pointers(1, "silly");
return mixed(6, test_list, 7);
}
:tests:
:common: |
void setUp(void) {}
@@ -54,6 +63,42 @@
function_a();
}
- :pass: FALSE
:should: 'handle the situation where we expected nulls to pointers but did not get that'
:code: |
test()
{
POINT_T pt = {1, 2};
bar_ExpectAndReturn(&pt);
foo_Expect(NULL);
function_a();
}
- :pass: FALSE
:should: 'handle the situation where we did not expect nulls to pointers but got null'
:code: |
test()
{
POINT_T ex = {1, 2};
bar_ExpectAndReturn(NULL);
foo_Expect(&ex);
function_a();
}
- :pass: FALSE
:should: 'handle the situation where it fails because you asked it to compare nothing at all'
:code: |
test()
{
POINT_T ex = {1, 2};
bar_ExpectAndReturn(&ex);
foo_ExpectWithArray(&ex, 0);
function_a();
}
- :pass: TRUE
:should: 'handle the situation where we pass single object with expect'
:code: |
@@ -80,6 +125,84 @@
function_a();
}
- :pass: TRUE
:should: 'handle the situation where we pass single object with expect and use array handler'
:code: |
test()
{
POINT_T pt = {1, 2};
POINT_T ex = {1, 2};
bar_ExpectAndReturn(&pt);
foo_ExpectWithArray(&ex, 1);
function_a();
}
- :pass: FALSE
:should: 'handle the situation where we pass single object with expect and use array handler and it is wrong'
:code: |
test()
{
POINT_T pt = {1, 2};
POINT_T ex = {1, 3};
bar_ExpectAndReturn(&pt);
foo_ExpectWithArray(&ex, 1);
function_a();
}
- :pass: TRUE
:should: 'handle the situation where we pass multiple objects with expect and use array handler'
:code: |
test()
{
POINT_T pt[] = {{1, 2}, {3, 4}, {5, 6}};
POINT_T ex[] = {{1, 2}, {3, 4}, {5, 6}};
bar_ExpectAndReturn(pt);
foo_ExpectWithArray(ex, 3);
function_a();
}
- :pass: FALSE
:should: 'handle the situation where we pass multiple objects with expect and use array handler and it is wrong at start'
:code: |
test()
{
POINT_T pt[] = {{1, 2}, {3, 4}, {5, 6}};
POINT_T ex[] = {{9, 2}, {3, 4}, {5, 6}};
bar_ExpectAndReturn(pt);
foo_ExpectWithArray(ex, 3);
function_a();
}
- :pass: FALSE
:should: 'handle the situation where we pass multiple objects with expect and use array handler and it is wrong at end'
:code: |
test()
{
POINT_T pt[] = {{1, 2}, {3, 4}, {5, 6}};
POINT_T ex[] = {{1, 2}, {3, 4}, {5, 9}};
bar_ExpectAndReturn(pt);
foo_ExpectWithArray(ex, 3);
function_a();
}
- :pass: FALSE
:should: 'handle the situation where we pass multiple objects with expect and use array handler and it is wrong in middle'
:code: |
test()
{
POINT_T pt[] = {{1, 2}, {3, 4}, {5, 6}};
POINT_T ex[] = {{1, 2}, {3, 9}, {5, 6}};
bar_ExpectAndReturn(pt);
foo_ExpectWithArray(ex, 3);
function_a();
}
- :pass: FALSE
:should: 'handle the situation where we pass nulls to pointers and fail'
:code: |
@@ -163,5 +286,53 @@
function_c();
}
- :pass: TRUE
:should: 'handle creating array expects when we have mixed arguments for single object'
:code: |
test()
{
int expect_list[] = { 1, 9 };
no_pointers_Expect(1, "silly");
mixed_ExpectAndReturn(6, expect_list, 7, 13);
TEST_ASSERT_EQUAL(13, function_d());
}
- :pass: FALSE
:should: 'handle creating array expects when we have mixed arguments and handle failures for single object'
:code: |
test()
{
int expect_list[] = { 9, 1 };
no_pointers_Expect(1, "silly");
mixed_ExpectAndReturn(6, expect_list, 7, 13);
TEST_ASSERT_EQUAL(13, function_d());
}
- :pass: TRUE
:should: 'handle creating array expects when we have mixed arguments for multiple objects'
:code: |
test()
{
int expect_list[] = { 1, 2, 3, 4, 6 };
no_pointers_Expect(1, "silly");
mixed_ExpectWithArrayAndReturn(6, expect_list, 4, 7, 13);
TEST_ASSERT_EQUAL(13, function_d());
}
- :pass: FALSE
:should: 'handle creating array expects when we have mixed arguments and handle failures for multiple objects'
:code: |
test()
{
int expect_list[] = { 1, 2, 3, 4, 6 };
no_pointers_Expect(1, "silly");
mixed_ExpectWithArrayAndReturn(6, expect_list, 5, 7, 13);
TEST_ASSERT_EQUAL(13, function_d());
}
...
@@ -0,0 +1,153 @@
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
require 'cmock_generator_plugin_array'
class CMockGeneratorPluginArrayTest < Test::Unit::TestCase
def setup
create_mocks :config, :utils
#no strict ordering
@config.expect.when_ptr_star.returns(:compare_data)
@config.expect.enforce_strict_ordering.returns(false)
@config.stubs!(:respond_to?).returns(true)
@utils.expect.helpers.returns({})
@cmock_generator_plugin_array = CMockGeneratorPluginArray.new(@config, @utils)
end
def teardown
end
should "have set up internal accessors correctly on init" do
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)
end
should "not include any additional include files" do
assert(!@cmock_generator_plugin_array.respond_to?(:include_files))
end
should "not add to control structure for functions of style 'int* func(void)'" do
function = {:name => "Oak", :args => [], :return_type => "int*"}
returned = @cmock_generator_plugin_array.instance_structure(function)
assert_equal("", returned)
end
should "add to control structure mock needs of functions of style 'void func(int chicken, int* pork)'" do
function = {:name => "Cedar", :args => [{ :name => "chicken", :type => "int", :ptr? => false}, { :name => "pork", :type => "int*", :ptr? => true}], :return_type => "void"}
expected = ["\n",
" int* Cedar_Expected_pork_Depth;\n",
" int* Cedar_Expected_pork_Depth_Head;\n",
" int* Cedar_Expected_pork_Depth_Tail;\n"
].join
returned = @cmock_generator_plugin_array.instance_structure(function)
assert_equal(expected, returned)
end
should "not add an additional mock interface for functions not containing pointers" do
function = {:name => "Maple", :args_string => "int blah", :return_type => "char*", :contains_ptr? => false}
returned = @cmock_generator_plugin_array.mock_function_declarations(function)
assert_nil(returned)
end
should "add another mock function declaration for functions of style 'void func(int* tofu)'" do
function = {:name => "Pine",
:args => [{ :type => "int*",
:name => "tofu",
:ptr? => true,
}],
:return_type => "void",
:return_string => "void",
:contains_ptr? => true }
expected = "void #{function[:name]}_ExpectWithArray(int* tofu, int tofu_Depth);\n"
returned = @cmock_generator_plugin_array.mock_function_declarations(function)
assert_equal(expected, returned)
end
should "add another mock function declaration for functions of style 'const char* func(int* tofu)'" do
function = {:name => "Pine",
:args => [{ :type => "int*",
:name => "tofu",
:ptr? => true,
}],
:return_type => "const char*",
:return_string => "const char* toReturn",
:contains_ptr? => true }
expected = "void #{function[:name]}_ExpectWithArrayAndReturn(int* tofu, int tofu_Depth, const char* toReturn);\n"
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 "add 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 "add 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)
end
should "add not have a mock interfaces for functions of style 'int* func(void)'" do
function = {:name => "Pear", :args => [], :args_string => "void", :return_type => "int*"}
returned = @cmock_generator_plugin_array.mock_interfaces(function)
assert_nil(returned)
end
should "add mock interfaces for functions of style 'int func(int* pescado, int pes)'" do
function = {:name => "Lemon",
:args => [{ :type => "int*", :name => "pescado", :ptr? => true}, { :type => "int", :name => "pes", :ptr? => false}],
:args_string => "int* pescado, int pes",
:return_type => "int",
:return_string => "int toReturn",
:contains_ptr? => true }
@utils.expect.code_add_an_arg_expectation(function, function[:args][0], "pescado_Depth").returns("mock_retval_2")
@utils.expect.code_add_an_arg_expectation(function, function[:args][1], "1").returns("mock_retval_3")
@utils.expect.code_add_base_expectation("Lemon").returns("mock_retval_0")
@utils.expect.code_insert_item_into_expect_array(function[:return_type], "Mock.Lemon_Return", 'toReturn').returns("mock_retval_1")
expected = ["void ExpectParametersWithArray_Lemon(int* pescado, int pescado_Depth, int pes)\n",
"{\n",
"mock_retval_2",
"mock_retval_3",
"}\n\n",
"void Lemon_ExpectWithArrayAndReturn(int* pescado, int pescado_Depth, int pes, int toReturn)\n",
"{\n",
"mock_retval_0",
" ExpectParametersWithArray_Lemon(pescado, pescado_Depth, pes);\n",
"mock_retval_1",
" Mock.Lemon_Return = Mock.Lemon_Return_Head;\n",
" Mock.Lemon_Return += Mock.Lemon_CallCount;\n",
"}\n\n"
].join
returned = @cmock_generator_plugin_array.mock_interfaces(function).join
assert_equal(expected, returned)
end
should "only add destruction of Depth attributes" do
function = {:name => "Coconut",
:args => [ { :type => "uint32*", :name => "grease", :ptr? => true},
{ :type => "uint16", :name => "grime", :ptr? => false}],
:return_type => "int",
:contains_ptr? => true }
expected = [ %q[
if (Mock.Coconut_Expected_grease_Depth_Head)
{
free(Mock.Coconut_Expected_grease_Depth_Head);
}
Mock.Coconut_Expected_grease_Depth=NULL;
Mock.Coconut_Expected_grease_Depth_Head=NULL;
Mock.Coconut_Expected_grease_Depth_Tail=NULL;
] ]
returned = @cmock_generator_plugin_array.mock_destroy(function)
assert_equal(expected, returned)
end
end
@@ -112,7 +112,6 @@ class CMockGeneratorPluginCexceptionTest < Test::Unit::TestCase
@utils.expect.code_add_base_expectation("Pear").returns("mock_retval_0")
@utils.expect.code_insert_item_into_expect_array("int", "Mock.Pear_ThrowOnCallCount", "Mock.Pear_CallsExpected").returns("mock_return_1")
@utils.expect.code_insert_item_into_expect_array("EXCEPTION_T", "Mock.Pear_ThrowValue", "toThrow").returns("mock_return_2")
@utils.expect.create_call_list(function).returns("mock_return_3")
expected = ["void Pear_ExpectAndThrow(int blah, EXCEPTION_T toThrow)\n",
"{\n",
@@ -127,7 +126,7 @@ class CMockGeneratorPluginCexceptionTest < Test::Unit::TestCase
" Mock.Pear_ThrowValue++;\n",
" Mock.Pear_ThrowOnCallCount++;\n",
" }\n",
" ExpectParameters_Pear(mock_return_3);\n",
" ExpectParameters_Pear(blah);\n",
"}\n\n"
].join
returned = @cmock_generator_plugin_cexception.mock_interfaces(function)
@@ -252,7 +252,6 @@ class CMockGeneratorPluginExpectTest < Test::Unit::TestCase
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, {: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")
expected = ["void ExpectParameters_Lemon(char* pescado)\n",
@@ -262,7 +261,7 @@ class CMockGeneratorPluginExpectTest < Test::Unit::TestCase
"void Lemon_ExpectAndReturn(char* pescado, int toReturn)\n",
"{\n",
"mock_retval_0",
" ExpectParameters_Lemon(mock_retval_3);\n",
" ExpectParameters_Lemon(pescado);\n",
"mock_retval_1",
" Mock.Lemon_Return = Mock.Lemon_Return_Head;\n",
" Mock.Lemon_Return += Mock.Lemon_CallCount;\n",
-21
View File
@@ -28,27 +28,6 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase
assert_equal({:A=>1, :B=>2},@cmock_generator_utils.helpers)
end
should "set up an empty call list if no arguments passed" do
function = {:args => []}
expected = ""
returned = @cmock_generator_utils.create_call_list(function)
assert_equal(expected, returned)
end
should "set up a single call list if one arguments passed" do
function = {:args => [{ :type => "const char*", :name => "spoon"}]}
expected = "spoon"
returned = @cmock_generator_utils.create_call_list(function)
assert_equal(expected, returned)
end
should "set up a call list if multiple arguments passed" do
function = {:args => [{ :type => "const char*", :name => "spoon"}, { :type => "int", :name => "fork"}, { :type => "unsigned int", :name => "knife"}] }
expected = "spoon, fork, knife"
returned = @cmock_generator_utils.create_call_list(function)
assert_equal(expected, returned)
end
should "make expand array" do
the_type = "int"
the_array = "array"