1
0
mirror of https://github.com/ThrowTheSwitch/CMock synced 2025-03-12 16:51:11 -04:00

- fixed broken tests introduced by Jocelyn's changes (oops. I should have checked that)

- reverted casting change, because it produces many pedantic C errors.
This commit is contained in:
Mark VanderVoord 2014-05-07 15:57:08 -04:00
parent db3ff131a5
commit b9b68bd26c
4 changed files with 84 additions and 85 deletions

View File

@ -183,9 +183,8 @@ class CMockGenerator
file << " UNITY_TEST_FAIL(cmock_line, \"Function '#{function[:name]}' called later than expected.\");\n"
# file << " UNITY_TEST_ASSERT((cmock_call_instance->CallOrder == ++GlobalVerifyOrder), cmock_line, \"Out of order function calls. Function '#{function[:name]}'\");\n"
end
return_type = function[:return][:const?] ? "const #{function[:return][:type]}" : function[:return][:type]
file << @plugins.run(:mock_implementation, function)
file << " return (#{return_type})cmock_call_instance->ReturnVal;\n" unless (function[:return][:void?])
file << " return cmock_call_instance->ReturnVal;\n" unless (function[:return][:void?])
file << "}\n\n"
end

View File

@ -2,7 +2,7 @@
# CMock Project - Automatic Mock Generation for C
# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
# [Released under MIT License. Please refer to license.txt for details]
# ==========================================
# ==========================================
$ThisIsOnlyATest = true
@ -13,23 +13,23 @@ class MockedPluginHelper
def initialize return_this
@return_this = return_this
end
def include_files
return @return_this
end
def instance_structure( name, args, rettype )
return " #{@return_this}_#{name}(#{args}, #{rettype})"
end
def mock_verify( name )
return " #{@return_this}_#{name}"
end
def mock_destroy( name, args, rettype )
return " #{@return_this}_#{name}(#{args}, #{rettype})"
end
def mock_implementation(name, args)
return " Mock#{name}#{@return_this}(#{args.join(", ")})"
end
@ -39,7 +39,7 @@ class CMockGeneratorTest < Test::Unit::TestCase
def setup
create_mocks :config, :file_writer, :utils, :plugins
@module_name = "PoutPoutFish"
#no strict handling
@config.expect.mock_prefix.returns("Mock")
@config.expect.enforce_strict_ordering.returns(nil)
@ -53,7 +53,7 @@ class CMockGeneratorTest < Test::Unit::TestCase
@cmock_generator.module_name = @module_name
@cmock_generator.mock_name = "Mock#{@module_name}"
@cmock_generator.clean_mock_name = "Mock#{@module_name}"
#strict handling
@config.expect.mock_prefix.returns("Mock")
@config.expect.enforce_strict_ordering.returns(true)
@ -71,14 +71,14 @@ class CMockGeneratorTest < Test::Unit::TestCase
def teardown
end
should "have set up internal accessors correctly on init" do
assert_equal(@config, @cmock_generator.config)
assert_equal(@file_writer, @cmock_generator.file_writer)
assert_equal(@utils, @cmock_generator.utils)
assert_equal(@plugins, @cmock_generator.plugins)
end
should "create the top of a header file with optional include files from config and include file from plugin" do
@config.expect.mock_prefix.returns("Mock")
orig_filename = "PoutPoutFish.h"
@ -96,9 +96,9 @@ class CMockGeneratorTest < Test::Unit::TestCase
]
@plugins.expect.run(:include_files).returns("#include \"PluginRequiredHeader.h\"\n")
@cmock_generator.create_mock_header_header(output, "MockPoutPoutFish.h")
assert_equal(expected, output)
end
@ -115,7 +115,7 @@ class CMockGeneratorTest < Test::Unit::TestCase
@cmock_generator2.module_name = "Pout-Pout Fish"
@cmock_generator2.mock_name = "MockPout-Pout Fish"
@cmock_generator2.clean_mock_name = "MockPout_Pout_Fish"
@config.expect.mock_prefix.returns("Mock")
orig_filename = "Pout-Pout Fish.h"
define_name = "MOCKPOUT_POUT_FISH_H"
@ -132,12 +132,12 @@ class CMockGeneratorTest < Test::Unit::TestCase
]
@plugins.expect.run(:include_files).returns("#include \"PluginRequiredHeader.h\"\n")
@cmock_generator2.create_mock_header_header(output, "MockPout-Pout Fish.h")
assert_equal(expected, output)
end
should "create the top of a header file with optional include files from config" do
@config.expect.mock_prefix.returns("Mock")
orig_filename = "PoutPoutFish.h"
@ -154,9 +154,9 @@ class CMockGeneratorTest < Test::Unit::TestCase
]
@plugins.expect.run(:include_files).returns('')
@cmock_generator.create_mock_header_header(output, "MockPoutPoutFish.h")
assert_equal(expected, output)
end
@ -177,14 +177,14 @@ class CMockGeneratorTest < Test::Unit::TestCase
]
@plugins.expect.run(:include_files).returns("#include \"PluginRequiredHeader.h\"\n")
@cmock_generator.create_mock_header_header(output, "MockPoutPoutFish.h")
assert_equal(expected, output)
end
should "write typedefs" do
typedefs = [ 'typedef unsigned char U8;',
typedefs = [ 'typedef unsigned char U8;',
'typedef char S8;',
'typedef unsigned long U32;'
]
@ -195,9 +195,9 @@ class CMockGeneratorTest < Test::Unit::TestCase
"typedef unsigned long U32;\n",
"\n\n"
]
@cmock_generator.create_typedefs(output, typedefs)
assert_equal(expected, output.flatten)
end
@ -209,21 +209,21 @@ class CMockGeneratorTest < Test::Unit::TestCase
"void #{mock_name}_Destroy(void);\n",
"void #{mock_name}_Verify(void);\n\n"
]
@cmock_generator.create_mock_header_service_call_declarations(output)
assert_equal(expected, output)
end
should "append the proper footer to the header file" do
should "append the proper footer to the header file" do
output = []
expected = ["\n#endif\n"]
@cmock_generator.create_mock_header_footer(output)
assert_equal(expected, output)
end
should "create a proper heading for a source file" do
output = []
expected = [ "/* AUTOGENERATED FILE. DO NOT EDIT. */\n",
@ -235,13 +235,13 @@ class CMockGeneratorTest < Test::Unit::TestCase
"#include \"MockPoutPoutFish.h\"\n",
"\n"
]
@cmock_generator.create_source_header_section(output, "MockPoutPoutFish.c")
assert_equal(expected, output)
end
should "create the instance structure where it is needed when no functions" do
should "create the instance structure where it is needed when no functions" do
output = []
functions = []
expected = [ "static struct MockPoutPoutFishInstance\n",
@ -249,15 +249,15 @@ class CMockGeneratorTest < Test::Unit::TestCase
" unsigned char placeHolder;\n",
"} Mock;\n\n"
].join
@cmock_generator.create_instance_structure(output, functions)
assert_equal(expected, output.join)
end
should "create the instance structure where it is needed when functions required" do
should "create the instance structure where it is needed when functions required" do
output = []
functions = [ { :name => "First", :args => "int Candy", :return => test_return[:int] },
functions = [ { :name => "First", :args => "int Candy", :return => test_return[:int] },
{ :name => "Second", :args => "bool Smarty", :return => test_return[:string] }
]
expected = [ "typedef struct _CMOCK_First_CALL_INSTANCE\n{\n",
@ -279,51 +279,51 @@ class CMockGeneratorTest < Test::Unit::TestCase
@plugins.expect.run(:instance_structure, functions[0]).returns([" d1"])
@plugins.expect.run(:instance_structure, functions[1]).returns([" e1"," e2"," e3"])
@cmock_generator.create_instance_structure(output, functions)
assert_equal(expected, output.join)
end
should "create extern declarations for source file" do
output = []
expected = [ "extern jmp_buf AbortFrame;\n",
"\n" ]
@cmock_generator.create_extern_declarations(output)
assert_equal(expected, output.flatten)
end
should "create extern declarations for source file when using strict ordering" do
output = []
expected = [ "extern jmp_buf AbortFrame;\n",
"extern int GlobalExpectCount;\n",
"extern int GlobalVerifyOrder;\n",
"\n" ]
@cmock_generator_strict.create_extern_declarations(output)
assert_equal(expected, output.flatten)
end
should "create mock verify functions in source file when no functions specified" do
functions = []
output = []
expected = "void MockPoutPoutFish_Verify(void)\n{\n}\n\n"
@cmock_generator.create_mock_verify_function(output, functions)
assert_equal(expected, output.join)
end
should "create mock verify functions in source file when extra functions specified" do
functions = [ { :name => "First", :args => "int Candy", :return => test_return[:int] },
{ :name => "Second", :args => "bool Smarty", :return => test_return[:string] }
functions = [ { :name => "First", :args => "int Candy", :return => test_return[:int] },
{ :name => "Second", :args => "bool Smarty", :return => test_return[:string] }
]
output = []
expected = [ "void MockPoutPoutFish_Verify(void)\n{\n",
" UNITY_LINE_TYPE cmock_line = TEST_LINE_NUM;\n",
" UNITY_LINE_TYPE cmock_line;\n cmock_line = TEST_LINE_NUM;\n",
" Uno_First" +
" Dos_First" +
" Uno_Second" +
@ -332,13 +332,13 @@ class CMockGeneratorTest < Test::Unit::TestCase
]
@plugins.expect.run(:mock_verify, functions[0]).returns([" Uno_First"," Dos_First"])
@plugins.expect.run(:mock_verify, functions[1]).returns([" Uno_Second"," Dos_Second"])
@cmock_generator.ordered = true
@cmock_generator.create_mock_verify_function(output, functions)
assert_equal(expected, output.flatten)
end
should "create mock init functions in source file" do
output = []
expected = [ "void MockPoutPoutFish_Init(void)\n{\n",
@ -347,10 +347,10 @@ class CMockGeneratorTest < Test::Unit::TestCase
]
@cmock_generator.create_mock_init_function(output)
assert_equal(expected.join, output.join)
end
should "create mock destroy functions in source file" do
functions = []
output = []
@ -364,10 +364,10 @@ class CMockGeneratorTest < Test::Unit::TestCase
assert_equal(expected.join, output.join)
end
should "create mock destroy functions in source file when specified with strict ordering" do
functions = [ { :name => "First", :args => "int Candy", :return => test_return[:int] },
{ :name => "Second", :args => "bool Smarty", :return => test_return[:string] }
functions = [ { :name => "First", :args => "int Candy", :return => test_return[:int] },
{ :name => "Second", :args => "bool Smarty", :return => test_return[:string] }
]
output = []
expected = [ "void MockPoutPoutFish_Destroy(void)\n{\n",
@ -380,16 +380,16 @@ class CMockGeneratorTest < Test::Unit::TestCase
]
@plugins.expect.run(:mock_destroy, functions[0]).returns([])
@plugins.expect.run(:mock_destroy, functions[1]).returns([" uno"])
@cmock_generator_strict.create_mock_destroy_function(output, functions)
assert_equal(expected.join, output.join)
end
should "create mock implementation functions in source file" do
function = { :modifier => "static",
:return => test_return[:int],
:args_string => "uint32 sandwiches, const char* named",
function = { :modifier => "static",
:return => test_return[:int],
:args_string => "uint32 sandwiches, const char* named",
:args => ["uint32 sandwiches", "const char* named"],
:var_arg => nil,
:name => "SupaFunction",
@ -398,7 +398,7 @@ class CMockGeneratorTest < Test::Unit::TestCase
output = []
expected = [ "static int SupaFunction(uint32 sandwiches, const char* named)\n",
"{\n",
" UNITY_LINE_TYPE cmock_line = TEST_LINE_NUM;\n",
" UNITY_LINE_TYPE cmock_line;\n cmock_line = TEST_LINE_NUM;\n",
" CMOCK_SupaFunction_CALL_INSTANCE* cmock_call_instance = (CMOCK_SupaFunction_CALL_INSTANCE*)CMock_Guts_GetAddressFor(Mock.SupaFunction_CallInstance);\n",
" Mock.SupaFunction_CallInstance = CMock_Guts_MemNext(Mock.SupaFunction_CallInstance);\n",
" uno",
@ -411,17 +411,17 @@ class CMockGeneratorTest < Test::Unit::TestCase
]
@plugins.expect.run(:mock_implementation_precheck, function).returns([" uno"])
@plugins.expect.run(:mock_implementation, function).returns([" dos"," tres"])
@cmock_generator.create_mock_implementation(output, function)
assert_equal(expected.join, output.join)
end
should "create mock implementation functions in source file with different options" do
function = { :modifier => "",
function = { :modifier => "",
:c_calling_convention => "__stdcall",
:return => test_return[:int],
:args_string => "uint32 sandwiches",
:return => test_return[:int],
:args_string => "uint32 sandwiches",
:args => ["uint32 sandwiches"],
:var_arg => "corn ...",
:name => "SupaFunction",
@ -430,7 +430,7 @@ class CMockGeneratorTest < Test::Unit::TestCase
output = []
expected = [ "int __stdcall SupaFunction(uint32 sandwiches, corn ...)\n",
"{\n",
" UNITY_LINE_TYPE cmock_line = TEST_LINE_NUM;\n",
" UNITY_LINE_TYPE cmock_line;\n cmock_line = TEST_LINE_NUM;\n",
" CMOCK_SupaFunction_CALL_INSTANCE* cmock_call_instance = (CMOCK_SupaFunction_CALL_INSTANCE*)CMock_Guts_GetAddressFor(Mock.SupaFunction_CallInstance);\n",
" Mock.SupaFunction_CallInstance = CMock_Guts_MemNext(Mock.SupaFunction_CallInstance);\n",
" uno",
@ -443,9 +443,9 @@ class CMockGeneratorTest < Test::Unit::TestCase
]
@plugins.expect.run(:mock_implementation_precheck, function).returns([" uno"])
@plugins.expect.run(:mock_implementation, function).returns([" dos"," tres"])
@cmock_generator.create_mock_implementation(output, function)
assert_equal(expected.join, output.join)
end
end

View File

@ -67,9 +67,9 @@ class CMockGeneratorPluginIgnoreTest < Test::Unit::TestCase
expected = [" if (Mock.Fungus_IgnoreBool)\n",
" {\n",
" if (cmock_call_instance == NULL)\n",
" return Mock.Fungus_FinalReturn;\n",
" return (int)Mock.Fungus_FinalReturn;\n",
" mock_retval_0",
" return cmock_call_instance->ReturnVal;\n",
" return (int)cmock_call_instance->ReturnVal;\n",
" }\n"
].join
returned = @cmock_generator_plugin_ignore.mock_implementation_precheck(function)

View File

@ -575,7 +575,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
:return=>{ :type => "int",
:name => 'cmock_to_return',
:ptr? => false,
:const? => false,
:const? => true,
:str => "int cmock_to_return",
:void? => false
},
@ -597,7 +597,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
:return=>{ :type => "int",
:name => 'cmock_to_return',
:ptr? => false,
:const? => false,
:const? => true,
:str => "int cmock_to_return",
:void? => false
},
@ -622,7 +622,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
:return=> { :type => "int",
:name => 'cmock_to_return',
:ptr? => false,
:const? => false,
:const? => true,
:str => "int cmock_to_return",
:void? => false
},
@ -664,7 +664,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
:return=> { :type => "int",
:name => 'cmock_to_return',
:ptr? => false,
:const? => false,
:const? => true,
:str => "int cmock_to_return",
:void? => false
},