|
| 1 | +# ========================================================================= |
| 2 | +# CMock - Automatic Mock Generation for C |
| 3 | +# ThrowTheSwitch.org |
| 4 | +# Copyright (c) 2007-25 Mike Karlesky, Mark VanderVoord, & Greg Williams |
| 5 | +# SPDX-License-Identifier: MIT |
| 6 | +# ========================================================================= |
| 7 | + |
| 8 | +require File.expand_path(File.dirname(__FILE__)) + "/../test_helper" |
| 9 | +require File.expand_path(File.dirname(__FILE__)) + '/../../lib/cmock_generator_plugin_array' |
| 10 | +require File.expand_path(File.dirname(__FILE__)) + '/../../lib/cmock_generator_utils' |
| 11 | + |
| 12 | +class UtilsStub |
| 13 | + def helpers |
| 14 | + {} |
| 15 | + end |
| 16 | + def arg_type_with_const(arg) |
| 17 | + CMockGeneratorUtils.arg_type_with_const(arg) |
| 18 | + end |
| 19 | + def code_add_base_expectation(func) |
| 20 | + "mock_retval_0" |
| 21 | + end |
| 22 | +end |
| 23 | + |
| 24 | +describe CMockGeneratorPluginArray, "Verify Generation Of Mock Function Declarations Without Error Stubs By CMockPGeneratorluginArray Module" do |
| 25 | + before do |
| 26 | + #no strict ordering |
| 27 | + @config = create_stub( |
| 28 | + :when_ptr => :compare_data, |
| 29 | + :enforce_strict_ordering => false, |
| 30 | + :respond_to? => true, |
| 31 | + :create_error_stubs => false) |
| 32 | + |
| 33 | + @utils = UtilsStub.new |
| 34 | + |
| 35 | + @cmock_generator_plugin_array = CMockGeneratorPluginArray.new(@config, @utils) |
| 36 | + end |
| 37 | + |
| 38 | + after do |
| 39 | + end |
| 40 | + |
| 41 | + it "add another mock function declaration for functions of style 'void func(int* tofu)'" do |
| 42 | + function = {:name => "Pine", |
| 43 | + :args => [{ :type => "int*", |
| 44 | + :name => "tofu", |
| 45 | + :ptr? => true, |
| 46 | + }], |
| 47 | + :return => test_return[:void], |
| 48 | + :contains_ptr? => true } |
| 49 | + |
| 50 | + expected = "#define #{function[:name]}_ExpectWithArray(tofu, tofu_Depth) #{function[:name]}_CMockExpectWithArray(__LINE__, tofu, (tofu_Depth))\n" + |
| 51 | + "void #{function[:name]}_CMockExpectWithArray(UNITY_LINE_TYPE cmock_line, int* tofu, int tofu_Depth);\n" |
| 52 | + returned = @cmock_generator_plugin_array.mock_function_declarations(function) |
| 53 | + assert_equal(expected, returned) |
| 54 | + end |
| 55 | + |
| 56 | + it "add another mock function declaration for functions of style 'const char* func(int* tofu)'" do |
| 57 | + function = {:name => "Pine", |
| 58 | + :args => [{ :type => "int*", |
| 59 | + :name => "tofu", |
| 60 | + :ptr? => true, |
| 61 | + }], |
| 62 | + :return => test_return[:string], |
| 63 | + :contains_ptr? => true } |
| 64 | + |
| 65 | + expected = "#define #{function[:name]}_ExpectWithArrayAndReturn(tofu, tofu_Depth, cmock_retval) #{function[:name]}_CMockExpectWithArrayAndReturn(__LINE__, tofu, (tofu_Depth), cmock_retval)\n" + |
| 66 | + "void #{function[:name]}_CMockExpectWithArrayAndReturn(UNITY_LINE_TYPE cmock_line, int* tofu, int tofu_Depth, const char* cmock_to_return);\n" |
| 67 | + returned = @cmock_generator_plugin_array.mock_function_declarations(function) |
| 68 | + assert_equal(expected, returned) |
| 69 | + end |
| 70 | + |
| 71 | + it "add another mock function declaration for functions of style 'const char* func(const int* tofu)'" do |
| 72 | + function = {:name => "Pine", |
| 73 | + :args => [{ :type => "const int*", |
| 74 | + :name => "tofu", |
| 75 | + :ptr? => true, |
| 76 | + :const? => true, |
| 77 | + }], |
| 78 | + :return => test_return[:string], |
| 79 | + :contains_ptr? => true } |
| 80 | + |
| 81 | + expected = "#define #{function[:name]}_ExpectWithArrayAndReturn(tofu, tofu_Depth, cmock_retval) #{function[:name]}_CMockExpectWithArrayAndReturn(__LINE__, tofu, (tofu_Depth), cmock_retval)\n" + |
| 82 | + "void #{function[:name]}_CMockExpectWithArrayAndReturn(UNITY_LINE_TYPE cmock_line, const int* tofu, int tofu_Depth, const char* cmock_to_return);\n" |
| 83 | + returned = @cmock_generator_plugin_array.mock_function_declarations(function) |
| 84 | + assert_equal(expected, returned) |
| 85 | + end |
| 86 | + |
| 87 | +end |
0 commit comments