| 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_expect_any_args.rb' |
| 9 |
|
| 10 |
describe CMockGeneratorPluginExpectAnyArgs, "Verify CMockGeneratorPluginExpectAnyArgs Module" do |
| 11 |
|
| 12 |
before do |
| 13 |
create_mocks :config, :utils |
| 14 |
@config = create_stub(:respond_to? => true) |
| 15 |
@cmock_generator_plugin_expect_any_args = CMockGeneratorPluginExpectAnyArgs.new(@config, @utils) |
| 16 |
end |
| 17 |
|
| 18 |
after do |
| 19 |
end |
| 20 |
|
| 21 |
it "have set up internal priority" do |
| 22 |
assert_equal(3, @cmock_generator_plugin_expect_any_args.priority) |
| 23 |
end |
| 24 |
|
| 25 |
it "not have any additional include file requirements" do |
| 26 |
assert(!@cmock_generator_plugin_expect_any_args.respond_to?(:include_files)) |
| 27 |
end |
| 28 |
|
| 29 |
it "ignore functions without arguments" do |
| 30 |
function = {:name => "Mold", :args_string => "void", :args => [], :return => test_return[:void]} |
| 31 |
expected = "" |
| 32 |
returned = @cmock_generator_plugin_expect_any_args.mock_function_declarations(function) |
| 33 |
assert_equal(expected, returned) |
| 34 |
end |
| 35 |
|
| 36 |
it "handle function declarations for functions without return values" do |
| 37 |
function = {:name => "Mold", :args_string => "int meh", :args => [ :stuff ], :return => test_return[:void]} |
| 38 |
expected = "#define Mold_ExpectAnyArgs() Mold_CMockExpectAnyArgs(__LINE__)\nvoid Mold_CMockExpectAnyArgs(UNITY_LINE_TYPE cmock_line);\n" |
| 39 |
returned = @cmock_generator_plugin_expect_any_args.mock_function_declarations(function) |
| 40 |
assert_equal(expected, returned) |
| 41 |
end |
| 42 |
|
| 43 |
it "handle function declarations for functions that returns something" do |
| 44 |
function = {:name => "Fungus", :args_string => "int meh", :args => [ :stuff ], :return => test_return[:string]} |
| 45 |
expected = "#define Fungus_ExpectAnyArgsAndReturn(cmock_retval) Fungus_CMockExpectAnyArgsAndReturn(__LINE__, cmock_retval)\n"+ |
| 46 |
"void Fungus_CMockExpectAnyArgsAndReturn(UNITY_LINE_TYPE cmock_line, const char* cmock_to_return);\n" |
| 47 |
returned = @cmock_generator_plugin_expect_any_args.mock_function_declarations(function) |
| 48 |
assert_equal(expected, returned) |
| 49 |
end |
| 50 |
|
| 51 |
it "should not respond to implementation requests" do |
| 52 |
assert(!@cmock_generator_plugin_expect_any_args.respond_to?(:mock_implementation)) |
| 53 |
end |
| 54 |
|
| 55 |
it "add a new mock interface for ignoring when function had no return value" do |
| 56 |
function = {:name => "Slime", :args_string => "int meh", :args => [ :stuff ], :return => test_return[:void]} |
| 57 |
expected = ["void Slime_CMockExpectAnyArgs(UNITY_LINE_TYPE cmock_line)\n", |
| 58 |
"{\n", |
| 59 |
"mock_return_1", |
| 60 |
" cmock_call_instance->ExpectAnyArgsBool = (char)1;\n", |
| 61 |
"}\n\n" |
| 62 |
].join |
| 63 |
@utils.expect :code_add_base_expectation, "mock_return_1", ["Slime", true] |
| 64 |
returned = @cmock_generator_plugin_expect_any_args.mock_interfaces(function) |
| 65 |
assert_equal(expected, returned) |
| 66 |
end |
| 67 |
end |