mirror of
https://github.com/ThrowTheSwitch/CMock.git
synced 2026-08-24 12:09:55 +00:00
- updated unit tests to use built-in minitest instead of old TestUnit and Hardmock
This commit is contained in:
@@ -10,8 +10,6 @@ require 'rake/clean'
|
||||
require 'rake/testtask'
|
||||
require './rakefile_helper'
|
||||
|
||||
require 'rspec/core/rake_task'
|
||||
|
||||
include RakefileHelpers
|
||||
|
||||
DEFAULT_CONFIG_FILE = 'gcc.yml'
|
||||
@@ -33,9 +31,9 @@ task :prep_system_tests => SYSTEM_TEST_SUPPORT_DIRS
|
||||
configure_clean
|
||||
configure_toolchain(DEFAULT_CONFIG_FILE)
|
||||
|
||||
task :default => ['test:all']
|
||||
task :ci => [:no_color, :default]
|
||||
task :cruise => :ci
|
||||
task :default => [:test]
|
||||
task :ci => [:no_color, :default]
|
||||
task :cruise => :ci
|
||||
|
||||
desc "Load configuration"
|
||||
task :config, :config_file do |t, args|
|
||||
@@ -44,10 +42,10 @@ task :config, :config_file do |t, args|
|
||||
configure_toolchain(args[:config_file])
|
||||
end
|
||||
|
||||
namespace :test do
|
||||
desc "Run all unit and system tests"
|
||||
task :all => [:clobber, :prep_system_tests, 'test:units', 'test:c', 'test:system']
|
||||
desc "Run all unit, c, and system tests"
|
||||
task :test => [:clobber, :prep_system_tests, 'test:units', 'test:c', 'test:system']
|
||||
|
||||
namespace :test do
|
||||
desc "Run Unit Tests"
|
||||
Rake::TestTask.new('units') do |t|
|
||||
t.pattern = 'test/unit/*_test.rb'
|
||||
@@ -56,7 +54,7 @@ namespace :test do
|
||||
|
||||
#individual unit tests
|
||||
FileList['test/unit/*_test.rb'].each do |test|
|
||||
Rake::TestTask.new(File.basename(test,'.*')) do |t|
|
||||
Rake::TestTask.new(File.basename(test,'.*').sub('_test','')) do |t|
|
||||
t.pattern = test
|
||||
t.verbose = true
|
||||
end
|
||||
@@ -88,8 +86,9 @@ namespace :test do
|
||||
|
||||
#individual system tests
|
||||
FileList['test/system/test_interactions/*.yml'].each do |test|
|
||||
desc "Run system test #{File.basename(test,'.*')}"
|
||||
task "test:#{File.basename(test,'.*')}" do
|
||||
basename = File.basename(test,'.*')
|
||||
desc "Run system test #{basename}"
|
||||
task basename do
|
||||
run_system_test_interactions([test])
|
||||
end
|
||||
end
|
||||
@@ -103,9 +102,3 @@ end
|
||||
task :no_color do
|
||||
$colour_output = false
|
||||
end
|
||||
|
||||
RSpec::Core::RakeTask.new(:spec) do |t|
|
||||
spec_path = File.join(CMOCK_ROOT, 'test/spec')
|
||||
t.pattern = spec_path + '/*_spec.rb'
|
||||
end
|
||||
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
here = File.expand_path(File.dirname(__FILE__))
|
||||
require "#{here}/spec_helper" #add this to execute tests from the spec directory
|
||||
require 'cmock_file_writer'
|
||||
|
||||
describe CMockFileWriter do
|
||||
before do
|
||||
@cmConfig = Object.new
|
||||
|
||||
#create instance of class under test
|
||||
@subject = CMockFileWriter.new(@cmConfig)
|
||||
end
|
||||
|
||||
describe 'initialize' do
|
||||
it "have set up internal accessors correctly on init" do
|
||||
result = @subject.config
|
||||
result.should == @cmConfig
|
||||
end
|
||||
end
|
||||
|
||||
describe 'create_file' do
|
||||
|
||||
it "should complain if a block was not specified when calling create" do
|
||||
expect {@subject.create_file("text.txt")}.should raise_error
|
||||
# should.be_false
|
||||
end
|
||||
|
||||
it "should perform block on new file" do
|
||||
# mock(@cmConfig).enforce_strict_ordering {false}
|
||||
mock(@cmConfig).mock_path {"testPath"}
|
||||
mock(@cmConfig).mock_path {"testPath"}
|
||||
|
||||
FakeFile = Object.new
|
||||
mock(File).open("testPath/test.txt.new", "w").yields(FakeFile, "test.txt")
|
||||
mock(FakeFile).write("hello world"){nil}
|
||||
|
||||
mock(File).exist?("testPath/test.txt") {true}
|
||||
mock(FileUtils).rm("testPath/test.txt")
|
||||
mock(FileUtils).cp("testPath/test.txt.new", "testPath/test.txt")
|
||||
mock(FileUtils).rm("testPath/test.txt.new")
|
||||
# Call function under test
|
||||
@subject.create_file("test.txt") {|f| f.write("hello world")}
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
@@ -1,52 +0,0 @@
|
||||
here = File.expand_path(File.dirname(__FILE__))
|
||||
require "#{here}/spec_helper" #add this to execute tests from the spec directory
|
||||
require 'cmock_generator_plugin_array'
|
||||
|
||||
describe :CMockGeneratorPluginArray do
|
||||
before do
|
||||
@cmConfig = Object.new
|
||||
@cmUtils = Object.new
|
||||
mock(@cmConfig).when_ptr {:compare_data}
|
||||
mock(@cmConfig).enforce_strict_ordering {false}
|
||||
mock(@cmUtils).helpers { {} }
|
||||
#create instance of class under test
|
||||
@subject = CMockGeneratorPluginArray.new(@cmConfig, @cmUtils)
|
||||
end
|
||||
|
||||
it "should not respond to include_files" do
|
||||
# @subject.should_not respond_to(:include_files)
|
||||
end
|
||||
|
||||
# it "should not add to typedef structure for functions of " +
|
||||
# "style 'int* func(void)'" do
|
||||
# function = {:name => "Oak", :args => [], :return => :int_ptr}
|
||||
# returned = @subject.instance_typedefs(function)
|
||||
# returned.should == ""
|
||||
# end
|
||||
|
||||
# it "should add to typedef structure mock needs of functions of style "+
|
||||
# "'void func(int chicken, int* pork)'" do
|
||||
# arg1 = { :name => "chicken", :type => "int", :ptr? => false}
|
||||
# arg2 = { :name => "pork", :type => "int*", :ptr? => true}
|
||||
# function = {:name => "Cedar",
|
||||
# :args => [arg1, arg2],
|
||||
# :return => :void}
|
||||
# expected = " int Expected_pork_Depth;\n"
|
||||
# returned = @subject.instance_typedefs(function)
|
||||
# returned.should == expected
|
||||
# end
|
||||
|
||||
# it "should not add an additional mock interface for functions not containing pointers" do
|
||||
# function = {:name => "Maple", :args_string => "int blah", :return => :string,
|
||||
# :contains_ptr? => false}
|
||||
# returned = @subject.mock_function_declarations(function)
|
||||
# returned.should_be nil
|
||||
# end
|
||||
|
||||
# describe 'create_file' do
|
||||
# it "complain if a block was not specified when calling create" do
|
||||
# expect {@subject.create_file("text.txt")}.should raise_error
|
||||
# # should.be_false
|
||||
# end
|
||||
# end
|
||||
end
|
||||
@@ -1,12 +0,0 @@
|
||||
require 'rubygems'
|
||||
|
||||
proj_root = File.expand_path(File.dirname(__FILE__) + '/../..')
|
||||
# require proj_root + '/config/environment'
|
||||
$LOAD_PATH << proj_root + '/lib'
|
||||
|
||||
require 'rspec'
|
||||
require 'rr'
|
||||
|
||||
RSpec.configure do |config|
|
||||
config.mock_with :rr
|
||||
end
|
||||
+33
-40
@@ -2,48 +2,41 @@
|
||||
# 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]
|
||||
# ==========================================
|
||||
[ "/../config/test_environment",
|
||||
"/../vendor/behaviors/lib/behaviors"
|
||||
].each do |req|
|
||||
require File.expand_path(File.dirname(__FILE__)) + req
|
||||
end
|
||||
# ==========================================
|
||||
|
||||
# Note from Matt July 16 2012: not sure why this is here, as 1.9 comes with
|
||||
# minitest, an implementation for Test::Unit in 1.9.
|
||||
# Using test-unit makes hardmock quite unhappy.
|
||||
# Long-term solution: replace hardmock with a mocking library like rr or rspec
|
||||
# that is well maintained into the future. hardmock is off of life support.
|
||||
#gem install test-unit -v 1.2.3
|
||||
# ruby_version = RUBY_VERSION.split('.')
|
||||
# if (ruby_version[1].to_i == 9) and (ruby_version[2].to_i > 1)
|
||||
# require 'rubygems'
|
||||
# gem 'test-unit'
|
||||
# end
|
||||
require 'test/unit'
|
||||
require 'hardmock'
|
||||
|
||||
class Test::Unit::TestCase
|
||||
extend Behaviors
|
||||
|
||||
#these are helpful test structures which can be used during tests
|
||||
|
||||
def test_return
|
||||
{
|
||||
:int => {:type => "int", :name => 'cmock_to_return', :ptr? => false, :const? => false, :void? => false, :str => 'int cmock_to_return'},
|
||||
:int_ptr => {:type => "int*", :name => 'cmock_to_return', :ptr? => true, :const? => false, :void? => false, :str => 'int* cmock_to_return'},
|
||||
:void => {:type => "void", :name => 'cmock_to_return', :ptr? => false, :const? => false, :void? => true, :str => 'void cmock_to_return'},
|
||||
:string => {:type => "char*", :name => 'cmock_to_return', :ptr? => false, :const? => true, :void? => false, :str => 'const char* cmock_to_return'},
|
||||
}
|
||||
end
|
||||
require 'minitest/autorun'
|
||||
|
||||
def test_arg
|
||||
{
|
||||
:int => {:type => "int", :name => 'MyInt', :ptr? => false, :const? => false},
|
||||
:int_ptr => {:type => "int*", :name => 'MyIntPtr', :ptr? => true, :const? => false},
|
||||
:mytype => {:type => "MY_TYPE", :name => 'MyMyType', :ptr? => false, :const? => true},
|
||||
:mytype_ptr => {:type => "MY_TYPE*", :name => 'MyMyTypePtr', :ptr? => true, :const? => false},
|
||||
:string => {:type => "char*", :name => 'MyStr', :ptr? => false, :const? => true},
|
||||
}
|
||||
def create_mocks(*mocks)
|
||||
mocks.each do |mock|
|
||||
eval "@#{mock} = Minitest::Mock.new"
|
||||
end
|
||||
end
|
||||
|
||||
def create_stub(funcs)
|
||||
stub = Class.new
|
||||
funcs.each_pair do |k,v|
|
||||
stub.define_singleton_method(k) {|unused=nil| return v }
|
||||
end
|
||||
stub
|
||||
end
|
||||
|
||||
def test_return
|
||||
{
|
||||
:int => {:type => "int", :name => 'cmock_to_return', :ptr? => false, :const? => false, :void? => false, :str => 'int cmock_to_return'},
|
||||
:int_ptr => {:type => "int*", :name => 'cmock_to_return', :ptr? => true, :const? => false, :void? => false, :str => 'int* cmock_to_return'},
|
||||
:void => {:type => "void", :name => 'cmock_to_return', :ptr? => false, :const? => false, :void? => true, :str => 'void cmock_to_return'},
|
||||
:string => {:type => "char*", :name => 'cmock_to_return', :ptr? => false, :const? => true, :void? => false, :str => 'const char* cmock_to_return'},
|
||||
}
|
||||
end
|
||||
|
||||
def test_arg
|
||||
{
|
||||
:int => {:type => "int", :name => 'MyInt', :ptr? => false, :const? => false},
|
||||
:int_ptr => {:type => "int*", :name => 'MyIntPtr', :ptr? => true, :const? => false},
|
||||
:mytype => {:type => "MY_TYPE", :name => 'MyMyType', :ptr? => false, :const? => true},
|
||||
:mytype_ptr => {:type => "MY_TYPE*", :name => 'MyMyTypePtr', :ptr? => true, :const? => false},
|
||||
:string => {:type => "char*", :name => 'MyStr', :ptr? => false, :const? => true},
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
@@ -2,19 +2,16 @@
|
||||
# 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 'cmock_config'
|
||||
|
||||
class CMockConfigTest < Test::Unit::TestCase
|
||||
def setup
|
||||
end
|
||||
|
||||
def teardown
|
||||
end
|
||||
|
||||
should "use default settings when no parameters are specified" do
|
||||
describe CMockConfig, "Verify CMockConfig Module" do
|
||||
|
||||
it "use default settings when no parameters are specified" do
|
||||
config = CMockConfig.new
|
||||
assert_equal(CMockConfig::CMockDefaultOptions[:mock_path], config.mock_path)
|
||||
assert_equal(CMockConfig::CMockDefaultOptions[:includes], config.includes)
|
||||
@@ -22,8 +19,8 @@ class CMockConfigTest < Test::Unit::TestCase
|
||||
assert_equal(CMockConfig::CMockDefaultOptions[:plugins], config.plugins)
|
||||
assert_equal(CMockConfig::CMockDefaultOptions[:treat_externs], config.treat_externs)
|
||||
end
|
||||
|
||||
should "replace only options specified in a hash" do
|
||||
|
||||
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)
|
||||
@@ -33,8 +30,8 @@ class CMockConfigTest < Test::Unit::TestCase
|
||||
assert_equal(CMockConfig::CMockDefaultOptions[:plugins], config.plugins)
|
||||
assert_equal(CMockConfig::CMockDefaultOptions[:treat_externs], config.treat_externs)
|
||||
end
|
||||
|
||||
should "replace only options specified in a yaml file" do
|
||||
|
||||
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::CMockDefaultOptions[:mock_path], config.mock_path)
|
||||
@@ -43,8 +40,8 @@ class CMockConfigTest < Test::Unit::TestCase
|
||||
assert_equal(:include, config.treat_externs)
|
||||
end
|
||||
|
||||
should "populate treat_as map with internal standard_treat_as_map defaults, redefine defaults, and add custom values" do
|
||||
|
||||
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
|
||||
@@ -55,10 +52,10 @@ class CMockConfigTest < Test::Unit::TestCase
|
||||
'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'])
|
||||
@@ -73,16 +70,16 @@ class CMockConfigTest < Test::Unit::TestCase
|
||||
# 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('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'])
|
||||
@@ -97,25 +94,25 @@ class CMockConfigTest < Test::Unit::TestCase
|
||||
|
||||
# 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('HEX32', config2.standard_treat_as_map['unsigned long'])
|
||||
assert_equal('STRING', config2.standard_treat_as_map['char*'])
|
||||
end
|
||||
|
||||
should "standard treat_as map should be incorruptable" do
|
||||
|
||||
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
|
||||
|
||||
@@ -2,29 +2,26 @@
|
||||
# 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 'cmock_file_writer'
|
||||
|
||||
class CMockFileWriterTest < Test::Unit::TestCase
|
||||
def setup
|
||||
describe CMockFileWriter, "Verify CMockFileWriter Module" do
|
||||
|
||||
before do
|
||||
create_mocks :config
|
||||
@cmock_file_writer = CMockFileWriter.new(@config)
|
||||
end
|
||||
|
||||
def teardown
|
||||
after do
|
||||
end
|
||||
|
||||
should "have set up internal accessors correctly on init" do
|
||||
assert_equal(@config, @cmock_file_writer.config)
|
||||
end
|
||||
|
||||
should "complain if a block was not specified when calling create" do
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
@@ -35,52 +35,46 @@ class MockedPluginHelper
|
||||
end
|
||||
end
|
||||
|
||||
class CMockGeneratorTest < Test::Unit::TestCase
|
||||
def setup
|
||||
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.returns("Mock")
|
||||
@config.expect.enforce_strict_ordering.returns(nil)
|
||||
@config.expect.framework.returns(:unity)
|
||||
@config.expect.includes.returns(["ConfigRequiredHeader1.h","ConfigRequiredHeader2.h"])
|
||||
#@config.expect.includes_h_pre_orig_header.returns(nil) #not called because includes called
|
||||
@config.expect.includes_h_post_orig_header.returns(nil)
|
||||
@config.expect.includes_c_pre_header.returns(nil)
|
||||
@config.expect.includes_c_post_header.returns(nil)
|
||||
@config.expect :mock_prefix, "Mock"
|
||||
@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
|
||||
@cmock_generator = CMockGenerator.new(@config, @file_writer, @utils, @plugins)
|
||||
@cmock_generator.module_name = @module_name
|
||||
@cmock_generator.mock_name = "Mock#{@module_name}"
|
||||
@cmock_generator.clean_mock_name = "Mock#{@module_name}"
|
||||
|
||||
#strict handling
|
||||
@config.expect.mock_prefix.returns("Mock")
|
||||
@config.expect.enforce_strict_ordering.returns(true)
|
||||
@config.expect.framework.returns(:unity)
|
||||
@config.expect.includes.returns(nil)
|
||||
@config.expect.includes_h_pre_orig_header.returns(nil)
|
||||
@config.expect.includes_h_post_orig_header.returns(nil)
|
||||
@config.expect.includes_c_pre_header.returns(nil)
|
||||
@config.expect.includes_c_post_header.returns(nil)
|
||||
@config.expect :mock_prefix, "Mock"
|
||||
@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
|
||||
@cmock_generator_strict = CMockGenerator.new(@config, @file_writer, @utils, @plugins)
|
||||
@cmock_generator_strict.module_name = @module_name
|
||||
@cmock_generator_strict.mock_name = "Mock#{@module_name}"
|
||||
@cmock_generator_strict.clean_mock_name = "Mock#{@module_name}"
|
||||
end
|
||||
|
||||
def teardown
|
||||
after do
|
||||
end
|
||||
|
||||
should "have set up internal accessors correctly on init" do
|
||||
assert_equal(@config, @cmock_generator.config)
|
||||
assert_equal(@file_writer, @cmock_generator.file_writer)
|
||||
assert_equal(@utils, @cmock_generator.utils)
|
||||
assert_equal(@plugins, @cmock_generator.plugins)
|
||||
end
|
||||
|
||||
should "create the top of a header file with optional include files from config and include file from plugin" do
|
||||
@config.expect.mock_prefix.returns("Mock")
|
||||
it "create the top of a header file with optional include files from config and include file from plugin" do
|
||||
@config.expect :mock_prefix, "Mock"
|
||||
orig_filename = "PoutPoutFish.h"
|
||||
define_name = "MOCKPOUTPOUTFISH_H"
|
||||
mock_name = "MockPoutPoutFish"
|
||||
@@ -103,29 +97,29 @@ class CMockGeneratorTest < Test::Unit::TestCase
|
||||
"\n",
|
||||
]
|
||||
|
||||
@config.expect.orig_header_include_fmt.returns("#include \"%s\"")
|
||||
@plugins.expect.run(:include_files).returns("#include \"PluginRequiredHeader.h\"\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
|
||||
|
||||
should "handle dashes and spaces in the module name" do
|
||||
it "handle dashes and spaces in the module name" do
|
||||
#no strict handling
|
||||
@config.expect.mock_prefix.returns("Mock")
|
||||
@config.expect.enforce_strict_ordering.returns(nil)
|
||||
@config.expect.framework.returns(:unity)
|
||||
@config.expect.includes.returns(["ConfigRequiredHeader1.h","ConfigRequiredHeader2.h"])
|
||||
@config.expect.includes_h_post_orig_header.returns(nil)
|
||||
@config.expect.includes_c_pre_header.returns(nil)
|
||||
@config.expect.includes_c_post_header.returns(nil)
|
||||
@config.expect :mock_prefix, "Mock"
|
||||
@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
|
||||
@cmock_generator2 = CMockGenerator.new(@config, @file_writer, @utils, @plugins)
|
||||
@cmock_generator2.module_name = "Pout-Pout Fish"
|
||||
@cmock_generator2.mock_name = "MockPout-Pout Fish"
|
||||
@cmock_generator2.clean_mock_name = "MockPout_Pout_Fish"
|
||||
|
||||
@config.expect.mock_prefix.returns("Mock")
|
||||
@config.expect :mock_prefix, "Mock"
|
||||
orig_filename = "Pout-Pout Fish.h"
|
||||
define_name = "MOCKPOUT_POUT_FISH_H"
|
||||
mock_name = "MockPout_Pout_Fish"
|
||||
@@ -148,16 +142,16 @@ class CMockGeneratorTest < Test::Unit::TestCase
|
||||
"\n",
|
||||
]
|
||||
|
||||
@config.expect.orig_header_include_fmt.returns("#include \"%s\"")
|
||||
@plugins.expect.run(:include_files).returns("#include \"PluginRequiredHeader.h\"\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
|
||||
|
||||
should "create the top of a header file with optional include files from config" do
|
||||
@config.expect.mock_prefix.returns("Mock")
|
||||
it "create the top of a header file with optional include files from config" do
|
||||
@config.expect :mock_prefix, "Mock"
|
||||
orig_filename = "PoutPoutFish.h"
|
||||
define_name = "MOCKPOUTPOUTFISH_H"
|
||||
mock_name = "MockPoutPoutFish"
|
||||
@@ -179,16 +173,16 @@ class CMockGeneratorTest < Test::Unit::TestCase
|
||||
"\n",
|
||||
]
|
||||
|
||||
@config.expect.orig_header_include_fmt.returns("#include \"%s\"")
|
||||
@plugins.expect.run(:include_files).returns('')
|
||||
@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
|
||||
|
||||
should "create the top of a header file with include file from plugin" do
|
||||
@config.expect.mock_prefix.returns("Mock")
|
||||
it "create the top of a header file with include file from plugin" do
|
||||
@config.expect :mock_prefix, "Mock"
|
||||
orig_filename = "PoutPoutFish.h"
|
||||
define_name = "MOCKPOUTPOUTFISH_H"
|
||||
mock_name = "MockPoutPoutFish"
|
||||
@@ -211,15 +205,15 @@ class CMockGeneratorTest < Test::Unit::TestCase
|
||||
"\n",
|
||||
]
|
||||
|
||||
@config.expect.orig_header_include_fmt.returns("#include \"%s\"")
|
||||
@plugins.expect.run(:include_files).returns("#include \"PluginRequiredHeader.h\"\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
|
||||
|
||||
should "write typedefs" do
|
||||
it "write typedefs" do
|
||||
typedefs = [ 'typedef unsigned char U8;',
|
||||
'typedef char S8;',
|
||||
'typedef unsigned long U32;'
|
||||
@@ -237,7 +231,7 @@ class CMockGeneratorTest < Test::Unit::TestCase
|
||||
assert_equal(expected, output.flatten)
|
||||
end
|
||||
|
||||
should "create the header file service call declarations" do
|
||||
it "create the header file service call declarations" do
|
||||
mock_name = "MockPoutPoutFish"
|
||||
|
||||
output = []
|
||||
@@ -251,7 +245,7 @@ class CMockGeneratorTest < Test::Unit::TestCase
|
||||
assert_equal(expected, output)
|
||||
end
|
||||
|
||||
should "append the proper footer to the header file" do
|
||||
it "append the proper footer to the header file" do
|
||||
output = []
|
||||
expected = ["\n#endif\n"]
|
||||
|
||||
@@ -260,7 +254,7 @@ class CMockGeneratorTest < Test::Unit::TestCase
|
||||
assert_equal(expected, output)
|
||||
end
|
||||
|
||||
should "create a proper heading for a source file" do
|
||||
it "create a proper heading for a source file" do
|
||||
output = []
|
||||
expected = [ "/* AUTOGENERATED FILE. DO NOT EDIT. */\n",
|
||||
"#include <string.h>\n",
|
||||
@@ -277,7 +271,7 @@ class CMockGeneratorTest < Test::Unit::TestCase
|
||||
assert_equal(expected, output)
|
||||
end
|
||||
|
||||
should "create the instance structure where it is needed when no functions" do
|
||||
it "create the instance structure where it is needed when no functions" do
|
||||
output = []
|
||||
functions = []
|
||||
expected = [ "static struct MockPoutPoutFishInstance\n",
|
||||
@@ -291,7 +285,7 @@ class CMockGeneratorTest < Test::Unit::TestCase
|
||||
assert_equal(expected, output.join)
|
||||
end
|
||||
|
||||
should "create the instance structure where it is needed when functions required" do
|
||||
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] }
|
||||
@@ -310,18 +304,18 @@ class CMockGeneratorTest < Test::Unit::TestCase
|
||||
" CMOCK_MEM_INDEX_TYPE Second_CallInstance;\n",
|
||||
"} Mock;\n\n"
|
||||
].join
|
||||
@plugins.expect.run(:instance_typedefs, functions[0]).returns([" b1"," b2"])
|
||||
@plugins.expect.run(:instance_typedefs, functions[1]).returns([])
|
||||
@plugins.expect :run, [" b1"," b2"], [:instance_typedefs, functions[0]]
|
||||
@plugins.expect :run, [], [:instance_typedefs, functions[1]]
|
||||
|
||||
@plugins.expect.run(:instance_structure, functions[0]).returns([" d1"])
|
||||
@plugins.expect.run(:instance_structure, functions[1]).returns([" e1"," e2"," e3"])
|
||||
@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
|
||||
|
||||
should "create extern declarations for source file" do
|
||||
it "create extern declarations for source file" do
|
||||
output = []
|
||||
expected = [ "extern jmp_buf AbortFrame;\n",
|
||||
"\n" ]
|
||||
@@ -331,7 +325,7 @@ class CMockGeneratorTest < Test::Unit::TestCase
|
||||
assert_equal(expected, output.flatten)
|
||||
end
|
||||
|
||||
should "create extern declarations for source file when using strict ordering" do
|
||||
it "create extern declarations for source file when using strict ordering" do
|
||||
output = []
|
||||
expected = [ "extern jmp_buf AbortFrame;\n",
|
||||
"extern int GlobalExpectCount;\n",
|
||||
@@ -343,7 +337,7 @@ class CMockGeneratorTest < Test::Unit::TestCase
|
||||
assert_equal(expected, output.flatten)
|
||||
end
|
||||
|
||||
should "create mock verify functions in source file when no functions specified" do
|
||||
it "create mock verify functions in source file when no functions specified" do
|
||||
functions = []
|
||||
output = []
|
||||
expected = "void MockPoutPoutFish_Verify(void)\n{\n}\n\n"
|
||||
@@ -353,7 +347,7 @@ class CMockGeneratorTest < Test::Unit::TestCase
|
||||
assert_equal(expected, output.join)
|
||||
end
|
||||
|
||||
should "create mock verify functions in source file when extra functions specified" do
|
||||
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] }
|
||||
]
|
||||
@@ -366,8 +360,8 @@ class CMockGeneratorTest < Test::Unit::TestCase
|
||||
" Dos_Second",
|
||||
"}\n\n"
|
||||
]
|
||||
@plugins.expect.run(:mock_verify, functions[0]).returns([" Uno_First"," Dos_First"])
|
||||
@plugins.expect.run(:mock_verify, functions[1]).returns([" Uno_Second"," Dos_Second"])
|
||||
@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)
|
||||
@@ -375,7 +369,7 @@ class CMockGeneratorTest < Test::Unit::TestCase
|
||||
assert_equal(expected, output.flatten)
|
||||
end
|
||||
|
||||
should "create mock init functions in source file" do
|
||||
it "create mock init functions in source file" do
|
||||
output = []
|
||||
expected = [ "void MockPoutPoutFish_Init(void)\n{\n",
|
||||
" MockPoutPoutFish_Destroy();\n",
|
||||
@@ -387,7 +381,7 @@ class CMockGeneratorTest < Test::Unit::TestCase
|
||||
assert_equal(expected.join, output.join)
|
||||
end
|
||||
|
||||
should "create mock destroy functions in source file" do
|
||||
it "create mock destroy functions in source file" do
|
||||
functions = []
|
||||
output = []
|
||||
expected = [ "void MockPoutPoutFish_Destroy(void)\n{\n",
|
||||
@@ -401,7 +395,7 @@ class CMockGeneratorTest < Test::Unit::TestCase
|
||||
assert_equal(expected.join, output.join)
|
||||
end
|
||||
|
||||
should "create mock destroy functions in source file when specified with strict ordering" do
|
||||
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] }
|
||||
]
|
||||
@@ -414,15 +408,15 @@ class CMockGeneratorTest < Test::Unit::TestCase
|
||||
" GlobalVerifyOrder = 0;\n",
|
||||
"}\n\n"
|
||||
]
|
||||
@plugins.expect.run(:mock_destroy, functions[0]).returns([])
|
||||
@plugins.expect.run(:mock_destroy, functions[1]).returns([" uno"])
|
||||
@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
|
||||
|
||||
should "create mock implementation functions in source file" do
|
||||
it "create mock implementation functions in source file" do
|
||||
function = { :modifier => "static",
|
||||
:return => test_return[:int],
|
||||
:args_string => "uint32 sandwiches, const char* named",
|
||||
@@ -445,15 +439,15 @@ class CMockGeneratorTest < Test::Unit::TestCase
|
||||
" return cmock_call_instance->ReturnVal;\n",
|
||||
"}\n\n"
|
||||
]
|
||||
@plugins.expect.run(:mock_implementation_precheck, function).returns([" uno"])
|
||||
@plugins.expect.run(:mock_implementation, function).returns([" dos"," tres"])
|
||||
@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
|
||||
|
||||
should "create mock implementation functions in source file with different options" do
|
||||
it "create mock implementation functions in source file with different options" do
|
||||
function = { :modifier => "",
|
||||
:c_calling_convention => "__stdcall",
|
||||
:return => test_return[:int],
|
||||
@@ -477,8 +471,8 @@ class CMockGeneratorTest < Test::Unit::TestCase
|
||||
" return cmock_call_instance->ReturnVal;\n",
|
||||
"}\n\n"
|
||||
]
|
||||
@plugins.expect.run(:mock_implementation_precheck, function).returns([" uno"])
|
||||
@plugins.expect.run(:mock_implementation, function).returns([" dos"," tres"])
|
||||
@plugins.expect :run, [" uno"], [:mock_implementation_precheck, function]
|
||||
@plugins.expect :run, [" dos"," tres"], [:mock_implementation, function]
|
||||
|
||||
@cmock_generator.create_mock_implementation(output, function)
|
||||
|
||||
|
||||
@@ -2,104 +2,107 @@
|
||||
# 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 'cmock_generator_plugin_array'
|
||||
|
||||
class CMockGeneratorPluginArrayTest < Test::Unit::TestCase
|
||||
def setup
|
||||
create_mocks :config, :utils
|
||||
|
||||
describe CMockGeneratorPluginArray, "Verify CMockPGeneratorluginArray Module" do
|
||||
before do
|
||||
create_mocks :utils
|
||||
|
||||
#no strict ordering
|
||||
@config.expect.when_ptr.returns(:compare_data)
|
||||
@config.expect.enforce_strict_ordering.returns(false)
|
||||
@config.stubs!(:respond_to?).returns(true)
|
||||
@utils.expect.helpers.returns({})
|
||||
@config = create_stub(
|
||||
:when_ptr => :compare_data,
|
||||
:enforce_strict_ordering => false,
|
||||
:respond_to? => true )
|
||||
|
||||
@utils = create_stub(
|
||||
:helpers => {},
|
||||
:code_add_base_expectation => "mock_retval_0"
|
||||
)
|
||||
|
||||
@cmock_generator_plugin_array = CMockGeneratorPluginArray.new(@config, @utils)
|
||||
end
|
||||
|
||||
def teardown
|
||||
after do
|
||||
end
|
||||
|
||||
should "have set up internal accessors correctly on init" do
|
||||
assert_equal(@config, @cmock_generator_plugin_array.config)
|
||||
assert_equal(@utils, @cmock_generator_plugin_array.utils)
|
||||
|
||||
it "have set up internal priority" do
|
||||
assert_equal(nil, @cmock_generator_plugin_array.unity_helper)
|
||||
assert_equal(8, @cmock_generator_plugin_array.priority)
|
||||
end
|
||||
|
||||
should "not include any additional include files" do
|
||||
|
||||
it "not include any additional include files" do
|
||||
assert(!@cmock_generator_plugin_array.respond_to?(:include_files))
|
||||
end
|
||||
|
||||
should "not add to typedef structure for functions of style 'int* func(void)'" do
|
||||
|
||||
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
|
||||
|
||||
should "add to tyepdef structure mock needs of functions of style 'void func(int chicken, int* pork)'" do
|
||||
|
||||
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
|
||||
|
||||
should "not add an additional mock interface for functions not containing pointers" do
|
||||
|
||||
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
|
||||
|
||||
should "add another mock function declaration for functions of style 'void func(int* tofu)'" do
|
||||
function = {:name => "Pine",
|
||||
|
||||
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],
|
||||
: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
|
||||
|
||||
should "add another mock function declaration for functions of style 'const char* func(int* tofu)'" do
|
||||
function = {:name => "Pine",
|
||||
|
||||
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
|
||||
|
||||
should "not have a mock function implementation" do
|
||||
|
||||
it "not have a mock function implementation" do
|
||||
assert(!@cmock_generator_plugin_array.respond_to?(:mock_implementation))
|
||||
end
|
||||
|
||||
should "not have a mock interfaces for functions of style 'int* func(void)'" do
|
||||
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
|
||||
|
||||
should "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],
|
||||
|
||||
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 }
|
||||
@utils.expect.code_add_base_expectation("Lemon").returns("mock_retval_0")
|
||||
|
||||
|
||||
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",
|
||||
@@ -110,5 +113,5 @@ class CMockGeneratorPluginArrayTest < Test::Unit::TestCase
|
||||
returned = @cmock_generator_plugin_array.mock_interfaces(function).join
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
@@ -2,51 +2,50 @@
|
||||
# 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 'cmock_generator_plugin_callback'
|
||||
|
||||
class CMockGeneratorPluginCallbackTest < Test::Unit::TestCase
|
||||
def setup
|
||||
describe CMockGeneratorPluginCallback, "Verify CMockGeneratorPluginCallback Module" do
|
||||
|
||||
before do
|
||||
create_mocks :config, :utils
|
||||
|
||||
@config.expect.callback_include_count.returns(true)
|
||||
@config.expect.callback_after_arg_check.returns(false)
|
||||
|
||||
|
||||
@config.expect :callback_include_count, true
|
||||
@config.expect :callback_after_arg_check, false
|
||||
|
||||
@cmock_generator_plugin_callback = CMockGeneratorPluginCallback.new(@config, @utils)
|
||||
end
|
||||
|
||||
def teardown
|
||||
after do
|
||||
end
|
||||
|
||||
should "have set up internal accessors correctly on init" do
|
||||
assert_equal(@config, @cmock_generator_plugin_callback.config)
|
||||
assert_equal(@utils, @cmock_generator_plugin_callback.utils)
|
||||
assert_equal(6, @cmock_generator_plugin_callback.priority)
|
||||
|
||||
it "have set up internal priority" do
|
||||
assert_equal(6, @cmock_generator_plugin_callback.priority)
|
||||
end
|
||||
|
||||
should "not include any additional include files" do
|
||||
|
||||
it "not include any additional include files" do
|
||||
assert(!@cmock_generator_plugin_callback.respond_to?(:include_files))
|
||||
end
|
||||
|
||||
should "add to instance structure" do
|
||||
|
||||
it "add to instance structure" do
|
||||
function = {:name => "Oak", :args => [:type => "int*", :name => "blah", :ptr? => true], :return => test_return[:int_ptr]}
|
||||
expected = " CMOCK_Oak_CALLBACK Oak_CallbackFunctionPointer;\n" +
|
||||
" int Oak_CallbackCalls;\n"
|
||||
returned = @cmock_generator_plugin_callback.instance_structure(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
should "add mock function declaration for function without arguments" do
|
||||
|
||||
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_StubWithCallback(CMOCK_Maple_CALLBACK Callback);\n" ].join
|
||||
returned = @cmock_generator_plugin_callback.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
should "add mock function declaration for function without arguments when count is also turned off" do
|
||||
|
||||
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_StubWithCallback(CMOCK_Maple_CALLBACK Callback);\n" ].join
|
||||
@@ -54,24 +53,24 @@ class CMockGeneratorPluginCallbackTest < Test::Unit::TestCase
|
||||
returned = @cmock_generator_plugin_callback.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
should "add mock function declaration for function with arguments" do
|
||||
|
||||
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_StubWithCallback(CMOCK_Maple_CALLBACK Callback);\n" ].join
|
||||
returned = @cmock_generator_plugin_callback.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
should "add mock function declaration for function with return values" do
|
||||
|
||||
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_StubWithCallback(CMOCK_Maple_CALLBACK Callback);\n" ].join
|
||||
returned = @cmock_generator_plugin_callback.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
should "add mock function declaration for function with return values and count is turned off" do
|
||||
|
||||
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_StubWithCallback(CMOCK_Maple_CALLBACK Callback);\n" ].join
|
||||
@@ -80,7 +79,7 @@ class CMockGeneratorPluginCallbackTest < Test::Unit::TestCase
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
should "add mock function implementation for functions of style 'void func(void)'" do
|
||||
it "add mock function implementation for functions 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",
|
||||
@@ -92,7 +91,7 @@ class CMockGeneratorPluginCallbackTest < Test::Unit::TestCase
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
should "add mock function implementation for functions of style 'void func(void)' when count turned off" do
|
||||
it "add mock function implementation for functions 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",
|
||||
@@ -105,7 +104,7 @@ class CMockGeneratorPluginCallbackTest < Test::Unit::TestCase
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
should "add mock function implementation for functions of style 'int func(void)'" do
|
||||
it "add mock function implementation for functions 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",
|
||||
@@ -116,10 +115,10 @@ class CMockGeneratorPluginCallbackTest < Test::Unit::TestCase
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
should "add mock function implementation for functions of style 'void func(int* steak, uint8_t flag)'" do
|
||||
function = {:name => "Apple",
|
||||
it "add mock function implementation for functions 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} ],
|
||||
{ :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",
|
||||
@@ -132,10 +131,10 @@ class CMockGeneratorPluginCallbackTest < Test::Unit::TestCase
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
should "add mock function implementation for functions of style 'void func(int* steak, uint8_t flag)' when count turned off" do
|
||||
function = {:name => "Apple",
|
||||
it "add mock function implementation for functions 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} ],
|
||||
{ :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",
|
||||
@@ -149,11 +148,11 @@ class CMockGeneratorPluginCallbackTest < Test::Unit::TestCase
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
should "add mock function implementation for functions of style 'int16_t func(int* steak, uint8_t flag)'" do
|
||||
function = {:name => "Apple",
|
||||
it "add mock function implementation for functions 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",
|
||||
:args_string => "int* steak, uint8_t flag",
|
||||
:return => test_return[:int]}
|
||||
expected = [" if (Mock.Apple_CallbackFunctionPointer != NULL)\n",
|
||||
" {\n",
|
||||
@@ -163,14 +162,14 @@ class CMockGeneratorPluginCallbackTest < Test::Unit::TestCase
|
||||
returned = @cmock_generator_plugin_callback.mock_implementation_precheck(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
should "add mock interfaces for functions " do
|
||||
function = {:name => "Lemon",
|
||||
:args => [{ :type => "char*", :name => "pescado"}],
|
||||
|
||||
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_StubWithCallback(CMOCK_Lemon_CALLBACK Callback)\n",
|
||||
"{\n",
|
||||
" Mock.Lemon_CallbackFunctionPointer = Callback;\n",
|
||||
@@ -180,7 +179,7 @@ class CMockGeneratorPluginCallbackTest < Test::Unit::TestCase
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
should "add mock destroy for functions" do
|
||||
it "add mock destroy for functions" do
|
||||
function = {:name => "Peach", :args => [], :return => test_return[:void] }
|
||||
expected = " Mock.Peach_CallbackFunctionPointer = NULL;\n" +
|
||||
" Mock.Peach_CallbackCalls = 0;\n"
|
||||
|
||||
@@ -2,68 +2,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 'cmock_generator_plugin_cexception'
|
||||
|
||||
class CMockGeneratorPluginCexceptionTest < Test::Unit::TestCase
|
||||
def setup
|
||||
describe CMockGeneratorPluginCexception, "Verify CMockGeneratorPluginCexception Module" do
|
||||
|
||||
before do
|
||||
create_mocks :config, :utils
|
||||
@cmock_generator_plugin_cexception = CMockGeneratorPluginCexception.new(@config, @utils)
|
||||
end
|
||||
|
||||
def teardown
|
||||
after do
|
||||
end
|
||||
|
||||
should "have set up internal accessors correctly on init" do
|
||||
assert_equal(@config, @cmock_generator_plugin_cexception.config)
|
||||
assert_equal(@utils, @cmock_generator_plugin_cexception.utils)
|
||||
assert_equal(7, @cmock_generator_plugin_cexception.priority)
|
||||
|
||||
it "have set up internal priority" do
|
||||
assert_equal(7, @cmock_generator_plugin_cexception.priority)
|
||||
end
|
||||
|
||||
should "include the cexception library" do
|
||||
|
||||
it "include the cexception library" do
|
||||
expected = "#include \"CException.h\"\n"
|
||||
returned = @cmock_generator_plugin_cexception.include_files
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
should "add to typedef structure mock needs" do
|
||||
|
||||
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
|
||||
|
||||
should "add mock function declarations for functions without arguments" do
|
||||
|
||||
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
|
||||
|
||||
should "add mock function declarations for functions with arguments" do
|
||||
|
||||
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
|
||||
|
||||
should "add a mock implementation" do
|
||||
|
||||
it "add a mock implementation" do
|
||||
function = {:name => "Cherry", :args => [], :return => test_return[:void]}
|
||||
expected = " if (cmock_call_instance->ExceptionToThrow != CEXCEPTION_NONE)\n {\n" +
|
||||
expected = " if (cmock_call_instance->ExceptionToThrow != CEXCEPTION_NONE)\n {\n" +
|
||||
" Throw(cmock_call_instance->ExceptionToThrow);\n }\n"
|
||||
returned = @cmock_generator_plugin_cexception.mock_implementation(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
should "add mock interfaces for functions without arguments" do
|
||||
|
||||
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("Pear").returns("mock_retval_0")
|
||||
@utils.expect.code_call_argument_loader(function).returns("")
|
||||
|
||||
@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",
|
||||
@@ -74,12 +73,12 @@ class CMockGeneratorPluginCexceptionTest < Test::Unit::TestCase
|
||||
returned = @cmock_generator_plugin_cexception.mock_interfaces(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
should "add a mock interfaces for functions with arguments" do
|
||||
|
||||
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("Pear").returns("mock_retval_0")
|
||||
@utils.expect.code_call_argument_loader(function).returns("mock_return_1")
|
||||
|
||||
@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",
|
||||
@@ -90,5 +89,5 @@ class CMockGeneratorPluginCexceptionTest < Test::Unit::TestCase
|
||||
returned = @cmock_generator_plugin_cexception.mock_interfaces(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
@@ -7,34 +7,33 @@
|
||||
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
|
||||
require 'cmock_generator_plugin_expect_any_args.rb'
|
||||
|
||||
class CMockGeneratorPluginExpectAnyArgsTest < Test::Unit::TestCase
|
||||
def setup
|
||||
describe CMockGeneratorPluginExpectAnyArgs, "Verify CMockGeneratorPluginExpectAnyArgs Module" do
|
||||
|
||||
before do
|
||||
create_mocks :config, :utils
|
||||
@config.stubs!(:respond_to?).returns(true)
|
||||
@config = create_stub(:respond_to? => true)
|
||||
@cmock_generator_plugin_expect_any_args = CMockGeneratorPluginExpectAnyArgs.new(@config, @utils)
|
||||
end
|
||||
|
||||
def teardown
|
||||
after do
|
||||
end
|
||||
|
||||
should "have set up internal accessors correctly on init" do
|
||||
assert_equal(@config, @cmock_generator_plugin_expect_any_args.config)
|
||||
assert_equal(@utils, @cmock_generator_plugin_expect_any_args.utils)
|
||||
assert_equal(3, @cmock_generator_plugin_expect_any_args.priority)
|
||||
it "have set up internal priority" do
|
||||
assert_equal(3, @cmock_generator_plugin_expect_any_args.priority)
|
||||
end
|
||||
|
||||
should "not have any additional include file requirements" do
|
||||
it "not have any additional include file requirements" do
|
||||
assert(!@cmock_generator_plugin_expect_any_args.respond_to?(:include_files))
|
||||
end
|
||||
|
||||
should "handle function declarations for functions without return values" do
|
||||
it "handle function declarations for functions without return values" do
|
||||
function = {:name => "Mold", :args_string => "void", :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
|
||||
|
||||
should "handle function declarations for functions that returns something" do
|
||||
it "handle function declarations for functions that returns something" do
|
||||
function = {:name => "Fungus", :args_string => "void", :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"
|
||||
@@ -42,7 +41,7 @@ class CMockGeneratorPluginExpectAnyArgsTest < Test::Unit::TestCase
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
should "add required code to implementation with void function" do
|
||||
it "add required code to implementation with void function" do
|
||||
function = {:name => "Mold", :args_string => "void", :return => test_return[:void]}
|
||||
expected = [" if (cmock_call_instance->IgnoreMode == CMOCK_ARG_NONE)\n",
|
||||
" {\n",
|
||||
@@ -53,10 +52,10 @@ class CMockGeneratorPluginExpectAnyArgsTest < Test::Unit::TestCase
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
should "add required code to implementation with return functions" do
|
||||
it "add required code to implementation 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.Fungus_FinalReturn", retval).returns(' mock_retval_0')
|
||||
@utils.expect :code_assign_argument_quickly, ' mock_retval_0', ["Mock.Fungus_FinalReturn", retval]
|
||||
expected = [" if (cmock_call_instance->IgnoreMode == CMOCK_ARG_NONE)\n",
|
||||
" {\n",
|
||||
" mock_retval_0",
|
||||
@@ -67,7 +66,7 @@ class CMockGeneratorPluginExpectAnyArgsTest < Test::Unit::TestCase
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
should "add a new mock interface for ignoring when function had no return value" do
|
||||
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_CMockExpectAnyArgs(UNITY_LINE_TYPE cmock_line)\n",
|
||||
"{\n",
|
||||
@@ -75,7 +74,7 @@ class CMockGeneratorPluginExpectAnyArgsTest < Test::Unit::TestCase
|
||||
" cmock_call_instance->IgnoreMode = CMOCK_ARG_NONE;\n",
|
||||
"}\n\n"
|
||||
].join
|
||||
@utils.expect.code_add_base_expectation("Slime", true).returns("mock_return_1")
|
||||
@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
|
||||
|
||||
@@ -2,143 +2,142 @@
|
||||
# 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 'cmock_generator_plugin_expect'
|
||||
|
||||
class CMockGeneratorPluginExpectTest < Test::Unit::TestCase
|
||||
def setup
|
||||
describe CMockGeneratorPluginExpect, "Verify CMockGeneratorPluginExpect Module" do
|
||||
|
||||
before do
|
||||
create_mocks :config, :utils
|
||||
|
||||
#no strict ordering and args_and_calls
|
||||
@config.expect.when_ptr.returns(:compare_data)
|
||||
@config.expect.enforce_strict_ordering.returns(false)
|
||||
@config.stubs!(:respond_to?).returns(true)
|
||||
# @config.expect.ignore.returns(:args_and_calls)
|
||||
@utils.expect.helpers.returns({})
|
||||
|
||||
@config = create_stub(
|
||||
:when_ptr => :compare_data,
|
||||
:enforce_strict_ordering => false,
|
||||
:respond_to? => true )
|
||||
|
||||
@utils.expect :helpers, {}
|
||||
@cmock_generator_plugin_expect = CMockGeneratorPluginExpect.new(@config, @utils)
|
||||
|
||||
#strict ordering and args_only
|
||||
@config.expect.when_ptr.returns(:compare_data)
|
||||
@config.expect.enforce_strict_ordering.returns(true)
|
||||
@config.stubs!(:respond_to?).returns(true)
|
||||
# @config.expect.ignore.returns(:args_only)
|
||||
@utils.expect.helpers.returns({})
|
||||
@cmock_generator_plugin_expect_strict = CMockGeneratorPluginExpect.new(@config, @utils)
|
||||
|
||||
@config_strict = create_stub(
|
||||
:when_ptr => :compare_data,
|
||||
:enforce_strict_ordering => true,
|
||||
:respond_to? => true )
|
||||
|
||||
@utils.expect :helpers, {}
|
||||
@cmock_generator_plugin_expect_strict = CMockGeneratorPluginExpect.new(@config_strict, @utils)
|
||||
end
|
||||
|
||||
def teardown
|
||||
after do
|
||||
end
|
||||
|
||||
should "have set up internal accessors correctly on init" do
|
||||
assert_equal(@config, @cmock_generator_plugin_expect.config)
|
||||
assert_equal(@utils, @cmock_generator_plugin_expect.utils)
|
||||
|
||||
it "have set up internal priority on init" do
|
||||
assert_equal(nil, @cmock_generator_plugin_expect.unity_helper)
|
||||
assert_equal(5, @cmock_generator_plugin_expect.priority)
|
||||
end
|
||||
|
||||
should "not include any additional include files" do
|
||||
|
||||
it "not include any additional include files" do
|
||||
assert(!@cmock_generator_plugin_expect.respond_to?(:include_files))
|
||||
end
|
||||
|
||||
should "add to typedef structure mock needs of functions of style 'void func(void)'" do
|
||||
|
||||
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
|
||||
|
||||
should "add to typedef structure mock needs of functions of style 'int func(void)'" do
|
||||
|
||||
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
|
||||
|
||||
should "add to typedef structure mock needs of functions of style 'void func(int chicken, char* pork)'" do
|
||||
|
||||
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
|
||||
|
||||
should "add to typedef structure mock needs of functions of style 'int func(float beef)'" do
|
||||
|
||||
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
|
||||
|
||||
should "add to typedef structure mock needs of functions of style 'void func(void)' and global ordering" do
|
||||
|
||||
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_strict.instance_typedefs(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
should "add mock function declaration for functions of style 'void func(void)'" do
|
||||
|
||||
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
|
||||
|
||||
should "add mock function declaration for functions of style 'int func(void)'" do
|
||||
|
||||
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
|
||||
|
||||
should "add mock function declaration for functions of style 'const char* func(int tofu)'" do
|
||||
|
||||
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
|
||||
|
||||
should "add mock function implementation for functions of style 'void func(void)'" do
|
||||
|
||||
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
|
||||
|
||||
should "add mock function implementation for functions of style 'int func(int veal, unsigned int sushi)'" do
|
||||
|
||||
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(function, function[:args][0]).returns(" mocked_retval_1")
|
||||
@utils.expect.code_verify_an_arg_expectation(function, function[:args][1]).returns(" mocked_retval_2")
|
||||
|
||||
@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
|
||||
|
||||
should "add mock function implementation using ordering if needed" do
|
||||
|
||||
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
|
||||
|
||||
should "add mock function implementation for functions of style 'void func(int worm)' and strict ordering" do
|
||||
|
||||
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(function, function[:args][0]).returns("mocked_retval_0")
|
||||
@utils.expect :code_verify_an_arg_expectation, "mocked_retval_0", [function, function[:args][0]]
|
||||
expected = "mocked_retval_0"
|
||||
@cmock_generator_plugin_expect.ordered = true
|
||||
returned = @cmock_generator_plugin_expect_strict.mock_implementation(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
should "add mock interfaces for functions of style 'void func(void)'" do
|
||||
|
||||
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("Pear").returns("mock_retval_0 ")
|
||||
@utils.expect.code_call_argument_loader(function).returns("mock_retval_1 ")
|
||||
@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 ",
|
||||
@@ -148,12 +147,12 @@ class CMockGeneratorPluginExpectTest < Test::Unit::TestCase
|
||||
returned = @cmock_generator_plugin_expect.mock_interfaces(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
should "add mock interfaces for functions of style 'int func(void)'" do
|
||||
|
||||
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("Orange").returns("mock_retval_0 ")
|
||||
@utils.expect.code_call_argument_loader(function).returns("mock_retval_1 ")
|
||||
@utils.expect.code_assign_argument_quickly("cmock_call_instance->ReturnVal", function[:return]).returns("mock_retval_2")
|
||||
@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 ",
|
||||
@@ -164,12 +163,12 @@ class CMockGeneratorPluginExpectTest < Test::Unit::TestCase
|
||||
returned = @cmock_generator_plugin_expect.mock_interfaces(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
should "add mock interfaces for functions of style 'int func(char* pescado)'" do
|
||||
|
||||
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("Lemon").returns("mock_retval_0 ")
|
||||
@utils.expect.code_call_argument_loader(function).returns("mock_retval_1 ")
|
||||
@utils.expect.code_assign_argument_quickly("cmock_call_instance->ReturnVal", function[:return]).returns("mock_retval_2")
|
||||
@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 ",
|
||||
@@ -180,11 +179,11 @@ class CMockGeneratorPluginExpectTest < Test::Unit::TestCase
|
||||
returned = @cmock_generator_plugin_expect.mock_interfaces(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
should "add mock interfaces for functions when using ordering" do
|
||||
|
||||
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("Pear").returns("mock_retval_0 ")
|
||||
@utils.expect.code_call_argument_loader(function).returns("mock_retval_1 ")
|
||||
@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 ",
|
||||
@@ -195,12 +194,12 @@ class CMockGeneratorPluginExpectTest < Test::Unit::TestCase
|
||||
returned = @cmock_generator_plugin_expect.mock_interfaces(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
should "add mock verify lines" do
|
||||
|
||||
it "add mock verify lines" do
|
||||
function = {:name => "Banana" }
|
||||
expected = " UNITY_TEST_ASSERT(CMOCK_GUTS_NONE == Mock.Banana_CallInstance, cmock_line, \"Function 'Banana' called less times than expected.\");\n"
|
||||
returned = @cmock_generator_plugin_expect.mock_verify(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
@@ -2,20 +2,21 @@
|
||||
# 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 'cmock_generator_plugin_ignore_arg'
|
||||
|
||||
class CMockGeneratorPluginIgnoreArgTest < Test::Unit::TestCase
|
||||
def setup
|
||||
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",
|
||||
@complex_func = {:name => "Pine",
|
||||
:args => [{ :type => "int",
|
||||
:name => "chicken",
|
||||
:ptr? => false,
|
||||
@@ -29,31 +30,30 @@ class CMockGeneratorPluginIgnoreArgTest < Test::Unit::TestCase
|
||||
:name => "tofu",
|
||||
:ptr? => true,
|
||||
}],
|
||||
:return => test_return[:void],
|
||||
:return => test_return[:void],
|
||||
:contains_ptr? => true }
|
||||
|
||||
#no strict ordering
|
||||
@cmock_generator_plugin_ignore_arg = CMockGeneratorPluginIgnoreArg.new(@config, @utils)
|
||||
end
|
||||
|
||||
def teardown
|
||||
after do
|
||||
end
|
||||
|
||||
should "have set up internal accessors correctly on init" do
|
||||
assert_equal(@utils, @cmock_generator_plugin_ignore_arg.utils)
|
||||
it "have set up internal priority correctly on init" do
|
||||
assert_equal(10, @cmock_generator_plugin_ignore_arg.priority)
|
||||
end
|
||||
|
||||
should "not include any additional include files" do
|
||||
|
||||
it "not include any additional include files" do
|
||||
assert(!@cmock_generator_plugin_ignore_arg.respond_to?(:include_files))
|
||||
end
|
||||
|
||||
should "not add to typedef structure for functions with no args" do
|
||||
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
|
||||
|
||||
should "add to tyepdef structure mock needs of functions of style 'void func(int chicken, int* pork)'" do
|
||||
|
||||
it "add to tyepdef structure mock needs of functions of style 'void func(int chicken, int* pork)'" do
|
||||
expected = " int IgnoreArg_chicken;\n" +
|
||||
" int IgnoreArg_beef;\n" +
|
||||
" int IgnoreArg_tofu;\n"
|
||||
@@ -61,7 +61,7 @@ class CMockGeneratorPluginIgnoreArgTest < Test::Unit::TestCase
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
should "add mock function declarations for all arguments" do
|
||||
it "add mock function declarations for all arguments" do
|
||||
expected =
|
||||
"#define Pine_IgnoreArg_chicken()" +
|
||||
" Pine_CMockIgnoreArg_chicken(__LINE__)\n" +
|
||||
@@ -79,7 +79,7 @@ class CMockGeneratorPluginIgnoreArgTest < Test::Unit::TestCase
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
should "add mock interfaces for all arguments" do
|
||||
it "add mock interfaces for all arguments" do
|
||||
expected =
|
||||
"void Pine_CMockIgnoreArg_chicken(UNITY_LINE_TYPE cmock_line)\n" +
|
||||
"{\n" +
|
||||
@@ -109,7 +109,7 @@ class CMockGeneratorPluginIgnoreArgTest < Test::Unit::TestCase
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
should "not add a mock implementation" do
|
||||
it "not add a mock implementation" do
|
||||
assert(!@cmock_generator_plugin_ignore_arg.respond_to?(:mock_implementation))
|
||||
end
|
||||
|
||||
|
||||
@@ -7,41 +7,40 @@
|
||||
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
|
||||
require 'cmock_generator_plugin_ignore'
|
||||
|
||||
class CMockGeneratorPluginIgnoreTest < Test::Unit::TestCase
|
||||
def setup
|
||||
describe CMockGeneratorPluginIgnore, "Verify CMockGeneratorPluginIgnore Module" do
|
||||
|
||||
before do
|
||||
create_mocks :config, :utils
|
||||
@config.stubs!(:respond_to?).returns(true)
|
||||
@config = create_stub(:respond_to? => true)
|
||||
@cmock_generator_plugin_ignore = CMockGeneratorPluginIgnore.new(@config, @utils)
|
||||
end
|
||||
|
||||
def teardown
|
||||
after do
|
||||
end
|
||||
|
||||
should "have set up internal accessors correctly on init" do
|
||||
assert_equal(@config, @cmock_generator_plugin_ignore.config)
|
||||
assert_equal(@utils, @cmock_generator_plugin_ignore.utils)
|
||||
assert_equal(2, @cmock_generator_plugin_ignore.priority)
|
||||
it "have set up internal priority" do
|
||||
assert_equal(2, @cmock_generator_plugin_ignore.priority)
|
||||
end
|
||||
|
||||
should "not have any additional include file requirements" do
|
||||
it "not have any additional include file requirements" do
|
||||
assert(!@cmock_generator_plugin_ignore.respond_to?(:include_files))
|
||||
end
|
||||
|
||||
should "add a required variable to the instance structure" do
|
||||
it "add a required variable to the instance structure" do
|
||||
function = {:name => "Grass", :args => [], :return => test_return[:void]}
|
||||
expected = " int Grass_IgnoreBool;\n"
|
||||
returned = @cmock_generator_plugin_ignore.instance_structure(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
should "handle function declarations for functions without return values" do
|
||||
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"
|
||||
returned = @cmock_generator_plugin_ignore.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
should "handle function declarations for functions that returns something" do
|
||||
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"
|
||||
@@ -49,7 +48,7 @@ class CMockGeneratorPluginIgnoreTest < Test::Unit::TestCase
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
should "add required code to implementation precheck with void function" do
|
||||
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",
|
||||
@@ -60,10 +59,10 @@ class CMockGeneratorPluginIgnoreTest < Test::Unit::TestCase
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
should "add required code to implementation precheck with return functions" do
|
||||
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.Fungus_FinalReturn", retval).returns(' mock_retval_0')
|
||||
@utils.expect :code_assign_argument_quickly, ' mock_retval_0', ["Mock.Fungus_FinalReturn", retval]
|
||||
expected = [" if (Mock.Fungus_IgnoreBool)\n",
|
||||
" {\n",
|
||||
" if (cmock_call_instance == NULL)\n",
|
||||
@@ -76,7 +75,7 @@ class CMockGeneratorPluginIgnoreTest < Test::Unit::TestCase
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
should "add a new mock interface for ignoring when function had no return value" do
|
||||
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",
|
||||
@@ -87,9 +86,9 @@ class CMockGeneratorPluginIgnoreTest < Test::Unit::TestCase
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
should "add a new mock interface for ignoring when function has return value" do
|
||||
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("Slime", false).returns("mock_return_1")
|
||||
@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",
|
||||
|
||||
@@ -7,8 +7,9 @@
|
||||
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
|
||||
require 'cmock_generator_plugin_return_thru_ptr'
|
||||
|
||||
class CMockGeneratorPluginReturnThruPtrTest < Test::Unit::TestCase
|
||||
def setup
|
||||
describe CMockGeneratorPluginReturnThruPtr, "Verify CMockGeneratorPluginReturnThruPtr Module" do
|
||||
|
||||
before do
|
||||
create_mocks :config, :utils
|
||||
|
||||
# int *Oak(void)"
|
||||
@@ -42,34 +43,33 @@ class CMockGeneratorPluginReturnThruPtrTest < Test::Unit::TestCase
|
||||
@cmock_generator_plugin_return_thru_ptr = CMockGeneratorPluginReturnThruPtr.new(@config, @utils)
|
||||
end
|
||||
|
||||
def teardown
|
||||
after do
|
||||
end
|
||||
|
||||
def simple_func_expect
|
||||
@utils.expect.ptr_or_str?('int').returns(false)
|
||||
@utils.expect :ptr_or_str?, false, ['int']
|
||||
end
|
||||
|
||||
def complex_func_expect
|
||||
@utils.expect.ptr_or_str?('int').returns(false)
|
||||
@utils.expect.ptr_or_str?('int*').returns(true)
|
||||
@utils.expect.ptr_or_str?('int*').returns(true)
|
||||
@utils.expect :ptr_or_str?, false, ['int']
|
||||
@utils.expect :ptr_or_str?, true, ['int*']
|
||||
@utils.expect :ptr_or_str?, true, ['int*']
|
||||
end
|
||||
|
||||
should "have set up internal accessors correctly on init" do
|
||||
assert_equal(@utils, @cmock_generator_plugin_return_thru_ptr.utils)
|
||||
it "have set up internal priority correctly on init" do
|
||||
assert_equal(1, @cmock_generator_plugin_return_thru_ptr.priority)
|
||||
end
|
||||
|
||||
should "not include any additional include files" do
|
||||
it "not include any additional include files" do
|
||||
assert(!@cmock_generator_plugin_return_thru_ptr.respond_to?(:include_files))
|
||||
end
|
||||
|
||||
should "not add to typedef structure for functions of style 'int* func(void)'" do
|
||||
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
|
||||
|
||||
should "add to tyepdef structure mock needs of functions of style 'void func(int chicken, int* pork)'" do
|
||||
it "add to tyepdef structure mock needs of functions of style 'void func(int chicken, int* pork)'" do
|
||||
complex_func_expect()
|
||||
expected = " int ReturnThruPtr_tofu_Used;\n" +
|
||||
" int* ReturnThruPtr_tofu_Val;\n" +
|
||||
@@ -78,13 +78,13 @@ class CMockGeneratorPluginReturnThruPtrTest < Test::Unit::TestCase
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
should "not add an additional mock interface for functions not containing pointers" do
|
||||
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
|
||||
|
||||
should "add a mock function declaration only for non-const pointer arguments" do
|
||||
it "add a mock function declaration only for non-const pointer arguments" do
|
||||
complex_func_expect();
|
||||
|
||||
expected =
|
||||
@@ -100,7 +100,7 @@ class CMockGeneratorPluginReturnThruPtrTest < Test::Unit::TestCase
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
should "add mock interfaces only for non-const pointer arguments" do
|
||||
it "add mock interfaces only for non-const pointer arguments" do
|
||||
complex_func_expect();
|
||||
|
||||
expected =
|
||||
@@ -118,7 +118,7 @@ class CMockGeneratorPluginReturnThruPtrTest < Test::Unit::TestCase
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
should "add mock implementations only for non-const pointer arguments" do
|
||||
it "add mock implementations only for non-const pointer arguments" do
|
||||
complex_func_expect()
|
||||
|
||||
expected =
|
||||
|
||||
@@ -7,57 +7,54 @@
|
||||
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
|
||||
require 'cmock_generator_utils'
|
||||
|
||||
class CMockGeneratorUtilsTest < Test::Unit::TestCase
|
||||
def setup
|
||||
describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do
|
||||
|
||||
before do
|
||||
create_mocks :config, :unity_helper, :unity_helper
|
||||
|
||||
@config.expect.when_ptr.returns(:compare_ptr)
|
||||
@config.expect.enforce_strict_ordering.returns(false)
|
||||
@config.expect.plugins.returns([])
|
||||
@config.expect.plugins.returns([])
|
||||
@config.expect.plugins.returns([])
|
||||
@config.expect.plugins.returns([])
|
||||
@config.expect.plugins.returns([])
|
||||
@config.expect.plugins.returns([])
|
||||
@config.expect.treat_as.returns({'int' => 'INT','short' => 'INT16','long' => 'INT','char' => 'INT8','char*' => 'STRING'})
|
||||
@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','char*' => 'STRING'}
|
||||
@cmock_generator_utils_simple = CMockGeneratorUtils.new(@config, {:unity_helper => @unity_helper})
|
||||
|
||||
@config.expect.when_ptr.returns(:smart)
|
||||
@config.expect.enforce_strict_ordering.returns(true)
|
||||
@config.expect.plugins.returns([:array, :cexception, :return_thru_ptr, :ignore_arg, :ignore])
|
||||
@config.expect.plugins.returns([:array, :cexception, :return_thru_ptr, :ignore_arg, :ignore])
|
||||
@config.expect.plugins.returns([:array, :cexception, :return_thru_ptr, :ignore_arg, :ignore])
|
||||
@config.expect.plugins.returns([:array, :cexception, :return_thru_ptr, :ignore_arg, :ignore])
|
||||
@config.expect.plugins.returns([:array, :cexception, :return_thru_ptr, :ignore_arg, :ignore])
|
||||
@config.expect.plugins.returns([:array, :cexception, :return_thru_ptr, :ignore_arg, :ignore])
|
||||
@config.expect.treat_as.returns({'int' => 'INT','short' => 'INT16','long' => 'INT','char' => 'INT8','uint32_t' => 'HEX32','char*' => 'STRING'})
|
||||
@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','char*' => 'STRING'}
|
||||
@cmock_generator_utils_complex = CMockGeneratorUtils.new(@config, {:unity_helper => @unity_helper, :A=>1, :B=>2})
|
||||
end
|
||||
|
||||
def teardown
|
||||
after do
|
||||
end
|
||||
|
||||
should "have set up internal accessors correctly on init" do
|
||||
assert_equal(@config, @cmock_generator_utils_simple.config)
|
||||
assert_equal({:unity_helper => @unity_helper}, @cmock_generator_utils_simple.helpers)
|
||||
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
|
||||
|
||||
should "have set up internal accessors correctly on init, complete with passed helpers" do
|
||||
assert_equal(@config, @cmock_generator_utils_complex.config)
|
||||
assert_equal({:unity_helper => @unity_helper, :A=>1, :B=>2},@cmock_generator_utils_complex.helpers)
|
||||
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
|
||||
|
||||
should "detect pointers and strings" do
|
||||
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
|
||||
|
||||
should "add code for a base expectation with no plugins" do
|
||||
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" +
|
||||
@@ -69,7 +66,7 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase
|
||||
assert_equal(expected, output)
|
||||
end
|
||||
|
||||
should "add code for a base expectation with all plugins" do
|
||||
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" +
|
||||
@@ -84,7 +81,7 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase
|
||||
assert_equal(expected, output)
|
||||
end
|
||||
|
||||
should "add code for a base expectation with all plugins and ordering not supported" do
|
||||
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" +
|
||||
@@ -98,7 +95,7 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase
|
||||
assert_equal(expected, output)
|
||||
end
|
||||
|
||||
should "add argument expectations for values when no array plugin" do
|
||||
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"
|
||||
|
||||
@@ -117,7 +114,7 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase
|
||||
assert_equal(expected4, @cmock_generator_utils_simple.code_add_an_arg_expectation(arg4))
|
||||
end
|
||||
|
||||
should "add argument expectations for values when array plugin enabled" do
|
||||
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"
|
||||
@@ -143,13 +140,13 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase
|
||||
assert_equal(expected4, @cmock_generator_utils_complex.code_add_an_arg_expectation(arg4))
|
||||
end
|
||||
|
||||
should 'not have an argument loader when the function has no arguments' do
|
||||
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
|
||||
|
||||
should 'create an argument loader when the function has arguments' do
|
||||
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]]
|
||||
@@ -162,7 +159,7 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase
|
||||
assert_equal(expected, @cmock_generator_utils_simple.code_add_argument_loader(function))
|
||||
end
|
||||
|
||||
should 'create an argument loader when the function has arguments supporting arrays' do
|
||||
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]]
|
||||
@@ -180,13 +177,13 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase
|
||||
assert_equal(expected, @cmock_generator_utils_complex.code_add_argument_loader(function))
|
||||
end
|
||||
|
||||
should "not call argument loader if there are no arguments to actually use for this function" do
|
||||
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
|
||||
|
||||
should 'call an argument loader when the function has arguments' do
|
||||
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]]
|
||||
@@ -195,7 +192,7 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase
|
||||
assert_equal(expected, @cmock_generator_utils_simple.code_call_argument_loader(function))
|
||||
end
|
||||
|
||||
should 'call an argument loader when the function has arguments with arrays' do
|
||||
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]]
|
||||
@@ -204,62 +201,68 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase
|
||||
assert_equal(expected, @cmock_generator_utils_complex.code_call_argument_loader(function))
|
||||
end
|
||||
|
||||
should 'handle a simple assert when requested' do
|
||||
it 'handle a simple assert when requested' do
|
||||
function = { :name => 'Pear' }
|
||||
arg = test_arg[:int]
|
||||
expected = " {\n UNITY_TEST_ASSERT_EQUAL_INT(cmock_call_instance->Expected_MyInt, MyInt, cmock_line, \"Function 'Pear' called with unexpected value for argument 'MyInt'.\");\n }\n"
|
||||
@unity_helper.expect.get_helper('int').returns(['UNITY_TEST_ASSERT_EQUAL_INT',''])
|
||||
@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
|
||||
|
||||
should 'handle a pointer comparison when configured to do so' do
|
||||
it 'handle a pointer comparison when configured to do so' do
|
||||
function = { :name => 'Pear' }
|
||||
arg = test_arg[:int_ptr]
|
||||
expected = " {\n UNITY_TEST_ASSERT_EQUAL_PTR(cmock_call_instance->Expected_MyIntPtr, MyIntPtr, cmock_line, \"Function 'Pear' called with unexpected value for argument 'MyIntPtr'.\");\n }\n"
|
||||
assert_equal(expected, @cmock_generator_utils_simple.code_verify_an_arg_expectation(function, arg))
|
||||
end
|
||||
|
||||
should 'handle const char as string compares ' do
|
||||
it 'handle const char as string compares ' do
|
||||
function = { :name => 'Pear' }
|
||||
arg = test_arg[:string]
|
||||
expected = " {\n UNITY_TEST_ASSERT_EQUAL_STRING(cmock_call_instance->Expected_MyStr, MyStr, cmock_line, \"Function 'Pear' called with unexpected value for argument 'MyStr'.\");\n }\n"
|
||||
@unity_helper.expect.get_helper('char*').returns(['UNITY_TEST_ASSERT_EQUAL_STRING',''])
|
||||
@unity_helper.expect :nil?, false
|
||||
@unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_STRING',''], ['char*']
|
||||
assert_equal(expected, @cmock_generator_utils_simple.code_verify_an_arg_expectation(function, arg))
|
||||
end
|
||||
|
||||
should 'handle custom types as memory compares when we have no better way to do it' do
|
||||
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_TEST_ASSERT_EQUAL_MEMORY((void*)(&cmock_call_instance->Expected_MyMyType), (void*)(&MyMyType), sizeof(MY_TYPE), cmock_line, \"Function 'Pear' called with unexpected value for argument 'MyMyType'.\");\n }\n"
|
||||
@unity_helper.expect.get_helper('MY_TYPE').returns(['UNITY_TEST_ASSERT_EQUAL_MEMORY','&'])
|
||||
@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
|
||||
|
||||
should 'handle custom types with custom handlers when available, even if they do not support the extra message' do
|
||||
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_TEST_ASSERT_EQUAL_MY_TYPE(cmock_call_instance->Expected_MyMyType, MyMyType, cmock_line, \"Function 'Pear' called with unexpected value for argument 'MyMyType'.\");\n }\n"
|
||||
@unity_helper.expect.get_helper('MY_TYPE').returns(['UNITY_TEST_ASSERT_EQUAL_MY_TYPE',''])
|
||||
@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
|
||||
|
||||
should 'handle pointers to custom types with array handlers, even if the array extension is turned off' do
|
||||
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_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY(&cmock_call_instance->Expected_MyMyType, &MyMyType, 1, cmock_line, \"Function 'Pear' called with unexpected value for argument 'MyMyType'.\");\n }\n"
|
||||
@unity_helper.expect.get_helper('MY_TYPE').returns(['UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY','&'])
|
||||
@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
|
||||
|
||||
should 'handle a simple assert when requested with array plugin enabled' do
|
||||
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_TEST_ASSERT_EQUAL_INT(cmock_call_instance->Expected_MyInt, MyInt, cmock_line, \"Function 'Pear' called with unexpected value for argument 'MyInt'.\");\n }\n"
|
||||
@unity_helper.expect.get_helper('int').returns(['UNITY_TEST_ASSERT_EQUAL_INT',''])
|
||||
@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
|
||||
|
||||
should 'handle an array comparison with array plugin enabled' do
|
||||
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" +
|
||||
@@ -271,35 +274,39 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase
|
||||
" else\n" +
|
||||
" { UNITY_TEST_ASSERT_EQUAL_INT_ARRAY(cmock_call_instance->Expected_MyIntPtr, MyIntPtr, cmock_call_instance->Expected_MyIntPtr_Depth, cmock_line, \"Function 'Pear' called with unexpected value for argument 'MyIntPtr'.\"); }\n" +
|
||||
" }\n"
|
||||
@unity_helper.expect.get_helper('int*').returns(['UNITY_TEST_ASSERT_EQUAL_INT_ARRAY',''])
|
||||
assert_equal(expected, @cmock_generator_utils_complex.code_verify_an_arg_expectation(function, arg))
|
||||
@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
|
||||
|
||||
should 'handle const char as string compares with array plugin enabled' do
|
||||
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_TEST_ASSERT_EQUAL_STRING(cmock_call_instance->Expected_MyStr, MyStr, cmock_line, \"Function 'Pear' called with unexpected value for argument 'MyStr'.\");\n }\n"
|
||||
@unity_helper.expect.get_helper('char*').returns(['UNITY_TEST_ASSERT_EQUAL_STRING',''])
|
||||
@unity_helper.expect :nil?, false
|
||||
@unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_STRING',''], ['char*']
|
||||
assert_equal(expected, @cmock_generator_utils_complex.code_verify_an_arg_expectation(function, arg))
|
||||
end
|
||||
|
||||
should 'handle custom types as memory compares when we have no better way to do it with array plugin enabled' do
|
||||
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 if (&cmock_call_instance->Expected_MyMyType == NULL)\n { UNITY_TEST_ASSERT_NULL(MyMyType, cmock_line, \"Expected NULL. Function 'Pear' called with unexpected value for argument 'MyMyType'.\"); }\n else\n { UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY((void*)(&cmock_call_instance->Expected_MyMyType), (void*)(&MyMyType), sizeof(MY_TYPE), 1, cmock_line, \"Function 'Pear' called with unexpected value for argument 'MyMyType'.\"); }\n }\n"
|
||||
@unity_helper.expect.get_helper('MY_TYPE').returns(['UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY','&'])
|
||||
@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
|
||||
|
||||
should 'handle custom types with custom handlers when available, even if they do not support the extra message with array plugin enabled' do
|
||||
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_TEST_ASSERT_EQUAL_MY_TYPE(cmock_call_instance->Expected_MyMyType, MyMyType, cmock_line, \"Function 'Pear' called with unexpected value for argument 'MyMyType'.\");\n }\n"
|
||||
@unity_helper.expect.get_helper('MY_TYPE').returns(['UNITY_TEST_ASSERT_EQUAL_MY_TYPE',''])
|
||||
@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
|
||||
|
||||
should 'handle custom types with array handlers when array plugin is enabled' do
|
||||
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" +
|
||||
@@ -311,15 +318,17 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase
|
||||
" else\n" +
|
||||
" { UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY(cmock_call_instance->Expected_MyMyTypePtr, MyMyTypePtr, cmock_call_instance->Expected_MyMyTypePtr_Depth, cmock_line, \"Function 'Pear' called with unexpected value for argument 'MyMyTypePtr'.\"); }\n" +
|
||||
" }\n"
|
||||
@unity_helper.expect.get_helper('MY_TYPE*').returns(['UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY',''])
|
||||
@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
|
||||
|
||||
should 'handle custom types with array handlers when array plugin is enabled for non-array types' do
|
||||
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_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY(&cmock_call_instance->Expected_MyMyType, &MyMyType, 1, cmock_line, \"Function 'Pear' called with unexpected value for argument 'MyMyType'.\");\n }\n"
|
||||
@unity_helper.expect.get_helper('MY_TYPE').returns(['UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY','&'])
|
||||
@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
|
||||
|
||||
@@ -10,33 +10,33 @@ $QUICK_RUBY_VERSION = RUBY_VERSION.split('.').inject(0){|vv,v| vv * 100 + v.to_i
|
||||
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
|
||||
require 'cmock_header_parser'
|
||||
|
||||
class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
describe CMockHeaderParser, "Verify CMockHeaderParser Module" do
|
||||
|
||||
def setup
|
||||
before do
|
||||
create_mocks :config
|
||||
@test_name = 'test_file.h'
|
||||
@config.expect.strippables.returns(["STRIPPABLE"])
|
||||
@config.expect.attributes.returns(['__ramfunc', 'funky_attrib', 'SQLITE_API'])
|
||||
@config.expect.c_calling_conventions.returns(['__stdcall'])
|
||||
@config.expect.treat_as_void.returns(['MY_FUNKY_VOID'])
|
||||
@config.expect.treat_as.returns({ "BANJOS" => "INT", "TUBAS" => "HEX16"} )
|
||||
@config.expect.when_no_prototypes.returns(:error)
|
||||
@config.expect.verbosity.returns(1)
|
||||
@config.expect.treat_externs.returns(:exclude)
|
||||
@config.expect :strippables, ["STRIPPABLE"]
|
||||
@config.expect :attributes, ['__ramfunc', 'funky_attrib', 'SQLITE_API']
|
||||
@config.expect :c_calling_conventions, ['__stdcall']
|
||||
@config.expect :treat_as_void, ['MY_FUNKY_VOID']
|
||||
@config.expect :treat_as, { "BANJOS" => "INT", "TUBAS" => "HEX16"}
|
||||
@config.expect :when_no_prototypes, :error
|
||||
@config.expect :verbosity, 1
|
||||
@config.expect :treat_externs, :exclude
|
||||
|
||||
@parser = CMockHeaderParser.new(@config)
|
||||
end
|
||||
|
||||
def teardown
|
||||
after do
|
||||
end
|
||||
|
||||
should "create and initialize variables to defaults appropriately" do
|
||||
it "create and initialize variables to defaults appropriately" do
|
||||
assert_equal([], @parser.funcs)
|
||||
assert_equal(['const', '__ramfunc', 'funky_attrib', 'SQLITE_API'], @parser.c_attributes)
|
||||
assert_equal(['void','MY_FUNKY_VOID'], @parser.treat_as_void)
|
||||
end
|
||||
|
||||
should "strip out line comments" do
|
||||
it "strip out line comments" do
|
||||
source =
|
||||
" abcd;\n" +
|
||||
"// hello;\n" +
|
||||
@@ -51,7 +51,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
assert_equal(expected, @parser.import_source(source).map!{|s|s.strip})
|
||||
end
|
||||
|
||||
should "remove block comments" do
|
||||
it "remove block comments" do
|
||||
source =
|
||||
" no_comments;\n" +
|
||||
"// basic_line_comment;\n" +
|
||||
@@ -84,7 +84,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
assert_equal(expected, @parser.import_source(source).map!{|s|s.strip})
|
||||
end
|
||||
|
||||
should "remove strippables from the beginning or end of function declarations" do
|
||||
it "remove strippables from the beginning or end of function declarations" do
|
||||
source =
|
||||
"void* my_calloc(size_t, size_t) STRIPPABLE;\n" +
|
||||
"void\n" +
|
||||
@@ -104,7 +104,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
assert_equal(expected, @parser.import_source(source))
|
||||
end
|
||||
|
||||
should "remove gcc's function __attribute__'s" do
|
||||
it "remove gcc's function __attribute__'s" do
|
||||
source =
|
||||
"void* my_calloc(size_t, size_t) __attribute__((alloc_size(1,2)));\n" +
|
||||
"void\n" +
|
||||
@@ -124,7 +124,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
assert_equal(expected, @parser.import_source(source))
|
||||
end
|
||||
|
||||
should "remove preprocessor directives" do
|
||||
it "remove preprocessor directives" do
|
||||
source =
|
||||
"#when stuff_happens\n" +
|
||||
"#ifdef _TEST\n" +
|
||||
@@ -136,7 +136,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
|
||||
should "remove assembler pragma sections" do
|
||||
it "remove assembler pragma sections" do
|
||||
source =
|
||||
" #pragma\tasm\n" +
|
||||
" .foo\n" +
|
||||
@@ -151,7 +151,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
|
||||
should "smush lines together that contain continuation characters" do
|
||||
it "smush lines together that contain continuation characters" do
|
||||
source =
|
||||
"hoo hah \\\n" +
|
||||
"when \\ \n"
|
||||
@@ -165,7 +165,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
|
||||
should "remove C macro definitions" do
|
||||
it "remove C macro definitions" do
|
||||
source =
|
||||
"#define this is the first line\\\n" +
|
||||
"and the second\\\n" +
|
||||
@@ -178,7 +178,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
|
||||
should "remove typedef statements" do
|
||||
it "remove typedef statements" do
|
||||
source =
|
||||
"typedef uint32 (unsigned int);\n" +
|
||||
"const typedef int INT;\n" +
|
||||
@@ -212,7 +212,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
|
||||
should "remove enum statements" do
|
||||
it "remove enum statements" do
|
||||
source =
|
||||
"enum _NamedEnum {\n" +
|
||||
" THING1 = (0x0001),\n" +
|
||||
@@ -230,7 +230,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
|
||||
should "remove union statements" do
|
||||
it "remove union statements" do
|
||||
source =
|
||||
"union _NamedDoohicky {\n" +
|
||||
" unsigned int a;\n" +
|
||||
@@ -248,7 +248,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
|
||||
should "remove struct statements" do
|
||||
it "remove struct statements" do
|
||||
source =
|
||||
"struct _NamedStruct1 {\n" +
|
||||
" unsigned int a;\n" +
|
||||
@@ -270,7 +270,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
@parser.import_source(source).map!{|s|s.strip})
|
||||
end
|
||||
|
||||
should "remove externed and inline functions" do
|
||||
it "remove externed and inline functions" do
|
||||
source =
|
||||
" extern uint32 foobar(unsigned int);\n" +
|
||||
"uint32 extern_name_func(unsigned int);\n" +
|
||||
@@ -289,7 +289,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
assert_equal(expected, @parser.import_source(source).map!{|s|s.strip})
|
||||
end
|
||||
|
||||
should "remove function definitions but keep function declarations" do
|
||||
it "remove function definitions but keep function declarations" do
|
||||
source =
|
||||
"uint32 func_with_decl_a(unsigned int);\n" +
|
||||
"uint32 func_with_decl_a(unsigned int a) { return a; }\n" +
|
||||
@@ -308,7 +308,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
assert_equal(expected, @parser.import_source(source).map!{|s|s.strip})
|
||||
end
|
||||
|
||||
should "remove a fully defined inline function" do
|
||||
it "remove a fully defined inline function" do
|
||||
source =
|
||||
"inline void foo(unsigned int a) { oranges = a; }\n" +
|
||||
"inline void bar(unsigned int a) { apples = a; };\n" +
|
||||
@@ -318,7 +318,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
"}"
|
||||
|
||||
# ensure it's expected type of exception
|
||||
assert_raise RuntimeError do
|
||||
assert_raises RuntimeError do
|
||||
@parser.parse("module", source)
|
||||
end
|
||||
|
||||
@@ -332,7 +332,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
should "remove just inline functions if externs to be included" do
|
||||
it "remove just inline functions if externs to be included" do
|
||||
source =
|
||||
" extern uint32 foobar(unsigned int);\n" +
|
||||
"uint32 extern_name_func(unsigned int);\n" +
|
||||
@@ -355,7 +355,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
|
||||
should "remove defines" do
|
||||
it "remove defines" do
|
||||
source =
|
||||
"#define whatever you feel like defining\n" +
|
||||
"void hello(void);\n" +
|
||||
@@ -372,7 +372,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
|
||||
should "remove keywords that would keep things from going smoothly in the future" do
|
||||
it "remove keywords that would keep things from going smoothly in the future" do
|
||||
source =
|
||||
"const int TheMatrix(register int Trinity, unsigned int *restrict Neo)"
|
||||
|
||||
@@ -387,7 +387,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
|
||||
# some code actually typedef's void even though it's not ANSI C and is, frankly, weird
|
||||
# since cmock treats void specially, we can't let void be obfuscated
|
||||
should "handle odd case of typedef'd void returned" do
|
||||
it "handle odd case of typedef'd void returned" do
|
||||
source = "MY_FUNKY_VOID FunkyVoidReturned(int a)"
|
||||
expected = { :var_arg=>nil,
|
||||
:name=>"FunkyVoidReturned",
|
||||
@@ -406,7 +406,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
assert_equal(expected, @parser.parse_declaration(source))
|
||||
end
|
||||
|
||||
should "handle odd case of typedef'd void as arg" do
|
||||
it "handle odd case of typedef'd void as arg" do
|
||||
source = "int FunkyVoidAsArg(MY_FUNKY_VOID)"
|
||||
expected = { :var_arg=>nil,
|
||||
:name=>"FunkyVoidAsArg",
|
||||
@@ -425,7 +425,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
assert_equal(expected, @parser.parse_declaration(source))
|
||||
end
|
||||
|
||||
should "handle odd case of typedef'd void as arg pointer" do
|
||||
it "handle odd case of typedef'd void as arg pointer" do
|
||||
source = "char FunkyVoidPointer(MY_FUNKY_VOID* bluh)"
|
||||
expected = { :var_arg=>nil,
|
||||
:name=>"FunkyVoidPointer",
|
||||
@@ -445,7 +445,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
|
||||
should "strip default values from function parameter lists" do
|
||||
it "strip default values from function parameter lists" do
|
||||
source =
|
||||
"void Foo(int a = 57, float b=37.52, char c= 'd', char* e=\"junk\");\n"
|
||||
|
||||
@@ -458,11 +458,11 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
|
||||
should "raise upon empty file" do
|
||||
it "raise upon empty file" do
|
||||
source = ''
|
||||
|
||||
# ensure it's expected type of exception
|
||||
assert_raise RuntimeError do
|
||||
assert_raises RuntimeError do
|
||||
@parser.parse("module", source)
|
||||
end
|
||||
|
||||
@@ -476,14 +476,14 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
should "clean up module names that contain spaces, dashes, and such" do
|
||||
it "clean up module names that contain spaces, dashes, and such" do
|
||||
source = 'void meh(int (*func)(int));'
|
||||
|
||||
retval = @parser.parse("C:\Ugly Module-Name", source)
|
||||
assert (retval[:typedefs][0] =~ /CUglyModuleName/)
|
||||
end
|
||||
|
||||
should "raise upon no function prototypes found in file" do
|
||||
it "raise upon no function prototypes found in file" do
|
||||
source =
|
||||
"typedef void SILLY_VOID_TYPE1;\n" +
|
||||
"typedef (void) SILLY_VOID_TYPE2 ;\n" +
|
||||
@@ -491,7 +491,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
"#define get_foo() \\\n ((Thing)foo.bar)"
|
||||
|
||||
# ensure it's expected type of exception
|
||||
assert_raise(RuntimeError) do
|
||||
assert_raises(RuntimeError) do
|
||||
@parser.parse("module", source)
|
||||
end
|
||||
|
||||
@@ -506,11 +506,11 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
|
||||
should "raise upon prototype parsing failure" do
|
||||
it "raise upon prototype parsing failure" do
|
||||
source = "void (int, )"
|
||||
|
||||
# ensure it's expected type of exception
|
||||
assert_raise(RuntimeError) do
|
||||
assert_raises(RuntimeError) do
|
||||
@parser.parse("module", source)
|
||||
end
|
||||
|
||||
@@ -522,7 +522,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
should "extract and return function declarations with retval and args" do
|
||||
it "extract and return function declarations with retval and args" do
|
||||
|
||||
source = "int Foo(int a, unsigned int b)"
|
||||
expected = { :var_arg=>nil,
|
||||
@@ -544,7 +544,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
assert_equal(expected, @parser.parse_declaration(source))
|
||||
end
|
||||
|
||||
should "extract and return function declarations with no retval" do
|
||||
it "extract and return function declarations with no retval" do
|
||||
|
||||
source = "void FunkyChicken( uint la, int de, bool da)"
|
||||
expected = { :var_arg=>nil,
|
||||
@@ -567,7 +567,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
assert_equal(expected, @parser.parse_declaration(source))
|
||||
end
|
||||
|
||||
should "extract and return function declarations with implied voids" do
|
||||
it "extract and return function declarations with implied voids" do
|
||||
|
||||
source = "void tat()"
|
||||
expected = { :var_arg=>nil,
|
||||
@@ -587,7 +587,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
assert_equal(expected, @parser.parse_declaration(source))
|
||||
end
|
||||
|
||||
should "extract modifiers properly" do
|
||||
it "extract modifiers properly" do
|
||||
|
||||
source = "const int TheMatrix(int Trinity, unsigned int * Neo)"
|
||||
expected = { :var_arg=>nil,
|
||||
@@ -609,7 +609,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
assert_equal(expected, @parser.parse_declaration(source))
|
||||
end
|
||||
|
||||
should "extract c calling conventions properly" do
|
||||
it "extract c calling conventions properly" do
|
||||
|
||||
source = "const int __stdcall TheMatrix(int Trinity, unsigned int * Neo)"
|
||||
expected = { :var_arg=>nil,
|
||||
@@ -632,7 +632,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
assert_equal(expected, @parser.parse_declaration(source))
|
||||
end
|
||||
|
||||
should "fully parse multiple prototypes" do
|
||||
it "fully parse multiple prototypes" do
|
||||
|
||||
source = "const int TheMatrix(int Trinity, unsigned int * Neo);\n" +
|
||||
"int Morpheus(int, unsigned int*);\n"
|
||||
@@ -673,7 +673,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
assert_equal(expected, @parser.parse("module", source)[:functions])
|
||||
end
|
||||
|
||||
should "not extract for mocking multiply defined prototypes" do
|
||||
it "not extract for mocking multiply defined prototypes" do
|
||||
|
||||
source = "const int TheMatrix(int Trinity, unsigned int * Neo);\n" +
|
||||
"const int TheMatrix(int, unsigned int*);\n"
|
||||
@@ -698,7 +698,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
assert_equal(expected, @parser.parse("module", source)[:functions])
|
||||
end
|
||||
|
||||
should "properly detect typedef'd variants of void and use those" do
|
||||
it "properly detect typedef'd variants of void and use those" do
|
||||
|
||||
source = "typedef (void) FUNKY_VOID_T;\n" +
|
||||
"typedef void CHUNKY_VOID_T;\n" +
|
||||
@@ -738,7 +738,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
assert_equal(expected, @parser.parse("module", source)[:functions])
|
||||
end
|
||||
|
||||
should "be ok with structs inside of function declarations" do
|
||||
it "be ok with structs inside of function declarations" do
|
||||
|
||||
source = "int DrHorrible(struct SingAlong Blog);\n" +
|
||||
"void Penny(struct const _KeepYourHeadUp_ * const BillyBuddy);\n" +
|
||||
@@ -792,7 +792,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
assert_equal(expected, @parser.parse("module", source)[:functions])
|
||||
end
|
||||
|
||||
should "extract functions containing unions with union specifier" do
|
||||
it "extract functions containing unions with union specifier" do
|
||||
source = "void OrangePeel(union STARS_AND_STRIPES * a, union AFL_CIO b)"
|
||||
expected = [{ :var_arg=>nil,
|
||||
:return=>{ :type => "void",
|
||||
@@ -814,7 +814,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
assert_equal(expected, result[:functions])
|
||||
end
|
||||
|
||||
should "not be thwarted by variables named with primitive types as part of the name" do
|
||||
it "not be thwarted by variables named with primitive types as part of the name" do
|
||||
source = "void ApplePeel(const unsigned int const_param, int int_param, int integer, char character, int* const constant)"
|
||||
expected = [{ :var_arg=>nil,
|
||||
:return=>{ :type => "void",
|
||||
@@ -839,7 +839,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
assert_equal(expected, result[:functions])
|
||||
end
|
||||
|
||||
should "not be thwarted by custom types named similarly to primitive types" do
|
||||
it "not be thwarted by custom types named similarly to primitive types" do
|
||||
source = "void LemonPeel(integer param, character thing, longint * junk, constant value, int32_t const number)"
|
||||
expected = [{:var_arg=>nil,
|
||||
:return=>{ :type => "void",
|
||||
@@ -864,7 +864,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
assert_equal(expected, result[:functions])
|
||||
end
|
||||
|
||||
should "handle some of those chains of C name specifiers naturally" do
|
||||
it "handle some of those chains of C name specifiers naturally" do
|
||||
source = "void CoinOperated(signed char abc, const unsigned long int xyz_123, unsigned int const abc_123, long long arm_of_the_law)"
|
||||
expected = [{:var_arg=>nil,
|
||||
:return=>{ :type => "void",
|
||||
@@ -888,7 +888,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
assert_equal(expected, result[:functions])
|
||||
end
|
||||
|
||||
should "handle custom types of various formats" do
|
||||
it "handle custom types of various formats" do
|
||||
source = "void CardOperated(CUSTOM_TYPE abc, CUSTOM_TYPE* xyz_123, CUSTOM_TYPE const abcxyz, struct CUSTOM_TYPE const * const abc123)"
|
||||
expected = [{:var_arg=>nil,
|
||||
:return=>{ :type => "void",
|
||||
@@ -912,7 +912,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
assert_equal(expected, result[:functions])
|
||||
end
|
||||
|
||||
should "handle arrays and treat them as pointers" do
|
||||
it "handle arrays and treat them as pointers" do
|
||||
source = "void KeyOperated(CUSTOM_TYPE thing1[], int thing2 [ ], char thing3 [][2 ][ 3], int* thing4[4])"
|
||||
expected = [{:var_arg=>nil,
|
||||
:return=>{ :type => "void",
|
||||
@@ -936,7 +936,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
assert_equal(expected, result[:functions])
|
||||
end
|
||||
|
||||
should "give a reasonable guess when dealing with weird combinations of custom types and modifiers" do
|
||||
it "give a reasonable guess when dealing with weird combinations of custom types and modifiers" do
|
||||
source = "void Cheese(unsigned CUSTOM_TYPE abc, unsigned xyz, CUSTOM_TYPE1 CUSTOM_TYPE2 pdq)"
|
||||
expected = [{:var_arg=>nil,
|
||||
:return=>{ :type => "void",
|
||||
@@ -959,7 +959,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
assert_equal(expected, result[:functions])
|
||||
end
|
||||
|
||||
should "extract functions containing a function pointer" do
|
||||
it "extract functions containing a function pointer" do
|
||||
source = "void FunkyTurkey(unsigned int (*func_ptr)(int, char))"
|
||||
expected = [{ :var_arg=>nil,
|
||||
:return=>{ :type => "void",
|
||||
@@ -982,7 +982,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
assert_equal(typedefs, result[:typedefs])
|
||||
end
|
||||
|
||||
should "extract functions containing a function pointer with an implied void" do
|
||||
it "extract functions containing a function pointer with an implied void" do
|
||||
source = "void FunkyTurkey(unsigned int (*func_ptr)())"
|
||||
expected = [{ :var_arg=>nil,
|
||||
:return=>{ :type => "void",
|
||||
@@ -1005,7 +1005,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
assert_equal(typedefs, result[:typedefs])
|
||||
end
|
||||
|
||||
should "extract functions containing a constant function pointer and a pointer in the nested arg list" do
|
||||
it "extract functions containing a constant function pointer and a pointer in the nested arg list" do
|
||||
source = "void FunkyChicken(unsigned int (* const func_ptr)(unsigned long int * , char))"
|
||||
expected = [{ :var_arg=>nil,
|
||||
:return=>{ :type => "void",
|
||||
@@ -1028,7 +1028,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
assert_equal(typedefs, result[:typedefs])
|
||||
end
|
||||
|
||||
# should "extract functions containing a function pointer taking a vararg" do
|
||||
# it "extract functions containing a function pointer taking a vararg" do
|
||||
# source = "void FunkyParrot(unsigned int (*func_ptr)(int, char, ...))"
|
||||
# expected = [{ :var_arg=>nil,
|
||||
# :return=>{ :type => "void",
|
||||
@@ -1051,7 +1051,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
# assert_equal(typedefs, result[:typedefs])
|
||||
# end
|
||||
|
||||
should "extract functions containing a function pointer with extra parenthesis and two sets" do
|
||||
it "extract functions containing a function pointer with extra parenthesis and two sets" do
|
||||
source = "void FunkyBudgie(int (((* func_ptr1)(int, char))), void (*func_ptr2)(void))"
|
||||
expected = [{ :var_arg=>nil,
|
||||
:return=>{ :type => "void",
|
||||
@@ -1075,7 +1075,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
assert_equal(typedefs, result[:typedefs])
|
||||
end
|
||||
|
||||
should "extract functions containing a function pointers, structs and other things" do
|
||||
it "extract functions containing a function pointers, structs and other things" do
|
||||
source = "struct mytype *FunkyRobin(uint16_t num1, uint16_t num2, void (*func_ptr1)(uint16_t num3, struct mytype2 *s));"
|
||||
expected = [{ :var_arg=>nil,
|
||||
:return=>{ :type => "struct mytype*",
|
||||
@@ -1100,7 +1100,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
assert_equal(typedefs, result[:typedefs])
|
||||
end
|
||||
|
||||
should "extract functions containing an anonymous function pointer" do
|
||||
it "extract functions containing an anonymous function pointer" do
|
||||
source = "void FunkyFowl(unsigned int (* const)(int, char))"
|
||||
expected = [{ :var_arg=>nil,
|
||||
:return=>{ :type => "void",
|
||||
@@ -1123,7 +1123,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
assert_equal(typedefs, result[:typedefs])
|
||||
end
|
||||
|
||||
should "extract functions returning a function pointer" do
|
||||
it "extract functions returning a function pointer" do
|
||||
source = "unsigned short (*FunkyPidgeon( const char op_code ))( int, long int )"
|
||||
expected = [{ :var_arg=>nil,
|
||||
:return=>{ :type => "cmock_module_func_ptr1",
|
||||
@@ -1146,7 +1146,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
assert_equal(typedefs, result[:typedefs])
|
||||
end
|
||||
|
||||
should "extract functions returning a function pointer with implied void" do
|
||||
it "extract functions returning a function pointer with implied void" do
|
||||
source = "unsigned short (*FunkyTweetie())()"
|
||||
expected = [{ :var_arg=>nil,
|
||||
:return=>{ :type => "cmock_module_func_ptr1",
|
||||
@@ -1168,7 +1168,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
assert_equal(typedefs, result[:typedefs])
|
||||
end
|
||||
|
||||
should "extract functions returning a function pointer where everything is a void" do
|
||||
it "extract functions returning a function pointer where everything is a void" do
|
||||
source = "void (* FunkySeaGull(void))(void)"
|
||||
expected = [{ :var_arg=>nil,
|
||||
:return=>{ :type => "cmock_module_func_ptr1",
|
||||
@@ -1190,7 +1190,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
assert_equal(typedefs, result[:typedefs])
|
||||
end
|
||||
|
||||
should "extract functions returning a function pointer with some pointer nonsense" do
|
||||
it "extract functions returning a function pointer with some pointer nonsense" do
|
||||
source = "unsigned int * (* FunkyMacaw(double* foo, THING *bar))(unsigned int)"
|
||||
expected = [{ :var_arg=>nil,
|
||||
:return=>{ :type => "cmock_module_func_ptr1",
|
||||
@@ -1214,7 +1214,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
assert_equal(typedefs, result[:typedefs])
|
||||
end
|
||||
|
||||
should "extract this SQLite3 function with an anonymous function pointer arg (regression test)" do
|
||||
it "extract this SQLite3 function with an anonymous function pointer arg (regression test)" do
|
||||
source = "SQLITE_API int sqlite3_bind_text(sqlite3_stmt*, int, const char*, int n, void(*)(void*))"
|
||||
expected = [{ :var_arg=>nil,
|
||||
:return=>{ :type => "int",
|
||||
@@ -1241,7 +1241,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
assert_equal(typedefs, result[:typedefs])
|
||||
end
|
||||
|
||||
should "extract functions with varargs" do
|
||||
it "extract functions with varargs" do
|
||||
source = "int XFiles(int Scully, int Mulder, ...);\n"
|
||||
expected = [{ :var_arg=>"...",
|
||||
:return=> { :type => "int",
|
||||
@@ -1263,7 +1263,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
assert_equal(expected, @parser.parse("module", source)[:functions])
|
||||
end
|
||||
|
||||
should "extract functions with strippable confusing junk like gcc attributes" do
|
||||
it "extract functions with strippable confusing junk like gcc attributes" do
|
||||
source = "int LaverneAndShirley(int Lenny, int Squiggy) __attribute__((weak)) __attribute__ ((deprecated));\n"
|
||||
expected = [{ :var_arg=>nil,
|
||||
:return=> { :type => "int",
|
||||
@@ -1285,7 +1285,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
assert_equal(expected, @parser.parse("module", source)[:functions])
|
||||
end
|
||||
|
||||
should "extract functions with strippable confusing junk like gcc attributes with parenthesis" do
|
||||
it "extract functions with strippable confusing junk like gcc attributes with parenthesis" do
|
||||
source = "int TheCosbyShow(int Cliff, int Claire) __attribute__((weak, alias (\"__f\"));\n"
|
||||
expected = [{ :var_arg=>nil,
|
||||
:return=> { :type => "int",
|
||||
|
||||
@@ -2,27 +2,35 @@
|
||||
# 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 'cmock_plugin_manager'
|
||||
require 'cmock_generator_plugin_expect'
|
||||
require 'cmock_generator_plugin_ignore'
|
||||
require 'cmock_generator_plugin_cexception'
|
||||
|
||||
class CMockPluginManagerTest < Test::Unit::TestCase
|
||||
def setup
|
||||
create_mocks :config, :utils, :pluginA, :pluginB
|
||||
@config.stubs!(:respond_to?).returns(true)
|
||||
@config.stubs!(:when_ptr).returns(:compare_data)
|
||||
@config.stubs!(:enforce_strict_ordering).returns(false)
|
||||
@config.stubs!(:ignore).returns(:args_and_calls)
|
||||
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
|
||||
)
|
||||
@config.define_singleton_method( :plugins ){ @plugins || [] }
|
||||
@config.define_singleton_method( :plugins= ){ |val| @plugins = val }
|
||||
end
|
||||
|
||||
def teardown
|
||||
after do
|
||||
end
|
||||
|
||||
should "return all plugins by default" do
|
||||
@config.expect.plugins.returns(['cexception','ignore'])
|
||||
@utils.expect.helpers.returns({})
|
||||
|
||||
|
||||
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
|
||||
@@ -36,13 +44,12 @@ class CMockPluginManagerTest < Test::Unit::TestCase
|
||||
assert_equal(true, contained[:ignore])
|
||||
assert_equal(true, contained[:cexception])
|
||||
end
|
||||
|
||||
should "return restricted plugins based on config" do
|
||||
@config.expect.plugins.returns([])
|
||||
@utils.expect.helpers.returns({})
|
||||
|
||||
|
||||
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|
|
||||
@@ -54,30 +61,28 @@ class CMockPluginManagerTest < Test::Unit::TestCase
|
||||
assert_equal(false,contained[:ignore])
|
||||
assert_equal(false,contained[:cexception])
|
||||
end
|
||||
|
||||
should "run a desired method over each plugin requested and return the results" do
|
||||
@config.expect.plugins.returns([])
|
||||
@utils.expect.helpers.returns({})
|
||||
|
||||
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]
|
||||
@pluginA.stubs!(:test_method).returns(["This Is An Awesome Test-"])
|
||||
@pluginB.stubs!(:test_method).returns(["And This is Part 2-","Of An Awesome Test"])
|
||||
|
||||
|
||||
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
|
||||
|
||||
should "run a desired method and arg list over each plugin requested and return the results" do
|
||||
@config.expect.plugins.returns([])
|
||||
@utils.expect.helpers.returns({})
|
||||
|
||||
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]
|
||||
@pluginA.stubs!(:test_method).returns(["This Is An Awesome Test-"])
|
||||
@pluginB.stubs!(:test_method).returns(["And This is Part 2-","Of An Awesome Test"])
|
||||
|
||||
|
||||
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)
|
||||
|
||||
@@ -2,50 +2,50 @@
|
||||
# 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 'cmock_unityhelper_parser'
|
||||
|
||||
class CMockUnityHelperParserTest < Test::Unit::TestCase
|
||||
describe CMockUnityHelperParser, "Verify CMockUnityHelperParser Module" do
|
||||
|
||||
def setup
|
||||
before do
|
||||
create_mocks :config
|
||||
end
|
||||
|
||||
def teardown
|
||||
after do
|
||||
end
|
||||
|
||||
should "ignore lines that are commented out" do
|
||||
source =
|
||||
|
||||
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.expects.plugins.returns([]) #not :array
|
||||
@config.expects.treat_as.returns({})
|
||||
@config.expects.load_unity_helper.returns(source)
|
||||
@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
|
||||
|
||||
should "ignore stuff in block comments" do
|
||||
source =
|
||||
|
||||
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.expects.plugins.returns([]) #not :array
|
||||
@config.expects.treat_as.returns({})
|
||||
@config.expect.load_unity_helper.returns(source)
|
||||
@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
|
||||
|
||||
should "notice equal helpers in the proper form and ignore others" do
|
||||
source =
|
||||
|
||||
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" +
|
||||
@@ -53,20 +53,20 @@ class CMockUnityHelperParserTest < Test::Unit::TestCase
|
||||
"#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.expects.plugins.returns([]) #not :array
|
||||
@config.expects.treat_as.returns({})
|
||||
@config.expect.load_unity_helper.returns(source)
|
||||
@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
|
||||
|
||||
should "notice equal helpers that contain arrays" do
|
||||
source =
|
||||
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" +
|
||||
@@ -74,19 +74,19 @@ class CMockUnityHelperParserTest < Test::Unit::TestCase
|
||||
"#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.expects.plugins.returns([]) #not :array
|
||||
@config.expects.treat_as.returns({})
|
||||
@config.expect.load_unity_helper.returns(source)
|
||||
@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
|
||||
|
||||
should "pull in the standard set of helpers and add them to my list" do
|
||||
it "pull in the standard set of helpers and add them to my list" do
|
||||
pairs = {
|
||||
"UINT" => "HEX32",
|
||||
"unsigned long" => "HEX64",
|
||||
@@ -97,15 +97,15 @@ class CMockUnityHelperParserTest < Test::Unit::TestCase
|
||||
"UINT*" => "UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY",
|
||||
"unsigned_long*"=> "UNITY_TEST_ASSERT_EQUAL_HEX64_ARRAY",
|
||||
}
|
||||
@config.expects.plugins.returns([]) #not :array
|
||||
@config.expects.treat_as.returns(pairs)
|
||||
@config.expect.load_unity_helper.returns(nil)
|
||||
@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
|
||||
|
||||
should "pull in the user specified set of helpers and add them to my list" do
|
||||
|
||||
it "pull in the user specified set of helpers and add them to my list" do
|
||||
pairs = {
|
||||
"char*" => "STRING",
|
||||
"unsigned int" => "HEX32",
|
||||
@@ -116,18 +116,18 @@ class CMockUnityHelperParserTest < Test::Unit::TestCase
|
||||
"char**" => "UNITY_TEST_ASSERT_EQUAL_STRING_ARRAY",
|
||||
"unsigned_int*" => "UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY",
|
||||
}
|
||||
@config.expects.plugins.returns([]) #not :array
|
||||
@config.expects.treat_as.returns(pairs)
|
||||
@config.expect.load_unity_helper.returns(nil)
|
||||
@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
|
||||
|
||||
should "be able to fetch helpers on my list" do
|
||||
@config.expects.plugins.returns([]) #not :array
|
||||
@config.expects.treat_as.returns({})
|
||||
@config.expect.load_unity_helper.returns("")
|
||||
|
||||
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",
|
||||
@@ -135,89 +135,89 @@ class CMockUnityHelperParserTest < Test::Unit::TestCase
|
||||
'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))
|
||||
assert_equal(["UNITY_TEST_ASSERT_EQUAL_#{exptype}",''], @parser.get_helper(ctype))
|
||||
end
|
||||
end
|
||||
|
||||
should "return memory comparison when asked to fetch helper of types not on my list" do
|
||||
@config.expects.plugins.returns([]) #not :array
|
||||
@config.expects.treat_as.returns({})
|
||||
@config.expects.load_unity_helper.returns("")
|
||||
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.returns(true)
|
||||
assert_equal(["UNITY_TEST_ASSERT_EQUAL_MEMORY",'&'], @parser.get_helper(ctype))
|
||||
@config.expect :memcmp_if_unknown, true
|
||||
assert_equal(["UNITY_TEST_ASSERT_EQUAL_MEMORY",'&'], @parser.get_helper(ctype))
|
||||
end
|
||||
end
|
||||
|
||||
should "return memory array comparison when asked to fetch helper of types not on my list" do
|
||||
@config.expects.plugins.returns([:array])
|
||||
@config.expects.treat_as.returns({})
|
||||
@config.expects.load_unity_helper.returns("")
|
||||
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.returns(true)
|
||||
assert_equal(["UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY",''], @parser.get_helper(ctype))
|
||||
@config.expect :memcmp_if_unknown, true
|
||||
assert_equal(["UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY",''], @parser.get_helper(ctype))
|
||||
end
|
||||
end
|
||||
|
||||
should "return the array handler if we cannot find the normal handler" do
|
||||
@config.expects.plugins.returns([]) #not :array
|
||||
@config.expects.treat_as.returns({})
|
||||
@config.expect.load_unity_helper.returns("")
|
||||
|
||||
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"))
|
||||
|
||||
assert_equal(["UNITY_TEST_ASSERT_EQUAL_UINT16_ARRAY",'&'], @parser.get_helper("UINT16"))
|
||||
end
|
||||
|
||||
should "return the normal handler if we cannot find the array handler" do
|
||||
@config.expects.plugins.returns([]) #not :array
|
||||
@config.expects.treat_as.returns({})
|
||||
@config.expect.load_unity_helper.returns("")
|
||||
|
||||
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*"))
|
||||
|
||||
assert_equal(["UNITY_TEST_ASSERT_EQUAL_UINT8",'*'], @parser.get_helper("UINT8*"))
|
||||
end
|
||||
|
||||
should "raise error when asked to fetch helper of type not on my list and not allowed to mem check" do
|
||||
@config.expects.plugins.returns([]) #not :array
|
||||
@config.expects.treat_as.returns({})
|
||||
@config.expect.load_unity_helper.returns("")
|
||||
@config.expect.memcmp_if_unknown.returns(false)
|
||||
|
||||
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_raise(RuntimeError) { @parser.get_helper("UINT16") }
|
||||
|
||||
assert_raises (RuntimeError) { @parser.get_helper("UINT16") }
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user