From fa6853e9d9753189a597e253ba3988f5e42791b8 Mon Sep 17 00:00:00 2001 From: mvandervoord Date: Sun, 22 Feb 2009 03:24:28 +0000 Subject: [PATCH] - Cleaned up some naming in generated code - Parsing can now handle arguments without names (they are named something standard) - Configurable Mock prefix name git-svn-id: http://cmock.svn.sourceforge.net/svnroot/cmock/trunk@64 bf332499-1b4d-0410-844d-d2d48d5cc64c --- lib/cmock_config.rb | 5 ++- lib/cmock_generator.rb | 2 +- lib/cmock_generator_plugin_cexception.rb | 12 +++--- lib/cmock_generator_plugin_expect.rb | 9 +++-- lib/cmock_generator_utils.rb | 11 +++--- lib/cmock_header_parser.rb | 11 +++++- test/unit/cmock_generator_main_test.rb | 1 + .../cmock_generator_plugin_cexception_test.rb | 12 +++--- .../cmock_generator_plugin_expect_test.rb | 17 +++++---- test/unit/cmock_generator_utils_test.rb | 34 ++++++++--------- test/unit/cmock_header_parser_test.rb | 37 ++++++++++++++++++- test/unit/cmock_plugin_manager_test.rb | 1 + 12 files changed, 101 insertions(+), 51 deletions(-) diff --git a/lib/cmock_config.rb b/lib/cmock_config.rb index 8c2b13f..9e108fe 100644 --- a/lib/cmock_config.rb +++ b/lib/cmock_config.rb @@ -4,6 +4,7 @@ class CMockConfig CMockDefaultOptions = { :mock_path => 'mocks', + :mock_prefix => 'Mock', :includes => [], :plugins => ['cexception', 'ignore'], :tab => ' ', @@ -15,8 +16,8 @@ class CMockConfig :unity_helper => false, :treat_as => {}, :memcpy_if_unknown => true, - :when_ptr_star =>:compare_data, - :when_ptr_brackets => :compare_array, + :when_ptr_star =>:compare_data, #the options being :compare_ptr, :compare_data, :compare_array + :when_ptr_brackets => :compare_array, #not really supported yet } def initialize(options=nil) diff --git a/lib/cmock_generator.rb b/lib/cmock_generator.rb index dc8a74d..6b6f37d 100644 --- a/lib/cmock_generator.rb +++ b/lib/cmock_generator.rb @@ -9,7 +9,7 @@ class CMockGenerator @file_writer = file_writer @tab = @config.tab @module_name = module_name - @mock_name = "Mock" + @module_name + @mock_name = @config.mock_prefix + @module_name @utils = utils @plugins = plugins end diff --git a/lib/cmock_generator_plugin_cexception.rb b/lib/cmock_generator_plugin_cexception.rb index d45e5e3..7b27356 100644 --- a/lib/cmock_generator_plugin_cexception.rb +++ b/lib/cmock_generator_plugin_cexception.rb @@ -25,10 +25,10 @@ class CMockGeneratorPluginCException throw_type = @config.cexception_throw_type lines << "#{@tab}#{call_count_type} *#{function[:name]}_ThrowOnCallCount;\n" lines << "#{@tab}#{call_count_type} *#{function[:name]}_ThrowOnCallCount_Head;\n" - lines << "#{@tab}#{call_count_type} *#{function[:name]}_ThrowOnCallCount_HeadTail;\n" + lines << "#{@tab}#{call_count_type} *#{function[:name]}_ThrowOnCallCount_Tail;\n" lines << "#{@tab}#{throw_type} *#{function[:name]}_ThrowValue;\n" lines << "#{@tab}#{throw_type} *#{function[:name]}_ThrowValue_Head;\n" - lines << "#{@tab}#{throw_type} *#{function[:name]}_ThrowValue_HeadTail;\n" + lines << "#{@tab}#{throw_type} *#{function[:name]}_ThrowValue_Tail;\n" end def mock_function_declarations(function) @@ -41,8 +41,8 @@ class CMockGeneratorPluginCException def mock_implementation(function) lines = ["\n"] - lines << "#{@tab}if((Mock.#{function[:name]}_ThrowOnCallCount != Mock.#{function[:name]}_ThrowOnCallCount_HeadTail) &&\n" - lines << "#{@tab}#{@tab}(Mock.#{function[:name]}_ThrowValue != Mock.#{function[:name]}_ThrowValue_HeadTail))\n" + lines << "#{@tab}if((Mock.#{function[:name]}_ThrowOnCallCount != Mock.#{function[:name]}_ThrowOnCallCount_Tail) &&\n" + lines << "#{@tab}#{@tab}(Mock.#{function[:name]}_ThrowValue != Mock.#{function[:name]}_ThrowValue_Tail))\n" lines << "#{@tab}{\n" lines << "#{@tab}#{@tab}if (*Mock.#{function[:name]}_ThrowOnCallCount && \n" lines << "#{@tab}#{@tab}#{@tab}(Mock.#{function[:name]}_CallCount == *Mock.#{function[:name]}_ThrowOnCallCount))\n" @@ -79,14 +79,14 @@ class CMockGeneratorPluginCException lines << "#{@tab}{\n" lines << "#{@tab}#{@tab}free(Mock.#{function[:name]}_ThrowOnCallCount_Head);\n" lines << "#{@tab}#{@tab}Mock.#{function[:name]}_ThrowOnCallCount_Head=NULL;\n" - lines << "#{@tab}#{@tab}Mock.#{function[:name]}_ThrowOnCallCount_HeadTail=NULL;\n" + lines << "#{@tab}#{@tab}Mock.#{function[:name]}_ThrowOnCallCount_Tail=NULL;\n" lines << "#{@tab}}\n" lines << "#{@tab}if(Mock.#{function[:name]}_ThrowValue_Head)\n" lines << "#{@tab}{\n" lines << "#{@tab}#{@tab}free(Mock.#{function[:name]}_ThrowValue_Head);\n" lines << "#{@tab}#{@tab}Mock.#{function[:name]}_ThrowValue_Head=NULL;\n" - lines << "#{@tab}#{@tab}Mock.#{function[:name]}_ThrowValue_HeadTail=NULL;\n" + lines << "#{@tab}#{@tab}Mock.#{function[:name]}_ThrowValue_Tail=NULL;\n" lines << "#{@tab}}\n" end end diff --git a/lib/cmock_generator_plugin_expect.rb b/lib/cmock_generator_plugin_expect.rb index d16ab87..053bfed 100644 --- a/lib/cmock_generator_plugin_expect.rb +++ b/lib/cmock_generator_plugin_expect.rb @@ -6,6 +6,7 @@ class CMockGeneratorPluginExpect def initialize(config, utils) @config = config @tab = @config.tab + @ptr_handling = @config.when_ptr_star @utils = utils @unity_helper = @utils.helpers[:unity_helper] end @@ -19,14 +20,14 @@ class CMockGeneratorPluginExpect if (function[:rettype] != "void") lines << "#{@tab}#{function[:rettype]} *#{function[:name]}_Return;\n" lines << "#{@tab}#{function[:rettype]} *#{function[:name]}_Return_Head;\n" - lines << "#{@tab}#{function[:rettype]} *#{function[:name]}_Return_HeadTail;\n" + lines << "#{@tab}#{function[:rettype]} *#{function[:name]}_Return_Tail;\n" end function[:args].each do |arg| type = arg[:type].sub(/const/, '').strip lines << "#{@tab}#{type} *#{function[:name]}_Expected_#{arg[:name]};\n" lines << "#{@tab}#{type} *#{function[:name]}_Expected_#{arg[:name]}_Head;\n" - lines << "#{@tab}#{type} *#{function[:name]}_Expected_#{arg[:name]}_HeadTail;\n" + lines << "#{@tab}#{type} *#{function[:name]}_Expected_#{arg[:name]}_Tail;\n" end lines end @@ -111,7 +112,7 @@ class CMockGeneratorPluginExpect lines << "#{@tab}{\n" lines << "#{@tab}#{@tab}free(Mock.#{function[:name]}_Return_Head);\n" lines << "#{@tab}#{@tab}Mock.#{function[:name]}_Return_Head=NULL;\n" - lines << "#{@tab}#{@tab}Mock.#{function[:name]}_Return_HeadTail=NULL;\n" + lines << "#{@tab}#{@tab}Mock.#{function[:name]}_Return_Tail=NULL;\n" lines << "#{@tab}}\n" end function[:args].each do |arg| @@ -119,7 +120,7 @@ class CMockGeneratorPluginExpect lines << "#{@tab}{\n" lines << "#{@tab}#{@tab}free(Mock.#{function[:name]}_Expected_#{arg[:name]}_Head);\n" lines << "#{@tab}#{@tab}Mock.#{function[:name]}_Expected_#{arg[:name]}_Head=NULL;\n" - lines << "#{@tab}#{@tab}Mock.#{function[:name]}_Expected_#{arg[:name]}_HeadTail=NULL;\n" + lines << "#{@tab}#{@tab}Mock.#{function[:name]}_Expected_#{arg[:name]}_Tail=NULL;\n" lines << "#{@tab}}\n" end lines diff --git a/lib/cmock_generator_utils.rb b/lib/cmock_generator_utils.rb index 3e91f1f..aff3ed7 100644 --- a/lib/cmock_generator_utils.rb +++ b/lib/cmock_generator_utils.rb @@ -23,11 +23,12 @@ class CMockGeneratorUtils end def code_insert_item_into_expect_array(type, array, newValue) + tail = array.gsub(/Head$/,'Tail') lines = ["\n"] lines << "#{@tab}{\n" lines << "#{@tab}#{@tab}int sz = 0;\n" lines << "#{@tab}#{@tab}#{type} *pointer = #{array};\n" - lines << "#{@tab}#{@tab}while (pointer && pointer != #{array}Tail) { sz++; pointer++; }\n" + lines << "#{@tab}#{@tab}while (pointer && pointer != #{tail}) { sz++; pointer++; }\n" lines << "#{@tab}#{@tab}if (sz == 0)\n" lines << "#{@tab}#{@tab}{\n" lines << "#{@tab}#{@tab}#{@tab}#{array} = (#{type}*)malloc(2*sizeof(#{type}));\n" @@ -43,13 +44,13 @@ class CMockGeneratorUtils lines << "#{@tab}#{@tab}#{@tab}#{@tab}#{array} = ptmp;\n" lines << "#{@tab}#{@tab}}\n" lines << "#{@tab}#{@tab}memcpy(&#{array}[sz], &#{newValue}, sizeof(#{type}));\n" - lines << "#{@tab}#{@tab}#{array}Tail = &#{array}[sz+1];\n" + lines << "#{@tab}#{@tab}#{tail} = &#{array}[sz+1];\n" lines << "#{@tab}}\n" end def code_handle_return_value(function, indent) lines = ["\n"] - lines << "#{indent}if (Mock.#{function[:name]}_Return != Mock.#{function[:name]}_Return_HeadTail)\n" + lines << "#{indent}if (Mock.#{function[:name]}_Return != Mock.#{function[:name]}_Return_Tail)\n" lines << "#{indent}{\n" lines << "#{indent}#{@tab}#{function[:rettype]} toReturn = *Mock.#{function[:name]}_Return;\n" lines << "#{indent}#{@tab}Mock.#{function[:name]}_Return++;\n" @@ -69,7 +70,7 @@ class CMockGeneratorUtils def code_verify_an_arg_expectation(function, arg_type, actual) lines = ["\n"] - lines << "#{@tab}if (Mock.#{function[:name]}_Expected_#{actual} != Mock.#{function[:name]}_Expected_#{actual}_HeadTail)\n" + lines << "#{@tab}if (Mock.#{function[:name]}_Expected_#{actual} != Mock.#{function[:name]}_Expected_#{actual}_Tail)\n" lines << "#{@tab}{\n" lines << "#{@tab}#{@tab}#{arg_type}* p_expected = Mock.#{function[:name]}_Expected_#{actual};\n" lines << "#{@tab}#{@tab}Mock.#{function[:name]}_Expected_#{actual}++;\n" @@ -79,7 +80,7 @@ class CMockGeneratorUtils end def expect_helper(c_type, expected, actual, msg, indent) - if ((c_type.strip[0] == 42) and (@ptr_handling == :compare_ptr)) + if ((c_type.strip[-1] == 42) and (@ptr_handling == :compare_ptr)) unity_func = "TEST_ASSERT_EQUAL_INT_MESSAGE" else unity_func = (@helpers.nil? or @helpers[:unity_helper].nil?) ? "TEST_ASSERT_EQUAL_MESSAGE" : @helpers[:unity_helper].get_helper(c_type) diff --git a/lib/cmock_header_parser.rb b/lib/cmock_header_parser.rb index f8b5904..54b077a 100644 --- a/lib/cmock_header_parser.rb +++ b/lib/cmock_header_parser.rb @@ -112,6 +112,15 @@ class CMockHeaderParser return args end + def clean_args(arg_list) + if ((arg_list.strip == 'void') or (arg_list.empty?)) + return 'void' + else + c=0 + arg_list.split(',').map{|arg| (arg.strip =~ /^(\w+|.+\*)\s*$/) ? "#{arg.strip} cmock_arg#{c+=1}" : arg.strip}.join(', ') + end + end + def parse_declaration(declaration) decl = {} @@ -146,7 +155,7 @@ class CMockHeaderParser decl[:var_arg] = nil end - args.strip! + args = clean_args(args) decl[:args_string] = args decl[:args] = parse_args(args) diff --git a/test/unit/cmock_generator_main_test.rb b/test/unit/cmock_generator_main_test.rb index 81c2a09..0b47936 100644 --- a/test/unit/cmock_generator_main_test.rb +++ b/test/unit/cmock_generator_main_test.rb @@ -40,6 +40,7 @@ class CMockGeneratorTest < Test::Unit::TestCase @module_name = "PoutPoutFish" @config.expect.tab.returns(" ") + @config.expect.mock_prefix.returns("Mock") @cmock_generator = CMockGenerator.new(@config, @module_name, @file_writer, @utils, @plugins) end diff --git a/test/unit/cmock_generator_plugin_cexception_test.rb b/test/unit/cmock_generator_plugin_cexception_test.rb index 1140923..42ee0a1 100644 --- a/test/unit/cmock_generator_plugin_cexception_test.rb +++ b/test/unit/cmock_generator_plugin_cexception_test.rb @@ -39,10 +39,10 @@ class CMockGeneratorPluginCExceptionTest < Test::Unit::TestCase expected = [" uint32 *Oak_ThrowOnCallCount;\n", " uint32 *Oak_ThrowOnCallCount_Head;\n", - " uint32 *Oak_ThrowOnCallCount_HeadTail;\n", + " uint32 *Oak_ThrowOnCallCount_Tail;\n", " EXCEPTION_TYPE *Oak_ThrowValue;\n", " EXCEPTION_TYPE *Oak_ThrowValue_Head;\n", - " EXCEPTION_TYPE *Oak_ThrowValue_HeadTail;\n" + " EXCEPTION_TYPE *Oak_ThrowValue_Tail;\n" ] returned = @cmock_generator_plugin_cexception.instance_structure(function) assert_equal(expected, returned) @@ -75,8 +75,8 @@ class CMockGeneratorPluginCExceptionTest < Test::Unit::TestCase @config.expect.cexception_throw_type.returns("EXCEPTION_TYPE") expected = ["\n", - " if((Mock.Cherry_ThrowOnCallCount != Mock.Cherry_ThrowOnCallCount_HeadTail) &&\n", - " (Mock.Cherry_ThrowValue != Mock.Cherry_ThrowValue_HeadTail))\n", + " if((Mock.Cherry_ThrowOnCallCount != Mock.Cherry_ThrowOnCallCount_Tail) &&\n", + " (Mock.Cherry_ThrowValue != Mock.Cherry_ThrowValue_Tail))\n", " {\n", " if (*Mock.Cherry_ThrowOnCallCount && \n", " (Mock.Cherry_CallCount == *Mock.Cherry_ThrowOnCallCount))\n", @@ -148,13 +148,13 @@ class CMockGeneratorPluginCExceptionTest < Test::Unit::TestCase " {\n", " free(Mock.Banana_ThrowOnCallCount_Head);\n", " Mock.Banana_ThrowOnCallCount_Head=NULL;\n", - " Mock.Banana_ThrowOnCallCount_HeadTail=NULL;\n", + " Mock.Banana_ThrowOnCallCount_Tail=NULL;\n", " }\n", " if(Mock.Banana_ThrowValue_Head)\n", " {\n", " free(Mock.Banana_ThrowValue_Head);\n", " Mock.Banana_ThrowValue_Head=NULL;\n", - " Mock.Banana_ThrowValue_HeadTail=NULL;\n", + " Mock.Banana_ThrowValue_Tail=NULL;\n", " }\n" ] returned = @cmock_generator_plugin_cexception.mock_destroy(function) diff --git a/test/unit/cmock_generator_plugin_expect_test.rb b/test/unit/cmock_generator_plugin_expect_test.rb index 7cc8a1a..067b6d6 100644 --- a/test/unit/cmock_generator_plugin_expect_test.rb +++ b/test/unit/cmock_generator_plugin_expect_test.rb @@ -5,6 +5,7 @@ class CMockGeneratorPluginExpectTest < Test::Unit::TestCase def setup create_mocks :config, :utils @config.expect.tab.returns(" ") + @config.expect.when_ptr_star.returns(:compare_data) @config.stubs!(:respond_to?).returns(true) @utils.expect.helpers.returns({}) @cmock_generator_plugin_expect = CMockGeneratorPluginExpect.new(@config, @utils) @@ -45,7 +46,7 @@ class CMockGeneratorPluginExpectTest < Test::Unit::TestCase " #{count_type} #{function[:name]}_CallsExpected;\n", " #{function[:rettype]} *#{function[:name]}_Return;\n", " #{function[:rettype]} *#{function[:name]}_Return_Head;\n", - " #{function[:rettype]} *#{function[:name]}_Return_HeadTail;\n" + " #{function[:rettype]} *#{function[:name]}_Return_Tail;\n" ] returned = @cmock_generator_plugin_expect.instance_structure(function) assert_equal(expected, returned) @@ -60,10 +61,10 @@ class CMockGeneratorPluginExpectTest < Test::Unit::TestCase " #{count_type} #{function[:name]}_CallsExpected;\n", " int *#{function[:name]}_Expected_chicken;\n", " int *#{function[:name]}_Expected_chicken_Head;\n", - " int *#{function[:name]}_Expected_chicken_HeadTail;\n", + " int *#{function[:name]}_Expected_chicken_Tail;\n", " char* *#{function[:name]}_Expected_pork;\n", " char* *#{function[:name]}_Expected_pork_Head;\n", - " char* *#{function[:name]}_Expected_pork_HeadTail;\n" + " char* *#{function[:name]}_Expected_pork_Tail;\n" ] returned = @cmock_generator_plugin_expect.instance_structure(function) assert_equal(expected, returned) @@ -78,10 +79,10 @@ class CMockGeneratorPluginExpectTest < Test::Unit::TestCase " #{count_type} #{function[:name]}_CallsExpected;\n", " #{function[:rettype]} *#{function[:name]}_Return;\n", " #{function[:rettype]} *#{function[:name]}_Return_Head;\n", - " #{function[:rettype]} *#{function[:name]}_Return_HeadTail;\n", + " #{function[:rettype]} *#{function[:name]}_Return_Tail;\n", " float *#{function[:name]}_Expected_beef;\n", " float *#{function[:name]}_Expected_beef_Head;\n", - " float *#{function[:name]}_Expected_beef_HeadTail;\n", + " float *#{function[:name]}_Expected_beef_Tail;\n", ] returned = @cmock_generator_plugin_expect.instance_structure(function) assert_equal(expected, returned) @@ -215,7 +216,7 @@ class CMockGeneratorPluginExpectTest < Test::Unit::TestCase " {\n", " free(Mock.Palm_Return_Head);\n", " Mock.Palm_Return_Head=NULL;\n", - " Mock.Palm_Return_HeadTail=NULL;\n", + " Mock.Palm_Return_Tail=NULL;\n", " }\n" ] returned = @cmock_generator_plugin_expect.mock_destroy(function) @@ -228,13 +229,13 @@ class CMockGeneratorPluginExpectTest < Test::Unit::TestCase " {\n", " free(Mock.Coconut_Return_Head);\n", " Mock.Coconut_Return_Head=NULL;\n", - " Mock.Coconut_Return_HeadTail=NULL;\n", + " Mock.Coconut_Return_Tail=NULL;\n", " }\n", " if (Mock.Coconut_Expected_grease_Head)\n", " {\n", " free(Mock.Coconut_Expected_grease_Head);\n", " Mock.Coconut_Expected_grease_Head=NULL;\n", - " Mock.Coconut_Expected_grease_HeadTail=NULL;\n", + " Mock.Coconut_Expected_grease_Tail=NULL;\n", " }\n" ] returned = @cmock_generator_plugin_expect.mock_destroy(function) diff --git a/test/unit/cmock_generator_utils_test.rb b/test/unit/cmock_generator_utils_test.rb index 4b3a138..dc69572 100644 --- a/test/unit/cmock_generator_utils_test.rb +++ b/test/unit/cmock_generator_utils_test.rb @@ -5,7 +5,7 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase def setup create_mocks :config, :unity_helper @config.expect.tab.returns(" ") - @config.expect.when_ptr_star.returns(:compare_ptr) + @config.expect.when_ptr_star.returns(:compare_data) @cmock_generator_utils = CMockGeneratorUtils.new(@config) end @@ -51,29 +51,29 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase should "make expand array" do the_type = "int" - the_array = "array" + the_array = "arrayHead" new_value = "new_value" expected = ["\n", " {\n", " int sz = 0;\n", - " int *pointer = array;\n", + " int *pointer = arrayHead;\n", " while (pointer && pointer != arrayTail) { sz++; pointer++; }\n", " if (sz == 0)\n", " {\n", - " array = (int*)malloc(2*sizeof(int));\n", - " if (!array)\n", + " arrayHead = (int*)malloc(2*sizeof(int));\n", + " if (!arrayHead)\n", " Mock.allocFailure++;\n", " }\n", " else\n", " {\n", - " int *ptmp = (int*)realloc(array, sizeof(int) * (sz+1));\n", + " int *ptmp = (int*)realloc(arrayHead, sizeof(int) * (sz+1));\n", " if (!ptmp)\n", " Mock.allocFailure++;\n", " else\n", - " array = ptmp;\n"," }\n", - " memcpy(&array[sz], &new_value, sizeof(int));\n", - " arrayTail = &array[sz+1];\n", + " arrayHead = ptmp;\n"," }\n", + " memcpy(&arrayHead[sz], &new_value, sizeof(int));\n", + " arrayTail = &arrayHead[sz+1];\n", " }\n" ] returned = @cmock_generator_utils.code_insert_item_into_expect_array(the_type, the_array, new_value) @@ -84,7 +84,7 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase function = { :name => "Spatula", :rettype => "uint64"} indent = "[tab]" expected = ["\n", - "[tab]if (Mock.Spatula_Return != Mock.Spatula_Return_HeadTail)\n", + "[tab]if (Mock.Spatula_Return != Mock.Spatula_Return_Tail)\n", "[tab]{\n", "[tab] uint64 toReturn = *Mock.Spatula_Return;\n", "[tab] Mock.Spatula_Return++;\n", @@ -108,7 +108,7 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase " {\n", " int sz = 0;\n", " uint16 *pointer = Mock.PizzaCutter_Expected_Spork_Head;\n", - " while (pointer && pointer != Mock.PizzaCutter_Expected_Spork_HeadTail) { sz++; pointer++; }\n", + " while (pointer && pointer != Mock.PizzaCutter_Expected_Spork_Tail) { sz++; pointer++; }\n", " if (sz == 0)\n", " {\n", " Mock.PizzaCutter_Expected_Spork_Head = (uint16*)malloc(2*sizeof(uint16));\n", @@ -124,7 +124,7 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase " Mock.PizzaCutter_Expected_Spork_Head = ptmp;\n", " }\n", " memcpy(&Mock.PizzaCutter_Expected_Spork_Head[sz], &Spork, sizeof(uint16));\n", - " Mock.PizzaCutter_Expected_Spork_HeadTail = &Mock.PizzaCutter_Expected_Spork_Head[sz+1];\n", + " Mock.PizzaCutter_Expected_Spork_Tail = &Mock.PizzaCutter_Expected_Spork_Head[sz+1];\n", " }\n", " Mock.PizzaCutter_Expected_Spork = Mock.PizzaCutter_Expected_Spork_Head;\n", " Mock.PizzaCutter_Expected_Spork += Mock.PizzaCutter_CallCount;\n" @@ -139,7 +139,7 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase var_name = "CorkScrew" expected = ["\n", - " if (Mock.CanOpener_Expected_CorkScrew != Mock.CanOpener_Expected_CorkScrew_HeadTail)\n", + " if (Mock.CanOpener_Expected_CorkScrew != Mock.CanOpener_Expected_CorkScrew_Tail)\n", " {\n", " uint16* p_expected = Mock.CanOpener_Expected_CorkScrew;\n", " Mock.CanOpener_Expected_CorkScrew++;\n", @@ -159,7 +159,7 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase @unity_helper.expect.get_helper(var_type).returns("TEST_ASSERT_EQUAL_STRING_MESSAGE") expected = ["\n", - " if (Mock.MeasureCup_Expected_TeaSpoon != Mock.MeasureCup_Expected_TeaSpoon_HeadTail)\n", + " if (Mock.MeasureCup_Expected_TeaSpoon != Mock.MeasureCup_Expected_TeaSpoon_Tail)\n", " {\n", " const char** p_expected = Mock.MeasureCup_Expected_TeaSpoon;\n", " Mock.MeasureCup_Expected_TeaSpoon++;\n", @@ -179,7 +179,7 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase @unity_helper.expect.get_helper(var_type).returns("TEST_ASSERT_EQUAL_MANDELBROT_SET_T_MESSAGE") expected = ["\n", - " if (Mock.TeaPot_Expected_TeaSpoon != Mock.TeaPot_Expected_TeaSpoon_HeadTail)\n", + " if (Mock.TeaPot_Expected_TeaSpoon != Mock.TeaPot_Expected_TeaSpoon_Tail)\n", " {\n", " MANDELBROT_SET_T* p_expected = Mock.TeaPot_Expected_TeaSpoon;\n", " Mock.TeaPot_Expected_TeaSpoon++;\n", @@ -199,7 +199,7 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase @unity_helper.expect.get_helper(var_type).returns("TEST_ASSERT_EQUAL_MEMORY_MESSAGE") expected = ["\n", - " if (Mock.Toaster_Expected_Bread != Mock.Toaster_Expected_Bread_HeadTail)\n", + " if (Mock.Toaster_Expected_Bread != Mock.Toaster_Expected_Bread_Tail)\n", " {\n", " SOME_STRUCT* p_expected = Mock.Toaster_Expected_Bread;\n", " Mock.Toaster_Expected_Bread++;\n", @@ -219,7 +219,7 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase @unity_helper.expect.get_helper(var_type).returns("TEST_ASSERT_EQUAL_FRUIT_ARRAY_MESSAGE") expected = ["\n", - " if (Mock.Blender_Expected_Strawberry != Mock.Blender_Expected_Strawberry_HeadTail)\n", + " if (Mock.Blender_Expected_Strawberry != Mock.Blender_Expected_Strawberry_Tail)\n", " {\n", " FRUIT** p_expected = Mock.Blender_Expected_Strawberry;\n", " Mock.Blender_Expected_Strawberry++;\n", diff --git a/test/unit/cmock_header_parser_test.rb b/test/unit/cmock_header_parser_test.rb index 7a8abcd..6d7fc92 100644 --- a/test/unit/cmock_header_parser_test.rb +++ b/test/unit/cmock_header_parser_test.rb @@ -235,7 +235,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase { :modifier => "", - :args_string => "", + :args_string => "void", :rettype => "void", :var_arg => nil, :args => [], @@ -352,5 +352,40 @@ class CMockHeaderParserTest < Test::Unit::TestCase assert_equal(expected, parsed_stuff[:functions]) end + + should "extract and return function declarations with just types (no argument names)" do + source = + "int buzzlightyear(char*, bool);\n" + + "bool woody();\n" + + @parser = CMockHeaderParser.new(source) + parsed_stuff = @parser.parse + + expected = + [ + { + :modifier => "", + :args_string => "char* cmock_arg1, bool cmock_arg2", + :rettype => "int", + :var_arg => nil, + :args => + [ + {:type => "char*", :name => "cmock_arg1"}, + {:type => "bool", :name => "cmock_arg2"} + ], + :name => "buzzlightyear" + }, + { + :modifier => "", + :args_string => "void", + :rettype => "bool", + :var_arg => nil, + :args => [], + :name => "woody" + } + ] + + assert_equal(expected, parsed_stuff[:functions]) + end end \ No newline at end of file diff --git a/test/unit/cmock_plugin_manager_test.rb b/test/unit/cmock_plugin_manager_test.rb index 74d08ce..26742dd 100644 --- a/test/unit/cmock_plugin_manager_test.rb +++ b/test/unit/cmock_plugin_manager_test.rb @@ -5,6 +5,7 @@ class CMockPluginManagerTest < Test::Unit::TestCase def setup create_mocks :config, :utils, :pluginA, :pluginB @config.stubs!(:respond_to?).returns(true) + @config.stubs!(:when_ptr_star).returns(:compare_data) end def teardown