| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper" |
| 8 |
require File.expand_path(File.dirname(__FILE__)) + '/../../lib/cmock_generator_plugin_array' |
| 9 |
require File.expand_path(File.dirname(__FILE__)) + '/../../lib/cmock_generator_utils' |
| 10 |
|
| 11 |
class UtilsStub |
| 12 |
def helpers |
| 13 |
{} |
| 14 |
end |
| 15 |
def arg_type_with_const(arg) |
| 16 |
CMockGeneratorUtils.arg_type_with_const(arg) |
| 17 |
end |
| 18 |
def code_add_base_expectation(func) |
| 19 |
"mock_retval_0" |
| 20 |
end |
| 21 |
end |
| 22 |
|
| 23 |
describe CMockGeneratorPluginArray, "Verify CMockPGeneratorluginArray Module" do |
| 24 |
before do |
| 25 |
|
| 26 |
@config = create_stub( |
| 27 |
:when_ptr => :compare_data, |
| 28 |
:enforce_strict_ordering => false, |
| 29 |
:respond_to? => true ) |
| 30 |
|
| 31 |
@utils = UtilsStub.new |
| 32 |
|
| 33 |
@cmock_generator_plugin_array = CMockGeneratorPluginArray.new(@config, @utils) |
| 34 |
end |
| 35 |
|
| 36 |
after do |
| 37 |
end |
| 38 |
|
| 39 |
it "have set up internal priority" do |
| 40 |
assert_nil(@cmock_generator_plugin_array.unity_helper) |
| 41 |
assert_equal(8, @cmock_generator_plugin_array.priority) |
| 42 |
end |
| 43 |
|
| 44 |
it "not include any additional include files" do |
| 45 |
assert(!@cmock_generator_plugin_array.respond_to?(:include_files)) |
| 46 |
end |
| 47 |
|
| 48 |
it "not add to typedef structure for functions of style 'int* func(void)'" do |
| 49 |
function = {:name => "Oak", :args => [], :return => test_return[:int_ptr]} |
| 50 |
returned = @cmock_generator_plugin_array.instance_typedefs(function) |
| 51 |
assert_equal("", returned) |
| 52 |
end |
| 53 |
|
| 54 |
it "add to tyepdef structure mock needs of functions of style 'void func(int chicken, int* pork)'" do |
| 55 |
function = {:name => "Cedar", :args => [{ :name => "chicken", :type => "int", :ptr? => false}, { :name => "pork", :type => "int*", :ptr? => true}], :return => test_return[:void]} |
| 56 |
expected = " int Expected_pork_Depth;\n" |
| 57 |
returned = @cmock_generator_plugin_array.instance_typedefs(function) |
| 58 |
assert_equal(expected, returned) |
| 59 |
end |
| 60 |
|
| 61 |
it "not add an additional mock interface for functions not containing pointers" do |
| 62 |
function = {:name => "Maple", :args_string => "int blah", :return => test_return[:string], :contains_ptr? => false} |
| 63 |
returned = @cmock_generator_plugin_array.mock_function_declarations(function) |
| 64 |
assert_nil(returned) |
| 65 |
end |
| 66 |
|
| 67 |
it "add another mock function declaration for functions of style 'void func(int* tofu)'" do |
| 68 |
function = {:name => "Pine", |
| 69 |
:args => [{ :type => "int*", |
| 70 |
:name => "tofu", |
| 71 |
:ptr? => true, |
| 72 |
}], |
| 73 |
:return => test_return[:void], |
| 74 |
:contains_ptr? => true } |
| 75 |
|
| 76 |
expected = "#define #{function[:name]}_ExpectWithArray(tofu, tofu_Depth) #{function[:name]}_CMockExpectWithArray(__LINE__, tofu, tofu_Depth)\n" + |
| 77 |
"void #{function[:name]}_CMockExpectWithArray(UNITY_LINE_TYPE cmock_line, int* tofu, int tofu_Depth);\n" |
| 78 |
returned = @cmock_generator_plugin_array.mock_function_declarations(function) |
| 79 |
assert_equal(expected, returned) |
| 80 |
end |
| 81 |
|
| 82 |
it "add another mock function declaration for functions of style 'const char* func(int* tofu)'" do |
| 83 |
function = {:name => "Pine", |
| 84 |
:args => [{ :type => "int*", |
| 85 |
:name => "tofu", |
| 86 |
:ptr? => true, |
| 87 |
}], |
| 88 |
:return => test_return[:string], |
| 89 |
:contains_ptr? => true } |
| 90 |
|
| 91 |
expected = "#define #{function[:name]}_ExpectWithArrayAndReturn(tofu, tofu_Depth, cmock_retval) #{function[:name]}_CMockExpectWithArrayAndReturn(__LINE__, tofu, tofu_Depth, cmock_retval)\n" + |
| 92 |
"void #{function[:name]}_CMockExpectWithArrayAndReturn(UNITY_LINE_TYPE cmock_line, int* tofu, int tofu_Depth, const char* cmock_to_return);\n" |
| 93 |
returned = @cmock_generator_plugin_array.mock_function_declarations(function) |
| 94 |
assert_equal(expected, returned) |
| 95 |
end |
| 96 |
|
| 97 |
it "add another mock function declaration for functions of style 'const char* func(const int* tofu)'" do |
| 98 |
function = {:name => "Pine", |
| 99 |
:args => [{ :type => "const int*", |
| 100 |
:name => "tofu", |
| 101 |
:ptr? => true, |
| 102 |
:const? => true, |
| 103 |
}], |
| 104 |
:return => test_return[:string], |
| 105 |
:contains_ptr? => true } |
| 106 |
|
| 107 |
expected = "#define #{function[:name]}_ExpectWithArrayAndReturn(tofu, tofu_Depth, cmock_retval) #{function[:name]}_CMockExpectWithArrayAndReturn(__LINE__, tofu, tofu_Depth, cmock_retval)\n" + |
| 108 |
"void #{function[:name]}_CMockExpectWithArrayAndReturn(UNITY_LINE_TYPE cmock_line, const int* tofu, int tofu_Depth, const char* cmock_to_return);\n" |
| 109 |
returned = @cmock_generator_plugin_array.mock_function_declarations(function) |
| 110 |
assert_equal(expected, returned) |
| 111 |
end |
| 112 |
|
| 113 |
it "not have a mock function implementation" do |
| 114 |
assert(!@cmock_generator_plugin_array.respond_to?(:mock_implementation)) |
| 115 |
end |
| 116 |
|
| 117 |
it "not have a mock interfaces for functions of style 'int* func(void)'" do |
| 118 |
function = {:name => "Pear", :args => [], :args_string => "void", :return => test_return[:int_ptr]} |
| 119 |
returned = @cmock_generator_plugin_array.mock_interfaces(function) |
| 120 |
assert_nil(returned) |
| 121 |
end |
| 122 |
|
| 123 |
it "add mock interfaces for functions of style 'int* func(int* pescado, int pes)'" do |
| 124 |
function = {:name => "Lemon", |
| 125 |
:args => [{ :type => "int*", :name => "pescado", :ptr? => true}, { :type => "int", :name => "pes", :ptr? => false}], |
| 126 |
:args_string => "int* pescado, int pes", |
| 127 |
:return => test_return[:int_ptr], |
| 128 |
:contains_ptr? => true } |
| 129 |
|
| 130 |
expected = ["void Lemon_CMockExpectWithArrayAndReturn(UNITY_LINE_TYPE cmock_line, int* pescado, int pescado_Depth, int pes, int* cmock_to_return)\n", |
| 131 |
"{\n", |
| 132 |
"mock_retval_0", |
| 133 |
" CMockExpectParameters_Lemon(cmock_call_instance, pescado, pescado_Depth, pes);\n", |
| 134 |
" cmock_call_instance->ReturnVal = cmock_to_return;\n", |
| 135 |
"}\n\n" |
| 136 |
].join |
| 137 |
returned = @cmock_generator_plugin_array.mock_interfaces(function).join |
| 138 |
assert_equal(expected, returned) |
| 139 |
end |
| 140 |
|
| 141 |
end |