[修改] 增加freeRTOS
1. 版本FreeRTOSv202212.01,命名为kernel;
This commit is contained in:
126
kernel/FreeRTOS-Plus/Test/CMock/test/unit/cmock_config_test.rb
Normal file
126
kernel/FreeRTOS-Plus/Test/CMock/test/unit/cmock_config_test.rb
Normal file
@ -0,0 +1,126 @@
|
||||
# ==========================================
|
||||
# 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]
|
||||
# ==========================================
|
||||
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
|
||||
require File.expand_path(File.dirname(__FILE__)) + '/../../lib/cmock_config'
|
||||
|
||||
|
||||
describe CMockConfig, "Verify CMockConfig Module" do
|
||||
|
||||
it "use default settings when no parameters are specified" do
|
||||
config = CMockConfig.new
|
||||
assert_equal(CMockConfig::CMOCK_DEFAULT_OPTIONS[:mock_path], config.mock_path)
|
||||
assert_nil(CMockConfig::CMOCK_DEFAULT_OPTIONS[:includes])
|
||||
assert_nil(config.includes)
|
||||
assert_equal(CMockConfig::CMOCK_DEFAULT_OPTIONS[:attributes], config.attributes)
|
||||
assert_equal(CMockConfig::CMOCK_DEFAULT_OPTIONS[:plugins], config.plugins)
|
||||
assert_equal(CMockConfig::CMOCK_DEFAULT_OPTIONS[:treat_externs], config.treat_externs)
|
||||
assert_equal(CMockConfig::CMOCK_DEFAULT_OPTIONS[:treat_inlines], config.treat_inlines)
|
||||
assert_equal(CMockConfig::CMOCK_DEFAULT_OPTIONS[:inline_function_patterns], config.inline_function_patterns)
|
||||
end
|
||||
|
||||
it "replace only options specified in a hash" do
|
||||
test_includes = ['hello']
|
||||
test_attributes = ['blah', 'bleh']
|
||||
config = CMockConfig.new(:includes => test_includes, :attributes => test_attributes)
|
||||
assert_equal(CMockConfig::CMOCK_DEFAULT_OPTIONS[:mock_path], config.mock_path)
|
||||
assert_equal(test_includes, config.includes)
|
||||
assert_equal(test_attributes, config.attributes)
|
||||
assert_equal(CMockConfig::CMOCK_DEFAULT_OPTIONS[:plugins], config.plugins)
|
||||
assert_equal(CMockConfig::CMOCK_DEFAULT_OPTIONS[:treat_externs], config.treat_externs)
|
||||
assert_equal(CMockConfig::CMOCK_DEFAULT_OPTIONS[:treat_inlines], config.treat_inlines)
|
||||
assert_equal(CMockConfig::CMOCK_DEFAULT_OPTIONS[:inline_function_patterns], config.inline_function_patterns)
|
||||
end
|
||||
|
||||
it "replace only options specified in a yaml file" do
|
||||
test_plugins = [:soda, :pizza]
|
||||
config = CMockConfig.new("#{File.expand_path(File.dirname(__FILE__))}/cmock_config_test.yml")
|
||||
assert_equal(CMockConfig::CMOCK_DEFAULT_OPTIONS[:mock_path], config.mock_path)
|
||||
assert_nil(CMockConfig::CMOCK_DEFAULT_OPTIONS[:includes])
|
||||
assert_nil(config.includes)
|
||||
assert_equal(test_plugins, config.plugins)
|
||||
assert_equal(:include, config.treat_externs)
|
||||
assert_equal(:include, config.treat_inlines)
|
||||
assert_equal(['MY_INLINE_FUNCTION_DECLARATION_PATTERN'], config.inline_function_patterns)
|
||||
end
|
||||
|
||||
it "populate treat_as map with internal standard_treat_as_map defaults, redefine defaults, and add custom values" do
|
||||
|
||||
user_treat_as1 = {
|
||||
'BOOL' => 'UINT8', # redefine standard default
|
||||
'unsigned long' => 'INT', # redefine standard default
|
||||
'U8' => 'UINT8', # custom value
|
||||
'U16' => 'UINT16' # custom value
|
||||
}
|
||||
user_treat_as2 = {
|
||||
'BOOL' => 'INT16', # redefine standard default
|
||||
'U16' => 'HEX16' # custom value
|
||||
}
|
||||
|
||||
config1 = CMockConfig.new({:treat_as => user_treat_as1})
|
||||
config2 = CMockConfig.new({:treat_as => user_treat_as2})
|
||||
|
||||
# ----- USER SET 1
|
||||
# standard defaults
|
||||
assert_equal('INT', config1.treat_as['BOOL_T'])
|
||||
assert_equal('HEX32', config1.treat_as['unsigned int'])
|
||||
assert_equal('HEX8_ARRAY',config1.treat_as['void*'])
|
||||
assert_equal('STRING', config1.treat_as['CSTRING'])
|
||||
assert_equal('STRING', config1.treat_as['char*'])
|
||||
assert_equal('HEX8', config1.treat_as['unsigned char'])
|
||||
assert_equal('INT', config1.treat_as['long'])
|
||||
assert_equal('INT16', config1.treat_as['short'])
|
||||
|
||||
# overrides
|
||||
assert_equal('UINT8', config1.treat_as['BOOL'])
|
||||
assert_equal('INT', config1.treat_as['unsigned long'])
|
||||
|
||||
# added custom values
|
||||
assert_equal('UINT8', config1.treat_as['U8'])
|
||||
assert_equal('UINT16', config1.treat_as['U16'])
|
||||
|
||||
# standard_treat_as_map: unchanged
|
||||
assert_equal('INT', config1.standard_treat_as_map['BOOL'])
|
||||
assert_equal('HEX32', config1.standard_treat_as_map['unsigned long'])
|
||||
assert_equal('STRING', config1.standard_treat_as_map['char*'])
|
||||
|
||||
# ----- USER SET 2
|
||||
# standard defaults
|
||||
assert_equal('INT', config2.treat_as['BOOL_T'])
|
||||
assert_equal('HEX32', config2.treat_as['unsigned int'])
|
||||
assert_equal('HEX8_ARRAY',config2.treat_as['void*'])
|
||||
assert_equal('STRING', config2.treat_as['CSTRING'])
|
||||
assert_equal('STRING', config2.treat_as['char*'])
|
||||
assert_equal('HEX8', config2.treat_as['unsigned char'])
|
||||
assert_equal('INT', config2.treat_as['long'])
|
||||
assert_equal('INT16', config2.treat_as['short'])
|
||||
assert_equal('HEX32', config2.treat_as['unsigned long'])
|
||||
|
||||
# overrides
|
||||
assert_equal('INT16', config2.treat_as['BOOL'])
|
||||
|
||||
# added custom values
|
||||
assert_equal('HEX16', config2.treat_as['U16'])
|
||||
|
||||
# standard_treat_as_map: unchanged
|
||||
assert_equal('INT', config2.standard_treat_as_map['BOOL'])
|
||||
assert_equal('HEX32', config2.standard_treat_as_map['unsigned long'])
|
||||
assert_equal('STRING', config2.standard_treat_as_map['char*'])
|
||||
end
|
||||
|
||||
it "standard treat_as map should be incorruptable" do
|
||||
config = CMockConfig.new({})
|
||||
|
||||
assert_equal('INT', config.standard_treat_as_map['BOOL_T'])
|
||||
|
||||
local = config.standard_treat_as_map
|
||||
local['BOOL_T'] = "U8"
|
||||
|
||||
assert_equal('INT', config.standard_treat_as_map['BOOL_T'])
|
||||
end
|
||||
|
||||
end
|
||||
@ -0,0 +1,7 @@
|
||||
:cmock:
|
||||
:plugins:
|
||||
- 'soda'
|
||||
- 'pizza'
|
||||
:treat_externs: :include
|
||||
:treat_inlines: :include
|
||||
:inline_function_patterns: ['MY_INLINE_FUNCTION_DECLARATION_PATTERN']
|
||||
@ -0,0 +1,27 @@
|
||||
# ==========================================
|
||||
# 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]
|
||||
# ==========================================
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
|
||||
require File.expand_path(File.dirname(__FILE__)) + '/../../lib/cmock_file_writer'
|
||||
|
||||
describe CMockFileWriter, "Verify CMockFileWriter Module" do
|
||||
|
||||
before do
|
||||
create_mocks :config
|
||||
@cmock_file_writer = CMockFileWriter.new(@config)
|
||||
end
|
||||
|
||||
after do
|
||||
end
|
||||
|
||||
it "complain if a block was not specified when calling create" do
|
||||
begin
|
||||
@cmock_file_writer.create_file("test.txt")
|
||||
assert false, "Should Have Thrown An Error When Calling Without A Block"
|
||||
rescue
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,686 @@
|
||||
# ==========================================
|
||||
# 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
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
|
||||
require File.expand_path(File.dirname(__FILE__)) + '/../../lib/cmock_generator'
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
describe CMockGenerator, "Verify CMockGenerator Module" do
|
||||
|
||||
before do
|
||||
create_mocks :config, :file_writer, :utils, :plugins
|
||||
@module_name = "PoutPoutFish"
|
||||
|
||||
#no strict handling
|
||||
@config.expect :mock_prefix, "Mock"
|
||||
@config.expect :mock_suffix, ""
|
||||
@config.expect :weak, ""
|
||||
@config.expect :enforce_strict_ordering, nil
|
||||
@config.expect :framework, :unity
|
||||
@config.expect :includes, ["ConfigRequiredHeader1.h","ConfigRequiredHeader2.h"]
|
||||
#@config.expect :includes_h_pre_orig_header, nil #not called because includes called
|
||||
@config.expect :includes_h_post_orig_header, nil
|
||||
@config.expect :includes_c_pre_header, nil
|
||||
@config.expect :includes_c_post_header, nil
|
||||
@config.expect :subdir, nil
|
||||
@config.expect :fail_on_unexpected_calls, true
|
||||
@config.expect :treat_inlines, :exclude
|
||||
@cmock_generator = CMockGenerator.new(@config, @file_writer, @utils, @plugins)
|
||||
@cmock_generator.module_name = @module_name
|
||||
@cmock_generator.module_ext = '.h'
|
||||
@cmock_generator.mock_name = "Mock#{@module_name}"
|
||||
@cmock_generator.clean_mock_name = "Mock#{@module_name}"
|
||||
|
||||
#strict handling
|
||||
@config.expect :mock_prefix, "Mock"
|
||||
@config.expect :mock_suffix, ""
|
||||
@config.expect :weak, ""
|
||||
@config.expect :enforce_strict_ordering, true
|
||||
@config.expect :framework, :unity
|
||||
@config.expect :includes, nil
|
||||
@config.expect :includes_h_pre_orig_header, nil
|
||||
@config.expect :includes_h_post_orig_header, nil
|
||||
@config.expect :includes_c_pre_header, nil
|
||||
@config.expect :includes_c_post_header, nil
|
||||
@config.expect :subdir, nil
|
||||
@config.expect :fail_on_unexpected_calls, true
|
||||
@config.expect :treat_inlines, :exclude
|
||||
@cmock_generator_strict = CMockGenerator.new(@config, @file_writer, @utils, @plugins)
|
||||
@cmock_generator_strict.module_name = @module_name
|
||||
@cmock_generator_strict.module_ext = '.h'
|
||||
@cmock_generator_strict.mock_name = "Mock#{@module_name}"
|
||||
@cmock_generator_strict.clean_mock_name = "Mock#{@module_name}"
|
||||
end
|
||||
|
||||
after do
|
||||
end
|
||||
|
||||
def helper_create_header_top_with_opt_incldues_form_config_and_plugin(ext)
|
||||
@config.expect :mock_prefix, "Mock"
|
||||
@config.expect :mock_suffix, ""
|
||||
@config.expect :weak, ""
|
||||
@cmock_generator.module_ext = ext
|
||||
orig_filename = "PoutPoutFish#{ext}"
|
||||
define_name = "MOCKPOUTPOUTFISH_H"
|
||||
output = []
|
||||
expected = [
|
||||
"/* AUTOGENERATED FILE. DO NOT EDIT. */\n",
|
||||
"#ifndef _#{define_name}\n",
|
||||
"#define _#{define_name}\n\n",
|
||||
"#include \"unity.h\"\n",
|
||||
"#include \"ConfigRequiredHeader1.h\"\n",
|
||||
"#include \"ConfigRequiredHeader2.h\"\n",
|
||||
"#include \"#{orig_filename}\"\n",
|
||||
"#include \"PluginRequiredHeader.h\"\n",
|
||||
"\n",
|
||||
"/* Ignore the following warnings, since we are copying code */\n",
|
||||
"#if defined(__GNUC__) && !defined(__ICC) && !defined(__TMS470__)\n",
|
||||
"#if __GNUC__ > 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ > 6 || (__GNUC_MINOR__ == 6 && __GNUC_PATCHLEVEL__ > 0)))\n",
|
||||
"#pragma GCC diagnostic push\n",
|
||||
"#endif\n",
|
||||
"#if !defined(__clang__)\n",
|
||||
"#pragma GCC diagnostic ignored \"-Wpragmas\"\n",
|
||||
"#endif\n",
|
||||
"#pragma GCC diagnostic ignored \"-Wunknown-pragmas\"\n",
|
||||
"#pragma GCC diagnostic ignored \"-Wduplicate-decl-specifier\"\n",
|
||||
"#endif\n",
|
||||
"\n",
|
||||
]
|
||||
|
||||
@config.expect :orig_header_include_fmt, "#include \"%s\""
|
||||
@plugins.expect :run, "#include \"PluginRequiredHeader.h\"\n", [:include_files]
|
||||
|
||||
@cmock_generator.create_mock_header_header(output, "Mock#{orig_filename}")
|
||||
|
||||
assert_equal(expected, output)
|
||||
end
|
||||
|
||||
it "create the top of a header file with optional include files from config and include file from plugin" do
|
||||
['.h','.hh','.hpp'].each do |ext|
|
||||
helper_create_header_top_with_opt_incldues_form_config_and_plugin(ext)
|
||||
end
|
||||
end
|
||||
|
||||
it "handle dashes and spaces in the module name" do
|
||||
#no strict handling
|
||||
@config.expect :mock_prefix, "Mock"
|
||||
@config.expect :mock_suffix, ""
|
||||
@config.expect :weak, ""
|
||||
@config.expect :enforce_strict_ordering, nil
|
||||
@config.expect :framework, :unity
|
||||
@config.expect :includes, ["ConfigRequiredHeader1.h","ConfigRequiredHeader2.h"]
|
||||
@config.expect :includes_h_post_orig_header, nil
|
||||
@config.expect :includes_c_pre_header, nil
|
||||
@config.expect :includes_c_post_header, nil
|
||||
@config.expect :subdir, nil
|
||||
@config.expect :fail_on_unexpected_calls, true
|
||||
@config.expect :treat_inlines, :exclude
|
||||
@cmock_generator2 = CMockGenerator.new(@config, @file_writer, @utils, @plugins)
|
||||
@cmock_generator2.module_name = "Pout-Pout Fish"
|
||||
@cmock_generator2.module_ext = '.h'
|
||||
@cmock_generator2.mock_name = "MockPout-Pout Fish"
|
||||
@cmock_generator2.clean_mock_name = "MockPout_Pout_Fish"
|
||||
|
||||
@config.expect :mock_prefix, "Mock"
|
||||
@config.expect :mock_suffix, ""
|
||||
@config.expect :weak, ""
|
||||
orig_filename = "Pout-Pout Fish.h"
|
||||
define_name = "MOCKPOUT_POUT_FISH_H"
|
||||
output = []
|
||||
expected = [
|
||||
"/* AUTOGENERATED FILE. DO NOT EDIT. */\n",
|
||||
"#ifndef _#{define_name}\n",
|
||||
"#define _#{define_name}\n\n",
|
||||
"#include \"unity.h\"\n",
|
||||
"#include \"ConfigRequiredHeader1.h\"\n",
|
||||
"#include \"ConfigRequiredHeader2.h\"\n",
|
||||
"#include \"#{orig_filename}\"\n",
|
||||
"#include \"PluginRequiredHeader.h\"\n",
|
||||
"\n",
|
||||
"/* Ignore the following warnings, since we are copying code */\n",
|
||||
"#if defined(__GNUC__) && !defined(__ICC) && !defined(__TMS470__)\n",
|
||||
"#if __GNUC__ > 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ > 6 || (__GNUC_MINOR__ == 6 && __GNUC_PATCHLEVEL__ > 0)))\n",
|
||||
"#pragma GCC diagnostic push\n",
|
||||
"#endif\n",
|
||||
"#if !defined(__clang__)\n",
|
||||
"#pragma GCC diagnostic ignored \"-Wpragmas\"\n",
|
||||
"#endif\n",
|
||||
"#pragma GCC diagnostic ignored \"-Wunknown-pragmas\"\n",
|
||||
"#pragma GCC diagnostic ignored \"-Wduplicate-decl-specifier\"\n",
|
||||
"#endif\n",
|
||||
"\n",
|
||||
]
|
||||
|
||||
@config.expect :orig_header_include_fmt, "#include \"%s\""
|
||||
@plugins.expect :run, "#include \"PluginRequiredHeader.h\"\n", [:include_files]
|
||||
|
||||
@cmock_generator2.create_mock_header_header(output, "MockPout-Pout Fish.h")
|
||||
|
||||
assert_equal(expected, output)
|
||||
end
|
||||
|
||||
it "create the top of a header file with optional include files from config" do
|
||||
@config.expect :mock_prefix, "Mock"
|
||||
@config.expect :mock_suffix, ""
|
||||
@config.expect :weak, ""
|
||||
orig_filename = "PoutPoutFish.h"
|
||||
define_name = "MOCKPOUTPOUTFISH_H"
|
||||
output = []
|
||||
expected = [
|
||||
"/* AUTOGENERATED FILE. DO NOT EDIT. */\n",
|
||||
"#ifndef _#{define_name}\n",
|
||||
"#define _#{define_name}\n\n",
|
||||
"#include \"unity.h\"\n",
|
||||
"#include \"ConfigRequiredHeader1.h\"\n",
|
||||
"#include \"ConfigRequiredHeader2.h\"\n",
|
||||
"#include \"#{orig_filename}\"\n",
|
||||
"\n",
|
||||
"/* Ignore the following warnings, since we are copying code */\n",
|
||||
"#if defined(__GNUC__) && !defined(__ICC) && !defined(__TMS470__)\n",
|
||||
"#if __GNUC__ > 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ > 6 || (__GNUC_MINOR__ == 6 && __GNUC_PATCHLEVEL__ > 0)))\n",
|
||||
"#pragma GCC diagnostic push\n",
|
||||
"#endif\n",
|
||||
"#if !defined(__clang__)\n",
|
||||
"#pragma GCC diagnostic ignored \"-Wpragmas\"\n",
|
||||
"#endif\n",
|
||||
"#pragma GCC diagnostic ignored \"-Wunknown-pragmas\"\n",
|
||||
"#pragma GCC diagnostic ignored \"-Wduplicate-decl-specifier\"\n",
|
||||
"#endif\n",
|
||||
"\n",
|
||||
]
|
||||
|
||||
@config.expect :orig_header_include_fmt, "#include \"%s\""
|
||||
@plugins.expect :run, '', [:include_files]
|
||||
|
||||
@cmock_generator.create_mock_header_header(output, "MockPoutPoutFish.h")
|
||||
|
||||
assert_equal(expected, output)
|
||||
end
|
||||
|
||||
it "create the top of a header file with include file from plugin" do
|
||||
@config.expect :mock_prefix, "Mock"
|
||||
@config.expect :mock_suffix, ""
|
||||
@config.expect :weak, ""
|
||||
orig_filename = "PoutPoutFish.h"
|
||||
define_name = "MOCKPOUTPOUTFISH_H"
|
||||
output = []
|
||||
expected = [
|
||||
"/* AUTOGENERATED FILE. DO NOT EDIT. */\n",
|
||||
"#ifndef _#{define_name}\n",
|
||||
"#define _#{define_name}\n\n",
|
||||
"#include \"unity.h\"\n",
|
||||
"#include \"ConfigRequiredHeader1.h\"\n",
|
||||
"#include \"ConfigRequiredHeader2.h\"\n",
|
||||
"#include \"#{orig_filename}\"\n",
|
||||
"#include \"PluginRequiredHeader.h\"\n",
|
||||
"\n",
|
||||
"/* Ignore the following warnings, since we are copying code */\n",
|
||||
"#if defined(__GNUC__) && !defined(__ICC) && !defined(__TMS470__)\n",
|
||||
"#if __GNUC__ > 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ > 6 || (__GNUC_MINOR__ == 6 && __GNUC_PATCHLEVEL__ > 0)))\n",
|
||||
"#pragma GCC diagnostic push\n",
|
||||
"#endif\n",
|
||||
"#if !defined(__clang__)\n",
|
||||
"#pragma GCC diagnostic ignored \"-Wpragmas\"\n",
|
||||
"#endif\n",
|
||||
"#pragma GCC diagnostic ignored \"-Wunknown-pragmas\"\n",
|
||||
"#pragma GCC diagnostic ignored \"-Wduplicate-decl-specifier\"\n",
|
||||
"#endif\n",
|
||||
"\n",
|
||||
]
|
||||
|
||||
@config.expect :orig_header_include_fmt, "#include \"%s\""
|
||||
@plugins.expect :run, "#include \"PluginRequiredHeader.h\"\n", [:include_files]
|
||||
|
||||
@cmock_generator.create_mock_header_header(output, "MockPoutPoutFish.h")
|
||||
|
||||
assert_equal(expected, output)
|
||||
end
|
||||
|
||||
it "write typedefs" do
|
||||
typedefs = [ 'typedef unsigned char U8;',
|
||||
'typedef char S8;',
|
||||
'typedef unsigned long U32;'
|
||||
]
|
||||
output = []
|
||||
expected = [ "\n",
|
||||
"typedef unsigned char U8;\n",
|
||||
"typedef char S8;\n",
|
||||
"typedef unsigned long U32;\n",
|
||||
"\n\n"
|
||||
]
|
||||
|
||||
@cmock_generator.create_typedefs(output, typedefs)
|
||||
|
||||
assert_equal(expected, output.flatten)
|
||||
end
|
||||
|
||||
it "create the header file service call declarations" do
|
||||
mock_name = "MockPoutPoutFish"
|
||||
|
||||
output = []
|
||||
expected = [ "void #{mock_name}_Init(void);\n",
|
||||
"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
|
||||
|
||||
it "append the proper footer to the header file" do
|
||||
output = []
|
||||
expected = ["\n",
|
||||
"#if defined(__GNUC__) && !defined(__ICC) && !defined(__TMS470__)\n",
|
||||
"#if __GNUC__ > 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ > 6 || (__GNUC_MINOR__ == 6 && __GNUC_PATCHLEVEL__ > 0)))\n",
|
||||
"#pragma GCC diagnostic pop\n",
|
||||
"#endif\n",
|
||||
"#endif\n",
|
||||
"\n",
|
||||
"#endif\n"
|
||||
]
|
||||
|
||||
@cmock_generator.create_mock_header_footer(output)
|
||||
|
||||
assert_equal(expected, output)
|
||||
end
|
||||
|
||||
it "create a proper heading for a source file" do
|
||||
output = []
|
||||
functions = [ { :name => "uno", :args => [ { :name => "arg1" }, { :name => "arg2" } ] },
|
||||
{ :name => "dos", :args => [ { :name => "arg3" }, { :name => "arg2" } ] },
|
||||
{ :name => "tres", :args => [] }
|
||||
]
|
||||
expected = [ "/* AUTOGENERATED FILE. DO NOT EDIT. */\n",
|
||||
"#include <string.h>\n",
|
||||
"#include <stdlib.h>\n",
|
||||
"#include <setjmp.h>\n",
|
||||
"#include \"cmock.h\"\n",
|
||||
"#include \"MockPoutPoutFish.h\"\n",
|
||||
"\n",
|
||||
"static const char* CMockString_arg1 = \"arg1\";\n",
|
||||
"static const char* CMockString_arg2 = \"arg2\";\n",
|
||||
"static const char* CMockString_arg3 = \"arg3\";\n",
|
||||
"static const char* CMockString_dos = \"dos\";\n",
|
||||
"static const char* CMockString_tres = \"tres\";\n",
|
||||
"static const char* CMockString_uno = \"uno\";\n",
|
||||
"\n"
|
||||
]
|
||||
|
||||
@cmock_generator.create_source_header_section(output, "MockPoutPoutFish.c", functions)
|
||||
|
||||
assert_equal(expected, output)
|
||||
end
|
||||
|
||||
it "create the instance structure where it is needed when no functions" do
|
||||
output = []
|
||||
functions = []
|
||||
expected = [ "static struct MockPoutPoutFishInstance\n",
|
||||
"{\n",
|
||||
" unsigned char placeHolder;\n",
|
||||
"} Mock;\n\n"
|
||||
].join
|
||||
|
||||
@cmock_generator.create_instance_structure(output, functions)
|
||||
|
||||
assert_equal(expected, output.join)
|
||||
end
|
||||
|
||||
it "create the instance structure where it is needed when functions required" do
|
||||
output = []
|
||||
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",
|
||||
" UNITY_LINE_TYPE LineNumber;\n",
|
||||
" b1 b2",
|
||||
"\n} CMOCK_First_CALL_INSTANCE;\n\n",
|
||||
"typedef struct _CMOCK_Second_CALL_INSTANCE\n{\n",
|
||||
" UNITY_LINE_TYPE LineNumber;\n",
|
||||
"\n} CMOCK_Second_CALL_INSTANCE;\n\n",
|
||||
"static struct MockPoutPoutFishInstance\n{\n",
|
||||
" d1",
|
||||
" CMOCK_MEM_INDEX_TYPE First_CallInstance;\n",
|
||||
" e1 e2 e3",
|
||||
" CMOCK_MEM_INDEX_TYPE Second_CallInstance;\n",
|
||||
"} Mock;\n\n"
|
||||
].join
|
||||
@plugins.expect :run, [" b1"," b2"], [:instance_typedefs, functions[0]]
|
||||
@plugins.expect :run, [], [:instance_typedefs, functions[1]]
|
||||
|
||||
@plugins.expect :run, [" d1"], [:instance_structure, functions[0]]
|
||||
@plugins.expect :run, [" e1"," e2"," e3"], [:instance_structure, functions[1]]
|
||||
|
||||
@cmock_generator.create_instance_structure(output, functions)
|
||||
|
||||
assert_equal(expected, output.join)
|
||||
end
|
||||
|
||||
it "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
|
||||
|
||||
it "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
|
||||
|
||||
it "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
|
||||
|
||||
it "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] }
|
||||
]
|
||||
output = []
|
||||
expected = [ "void MockPoutPoutFish_Verify(void)\n{\n",
|
||||
" UNITY_LINE_TYPE cmock_line = TEST_LINE_NUM;\n",
|
||||
" CMOCK_MEM_INDEX_TYPE call_instance;\n",
|
||||
" call_instance = Mock.First_CallInstance;\n" +
|
||||
" Uno_First" +
|
||||
" Dos_First" +
|
||||
" call_instance = Mock.Second_CallInstance;\n" +
|
||||
" Uno_Second" +
|
||||
" Dos_Second",
|
||||
"}\n\n"
|
||||
]
|
||||
@plugins.expect :run, [" Uno_First"," Dos_First"], [:mock_verify, functions[0]]
|
||||
@plugins.expect :run, [" Uno_Second"," Dos_Second"], [:mock_verify, functions[1]]
|
||||
|
||||
@cmock_generator.ordered = true
|
||||
@cmock_generator.create_mock_verify_function(output, functions)
|
||||
|
||||
assert_equal(expected, output.flatten)
|
||||
end
|
||||
|
||||
it "create mock init functions in source file" do
|
||||
output = []
|
||||
expected = [ "void MockPoutPoutFish_Init(void)\n{\n",
|
||||
" MockPoutPoutFish_Destroy();\n",
|
||||
"}\n\n"
|
||||
]
|
||||
|
||||
@cmock_generator.create_mock_init_function(output)
|
||||
|
||||
assert_equal(expected.join, output.join)
|
||||
end
|
||||
|
||||
it "create mock destroy functions in source file" do
|
||||
functions = []
|
||||
output = []
|
||||
expected = [ "void MockPoutPoutFish_Destroy(void)\n{\n",
|
||||
" CMock_Guts_MemFreeAll();\n",
|
||||
" memset(&Mock, 0, sizeof(Mock));\n",
|
||||
"}\n\n"
|
||||
]
|
||||
|
||||
@cmock_generator.create_mock_destroy_function(output, functions)
|
||||
|
||||
assert_equal(expected.join, output.join)
|
||||
end
|
||||
|
||||
it "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] }
|
||||
]
|
||||
output = []
|
||||
expected = [ "void MockPoutPoutFish_Destroy(void)\n{\n",
|
||||
" CMock_Guts_MemFreeAll();\n",
|
||||
" memset(&Mock, 0, sizeof(Mock));\n",
|
||||
" uno",
|
||||
" GlobalExpectCount = 0;\n",
|
||||
" GlobalVerifyOrder = 0;\n",
|
||||
"}\n\n"
|
||||
]
|
||||
@plugins.expect :run, [], [:mock_destroy, functions[0]]
|
||||
@plugins.expect :run, [" uno"], [:mock_destroy, functions[1]]
|
||||
|
||||
@cmock_generator_strict.create_mock_destroy_function(output, functions)
|
||||
|
||||
assert_equal(expected.join, output.join)
|
||||
end
|
||||
|
||||
it "create mock implementation functions in source file" do
|
||||
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",
|
||||
:unscoped_name => "SupaFunction",
|
||||
:namespace => [],
|
||||
:class => nil,
|
||||
:attributes => "__inline"
|
||||
}
|
||||
output = []
|
||||
expected = [ "static int SupaFunction(uint32 sandwiches, const char* named)\n",
|
||||
"{\n",
|
||||
" UNITY_LINE_TYPE cmock_line = TEST_LINE_NUM;\n",
|
||||
" CMOCK_SupaFunction_CALL_INSTANCE* cmock_call_instance;\n",
|
||||
" UNITY_SET_DETAIL(CMockString_SupaFunction);\n",
|
||||
" 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",
|
||||
" UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringCalledMore);\n",
|
||||
" cmock_line = cmock_call_instance->LineNumber;\n",
|
||||
" dos",
|
||||
" tres",
|
||||
" UNITY_CLR_DETAILS();\n",
|
||||
" return cmock_call_instance->ReturnVal;\n",
|
||||
"}\n\n"
|
||||
]
|
||||
@plugins.expect :run, [" uno"], [:mock_implementation_precheck, function]
|
||||
@plugins.expect :run, [" dos"," tres"], [:mock_implementation, function]
|
||||
|
||||
@cmock_generator.create_mock_implementation(output, function)
|
||||
|
||||
assert_equal(expected.join, output.join)
|
||||
end
|
||||
|
||||
it "create mock implementation functions in source file with different options" do
|
||||
function = { :modifier => "",
|
||||
:c_calling_convention => "__stdcall",
|
||||
:return => test_return[:int],
|
||||
:args_string => "uint32 sandwiches",
|
||||
:args => ["uint32 sandwiches"],
|
||||
:var_arg => "corn ...",
|
||||
:name => "SupaFunction",
|
||||
:unscoped_name => "SupaFunction",
|
||||
:namespace => [],
|
||||
:class => nil,
|
||||
:attributes => nil
|
||||
}
|
||||
output = []
|
||||
expected = [ "int __stdcall SupaFunction(uint32 sandwiches, corn ...)\n",
|
||||
"{\n",
|
||||
" UNITY_LINE_TYPE cmock_line = TEST_LINE_NUM;\n",
|
||||
" CMOCK_SupaFunction_CALL_INSTANCE* cmock_call_instance;\n",
|
||||
" UNITY_SET_DETAIL(CMockString_SupaFunction);\n",
|
||||
" 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",
|
||||
" UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringCalledMore);\n",
|
||||
" cmock_line = cmock_call_instance->LineNumber;\n",
|
||||
" dos",
|
||||
" tres",
|
||||
" UNITY_CLR_DETAILS();\n",
|
||||
" return cmock_call_instance->ReturnVal;\n",
|
||||
"}\n\n"
|
||||
]
|
||||
@plugins.expect :run, [" uno"], [:mock_implementation_precheck, function]
|
||||
@plugins.expect :run, [" dos"," tres"], [:mock_implementation, function]
|
||||
|
||||
@cmock_generator.create_mock_implementation(output, function)
|
||||
|
||||
assert_equal(expected.join, output.join)
|
||||
end
|
||||
|
||||
it "create mock implementation function in source file for C++ static member" do
|
||||
function = { :modifier => "static",
|
||||
:return => test_return[:int],
|
||||
:args_string => "uint32 sandwiches, const char* named",
|
||||
:args => ["uint32 sandwiches", "const char* named"],
|
||||
:var_arg => nil,
|
||||
:unscoped_name => "SupaFunction",
|
||||
:namespace => ["ns1", "ns2"],
|
||||
:class => "SupaClass",
|
||||
:name => "ns1_ns2_SupaClass_SupaFunction",
|
||||
:attributes => nil
|
||||
}
|
||||
output = []
|
||||
expected = [ "namespace ns1 {\n",
|
||||
"namespace ns2 {\n",
|
||||
"static int SupaClass::SupaFunction(uint32 sandwiches, const char* named)\n",
|
||||
"{\n",
|
||||
" UNITY_LINE_TYPE cmock_line = TEST_LINE_NUM;\n",
|
||||
" CMOCK_ns1_ns2_SupaClass_SupaFunction_CALL_INSTANCE* cmock_call_instance;\n",
|
||||
" UNITY_SET_DETAIL(CMockString_ns1_ns2_SupaClass_SupaFunction);\n",
|
||||
" cmock_call_instance = (CMOCK_ns1_ns2_SupaClass_SupaFunction_CALL_INSTANCE*)CMock_Guts_GetAddressFor(Mock.ns1_ns2_SupaClass_SupaFunction_CallInstance);\n",
|
||||
" Mock.ns1_ns2_SupaClass_SupaFunction_CallInstance = CMock_Guts_MemNext(Mock.ns1_ns2_SupaClass_SupaFunction_CallInstance);\n",
|
||||
" uno",
|
||||
" UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringCalledMore);\n",
|
||||
" cmock_line = cmock_call_instance->LineNumber;\n",
|
||||
" dos",
|
||||
" tres",
|
||||
" UNITY_CLR_DETAILS();\n",
|
||||
" return cmock_call_instance->ReturnVal;\n",
|
||||
"}\n",
|
||||
"}\n",
|
||||
"}\n\n",
|
||||
]
|
||||
@plugins.expect :run, [" uno"], [:mock_implementation_precheck, function]
|
||||
@plugins.expect :run, [" dos"," tres"], [:mock_implementation, function]
|
||||
|
||||
@cmock_generator.create_mock_implementation(output, function)
|
||||
|
||||
assert_equal(expected.join, output.join)
|
||||
end
|
||||
|
||||
it "create mock implementation functions in source file with different options for C++ static member" do
|
||||
function = { :modifier => "static",
|
||||
:c_calling_convention => "__stdcall",
|
||||
:return => test_return[:int],
|
||||
:args_string => "uint32 sandwiches",
|
||||
:args => ["uint32 sandwiches"],
|
||||
:var_arg => "corn ...",
|
||||
:name => "SupaClass_SupaFunction",
|
||||
:unscoped_name => "SupaFunction",
|
||||
:namespace => [],
|
||||
:class => "SupaClass",
|
||||
:attributes => nil
|
||||
}
|
||||
output = []
|
||||
expected = [ "static int __stdcall SupaClass::SupaFunction(uint32 sandwiches, corn ...)\n",
|
||||
"{\n",
|
||||
" UNITY_LINE_TYPE cmock_line = TEST_LINE_NUM;\n",
|
||||
" CMOCK_SupaClass_SupaFunction_CALL_INSTANCE* cmock_call_instance;\n",
|
||||
" UNITY_SET_DETAIL(CMockString_SupaClass_SupaFunction);\n",
|
||||
" cmock_call_instance = (CMOCK_SupaClass_SupaFunction_CALL_INSTANCE*)CMock_Guts_GetAddressFor(Mock.SupaClass_SupaFunction_CallInstance);\n",
|
||||
" Mock.SupaClass_SupaFunction_CallInstance = CMock_Guts_MemNext(Mock.SupaClass_SupaFunction_CallInstance);\n",
|
||||
" uno",
|
||||
" UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringCalledMore);\n",
|
||||
" cmock_line = cmock_call_instance->LineNumber;\n",
|
||||
" dos",
|
||||
" tres",
|
||||
" UNITY_CLR_DETAILS();\n",
|
||||
" return cmock_call_instance->ReturnVal;\n",
|
||||
"}\n\n"
|
||||
]
|
||||
@plugins.expect :run, [" uno"], [:mock_implementation_precheck, function]
|
||||
@plugins.expect :run, [" dos"," tres"], [:mock_implementation, function]
|
||||
|
||||
@cmock_generator.create_mock_implementation(output, function)
|
||||
|
||||
assert_equal(expected.join, output.join)
|
||||
end
|
||||
|
||||
it "creates using statements for C++ static member in namespace" do
|
||||
function = { :modifier => "static",
|
||||
:return => test_return[:int],
|
||||
:args_string => "uint32 sandwiches",
|
||||
:args => ["uint32 sandwiches"],
|
||||
:var_arg => nil,
|
||||
:unscoped_name => "SupaFunction",
|
||||
:namespace => ["ns1"],
|
||||
:class => "SupaClass",
|
||||
:name => "ns1_SupaClass_SupaFunction",
|
||||
:attributes => nil
|
||||
}
|
||||
output = []
|
||||
expected = "using namespace ns1;\n"
|
||||
|
||||
@cmock_generator.create_using_statement(output, function)
|
||||
|
||||
assert_equal(expected, output.join)
|
||||
end
|
||||
|
||||
it "creates using statements for C++ static member in nested namespace" do
|
||||
function = { :modifier => "static",
|
||||
:return => test_return[:int],
|
||||
:args_string => "uint32 sandwiches",
|
||||
:args => ["uint32 sandwiches"],
|
||||
:var_arg => nil,
|
||||
:unscoped_name => "SupaFunction",
|
||||
:namespace => ["ns1", "ns2"],
|
||||
:class => "SupaClass",
|
||||
:name => "ns1_ns2_SupaClass_SupaFunction",
|
||||
:attributes => nil
|
||||
}
|
||||
output = []
|
||||
expected = "using namespace ns1::ns2;\n"
|
||||
|
||||
@cmock_generator.create_using_statement(output, function)
|
||||
|
||||
assert_equal(expected, output.join)
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,141 @@
|
||||
# ==========================================
|
||||
# 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]
|
||||
# ==========================================
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
|
||||
require File.expand_path(File.dirname(__FILE__)) + '/../../lib/cmock_generator_plugin_array'
|
||||
require File.expand_path(File.dirname(__FILE__)) + '/../../lib/cmock_generator_utils'
|
||||
|
||||
class UtilsStub
|
||||
def helpers
|
||||
{}
|
||||
end
|
||||
def arg_type_with_const(arg)
|
||||
CMockGeneratorUtils.arg_type_with_const(arg)
|
||||
end
|
||||
def code_add_base_expectation(func)
|
||||
"mock_retval_0"
|
||||
end
|
||||
end
|
||||
|
||||
describe CMockGeneratorPluginArray, "Verify CMockPGeneratorluginArray Module" do
|
||||
before do
|
||||
#no strict ordering
|
||||
@config = create_stub(
|
||||
:when_ptr => :compare_data,
|
||||
:enforce_strict_ordering => false,
|
||||
:respond_to? => true )
|
||||
|
||||
@utils = UtilsStub.new
|
||||
|
||||
@cmock_generator_plugin_array = CMockGeneratorPluginArray.new(@config, @utils)
|
||||
end
|
||||
|
||||
after do
|
||||
end
|
||||
|
||||
it "have set up internal priority" do
|
||||
assert_nil(@cmock_generator_plugin_array.unity_helper)
|
||||
assert_equal(8, @cmock_generator_plugin_array.priority)
|
||||
end
|
||||
|
||||
it "not include any additional include files" do
|
||||
assert(!@cmock_generator_plugin_array.respond_to?(:include_files))
|
||||
end
|
||||
|
||||
it "not add to typedef structure for functions of style 'int* func(void)'" do
|
||||
function = {:name => "Oak", :args => [], :return => test_return[:int_ptr]}
|
||||
returned = @cmock_generator_plugin_array.instance_typedefs(function)
|
||||
assert_equal("", returned)
|
||||
end
|
||||
|
||||
it "add to tyepdef structure mock needs of functions of style 'void func(int chicken, int* pork)'" do
|
||||
function = {:name => "Cedar", :args => [{ :name => "chicken", :type => "int", :ptr? => false}, { :name => "pork", :type => "int*", :ptr? => true}], :return => test_return[:void]}
|
||||
expected = " int Expected_pork_Depth;\n"
|
||||
returned = @cmock_generator_plugin_array.instance_typedefs(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "not add an additional mock interface for functions not containing pointers" do
|
||||
function = {:name => "Maple", :args_string => "int blah", :return => test_return[:string], :contains_ptr? => false}
|
||||
returned = @cmock_generator_plugin_array.mock_function_declarations(function)
|
||||
assert_nil(returned)
|
||||
end
|
||||
|
||||
it "add another mock function declaration for functions of style 'void func(int* tofu)'" do
|
||||
function = {:name => "Pine",
|
||||
:args => [{ :type => "int*",
|
||||
:name => "tofu",
|
||||
:ptr? => true,
|
||||
}],
|
||||
:return => test_return[:void],
|
||||
:contains_ptr? => true }
|
||||
|
||||
expected = "#define #{function[:name]}_ExpectWithArray(tofu, tofu_Depth) #{function[:name]}_CMockExpectWithArray(__LINE__, tofu, tofu_Depth)\n" +
|
||||
"void #{function[:name]}_CMockExpectWithArray(UNITY_LINE_TYPE cmock_line, int* tofu, int tofu_Depth);\n"
|
||||
returned = @cmock_generator_plugin_array.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add another mock function declaration for functions of style 'const char* func(int* tofu)'" do
|
||||
function = {:name => "Pine",
|
||||
:args => [{ :type => "int*",
|
||||
:name => "tofu",
|
||||
:ptr? => true,
|
||||
}],
|
||||
:return => test_return[:string],
|
||||
:contains_ptr? => true }
|
||||
|
||||
expected = "#define #{function[:name]}_ExpectWithArrayAndReturn(tofu, tofu_Depth, cmock_retval) #{function[:name]}_CMockExpectWithArrayAndReturn(__LINE__, tofu, tofu_Depth, cmock_retval)\n" +
|
||||
"void #{function[:name]}_CMockExpectWithArrayAndReturn(UNITY_LINE_TYPE cmock_line, int* tofu, int tofu_Depth, const char* cmock_to_return);\n"
|
||||
returned = @cmock_generator_plugin_array.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add another mock function declaration for functions of style 'const char* func(const int* tofu)'" do
|
||||
function = {:name => "Pine",
|
||||
:args => [{ :type => "const int*",
|
||||
:name => "tofu",
|
||||
:ptr? => true,
|
||||
:const? => true,
|
||||
}],
|
||||
:return => test_return[:string],
|
||||
:contains_ptr? => true }
|
||||
|
||||
expected = "#define #{function[:name]}_ExpectWithArrayAndReturn(tofu, tofu_Depth, cmock_retval) #{function[:name]}_CMockExpectWithArrayAndReturn(__LINE__, tofu, tofu_Depth, cmock_retval)\n" +
|
||||
"void #{function[:name]}_CMockExpectWithArrayAndReturn(UNITY_LINE_TYPE cmock_line, const int* tofu, int tofu_Depth, const char* cmock_to_return);\n"
|
||||
returned = @cmock_generator_plugin_array.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "not have a mock function implementation" do
|
||||
assert(!@cmock_generator_plugin_array.respond_to?(:mock_implementation))
|
||||
end
|
||||
|
||||
it "not have a mock interfaces for functions of style 'int* func(void)'" do
|
||||
function = {:name => "Pear", :args => [], :args_string => "void", :return => test_return[:int_ptr]}
|
||||
returned = @cmock_generator_plugin_array.mock_interfaces(function)
|
||||
assert_nil(returned)
|
||||
end
|
||||
|
||||
it "add mock interfaces for functions of style 'int* func(int* pescado, int pes)'" do
|
||||
function = {:name => "Lemon",
|
||||
:args => [{ :type => "int*", :name => "pescado", :ptr? => true}, { :type => "int", :name => "pes", :ptr? => false}],
|
||||
:args_string => "int* pescado, int pes",
|
||||
:return => test_return[:int_ptr],
|
||||
:contains_ptr? => true }
|
||||
|
||||
expected = ["void Lemon_CMockExpectWithArrayAndReturn(UNITY_LINE_TYPE cmock_line, int* pescado, int pescado_Depth, int pes, int* cmock_to_return)\n",
|
||||
"{\n",
|
||||
"mock_retval_0",
|
||||
" CMockExpectParameters_Lemon(cmock_call_instance, pescado, pescado_Depth, pes);\n",
|
||||
" cmock_call_instance->ReturnVal = cmock_to_return;\n",
|
||||
"}\n\n"
|
||||
].join
|
||||
returned = @cmock_generator_plugin_array.mock_interfaces(function).join
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
end
|
||||
@ -0,0 +1,281 @@
|
||||
# ==========================================
|
||||
# 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]
|
||||
# ==========================================
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
|
||||
require File.expand_path(File.dirname(__FILE__)) + '/../../lib/cmock_generator_plugin_callback'
|
||||
|
||||
describe CMockGeneratorPluginCallback, "Verify CMockGeneratorPluginCallback Module" do
|
||||
|
||||
before do
|
||||
create_mocks :config, :utils
|
||||
|
||||
@config.expect :callback_include_count, true
|
||||
@config.expect :callback_after_arg_check, false
|
||||
@config.expect :plugins, [:ignore]
|
||||
|
||||
@cmock_generator_plugin_callback = CMockGeneratorPluginCallback.new(@config, @utils)
|
||||
end
|
||||
|
||||
after do
|
||||
end
|
||||
|
||||
it "have set up internal priority" do
|
||||
assert_equal(6, @cmock_generator_plugin_callback.priority)
|
||||
end
|
||||
|
||||
it "not include any additional include files" do
|
||||
assert(!@cmock_generator_plugin_callback.respond_to?(:include_files))
|
||||
end
|
||||
|
||||
it "add to instance structure" do
|
||||
function = {:name => "Oak", :args => [:type => "int*", :name => "blah", :ptr? => true], :return => test_return[:int_ptr]}
|
||||
expected = " char Oak_CallbackBool;\n" +
|
||||
" CMOCK_Oak_CALLBACK Oak_CallbackFunctionPointer;\n" +
|
||||
" int Oak_CallbackCalls;\n"
|
||||
returned = @cmock_generator_plugin_callback.instance_structure(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock function declaration for function without arguments" do
|
||||
function = {:name => "Maple", :args_string => "void", :args => [], :return => test_return[:void]}
|
||||
expected = [ "typedef void (* CMOCK_Maple_CALLBACK)(int cmock_num_calls);\n",
|
||||
"void Maple_AddCallback(CMOCK_Maple_CALLBACK Callback);\n",
|
||||
"void Maple_Stub(CMOCK_Maple_CALLBACK Callback);\n",
|
||||
"#define Maple_StubWithCallback Maple_Stub\n" ].join
|
||||
returned = @cmock_generator_plugin_callback.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock function declaration for function without arguments when count is also turned off" do
|
||||
function = {:name => "Maple", :args_string => "void", :args => [], :return => test_return[:void]}
|
||||
expected = [ "typedef void (* CMOCK_Maple_CALLBACK)(void);\n",
|
||||
"void Maple_AddCallback(CMOCK_Maple_CALLBACK Callback);\n",
|
||||
"void Maple_Stub(CMOCK_Maple_CALLBACK Callback);\n",
|
||||
"#define Maple_StubWithCallback Maple_Stub\n" ].join
|
||||
@cmock_generator_plugin_callback.include_count = false
|
||||
returned = @cmock_generator_plugin_callback.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock function declaration for function with arguments" do
|
||||
function = {:name => "Maple", :args_string => "int* tofu", :args => [1], :return => test_return[:void]}
|
||||
expected = [ "typedef void (* CMOCK_Maple_CALLBACK)(int* tofu, int cmock_num_calls);\n",
|
||||
"void Maple_AddCallback(CMOCK_Maple_CALLBACK Callback);\n",
|
||||
"void Maple_Stub(CMOCK_Maple_CALLBACK Callback);\n",
|
||||
"#define Maple_StubWithCallback Maple_Stub\n" ].join
|
||||
returned = @cmock_generator_plugin_callback.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock function declaration for function with return values" do
|
||||
function = {:name => "Maple", :args_string => "int* tofu", :args => [1], :return => test_return[:string]}
|
||||
expected = [ "typedef const char* (* CMOCK_Maple_CALLBACK)(int* tofu, int cmock_num_calls);\n",
|
||||
"void Maple_AddCallback(CMOCK_Maple_CALLBACK Callback);\n",
|
||||
"void Maple_Stub(CMOCK_Maple_CALLBACK Callback);\n",
|
||||
"#define Maple_StubWithCallback Maple_Stub\n" ].join
|
||||
returned = @cmock_generator_plugin_callback.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock function declaration for function with return values and count is turned off" do
|
||||
function = {:name => "Maple", :args_string => "int* tofu", :args => [1], :return => test_return[:string]}
|
||||
expected = [ "typedef const char* (* CMOCK_Maple_CALLBACK)(int* tofu);\n",
|
||||
"void Maple_AddCallback(CMOCK_Maple_CALLBACK Callback);\n",
|
||||
"void Maple_Stub(CMOCK_Maple_CALLBACK Callback);\n",
|
||||
"#define Maple_StubWithCallback Maple_Stub\n" ].join
|
||||
@cmock_generator_plugin_callback.include_count = false
|
||||
returned = @cmock_generator_plugin_callback.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock function implementation for functions with no arg check and of style 'void func(void)'" do
|
||||
function = {:name => "Apple", :args => [], :args_string => "void", :return => test_return[:void]}
|
||||
expected = [" if (Mock.Apple_CallbackFunctionPointer != NULL)\n",
|
||||
" {\n",
|
||||
" Mock.Apple_CallbackFunctionPointer(Mock.Apple_CallbackCalls++);\n",
|
||||
" }\n"
|
||||
].join
|
||||
returned = @cmock_generator_plugin_callback.mock_implementation(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock function implementation for functions with no arg check and of style 'void func(void)' when count turned off" do
|
||||
function = {:name => "Apple", :args => [], :args_string => "void", :return => test_return[:void]}
|
||||
expected = [" if (Mock.Apple_CallbackFunctionPointer != NULL)\n",
|
||||
" {\n",
|
||||
" Mock.Apple_CallbackFunctionPointer();\n",
|
||||
" }\n"
|
||||
].join
|
||||
@cmock_generator_plugin_callback.include_count = false
|
||||
returned = @cmock_generator_plugin_callback.mock_implementation(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock function implementation for functions with no arg check and of style 'int func(void)'" do
|
||||
function = {:name => "Apple", :args => [], :args_string => "void", :return => test_return[:int]}
|
||||
expected = [" if (Mock.Apple_CallbackFunctionPointer != NULL)\n",
|
||||
" {\n",
|
||||
" cmock_call_instance->ReturnVal = Mock.Apple_CallbackFunctionPointer(Mock.Apple_CallbackCalls++);\n",
|
||||
" }\n"
|
||||
].join
|
||||
returned = @cmock_generator_plugin_callback.mock_implementation(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock function implementation for functions with no arg check and of style 'void func(int* steak, uint8_t flag)'" do
|
||||
function = {:name => "Apple",
|
||||
:args => [ { :type => 'int*', :name => 'steak', :ptr? => true},
|
||||
{ :type => 'uint8_t', :name => 'flag', :ptr? => false} ],
|
||||
:args_string => "int* steak, uint8_t flag",
|
||||
:return=> test_return[:void]}
|
||||
expected = [" if (Mock.Apple_CallbackFunctionPointer != NULL)\n",
|
||||
" {\n",
|
||||
" Mock.Apple_CallbackFunctionPointer(steak, flag, Mock.Apple_CallbackCalls++);\n",
|
||||
" }\n"
|
||||
].join
|
||||
returned = @cmock_generator_plugin_callback.mock_implementation(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock function implementation for functions with no arg check and of style 'void func(int* steak, uint8_t flag)' when count turned off" do
|
||||
function = {:name => "Apple",
|
||||
:args => [ { :type => 'int*', :name => 'steak', :ptr? => true},
|
||||
{ :type => 'uint8_t', :name => 'flag', :ptr? => false} ],
|
||||
:args_string => "int* steak, uint8_t flag",
|
||||
:return=> test_return[:void]}
|
||||
expected = [" if (Mock.Apple_CallbackFunctionPointer != NULL)\n",
|
||||
" {\n",
|
||||
" Mock.Apple_CallbackFunctionPointer(steak, flag);\n",
|
||||
" }\n"
|
||||
].join
|
||||
@cmock_generator_plugin_callback.include_count = false
|
||||
returned = @cmock_generator_plugin_callback.mock_implementation(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock function implementation for functions with no arg check and of style 'int16_t func(int* steak, uint8_t flag)'" do
|
||||
function = {:name => "Apple",
|
||||
:args => [ { :type => 'int*', :name => 'steak', :ptr? => true},
|
||||
{ :type => 'uint8_t', :name => 'flag', :ptr? => false} ],
|
||||
:args_string => "int* steak, uint8_t flag",
|
||||
:return => test_return[:int]}
|
||||
expected = [" if (Mock.Apple_CallbackFunctionPointer != NULL)\n",
|
||||
" {\n",
|
||||
" cmock_call_instance->ReturnVal = Mock.Apple_CallbackFunctionPointer(steak, flag, Mock.Apple_CallbackCalls++);\n",
|
||||
" }\n"
|
||||
].join
|
||||
returned = @cmock_generator_plugin_callback.mock_implementation(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock function implementation for functions without arg check and of style 'void func(void)' when count turned off" do
|
||||
function = {:name => "Apple", :args => [], :args_string => "void", :return => test_return[:void]}
|
||||
expected = [" if (!Mock.Apple_CallbackBool &&\n",
|
||||
" Mock.Apple_CallbackFunctionPointer != NULL)\n",
|
||||
" {\n",
|
||||
" Mock.Apple_CallbackFunctionPointer();\n",
|
||||
" UNITY_CLR_DETAILS();\n",
|
||||
" return;\n",
|
||||
" }\n"
|
||||
].join
|
||||
@cmock_generator_plugin_callback.include_count = false
|
||||
returned = @cmock_generator_plugin_callback.mock_implementation_precheck(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock function implementation for functions without arg check and of style 'int func(void)'" do
|
||||
function = {:name => "Apple", :args => [], :args_string => "void", :return => test_return[:int]}
|
||||
expected = [" if (!Mock.Apple_CallbackBool &&\n",
|
||||
" Mock.Apple_CallbackFunctionPointer != NULL)\n",
|
||||
" {\n",
|
||||
" int cmock_cb_ret = Mock.Apple_CallbackFunctionPointer(Mock.Apple_CallbackCalls++);\n",
|
||||
" UNITY_CLR_DETAILS();\n",
|
||||
" return cmock_cb_ret;\n",
|
||||
" }\n"
|
||||
].join
|
||||
returned = @cmock_generator_plugin_callback.mock_implementation_precheck(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock function implementation for functions without arg check and of style 'void func(int* steak, uint8_t flag)'" do
|
||||
function = {:name => "Apple",
|
||||
:args => [ { :type => 'int*', :name => 'steak', :ptr? => true},
|
||||
{ :type => 'uint8_t', :name => 'flag', :ptr? => false} ],
|
||||
:args_string => "int* steak, uint8_t flag",
|
||||
:return=> test_return[:void]}
|
||||
expected = [" if (!Mock.Apple_CallbackBool &&\n",
|
||||
" Mock.Apple_CallbackFunctionPointer != NULL)\n",
|
||||
" {\n",
|
||||
" Mock.Apple_CallbackFunctionPointer(steak, flag, Mock.Apple_CallbackCalls++);\n",
|
||||
" UNITY_CLR_DETAILS();\n",
|
||||
" return;\n",
|
||||
" }\n"
|
||||
].join
|
||||
returned = @cmock_generator_plugin_callback.mock_implementation_precheck(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock function implementation for functions without arg check and of style 'void func(int* steak, uint8_t flag)' when count turned off" do
|
||||
function = {:name => "Apple",
|
||||
:args => [ { :type => 'int*', :name => 'steak', :ptr? => true},
|
||||
{ :type => 'uint8_t', :name => 'flag', :ptr? => false} ],
|
||||
:args_string => "int* steak, uint8_t flag",
|
||||
:return=> test_return[:void]}
|
||||
expected = [" if (!Mock.Apple_CallbackBool &&\n",
|
||||
" Mock.Apple_CallbackFunctionPointer != NULL)\n",
|
||||
" {\n",
|
||||
" Mock.Apple_CallbackFunctionPointer(steak, flag);\n",
|
||||
" UNITY_CLR_DETAILS();\n",
|
||||
" return;\n",
|
||||
" }\n"
|
||||
].join
|
||||
@cmock_generator_plugin_callback.include_count = false
|
||||
returned = @cmock_generator_plugin_callback.mock_implementation_precheck(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock function implementation for functions without arg check and of style 'int16_t func(int* steak, uint8_t flag)'" do
|
||||
function = {:name => "Apple",
|
||||
:args => [ { :type => 'int*', :name => 'steak', :ptr? => true},
|
||||
{ :type => 'uint8_t', :name => 'flag', :ptr? => false} ],
|
||||
:args_string => "int* steak, uint8_t flag",
|
||||
:return => test_return[:int]}
|
||||
expected = [" if (!Mock.Apple_CallbackBool &&\n",
|
||||
" Mock.Apple_CallbackFunctionPointer != NULL)\n",
|
||||
" {\n",
|
||||
" int cmock_cb_ret = Mock.Apple_CallbackFunctionPointer(steak, flag, Mock.Apple_CallbackCalls++);\n",
|
||||
" UNITY_CLR_DETAILS();\n",
|
||||
" return cmock_cb_ret;\n",
|
||||
" }\n"
|
||||
].join
|
||||
returned = @cmock_generator_plugin_callback.mock_implementation_precheck(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock interfaces for functions " do
|
||||
function = {:name => "Lemon",
|
||||
:args => [{ :type => "char*", :name => "pescado"}],
|
||||
:args_string => "char* pescado",
|
||||
:return => test_return[:int]
|
||||
}
|
||||
|
||||
expected = ["void Lemon_AddCallback(CMOCK_Lemon_CALLBACK Callback)\n",
|
||||
"{\n",
|
||||
" Mock.Lemon_IgnoreBool = (char)0;\n",
|
||||
" Mock.Lemon_CallbackBool = (char)1;\n",
|
||||
" Mock.Lemon_CallbackFunctionPointer = Callback;\n",
|
||||
"}\n\n",
|
||||
"void Lemon_Stub(CMOCK_Lemon_CALLBACK Callback)\n",
|
||||
"{\n",
|
||||
" Mock.Lemon_IgnoreBool = (char)0;\n",
|
||||
" Mock.Lemon_CallbackBool = (char)0;\n",
|
||||
" Mock.Lemon_CallbackFunctionPointer = Callback;\n",
|
||||
"}\n\n"
|
||||
].join
|
||||
returned = @cmock_generator_plugin_callback.mock_interfaces(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,96 @@
|
||||
# ==========================================
|
||||
# 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]
|
||||
# ==========================================
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
|
||||
require File.expand_path(File.dirname(__FILE__)) + '/../../lib/cmock_generator_plugin_cexception'
|
||||
|
||||
describe CMockGeneratorPluginCexception, "Verify CMockGeneratorPluginCexception Module" do
|
||||
|
||||
before do
|
||||
create_mocks :config, :utils
|
||||
@cmock_generator_plugin_cexception = CMockGeneratorPluginCexception.new(@config, @utils)
|
||||
end
|
||||
|
||||
after do
|
||||
end
|
||||
|
||||
it "have set up internal priority" do
|
||||
assert_equal(7, @cmock_generator_plugin_cexception.priority)
|
||||
end
|
||||
|
||||
it "include the cexception library" do
|
||||
expected = "#include \"CException.h\"\n"
|
||||
returned = @cmock_generator_plugin_cexception.include_files
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add to typedef structure mock needs" do
|
||||
function = { :name => "Oak", :args => [], :return => test_return[:void] }
|
||||
expected = " CEXCEPTION_T ExceptionToThrow;\n"
|
||||
returned = @cmock_generator_plugin_cexception.instance_typedefs(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock function declarations for functions without arguments" do
|
||||
function = { :name => "Spruce", :args_string => "void", :return => test_return[:void] }
|
||||
expected = "#define Spruce_ExpectAndThrow(cmock_to_throw) Spruce_CMockExpectAndThrow(__LINE__, cmock_to_throw)\n"+
|
||||
"void Spruce_CMockExpectAndThrow(UNITY_LINE_TYPE cmock_line, CEXCEPTION_T cmock_to_throw);\n"
|
||||
returned = @cmock_generator_plugin_cexception.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock function declarations for functions with arguments" do
|
||||
function = { :name => "Spruce", :args_string => "const char* Petunia, uint32_t Lily", :args_call => "Petunia, Lily", :return => test_return[:void] }
|
||||
expected = "#define Spruce_ExpectAndThrow(Petunia, Lily, cmock_to_throw) Spruce_CMockExpectAndThrow(__LINE__, Petunia, Lily, cmock_to_throw)\n" +
|
||||
"void Spruce_CMockExpectAndThrow(UNITY_LINE_TYPE cmock_line, const char* Petunia, uint32_t Lily, CEXCEPTION_T cmock_to_throw);\n"
|
||||
returned = @cmock_generator_plugin_cexception.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add a mock implementation" do
|
||||
function = {:name => "Cherry", :args => [], :return => test_return[:void]}
|
||||
expected = " if (cmock_call_instance->ExceptionToThrow != CEXCEPTION_NONE)\n" +
|
||||
" {\n" +
|
||||
" UNITY_CLR_DETAILS();\n" +
|
||||
" Throw(cmock_call_instance->ExceptionToThrow);\n" +
|
||||
" }\n"
|
||||
returned = @cmock_generator_plugin_cexception.mock_implementation(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock interfaces for functions without arguments" do
|
||||
function = {:name => "Pear", :args_string => "void", :args => [], :return => test_return[:void]}
|
||||
@utils.expect :code_add_base_expectation, "mock_retval_0", ["Pear"]
|
||||
@utils.expect :code_call_argument_loader, "", [function]
|
||||
|
||||
expected = ["void Pear_CMockExpectAndThrow(UNITY_LINE_TYPE cmock_line, CEXCEPTION_T cmock_to_throw)\n",
|
||||
"{\n",
|
||||
"mock_retval_0",
|
||||
"",
|
||||
" cmock_call_instance->ExceptionToThrow = cmock_to_throw;\n",
|
||||
"}\n\n"
|
||||
].join
|
||||
returned = @cmock_generator_plugin_cexception.mock_interfaces(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add a mock interfaces for functions with arguments" do
|
||||
function = {:name => "Pear", :args_string => "int blah", :args => [{ :type => "int", :name => "blah" }], :return => test_return[:void]}
|
||||
@utils.expect :code_add_base_expectation, "mock_retval_0", ["Pear"]
|
||||
@utils.expect :code_call_argument_loader, "mock_return_1", [function]
|
||||
|
||||
expected = ["void Pear_CMockExpectAndThrow(UNITY_LINE_TYPE cmock_line, int blah, CEXCEPTION_T cmock_to_throw)\n",
|
||||
"{\n",
|
||||
"mock_retval_0",
|
||||
"mock_return_1",
|
||||
" cmock_call_instance->ExceptionToThrow = cmock_to_throw;\n",
|
||||
"}\n\n"
|
||||
].join
|
||||
returned = @cmock_generator_plugin_cexception.mock_interfaces(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
end
|
||||
@ -0,0 +1,185 @@
|
||||
# ==========================================
|
||||
# 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]
|
||||
# ==========================================
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
|
||||
require File.expand_path(File.dirname(__FILE__)) + '/../../lib/cmock_generator_plugin_expect'
|
||||
|
||||
describe CMockGeneratorPluginExpect, "Verify CMockGeneratorPluginExpect Module Without Global Ordering" do
|
||||
|
||||
before do
|
||||
create_mocks :config, :utils
|
||||
|
||||
@config = create_stub(
|
||||
:when_ptr => :compare_data,
|
||||
:enforce_strict_ordering => false,
|
||||
:respond_to? => true,
|
||||
:plugins => [ :expect ] )
|
||||
|
||||
@utils.expect :helpers, {}
|
||||
@cmock_generator_plugin_expect = CMockGeneratorPluginExpect.new(@config, @utils)
|
||||
end
|
||||
|
||||
after do
|
||||
end
|
||||
|
||||
it "have set up internal priority on init" do
|
||||
assert_nil(@cmock_generator_plugin_expect.unity_helper)
|
||||
assert_equal(5, @cmock_generator_plugin_expect.priority)
|
||||
end
|
||||
|
||||
it "not include any additional include files" do
|
||||
assert(!@cmock_generator_plugin_expect.respond_to?(:include_files))
|
||||
end
|
||||
|
||||
it "add to typedef structure mock needs of functions of style 'void func(void)'" do
|
||||
function = {:name => "Oak", :args => [], :return => test_return[:void]}
|
||||
expected = ""
|
||||
returned = @cmock_generator_plugin_expect.instance_typedefs(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add to typedef structure mock needs of functions of style 'int func(void)'" do
|
||||
function = {:name => "Elm", :args => [], :return => test_return[:int]}
|
||||
expected = " int ReturnVal;\n"
|
||||
returned = @cmock_generator_plugin_expect.instance_typedefs(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add to typedef structure mock needs of functions of style 'void func(int chicken, char* pork)'" do
|
||||
function = {:name => "Cedar", :args => [{ :name => "chicken", :type => "int"}, { :name => "pork", :type => "char*"}], :return => test_return[:void]}
|
||||
expected = " int Expected_chicken;\n char* Expected_pork;\n"
|
||||
returned = @cmock_generator_plugin_expect.instance_typedefs(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add to typedef structure mock needs of functions of style 'int func(float beef)'" do
|
||||
function = {:name => "Birch", :args => [{ :name => "beef", :type => "float"}], :return => test_return[:int]}
|
||||
expected = " int ReturnVal;\n float Expected_beef;\n"
|
||||
returned = @cmock_generator_plugin_expect.instance_typedefs(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock function declaration for functions of style 'void func(void)'" do
|
||||
function = {:name => "Maple", :args => [], :return => test_return[:void]}
|
||||
expected = "#define Maple_Expect() Maple_CMockExpect(__LINE__)\n" +
|
||||
"void Maple_CMockExpect(UNITY_LINE_TYPE cmock_line);\n"
|
||||
returned = @cmock_generator_plugin_expect.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock function declaration for functions of style 'int func(void)'" do
|
||||
function = {:name => "Spruce", :args => [], :return => test_return[:int]}
|
||||
expected = "#define Spruce_ExpectAndReturn(cmock_retval) Spruce_CMockExpectAndReturn(__LINE__, cmock_retval)\n" +
|
||||
"void Spruce_CMockExpectAndReturn(UNITY_LINE_TYPE cmock_line, int cmock_to_return);\n"
|
||||
returned = @cmock_generator_plugin_expect.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock function declaration for functions of style 'const char* func(int tofu)'" do
|
||||
function = {:name => "Pine", :args => ["int tofu"], :args_string => "int tofu", :args_call => 'tofu', :return => test_return[:string]}
|
||||
expected = "#define Pine_ExpectAndReturn(tofu, cmock_retval) Pine_CMockExpectAndReturn(__LINE__, tofu, cmock_retval)\n" +
|
||||
"void Pine_CMockExpectAndReturn(UNITY_LINE_TYPE cmock_line, int tofu, const char* cmock_to_return);\n"
|
||||
returned = @cmock_generator_plugin_expect.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock function implementation for functions of style 'void func(void)'" do
|
||||
function = {:name => "Apple", :args => [], :return => test_return[:void]}
|
||||
expected = ""
|
||||
returned = @cmock_generator_plugin_expect.mock_implementation(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock function implementation for functions of style 'int func(int veal, unsigned int sushi)'" do
|
||||
function = {:name => "Cherry", :args => [ { :type => "int", :name => "veal" }, { :type => "unsigned int", :name => "sushi" } ], :return => test_return[:int]}
|
||||
|
||||
@utils.expect :code_verify_an_arg_expectation, " mocked_retval_1", [function, function[:args][0]]
|
||||
@utils.expect :code_verify_an_arg_expectation, " mocked_retval_2", [function, function[:args][1]]
|
||||
expected = " mocked_retval_1 mocked_retval_2"
|
||||
returned = @cmock_generator_plugin_expect.mock_implementation(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock function implementation using ordering if needed" do
|
||||
function = {:name => "Apple", :args => [], :return => test_return[:void]}
|
||||
expected = ""
|
||||
@cmock_generator_plugin_expect.ordered = true
|
||||
returned = @cmock_generator_plugin_expect.mock_implementation(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock interfaces for functions of style 'void func(void)'" do
|
||||
function = {:name => "Pear", :args => [], :args_string => "void", :return => test_return[:void]}
|
||||
@utils.expect :code_add_base_expectation, "mock_retval_0 ", ["Pear"]
|
||||
@utils.expect :code_call_argument_loader, "mock_retval_1 ", [function]
|
||||
expected = ["void Pear_CMockExpect(UNITY_LINE_TYPE cmock_line)\n",
|
||||
"{\n",
|
||||
"mock_retval_0 ",
|
||||
"mock_retval_1 ",
|
||||
"}\n\n"
|
||||
].join
|
||||
returned = @cmock_generator_plugin_expect.mock_interfaces(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock interfaces for functions of style 'int func(void)'" do
|
||||
function = {:name => "Orange", :args => [], :args_string => "void", :return => test_return[:int]}
|
||||
@utils.expect :code_add_base_expectation, "mock_retval_0 ", ["Orange"]
|
||||
@utils.expect :code_call_argument_loader, "mock_retval_1 ", [function]
|
||||
@utils.expect :code_assign_argument_quickly, "mock_retval_2", ["cmock_call_instance->ReturnVal", function[:return]]
|
||||
expected = ["void Orange_CMockExpectAndReturn(UNITY_LINE_TYPE cmock_line, int cmock_to_return)\n",
|
||||
"{\n",
|
||||
"mock_retval_0 ",
|
||||
"mock_retval_1 ",
|
||||
"mock_retval_2",
|
||||
"}\n\n"
|
||||
].join
|
||||
returned = @cmock_generator_plugin_expect.mock_interfaces(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock interfaces for functions of style 'int func(char* pescado)'" do
|
||||
function = {:name => "Lemon", :args => [{ :type => "char*", :name => "pescado"}], :args_string => "char* pescado", :return => test_return[:int]}
|
||||
@utils.expect :code_add_base_expectation, "mock_retval_0 ", ["Lemon"]
|
||||
@utils.expect :code_call_argument_loader, "mock_retval_1 ", [function]
|
||||
@utils.expect :code_assign_argument_quickly, "mock_retval_2", ["cmock_call_instance->ReturnVal", function[:return]]
|
||||
expected = ["void Lemon_CMockExpectAndReturn(UNITY_LINE_TYPE cmock_line, char* pescado, int cmock_to_return)\n",
|
||||
"{\n",
|
||||
"mock_retval_0 ",
|
||||
"mock_retval_1 ",
|
||||
"mock_retval_2",
|
||||
"}\n\n"
|
||||
].join
|
||||
returned = @cmock_generator_plugin_expect.mock_interfaces(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock interfaces for functions when using ordering" do
|
||||
function = {:name => "Pear", :args => [], :args_string => "void", :return => test_return[:void]}
|
||||
@utils.expect :code_add_base_expectation, "mock_retval_0 ", ["Pear"]
|
||||
@utils.expect :code_call_argument_loader, "mock_retval_1 ", [function]
|
||||
expected = ["void Pear_CMockExpect(UNITY_LINE_TYPE cmock_line)\n",
|
||||
"{\n",
|
||||
"mock_retval_0 ",
|
||||
"mock_retval_1 ",
|
||||
"}\n\n"
|
||||
].join
|
||||
@cmock_generator_plugin_expect.ordered = true
|
||||
returned = @cmock_generator_plugin_expect.mock_interfaces(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock verify lines" do
|
||||
function = {:name => "Banana" }
|
||||
expected = " if (CMOCK_GUTS_NONE != call_instance)\n" \
|
||||
" {\n" \
|
||||
" UNITY_SET_DETAIL(CMockString_Banana);\n" \
|
||||
" UNITY_TEST_FAIL(cmock_line, CMockStringCalledLess);\n" \
|
||||
" }\n"
|
||||
returned = @cmock_generator_plugin_expect.mock_verify(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,67 @@
|
||||
# ==========================================
|
||||
# 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]
|
||||
# ==========================================
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
|
||||
require File.expand_path(File.dirname(__FILE__)) + '/../../lib/cmock_generator_plugin_expect_any_args.rb'
|
||||
|
||||
describe CMockGeneratorPluginExpectAnyArgs, "Verify CMockGeneratorPluginExpectAnyArgs Module" do
|
||||
|
||||
before do
|
||||
create_mocks :config, :utils
|
||||
@config = create_stub(:respond_to? => true)
|
||||
@cmock_generator_plugin_expect_any_args = CMockGeneratorPluginExpectAnyArgs.new(@config, @utils)
|
||||
end
|
||||
|
||||
after do
|
||||
end
|
||||
|
||||
it "have set up internal priority" do
|
||||
assert_equal(3, @cmock_generator_plugin_expect_any_args.priority)
|
||||
end
|
||||
|
||||
it "not have any additional include file requirements" do
|
||||
assert(!@cmock_generator_plugin_expect_any_args.respond_to?(:include_files))
|
||||
end
|
||||
|
||||
it "ignore functions without arguments" do
|
||||
function = {:name => "Mold", :args_string => "void", :args => [], :return => test_return[:void]}
|
||||
expected = ""
|
||||
returned = @cmock_generator_plugin_expect_any_args.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "handle function declarations for functions without return values" do
|
||||
function = {:name => "Mold", :args_string => "int meh", :args => [ :stuff ], :return => test_return[:void]}
|
||||
expected = "#define Mold_ExpectAnyArgs() Mold_CMockExpectAnyArgs(__LINE__)\nvoid Mold_CMockExpectAnyArgs(UNITY_LINE_TYPE cmock_line);\n"
|
||||
returned = @cmock_generator_plugin_expect_any_args.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "handle function declarations for functions that returns something" do
|
||||
function = {:name => "Fungus", :args_string => "int meh", :args => [ :stuff ], :return => test_return[:string]}
|
||||
expected = "#define Fungus_ExpectAnyArgsAndReturn(cmock_retval) Fungus_CMockExpectAnyArgsAndReturn(__LINE__, cmock_retval)\n"+
|
||||
"void Fungus_CMockExpectAnyArgsAndReturn(UNITY_LINE_TYPE cmock_line, const char* cmock_to_return);\n"
|
||||
returned = @cmock_generator_plugin_expect_any_args.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "should not respond to implementation requests" do
|
||||
assert(!@cmock_generator_plugin_expect_any_args.respond_to?(:mock_implementation))
|
||||
end
|
||||
|
||||
it "add a new mock interface for ignoring when function had no return value" do
|
||||
function = {:name => "Slime", :args_string => "int meh", :args => [ :stuff ], :return => test_return[:void]}
|
||||
expected = ["void Slime_CMockExpectAnyArgs(UNITY_LINE_TYPE cmock_line)\n",
|
||||
"{\n",
|
||||
"mock_return_1",
|
||||
" cmock_call_instance->ExpectAnyArgsBool = (char)1;\n",
|
||||
"}\n\n"
|
||||
].join
|
||||
@utils.expect :code_add_base_expectation, "mock_return_1", ["Slime", true]
|
||||
returned = @cmock_generator_plugin_expect_any_args.mock_interfaces(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,201 @@
|
||||
# ==========================================
|
||||
# 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]
|
||||
# ==========================================
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
|
||||
require File.expand_path(File.dirname(__FILE__)) + '/../../lib/cmock_generator_plugin_expect'
|
||||
|
||||
describe CMockGeneratorPluginExpect, "Verify CMockGeneratorPluginExpect Module with Global Ordering" do
|
||||
|
||||
before do
|
||||
create_mocks :config, :utils
|
||||
|
||||
@config = create_stub(
|
||||
:when_ptr => :compare_data,
|
||||
:enforce_strict_ordering => true,
|
||||
:respond_to? => true,
|
||||
:plugins => [ :expect, :expect_any_args ] )
|
||||
|
||||
@utils.expect :helpers, {}
|
||||
@cmock_generator_plugin_expect = CMockGeneratorPluginExpect.new(@config, @utils)
|
||||
end
|
||||
|
||||
after do
|
||||
end
|
||||
|
||||
it "have set up internal priority on init" do
|
||||
assert_nil(@cmock_generator_plugin_expect.unity_helper)
|
||||
assert_equal(5, @cmock_generator_plugin_expect.priority)
|
||||
end
|
||||
|
||||
it "not include any additional include files" do
|
||||
assert(!@cmock_generator_plugin_expect.respond_to?(:include_files))
|
||||
end
|
||||
|
||||
it "add to typedef structure mock needs of functions of style 'void func(void)' and global ordering" do
|
||||
function = {:name => "Oak", :args => [], :return => test_return[:void]}
|
||||
expected = " int CallOrder;\n"
|
||||
returned = @cmock_generator_plugin_expect.instance_typedefs(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add to typedef structure mock needs of functions of style 'int func(void)'" do
|
||||
function = {:name => "Elm", :args => [], :return => test_return[:int]}
|
||||
expected = " int ReturnVal;\n int CallOrder;\n"
|
||||
returned = @cmock_generator_plugin_expect.instance_typedefs(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add to typedef structure mock needs of functions of style 'void func(int chicken, char* pork)'" do
|
||||
function = {:name => "Cedar", :args => [{ :name => "chicken", :type => "int"}, { :name => "pork", :type => "char*"}], :return => test_return[:void]}
|
||||
expected = " int CallOrder;\n int Expected_chicken;\n char* Expected_pork;\n"
|
||||
returned = @cmock_generator_plugin_expect.instance_typedefs(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add to typedef structure mock needs of functions of style 'int func(float beef)'" do
|
||||
function = {:name => "Birch", :args => [{ :name => "beef", :type => "float"}], :return => test_return[:int]}
|
||||
expected = " int ReturnVal;\n int CallOrder;\n float Expected_beef;\n"
|
||||
returned = @cmock_generator_plugin_expect.instance_typedefs(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock function declaration for functions of style 'void func(void)'" do
|
||||
function = {:name => "Maple", :args => [], :return => test_return[:void]}
|
||||
expected = "#define Maple_Expect() Maple_CMockExpect(__LINE__)\n" +
|
||||
"void Maple_CMockExpect(UNITY_LINE_TYPE cmock_line);\n"
|
||||
returned = @cmock_generator_plugin_expect.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock function declaration for functions of style 'int func(void)'" do
|
||||
function = {:name => "Spruce", :args => [], :return => test_return[:int]}
|
||||
expected = "#define Spruce_ExpectAndReturn(cmock_retval) Spruce_CMockExpectAndReturn(__LINE__, cmock_retval)\n" +
|
||||
"void Spruce_CMockExpectAndReturn(UNITY_LINE_TYPE cmock_line, int cmock_to_return);\n"
|
||||
returned = @cmock_generator_plugin_expect.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock function declaration for functions of style 'const char* func(int tofu)'" do
|
||||
function = {:name => "Pine", :args => ["int tofu"], :args_string => "int tofu", :args_call => 'tofu', :return => test_return[:string]}
|
||||
expected = "#define Pine_ExpectAndReturn(tofu, cmock_retval) Pine_CMockExpectAndReturn(__LINE__, tofu, cmock_retval)\n" +
|
||||
"void Pine_CMockExpectAndReturn(UNITY_LINE_TYPE cmock_line, int tofu, const char* cmock_to_return);\n"
|
||||
returned = @cmock_generator_plugin_expect.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock function implementation for functions of style 'void func(void)'" do
|
||||
function = {:name => "Apple", :args => [], :return => test_return[:void]}
|
||||
expected = ""
|
||||
returned = @cmock_generator_plugin_expect.mock_implementation(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock function implementation for functions of style 'int func(int veal, unsigned int sushi)'" do
|
||||
function = {:name => "Cherry", :args => [ { :type => "int", :name => "veal" }, { :type => "unsigned int", :name => "sushi" } ], :return => test_return[:int]}
|
||||
|
||||
@utils.expect :code_verify_an_arg_expectation, "mocked_retval_1\n", [function, function[:args][0]]
|
||||
@utils.expect :code_verify_an_arg_expectation, "mocked_retval_2\n", [function, function[:args][1]]
|
||||
expected = " if (!cmock_call_instance->ExpectAnyArgsBool)\n" +
|
||||
" {\n" +
|
||||
"mocked_retval_1\n" +
|
||||
"mocked_retval_2\n" +
|
||||
" }\n"
|
||||
returned = @cmock_generator_plugin_expect.mock_implementation(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock function implementation using ordering if needed" do
|
||||
function = {:name => "Apple", :args => [], :return => test_return[:void]}
|
||||
expected = ""
|
||||
@cmock_generator_plugin_expect.ordered = true
|
||||
returned = @cmock_generator_plugin_expect.mock_implementation(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock function implementation for functions of style 'void func(int worm)' and strict ordering" do
|
||||
function = {:name => "Apple", :args => [{ :type => "int", :name => "worm" }], :return => test_return[:void]}
|
||||
@utils.expect :code_verify_an_arg_expectation, "mocked_retval_0\n", [function, function[:args][0]]
|
||||
expected = " if (!cmock_call_instance->ExpectAnyArgsBool)\n" +
|
||||
" {\n" +
|
||||
"mocked_retval_0\n" +
|
||||
" }\n"
|
||||
@cmock_generator_plugin_expect.ordered = true
|
||||
returned = @cmock_generator_plugin_expect.mock_implementation(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock interfaces for functions of style 'void func(void)'" do
|
||||
function = {:name => "Pear", :args => [], :args_string => "void", :return => test_return[:void]}
|
||||
@utils.expect :code_add_base_expectation, "mock_retval_0\n", ["Pear"]
|
||||
@utils.expect :code_call_argument_loader, "mock_retval_1\n", [function]
|
||||
expected = ["void Pear_CMockExpect(UNITY_LINE_TYPE cmock_line)\n",
|
||||
"{\n",
|
||||
"mock_retval_0\n",
|
||||
"mock_retval_1\n",
|
||||
"}\n\n"
|
||||
].join
|
||||
returned = @cmock_generator_plugin_expect.mock_interfaces(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock interfaces for functions of style 'int func(void)'" do
|
||||
function = {:name => "Orange", :args => [], :args_string => "void", :return => test_return[:int]}
|
||||
@utils.expect :code_add_base_expectation, "mock_retval_0\n", ["Orange"]
|
||||
@utils.expect :code_call_argument_loader, "mock_retval_1\n", [function]
|
||||
@utils.expect :code_assign_argument_quickly, "mock_retval_2\n", ["cmock_call_instance->ReturnVal", function[:return]]
|
||||
expected = ["void Orange_CMockExpectAndReturn(UNITY_LINE_TYPE cmock_line, int cmock_to_return)\n",
|
||||
"{\n",
|
||||
"mock_retval_0\n",
|
||||
"mock_retval_1\n",
|
||||
"mock_retval_2\n",
|
||||
"}\n\n"
|
||||
].join
|
||||
returned = @cmock_generator_plugin_expect.mock_interfaces(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock interfaces for functions of style 'int func(char* pescado)'" do
|
||||
function = {:name => "Lemon", :args => [{ :type => "char*", :name => "pescado"}], :args_string => "char* pescado", :return => test_return[:int]}
|
||||
@utils.expect :code_add_base_expectation, "mock_retval_0\n", ["Lemon"]
|
||||
@utils.expect :code_call_argument_loader, "mock_retval_1\n", [function]
|
||||
@utils.expect :code_assign_argument_quickly, "mock_retval_2\n", ["cmock_call_instance->ReturnVal", function[:return]]
|
||||
expected = ["void Lemon_CMockExpectAndReturn(UNITY_LINE_TYPE cmock_line, char* pescado, int cmock_to_return)\n",
|
||||
"{\n",
|
||||
"mock_retval_0\n",
|
||||
"mock_retval_1\n",
|
||||
"mock_retval_2\n",
|
||||
"}\n\n"
|
||||
].join
|
||||
returned = @cmock_generator_plugin_expect.mock_interfaces(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock interfaces for functions when using ordering" do
|
||||
function = {:name => "Pear", :args => [], :args_string => "void", :return => test_return[:void]}
|
||||
@utils.expect :code_add_base_expectation, "mock_retval_0\n", ["Pear"]
|
||||
@utils.expect :code_call_argument_loader, "mock_retval_1\n", [function]
|
||||
expected = ["void Pear_CMockExpect(UNITY_LINE_TYPE cmock_line)\n",
|
||||
"{\n",
|
||||
"mock_retval_0\n",
|
||||
"mock_retval_1\n",
|
||||
"}\n\n"
|
||||
].join
|
||||
@cmock_generator_plugin_expect.ordered = true
|
||||
returned = @cmock_generator_plugin_expect.mock_interfaces(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock verify lines" do
|
||||
function = {:name => "Banana" }
|
||||
expected = " if (CMOCK_GUTS_NONE != call_instance)\n" \
|
||||
" {\n" \
|
||||
" UNITY_SET_DETAIL(CMockString_Banana);\n" \
|
||||
" UNITY_TEST_FAIL(cmock_line, CMockStringCalledLess);\n" \
|
||||
" }\n"
|
||||
returned = @cmock_generator_plugin_expect.mock_verify(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,116 @@
|
||||
# ==========================================
|
||||
# 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]
|
||||
# ==========================================
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
|
||||
require File.expand_path(File.dirname(__FILE__)) + '/../../lib/cmock_generator_plugin_ignore_arg'
|
||||
|
||||
describe CMockGeneratorPluginIgnoreArg, "Verify CMockGeneratorPluginIgnoreArg Module" do
|
||||
|
||||
before do
|
||||
create_mocks :config, :utils
|
||||
|
||||
# int *Oak(void)"
|
||||
@void_func = {:name => "Oak", :args => [], :return => test_return[:int_ptr]}
|
||||
|
||||
# void Pine(int chicken, const int beef, int *tofu)
|
||||
@complex_func = {:name => "Pine",
|
||||
:args => [{ :type => "int",
|
||||
:name => "chicken",
|
||||
:ptr? => false,
|
||||
},
|
||||
{ :type => "const int*",
|
||||
:name => "beef",
|
||||
:ptr? => true,
|
||||
:const? => true,
|
||||
},
|
||||
{ :type => "int*",
|
||||
:name => "tofu",
|
||||
:ptr? => true,
|
||||
}],
|
||||
:return => test_return[:void],
|
||||
:contains_ptr? => true }
|
||||
|
||||
#no strict ordering
|
||||
@cmock_generator_plugin_ignore_arg = CMockGeneratorPluginIgnoreArg.new(@config, @utils)
|
||||
end
|
||||
|
||||
after do
|
||||
end
|
||||
|
||||
it "have set up internal priority correctly on init" do
|
||||
assert_equal(10, @cmock_generator_plugin_ignore_arg.priority)
|
||||
end
|
||||
|
||||
it "not include any additional include files" do
|
||||
assert(!@cmock_generator_plugin_ignore_arg.respond_to?(:include_files))
|
||||
end
|
||||
|
||||
it "not add to typedef structure for functions with no args" do
|
||||
returned = @cmock_generator_plugin_ignore_arg.instance_typedefs(@void_func)
|
||||
assert_equal("", returned)
|
||||
end
|
||||
|
||||
it "add to tyepdef structure mock needs of functions of style 'void func(int chicken, int* pork)'" do
|
||||
expected = " char IgnoreArg_chicken;\n" +
|
||||
" char IgnoreArg_beef;\n" +
|
||||
" char IgnoreArg_tofu;\n"
|
||||
returned = @cmock_generator_plugin_ignore_arg.instance_typedefs(@complex_func)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock function declarations for all arguments" do
|
||||
expected =
|
||||
"#define Pine_IgnoreArg_chicken()" +
|
||||
" Pine_CMockIgnoreArg_chicken(__LINE__)\n" +
|
||||
"void Pine_CMockIgnoreArg_chicken(UNITY_LINE_TYPE cmock_line);\n" +
|
||||
|
||||
"#define Pine_IgnoreArg_beef()" +
|
||||
" Pine_CMockIgnoreArg_beef(__LINE__)\n" +
|
||||
"void Pine_CMockIgnoreArg_beef(UNITY_LINE_TYPE cmock_line);\n" +
|
||||
|
||||
"#define Pine_IgnoreArg_tofu()" +
|
||||
" Pine_CMockIgnoreArg_tofu(__LINE__)\n" +
|
||||
"void Pine_CMockIgnoreArg_tofu(UNITY_LINE_TYPE cmock_line);\n"
|
||||
|
||||
returned = @cmock_generator_plugin_ignore_arg.mock_function_declarations(@complex_func)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock interfaces for all arguments" do
|
||||
expected =
|
||||
"void Pine_CMockIgnoreArg_chicken(UNITY_LINE_TYPE cmock_line)\n" +
|
||||
"{\n" +
|
||||
" CMOCK_Pine_CALL_INSTANCE* cmock_call_instance = " +
|
||||
"(CMOCK_Pine_CALL_INSTANCE*)CMock_Guts_GetAddressFor(CMock_Guts_MemEndOfChain(Mock.Pine_CallInstance));\n" +
|
||||
" UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringIgnPreExp);\n" +
|
||||
" cmock_call_instance->IgnoreArg_chicken = 1;\n" +
|
||||
"}\n\n" +
|
||||
|
||||
"void Pine_CMockIgnoreArg_beef(UNITY_LINE_TYPE cmock_line)\n" +
|
||||
"{\n" +
|
||||
" CMOCK_Pine_CALL_INSTANCE* cmock_call_instance = " +
|
||||
"(CMOCK_Pine_CALL_INSTANCE*)CMock_Guts_GetAddressFor(CMock_Guts_MemEndOfChain(Mock.Pine_CallInstance));\n" +
|
||||
" UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringIgnPreExp);\n" +
|
||||
" cmock_call_instance->IgnoreArg_beef = 1;\n" +
|
||||
"}\n\n" +
|
||||
|
||||
"void Pine_CMockIgnoreArg_tofu(UNITY_LINE_TYPE cmock_line)\n" +
|
||||
"{\n" +
|
||||
" CMOCK_Pine_CALL_INSTANCE* cmock_call_instance = " +
|
||||
"(CMOCK_Pine_CALL_INSTANCE*)CMock_Guts_GetAddressFor(CMock_Guts_MemEndOfChain(Mock.Pine_CallInstance));\n" +
|
||||
" UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringIgnPreExp);\n" +
|
||||
" cmock_call_instance->IgnoreArg_tofu = 1;\n" +
|
||||
"}\n\n"
|
||||
|
||||
returned = @cmock_generator_plugin_ignore_arg.mock_interfaces(@complex_func).join("")
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "not add a mock implementation" do
|
||||
assert(!@cmock_generator_plugin_ignore_arg.respond_to?(:mock_implementation))
|
||||
end
|
||||
|
||||
end
|
||||
@ -0,0 +1,119 @@
|
||||
# ==========================================
|
||||
# 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]
|
||||
# ==========================================
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
|
||||
require File.expand_path(File.dirname(__FILE__)) + '/../../lib/cmock_generator_plugin_ignore'
|
||||
|
||||
describe CMockGeneratorPluginIgnore, "Verify CMockGeneratorPluginIgnore Module" do
|
||||
|
||||
before do
|
||||
create_mocks :config, :utils
|
||||
@config = create_stub(:respond_to? => true)
|
||||
@cmock_generator_plugin_ignore = CMockGeneratorPluginIgnore.new(@config, @utils)
|
||||
end
|
||||
|
||||
after do
|
||||
end
|
||||
|
||||
it "have set up internal priority" do
|
||||
assert_equal(2, @cmock_generator_plugin_ignore.priority)
|
||||
end
|
||||
|
||||
it "not have any additional include file requirements" do
|
||||
assert(!@cmock_generator_plugin_ignore.respond_to?(:include_files))
|
||||
end
|
||||
|
||||
it "add a required variable to the instance structure" do
|
||||
function = {:name => "Grass", :args => [], :return => test_return[:void]}
|
||||
expected = " char Grass_IgnoreBool;\n"
|
||||
returned = @cmock_generator_plugin_ignore.instance_structure(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "handle function declarations for functions without return values" do
|
||||
function = {:name => "Mold", :args_string => "void", :return => test_return[:void]}
|
||||
expected = "#define Mold_Ignore() Mold_CMockIgnore()\nvoid Mold_CMockIgnore(void);\n" +
|
||||
"#define Mold_StopIgnore() Mold_CMockStopIgnore()\nvoid Mold_CMockStopIgnore(void);\n"
|
||||
returned = @cmock_generator_plugin_ignore.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "handle function declarations for functions that returns something" do
|
||||
function = {:name => "Fungus", :args_string => "void", :return => test_return[:string]}
|
||||
expected = "#define Fungus_IgnoreAndReturn(cmock_retval) Fungus_CMockIgnoreAndReturn(__LINE__, cmock_retval)\n"+
|
||||
"void Fungus_CMockIgnoreAndReturn(UNITY_LINE_TYPE cmock_line, const char* cmock_to_return);\n" +
|
||||
"#define Fungus_StopIgnore() Fungus_CMockStopIgnore()\n"+
|
||||
"void Fungus_CMockStopIgnore(void);\n"
|
||||
returned = @cmock_generator_plugin_ignore.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add required code to implementation precheck with void function" do
|
||||
function = {:name => "Mold", :args_string => "void", :return => test_return[:void]}
|
||||
expected = [" if (Mock.Mold_IgnoreBool)\n",
|
||||
" {\n",
|
||||
" UNITY_CLR_DETAILS();\n",
|
||||
" return;\n",
|
||||
" }\n"
|
||||
].join
|
||||
returned = @cmock_generator_plugin_ignore.mock_implementation_precheck(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add required code to implementation precheck with return functions" do
|
||||
function = {:name => "Fungus", :args_string => "void", :return => test_return[:int]}
|
||||
retval = test_return[:int].merge({ :name => "cmock_call_instance->ReturnVal"})
|
||||
@utils.expect :code_assign_argument_quickly, ' mock_retval_0', ["Mock.Fungus_FinalReturn", retval]
|
||||
expected = [" if (Mock.Fungus_IgnoreBool)\n",
|
||||
" {\n",
|
||||
" UNITY_CLR_DETAILS();\n",
|
||||
" if (cmock_call_instance == NULL)\n",
|
||||
" return Mock.Fungus_FinalReturn;\n",
|
||||
" mock_retval_0",
|
||||
" return cmock_call_instance->ReturnVal;\n",
|
||||
" }\n"
|
||||
].join
|
||||
returned = @cmock_generator_plugin_ignore.mock_implementation_precheck(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add a new mock interface for ignoring when function had no return value" do
|
||||
function = {:name => "Slime", :args => [], :args_string => "void", :return => test_return[:void]}
|
||||
expected = ["void Slime_CMockIgnore(void)\n",
|
||||
"{\n",
|
||||
" Mock.Slime_IgnoreBool = (char)1;\n",
|
||||
"}\n\n",
|
||||
|
||||
"void Slime_CMockStopIgnore(void)\n",
|
||||
"{\n",
|
||||
" Mock.Slime_IgnoreBool = (char)0;\n",
|
||||
"}\n\n"
|
||||
].join
|
||||
returned = @cmock_generator_plugin_ignore.mock_interfaces(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add a new mock interface for ignoring when function has return value" do
|
||||
function = {:name => "Slime", :args => [], :args_string => "void", :return => test_return[:int]}
|
||||
@utils.expect :code_add_base_expectation, "mock_return_1", ["Slime", false]
|
||||
expected = ["void Slime_CMockIgnoreAndReturn(UNITY_LINE_TYPE cmock_line, int cmock_to_return)\n",
|
||||
"{\n",
|
||||
"mock_return_1",
|
||||
" cmock_call_instance->ReturnVal = cmock_to_return;\n",
|
||||
" Mock.Slime_IgnoreBool = (char)1;\n",
|
||||
"}\n\n",
|
||||
|
||||
"void Slime_CMockStopIgnore(void)\n{\n",
|
||||
" if(Mock.Slime_IgnoreBool)\n",
|
||||
" Mock.Slime_CallInstance = CMock_Guts_MemNext(Mock.Slime_CallInstance);\n",
|
||||
" Mock.Slime_IgnoreBool = (char)0;\n",
|
||||
"}\n\n"
|
||||
].join
|
||||
returned = @cmock_generator_plugin_ignore.mock_interfaces(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
end
|
||||
@ -0,0 +1,136 @@
|
||||
# ==========================================
|
||||
# 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]
|
||||
# ==========================================
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
|
||||
require File.expand_path(File.dirname(__FILE__)) + '/../../lib/cmock_generator_plugin_return_thru_ptr'
|
||||
|
||||
describe CMockGeneratorPluginReturnThruPtr, "Verify CMockGeneratorPluginReturnThruPtr Module" do
|
||||
|
||||
before do
|
||||
create_mocks :config, :utils
|
||||
|
||||
# int *Oak(void)"
|
||||
@void_func = {:name => "Oak", :args => [], :return => test_return[:int_ptr]}
|
||||
|
||||
# char *Maple(int blah)
|
||||
@simple_func = {:name => "Maple",
|
||||
:args => [{:name => "blah", :type => "int", :ptr? => false}],
|
||||
:return => test_return[:string],
|
||||
:contains_ptr? => false}
|
||||
|
||||
# void Pine(int chicken, const int beef, int *tofu)
|
||||
@complex_func = {:name => "Pine",
|
||||
:args => [{ :type => "int",
|
||||
:name => "chicken",
|
||||
:ptr? => false,
|
||||
},
|
||||
{ :type => "const int*",
|
||||
:name => "beef",
|
||||
:ptr? => true,
|
||||
:const? => true,
|
||||
},
|
||||
{ :type => "int*",
|
||||
:name => "tofu",
|
||||
:ptr? => true,
|
||||
}],
|
||||
:return => test_return[:void],
|
||||
:contains_ptr? => true }
|
||||
|
||||
#no strict ordering
|
||||
@cmock_generator_plugin_return_thru_ptr = CMockGeneratorPluginReturnThruPtr.new(@config, @utils)
|
||||
end
|
||||
|
||||
after do
|
||||
end
|
||||
|
||||
def simple_func_expect
|
||||
@utils.expect :ptr_or_str?, false, ['int']
|
||||
end
|
||||
|
||||
def complex_func_expect
|
||||
@utils.expect :ptr_or_str?, false, ['int']
|
||||
@utils.expect :ptr_or_str?, true, ['const int*']
|
||||
@utils.expect :ptr_or_str?, true, ['int*']
|
||||
end
|
||||
|
||||
it "have set up internal priority correctly on init" do
|
||||
assert_equal(9, @cmock_generator_plugin_return_thru_ptr.priority)
|
||||
end
|
||||
|
||||
it "not include any additional include files" do
|
||||
assert(!@cmock_generator_plugin_return_thru_ptr.respond_to?(:include_files))
|
||||
end
|
||||
|
||||
it "not add to typedef structure for functions of style 'int* func(void)'" do
|
||||
returned = @cmock_generator_plugin_return_thru_ptr.instance_typedefs(@void_func)
|
||||
assert_equal("", returned)
|
||||
end
|
||||
|
||||
it "add to tyepdef structure mock needs of functions of style 'void func(int chicken, int* pork)'" do
|
||||
complex_func_expect()
|
||||
expected = " char ReturnThruPtr_tofu_Used;\n" +
|
||||
" int* ReturnThruPtr_tofu_Val;\n" +
|
||||
" int ReturnThruPtr_tofu_Size;\n"
|
||||
returned = @cmock_generator_plugin_return_thru_ptr.instance_typedefs(@complex_func)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "not add an additional mock interface for functions not containing pointers" do
|
||||
simple_func_expect()
|
||||
returned = @cmock_generator_plugin_return_thru_ptr.mock_function_declarations(@simple_func)
|
||||
assert_equal("", returned)
|
||||
end
|
||||
|
||||
it "add a mock function declaration only for non-const pointer arguments" do
|
||||
complex_func_expect();
|
||||
|
||||
expected =
|
||||
"#define Pine_ReturnThruPtr_tofu(tofu)" +
|
||||
" Pine_CMockReturnMemThruPtr_tofu(__LINE__, tofu, sizeof(int))\n" +
|
||||
"#define Pine_ReturnArrayThruPtr_tofu(tofu, cmock_len)" +
|
||||
" Pine_CMockReturnMemThruPtr_tofu(__LINE__, tofu, (int)(cmock_len * (int)sizeof(*tofu)))\n" +
|
||||
"#define Pine_ReturnMemThruPtr_tofu(tofu, cmock_size)" +
|
||||
" Pine_CMockReturnMemThruPtr_tofu(__LINE__, tofu, cmock_size)\n" +
|
||||
"void Pine_CMockReturnMemThruPtr_tofu(UNITY_LINE_TYPE cmock_line, int* tofu, int cmock_size);\n"
|
||||
|
||||
returned = @cmock_generator_plugin_return_thru_ptr.mock_function_declarations(@complex_func)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock interfaces only for non-const pointer arguments" do
|
||||
complex_func_expect();
|
||||
|
||||
expected =
|
||||
"void Pine_CMockReturnMemThruPtr_tofu(UNITY_LINE_TYPE cmock_line, int* tofu, int cmock_size)\n" +
|
||||
"{\n" +
|
||||
" CMOCK_Pine_CALL_INSTANCE* cmock_call_instance = " +
|
||||
"(CMOCK_Pine_CALL_INSTANCE*)CMock_Guts_GetAddressFor(CMock_Guts_MemEndOfChain(Mock.Pine_CallInstance));\n" +
|
||||
" UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringPtrPreExp);\n" +
|
||||
" cmock_call_instance->ReturnThruPtr_tofu_Used = 1;\n" +
|
||||
" cmock_call_instance->ReturnThruPtr_tofu_Val = tofu;\n" +
|
||||
" cmock_call_instance->ReturnThruPtr_tofu_Size = cmock_size;\n" +
|
||||
"}\n\n"
|
||||
|
||||
returned = @cmock_generator_plugin_return_thru_ptr.mock_interfaces(@complex_func).join("")
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock implementations only for non-const pointer arguments" do
|
||||
complex_func_expect()
|
||||
|
||||
expected =
|
||||
" if (cmock_call_instance->ReturnThruPtr_tofu_Used)\n" +
|
||||
" {\n" +
|
||||
" UNITY_TEST_ASSERT_NOT_NULL(tofu, cmock_line, CMockStringPtrIsNULL);\n" +
|
||||
" memcpy((void*)tofu, (void*)cmock_call_instance->ReturnThruPtr_tofu_Val,\n" +
|
||||
" cmock_call_instance->ReturnThruPtr_tofu_Size);\n" +
|
||||
" }\n"
|
||||
|
||||
returned = @cmock_generator_plugin_return_thru_ptr.mock_implementation(@complex_func).join("")
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
end
|
||||
@ -0,0 +1,398 @@
|
||||
# ==========================================
|
||||
# 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]
|
||||
# ==========================================
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
|
||||
require File.expand_path(File.dirname(__FILE__)) + '/../../lib/cmock_generator_utils'
|
||||
|
||||
describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do
|
||||
|
||||
before do
|
||||
create_mocks :config, :unity_helper, :unity_helper
|
||||
|
||||
@config.expect :when_ptr, :compare_ptr
|
||||
@config.expect :enforce_strict_ordering, false
|
||||
@config.expect :plugins, []
|
||||
@config.expect :plugins, []
|
||||
@config.expect :plugins, []
|
||||
@config.expect :plugins, []
|
||||
@config.expect :plugins, []
|
||||
@config.expect :plugins, []
|
||||
@config.expect :treat_as, {'int' => 'INT','short' => 'INT16','long' => 'INT','char' => 'INT8','const char*' => 'STRING'}
|
||||
@cmock_generator_utils_simple = CMockGeneratorUtils.new(@config, {:unity_helper => @unity_helper})
|
||||
|
||||
@config.expect :when_ptr, :smart
|
||||
@config.expect :enforce_strict_ordering, true
|
||||
@config.expect :plugins, [:array, :cexception, :return_thru_ptr, :ignore_arg, :ignore]
|
||||
@config.expect :plugins, [:array, :cexception, :return_thru_ptr, :ignore_arg, :ignore]
|
||||
@config.expect :plugins, [:array, :cexception, :return_thru_ptr, :ignore_arg, :ignore]
|
||||
@config.expect :plugins, [:array, :cexception, :return_thru_ptr, :ignore_arg, :ignore]
|
||||
@config.expect :plugins, [:array, :cexception, :return_thru_ptr, :ignore_arg, :ignore]
|
||||
@config.expect :plugins, [:array, :cexception, :return_thru_ptr, :ignore_arg, :ignore]
|
||||
@config.expect :treat_as, {'int' => 'INT','short' => 'INT16','long' => 'INT','char' => 'INT8','uint32_t' => 'HEX32','const char*' => 'STRING'}
|
||||
@cmock_generator_utils_complex = CMockGeneratorUtils.new(@config, {:unity_helper => @unity_helper, :A=>1, :B=>2})
|
||||
end
|
||||
|
||||
after do
|
||||
end
|
||||
|
||||
it "have set up internal accessors correctly on init" do
|
||||
assert_equal(false, @cmock_generator_utils_simple.arrays)
|
||||
assert_equal(false, @cmock_generator_utils_simple.cexception)
|
||||
end
|
||||
|
||||
it "have set up internal accessors correctly on init, complete with passed helpers" do
|
||||
assert_equal(true, @cmock_generator_utils_complex.arrays)
|
||||
assert_equal(true, @cmock_generator_utils_complex.cexception)
|
||||
end
|
||||
|
||||
it "detect pointers and strings" do
|
||||
assert_equal(false, @cmock_generator_utils_simple.ptr_or_str?('int'))
|
||||
assert_equal(true, @cmock_generator_utils_simple.ptr_or_str?('int*'))
|
||||
assert_equal(true, @cmock_generator_utils_simple.ptr_or_str?('char*'))
|
||||
end
|
||||
|
||||
it "add code for a base expectation with no plugins" do
|
||||
expected =
|
||||
" CMOCK_MEM_INDEX_TYPE cmock_guts_index = CMock_Guts_MemNew(sizeof(CMOCK_Apple_CALL_INSTANCE));\n" +
|
||||
" CMOCK_Apple_CALL_INSTANCE* cmock_call_instance = (CMOCK_Apple_CALL_INSTANCE*)CMock_Guts_GetAddressFor(cmock_guts_index);\n" +
|
||||
" UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringOutOfMemory);\n" +
|
||||
" memset(cmock_call_instance, 0, sizeof(*cmock_call_instance));\n" +
|
||||
" Mock.Apple_CallInstance = CMock_Guts_MemChain(Mock.Apple_CallInstance, cmock_guts_index);\n" +
|
||||
" cmock_call_instance->LineNumber = cmock_line;\n"
|
||||
output = @cmock_generator_utils_simple.code_add_base_expectation("Apple")
|
||||
assert_equal(expected, output)
|
||||
end
|
||||
|
||||
it "add code for a base expectation with all plugins" do
|
||||
expected =
|
||||
" CMOCK_MEM_INDEX_TYPE cmock_guts_index = CMock_Guts_MemNew(sizeof(CMOCK_Apple_CALL_INSTANCE));\n" +
|
||||
" CMOCK_Apple_CALL_INSTANCE* cmock_call_instance = (CMOCK_Apple_CALL_INSTANCE*)CMock_Guts_GetAddressFor(cmock_guts_index);\n" +
|
||||
" UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringOutOfMemory);\n" +
|
||||
" memset(cmock_call_instance, 0, sizeof(*cmock_call_instance));\n" +
|
||||
" Mock.Apple_CallInstance = CMock_Guts_MemChain(Mock.Apple_CallInstance, cmock_guts_index);\n" +
|
||||
" Mock.Apple_IgnoreBool = (char)0;\n" +
|
||||
" cmock_call_instance->LineNumber = cmock_line;\n" +
|
||||
" cmock_call_instance->CallOrder = ++GlobalExpectCount;\n" +
|
||||
" cmock_call_instance->ExceptionToThrow = CEXCEPTION_NONE;\n"
|
||||
output = @cmock_generator_utils_complex.code_add_base_expectation("Apple", true)
|
||||
assert_equal(expected, output)
|
||||
end
|
||||
|
||||
it "add code for a base expectation with all plugins and ordering not supported" do
|
||||
expected =
|
||||
" CMOCK_MEM_INDEX_TYPE cmock_guts_index = CMock_Guts_MemNew(sizeof(CMOCK_Apple_CALL_INSTANCE));\n" +
|
||||
" CMOCK_Apple_CALL_INSTANCE* cmock_call_instance = (CMOCK_Apple_CALL_INSTANCE*)CMock_Guts_GetAddressFor(cmock_guts_index);\n" +
|
||||
" UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringOutOfMemory);\n" +
|
||||
" memset(cmock_call_instance, 0, sizeof(*cmock_call_instance));\n" +
|
||||
" Mock.Apple_CallInstance = CMock_Guts_MemChain(Mock.Apple_CallInstance, cmock_guts_index);\n" +
|
||||
" Mock.Apple_IgnoreBool = (char)0;\n" +
|
||||
" cmock_call_instance->LineNumber = cmock_line;\n" +
|
||||
" cmock_call_instance->ExceptionToThrow = CEXCEPTION_NONE;\n"
|
||||
output = @cmock_generator_utils_complex.code_add_base_expectation("Apple", false)
|
||||
assert_equal(expected, output)
|
||||
end
|
||||
|
||||
it "add argument expectations for values when no array plugin" do
|
||||
arg1 = { :name => "Orange", :const? => false, :type => 'int', :ptr? => false }
|
||||
expected1 = " cmock_call_instance->Expected_Orange = Orange;\n"
|
||||
|
||||
arg2 = { :name => "Lemon", :const? => true, :type => 'const char*', :ptr? => false }
|
||||
expected2 = " cmock_call_instance->Expected_Lemon = Lemon;\n"
|
||||
|
||||
arg3 = { :name => "Kiwi", :const? => false, :type => 'KIWI_T*', :ptr? => true }
|
||||
expected3 = " cmock_call_instance->Expected_Kiwi = Kiwi;\n"
|
||||
|
||||
arg4 = { :name => "Lime", :const? => false, :type => 'LIME_T', :ptr? => false }
|
||||
expected4 = " memcpy((void*)(&cmock_call_instance->Expected_Lime), (void*)(&Lime),\n" +
|
||||
" sizeof(LIME_T[sizeof(Lime) == sizeof(LIME_T) ? 1 : -1])); /* add LIME_T to :treat_as_array if this causes an error */\n"
|
||||
|
||||
assert_equal(expected1, @cmock_generator_utils_simple.code_add_an_arg_expectation(arg1))
|
||||
assert_equal(expected2, @cmock_generator_utils_simple.code_add_an_arg_expectation(arg2))
|
||||
assert_equal(expected3, @cmock_generator_utils_simple.code_add_an_arg_expectation(arg3))
|
||||
assert_equal(expected4, @cmock_generator_utils_simple.code_add_an_arg_expectation(arg4))
|
||||
end
|
||||
|
||||
it "add argument expectations for values when array plugin enabled" do
|
||||
arg1 = { :name => "Orange", :const? => false, :type => 'int', :ptr? => false }
|
||||
expected1 = " cmock_call_instance->Expected_Orange = Orange;\n" +
|
||||
" cmock_call_instance->IgnoreArg_Orange = 0;\n"
|
||||
|
||||
arg2 = { :name => "Lemon", :const? => true, :type => 'const char*', :ptr? => false }
|
||||
expected2 = " cmock_call_instance->Expected_Lemon = Lemon;\n" +
|
||||
" cmock_call_instance->Expected_Lemon_Depth = Lemon_Depth;\n" +
|
||||
" cmock_call_instance->IgnoreArg_Lemon = 0;\n"
|
||||
|
||||
arg3 = { :name => "Kiwi", :const? => false, :type => 'KIWI_T*', :ptr? => true }
|
||||
expected3 = " cmock_call_instance->Expected_Kiwi = Kiwi;\n" +
|
||||
" cmock_call_instance->Expected_Kiwi_Depth = Kiwi_Depth;\n" +
|
||||
" cmock_call_instance->IgnoreArg_Kiwi = 0;\n" +
|
||||
" cmock_call_instance->ReturnThruPtr_Kiwi_Used = 0;\n"
|
||||
|
||||
arg4 = { :name => "Lime", :const? => false, :type => 'LIME_T', :ptr? => false }
|
||||
expected4 = " memcpy((void*)(&cmock_call_instance->Expected_Lime), (void*)(&Lime),\n" +
|
||||
" sizeof(LIME_T[sizeof(Lime) == sizeof(LIME_T) ? 1 : -1])); /* add LIME_T to :treat_as_array if this causes an error */\n" +
|
||||
" cmock_call_instance->IgnoreArg_Lime = 0;\n"
|
||||
|
||||
assert_equal(expected1, @cmock_generator_utils_complex.code_add_an_arg_expectation(arg1))
|
||||
assert_equal(expected2, @cmock_generator_utils_complex.code_add_an_arg_expectation(arg2, 'Lemon_Depth'))
|
||||
assert_equal(expected3, @cmock_generator_utils_complex.code_add_an_arg_expectation(arg3, 'Lemon_Depth'))
|
||||
assert_equal(expected4, @cmock_generator_utils_complex.code_add_an_arg_expectation(arg4))
|
||||
end
|
||||
|
||||
it 'not have an argument loader when the function has no arguments' do
|
||||
function = { :name => "Melon", :args_string => "void" }
|
||||
|
||||
assert_equal("", @cmock_generator_utils_complex.code_add_argument_loader(function))
|
||||
end
|
||||
|
||||
it 'create an argument loader when the function has arguments' do
|
||||
function = { :name => "Melon",
|
||||
:args_string => "stuff",
|
||||
:args => [test_arg[:int_ptr], test_arg[:mytype], test_arg[:string]]
|
||||
}
|
||||
expected = "void CMockExpectParameters_Melon(CMOCK_Melon_CALL_INSTANCE* cmock_call_instance, stuff)\n{\n" +
|
||||
" cmock_call_instance->Expected_MyIntPtr = MyIntPtr;\n" +
|
||||
" memcpy((void*)(&cmock_call_instance->Expected_MyMyType), (void*)(&MyMyType),\n" +
|
||||
" sizeof(MY_TYPE[sizeof(MyMyType) == sizeof(MY_TYPE) ? 1 : -1])); /* add MY_TYPE to :treat_as_array if this causes an error */\n" +
|
||||
" cmock_call_instance->Expected_MyStr = MyStr;\n" +
|
||||
"}\n\n"
|
||||
assert_equal(expected, @cmock_generator_utils_simple.code_add_argument_loader(function))
|
||||
end
|
||||
|
||||
it 'create an argument loader when the function has arguments supporting arrays' do
|
||||
function = { :name => "Melon",
|
||||
:args_string => "stuff",
|
||||
:args => [test_arg[:int_ptr], test_arg[:mytype], test_arg[:string]]
|
||||
}
|
||||
expected = "void CMockExpectParameters_Melon(CMOCK_Melon_CALL_INSTANCE* cmock_call_instance, int* MyIntPtr, int MyIntPtr_Depth, const MY_TYPE MyMyType, const char* MyStr)\n{\n" +
|
||||
" cmock_call_instance->Expected_MyIntPtr = MyIntPtr;\n" +
|
||||
" cmock_call_instance->Expected_MyIntPtr_Depth = MyIntPtr_Depth;\n" +
|
||||
" cmock_call_instance->IgnoreArg_MyIntPtr = 0;\n" +
|
||||
" cmock_call_instance->ReturnThruPtr_MyIntPtr_Used = 0;\n" +
|
||||
" memcpy((void*)(&cmock_call_instance->Expected_MyMyType), (void*)(&MyMyType),\n" +
|
||||
" sizeof(MY_TYPE[sizeof(MyMyType) == sizeof(MY_TYPE) ? 1 : -1])); /* add MY_TYPE to :treat_as_array if this causes an error */\n" +
|
||||
" cmock_call_instance->IgnoreArg_MyMyType = 0;\n" +
|
||||
" cmock_call_instance->Expected_MyStr = MyStr;\n" +
|
||||
" cmock_call_instance->IgnoreArg_MyStr = 0;\n" +
|
||||
"}\n\n"
|
||||
assert_equal(expected, @cmock_generator_utils_complex.code_add_argument_loader(function))
|
||||
end
|
||||
|
||||
it 'create an argument loader when the function has pointer arguments supporting arrays' do
|
||||
function = { :name => "Melon",
|
||||
:args_string => "stuff",
|
||||
:args => [test_arg[:const_ptr], test_arg[:double_ptr]]
|
||||
}
|
||||
expected = "void CMockExpectParameters_Melon(CMOCK_Melon_CALL_INSTANCE* cmock_call_instance, int* const MyConstPtr, int MyConstPtr_Depth, int const** MyDoublePtr, int MyDoublePtr_Depth)\n{\n" +
|
||||
" cmock_call_instance->Expected_MyConstPtr = MyConstPtr;\n" +
|
||||
" cmock_call_instance->Expected_MyConstPtr_Depth = MyConstPtr_Depth;\n" +
|
||||
" cmock_call_instance->IgnoreArg_MyConstPtr = 0;\n" +
|
||||
" cmock_call_instance->ReturnThruPtr_MyConstPtr_Used = 0;\n" +
|
||||
" cmock_call_instance->Expected_MyDoublePtr = MyDoublePtr;\n" +
|
||||
" cmock_call_instance->Expected_MyDoublePtr_Depth = MyDoublePtr_Depth;\n" +
|
||||
" cmock_call_instance->IgnoreArg_MyDoublePtr = 0;\n" +
|
||||
"}\n\n"
|
||||
assert_equal(expected, @cmock_generator_utils_complex.code_add_argument_loader(function))
|
||||
end
|
||||
|
||||
it "not call argument loader if there are no arguments to actually use for this function" do
|
||||
function = { :name => "Pineapple", :args_string => "void" }
|
||||
|
||||
assert_equal("", @cmock_generator_utils_complex.code_call_argument_loader(function))
|
||||
end
|
||||
|
||||
it 'call an argument loader when the function has arguments' do
|
||||
function = { :name => "Pineapple",
|
||||
:args_string => "stuff",
|
||||
:args => [test_arg[:int_ptr], test_arg[:mytype], test_arg[:string]]
|
||||
}
|
||||
expected = " CMockExpectParameters_Pineapple(cmock_call_instance, MyIntPtr, MyMyType, MyStr);\n"
|
||||
assert_equal(expected, @cmock_generator_utils_simple.code_call_argument_loader(function))
|
||||
end
|
||||
|
||||
it 'call an argument loader when the function has arguments with arrays' do
|
||||
function = { :name => "Pineapple",
|
||||
:args_string => "stuff",
|
||||
:args => [test_arg[:int_ptr], test_arg[:mytype], test_arg[:string]]
|
||||
}
|
||||
expected = " CMockExpectParameters_Pineapple(cmock_call_instance, MyIntPtr, 1, MyMyType, MyStr);\n"
|
||||
assert_equal(expected, @cmock_generator_utils_complex.code_call_argument_loader(function))
|
||||
end
|
||||
|
||||
it 'handle a simple assert when requested' do
|
||||
function = { :name => 'Pear' }
|
||||
arg = test_arg[:int]
|
||||
expected = " {\n" +
|
||||
" UNITY_SET_DETAILS(CMockString_Pear,CMockString_MyInt);\n" +
|
||||
" UNITY_TEST_ASSERT_EQUAL_INT(cmock_call_instance->Expected_MyInt, MyInt, cmock_line, CMockStringMismatch);\n" +
|
||||
" }\n"
|
||||
@unity_helper.expect :nil?, false
|
||||
@unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_INT', ''], ['int']
|
||||
assert_equal(expected, @cmock_generator_utils_simple.code_verify_an_arg_expectation(function, arg))
|
||||
end
|
||||
|
||||
it 'handle a pointer comparison when configured to do so' do
|
||||
function = { :name => 'Pear' }
|
||||
arg = test_arg[:int_ptr]
|
||||
expected = " {\n" +
|
||||
" UNITY_SET_DETAILS(CMockString_Pear,CMockString_MyIntPtr);\n" +
|
||||
" UNITY_TEST_ASSERT_EQUAL_PTR(cmock_call_instance->Expected_MyIntPtr, MyIntPtr, cmock_line, CMockStringMismatch);\n" +
|
||||
" }\n"
|
||||
assert_equal(expected, @cmock_generator_utils_simple.code_verify_an_arg_expectation(function, arg))
|
||||
end
|
||||
|
||||
it 'handle const char as string compares ' do
|
||||
function = { :name => 'Pear' }
|
||||
arg = test_arg[:string]
|
||||
expected = " {\n" +
|
||||
" UNITY_SET_DETAILS(CMockString_Pear,CMockString_MyStr);\n" +
|
||||
" UNITY_TEST_ASSERT_EQUAL_STRING(cmock_call_instance->Expected_MyStr, MyStr, cmock_line, CMockStringMismatch);\n" +
|
||||
" }\n"
|
||||
@unity_helper.expect :nil?, false
|
||||
@unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_STRING',''], ['const char*']
|
||||
assert_equal(expected, @cmock_generator_utils_simple.code_verify_an_arg_expectation(function, arg))
|
||||
end
|
||||
|
||||
it 'handle custom types as memory compares when we have no better way to do it' do
|
||||
function = { :name => 'Pear' }
|
||||
arg = test_arg[:mytype]
|
||||
expected = " {\n" +
|
||||
" UNITY_SET_DETAILS(CMockString_Pear,CMockString_MyMyType);\n" +
|
||||
" UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)(&cmock_call_instance->Expected_MyMyType), (void*)(&MyMyType), sizeof(MY_TYPE), cmock_line, CMockStringMismatch);\n" +
|
||||
" }\n"
|
||||
@unity_helper.expect :nil?, false
|
||||
@unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_MEMORY','&'], ['MY_TYPE']
|
||||
assert_equal(expected, @cmock_generator_utils_simple.code_verify_an_arg_expectation(function, arg))
|
||||
end
|
||||
|
||||
it 'handle custom types with custom handlers when available, even if they do not support the extra message' do
|
||||
function = { :name => 'Pear' }
|
||||
arg = test_arg[:mytype]
|
||||
expected = " {\n" +
|
||||
" UNITY_SET_DETAILS(CMockString_Pear,CMockString_MyMyType);\n" +
|
||||
" UNITY_TEST_ASSERT_EQUAL_MY_TYPE(cmock_call_instance->Expected_MyMyType, MyMyType, cmock_line, CMockStringMismatch);\n" +
|
||||
" }\n"
|
||||
@unity_helper.expect :nil?, false
|
||||
@unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_MY_TYPE',''], ['MY_TYPE']
|
||||
assert_equal(expected, @cmock_generator_utils_simple.code_verify_an_arg_expectation(function, arg))
|
||||
end
|
||||
|
||||
it 'handle pointers to custom types with array handlers, even if the array extension is turned off' do
|
||||
function = { :name => 'Pear' }
|
||||
arg = test_arg[:mytype]
|
||||
expected = " {\n" +
|
||||
" UNITY_SET_DETAILS(CMockString_Pear,CMockString_MyMyType);\n" +
|
||||
" UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY(&cmock_call_instance->Expected_MyMyType, &MyMyType, 1, cmock_line, CMockStringMismatch);\n" +
|
||||
" }\n"
|
||||
@unity_helper.expect :nil?, false
|
||||
@unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY','&'], ['MY_TYPE']
|
||||
assert_equal(expected, @cmock_generator_utils_simple.code_verify_an_arg_expectation(function, arg))
|
||||
end
|
||||
|
||||
it 'handle a simple assert when requested with array plugin enabled' do
|
||||
function = { :name => 'Pear' }
|
||||
arg = test_arg[:int]
|
||||
expected = " if (!cmock_call_instance->IgnoreArg_MyInt)\n" +
|
||||
" {\n" +
|
||||
" UNITY_SET_DETAILS(CMockString_Pear,CMockString_MyInt);\n" +
|
||||
" UNITY_TEST_ASSERT_EQUAL_INT(cmock_call_instance->Expected_MyInt, MyInt, cmock_line, CMockStringMismatch);\n" +
|
||||
" }\n"
|
||||
@unity_helper.expect :nil?, false
|
||||
@unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_INT',''], ['int']
|
||||
assert_equal(expected, @cmock_generator_utils_complex.code_verify_an_arg_expectation(function, arg))
|
||||
end
|
||||
|
||||
it 'handle an array comparison with array plugin enabled' do
|
||||
function = { :name => 'Pear' }
|
||||
arg = test_arg[:int_ptr]
|
||||
expected = " if (!cmock_call_instance->IgnoreArg_MyIntPtr)\n" +
|
||||
" {\n" +
|
||||
" UNITY_SET_DETAILS(CMockString_Pear,CMockString_MyIntPtr);\n" +
|
||||
" if (cmock_call_instance->Expected_MyIntPtr == NULL)\n" +
|
||||
" { UNITY_TEST_ASSERT_NULL(MyIntPtr, cmock_line, CMockStringExpNULL); }\n" +
|
||||
" else if (cmock_call_instance->Expected_MyIntPtr_Depth == 0)\n" +
|
||||
" { UNITY_TEST_ASSERT_EQUAL_PTR(cmock_call_instance->Expected_MyIntPtr, MyIntPtr, cmock_line, CMockStringMismatch); }\n" +
|
||||
" else\n" +
|
||||
" { UNITY_TEST_ASSERT_EQUAL_INT_ARRAY(cmock_call_instance->Expected_MyIntPtr, MyIntPtr, cmock_call_instance->Expected_MyIntPtr_Depth, cmock_line, CMockStringMismatch); }\n" +
|
||||
" }\n"
|
||||
@unity_helper.expect :nil?, false
|
||||
@unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_INT_ARRAY',''], ['int*']
|
||||
assert_equal(expected, @cmock_generator_utils_complex.code_verify_an_arg_expectation(function, arg))
|
||||
end
|
||||
|
||||
it 'handle const char as string compares with array plugin enabled' do
|
||||
function = { :name => 'Pear' }
|
||||
arg = test_arg[:string]
|
||||
expected = " if (!cmock_call_instance->IgnoreArg_MyStr)\n" +
|
||||
" {\n" +
|
||||
" UNITY_SET_DETAILS(CMockString_Pear,CMockString_MyStr);\n" +
|
||||
" UNITY_TEST_ASSERT_EQUAL_STRING(cmock_call_instance->Expected_MyStr, MyStr, cmock_line, CMockStringMismatch);\n" +
|
||||
" }\n"
|
||||
@unity_helper.expect :nil?, false
|
||||
@unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_STRING',''], ['const char*']
|
||||
assert_equal(expected, @cmock_generator_utils_complex.code_verify_an_arg_expectation(function, arg))
|
||||
end
|
||||
|
||||
it 'handle custom types as memory compares when we have no better way to do it with array plugin enabled' do
|
||||
function = { :name => 'Pear' }
|
||||
arg = test_arg[:mytype]
|
||||
expected = " if (!cmock_call_instance->IgnoreArg_MyMyType)\n" +
|
||||
" {\n" +
|
||||
" UNITY_SET_DETAILS(CMockString_Pear,CMockString_MyMyType);\n" +
|
||||
" if (cmock_call_instance->Expected_MyMyType == NULL)\n" +
|
||||
" { UNITY_TEST_ASSERT_NULL(MyMyType, cmock_line, CMockStringExpNULL); }\n" +
|
||||
" else\n" +
|
||||
" { UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY((void*)(cmock_call_instance->Expected_MyMyType), (void*)(MyMyType), sizeof(MY_TYPE), 1, cmock_line, CMockStringMismatch); }\n" +
|
||||
" }\n"
|
||||
@unity_helper.expect :nil?, false
|
||||
@unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY', ''], ['MY_TYPE']
|
||||
assert_equal(expected, @cmock_generator_utils_complex.code_verify_an_arg_expectation(function, arg))
|
||||
end
|
||||
|
||||
it 'handle custom types with custom handlers when available, even if they do not support the extra message with array plugin enabled' do
|
||||
function = { :name => 'Pear' }
|
||||
arg = test_arg[:mytype]
|
||||
expected = " if (!cmock_call_instance->IgnoreArg_MyMyType)\n" +
|
||||
" {\n" +
|
||||
" UNITY_SET_DETAILS(CMockString_Pear,CMockString_MyMyType);\n" +
|
||||
" UNITY_TEST_ASSERT_EQUAL_MY_TYPE(cmock_call_instance->Expected_MyMyType, MyMyType, cmock_line, CMockStringMismatch);\n" +
|
||||
" }\n"
|
||||
@unity_helper.expect :nil?, false
|
||||
@unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_MY_TYPE', ''], ['MY_TYPE']
|
||||
assert_equal(expected, @cmock_generator_utils_complex.code_verify_an_arg_expectation(function, arg))
|
||||
end
|
||||
|
||||
it 'handle custom types with array handlers when array plugin is enabled' do
|
||||
function = { :name => 'Pear' }
|
||||
arg = test_arg[:mytype_ptr]
|
||||
expected = " if (!cmock_call_instance->IgnoreArg_MyMyTypePtr)\n" +
|
||||
" {\n" +
|
||||
" UNITY_SET_DETAILS(CMockString_Pear,CMockString_MyMyTypePtr);\n" +
|
||||
" if (cmock_call_instance->Expected_MyMyTypePtr == NULL)\n" +
|
||||
" { UNITY_TEST_ASSERT_NULL(MyMyTypePtr, cmock_line, CMockStringExpNULL); }\n" +
|
||||
" else if (cmock_call_instance->Expected_MyMyTypePtr_Depth == 0)\n" +
|
||||
" { UNITY_TEST_ASSERT_EQUAL_PTR(cmock_call_instance->Expected_MyMyTypePtr, MyMyTypePtr, cmock_line, CMockStringMismatch); }\n" +
|
||||
" else\n" +
|
||||
" { UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY(cmock_call_instance->Expected_MyMyTypePtr, MyMyTypePtr, cmock_call_instance->Expected_MyMyTypePtr_Depth, cmock_line, CMockStringMismatch); }\n" +
|
||||
" }\n"
|
||||
@unity_helper.expect :nil?, false
|
||||
@unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY', ''], ['MY_TYPE*']
|
||||
assert_equal(expected, @cmock_generator_utils_complex.code_verify_an_arg_expectation(function, arg))
|
||||
end
|
||||
|
||||
it 'handle custom types with array handlers when array plugin is enabled for non-array types' do
|
||||
function = { :name => 'Pear' }
|
||||
arg = test_arg[:mytype]
|
||||
expected = " if (!cmock_call_instance->IgnoreArg_MyMyType)\n" +
|
||||
" {\n" +
|
||||
" UNITY_SET_DETAILS(CMockString_Pear,CMockString_MyMyType);\n" +
|
||||
" UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY(&cmock_call_instance->Expected_MyMyType, &MyMyType, 1, cmock_line, CMockStringMismatch);\n" +
|
||||
" }\n"
|
||||
@unity_helper.expect :nil?, false
|
||||
@unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY', '&'], ['MY_TYPE']
|
||||
assert_equal(expected, @cmock_generator_utils_complex.code_verify_an_arg_expectation(function, arg))
|
||||
end
|
||||
end
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,100 @@
|
||||
# ==========================================
|
||||
# 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]
|
||||
# ==========================================
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
|
||||
require File.expand_path(File.dirname(__FILE__)) + '/../../lib/cmock_plugin_manager'
|
||||
require File.expand_path(File.dirname(__FILE__)) + '/../../lib/cmock_generator_plugin_expect'
|
||||
require File.expand_path(File.dirname(__FILE__)) + '/../../lib/cmock_generator_plugin_ignore'
|
||||
require File.expand_path(File.dirname(__FILE__)) + '/../../lib/cmock_generator_plugin_cexception'
|
||||
|
||||
describe CMockPluginManager, "Verify CMockPluginManager Module" do
|
||||
|
||||
before do
|
||||
create_mocks :utils, :pluginA, :pluginB
|
||||
@config = create_stub(
|
||||
:respond_to => true,
|
||||
:when_ptr => :compare_data,
|
||||
:enforce_strict_ordering => false,
|
||||
:ignore => :args_and_calls
|
||||
)
|
||||
|
||||
def @config.plugins
|
||||
if instance_variable_defined?(:@plugins)
|
||||
@plugins || []
|
||||
else
|
||||
[]
|
||||
end
|
||||
end
|
||||
|
||||
def @config.plugins=(val)
|
||||
@plugins = val
|
||||
end
|
||||
end
|
||||
|
||||
after do
|
||||
end
|
||||
|
||||
it "return all plugins by default" do
|
||||
@config.plugins = ['cexception','ignore']
|
||||
@utils.expect :helpers, {}
|
||||
|
||||
@cmock_plugins = CMockPluginManager.new(@config, @utils)
|
||||
|
||||
test_plugins = @cmock_plugins.plugins
|
||||
contained = { :expect => false, :ignore => false, :cexception => false }
|
||||
test_plugins.each do |plugin|
|
||||
contained[:expect] = true if plugin.instance_of?(CMockGeneratorPluginExpect)
|
||||
contained[:ignore] = true if plugin.instance_of?(CMockGeneratorPluginIgnore)
|
||||
contained[:cexception] = true if plugin.instance_of?(CMockGeneratorPluginCexception)
|
||||
end
|
||||
assert_equal(true, contained[:expect])
|
||||
assert_equal(true, contained[:ignore])
|
||||
assert_equal(true, contained[:cexception])
|
||||
end
|
||||
|
||||
it "return restricted plugins based on config" do
|
||||
@utils.expect :helpers, {}
|
||||
|
||||
@cmock_plugins = CMockPluginManager.new(@config, @utils)
|
||||
|
||||
test_plugins = @cmock_plugins.plugins
|
||||
contained = { :expect => false, :ignore => false, :cexception => false }
|
||||
test_plugins.each do |plugin|
|
||||
contained[:expect] = true if plugin.instance_of?(CMockGeneratorPluginExpect)
|
||||
contained[:ignore] = true if plugin.instance_of?(CMockGeneratorPluginIgnore)
|
||||
contained[:cexception] = true if plugin.instance_of?(CMockGeneratorPluginCexception)
|
||||
end
|
||||
assert_equal(true, contained[:expect])
|
||||
assert_equal(false,contained[:ignore])
|
||||
assert_equal(false,contained[:cexception])
|
||||
end
|
||||
|
||||
it "run a desired method over each plugin requested and return the results" do
|
||||
@utils.expect :helpers, {}
|
||||
@cmock_plugins = CMockPluginManager.new(@config, @utils)
|
||||
|
||||
@pluginA = create_stub(:test_method => ["This Is An Awesome Test-"])
|
||||
@pluginB = create_stub(:test_method => ["And This is Part 2-","Of An Awesome Test"])
|
||||
@cmock_plugins.plugins = [@pluginA, @pluginB]
|
||||
|
||||
expected = "This Is An Awesome Test-And This is Part 2-Of An Awesome Test"
|
||||
output = @cmock_plugins.run(:test_method)
|
||||
assert_equal(expected, output)
|
||||
end
|
||||
|
||||
it "run a desired method and arg list over each plugin requested and return the results" do
|
||||
@utils.expect :helpers, {}
|
||||
@cmock_plugins = CMockPluginManager.new(@config, @utils)
|
||||
|
||||
@pluginA = create_stub(:test_method => ["This Is An Awesome Test-"])
|
||||
@pluginB = create_stub(:test_method => ["And This is Part 2-","Of An Awesome Test"])
|
||||
@cmock_plugins.plugins = [@pluginA, @pluginB]
|
||||
|
||||
expected = "This Is An Awesome Test-And This is Part 2-Of An Awesome Test"
|
||||
output = @cmock_plugins.run(:test_method, "chickenpotpie")
|
||||
assert_equal(expected, output)
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,223 @@
|
||||
# ==========================================
|
||||
# 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]
|
||||
# ==========================================
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
|
||||
require File.expand_path(File.dirname(__FILE__)) + '/../../lib/cmock_unityhelper_parser'
|
||||
|
||||
describe CMockUnityHelperParser, "Verify CMockUnityHelperParser Module" do
|
||||
|
||||
before do
|
||||
create_mocks :config
|
||||
end
|
||||
|
||||
after do
|
||||
end
|
||||
|
||||
it "ignore lines that are commented out" do
|
||||
source =
|
||||
" abcd;\n" +
|
||||
"// #define UNITY_TEST_ASSERT_EQUAL_CHICKENS(a,b,line,msg) {...};\n" +
|
||||
"or maybe // #define UNITY_TEST_ASSERT_EQUAL_CHICKENS(a,b,line,msg) {...};\n\n"
|
||||
@config.expect :plugins, [] #not :array
|
||||
@config.expect :treat_as, {}
|
||||
@config.expect :load_unity_helper, source
|
||||
@parser = CMockUnityHelperParser.new(@config)
|
||||
expected = {}
|
||||
|
||||
assert_equal(expected, @parser.c_types)
|
||||
end
|
||||
|
||||
it "ignore stuff in block comments" do
|
||||
source =
|
||||
" abcd; /*\n" +
|
||||
"#define UNITY_TEST_ASSERT_EQUAL_CHICKENS(a,b,line,msg) {...};\n" +
|
||||
"#define UNITY_TEST_ASSERT_EQUAL_CHICKENS(a,b,line,msg) {...};\n */\n"
|
||||
@config.expect :plugins, [] #not :array
|
||||
@config.expect :treat_as, {}
|
||||
@config.expect :load_unity_helper, source
|
||||
@parser = CMockUnityHelperParser.new(@config)
|
||||
expected = {}
|
||||
|
||||
assert_equal(expected, @parser.c_types)
|
||||
end
|
||||
|
||||
it "notice equal helpers in the proper form and ignore others" do
|
||||
source =
|
||||
"abcd;\n" +
|
||||
"#define UNITY_TEST_ASSERT_EQUAL_TURKEYS_T(a,b,line,msg) {...};\n" +
|
||||
"abcd;\n" +
|
||||
"#define UNITY_TEST_ASSERT_EQUAL_WRONG_NUM_ARGS(a,b,c,d,e) {...};\n" +
|
||||
"#define UNITY_TEST_ASSERT_WRONG_NAME_EQUAL(a,b,c,d) {...};\n" +
|
||||
"#define UNITY_TEST_ASSERT_EQUAL_unsigned_funky_rabbits(a,b,c,d) {...};\n" +
|
||||
"abcd;\n"
|
||||
@config.expect :plugins, [] #not :array
|
||||
@config.expect :treat_as, {}
|
||||
@config.expect :load_unity_helper, source
|
||||
@parser = CMockUnityHelperParser.new(@config)
|
||||
expected = {
|
||||
'TURKEYS_T' => "UNITY_TEST_ASSERT_EQUAL_TURKEYS_T",
|
||||
'unsigned_funky_rabbits' => "UNITY_TEST_ASSERT_EQUAL_unsigned_funky_rabbits"
|
||||
}
|
||||
|
||||
assert_equal(expected, @parser.c_types)
|
||||
end
|
||||
|
||||
it "notice equal helpers that contain arrays" do
|
||||
source =
|
||||
"abcd;\n" +
|
||||
"#define UNITY_TEST_ASSERT_EQUAL_TURKEYS_ARRAY(a,b,c,d,e) {...};\n" +
|
||||
"abcd;\n" +
|
||||
"#define UNITY_TEST_ASSERT_EQUAL_WRONG_NUM_ARGS_ARRAY(a,b,c,d,e,f) {...};\n" +
|
||||
"#define UNITY_TEST_ASSERT_WRONG_NAME_EQUAL_ARRAY(a,b,c,d,e) {...};\n" +
|
||||
"#define UNITY_TEST_ASSERT_EQUAL_unsigned_funky_rabbits_ARRAY(a,b,c,d,e) {...};\n" +
|
||||
"abcd;\n"
|
||||
@config.expect :plugins, [] #not :array
|
||||
@config.expect :treat_as, {}
|
||||
@config.expect :load_unity_helper, source
|
||||
@parser = CMockUnityHelperParser.new(@config)
|
||||
expected = {
|
||||
'TURKEYS*' => "UNITY_TEST_ASSERT_EQUAL_TURKEYS_ARRAY",
|
||||
'unsigned_funky_rabbits*' => "UNITY_TEST_ASSERT_EQUAL_unsigned_funky_rabbits_ARRAY"
|
||||
}
|
||||
|
||||
assert_equal(expected, @parser.c_types)
|
||||
end
|
||||
|
||||
it "pull in the standard set of helpers and add them to my list" do
|
||||
pairs = {
|
||||
"UINT" => "HEX32",
|
||||
"unsigned long" => "HEX64",
|
||||
}
|
||||
expected = {
|
||||
"UINT" => "UNITY_TEST_ASSERT_EQUAL_HEX32",
|
||||
"unsigned_long" => "UNITY_TEST_ASSERT_EQUAL_HEX64",
|
||||
"UINT*" => "UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY",
|
||||
"unsigned_long*"=> "UNITY_TEST_ASSERT_EQUAL_HEX64_ARRAY",
|
||||
}
|
||||
@config.expect :plugins, [] #not :array
|
||||
@config.expect :treat_as, pairs
|
||||
@config.expect :load_unity_helper, nil
|
||||
@parser = CMockUnityHelperParser.new(@config)
|
||||
|
||||
assert_equal(expected, @parser.c_types)
|
||||
end
|
||||
|
||||
it "pull in the user specified set of helpers and add them to my list" do
|
||||
pairs = {
|
||||
"char*" => "STRING",
|
||||
"unsigned int" => "HEX32",
|
||||
}
|
||||
expected = {
|
||||
"char*" => "UNITY_TEST_ASSERT_EQUAL_STRING",
|
||||
"unsigned_int" => "UNITY_TEST_ASSERT_EQUAL_HEX32",
|
||||
"char**" => "UNITY_TEST_ASSERT_EQUAL_STRING_ARRAY",
|
||||
"unsigned_int*" => "UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY",
|
||||
}
|
||||
@config.expect :plugins, [] #not :array
|
||||
@config.expect :treat_as, pairs
|
||||
@config.expect :load_unity_helper, nil
|
||||
@parser = CMockUnityHelperParser.new(@config)
|
||||
|
||||
assert_equal(expected, @parser.c_types)
|
||||
end
|
||||
|
||||
it "be able to fetch helpers on my list" do
|
||||
@config.expect :plugins, [] #not :array
|
||||
@config.expect :treat_as, {}
|
||||
@config.expect :load_unity_helper, ""
|
||||
@parser = CMockUnityHelperParser.new(@config)
|
||||
@parser.c_types = {
|
||||
'UINT8' => "UNITY_TEST_ASSERT_EQUAL_UINT8",
|
||||
'UINT16*' => "UNITY_TEST_ASSERT_EQUAL_UINT16_ARRAY",
|
||||
'SPINACH' => "UNITY_TEST_ASSERT_EQUAL_SPINACH",
|
||||
'LONG_LONG' => "UNITY_TEST_ASSERT_EQUAL_LONG_LONG"
|
||||
}
|
||||
|
||||
[["UINT8","UINT8"],
|
||||
["UINT16*","UINT16_ARRAY"],
|
||||
["const SPINACH","SPINACH"],
|
||||
["LONG LONG","LONG_LONG"] ].each do |ctype, exptype|
|
||||
assert_equal(["UNITY_TEST_ASSERT_EQUAL_#{exptype}",''], @parser.get_helper(ctype))
|
||||
end
|
||||
end
|
||||
|
||||
it "return memory comparison when asked to fetch helper of types not on my list" do
|
||||
@config.expect :plugins, [] #not :array
|
||||
@config.expect :treat_as, {}
|
||||
@config.expect :load_unity_helper, ""
|
||||
@parser = CMockUnityHelperParser.new(@config)
|
||||
@parser.c_types = {
|
||||
'UINT8' => "UNITY_TEST_ASSERT_EQUAL_UINT8",
|
||||
'UINT16*' => "UNITY_TEST_ASSERT_EQUAL_UINT16_ARRAY",
|
||||
'SPINACH' => "UNITY_TEST_ASSERT_EQUAL_SPINACH",
|
||||
}
|
||||
|
||||
["UINT32","SPINACH_T","SALAD","PINEAPPLE"].each do |ctype|
|
||||
@config.expect :memcmp_if_unknown, true
|
||||
assert_equal(["UNITY_TEST_ASSERT_EQUAL_MEMORY",'&'], @parser.get_helper(ctype))
|
||||
end
|
||||
end
|
||||
|
||||
it "return memory array comparison when asked to fetch helper of types not on my list" do
|
||||
@config.expect :plugins, [:array]
|
||||
@config.expect :treat_as, {}
|
||||
@config.expect :load_unity_helper, ""
|
||||
@parser = CMockUnityHelperParser.new(@config)
|
||||
@parser.c_types = {
|
||||
'UINT8' => "UNITY_TEST_ASSERT_EQUAL_UINT8",
|
||||
'UINT16*' => "UNITY_TEST_ASSERT_EQUAL_UINT16_ARRAY",
|
||||
'SPINACH' => "UNITY_TEST_ASSERT_EQUAL_SPINACH",
|
||||
}
|
||||
|
||||
["UINT32*","SPINACH_T*"].each do |ctype|
|
||||
@config.expect :memcmp_if_unknown, true
|
||||
assert_equal(["UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY",''], @parser.get_helper(ctype))
|
||||
end
|
||||
end
|
||||
|
||||
it "return the array handler if we cannot find the normal handler" do
|
||||
@config.expect :plugins, [] #not :array
|
||||
@config.expect :treat_as, {}
|
||||
@config.expect :load_unity_helper, ""
|
||||
@parser = CMockUnityHelperParser.new(@config)
|
||||
@parser.c_types = {
|
||||
'UINT8' => "UNITY_TEST_ASSERT_EQUAL_UINT8",
|
||||
'UINT16*' => "UNITY_TEST_ASSERT_EQUAL_UINT16_ARRAY",
|
||||
'SPINACH' => "UNITY_TEST_ASSERT_EQUAL_SPINACH",
|
||||
}
|
||||
|
||||
assert_equal(["UNITY_TEST_ASSERT_EQUAL_UINT16_ARRAY",'&'], @parser.get_helper("UINT16"))
|
||||
end
|
||||
|
||||
it "return the normal handler if we cannot find the array handler" do
|
||||
@config.expect :plugins, [] #not :array
|
||||
@config.expect :treat_as, {}
|
||||
@config.expect :load_unity_helper, ""
|
||||
@parser = CMockUnityHelperParser.new(@config)
|
||||
@parser.c_types = {
|
||||
'UINT8' => "UNITY_TEST_ASSERT_EQUAL_UINT8",
|
||||
'UINT16' => "UNITY_TEST_ASSERT_EQUAL_UINT16",
|
||||
'SPINACH' => "UNITY_TEST_ASSERT_EQUAL_SPINACH",
|
||||
}
|
||||
|
||||
assert_equal(["UNITY_TEST_ASSERT_EQUAL_UINT8",'*'], @parser.get_helper("UINT8*"))
|
||||
end
|
||||
|
||||
it "raise error when asked to fetch helper of type not on my list and not allowed to mem check" do
|
||||
@config.expect :plugins, [] #not :array
|
||||
@config.expect :treat_as, {}
|
||||
@config.expect :load_unity_helper, ""
|
||||
@config.expect :memcmp_if_unknown, false
|
||||
@parser = CMockUnityHelperParser.new(@config)
|
||||
@parser.c_types = {
|
||||
'UINT8' => "UNITY_TEST_ASSERT_EQUAL_UINT8",
|
||||
'UINT32*' => "UNITY_TEST_ASSERT_EQUAL_UINT32_ARRAY",
|
||||
'SPINACH' => "UNITY_TEST_ASSERT_EQUAL_SPINACH",
|
||||
}
|
||||
|
||||
assert_raises (RuntimeError) { @parser.get_helper("UINT16") }
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user